Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/de/tosox/zonerelay/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -101,16 +101,16 @@ private Optional<DownloadResult> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"));
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/tosox/zonerelay/shared/config/AppPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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());
}
Expand Down
Loading