Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
        }