mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +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 txtProductVersion;
|
||||
}
|
||||
public static class NettyUpdatesBind
|
||||
{
|
||||
|
||||
public static class NettyUpdatesBind {
|
||||
public String url;
|
||||
public boolean zip;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
}
|
||||
String url = LaunchServer.server.config.netty.downloadURL.replace("%dirname%", dirName);
|
||||
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);
|
||||
url = bind.url;
|
||||
zip = bind.zip;
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
@LauncherAPI
|
||||
public class GravitGuardBridge {
|
||||
@LauncherAPI
|
||||
public static native void callGuard();
|
||||
|
||||
@LauncherAPI
|
||||
public static int sendHTTPRequest(String strurl) throws IOException {
|
||||
URL url = new URL(strurl);
|
||||
|
|
|
@ -34,8 +34,7 @@ public void preDiff(UpdateRequest request, UpdateRequestEvent e) {
|
|||
@Override
|
||||
public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException {
|
||||
if (e.zip) return;
|
||||
if(SettingsManager.settings.featureStore)
|
||||
{
|
||||
if (SettingsManager.settings.featureStore) {
|
||||
LogHelper.info("Enabled HStore feature. Find");
|
||||
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
|
||||
//ArrayList<String> removed = new ArrayList<>();
|
||||
|
@ -47,24 +46,19 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
|
|||
HashedFile file = (HashedFile) entry;
|
||||
//Первый экспериментальный способ - честно обходим все возможные Store
|
||||
Path ret = null;
|
||||
if(lastEn.get() == null)
|
||||
{
|
||||
for(NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs)
|
||||
{
|
||||
if (lastEn.get() == null) {
|
||||
for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) {
|
||||
ret = tryFind(en, file);
|
||||
if (ret != null) {
|
||||
lastEn.set(en);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ret = tryFind(lastEn.get(), file);
|
||||
}
|
||||
if(ret == null)
|
||||
{
|
||||
for(NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs)
|
||||
{
|
||||
if (ret == null) {
|
||||
for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) {
|
||||
ret = tryFind(en, file);
|
||||
if (ret != null) {
|
||||
lastEn.set(en);
|
||||
|
@ -72,8 +66,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
|
|||
}
|
||||
}
|
||||
}
|
||||
if(ret != null)
|
||||
{
|
||||
if (ret != null) {
|
||||
//Еще раз проверим корректность хеша
|
||||
//Возможно эта проверка избыточна
|
||||
//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());
|
||||
//Let's go!
|
||||
Files.copy(ret, source);
|
||||
try(InputStream input = IOHelper.newInput(ret))
|
||||
{
|
||||
try (InputStream input = IOHelper.newInput(ret)) {
|
||||
IOHelper.transfer(input, source);
|
||||
}
|
||||
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);
|
||||
en.hdir.walk(File.separator, (path, name, entry) -> {
|
||||
if (entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE;
|
||||
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);
|
||||
Path tdir = Paths.get(en.fullPath).resolve(path);
|
||||
try {
|
||||
if(tfile.isSame(tdir, true))
|
||||
{
|
||||
if (tfile.isSame(tdir, true)) {
|
||||
LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path);
|
||||
ret.set(tdir);
|
||||
return HashedDir.WalkAction.STOP;
|
||||
}
|
||||
} catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
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 {
|
||||
verifyArgs(args, 2);
|
||||
boolean enabled = Boolean.valueOf(args[1]);
|
||||
switch (args[0])
|
||||
{
|
||||
case "store":
|
||||
{
|
||||
switch (args[0]) {
|
||||
case "store": {
|
||||
SettingsManager.settings.featureStore = enabled;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
LogHelper.info("Features: [store]");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -26,20 +26,16 @@ public void invoke(String... args) throws Exception {
|
|||
int ind = 1;
|
||||
int index = Integer.valueOf(args[0]);
|
||||
boolean overwrite = Boolean.valueOf(args[1]);
|
||||
for(NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs)
|
||||
{
|
||||
if(ind == index)
|
||||
{
|
||||
for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) {
|
||||
if (ind == index) {
|
||||
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
||||
Path path = Paths.get(e.fullPath);
|
||||
if(!Files.isDirectory(path))
|
||||
{
|
||||
if (!Files.isDirectory(path)) {
|
||||
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
||||
return;
|
||||
}
|
||||
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());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -26,20 +26,16 @@ public void invoke(String... args) throws Exception {
|
|||
verifyArgs(args, 1);
|
||||
int ind = 1;
|
||||
int index = Integer.valueOf(args[0]);
|
||||
for(NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs)
|
||||
{
|
||||
if(ind == index)
|
||||
{
|
||||
for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) {
|
||||
if (ind == index) {
|
||||
LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name);
|
||||
Path path = Paths.get(e.fullPath);
|
||||
if(!Files.isDirectory(path))
|
||||
{
|
||||
if (!Files.isDirectory(path)) {
|
||||
LogHelper.error("Directory %s not found", path.toAbsolutePath().toString());
|
||||
return;
|
||||
}
|
||||
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());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ public String getUsageDescription() {
|
|||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
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);
|
||||
ind++;
|
||||
}
|
||||
|
|
|
@ -32,14 +32,12 @@ public Path getJavaBinPath() {
|
|||
String projectName = Launcher.getConfig().projectname;
|
||||
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
||||
} else if(ClientLauncher.getJavaBinPath() != null)
|
||||
{
|
||||
} else if (ClientLauncher.getJavaBinPath() != null) {
|
||||
javaBinPath = ClientLauncher.getJavaBinPath();
|
||||
String projectName = Launcher.getConfig().projectname;
|
||||
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
|||
String fullPath = input.readString(1024);
|
||||
HashedDir dir = new HashedDir(input);
|
||||
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());
|
||||
}
|
||||
return super.visitFile(file, attrs);
|
||||
|
@ -61,10 +60,8 @@ public void setConfig(NewLauncherSettings config) {
|
|||
settings = config;
|
||||
if (settings.updatesDirPath != null)
|
||||
settings.updatesDir = Paths.get(settings.updatesDirPath);
|
||||
if(settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock)
|
||||
{
|
||||
if(ConsoleManager.checkUnlockKey(settings.consoleUnlockKey))
|
||||
{
|
||||
if (settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock) {
|
||||
if (ConsoleManager.checkUnlockKey(settings.consoleUnlockKey)) {
|
||||
ConsoleManager.unlock();
|
||||
LogHelper.info("Console auto unlocked");
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
/*try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setRedirectStrategy(new LaxRedirectStrategy())
|
||||
|
@ -132,23 +133,18 @@ public FileDownloadResponseHandler(Path target, DownloadCallback callback, Downl
|
|||
@Override
|
||||
public Path handleResponse(HttpResponse response) throws IOException {
|
||||
InputStream source = response.getEntity().getContent();
|
||||
if(zip)
|
||||
{
|
||||
try(ZipInputStream input = IOHelper.newZipInput(source))
|
||||
{
|
||||
if (zip) {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(source)) {
|
||||
ZipEntry entry = input.getNextEntry();
|
||||
while(entry != null)
|
||||
{
|
||||
if(entry.isDirectory())
|
||||
{
|
||||
while (entry != null) {
|
||||
if (entry.isDirectory()) {
|
||||
entry = input.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
long size = entry.getSize();
|
||||
String filename = entry.getName();
|
||||
Path target = this.target.resolve(filename);
|
||||
if(callback != null)
|
||||
{
|
||||
if (callback != null) {
|
||||
callback.stateChanged(entry.getName(), 0, entry.getSize());
|
||||
}
|
||||
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;
|
||||
|
||||
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
||||
public interface UpdateController
|
||||
{
|
||||
public interface UpdateController {
|
||||
void preUpdate(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 preDownload(UpdateRequest request, UpdateRequestEvent e, List<ListDownloader.DownloadTask> adds) throws IOException;
|
||||
|
||||
void postDownload(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||
|
||||
void postUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException;
|
||||
}
|
||||
|
||||
private static UpdateController controller;
|
||||
|
||||
public static void setController(UpdateController controller) {
|
||||
|
@ -194,8 +199,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
|
|||
if (controller != null) controller.preDownload(this, e, adds);
|
||||
diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> {
|
||||
if (entry.getType().equals(HashedEntry.Type.FILE)) {
|
||||
if(!entry.flag)
|
||||
{
|
||||
if (!entry.flag) {
|
||||
HashedFile file = (HashedFile) entry;
|
||||
totalSize += file.size;
|
||||
adds.add(new ListDownloader.DownloadTask(path, file.size));
|
||||
|
@ -214,12 +218,9 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
|
|||
updateState("UnknownFile", 0L, 100);
|
||||
ListDownloader listDownloader = new ListDownloader();
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add);
|
||||
}
|
||||
if (controller != null) controller.postDownload(this, e);
|
||||
|
|
|
@ -342,8 +342,8 @@ public void walk(CharSequence separator, WalkCallback callback) throws IOExcepti
|
|||
String append = "";
|
||||
walk(append, separator, callback, true);
|
||||
}
|
||||
public enum WalkAction
|
||||
{
|
||||
|
||||
public enum WalkAction {
|
||||
STOP, CONTINUE
|
||||
}
|
||||
|
||||
|
@ -356,13 +356,10 @@ private WalkAction walk(String append, CharSequence separator, WalkCallback call
|
|||
for (Map.Entry<String, HashedEntry> entry : map.entrySet()) {
|
||||
HashedEntry e = entry.getValue();
|
||||
if (e.getType() == Type.FILE) {
|
||||
if (noSeparator)
|
||||
{
|
||||
if (noSeparator) {
|
||||
WalkAction a = callback.walked(append + entry.getKey(), entry.getKey(), e);
|
||||
if (a == WalkAction.STOP) return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
WalkAction a = callback.walked(append + separator + entry.getKey(), entry.getKey(), e);
|
||||
if (a == WalkAction.STOP) return a;
|
||||
}
|
||||
|
|
|
@ -113,8 +113,7 @@ public static void debug(String format, Object... args) {
|
|||
|
||||
@LauncherAPI
|
||||
public static void dev(String format, Object... args) {
|
||||
if(isDevEnabled())
|
||||
{
|
||||
if (isDevEnabled()) {
|
||||
dev(String.format(format, args));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue