Skip to content

Commit 66cc669

Browse files
authored
Add ability to convert size abbreviations and translate them (#1151)
1 parent 0860675 commit 66cc669

22 files changed

+382
-20
lines changed

Common/ShellFileItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public class ShellFileItem
1010
public string FilePath;
1111
public DateTime RecycleDate;
1212
public string FileSize;
13-
public ulong FileSizeBytes;
13+
public long FileSizeBytes;
1414
public string FileType;
1515

1616
public ShellFileItem()
1717
{
1818
}
1919

20-
public ShellFileItem(bool isFolder, string recyclePath, string fileName, string filePath, DateTime recycleDate, string fileSize, ulong fileSizeBytes, string fileType)
20+
public ShellFileItem(bool isFolder, string recyclePath, string fileName, string filePath, DateTime recycleDate, string fileSize, long fileSizeBytes, string fileType)
2121
{
2222
this.IsFolder = isFolder;
2323
this.RecyclePath = recyclePath;

Files.Launcher/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private static async void Connection_RequestReceived(AppServiceConnection sender
213213
var dt = (System.Runtime.InteropServices.ComTypes.FILETIME)folderItem.Properties[Vanara.PInvoke.Ole32.PROPERTYKEY.System.DateCreated];
214214
var recycleDate = dt.ToDateTime().ToLocalTime(); // This is LocalTime
215215
string fileSize = folderItem.Properties.GetPropertyString(Vanara.PInvoke.Ole32.PROPERTYKEY.System.Size);
216-
ulong fileSizeBytes = (ulong)folderItem.Properties[Vanara.PInvoke.Ole32.PROPERTYKEY.System.Size];
216+
long fileSizeBytes = (long)folderItem.Properties[Vanara.PInvoke.Ole32.PROPERTYKEY.System.Size];
217217
string fileType = (string)folderItem.Properties[Vanara.PInvoke.Ole32.PROPERTYKEY.System.ItemTypeText];
218218
bool isFolder = folderItem.IsFolder && Path.GetExtension(folderItem.Name) != ".zip";
219219
folderContentsList.Add(new ShellFileItem(isFolder, recyclePath, fileName, filePath, recycleDate, fileSize, fileSizeBytes, fileType));

Files/Filesystem/DriveItem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ByteSizeLib;
2+
using Files.Helpers;
23
using System;
34
using System.Threading.Tasks;
45
using Windows.Storage;
@@ -54,8 +55,8 @@ public DriveItem(StorageFolder root, DriveType type)
5455
SpaceUsed = MaxSpace - FreeSpace;
5556
SpaceText = string.Format(
5657
ResourceController.GetTranslation("DriveFreeSpaceAndCapacity"),
57-
FreeSpace.ToBinaryString(),
58-
MaxSpace.ToBinaryString());
58+
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
59+
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
5960
}
6061
catch (NullReferenceException)
6162
{

Files/Filesystem/ListedItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public string ItemType
9090
public string FileExtension { get; set; }
9191
public string ItemPath { get; set; }
9292
public string FileSize { get; set; }
93-
public ulong FileSizeBytes { get; set; }
93+
public long FileSizeBytes { get; set; }
9494

9595
// For recycle bin elements (path + name)
9696
public string ItemOriginalPath { get; set; }

Files/Helpers/StringExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using JetBrains.Annotations;
22
using System;
3+
using System.Collections.Generic;
34
using System.IO;
45

56
namespace Files.Helpers
@@ -64,5 +65,24 @@ public static string Right([NotNull] this string value, int length)
6465

6566
return (length < value.Length) ? value.Substring(value.Length - length) : value;
6667
}
68+
69+
private static readonly Dictionary<string, string> abbreviations = new Dictionary<string, string>()
70+
{
71+
{ "KiB", ResourceController.GetTranslation("KiloByteSymbol") },
72+
{ "MiB", ResourceController.GetTranslation("MegaByteSymbol") },
73+
{ "GiB", ResourceController.GetTranslation("GigaByteSymbol") },
74+
{ "TiB", ResourceController.GetTranslation("TeraByteSymbol") },
75+
{ "PiB", ResourceController.GetTranslation("PetaByteSymbol") },
76+
{ "B", ResourceController.GetTranslation("ByteSymbol") }
77+
};
78+
79+
public static string ConvertSizeAbbreviation(this string value)
80+
{
81+
foreach (var item in abbreviations)
82+
{
83+
value = value.Replace(item.Key, item.Value);
84+
}
85+
return value;
86+
}
6787
}
6888
}

Files/MultilingualResources/Files.de-DE.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,30 @@
837837
<source>bytes</source>
838838
<target state="new">bytes</target>
839839
</trans-unit>
840+
<trans-unit id="KiloByteSymbol" translate="yes" xml:space="preserve">
841+
<source>KB</source>
842+
<target state="new">KB</target>
843+
</trans-unit>
844+
<trans-unit id="MegaByteSymbol" translate="yes" xml:space="preserve">
845+
<source>MB</source>
846+
<target state="new">MB</target>
847+
</trans-unit>
848+
<trans-unit id="GigaByteSymbol" translate="yes" xml:space="preserve">
849+
<source>GB</source>
850+
<target state="new">GB</target>
851+
</trans-unit>
852+
<trans-unit id="TeraByteSymbol" translate="yes" xml:space="preserve">
853+
<source>TB</source>
854+
<target state="new">TB</target>
855+
</trans-unit>
856+
<trans-unit id="PetaByteSymbol" translate="yes" xml:space="preserve">
857+
<source>PB</source>
858+
<target state="new">PB</target>
859+
</trans-unit>
860+
<trans-unit id="ByteSymbol" translate="yes" xml:space="preserve">
861+
<source>B</source>
862+
<target state="new">B</target>
863+
</trans-unit>
840864
</group>
841865
</body>
842866
</file>

