static void Main() { bool createdNew; var mutexSecurity = new MutexSecurity(); mutexSecurity.AddAccessRule(new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow)); using (var setupMutex = new Mutex(false, @"Global\JosipMedved_ChangeLetter", out createdNew, mutexSecurity)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Medo.Application.UnhandledCatch.ThreadException += new EventHandler <ThreadExceptionEventArgs>(UnhandledCatch_ThreadException); Medo.Application.UnhandledCatch.Attach(); var volumeArg = Medo.Application.Args.Current.GetValue("volume"); var letterArg = Medo.Application.Args.Current.GetValue("letter"); try { var volume = (volumeArg != null) ? Volume.GetFromVolumeName(volumeArg) : null; if (Medo.Application.Args.Current.ContainsKey("change")) { if ((volume != null) && (letterArg != null)) { volume.ChangeLetter(letterArg); } } else if (Medo.Application.Args.Current.ContainsKey("remove")) { if (volume != null) { volume.RemoveLetter(); } } else if (Medo.Application.Args.Current.ContainsKey("hide")) { if (letterArg != null) { ExplorerDrives.Hide(letterArg); } } else if (Medo.Application.Args.Current.ContainsKey("show")) { if (letterArg != null) { ExplorerDrives.Show(letterArg); } } } catch (Exception ex) { Medo.MessageBox.ShowError(null, ex.Message); } } }
private void btnShow_Click(object sender, EventArgs e) { if (Medo.MessageBox.ShowQuestion(this, "Restoring visibility of a drive letter will require Windows Explorer restart. Do you wish to proceed?", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } btnShow.Visible = false; try { var volume = cmbVolumes.SelectedItem as Volume; Executor.Show(volume.DriveLetter2); btnHide.Visible = true; } catch (NotSupportedException ex) { Medo.MessageBox.ShowError(this, ex.Message); } ExplorerDrives.RestartExplorer(); }
private void UpdateLetterVisibility(Volume volume) { string driveLetter = (volume != null) ? volume.DriveLetter2 : null; btnHide.Visible = false; btnShow.Visible = false; var isVisible = ExplorerDrives.IsVisible(driveLetter); if (isVisible.HasValue) { if (isVisible.Value) { btnHide.Visible = true; } else { btnShow.Visible = true; } } }