From 6e3a594641a63b853d284937bb992d452c70f82d Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 26 Feb 2012 02:56:51 +0300 Subject: [PATCH] [android] Copy downloaded countries from v2.0.0 to the shared location /sdcard/MapsWithMe --- .../mapswithme/maps/CopyResourcesActivity.cpp | 40 +++++++++++++++++++ .../maps/CopyResourcesActivity.java | 10 +++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/android/jni/com/mapswithme/maps/CopyResourcesActivity.cpp b/android/jni/com/mapswithme/maps/CopyResourcesActivity.cpp index b2b9c1f3a7..bef7acdf59 100644 --- a/android/jni/com/mapswithme/maps/CopyResourcesActivity.cpp +++ b/android/jni/com/mapswithme/maps/CopyResourcesActivity.cpp @@ -2,6 +2,8 @@ // To get free disk space #include +#include "../../../../../defines.hpp" + #include "../../../../../base/logging.hpp" #include "../../../../../coding/zip_reader.hpp" @@ -115,4 +117,42 @@ extern "C" g_filesToCopy.erase(it); return g_copiedBytesProgress; } + + // Move downloaded maps from /sdcard/Android/data/com.mapswithme.maps/files/ to /sdcard/MapsWithMe + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_CopyResourcesActivity_nativeMoveMaps(JNIEnv * env, jobject thiz, + jstring fromPath, jstring toPath) + { + string from, to; + { + char const * strFrom = env->GetStringUTFChars(fromPath, 0); + if (!strFrom) + return; + from = strFrom; + env->ReleaseStringUTFChars(fromPath, strFrom); + + char const * strTo = env->GetStringUTFChars(toPath, 0); + if (!strTo) + return; + to = strTo; + env->ReleaseStringUTFChars(toPath, strTo); + } + + Platform & pl = GetPlatform(); + Platform::FilesList files; + // Move *.mwm files + pl.GetFilesInDir(from, "*" DATA_FILE_EXTENSION, files); + for (size_t i = 0; i < files.size(); ++i) + { + LOG(LINFO, (from + files[i], to + files[i])); + rename((from + files[i]).c_str(), (to + files[i]).c_str()); + } + + // Delete not finished *.downloading files + files.clear(); + pl.GetFilesInDir(from, "*" DOWNLOADING_FILE_EXTENSION, files); + pl.GetFilesInDir(from, "*" RESUME_FILE_EXTENSION, files); + for (size_t i = 0; i < files.size(); ++i) + remove((from + files[i]).c_str()); + } } diff --git a/android/src/com/mapswithme/maps/CopyResourcesActivity.java b/android/src/com/mapswithme/maps/CopyResourcesActivity.java index 80bc2f8fb6..9c60c18e39 100644 --- a/android/src/com/mapswithme/maps/CopyResourcesActivity.java +++ b/android/src/com/mapswithme/maps/CopyResourcesActivity.java @@ -35,8 +35,6 @@ public class CopyResourcesActivity extends Activity { m_apkPath = apkPath; m_sdcardPath = sdcardPath; - // Create sdcard folder if it doesn't exist - new File(sdcardPath).mkdirs(); } @Override @@ -107,8 +105,13 @@ public class CopyResourcesActivity extends Activity View v = new View(this); v.setVisibility(View.INVISIBLE); setContentView(v); + final String extPath = MWMActivity.getDataStoragePath(); + // Create sdcard folder if it doesn't exist + new File(extPath).mkdirs(); + // Used to migrate from v2.0.0 to 2.0.1 + nativeMoveMaps(MWMActivity.getExtAppDirectoryPath("files"), extPath); // All copy checks are made in the background task - new CopyResourcesTask(MWMActivity.getApkPath(this), MWMActivity.getDataStoragePath()).execute(); + new CopyResourcesTask(MWMActivity.getApkPath(this), extPath).execute(); } public void onCopyTaskFinished(int result) @@ -160,6 +163,7 @@ public class CopyResourcesActivity extends Activity m_dialog.setProgress(copiedBytes); } + private native void nativeMoveMaps(String fromFolder, String toFolder); private native int nativeGetBytesToCopy(String m_apkPath, String m_sdcardPath); private native int nativeCopyNextFile(); }