Convert ignore list in a list of URLs to save space

This commit is contained in:
0xb00bface 2021-03-27 19:22:16 +01:00
parent 0e014f8d8d
commit 924c60fb0e
6 changed files with 27 additions and 16 deletions

View File

@ -1,6 +1,9 @@
4.1.2
========================
* Fixed bug, which caused recordings to get stuck
* Ignore list is now saved as URLs only. The old format is not compatible
anymore, so make sure, that you export them again, if you created a backup
before.
4.1.1
========================

View File

@ -40,7 +40,7 @@ public class IgnoreModelsAction {
if (confirmed) {
for (Model model : selectedModels) {
Model modelToIgnore = unwrap(model);
settings.modelsIgnored.add(modelToIgnore);
settings.ignoredModels.add(modelToIgnore.getUrl());
}
if (withRemoveDialog) {
boolean removeAsWell = Dialogs.showConfirmDialog("Ignore Model", null, "Remove as well?", source.getScene());

View File

@ -42,7 +42,7 @@ public class IgnoreList extends GridPane {
private static final Logger LOG = LoggerFactory.getLogger(IgnoreList.class);
private ListView<Model> ignoreListView;
private ListView<String> ignoreListView;
private List<Site> sites;
@ -83,13 +83,13 @@ public class IgnoreList extends GridPane {
}
private void removeSelectedModels() {
List<Model> selectedModels = ignoreListView.getSelectionModel().getSelectedItems();
List<String> selectedModels = ignoreListView.getSelectionModel().getSelectedItems();
if (selectedModels.isEmpty()) {
return;
} else {
Config.getInstance().getSettings().modelsIgnored.removeAll(selectedModels);
Config.getInstance().getSettings().ignoredModels.removeAll(selectedModels);
ignoreListView.getItems().removeAll(selectedModels);
LOG.debug(Config.getInstance().getSettings().modelsIgnored.toString());
LOG.debug(Config.getInstance().getSettings().ignoredModels.toString());
try {
Config.getInstance().save();
} catch (IOException e) {
@ -99,7 +99,7 @@ public class IgnoreList extends GridPane {
}
private void loadIgnoredModels() {
List<Model> ignored = Config.getInstance().getSettings().modelsIgnored;
List<String> ignored = Config.getInstance().getSettings().ignoredModels;
ignoreListView.getItems().clear();
ignoreListView.getItems().addAll(ignored);
Collections.sort(ignoreListView.getItems());
@ -116,11 +116,11 @@ public class IgnoreList extends GridPane {
File file = chooser.showSaveDialog(null);
if (file != null) {
Moshi moshi = new Moshi.Builder().add(Model.class, new ModelJsonAdapter(sites)).build();
Type modelListType = Types.newParameterizedType(List.class, Model.class);
JsonAdapter<List<Model>> adapter = moshi.adapter(modelListType);
Type modelListType = Types.newParameterizedType(List.class, String.class);
JsonAdapter<List<String>> adapter = moshi.adapter(modelListType);
adapter = adapter.indent(" ");
try (FileOutputStream out = new FileOutputStream(file)) {
String json = adapter.toJson(Config.getInstance().getSettings().modelsIgnored);
String json = adapter.toJson(Config.getInstance().getSettings().ignoredModels);
out.write(json.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
Dialogs.showError(getScene(), "Couldn't export ignore list", e.getLocalizedMessage(), e);
@ -134,13 +134,13 @@ public class IgnoreList extends GridPane {
File file = chooser.showOpenDialog(null);
if (file != null) {
Moshi moshi = new Moshi.Builder().add(Model.class, new ModelJsonAdapter(sites)).build();
Type modelListType = Types.newParameterizedType(List.class, Model.class);
JsonAdapter<List<Model>> adapter = moshi.adapter(modelListType);
Type modelListType = Types.newParameterizedType(List.class, String.class);
JsonAdapter<List<String>> adapter = moshi.adapter(modelListType);
try {
byte[] fileContent = Files.readAllBytes(file.toPath());
List<Model> ignoredModels = adapter.fromJson(new String(fileContent, StandardCharsets.UTF_8));
List<String> ignoredModels = adapter.fromJson(new String(fileContent, StandardCharsets.UTF_8));
boolean confirmed = true;
if (!Config.getInstance().getSettings().modelsIgnored.isEmpty()) {
if (!Config.getInstance().getSettings().ignoredModels.isEmpty()) {
String msg = "This will replace the existing ignore list! Continue?";
AutosizeAlert confirm = new AutosizeAlert(AlertType.CONFIRMATION, msg, getScene(), YES, NO);
confirm.setTitle("Import ignore list");
@ -149,7 +149,7 @@ public class IgnoreList extends GridPane {
confirmed = confirm.getResult() == ButtonType.YES;
}
if (confirmed) {
Config.getInstance().getSettings().modelsIgnored = ignoredModels;
Config.getInstance().getSettings().ignoredModels = ignoredModels;
refresh();
}
} catch (IOException e) {

View File

@ -358,9 +358,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
private List<Model> filterIgnoredModels(List<Model> models) {
List<Model> ignored = Config.getInstance().getSettings().modelsIgnored;
List<String> ignored = Config.getInstance().getSettings().ignoredModels;
return models.stream()
.filter(m -> !ignored.contains(m))
.filter(m -> !ignored.contains(m.getUrl()))
.collect(Collectors.toList());
}

View File

@ -18,6 +18,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
@ -181,6 +182,11 @@ public class Config {
settings.modelsIgnored.stream()
.filter(m -> m instanceof Cam4Model)
.forEach(m -> m.setName(m.getName().toLowerCase()));
// 4.1.2 reduce models ignore to store only the URL
settings.ignoredModels = settings.modelsIgnored.stream()
.map(Model::getUrl)
.collect(Collectors.toList());
settings.modelsIgnored = null;
}
private void makeBackup(File source) {

View File

@ -78,6 +78,7 @@ public class Settings {
public String httpUserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0";
public String httpUserAgentMobile = "Mozilla/5.0 (Android 9.0; Mobile; rv:82.0) Gecko/82.0 Firefox/82.0";
public byte[] key = null;
public List<String> ignoredModels = new ArrayList<>();
public String lastDownloadDir = "";
public String livejasminBaseUrl = "https://www.livejasmin.com";
public boolean livejasminBetaAcknowledged = false;
@ -106,6 +107,7 @@ public class Settings {
public long minimumSpaceLeftInBytes = 0;
public Map<String, String> modelNotes = new HashMap<>();
public List<Model> models = new ArrayList<>();
@Deprecated
public List<Model> modelsIgnored = new ArrayList<>();
public boolean monitorClipboard = false;
public int onlineCheckIntervalInSecs = 60;