mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FIX] HashedDir Store
This commit is contained in:
parent
264bd514f5
commit
da739b3eb6
5 changed files with 71 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -34,5 +34,5 @@ public class NewLauncherSettings {
|
|||
@LauncherAPI
|
||||
public List<ClientProfile> lastProfiles = new LinkedList<>();
|
||||
@LauncherAPI
|
||||
public Map<String, HashedDir> lastHDirs = new HashMap<>(16);
|
||||
public transient Map<String, HashedDir> lastHDirs = new HashMap<>(16);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<NewLauncherSettings> {
|
||||
public class StoreFileVisitor extends SimpleFileVisitor<Path> {
|
||||
@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<String, HashedDir> 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) {
|
||||
|
|
Loading…
Reference in a new issue