Skip to content

Commit

Permalink
Fix mod failure i18n key
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Mar 29, 2023
1 parent 64a9fa8 commit 36aa8ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
79 changes: 38 additions & 41 deletions src/main/java/com/faforever/client/mod/ModService.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private Thread startDirectoryWatcher(Path modsDirectory) {
modsDirectory.register(watcher, ENTRY_DELETE, ENTRY_CREATE);
while (!Thread.interrupted()) {
WatchKey key = watcher.take();
key.pollEvents().stream()
key.pollEvents()
.stream()
.filter(event -> event.kind() == ENTRY_DELETE || event.kind() == ENTRY_CREATE)
.forEach(event -> {
Path modPath = modsDirectory.resolve((Path) event.context());
Expand All @@ -171,8 +172,7 @@ private Thread startDirectoryWatcher(Path modsDirectory) {
.retryWhen(Retry.fixedDelay(30, Duration.ofSeconds(1)).filter(ModLoadException.class::isInstance))
.subscribe(null, throwable -> {
log.error("Mod could not be read: `{}`", modPath, throwable);
notificationService.addPersistentWarnNotification(i18n.get("corruptedModsError.notification", modPath.getFileName()),
List.of(new Action(i18n.get("corruptedMods.show"), evt -> platformService.reveal(modPath))));
notificationService.addPersistentWarnNotification(List.of(new Action(i18n.get("corruptedMods.show"), evt -> platformService.reveal(modPath))), "corruptedModsError.notification", modPath.getFileName());
});
}
});
Expand Down Expand Up @@ -206,8 +206,7 @@ protected Void call() {
} catch (Exception e) {
log.warn("Corrupt mod: `{}`", modPath, e);

notificationService.addPersistentWarnNotification(i18n.get("corruptedModsError.notification", modPath.getFileName()),
List.of(new Action(i18n.get("corruptedMods.show"), event -> platformService.reveal(modPath))));
notificationService.addPersistentWarnNotification(List.of(new Action(i18n.get("corruptedMods.show"), event -> platformService.reveal(modPath))), "corruptedModsError.notification", modPath.getFileName());
}
}
} catch (IOException e) {
Expand All @@ -219,15 +218,13 @@ protected Void call() {
}

public CompletableFuture<Void> downloadAndInstallMod(String uid) {
return getModVersionByUid(uid)
.thenCompose(potentialModVersion -> {
ModVersionBean modVersion = potentialModVersion.orElseThrow(() -> new IllegalArgumentException("Mod could not be found"));
return downloadAndInstallMod(modVersion, null, null);
})
.exceptionally(throwable -> {
log.error("Mod could not be installed", throwable);
return null;
});
return getModVersionByUid(uid).thenCompose(potentialModVersion -> {
ModVersionBean modVersion = potentialModVersion.orElseThrow(() -> new IllegalArgumentException("Mod could not be found"));
return downloadAndInstallMod(modVersion, null, null);
}).exceptionally(throwable -> {
log.error("Mod could not be installed", throwable);
return null;
});
}

public CompletableFuture<Void> downloadAndInstallMod(URL url) {
Expand Down Expand Up @@ -257,9 +254,7 @@ public CompletableFuture<Void> downloadAndInstallMod(ModVersionBean modVersion,
public void enableSimMods(Set<String> simMods) throws IOException {
Set<String> installedUiMods = modsByUid.keySet();

Set<String> activeMods = readActiveMods().stream()
.filter(installedUiMods::contains)
.collect(Collectors.toSet());
Set<String> activeMods = readActiveMods().stream().filter(installedUiMods::contains).collect(Collectors.toSet());

activeMods.addAll(simMods);

Expand All @@ -281,7 +276,8 @@ public CompletableFuture<Void> uninstallMod(ModVersionBean modVersion) {
}

public Path getPathForMod(ModVersionBean modVersionToFind) {
return pathToMod.entrySet().stream()
return pathToMod.entrySet()
.stream()
.filter(pathModEntry -> pathModEntry.getValue().getUid().equals(modVersionToFind.getUid()))
.findFirst()
.map(Entry::getKey)
Expand Down Expand Up @@ -326,9 +322,7 @@ public CompletableFuture<Integer> getFileSize(ModVersionBean modVersion) {

public Collection<ModVersionBean> getActivatedSimAndUIMods() throws IOException {
Set<String> activeMods = readActiveMods();
return installedMods.stream()
.filter(mod -> activeMods.contains(mod.getUid()))
.collect(Collectors.toSet());
return installedMods.stream().filter(mod -> activeMods.contains(mod.getUid())).collect(Collectors.toSet());
}

public void overrideActivatedMods(Collection<ModVersionBean> modVersions) {
Expand Down Expand Up @@ -464,7 +458,8 @@ public CompletableFuture<Collection<ModVersionBean>> updateAndActivateModVersion
}

private CompletableFuture<Optional<ModVersionBean>> getModVersionByUid(String uid) {
ElideNavigatorOnCollection<ModVersion> navigator = ElideNavigator.of(ModVersion.class).collection()
ElideNavigatorOnCollection<ModVersion> navigator = ElideNavigator.of(ModVersion.class)
.collection()
.setFilter(qBuilder().string("uid").eq(uid))
.pageSize(1)
.pageNumber(1);
Expand All @@ -477,8 +472,9 @@ private CompletableFuture<Optional<ModVersionBean>> getModVersionByUid(String ui

@Cacheable(value = CacheNames.FEATURED_MOD_FILES, sync = true)
public CompletableFuture<List<FeaturedModFile>> getFeaturedModFiles(FeaturedModBean featuredMod, Integer version) {
String endpoint = format("/featuredMods/%s/files/%s", featuredMod.getId(),
Optional.ofNullable(version).map(String::valueOf).orElse("latest"));
String endpoint = format("/featuredMods/%s/files/%s", featuredMod.getId(), Optional.ofNullable(version)
.map(String::valueOf)
.orElse("latest"));
return fafApiAccessor.getMany(FeaturedModFile.class, endpoint, fafApiAccessor.getMaxPageSize(), java.util.Map.of())
.collectList()
.switchIfEmpty(Mono.just(List.of()))
Expand Down Expand Up @@ -516,7 +512,8 @@ public CompletableFuture<List<FeaturedModBean>> getFeaturedMods() {
public CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> findByQueryWithPageCount(SearchConfig searchConfig,
int count, int page) {
SortConfig sortConfig = searchConfig.getSortConfig();
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class).collection()
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class)
.collection()
.addSortingRule(sortConfig.getSortProperty(), sortConfig.getSortOrder().equals(SortOrder.ASC));
return getModPage(navigator, searchConfig.getSearchQuery(), count, page);
}
Expand All @@ -527,29 +524,33 @@ public CompletableFuture<Integer> getRecommendedModPageCount(int count) {
}

public CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getRecommendedModsWithPageCount(int count, int page) {
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class).collection()
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class)
.collection()
.setFilter(qBuilder().bool("recommended").isTrue());
return getModPage(navigator, count, page);
}

public CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getHighestRatedUiModsWithPageCount(int count,
int page) {
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class).collection()
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class)
.collection()
.setFilter(qBuilder().string("latestVersion.type").eq("UI"))
.addSortingRule("reviewsSummary.lowerBound", false);
return getModPage(navigator, count, page);
}

public CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getHighestRatedModsWithPageCount(int count,
int page) {
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class).collection()
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class)
.collection()
.setFilter(qBuilder().string("latestVersion.type").eq("SIM"))
.addSortingRule("reviewsSummary.lowerBound", false);
return getModPage(navigator, count, page);
}

public CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getNewestModsWithPageCount(int count, int page) {
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class).collection()
ElideNavigatorOnCollection<Mod> navigator = ElideNavigator.of(Mod.class)
.collection()
.addSortingRule("latestVersion.createTime", false);
return getModPage(navigator, count, page);
}
Expand All @@ -558,12 +559,10 @@ private CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getModPage(Elid
int count, int page) {
navigator.pageNumber(page).pageSize(count);
return fafApiAccessor.getManyWithPageCount(navigator)
.map(tuple -> tuple.mapT1(mods ->
mods.stream()
.map(Mod::getLatestVersion)
.map(dto -> modMapper.map(dto, new CycleAvoidingMappingContext()))
.collect(toList())
))
.map(tuple -> tuple.mapT1(mods -> mods.stream()
.map(Mod::getLatestVersion)
.map(dto -> modMapper.map(dto, new CycleAvoidingMappingContext()))
.collect(toList())))
.toFuture();
}

Expand All @@ -572,12 +571,10 @@ private CompletableFuture<Tuple2<List<ModVersionBean>, Integer>> getModPage(Elid
int page) {
navigator.pageNumber(page).pageSize(count);
return fafApiAccessor.getManyWithPageCount(navigator, customFilter)
.map(tuple -> tuple.mapT1(mods ->
mods.stream()
.map(Mod::getLatestVersion)
.map(dto -> modMapper.map(dto, new CycleAvoidingMappingContext()))
.collect(toList())
))
.map(tuple -> tuple.mapT1(mods -> mods.stream()
.map(Mod::getLatestVersion)
.map(dto -> modMapper.map(dto, new CycleAvoidingMappingContext()))
.collect(toList())))
.toFuture();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void addPersistentErrorNotification(Throwable throwable, String messageKe
addNotification(new PersistentNotification(i18n.get(messageKey, args), ERROR, singletonList(new GetHelpAction(i18n, reportingService))));
}

public void addPersistentWarnNotification(String messageKey, List<Action> actions) {
addNotification(new PersistentNotification(i18n.get(messageKey), WARN, actions));
public void addPersistentWarnNotification(List<Action> actions, String messageKey, Object... args) {
addNotification(new PersistentNotification(i18n.get(messageKey, args), WARN, actions));
}

public void addImmediateErrorNotification(Throwable throwable, String messageKey, Object... args) {
Expand Down

0 comments on commit 36aa8ff

Please sign in to comment.