예제 #1
0
        /// <summary>
        /// Handles the DeleteSelectedItemsRequested event.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DeleteSelectedFoldersRequested(object sender, EventArgs e)
        {
            Debug.Assert(sender is MainViewModel);
            var vm = sender as MainViewModel;

            var selectedToDelete = new List <FolderViewModel>();

            foreach (var item in vm.SelectedFoldersCollection)
            {
                selectedToDelete.Add(item);
            }

            var folderNames = Environment.NewLine +
                              Environment.NewLine;

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

            var proceed = App.LastChance("Delete Folders Request", $"Deleting Selected Folders", $"This operation will delete these (this) {selectedToDelete.Count} folder(s) from the community or hidden directories:" +
                                         folderNames +
                                         Environment.NewLine +
                                         "Is this what you want to do?");

            if (proceed)
            {
                var hiddenFolder    = AppSettings.Default.HiddenFilesFolder;
                var communityFolder = AppSettings.Default.CommunityFolder;

                foreach (var item in selectedToDelete)
                {
                    FileOps.Delete(item.FolderName, item.IsHidden ? hiddenFolder : communityFolder);
                    vm.FolderCollection.Remove(item);
                }

                DbCore.Delete(selectedToDelete);
            }
        }
예제 #2
0
 /// <summary>
 /// The DeleteRecord.
 /// </summary>
 /// <param name="item">The item<see cref="ZipFileViewModel"/>.</param>
 private static void DeleteRecord(ZipFileViewModel item)
 {
     DbCore.Delete(item);
     Locator.MainViewModel.ZipFileFolderCollection.Remove(item);
 }
예제 #3
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);
            }
        }