Example #1
0
        private void CalculateAllUpdateFileExtensionsAreChecked()
        {
            if (UpdateFileExtensions == null)
            {
                return;
            }

            if (UpdateFileExtensions.All(x => x.IsChecked))
            {
                _allUpdateFileExtensionsAreChecked = true;
            }
            else if (UpdateFileExtensions.All(x => !x.IsChecked))
            {
                _allUpdateFileExtensionsAreChecked = false;
            }
            else
            {
                _allUpdateFileExtensionsAreChecked = null;
            }
            OnPropertyChanged("AllUpdateFileExtensionsAreChecked");
        }
Example #2
0
        private void UpdateApplicationOkCommand_Execute(object obj)
        {
            var application = SelectedApplication;

            var fileExtensions = UpdateFileExtensions.Where(x => x.IsChecked).Select(x => (string)x.Tag).ToArray();

            if (!fileExtensions.Any())
            {
                return;
            }

            var search = false;

            if (application.Backups.All(x => x.Date != DateTime.Today))
            {
                if (BackupApplication(application))
                {
                    search = true;
                }
            }

            var directories = _updateParentDirectory.GetDirectories("*", SearchOption.AllDirectories);

            foreach (var directory in directories)
            {
                var relativePath = directory.FullName.Substring(_updateParentDirectory.FullName.Length + 1);
                var newPath      = Path.Combine(application.FullPath, relativePath);
                Directory.CreateDirectory(newPath);
            }

            var updatedFilesCount = 0;

            var files = _updateParentDirectory.GetFiles("*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                if (!fileExtensions.Contains(file.Extension.ToLower()))
                {
                    continue;
                }

                var relativePath = file.FullName.Substring(_updateParentDirectory.FullName.Length + 1);
                var newPath      = Path.Combine(application.FullPath, relativePath);
                while (true)
                {
                    try
                    {
                        File.Copy(file.FullName, newPath, true);
                        updatedFilesCount++;
                        break;
                    }
                    catch (IOException ex)
                    {
                        var res2 = MessageBox.Show(string.Format("{0}\nError: {1}\n\nUnable to copy the file.\nClick OK to retry or Cancel to skip.", newPath, ex.Message), string.Format("Update {0}", application.Name), MessageBoxButton.OKCancel);
                        if (res2 == MessageBoxResult.Cancel)
                        {
                            break;
                        }
                    }
                }
            }

            UpdateFileExtensions = null;

            if (search)
            {
                Search();
                SelectedApplication = application;
            }

            MessageBox.Show(string.Format("Updated {0} files.", updatedFilesCount), string.Format("Update {0}", application.Name), MessageBoxButton.OK, MessageBoxImage.Information);
        }