Browse Source

android: add more prompts when user launches the game without data files

Wei Mingzhi 6 years ago
parent
commit
bcaeb4daba

+ 35 - 0
android/app/src/main/cpp/android_jni.cpp

@@ -190,6 +190,41 @@ JNIEXPORT jboolean JNICALL Java_com_sdlpal_sdlpal_SettingsActivity_setConfigStri
     return item >= 0 ? PAL_SetConfigString(item, v_str ? jstring_to_utf8(env, v_str).c_str() : nullptr) : JNI_FALSE;
 }
 
+/*
+ * Class:     com_sdlpal_sdlpal_SettingsActivity
+ * Method:    checkDataFile
+ * Signature: (Ljava/lang/String;)Z
+ */
+EXTERN_C_LINKAGE
+JNIEXPORT jboolean JNICALL Java_com_sdlpal_sdlpal_SettingsActivity_checkDataFiles(JNIEnv *env, jclass cls, jstring j_str)
+{
+    std::string path = jstring_to_utf8(env, j_str);
+    FILE *fp;
+
+#define checkFile(filename) \
+    fp = fopen((path + "/" + filename).c_str(), "rb"); \
+    if (fp == nullptr) return JNI_FALSE; \
+    fclose(fp);
+
+    checkFile("abc.mkf");
+    checkFile("ball.mkf");
+    checkFile("data.mkf");
+    checkFile("f.mkf");
+    checkFile("fbp.mkf");
+    checkFile("fire.mkf");
+    checkFile("gop.mkf");
+    checkFile("m.msg");
+    checkFile("map.mkf");
+    checkFile("mgo.mkf");
+    checkFile("rgm.mkf");
+    checkFile("rng.mkf");
+    checkFile("sss.mkf");
+    checkFile("word.dat");
+
+    return JNI_TRUE;
+}
+
+
 EXTERN_C_LINKAGE
 void* JNI_mediaplayer_load(const char *filename)
 {

+ 13 - 0
android/app/src/main/java/com/sdlpal/sdlpal/SettingsActivity.java

@@ -32,6 +32,7 @@ public class SettingsActivity extends AppCompatActivity {
     public static native boolean setConfigBoolean(String item, boolean value);
     public static native boolean setConfigInt(String item, int value);
     public static native boolean setConfigString(String item, String value);
+    public static native boolean checkDataFiles(String path);
     public static native String getGitRevision();
 
     private static final String KeepAspectRatio = "KeepAspectRatio";
@@ -129,6 +130,18 @@ public class SettingsActivity extends AppCompatActivity {
         findViewById(R.id.btnFinish).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                String gamePath = ((EditText)findViewById(R.id.edFolder)).getText().toString();
+                if (!checkDataFiles(gamePath)) {
+                    AlertDialog.Builder builder = new AlertDialog.Builder(mInstance);
+                    builder.setMessage(getString(R.string.msg_data_not_found_header) + "\n" +
+                            gamePath + "\n\n" +
+                            getString(R.string.msg_data_not_found_footer));
+                    builder.setCancelable(true);
+                    builder.setPositiveButton(android.R.string.ok, null);
+                    builder.create().show();
+                    return;
+                }
+
                 if (!setConfigs()) return;
                 setConfigBoolean(LaunchSetting, false);
                 saveConfigFile();

+ 2 - 0
android/app/src/main/res/values-zh-rCN/strings.xml

@@ -29,4 +29,6 @@
     <string name="action_usefontfile">自定义字体文件</string>
     <string name="toast_requestpermission">本应用需要存储设备读写权限以访问游戏资源。如拒绝授权,则本应用无法正常运行。</string>
     <string name="toast_grantpermission">本应用需要存储设备读写权限以访问游戏资源。请点击“确定”后手动为本应用开启权限。</string>
+    <string name="msg_data_not_found_header">无法在以下文件夹中找到游戏数据文件:</string>
+    <string name="msg_data_not_found_footer">注意:由于版权问题,数据文件无法提供。请自行从百游官方下载并解压拷贝到手机中。</string>
 </resources>

+ 5 - 3
android/app/src/main/res/values-zh-rTW/strings.xml

@@ -20,13 +20,15 @@
     <string name="label_opl">OPL模擬器</string>
     <string name="label_oplrate">OPL模擬器取樣速率</string>
     <string name="msg_crash">上次程式異常退出,已顯示設定頁供您檢查設定是否正確。</string>
-    <string name="msg_empty">必須指定遊戲資源檔案夾!</string>
+    <string name="msg_empty">必須指定遊戲資料檔所在資料夾!</string>
     <string name="msg_exit">您的設定已保存,下次開啟時將直接開始遊戲。在遊戲中,您可以通過「系統」功能表的「返回設定」項回到本設定頁。</string>
     <string name="action_restore">撤銷修改</string>
     <string name="label_loglevel">日誌記錄級別</string>
     <string name="action_usefontfile">自訂字體檔案</string>
     <string name="action_usemsgfile">自訂語言檔案</string>
     <string name="action_uselogfile">記錄到檔案</string>
-    <string name="toast_requestpermission">本應用需要存儲裝置讀寫許可權以訪問遊戲資料檔。如拒絕授權,則本app無法正常執行。</string>
-    <string name="toast_grantpermission">本應用需要存儲裝置讀寫許可權以訪問遊戲資料檔。請按「確定」後手動為本應用開啟許可權。</string>
+    <string name="toast_requestpermission">本app需要存儲裝置讀寫許可權以訪問遊戲資料檔。如拒絕授權,則本app無法正常執行。</string>
+    <string name="toast_grantpermission">本app需要存儲裝置讀寫許可權以訪問遊戲資料檔。請按「確定」後手動為本app開啟許可權。</string>
+    <string name="msg_data_not_found_header">無法在以下資料夾中找到遊戲資料檔:</string>
+    <string name="msg_data_not_found_footer">說明:為防止侵害大宇公司版權,恕不提供遊戲資料檔。请自行將正版PAL的資料檔復製到手機中。</string>
 </resources>

+ 2 - 0
android/app/src/main/res/values/strings.xml

@@ -29,4 +29,6 @@
     <string name="action_uselogfile">Log to file</string>
     <string name="toast_requestpermission">This app requires storage permission to access game resources. Denying the request prevents the app running properly.</string>
     <string name="toast_grantpermission">This app requires storage permission to access game resources. Please click \'OK\' and grant the permission manually.</string>
+    <string name="msg_data_not_found_header">Cannot find data file in the following directory:</string>
+    <string name="msg_data_not_found_footer">NOTE: For copyright reasons data files required to run the game are NOT included.</string>
 </resources>