From 1bf440872ea70f85ac5e6f89cb54d922b35187a6 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 18 Jan 2012 23:21:09 +0000 Subject: [PATCH] repo: Cache folder sizes and update them after a sync. Closes #535 --- SparkleLib/Git/SparkleRepoGit.cs | 40 +++++++++++++++++---- SparkleShare/Mac/SparkleStatusIcon.cs | 4 +-- SparkleShare/SparkleStatusIcon.cs | 4 +-- SparkleShare/SparkleStatusIconController.cs | 11 +++--- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index cf8d7aef..a68cc8cb 100755 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -71,22 +71,48 @@ namespace SparkleLib { public override double Size { get { - return CalculateSize ( - new DirectoryInfo (LocalPath) - ); + string file_path = Path.Combine (LocalPath, ".git", "repo_size"); + + try { + return double.Parse (File.ReadAllText (file_path)); + + } catch { + return 0; + } } } public override double HistorySize { get { - return CalculateSize ( - new DirectoryInfo (Path.Combine (LocalPath, ".git")) - ); + string file_path = Path.Combine (LocalPath, ".git", "repo_history_size"); + + try { + return double.Parse (File.ReadAllText (file_path)); + + } catch { + return 0; + } } } + private void CalculateSizes () + { + double size = CalculateSize ( + new DirectoryInfo (LocalPath)); + + double history_size = CalculateSize ( + new DirectoryInfo (Path.Combine (LocalPath, ".git"))); + + string size_file_path = Path.Combine (LocalPath, ".git", "repo_size"); + string history_size_file_path = Path.Combine (LocalPath, ".git", "repo_history_size"); + + File.WriteAllText (size_file_path, size.ToString ()); + File.WriteAllText (history_size_file_path, history_size.ToString ()); + } + + public override string [] UnsyncedFilePaths { get { List file_paths = new List (); @@ -221,6 +247,7 @@ namespace SparkleLib { git.WaitForExit (); + CalculateSizes (); if (git.ExitCode == 0) return true; @@ -277,6 +304,7 @@ namespace SparkleLib { git.WaitForExit (); + CalculateSizes (); if (git.ExitCode == 0) { Rebase (); diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index d2d4a9cd..f0e75ef0 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -84,7 +84,7 @@ namespace SparkleShare { if (Controller.Folders.Length == 0) StateText = _("Welcome to SparkleShare!"); else - StateText = _("Up to date") + " — " + Controller.FolderSize; + StateText = _("Up to date") + Controller.FolderSize; CreateMenu (); @@ -102,7 +102,7 @@ namespace SparkleShare { if (Controller.Folders.Length == 0) StateText = _("Welcome to SparkleShare!"); else - StateText = _("Up to date") + " — " + Controller.FolderSize; + StateText = _("Up to date") + Controller.FolderSize; StateMenuItem.Title = StateText; CreateMenu (); diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index 844dcef1..4d70a5b2 100755 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -74,7 +74,7 @@ namespace SparkleShare { if (Controller.Folders.Length == 0) StateText = _("Welcome to SparkleShare!"); else - StateText = _("Up to date") + " — " + Controller.FolderSize; + StateText = _("Up to date") + Controller.FolderSize; CreateMenu (); @@ -88,7 +88,7 @@ namespace SparkleShare { if (Controller.Folders.Length == 0) StateText = _("Welcome to SparkleShare!"); else - StateText = _("Up to date") + " — " + Controller.FolderSize; + StateText = _("Up to date") + Controller.FolderSize; #if HAVE_APP_INDICATOR this.indicator.IconName = "process-syncing-sparkleshare-i"; diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index d53af998..e2a43999 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -50,19 +50,20 @@ namespace SparkleShare { get { double size = 0; - foreach (SparkleRepoBase repo in - Program.Controller.Repositories.GetRange (0, - Program.Controller.Repositories.Count)) { + Program.Controller.Repositories.GetRange ( + 0, Program.Controller.Repositories.Count)) { size += repo.Size + repo.HistorySize; } - return Program.Controller.FormatSize (size); + if (size == 0) + return ""; + else + return " — " + Program.Controller.FormatSize (size); } } - public int ProgressPercentage { get { return (int) Program.Controller.ProgressPercentage;