[android] Check files to download in sdcard and in apk. Minor changes.

This commit is contained in:
vng 2012-06-10 15:28:45 -07:00 committed by Alex Zolotarev
parent b2414734eb
commit 6825b9e482
3 changed files with 27 additions and 30 deletions

View file

@ -44,8 +44,8 @@ struct FileToDownload
uint64_t m_fileSize;
};
static string g_apkPath;
static string g_sdcardPath;
//static string g_apkPath;
//static string g_sdcardPath;
static vector<FileToDownload> g_filesToDownload;
static int g_totalDownloadedBytes;
static int g_totalBytesToDownload;
@ -53,11 +53,11 @@ static shared_ptr<downloader::HttpRequest> g_currentRequest;
extern "C"
{
int HasSpaceForFiles(size_t fileSize)
int HasSpaceForFiles(string const & sdcardPath, size_t fileSize)
{
struct statfs st;
if (statfs(g_sdcardPath.c_str(), &st) != 0)
if (statfs(sdcardPath.c_str(), &st) != 0)
return ERR_STORAGE_DISCONNECTED;
if (st.f_bsize * st.f_bavail <= fileSize)
@ -70,12 +70,13 @@ extern "C"
Java_com_mapswithme_maps_DownloadResourcesActivity_getBytesToDownload(JNIEnv * env, jobject thiz,
jstring apkPath, jstring sdcardPath)
{
g_apkPath = jni::ToNativeString(apkPath);
g_sdcardPath = jni::ToNativeString(sdcardPath);
//g_apkPath = jni::ToNativeString(apkPath);
string const path = jni::ToNativeString(sdcardPath);
jint totalBytesToDownload = 0;
int totalBytesToDownload = 0;
ReaderStreamBuf buffer(GetPlatform().GetReader("external_resources.txt"));
Platform & pl = GetPlatform();
ReaderStreamBuf buffer(pl.GetReader("external_resources.txt"));
istream in(&buffer);
@ -94,18 +95,16 @@ extern "C"
if (!in.good())
break;
FileToDownload f;
f.m_pathOnSdcard = g_sdcardPath + name;
f.m_fileName = name;
uint64_t sizeOnSdcard = 0;
Platform::GetFileSizeByFullPath(f.m_pathOnSdcard, sizeOnSdcard);
if (size != sizeOnSdcard)
uint64_t originSize = 0;
if (!pl.GetFileSizeByName(name, originSize) || size != originSize)
{
LOG(LDEBUG, ("should download : ", name, "sized", size, "bytes"));
LOG(LDEBUG, ("Should download", name, "sized", size, "bytes"));
FileToDownload f;
f.m_pathOnSdcard = path + name;
f.m_fileName = name;
f.m_fileSize = size;
g_filesToDownload.push_back(f);
totalBytesToDownload += size;
}
@ -113,7 +112,7 @@ extern "C"
g_totalDownloadedBytes = 0;
int res = HasSpaceForFiles(totalBytesToDownload);
int res = HasSpaceForFiles(path, totalBytesToDownload);
switch (res)
{

View file

@ -135,7 +135,7 @@ extern "C"
void OnProVersionServerReply(downloader::HttpRequest & r, shared_ptr<jobject> obj)
{
uint64_t curTime = time(0);
uint64_t const curTime = time(0);
if (r.Status() == downloader::HttpRequest::ECompleted)
{
@ -155,8 +155,6 @@ extern "C"
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onProVersionAvailable", "()V");
env->CallVoidMethod(*obj.get(), methodID);
return;
}
else
LOG(LDEBUG, ("ProVersion is not available, checkTime=", curTime));

View file

@ -201,17 +201,19 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
void checkProVersionAvailable()
{
if (nativeIsProVersion() || (nativeGetProVersionURL().length() != 0))
final boolean isPro = nativeIsProVersion();
// get pro-version url only for lite-version
final String url = isPro ? "" : nativeGetProVersionURL();
if (isPro || (url.length() != 0))
findViewById(R.id.map_button_search).setVisibility(View.VISIBLE);
if (!nativeIsProVersion() && (nativeGetProVersionURL().length() == 0))
if (!isPro && (url.length() == 0))
{
String commonServerURL = "http://redbutton.mapswithme.com/enable_search_banner_google_play";
String kindleServerURL = "http://redbutton.mapswithme.com/enable_search_banner_amazon_appstore";
if (android.os.Build.MODEL.equals("Kindle Fire"))
nativeCheckForProVersion(kindleServerURL);
nativeCheckForProVersion("http://redbutton.mapswithme.com/enable_search_banner_amazon_appstore");
else
nativeCheckForProVersion(commonServerURL);
nativeCheckForProVersion("http://redbutton.mapswithme.com/enable_search_banner_google_play");
}
}
@ -225,8 +227,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
{
AlertDialog alert = new AlertDialog.Builder(getCurrentContext()).create();
final Activity a = this;
alert.setMessage(message);
alert.setCancelable(false);