private void StopBackUp() { backUpThread.Abort(); loadIconThread.Abort(); trayIcon.Icon = Resources.AppIcon; Reloadmenu(); LoggingUtilities.Log("INTERRUPTED BACK-UP\n"); }
private void StartBackUp(string userSettings) { LoadBackingUpMenu(); backUpThread = new Thread(() => { LoggingUtilities.SetAppDataRoot(AppDataRoot); try { LoadingIcon(); LoggingUtilities.LogFormat("\nInitiating Simple Back-Up ({0})\n", DateTime.Now.ToString()); BackUpSettings loadedSettings = settings.Load(userSettings); backUp = new BackUp(); backUp.Start(loadedSettings); } catch (Exception ex) { LoggingUtilities.Log("ERROR\n"); LoggingUtilities.Log(ex.StackTrace + "\n"); LoggingUtilities.Log(ex.Message + "\n"); LoggingUtilities.Log(ex.Data.ToString() + "\n"); Console.Beep(200, 500); Console.Beep(200, 500); Console.Beep(200, 500); } finally { if (loadIconThread != null) { loadIconThread.Abort(); loadIconThread = null; trayIcon.Icon = Resources.AppIcon; } Reloadmenu(); Console.Beep(400, 500); LoggingUtilities.LogFormat("Finished AFB ({0})\n", DateTime.Now.ToString()); } }); backUpThread.Start(); }
private void Copy( string originDirectory, string targetDirectory) { DirectoryUtilities.EnsureDirectory(targetDirectory); DirectoryUtilities.ForeachFolderAt(originDirectory, (string childDir) => Copy(childDir, Path.Combine(targetDirectory, Path.GetFileName(childDir)))); DirectoryUtilities.ForeachFileAt(originDirectory, (FileInfo file) => { // TODO: add sub folders to settings to autoskip (e.g. ".git" folders). string targetPath = Path.Combine(targetDirectory, file.Name); // if it's the same file, but a different version. if (File.Exists(targetPath) && file.LastWriteTime != File.GetLastWriteTime(targetPath)) { LoggingUtilities.LogFormat("DUPLICATE FILE: {0}\n", targetPath); bool overwrite = overwriteState == ActionState.Yes; if (overwriteState == ActionState.Unset) { overwrite = RequestActionState(ref overwriteState, "overwrite", targetPath); } if (!overwrite) { LoggingUtilities.LogFormat("Skipped\n"); return; } LoggingUtilities.LogFormat("Overwritten\n"); } try { File.Copy(file.FullName, targetPath, true); } catch (Exception e) { LoggingUtilities.LogFormat("ERROR: {0} | {1}\n", e.GetType(), e.Message); bool skip = skipState == ActionState.Yes; if (skipState == ActionState.Unset) { skip = RequestActionState(ref skipState, string.Format("Can't reach file due to error ({0}). Skip", e.Message), targetPath); } if (skip) { LoggingUtilities.Log("Skipped\n"); return; } } FileAttributes attributes = File.GetAttributes(targetPath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { attributes = attributes & ~FileAttributes.ReadOnly; File.SetAttributes(targetPath, attributes); } }); }