1
0

43 lines
1.7 KiB
C#

using System.IO;
using Flawless.Client.Service;
namespace Flawless.Client;
public static class PathUtility
{
public static string GetWorkspacePath(string login, string owner, string repo)
=> Path.Combine(SettingService.C.AppSetting.RepositoryPath, login, owner, repo);
public static string GetWorkspaceManagerPath(string login, string owner, string repo)
=> Path.Combine(SettingService.C.AppSetting.RepositoryPath, login, owner, repo, AppDefaultValues.RepoLocalStorageManagerFolder);
public static string GetWorkspaceDbPath(string login, string owner, string repo)
=> Path.Combine(SettingService.C.AppSetting.RepositoryPath, login, owner, repo,
AppDefaultValues.RepoLocalStorageManagerFolder, AppDefaultValues.RepoLocalStorageDatabaseFile);
public static string GetWorkspaceDepotCachePath(string login, string owner, string repo)
=> Path.Combine(SettingService.C.AppSetting.RepositoryPath, login, owner, repo,
AppDefaultValues.RepoLocalStorageManagerFolder, AppDefaultValues.RepoLocalStorageDepotFolder);
public static string ConvertBytesToBestDisplay(long bytes)
{
if (bytes < 0) return string.Empty;
string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
int unitIndex = 0;
double size = bytes;
if (bytes <= 0) return "0B"; // 处理零值和负值[6,7](@ref)
// 单位递进计算[6](@ref)
while (size >= 1024 && unitIndex < units.Length - 1)
{
size /= 1024.0;
unitIndex++;
}
// 智能格式化输出[6,7](@ref)
return $"{size:0.#}{units[unitIndex]}";
}
}