From 16a1e21147a6e1c573f3c36a0c639c49dbfde9ea Mon Sep 17 00:00:00 2001 From: Axwabo Date: Sat, 24 Feb 2024 13:07:46 +0100 Subject: [PATCH] don't modify csproj files if they don't exist --- Editor/Updater/FileModification.cs | 12 +++++++----- Scripts/slocExporter/API.cs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Editor/Updater/FileModification.cs b/Editor/Updater/FileModification.cs index adbae5f..b5290fd 100644 --- a/Editor/Updater/FileModification.cs +++ b/Editor/Updater/FileModification.cs @@ -41,8 +41,8 @@ public static void PatchFiles(ProgressUpdater update, ChangedFile[] files, strin return; } - var projectFile = File.ReadAllLines(Constants.ProjectFileName).ToList(); - var editorProjectFile = File.ReadAllLines(Constants.EditorProjectFileName).ToList(); + var projectFile = File.Exists(Constants.ProjectFileName) ? File.ReadAllLines(Constants.ProjectFileName).ToList() : new List(); + var editorProjectFile = File.Exists(Constants.EditorProjectFileName) ? File.ReadAllLines(Constants.EditorProjectFileName).ToList() : new List(); var count = files.Length; var fc = (float) count; for (var i = 0; i < count; i++) @@ -61,8 +61,10 @@ public static void PatchFiles(ProgressUpdater update, ChangedFile[] files, strin update(name, (i + 1) / fc); } - File.WriteAllLines(Constants.ProjectFileName, projectFile); - File.WriteAllLines(Constants.EditorProjectFileName, editorProjectFile); + if (projectFile.Count != 0) + File.WriteAllLines(Constants.ProjectFileName, projectFile); + if (editorProjectFile.Count != 0) + File.WriteAllLines(Constants.EditorProjectFileName, editorProjectFile); } private static void ProcessPatch(ChangedFile file, ZipArchiveEntry entry, bool wasRemoved, string assets, List projectFile, List editorProjectFile) @@ -93,7 +95,7 @@ private static void ProcessPatch(ChangedFile file, ZipArchiveEntry entry, bool w private static void ModifyCsproj(string path, bool wasRemoved, string assets, List list) { - if (!path.EndsWith(".cs")) + if (!path.EndsWith(".cs") || list.Count == 0) return; var pathFromRoot = Path.GetRelativePath(Directory.GetParent(assets)!.FullName, path).Replace('\\', '/'); var existingIndex = list.FindIndex(s => diff --git a/Scripts/slocExporter/API.cs b/Scripts/slocExporter/API.cs index b1563b6..2b652b2 100644 --- a/Scripts/slocExporter/API.cs +++ b/Scripts/slocExporter/API.cs @@ -22,7 +22,7 @@ public static class API public const ushort slocVersion = 5; - public static string CurrentVersion = "5.1.0"; + public static string CurrentVersion = "5.1.1"; #region Reader Declarations