repo: Cache folder sizes and update them after a sync. Closes #535
This commit is contained in:
parent
cc609aedcc
commit
2a98aec8c7
|
@ -71,22 +71,48 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public override double Size {
|
public override double Size {
|
||||||
get {
|
get {
|
||||||
return CalculateSize (
|
string file_path = Path.Combine (LocalPath, ".git", "repo_size");
|
||||||
new DirectoryInfo (LocalPath)
|
|
||||||
);
|
try {
|
||||||
|
return double.Parse (File.ReadAllText (file_path));
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override double HistorySize {
|
public override double HistorySize {
|
||||||
get {
|
get {
|
||||||
return CalculateSize (
|
string file_path = Path.Combine (LocalPath, ".git", "repo_history_size");
|
||||||
new DirectoryInfo (Path.Combine (LocalPath, ".git"))
|
|
||||||
);
|
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 {
|
public override string [] UnsyncedFilePaths {
|
||||||
get {
|
get {
|
||||||
List<string> file_paths = new List<string> ();
|
List<string> file_paths = new List<string> ();
|
||||||
|
@ -221,6 +247,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
|
CalculateSizes ();
|
||||||
|
|
||||||
if (git.ExitCode == 0)
|
if (git.ExitCode == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -277,6 +304,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
|
CalculateSizes ();
|
||||||
|
|
||||||
if (git.ExitCode == 0) {
|
if (git.ExitCode == 0) {
|
||||||
Rebase ();
|
Rebase ();
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace SparkleShare {
|
||||||
if (Controller.Folders.Length == 0)
|
if (Controller.Folders.Length == 0)
|
||||||
StateText = _("Welcome to SparkleShare!");
|
StateText = _("Welcome to SparkleShare!");
|
||||||
else
|
else
|
||||||
StateText = _("Up to date") + " — " + Controller.FolderSize;
|
StateText = _("Up to date") + Controller.FolderSize;
|
||||||
|
|
||||||
CreateMenu ();
|
CreateMenu ();
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace SparkleShare {
|
||||||
if (Controller.Folders.Length == 0)
|
if (Controller.Folders.Length == 0)
|
||||||
StateText = _("Welcome to SparkleShare!");
|
StateText = _("Welcome to SparkleShare!");
|
||||||
else
|
else
|
||||||
StateText = _("Up to date") + " — " + Controller.FolderSize;
|
StateText = _("Up to date") + Controller.FolderSize;
|
||||||
|
|
||||||
StateMenuItem.Title = StateText;
|
StateMenuItem.Title = StateText;
|
||||||
CreateMenu ();
|
CreateMenu ();
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace SparkleShare {
|
||||||
if (Controller.Folders.Length == 0)
|
if (Controller.Folders.Length == 0)
|
||||||
StateText = _("Welcome to SparkleShare!");
|
StateText = _("Welcome to SparkleShare!");
|
||||||
else
|
else
|
||||||
StateText = _("Up to date") + " — " + Controller.FolderSize;
|
StateText = _("Up to date") + Controller.FolderSize;
|
||||||
|
|
||||||
CreateMenu ();
|
CreateMenu ();
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ namespace SparkleShare {
|
||||||
if (Controller.Folders.Length == 0)
|
if (Controller.Folders.Length == 0)
|
||||||
StateText = _("Welcome to SparkleShare!");
|
StateText = _("Welcome to SparkleShare!");
|
||||||
else
|
else
|
||||||
StateText = _("Up to date") + " — " + Controller.FolderSize;
|
StateText = _("Up to date") + Controller.FolderSize;
|
||||||
|
|
||||||
#if HAVE_APP_INDICATOR
|
#if HAVE_APP_INDICATOR
|
||||||
this.indicator.IconName = "process-syncing-sparkleshare-i";
|
this.indicator.IconName = "process-syncing-sparkleshare-i";
|
||||||
|
|
|
@ -50,19 +50,20 @@ namespace SparkleShare {
|
||||||
get {
|
get {
|
||||||
double size = 0;
|
double size = 0;
|
||||||
|
|
||||||
|
|
||||||
foreach (SparkleRepoBase repo in
|
foreach (SparkleRepoBase repo in
|
||||||
Program.Controller.Repositories.GetRange (0,
|
Program.Controller.Repositories.GetRange (
|
||||||
Program.Controller.Repositories.Count)) {
|
0, Program.Controller.Repositories.Count)) {
|
||||||
|
|
||||||
size += repo.Size + repo.HistorySize;
|
size += repo.Size + repo.HistorySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Program.Controller.FormatSize (size);
|
if (size == 0)
|
||||||
|
return "";
|
||||||
|
else
|
||||||
|
return " — " + Program.Controller.FormatSize (size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int ProgressPercentage {
|
public int ProgressPercentage {
|
||||||
get {
|
get {
|
||||||
return (int) Program.Controller.ProgressPercentage;
|
return (int) Program.Controller.ProgressPercentage;
|
||||||
|
|
Loading…
Reference in a new issue