mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Zone DirWatcher
This commit is contained in:
parent
837d27dd7b
commit
a06014837d
2 changed files with 24 additions and 2 deletions
|
@ -211,9 +211,11 @@ public static void main(String[] args) throws Throwable {
|
|||
for(ClientLauncherProcess.ClientParams.ClientZoneInfo info : params.zones) {
|
||||
if(info.dir == null)
|
||||
continue;
|
||||
DirWatcher watcher = new DirWatcher(Paths.get(info.path), info.dir, null, digest);
|
||||
Path zoneDir = Paths.get(info.path);
|
||||
DirWatcher watcher = new DirWatcher(zoneDir, info.dir, null, digest);
|
||||
watchers.add(watcher);
|
||||
CommonHelper.newThread(String.format("Zone '%s' Watcher", info.name), true, watcher).start();
|
||||
verifyZoneHDir(zoneDir, info.dir, null, digest); //TODO: Optimize this
|
||||
}
|
||||
}
|
||||
LauncherEngine.modulesManager.invokeEvent(new ClientProcessLaunchEvent(engine, params));
|
||||
|
@ -285,6 +287,26 @@ public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher,
|
|||
}
|
||||
}
|
||||
|
||||
public static void verifyZoneHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) throws IOException {
|
||||
//if (matcher != null)
|
||||
// matcher = matcher.verifyOnly();
|
||||
|
||||
// Hash directory and compare (ignore update-only matcher entries, it will break offline-mode)
|
||||
HashedDir currentHDir = new HashedDir(dir, matcher, true, digest);
|
||||
HashedDir.Diff diff = hdir.diffWithoutExtra(currentHDir, matcher);
|
||||
if (!diff.isSame()) {
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
diff.mismatch.walk(File.separator, (e, k, v) -> {
|
||||
if (v.getType().equals(HashedEntry.Type.FILE)) {
|
||||
LogHelper.error("Mismatch file %s", e);
|
||||
} else LogHelper.error("Mismatch %s", e);
|
||||
return HashedDir.WalkAction.CONTINUE;
|
||||
});
|
||||
}
|
||||
throw new SecurityException(String.format("Forbidden modification: '%s'", IOHelper.getFileName(dir)));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkJVMBitsAndVersion(int minVersion, int recommendVersion, int maxVersion, boolean showMessage) {
|
||||
boolean ok = true;
|
||||
if (JVMHelper.JVM_BITS != JVMHelper.OS_BITS) {
|
||||
|
|
|
@ -413,7 +413,7 @@ private Diff(HashedDir mismatch, HashedDir extra) {
|
|||
|
||||
|
||||
public boolean isSame() {
|
||||
return mismatch.isEmpty() && extra.isEmpty();
|
||||
return mismatch.isEmpty() && (extra == null || extra.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue