mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[ANY] IDEA Reformat code
This commit is contained in:
parent
bee6429bed
commit
3ecc4c3bf1
18 changed files with 79 additions and 173 deletions
|
@ -265,8 +265,8 @@ public static class ExeConf {
|
||||||
public String txtFileVersion;
|
public String txtFileVersion;
|
||||||
public String txtProductVersion;
|
public String txtProductVersion;
|
||||||
}
|
}
|
||||||
public static class NettyUpdatesBind
|
|
||||||
{
|
public static class NettyUpdatesBind {
|
||||||
public String url;
|
public String url;
|
||||||
public boolean zip;
|
public boolean zip;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ private void setConfig() {
|
||||||
// Prepare JRE
|
// Prepare JRE
|
||||||
Jre jre = new Jre();
|
Jre jre = new Jre();
|
||||||
jre.setMinVersion("1.8.0");
|
jre.setMinVersion("1.8.0");
|
||||||
if(server.config.launch4j.setMaxVersion)
|
if (server.config.launch4j.setMaxVersion)
|
||||||
jre.setMaxVersion(server.config.launch4j.maxVersion);
|
jre.setMaxVersion(server.config.launch4j.maxVersion);
|
||||||
jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32);
|
jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32);
|
||||||
jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE);
|
jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE);
|
||||||
|
|
|
@ -42,11 +42,11 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
public void init() {
|
public void init() {
|
||||||
tasks.add(new PrepareBuildTask(server));
|
tasks.add(new PrepareBuildTask(server));
|
||||||
tasks.add(new MainBuildTask(server));
|
tasks.add(new MainBuildTask(server));
|
||||||
if(server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
if (server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
||||||
tasks.add(new ProGuardBuildTask(server));
|
tasks.add(new ProGuardBuildTask(server));
|
||||||
tasks.add(new AdditionalFixesApplyTask(server));
|
tasks.add(new AdditionalFixesApplyTask(server));
|
||||||
tasks.add(new RadonBuildTask(server));
|
tasks.add(new RadonBuildTask(server));
|
||||||
if(!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -137,7 +137,7 @@ public Path process(Path inputJar) throws IOException {
|
||||||
jaConfigurator.setGuardType(server.config.launcher.guardType);
|
jaConfigurator.setGuardType(server.config.launcher.guardType);
|
||||||
jaConfigurator.setWarningMissArchJava(server.config.isWarningMissArchJava);
|
jaConfigurator.setWarningMissArchJava(server.config.isWarningMissArchJava);
|
||||||
jaConfigurator.setEnv(server.config.env);
|
jaConfigurator.setEnv(server.config.env);
|
||||||
if(server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken();
|
if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken();
|
||||||
jaConfigurator.setOemUnlockKey(server.runtime.oemUnlockKey);
|
jaConfigurator.setOemUnlockKey(server.runtime.oemUnlockKey);
|
||||||
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
||||||
reader.getCp().add(new JarFile(inputJar.toFile()));
|
reader.getCp().add(new JarFile(inputJar.toFile()));
|
||||||
|
|
|
@ -40,8 +40,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
}
|
}
|
||||||
String url = LaunchServer.server.config.netty.downloadURL.replace("%dirname%", dirName);
|
String url = LaunchServer.server.config.netty.downloadURL.replace("%dirname%", dirName);
|
||||||
boolean zip = false;
|
boolean zip = false;
|
||||||
if (server.config.netty.bindings.get(dirName) != null)
|
if (server.config.netty.bindings.get(dirName) != null) {
|
||||||
{
|
|
||||||
LaunchServer.NettyUpdatesBind bind = server.config.netty.bindings.get(dirName);
|
LaunchServer.NettyUpdatesBind bind = server.config.netty.bindings.get(dirName);
|
||||||
url = bind.url;
|
url = bind.url;
|
||||||
zip = bind.zip;
|
zip = bind.zip;
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public class GravitGuardBridge {
|
public class GravitGuardBridge {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static native void callGuard();
|
public static native void callGuard();
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static int sendHTTPRequest(String strurl) throws IOException {
|
public static int sendHTTPRequest(String strurl) throws IOException {
|
||||||
URL url = new URL(strurl);
|
URL url = new URL(strurl);
|
||||||
|
|
|
@ -33,47 +33,40 @@ public void preDiff(UpdateRequest request, UpdateRequestEvent e) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException {
|
public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException {
|
||||||
if(e.zip) return;
|
if (e.zip) return;
|
||||||
if(SettingsManager.settings.featureStore)
|
if (SettingsManager.settings.featureStore) {
|
||||||
{
|
|
||||||
LogHelper.info("Enabled HStore feature. Find");
|
LogHelper.info("Enabled HStore feature. Find");
|
||||||
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
|
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
|
||||||
//ArrayList<String> removed = new ArrayList<>();
|
//ArrayList<String> removed = new ArrayList<>();
|
||||||
diff.mismatch.walk(File.separator, (path, name, entry) -> {
|
diff.mismatch.walk(File.separator, (path, name, entry) -> {
|
||||||
if(entry.getType() == HashedEntry.Type.DIR) {
|
if (entry.getType() == HashedEntry.Type.DIR) {
|
||||||
Files.createDirectories(request.getDir().resolve(path));
|
Files.createDirectories(request.getDir().resolve(path));
|
||||||
return HashedDir.WalkAction.CONTINUE;
|
return HashedDir.WalkAction.CONTINUE;
|
||||||
}
|
}
|
||||||
HashedFile file = (HashedFile) entry;
|
HashedFile file = (HashedFile) entry;
|
||||||
//Первый экспериментальный способ - честно обходим все возможные Store
|
//Первый экспериментальный способ - честно обходим все возможные Store
|
||||||
Path ret = null;
|
Path ret = null;
|
||||||
if(lastEn.get() == null)
|
if (lastEn.get() == null) {
|
||||||
{
|
for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) {
|
||||||
for(NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs)
|
|
||||||
{
|
|
||||||
ret = tryFind(en, file);
|
ret = tryFind(en, file);
|
||||||
if(ret != null) {
|
if (ret != null) {
|
||||||
lastEn.set(en);
|
lastEn.set(en);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ret = tryFind(lastEn.get(), file);
|
ret = tryFind(lastEn.get(), file);
|
||||||
}
|
}
|
||||||
if(ret == null)
|
if (ret == null) {
|
||||||
{
|
for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) {
|
||||||
for(NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs)
|
|
||||||
{
|
|
||||||
ret = tryFind(en, file);
|
ret = tryFind(en, file);
|
||||||
if(ret != null) {
|
if (ret != null) {
|
||||||
lastEn.set(en);
|
lastEn.set(en);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ret != null)
|
if (ret != null) {
|
||||||
{
|
|
||||||
//Еще раз проверим корректность хеша
|
//Еще раз проверим корректность хеша
|
||||||
//Возможно эта проверка избыточна
|
//Возможно эта проверка избыточна
|
||||||
//if(file.isSame(ret, true))
|
//if(file.isSame(ret, true))
|
||||||
|
@ -82,8 +75,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
|
||||||
LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString());
|
LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString());
|
||||||
//Let's go!
|
//Let's go!
|
||||||
Files.copy(ret, source);
|
Files.copy(ret, source);
|
||||||
try(InputStream input = IOHelper.newInput(ret))
|
try (InputStream input = IOHelper.newInput(ret)) {
|
||||||
{
|
|
||||||
IOHelper.transfer(input, source);
|
IOHelper.transfer(input, source);
|
||||||
}
|
}
|
||||||
entry.flag = true;
|
entry.flag = true;
|
||||||
|
@ -94,25 +86,22 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException
|
|
||||||
{
|
public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException {
|
||||||
AtomicReference<Path> ret = new AtomicReference<>(null);
|
AtomicReference<Path> ret = new AtomicReference<>(null);
|
||||||
en.hdir.walk(File.separator, (path, name, entry) -> {
|
en.hdir.walk(File.separator, (path, name, entry) -> {
|
||||||
if(entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE;
|
if (entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE;
|
||||||
HashedFile tfile = (HashedFile) entry;
|
HashedFile tfile = (HashedFile) entry;
|
||||||
if(tfile.isSame(file))
|
if (tfile.isSame(file)) {
|
||||||
{
|
|
||||||
LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path);
|
LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path);
|
||||||
Path tdir = Paths.get(en.fullPath).resolve(path);
|
Path tdir = Paths.get(en.fullPath).resolve(path);
|
||||||
try {
|
try {
|
||||||
if(tfile.isSame(tdir, true))
|
if (tfile.isSame(tdir, true)) {
|
||||||
{
|
|
||||||
LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path);
|
LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path);
|
||||||
ret.set(tdir);
|
ret.set(tdir);
|
||||||
return HashedDir.WalkAction.STOP;
|
return HashedDir.WalkAction.STOP;
|
||||||
}
|
}
|
||||||
} catch (IOException e)
|
} catch (IOException e) {
|
||||||
{
|
|
||||||
LogHelper.error("Check file error %s %s", e.getClass().getName(), e.getMessage());
|
LogHelper.error("Check file error %s %s", e.getClass().getName(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,12 @@ public String getUsageDescription() {
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 2);
|
verifyArgs(args, 2);
|
||||||
boolean enabled = Boolean.valueOf(args[1]);
|
boolean enabled = Boolean.valueOf(args[1]);
|
||||||
switch (args[0])
|
switch (args[0]) {
|
||||||
{
|
case "store": {
|
||||||
case "store":
|
|
||||||
{
|
|
||||||
SettingsManager.settings.featureStore = enabled;
|
SettingsManager.settings.featureStore = enabled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
LogHelper.info("Features: [store]");
|
LogHelper.info("Features: [store]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,20 +26,16 @@ public void invoke(String... args) throws Exception {
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
int index = Integer.valueOf(args[0]);
|
int index = Integer.valueOf(args[0]);
|
||||||
boolean overwrite = Boolean.valueOf(args[1]);
|
boolean overwrite = Boolean.valueOf(args[1]);
|
||||||
for(NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs)
|
for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) {
|
||||||
{
|
if (ind == index) {
|
||||||
if(ind == index)
|
|
||||||
{
|
|
||||||
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
||||||
Path path = Paths.get(e.fullPath);
|
Path path = Paths.get(e.fullPath);
|
||||||
if(!Files.isDirectory(path))
|
if (!Files.isDirectory(path)) {
|
||||||
{
|
|
||||||
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name);
|
Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name);
|
||||||
if(Files.exists(target) && !overwrite)
|
if (Files.exists(target) && !overwrite) {
|
||||||
{
|
|
||||||
LogHelper.error("Directory %s found, flag overwrite not found", target.toAbsolutePath().toString());
|
LogHelper.error("Directory %s found, flag overwrite not found", target.toAbsolutePath().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,20 +26,16 @@ public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 1);
|
verifyArgs(args, 1);
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
int index = Integer.valueOf(args[0]);
|
int index = Integer.valueOf(args[0]);
|
||||||
for(NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs)
|
for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) {
|
||||||
{
|
if (ind == index) {
|
||||||
if(ind == index)
|
|
||||||
{
|
|
||||||
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
||||||
Path path = Paths.get(e.fullPath);
|
Path path = Paths.get(e.fullPath);
|
||||||
if(!Files.isDirectory(path))
|
if (!Files.isDirectory(path)) {
|
||||||
{
|
|
||||||
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name);
|
Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name);
|
||||||
if(Files.exists(target))
|
if (Files.exists(target)) {
|
||||||
{
|
|
||||||
LogHelper.error("Directory %s already exists", target.toAbsolutePath().toString());
|
LogHelper.error("Directory %s already exists", target.toAbsolutePath().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
for(NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs)
|
for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) {
|
||||||
{
|
|
||||||
LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
||||||
ind++;
|
ind++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,12 @@ public Path getJavaBinPath() {
|
||||||
String projectName = Launcher.getConfig().projectname;
|
String projectName = Launcher.getConfig().projectname;
|
||||||
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||||
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
||||||
} else if(ClientLauncher.getJavaBinPath() != null)
|
} else if (ClientLauncher.getJavaBinPath() != null) {
|
||||||
{
|
|
||||||
javaBinPath = ClientLauncher.getJavaBinPath();
|
javaBinPath = ClientLauncher.getJavaBinPath();
|
||||||
String projectName = Launcher.getConfig().projectname;
|
String projectName = Launcher.getConfig().projectname;
|
||||||
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||||
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ public void init(boolean clientInstance) {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException(e);
|
throw new SecurityException(e);
|
||||||
}
|
}
|
||||||
if(clientInstance) GravitGuardBridge.callGuard();
|
if (clientInstance) GravitGuardBridge.callGuard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,7 +69,7 @@ public void addCustomParams(ClientLauncherContext context) {
|
||||||
@Override
|
@Override
|
||||||
public void addCustomEnv(ClientLauncherContext context) {
|
public void addCustomEnv(ClientLauncherContext context) {
|
||||||
Map<String, String> env = context.builder.environment();
|
Map<String, String> env = context.builder.environment();
|
||||||
if(javaBinPath == null)
|
if (javaBinPath == null)
|
||||||
env.put("JAVA_HOME", System.getProperty("java.home"));
|
env.put("JAVA_HOME", System.getProperty("java.home"));
|
||||||
else
|
else
|
||||||
env.put("JAVA_HOME", javaBinPath.toAbsolutePath().toString());
|
env.put("JAVA_HOME", javaBinPath.toAbsolutePath().toString());
|
||||||
|
|
|
@ -25,8 +25,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||||
String fullPath = input.readString(1024);
|
String fullPath = input.readString(1024);
|
||||||
HashedDir dir = new HashedDir(input);
|
HashedDir dir = new HashedDir(input);
|
||||||
settings.lastHDirs.add(new NewLauncherSettings.HashedStoreEntry(dir, dirName, fullPath));
|
settings.lastHDirs.add(new NewLauncherSettings.HashedStoreEntry(dir, dirName, fullPath));
|
||||||
} catch (IOException e)
|
} catch (IOException e) {
|
||||||
{
|
|
||||||
LogHelper.error("Skip file %s exception: %s", file.toAbsolutePath().toString(), e.getMessage());
|
LogHelper.error("Skip file %s exception: %s", file.toAbsolutePath().toString(), e.getMessage());
|
||||||
}
|
}
|
||||||
return super.visitFile(file, attrs);
|
return super.visitFile(file, attrs);
|
||||||
|
@ -61,10 +60,8 @@ public void setConfig(NewLauncherSettings config) {
|
||||||
settings = config;
|
settings = config;
|
||||||
if (settings.updatesDirPath != null)
|
if (settings.updatesDirPath != null)
|
||||||
settings.updatesDir = Paths.get(settings.updatesDirPath);
|
settings.updatesDir = Paths.get(settings.updatesDirPath);
|
||||||
if(settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock)
|
if (settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock) {
|
||||||
{
|
if (ConsoleManager.checkUnlockKey(settings.consoleUnlockKey)) {
|
||||||
if(ConsoleManager.checkUnlockKey(settings.consoleUnlockKey))
|
|
||||||
{
|
|
||||||
ConsoleManager.unlock();
|
ConsoleManager.unlock();
|
||||||
LogHelper.info("Console auto unlocked");
|
LogHelper.info("Console auto unlocked");
|
||||||
}
|
}
|
||||||
|
@ -81,7 +78,7 @@ public void loadHDirStore(Path storePath) throws IOException {
|
||||||
public void saveHDirStore(Path storeProjectPath) throws IOException {
|
public void saveHDirStore(Path storeProjectPath) throws IOException {
|
||||||
Files.createDirectories(storeProjectPath);
|
Files.createDirectories(storeProjectPath);
|
||||||
for (NewLauncherSettings.HashedStoreEntry e : settings.lastHDirs) {
|
for (NewLauncherSettings.HashedStoreEntry e : settings.lastHDirs) {
|
||||||
if(!e.needSave) continue;
|
if (!e.needSave) continue;
|
||||||
Path file = storeProjectPath.resolve(e.name.concat(".bin"));
|
Path file = storeProjectPath.resolve(e.name.concat(".bin"));
|
||||||
if (!Files.exists(file)) Files.createFile(file);
|
if (!Files.exists(file)) Files.createFile(file);
|
||||||
try (HOutput output = new HOutput(IOHelper.newOutput(file))) {
|
try (HOutput output = new HOutput(IOHelper.newOutput(file))) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ public void download(String base, List<DownloadTask> applies, Path dstDirFile, D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException {
|
public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException {
|
||||||
/*try (CloseableHttpClient httpclient = HttpClients.custom()
|
/*try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||||
.setRedirectStrategy(new LaxRedirectStrategy())
|
.setRedirectStrategy(new LaxRedirectStrategy())
|
||||||
|
@ -132,23 +133,18 @@ public FileDownloadResponseHandler(Path target, DownloadCallback callback, Downl
|
||||||
@Override
|
@Override
|
||||||
public Path handleResponse(HttpResponse response) throws IOException {
|
public Path handleResponse(HttpResponse response) throws IOException {
|
||||||
InputStream source = response.getEntity().getContent();
|
InputStream source = response.getEntity().getContent();
|
||||||
if(zip)
|
if (zip) {
|
||||||
{
|
try (ZipInputStream input = IOHelper.newZipInput(source)) {
|
||||||
try(ZipInputStream input = IOHelper.newZipInput(source))
|
|
||||||
{
|
|
||||||
ZipEntry entry = input.getNextEntry();
|
ZipEntry entry = input.getNextEntry();
|
||||||
while(entry != null)
|
while (entry != null) {
|
||||||
{
|
if (entry.isDirectory()) {
|
||||||
if(entry.isDirectory())
|
|
||||||
{
|
|
||||||
entry = input.getNextEntry();
|
entry = input.getNextEntry();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
long size = entry.getSize();
|
long size = entry.getSize();
|
||||||
String filename = entry.getName();
|
String filename = entry.getName();
|
||||||
Path target = this.target.resolve(filename);
|
Path target = this.target.resolve(filename);
|
||||||
if(callback != null)
|
if (callback != null) {
|
||||||
{
|
|
||||||
callback.stateChanged(entry.getName(), 0, entry.getSize());
|
callback.stateChanged(entry.getName(), 0, entry.getSize());
|
||||||
}
|
}
|
||||||
LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString());
|
LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString());
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
package ru.gravit.launcher.request;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.hasher.HashedEntry;
|
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
|
||||||
import ru.gravit.launcher.serialize.stream.EnumSerializer;
|
|
||||||
import ru.gravit.launcher.serialize.stream.StreamObject;
|
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public final class UpdateAction extends StreamObject {
|
|
||||||
public enum Type implements EnumSerializer.Itf {
|
|
||||||
CD(1), CD_BACK(2), GET(3), FINISH(255);
|
|
||||||
private static final EnumSerializer<Type> SERIALIZER = new EnumSerializer<>(Type.class);
|
|
||||||
|
|
||||||
public static Type read(HInput input) throws IOException {
|
|
||||||
return SERIALIZER.read(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final int n;
|
|
||||||
|
|
||||||
Type(int n) {
|
|
||||||
this.n = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumber() {
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final UpdateAction CD_BACK = new UpdateAction(Type.CD_BACK, null, null);
|
|
||||||
|
|
||||||
public static final UpdateAction FINISH = new UpdateAction(Type.FINISH, null, null);
|
|
||||||
// Instance
|
|
||||||
public final Type type;
|
|
||||||
public final String name;
|
|
||||||
|
|
||||||
public final HashedEntry entry;
|
|
||||||
|
|
||||||
public UpdateAction(HInput input) throws IOException {
|
|
||||||
type = Type.read(input);
|
|
||||||
name = type == Type.CD || type == Type.GET ? IOHelper.verifyFileName(input.readString(255)) : null;
|
|
||||||
entry = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateAction(Type type, String name, HashedEntry entry) {
|
|
||||||
this.type = type;
|
|
||||||
this.name = name;
|
|
||||||
this.entry = entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(HOutput output) throws IOException {
|
|
||||||
EnumSerializer.write(output, type);
|
|
||||||
if (type == Type.CD || type == Type.GET)
|
|
||||||
output.writeString(name, 255);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,15 +27,20 @@
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
||||||
public interface UpdateController
|
public interface UpdateController {
|
||||||
{
|
|
||||||
void preUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
void preUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||||
|
|
||||||
void preDiff(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
void preDiff(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||||
void postDiff(UpdateRequest request, UpdateRequestEvent e,HashedDir.Diff diff) throws IOException;
|
|
||||||
|
void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException;
|
||||||
|
|
||||||
void preDownload(UpdateRequest request, UpdateRequestEvent e, List<ListDownloader.DownloadTask> adds) throws IOException;
|
void preDownload(UpdateRequest request, UpdateRequestEvent e, List<ListDownloader.DownloadTask> adds) throws IOException;
|
||||||
|
|
||||||
void postDownload(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
void postDownload(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||||
|
|
||||||
void postUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
void postUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UpdateController controller;
|
private static UpdateController controller;
|
||||||
|
|
||||||
public static void setController(UpdateController controller) {
|
public static void setController(UpdateController controller) {
|
||||||
|
@ -184,18 +189,17 @@ public double getTotalSizeMiB() {
|
||||||
public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception {
|
public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception {
|
||||||
LogHelper.debug("Start update request");
|
LogHelper.debug("Start update request");
|
||||||
UpdateRequestEvent e = (UpdateRequestEvent) service.sendRequest(this);
|
UpdateRequestEvent e = (UpdateRequestEvent) service.sendRequest(this);
|
||||||
if(controller != null) controller.preUpdate(this, e);
|
if (controller != null) controller.preUpdate(this, e);
|
||||||
LogHelper.debug("Start update");
|
LogHelper.debug("Start update");
|
||||||
Launcher.profile.pushOptionalFile(e.hdir, !Launcher.profile.isUpdateFastCheck());
|
Launcher.profile.pushOptionalFile(e.hdir, !Launcher.profile.isUpdateFastCheck());
|
||||||
if(controller != null) controller.preDiff(this, e);
|
if (controller != null) controller.preDiff(this, e);
|
||||||
HashedDir.Diff diff = e.hdir.diff(localDir, matcher);
|
HashedDir.Diff diff = e.hdir.diff(localDir, matcher);
|
||||||
if(controller != null) controller.postDiff(this, e, diff);
|
if (controller != null) controller.postDiff(this, e, diff);
|
||||||
final List<ListDownloader.DownloadTask> adds = new ArrayList<>();
|
final List<ListDownloader.DownloadTask> adds = new ArrayList<>();
|
||||||
if(controller != null) controller.preDownload(this, e, adds);
|
if (controller != null) controller.preDownload(this, e, adds);
|
||||||
diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> {
|
diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> {
|
||||||
if (entry.getType().equals(HashedEntry.Type.FILE)) {
|
if (entry.getType().equals(HashedEntry.Type.FILE)) {
|
||||||
if(!entry.flag)
|
if (!entry.flag) {
|
||||||
{
|
|
||||||
HashedFile file = (HashedFile) entry;
|
HashedFile file = (HashedFile) entry;
|
||||||
totalSize += file.size;
|
totalSize += file.size;
|
||||||
adds.add(new ListDownloader.DownloadTask(path, file.size));
|
adds.add(new ListDownloader.DownloadTask(path, file.size));
|
||||||
|
@ -214,17 +218,14 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
|
||||||
updateState("UnknownFile", 0L, 100);
|
updateState("UnknownFile", 0L, 100);
|
||||||
ListDownloader listDownloader = new ListDownloader();
|
ListDownloader listDownloader = new ListDownloader();
|
||||||
LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString());
|
LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString());
|
||||||
if(e.zip && !adds.isEmpty())
|
if (e.zip && !adds.isEmpty()) {
|
||||||
{
|
|
||||||
listDownloader.downloadZip(e.url, dir, this::updateState, (add) -> totalDownloaded += add);
|
listDownloader.downloadZip(e.url, dir, this::updateState, (add) -> totalDownloaded += add);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add);
|
listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add);
|
||||||
}
|
}
|
||||||
if(controller != null) controller.postDownload(this, e);
|
if (controller != null) controller.postDownload(this, e);
|
||||||
deleteExtraDir(dir, diff.extra, diff.extra.flag);
|
deleteExtraDir(dir, diff.extra, diff.extra.flag);
|
||||||
if(controller != null) controller.postUpdate(this, e);
|
if (controller != null) controller.postUpdate(this, e);
|
||||||
LogHelper.debug("Update success");
|
LogHelper.debug("Update success");
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,8 +342,8 @@ public void walk(CharSequence separator, WalkCallback callback) throws IOExcepti
|
||||||
String append = "";
|
String append = "";
|
||||||
walk(append, separator, callback, true);
|
walk(append, separator, callback, true);
|
||||||
}
|
}
|
||||||
public enum WalkAction
|
|
||||||
{
|
public enum WalkAction {
|
||||||
STOP, CONTINUE
|
STOP, CONTINUE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,24 +356,21 @@ private WalkAction walk(String append, CharSequence separator, WalkCallback call
|
||||||
for (Map.Entry<String, HashedEntry> entry : map.entrySet()) {
|
for (Map.Entry<String, HashedEntry> entry : map.entrySet()) {
|
||||||
HashedEntry e = entry.getValue();
|
HashedEntry e = entry.getValue();
|
||||||
if (e.getType() == Type.FILE) {
|
if (e.getType() == Type.FILE) {
|
||||||
if (noSeparator)
|
if (noSeparator) {
|
||||||
{
|
|
||||||
WalkAction a = callback.walked(append + entry.getKey(), entry.getKey(), e);
|
WalkAction a = callback.walked(append + entry.getKey(), entry.getKey(), e);
|
||||||
if(a == WalkAction.STOP) return a;
|
if (a == WalkAction.STOP) return a;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
WalkAction a = callback.walked(append + separator + entry.getKey(), entry.getKey(), e);
|
WalkAction a = callback.walked(append + separator + entry.getKey(), entry.getKey(), e);
|
||||||
if(a == WalkAction.STOP) return a;
|
if (a == WalkAction.STOP) return a;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String newAppend;
|
String newAppend;
|
||||||
if (noSeparator) newAppend = append + entry.getKey();
|
if (noSeparator) newAppend = append + entry.getKey();
|
||||||
else newAppend = append + separator + entry.getKey();
|
else newAppend = append + separator + entry.getKey();
|
||||||
WalkAction a = callback.walked(newAppend, entry.getKey(), e);
|
WalkAction a = callback.walked(newAppend, entry.getKey(), e);
|
||||||
if(a == WalkAction.STOP) return a;
|
if (a == WalkAction.STOP) return a;
|
||||||
a = ((HashedDir) e).walk(newAppend, separator, callback, false);
|
a = ((HashedDir) e).walk(newAppend, separator, callback, false);
|
||||||
if(a == WalkAction.STOP) return a;
|
if (a == WalkAction.STOP) return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return WalkAction.CONTINUE;
|
return WalkAction.CONTINUE;
|
||||||
|
|
|
@ -113,8 +113,7 @@ public static void debug(String format, Object... args) {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void dev(String format, Object... args) {
|
public static void dev(String format, Object... args) {
|
||||||
if(isDevEnabled())
|
if (isDevEnabled()) {
|
||||||
{
|
|
||||||
dev(String.format(format, args));
|
dev(String.format(format, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue