Просмотр исходного кода

Move GetFileSizeString() to StringUtils.

Yao Wei Tjong 姚伟忠 10 лет назад
Родитель
Сommit
d7bc2d6a0d

+ 1 - 0
Source/Urho3D/AngelScript/CoreAPI.cpp

@@ -719,6 +719,7 @@ static void RegisterStringUtils(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("bool IsAlpha(uint)", asFUNCTION(IsAlpha), asCALL_CDECL);
     engine->RegisterGlobalFunction("uint ToUpper(uint)", asFUNCTION(ToUpper), asCALL_CDECL);
     engine->RegisterGlobalFunction("uint ToLower(uint)", asFUNCTION(ToLower), asCALL_CDECL);
+    engine->RegisterGlobalFunction("String GetFileSizeString(uint64)", asFUNCTION(GetFileSizeString), asCALL_CDECL);
 }
 
 static void ConstructTimer(Timer* ptr)

+ 0 - 1
Source/Urho3D/AngelScript/IOAPI.cpp

@@ -351,7 +351,6 @@ void RegisterFileSystem(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("String GetParentPath(const String&in)", asFUNCTION(GetParentPath), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetInternalPath(const String&in)", asFUNCTION(GetInternalPath), asCALL_CDECL);
     engine->RegisterGlobalFunction("bool IsAbsolutePath(const String&in)", asFUNCTION(IsAbsolutePath), asCALL_CDECL);
-    engine->RegisterGlobalFunction("String GetFileSizeString(uint64)", asFUNCTION(GetFileSizeString), asCALL_CDECL);
 }
 
 static PackageFile* ConstructPackageFile()

+ 25 - 0
Source/Urho3D/Core/StringUtils.cpp

@@ -667,4 +667,29 @@ unsigned ToLower(unsigned ch)
     return (unsigned)tolower(ch);
 }
 
+String GetFileSizeString(unsigned long long memorySize)
+{
+    static const char* memorySizeStrings = "kMGTPE";
+
+    String output;
+
+    if (memorySize < 1024)
+    {
+        output = String(memorySize) + " b";
+    }
+    else
+    {
+        const int exponent = (int)(log(memorySize) / log(1024));
+        const double majorValue = ((double)memorySize) / pow(1024, exponent);
+        char buffer[64];
+        memset(buffer, 0, 64);
+        sprintf(buffer, "%.1f", majorValue);
+        output = buffer;
+        output += " ";
+        output += memorySizeStrings[exponent - 1];
+    }
+
+    return output;
+}
+
 }

+ 2 - 0
Source/Urho3D/Core/StringUtils.h

@@ -121,5 +121,7 @@ URHO3D_API bool IsDigit(unsigned ch);
 URHO3D_API unsigned ToUpper(unsigned ch);
 /// Return char in lowercase.
 URHO3D_API unsigned ToLower(unsigned ch);
+/// Convert a memory size into a formatted size string, of the style "1.5 Mb".
+URHO3D_API String GetFileSizeString(unsigned long long memorySize);
 
 }

+ 0 - 26
Source/Urho3D/IO/FileSystem.cpp

@@ -1068,30 +1068,4 @@ bool IsAbsolutePath(const String& pathName)
     return false;
 }
 
-/// Convert a memory size into a formatted size string, of the style "1.5 Mb"
-String GetFileSizeString(unsigned long long memorySize)
-{
-    const char* memorySizeStrings = "kMGTPE";
-
-    String output;
-
-    if (memorySize < 1024)
-    {
-        output = String(memorySize) + " b";
-    }
-    else
-    {
-        const int exponent = (int)(log(memorySize) / log(1024));
-        const double majorValue = ((double)memorySize) / pow(1024, exponent);
-        char buffer[64];
-        memset(buffer, 0, 64);
-        sprintf(buffer, "%.1f", majorValue);
-        output = buffer;
-        output += " ";
-        output += (char)(memorySizeStrings[exponent - 1]);
-    }
-
-    return output;
-}
-
 }

+ 0 - 2
Source/Urho3D/IO/FileSystem.h

@@ -150,7 +150,5 @@ URHO3D_API String GetNativePath(const String& pathName);
 URHO3D_API WString GetWideNativePath(const String& pathName);
 /// Return whether a path is absolute.
 URHO3D_API bool IsAbsolutePath(const String& pathName);
-/// Convert a memory size into a formatted size string, of the style "1.5 Mb"
-URHO3D_API String GetFileSizeString(unsigned long long memorySize);
 
 }

+ 3 - 5
Source/Urho3D/Resource/ResourceCache.cpp

@@ -36,12 +36,10 @@
 #include "../Resource/PListFile.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/ResourceEvents.h"
-#include "../Container/Sort.h"
 #include "../Resource/XMLFile.h"
 
 #include "../DebugNew.h"
 
-#include <cstring>
 #include <cstdio>
 
 namespace Urho3D
@@ -496,7 +494,7 @@ SharedPtr<File> ResourceCache::GetFile(const String& nameIn, bool sendEventOnFai
             resourceRouters_[i]->Route(name, RESOURCE_GETFILE);
         isRouting_ = false;
     }
-    
+
     if (name.Length())
     {
         File* file = 0;
@@ -937,9 +935,9 @@ String ResourceCache::PrintMemoryUsage() const
             if (largest > totalLargest)
                 totalLargest = largest;
         }
-        
+
         totalResourceCt += resourceCt;
-        
+
         const String countString(cit->second_.resources_.Size());
         const String memUseString = GetFileSizeString(average);
         const String memMaxString = GetFileSizeString(largest);