diff --git a/.gitignore b/.gitignore index 603b1407..044357bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.iml +.idea .gradle /local.properties /.idea/caches diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d8d2213c..8bf5682e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ (this); //使用语言管理器切换语言 @@ -169,6 +173,13 @@ private void setMCinaBoxNoMedia() { } } + // 为了兼容旧版本的AndroidSDK做的一些妥协 + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + FileSelectUtils.getCallback().onResult(requestCode, resultCode, data); + } + /** * 【移除缓存文件夹】 **/ diff --git a/app/src/main/java/com/aof/mcinabox/launcher/download/support/UrlSource.java b/app/src/main/java/com/aof/mcinabox/launcher/download/support/UrlSource.java index 931ed2af..8fbcd829 100644 --- a/app/src/main/java/com/aof/mcinabox/launcher/download/support/UrlSource.java +++ b/app/src/main/java/com/aof/mcinabox/launcher/download/support/UrlSource.java @@ -75,6 +75,9 @@ private void initSourceMap(String[][] originMap) { } public String getSourceUrl(String sourceName, String type) { + if (sourceName.equals("origin")) { + return Objects.requireNonNull(SourceMap.get("official")).get(type); + } return Objects.requireNonNull(SourceMap.get(sourceName)).get(type); } diff --git a/app/src/main/java/com/aof/mcinabox/launcher/gamedir/GamedirManager.java b/app/src/main/java/com/aof/mcinabox/launcher/gamedir/GamedirManager.java index 4304752d..5bcc3def 100644 --- a/app/src/main/java/com/aof/mcinabox/launcher/gamedir/GamedirManager.java +++ b/app/src/main/java/com/aof/mcinabox/launcher/gamedir/GamedirManager.java @@ -12,7 +12,7 @@ public class GamedirManager { private final static String TAG = "GamedirManager"; - public final static String PUBLIC_GAMEDIR = SettingJson.DEFAULT_GAMEDIR; + public static String PUBLIC_GAMEDIR = SettingJson.getDEFAULT_GAMEDIR(); public final static String PRIVATE_GAMEDIR = AppManifest.MCINABOX_HOME + "/gamedir"; public static boolean setGamedir(Context context, SettingJson setting, String gamedir) { diff --git a/app/src/main/java/com/aof/mcinabox/launcher/setting/support/SettingJson.java b/app/src/main/java/com/aof/mcinabox/launcher/setting/support/SettingJson.java index 462e66be..e0bdd9d3 100644 --- a/app/src/main/java/com/aof/mcinabox/launcher/setting/support/SettingJson.java +++ b/app/src/main/java/com/aof/mcinabox/launcher/setting/support/SettingJson.java @@ -1,6 +1,6 @@ package com.aof.mcinabox.launcher.setting.support; -import android.os.Environment; +import android.content.Context; public class SettingJson { @@ -8,12 +8,13 @@ public class SettingJson { public final static String USER_TYPE_ONLINE = "online"; public final static String USER_TYPE_EXTERNAL = "external"; + public final static String DOWNLOAD_SOURCE_ORIGIN = "official"; public final static String DOWNLOAD_SOURCE_OFFICIAL = "official"; public final static String DOWNLOAD_SOURCE_BMCLAPI = "bmclapi"; public final static String DOWNLOAD_SOURCE_MCBBS = "mcbbs"; - public final static String[] DOWNLOAD_SOURCES = {DOWNLOAD_SOURCE_OFFICIAL, DOWNLOAD_SOURCE_BMCLAPI, DOWNLOAD_SOURCE_MCBBS}; + public final static String[] DOWNLOAD_SOURCES = {DOWNLOAD_SOURCE_ORIGIN, DOWNLOAD_SOURCE_OFFICIAL, DOWNLOAD_SOURCE_BMCLAPI, DOWNLOAD_SOURCE_MCBBS}; - public final static String DEFAULT_GAMEDIR = Environment.getExternalStorageDirectory().getPath() + "/MCinaBox/gamedir"; + public static String DEFAULT_GAMEDIR; private String downloadType; //下载源 private Configurations configurations; //全局游戏设置 @@ -27,9 +28,9 @@ public SettingJson() { //默认模板初始化 super(); - downloadType = DOWNLOAD_SOURCE_OFFICIAL; + downloadType = DOWNLOAD_SOURCE_ORIGIN; lastVersion = ""; - gamedir = DEFAULT_GAMEDIR; + gamedir = getDEFAULT_GAMEDIR(); configurations = new Configurations() .setJavaArgs("") @@ -41,6 +42,17 @@ public SettingJson() { accounts = new Account[]{}; } + public static void initStaticConfig(Context mContext) { + if (SettingJson.DEFAULT_GAMEDIR == null) { + SettingJson.DEFAULT_GAMEDIR = mContext.getExternalCacheDir().getPath() + "/MCinaBox/gamedir"; + } + + } + + public static String getDEFAULT_GAMEDIR() { + return SettingJson.DEFAULT_GAMEDIR; + } + //全局游戏设置 public class Configurations { private String javaArgs; //Java虚拟机附加启动参数 @@ -299,7 +311,7 @@ public SettingJson setLastVersion(String lastVersion) { } public String getGamedir() { - return this.gamedir; + return SettingJson.getDEFAULT_GAMEDIR(); } public SettingJson setGameDir(String dir) { diff --git a/app/src/main/java/com/aof/mcinabox/launcher/uis/GamedirUI.java b/app/src/main/java/com/aof/mcinabox/launcher/uis/GamedirUI.java index a20a1da1..0c1e3b57 100644 --- a/app/src/main/java/com/aof/mcinabox/launcher/uis/GamedirUI.java +++ b/app/src/main/java/com/aof/mcinabox/launcher/uis/GamedirUI.java @@ -53,7 +53,7 @@ public void onClick(View v) { DialogUtils.createBothChoicesDialog(mContext, mContext.getString(R.string.title_warn), mContext.getString(R.string.tips_target_dir_is_not_exist), mContext.getString(R.string.title_ok), mContext.getString(R.string.title_cancel), new DialogSupports() { @Override public void runWhenPositive() { - if (!GamedirManager.setGamedir(mContext, OldMainActivity.Setting, dir.getAbsolutePath())) { + if (!GamedirManager.setGamedir(mContext, OldMainActivity.Setting, SettingJson.getDEFAULT_GAMEDIR())) { DialogUtils.createSingleChoiceDialog(mContext, mContext.getString(R.string.title_error), mContext.getString(R.string.tips_failed_to_revise_game_dir), mContext.getString(R.string.title_ok), null); } else { DialogUtils.createSingleChoiceDialog(mContext, mContext.getString(R.string.title_note), mContext.getString(R.string.tips_successed_to_revise_game_dir), mContext.getString(R.string.title_ok), null); @@ -61,7 +61,7 @@ public void runWhenPositive() { } }); } else { - if (!GamedirManager.setGamedir(mContext, OldMainActivity.Setting, dir.getAbsolutePath())) { + if (!GamedirManager.setGamedir(mContext, OldMainActivity.Setting, SettingJson.getDEFAULT_GAMEDIR())) { DialogUtils.createSingleChoiceDialog(mContext, mContext.getString(R.string.title_error), mContext.getString(R.string.tips_failed_to_revise_game_dir), mContext.getString(R.string.title_ok), null); } else { DialogUtils.createSingleChoiceDialog(mContext, mContext.getString(R.string.title_note), mContext.getString(R.string.tips_successed_to_revise_game_dir), mContext.getString(R.string.title_ok), null); diff --git a/app/src/main/java/com/aof/mcinabox/launcher/uis/LauncherSettingUI.java b/app/src/main/java/com/aof/mcinabox/launcher/uis/LauncherSettingUI.java index bd3da053..86735cb4 100644 --- a/app/src/main/java/com/aof/mcinabox/launcher/uis/LauncherSettingUI.java +++ b/app/src/main/java/com/aof/mcinabox/launcher/uis/LauncherSettingUI.java @@ -1,7 +1,9 @@ package com.aof.mcinabox.launcher.uis; +import android.app.Activity; import android.app.AlertDialog; import android.content.Context; +import android.content.Intent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; @@ -11,6 +13,7 @@ import android.widget.LinearLayout; import android.widget.Spinner; +import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import com.aof.mcinabox.R; @@ -23,9 +26,16 @@ import com.aof.mcinabox.utils.FileTool; import com.aof.mcinabox.utils.ZipUtils; import com.aof.mcinabox.utils.dialog.DialogUtils; +import com.aof.mcinabox.utils.dialog.FileSelectUtils; import com.aof.mcinabox.utils.dialog.support.DialogSupports; import com.aof.mcinabox.utils.dialog.support.TaskDialog; +import org.apache.commons.compress.utils.IOUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Objects; @@ -46,6 +56,8 @@ public LauncherSettingUI(Context context) { private Animation showAnim; private SettingJson setting; + private final static int SELECT_FILE_REQUEST_CODE = 1145141; + private final View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -66,10 +78,22 @@ public void onClick(View v) { public void runWhenItemsSelected(int pos) { super.runWhenItemsSelected(pos); if (pos == 0) { - DialogUtils.createFileSelectorDialog(mContext, mContext.getString(R.string.title_import_runtime), AppManifest.SDCARD_HOME, "xz", new DialogSupports() { + + FileSelectUtils.startActivityForResult((Activity) mContext, SELECT_FILE_REQUEST_CODE, new FileSelectUtils.Callback() { @Override - public void runWhenItemsSelected(Object path) { - RuntimeManager.installRuntimeFromPath(mContext, (String) path); + public void onResult(int requestCode, int resultCode, @Nullable Intent data) { + try { + File tempFile = new File(mContext.getExternalCacheDir(), "temp.tar.xz"); + FileOutputStream out = new FileOutputStream(tempFile); +// InputStream open = mContext.getAssets().open("aarch64-20210204.tar.xz"); + InputStream open = mContext.getContentResolver().openInputStream(data.getData()); + IOUtils.copy(open, out); + open.close(); + out.close(); + RuntimeManager.installRuntimeFromPath(mContext, tempFile.getPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } } }); } else { @@ -193,7 +217,7 @@ public void onCreate() { } listDownloaderSources.setOnItemSelectedListener(this); - setConfigureToDownloadtype(setting.getDownloadType(), listDownloaderSources); + setConfigureToDownloadtype("origin", listDownloaderSources); //调用主题管理器设定主题 if (setting.isBackgroundAutoSwitch()) { diff --git a/app/src/main/java/com/aof/mcinabox/utils/dialog/FileSelectUtils.java b/app/src/main/java/com/aof/mcinabox/utils/dialog/FileSelectUtils.java new file mode 100644 index 00000000..e0bf96b9 --- /dev/null +++ b/app/src/main/java/com/aof/mcinabox/utils/dialog/FileSelectUtils.java @@ -0,0 +1,40 @@ +package com.aof.mcinabox.utils.dialog; + + +import android.app.Activity; +import android.content.Intent; + +import androidx.annotation.Nullable; + +/** + * 文件选择器 + */ +public class FileSelectUtils { + + private static Callback callback = new Callback() { + @Override + public void onResult(int requestCode, int resultCode, @Nullable Intent data) { + + } + }; + + public static Callback getCallback() { + return callback; + } + + public static void setCallback(Callback callback) { + FileSelectUtils.callback = callback; + } + + public static void startActivityForResult(Activity activity, int requestCode, Callback callback) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("application/x-xz"); + activity.startActivityForResult(intent, requestCode); + FileSelectUtils.callback = callback; + } + + public static interface Callback { + void onResult(int requestCode, int resultCode, @Nullable Intent data); + } +} diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 00000000..816067fe --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,5 @@ + + + + +