From d48159dddd5229c45f434a36294460dbabc4b052 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Sun, 15 Mar 2020 16:33:01 +0800 Subject: [PATCH] Layout adjust, list update logic fix --- .../assets/downloadable_content_list.json | 2 +- app/src/main/assets/smapi/config.json | 5 ++ .../com/zane/smapiinstaller/MainActivity.java | 56 +++++++++++++++---- .../smapiinstaller/constant/Constants.java | 5 ++ .../entity/FrameworkConfig.java | 30 ++++++++++ .../smapiinstaller/logic/ConfigManager.java | 35 ++++++++++++ .../zane/smapiinstaller/utils/FileUtils.java | 32 ++++++++++- app/src/main/res/layout/fragment_install.xml | 17 +++++- app/src/main/res/menu/main.xml | 23 ++++++-- app/src/main/res/values-zh-rHK/strings.xml | 5 +- app/src/main/res/values-zh-rTW/strings.xml | 5 +- app/src/main/res/values-zh/strings.xml | 5 +- app/src/main/res/values/strings.xml | 5 +- 13 files changed, 203 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/zane/smapiinstaller/entity/FrameworkConfig.java create mode 100644 app/src/main/java/com/zane/smapiinstaller/logic/ConfigManager.java diff --git a/app/src/main/assets/downloadable_content_list.json b/app/src/main/assets/downloadable_content_list.json index c6e534c..0c8c31c 100644 --- a/app/src/main/assets/downloadable_content_list.json +++ b/app/src/main/assets/downloadable_content_list.json @@ -5,7 +5,7 @@ "type": "COMPAT", "name": "SMAPI for 1.4.5.137", "assetPath": "compat/137/", - "description": "SMAPI compat package for game 1.4.4.128 - 1.4.5.137", + "description": "SMAPI compat package for game 1.4.4.128 - 1.4.5.137, SMAPI 3.3.2.0", "url": "http://zaneyork.cn/download/compat/smapi_137.zip", "hash": "bd16e8e4cb52d636e24c6a2d2309b66a60e492d2b97c1b8f6a519c04ac42ebdc" }, diff --git a/app/src/main/assets/smapi/config.json b/app/src/main/assets/smapi/config.json index d30425c..5a136fc 100644 --- a/app/src/main/assets/smapi/config.json +++ b/app/src/main/assets/smapi/config.json @@ -27,6 +27,11 @@ The default values are mirrored in StardewModdingAPI.Framework.Models.SConfig to */ "DeveloperMode": false, + /** + * Whether to enable load mods with multithreading supports. + */ + "MultithreadingLoading": false, + /** * Whether to add a section to the 'mod issues' list for mods which directly use potentially * sensitive .NET APIs like file or shell access. Note that many mods do this legitimately as diff --git a/app/src/main/java/com/zane/smapiinstaller/MainActivity.java b/app/src/main/java/com/zane/smapiinstaller/MainActivity.java index 8d4e31b..6e80f95 100644 --- a/app/src/main/java/com/zane/smapiinstaller/MainActivity.java +++ b/app/src/main/java/com/zane/smapiinstaller/MainActivity.java @@ -4,12 +4,15 @@ import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.view.Menu; +import android.view.MenuItem; import com.google.android.material.navigation.NavigationView; import com.microsoft.appcenter.AppCenter; import com.microsoft.appcenter.analytics.Analytics; import com.microsoft.appcenter.crashes.Crashes; import com.zane.smapiinstaller.constant.Constants; +import com.zane.smapiinstaller.entity.FrameworkConfig; +import com.zane.smapiinstaller.logic.ConfigManager; import com.zane.smapiinstaller.logic.GameLauncher; import androidx.annotation.NonNull; @@ -40,25 +43,20 @@ public class MainActivity extends AppCompatActivity { @BindView(R.id.nav_view) NavigationView navigationView; - private void requestPermissions() - { + private void requestPermissions() { if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); - } - else - { + } else { initView(); } } public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) - { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { initView(); - } - else { + } else { requestPermissions(); } } @@ -85,7 +83,8 @@ public class MainActivity extends AppCompatActivity { NavigationUI.setupWithNavController(navigationView, navController); } - @OnClick(R.id.launch) void launchButtonClick() { + @OnClick(R.id.launch) + void launchButtonClick() { new GameLauncher(navigationView).launch(); } @@ -96,6 +95,43 @@ public class MainActivity extends AppCompatActivity { return true; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + ConfigManager manager = new ConfigManager(); + FrameworkConfig config = manager.getConfig(); + menu.findItem(R.id.settings_verbose_logging).setChecked(config.isVerboseLogging()); + menu.findItem(R.id.settings_check_for_updates).setChecked(config.isCheckForUpdates()); + menu.findItem(R.id.settings_developer_mode).setChecked(config.isDeveloperMode()); + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.isCheckable()) { + if (item.isChecked()) + item.setChecked(false); + else + item.setChecked(true); + } + ConfigManager manager = new ConfigManager(); + FrameworkConfig config = manager.getConfig(); + switch (item.getItemId()) { + case R.id.settings_verbose_logging: + config.setVerboseLogging(item.isChecked()); + break; + case R.id.settings_check_for_updates: + config.setCheckForUpdates(item.isChecked()); + break; + case R.id.settings_developer_mode: + config.setDeveloperMode(item.isChecked()); + break; + default: + return super.onOptionsItemSelected(item); + } + manager.flushConfig(); + return true; + } + @Override public boolean onSupportNavigateUp() { NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); diff --git a/app/src/main/java/com/zane/smapiinstaller/constant/Constants.java b/app/src/main/java/com/zane/smapiinstaller/constant/Constants.java index 31bdc0a..ddcb66d 100644 --- a/app/src/main/java/com/zane/smapiinstaller/constant/Constants.java +++ b/app/src/main/java/com/zane/smapiinstaller/constant/Constants.java @@ -12,6 +12,11 @@ public class Constants { * 日志路径 */ public static final String LOG_PATH = "StardewValley/ErrorLogs/SMAPI-latest.txt"; + + /** + * 配置文件路径 + */ + public static final String CONFIG_PATH = "StardewValley/smapi-internal/config.user.json"; /** * 安装包目标包名 */ diff --git a/app/src/main/java/com/zane/smapiinstaller/entity/FrameworkConfig.java b/app/src/main/java/com/zane/smapiinstaller/entity/FrameworkConfig.java new file mode 100644 index 0000000..b0ee345 --- /dev/null +++ b/app/src/main/java/com/zane/smapiinstaller/entity/FrameworkConfig.java @@ -0,0 +1,30 @@ +package com.zane.smapiinstaller.entity; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +/** + * SMAPI的配置 + */ +@Data +@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY, getterVisibility= JsonAutoDetect.Visibility.NONE) +public class FrameworkConfig { + /** + * 详细日志 + */ + @JsonProperty("VerboseLogging") + private boolean VerboseLogging = false; + /** + * 检查更新 + */ + @JsonProperty("CheckForUpdates") + private boolean CheckForUpdates = true; + /** + * 开发者模式 + */ + @JsonProperty("DeveloperMode") + private boolean DeveloperMode = false; +} diff --git a/app/src/main/java/com/zane/smapiinstaller/logic/ConfigManager.java b/app/src/main/java/com/zane/smapiinstaller/logic/ConfigManager.java new file mode 100644 index 0000000..798829b --- /dev/null +++ b/app/src/main/java/com/zane/smapiinstaller/logic/ConfigManager.java @@ -0,0 +1,35 @@ +package com.zane.smapiinstaller.logic; + +import android.os.Environment; + +import com.zane.smapiinstaller.constant.Constants; +import com.zane.smapiinstaller.entity.FrameworkConfig; +import com.zane.smapiinstaller.utils.FileUtils; + +import java.io.File; + +/** + * 配置管理器 + */ +public class ConfigManager { + private FrameworkConfig config; + + public ConfigManager() { + File configFile = new File(Environment.getExternalStorageDirectory(), Constants.CONFIG_PATH); + if(configFile.exists()) { + config = FileUtils.getFileJson(configFile, FrameworkConfig.class); + } + if(config == null) { + config = new FrameworkConfig(); + } + } + + public FrameworkConfig getConfig() { + return config; + } + + public void flushConfig() { + File configFile = new File(Environment.getExternalStorageDirectory(), Constants.CONFIG_PATH); + FileUtils.writeFileJson(configFile, config); + } +} diff --git a/app/src/main/java/com/zane/smapiinstaller/utils/FileUtils.java b/app/src/main/java/com/zane/smapiinstaller/utils/FileUtils.java index 8c7c520..5884dd9 100644 --- a/app/src/main/java/com/zane/smapiinstaller/utils/FileUtils.java +++ b/app/src/main/java/com/zane/smapiinstaller/utils/FileUtils.java @@ -107,7 +107,37 @@ public class FileUtils { try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { writer.write(JSONUtil.toJson(content)); } finally { - org.zeroturnaround.zip.commons.FileUtils.moveFile(file, new File(context.getFilesDir(), filename)); + File distFile = new File(context.getFilesDir(), filename); + if(file.exists()) { + org.zeroturnaround.zip.commons.FileUtils.forceDelete(distFile); + } + org.zeroturnaround.zip.commons.FileUtils.moveFile(file, distFile); + } + } catch (Exception ignored) { + } + } + + /** + * 写入JSON文件到本地 + * @param file 文件 + * @param content 内容 + */ + public static void writeFileJson(File file, Object content) { + try { + if(!file.getParentFile().exists()) { + org.zeroturnaround.zip.commons.FileUtils.forceMkdir(file.getParentFile()); + } + String filename = file.getName(); + String tmpFilename = filename + ".tmp"; + File fileTmp = new File(file.getParent(), tmpFilename); + FileOutputStream outputStream = new FileOutputStream(fileTmp); + try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { + writer.write(JSONUtil.toJson(content)); + } finally { + if(file.exists()) { + org.zeroturnaround.zip.commons.FileUtils.forceDelete(file); + } + org.zeroturnaround.zip.commons.FileUtils.moveFile(fileTmp, file); } } catch (Exception ignored) { } diff --git a/app/src/main/res/layout/fragment_install.xml b/app/src/main/res/layout/fragment_install.xml index 10deb00..7ea812d 100644 --- a/app/src/main/res/layout/fragment_install.xml +++ b/app/src/main/res/layout/fragment_install.xml @@ -32,17 +32,32 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> + + + app:layout_constraintGuide_percent="0.1" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index a2411e3..a861f3b 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -1,9 +1,22 @@ - + + + + + diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index a5bba38..21bbaea 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -34,7 +34,6 @@ 兼容性 N網 官網 - 暫處於內測階段, Q群:860453392 日誌 SMAPI星露穀物語 無法創建以下文件: %s @@ -55,4 +54,8 @@ 捐贈 QQ群②: 1078428449 谷歌商店详情 + SMAPI版本: 3.3.2.2 + 詳細日誌 + 檢查更新 + 開發者模式 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index a5bba38..682cff2 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -34,7 +34,6 @@ 兼容性 N網 官網 - 暫處於內測階段, Q群:860453392 日誌 SMAPI星露穀物語 無法創建以下文件: %s @@ -55,4 +54,8 @@ 捐贈 QQ群②: 1078428449 谷歌商店详情 + SMAPI版本: 3.3.2.2 + 詳細日誌 + 開發者模式 + 檢查更新 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 21cecf1..ec5858b 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -34,7 +34,6 @@ 兼容性 N网 官网 - 暂处于内测阶段, Q群:860453392 日志 SMAPI星露谷物语 无法创建以下文件: %s @@ -55,4 +54,8 @@ QQ群②: 1078428449 %1$s依赖%2$s %3$s版本,请先更新它 谷歌商店详情 + SMAPI版本: 3.3.2.2 + 详细日志 + 开发者模式 + 检查更新 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b8bb35..a024dbb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,7 +34,6 @@ Compat Nexus Release - Still at test stage now. Logs SMAPI Stardew Valley Failed to create target file : %s @@ -59,4 +58,8 @@ Donation 红包码已复制\n支付宝首页搜索“9188262” 立即领红包 View in Play Store + SMAPI Version: 3.3.2.2 + Verbose Logging + Check For Updates + Developer Mode