Exemplo n.º 1
0
 private bool SaveSettings()
 {
     if (IsDirty)
     {
         string msg;
         if (SettingsFilePath.IsNullOrWhiteSpace())
         {
             msg = "Do you want to save settings changes to untitled?";
         }
         else
         {
             msg = "Do you want to save settings changes to '{0}'?".FormatString(Path.GetFileName(SettingsFilePath));
         }
         MessageBoxResult r = MessageBox.Show(msg, Caption, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
         if (r == MessageBoxResult.Cancel)
         {
             return(true);
         }
         else if (r == MessageBoxResult.No)
         {
             IsDirty = false;
             return(false);
         }
         else
         {
             return(!SaveSettings(false));
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private void MyWindow_Loaded(object sender1, RoutedEventArgs e1)
        {
            _bindObj     = new ChoWPFBindableConfigObject <ChoAppSettings>();
            _appSettings = _bindObj.UnderlyingSource;
            _appSettings.Init();
            if (!SettingsFilePath.IsNullOrWhiteSpace() && File.Exists(SettingsFilePath))
            {
                _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
            }
            else
            {
                _appSettings.Reset();
            }

            DataContext   = this;
            _mainUIThread = Thread.CurrentThread;

            btnNewFile_Click(null, null);

            _dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
            _dispatcherTimer.Start();

            string x = _appSettings.SourceDirectory;
            ChoShellExtCmdLineArgs cmdLineArgs = new ChoShellExtCmdLineArgs();

            if (!cmdLineArgs.Directory.IsNullOrWhiteSpace())
            {
                _appSettings.SourceDirectory = cmdLineArgs.Directory;
            }

            IsDirty = false;
        }
Exemplo n.º 3
0
 protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs)
 {
     if (!SettingsFilePath.IsNullOrWhiteSpace())
     {
         SettingsFilePath = ChoPath.GetFullPath(SettingsFilePath);
     }
 }
Exemplo n.º 4
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            grpFolders.IsEnabled = !IsRunning;
            if (IsRunning)
            {
                btnRun.IsEnabled = false;
            }
            else
            {
                if (!txtSourceDirectory.Text.IsNullOrWhiteSpace() &&
                    Directory.Exists(txtSourceDirectory.Text) &&
                    !txtDestDirectory.Text.IsNullOrWhiteSpace()
                    )
                {
                    btnRun.IsEnabled = true;
                }
                else
                {
                    btnRun.IsEnabled = false;
                }
            }

            btnStop.IsEnabled       = IsRunning;
            btnNewFile.IsEnabled    = !IsRunning;
            btnOpenFile.IsEnabled   = !IsRunning;
            btnSaveFile.IsEnabled   = !IsRunning && IsDirty;
            btnSaveAsFile.IsEnabled = !IsRunning;
            if (SettingsFilePath.IsNullOrWhiteSpace())
            {
                this.ToolTip           = null;
                tbSettingsName.Text    = "<NEW>";
                tbSettingsName.ToolTip = "New File";
            }
            else
            {
                this.ToolTip           = SettingsFilePath;
                tbSettingsName.Text    = Path.GetFileNameWithoutExtension(SettingsFilePath);
                tbSettingsName.ToolTip = SettingsFilePath;
            }
            btnClear.IsEnabled = !IsRunning && txtStatus.Text.Length > 0;

            if (_fileNameProcessThread != null && _fileNameProcessThread.IsAlive)
            {
            }
            else
            {
            }
            // Forcing the CommandManager to raise the RequerySuggested event
            CommandManager.InvalidateRequerySuggested();
        }
Exemplo n.º 5
0
        public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
        {
            try
            {
                ChoAppSettings appSettings = new ChoAppSettings();
                if (!SettingsFilePath.IsNullOrWhiteSpace())
                {
                    if (!File.Exists(SettingsFilePath))
                    {
                        throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
                    }

                    appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                }

                ChoConsole.WriteLine();

                ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
                _roboCopyManager.Status += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };
                _roboCopyManager.AppStatus += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };

                _roboCopyManager.Process(appSettings.RoboCopyFilePath, appSettings.GetCmdLineParams(),
                                         appSettings, true);
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("RoboCopy operation cancelled by user.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
            }
        }
Exemplo n.º 6
0
        private bool SaveSettings(bool newFile)
        {
            SaveDirectories();

            if (newFile || SettingsFilePath.IsNullOrWhiteSpace())
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.DefaultExt = AppHost.AppFileExt;
                dlg.Filter     = "EazyCopy files|*{0}".FormatString(AppHost.AppFileExt);

                var result = dlg.ShowDialog();

                if (result == true)
                {
                    SettingsFilePath = dlg.FileName;
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                if (SettingsFilePath.IsNullOrWhiteSpace())
                {
                    return(true);
                }
                File.WriteAllText(SettingsFilePath, _appSettings.ToXml());
                IsDirty = false;
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed saving settings to file. {0}".FormatString(ex.Message), this.Caption, MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
Exemplo n.º 7
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (_msgBuffer.Length > 0)
            {
                lock (_msgBufferLock)
                {
                    if (_msgBuffer.Length > 0)
                    {
                        txtStatus.AppendText(_msgBuffer.ToString());
                        if (ScrollOutput)
                        {
                            txtStatus.ScrollToEnd();
                        }
                        _msgBuffer.Clear();
                    }
                }
            }
            if (IsStopping)
            {
                return;
            }

            grpFolders.IsEnabled = !IsRunning;

            if (IsRunning)
            {
                btnRun.IsEnabled = false;
            }
            else
            {
                if (!txtSourceDirectory.Text.IsNullOrWhiteSpace() &&
                    Directory.Exists(txtSourceDirectory.Text) &&
                    !txtDestDirectory.Text.IsNullOrWhiteSpace()
                    )
                {
                    btnRun.IsEnabled = true;
                }
                else
                {
                    btnRun.IsEnabled = false;
                }
            }
            if (txtSourceDirectory.Text.IsNullOrWhiteSpace() ||
                Directory.Exists(txtSourceDirectory.Text)
                )
            {
                SourceDirTooltip = "Choose source directory...";
                SourceDirStatus  = true;
            }
            else
            {
                SourceDirTooltip = $"Direcory not exists.";
                SourceDirStatus  = false;
            }

            btnStop.IsEnabled       = IsRunning;
            btnNewFile.IsEnabled    = !IsRunning;
            btnOpenFile.IsEnabled   = !IsRunning;
            btnSaveFile.IsEnabled   = !IsRunning && IsDirty;
            btnSaveAsFile.IsEnabled = !IsRunning;
            if (SettingsFilePath.IsNullOrWhiteSpace())
            {
                this.ToolTip           = null;
                tbSettingsName.Text    = "<NEW>";
                tbSettingsName.ToolTip = "New File";
            }
            else
            {
                this.ToolTip           = SettingsFilePath;
                tbSettingsName.Text    = Path.GetFileNameWithoutExtension(SettingsFilePath);
                tbSettingsName.ToolTip = SettingsFilePath;
            }
            btnClear.IsEnabled = !IsRunning && txtStatus.Text.Length > 0;

            if (_processFilesThread != null && _processFilesThread.IsAlive)
            {
            }
            else
            {
            }
            // Forcing the CommandManager to raise the RequerySuggested event
            CommandManager.InvalidateRequerySuggested();
        }