remove XDG stuff and some dependency
This commit is contained in:
@@ -37,7 +37,6 @@ import yugecin.opsudance.render.GameObjectRenderer;
|
||||
import yugecin.opsudance.skinning.SkinService;
|
||||
import yugecin.opsudance.ui.BackButton;
|
||||
import yugecin.opsudance.ui.OptionsOverlay;
|
||||
import yugecin.opsudance.utils.ManifestWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -88,8 +87,7 @@ public class InstanceContainer {
|
||||
env = new Environment();
|
||||
|
||||
JarFile jarfile = getJarfile();
|
||||
ManifestWrapper manifest = new ManifestWrapper(getJarManifest(jarfile));
|
||||
config = new Configuration(manifest);
|
||||
config = new Configuration();
|
||||
if (jarfile != null) {
|
||||
try {
|
||||
NativeLoader.loadNatives(jarfile);
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import yugecin.opsudance.utils.ManifestWrapper;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -41,13 +40,11 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static itdelatrisu.opsu.ui.Colors.*;
|
||||
import static yugecin.opsudance.core.errorhandling.ErrorHandler.*;
|
||||
import static yugecin.opsudance.options.Options.*;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
public final boolean USE_XDG;
|
||||
public final File CONFIG_DIR;
|
||||
public final File DATA_DIR;
|
||||
public final File CACHE_DIR;
|
||||
@@ -72,12 +69,10 @@ public class Configuration {
|
||||
public File replayImportDir;
|
||||
public File skinRootDir;
|
||||
|
||||
public Configuration(ManifestWrapper jarmanifest) {
|
||||
USE_XDG = jarmanifest.valueOrDefault(null, "Use-XDG", "").equalsIgnoreCase("true");
|
||||
|
||||
CONFIG_DIR = getXDGBaseDir("XDG_CONFIG_HOME", ".config");
|
||||
DATA_DIR = getXDGBaseDir("XDG_DATA_HOME", ".local/share");
|
||||
CACHE_DIR = getXDGBaseDir("XDG_CACHE_HOME", ".cache");
|
||||
public Configuration() {
|
||||
CONFIG_DIR = env.workingdir;
|
||||
DATA_DIR = env.workingdir;
|
||||
CACHE_DIR = env.workingdir;
|
||||
|
||||
BEATMAP_DIR = new File(DATA_DIR, "Songs/");
|
||||
SKIN_ROOT_DIR = new File(DATA_DIR, "Skins/");
|
||||
@@ -174,39 +169,6 @@ public class Configuration {
|
||||
return loadDirectory(dir, defaultDir, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory based on the XDG base directory specification for
|
||||
* Unix-like operating systems, only if the "XDG" flag is enabled.
|
||||
* @param envvar the environment variable to check (XDG_*_*)
|
||||
* @param fallback the fallback directory relative to ~home
|
||||
* @return the XDG base directory, or the working directory if unavailable
|
||||
*/
|
||||
private File getXDGBaseDir(String envvar, String fallback) {
|
||||
if (!USE_XDG) {
|
||||
return env.workingdir;
|
||||
}
|
||||
|
||||
String OS = System.getProperty("os.name").toLowerCase();
|
||||
if (OS.indexOf("nix") == -1 && OS.indexOf("nux") == -1 && OS.indexOf("aix") == -1){
|
||||
return env.workingdir;
|
||||
}
|
||||
|
||||
String rootPath = System.getenv(envvar);
|
||||
if (rootPath == null) {
|
||||
String home = System.getProperty("user.home");
|
||||
if (home == null) {
|
||||
return new File("./");
|
||||
}
|
||||
rootPath = String.format("%s/%s", home, fallback);
|
||||
}
|
||||
File dir = new File(rootPath, "opsu");
|
||||
if (!dir.isDirectory() && !dir.mkdir()) {
|
||||
explode(String.format("Failed to create configuration folder at '%s/opsu'.", rootPath),
|
||||
new Exception("empty"), PREVENT_REPORT);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots
|
||||
*/
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* opsu!dance - fork of opsu! with cursordance auto
|
||||
* Copyright (C) 2017 yugecin
|
||||
*
|
||||
* opsu!dance is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* opsu!dance is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package yugecin.opsudance.utils;
|
||||
|
||||
import yugecin.opsudance.core.NotNull;
|
||||
import yugecin.opsudance.core.Nullable;
|
||||
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class ManifestWrapper {
|
||||
|
||||
@Nullable
|
||||
public final Manifest manifest;
|
||||
|
||||
public ManifestWrapper(@Nullable Manifest manifest) {
|
||||
this.manifest = manifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute attribute in jarfile or null for default attributes
|
||||
*/
|
||||
public String valueOrDefault(@Nullable String attribute, @NotNull String key, @Nullable String dfault) {
|
||||
if (manifest == null) {
|
||||
return dfault;
|
||||
}
|
||||
Attributes attributes =
|
||||
attribute == null ? manifest.getMainAttributes() : manifest.getAttributes(attribute);
|
||||
if (attributes == null) {
|
||||
return dfault;
|
||||
}
|
||||
String val = attributes.getValue(key);
|
||||
if (val == null) {
|
||||
return dfault;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
67
src/yugecin/opsudance/utils/SimpleVersion.java
Normal file
67
src/yugecin/opsudance/utils/SimpleVersion.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* opsu!dance - fork of opsu! with cursordance auto
|
||||
* Copyright (C) 2018 yugecin
|
||||
*
|
||||
* opsu!dance is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* opsu!dance is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package yugecin.opsudance.utils;
|
||||
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import yugecin.opsudance.core.NotNull;
|
||||
import yugecin.opsudance.core.Nullable;
|
||||
|
||||
public class SimpleVersion implements Comparable<SimpleVersion> {
|
||||
|
||||
@Nullable
|
||||
public static SimpleVersion parse(@NotNull String version) {
|
||||
int dashpos = version.indexOf('-');
|
||||
if (dashpos != -1) {
|
||||
version = version.substring(0, dashpos);
|
||||
}
|
||||
final String[] parts = version.split("\\.");
|
||||
if (parts.length < 3) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new SimpleVersion(
|
||||
Integer.parseInt(parts[0]),
|
||||
Integer.parseInt(parts[1]),
|
||||
Integer.parseInt(parts[2])
|
||||
);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final int major, minor, incremental;
|
||||
|
||||
public SimpleVersion(int major, int minor, int incremental) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.incremental = incremental;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull SimpleVersion o) {
|
||||
return
|
||||
Utils.clamp(Integer.compare(major, o.major), -1, 1) * 100 +
|
||||
Utils.clamp(Integer.compare(minor, o.minor), -1, 1) * 10 +
|
||||
Utils.clamp(Integer.compare(incremental, o.incremental), -1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + major + '.' + minor + '.' + incremental;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user