Skip to content

Commit

Permalink
Merge pull request #183 from Querz/1.15
Browse files Browse the repository at this point in the history
1.15
  • Loading branch information
Querz authored Mar 31, 2021
2 parents 5b1db63 + da9bd49 commit c04765a
Show file tree
Hide file tree
Showing 123 changed files with 3,486 additions and 458 deletions.
51 changes: 31 additions & 20 deletions README.md

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'css'
apply plugin: 'edu.sc.seis.launch4j'

group 'net.querz.mcaselector'
version '1.14.2'
version '1.15'
def appName = 'MCA Selector'
def appUrl = 'https://github.com/Querz/mcaselector'
def appAuthor = 'Querz'
Expand All @@ -37,24 +37,39 @@ repositories {
}
}

configurations {
project.configurations.implementation.canBeResolved = true
}

dependencies {
implementation 'com.github.Querz:NBT:4192a95c9d'
implementation 'org.json:json:20201115'
implementation 'ar.com.hjg:pngj:2.1.0'
implementation 'org.xerial:sqlite-jdbc:3.34.0'
implementation 'org.controlsfx:controlsfx:8.40.18'
testImplementation 'junit:junit:4.12'
testImplementation 'commons-io:commons-io:2.6'
}

task copyRuntimeLibs(type: Copy) {
from configurations.implementation
into file("$buildDir/libs/lib/")
}

jar {
archiveFileName = "${project.name}-${project.version}-min.jar"
manifest.attributes 'Main-Class': 'net.querz.mcaselector.Main', 'Application-Version': project.version
manifest.attributes (
'Main-Class': 'net.querz.mcaselector.Main',
'Application-Version': project.version,
'Class-Path': configurations.implementation.files.collect{"lib/$it.name"}.join(' ')
)
exclude 'licenses/'
from 'LICENSE'
}

