Exemplo n.º 1
0
        /// <summary>
        /// The Vm_DoneEditingRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DoneEditingRequested(object sender, EventArgs e)
        {
            DbCore.Update(viewModel);
            var win = Window.GetWindow(this);

            win.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the HideSelectedItemsRequested event.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_HideSelectedFoldersRequested(object sender, EventArgs e)
        {
            Debug.Assert(sender is MainViewModel);
            var vm = sender as MainViewModel;

            var selectedToHide = new List <FolderViewModel>();

            foreach (var item in vm.SelectedFoldersCollection)
            {
                if (item.IsHidden == false)
                {
                    selectedToHide.Add(item);
                }
            }

            if (selectedToHide.Count == 0)
            {
                App.Inform("No Folders to Hide", "There are no unhidden folders to hide in the current selection.");
                return;
            }

            var folderNames = Environment.NewLine +
                              Environment.NewLine;

            foreach (var item in selectedToHide)
            {
                folderNames += item.FolderName + Environment.NewLine;
            }

            var proceed = App.LastChance("Hide Folders Request", $"Hiding Selected Folders", $"This operation will move these (this) {selectedToHide.Count} folder(s) from the community directory to the hidden directory:" +
                                         folderNames +
                                         Environment.NewLine +
                                         "Is this what you want to do?");

            int count = 0;

            if (proceed)
            {
                var su = Locator.SetupViewModel;
                foreach (var item in selectedToHide)
                {
                    if (FileOps.Hide(item.FolderName, su.CommunityFolder, su.HiddenFilesFolder))
                    {
                        item.IsHidden = true;
                        count++;
                    }
                }

                DbCore.Update(selectedToHide);

                if (count == selectedToHide.Count)
                {
                    App.Inform("Hide Folders Request Results", "All unhidden folders were successfully hidden.");
                }
                else
                {
                    App.Inform("Hide Folders Request Results", $"{selectedToHide.Count - count} folder(s) could not be hidden. Synchronization may be necessary.");
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnClosing(CancelEventArgs e)
        {
            var vm = this.DataContext as FolderViewModel;

            Debug.Assert(vm != null);

            if (!vm.DeleteScheduled)
            {
                DbCore.Update(vm);
            }

            base.OnClosing(e);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the RestoreFolderRequested event.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_RestoreFolderRequested(object sender, EventArgs e)
        {
            Debug.Assert(sender is FolderViewModel);
            var vm = sender as FolderViewModel;

            var proceed = App.LastChance("Restore Folder Request", $"Restoring {vm.FolderName}", $"This operation will move {vm.FolderName} from the hidden directory to the community directory. Is this what you want to do?.");
            var su      = Locator.SetupViewModel;

            if (proceed)
            {
                vm.IsHidden = false;
                FileOps.Restore(vm.FolderName, su.CommunityFolder, su.HiddenFilesFolder);
                DbCore.Update(vm);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// The Vm_BrowseZipFileRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_BrowseZipFileRequested(object sender, EventArgs e)
        {
            var vm = sender as ZipFileViewModel;

            Debug.Assert(vm != null);

            var dia = new OpenFileDialog
            {
                AddExtension     = false,
                CheckFileExists  = true,
                Multiselect      = false,
                Title            = "Find a Plugin Package to Add",
                DereferenceLinks = true,
                Filter           = "Zip files (*.zip, *.7z)|*.zip;*.7z|Exe files (*.exe)|*.exe|All files (*.*)|*.*",
                FilterIndex      = 1,
                InitialDirectory = Locator.SetupViewModel.ZipFilesFolder
            };

            var result = dia.ShowDialog();

            if (result == null || result == false)
            {
                return;
            }

            var fullpath = dia.FileName;
            var filename = Path.GetFileName(fullpath);
            var path     = Path.GetDirectoryName(fullpath);
            var fi       = new FileInfo(fullpath);

            if (vm.Filename != filename || vm.FileDate != fi.CreationTime)
            {
                vm.FileDate  = fi.CreationTime;
                vm.AddedDate = DateTime.Now;
                vm.Filename  = filename;
                vm.FileSize  = fi.Length;
            }

            vm.FilePath = path;

            DbCore.Update(vm);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the HideFolderRequested event.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_HideFolderRequested(object sender, EventArgs e)
        {
            Debug.Assert(sender is FolderViewModel);
            var vm = sender as FolderViewModel;

            var proceed = App.LastChance("Hide Folder Request", $"Hiding {vm.FolderName}", $"This operation will move {vm.FolderName} from the community directory to the hidden directory. Is this what you want to do?.");
            var su      = Locator.SetupViewModel;

            if (proceed)
            {
                if (FileOps.Hide(vm.FolderName, su.CommunityFolder, su.HiddenFilesFolder))
                {
                    vm.IsHidden = true;
                    DbCore.Update(vm);
                    return;
                }

                App.Inform("Hide Folder Request Error", $"{vm.FolderName} could not be hidden. Synchronization may be necessary.");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The InstallButtonClick.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="RoutedEventArgs"/>.</param>
        private void InstallButtonClick(object sender, RoutedEventArgs e)
        {
            var vm        = DataContext as IArchiveViewModel;
            var directory = vm.SelectedDirectory;

            if (directory.Entries.Any(m => m.WillInstall) == false)
            {
                return;
            }

            var installFolder = Locator.SetupViewModel.CommunityFolder;

            Debug.Assert(string.IsNullOrEmpty(installFolder) == false);

            // var wd = App.WaitDialog("Your selected contents are being installed.");
            IEnumerable <string> installedFolders;

            if (vm.AreAnyCheckedEntriesInstalled(installFolder))
            {
                if (App.LastChance("Overwrite Files?", "This operation will require some files and folders to be overwritten.", "Do you want to do this?", true))
                {
                    // #Note This should on a background thread
                    // wd.Show();
                    installedFolders = vm.InstallCheckedEntries(installFolder, true);
                }
                else
                {
                    return;
                }
            }
            else
            {
                // #Note See note above.
                // wd.Show();
                installedFolders = vm.InstallCheckedEntries(installFolder);
            }

            var mainVm    = Locator.MainViewModel;
            var packageId = vm.PackageId;

            // This will update the DB for the new folders
            foreach (var folderName in installedFolders)
            {
                var fullName    = Path.Combine(installFolder, folderName);
                var di          = new DirectoryInfo(fullName);
                var installDate = di.CreationTime;

                if (mainVm.FolderCollection.Any(e => e.FolderName.ToLower() == folderName.ToLower()))
                {
                    var oldFe = mainVm.FolderCollection.First(e => e.FolderName.ToLower() == folderName.ToLower());
                    oldFe.PackageId = packageId;
                    DbCore.Update(oldFe);
                    continue;
                }

                var newFe = new FolderViewModel()
                {
                    FolderName  = folderName,
                    PackageId   = packageId,
                    InstallDate = installDate
                };

                DbCore.Add(newFe);
                mainVm.FolderCollection.Add(newFe);
            }

            // wd.Close();
            App.Inform("Zip Contents Installed", "The selected contents have been installed in your community folder.");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the SynchronizeDataBaseRequested event.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_SynchronizeDataBaseRequested(object sender, EventArgs e)
        {
            var su = Locator.SetupViewModel;
            var cf = su.CommunityFolder;
            var hf = su.HiddenFilesFolder;

            var communityFolderNames = Directory.GetDirectories(cf);
            var hiddenFolderNames    = Directory.GetDirectories(hf);

            for (int i = 0; i < communityFolderNames.Length; i++)
            {
                ShortenName(ref communityFolderNames[i]);
            }

            for (int i = 0; i < hiddenFolderNames.Length; i++)
            {
                ShortenName(ref hiddenFolderNames[i]);
            }

            var allNames = new List <string>();

            allNames.AddRange(communityFolderNames);
            allNames.AddRange(hiddenFolderNames);

            var temp = new List <FolderViewModel>();

            // Look for folders that are listed in FolderCollection but
            // don't exist in either the community folder or the hidden
            // folder, and add those to temp.
            foreach (var folder in Locator.MainViewModel.FolderCollection)
            {
                if (allNames.Contains(folder.FolderName))
                {
                    continue;
                }

                temp.Add(folder);
            }

            // Remome the outdated records from FolderCollection.
            foreach (var folder in temp)
            {
                Locator.MainViewModel.FolderCollection.Remove(folder);
            }

            // Delete the outdated records from the database.
            DbCore.Delete(temp);
            temp.Clear();

            // Correct hidden folder statuses if they are no longer
            // hidden.
            foreach (var item in hiddenFolderNames)
            {
                var folder = Locator.MainViewModel.FolderCollection.Where(m => m.FolderName == item).FirstOrDefault();
                if (folder == null || folder.IsHidden)
                {
                    continue;
                }

                folder.IsHidden = true;
                temp.Add(folder);
            }

            // Correct unhidden folder statuses if they are now hidden.
            foreach (var item in communityFolderNames)
            {
                var folder = Locator.MainViewModel.FolderCollection.Where(m => m.FolderName == item).FirstOrDefault();
                if (folder == null || !folder.IsHidden)
                {
                    continue;
                }

                folder.IsHidden = false;
                temp.Add(folder);
            }

            DbCore.Update(temp);
            temp.Clear();

            // Add new community folders to temp
            foreach (var item in communityFolderNames.Where(m => !Locator.MainViewModel.FolderCollection.Any(v => v.FolderName == m)))
            {
                var di = new DirectoryInfo(Path.Combine(Locator.SetupViewModel.CommunityFolder, item));
                var vm = new FolderViewModel()
                {
                    FolderName  = item,
                    IsHidden    = false,
                    InstallDate = di.CreationTime
                };

                temp.Add(vm);
            }

            // Add new hidden folders to temp
            foreach (var item in hiddenFolderNames.Where(m => !Locator.MainViewModel.FolderCollection.Any(v => v.FolderName == m)))
            {
                var di = new DirectoryInfo(Path.Combine(Locator.SetupViewModel.HiddenFilesFolder, item));
                var vm = new FolderViewModel()
                {
                    FolderName  = item,
                    IsHidden    = true,
                    InstallDate = di.CreationTime
                };

                temp.Add(vm);
            }

            // Add new folders to the database.
            DbCore.Add(temp);
            // Add new folders to FolderCollection.
            foreach (var item in temp)
            {
                Locator.MainViewModel.FolderCollection.Add(item);
            }

            // Fix InstallDate field error from PluginManager 1.0.17 Beta
            var ErroneousDate = DateTimeOffset.Parse("12/31/1600 6:00:00 PM").DateTime;

            foreach (var item in Locator.MainViewModel.FolderCollection
                     .Where(m => m.InstallDate == ErroneousDate))
            {
                var path = item.IsHidden ? Locator.SetupViewModel.HiddenFilesFolder : Locator.SetupViewModel.CommunityFolder;
                var di   = new DirectoryInfo(Path.Combine(path, item.FolderName));
                item.InstallDate = di.CreationTime;
                DbCore.Update(item);
            }
        }