event log: report size and history size. Closes #379
This commit is contained in:
parent
3f70f08084
commit
a4d1e5d120
|
@ -59,6 +59,24 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public override double Size {
|
||||
get {
|
||||
return CalculateSize (
|
||||
new DirectoryInfo (LocalPath)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override double HistorySize {
|
||||
get {
|
||||
return CalculateSize (
|
||||
new DirectoryInfo (Path.Combine (LocalPath, ".git"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string [] UnsyncedFilePaths {
|
||||
get {
|
||||
List<string> file_paths = new List<string> ();
|
||||
|
@ -638,5 +656,38 @@ namespace SparkleLib {
|
|||
base.CreateInitialChangeSet ();
|
||||
SyncUp ();
|
||||
}
|
||||
|
||||
|
||||
// Recursively gets a folder's size in bytes
|
||||
public override double CalculateSize (DirectoryInfo parent)
|
||||
{
|
||||
if (!Directory.Exists (parent.ToString ()))
|
||||
return 0;
|
||||
|
||||
double size = 0;
|
||||
|
||||
// Ignore the temporary 'rebase-apply' and '.tmp' directories. This prevents potential
|
||||
// crashes when files are being queried whilst the files have already been deleted.
|
||||
if (parent.Name.Equals ("rebase-apply") ||
|
||||
parent.Name.Equals (".tmp"))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
foreach (FileInfo file in parent.GetFiles()) {
|
||||
if (!file.Exists)
|
||||
return 0;
|
||||
|
||||
size += file.Length;
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo directory in parent.GetDirectories ())
|
||||
size += CalculateSize (directory);
|
||||
|
||||
} catch (Exception) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,8 +64,12 @@ namespace SparkleLib {
|
|||
public abstract string CurrentRevision { get; }
|
||||
public abstract bool SyncUp ();
|
||||
public abstract bool SyncDown ();
|
||||
public abstract double CalculateSize (DirectoryInfo parent);
|
||||
public abstract bool HasUnsyncedChanges { get; set; }
|
||||
|
||||
public abstract double Size { get; }
|
||||
public abstract double HistorySize { get; }
|
||||
|
||||
public delegate void SyncStatusChangedEventHandler (SyncStatus new_status);
|
||||
public event SyncStatusChangedEventHandler SyncStatusChanged;
|
||||
|
||||
|
@ -309,7 +313,7 @@ namespace SparkleLib {
|
|||
this.sizebuffer.RemoveAt (0);
|
||||
|
||||
DirectoryInfo dir_info = new DirectoryInfo (LocalPath);
|
||||
this.sizebuffer.Add (CalculateFolderSize (dir_info));
|
||||
this.sizebuffer.Add (CalculateSize (dir_info));
|
||||
|
||||
if (this.sizebuffer.Count >= 4 &&
|
||||
this.sizebuffer [0].Equals (this.sizebuffer [1]) &&
|
||||
|
@ -588,33 +592,6 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
// Recursively gets a folder's size in bytes
|
||||
private double CalculateFolderSize (DirectoryInfo parent)
|
||||
{
|
||||
if (!System.IO.Directory.Exists (parent.ToString ()))
|
||||
return 0;
|
||||
|
||||
double size = 0;
|
||||
|
||||
// Ignore the temporary 'rebase-apply' directory. This prevents potential
|
||||
// crashes when files are being queried whilst the files have already been deleted.
|
||||
if (parent.Name.Equals ("rebase-apply"))
|
||||
return 0;
|
||||
|
||||
foreach (FileInfo file in parent.GetFiles ()) {
|
||||
if (!file.Exists)
|
||||
return 0;
|
||||
|
||||
size += file.Length;
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo directory in parent.GetDirectories())
|
||||
size += CalculateFolderSize (directory);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
// Creates a SHA-1 hash of input
|
||||
private string SHA1 (string s)
|
||||
{
|
||||
|
|
|
@ -35,14 +35,17 @@ namespace SparkleShare {
|
|||
PolicyDelegate = new SparkleWebPolicyDelegate ()
|
||||
};
|
||||
|
||||
private NSBox Separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
|
||||
private NSBox separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
|
||||
BorderColor = NSColor.LightGray,
|
||||
BoxType = NSBoxType.NSBoxCustom
|
||||
};
|
||||
|
||||
private NSPopUpButton popup_button;
|
||||
private NSProgressIndicator progress_indicator;
|
||||
|
||||
private NSTextField size_label;
|
||||
private NSTextField size_label_value;
|
||||
private NSTextField history_label;
|
||||
private NSTextField history_label_value;
|
||||
|
||||
public SparkleEventLog (IntPtr handle) : base (handle) { }
|
||||
|
||||
|
@ -64,7 +67,54 @@ namespace SparkleShare {
|
|||
HasShadow = true;
|
||||
BackingType = NSBackingStore.Buffered;
|
||||
|
||||
ContentView.AddSubview (Separator);
|
||||
|
||||
this.size_label = new NSTextField () {
|
||||
Alignment = NSTextAlignment.Right,
|
||||
BackgroundColor = NSColor.WindowBackground,
|
||||
Bordered = false,
|
||||
Editable = false,
|
||||
Frame = new RectangleF (0, 588, 60, 20),
|
||||
StringValue = "Size:",
|
||||
Font = SparkleUI.BoldFont
|
||||
};
|
||||
|
||||
this.size_label_value = new NSTextField () {
|
||||
Alignment = NSTextAlignment.Left,
|
||||
BackgroundColor = NSColor.WindowBackground,
|
||||
Bordered = false,
|
||||
Editable = false,
|
||||
Frame = new RectangleF (60, 588, 75, 20),
|
||||
StringValue = Controller.Size,
|
||||
Font = SparkleUI.Font
|
||||
};
|
||||
|
||||
|
||||
this.history_label = new NSTextField () {
|
||||
Alignment = NSTextAlignment.Right,
|
||||
BackgroundColor = NSColor.WindowBackground,
|
||||
Bordered = false,
|
||||
Editable = false,
|
||||
Frame = new RectangleF (130, 588, 60, 20),
|
||||
StringValue = "History:",
|
||||
Font = SparkleUI.BoldFont
|
||||
};
|
||||
|
||||
this.history_label_value = new NSTextField () {
|
||||
Alignment = NSTextAlignment.Left,
|
||||
BackgroundColor = NSColor.WindowBackground,
|
||||
Bordered = false,
|
||||
Editable = false,
|
||||
Frame = new RectangleF (190, 588, 75, 20),
|
||||
StringValue = Controller.HistorySize,
|
||||
Font = SparkleUI.Font
|
||||
};
|
||||
|
||||
|
||||
ContentView.AddSubview (this.size_label);
|
||||
ContentView.AddSubview (this.size_label_value);
|
||||
ContentView.AddSubview (this.history_label);
|
||||
ContentView.AddSubview (this.history_label_value);
|
||||
ContentView.AddSubview (this.separator);
|
||||
|
||||
|
||||
this.progress_indicator = new NSProgressIndicator () {
|
||||
|
@ -102,6 +152,14 @@ namespace SparkleShare {
|
|||
ContentView.AddSubview (this.progress_indicator);
|
||||
});
|
||||
};
|
||||
|
||||
Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
|
||||
InvokeOnMainThread (delegate {
|
||||
Console.WriteLine (size + " " + history_size);
|
||||
this.size_label_value.StringValue = size;
|
||||
this.history_label_value.StringValue = history_size;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,7 +180,7 @@ namespace SparkleShare {
|
|||
this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||
("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize);
|
||||
|
||||
this.popup_button.AddItem ("All Folders");
|
||||
this.popup_button.AddItem ("All Projects");
|
||||
this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
this.popup_button.AddItems (folders);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace SparkleShare {
|
|||
public static SparkleBubbles Bubbles;
|
||||
public static SparkleAbout About;
|
||||
public static NSFont Font;
|
||||
public static NSFont BoldFont;
|
||||
|
||||
|
||||
public SparkleUI ()
|
||||
|
@ -59,6 +60,9 @@ namespace SparkleShare {
|
|||
Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||
("Lucida Grande", NSFontTraitMask.Condensed, 0, 13);
|
||||
|
||||
BoldFont = NSFontManager.SharedFontManager.FontWithFamily
|
||||
("Lucida Grande", NSFontTraitMask.Bold, 0, 13);
|
||||
|
||||
StatusIcon = new SparkleStatusIcon ();
|
||||
Bubbles = new SparkleBubbles ();
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace SparkleShare {
|
|||
public abstract class SparkleControllerBase {
|
||||
|
||||
public List <SparkleRepoBase> Repositories;
|
||||
public string FolderSize;
|
||||
public readonly string SparklePath = SparkleConfig.DefaultConfig.FoldersPath;
|
||||
|
||||
public event OnQuitWhileSyncingHandler OnQuitWhileSyncing;
|
||||
|
@ -53,9 +52,6 @@ namespace SparkleShare {
|
|||
public event FolderListChangedHandler FolderListChanged;
|
||||
public delegate void FolderListChangedHandler ();
|
||||
|
||||
public event FolderSizeChangedHandler FolderSizeChanged;
|
||||
public delegate void FolderSizeChangedHandler (string folder_size);
|
||||
|
||||
public event AvatarFetchedHandler AvatarFetched;
|
||||
public delegate void AvatarFetchedHandler ();
|
||||
|
||||
|
@ -109,8 +105,6 @@ namespace SparkleShare {
|
|||
if (CreateSparkleShareFolder ())
|
||||
AddToBookmarks ();
|
||||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
if (FirstRun)
|
||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
||||
else
|
||||
|
@ -130,11 +124,6 @@ namespace SparkleShare {
|
|||
|
||||
if (FolderListChanged != null)
|
||||
FolderListChanged ();
|
||||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
if (FolderSizeChanged != null)
|
||||
FolderSizeChanged (FolderSize);
|
||||
};
|
||||
|
||||
|
||||
|
@ -163,8 +152,8 @@ namespace SparkleShare {
|
|||
public bool AcceptInvitation (string server, string folder, string token)
|
||||
{
|
||||
// The location of the user's public key for SparkleShare
|
||||
string public_key_file_path = SparkleHelpers.CombineMore (SparkleConfig.DefaultConfig.HomePath, ".ssh",
|
||||
"sparkleshare." + UserEmail + ".key.pub");
|
||||
string public_key_file_path = SparkleHelpers.CombineMore (SparkleConfig.DefaultConfig.HomePath,
|
||||
".ssh", "sparkleshare." + UserEmail + ".key.pub");
|
||||
|
||||
if (!File.Exists (public_key_file_path))
|
||||
return false;
|
||||
|
@ -561,11 +550,6 @@ namespace SparkleShare {
|
|||
} else {
|
||||
if (OnIdle != null)
|
||||
OnIdle ();
|
||||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
if (FolderSizeChanged != null)
|
||||
FolderSizeChanged (FolderSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -660,11 +644,6 @@ namespace SparkleShare {
|
|||
|
||||
if (FolderListChanged != null)
|
||||
FolderListChanged ();
|
||||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
if (FolderSizeChanged != null)
|
||||
FolderSizeChanged (FolderSize);
|
||||
}
|
||||
|
||||
|
||||
|
@ -696,51 +675,37 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
private string GetFolderSize ()
|
||||
public string GetSize (string folder_name)
|
||||
{
|
||||
double folder_size = CalculateFolderSize (
|
||||
new DirectoryInfo (SparkleConfig.DefaultConfig.FoldersPath));
|
||||
double folder_size = 0;
|
||||
/* TODO
|
||||
foreach (SparkleRepoBase repo in
|
||||
Repositories.GetRange (0, Repositories.Count)) {
|
||||
|
||||
folder_size += repo.Size + repo.HistorySize;
|
||||
}
|
||||
*/
|
||||
return FormatFolderSize (folder_size);
|
||||
}
|
||||
|
||||
|
||||
// Recursively gets a folder's size in bytes
|
||||
private double CalculateFolderSize (DirectoryInfo parent)
|
||||
public string GetHistorySize (string folder_name)
|
||||
{
|
||||
if (!Directory.Exists (parent.ToString ()))
|
||||
return 0;
|
||||
double folder_size = 0;
|
||||
/* TODO
|
||||
foreach (SparkleRepoBase repo in
|
||||
Repositories.GetRange (0, Repositories.Count)) {
|
||||
|
||||
double size = 0;
|
||||
|
||||
// Ignore the temporary 'rebase-apply' and '.tmp' directories. This prevents potential
|
||||
// crashes when files are being queried whilst the files have already been deleted.
|
||||
if (parent.Name.Equals ("rebase-apply") ||
|
||||
parent.Name.Equals (".tmp"))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
foreach (FileInfo file in parent.GetFiles()) {
|
||||
if (!file.Exists)
|
||||
return 0;
|
||||
|
||||
size += file.Length;
|
||||
folder_size += repo.Size + repo.HistorySize;
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo directory in parent.GetDirectories())
|
||||
size += CalculateFolderSize (directory);
|
||||
|
||||
} catch (Exception) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
*/
|
||||
return FormatFolderSize (folder_size);
|
||||
}
|
||||
|
||||
|
||||
// Format a file size nicely with small caps.
|
||||
// Example: 1048576 becomes "1 ᴍʙ"
|
||||
private string FormatFolderSize (double byte_count)
|
||||
public string FormatFolderSize (double byte_count)
|
||||
{
|
||||
if (byte_count >= 1099511627776)
|
||||
return String.Format ("{0:##.##} ᴛʙ", Math.Round (byte_count / 1099511627776, 1));
|
||||
|
@ -1037,11 +1002,6 @@ namespace SparkleShare {
|
|||
if (FolderFetched != null)
|
||||
FolderFetched (warnings);
|
||||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
if (FolderSizeChanged != null)
|
||||
FolderSizeChanged (FolderSize);
|
||||
|
||||
if (FolderListChanged != null)
|
||||
FolderListChanged ();
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace SparkleShare {
|
|||
|
||||
public SparkleEventLogController Controller = new SparkleEventLogController ();
|
||||
|
||||
private Label size_label;
|
||||
private HBox layout_horizontal;
|
||||
private ComboBox combo_box;
|
||||
private EventBox content_wrapper;
|
||||
|
@ -58,6 +59,11 @@ namespace SparkleShare {
|
|||
|
||||
DeleteEvent += Close;
|
||||
|
||||
this.size_label = new Label () {
|
||||
Markup = "<b>Size:</b> " + Controller.Size + " " +
|
||||
"<b>History:</b> " + Controller.HistorySize;
|
||||
};
|
||||
|
||||
VBox layout_vertical = new VBox (false, 0);
|
||||
this.spinner = new SparkleSpinner (22);
|
||||
this.content_wrapper = new EventBox ();
|
||||
|
@ -86,7 +92,7 @@ namespace SparkleShare {
|
|||
this.spinner.Start ();
|
||||
|
||||
this.layout_horizontal = new HBox (true, 0);
|
||||
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
||||
this.layout_horizontal.PackStart (this.size_label, true, true, 0);
|
||||
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
||||
|
||||
layout_vertical.PackStart (this.layout_horizontal, false, false, 0);
|
||||
|
@ -123,6 +129,13 @@ namespace SparkleShare {
|
|||
this.content_wrapper.ShowAll ();
|
||||
});
|
||||
};
|
||||
|
||||
Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
|
||||
Application.Invoke (delegate {
|
||||
Markup = "<b>Size:</b> " + size + " " +
|
||||
"<b>History:</b> " + history_size;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,7 +155,7 @@ namespace SparkleShare {
|
|||
|
||||
ListStore store = new ListStore (typeof (string));
|
||||
|
||||
store.AppendValues (_("All Folders"));
|
||||
store.AppendValues (_("All Projects"));
|
||||
store.AppendValues ("---");
|
||||
|
||||
foreach (string folder in folders)
|
||||
|
|
|
@ -34,9 +34,14 @@ namespace SparkleShare {
|
|||
public event UpdateChooserEventHandler UpdateChooserEvent;
|
||||
public delegate void UpdateChooserEventHandler (string [] folders);
|
||||
|
||||
public event UpdateSizeInfoEventHandler UpdateSizeInfoEvent;
|
||||
public delegate void UpdateSizeInfoEventHandler (string size, string history_size);
|
||||
|
||||
public event ContentLoadingEventHandler ContentLoadingEvent;
|
||||
public delegate void ContentLoadingEventHandler ();
|
||||
|
||||
private string selected_folder;
|
||||
|
||||
|
||||
public string SelectedFolder {
|
||||
get {
|
||||
|
@ -63,6 +68,9 @@ namespace SparkleShare {
|
|||
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (html);
|
||||
|
||||
if (UpdateSizeInfoEvent != null)
|
||||
UpdateSizeInfoEvent (Size, HistorySize);
|
||||
}));
|
||||
|
||||
thread.Start ();
|
||||
|
@ -82,8 +90,35 @@ namespace SparkleShare {
|
|||
}
|
||||
}
|
||||
|
||||
public string Size {
|
||||
get {
|
||||
double size = 0;
|
||||
|
||||
private string selected_folder;
|
||||
foreach (SparkleRepoBase repo in Program.Controller.Repositories) {
|
||||
if (this.selected_folder == null)
|
||||
size += repo.Size;
|
||||
else if (this.selected_folder.Equals (repo.Name))
|
||||
return Program.Controller.FormatFolderSize (repo.Size);
|
||||
}
|
||||
|
||||
return Program.Controller.FormatSize (size);
|
||||
}
|
||||
}
|
||||
|
||||
public string HistorySize {
|
||||
get {
|
||||
double size = 0;
|
||||
|
||||
foreach (SparkleRepoBase repo in Program.Controller.Repositories) {
|
||||
if (this.selected_folder == null)
|
||||
size += repo.HistorySize;
|
||||
else if (this.selected_folder.Equals (repo.Name))
|
||||
return Program.Controller.FormatFolderSize (repo.HistorySize);
|
||||
}
|
||||
|
||||
return Program.Controller.FormatSize (size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SparkleEventLogController ()
|
||||
|
@ -96,6 +131,9 @@ namespace SparkleShare {
|
|||
Program.Controller.OnIdle += delegate {
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML);
|
||||
|
||||
if (UpdateSizeInfoEvent != null)
|
||||
UpdateSizeInfoEvent (Size, HistorySize);
|
||||
};
|
||||
|
||||
Program.Controller.FolderListChanged += delegate {
|
||||
|
@ -110,11 +148,9 @@ namespace SparkleShare {
|
|||
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML);
|
||||
};
|
||||
|
||||
Program.Controller.NotificationRaised += delegate {
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML);
|
||||
if (UpdateSizeInfoEvent != null)
|
||||
UpdateSizeInfoEvent (Size, HistorySize);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using SparkleLib;
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
public enum IconState {
|
||||
|
@ -46,17 +48,18 @@ namespace SparkleShare {
|
|||
|
||||
public string FolderSize {
|
||||
get {
|
||||
return Program.Controller.FolderSize;
|
||||
double size = 0;
|
||||
|
||||
foreach (SparkleRepoBase repo in Program.Controller.Repositories)
|
||||
size += repo.Size + repo.HistorySize;
|
||||
|
||||
return Program.Controller.FormatSize (size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SparkleStatusIconController ()
|
||||
{
|
||||
Program.Controller.FolderSizeChanged += delegate {
|
||||
if (UpdateMenuEvent != null)
|
||||
UpdateMenuEvent (CurrentState);
|
||||
};
|
||||
|
||||
Program.Controller.FolderListChanged += delegate {
|
||||
if (UpdateMenuEvent != null)
|
||||
UpdateMenuEvent (CurrentState);
|
||||
|
|
Loading…
Reference in a new issue