Browse Source

put cfg to data dir, prevent cache clear

Pal Lockheart 7 years ago
parent
commit
1c487eb634

+ 9 - 6
android/app/src/main/cpp/android_jni.cpp

@@ -17,7 +17,7 @@
 
 #include <string>
 
-static std::string g_basepath, g_configpath, g_midipath;
+static std::string g_basepath, g_configpath, g_cachepath, g_midipath;
 static int g_screenWidth = 640, g_screenHeight = 400;
 const char* midiInterFile;
 
@@ -58,13 +58,16 @@ static JNIEnv* getJNIEnv()
  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
  */
 EXTERN_C_LINKAGE
-JNIEXPORT void JNICALL Java_io_github_sdlpal_PalActivity_setAppPath(JNIEnv *env, jclass cls, jstring base_path, jstring cache_path)
+JNIEXPORT void JNICALL Java_io_github_sdlpal_PalActivity_setAppPath(JNIEnv *env, jclass cls, jstring base_path, jstring data_path, jstring cache_path)
 {
     g_basepath = jstring_to_utf8(env, base_path);
-    g_configpath = jstring_to_utf8(env, cache_path);
+    g_configpath = jstring_to_utf8(env, data_path);
+    g_cachepath = jstring_to_utf8(env, cache_path);
+    LOGV("got basepath:%s,configpath:%s,cachepath:%s\n",g_basepath.c_str(),g_configpath.c_str(),g_cachepath.c_str());
     if (*g_basepath.rbegin() != '/') g_basepath.append("/");
     if (*g_configpath.rbegin() != '/') g_configpath.append("/");
-    g_midipath = g_configpath + "intermediates.mid";
+    if (*g_cachepath.rbegin() != '/') g_cachepath.append("/");
+    g_midipath = g_cachepath + "intermediates.mid";
     midiInterFile = g_midipath.c_str();
 }
 
@@ -300,7 +303,7 @@ UTIL_Platform_Init(
 		__android_log_print(level_mapping[level], TAG, "%s", str);
 	});
 
-    FILE *fp = fopen((g_configpath + "running").c_str(), "w");
+    FILE *fp = fopen((g_cachepath + "running").c_str(), "w");
     if (fp) fclose(fp);
     return 0;
 }
@@ -311,5 +314,5 @@ UTIL_Platform_Quit(
    VOID
 )
 {
-    unlink((g_configpath + "running").c_str());
+    unlink((g_cachepath + "running").c_str());
 }

+ 4 - 3
android/app/src/main/java/io/github/sdlpal/PalActivity.java

@@ -13,7 +13,7 @@ public class PalActivity extends SDLActivity {
     private static final String TAG = "sdlpal-debug";
     private static MediaPlayer mediaPlayer;
 
-    public static native void setAppPath(String basepath, String cachepath);
+    public static native void setAppPath(String basepath, String datapath, String cachepath);
     public static native void setScreenSize(int width, int height);
 
     public static boolean crashed = false;
@@ -36,12 +36,13 @@ public class PalActivity extends SDLActivity {
     public void onCreate(Bundle savedInstanceState) {  
         super.onCreate(savedInstanceState);
 
+        String dataPath = getApplicationContext().getFilesDir().getPath();
         String cachePath = getApplicationContext().getCacheDir().getPath();
         String sdcardState = Environment.getExternalStorageState();
         if (sdcardState.equals(Environment.MEDIA_MOUNTED)){
-            setAppPath(Environment.getExternalStorageDirectory().getPath() + "/sdlpal", cachePath);
+            setAppPath(Environment.getExternalStorageDirectory().getPath() + "/sdlpal", dataPath, cachePath);
         } else {
-            setAppPath("/sdcard/sdlpal", cachePath);
+            setAppPath("/sdcard/sdlpal", dataPath, cachePath);
         }
 
         DisplayMetrics metrics = new DisplayMetrics();

+ 5 - 0
android/build.gradle

@@ -12,4 +12,9 @@ allprojects {
     repositories {
         jcenter()
     }
+    gradle.projectsEvaluated {
+        tasks.withType(JavaCompile) {
+            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
+        }
+    }
 }