From bc00191bfcc5c86ecb3257597206c91b88c1e415 Mon Sep 17 00:00:00 2001 From: Irame Date: Mon, 29 Jul 2024 23:20:15 +0200 Subject: [PATCH] the solution json now contains the project unique name it is used if the guid does not match any exisiting project --- .../SolutionDataSerializer.cs | 6 +----- .../Services/FileStorageService.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SmartCmdArgs/SmartCmdArgs.Shared/DataSerialization/SolutionDataSerializer.cs b/SmartCmdArgs/SmartCmdArgs.Shared/DataSerialization/SolutionDataSerializer.cs index 1c1e8b09..6b864534 100644 --- a/SmartCmdArgs/SmartCmdArgs.Shared/DataSerialization/SolutionDataSerializer.cs +++ b/SmartCmdArgs/SmartCmdArgs.Shared/DataSerialization/SolutionDataSerializer.cs @@ -10,20 +10,16 @@ namespace SmartCmdArgs.DataSerialization { class SolutionDataSerializer : DataSerializer { - public static SolutionDataJson Serialize(TreeViewModel vm, Stream stream) + public static void Serialize(SolutionDataJson data, Stream stream) { if (stream == null) throw new ArgumentNullException(nameof(stream)); - var data = Serialize(vm); - string jsonStr = JsonConvert.SerializeObject(data, Formatting.Indented); StreamWriter sw = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); sw.Write(jsonStr); sw.Flush(); - - return data; } public static SolutionDataJson Serialize(TreeViewModel vm) diff --git a/SmartCmdArgs/SmartCmdArgs.Shared/Services/FileStorageService.cs b/SmartCmdArgs/SmartCmdArgs.Shared/Services/FileStorageService.cs index 69057f18..02f34f91 100644 --- a/SmartCmdArgs/SmartCmdArgs.Shared/Services/FileStorageService.cs +++ b/SmartCmdArgs/SmartCmdArgs.Shared/Services/FileStorageService.cs @@ -229,7 +229,6 @@ public ProjectDataJson ReadDataForProject(IVsHierarchyWrapper project) } else { - Guid projectGui = project.GetGuid(); string jsonFilename = FullFilenameForSolutionJsonFile(); if (File.Exists(jsonFilename)) @@ -240,7 +239,14 @@ public ProjectDataJson ReadDataForProject(IVsHierarchyWrapper project) { SolutionDataJson slnData = SolutionDataSerializer.Deserialize(fileStream); + Guid projectGui = project.GetGuid(); result = slnData.ProjectArguments.FirstOrDefault(p => p.Id == projectGui); + + if (result == null) + { + string projectFullName = vsHelper.GetUniqueName(project); + result = slnData.ProjectArguments.FirstOrDefault(p => p.Command == projectFullName); + } } Logger.Info($"Read {result?.Items?.Count} commands for project '{project.GetName()}' from json-file '{jsonFilename}'."); } @@ -344,7 +350,15 @@ private void SaveJsonForSolution() { using (Stream fileStream = File.Open(jsonFilename, FileMode.Create, FileAccess.Write)) { - SolutionDataSerializer.Serialize(treeViewModel, fileStream); + var solutionData = SolutionDataSerializer.Serialize(treeViewModel); + + foreach(var projectData in solutionData.ProjectArguments) + { + var project = vsHelper.HierarchyForProjectGuid(projectData.Id); + projectData.Command = vsHelper.GetUniqueName(project); + } + + SolutionDataSerializer.Serialize(solutionData, fileStream); } } catch (Exception e)