mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Ключи у клиента, название папки лаунчера настраивается через projectName
This commit is contained in:
parent
35a94ae59f
commit
4a0485d1de
4 changed files with 48 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
var config = {
|
||||
//*** Настройки лаунчера ***//
|
||||
dir: "GravitLauncher", // Название папки лаунчера
|
||||
// Название папки лаунчера настраивается в LaunchServer.conf(строка projectName)
|
||||
title: "GravitLauncher", // Заголовок окна
|
||||
icons: ["favicon.png"], // Путь/Пути до иконки окна
|
||||
|
||||
|
@ -36,12 +36,6 @@ var config = {
|
|||
settingsMagic: 0xC0DE5, // Магия вне хогвартса
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates");
|
||||
if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) {
|
||||
java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir);
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package pro.gravit.launcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.security.*;
|
||||
import java.security.interfaces.ECPrivateKey;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
@ -72,9 +77,33 @@ public static void initGson(ClientModuleManager modulesManager) {
|
|||
Launcher.gsonManager.initGson();
|
||||
}
|
||||
|
||||
public void readKeys() throws IOException, InvalidKeySpecException {
|
||||
if(privateKey != null || publicKey != null) return;
|
||||
Path dir = DirBridge.dir;
|
||||
Path publicKeyFile =dir.resolve("public.key");
|
||||
Path privateKeyFile = dir.resolve("private.key");
|
||||
if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) {
|
||||
LogHelper.info("Reading EC keypair");
|
||||
publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile));
|
||||
privateKey = SecurityHelper.toPrivateECKey(IOHelper.read(privateKeyFile));
|
||||
} else {
|
||||
LogHelper.info("Generating EC keypair");
|
||||
KeyPair pair = SecurityHelper.genECKeyPair(new SecureRandom());
|
||||
publicKey = (ECPublicKey) pair.getPublic();
|
||||
privateKey = (ECPrivateKey) pair.getPrivate();
|
||||
|
||||
// Write key pair list
|
||||
LogHelper.info("Writing EC keypair list");
|
||||
IOHelper.write(publicKeyFile, publicKey.getEncoded());
|
||||
IOHelper.write(privateKeyFile, privateKey.getEncoded());
|
||||
}
|
||||
}
|
||||
|
||||
// Instance
|
||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
public RuntimeProvider runtimeProvider;
|
||||
public ECPublicKey publicKey;
|
||||
public ECPrivateKey privateKey;
|
||||
|
||||
public static ClientModuleManager modulesManager;
|
||||
|
||||
|
@ -119,6 +148,7 @@ public void start(String... args) throws Throwable {
|
|||
Objects.requireNonNull(args, "args");
|
||||
if (started.getAndSet(true))
|
||||
throw new IllegalStateException("Launcher has been already started");
|
||||
readKeys();
|
||||
LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this));
|
||||
runtimeProvider.preLoad();
|
||||
LauncherGuardManager.initGuard(false);
|
||||
|
|
|
@ -461,6 +461,7 @@ public static void main(String... args) throws Throwable {
|
|||
if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider();
|
||||
engine.runtimeProvider.init(true);
|
||||
engine.runtimeProvider.preLoad();
|
||||
engine.readKeys();
|
||||
HWIDProvider.registerHWIDs();
|
||||
LauncherGuardManager.initGuard(true);
|
||||
LogHelper.debug("Reading ClientLauncher params");
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherAPI;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class DirBridge {
|
||||
|
||||
|
@ -98,4 +100,18 @@ public static Path getLegacyLauncherDir(String projectname) {
|
|||
public static void setUseLegacyDir(boolean b) {
|
||||
useLegacyDir = b;
|
||||
}
|
||||
|
||||
static {
|
||||
String projectName = Launcher.getConfig().projectname;
|
||||
try {
|
||||
DirBridge.dir = getLauncherDir(projectName);
|
||||
if(!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir);
|
||||
DirBridge.dirStore = getStoreDir(projectName);
|
||||
if(!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore);
|
||||
DirBridge.dirProjectStore = getProjectStoreDir(projectName);
|
||||
if(!IOHelper.exists(DirBridge.dirProjectStore)) Files.createDirectories(DirBridge.dirProjectStore);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue