added files.
This commit is contained in:
1 parent
adf299cc81
commit
4e22dc2f72
10 files changed
+121
-19
No files matched your search
@@ -177,18 +177,32 @@ public class Augustus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public synchronized void stop() {
|
||||||
if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().getSession() != null) {
|
if (this.shuttingDown) {
|
||||||
Minecraft.getMinecraft().getSession().updatePlayTime(false);
|
return;
|
||||||
}
|
}
|
||||||
|
this.shuttingDown = true;
|
||||||
this.configManager.snapshotAll();
|
|
||||||
this.configManager.saveAll();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200L);
|
if (this.moduleManager != null && this.moduleManager.clickGui != null && this.moduleManager.clickGui.isToggled()) {
|
||||||
} catch (InterruptedException e) {
|
this.moduleManager.clickGui.setToggled(false, false);
|
||||||
throw new RuntimeException(e);
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().getSession() != null) {
|
||||||
|
Minecraft.getMinecraft().getSession().updatePlayTime(false);
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.configManager != null) {
|
||||||
|
this.configManager.saveAllForShutdown();
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class CommandManager implements ChatListener {
|
|||||||
if (args.length > 0 && args[0].equalsIgnoreCase(command.getCommand())) {
|
if (args.length > 0 && args[0].equalsIgnoreCase(command.getCommand())) {
|
||||||
command.commandAction(args, message);
|
command.commandAction(args, message);
|
||||||
event.cancel();
|
event.cancel();
|
||||||
Augustus.getInstance().getConfigManager().snapshotAll();
|
Augustus.getInstance().getConfigManager().saveAllAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,4 +23,9 @@ public class ClientSettingsConfigFile extends AbstractFeatureConfigFile {
|
|||||||
public boolean alwaysReserializeOnSave() {
|
public boolean alwaysReserializeOnSave() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean markLoadedEvenIfEmpty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,22 @@
|
|||||||
package net.augustus.config;
|
package net.augustus.config;
|
||||||
|
|
||||||
import net.augustus.settings.Setting;
|
import com.google.gson.JsonElement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
public static final ArrayList CONFIG_FILES = new ArrayList();
|
public static final ArrayList CONFIG_FILES = new ArrayList();
|
||||||
|
private final Object ioLock = new Object();
|
||||||
|
private volatile boolean shuttingDown = false;
|
||||||
|
private final ExecutorService saveExecutor = Executors.newSingleThreadExecutor(r -> {
|
||||||
|
Thread t = new Thread(r, "OpenAugustus-ConfigSaver");
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
public final ModuleSettingsConfigSection moduleSettingsConfig;
|
public final ModuleSettingsConfigSection moduleSettingsConfig;
|
||||||
public final AccountConfigStorage accountConfig;
|
public final AccountConfigStorage accountConfig;
|
||||||
public final ProxyConfigStorage proxyConfig;
|
public final ProxyConfigStorage proxyConfig;
|
||||||
@@ -21,7 +33,7 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadAll() {
|
public void loadAll() {
|
||||||
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> {
|
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> {
|
||||||
if (jsonConfigFile.isAutoManaged()) {
|
if (jsonConfigFile.isAutoManaged()) {
|
||||||
jsonConfigFile.load();
|
jsonConfigFile.load();
|
||||||
}
|
}
|
||||||
@@ -29,17 +41,60 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveAll() {
|
public void saveAll() {
|
||||||
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> saveConfigFile(jsonConfigFile));
|
synchronized (this.ioLock) {
|
||||||
|
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> saveConfigFile(jsonConfigFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAllForShutdown() {
|
||||||
|
this.shuttingDown = true;
|
||||||
|
this.saveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAllAsync() {
|
||||||
|
if (this.shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<JsonConfigFile, JsonElement> snapshots = new LinkedHashMap<>();
|
||||||
|
for (JsonConfigFile jsonConfigFile : (List<JsonConfigFile>)CONFIG_FILES) {
|
||||||
|
if (jsonConfigFile.isAutoManaged()) {
|
||||||
|
jsonConfigFile.captureSnapshot();
|
||||||
|
JsonElement snapshot = jsonConfigFile.getCachedJson();
|
||||||
|
if (snapshot != null) {
|
||||||
|
snapshots.put(jsonConfigFile, snapshot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshots.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saveExecutor.execute(() -> {
|
||||||
|
synchronized (this.ioLock) {
|
||||||
|
if (this.shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Map.Entry<JsonConfigFile, JsonElement> entry : snapshots.entrySet()) {
|
||||||
|
try {
|
||||||
|
entry.getKey().writeSnapshot(entry.getValue());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void saveConfigFile(JsonConfigFile jsonConfigFile) {
|
private static void saveConfigFile(JsonConfigFile jsonConfigFile) {
|
||||||
if (jsonConfigFile.isAutoManaged()) {
|
if (jsonConfigFile.isAutoManaged()) {
|
||||||
jsonConfigFile.save();
|
jsonConfigFile.save(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void snapshotAll() {
|
public void snapshotAll() {
|
||||||
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> snapshotConfigFile(jsonConfigFile));
|
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> snapshotConfigFile(jsonConfigFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void snapshotConfigFile(JsonConfigFile jsonConfigFile) {
|
private static void snapshotConfigFile(JsonConfigFile jsonConfigFile) {
|
||||||
|
|||||||
@@ -201,6 +201,12 @@ public abstract class JsonConfigFile implements NamedConfigComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeSnapshot(JsonElement snapshot) {
|
||||||
|
if (snapshot != null) {
|
||||||
|
this.writeJsonFile(new File(this.getFilePath()), snapshot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean markLoadedEvenIfEmpty() {
|
public boolean markLoadedEvenIfEmpty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -89,18 +90,29 @@ public class JsonFileStorageHandler {
|
|||||||
public void write(File file, JsonElement elem, Gson gson) {
|
public void write(File file, JsonElement elem, Gson gson) {
|
||||||
this.ensureParentDirectory(file);
|
this.ensureParentDirectory(file);
|
||||||
|
|
||||||
|
Path target = file.toPath();
|
||||||
|
Path tmp = target.resolveSibling(file.getName() + ".tmp");
|
||||||
try {
|
try {
|
||||||
String str = gson.toJson(elem);
|
String str = gson.toJson(elem);
|
||||||
if (this.encoder != null) {
|
if (this.encoder != null) {
|
||||||
byte[] bytes = (byte[])this.encoder.apply(str);
|
byte[] bytes = (byte[])this.encoder.apply(str);
|
||||||
Files.write(file.toPath(), bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
Files.write(tmp, bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
|
||||||
} else {
|
} else {
|
||||||
try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
|
try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
|
||||||
writer.write(str);
|
writer.write(str);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||||
|
} catch (IOException atomicEx) {
|
||||||
|
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(tmp);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -755,6 +755,10 @@ public class ModuleConfigStorage extends JsonConfigFile {
|
|||||||
Augustus.getInstance().getModuleManager().sortModules();
|
Augustus.getInstance().getModuleManager().sortModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Augustus.getInstance().getConfigManager() != null) {
|
||||||
|
Augustus.getInstance().getConfigManager().saveAllAsync();
|
||||||
|
}
|
||||||
|
|
||||||
if (report.hasAnyIssue()) {
|
if (report.hasAnyIssue()) {
|
||||||
report.logToConsole();
|
report.logToConsole();
|
||||||
if (notify) {
|
if (notify) {
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ public class ModuleSettingsConfigSection extends AbstractFeatureConfigFile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean markLoadedEvenIfEmpty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static JsonObject deepMergeJson(JsonObject json, JsonObject json2) {
|
private static JsonObject deepMergeJson(JsonObject json, JsonObject json2) {
|
||||||
JsonObject json3 = new JsonObject();
|
JsonObject json3 = new JsonObject();
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class ClickGui extends Module implements DownloadTerrainListener, TickLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
Augustus.getInstance().getConfigManager().snapshotAll();
|
Augustus.getInstance().getConfigManager().saveAllAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2215,6 +2215,7 @@ this.entityRenderer.itemRenderer.resetEquippedProgress();
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
flag = true;
|
flag = true;
|
||||||
|
Augustus.getInstance().stop();
|
||||||
Augustus.getInstance().getDiscordRpcManager().shutdown();
|
Augustus.getInstance().getDiscordRpcManager().shutdown();
|
||||||
LOGGER.info("Stopping!");
|
LOGGER.info("Stopping!");
|
||||||
|
|
||||||
@@ -2727,7 +2728,7 @@ if (this.gameSettings.language != null) {
|
|||||||
this.ingameGUI = new GuiIngameHook(this);
|
this.ingameGUI = new GuiIngameHook(this);
|
||||||
Augustus.getInstance().preStart();
|
Augustus.getInstance().preStart();
|
||||||
Augustus.getInstance().start();
|
Augustus.getInstance().start();
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(Augustus.getInstance()::getMouseWheelTracker));
|
Runtime.getRuntime().addShutdownHook(new Thread(Augustus.getInstance()::stop, "OpenAugustus-ShutdownHook"));
|
||||||
mc = this;
|
mc = this;
|
||||||
if (this.serverName != null) {
|
if (this.serverName != null) {
|
||||||
this.displayGuiScreen(new GuiConnecting(new GuiMainMenu(), this, this.serverName, this.serverPort));
|
this.displayGuiScreen(new GuiConnecting(new GuiMainMenu(), this, this.serverName, this.serverPort));
|
||||||
|
|||||||
Reference in new issue
Block a user