public void SaveChanges() { Settings.Default.RecentFiles_MaxFiles = (int)nudMaxRecentFiles.Value; Settings.Default.CheckForUpdates = chbCheckForUpdates.Checked; Settings.Default.RememberArchives = chbRememberArchives.Checked; Settings.Default.SortArchiveDirectories = chbSortBSADirectories.Checked; Settings.Default.RetrieveRealSize = chbRetrieveRealSize.Checked; Settings.Default.EncodingCodePage = (cbEncodings.SelectedItem as Encoding).CodePage; Enums.Icons icons = Enums.Icons.None; if (chbIconsFileList.Checked) { icons |= Enums.Icons.FileList; } if (chbIconsFolderTree.Checked) { icons |= Enums.Icons.FolderTree; } Settings.Default.Icons = icons; Settings.Default.MatchLastWriteTime = chbMatchLastWriteTime.Checked; Settings.Default.ReplaceGNFExt = chbReplaceGNFExt.Checked; Settings.Default.QuickExtractPaths.Clear(); Settings.Default.QuickExtractPaths.AddRange(lvQuickExtract.Items .Cast <ListViewItem>().Select(x => (QuickExtractPath)x.Tag)); Settings.Default.PreviewMaxResolution = new Size( (int)nudMaxResolutionW.Value, (int)nudMaxResolutionH.Value); Settings.Default.BuiltInPreviewing.Clear(); Settings.Default.BuiltInPreviewing.AddRange(lvPreviewing.Items .Cast <ListViewItem>().Where(x => x.Checked).Select(x => x.Text).ToArray()); if (this.CheckAssociationAndIntegrationChanged()) { if (FileAssociation.HasAdminPrivileges() == false) { MessageBox.Show(this, "File association and shell integration requires administrative rights.\n\nPrompt will be shown automatically.", "BSA Browser", MessageBoxButtons.OK, MessageBoxIcon.Information); } // If file association is disabled we don't care whether shell integration has changed or not bool?shellIntegration = null; if (cbAssociateFiles.Checked) { shellIntegration = cbShellIntegration.Checked; } this.ToggleAssociateAndIntegration(cbAssociateFiles.Checked, shellIntegration); } }
private bool ToggleAssociateAndIntegration(bool fileAssociation, bool?shellIntegration) { var args = new List <string>(); if (fileAssociation != _fileAssociationInitialValue) { args.Add(fileAssociation ? "--associate" : "--associate-disable"); } // Ignore 'shellIntegration' if it's null, don't even compare to cached if (shellIntegration != null && shellIntegration != _shellIntegrationInitialValue) { args.Add(shellIntegration == true ? "--integration" : "--integration-disable"); } if (args.Count == 0) { return(false); } if (FileAssociation.HasAdminPrivileges()) { FileAssociation.ToggleAssociationAndIntegration(args.ToArray()); } else { // Prompt for admin privileges var process = Process.Start(new ProcessStartInfo(Application.ExecutablePath) { Arguments = string.Join(" ", args), UseShellExecute = true, Verb = "runas" }); process.WaitForExit(); } return(true); }