public MainWindow(string[] args) { if (args.Length < 1) { Panic("Please drop a .dir file into this application."); } #if !DEBUG try { #endif fs = new DirFS(args[0]); new Thread(() => { fs.Mount(DRIVE_LETTER + ":\\", DokanOptions.StderrOutput); Dispatcher.Invoke(() => { unmountingPhase = UnmountingPhase.Shutdown; Close(); }); }).Start(); #if !DEBUG } catch (Exception e) { Panic(e.ToString()); } #endif InitializeComponent(); pathRow.Text = args[0]; }
private void OnClosing(object sender, CancelEventArgs e) { if (unmountingPhase != UnmountingPhase.NotInitiated) { if (unmountingPhase == UnmountingPhase.Initiated) { e.Cancel = true; } return; } try { fs.Save(); if (Dokan.Unmount(DRIVE_LETTER)) { e.Cancel = true; unmountingPhase = UnmountingPhase.Initiated; pathRow.Opacity = 0; messageRow.Text = "Unmounting..."; saveButton.Opacity = 0; saveButton.IsEnabled = false; } else { throw new IOException("Unmount error"); } } catch (WrappedFileException ef) { if (MessageBox.Show("Some files were not successfully converted and retained unmodified. " + "If you close this application now, you will lose any changes made to these 'faulted' files.\n\n" + ef.MessageBoxText + "\n\nDo you want to close the app?", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) != MessageBoxResult.Yes) { e.Cancel = true; } } catch (Exception ex) { MessageBox.Show("Due to some reason, unmounting wasn't successful.\n\n" + ex.GetType().ToString() + ": " + ex.Message + "\n\n" + "The application will be TERMINATED right after the OK button is pressed.\n\nBye.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(-1); } }