From d7863d476ac11fb0ee74122cceb97e31c82a9222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 17 Mar 2025 08:41:06 +0100 Subject: [PATCH 1/5] fix: Catching UnauthorizedAccessException trying to write files to a path without permissions --- MN.L10n/FileProviders/FileDataProvider.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/MN.L10n/FileProviders/FileDataProvider.cs b/MN.L10n/FileProviders/FileDataProvider.cs index 982d1e6..8a660b3 100644 --- a/MN.L10n/FileProviders/FileDataProvider.cs +++ b/MN.L10n/FileProviders/FileDataProvider.cs @@ -23,7 +23,7 @@ public class FileDataProvider : IL10nDataProvider private string LanguagesFile { get; set; } private string LanguageFile { get; set; } public bool SaveChangesToDisk { get; set; } = true; - + public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json", string l10nLanguagesFileName = "languages.json") { FilePath = path; @@ -157,7 +157,7 @@ public async Task LoadTranslationFromSources(L10n l10n, bool removeAllPhra sources.Reverse(); // If we have sources, and the removeAllPhrases is true, remove all current phrases, to get rid of old ones as well - if(sources.Count > 0 && removeAllPhrases) + if (sources.Count > 0 && removeAllPhrases) { l10nLang.Phrases.Clear(); } @@ -237,7 +237,16 @@ private void WriteToDiskIfAllowed(string pathAndFilename, string contents) { if (SaveChangesToDisk) { - File.WriteAllText(pathAndFilename, contents); + try + { + File.WriteAllText(pathAndFilename, contents); + } + catch (UnauthorizedAccessException uae) + { + Console.WriteLine("error l10n: Unauthorized Access Exception"); + Console.WriteLine($"error l10n: Got an error trying to save the file {pathAndFilename}"); + Console.WriteLine(uae.ToString()); + } } } } From a7e79febbbb0abbc72078c5eb7cf3b73637ae34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 17 Mar 2025 08:48:39 +0100 Subject: [PATCH 2/5] fix: ErrorHandler --- MN.L10n/FileProviders/FileDataProvider.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MN.L10n/FileProviders/FileDataProvider.cs b/MN.L10n/FileProviders/FileDataProvider.cs index 8a660b3..5aaf4fa 100644 --- a/MN.L10n/FileProviders/FileDataProvider.cs +++ b/MN.L10n/FileProviders/FileDataProvider.cs @@ -24,6 +24,8 @@ public class FileDataProvider : IL10nDataProvider private string LanguageFile { get; set; } public bool SaveChangesToDisk { get; set; } = true; + public Action? OnWriteError { get; set; } + public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json", string l10nLanguagesFileName = "languages.json") { FilePath = path; @@ -246,6 +248,12 @@ private void WriteToDiskIfAllowed(string pathAndFilename, string contents) Console.WriteLine("error l10n: Unauthorized Access Exception"); Console.WriteLine($"error l10n: Got an error trying to save the file {pathAndFilename}"); Console.WriteLine(uae.ToString()); + + OnWriteError?.Invoke(pathAndFilename, contents, uae); + } + catch (Exception ex) + { + OnWriteError?.Invoke(pathAndFilename, contents, ex); } } } From 12141e1d7d535418ade5225ed47d0c80711dbb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 17 Mar 2025 09:07:46 +0100 Subject: [PATCH 3/5] chore: Upgrade .NET and nuget-packages --- .../MN.L10n.Analyzer.Test.csproj | 14 +++++++------- .../MN.L10n.Analyzer/MN.L10n.Analyzer.csproj | 2 +- MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj | 2 +- .../MN.L10n.Javascript.Core.csproj | 8 ++++---- .../MN.L10n.JavascriptTranslationMiddleware.csproj | 2 +- MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj | 2 +- MN.L10n.Tests/MN.L10n.Tests.csproj | 12 ++++++------ MN.L10n/MN.L10n.csproj | 2 +- dotnet-l10n-buildtask/dotnet-l10n-buildtask.csproj | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/MN.L10n.Analyzer/MN.L10n.Analyzer.Test/MN.L10n.Analyzer.Test.csproj b/MN.L10n.Analyzer/MN.L10n.Analyzer.Test/MN.L10n.Analyzer.Test.csproj index 0c75db3..78ee7ec 100644 --- a/MN.L10n.Analyzer/MN.L10n.Analyzer.Test/MN.L10n.Analyzer.Test.csproj +++ b/MN.L10n.Analyzer/MN.L10n.Analyzer.Test/MN.L10n.Analyzer.Test.csproj @@ -1,20 +1,20 @@  - net8.0 + net9.0 false - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MN.L10n.Analyzer/MN.L10n.Analyzer/MN.L10n.Analyzer.csproj b/MN.L10n.Analyzer/MN.L10n.Analyzer/MN.L10n.Analyzer.csproj index 732381b..6ae1812 100644 --- a/MN.L10n.Analyzer/MN.L10n.Analyzer/MN.L10n.Analyzer.csproj +++ b/MN.L10n.Analyzer/MN.L10n.Analyzer/MN.L10n.Analyzer.csproj @@ -30,7 +30,7 @@ - + diff --git a/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj b/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj index 07112e9..a4625e6 100644 --- a/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj +++ b/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 Exe MN.L10n.BuildTasks.Program diff --git a/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj b/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj index 69ffcec..0b5a79a 100644 --- a/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj +++ b/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0;net8.0 + net8.0;net9.0 True https://github.com/MultinetInteractive/MN.L10n https://github.com/MultinetInteractive/MN.L10n @@ -11,9 +11,9 @@ - - - + + + diff --git a/MN.L10n.JavascriptTranslationMiddleware/MN.L10n.JavascriptTranslationMiddleware.csproj b/MN.L10n.JavascriptTranslationMiddleware/MN.L10n.JavascriptTranslationMiddleware.csproj index 43490b4..4273de2 100644 --- a/MN.L10n.JavascriptTranslationMiddleware/MN.L10n.JavascriptTranslationMiddleware.csproj +++ b/MN.L10n.JavascriptTranslationMiddleware/MN.L10n.JavascriptTranslationMiddleware.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net8.0;net9.0 Enable True 3.0.0 diff --git a/MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj b/MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj index 8d20d46..38bf165 100644 --- a/MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj +++ b/MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj @@ -1,6 +1,6 @@ - net8.0 + net9.0 TheTest lice, chbe https://github.com/MultinetInteractive/MN.L10n diff --git a/MN.L10n.Tests/MN.L10n.Tests.csproj b/MN.L10n.Tests/MN.L10n.Tests.csproj index 291fa93..6f83247 100644 --- a/MN.L10n.Tests/MN.L10n.Tests.csproj +++ b/MN.L10n.Tests/MN.L10n.Tests.csproj @@ -1,19 +1,19 @@  - net8.0 + net9.0 false - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MN.L10n/MN.L10n.csproj b/MN.L10n/MN.L10n.csproj index 253870d..18f36b5 100644 --- a/MN.L10n/MN.L10n.csproj +++ b/MN.L10n/MN.L10n.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;net6.0;net7.0;net8.0 + net472;netstandard2.0;net8.0;net9.0 True MultiNet Interactive AB Chris Gårdenberg diff --git a/dotnet-l10n-buildtask/dotnet-l10n-buildtask.csproj b/dotnet-l10n-buildtask/dotnet-l10n-buildtask.csproj index 4ef67de..36a3280 100644 --- a/dotnet-l10n-buildtask/dotnet-l10n-buildtask.csproj +++ b/dotnet-l10n-buildtask/dotnet-l10n-buildtask.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 dotnet_l10n_buildtask true l10n-buildtask From 89831aecbb85d73d6b082c6fc9e6d3e727d58b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 17 Mar 2025 09:09:55 +0100 Subject: [PATCH 4/5] chore: Disable build for CodeQL --- .github/workflows/codeql-analysis.yml | 20 ++++++-------------- MN.L10n.sln | 2 ++ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 4b04851..b7f1c69 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -23,32 +23,24 @@ jobs: # Override automatic language detection by changing the below list # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] language: ['csharp'] + build-mode: ['none'] # Learn more... # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection steps: - name: Checkout repository - uses: actions/checkout@v3 - + uses: actions/checkout@v4 + - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: '8.0' + dotnet-version: '9.0' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - name: Build L10n - run: | - dotnet restore - dotnet build - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/MN.L10n.sln b/MN.L10n.sln index c25c380..8c9202c 100644 --- a/MN.L10n.sln +++ b/MN.L10n.sln @@ -10,7 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore + .github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml CONTRIBUTING.md = CONTRIBUTING.md + .github\workflows\javascripts-tests.yml = .github\workflows\javascripts-tests.yml LICENSE.txt = LICENSE.txt README.md = README.md TROUBLESHOOTING.md = TROUBLESHOOTING.md From 905239d720815c8ed4d3c8c30cbdb53d80b679ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 17 Mar 2025 09:25:02 +0100 Subject: [PATCH 5/5] ci: Trying to get CodeQL to work as it should for build-mode none. --- .github/workflows/codeql-analysis.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b7f1c69..6a0e5f8 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,16 +17,6 @@ jobs: name: Analyze runs-on: windows-latest - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['csharp'] - build-mode: ['none'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -40,7 +30,11 @@ jobs: - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: - languages: ${{ matrix.language }} + languages: csharp + build-mode: none + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3