public frmNewSource(ref BackupSource BackupSource) { _BackupSource = BackupSource; InitializeComponent(); SetText(); }
public frmNewSourceAdvanced(ref BackupSource BackupSource, String Directory) { _BackupSource = BackupSource; _Directory = Directory; InitializeComponent(); SetText(); }
private void bnAddSource_Click(object sender, EventArgs e) { try { BackupSource BackupSource = new BackupSource(); frmNewSource NQ = new frmNewSource(ref BackupSource); if (NQ.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { Settings.Sources.Add(BackupSource); ((CurrencyManager)dgvSources.BindingContext[Settings.Sources]).Refresh(); dgvSources.CurrentCell = dgvSources[0, dgvSources.RowCount - 1]; } } catch (Exception ex) { HelperFunctions.ShowError(ex); } }
public static void MirrorDirectory(BackupSource BackupSource) { try { if (BackupSource.DisableJob) { return; } String Source = BackupSource.Mount; String Target = BackupSource.TargetPath.ToString(); _CurrentRealSourceDir = BackupSource.SourcePath; _CurrentSourceDir = Source; _CurrentTargetDir = Target; if (Source.EndsWith("\\") && Source.Length > 3) Source = Source.Substring(0, Source.Length - 1); //Error in backup of an entire drive if (Source.Contains(" ")) //For some reason robocopy quotes accepted only if space in the path name { Source = "\"" + Source + "\""; } if (Target.EndsWith("\\")) Target = Target.Substring(0, Target.Length - 1); if (Target.Contains(" ") && Target.Length > 3) { Target = "\"" + Target + "\""; } HelperFunctions.WriteLogLine(); HelperFunctions.WriteLog(Translations.Get("StartingRobocopy")); _Cmd = new Process(); _Cmd.StartInfo.FileName = "cmd.exe"; if (System.Windows.Forms.Application.StartupPath.StartsWith(@"\\")) _Cmd.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (Alphaleonis.Win32.Vss.OperatingSystemInfo.OSVersionName <= Alphaleonis.Win32.Vss.OSVersionName.WindowsServer2003) { _FirstLines = 1; _Cmd.StartInfo.Arguments = "/U /S /C \"\"" + GlobalData.RobocopyPath + "\" " + Source + " " + Target + " " + BackupSource.GetBackupMode() + Settings.Retries.ToString() + " /W:" + Settings.WaitBetweenRetries.ToString() + " /FFT /DST /NJH /NJS /BYTES /XJ" + BackupSource.GetRobocopyParameters() + "\""; // /NC /NS /NFL /NDL /NJH /TEE _Cmd.StartInfo.StandardOutputEncoding = System.Text.Encoding.Unicode; _Cmd.StartInfo.StandardErrorEncoding = System.Text.Encoding.Unicode; } else { _FirstLines = 2; _Cmd.StartInfo.Arguments = "/U /C chcp 65001 & \"" + GlobalData.RobocopyPath + "\" " + Source + " " + Target + " " + BackupSource.GetBackupMode() + Settings.Retries.ToString() + " /W:" + Settings.WaitBetweenRetries.ToString() + " /FFT /DST /NJH /NJS /BYTES /XJ" + BackupSource.GetRobocopyParameters(); // /NC /NS /NFL /NDL /NJH /TEE _Cmd.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; _Cmd.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; } _Cmd.StartInfo.CreateNoWindow = true; _Cmd.StartInfo.UseShellExecute = false; _Cmd.StartInfo.RedirectStandardError = true; _Cmd.StartInfo.RedirectStandardOutput = true; _Cmd.StartInfo.RedirectStandardInput = true; _Cmd.Start(); _Cmd.BeginOutputReadLine(); _Cmd.OutputDataReceived += new DataReceivedEventHandler(GetMirrorDirectoryOutputHandler); String Error = _Cmd.StandardError.ReadToEnd().Trim(); if (Error != "") HelperFunctions.ShowError(Translations.Get("ErrorInRobocopy") + Error); _Cmd.WaitForExit(); if ((_Cmd.ExitCode & 16) == 16 && !_Abort) HelperFunctions.ShowError(GetRobocopyReadableExitCode(_Cmd.ExitCode)); if (_Abort) HelperFunctions.WriteLog(Translations.Get("Aborted")); else HelperFunctions.WriteLog(Translations.Get("ExitCode") + _Cmd.ExitCode + ": " + GetRobocopyReadableExitCode(_Cmd.ExitCode)); _Cmd = null; HelperFunctions.WriteLogLine(); } catch (Exception ex) { HelperFunctions.ShowError(ex); } }
public static bool LoadSettings(bool ErrorWhenNotFound, bool loadFile) { try { bool ReadOnly = false; _Sources.Clear(); _Subfolder = ""; _Path = GlobalData.SystemXMLFile; if (loadFile) { OpenFileDialog FB = new OpenFileDialog(); FB.Title = Translations.Get("SelectDirectoryToBackup"); FB.Filter = "XML Files (*.xml)|*.xml"; FB.FilterIndex = 0; FB.DefaultExt = "xml"; if (FB.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _Path = FB.FileName; } } else { // Get the current configuration associated // with the application. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); System.Configuration.AppSettingsSection appSettings = config.AppSettings; if (appSettings.Settings["SettingsXMLFile"] != null) { _Path = appSettings.Settings["SettingsXMLFile"].Value.ToString(); } } if (System.IO.Directory.Exists(new FileInfo(_Path).DirectoryName)) { try { if (System.IO.File.Exists(_Path + ".test")) File.Delete(_Path + ".test"); using (System.IO.File.Create(_Path + ".test")) { } File.Delete(_Path + ".test"); } catch { ReadOnly = true; } } if (!System.IO.File.Exists(_Path) || ReadOnly) { if (System.IO.File.Exists(_Path)) { GlobalData.SettingsInAppData = true; } else { return false; } } BackupSource BackupSource = new BackupSource(); System.Reflection.PropertyInfo[] Properties = BackupSource.GetType().GetProperties(); try { using (XmlTextReader Rd = HelperFunctions.LoadXMLFile(_Path)) { Rd.WhitespaceHandling = WhitespaceHandling.Significant; String Temp; int TempInt; while (Rd.Read()) { if (Rd.NodeType == XmlNodeType.Element) { if (Rd.Name.StartsWith("Auto") && Rd.Name.Length > 4) { IEnumerable<System.Reflection.PropertyInfo> SelectedProperty = from Property in Properties where Property.Name == Rd.Name.Substring(4) select Property; foreach (System.Reflection.PropertyInfo Property in SelectedProperty) //Sollte nur eine sein { try { if (Property.PropertyType == typeof(List<String>)) Property.SetValue(BackupSource, new List<String>(Rd.ReadString().Split('|')), null); if (Property.PropertyType == typeof(String)) Property.SetValue(BackupSource, Rd.ReadString(), null); if (Property.PropertyType == typeof(int)) Property.SetValue(BackupSource, int.Parse(Rd.ReadString()), null); if (Property.PropertyType == typeof(long)) Property.SetValue(BackupSource, long.Parse(Rd.ReadString()), null); if (Property.PropertyType == typeof(bool)) Property.SetValue(BackupSource, bool.Parse(Rd.ReadString()), null); if (Property.PropertyType == typeof(BackupSource.Attribute)) Property.SetValue(BackupSource, (BackupSource.Attribute)int.Parse(Rd.ReadString()), null); if (Property.PropertyType == typeof(BackupSource.CopyFlag)) Property.SetValue(BackupSource, (BackupSource.CopyFlag)int.Parse(Rd.ReadString()), null); } catch (Exception ex) { HelperFunctions.ShowError(ex); } } } else { switch (Rd.Name.ToLower()) { case "language": _Language = Rd.ReadString().Trim(); break; case "smallestdriveletter": _SmallestDriveLetter = CheckDriveLetter(Rd.ReadString().Trim()); if (_SmallestDriveLetter == null) _SmallestDriveLetter = @"A:\"; break; case "biggestdriveletter": _LargestDriveLetter = CheckDriveLetter(Rd.ReadString().Trim()); if (_LargestDriveLetter == null) _LargestDriveLetter = @"Z:\"; break; case "source": if (BackupSource.SourcePath != "" && BackupSource.Name != "") _Sources.Add(BackupSource); BackupSource = new BackupSource(); break; case "subfolder": Subfolder = Rd.ReadString().Trim(); break; case "networkshare": NetworkShare = Rd.ReadString().Trim(); break; case "retries": if (int.TryParse(Rd.ReadString().Trim(), out TempInt)) _Retries = TempInt; break; case "waitbetweenretries": if (int.TryParse(Rd.ReadString().Trim(), out TempInt)) _WaitBetweenRetries = TempInt; break; case "exitafterbackup": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") _AutoExit = true; else _AutoExit = false; break; case "alwaysexitafterbackup": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") _AutoExitAlways = true; else _AutoExitAlways = false; break; case "programbeforebackup": ProgramBeforeBackup = Rd.ReadString().Trim(); break; case "argumentsprogrambeforebackup": ArgumentsProgramBeforeBackup = Rd.ReadString().Trim(); break; case "programbeforebackupadmin": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") ProgramBeforeBackupAdmin = true; else ProgramBeforeBackupAdmin = false; break; case "programafterbackup": ProgramAfterBackup = Rd.ReadString().Trim(); break; case "argumentsprogramafterbackup": ArgumentsProgramAfterBackup = Rd.ReadString().Trim(); break; case "programafterbackupadmin": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") ProgramAfterBackupAdmin = true; else ProgramAfterBackupAdmin = false; break; case "programonerror": ProgramOnError = Rd.ReadString().Trim(); break; case "argumentsprogramonerror": ArgumentsProgramOnError = Rd.ReadString().Trim(); break; case "programonerroradmin": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") ProgramOnErrorAdmin = true; else ProgramOnErrorAdmin = false; break; case "startmode": if (Rd.ReadString().Trim().ToLower() == "debug") _StartMode = DebugMode.Debug; break; case "incrementalbackup": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") _IncrementalBackup = true; else _IncrementalBackup = false; break; case "deletefilesbeforecopying": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") _DeleteFilesBeforeCopying = true; else _DeleteFilesBeforeCopying = false; break; case "silentmode": Temp = Rd.ReadString().Trim().ToLower(); if (Temp == "1" || Temp == "true") _SilentMode = true; else _SilentMode = false; break; } } } } } } catch (Exception ex) { HelperFunctions.ShowError("Please select a valid XML settings file. " + ex.Message); } if (BackupSource.SourcePath != "") { _Sources.Add(BackupSource); } return true; } catch (XmlException ex) { HelperFunctions.ShowError(ex.Message); } catch (Exception ex) { HelperFunctions.ShowError(ex.Message); } GlobalData.SettingsInAppData = false; return false; }
public bool Remove(BackupSource item) { return _BackupSources.Remove(item); }
public void Insert(int index, BackupSource item) { _BackupSources.Insert(index, item); }
public int IndexOf(BackupSource item) { return _BackupSources.IndexOf(item); }
public void CopyTo(BackupSource[] array, int arrayIndex) { _BackupSources.CopyTo(array, arrayIndex); }
public bool Contains(BackupSource BackupSource) { return _BackupSources.Contains(BackupSource); }
public void Add(BackupSource BackupSource) { _BackupSources.Add(BackupSource); }