private void Settings_Load(object sender, EventArgs e) { //Load source folders string[] sourceFolders = new string[1]; string sourceFoldersString = UserSettings.getSetting("source-folders"); if (sourceFoldersString.Contains("*")) { sourceFolders = G.splitString(UserSettings.getSetting("source-folders"), "*"); } else { sourceFolders[0] = sourceFoldersString; } //Set source folders in itemBox for (int i = 0; i < sourceFolders.Length; i++) { if (sourceFolders[i].Length > 3) { listBox1.Items.Add(sourceFolders[i]); } } //Set target folder in textbox textBox1.Text = UserSettings.getSetting("target-folder"); }
private void Schedule_Load(object sender, EventArgs e) { if (UserSettings.getSetting("auto-backup").Equals("No")) { radioButton2.Checked = true; } numericUpDown1.Value = int.Parse(UserSettings.getSetting("backup-interval")); }
public static long timeUntilNextBackup() { if (UserSettings.getSetting("last-backup-millis").Equals("0")) { return(-1); } return(long.Parse(UserSettings.getSetting("last-backup-millis")) + (1000 * 60 * 60 * int.Parse(UserSettings.getSetting("backup-interval"))) - getTimeMilli()); }
public Form1() { InitializeComponent(); G.form1 = this; //Reset crash reason UserSettings.setSetting("crash-reason", "None"); new CrashHelper("RootBackup Helper", @"C:\Program Files\RootBackup\RootBackup Helper.exe").start(); //Enable devmode in title if (G.getUsername().Equals("JBlevins") && Debugger.IsAttached) { this.Text = "DevMode"; } //Notify Icon init notifyIcon1.Text = "RootBackup"; notifyIcon1.Icon = Icon; notifyIcon1.Visible = true; notifyIcon1.ContextMenu = new ContextMenu(); notifyIcon1.ContextMenu.MenuItems.Add(new MenuItem("Exit", closeDown)); //Other startup stuff UserSettings.setSetting("Version", G.VERSION); if (!Visible) { G.messageBox("RootBackup", "RootBackup is now hidden in your toolbar. You can access it again by clicking on the RootBackup icon.", ToolTipIcon.Info); } //Auto set next and last backup times new Thread(new ThreadStart(() => { while (true) { Thread.Sleep(250); G.setLastBackupTime(); G.setNextBackupTime(); G.refreshStatus(); if (G.timeUntilNextBackup() <= 0 && UserSettings.getSetting("auto-backup").Equals("Yes") && UserSettings.getSetting("source-folders").Length > 3) { bool startBackupBool = true; if (startBackupBool && !G.backingUp) { G.backupThread = new Thread(new ThreadStart(() => { startBackup(); })); G.backupThread.Start(); } } } })).Start(); G.setProgressBar(0, 0); }
public static string displayTimeUntilNextBackup() { if (UserSettings.getSetting("auto-backup").Equals("Yes")) { int hours = (int)(timeUntilNextBackup() / (60 * 60 * 1000)); int minutes = (int)(((timeUntilNextBackup() / (60f * 60f * 1000f)) - hours) * 60f); if (hours >= 0 && minutes >= 0) { return("Next backup will start in " + hours + " hours and " + minutes + " minutes"); } else { return("Backing up files now"); } } else { return("N/A"); } }
public static void setLastBackupTime() { if (form1.Visible) { Form1.label2.Invoke(new MethodInvoker(delegate { if (!UserSettings.getSetting("last-backup").Equals("N/A")) { DateTime datetime = DateTime.Parse(UserSettings.getSetting("last-backup")); datetime = datetime.ToLocalTime(); string date = datetime.ToString("MMMM d"); string time = datetime.ToString("h:mm tt"); Form1.label2.Text = "Last backup finished on " + date + " at " + time + "."; } else { Form1.label2.Text = "Launching first backup ever."; } })); } }
public static void compressDirectory(string sourcePath, string destPath) { //If backups directory doesn't exist already, create it if (!Directory.Exists(UserSettings.getSetting("target-folder"))) { Directory.CreateDirectory(UserSettings.getSetting("target-folder")); } zip = new ZipFile(); zip.UseZip64WhenSaving = Zip64Option.AsNecessary; string[] dirs = Directory.GetDirectories(sourcePath); string[] files = Directory.GetFiles(sourcePath); G.print("Adding files"); int items = 0; int directories = 0; for (int i = 0; i < files.Length; i++) { string directoryPath = ""; try { int startIndex = files[i].IndexOf(@"\") + 1; directoryPath = files[i].Substring(startIndex, files[i].LastIndexOf(@"\") - startIndex); createPathsInZip(directoryPath); zip.AddFile(files[i], directoryPath); items++; setProgressBar(items + directories, dirs.Length + files.Length); setStatus("Creating backup for " + sourcePath + ". " + items + " items, and " + directories + " directories added so far. This may take a while, please be patient."); G.print("Added " + files[i] + " to files under " + directoryPath); } catch (Exception e) { G.print("Error when adding " + files[i] + " to files under " + directoryPath); G.print(e.ToString()); backupErrors.Add(e); } } G.print("Adding directories"); for (int i = 0; i < dirs.Length; i++) { string directoryPath = ""; try{ int startIndex = dirs[i].IndexOf(@"\") + 1; directoryPath = dirs[i].Substring(startIndex, dirs[i].LastIndexOf(@"\") - startIndex); zip.UpdateDirectory(dirs[i], directoryPath); directories++; setProgressBar(items + directories, dirs.Length + files.Length); setStatus("Creating backup for " + sourcePath + ". " + items + " items, and " + directories + " directories added so far. This may take a while, please be patient."); G.print("Added " + dirs[i] + " to directories under " + directoryPath); } catch (Exception e) { G.print("Error when adding " + dirs[i] + " to directories under " + directoryPath); G.print(e.ToString()); backupErrors.Add(e); } } setProgressBar(0, 0); setStatus("Creating backup for " + sourcePath + ". Finalizing backup file. This may take a while, please be patient."); G.print("Finalizing backup file"); zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; zip.Save(destPath); }
void startBackup() { G.setProgressBar(0, 0); if (!G.backingUp) { PowerHelper.ForceSystemAwake(); G.backingUp = true; G.setStartBackupOption(false); G.setStatus("Analyzing source folders"); string[] sourceFolders = G.splitString(UserSettings.getSetting("source-folders"), "*"); //Delete old tmp files string[] tmpFiles = Directory.GetFiles(UserSettings.getSetting("target-folder")); for (int i = 0; i < tmpFiles.Length && G.backingUp; i++) { G.print("Deleteing " + tmpFiles[i]); if (tmpFiles[i].EndsWith(".tmp")) { File.Delete(tmpFiles[i]); } } //Backup files online Thread.Sleep(1000); string[] sourcePaths = G.splitString(UserSettings.getSetting("source-folders"), "*"); //G.connection.sendMessage("beginRevision"); for (int x = 0; x < sourcePaths.Length && G.backingUp; x++) { G.setProgressBar(0, 0); if (!G.replaceAll(sourcePaths[x], " ", "").Equals("")) { string[] sourceFolderNameArgs = G.splitString(sourcePaths[x], @"\"); string sourceFolderName = sourceFolderNameArgs[sourceFolderNameArgs.Length - 1]; G.setStatus("Creating backup for " + sourcePaths[x] + ". This may take a while, please be patient."); G.compressDirectory(sourcePaths[x], UserSettings.getSetting("target-folder") + sourceFolderName + ".zip"); //G.setStatus("Uploading backup for " + sourcePaths[x] + ". This may take a while, please be patient."); //G.connection.uploadFile(@"C:\RootBackup\" + sourceFolderName + ".zip"); //G.setStatus("Clearing space for next folder backup."); //File.Delete(@"C:\RootBackup\" + sourceFolderName + ".zip"); } } G.handleFinalErrors(); } G.backingUp = false; G.messageBox("Backup Finished", "RootBackup has finished backing up your files.", ToolTipIcon.Info); G.setStartBackupOption(true); G.setProgressBar(0, 0); if (G.backupError) { G.setStatus("Backup finished with errors. Will try again in " + UserSettings.getSetting("backup-interval") + " hours."); G.backupError = false; } else { G.setStatus("Backup finished"); } PowerHelper.ResetSystemDefault(); UserSettings.setSetting("last-backup", G.getTimeUTC()); UserSettings.setSetting("last-backup-millis", "" + G.getTimeMilli()); }
private void button2_Click(object sender, EventArgs e) { Process.Start("explorer.exe", UserSettings.getSetting("target-folder")); }