mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-09 03:46:18 -04:00
Fixed #66
This commit is contained in:
parent
8d5088d2e4
commit
b232a255e7
@ -20,7 +20,6 @@ package org.jackhuang.hellominecraft.launcher.core;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
|
||||
/**
|
||||
@ -63,14 +62,11 @@ public final class MCUtils {
|
||||
}
|
||||
|
||||
public static File getInitGameDir() {
|
||||
File gameDir = IOUtils.currentDir();
|
||||
if (gameDir.exists()) {
|
||||
gameDir = new File(gameDir, MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
File gameDir = new File(MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
return gameDir;
|
||||
}
|
||||
@ -80,6 +76,6 @@ public final class MCUtils {
|
||||
public static void tryWriteProfile(File gameDir) throws IOException {
|
||||
File file = new File(gameDir, "launcher_profiles.json");
|
||||
if (!file.exists())
|
||||
FileUtils.writeStringToFile(file, PROFILE);
|
||||
FileUtils.write(file, PROFILE);
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
||||
public void executeTask() throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
throw new IllegalStateException("Failed to get asset index");
|
||||
String result = FileUtils.readFileToString(f);
|
||||
String result = FileUtils.read(f);
|
||||
if (StrUtils.isBlank(result))
|
||||
throw new IllegalStateException("Index json is empty, please redownload it!");
|
||||
AssetsIndex o = C.GSON.fromJson(result, AssetsIndex.class);
|
||||
|
@ -133,7 +133,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
File objectsDir = new File(assetsDir, "objects");
|
||||
File indexFile = new File(indexDir, assetVersion + ".json");
|
||||
try {
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.read(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
|
||||
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
|
||||
return new File(objectsDir, hash.substring(0, 2) + "/" + hash);
|
||||
@ -152,7 +152,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
return false;
|
||||
|
||||
try {
|
||||
String assetIndexContent = FileUtils.readFileToString(indexFile, "UTF-8");
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, AssetsIndex.class);
|
||||
|
||||
if (index == null)
|
||||
@ -180,7 +180,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
}
|
||||
|
||||
try {
|
||||
String assetIndexContent = FileUtils.readFileToString(indexFile, "UTF-8");
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, AssetsIndex.class);
|
||||
|
||||
if (index == null)
|
||||
@ -195,7 +195,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
if (original.exists()) {
|
||||
cnt++;
|
||||
if (!target.isFile())
|
||||
FileUtils.copyFile(original, target, false);
|
||||
FileUtils.copyFile(original, target);
|
||||
}
|
||||
}
|
||||
// If the scale new format existent file is lower then 0.1, use the old format.
|
||||
|
@ -85,7 +85,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
if (mvj.exists() && !mvj.delete())
|
||||
HMCLog.warn("Failed to delete " + mvj);
|
||||
try {
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
|
||||
if (mv == null)
|
||||
throw new JsonSyntaxException("incorrect version");
|
||||
|
||||
|
@ -57,7 +57,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadForge(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("forge-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
else
|
||||
@ -68,7 +68,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "optifine-installer.jar");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("optifine-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||
@ -79,7 +79,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
|
||||
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
||||
return task.after(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
||||
.after(new DeleteFileTask(filepath));
|
||||
|
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.system.Compressor;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -40,7 +39,7 @@ public class PackMinecraftInstaller {
|
||||
}
|
||||
|
||||
public void install() throws IOException {
|
||||
File file = new File(IOUtils.currentDir(), "HMCL-MERGE-TEMP");
|
||||
File file = new File("HMCL-MERGE-TEMP");
|
||||
if (!file.exists() && !file.mkdirs())
|
||||
HMCLog.warn("Failed to make directories: " + file);
|
||||
for (String src1 : src)
|
||||
|
@ -79,7 +79,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
|
||||
if (!loc.exists() && loc.mkdirs())
|
||||
HMCLog.warn("Failed to make directories: " + loc);
|
||||
File json = new File(loc, mv.id + ".json");
|
||||
FileUtils.writeStringToFile(json, C.GSON.toJson(mv, MinecraftVersion.class));
|
||||
FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class));
|
||||
|
||||
service.version().refreshVersions();
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
import org.jackhuang.hellominecraft.util.system.Platform;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.Utils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
|
@ -121,7 +121,7 @@ public class GameLauncher {
|
||||
* @throws IOException failed creating process
|
||||
*/
|
||||
public void launch(List str) throws IOException {
|
||||
if (!service.version().onLaunch())
|
||||
if (!service.version().onLaunch(options.getLaunchVersion()))
|
||||
return;
|
||||
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
|
||||
Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
|
||||
@ -155,7 +155,7 @@ public class GameLauncher {
|
||||
*/
|
||||
public File makeLauncher(String launcherName, List str) throws IOException {
|
||||
HMCLog.log("Making shell launcher...");
|
||||
service.version().onLaunch();
|
||||
service.version().onLaunch(options.getLaunchVersion());
|
||||
boolean isWin = OS.os() == OS.WINDOWS;
|
||||
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
|
||||
if (!f.exists() && !f.createNewFile())
|
||||
|
@ -164,13 +164,13 @@ public final class ModpackManager {
|
||||
HMCLog.warn("Failed to rename incorrect json " + oldFile + " to " + nowFile);
|
||||
|
||||
File json = new File(nowFile, "pack.json");
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readFileToString(json), MinecraftVersion.class);
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.read(json), MinecraftVersion.class);
|
||||
if (mv.jar == null)
|
||||
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar"));
|
||||
|
||||
c.add(service.download().downloadMinecraftJar(mv, new File(nowFile, id + ".jar")));
|
||||
mv.jar = null;
|
||||
FileUtils.writeStringToFile(json, C.GSON.toJson(mv));
|
||||
FileUtils.write(json, C.GSON.toJson(mv));
|
||||
if (!json.renameTo(new File(nowFile, id + ".json")))
|
||||
HMCLog.warn("Failed to rename pack.json to new id");
|
||||
|
||||
|
@ -72,13 +72,6 @@ public abstract class IMinecraftProvider {
|
||||
*/
|
||||
public abstract boolean install(String version, Consumer<MinecraftVersion> callback);
|
||||
|
||||
/**
|
||||
* Returns the thing like ".minecraft/resourcepacks".
|
||||
*
|
||||
* @return the thing
|
||||
*/
|
||||
public abstract File getResourcePacks();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param v should be resolved
|
||||
@ -164,7 +157,7 @@ public abstract class IMinecraftProvider {
|
||||
*
|
||||
* @return if false, will break the launch process.
|
||||
*/
|
||||
public abstract boolean onLaunch();
|
||||
public abstract boolean onLaunch(String id);
|
||||
|
||||
public File baseDirectory() {
|
||||
return service.baseDirectory();
|
||||
|
@ -111,7 +111,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
}
|
||||
MinecraftVersion mcVersion;
|
||||
try {
|
||||
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null)
|
||||
throw new GameException("Wrong json format, got null.");
|
||||
} catch (Exception e) {
|
||||
@ -119,7 +119,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
service.download().downloadMinecraftVersionJson(id);
|
||||
try {
|
||||
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null)
|
||||
throw new GameException("Wrong json format, got null.");
|
||||
} catch (IOException | GameException | JsonSyntaxException ex) {
|
||||
@ -164,7 +164,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
public boolean renameVersion(String from, String to) {
|
||||
try {
|
||||
File fromJson = new File(versionRoot(from), from + ".json");
|
||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.readFileToString(fromJson), MinecraftVersion.class);
|
||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.read(fromJson), MinecraftVersion.class);
|
||||
mcVersion.id = to;
|
||||
FileUtils.writeQuietly(fromJson, C.GSON.toJson(mcVersion));
|
||||
File toDir = versionRoot(to);
|
||||
@ -198,7 +198,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
return false;
|
||||
if (callback != null) {
|
||||
File mvt = new File(versionRoot(id), id + ".json");
|
||||
MinecraftVersion v = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
|
||||
MinecraftVersion v = C.GSON.fromJson(FileUtils.readQuietly(mvt), MinecraftVersion.class);
|
||||
if (v == null)
|
||||
return false;
|
||||
callback.accept(v);
|
||||
@ -254,13 +254,8 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getResourcePacks() {
|
||||
return new File(service.baseDirectory(), "resourcepacks");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLaunch() {
|
||||
File resourcePacks = getResourcePacks();
|
||||
public boolean onLaunch(String id) {
|
||||
File resourcePacks = new File(getRunDirectory(id), "resourcepacks");
|
||||
if (!resourcePacks.exists() && !resourcePacks.mkdirs())
|
||||
HMCLog.warn("Failed to make resourcePacks: " + resourcePacks);
|
||||
return true;
|
||||
|
@ -46,7 +46,7 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public Profile(String name) {
|
||||
this(name, new File(IOUtils.currentDir(), ".minecraft").getPath());
|
||||
this(name, new File(".minecraft").getPath());
|
||||
}
|
||||
|
||||
public Profile(String name, String gameDir) {
|
||||
|
@ -30,7 +30,6 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
import org.jackhuang.hellominecraft.util.CollectionUtils;
|
||||
import org.jackhuang.hellominecraft.util.EventHandler;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.UpdateChecker;
|
||||
|
||||
@ -43,7 +42,7 @@ public final class Settings {
|
||||
public static final String DEFAULT_PROFILE = "Default";
|
||||
public static final String HOME_PROFILE = "Home";
|
||||
|
||||
public static final File SETTINGS_FILE = new File(IOUtils.currentDir(), "hmcl.json");
|
||||
public static final File SETTINGS_FILE = new File("hmcl.json");
|
||||
|
||||
private static final Config SETTINGS;
|
||||
public static final UpdateChecker UPDATE_CHECKER = new UpdateChecker(Main.getVersionNumber(), "hmcl");
|
||||
@ -71,7 +70,7 @@ public final class Settings {
|
||||
Config c = new Config();
|
||||
if (SETTINGS_FILE.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(SETTINGS_FILE);
|
||||
String str = FileUtils.read(SETTINGS_FILE);
|
||||
if (str == null || str.trim().equals(""))
|
||||
HMCLog.log("Settings file is empty, use the default settings.");
|
||||
else {
|
||||
|
@ -406,10 +406,6 @@
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="txtWrapperLauncher" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblPrecalledCommand1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="chkNoJVMArgs" min="-2" max="-2" attributes="0"/>
|
||||
@ -418,6 +414,7 @@
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblPrecalledCommand1" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblPrecalledCommand" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblServerIP" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
|
@ -61,7 +61,6 @@ import org.jackhuang.hellominecraft.util.system.OS;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.Java;
|
||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
||||
@ -1095,7 +1094,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
||||
|
||||
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
|
||||
JFileChooser fc = new JFileChooser(IOUtils.currentDir());
|
||||
JFileChooser fc = new JFileChooser(new File("."));
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
File newGameDir = fc.getSelectedFile();
|
||||
|
@ -109,7 +109,7 @@ public class LaunchingUIDaemon {
|
||||
}
|
||||
String msg = C.i18n("launch.exited_abnormally") + " exit code: " + t;
|
||||
if (errorText != null)
|
||||
msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readFileToStringQuietly(new File(errorText)));
|
||||
msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readQuietly(new File(errorText)));
|
||||
MessageBox.Show(msg);
|
||||
WebFrame f = new WebFrame(logs);
|
||||
f.setModal(true);
|
||||
|
@ -91,7 +91,7 @@ public class HMCLMinecraftService extends IMinecraftService {
|
||||
VersionSetting vs = null;
|
||||
File f = new File(provider.versionRoot(id), "hmclversion.cfg");
|
||||
if (f.exists()) {
|
||||
String s = FileUtils.readFileToStringQuietly(f);
|
||||
String s = FileUtils.readQuietly(f);
|
||||
if (s != null)
|
||||
try {
|
||||
vs = C.GSON.fromJson(s, VersionSetting.class);
|
||||
|
@ -81,7 +81,7 @@ public class AppDataUpgrader extends IUpgrader {
|
||||
try {
|
||||
File f = AppDataUpgraderTask.HMCL_VER_FILE;
|
||||
if (f.exists()) {
|
||||
Map<String, String> m = C.GSON.fromJson(FileUtils.readFileToString(f), Map.class);
|
||||
Map<String, String> m = C.GSON.fromJson(FileUtils.read(f), Map.class);
|
||||
String s = m.get("ver");
|
||||
if (s != null && VersionNumber.check(s).compareTo(nowVersion) > 0) {
|
||||
String j = m.get("loc");
|
||||
@ -179,7 +179,7 @@ public class AppDataUpgrader extends IUpgrader {
|
||||
json.put("ver", newestVersion);
|
||||
json.put("loc", f.getAbsolutePath());
|
||||
String result = C.GSON.toJson(json);
|
||||
FileUtils.writeStringToFile(HMCL_VER_FILE, result);
|
||||
FileUtils.write(HMCL_VER_FILE, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,8 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
@ -134,20 +135,10 @@ public class FileUtils {
|
||||
|
||||
public static void copyDirectory(File srcDir, File destDir)
|
||||
throws IOException {
|
||||
copyDirectory(srcDir, destDir, true);
|
||||
}
|
||||
|
||||
public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate)
|
||||
throws IOException {
|
||||
copyDirectory(srcDir, destDir, null, preserveFileDate);
|
||||
copyDirectory(srcDir, destDir, null);
|
||||
}
|
||||
|
||||
public static void copyDirectory(File srcDir, File destDir, FileFilter filter)
|
||||
throws IOException {
|
||||
copyDirectory(srcDir, destDir, filter, true);
|
||||
}
|
||||
|
||||
public static void copyDirectory(File srcDir, File destDir, FileFilter filter, boolean preserveFileDate)
|
||||
throws IOException {
|
||||
if (srcDir == null)
|
||||
throw new NullPointerException("Source must not be null");
|
||||
@ -171,10 +162,10 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
doCopyDirectory(srcDir, destDir, filter, preserveFileDate, exclusionList);
|
||||
doCopyDirectory(srcDir, destDir, filter, exclusionList);
|
||||
}
|
||||
|
||||
private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter, boolean preserveFileDate, List<String> exclusionList)
|
||||
private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter, List<String> exclusionList)
|
||||
throws IOException {
|
||||
File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
|
||||
if (srcFiles == null)
|
||||
@ -191,22 +182,19 @@ public class FileUtils {
|
||||
File dstFile = new File(destDir, srcFile.getName());
|
||||
if ((exclusionList == null) || (!exclusionList.contains(srcFile.getCanonicalPath())))
|
||||
if (srcFile.isDirectory())
|
||||
doCopyDirectory(srcFile, dstFile, filter, preserveFileDate, exclusionList);
|
||||
doCopyDirectory(srcFile, dstFile, filter, exclusionList);
|
||||
else
|
||||
doCopyFile(srcFile, dstFile, preserveFileDate);
|
||||
|
||||
doCopyFile(srcFile, dstFile);
|
||||
}
|
||||
|
||||
if (preserveFileDate)
|
||||
destDir.setLastModified(srcDir.lastModified());
|
||||
destDir.setLastModified(srcDir.lastModified());
|
||||
}
|
||||
|
||||
public static String readFileToString(File file)
|
||||
public static String read(File file)
|
||||
throws IOException {
|
||||
return NetUtils.getStreamContent(IOUtils.openInputStream(file));
|
||||
}
|
||||
|
||||
public static String readFileToStringQuietly(File file) {
|
||||
public static String readQuietly(File file) {
|
||||
try {
|
||||
return NetUtils.getStreamContent(IOUtils.openInputStream(file));
|
||||
} catch (IOException ex) {
|
||||
@ -215,12 +203,12 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String readFileToString(File file, String charset)
|
||||
public static String read(File file, String charset)
|
||||
throws IOException {
|
||||
return NetUtils.getStreamContent(IOUtils.openInputStream(file), charset);
|
||||
}
|
||||
|
||||
public static String readFileToStringIgnoreFileNotFound(File file) throws IOException {
|
||||
public static String readIgnoreFileNotFound(File file) throws IOException {
|
||||
try {
|
||||
return NetUtils.getStreamContent(IOUtils.openInputStream(file));
|
||||
} catch (FileNotFoundException ex) {
|
||||
@ -237,11 +225,6 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static void copyFile(File srcFile, File destFile)
|
||||
throws IOException {
|
||||
copyFile(srcFile, destFile, true);
|
||||
}
|
||||
|
||||
public static void copyFile(File srcFile, File destFile, boolean preserveFileDate)
|
||||
throws IOException {
|
||||
if (srcFile == null)
|
||||
throw new NullPointerException("Source must not be null");
|
||||
@ -260,42 +243,12 @@ public class FileUtils {
|
||||
|
||||
if ((destFile.exists()) && (!destFile.canWrite()))
|
||||
throw new IOException("Destination '" + destFile + "' exists but is read-only");
|
||||
doCopyFile(srcFile, destFile, preserveFileDate);
|
||||
doCopyFile(srcFile, destFile);
|
||||
}
|
||||
|
||||
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
|
||||
public static void doCopyFile(File srcFile, File destFile)
|
||||
throws IOException {
|
||||
if ((destFile.exists()) && (destFile.isDirectory()))
|
||||
throw new IOException("Destination '" + destFile + "' exists but is a directory");
|
||||
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
FileChannel input = null;
|
||||
FileChannel output = null;
|
||||
try {
|
||||
fis = new FileInputStream(srcFile);
|
||||
fos = new FileOutputStream(destFile);
|
||||
input = fis.getChannel();
|
||||
output = fos.getChannel();
|
||||
long size = input.size();
|
||||
long pos = 0L;
|
||||
long count;
|
||||
while (pos < size) {
|
||||
count = size - pos > 31457280L ? 31457280L : size - pos;
|
||||
pos += output.transferFrom(input, pos, count);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(output);
|
||||
IOUtils.closeQuietly(fos);
|
||||
IOUtils.closeQuietly(input);
|
||||
IOUtils.closeQuietly(fis);
|
||||
}
|
||||
|
||||
if (srcFile.length() != destFile.length())
|
||||
throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
|
||||
|
||||
if (preserveFileDate)
|
||||
destFile.setLastModified(srcFile.lastModified());
|
||||
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
public static int indexOfLastSeparator(String filename) {
|
||||
@ -350,9 +303,9 @@ public class FileUtils {
|
||||
return filename.substring(0, index);
|
||||
}
|
||||
|
||||
public static boolean writeQuietly(File file, CharSequence data) {
|
||||
public static boolean writeQuietly(File file, String data) {
|
||||
try {
|
||||
write(file, data);
|
||||
FileUtils.write(file, data);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to write data to file: " + file, e);
|
||||
@ -360,38 +313,17 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(File file, CharSequence data)
|
||||
public static void write(File file, String data)
|
||||
throws IOException {
|
||||
write(file, data, "UTF-8", false);
|
||||
}
|
||||
|
||||
public static void write(File file, CharSequence data, boolean append)
|
||||
throws IOException {
|
||||
write(file, data, "UTF-8", append);
|
||||
}
|
||||
|
||||
public static void write(File file, CharSequence data, String encoding)
|
||||
public static void write(File file, String data, String encoding)
|
||||
throws IOException {
|
||||
write(file, data, encoding, false);
|
||||
}
|
||||
|
||||
public static void write(File file, CharSequence data, String encoding, boolean append)
|
||||
throws IOException {
|
||||
String str = data == null ? null : data.toString();
|
||||
writeStringToFile(file, str, encoding, append);
|
||||
}
|
||||
|
||||
public static void writeStringToFile(File file, String data)
|
||||
throws IOException {
|
||||
writeStringToFile(file, data, "UTF-8", false);
|
||||
}
|
||||
|
||||
public static void writeStringToFile(File file, String data, String encoding)
|
||||
throws IOException {
|
||||
writeStringToFile(file, data, encoding, false);
|
||||
}
|
||||
|
||||
public static void writeStringToFile(File file, String data, String encoding, boolean append)
|
||||
public static void write(File file, String data, String encoding, boolean append)
|
||||
throws IOException {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
|
@ -27,8 +27,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.NetworkInterface;
|
||||
@ -37,6 +35,7 @@ import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
|
||||
/**
|
||||
@ -85,40 +84,24 @@ public class IOUtils {
|
||||
return t.substring(i + 1, (t.length() - i) + (i + 1) - 1);
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllFile(File f) {
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
public static void findAllFile(File f, Consumer<String> callback) {
|
||||
if (f.isDirectory()) {
|
||||
File[] f1 = f.listFiles();
|
||||
int len = f1.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (f1[i].isFile())
|
||||
arr.add(f1[i].getName());
|
||||
callback.accept(f1[i].getName());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllFileWithFullName(File f) {
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
if (f.isDirectory()) {
|
||||
File[] f1 = f.listFiles();
|
||||
int len = f1.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (f1[i].isFile())
|
||||
arr.add(addSeparator(f.getAbsolutePath()) + f1[i].getName());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllDir(File f) {
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
public static void findAllDir(File f, Consumer<String> callback) {
|
||||
if (f.isDirectory()) {
|
||||
File[] f1 = f.listFiles();
|
||||
int len = f1.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (f1[i].isDirectory())
|
||||
arr.add(f1[i].getName());
|
||||
callback.accept(f1[i].getName());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static String getRealPath() {
|
||||
@ -139,14 +122,6 @@ public class IOUtils {
|
||||
return path.startsWith("/") || path.indexOf(":") > 0;
|
||||
}
|
||||
|
||||
public static File currentDir() {
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
public static String currentDirWithSeparator() {
|
||||
return addSeparator(currentDir().getAbsolutePath());
|
||||
}
|
||||
|
||||
public static String getLocalMAC() {
|
||||
InetAddress addr;
|
||||
try {
|
||||
@ -221,22 +196,6 @@ public class IOUtils {
|
||||
return entryBuffer;
|
||||
}
|
||||
|
||||
public static void closeQuietly(Reader input) {
|
||||
closeQuietly((Closeable) input);
|
||||
}
|
||||
|
||||
public static void closeQuietly(Writer output) {
|
||||
closeQuietly((Closeable) output);
|
||||
}
|
||||
|
||||
public static void closeQuietly(InputStream input) {
|
||||
closeQuietly((Closeable) input);
|
||||
}
|
||||
|
||||
public static void closeQuietly(OutputStream output) {
|
||||
closeQuietly((Closeable) output);
|
||||
}
|
||||
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
try {
|
||||
if (closeable != null)
|
||||
|
@ -109,7 +109,7 @@ public enum OS {
|
||||
}
|
||||
|
||||
public static String getLinuxReleaseVersion() throws IOException {
|
||||
return FileUtils.readFileToString(new File("/etc/issue"));
|
||||
return FileUtils.read(new File("/etc/issue"));
|
||||
}
|
||||
|
||||
public static String getSystemVersion() {
|
||||
|
@ -20,12 +20,12 @@ package org.jackhuang.hellominecraft.svrmgr.server;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.system.Compressor;
|
||||
import org.jackhuang.hellominecraft.svrmgr.setting.SettingsManager;
|
||||
import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
|
||||
@ -39,9 +39,8 @@ public class BackupManager {
|
||||
return Utilities.getGameDir() + "backups-HMCSM" + File.separator;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getBackupList() {
|
||||
String gameDir = backupDir();
|
||||
return IOUtils.findAllFile(new File(gameDir));
|
||||
public static void getBackupList(Consumer<String> c) {
|
||||
IOUtils.findAllFile(new File(backupDir()), c);
|
||||
}
|
||||
|
||||
public static void addWorldBackup(final String folder) {
|
||||
@ -61,17 +60,15 @@ public class BackupManager {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllWorlds() {
|
||||
public static void findAllWorlds(Consumer<String> callback) {
|
||||
String gameDir = Utilities.getGameDir();
|
||||
ArrayList<String> folders = IOUtils.findAllDir(new File(gameDir));
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for (String folder : folders) {
|
||||
String worldPath = gameDir + folder + File.separator;
|
||||
ArrayList<String> files = IOUtils.findAllFile(new File(worldPath));
|
||||
if (files.contains("level.dat"))
|
||||
result.add(folder);
|
||||
}
|
||||
return result;
|
||||
IOUtils.findAllDir(new File(gameDir), folder -> {
|
||||
String worldPath = gameDir + folder + File.separator;
|
||||
IOUtils.findAllFile(new File(worldPath), f -> {
|
||||
if ("level.dat".equals(f))
|
||||
callback.accept(folder);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void restoreBackup(File backupFile) {
|
||||
@ -89,10 +86,10 @@ public class BackupManager {
|
||||
}
|
||||
|
||||
public static void backupAllWorlds() {
|
||||
ArrayList<String> al = findAllWorlds();
|
||||
for (String world : al)
|
||||
findAllWorlds(world -> {
|
||||
if (!SettingsManager.settings.inactiveWorlds.contains(world))
|
||||
addWorldBackup(world);
|
||||
});
|
||||
}
|
||||
|
||||
public static void backupAllPlugins() {
|
||||
|
@ -90,7 +90,7 @@ public abstract class PlayerList<T extends BasePlayer> {
|
||||
op = null;
|
||||
if (txt.exists())
|
||||
try {
|
||||
initByText(FileUtils.readFileToStringIgnoreFileNotFound(txt));
|
||||
initByText(FileUtils.readIgnoreFileNotFound(txt));
|
||||
if (op != null)
|
||||
player.addAll(op);
|
||||
} catch (IOException e) {
|
||||
|
@ -26,7 +26,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -37,13 +36,13 @@ public class SettingsManager {
|
||||
public static Settings settings;
|
||||
public static boolean isFirstLoad = false;
|
||||
static Gson gson;
|
||||
private static final File file = new File("hmcsm.json");
|
||||
|
||||
public static void load() {
|
||||
gson = new Gson();
|
||||
File file = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
if (file.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(file);
|
||||
String str = FileUtils.read(file);
|
||||
if (str == null || str.trim().equals(""))
|
||||
init();
|
||||
else
|
||||
@ -64,9 +63,8 @@ public class SettingsManager {
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
File f = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
try {
|
||||
FileUtils.write(f, gson.toJson(settings));
|
||||
FileUtils.write(file, gson.toJson(settings));
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Failed to save settings.", ex);
|
||||
}
|
||||
|
@ -2781,13 +2781,12 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
String path = Utilities.getPath("mods");
|
||||
if (path == null)
|
||||
return;
|
||||
ArrayList<String> sl = IOUtils.findAllFile(new File(path));
|
||||
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
for (String s : sl)
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactiveExtMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(IOUtils.addSeparator(path) + s)) });
|
||||
|
||||
IOUtils.findAllFile(new File(path), s
|
||||
-> model.addRow(new Object[] { !SettingsManager.settings.inactiveExtMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(IOUtils.addSeparator(path) + s)) })
|
||||
);
|
||||
lstExternalMods.updateUI();
|
||||
}
|
||||
|
||||
@ -2795,19 +2794,18 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
String path = Utilities.getPath("plugins");
|
||||
if (path == null)
|
||||
return;
|
||||
ArrayList<String> sl = IOUtils.findAllFile(new File(path));
|
||||
DefaultTableModel model = (DefaultTableModel) lstPlugins.getModel();
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
for (String s : sl) {
|
||||
PluginInformation p = PluginManager.getPluginYML(new File(Utilities.getGameDir() + "plugins" + File.separator + s));
|
||||
if (p == null)
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactivePlugins.contains(s), s,
|
||||
"", "", "", "" });
|
||||
else
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactivePlugins.contains(s), s,
|
||||
p.name, p.version, p.author, p.description });
|
||||
}
|
||||
IOUtils.findAllFile(new File(path), s -> {
|
||||
PluginInformation p = PluginManager.getPluginYML(new File(Utilities.getGameDir() + "plugins" + File.separator + s));
|
||||
if (p == null)
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactivePlugins.contains(s), s,
|
||||
"", "", "", "" });
|
||||
else
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactivePlugins.contains(s), s,
|
||||
p.name, p.version, p.author, p.description });
|
||||
});
|
||||
|
||||
lstPlugins.updateUI();
|
||||
}
|
||||
@ -2816,37 +2814,35 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
String path = Utilities.getPath("coremods");
|
||||
if (path == null)
|
||||
return;
|
||||
ArrayList<String> sl = IOUtils.findAllFile(new File(path));
|
||||
DefaultTableModel model = (DefaultTableModel) lstCoreMods.getModel();
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
for (String s : sl)
|
||||
model.addRow(new Object[] { !SettingsManager.settings.inactiveCoreMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(IOUtils.addSeparator(path) + s)) });
|
||||
IOUtils.findAllFile(new File(path), s
|
||||
-> model.addRow(new Object[] { !SettingsManager.settings.inactiveCoreMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(IOUtils.addSeparator(path) + s)) }));
|
||||
|
||||
lstCoreMods.updateUI();
|
||||
}
|
||||
|
||||
void loadWorlds() {
|
||||
ArrayList<String> s = BackupManager.findAllWorlds();
|
||||
DefaultTableModel model = (DefaultTableModel) lstWorlds.getModel();
|
||||
if (SettingsManager.settings.inactiveWorlds == null)
|
||||
SettingsManager.settings.inactiveWorlds = new ArrayList<>();
|
||||
for (String world : s)
|
||||
BackupManager.findAllWorlds(world -> {
|
||||
model.addRow(new Object[] {
|
||||
world, Utilities.getGameDir() + world, !SettingsManager.settings.inactiveWorlds.contains(world)
|
||||
});
|
||||
});
|
||||
lstWorlds.updateUI();
|
||||
}
|
||||
|
||||
void loadBackups() {
|
||||
ArrayList<String> al = BackupManager.getBackupList();
|
||||
DefaultTableModel model = (DefaultTableModel) lstBackups.getModel();
|
||||
for (String backup : al) {
|
||||
BackupManager.getBackupList(backup -> {
|
||||
String[] names = FileUtils.getExtension(backup).split("\\+");
|
||||
model.addRow(new Object[] {
|
||||
names[0], names[1], names[2]
|
||||
});
|
||||
}
|
||||
});
|
||||
lstBackups.updateUI();
|
||||
}
|
||||
|
||||
@ -3007,17 +3003,16 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
}
|
||||
|
||||
void refreshInfos() {
|
||||
ArrayList<String> al = IOUtils.findAllFile(new File(Utilities.getGameDir() + "infos-HMCSM"));
|
||||
DefaultTableModel model = (DefaultTableModel) lstInfos.getModel();
|
||||
for (String s : al)
|
||||
model.addRow(new Object[] { s, FileUtils.getExtension(s) });
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
IOUtils.findAllFile(new File(Utilities.getGameDir() + "infos-HMCSM"), s -> model.addRow(new Object[] { s, FileUtils.getExtension(s) }));
|
||||
lstInfos.updateUI();
|
||||
}
|
||||
|
||||
void refreshReports() {
|
||||
ArrayList<String> al = IOUtils.findAllFile(new File(Utilities.getGameDir() + "crash-reports"));
|
||||
for (String s : al)
|
||||
lstCrashReportsModel.addElement(s);
|
||||
lstCrashReportsModel.clear();
|
||||
IOUtils.findAllFile(new File(Utilities.getGameDir() + "crash-reports"), s -> lstCrashReportsModel.addElement(s));
|
||||
lstReports.setModel(lstCrashReportsModel);
|
||||
}
|
||||
|
||||
@ -3721,7 +3716,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
|
||||
final String MC_DOWNLOAD_URL = "https://s3.amazonaws.com/Minecraft.Download/versions/";
|
||||
String url = MC_DOWNLOAD_URL + id + "/";
|
||||
File serverjar = new File(IOUtils.currentDir(), "minecraft_server." + id + ".jar");
|
||||
File serverjar = new File("minecraft_server." + id + ".jar");
|
||||
serverjar.delete();
|
||||
|
||||
String downloadURL = url + "minecraft_server." + id + ".jar";
|
||||
@ -3739,7 +3734,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
if (index == -1)
|
||||
return;
|
||||
String path = Utilities.getGameDir() + "infos-HMCSM" + File.separator + model.getValueAt(index, 0);
|
||||
String content = FileUtils.readFileToString(new File(path));
|
||||
String content = FileUtils.read(new File(path));
|
||||
txtInfo.setText(content);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to read info.", ex);
|
||||
@ -3747,14 +3742,14 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
}//GEN-LAST:event_btnShowInfoActionPerformed
|
||||
|
||||
private void btnAutoSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSearchActionPerformed
|
||||
ArrayList<String> al = IOUtils.findAllFile(IOUtils.currentDir());
|
||||
for (String s : al)
|
||||
if (ServerChecker.isServerJar(new File(s))) {
|
||||
String path = IOUtils.tryGetCanonicalFilePath(new File(IOUtils.currentDir(), s));
|
||||
txtMainJar.setText(path);
|
||||
SettingsManager.settings.mainjar = path;
|
||||
SettingsManager.save();
|
||||
}
|
||||
IOUtils.findAllFile(new File("."), s -> {
|
||||
if (ServerChecker.isServerJar(new File(s))) {
|
||||
String path = IOUtils.tryGetCanonicalFilePath(new File(s));
|
||||
txtMainJar.setText(path);
|
||||
SettingsManager.settings.mainjar = path;
|
||||
SettingsManager.save();
|
||||
}
|
||||
});
|
||||
}//GEN-LAST:event_btnAutoSearchActionPerformed
|
||||
|
||||
private void cboCategoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCategoryItemStateChanged
|
||||
@ -3784,7 +3779,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
if (index == -1)
|
||||
return;
|
||||
String path = Utilities.getGameDir() + "crash-reports" + File.separator + lstCrashReportsModel.get(index);
|
||||
String content = FileUtils.readFileToString(new File(path));
|
||||
String content = FileUtils.read(new File(path));
|
||||
txtCrashReport.setText(content);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to get crash-report.", ex);
|
||||
@ -3858,7 +3853,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
return;
|
||||
}
|
||||
BukkitVersion v = cb.get(idx);
|
||||
File file = new File(IOUtils.currentDir(), "craftbukkit-" + ext + "-" + v.version + ".jar");
|
||||
File file = new File("craftbukkit-" + ext + "-" + v.version + ".jar");
|
||||
TaskWindow.factory().append(new FileDownloadTask(v.downloadLink, IOUtils.tryGetCanonicalFile(file)).setTag("bukkit-" + ext + "-" + v.version))
|
||||
.create();
|
||||
}//GEN-LAST:event_btnDownloadCraftbukkitActionPerformed
|
||||
@ -3869,7 +3864,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
return;
|
||||
ForgeVersion v = mcpcPackages.get(cboCauldronMinecraft.getSelectedItem().toString()).get(idx);
|
||||
String url;
|
||||
File filepath = new File(IOUtils.currentDir(), "forge-installer.jar");
|
||||
File filepath = new File("forge-installer.jar");
|
||||
url = v.installer[1];
|
||||
if (!TaskWindow.factory().append(new FileDownloadTask(url, filepath).setTag("cauldron-" + v.ver)).create())
|
||||
MessageBox.Show(C.i18n("install.failed_download_forge"));
|
||||
@ -3879,7 +3874,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
|
||||
private void installMCPC(final File filepath) {
|
||||
try {
|
||||
ForgeInstaller installer = new ForgeInstaller(IOUtils.currentDir(), filepath);
|
||||
ForgeInstaller installer = new ForgeInstaller(new File("."), filepath);
|
||||
installer.install();
|
||||
MessageBox.Show(C.i18n("install.success"));
|
||||
} catch (Exception e) {
|
||||
@ -3910,7 +3905,7 @@ public final class MainWindow extends javax.swing.JFrame
|
||||
}//GEN-LAST:event_cboCauldronMinecraftItemStateChanged
|
||||
|
||||
private void btnInstallMCPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstallMCPCActionPerformed
|
||||
File filepath = new File(IOUtils.currentDir(), "forge-installer.jar");
|
||||
File filepath = new File("forge-installer.jar");
|
||||
if (!filepath.exists()) {
|
||||
MessageBox.Show("您还未下载Cauldron!请点击下载按钮下载并自动安装!");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user