/// <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); } }
/// <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."); }
/// <summary> /// The Vm_AddNewZipFileRequested. /// </summary> /// <param name="sender">The sender<see cref="object"/>.</param> /// <param name="e">The e<see cref="EventArgs"/>.</param> private void Vm_AddNewZipFileRequested(object sender, EventArgs e) { var dia = new OpenFileDialog { AddExtension = false, CheckFileExists = true, Multiselect = true, Title = "Find Zip Files 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 == true) { var zipList = new List <ZipFileViewModel>(); foreach (var fullpath in dia.FileNames) { var filename = Path.GetFileName(fullpath); var path = Path.GetDirectoryName(fullpath); var di = new FileInfo(fullpath); var zipFile = new ZipFileViewModel() { FileDate = di.CreationTime, Filename = filename, FilePath = path, AddedDate = DateTime.Now, FileSize = di.Length }; zipList.Add(zipFile); } DbCore.Add(zipList); string fileItems = ""; foreach (var item in zipList) { Locator.MainViewModel.ZipFileFolderCollection.Add(item); fileItems += Environment.NewLine + item.Filename; } string message; string title; var isSingle = zipList.Count == 1; if (isSingle) { message = $"One zip file was added:\n{fileItems}"; title = "Zip File Added"; } else { message = $"These {zipList.Count} zip files were added:\n{fileItems}"; title = "Zip Files Added"; } App.Inform(title, message); } }