private static void CheckForDupes(List <SavedPath> curPath) { var duplicates = curPath.GroupBy(x => x.PathDirectory).Where(x => x.Count() > 1).Select(x => x.Key).ToList(); if (duplicates.Count > 0) { List <SavedPath> allDupes = new List <SavedPath>(); foreach (string dupe in duplicates) { foreach (var item in curPath.FindAll(x => x.PathDirectory == dupe)) { allDupes.Add(item); logTemp.Warn($"Duplicate found: {item.SeqNumber} {item.PathType} {item.PathDirectory}"); } } Duplicates d = new Duplicates(); d.dgDupes.ItemsSource = allDupes; d.Owner = Application.Current.MainWindow; d.WindowStartupLocation = WindowStartupLocation.CenterOwner; _ = d.ShowDialog(); } else { _ = TKMessageBox.Show("No duplicates found.", "PathTools", MessageBoxButton.OK, MessageBoxImage.Check); } }
private void FirstRunSetup() { if (UserSettings.Setting.FirstRun) { Visibility = Visibility.Visible; MessageBoxResult result = TKMessageBox.Show("It looks like this is the first run of PathTools.\n\n" + "Would you like to keep a log file?", "PathTools - Keep a Log File?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { LogFileWindow log = new LogFileWindow { Owner = this }; log.cbKeepLog.IsChecked = true; _ = log.ShowDialog(); } else if (result == MessageBoxResult.No) { UserSettings.Setting.KeepLogFile = false; } else if (result == MessageBoxResult.Cancel) { Application.Current.Shutdown(); } UserSettings.Setting.FirstRun = false; } }
public static void ViewTextFile(string txtfile) { if (File.Exists(txtfile)) { try { using (Process p = new Process()) { p.StartInfo.FileName = txtfile; p.StartInfo.UseShellExecute = true; p.StartInfo.ErrorDialog = false; _ = p.Start(); } } catch (Win32Exception ex) { if (ex.NativeErrorCode == 1155) { using (Process p = new Process()) { p.StartInfo.FileName = "notepad.exe"; p.StartInfo.Arguments = txtfile; p.StartInfo.UseShellExecute = true; p.StartInfo.ErrorDialog = false; _ = p.Start(); logTemp.Info($"Falling back to Notepad to open {txtfile}"); } } else { _ = TKMessageBox.Show($"Error reading file {txtfile}\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); logTemp.Error(ex, $"Unable to open {txtfile}"); } } catch (Exception ex) { _ = TKMessageBox.Show($"Unable to start default application used to open {txtfile}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); logTemp.Error(ex, $"Unable to open {txtfile}"); } } else { Debug.WriteLine($">>> File not found: {txtfile}"); logTemp.Error($"{txtfile} could not be found"); _ = TKMessageBox.Show($"The file: {txtfile} could not be found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) { logTemp.Error("Unhandled Exception"); Exception e = (Exception)args.ExceptionObject; logTemp.Error(e.Message); if (e.InnerException != null) { logTemp.Error(e.InnerException.ToString()); } logTemp.Error(e.StackTrace); _ = TKMessageBox.Show($"An unexpected error has occurred. \n{e.Message}\nSee the log file for more information.", "PathTools Error", MessageBoxButton.OK, MessageBoxImage.Error); }
//Window Closing private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (cbKeepLog.IsChecked == true && string.IsNullOrEmpty(tbLogFileName.Text)) { _ = TKMessageBox.Show("Please supply a log file name or uncheck 'Keep a log' checkbox", "Try again please", MessageBoxButton.OK, MessageBoxImage.Warning); e.Cancel = true; } else { UserSettings.SaveSettings(); } Debug.WriteLine("LogFileWindow closing"); }
private void CxmTerminal_Click(object sender, RoutedEventArgs e) { if (dgPath.SelectedItem != null) { DisplayPath row = (DisplayPath)dgPath.SelectedItem; string selPath = Path.GetFullPath(row.PathDirectory).TrimEnd('\\'); using Process wt = new Process(); wt.StartInfo.FileName = "wt.exe"; wt.StartInfo.Arguments = $"-d \"{selPath}\" "; wt.StartInfo.UseShellExecute = false; try { _ = wt.Start(); } catch (Win32Exception ex) { logTemp.Warn(ex, "Unable to launch Windows Terminal. Falling back to CMD.exe"); using Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.Arguments = "/k Title PathTools"; cmd.StartInfo.WorkingDirectory = selPath; cmd.StartInfo.UseShellExecute = true; try { _ = cmd.Start(); } catch (Exception ex2) { logTemp.Warn(ex2, "Unable to launch CMD.exe"); _ = TKMessageBox.Show("Unable to launch a terminal. See log file.", "PathTools Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { _ = TKMessageBox.Show("Unable to launch a terminal. See log file.", "PathTools Error", MessageBoxButton.OK, MessageBoxImage.Error); logTemp.Warn(ex, "Unable to launch Windows Terminal."); } } }
private void WriteSavedPathFile() { // Write the current path to disk for next time try { JsonSerializerOptions opts = new JsonSerializerOptions { AllowTrailingCommas = true, ReadCommentHandling = JsonCommentHandling.Skip, WriteIndented = true }; string json = JsonSerializer.Serialize(GetCurrentPath(), opts); File.WriteAllText(savedPathFile, json); } catch (Exception) { TKMessageBox.Show("Error saving file", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void MnuLongPath_Click(object sender, RoutedEventArgs e) { string regMessage = null; try { using RegistryKey key = Registry.LocalMachine. OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\FileSystem"); string longPath = key.GetValue("LongPathsEnabled", "no value present").ToString(); if (longPath != null) { if (longPath == "1") { regMessage = "Long paths ARE enabled."; } else { regMessage = "Long paths are NOT enabled."; } regMessage += "\n\nRegistry location and value:" + "\n\nHKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\\LongPathsEnable = " + longPath; } else { regMessage = "Registry value for LongPathsEnabled not found"; } } catch (SecurityException) { regMessage = "Permission to access registry denied"; } catch (UnauthorizedAccessException) { regMessage = "No registry rights "; } finally { _ = TKMessageBox.Show(regMessage, "Long Paths", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void ReadMeLink_Click(object sender, RoutedEventArgs e) { try { using (Process ps = new Process()) { ps.StartInfo.FileName = ".\\ReadMe.txt"; ps.StartInfo.UseShellExecute = true; _ = ps.Start(); } e.Handled = true; Close(); } catch (System.Exception ex) { _ = TKMessageBox.Show($"Error opening ReadMe.txt\n{ex}", "PathTools Error", MessageBoxButton.OK, TKUtils.MessageBoxImage.Error); } }
private void OnNavigate(object sender, RequestNavigateEventArgs e) { Debug.WriteLine($"Opening {e.Uri.AbsoluteUri}"); try { using (Process ps = new Process()) { ps.StartInfo.FileName = e.Uri.AbsoluteUri; ps.StartInfo.UseShellExecute = true; _ = ps.Start(); } e.Handled = true; Close(); } catch (System.Exception ex) { _ = TKMessageBox.Show($"Error opening the link\n{ex}", "PathTools Error", MessageBoxButton.OK, TKUtils.MessageBoxImage.Error); } }
private void BtnOK_Click(object sender, RoutedEventArgs e) { if (cbKeepLog.IsChecked == true) { if (string.IsNullOrEmpty(tbLogFileName.Text)) { SystemSounds.Asterisk.Play(); _ = tbLogFileName.Focus(); tbLogFileName.Background = Brushes.LemonChiffon; lblStatus.Foreground = Brushes.Red; lblStatus.FontWeight = FontWeights.Bold; lblStatus.FontSize = 16; lblStatus.Text = "File name can't be blank"; return; } UserSettings.Setting.LogFile = tbLogFileName.Text; if (!File.Exists(tbLogFileName.Text)) { try { GlobalDiagnosticsContext.Set("LogPerm", tbLogFileName.Text); logPerm.Info($"This log file was created by {AppInfo.AppName} {AppInfo.TitleVersion}"); } catch (System.Exception ex) { logTemp.Error("Error creating log file."); logTemp.Error(ex, $"Error creating log file: {UserSettings.Setting.LogFile}"); _ = TKMessageBox.Show($"Error creating log file.\n{ex.Message}", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } } Close(); }
private void MnuPathLen_Click(object sender, RoutedEventArgs e) { string message = $"The PATH variable is {DisplayPath.TotalPathLength} bytes"; _ = TKMessageBox.Show(message, "Path Length", MessageBoxButton.OK, MessageBoxImage.Information); }