diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js index 1bfc5ee7..882b271c 100644 --- a/Launcher/runtime/config.js +++ b/Launcher/runtime/config.js @@ -19,6 +19,8 @@ var config = { }; DirBridge.dir = DirBridge.getLauncherDir(config.dir); +DirBridge.dirStore = DirBridge.getStoreDir(config.dir); +DirBridge.dirProjectStore = DirBridge.getProjectStoreDir(config.dir); if (!IOHelper.isDir(DirBridge.dir)) { java.nio.file.Files.createDirectory(DirBridge.dir); } diff --git a/Launcher/runtime/init.js b/Launcher/runtime/init.js index 8cb07648..8b1d6941 100644 --- a/Launcher/runtime/init.js +++ b/Launcher/runtime/init.js @@ -7,6 +7,7 @@ var LauncherApp = Java.extend(JSApplication, { cliParams.init(app.getParameters()); settingsManager.loadConfig(); settings = SettingsManager.settings; + settingsManager.loadHDirStore(); cliParams.applySettings(); }, start: function(primaryStage) { stage = primaryStage; @@ -41,6 +42,7 @@ var LauncherApp = Java.extend(JSApplication, { }, stop: function() { settingsManager.saveConfig(); + settingsManager.saveHDirStore(); options.save(); } }); diff --git a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java index 2824c1be..4cbab087 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java @@ -34,5 +34,5 @@ public class NewLauncherSettings { @LauncherAPI public List lastProfiles = new LinkedList<>(); @LauncherAPI - public Map lastHDirs = new HashMap<>(16); + public transient Map lastHDirs = new HashMap<>(16); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index 7a73d6a5..7b65f5b4 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -18,6 +18,10 @@ public class DirBridge { @LauncherAPI public static Path dir; @LauncherAPI + public static Path dirStore; + @LauncherAPI + public static Path dirProjectStore; + @LauncherAPI public static Path dirUpdates; @LauncherAPI public static Path defaultUpdatesDir; @@ -64,6 +68,16 @@ public static Path getAppDataDir() throws IOException { public static Path getLauncherDir(String projectname) throws IOException { return getAppDataDir().resolve(projectname); } + @LauncherAPI + public static Path getStoreDir(String projectname) throws IOException + { + return getAppDataDir().resolve("store"); + } + @LauncherAPI + public static Path getProjectStoreDir(String projectname) throws IOException + { + return getStoreDir(projectname).resolve(projectname); + } @LauncherAPI public static Path getGuardDir() { diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java index dfb9f142..dc0ea894 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java @@ -3,13 +3,34 @@ import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.NewLauncherSettings; import ru.gravit.launcher.client.DirBridge; +import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; import ru.gravit.utils.config.JsonConfigurable; +import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Map; public class SettingsManager extends JsonConfigurable { + public class StoreFileVisitor extends SimpleFileVisitor { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException + { + try(HInput input = new HInput(IOHelper.newInput(file))) + { + HashedDir dir = new HashedDir(input); + settings.lastHDirs.put(file.getFileName().toString(), dir); + } + return super.visitFile(file, attrs); + } + + } @LauncherAPI public static NewLauncherSettings settings; @@ -35,6 +56,35 @@ public void setConfig(NewLauncherSettings config) { if(settings.updatesDirPath != null) settings.updatesDir = Paths.get(settings.updatesDirPath); } + @LauncherAPI + public void loadHDirStore(Path storePath) throws IOException + { + Files.createDirectories(storePath); + IOHelper.walk(storePath, new StoreFileVisitor(), false); + } + @LauncherAPI + public void saveHDirStore(Path storeProjectPath) throws IOException + { + Files.createDirectories(storeProjectPath); + for(Map.Entry e : settings.lastHDirs.entrySet()) + { + Path file = Files.createFile(storeProjectPath.resolve(e.getKey())); + try(HOutput output = new HOutput(IOHelper.newOutput(file))) + { + e.getValue().write(output); + } + } + } + @LauncherAPI + public void loadHDirStore() throws IOException + { + loadHDirStore(DirBridge.dirStore); + } + @LauncherAPI + public void saveHDirStore() throws IOException + { + saveHDirStore(DirBridge.dirProjectStore); + } @Override public void setType(Type type) {