shadowJar {
minimize()
archiveFileName = "${project.name}-${project.version}.jar"
project.configurations.implementation.canBeResolved = true
configurations = [project.configurations.implementation]
exclude 'LICENSE.txt', 'NOTICE.txt'
from 'LICENSE'
Expand Down Expand Up @@ -86,16 +101,25 @@ task installer {
delete innoSetupDir
innoSetupDir.mkdir()

def innoSetupLibDir = new File("${innoSetupDir}/lib")
innoSetupLibDir.mkdir()

copy {
from("${rootProject.projectDir}/inno/icon.ico")
from("${rootProject.projectDir}/inno/small.bmp")
from("${rootProject.projectDir}/inno/large.bmp")
from("${buildDir}/libs/${project.name}-${project.version}.jar")
from("${buildDir}/libs/${project.name}-${project.version}-min.jar")
from("${buildDir}/launch4j/${appName}.exe")
from("${rootProject.projectDir}/LICENSE")
from("${rootProject.projectDir}/7za.exe")
into(innoSetupDir)
rename("${project.name}-${project.version}.jar", "${project.name}.jar")
rename("${project.name}-${project.version}-min.jar", "${project.name}.jar")
}

copy {
from("${buildDir}/libs/lib/")
include('*.jar')
into(innoSetupLibDir)
}

copy {
Expand All @@ -114,7 +138,9 @@ task installer {

jar.finalizedBy shadowJar
jar.dependsOn minifyCss
jar.dependsOn copyRuntimeLibs
assemble.dependsOn shadowJar
installer.dependsOn jar

task updateReadme {
doLast {
Expand Down
4 changes: 4 additions & 0 deletions inno/inno.iss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
Source: "${applicationName}.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "7za.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
Source: "${applicationJar}"; DestDir: "{app}"; Flags: ignoreversion
Source: "lib\\*"; DestDir: "{app}\\lib"; Flags: ignoreversion

[InstallDelete]
Type: filesandordirs; Name: "{app}\\jre"

[UninstallDelete]
Type: filesandordirs; Name: "{app}\\jre"
Expand Down
160 changes: 112 additions & 48 deletions src/main/java/net/querz/mcaselector/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import net.querz.mcaselector.io.FileHelper;
import net.querz.mcaselector.io.WorldDirectories;
import net.querz.mcaselector.tiles.Tile;
import net.querz.mcaselector.tiles.overlay.OverlayParser;
import net.querz.mcaselector.ui.Color;
import net.querz.mcaselector.debug.Debug;
import net.querz.mcaselector.text.Translation;
import net.querz.mcaselector.ui.Window;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.*;
import java.nio.file.Files;
import java.util.*;
Expand Down Expand Up @@ -35,21 +40,25 @@ public final class Config {
public static final File DEFAULT_BASE_CACHE_DIR;
public static final File DEFAULT_BASE_LOG_FILE;
public static final File DEFAULT_BASE_CONFIG_FILE;
public static final File DEFAULT_BASE_OVERLAYS_FILE;

static {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("mac")) {
DEFAULT_BASE_CACHE_DIR = new File(System.getProperty("user.home"), "Library/Caches/mcaselector");
DEFAULT_BASE_LOG_FILE = new File(System.getProperty("user.home"), "Library/Logs/mcaselector/debug.log");
DEFAULT_BASE_CONFIG_FILE = new File(System.getProperty("user.home"), "Library/Application Support/mcaselector/settings.ini");
DEFAULT_BASE_OVERLAYS_FILE = new File(System.getProperty("user.home"), "Library/Application Support/mcaselector/overlays.json");
} else if (osName.contains("windows")) {
DEFAULT_BASE_CACHE_DIR = getEnvFilesWithDefault(DEFAULT_BASE_DIR.getAbsolutePath(), "mcaselector/cache", ';', "LOCALAPPDATA");
DEFAULT_BASE_LOG_FILE = getEnvFilesWithDefault(DEFAULT_BASE_DIR.getAbsolutePath(), "mcaselector/debug.log", ';', "LOCALAPPDATA");
DEFAULT_BASE_CONFIG_FILE = getEnvFilesWithDefault(DEFAULT_BASE_DIR.getAbsolutePath(), "mcaselector/settings.ini", ';', "LOCALAPPDATA");
DEFAULT_BASE_OVERLAYS_FILE = getEnvFilesWithDefault(DEFAULT_BASE_DIR.getAbsolutePath(), "mcaselector/overlays.json", ';', "LOCALAPPDATA");
} else {
DEFAULT_BASE_CACHE_DIR = getEnvFilesWithDefault("~/.cache", "mcaselector", ':', "XDG_CACHE_HOME", "XDG_CACHE_DIRS");
DEFAULT_BASE_LOG_FILE = getEnvFilesWithDefault("~/.local/share", "mcaselector/debug.log", ';', "XDG_DATA_HOME", "XDG_DATA_DIRS");
DEFAULT_BASE_CONFIG_FILE = getEnvFilesWithDefault("~/.mcaselector", "mcaselector/settings.ini", ';', "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS");
DEFAULT_BASE_OVERLAYS_FILE = getEnvFilesWithDefault("~/.mcaselector", "mcaselector/overlays.json", ';', "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS");
}

if (!DEFAULT_BASE_CACHE_DIR.exists()) {
Expand All @@ -61,6 +70,9 @@ public final class Config {
if (!DEFAULT_BASE_CONFIG_FILE.getParentFile().exists()) {
DEFAULT_BASE_CONFIG_FILE.getParentFile().mkdirs();
}
if (!DEFAULT_BASE_OVERLAYS_FILE.getParentFile().exists()) {
DEFAULT_BASE_OVERLAYS_FILE.getParentFile().mkdirs();
}
}

private static File getEnvFilesWithDefault(String def, String suffix, char divider, String... envs) {
Expand Down Expand Up @@ -129,6 +141,8 @@ private static String resolveHome(String dir) {
public static final float MIN_SCALE = 0.2f;
public static final double IMAGE_POOL_SIZE = 2.5;

private static List<OverlayParser> overlays = null;

private Config() {}

public static File getWorldDir() {
Expand Down Expand Up @@ -165,6 +179,10 @@ public static File getCacheDirForWorldUUID(UUID world, int zoomLevel) {
return new File(baseCacheDir, world.toString().replace("-", "") + "/" + zoomLevel);
}

public static File getCacheDirForWorldUUID(UUID world) {
return new File(baseCacheDir, world.toString().replace("-", ""));
}

public static UUID getWorldUUID() {
return worldUUID;
}
Expand Down Expand Up @@ -249,6 +267,14 @@ public static void setLocale(Locale locale) {
Translation.load(locale);
}

public static void setOverlays(List<OverlayParser> overlays) {
Config.overlays = overlays;
}

public static List<OverlayParser> getOverlays() {
return Config.overlays;
}

public static Color getRegionSelectionColor() {
return regionSelectionColor;
}
Expand All @@ -258,58 +284,79 @@ public static void setRegionSelectionColor(Color regionSelectionColor) {
}

public static void loadFromIni() {
if (!DEFAULT_BASE_CONFIG_FILE.exists()) {
return;
}
String userDir = DEFAULT_BASE_DIR.getAbsolutePath();
Map<String, String> config = new HashMap<>();
try {
Files.lines(DEFAULT_BASE_CONFIG_FILE.toPath()).forEach(l -> {
if (l.charAt(0) == ';') {
return;
}
String[] elements = l.split("=", 2);
if (elements.length != 2) {
Debug.errorf("invalid line in settings: \"%s\"", l);
return;
if (DEFAULT_BASE_CONFIG_FILE.exists()) {
String userDir = DEFAULT_BASE_DIR.getAbsolutePath();
Map<String, String> config = new HashMap<>();
try {
Files.lines(DEFAULT_BASE_CONFIG_FILE.toPath()).forEach(l -> {
if (l.charAt(0) == ';') {
return;
}
String[] elements = l.split("=", 2);
if (elements.length != 2) {
Debug.errorf("invalid line in settings: \"%s\"", l);
return;
}
config.put(elements[0], elements[1]);
});
} catch (IOException ex) {
Debug.dumpException("failed to read settings", ex);
}

try {
//set values
baseCacheDir = new File(config.getOrDefault(
"BaseCacheDir",
DEFAULT_BASE_CACHE_DIR.getAbsolutePath()).replace("{user.dir}", userDir)
);
logFile = new File(config.getOrDefault(
"LogFile",
DEFAULT_BASE_LOG_FILE.getAbsolutePath()).replace("{user.dir}", userDir)
);

String localeString = config.getOrDefault("Locale", DEFAULT_LOCALE.toString());
String[] localeSplit = localeString.split("_");
setLocale(new Locale(localeSplit[0], localeSplit[1]));

regionSelectionColor = new Color(config.getOrDefault("RegionSelectionColor", DEFAULT_REGION_SELECTION_COLOR.toString()));
chunkSelectionColor = new Color(config.getOrDefault("ChunkSelectionColor", DEFAULT_CHUNK_SELECTION_COLOR.toString()));
pasteChunksColor = new Color(config.getOrDefault("PasteChunksColor", DEFAULT_PASTE_CHUNKS_COLOR.toString()));
loadThreads = Integer.parseInt(config.getOrDefault("LoadThreads", DEFAULT_LOAD_THREADS + ""));
processThreads = Integer.parseInt(config.getOrDefault("ProcessThreads", DEFAULT_PROCESS_THREADS + ""));
writeThreads = Integer.parseInt(config.getOrDefault("WriteThreads", DEFAULT_WRITE_THREADS + ""));
maxLoadedFiles = Integer.parseInt(config.getOrDefault("MaxLoadedFiles", DEFAULT_MAX_LOADED_FILES + ""));
shade = Boolean.parseBoolean(config.getOrDefault("Shade", DEFAULT_SHADE + ""));
shadeWater = Boolean.parseBoolean(config.getOrDefault("ShadeWater", DEFAULT_SHADE_WATER + ""));
mcSavesDir = config.getOrDefault("MCSavesDir", DEFAULT_MC_SAVES_DIR);
if (!new File(mcSavesDir).exists()) {
mcSavesDir = DEFAULT_MC_SAVES_DIR;
}
config.put(elements[0], elements[1]);
});
} catch (IOException ex) {
Debug.dumpException("failed to read settings", ex);
debug = Boolean.parseBoolean(config.getOrDefault("Debug", DEFAULT_DEBUG + ""));
} catch (Exception ex) {
Debug.dumpException("error loading settings", ex);
}
}

try {
//set values
baseCacheDir = new File(config.getOrDefault(
"BaseCacheDir",
DEFAULT_BASE_CACHE_DIR.getAbsolutePath()).replace("{user.dir}", userDir)
);
logFile = new File(config.getOrDefault(
"LogFile",
DEFAULT_BASE_LOG_FILE.getAbsolutePath()).replace("{user.dir}", userDir)
);

String localeString = config.getOrDefault("Locale", DEFAULT_LOCALE.toString());
String[] localeSplit = localeString.split("_");
setLocale(new Locale(localeSplit[0], localeSplit[1]));

regionSelectionColor = new Color(config.getOrDefault("RegionSelectionColor", DEFAULT_REGION_SELECTION_COLOR.toString()));
chunkSelectionColor = new Color(config.getOrDefault("ChunkSelectionColor", DEFAULT_CHUNK_SELECTION_COLOR.toString()));
pasteChunksColor = new Color(config.getOrDefault("PasteChunksColor", DEFAULT_PASTE_CHUNKS_COLOR.toString()));
loadThreads = Integer.parseInt(config.getOrDefault("LoadThreads", DEFAULT_LOAD_THREADS + ""));
processThreads = Integer.parseInt(config.getOrDefault("ProcessThreads", DEFAULT_PROCESS_THREADS + ""));
writeThreads = Integer.parseInt(config.getOrDefault("WriteThreads", DEFAULT_WRITE_THREADS + ""));
maxLoadedFiles = Integer.parseInt(config.getOrDefault("MaxLoadedFiles", DEFAULT_MAX_LOADED_FILES + ""));
shade = Boolean.parseBoolean(config.getOrDefault("Shade", DEFAULT_SHADE + ""));
shadeWater = Boolean.parseBoolean(config.getOrDefault("ShadeWater", DEFAULT_SHADE_WATER + ""));
mcSavesDir = config.getOrDefault("MCSavesDir", DEFAULT_MC_SAVES_DIR);
if (!new File(mcSavesDir).exists()) {
mcSavesDir = DEFAULT_MC_SAVES_DIR;

// load overlays
if (DEFAULT_BASE_OVERLAYS_FILE.exists()) {
JSONArray overlayArray = null;
try {
overlayArray = new JSONArray(new String(Files.readAllBytes(DEFAULT_BASE_OVERLAYS_FILE.toPath())));
} catch (IOException ex) {
Debug.dumpException("failed to read overlays", ex);
}
if (overlayArray != null) {
List<OverlayParser> overlays = new ArrayList<>();
for (Object o : overlayArray) {
try {
overlays.add(OverlayParser.fromJSON((JSONObject) o));
} catch (Exception ex) {
Debug.dumpException("failed to parse overlay", ex);
}
}
Config.overlays = overlays;
}
debug = Boolean.parseBoolean(config.getOrDefault("Debug", DEFAULT_DEBUG + ""));
} catch (Exception ex) {
Debug.dumpException("error loading settings", ex);
}
}

Expand Down Expand Up @@ -347,6 +394,23 @@ public static void exportConfig() {
} catch (IOException ex) {
Debug.dumpException("error writing settings", ex);
}

// save overlays
if (overlays == null) {
if (DEFAULT_BASE_OVERLAYS_FILE.exists() && !DEFAULT_BASE_OVERLAYS_FILE.delete()) {
Debug.errorf("could not delete %s", DEFAULT_BASE_OVERLAYS_FILE.getAbsolutePath());
}
} else {
JSONArray overlayArray = new JSONArray();
for (OverlayParser parser : overlays) {
overlayArray.put(parser.toJSON());
}
try {
Files.write(DEFAULT_BASE_OVERLAYS_FILE.toPath(), Collections.singleton(overlayArray.toString()));
} catch (IOException ex) {
Debug.dumpException("error writing overlays", ex);
}
}
}

private static void addSettingsLine(String key, Object value, Object def, List<String> lines) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/querz/mcaselector/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.querz.mcaselector.ui.Window;
import net.querz.mcaselector.debug.Debug;
import net.querz.mcaselector.text.Translation;
import net.querz.mcaselector.validation.ShutdownHooks;

import javax.swing.*;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
Expand All @@ -29,7 +31,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
}

Config.loadFromIni();
Runtime.getRuntime().addShutdownHook(new Thread(Config::exportConfig));
ShutdownHooks.addShutdownHook(Config::exportConfig);
if (Config.debug()) {
Debug.initLogWriter();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/querz/mcaselector/changer/FieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum FieldType {
REPLACE_BLOCKS("ReplaceBlocks", ReplaceBlocksField.class, false, true),
DELETE_ENTITIES("DeleteEntities", DeleteEntitiesField.class, false, false),
DELETE_SECTIONS("DeleteSections", DeleteSectionsField.class, false, true),
FIX_STATUS("FixStatus", FixStatusField.class, false, true),
STRUCTURE_REFERENCE("FixStructureReferences", ReferenceField.class, true, false);

private final String name;
Expand Down
Loading

0 comments on commit c04765a

Please sign in to comment.