public void TakeFocus() { if (dirListMode) { LogDirsListView.Focus(); } }
public LogSelectionView() { InitializeComponent(); TxDictionaryBinding.AddTextBindings(this); LogBasePathHeader.Text = Tx.T("log selection view.list.log base path"); LastUpdateHeader.Text = Tx.T("log selection view.list.last update"); SizeHeader.Text = Tx.T("log selection view.list.size"); Dock = DockStyle.Fill; // Set up and initialise column sorting logDirsColumnSorter = new ListViewColumnSorter(LogDirsListView); logDirsColumnSorter.SortColumn = 0; logDirsColumnSorter.Order = SortOrder.Ascending; logDirsColumnSorter.Update(); LogDirsListView.ListViewItemSorter = logDirsColumnSorter; // Force-enable double buffering in the ListView to prevent flickering var prop = LogDirsListView.GetType().GetProperty( "DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (prop != null) { prop.SetValue(LogDirsListView, true, null); } }
public void FindLogBasePath() { string appDir = Path.GetDirectoryName(Application.ExecutablePath); Dictionary <string, LogBasePathInfo> logPaths = new Dictionary <string, LogBasePathInfo>(); // Find *.flconfig in appDir foreach (string fileName in Directory.GetFiles(appDir, "*.flconfig")) { // Read the path setting var config = new ConfigReader(fileName); string basePath = config.ReadPath(); // If a log file was found in that path, put it on the list if (!string.IsNullOrEmpty(basePath)) { CheckLogBasePath(basePath, logPaths); } } // Find *.exe in appDir foreach (string fileName in Directory.GetFiles(appDir, "*.exe")) { string baseName = Path.GetFileNameWithoutExtension(fileName); // Go through all possible default log paths for the exe file // If a log file was found in a path, put it on the list CheckLogBasePath(Path.Combine(appDir, "log", baseName), logPaths); CheckLogBasePath(Path.Combine(appDir, baseName), logPaths); CheckLogBasePath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), baseName + "-log", baseName), logPaths); CheckLogBasePath(Path.Combine(Path.GetTempPath(), baseName + "-log", baseName), logPaths); } if (logPaths.Count == 1) { SetLogBasePath(logPaths.Values.First().LogBasePath); } else if (logPaths.Count > 1) { LogDirsListView.Items.Clear(); foreach (var kvp in logPaths) { AddDirectory(kvp.Value); } // Sort by latest update time logDirsColumnSorter.SortColumn = 1; logDirsColumnSorter.Order = SortOrder.Descending; logDirsColumnSorter.Update(); CurrentLabel.Hide(); SelectedLogDirText.Hide(); LogDirsListView.Show(); dirListMode = true; UpdateButtons(); } }
private void BrowseLogButton_Click(object sender, EventArgs args) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.FileName = SelectedLogDirText.Text; dlg.Filter = Tx.T("log selection view.file dialog.filter"); if (!string.IsNullOrEmpty(SelectedLogDirText.Text)) { dlg.InitialDirectory = Path.GetDirectoryName(SelectedLogDirText.Text); } dlg.Title = Tx.T("log selection view.file dialog.title"); if (dlg.ShowDialog() == DialogResult.OK) { if (ScanDirectoryWorker.IsBusy) { ScanDirectoryWorker.CancelAsync(); } string basePath = GetBasePath(dlg.FileName); SelectedLogDirText.Text = basePath; try { SetLogBasePath(basePath); } catch { MessageBox.Show( FindForm(), Tx.T("msg.logpath parameter invalid", "value", basePath), Tx.T("msg.title.error"), MessageBoxButtons.OK, MessageBoxIcon.Error); ResetLogBasePath(); FindLogBasePath(); return; } CurrentLabel.Show(); SelectedLogDirText.Show(); FindLogsButton.Show(); LogDirsListView.Hide(); dirListMode = false; fullScanMode = false; UpdateButtons(); } } }
private void FindLogsButton_Click(object sender, EventArgs args) { CurrentLabel.Hide(); SelectedLogDirText.Hide(); FindLogsButton.Hide(); ConfigErrorLabel.Hide(); LogDirsListView.Items.Clear(); LogDirsListView.Show(); dirListMode = true; UpdateButtons(); if (ignoredDirectories.Count == 0) { ignoredDirectories.Add(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\"); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Adobe\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Common Files\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Google\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Reference Assemblies\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows ")); if (Environment.Is64BitOperatingSystem) { ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Adobe\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Common Files\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Google\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Reference Assemblies\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows ")); } ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Adobe\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft\\")); ignoredDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Package Cache\\")); } fullScanMode = true; ScanDirectoryWorker.RunWorkerAsync(); MainForm.Instance.SetProgress(true, -1); }