예제 #1
0
        public static void SaveCustomArguments(string projectFilePath, string newArguments)
        {
            using (SingleGlobalInstance.Acquire(Path.GetFileName(customArgumentsFilePath)))
            {
                if (!File.Exists(customArgumentsFilePath))
                {
                    if (newArguments == DefaultArguments)
                    {
                        return;
                    }
                    else
                    {
                        string directoryName = Path.GetDirectoryName(customArgumentsFilePath);
                        Directory.CreateDirectory(directoryName);
                        File.WriteAllLines(customArgumentsFilePath, new[] { projectFilePath + "=" + newArguments });
                        return;
                    }
                }

                var list = File.ReadAllLines(customArgumentsFilePath).ToList();

                if (FindArguments(list, projectFilePath, out string?arguments, out int index))
                {
                    list.RemoveAt(index);
                }

                list.Insert(0, projectFilePath + "=" + newArguments);
                if (list.Count >= MaximumProjectsInRecentArgumentsList)
                {
                    list.RemoveAt(list.Count - 1);
                }

                File.WriteAllLines(customArgumentsFilePath, list);
            }
        }
예제 #2
0
        private static void CleanupTempFiles()
        {
            using (SingleGlobalInstance.Acquire("StructuredLogViewerTempFileCleanup"))
            {
                if (cleanedUpTempFiles)
                {
                    return;
                }

                cleanedUpTempFiles = true;

                var folder = tempFolder;
                try
                {
                    foreach (var file in Directory.GetFiles(folder))
                    {
                        try
                        {
                            var fileInfo = new FileInfo(file);
                            if (fileInfo.LastWriteTimeUtc < DateTime.UtcNow - TimeSpan.FromDays(30))
                            {
                                fileInfo.Delete();
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                catch
                {
                }
            }
        }
예제 #3
0
        private static void ReadSettings()
        {
            using (SingleGlobalInstance.Acquire(Path.GetFileName(settingsFilePath)))
            {
                if (!File.Exists(settingsFilePath))
                {
                    return;
                }

                var lines = File.ReadAllLines(settingsFilePath);
                foreach (var line in lines)
                {
                    ProcessLine(Virtualization, line, ref enableTreeViewVirtualization);
                    //ProcessLine(ParentAllTargetsUnderProjectSetting, line, ref parentAllTargetsUnderProject);
                    ProcessLine(MarkResultsInTreeSetting, line, ref markResultsInTree);
                    ProcessLine(UseDarkThemeSetting, line, ref useDarkTheme);

                    void ProcessLine(string setting, string text, ref bool variable)
                    {
                        if (!text.StartsWith(setting))
                        {
                            return;
                        }

                        var value = text.Substring(setting.Length);

                        if (bool.TryParse(value, out bool boolValue))
                        {
                            variable = boolValue;
                        }
                    }
                }
            }
        }
예제 #4
0
 private static void SaveText(string storageFilePath, IEnumerable <string> lines)
 {
     using (SingleGlobalInstance.Acquire(Path.GetFileName(storageFilePath)))
     {
         string directoryName = Path.GetDirectoryName(storageFilePath);
         Directory.CreateDirectory(directoryName);
         File.WriteAllLines(storageFilePath, lines);
     }
 }
예제 #5
0
        private static IEnumerable <string> GetRecentItems(string storageFilePath)
        {
            using (SingleGlobalInstance.Acquire(Path.GetFileName(storageFilePath)))
            {
                if (!File.Exists(storageFilePath))
                {
                    return(Array.Empty <string>());
                }

                var lines = File.ReadAllLines(storageFilePath);
                return(lines);
            }
        }
예제 #6
0
        private static void SaveSettings()
        {
            var sb = new StringBuilder();

            sb.AppendLine(Virtualization + enableTreeViewVirtualization.ToString());
            sb.AppendLine(ParentAllTargetsUnderProjectSetting + parentAllTargetsUnderProject.ToString());
            sb.AppendLine(MarkResultsInTreeSetting + markResultsInTree.ToString());

            using (SingleGlobalInstance.Acquire(Path.GetFileName(settingsFilePath)))
            {
                File.WriteAllText(settingsFilePath, sb.ToString());
            }
        }
예제 #7
0
        private static void ReadSettings()
        {
            using (SingleGlobalInstance.Acquire(Path.GetFileName(settingsFilePath)))
            {
                if (!File.Exists(settingsFilePath))
                {
                    return;
                }

                var lines = File.ReadAllLines(settingsFilePath);
                foreach (var line in lines)
                {
                    if (line.StartsWith(Virtualization))
                    {
                        var value = line.Substring(Virtualization.Length);
                        if (bool.TryParse(value, out bool boolValue))
                        {
                            enableTreeViewVirtualization = boolValue;
                        }
                    }
                    else if (line.StartsWith(ParentAllTargetsUnderProjectSetting))
                    {
                        var value = line.Substring(ParentAllTargetsUnderProjectSetting.Length);
                        if (bool.TryParse(value, out bool boolValue))
                        {
                            parentAllTargetsUnderProject = boolValue;
                        }
                    }
                    else if (line.StartsWith(MarkResultsInTreeSetting))
                    {
                        var value = line.Substring(MarkResultsInTreeSetting.Length);
                        if (bool.TryParse(value, out bool boolValue))
                        {
                            markResultsInTree = boolValue;
                        }
                    }
                }
            }
        }
예제 #8
0
        public static string WriteContentToTempFileAndGetPath(string content, string fileExtension)
        {
            var folder   = tempFolder;
            var filePath = Path.Combine(folder, Utilities.GetMD5Hash(content, 16) + fileExtension);

            using (SingleGlobalInstance.Acquire(Path.GetFileName(filePath)))
            {
                if (File.Exists(filePath))
                {
                    return(filePath);
                }

                Directory.CreateDirectory(folder);
                File.WriteAllText(filePath, content);
            }

            if (!cleanedUpTempFiles)
            {
                System.Threading.Tasks.Task.Run(() => CleanupTempFiles());
            }

            return(filePath);
        }
예제 #9
0
        public static string GetCustomArguments(string filePath)
        {
            string[] lines;

            using (SingleGlobalInstance.Acquire(Path.GetFileName(customArgumentsFilePath)))
            {
                if (!File.Exists(customArgumentsFilePath))
                {
                    return(DefaultArguments);
                }

                lines = File.ReadAllLines(customArgumentsFilePath);
            }

            if (FindArguments(lines, filePath, out string?arguments, out int index))
            {
                return(arguments);
            }

            var mostRecentArguments = TextUtilities.ParseNameValue(lines[0]);

            return(mostRecentArguments.Value);
        }