[chronojump] Copy database now do not copies backups and gives better feedback with 2 progressbars
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Copy database now do not copies backups and gives better feedback with 2 progressbars
- Date: Wed, 17 Jul 2019 13:41:33 +0000 (UTC)
commit 67ac20e960601a6102381be01bec164970164f0b
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jul 17 15:40:22 2019 +0200
Copy database now do not copies backups and gives better feedback with 2 progressbars
glade/preferences_win.glade | 13 ++++++++++++-
src/gui/preferences.cs | 29 +++++++++++++++++++++++------
src/util.cs | 43 ++++++++++++++++++++++++++++++-------------
3 files changed, 65 insertions(+), 20 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 4a699f43..7816612a 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -277,7 +277,7 @@
</packing>
</child>
<child>
- <widget class="GtkProgressBar" id="pulsebar">
+ <widget class="GtkProgressBar" id="pulsebarBackupDirs">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
@@ -287,6 +287,17 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkProgressBar" id="pulsebarBackupActivity">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index e143da68..667e3f87 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -60,7 +60,8 @@ public class PreferencesWindow
[Widget] Gtk.Button button_db_backup;
[Widget] Gtk.Box hbox_backup_doing;
- [Widget] Gtk.ProgressBar pulsebar;
+ [Widget] Gtk.ProgressBar pulsebarBackupDirs;
+ [Widget] Gtk.ProgressBar pulsebarBackupActivity;
//jumps tab
@@ -1324,6 +1325,7 @@ public class PreferencesWindow
//if multimedia_and_encoder, then copy the folder. If not checked,
then copy only the db file
if(check_backup_multimedia_and_encoder.Active)
{
+ uc = new UtilCopy();
thread = new Thread(new ThreadStart(copyRecursive));
GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
@@ -1397,6 +1399,7 @@ public class PreferencesWindow
//if multimedia_and_encoder, then copy the folder. If not checked, then copy only the
db file
if(check_backup_multimedia_and_encoder.Active) {
Directory.Delete(fileCopy, true);
+ uc = new UtilCopy();
thread = new Thread(new ThreadStart(copyRecursive));
GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
@@ -1421,8 +1424,20 @@ public class PreferencesWindow
/*
* deprecated since 1.6.0. Use backup method below
*/
- private void copyRecursive() {
- Util.CopyFilesRecursively(new DirectoryInfo(Util.GetParentDir(false)), new
DirectoryInfo(fileCopy));
+ static long copyRecursiveElapsedMs;
+ static int backupMainDirsDone;
+ static UtilCopy uc;
+ private void copyRecursive()
+ {
+ copyRecursiveElapsedMs = 0;
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+
+ //Util.CopyFilesRecursively(new DirectoryInfo(Util.GetParentDir(false)), new
DirectoryInfo(fileCopy), out backupMainDirsDone);
+ uc.CopyFilesRecursively(new DirectoryInfo(Util.GetParentDir(false)), new
DirectoryInfo(fileCopy), true);
+ sw.Stop();
+
+ copyRecursiveElapsedMs = sw.ElapsedMilliseconds;
}
/*
@@ -1571,17 +1586,19 @@ public class PreferencesWindow
return false;
}
- pulsebar.Pulse();
+ pulsebarBackupDirs.Fraction = Util.DivideSafeFraction(uc.BackupMainDirsDone, 6); //6 for:
database, encoder, forceSensor, logs, multimedia, raceAnalyzer
+ pulsebarBackupActivity.Pulse();
Thread.Sleep (50);
//LogB.Debug(thread.ThreadState.ToString());
return true;
}
private void endPulse() {
- pulsebar.Fraction = 1;
+ pulsebarBackupDirs.Fraction = 1;
+ pulsebarBackupActivity.Fraction = 1;
backup_doing_sensitive_start_end(false);
fc.Hide ();
- string myString = string.Format(Catalog.GetString("Copied to {0}"), fileCopy);
+ string myString = string.Format(Catalog.GetString("Copied to {0} in {1} ms"), fileCopy,
copyRecursiveElapsedMs);
new DialogMessage(Constants.MessageTypes.INFO, myString);
}
diff --git a/src/util.cs b/src/util.cs
index d49ffbb4..e476c945 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1229,10 +1229,10 @@ public class Util
public static string GetSoundsDir(){
return GetImagesDir();
}
-
-
+
+ static string backupDir = GetDatabaseDir() + Path.DirectorySeparatorChar + "backup";
+
public static void BackupDirCreateIfNeeded () {
- string backupDir = GetDatabaseDir() + Path.DirectorySeparatorChar + "backup";
if( ! Directory.Exists(backupDir)) {
Directory.CreateDirectory (backupDir);
LogB.Information ("created backup dir");
@@ -1241,8 +1241,6 @@ public class Util
public static void BackupDatabase () {
string homeDir = GetDatabaseDir();
- string backupDir = homeDir + Path.DirectorySeparatorChar + "backup";
-
string dateParsed = UtilDate.ToFile(DateTime.Now);
if(File.Exists(System.IO.Path.Combine(homeDir, "chronojump.db")))
@@ -1253,14 +1251,6 @@ public class Util
}
}
- //http://stackoverflow.com/a/58779
- public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
- foreach (DirectoryInfo dir in source.GetDirectories())
- CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
- foreach (FileInfo file in source.GetFiles())
- file.CopyTo(Path.Combine(target.FullName, file.Name));
- }
-
public static bool FileDelete(string fileName)
{
LogB.Information("Checking if this filename exists: " + fileName);
@@ -2220,3 +2210,30 @@ public class Util
}
}
}
+
+public class UtilCopy
+{
+ public int BackupMainDirsDone;
+
+ //to go faster on CopyFilesRecursively
+ static string backupDir = Util.GetDatabaseDir() + Path.DirectorySeparatorChar + "backup";
+
+ public UtilCopy()
+ {
+ BackupMainDirsDone = 0;
+ }
+
+ //http://stackoverflow.com/a/58779
+ public void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target, bool mainDir)
+ {
+ foreach (DirectoryInfo dir in source.GetDirectories())
+ if(dir.ToString() != backupDir) //do not copy backup files
+ {
+ CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name), false);
+ if(mainDir)
+ BackupMainDirsDone ++;
+ }
+ foreach (FileInfo file in source.GetFiles())
+ file.CopyTo(Path.Combine(target.FullName, file.Name));
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]