winefile: Make it possible to translate the disk size units.

Francois Gouget fgouget at free.fr
Sat Nov 19 08:09:53 CST 2011


---
 programs/winefile/resource.h  |    3 +++
 programs/winefile/winefile.c  |   41 +++++++++++++++++++++++++++--------------
 programs/winefile/winefile.rc |    3 +++
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/programs/winefile/resource.h b/programs/winefile/resource.h
index 78509dc..83a6368 100644
--- a/programs/winefile/resource.h
+++ b/programs/winefile/resource.h
@@ -126,6 +126,9 @@
 #define IDS_COL_ATTR                    1217
 #define IDS_COL_SEC                     1218
 #define IDS_FREE_SPACE_FMT              1219
+#define IDS_UNIT_KB                     1220
+#define IDS_UNIT_MB                     1221
+#define IDS_UNIT_GB                     1222
 
 /* range for drive bar command ids: 0x9000..0x90FF */
 
diff --git a/programs/winefile/winefile.c b/programs/winefile/winefile.c
index 638adeb..7876da5 100644
--- a/programs/winefile/winefile.c
+++ b/programs/winefile/winefile.c
@@ -2751,21 +2751,34 @@ static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_fl
 
 static void format_bytes(LPWSTR buffer, LONGLONG bytes)
 {
-	static const WCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
-	static const WCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
-	static const WCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
-	static const WCHAR sFmtB[]  = {'%', 'u', 0};
-
-	float fBytes = (float)bytes;
-
-	if (bytes >= 1073741824)	/* 1 GB */
-		sprintfW(buffer, sFmtGB, fBytes/1073741824.f+.5f);
-	else if (bytes >= 1048576)	/* 1 MB */
-		sprintfW(buffer, sFmtMB, fBytes/1048576.f+.5f);
-	else if (bytes >= 1024)		/* 1 kB */
-		sprintfW(buffer, sFmtkB, fBytes/1024.f+.5f);
+	static const WCHAR sFmtSmall[]  = {'%', 'u', 0};
+	static const WCHAR sFmtBig[] = {'%', '.', '1', 'f', ' ', '%', 's', '\0'};
+
+	if (bytes < 1024)
+		sprintfW(buffer, sFmtSmall, (DWORD)bytes);
 	else
-		sprintfW(buffer, sFmtB, (DWORD)bytes);
+	{
+		WCHAR unit[64];
+		UINT resid;
+		float fBytes;
+		if (bytes >= 1073741824)	/* 1 GB */
+		{
+			fBytes = ((float)bytes)/1073741824.f+.5f;
+			resid = IDS_UNIT_GB;
+		}
+		else if (bytes >= 1048576)	/* 1 MB */
+		{
+			fBytes = ((float)bytes)/1048576.f+.5f;
+			resid = IDS_UNIT_MB;
+		}
+		else if (bytes >= 1024)		/* 1 kB */
+		{
+			fBytes = ((float)bytes)/1024.f+.5f;
+			resid = IDS_UNIT_KB;
+		}
+		LoadStringW(Globals.hInstance, resid, unit, sizeof(unit)/sizeof(*unit));
+		sprintfW(buffer, sFmtBig, fBytes, unit);
+	}
 }
 
 static void set_space_status(void)
diff --git a/programs/winefile/winefile.rc b/programs/winefile/winefile.rc
index 5d7638b..2384f3f 100644
--- a/programs/winefile/winefile.rc
+++ b/programs/winefile/winefile.rc
@@ -118,6 +118,9 @@ STRINGTABLE
     IDS_COL_SEC             "Security"
 
     IDS_FREE_SPACE_FMT      "%1 of %2 free"
+    IDS_UNIT_KB             "#msgctxt#unit kilobyte#kB"
+    IDS_UNIT_MB             "#msgctxt#unit megabyte#MB"
+    IDS_UNIT_GB             "#msgctxt#unit gigabyte#GB"
 }
 
 IDD_SELECT_DESTINATION DIALOG 15, 13, 210, 63
-- 
1.7.7.1




More information about the wine-patches mailing list