diff --git a/Flawless.Client/PathUtility.cs b/Flawless.Client/PathUtility.cs index a47cdfa..8734b82 100644 --- a/Flawless.Client/PathUtility.cs +++ b/Flawless.Client/PathUtility.cs @@ -21,8 +21,9 @@ public static class PathUtility => Path.Combine(SettingService.C.AppSetting.RepositoryPath, login, owner, repo, AppDefaultValues.RepoLocalStorageManagerFolder, AppDefaultValues.RepoLocalStorageDepotFolder); - public static string ConvertBytesToBestDisplay(ulong bytes) + 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; diff --git a/Flawless.Client/Service/LocalFileTreeAccessor.cs b/Flawless.Client/Service/LocalFileTreeAccessor.cs index 5acb415..ce957d2 100644 --- a/Flawless.Client/Service/LocalFileTreeAccessor.cs +++ b/Flawless.Client/Service/LocalFileTreeAccessor.cs @@ -124,14 +124,16 @@ public class LocalFileTreeAccessor if (!WorkPath.IsPathValid(workPath) || IgnoredDirectories.Any(d => workPath.StartsWith(d))) continue; - var modifyTime = File.GetLastWriteTimeUtc(f); - _currentFiles.Add(workPath, new WorkspaceFile { WorkPath = workPath, ModifyTime = modifyTime }); + var inf = new FileInfo(f); + _currentFiles.Add(workPath, new WorkspaceFile(inf.LastWriteTimeUtc, workPath, inf.Length)); } LastScanTimeUtc = DateTime.UtcNow; // Find those are changed - var changes = _currentFiles.Values.Where(v => _baseline.TryGetValue(v.WorkPath, out var fi) && fi.ModifyTime != v.ModifyTime); + var changes = _currentFiles.Values.Where(v => + _baseline.TryGetValue(v.WorkPath, out var fi) && + (fi.ModifyTime != v.ModifyTime || fi.Size != v.Size)); var news = _currentFiles.Values.Where(v => !_baseline.ContainsKey(v.WorkPath)); var removed = _baseline.Values.Where(v => !_currentFiles.ContainsKey(v.WorkPath)); diff --git a/Flawless.Client/Service/Remote_Generated.cs b/Flawless.Client/Service/Remote_Generated.cs index ab41d73..2daf58b 100644 --- a/Flawless.Client/Service/Remote_Generated.cs +++ b/Flawless.Client/Service/Remote_Generated.cs @@ -955,6 +955,9 @@ namespace Flawless.Client.Remote [JsonPropertyName("workPath")] public string WorkPath { get; set; } + + [JsonPropertyName("size")] + public long Size { get; set; } } diff --git a/Flawless.Client/Service/RepositoryFileTreeAccessor.cs b/Flawless.Client/Service/RepositoryFileTreeAccessor.cs index 7d6df58..526d309 100644 --- a/Flawless.Client/Service/RepositoryFileTreeAccessor.cs +++ b/Flawless.Client/Service/RepositoryFileTreeAccessor.cs @@ -156,7 +156,7 @@ public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable, IEnumer public IEnumerator GetEnumerator() { return _cached.Values - .Select(cv => new WorkspaceFile(cv.FileInfo.ModifyTime, cv.FileInfo.Path)).GetEnumerator(); + .Select(cv => new WorkspaceFile(cv.FileInfo.ModifyTime, cv.FileInfo.Path, (long)cv.FileInfo.Size)).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() diff --git a/Flawless.Client/Service/RepositoryService.cs b/Flawless.Client/Service/RepositoryService.cs index df9f7f7..f7ca449 100644 --- a/Flawless.Client/Service/RepositoryService.cs +++ b/Flawless.Client/Service/RepositoryService.cs @@ -1177,7 +1177,7 @@ public class RepositoryService : BaseService return new( rsp.ManifestId, rsp.Depot.Select(x => new DepotLabel(x.Id, x.Length)).ToArray(), - rsp.FilePaths.Select(x => new WorkspaceFile(x.ModifyTime.UtcDateTime, x.WorkPath)).ToArray()); + rsp.FilePaths.Select(x => new WorkspaceFile(x.ModifyTime.UtcDateTime, x.WorkPath, x.Size)).ToArray()); } catch (Exception e) { @@ -1205,8 +1205,8 @@ public class RepositoryService : BaseService return true; } - public async ValueTask CommitWorkspaceAsBaselineAsync - (RepositoryModel repo, IEnumerable changes, string message) + public async ValueTask CommitWorkspaceAsync + (RepositoryModel repo, IEnumerable changes, string message, bool forceBaseline = false) { // Check if current version is the latest var api = Api.C; @@ -1233,6 +1233,12 @@ public class RepositoryService : BaseService return null; } + // Decide create new depot, create full depot or create addon depot. + var changesSize = localDb.LocalAccessor.Changes.Values.Sum(x => (long) x.File.Size); + var hasAddOrModify = localDb.LocalAccessor.Changes.Any(x => + x.Value.Type == ChangeInfoType.Add || x.Value.Type == ChangeInfoType.Modify); + + // Generate depot var tempDepotPath = await CreateDepotIntoTempFileAsync(repo, manifestList); if (tempDepotPath == null) return null; diff --git a/Flawless.Client/ViewModels/RepositoryViewModel.cs b/Flawless.Client/ViewModels/RepositoryViewModel.cs index 5ae04b4..9453bf2 100644 --- a/Flawless.Client/ViewModels/RepositoryViewModel.cs +++ b/Flawless.Client/ViewModels/RepositoryViewModel.cs @@ -32,6 +32,8 @@ public partial class LocalChangesNode : ReactiveModel [Reactive] private DateTime? _modifiedTime; [Reactive] private LocalChangesNode? _parent; + + [Reactive] private long _size; public bool Included { @@ -59,7 +61,8 @@ public partial class LocalChangesNode : ReactiveModel Type = "Folder", FullPath = folderPath, Contents = new(), - Parent = parent + Parent = parent, + Size = -1 }; } @@ -70,7 +73,8 @@ public partial class LocalChangesNode : ReactiveModel Type = file.Type.ToString(), FullPath = file.File.WorkPath, ModifiedTime = file.File.ModifyTime, - Parent = parent + Parent = parent, + Size = (long) file.File.Size }; } } @@ -179,7 +183,7 @@ public partial class RepositoryViewModel : RoutableViewModelBase new TextColumn( "Size", - n => PathUtility.ConvertBytesToBestDisplay(GetFileSize(n))), + n => PathUtility.ConvertBytesToBestDisplay(n.Size)), new TextColumn( "ModifiedTime", n => n.ModifiedTime.HasValue ? n.ModifiedTime.Value.ToLocalTime() : null), @@ -221,9 +225,9 @@ public partial class RepositoryViewModel : RoutableViewModelBase "File Type", n => n.Contents != null ? "Folder" : Path.GetExtension(n.FullPath)), - new TextColumn( + new TextColumn( "Size", - n => 0), + n => PathUtility.ConvertBytesToBestDisplay(n.Size)), new TextColumn( "ModifiedTime", n => n.ModifiedTime.HasValue ? n.ModifiedTime.Value.ToLocalTime() : null), @@ -232,13 +236,6 @@ public partial class RepositoryViewModel : RoutableViewModelBase _ = StartupTasksAsync(); } - - private ulong GetFileSize(LocalChangesNode node) - { - if (!File.Exists(node.FullPath)) return 0; - var path = Path.Combine(_wsRoot, node.FullPath); - return (ulong)new FileInfo(path).Length; - } private async Task StartupTasksAsync() @@ -552,7 +549,7 @@ public partial class RepositoryViewModel : RoutableViewModelBase } using var l = UIHelper.MakeLoading("Committing changes..."); - var manifest = await RepositoryService.C.CommitWorkspaceAsBaselineAsync(Repository, changes, LocalDatabase.CommitMessage!); + var manifest = await RepositoryService.C.CommitWorkspaceAsync(Repository, changes, LocalDatabase.CommitMessage!); if (manifest == null) return; LocalDatabase.LocalAccessor.SetBaseline(manifest.Value.FilePaths); diff --git a/Flawless.Client/ViewModels/SettingViewModel.cs b/Flawless.Client/ViewModels/SettingViewModel.cs index 8f49063..55f3f75 100644 --- a/Flawless.Client/ViewModels/SettingViewModel.cs +++ b/Flawless.Client/ViewModels/SettingViewModel.cs @@ -76,6 +76,14 @@ public partial class SettingViewModel : RoutableViewModelBase { UIHelper.NotifyError(ex); } + + try + { + } + catch (Exception ex) + { + UIHelper.NotifyError(ex); + } } private async Task LoadClientSettings() diff --git a/Flawless.Client/Views/SettingView.axaml b/Flawless.Client/Views/SettingView.axaml index a0eae50..99a2ccc 100644 --- a/Flawless.Client/Views/SettingView.axaml +++ b/Flawless.Client/Views/SettingView.axaml @@ -42,16 +42,16 @@ - - - - - - + + + + + + + + - + @@ -84,11 +84,11 @@ -