Files/MultilingualResources/Files.es-ES.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,30 @@
830830
<source>bytes</source>
831831
<target state="new">bytes</target>
832832
</trans-unit>
833+
<trans-unit id="KiloByteSymbol" translate="yes" xml:space="preserve">
834+
<source>KB</source>
835+
<target state="new">KB</target>
836+
</trans-unit>
837+
<trans-unit id="MegaByteSymbol" translate="yes" xml:space="preserve">
838+
<source>MB</source>
839+
<target state="new">MB</target>
840+
</trans-unit>
841+
<trans-unit id="GigaByteSymbol" translate="yes" xml:space="preserve">
842+
<source>GB</source>
843+
<target state="new">GB</target>
844+
</trans-unit>
845+
<trans-unit id="TeraByteSymbol" translate="yes" xml:space="preserve">
846+
<source>TB</source>
847+
<target state="new">TB</target>
848+
</trans-unit>
849+
<trans-unit id="PetaByteSymbol" translate="yes" xml:space="preserve">
850+
<source>PB</source>
851+
<target state="new">PB</target>
852+
</trans-unit>
853+
<trans-unit id="ByteSymbol" translate="yes" xml:space="preserve">
854+
<source>B</source>
855+
<target state="new">B</target>
856+
</trans-unit>
833857
</group>
834858
</body>
835859
</file>

Files/MultilingualResources/Files.fr-FR.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,30 @@
833833
<source>bytes</source>
834834
<target state="new">bytes</target>
835835
</trans-unit>
836+
<trans-unit id="KiloByteSymbol" translate="yes" xml:space="preserve">
837+
<source>KB</source>
838+
<target state="new">KB</target>
839+
</trans-unit>
840+
<trans-unit id="MegaByteSymbol" translate="yes" xml:space="preserve">
841+
<source>MB</source>
842+
<target state="new">MB</target>
843+
</trans-unit>
844+
<trans-unit id="GigaByteSymbol" translate="yes" xml:space="preserve">
845+
<source>GB</source>
846+
<target state="new">GB</target>
847+
</trans-unit>
848+
<trans-unit id="TeraByteSymbol" translate="yes" xml:space="preserve">
849+
<source>TB</source>
850+
<target state="new">TB</target>
851+
</trans-unit>
852+
<trans-unit id="PetaByteSymbol" translate="yes" xml:space="preserve">
853+
<source>PB</source>
854+
<target state="new">PB</target>
855+
</trans-unit>
856+
<trans-unit id="ByteSymbol" translate="yes" xml:space="preserve">
857+
<source>B</source>
858+
<target state="new">B</target>
859+
</trans-unit>
836860
</group>
837861
</body>
838862
</file>

Files/MultilingualResources/Files.it-IT.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,30 @@
837837
<source>bytes</source>
838838
<target state="new">bytes</target>
839839
</trans-unit>
840+
<trans-unit id="KiloByteSymbol" translate="yes" xml:space="preserve">
841+
<source>KB</source>
842+
<target state="new">KB</target>
843+
</trans-unit>
844+
<trans-unit id="MegaByteSymbol" translate="yes" xml:space="preserve">
845+
<source>MB</source>
846+
<target state="new">MB</target>
847+
</trans-unit>
848+
<trans-unit id="GigaByteSymbol" translate="yes" xml:space="preserve">
849+
<source>GB</source>
850+
<target state="new">GB</target>
851+
</trans-unit>
852+
<trans-unit id="TeraByteSymbol" translate="yes" xml:space="preserve">
853+
<source>TB</source>
854+
<target state="new">TB</target>
855+
</trans-unit>
856+
<trans-unit id="PetaByteSymbol" translate="yes" xml:space="preserve">
857+
<source>PB</source>
858+
<target state="new">PB</target>
859+
</trans-unit>
860+
<trans-unit id="ByteSymbol" translate="yes" xml:space="preserve">
861+
<source>B</source>
862+
<target state="new">B</target>
863+
</trans-unit>
840864
</group>
841865
</body>
842866
</file>

Files/MultilingualResources/Files.ja-JP.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,30 @@
830830
<source>bytes</source>
831831
<target state="new">bytes</target>
832832
</trans-unit>
833+
<trans-unit id="KiloByteSymbol" translate="yes" xml:space="preserve">
834+
<source>KB</source>
835+
<target state="new">KB</target>
836+
</trans-unit>
837+
<trans-unit id="MegaByteSymbol" translate="yes" xml:space="preserve">
838+
<source>MB</source>
839+
<target state="new">MB</target>
840+
</trans-unit>
841+
<trans-unit id="GigaByteSymbol" translate="yes" xml:space="preserve">
842+
<source>GB</source>
843+
<target state="new">GB</target>
844+
</trans-unit>
845+
<trans-unit id="TeraByteSymbol" translate="yes" xml:space="preserve">
846+
<source>TB</source>
847+
<target state="new">TB</target>
848+
</trans-unit>
849+
<trans-unit id="PetaByteSymbol" translate="yes" xml:space="preserve">
850+
<source>PB</source>
851+
<target state="new">PB</target>
852+
</trans-unit>
853+
<trans-unit id="ByteSymbol" translate="yes" xml:space="preserve">
854+
<source>B</source>
855+
<target state="new">B</target>
856+
</trans-unit>
833857
</group>
834858
</body>
835859
</file>

0 commit comments

Comments
 (0)