Browse Source

get free space

dmuratshin 8 years ago
parent
commit
d06e9e8dd8

+ 8 - 1
oxygine/SDL/android/lib/src/org/oxygine/lib/Utils.java

@@ -9,7 +9,7 @@ import android.net.NetworkInfo;
 import android.net.Uri;
 import android.provider.Settings;
 import android.app.PendingIntent;
-
+import android.os.StatFs;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -22,6 +22,13 @@ public class Utils {
         return System.currentTimeMillis();
     }
 
+    public static long getFreeSpace(String path) {
+        StatFs fs = new StatFs(path);
+        long blocks = fs.getFreeBlocks();
+        long blsize = fs.getBlockSize();
+        return blocks * blsize;
+    }
+
     public static String getLanguage() {
         return Locale.getDefault().getLanguage();
     }

+ 1 - 0
oxygine/src/HttpRequestTask.h

@@ -57,6 +57,7 @@ namespace oxygine
         void setFileName(const std::string& name, bool continueDownload = false);
         void setCacheEnabled(bool enabled);
 
+
         void setResponseCodeChecker(const responseCodeChecker& f) {_responseCodeChecker = f;}
         void setSuccessOnAnyResponseCode(bool en);
 

+ 23 - 15
oxygine/src/core/android/jniUtils.cpp

@@ -14,6 +14,7 @@ jmethodID _jUtils_getLanguage = 0;
 jmethodID _jUtils_getPackage = 0;
 jmethodID _jUtils_getProperty = 0;
 jmethodID _jUtils_isNetworkAvailable = 0;
+jmethodID _jUtils_getFreeSpace = 0;
 jmethodID _jRunnable_run = 0;
 
 namespace oxygine
@@ -44,8 +45,11 @@ namespace oxygine
             _jUtils = (jclass)env->NewGlobalRef(env->FindClass("org/oxygine/lib/Utils"));
             JNI_NOT_NULL(_jUtils);
 
-            _jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
-            JNI_NOT_NULL(_jUtils_getTimeUTCMS);
+			_jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
+			JNI_NOT_NULL(_jUtils_getTimeUTCMS);
+
+			_jUtils_getFreeSpace = env->GetStaticMethodID(_jUtils, "getFreeSpace", "(Ljava/lang/String;)J");
+			JNI_NOT_NULL(_jUtils_getFreeSpace);
 
             _jUtils_getLanguage = env->GetStaticMethodID(_jUtils, "getLanguage", "()Ljava/lang/String;");
             JNI_NOT_NULL(_jUtils_getLanguage);
@@ -74,20 +78,11 @@ namespace oxygine
 
     int64 jniGetTimeUTCMS()
     {
-        try
-        {
-            JNIEnv* env = jniGetEnv();
-            LOCAL_REF_HOLDER(env);
-
-            jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getTimeUTCMS);
-            return value;
-        }
-        catch (const notFound&)
-        {
-
-        }
+        JNIEnv* env = jniGetEnv();
+        LOCAL_REF_HOLDER(env);
 
-        return 0;
+        jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getTimeUTCMS);
+        return value;
     }
 
     std::string     jniGetLanguage()
@@ -128,6 +123,19 @@ namespace oxygine
         return false;
     }
 
+
+	int64			jniGetFreeSpace(const char *path)
+	{
+		JNIEnv* env = jniGetEnv();
+		LOCAL_REF_HOLDER(env);
+
+		jstring jarg = env->NewStringUTF(path);
+		jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getFreeSpace, jarg);
+		return value;
+
+		
+	}
+
     bool            jniExit()
     {
         try

+ 2 - 0
oxygine/src/core/android/jniUtils.h

@@ -18,6 +18,8 @@ namespace oxygine
     std::string     jniGetPackage();
     bool            jniIsNetworkAvailable();
 
+	int64			jniGetFreeSpace(const char *);
+
     bool            jniExit();
     void            jniRestartApp();
     void            jniMoveTaskToBack();

+ 14 - 1
oxygine/src/core/oxygine.cpp

@@ -16,6 +16,7 @@
 #include "DebugActor.h"
 #include "Stage.h"
 #include "KeyEvent.h"
+#include "STDFileSystem.h"
 #include "res/ResStarlingAtlas.h"
 
 
@@ -1012,7 +1013,19 @@ namespace oxygine
         return true;
     }
 
-    std::string     getLanguage()
+	int64 getFreeSpace(const char *fullpath /*= 0*/)
+	{
+#ifdef __ANDROID__
+		if (fullpath)
+			return jniGetFreeSpace(fullpath);
+		return jniGetFreeSpace(file::wfs().getFullPath("").c_str());
+#else
+#endif
+		return 123;
+		return std::numeric_limits<int64>::max();
+	}
+
+	std::string     getLanguage()
     {
 #ifdef __ANDROID__
         return jniGetLanguage();

+ 3 - 0
oxygine/src/core/oxygine.h

@@ -31,6 +31,9 @@ namespace oxygine
     /** is any network connection available?*/
     bool            isNetworkAvailable();
 
+
+	int64			getFreeSpace(const char *fullpath = 0);
+
     /**returns locale. ISO 639-1 */
     std::string     getLanguage();