-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extra settings, import errors handling, packing all binary dependenci…
…es into single executable
- Loading branch information
1 parent
5aa1c37
commit 5d0ab4e
Showing
16 changed files
with
1,339 additions
and
908 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
using System.Globalization; | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace LibgenDesktop.Interface | ||
{ | ||
internal static class Formatters | ||
{ | ||
private static readonly NumberFormatInfo bookCountFormat; | ||
private static readonly NumberFormatInfo thousandsSeparatedNumberFormat; | ||
private static readonly string[] fileSizePostfixes; | ||
|
||
static Formatters() | ||
{ | ||
bookCountFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); | ||
bookCountFormat.NumberGroupSeparator = " "; | ||
thousandsSeparatedNumberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); | ||
thousandsSeparatedNumberFormat.NumberGroupSeparator = " "; | ||
fileSizePostfixes = new[] { "байт", "Кб", "Мб", "Гб", "Тб" }; | ||
} | ||
|
||
public static NumberFormatInfo BookCountFormat => bookCountFormat; | ||
public static NumberFormatInfo ThousandsSeparatedNumberFormat => thousandsSeparatedNumberFormat; | ||
|
||
public static string FileSizeToString(long fileSize, bool showBytes) | ||
{ | ||
int postfixIndex = fileSize != 0 ? (int)Math.Floor(Math.Log(fileSize) / Math.Log(1024)) : 0; | ||
StringBuilder resultBuilder = new StringBuilder(); | ||
resultBuilder.Append((fileSize / Math.Pow(1024, postfixIndex)).ToString("N2")); | ||
resultBuilder.Append(" "); | ||
resultBuilder.Append(fileSizePostfixes[postfixIndex]); | ||
if (showBytes && postfixIndex != 0) | ||
{ | ||
resultBuilder.Append(" ("); | ||
resultBuilder.Append(fileSize.ToString("N0", thousandsSeparatedNumberFormat)); | ||
resultBuilder.Append(" байт)"); | ||
} | ||
return resultBuilder.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.