[AND] review fix

This commit is contained in:
ExMix 2014-04-25 12:33:22 +03:00 committed by Alex Zolotarev
parent 83ae643861
commit 6398772154
21 changed files with 173 additions and 55 deletions

View file

@ -1,9 +1,3 @@
/*
* StoragePathManager.cpp
*
* Created on: 23 ???. 2014 ?.
* Author: ExMix
*/
#include "../platform/Platform.hpp"
#include "../core/jni_helper.hpp"
#include "Framework.hpp"
@ -31,7 +25,7 @@ namespace
void operator() (string const & name)
{
m_set.insert(m_dirPath + "/" + name);
m_set.insert(m_dirPath + name);
}
private:
@ -108,17 +102,17 @@ JNIEXPORT jboolean JNICALL
Java_com_mapswithme_util_StoragePathManager_nativeMoveBookmarks(JNIEnv * env, jclass thiz, jobjectArray pathArray, jlong storageAvSize)
{
set<string> fullBookmarkSet;
Platform * pl = &GetPlatform();
string settingsDir = pl->SettingsDir();
string writableDir = pl->WritableDir();
Platform & pl = GetPlatform();
string const settingsDir = pl.SettingsDir();
string const writableDir = pl.WritableDir();
if (writableDir != settingsDir)
{
Platform::FilesList list;
pl->GetFilesByExt(writableDir, BOOKMARKS_FILE_EXTENSION, list);
pl.GetFilesByExt(writableDir, BOOKMARKS_FILE_EXTENSION, list);
for_each(list.begin(), list.end(), PathInserter(writableDir, fullBookmarkSet));
}
int arraySize = env->GetArrayLength(pathArray);
int const arraySize = env->GetArrayLength(pathArray);
for (int i = 0; i < arraySize; ++i)
{
jstring jPath = (jstring)env->GetObjectArrayElement(pathArray, i);
@ -127,7 +121,7 @@ Java_com_mapswithme_util_StoragePathManager_nativeMoveBookmarks(JNIEnv * env, jc
if (path != settingsDir)
{
Platform::FilesList list;
pl->GetFilesByExt(path, BOOKMARKS_FILE_EXTENSION, list);
pl.GetFilesByExt(path, BOOKMARKS_FILE_EXTENSION, list);
for_each(list.begin(), list.end(), PathInserter(path, fullBookmarkSet));
}
}
@ -147,11 +141,11 @@ Java_com_mapswithme_util_StoragePathManager_nativeMoveBookmarks(JNIEnv * env, jc
for (fileIt it = fullBookmarkSet.begin(); it != fullBookmarkSet.end(); ++it)
{
string oldFilePath = *it;
string const oldFilePath = *it;
string fileName = oldFilePath;
my::GetNameFromFullPath(fileName);
my::GetNameWithoutExt(fileName);
string newFilePath = BookmarkCategory::GenerateUniqueFileName(settingsDir, fileName);
string const newFilePath = BookmarkCategory::GenerateUniqueFileName(settingsDir, fileName);
if (my::CopyFileX(oldFilePath, newFilePath))
my::DeleteFileX(oldFilePath);

View file

@ -343,8 +343,8 @@
<string name="placepage_coordinates">Coordinates</string>
<string name="placepage_unsorted">Unsorted</string>
<string name="search_show_on_map">View on map</string>
<string name="kitkat_migrate_ok">All maps been copyed. You can delete MapsWithMe folder from your sdcard</string>
<string name="kitkat_migrate_filed">Not enough space for maps</string>
<string name="bookmark_move_fail">Not enough space for bookmarks</string>
<string name="kitkat_optimization_in_progress">Optimization. This can take several minutes.\nPlease wait…</string>
<string name="kitkat_migrate_ok">Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.</string>
<string name="kitkat_migrate_failed">Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.</string>
<string name="bookmark_move_fail">We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.</string>
<string name="kitkat_optimization_in_progress">Your map storage is being optimized now. Please wait, it may take a few minutes.</string>
</resources>

View file

@ -321,7 +321,7 @@ public class MWMActivity extends NvEventQueueActivity
{
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle(tittleID)
.setMessage(tittleID)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
{
@Override
@ -335,8 +335,8 @@ public class MWMActivity extends NvEventQueueActivity
{
final String KmlMovedFlag = "KmlBeenMoved";
final String KitKatMigrationCompleted = "KitKatMigrationCompleted";
boolean kmlMoved = MWMApplication.get().nativeGetBoolean(KmlMovedFlag, false);
boolean mapsCpy = MWMApplication.get().nativeGetBoolean(KitKatMigrationCompleted, false);
final boolean kmlMoved = MWMApplication.get().nativeGetBoolean(KmlMovedFlag, false);
final boolean mapsCpy = MWMApplication.get().nativeGetBoolean(KitKatMigrationCompleted, false);
if (!kmlMoved)
{
@ -361,7 +361,7 @@ public class MWMActivity extends NvEventQueueActivity
}
};
if (StoragePathManager.CheckWritableDir(this, listener) == false)
ShowAlertDlg(R.string.kitkat_migrate_filed);
ShowAlertDlg(R.string.kitkat_migrate_failed);
}
}

View file

@ -238,12 +238,10 @@ public class StoragePathActivity extends MapsWithMeBaseListActivity
oldItem = m_items.get(m_current);
StoragePathManager.SetStoragePath(m_context, new StoragePathManager.SetStoragePathListener()
{
@Override
public void MoveFilesFinished(String newPath)
{
doUpdateAfterMove(newPath);
}
}, m_items.get(index), oldItem);

View file

@ -63,7 +63,10 @@ public class StoragePathManager
File primaryStorageDir = context.getExternalFilesDir(null);
for(File f : files)
{
if (!f.equals(primaryStorageDir))
// On kitkat and Greater we ignore private folder on primary storage
// like "PrimaryStorage/Android/data/com.mapswithme.maps.pro/file/" because
// we can write to root of PrimaryStorage/
if (f != null && !f.equals(primaryStorageDir))
pathes.add(f.getPath());
}
}
@ -127,7 +130,7 @@ public class StoragePathManager
approvedPathes.add(mwmPath);
}
String tmp[] = approvedPathes.toArray(new String[approvedPathes.size()]);
return nativeMoveBookmarks(tmp, getAvailablePath(nativeGetBookmarkDir()));
return nativeMoveBookmarks(tmp, getFreeBytesAtPath(nativeGetBookmarkDir()));
}
static public boolean CheckWritableDir(Context context, SetStoragePathListener listener)
@ -135,24 +138,18 @@ public class StoragePathManager
if (Utils.apiLowerThan(android.os.Build.VERSION_CODES.KITKAT))
return true;
String settingsDir = nativeGetSettingsDir();
String writableDir = nativeGetWritableDir();
final String settingsDir = nativeGetSettingsDir();
final String writableDir = nativeGetWritableDir();
if (settingsDir == writableDir)
if (settingsDir.equals(writableDir))
return true;
File f = new File(writableDir + "testDir");
f.mkdir();
if (f.exists())
{
// this path is writable. Don't try copy maps
f.delete();
if (isDirWritable(writableDir))
return true;
}
ArrayList<StorageItem> items = GetStorages(context, writableDir.replace(MWM_DIR_POSTFIX, ""),
final ArrayList<StorageItem> items = GetStorages(context, writableDir.replace(MWM_DIR_POSTFIX, ""),
settingsDir.replace(MWM_DIR_POSTFIX, ""));
long size = getDirSizeImpl(writableDir);
final long size = getDirSizeImpl(writableDir);
for (StorageItem item : items)
{
if (item.m_size > size)
@ -182,6 +179,21 @@ public class StoragePathManager
task.execute("");
}
static private boolean isDirWritable(String path)
{
final File f = new File(path + "/testDir");
f.mkdir();
// we can't only call canWrite, because on KitKat (Samsung S4) this return true
// for sdcard but actually it's read only
if (f.exists())
{
f.delete();
return true;
}
return false;
}
private static int VOLD_MODE = 1;
private static int MOUNTS_MODE = 2;
@ -252,22 +264,16 @@ public class StoragePathManager
final File f = new File(path + "/");
if (f.exists() && f.isDirectory() && f.canWrite())
{
// we can't only call canWrite, because on KitKat (Samsung S4) this return true
// for sdcard but actually it's read only
File ff = new File(path + "/" + "TestDir");
ff.mkdir();
if (!ff.exists())
if (!isDirWritable(path))
return false;
else
ff.delete();
for (StorageItem item : items)
{
if (item.m_path.equals(path))
return true;
}
final long size = getAvailablePath(path);
Log.i(TAG, "Available size = " + size);
final long size = getFreeBytesAtPath(path);
final StorageItem item = new StorageItem();
item.m_path = path;
@ -290,7 +296,7 @@ public class StoragePathManager
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
static private long getAvailablePath(String path)
static private long getFreeBytesAtPath(String path)
{
final StatFs stat = new StatFs(path);
final long size = Utils.apiLowerThan(android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Nezařazené";
"search_show_on_map" = "Zobrazit a mapě";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Unsortiert";
"search_show_on_map" = "Auf der Karte ansehen";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Unsorted";
"search_show_on_map" = "View on map";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Sin clasificar";
"search_show_on_map" = "Ver en el mapa";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Non classé";
"search_show_on_map" = "Afficher sur la carte";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Osztályozatlan";
"search_show_on_map" = "Megtekintés a térképen";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Non classificato";
"search_show_on_map" = "Visualizza sulla mappa";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "未分類";
"search_show_on_map" = "地図に表示";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "분류되지 않음";
"search_show_on_map" = "지도 보기";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Ongeclassificeerd";
"search_show_on_map" = "Op kaart bekijken";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Niesklasyfikowane";
"search_show_on_map" = "Zobacz na mapie";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Não classificado";
"search_show_on_map" = "Ver no mapa";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Без категории";
"search_show_on_map" = "Посмотреть на карте";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "Без категорії";
"search_show_on_map" = "Подивитись на карті";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -532,3 +532,11 @@
"placepage_unsorted" = "未分类的";
"search_show_on_map" = "在地图上查看";
"kitkat_migrate_ok" = "Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.";
"kitkat_migrate_failed" = "Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.";
"bookmark_move_fail" = "We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.";
"kitkat_optimization_in_progress" = "Your map storage is being optimized now. Please wait, it may take a few minutes.";

View file

@ -2355,7 +2355,7 @@
zh-Hant = 下載您目前所在位置的國家 (%@) 地圖
pl = Pobierz mapę kraju (%@), w którym aktualnie przebywasz
pt = Descarregue o país (%@) da sua localização atual
hu = Töltse le az aktuális helyzet országát (%@)
hu = Töltse le az aktuális helyzet országát (%@)
[download_viewport_country_to_search]
en = Download the country (%@) you are searching on
tags = ios,android
@ -3123,10 +3123,10 @@
ru = Посмотреть на карте
hu = Megtekintés a térképen
[kitkat_migrate_ok]
en = All maps been copyed. You can delete MapsWithMe folder from your sdcard
[kitkat_migrate_filed]
en = Not enough space for maps
en = Map data storage has been optimized. Please restart the app.\n\nMapsWithMe folder in the root of SD card is not needed anymore, you can delete it.
[kitkat_migrate_failed]
en = Due to changes in Android 4.4, we need to optimize map data storage, but there is no enough space to copy map data.\n\nPlease free up the memory, otherwise maps will be available in read-only mode.
[bookmark_move_fail]
en = Not enough space for bookmarks
en = We need to move your bookmarks to internal memory, but there is no available space for them. Please free up the memory, otherwise bookmarks wont be available.
[kitkat_optimization_in_progress]
en = Optimization. This can take several minutes.\nPlease wait…
en = Your map storage is being optimized now. Please wait, it may take a few minutes.