diff --git a/.github/workflows/build-legacy.yml b/.github/workflows/build-legacy.yml new file mode 100644 index 00000000..5cff33ce --- /dev/null +++ b/.github/workflows/build-legacy.yml @@ -0,0 +1,56 @@ +name: Publish Legacy + +on: + release: + types: [published] + +jobs: + release: + name: Release + strategy: + matrix: + kind: ['macOS'] + include: + - kind: macOS + os: macos-latest + target: osx + arm: true + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 9.0.100 + + - name: Build + shell: bash + run: | + tag=$(git describe --tags --abbrev=0) + release_name="App-$tag-${{ matrix.target }}" + trim="True" + + # Build everything + dotnet publish pupdate_legacy.csproj -r ${{ matrix.target }}-x64 --self-contained true -c Release -o "$release_name" --consoleloggerparameters:ErrorsOnly -p:PublishTrimmed=$trim -p:TrimMode=partial + mv ${release_name}/pupdate ${release_name}/pupdate_x64 + dotnet publish pupdate_legacy.csproj -r ${{ matrix.target }}-arm64 --self-contained true -c Release -o "$release_name" --consoleloggerparameters:ErrorsOnly -p:PublishTrimmed=$trim -p:TrimMode=partial + mv ${release_name}/pupdate ${release_name}/pupdate_arm64 + + # Pack files + cd $release_name + lipo -create -output pupdate pupdate_arm64 pupdate_x64 + rm pupdate_arm64 + rm pupdate_x64 + zip "../dotnet7_pupdate_mac.zip" "pupdate"; cd ..; + + # Delete output directory + rm -r "$release_name" + + - name: Publish Legacy + uses: softprops/action-gh-release@v1 + with: + files: "pupdate*.zip" + env: + GITHUB_TOKEN: ${{ secrets.API_TOKEN }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index fadd4bd6..a4265319 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -18,8 +18,8 @@ jobs: with: dotnet-version: 9.0.100 - name: Restore dependencies - run: dotnet restore + run: dotnet restore pupdate.csproj - name: Build - run: dotnet build --no-restore + run: dotnet build pupdate.csproj --no-restore - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test pupdate.csproj --no-build --verbosity normal diff --git a/pupdate_legacy.csproj b/pupdate_legacy.csproj new file mode 100644 index 00000000..94464e14 --- /dev/null +++ b/pupdate_legacy.csproj @@ -0,0 +1,57 @@ + + + Exe + true + net7.0 + enable + disable + 4.2.1 + Keep your Analogue Pocket up to date + 2024 Matt Pannella + Matt Pannella + Pupdate + https://github.com/mattpannella/pupdate + Pannella + NU1605 + + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + + + + + + + + + diff --git a/pupdate_legacy.csproj.DotSettings b/pupdate_legacy.csproj.DotSettings new file mode 100644 index 00000000..932a944b --- /dev/null +++ b/pupdate_legacy.csproj.DotSettings @@ -0,0 +1,7 @@ + + True + diff --git a/pupdate_legacy.sln b/pupdate_legacy.sln new file mode 100644 index 00000000..ead6cc05 --- /dev/null +++ b/pupdate_legacy.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pupdate_legacy", "pupdate_legacy.csproj", "{88615FF5-4649-4DD0-B721-449269388A88}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {88615FF5-4649-4DD0-B721-449269388A88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88615FF5-4649-4DD0-B721-449269388A88}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88615FF5-4649-4DD0-B721-449269388A88}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88615FF5-4649-4DD0-B721-449269388A88}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E762A40A-D6F5-4D10-B9D2-9310E95944B6} + EndGlobalSection +EndGlobal diff --git a/src/Program.cs b/src/Program.cs index ecfe64ea..6033813e 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -7,7 +7,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void Main(string[] args) { @@ -35,7 +35,7 @@ private static void Main(string[] args) break; case VersionRequestedError: - Console.WriteLine("Pupdate v" + VERSION); + Console.WriteLine("pupdate v" + VERSION); break; } } @@ -218,17 +218,13 @@ private static void Main(string[] args) break; } } - catch (Exception e) + catch (Exception ex) { Console.WriteLine("Well, something went wrong. Sorry about that."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); + Pause(); } } diff --git a/src/helpers/ConsoleHelper.cs b/src/helpers/ConsoleHelper.cs index 4743a14c..60bfa7e2 100644 --- a/src/helpers/ConsoleHelper.cs +++ b/src/helpers/ConsoleHelper.cs @@ -1,26 +1,7 @@ namespace Pannella.Helpers; -public class ConsoleHelper +public static class ConsoleHelper { - // public static void ShowProgressBar(int current, int total) - // { - // var progress = (double)current / total; - // var progressWidth = Console.WindowWidth - 14; - // var progressBarWidth = (int)(progress * progressWidth); - // var progressBar = new string('=', progressBarWidth); - // var emptyProgressBar = new string(' ', progressWidth - progressBarWidth); - // - // Console.Write($"\r{progressBar}{emptyProgressBar}] {(progress * 100):0.00}%"); - // - // if (current == total) - // { - // Console.CursorLeft = 0; - // Console.Write(new string(' ', Console.WindowWidth)); - // Console.CursorLeft = 0; - // Console.Write("\r"); - // } - // } - public static void ShowProgressBar(long current, long total) { var progress = (double)current / total; @@ -29,7 +10,7 @@ public static void ShowProgressBar(long current, long total) var progressBar = new string('=', progressBarWidth); var emptyProgressBar = new string(' ', progressWidth - progressBarWidth); - Console.Write($"\r{progressBar}{emptyProgressBar}] {(progress * 100):0.00}%"); + Console.Write($"\r{progressBar}{emptyProgressBar}] {progress * 100:0.00}%"); if (current == total) { diff --git a/src/helpers/ContactResolvers.cs b/src/helpers/ContactResolvers.cs index ed06c863..4a9129aa 100644 --- a/src/helpers/ContactResolvers.cs +++ b/src/helpers/ContactResolvers.cs @@ -7,7 +7,7 @@ namespace Pannella.Helpers { public class ArchiveContractResolver : DefaultContractResolver { - public static readonly ArchiveContractResolver Instance = new(); + public static readonly ArchiveContractResolver INSTANCE = new(); protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { @@ -20,7 +20,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ { Archive archive = (Archive)instance; - return (archive.type == ArchiveType.core_specific_archive || archive.type == ArchiveType.core_specific_custom_archive); + return archive.type is ArchiveType.core_specific_archive or ArchiveType.core_specific_custom_archive; }; } diff --git a/src/helpers/HttpHelper.cs b/src/helpers/HttpHelper.cs index d7368a78..58fc0763 100644 --- a/src/helpers/HttpHelper.cs +++ b/src/helpers/HttpHelper.cs @@ -1,13 +1,10 @@ using System.Net; -using System.Net.Cache; -using System.Net.Http.Headers; -using System.Web; namespace Pannella.Helpers; public class HttpHelper { - private static HttpHelper instance; + private static HttpHelper INSTANCE; private static readonly object SYNC_LOCK = new(); private HttpClient client; @@ -26,7 +23,7 @@ public static HttpHelper Instance { lock (SYNC_LOCK) { - return instance ??= new HttpHelper(); + return INSTANCE ??= new HttpHelper(); } } } @@ -111,27 +108,38 @@ public void GetAuthCookie(string username, string password, string loginUrl, Dic var loginUri = new Uri(loginUrl); var host = loginUri.GetLeftPart(UriPartial.Authority); var cookies = this.handler.CookieContainer.GetCookies(new Uri(host)); - if(cookies.Count() > 0) { + + if(cookies.Any()) + { return; } - var data = new List>(); - data.Add(new KeyValuePair("username", username)); - data.Add(new KeyValuePair("password", password) ); + + var data = new List> + { + new("username", username), + new("password", password) + }; foreach (var item in additional) { data.Add(new KeyValuePair(item.Key, item.Value)); } + var formData = new FormUrlEncodedContent(data); + this.client.DefaultRequestHeaders.Add("User-Agent", "Pupdate"); + HttpResponseMessage loginResponse = this.client.PostAsync(loginUrl, formData).Result; + if (loginResponse.IsSuccessStatusCode) { - //if the login form requires some csrf type headers to be sent up, send the requst a second time so they are included + // if the login form requires some csrf type headers to be sent up, send the request a second time so they are included + // ReSharper disable once RedundantAssignment loginResponse = this.client.PostAsync(loginUrl, formData).Result; } } + // ReSharper disable once InconsistentNaming public string GetHTML(string uri, bool allowRedirect = true) { if (!Uri.TryCreate(uri, UriKind.Absolute, out _)) @@ -146,6 +154,7 @@ public string GetHTML(string uri, bool allowRedirect = true) var response = this.client.GetAsync(uri).Result; + // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault string html = response.StatusCode switch { HttpStatusCode.OK => response.Content.ReadAsStringAsync().Result, @@ -162,7 +171,7 @@ public string GetHTML(string uri, bool allowRedirect = true) private void CreateClient(bool allowRedirect = true) { - //Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 + // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 this.handler = new HttpClientHandler { AllowAutoRedirect = allowRedirect, CookieContainer = new CookieContainer() }; this.client = new HttpClient(this.handler); this.client.Timeout = TimeSpan.FromMinutes(10); // 10min @@ -171,9 +180,9 @@ private void CreateClient(bool allowRedirect = true) private void OnDownloadProgressUpdate(DownloadProgressEventArgs e) { - EventHandler handler = DownloadProgressUpdate; + EventHandler downloadProgressUpdateHandler = DownloadProgressUpdate; - handler?.Invoke(this, e); + downloadProgressUpdateHandler?.Invoke(this, e); } } diff --git a/src/helpers/SemverUtil.cs b/src/helpers/SemverUtil.cs index 13c7adbe..ebf17d5d 100644 --- a/src/helpers/SemverUtil.cs +++ b/src/helpers/SemverUtil.cs @@ -2,7 +2,7 @@ namespace Pannella.Helpers; -public class SemverUtil +public static class SemverUtil { private const string SEMVER_FINDER = @"\D*(\d+(\.\d+)*\.\d+)\D*"; diff --git a/src/helpers/ServiceHelper.cs b/src/helpers/ServiceHelper.cs index 1c8defad..ce87585b 100644 --- a/src/helpers/ServiceHelper.cs +++ b/src/helpers/ServiceHelper.cs @@ -17,21 +17,27 @@ public static class ServiceHelper public static EventHandler StatusUpdated { get; private set; } public static EventHandler UpdateProcessComplete { get; private set; } - private static bool isInitialized; + private static bool IS_INITIALIZED; public static void Initialize(string path, string settingsPath, EventHandler statusUpdated = null, EventHandler updateProcessComplete = null, bool forceReload = false) { - if (!isInitialized || forceReload) + if (!IS_INITIALIZED || forceReload) { - isInitialized = true; + IS_INITIALIZED = true; UpdateDirectory = path; SettingsDirectory = settingsPath; SettingsService = new SettingsService(settingsPath); - ArchiveService = new ArchiveService(SettingsService.Config.archives, - SettingsService.Config.crc_check, SettingsService.Config.use_custom_archive); + ArchiveService = new ArchiveService( + SettingsService.Config.archives, + SettingsService.Credentials?.internet_archive, + SettingsService.Config.crc_check, + SettingsService.Config.use_custom_archive, + SettingsService.Debug.show_stack_traces); TempDirectory = SettingsService.Config.temp_directory ?? UpdateDirectory; - AssetsService = new AssetsService(SettingsService.Config.use_local_blacklist); + AssetsService = new AssetsService( + SettingsService.Config.use_local_blacklist, + SettingsService.Debug.show_stack_traces); CoresService = new CoresService(path, SettingsService, ArchiveService, AssetsService); SettingsService.InitializeCoreSettings(CoresService.Cores); SettingsService.Save(); @@ -60,8 +66,12 @@ public static void ReloadSettings() { SettingsService = new SettingsService(SettingsDirectory, CoresService.Cores); // reload the archive service, in case that setting has changed - ArchiveService = new ArchiveService(SettingsService.Config.archives, - SettingsService.Config.crc_check, SettingsService.Config.use_custom_archive); + ArchiveService = new ArchiveService( + SettingsService.Config.archives, + SettingsService.Credentials?.internet_archive, + SettingsService.Config.crc_check, + SettingsService.Config.use_custom_archive, + SettingsService.Debug.show_stack_traces); CoresService = new CoresService(UpdateDirectory, SettingsService, ArchiveService, AssetsService); CoresService.StatusUpdated += StatusUpdated; } diff --git a/src/helpers/SevenZipHelper.cs b/src/helpers/SevenZipHelper.cs index ea3e91a2..900d299f 100644 --- a/src/helpers/SevenZipHelper.cs +++ b/src/helpers/SevenZipHelper.cs @@ -2,12 +2,14 @@ namespace Pannella.Helpers; -public class SevenZipHelper +public static class SevenZipHelper { public static void ExtractToDirectory(string zipFile, string destination) { - SevenZipArchive sevenzip = new SevenZipArchive(zipFile); + SevenZipArchive sevenZip = new SevenZipArchive(zipFile); + Console.WriteLine("Extracting..."); - sevenzip.ExtractToDirectory(destination); + + sevenZip.ExtractToDirectory(destination); } } \ No newline at end of file diff --git a/src/helpers/StringConverter.cs b/src/helpers/StringConverter.cs deleted file mode 100644 index df5bc635..00000000 --- a/src/helpers/StringConverter.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Pannella.Helpers; - -public class StringConverter : JsonConverter -{ - public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - return reader.TokenType switch - { - JsonTokenType.Number => reader.GetInt32().ToString(), - JsonTokenType.String => reader.GetString(), - _ => throw new JsonException() - }; - } - - public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) - { - writer.WriteStringValue(value); - } -} diff --git a/src/helpers/Util.cs b/src/helpers/Util.cs index 526800be..94c50c85 100644 --- a/src/helpers/Util.cs +++ b/src/helpers/Util.cs @@ -12,7 +12,9 @@ public static class Util public enum HashTypes { + // ReSharper disable once InconsistentNaming CRC32, + // ReSharper disable once InconsistentNaming MD5 } @@ -205,4 +207,18 @@ public static string WordWrap(string line, int width, string padding = "") return message.ToString(); } + + public static string GetExceptionMessage(Exception ex) + { + StringBuilder sb = new(); + Exception current = ex; + + while (current != null) + { + sb.AppendLine(current.Message); + current = current.InnerException; + } + + return sb.ToString(); + } } diff --git a/src/helpers/ZipHelper.cs b/src/helpers/ZipHelper.cs index ecaa1c32..7985f92e 100644 --- a/src/helpers/ZipHelper.cs +++ b/src/helpers/ZipHelper.cs @@ -2,7 +2,7 @@ namespace Pannella.Helpers; -public class ZipHelper +public static class ZipHelper { private static void UpdateProgress(object sender, ZipProgress zipProgress) { diff --git a/src/models/Analogue/Core/AnalogueCore.cs b/src/models/Analogue/Core/AnalogueCore.cs index 5710b4b3..f42bbf12 100644 --- a/src/models/Analogue/Core/AnalogueCore.cs +++ b/src/models/Analogue/Core/AnalogueCore.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Core; public class Core diff --git a/src/models/Analogue/Core/AnalogueFramework.cs b/src/models/Analogue/Core/AnalogueFramework.cs index 8a28eef5..c318104e 100644 --- a/src/models/Analogue/Core/AnalogueFramework.cs +++ b/src/models/Analogue/Core/AnalogueFramework.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Core; public class Framework diff --git a/src/models/Analogue/Core/AnalogueMetadata.cs b/src/models/Analogue/Core/AnalogueMetadata.cs index 635bb773..12dd6e95 100644 --- a/src/models/Analogue/Core/AnalogueMetadata.cs +++ b/src/models/Analogue/Core/AnalogueMetadata.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Core; public class Metadata diff --git a/src/models/Analogue/Data/AnalogueData.cs b/src/models/Analogue/Data/AnalogueData.cs index 814143ab..8ced31cb 100644 --- a/src/models/Analogue/Data/AnalogueData.cs +++ b/src/models/Analogue/Data/AnalogueData.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using Pannella.Models.Analogue.Shared; namespace Pannella.Models.Analogue.Data; diff --git a/src/models/Analogue/Data/AnalogueDataJSON.cs b/src/models/Analogue/Data/AnalogueDataJSON.cs index 830bbf09..8fea90f8 100644 --- a/src/models/Analogue/Data/AnalogueDataJSON.cs +++ b/src/models/Analogue/Data/AnalogueDataJSON.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Data; public class DataJSON diff --git a/src/models/Analogue/Instance/AnalogueInstance.cs b/src/models/Analogue/Instance/AnalogueInstance.cs index 2c981b1b..1af15e05 100644 --- a/src/models/Analogue/Instance/AnalogueInstance.cs +++ b/src/models/Analogue/Instance/AnalogueInstance.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using Pannella.Models.Analogue.Shared; namespace Pannella.Models.Analogue.Instance; diff --git a/src/models/Analogue/Instance/AnalogueInstanceJSON.cs b/src/models/Analogue/Instance/AnalogueInstanceJSON.cs index b8a43eb8..f3525bd0 100644 --- a/src/models/Analogue/Instance/AnalogueInstanceJSON.cs +++ b/src/models/Analogue/Instance/AnalogueInstanceJSON.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Instance; public class InstanceJSON diff --git a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstance.cs b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstance.cs index ec00500c..24526f9d 100644 --- a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstance.cs +++ b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstance.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Instance.Simple; public class SimpleInstance diff --git a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceDataSlot.cs b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceDataSlot.cs index 953525e2..8714289c 100644 --- a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceDataSlot.cs +++ b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceDataSlot.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Instance.Simple; public class SimpleDataSlot diff --git a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceJSON.cs b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceJSON.cs index 7c1b7326..392598ef 100644 --- a/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceJSON.cs +++ b/src/models/Analogue/Instance/Simple/AnalogueSimpleInstanceJSON.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Instance.Simple; public class SimpleInstanceJSON diff --git a/src/models/Analogue/Release.cs b/src/models/Analogue/Release.cs index f8040589..dbb35588 100644 --- a/src/models/Analogue/Release.cs +++ b/src/models/Analogue/Release.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue; public class ReleaseDetails diff --git a/src/models/Analogue/Shared/AnalogueDataSlot.cs b/src/models/Analogue/Shared/AnalogueDataSlot.cs index c80147df..b2b6b045 100644 --- a/src/models/Analogue/Shared/AnalogueDataSlot.cs +++ b/src/models/Analogue/Shared/AnalogueDataSlot.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using System.Collections; namespace Pannella.Models.Analogue.Shared; @@ -19,17 +21,9 @@ private BitArray GetBits() return null; } - int p; - - if (parameters.StartsWith("0x")) - { - p = Convert.ToInt32(parameters, 16); - } - else - { - p = int.Parse(parameters); - } - + int p = parameters.StartsWith("0x") + ? Convert.ToInt32(parameters, 16) + : int.Parse(parameters); byte[] bytes = BitConverter.GetBytes(p); BitArray bits = new BitArray(bytes); diff --git a/src/models/Analogue/Video/AnalogueDisplayMode.cs b/src/models/Analogue/Video/AnalogueDisplayMode.cs index 680e1296..9387c0e0 100644 --- a/src/models/Analogue/Video/AnalogueDisplayMode.cs +++ b/src/models/Analogue/Video/AnalogueDisplayMode.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using Newtonsoft.Json; namespace Pannella.Models.Analogue.Video; diff --git a/src/models/Analogue/Video/AnalogueScalerMode.cs b/src/models/Analogue/Video/AnalogueScalerMode.cs index b8468fdf..24ed5644 100644 --- a/src/models/Analogue/Video/AnalogueScalerMode.cs +++ b/src/models/Analogue/Video/AnalogueScalerMode.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Analogue.Video; public class ScalerMode diff --git a/src/models/Analogue/Video/AnalogueVideo.cs b/src/models/Analogue/Video/AnalogueVideo.cs index c4713156..ed62450f 100644 --- a/src/models/Analogue/Video/AnalogueVideo.cs +++ b/src/models/Analogue/Video/AnalogueVideo.cs @@ -1,3 +1,6 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable CollectionNeverUpdated.Global + using Newtonsoft.Json; namespace Pannella.Models.Analogue.Video; diff --git a/src/models/Archive/Archive.cs b/src/models/Archive/Archive.cs index bfc3aa72..ccbf170d 100644 --- a/src/models/Archive/Archive.cs +++ b/src/models/Archive/Archive.cs @@ -1,3 +1,6 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable CollectionNeverUpdated.Global + namespace Pannella.Models.Archive; public class Archive diff --git a/src/models/Archive/File.cs b/src/models/Archive/File.cs index 0346d945..e686107b 100644 --- a/src/models/Archive/File.cs +++ b/src/models/Archive/File.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Archive; public class File diff --git a/src/models/DisplayModes/DisplayMode.cs b/src/models/DisplayModes/DisplayMode.cs index 66e7f00a..0bed6c4e 100644 --- a/src/models/DisplayModes/DisplayMode.cs +++ b/src/models/DisplayModes/DisplayMode.cs @@ -1,3 +1,6 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable CollectionNeverUpdated.Global + namespace Pannella.Models.DisplayModes; public class DisplayMode diff --git a/src/models/DisplayModes/DisplayModes.cs b/src/models/DisplayModes/DisplayModes.cs index dedbe768..4349b333 100644 --- a/src/models/DisplayModes/DisplayModes.cs +++ b/src/models/DisplayModes/DisplayModes.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.DisplayModes; public class DisplayModes diff --git a/src/models/Extras/PocketExtra.cs b/src/models/Extras/PocketExtra.cs index d0f968cd..593ca39b 100644 --- a/src/models/Extras/PocketExtra.cs +++ b/src/models/Extras/PocketExtra.cs @@ -1,3 +1,6 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable CollectionNeverUpdated.Global + using System.Text.Json.Serialization; namespace Pannella.Models.Extras; diff --git a/src/models/Extras/PocketExtraType.cs b/src/models/Extras/PocketExtraType.cs index f1cebd6f..b7bc63d6 100644 --- a/src/models/Extras/PocketExtraType.cs +++ b/src/models/Extras/PocketExtraType.cs @@ -1,8 +1,10 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Extras; public enum PocketExtraType { additional_assets, combination_platform, - variant_core, + variant_core } diff --git a/src/models/Extras/PocketExtras.cs b/src/models/Extras/PocketExtras.cs index fd2c253d..355780de 100644 --- a/src/models/Extras/PocketExtras.cs +++ b/src/models/Extras/PocketExtras.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Extras; public class PocketExtras diff --git a/src/models/Github/GithubAsset.cs b/src/models/Github/GithubAsset.cs index 2c2deb9f..0ad18f31 100644 --- a/src/models/Github/GithubAsset.cs +++ b/src/models/Github/GithubAsset.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Github; public class Asset diff --git a/src/models/Github/GithubFile.cs b/src/models/Github/GithubFile.cs index a225ac54..9000ab96 100644 --- a/src/models/Github/GithubFile.cs +++ b/src/models/Github/GithubFile.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Github; public class File diff --git a/src/models/Github/GithubRelease.cs b/src/models/Github/GithubRelease.cs index 8bf4be1c..1e9a6f0f 100644 --- a/src/models/Github/GithubRelease.cs +++ b/src/models/Github/GithubRelease.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Github; public class Release diff --git a/src/models/IngoreInstanceJson.cs b/src/models/IngoreInstanceJson.cs index 2cec974c..9f870f55 100644 --- a/src/models/IngoreInstanceJson.cs +++ b/src/models/IngoreInstanceJson.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models { public class IgnoreInstanceJson diff --git a/src/models/InstancePackager/DataSlot.cs b/src/models/InstancePackager/DataSlot.cs index f427cde9..1b6d7549 100644 --- a/src/models/InstancePackager/DataSlot.cs +++ b/src/models/InstancePackager/DataSlot.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.InstancePackager; public class DataSlot diff --git a/src/models/InstancePackager/InstanceJsonPackager.cs b/src/models/InstancePackager/InstanceJsonPackager.cs index 97b6cc27..9f82ba47 100644 --- a/src/models/InstancePackager/InstanceJsonPackager.cs +++ b/src/models/InstancePackager/InstanceJsonPackager.cs @@ -1,3 +1,6 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable CollectionNeverUpdated.Global + namespace Pannella.Models.InstancePackager; public class InstanceJsonPackager diff --git a/src/models/OpenFPGA_Cores_Inventory/Core.cs b/src/models/OpenFPGA_Cores_Inventory/Core.cs index e48acbf0..7a862faa 100644 --- a/src/models/OpenFPGA_Cores_Inventory/Core.cs +++ b/src/models/OpenFPGA_Cores_Inventory/Core.cs @@ -1,6 +1,9 @@ -namespace Pannella.Models.OpenFPGA_Cores_Inventory; +// ReSharper disable InconsistentNaming using Pannella.Models.Updater; + +namespace Pannella.Models.OpenFPGA_Cores_Inventory; + public class Core { public string identifier { get; set; } diff --git a/src/models/OpenFPGA_Cores_Inventory/Platform.cs b/src/models/OpenFPGA_Cores_Inventory/Platform.cs index 51b5124e..5bbd1dc8 100644 --- a/src/models/OpenFPGA_Cores_Inventory/Platform.cs +++ b/src/models/OpenFPGA_Cores_Inventory/Platform.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.OpenFPGA_Cores_Inventory; public class Platform diff --git a/src/models/OpenFPGA_Cores_Inventory/Repository.cs b/src/models/OpenFPGA_Cores_Inventory/Repository.cs index 7f5424d7..50d36815 100644 --- a/src/models/OpenFPGA_Cores_Inventory/Repository.cs +++ b/src/models/OpenFPGA_Cores_Inventory/Repository.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.OpenFPGA_Cores_Inventory; public class Repository diff --git a/src/models/OpenFPGA_Cores_Inventory/Sponsor.cs b/src/models/OpenFPGA_Cores_Inventory/Sponsor.cs index 7ab1f909..b2755b13 100644 --- a/src/models/OpenFPGA_Cores_Inventory/Sponsor.cs +++ b/src/models/OpenFPGA_Cores_Inventory/Sponsor.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using System.Text; namespace Pannella.Models.OpenFPGA_Cores_Inventory; diff --git a/src/models/PlatformImagePack.cs b/src/models/PlatformImagePack.cs index 3fba2a58..bc01cb16 100644 --- a/src/models/PlatformImagePack.cs +++ b/src/models/PlatformImagePack.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models; public class PlatformImagePack diff --git a/src/models/Settings/Archive.cs b/src/models/Settings/Archive.cs index c4c05691..a89a741e 100644 --- a/src/models/Settings/Archive.cs +++ b/src/models/Settings/Archive.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -9,7 +11,7 @@ public enum ArchiveType internet_archive, custom_archive, core_specific_archive, - core_specific_custom_archive, + core_specific_custom_archive } public class Archive diff --git a/src/models/Settings/Config.cs b/src/models/Settings/Config.cs index d078e95c..b93f12cf 100644 --- a/src/models/Settings/Config.cs +++ b/src/models/Settings/Config.cs @@ -1,8 +1,9 @@ -using System.ComponentModel; -using Newtonsoft.Json; // ReSharper disable RedundantDefaultMemberInitializer // ReSharper disable InconsistentNaming +using System.ComponentModel; +using Newtonsoft.Json; + namespace Pannella.Models.Settings; public class Config @@ -99,7 +100,7 @@ public class Config { name = "default", type = ArchiveType.internet_archive, - archive_name = "openFPGA-Files", + archive_name = "openFPGA-Files" }, new Archive { @@ -107,7 +108,7 @@ public class Config type = ArchiveType.custom_archive, archive_name = "custom", url = "https://updater.retrodriven.com", - index = "updater.php", + index = "updater.php" }, new Archive { @@ -116,7 +117,7 @@ public class Config archive_name = "fpga-gnw-opt", archive_folder = null, file_extensions = new List { ".gnw" }, - enabled = false, + enabled = false } }; diff --git a/src/models/Settings/CoreSettings.cs b/src/models/Settings/CoreSettings.cs index 827d5d18..6f8a3d70 100644 --- a/src/models/Settings/CoreSettings.cs +++ b/src/models/Settings/CoreSettings.cs @@ -1,7 +1,8 @@ -using Newtonsoft.Json; // ReSharper disable InconsistentNaming // ReSharper disable RedundantDefaultMemberInitializer +using Newtonsoft.Json; + namespace Pannella.Models.Settings; public class CoreSettings diff --git a/src/models/Settings/Credentials.cs b/src/models/Settings/Credentials.cs index 1e9a21a8..022e01a2 100644 --- a/src/models/Settings/Credentials.cs +++ b/src/models/Settings/Credentials.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +// ReSharper disable InconsistentNaming namespace Pannella.Models.Settings; diff --git a/src/models/Settings/CustomArchive.cs b/src/models/Settings/CustomArchive.cs index 8c9c596a..12fe0f40 100644 --- a/src/models/Settings/CustomArchive.cs +++ b/src/models/Settings/CustomArchive.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Settings { public class CustomArchive diff --git a/src/models/Settings/Debug.cs b/src/models/Settings/Debug.cs index d3a71ce7..fb21b839 100644 --- a/src/models/Settings/Debug.cs +++ b/src/models/Settings/Debug.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Settings; public class Debug diff --git a/src/models/Settings/InternetArchive.cs b/src/models/Settings/InternetArchive.cs index 254e304e..6207ef46 100644 --- a/src/models/Settings/InternetArchive.cs +++ b/src/models/Settings/InternetArchive.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +// ReSharper disable InconsistentNaming namespace Pannella.Models.Settings; diff --git a/src/models/Settings/Settings.cs b/src/models/Settings/Settings.cs index 1e8c9e2a..a71dc5f1 100644 --- a/src/models/Settings/Settings.cs +++ b/src/models/Settings/Settings.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + using Newtonsoft.Json; namespace Pannella.Models.Settings; diff --git a/src/models/Updater/Substitute.cs b/src/models/Updater/Substitute.cs index 01c94d24..ae2d1023 100644 --- a/src/models/Updater/Substitute.cs +++ b/src/models/Updater/Substitute.cs @@ -1,3 +1,5 @@ +// ReSharper disable InconsistentNaming + namespace Pannella.Models.Updater; public class Substitute diff --git a/src/partials/Program.CheckForUpdates.cs b/src/partials/Program.CheckForUpdates.cs index f0b6cdad..82a6c377 100644 --- a/src/partials/Program.CheckForUpdates.cs +++ b/src/partials/Program.CheckForUpdates.cs @@ -1,20 +1,30 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void CheckForUpdates(string path, bool selfUpdate, string[] args, bool forceUpdate) { - Console.WriteLine("Pupdate v" + VERSION); + Console.WriteLine("pupdate v" + VERSION); Console.WriteLine("Checking for updates..."); if (CheckVersion(path) && !selfUpdate) { +#if NET7_0 + Console.WriteLine("You are using a legacy version of Pupdate that is running on .NET 7.0"); + Console.WriteLine("Auto/Self updates are not supported in this mode."); + Console.WriteLine("Please download the latest version of Pupdate from GitHub directly."); + Console.ReadKey(false); + Console.WriteLine(); + + return; +#endif if (forceUpdate) { int result = UpdateSelfAndRun(path, args); Environment.Exit(result); return; } + ConsoleKey[] acceptedInputs = { ConsoleKey.I, ConsoleKey.C, ConsoleKey.Q }; ConsoleKey response; @@ -29,6 +39,7 @@ private static void CheckForUpdates(string path, bool selfUpdate, string[] args, } while (!acceptedInputs.Contains(response)); + // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault switch (response) { case ConsoleKey.I: diff --git a/src/partials/Program.Constants.cs b/src/partials/Program.Constants.cs index d83561ba..bb85771d 100644 --- a/src/partials/Program.Constants.cs +++ b/src/partials/Program.Constants.cs @@ -1,8 +1,10 @@ +// ReSharper disable UseRawString + using System.Reflection; namespace Pannella; -internal partial class Program +internal static partial class Program { private static readonly string VERSION = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3); diff --git a/src/partials/Program.DisplayModes.cs b/src/partials/Program.DisplayModes.cs index 52dbb2c1..9d0e8b91 100644 --- a/src/partials/Program.DisplayModes.cs +++ b/src/partials/Program.DisplayModes.cs @@ -3,7 +3,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void EnableDisplayModes(List coreIdentifiers = null, List displayModes = null, bool isCurated = false) @@ -30,17 +30,12 @@ private static void EnableDisplayModes(List coreIdentifiers = null, List ServiceHelper.CoresService.AddDisplayModes(coreIdentifier, displayModes, isCurated, merge: answer == "merge"); } - catch (Exception e) + catch (Exception ex) { Console.WriteLine("Uh oh something went wrong."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e.ToString()); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); } } @@ -78,17 +73,12 @@ private static void ResetDisplayModes(List coreIdentifiers = null) coreSettings.original_display_modes = null; coreSettings.selected_display_modes = null; } - catch (Exception e) + catch (Exception ex) { Console.WriteLine("Uh oh something went wrong."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e.ToString()); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); } } diff --git a/src/partials/Program.GameAndWatch.cs b/src/partials/Program.GameAndWatch.cs index 948f51fb..d07ef0b9 100644 --- a/src/partials/Program.GameAndWatch.cs +++ b/src/partials/Program.GameAndWatch.cs @@ -7,7 +7,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void BuildGameAndWatchRoms() { @@ -75,9 +75,9 @@ private static void BuildGameAndWatchRoms() p!.WaitForExit(); } - catch (Exception e) + catch (Exception ex) { - Console.Error.WriteLine($"An error occurred: {e.GetType().Name} : {e}"); + Console.Error.WriteLine($"An error occurred: {ex.GetType().Name} : {ex}"); } } diff --git a/src/partials/Program.GameBoyPalettes.cs b/src/partials/Program.GameBoyPalettes.cs index 75df59a5..d69d8eb9 100644 --- a/src/partials/Program.GameBoyPalettes.cs +++ b/src/partials/Program.GameBoyPalettes.cs @@ -6,7 +6,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void DownloadGameBoyPalettes() { @@ -36,17 +36,12 @@ private static void DownloadGameBoyPalettes() Directory.Delete(extractPath, true); Console.WriteLine("Complete."); } - catch (Exception e) + catch (Exception ex) { Console.WriteLine("Something happened while trying to install the asset files..."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); } } } diff --git a/src/partials/Program.HelpText.cs b/src/partials/Program.HelpText.cs index 436bc51a..6930c231 100644 --- a/src/partials/Program.HelpText.cs +++ b/src/partials/Program.HelpText.cs @@ -1,6 +1,6 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private const string HELP_TEXT = """ diff --git a/src/partials/Program.Helpers.cs b/src/partials/Program.Helpers.cs index d0f4e893..e20b9fbe 100644 --- a/src/partials/Program.Helpers.cs +++ b/src/partials/Program.Helpers.cs @@ -6,7 +6,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { // return true if newer version is available private static bool CheckVersion(string path) @@ -25,6 +25,9 @@ private static bool CheckVersion(string path) if (check) { +#if NET7_0 + Console.WriteLine($"A new version {v} is available."); +#else Console.WriteLine($"A new version {v} is available. Downloading now..."); string url = string.Format(RELEASE_URL, tagName, SYSTEM_OS_PLATFORM); @@ -34,7 +37,8 @@ private static bool CheckVersion(string path) Console.WriteLine("Download complete."); Console.WriteLine(saveLocation); - Console.WriteLine("Go to " + releases[0].html_url + " for a change log"); +#endif + Console.WriteLine("Go to " + releases[0].html_url + " for a change log."); } else { @@ -46,16 +50,12 @@ private static bool CheckVersion(string path) return false; } - catch (HttpRequestException e) + catch (HttpRequestException ex) { - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); + return false; } } diff --git a/src/partials/Program.InstanceGenerator.cs b/src/partials/Program.InstanceGenerator.cs index 5d4d456b..f7cfef9c 100644 --- a/src/partials/Program.InstanceGenerator.cs +++ b/src/partials/Program.InstanceGenerator.cs @@ -2,7 +2,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void RunInstanceGenerator(CoreUpdaterService coreUpdaterService, bool force = false) { diff --git a/src/partials/Program.Menus.Cores.cs b/src/partials/Program.Menus.Cores.cs index c86b3bb9..f8a017b1 100644 --- a/src/partials/Program.Menus.Cores.cs +++ b/src/partials/Program.Menus.Cores.cs @@ -4,7 +4,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static Dictionary ShowCoresMenu(List cores, string message, bool isCoreSelection, bool skipQuit = false) @@ -41,7 +41,7 @@ private static Dictionary ShowCoresMenu(List cores, string m }); var current = -1; - if ((offset + pageSize) <= cores.Count) + if (offset + pageSize <= cores.Count) { menu.Add("Next Page", thisMenu => { @@ -54,7 +54,7 @@ private static Dictionary ShowCoresMenu(List cores, string m { current++; - if ((current <= (offset + pageSize)) && (current >= offset)) + if (current <= offset + pageSize && current >= offset) { var coreSettings = ServiceHelper.SettingsService.GetCoreSettings(core.identifier); var selected = @@ -82,7 +82,7 @@ private static Dictionary ShowCoresMenu(List cores, string m } } - if ((offset + pageSize) <= cores.Count) + if (offset + pageSize <= cores.Count) { menu.Add("Next Page", thisMenu => { diff --git a/src/partials/Program.Menus.DisplayModes.cs b/src/partials/Program.Menus.DisplayModes.cs index 845dd6ce..1e63bfc0 100644 --- a/src/partials/Program.Menus.DisplayModes.cs +++ b/src/partials/Program.Menus.DisplayModes.cs @@ -5,7 +5,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void DisplayModeSelector(bool showCoreSelector = false) { @@ -35,7 +35,7 @@ private static void DisplayModeSelector(bool showCoreSelector = false) }); var current = -1; - if ((offset + pageSize) <= ServiceHelper.CoresService.AllDisplayModes.Count) + if (offset + pageSize <= ServiceHelper.CoresService.AllDisplayModes.Count) { menu.Add("Next Page", thisMenu => { @@ -48,7 +48,7 @@ private static void DisplayModeSelector(bool showCoreSelector = false) { current++; - if ((current <= (offset + pageSize)) && (current >= offset)) + if (current <= offset + pageSize && current >= offset) { var selected = results.Contains(displayMode.value); var title = MenuItemName(displayMode.description, selected); @@ -76,7 +76,7 @@ private static void DisplayModeSelector(bool showCoreSelector = false) } } - if ((offset + pageSize) <= ServiceHelper.CoresService.AllDisplayModes.Count) + if (offset + pageSize <= ServiceHelper.CoresService.AllDisplayModes.Count) { menu.Add("Next Page", thisMenu => { diff --git a/src/partials/Program.Menus.PlatformImagePacks.cs b/src/partials/Program.Menus.PlatformImagePacks.cs index c3e14776..bc7baba0 100644 --- a/src/partials/Program.Menus.PlatformImagePacks.cs +++ b/src/partials/Program.Menus.PlatformImagePacks.cs @@ -3,7 +3,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void PlatformImagePackSelector() { diff --git a/src/partials/Program.Menus.Questions.cs b/src/partials/Program.Menus.Questions.cs index 4729b384..e0218c86 100644 --- a/src/partials/Program.Menus.Questions.cs +++ b/src/partials/Program.Menus.Questions.cs @@ -2,7 +2,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void AskAboutNewCores(bool force = false) { diff --git a/src/partials/Program.Menus.Settings.cs b/src/partials/Program.Menus.Settings.cs index 4b9e55a3..8836396d 100644 --- a/src/partials/Program.Menus.Settings.cs +++ b/src/partials/Program.Menus.Settings.cs @@ -5,7 +5,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void SettingsMenu() { @@ -28,7 +28,7 @@ from property in type.GetProperties() config.WriteItemAction = item => Console.Write("{0}", item.Name); }); - foreach (var (name, text) in menuItems) + foreach ((string name, string text) in menuItems) { var property = type.GetProperty(name); var value = (bool)property!.GetValue(ServiceHelper.SettingsService.Config)!; diff --git a/src/partials/Program.Menus.cs b/src/partials/Program.Menus.cs index f8e7d03b..a02a8146 100644 --- a/src/partials/Program.Menus.cs +++ b/src/partials/Program.Menus.cs @@ -5,7 +5,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void DisplayMenu(CoreUpdaterService coreUpdaterService) { @@ -36,7 +36,7 @@ private static void DisplayMenu(CoreUpdaterService coreUpdaterService) EnableWriteTitle = true, WriteHeaderAction = () => Console.WriteLine("Choose your destiny:"), SelectedItemBackgroundColor = Console.ForegroundColor, - SelectedItemForegroundColor = Console.BackgroundColor, + SelectedItemForegroundColor = Console.BackgroundColor }; #region Pocket Setup - Display Modes diff --git a/src/partials/Program.MissingCores.cs b/src/partials/Program.MissingCores.cs index 65990bf4..891bb277 100644 --- a/src/partials/Program.MissingCores.cs +++ b/src/partials/Program.MissingCores.cs @@ -3,7 +3,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void CheckForMissingCores(bool enableMissingCores) { diff --git a/src/partials/Program.PocketLibraryImages.cs b/src/partials/Program.PocketLibraryImages.cs index 00e9ff1f..0147bc57 100644 --- a/src/partials/Program.PocketLibraryImages.cs +++ b/src/partials/Program.PocketLibraryImages.cs @@ -1,11 +1,10 @@ using Pannella.Helpers; using Pannella.Models.Settings; -using Pannella.Services; using ArchiveFile = Pannella.Models.Archive.File; namespace Pannella; -internal partial class Program +internal static partial class Program { private static void DownloadPockLibraryImages() { @@ -34,17 +33,12 @@ private static void DownloadPockLibraryImages() Directory.Delete(extractPath, true); Console.WriteLine("Complete."); } - catch (Exception e) + catch (Exception ex) { Console.WriteLine("Something happened while trying to install the asset files..."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - Console.WriteLine(e); - } - else - { - Console.WriteLine(e.Message); - } + Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces + ? ex + : Util.GetExceptionMessage(ex)); } } else diff --git a/src/partials/Program.PrintOpenFpgaFolders.cs b/src/partials/Program.PrintOpenFpgaFolders.cs index de670c8e..faae81d7 100644 --- a/src/partials/Program.PrintOpenFpgaFolders.cs +++ b/src/partials/Program.PrintOpenFpgaFolders.cs @@ -2,7 +2,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static void PrintOpenFpgaCategories() { diff --git a/src/partials/Program.Sponsors.cs b/src/partials/Program.Sponsors.cs index 46340e74..5630fe1f 100644 --- a/src/partials/Program.Sponsors.cs +++ b/src/partials/Program.Sponsors.cs @@ -4,7 +4,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static string GetRandomSponsorLinks() { diff --git a/src/partials/Program.UpdateSelfAndRun.cs b/src/partials/Program.UpdateSelfAndRun.cs index dc300c3d..0cedf4d6 100644 --- a/src/partials/Program.UpdateSelfAndRun.cs +++ b/src/partials/Program.UpdateSelfAndRun.cs @@ -5,7 +5,7 @@ namespace Pannella; -internal partial class Program +internal static partial class Program { private static int UpdateSelfAndRun(string directory, string[] updaterArgs) { @@ -71,9 +71,9 @@ private static int UpdateSelfAndRun(string directory, string[] updaterArgs) exitCode = p.ExitCode; } - catch (Exception e) + catch (Exception ex) { - Console.Error.WriteLine($"An error occurred: {e.GetType().Name}:{e}"); + Console.Error.WriteLine($"An error occurred: {ex.GetType().Name}:{ex}"); } return exitCode; diff --git a/src/services/AnalogizerSettingsService.cs b/src/services/AnalogizerSettingsService.cs index 7176c080..1608da90 100644 --- a/src/services/AnalogizerSettingsService.cs +++ b/src/services/AnalogizerSettingsService.cs @@ -1,3 +1,6 @@ +// ReSharper disable UseRawString +// ReSharper disable UseObjectOrCollectionInitializer + using Pannella.Helpers; namespace Pannella.Services; @@ -76,6 +79,7 @@ public static void GenerateUserOptions(AnalogizerOptionType[] records, int wLen foreach (var sel in records) { + // ReSharper disable once UnusedVariable string selInput = sel.GetInput(); foreach (var item in sel.Dict) diff --git a/src/services/ArchiveService.cs b/src/services/ArchiveService.cs index e01718b5..091c3c04 100644 --- a/src/services/ArchiveService.cs +++ b/src/services/ArchiveService.cs @@ -20,15 +20,17 @@ public class ArchiveService : Base private readonly Dictionary archiveFiles; private readonly List archives; private readonly bool useCustomArchive; - private InternetArchive creds; + private readonly InternetArchive credentials; + private readonly bool showStackTraces; - public ArchiveService(List archives, bool crcCheck, bool useCustomArchive) + public ArchiveService(List archives, InternetArchive credentials, bool crcCheck, bool useCustomArchive, bool showStackTraces) { this.crcCheck = crcCheck; this.useCustomArchive = useCustomArchive; this.archives = archives; this.archiveFiles = new Dictionary(); - this.creds = ServiceHelper.SettingsService.credentials?.internet_archive; + this.credentials = credentials; + this.showStackTraces = showStackTraces; } public SettingsArchive GetArchive(string coreIdentifier = null) @@ -56,6 +58,7 @@ public ArchiveFile GetArchiveFile(string fileName, string coreIdentifier = null) return files.FirstOrDefault(x => x.name == fileName); } + // ReSharper disable once MemberCanBePrivate.Global public IEnumerable GetArchiveFiles(string coreIdentifier) { SettingsArchive archive = this.GetArchive(coreIdentifier); @@ -162,27 +165,26 @@ public bool DownloadArchiveFile(SettingsArchive archive, ArchiveFile archiveFile { HttpHelper.Instance.DownloadFile(url, destinationFileName, 600); count++; - } - while (count < 3 && !ValidateChecksum(destinationFileName, archiveFile)); - - if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".zip") - { - //extract - ZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName), true); - //delete - File.Delete(destinationFileName); - } - else if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".7z") - { - //extract - SevenZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName)); - //delete - File.Delete(destinationFileName); - } + } while (count < 3 && !ValidateChecksum(destinationFileName, archiveFile)); + + // if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".zip") + // { + // //extract + // ZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName), true); + // //delete + // File.Delete(destinationFileName); + // } + // else if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".7z") + // { + // //extract + // SevenZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName)); + // //delete + // File.Delete(destinationFileName); + // } } - catch (HttpRequestException e) + catch (HttpRequestException ex) { - WriteMessage(e.StatusCode switch + WriteMessage(ex.StatusCode switch { HttpStatusCode.NotFound => $"Unable to find '{archiveFile.name}' in archive '{archive.name}'", _ => $"There was a problem downloading '{archiveFile.name}'" @@ -192,19 +194,13 @@ public bool DownloadArchiveFile(SettingsArchive archive, ArchiveFile archiveFile return false; } - catch (Exception e) + catch (Exception ex) { WriteMessage($"Something went wrong with '{archiveFile.name}'"); - - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } - + WriteMessage(this.showStackTraces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); + return false; } @@ -226,15 +222,19 @@ private bool ValidateChecksum(string filePath, ArchiveFile archiveFile) return false; } - public void Authenticate() + private void Authenticate() { - if (this.creds != null) { - Dictionary fields = new Dictionary(); - fields.Add("login", "true"); - fields.Add("remember", "true"); - fields.Add("submit_by_js", "true"); - fields.Add("referrer", "https://archive.org/CREATE/"); - HttpHelper.Instance.GetAuthCookie(this.creds.username, this.creds.password, LOGIN, fields); - } + if (this.credentials != null) + { + var fields = new Dictionary + { + { "login", "true" }, + { "remember", "true" }, + { "submit_by_js", "true" }, + { "referrer", "https://archive.org/CREATE/" } + }; + + HttpHelper.Instance.GetAuthCookie(this.credentials.username, this.credentials.password, LOGIN, fields); + } } } diff --git a/src/services/AssetsService.cs b/src/services/AssetsService.cs index bd13af4b..ae31f5a7 100644 --- a/src/services/AssetsService.cs +++ b/src/services/AssetsService.cs @@ -13,6 +13,7 @@ public class AssetsService private const string BLACKLIST_FILE = "blacklist.json"; private readonly bool useLocalBlacklist; + private readonly bool showStackTraces; private List blacklist; public List Blacklist @@ -58,7 +59,8 @@ public List Blacklist catch (Exception ex) { Console.WriteLine($"There was an error parsing the {BLACKLIST_FILE} file."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) + + if (this.showStackTraces) { Console.WriteLine(ex); } @@ -78,9 +80,10 @@ public List Blacklist } } - public AssetsService(bool useLocalBlacklist) + public AssetsService(bool useLocalBlacklist, bool showStackTraces) { this.useLocalBlacklist = useLocalBlacklist; + this.showStackTraces = showStackTraces; } public static void BackupSaves(string directory, string backupLocation) @@ -133,7 +136,7 @@ private static void BackupDirectory(string rootDirectory, string folderName, str } else { - Console.WriteLine($"Backup with the same contents already exists, skipping..."); + Console.WriteLine("Backup with the same contents already exists, skipping..."); } } else @@ -172,7 +175,7 @@ public static void PruneSaveStates(string rootDirectory, string coreName = null) string savesPath = Path.Combine(rootDirectory, "Memories", "Save States"); //YYYYMMDD_HHMMSS_SOMETHING_SOMETHING_GAMETITLE.STA - string pattern = @"^(\d\d\d\d\d\d\d\d_\d\d\d\d\d\d)_[A-Za-z]+_[A-Za-z0-9]+_(.*)\.sta$"; + const string pattern = @"^(\d\d\d\d\d\d\d\d_\d\d\d\d\d\d)_[A-Za-z]+_[A-Za-z0-9]+_(.*)\.sta$"; Regex regex = new Regex(pattern); foreach (var dir in Directory.EnumerateDirectories(savesPath) ) @@ -199,7 +202,7 @@ public static void PruneSaveStates(string rootDirectory, string coreName = null) if (match.Success) { // Extract the timestamp (group 1) and game name (group 2) - long timestamp = long.Parse(match.Groups[1].Value.Replace("_", String.Empty)); + long timestamp = long.Parse(match.Groups[1].Value.Replace("_", string.Empty)); string applicationName = match.Groups[2].Value; // Check if this game already has a file in the dictionary diff --git a/src/services/CoinOpService.cs b/src/services/CoinOpService.cs index 1538b0f5..87681bc3 100644 --- a/src/services/CoinOpService.cs +++ b/src/services/CoinOpService.cs @@ -11,7 +11,7 @@ public static byte[] FetchLicense(string email) { var client = new HttpClient(); - string url = String.Format(LICENSE_ENDPOINT, System.Web.HttpUtility.UrlEncode(email)); + string url = string.Format(LICENSE_ENDPOINT, System.Web.HttpUtility.UrlEncode(email)); var request = new HttpRequestMessage { Method = HttpMethod.Get, @@ -24,10 +24,14 @@ public static byte[] FetchLicense(string email) var response = client.Send(request); - if (response.StatusCode == HttpStatusCode.NotFound) { + if (response.StatusCode == HttpStatusCode.NotFound) + { var responseBody = response.Content.ReadAsStringAsync().Result; throw new Exception(responseBody); - } else if (response.StatusCode != HttpStatusCode.OK) { + } + + if (response.StatusCode != HttpStatusCode.OK) + { throw new Exception("Didn't work"); } diff --git a/src/services/CoreUpdaterService.cs b/src/services/CoreUpdaterService.cs index 194d5550..1b37d6ff 100644 --- a/src/services/CoreUpdaterService.cs +++ b/src/services/CoreUpdaterService.cs @@ -294,17 +294,12 @@ public void RunUpdates(string[] ids = null, bool clean = false) WriteMessage("Installation complete."); Divide(); } - catch (Exception e) + catch (Exception ex) { WriteMessage("Uh oh something went wrong."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } @@ -319,7 +314,7 @@ public void RunUpdates(string[] ids = null, bool clean = false) SkippedAssets = skippedAssets, MissingLicenses = missingLicenses, FirmwareUpdated = firmwareDownloaded, - SkipOutro = false, + SkipOutro = false }; OnUpdateProcessComplete(args); diff --git a/src/services/CoresService.DisplayModes.cs b/src/services/CoresService.DisplayModes.cs index 6e1e64a6..2265c4d5 100644 --- a/src/services/CoresService.DisplayModes.cs +++ b/src/services/CoresService.DisplayModes.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Pannella.Helpers; using Pannella.Models.DisplayModes; namespace Pannella.Services; @@ -51,14 +52,9 @@ public Dictionary> DisplayModes catch (Exception ex) { WriteMessage($"There was an error parsing the {DISPLAY_MODES_FILE} file."); - if (this.settingsService.Debug.show_stack_traces) - { - WriteMessage(ex.ToString()); - } - else - { - WriteMessage(ex.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } else diff --git a/src/services/CoresService.Download.cs b/src/services/CoresService.Download.cs index db1a155c..e8cbd508 100644 --- a/src/services/CoresService.Download.cs +++ b/src/services/CoresService.Download.cs @@ -57,17 +57,12 @@ public void DownloadCoreAssets(List coreList) Divide(); } - catch (Exception e) + catch (Exception ex) { WriteMessage("Uh oh something went wrong."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } @@ -77,7 +72,7 @@ public void DownloadCoreAssets(List coreList) InstalledAssets = installedAssets, SkippedAssets = skippedAssets, MissingLicenses = missingLicenses, - SkipOutro = false, + SkipOutro = false }; OnUpdateProcessComplete(args); @@ -127,6 +122,7 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet } WriteMessage("Looking for Assets..."); + Archive archive = this.archiveService.GetArchive(); AnalogueCore info = this.ReadCoreJson(core.identifier); // cores with multiple platforms won't work...not sure any exist right now? @@ -194,9 +190,10 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet } } - //grab the core specific archive, now + // grab the core specific archive, now archive = this.archiveService.GetArchive(core.identifier); - if ((archive.type == ArchiveType.core_specific_archive || archive.type == ArchiveType.core_specific_custom_archive) + + if (archive.type is ArchiveType.core_specific_archive or ArchiveType.core_specific_custom_archive && archive.enabled && !archive.has_instance_jsons && ((archive.one_time && !archive.complete) || !archive.one_time)) { @@ -220,6 +217,22 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet { WriteMessage($"Downloading: {file.name}..."); bool result = this.archiveService.DownloadArchiveFile(archive, file, commonPath); + string destinationFileName = Path.Combine(commonPath, file.name); + + if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".zip") + { + //extract + ZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName), true); + //delete + File.Delete(destinationFileName); + } + else if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".7z") + { + //extract + SevenZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName)); + //delete + File.Delete(destinationFileName); + } if (result) { @@ -340,17 +353,12 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet } } } - catch (Exception e) + catch (Exception ex) { WriteMessage($"Error while processing '{file}'"); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } } diff --git a/src/services/CoresService.Extras.cs b/src/services/CoresService.Extras.cs index 59cc7533..0e91e084 100644 --- a/src/services/CoresService.Extras.cs +++ b/src/services/CoresService.Extras.cs @@ -37,14 +37,9 @@ public List PocketExtrasList catch (Exception ex) { WriteMessage($"There was an error parsing the {POCKET_EXTRAS_FILE} file."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(ex.ToString()); - } - else - { - WriteMessage(ex.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } else @@ -66,6 +61,7 @@ public PocketExtra GetPocketExtra(string pocketExtraIdOrCoreIdentifier) public void GetPocketExtra(PocketExtra pocketExtra, string path, bool downloadAssets) { + // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (pocketExtra.type) { case PocketExtraType.additional_assets: @@ -179,17 +175,13 @@ private void DownloadPocketExtrasPlatform(PocketExtra pocketExtra, string path, WriteMessage("Complete."); } - catch (Exception e) + catch (Exception ex) { WriteMessage("Something happened while trying to install the asset files..."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); + return; } @@ -216,7 +208,7 @@ private void DownloadPocketExtrasPlatform(PocketExtra pocketExtra, string path, MissingLicenses = (bool)results["missingLicense"] ? new List { core.identifier } : new List(), - SkipOutro = true, + SkipOutro = true }; OnUpdateProcessComplete(args); @@ -331,17 +323,13 @@ private void DownloadPocketExtras(PocketExtra pocketExtra, string path, bool dow Directory.Delete(extractPath, true); WriteMessage("Complete."); } - catch (Exception e) + catch (Exception ex) { WriteMessage("Something happened while trying to install the asset files..."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); + return; } @@ -359,7 +347,7 @@ private void DownloadPocketExtras(PocketExtra pocketExtra, string path, bool dow MissingLicenses = (bool)results["missingLicense"] ? new List { core.identifier } : new List(), - SkipOutro = true, + SkipOutro = true }; OnUpdateProcessComplete(args); diff --git a/src/services/CoresService.Helpers.cs b/src/services/CoresService.Helpers.cs index b773070e..e04da164 100644 --- a/src/services/CoresService.Helpers.cs +++ b/src/services/CoresService.Helpers.cs @@ -40,7 +40,7 @@ private IEnumerable GetLocalCores() public void RefreshLocalCores() { - cores.AddRange(this.GetLocalCores()); + CORES.AddRange(this.GetLocalCores()); } private bool InstallGithubAsset(string identifier, string platformId, string downloadUrl) @@ -159,7 +159,7 @@ private bool CheckCrc(string filePath, ArchiveFile archiveFile) private bool CheckLicenseMd5(DataSlot slot, string licenseSlotId, string platform) { - if (slot.md5 != null && (licenseSlotId != null && slot.id == licenseSlotId)) + if (slot.md5 != null && licenseSlotId != null && slot.id == licenseSlotId) { string path = Path.Combine(this.installPath, "Assets", platform); string filePath = Path.Combine(path, "common", slot.filename); @@ -184,10 +184,7 @@ private bool CheckLicenseMd5(DataSlot slot, string licenseSlotId, string platfor public bool CheckLicenseFile(Core core) { - if (core.updaters?.license.filename != null) - { - return File.Exists(Path.Combine(this.installPath, LICENSE_EXTRACT_LOCATION, core.updaters.license.filename)); - } - return false; + return core.updaters?.license.filename != null && + File.Exists(Path.Combine(this.installPath, LICENSE_EXTRACT_LOCATION, core.updaters.license.filename)); } } diff --git a/src/services/CoresService.IgnoreInstanceJson.cs b/src/services/CoresService.IgnoreInstanceJson.cs index 59e9915e..42b83c0f 100644 --- a/src/services/CoresService.IgnoreInstanceJson.cs +++ b/src/services/CoresService.IgnoreInstanceJson.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Pannella.Helpers; using Pannella.Models; namespace Pannella.Services; @@ -8,13 +9,13 @@ public partial class CoresService private const string IGNORE_INSTANCE_JSON_END_POINT = "https://raw.githubusercontent.com/mattpannella/pupdate/main/ignore_instance.json"; private const string IGNORE_INSTANCE_JSON_FILE = "ignore_instance.json"; - private static List ignoreInstanceJson; + private static List IGNORE_INSTANCE_JSON; private List IgnoreInstanceJson { get { - if (ignoreInstanceJson == null) + if (IGNORE_INSTANCE_JSON == null) { string json = this.GetServerJsonFile( this.settingsService.Config.use_local_ignore_instance_json, @@ -27,28 +28,23 @@ private List IgnoreInstanceJson { var coreIdentifiers = JsonConvert.DeserializeObject(json); - ignoreInstanceJson = coreIdentifiers.core_identifiers; + IGNORE_INSTANCE_JSON = coreIdentifiers.core_identifiers; } catch (Exception ex) { WriteMessage($"There was an error parsing the {IGNORE_INSTANCE_JSON_FILE} file."); - if (this.settingsService.Debug.show_stack_traces) - { - WriteMessage(ex.ToString()); - } - else - { - WriteMessage(ex.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } } else { - ignoreInstanceJson = new List(); + IGNORE_INSTANCE_JSON = new List(); } } - return ignoreInstanceJson; + return IGNORE_INSTANCE_JSON; } } } diff --git a/src/services/CoresService.Jotego.cs b/src/services/CoresService.Jotego.cs index 5712ed1d..04602675 100644 --- a/src/services/CoresService.Jotego.cs +++ b/src/services/CoresService.Jotego.cs @@ -5,8 +5,8 @@ namespace Pannella.Services; public partial class CoresService { - public const string JTBETA_KEY_FILENAME = "jtbeta.zip"; - public const string JTBETA_KEY_ALT_FILENAME = "beta.bin"; + private const string JTBETA_KEY_FILENAME = "jtbeta.zip"; + private const string JTBETA_KEY_ALT_FILENAME = "beta.bin"; private Dictionary renamedPlatformFiles; @@ -40,23 +40,19 @@ private Dictionary LoadRenamedPlatformFiles() } } } - catch (Exception e) + catch (Exception ex) { WriteMessage("Unable to retrieve archive contents. Asset download may not work."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(e.ToString()); - } - else - { - WriteMessage(e.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); } return platformFiles; } - public bool ExtractJTBetaKey() + // ReSharper disable once InconsistentNaming + private bool ExtractJTBetaKey() { string keyPath = Path.Combine(this.installPath, LICENSE_EXTRACT_LOCATION); string zipFile = Path.Combine(this.installPath, JTBETA_KEY_FILENAME); diff --git a/src/services/CoresService.License.cs b/src/services/CoresService.License.cs index 30e91572..1557f7eb 100644 --- a/src/services/CoresService.License.cs +++ b/src/services/CoresService.License.cs @@ -49,9 +49,10 @@ public void CopyLicense(Core core) } } - public bool RetrieveKeys() + public void RetrieveKeys() { string keyPath = Path.Combine(this.installPath, LICENSE_EXTRACT_LOCATION); + this.ExtractJTBetaKey(); string email = ServiceHelper.SettingsService.Config.patreon_email_address; @@ -59,28 +60,38 @@ public bool RetrieveKeys() { Console.WriteLine("Unable to retrieve Coin-Op Collection Beta license. Please set your patreon email address."); Console.Write("Enter value: "); + email = Console.ReadLine(); + ServiceHelper.SettingsService.Config.patreon_email_address = email; ServiceHelper.SettingsService.Save(); } + if (email != null && ServiceHelper.SettingsService.Config.coin_op_beta) { if (!Directory.Exists(keyPath)) { Directory.CreateDirectory(keyPath); } - try { + + try + { Console.WriteLine("Retrieving Coin-Op Collection license..."); + var license = CoinOpService.FetchLicense(email); + File.WriteAllBytes(Path.Combine(keyPath, "coinop.key"), license); + Console.WriteLine("License successfully downloaded."); - } catch (Exception e) { - Console.WriteLine(e.Message); - } finally { + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { Divide(); } } - - return true; } } diff --git a/src/services/CoresService.Video.cs b/src/services/CoresService.Video.cs index ceed708b..dd96199e 100644 --- a/src/services/CoresService.Video.cs +++ b/src/services/CoresService.Video.cs @@ -32,8 +32,7 @@ public void AddDisplayModes(string identifier, List displayModes = bool forceOriginal = false, bool merge = false) { var info = this.ReadCoreJson(identifier); - var video = this.ReadVideoJson(identifier); - Dictionary toAdd = new Dictionary(); + var toAdd = new Dictionary(); if (isCurated) { @@ -64,7 +63,6 @@ public void AddDisplayModes(string identifier, List displayModes = { toAdd.TryAdd(displayMode.value, displayMode); } - } else if (info.metadata.platform_ids.Contains("lynx") && this.DisplayModes.TryGetValue("lynx", out var lynx)) { @@ -114,6 +112,7 @@ public void AddDisplayModes(string identifier, List displayModes = } var settings = this.settingsService.GetCoreSettings(identifier); + var video = this.ReadVideoJson(identifier); if (!settings.display_modes || forceOriginal) { @@ -152,10 +151,41 @@ public void AddDisplayModes(string identifier, List displayModes = .Select(kvp => new AnalogueDisplayMode { id = kvp.Value.value }) .ToList(); - Dictionary output = new Dictionary { { "video", video } }; - string json = JsonConvert.SerializeObject(output, Formatting.Indented); + var output = new Dictionary { { "video", video } }; + var json = JsonConvert.SerializeObject(output, Formatting.Indented); + + // making a backup copy of the video.json to account for any errors during the file writing process + // related to issue #354 + var fileName = Path.Combine(this.installPath, "Cores", identifier, "video.json"); + var backupFileName = Path.Combine(this.installPath, "Cores", identifier, "video.copy.json"); + var restore = false; + + if (File.Exists(backupFileName)) + File.Delete(backupFileName); + + File.Copy(fileName, backupFileName); + + try + { + File.WriteAllText(fileName, json); + } + catch (Exception ex) + { + Console.WriteLine("Unable to write to the video.json file. Restoring the existing one."); + Console.WriteLine(this.settingsService.Debug.show_stack_traces + ? ex + : ex.Message); - File.WriteAllText(Path.Combine(this.installPath, "Cores", identifier, "video.json"), json); + restore = true; + } + + if (restore) + { + File.Delete(fileName); + File.Copy(backupFileName, fileName); + } + + File.Delete(backupFileName); } public void ClearDisplayModes(string identifier) diff --git a/src/services/CoresService.cs b/src/services/CoresService.cs index ce167438..eb4f1801 100644 --- a/src/services/CoresService.cs +++ b/src/services/CoresService.cs @@ -17,13 +17,13 @@ public partial class CoresService : BaseProcess private readonly SettingsService settingsService; private readonly ArchiveService archiveService; private readonly AssetsService assetsService; - private static List cores; + private static List CORES; public List Cores { get { - if (cores == null) + if (CORES == null) { string json = null; @@ -62,27 +62,23 @@ public List Cores if (settingsService.Config.no_analogizer_variants) { //filter the list if the setting is on - cores = coresList.Where(core => !IsAnalogizerVariant(core.identifier)).ToList(); + CORES = coresList.Where(core => !IsAnalogizerVariant(core.identifier)).ToList(); } else { - cores = coresList; + CORES = coresList; } - cores.AddRange(this.GetLocalCores()); - cores = cores.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); + CORES.AddRange(this.GetLocalCores()); + CORES = CORES.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); } } catch (Exception ex) { WriteMessage($"There was an error parsing the {CORES_FILE} file from the openFPGA cores inventory."); - if (ServiceHelper.SettingsService.Debug.show_stack_traces) - { - WriteMessage(ex.ToString()); - } - else - { - WriteMessage(ex.Message); - } + WriteMessage(this.settingsService.Debug.show_stack_traces + ? ex.ToString() + : Util.GetExceptionMessage(ex)); + throw; } } @@ -92,67 +88,67 @@ public List Cores } } - return cores; + return CORES; } } - private static List installedCores; + private static List INSTALLED_CORES; public List InstalledCores { get { - if (installedCores == null) + if (INSTALLED_CORES == null) { this.RefreshInstalledCores(); } - return installedCores; + return INSTALLED_CORES; } } - private static Dictionary> installedCoresWithSponsors; + private static Dictionary> INSTALLED_CORES_WITH_SPONSORS; public Dictionary> InstalledCoresWithSponsors { get { - if (installedCoresWithSponsors == null) + if (INSTALLED_CORES_WITH_SPONSORS == null) { this.RefreshInstalledCores(); } - return installedCoresWithSponsors; + return INSTALLED_CORES_WITH_SPONSORS; } } - private static List installedCoresWithCustomDisplayModes; + private static List INSTALLED_CORES_WITH_CUSTOM_DISPLAY_MODES; public List InstalledCoresWithCustomDisplayModes { get { - if (installedCoresWithCustomDisplayModes == null) + if (INSTALLED_CORES_WITH_CUSTOM_DISPLAY_MODES == null) { this.RefreshInstalledCores(); } - return installedCoresWithCustomDisplayModes; + return INSTALLED_CORES_WITH_CUSTOM_DISPLAY_MODES; } } - private static List coresNotInstalled; + private static List CORES_NOT_INSTALLED; public List CoresNotInstalled { get { - if (coresNotInstalled == null) + if (CORES_NOT_INSTALLED == null) { RefreshInstalledCores(); } - return coresNotInstalled; + return CORES_NOT_INSTALLED; } } @@ -192,45 +188,45 @@ public bool IsAnalogizerVariant(string identifier) public void RefreshInstalledCores() { - installedCores = new List(); - coresNotInstalled = new List(); - installedCoresWithSponsors = new Dictionary>(); - installedCoresWithCustomDisplayModes = new List(); + INSTALLED_CORES = new List(); + CORES_NOT_INSTALLED = new List(); + INSTALLED_CORES_WITH_SPONSORS = new Dictionary>(); + INSTALLED_CORES_WITH_CUSTOM_DISPLAY_MODES = new List(); - foreach (var core in cores) + foreach (var core in CORES) { if (this.IsInstalled(core.identifier)) { - installedCores.Add(core); + INSTALLED_CORES.Add(core); if (core.sponsor != null) { var info = ServiceHelper.CoresService.ReadCoreJson(core.identifier); var author = info.metadata.author; - if (installedCoresWithSponsors.TryGetValue(author, out List authorCores)) + if (INSTALLED_CORES_WITH_SPONSORS.TryGetValue(author, out List authorCores)) { authorCores.Add(core); } else { - installedCoresWithSponsors.Add(author, new List { core }); + INSTALLED_CORES_WITH_SPONSORS.Add(author, new List { core }); } } if (this.settingsService.GetCoreSettings(core.identifier).display_modes) { - installedCoresWithCustomDisplayModes.Add(core); + INSTALLED_CORES_WITH_CUSTOM_DISPLAY_MODES.Add(core); } } else { - coresNotInstalled.Add(core); + CORES_NOT_INSTALLED.Add(core); } } - installedCores = installedCores.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); - coresNotInstalled = coresNotInstalled.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); + INSTALLED_CORES = INSTALLED_CORES.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); + CORES_NOT_INSTALLED = CORES_NOT_INSTALLED.OrderBy(c => c.identifier.ToLowerInvariant()).ToList(); } public bool Install(Core core, bool clean = false) diff --git a/src/services/FirmwareService.cs b/src/services/FirmwareService.cs index 32730610..a8c2c809 100644 --- a/src/services/FirmwareService.cs +++ b/src/services/FirmwareService.cs @@ -11,13 +11,13 @@ public class FirmwareService : Base private const string DETAILS = "support/pocket/firmware/{0}/details"; private const string FILENAME_PATTERN = "pocket_firmware_*.bin"; - private static ReleaseDetails latest; + private static ReleaseDetails LATEST; private static ReleaseDetails GetDetails(string version = "latest") { - if (latest != null) + if (LATEST != null) { - return latest; + return LATEST; } string url = string.Format(BASE_URL + DETAILS, version); @@ -26,7 +26,7 @@ private static ReleaseDetails GetDetails(string version = "latest") if (version == "latest") { - latest = details; + LATEST = details; } return details; diff --git a/src/services/SettingsService.cs b/src/services/SettingsService.cs index a56c6666..b43a586b 100644 --- a/src/services/SettingsService.cs +++ b/src/services/SettingsService.cs @@ -16,7 +16,7 @@ public class SettingsService public Config Config => this.settings.config; public Debug Debug => this.settings.debug; - public Credentials credentials => this.settings.credentials; + public Credentials Credentials => this.settings.credentials; public SettingsService(string settingsPath, List cores = null) { @@ -57,7 +57,7 @@ public SettingsService(string settingsPath, List cores = null) public void Save() { - var options = new JsonSerializerSettings { ContractResolver = ArchiveContractResolver.Instance }; + var options = new JsonSerializerSettings { ContractResolver = ArchiveContractResolver.INSTANCE }; var json = JsonConvert.SerializeObject(settings, Formatting.Indented, options); File.WriteAllText(this.settingsFile, json);