diff options
author | vng <viktor.govako@gmail.com> | 2012-11-14 21:32:21 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:46:56 +0300 |
commit | 20850a911730f1496a6c66b7fc0bee06ae70cba4 (patch) | |
tree | be93ea2183c84a78b89d6356bc44eeb827bda2d0 /android/jni/com/mapswithme/maps/settings | |
parent | e16c4e4c13dd4ed564c78950cf61adce9c9ccf65 (diff) |
[android] Add common SettingsActivity stub like PreferenceActivity.
Diffstat (limited to 'android/jni/com/mapswithme/maps/settings')
-rw-r--r-- | android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp new file mode 100644 index 0000000000..f51d3a8315 --- /dev/null +++ b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp @@ -0,0 +1,56 @@ +#include "../Framework.hpp" + +#include "../../core/jni_helper.hpp" + +#include "../../platform/Platform.hpp" + +#include "../../../../../../coding/internal/file_data.hpp" + + +extern "C" +{ + JNIEXPORT jstring JNICALL + Java_com_mapswithme_maps_settings_StoragePathActivity_nativeGetStoragePath(JNIEnv * env, jobject thiz) + { + return jni::ToJavaString(env, android::Platform::Instance().GetStoragePathPrefix()); + } + + JNIEXPORT jboolean JNICALL + Java_com_mapswithme_maps_settings_StoragePathActivity_nativeSetStoragePath(JNIEnv * env, jobject thiz, + jstring s) + { + string const from = GetPlatform().WritableDir(); + string const to = jni::ToNativeString(env, s); + + // Remove all maps from container. + g_framework->RemoveLocalMaps(); + + // Get files to copy. + Platform & pl = GetPlatform(); + + // Get regexp like this: (\.mwm$|\.ttf$) + string const regexp = "(\\" DATA_FILE_EXTENSION "$|\\.ttf$)"; + Platform::FilesList files; + pl.GetFilesByRegExp(from, regexp, files); + + // Copy all needed files. + for (size_t i = 0; i < files.size(); ++i) + if (!my::CopyFile(from + files[i], to + files[i])) + { + // Do the undo - delete all previously copied files. + for (size_t j = 0; j <= i; ++j) + { + string const path = to + files[j]; + VERIFY ( my::DeleteFileX(path), (path) ); + } + return false; + } + + // Set new storage path. + android::Platform::Instance().SetStoragePath(to); + + // Add all maps again. + g_framework->AddLocalMaps(); + return true; + } +} |