Start moving Pojav modules outside of the game directory

This commit is contained in:
ArtDev 2021-02-07 18:15:16 +03:00 committed by khanhduytran0
parent 7b99b423e5
commit 9e14381b32
8 changed files with 35 additions and 33 deletions

View file

@ -120,7 +120,7 @@ public class BaseMainActivity extends LoggableActivity {
// FIXME: is it safe fot multi thread? // FIXME: is it safe fot multi thread?
GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
logFile = new File(Tools.DIR_GAME_NEW, "latestlog.txt"); logFile = new File(Tools.DIR_GAME_HOME, "latestlog.txt");
logFile.delete(); logFile.delete();
logFile.createNewFile(); logFile.createNewFile();
logStream = new PrintStream(logFile.getAbsolutePath()); logStream = new PrintStream(logFile.getAbsolutePath());
@ -931,7 +931,7 @@ public class BaseMainActivity extends LoggableActivity {
} }
private void checkLWJGL3Installed() { private void checkLWJGL3Installed() {
File lwjgl3dir = new File(Tools.DIR_GAME_NEW, "lwjgl3"); File lwjgl3dir = new File(Tools.DIR_GAME_HOME, "lwjgl3");
if (!lwjgl3dir.exists() || lwjgl3dir.isFile() || lwjgl3dir.list().length == 0) { if (!lwjgl3dir.exists() || lwjgl3dir.isFile() || lwjgl3dir.list().length == 0) {
appendlnToLog("Error: LWJGL3 was not installed!"); appendlnToLog("Error: LWJGL3 was not installed!");
throw new RuntimeException(getString(R.string.mcn_check_fail_lwjgl)); throw new RuntimeException(getString(R.string.mcn_check_fail_lwjgl));

View file

@ -164,7 +164,7 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2); placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2);
logFile = new File(Tools.DIR_GAME_NEW, "latestlog.txt"); logFile = new File(Tools.DIR_GAME_HOME, "latestlog.txt");
logFile.delete(); logFile.delete();
logFile.createNewFile(); logFile.createNewFile();
logStream = new PrintStream(logFile.getAbsolutePath()); logStream = new PrintStream(logFile.getAbsolutePath());

View file

@ -24,7 +24,7 @@ public class PojavApplication extends Application
@Override @Override
public void uncaughtException(Thread thread, Throwable th) { public void uncaughtException(Thread thread, Throwable th) {
boolean storagePermAllowed = Build.VERSION.SDK_INT < 23 || ActivityCompat.checkSelfPermission(PojavApplication.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; boolean storagePermAllowed = Build.VERSION.SDK_INT < 23 || ActivityCompat.checkSelfPermission(PojavApplication.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
File crashFile = new File(storagePermAllowed ? Tools.DIR_GAME_NEW : Tools.DIR_DATA, "latestcrash.txt"); File crashFile = new File(storagePermAllowed ? Tools.DIR_GAME_HOME : Tools.DIR_DATA, "latestcrash.txt");
try { try {
// Write to file, since some devices may not able to show error // Write to file, since some devices may not able to show error
crashFile.getParentFile().mkdirs(); crashFile.getParentFile().mkdirs();

View file

@ -326,7 +326,7 @@ public class PojavLoginActivity extends BaseActivity
} }
private void unpackComponent(AssetManager am, String component) throws IOException { private void unpackComponent(AssetManager am, String component) throws IOException {
File versionFile = new File(Tools.DIR_GAME_NEW + "/" + component + "/version"); File versionFile = new File(Tools.DIR_GAME_HOME + "/" + component + "/version");
InputStream is = am.open("components/" + component + "/version"); InputStream is = am.open("components/" + component + "/version");
if(!versionFile.exists()) { if(!versionFile.exists()) {
if (versionFile.getParentFile().exists() && versionFile.getParentFile().isDirectory()) { if (versionFile.getParentFile().exists() && versionFile.getParentFile().isDirectory()) {
@ -337,7 +337,7 @@ public class PojavLoginActivity extends BaseActivity
Log.i("UnpackPrep", component + ": Pack was installed manually, or does not exist, unpacking new..."); Log.i("UnpackPrep", component + ": Pack was installed manually, or does not exist, unpacking new...");
String[] fileList = am.list("components/" + component); String[] fileList = am.list("components/" + component);
for(String s : fileList) { for(String s : fileList) {
Tools.copyAssetFile(this, "components/" + component + "/" + s, Tools.DIR_GAME_NEW + "/" + component, true); Tools.copyAssetFile(this, "components/" + component + "/" + s, Tools.DIR_GAME_HOME + "/" + component, true);
} }
} else { } else {
FileInputStream fis = new FileInputStream(versionFile); FileInputStream fis = new FileInputStream(versionFile);
@ -351,28 +351,15 @@ public class PojavLoginActivity extends BaseActivity
String[] fileList = am.list("components/" + component); String[] fileList = am.list("components/" + component);
for (String s : fileList) { for (String s : fileList) {
Tools.copyAssetFile(this, "components/" + component + "/" + s, Tools.DIR_GAME_NEW + "/" + component, true); Tools.copyAssetFile(this, "components/" + component + "/" + s, Tools.DIR_GAME_HOME + "/" + component, true);
} }
} else { } else {
Log.i("UnpackPrep", component + ": Pack is up-to-date with the launcher, continuing..."); Log.i("UnpackPrep", component + ": Pack is up-to-date with the launcher, continuing...");
} }
} }
} }
public static void disableSplash() {
private void initMain() throws Throwable { mkdirs(Tools.DIR_GAME_NEW + "/config");
mkdirs(Tools.DIR_ACCOUNT_NEW);
PojavMigrator.migrateAccountData(this);
mkdirs(Tools.DIR_GAME_HOME);
if (!PojavMigrator.migrateGameDir()) {
mkdirs(Tools.DIR_GAME_NEW);
mkdirs(Tools.DIR_GAME_NEW + "/config");
mkdirs(Tools.DIR_GAME_NEW + "/lwjgl3");
mkdirs(Tools.DIR_GAME_NEW + "/mods");
mkdirs(Tools.DIR_HOME_VERSION);
mkdirs(Tools.DIR_HOME_LIBRARY);
}
File forgeSplashFile = new File(Tools.DIR_GAME_NEW, "config/splash.properties"); File forgeSplashFile = new File(Tools.DIR_GAME_NEW, "config/splash.properties");
String forgeSplashContent = "enabled=true"; String forgeSplashContent = "enabled=true";
try { try {
@ -381,12 +368,26 @@ public class PojavLoginActivity extends BaseActivity
} }
if (forgeSplashContent.contains("enabled=true")) { if (forgeSplashContent.contains("enabled=true")) {
Tools.write(forgeSplashFile.getAbsolutePath(), Tools.write(forgeSplashFile.getAbsolutePath(),
forgeSplashContent.replace("enabled=true", "enabled=false")); forgeSplashContent.replace("enabled=true", "enabled=false"));
} }
} catch (IOException e) { } catch (IOException e) {
Log.w(Tools.APP_NAME, "Could not disable Forge 1.12.2 and below splash screen!", e); Log.w(Tools.APP_NAME, "Could not disable Forge 1.12.2 and below splash screen!", e);
} }
}
private void initMain() throws Throwable {
mkdirs(Tools.DIR_ACCOUNT_NEW);
PojavMigrator.migrateAccountData(this);
mkdirs(Tools.DIR_GAME_HOME);
mkdirs(Tools.DIR_GAME_HOME + "/lwjgl3");
mkdirs(Tools.DIR_GAME_HOME + "/config");
if (!PojavMigrator.migrateGameDir()) {
mkdirs(Tools.DIR_GAME_NEW);
mkdirs(Tools.DIR_GAME_NEW + "/mods");
mkdirs(Tools.DIR_HOME_VERSION);
mkdirs(Tools.DIR_HOME_LIBRARY);
}
mkdirs(Tools.CTRLMAP_PATH); mkdirs(Tools.CTRLMAP_PATH);
try { try {
@ -601,7 +602,7 @@ public class PojavLoginActivity extends BaseActivity
tarIn.close(); tarIn.close();
} }
private boolean mkdirs(String path) private static boolean mkdirs(String path)
{ {
File file = new File(path); File file = new File(path);
// check necessary??? // check necessary???

View file

@ -49,16 +49,16 @@ public class PojavMigrator
} }
return moved; return moved;
} }
/*
public static boolean migrateBugFix20201217() throws IOException, InterruptedException { public static boolean migrateBugFix20201217() throws IOException, InterruptedException {
File bugGameDir = new File(Tools.DIR_GAME_NEW + "/.minecraft"); File bugGameDir = new File(Tools.DIR_GAME_NEW + "/.minecraft");
File oldGameDir = new File(Tools.DIR_GAME_OLD); File oldGameDir = new File(Tools.DIR_GAME_OLD);
boolean moved = bugGameDir.exists() && bugGameDir.isDirectory(); boolean moved = bugGameDir.exists() && bugGameDir.isDirectory();
/*
if (oldGameDir.exists() && oldGameDir.isDirectory() && moved) { if (oldGameDir.exists() && oldGameDir.isDirectory() && moved) {
command("rm -rf " + oldGameDir.getAbsolutePath()); command("rm -rf " + oldGameDir.getAbsolutePath());
} }
*/
if (moved) { if (moved) {
command("mv " + bugGameDir.getAbsolutePath() + " " + Tools.DIR_GAME_OLD); command("mv " + bugGameDir.getAbsolutePath() + " " + Tools.DIR_GAME_OLD);
command("rm -rf " + Tools.DIR_GAME_HOME + "/*"); command("rm -rf " + Tools.DIR_GAME_HOME + "/*");
@ -67,7 +67,7 @@ public class PojavMigrator
return moved; return moved;
} }
*/
private static void command(String cmd) throws IOException, InterruptedException { private static void command(String cmd) throws IOException, InterruptedException {
Process p = Runtime.getRuntime().exec(cmd); Process p = Runtime.getRuntime().exec(cmd);
int exitCode = p.waitFor(); int exitCode = p.waitFor();

View file

@ -59,8 +59,8 @@ public final class Tools
public static final String ASSETS_PATH = DIR_GAME_NEW + "/assets"; public static final String ASSETS_PATH = DIR_GAME_NEW + "/assets";
public static final String OBSOLETE_RESOURCES_PATH= DIR_GAME_NEW + "/resources"; public static final String OBSOLETE_RESOURCES_PATH= DIR_GAME_NEW + "/resources";
public static final String CTRLMAP_PATH = DIR_GAME_NEW + "/controlmap"; public static final String CTRLMAP_PATH = DIR_GAME_HOME + "/controlmap";
public static final String CTRLDEF_FILE = DIR_GAME_NEW + "/controlmap/default.json"; public static final String CTRLDEF_FILE = DIR_GAME_HOME + "/controlmap/default.json";
public static final String LIBNAME_OPTIFINE = "optifine:OptiFine"; public static final String LIBNAME_OPTIFINE = "optifine:OptiFine";
@ -113,7 +113,7 @@ public final class Tools
StringBuilder cacioClasspath = new StringBuilder(); StringBuilder cacioClasspath = new StringBuilder();
cacioClasspath.append("-Xbootclasspath/p"); cacioClasspath.append("-Xbootclasspath/p");
File cacioDir = new File(DIR_GAME_NEW + "/caciocavallo"); File cacioDir = new File(DIR_GAME_HOME + "/caciocavallo");
if (cacioDir.exists() && cacioDir.isDirectory()) { if (cacioDir.exists() && cacioDir.isDirectory()) {
for (File file : cacioDir.listFiles()) { for (File file : cacioDir.listFiles()) {
if (file.getName().endsWith(".jar")) { if (file.getName().endsWith(".jar")) {
@ -270,7 +270,7 @@ public final class Tools
private static String getLWJGL3ClassPath() { private static String getLWJGL3ClassPath() {
StringBuilder libStr = new StringBuilder(); StringBuilder libStr = new StringBuilder();
File lwjgl3Folder = new File(Tools.DIR_GAME_NEW, "lwjgl3"); File lwjgl3Folder = new File(Tools.DIR_GAME_HOME, "lwjgl3");
if (/* info.arguments != null && */ lwjgl3Folder.exists()) { if (/* info.arguments != null && */ lwjgl3Folder.exists()) {
for (File file: lwjgl3Folder.listFiles()) { for (File file: lwjgl3Folder.listFiles()) {
if (file.getName().endsWith(".jar")) { if (file.getName().endsWith(".jar")) {

View file

@ -259,6 +259,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
jvmArgs.add("-Xms128M"); jvmArgs.add("-Xms128M");
jvmArgs.add("-Xmx1G"); jvmArgs.add("-Xmx1G");
*/ */
PojavLoginActivity.disableSplash();
Intent mainIntent = new Intent(mActivity, MainActivity.class /* MainActivity.class */); Intent mainIntent = new Intent(mActivity, MainActivity.class /* MainActivity.class */);
// mainIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); // mainIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

View file

@ -227,7 +227,7 @@ public class JREUtils
envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth)); envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth));
envMap.put("AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight > 0 ? CallbackBridge.windowHeight : CallbackBridge.physicalHeight)); envMap.put("AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight > 0 ? CallbackBridge.windowHeight : CallbackBridge.physicalHeight));
File customEnvFile = new File(Tools.DIR_GAME_NEW, "custom_env.txt"); File customEnvFile = new File(Tools.DIR_GAME_HOME, "custom_env.txt");
if (customEnvFile.exists() && customEnvFile.isFile()) { if (customEnvFile.exists() && customEnvFile.isFile()) {
BufferedReader reader = new BufferedReader(new FileReader(customEnvFile)); BufferedReader reader = new BufferedReader(new FileReader(customEnvFile));
String line; String line;