diff --git a/src/main/java/de/tosox/zonerelay/Application.java b/src/main/java/de/tosox/zonerelay/Application.java index b350796..8ccc481 100644 --- a/src/main/java/de/tosox/zonerelay/Application.java +++ b/src/main/java/de/tosox/zonerelay/Application.java @@ -4,6 +4,7 @@ import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.name.Names; +import de.tosox.zonerelay.shared.config.AppPaths; import de.tosox.zonerelay.ui.CrashHandler; import de.tosox.zonerelay.ui.MainFrame; import de.tosox.zonerelay.shared.i18n.Localizer; @@ -21,9 +22,12 @@ public Application() { this.mainFrame = injector.getInstance(MainFrame.class); + Logger fileLogger = injector.getInstance(Key.get(Logger.class, Names.named("file"))); Logger uiLogger = injector.getInstance(Key.get(Logger.class, Names.named("ui"))); Localizer localizer = injector.getInstance(Localizer.class); + AppPaths paths = injector.getInstance(AppPaths.class); + fileLogger.info("Working directory: %s", paths.getBase()); uiLogger.info(localizer.translate("MSG_WELCOME_MESSAGE", BuildInfo.APP_NAME)); uiLogger.info("-------------------------------------------------------------------\n"); } diff --git a/src/main/java/de/tosox/zonerelay/infrastructure/download/HttpArchiveDownloader.java b/src/main/java/de/tosox/zonerelay/infrastructure/download/HttpArchiveDownloader.java index 8ddaa66..a5ce120 100644 --- a/src/main/java/de/tosox/zonerelay/infrastructure/download/HttpArchiveDownloader.java +++ b/src/main/java/de/tosox/zonerelay/infrastructure/download/HttpArchiveDownloader.java @@ -82,7 +82,7 @@ public DownloadResult download(String url, String modId, String declaredHash, Fi String computedHash = HashUtils.md5(archive); manifestStore.recordDownload(modId, url, filename); - logger.info("Downloaded to %s", archive.getPath()); + logger.info("Downloaded to %s", archive.getName()); return new DownloadResult(archive, computedHash); } @@ -101,16 +101,16 @@ private Optional tryServeFromCache(String url, String modId, Str if (resolved.hasHash()) { String installedHash = cached.installedHash(); if (installedHash != null && installedHash.equalsIgnoreCase(resolved.hash())) { - logger.info("Archive unchanged on server (scraped hash match), skipping: %s", cachedArchive.getPath()); + logger.info("Archive unchanged on server (scraped hash match), skipping: %s", cachedArchive.getName()); return Optional.of(new DownloadResult(cachedArchive, installedHash)); } } else if (declaredHash != null) { String cachedFileHash = HashUtils.md5(cachedArchive); if (declaredHash.equalsIgnoreCase(cachedFileHash)) { - logger.info("Archive already downloaded (declared hash match), skipping: %s", cachedArchive.getPath()); + logger.info("Archive already downloaded (declared hash match), skipping: %s", cachedArchive.getName()); return Optional.of(new DownloadResult(cachedArchive, cachedFileHash)); } - logger.info("Cached archive does not match declared hash, re-downloading: %s", cachedArchive.getPath()); + logger.info("Cached archive does not match declared hash, re-downloading: %s", cachedArchive.getName()); } return Optional.empty(); diff --git a/src/main/java/de/tosox/zonerelay/infrastructure/extraction/SevenZipExtractor.java b/src/main/java/de/tosox/zonerelay/infrastructure/extraction/SevenZipExtractor.java index e1ea8e7..993194a 100644 --- a/src/main/java/de/tosox/zonerelay/infrastructure/extraction/SevenZipExtractor.java +++ b/src/main/java/de/tosox/zonerelay/infrastructure/extraction/SevenZipExtractor.java @@ -16,17 +16,19 @@ @Singleton public class SevenZipExtractor implements ArchiveExtractor { private final Logger logger; + private final AppPaths paths; private final String sevenZipPath; @Inject public SevenZipExtractor(@Named("file") Logger logger, AppPaths paths) { this.logger = logger; + this.paths = paths; this.sevenZipPath = paths.getSevenZipExe().toString(); } @Override public void extract(File archive, Path destination) throws Exception { - logger.info("Extracting %s to %s", archive.getPath(), destination); + logger.info("Extracting %s to %s", paths.relativize(archive.toPath()), paths.relativize(destination)); Process extractProcess = new ProcessBuilder( sevenZipPath, "-bso0", "x", archive.getPath(), "-o" + destination.toString(), "-y") diff --git a/src/main/java/de/tosox/zonerelay/infrastructure/install/ModEntryInstaller.java b/src/main/java/de/tosox/zonerelay/infrastructure/install/ModEntryInstaller.java index e006e79..c0a4f55 100644 --- a/src/main/java/de/tosox/zonerelay/infrastructure/install/ModEntryInstaller.java +++ b/src/main/java/de/tosox/zonerelay/infrastructure/install/ModEntryInstaller.java @@ -63,7 +63,7 @@ public void install(ModEntry entry, File archive, ProgressListener progressListe if (mod.getType() == EntryType.MOD) { targetDir = paths.getModsDir().resolve(mod.getName()); uiLogger.info(localizer.translate("MSG_ADDON_DELETE_OLD_VERSION")); - fileLogger.info("Deleting previous version in %s", targetDir); + fileLogger.info("Deleting previous version in %s", paths.relativize(targetDir)); FileUtils.deleteDirectory(targetDir.toFile()); } else { targetDir = mo2ConfigReader.getGamePath(); @@ -73,8 +73,7 @@ public void install(ModEntry entry, File archive, ProgressListener progressListe Files.createDirectories(tempDir); try { - uiLogger.info(localizer.translate("MSG_EXTRACT_TO", tempDir)); - fileLogger.info("Extracting %s to %s", archive.getPath(), tempDir); + uiLogger.info(localizer.translate("MSG_EXTRACT_TO", paths.relativize(tempDir))); extractor.extract(archive, tempDir); uiLogger.info(localizer.translate("MSG_READ_SETUP")); @@ -101,14 +100,14 @@ public void install(ModEntry entry, File archive, ProgressListener progressListe String instruction = setup.get(i); SetupMapping mapping = resolveMapping(instruction, tempDir, targetDir); - uiLogger.info(localizer.translate("MSG_COPY_TO", mapping.source().getFileName(), mapping.destination())); - fileLogger.info("Copying %s → %s", mapping.source(), mapping.destination()); + uiLogger.info(localizer.translate("MSG_COPY_TO", mapping.source().getFileName(), paths.relativize(mapping.destination()))); + fileLogger.info("Copying %s → %s", paths.relativize(mapping.source()), paths.relativize(mapping.destination())); copyEntry(mapping.source(), mapping.destination()); progressListener.onProgressUpdate(i + 1, total); } } finally { - fileLogger.info("Cleaning up temp dir: %s", tempDir); + fileLogger.info("Cleaning up temp dir: %s", paths.relativize(tempDir)); FileUtils.deleteDirectory(tempDir.toFile()); } diff --git a/src/main/java/de/tosox/zonerelay/infrastructure/install/SeparatorInstaller.java b/src/main/java/de/tosox/zonerelay/infrastructure/install/SeparatorInstaller.java index c260ecd..5dc5a7a 100644 --- a/src/main/java/de/tosox/zonerelay/infrastructure/install/SeparatorInstaller.java +++ b/src/main/java/de/tosox/zonerelay/infrastructure/install/SeparatorInstaller.java @@ -49,7 +49,7 @@ public void install(ModEntry entry, File archive, ProgressListener progressListe Path modDir = paths.getModsDir().resolve(separator.getName() + "_separator"); - uiLogger.info(localizer.translate("MSG_CREATE_SEPARATOR", modDir)); + uiLogger.info(localizer.translate("MSG_CREATE_SEPARATOR", paths.relativize(modDir))); fileLogger.info("Creating separator: %s", separator.getName()); Files.createDirectories(modDir); diff --git a/src/main/java/de/tosox/zonerelay/shared/config/AppPaths.java b/src/main/java/de/tosox/zonerelay/shared/config/AppPaths.java index 37714eb..775f5a3 100644 --- a/src/main/java/de/tosox/zonerelay/shared/config/AppPaths.java +++ b/src/main/java/de/tosox/zonerelay/shared/config/AppPaths.java @@ -6,6 +6,7 @@ @Getter public final class AppPaths { + private final Path base; private final Path mo2Dir; private final Path modsDir; private final Path profilesDir; @@ -27,6 +28,7 @@ public final class AppPaths { private final Path userConfig; private AppPaths(Path base) { + this.base = base; mo2Dir = base.resolve("../").normalize(); modsDir = mo2Dir.resolve("mods"); profilesDir = mo2Dir.resolve("profiles"); @@ -48,6 +50,14 @@ private AppPaths(Path base) { userConfig = base.resolve("user_config.yaml"); } + public Path relativize(Path path) { + try { + return base.relativize(path.toAbsolutePath().normalize()); + } catch (IllegalArgumentException e) { + return path; + } + } + public static AppPaths fromBase(Path baseDir) { return new AppPaths(baseDir.toAbsolutePath().normalize()); }