forked from organicmaps/organicmaps
[android] Fix bug with paths in DownloadResourcesActivity.
This commit is contained in:
parent
6a13b1841b
commit
4c4b9931fe
2 changed files with 23 additions and 43 deletions
|
@ -51,9 +51,9 @@ static shared_ptr<downloader::HttpRequest> g_currentRequest;
|
|||
|
||||
extern "C"
|
||||
{
|
||||
int HasSpaceForFiles(string const & sdcardPath, size_t fileSize)
|
||||
int HasSpaceForFiles(Platform & pl, string const & sdcardPath, size_t fileSize)
|
||||
{
|
||||
switch (GetPlatform().GetWritableStorageStatus(fileSize))
|
||||
switch (pl.GetWritableStorageStatus(fileSize))
|
||||
{
|
||||
case Platform::STORAGE_DISCONNECTED: return ERR_STORAGE_DISCONNECTED;
|
||||
case Platform::NOT_ENOUGH_SPACE: return ERR_NOT_ENOUGH_FREE_SPACE;
|
||||
|
@ -62,10 +62,10 @@ extern "C"
|
|||
}
|
||||
|
||||
// Check if we need to download mandatory resource file.
|
||||
bool NeedToDownload(string const & name, int size)
|
||||
bool NeedToDownload(Platform & pl, string const & name, int size)
|
||||
{
|
||||
uint64_t originSize = 0;
|
||||
if (!GetPlatform().GetFileSizeByName(name, originSize))
|
||||
if (!pl.GetFileSizeByName(name, originSize))
|
||||
{
|
||||
// no such file
|
||||
return true;
|
||||
|
@ -79,11 +79,19 @@ extern "C"
|
|||
|
||||
if (name == WORLD_FILE_NAME DATA_FILE_EXTENSION)
|
||||
{
|
||||
FilesContainerR cont(name);
|
||||
if (cont.IsReaderExist(SEARCH_INDEX_FILE_TAG))
|
||||
try
|
||||
{
|
||||
// World.mwm file has search index - can skip new version
|
||||
return false;
|
||||
FilesContainerR cont(pl.GetReader(name));
|
||||
if (cont.IsReaderExist(SEARCH_INDEX_FILE_TAG))
|
||||
{
|
||||
// World.mwm file has search index - can skip new version.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (RootException const &)
|
||||
{
|
||||
// Some error occurred when loading file.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (name == WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION)
|
||||
|
@ -97,38 +105,32 @@ extern "C"
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_DownloadResourcesActivity_getBytesToDownload(
|
||||
JNIEnv * env, jobject thiz, jstring apkPath, jstring sdcardPath)
|
||||
Java_com_mapswithme_maps_DownloadResourcesActivity_getBytesToDownload(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
// clear all
|
||||
g_filesToDownload.clear();
|
||||
g_totalBytesToDownload = 0;
|
||||
g_totalDownloadedBytes = 0;
|
||||
|
||||
//g_apkPath = jni::ToNativeString(env, apkPath);
|
||||
string const path = jni::ToNativeString(env, sdcardPath);
|
||||
|
||||
Platform & pl = GetPlatform();
|
||||
ReaderStreamBuf buffer(pl.GetReader("external_resources.txt"));
|
||||
string const path = pl.WritableDir();
|
||||
|
||||
ReaderStreamBuf buffer(pl.GetReader("external_resources.txt"));
|
||||
istream in(&buffer);
|
||||
|
||||
string name;
|
||||
int size;
|
||||
|
||||
while (true)
|
||||
{
|
||||
in >> name;
|
||||
|
||||
if (!in.good())
|
||||
break;
|
||||
|
||||
in >> size;
|
||||
|
||||
if (!in.good())
|
||||
break;
|
||||
|
||||
if (NeedToDownload(name, size))
|
||||
if (NeedToDownload(pl, name, size))
|
||||
{
|
||||
LOG(LDEBUG, ("Should download", name, "sized", size, "bytes"));
|
||||
|
||||
|
@ -142,7 +144,7 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
int const res = HasSpaceForFiles(path, g_totalBytesToDownload);
|
||||
int const res = HasSpaceForFiles(pl, path, g_totalBytesToDownload);
|
||||
switch (res)
|
||||
{
|
||||
case ERR_STORAGE_DISCONNECTED:
|
||||
|
|
|
@ -51,19 +51,6 @@ public class DownloadResourcesActivity extends Activity implements LocationServi
|
|||
private LocationService mLocationService = null;
|
||||
private String mCountryName = null;
|
||||
|
||||
private int getBytesToDownload()
|
||||
{
|
||||
return getBytesToDownload(mApplication.getApkPath(),
|
||||
mApplication.getDataStoragePath());
|
||||
}
|
||||
|
||||
private boolean isWorldExists()
|
||||
{
|
||||
// 2.0.3 version doesn't contain WorldCoasts on sdcard. No need to check something.
|
||||
//return isWorldExists(mApplication.getDataStoragePath());
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setDownloadMessage(int bytesToDownload)
|
||||
{
|
||||
Log.d(TAG, "prepareFilesDownload, bytesToDownload:" + bytesToDownload);
|
||||
|
@ -308,17 +295,8 @@ public class DownloadResourcesActivity extends Activity implements LocationServi
|
|||
|
||||
prepareFilesDownload();
|
||||
|
||||
switch (ConnectionState.getState(this))
|
||||
{
|
||||
case ConnectionState.CONNECTED_BY_WIFI:
|
||||
if (ConnectionState.getState(this) == ConnectionState.CONNECTED_BY_WIFI)
|
||||
onDownloadClicked(mDownloadButton);
|
||||
break;
|
||||
|
||||
case ConnectionState.NOT_CONNECTED:
|
||||
if (!isPro && isWorldExists())
|
||||
showMapView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,7 +406,7 @@ public class DownloadResourcesActivity extends Activity implements LocationServi
|
|||
}
|
||||
|
||||
private native void moveMaps(String fromFolder, String toFolder);
|
||||
private native int getBytesToDownload(String apkPath, String sdcardPath);
|
||||
private native int getBytesToDownload();
|
||||
private native boolean isWorldExists(String path);
|
||||
private native int startNextFileDownload(Object observer);
|
||||
private native String findCountryByPos(double lat, double lon);
|
||||
|
|
Loading…
Add table
Reference in a new issue