From a896ffb273dc1f8e74a15174d900217db0d13fa9 Mon Sep 17 00:00:00 2001 From: Boulay Mathias Date: Mon, 31 Oct 2022 20:12:03 +0100 Subject: [PATCH] Refactor: Remove old migrators They are now not needed, partially due to google policy regarding storage --- .../java/net/kdt/pojavlaunch/MCProfile.java | 143 ------------------ .../kdt/pojavlaunch/PojavLoginActivity.java | 7 - .../net/kdt/pojavlaunch/PojavMigrator.java | 60 -------- 3 files changed, 210 deletions(-) delete mode 100644 app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java delete mode 100644 app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavMigrator.java diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java deleted file mode 100644 index 54fd88758..000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MCProfile.java +++ /dev/null @@ -1,143 +0,0 @@ -package net.kdt.pojavlaunch; - -import java.io.*;; - -/** - * This account data format is deprecated. - * The current account data format is JSON on net.kdt.pojavlaunch.value.MinecraftAccount. - * This class remain for account data migrator only. - * Methods for saving/exporting on this format are no longer available. - */ -@Deprecated -public class MCProfile -{ - private static String[] emptyBuilder = new String[]{ - "1.9", //Version - "ProfileIDEmpty", - "AccessToken", - "AccessTokenEmpty", - "Steve" - }; - - public static MCProfile.Builder load(String pofFilePath) { - try { - String pofContent = Tools.read(pofFilePath); - return parse(pofContent); - } catch (Exception e) { - throw new RuntimeException("Unable to load Profile " + pofFilePath, e); - } - } - - public static MCProfile.Builder parse(String content) { - if (content == null || content.isEmpty()) { - return null; - } - - MCProfile.Builder builder = new MCProfile.Builder(); - - String[] profileInfos = content.split(":"); - - String cltk = profileInfos[0]; - String prtk = profileInfos[1]; - String acct = profileInfos[2]; - String name = profileInfos[3]; - String vers = profileInfos[4]; - String isAc = profileInfos[5]; - - //System.out.println("parse THE VER = " + vers); - - builder.setClientID(cltk); - builder.setProfileID(prtk); - builder.setAccessToken(acct); - builder.setUsername(name); - builder.setVersion(vers); - builder.setIsMojangAccount(Boolean.parseBoolean(isAc)); - - return builder; - } - - public static MCProfile.Builder loadSafety(String pofFilePath) { - try { - return load(pofFilePath); - } catch (Exception e) { - e.printStackTrace(); - - // return new MCProfile.Builder(); - return null; - } - } - - public static class Builder implements Serializable - { - private String[] fullArgs = new String[6]; - private boolean isMojangAccount = true; - - public Builder() - { - fullArgs = emptyBuilder; - setClientID("0"); - setProfileID("00000000-0000-0000-0000-000000000000"); - setAccessToken("0"); - } - - public boolean isMojangAccount() - { - return isMojangAccount; - } - - public String getVersion() - { - return fullArgs[0]; - } - - public String getClientID() - { - return fullArgs[1]; - } - - public String getProfileID() - { - return fullArgs[2]; - } - - public String getAccessToken() - { - return fullArgs[3]; - } - - public String getUsername() - { - return fullArgs[4]; - } - - public void setIsMojangAccount(boolean value) - { - isMojangAccount = value; - } - - public void setVersion(String value) - { - fullArgs[0] = value; - } - - public void setClientID(String value) - { - fullArgs[1] = value; - } - - public void setProfileID(String value) - { - fullArgs[2] = value; - } - - public void setAccessToken(String value) - { - fullArgs[3] = value; - } - - public void setUsername(String value) - { - fullArgs[4] = value; - } - } -} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java index f1eecd1f0..4f975f667 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -315,17 +315,10 @@ public class PojavLoginActivity extends BaseActivity { } 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); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavMigrator.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavMigrator.java deleted file mode 100644 index ed4082e7b..000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavMigrator.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.kdt.pojavlaunch; -import android.content.*; -import java.io.*; -import net.kdt.pojavlaunch.value.*; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; - -public class PojavMigrator { - public static void migrateAccountData(Context ctx) { - File oldAccDir = new File(Tools.DIR_ACCOUNT_OLD); - if (oldAccDir.exists() && oldAccDir.isDirectory()) { - for (String account : oldAccDir.list()) { - File oldAccFile = new File(oldAccDir, account); - - try { - MCProfile.Builder oldAccStruct = MCProfile.load(oldAccFile.getAbsolutePath()); - - MinecraftAccount newAccStruct = new MinecraftAccount(); - newAccStruct.accessToken = oldAccStruct.getAccessToken(); - newAccStruct.clientToken = oldAccStruct.getClientID(); - newAccStruct.isMicrosoft = false; - newAccStruct.profileId = oldAccStruct.getProfileID(); - newAccStruct.selectedVersion = oldAccStruct.getVersion(); - newAccStruct.username = oldAccStruct.getUsername(); - newAccStruct.save(); - } catch (IOException e) { - Tools.showError(ctx, e); - } - - oldAccFile.delete(); - } - } - } - - public static boolean migrateGameDir() throws IOException { - File oldGameDir = new File(Tools.DIR_GAME_OLD); - - boolean moved = oldGameDir.exists() && oldGameDir.isDirectory(); - /* - if (!migrateBugFix20201217() && moved) { - command("mv " + Tools.DIR_GAME_OLD + " " + Tools.DIR_GAME_HOME + "/"); - } - */ - if(moved) { - oldGameDir.renameTo(new File(Tools.DIR_GAME_NEW + "/")); - FileUtils.deleteDirectory(new File(Tools.DIR_GAME_NEW + "/lwjgl3")); - } - return moved; - } - - private static void command(String cmd) throws IOException, InterruptedException { - Process p = Runtime.getRuntime().exec(cmd); - int exitCode = p.waitFor(); - if (exitCode != 0) { - throw new IOException("Exit code " + exitCode + - ", message:\n" + Tools.read(p.getErrorStream())); - } - } -}