diff --git a/Core/Objects/Vehicle/VehicleObject.cs b/Core/Objects/Vehicle/VehicleObject.cs index 3a9e1cb7..61acacd9 100644 --- a/Core/Objects/Vehicle/VehicleObject.cs +++ b/Core/Objects/Vehicle/VehicleObject.cs @@ -256,7 +256,7 @@ public ReadOnlySpan Load(ReadOnlySpan remainingData) // driving/start sounds StartSounds.Clear(); - var mask = 127; + const int mask = 127; var count = NumStartSounds & mask; for (var i = 0; i < count; ++i) { diff --git a/Core/Types/G1Dat.cs b/Core/Types/G1Dat.cs index 826083a7..44c1a0e0 100644 --- a/Core/Types/G1Dat.cs +++ b/Core/Types/G1Dat.cs @@ -17,7 +17,7 @@ public bool TryGetImageName(int id, out string? value) ? BaseImageIdNameMap.TryGetValue(id, out value) : (IsSteamG1 ? SteamImageIdNameMap : OtherImageIdNameMap).TryGetValue(id, out value); - public static Dictionary BaseImageIdNameMap = new() + static readonly Dictionary BaseImageIdNameMap = new() { { 304, "default_palette" }, @@ -2147,7 +2147,7 @@ public bool TryGetImageName(int id, out string? value) { 3549, "title_menu_lesson_l" }, }; - public static Dictionary SteamImageIdNameMap = new() + static readonly Dictionary SteamImageIdNameMap = new() { { 3550, "title_menu_globe_spin_0" }, { 3551, "title_menu_globe_spin_1" }, @@ -2228,7 +2228,7 @@ public bool TryGetImageName(int id, out string? value) { 3628, "owner_jailed" }, }; - public static Dictionary OtherImageIdNameMap = new() + static readonly Dictionary OtherImageIdNameMap = new() { // steam G1.dat doesn't have these 2 { 3550, "title_menu_lesson_a" }, diff --git a/Gui/MainForm.cs b/Gui/MainForm.cs index d7557c3f..a099a4f8 100644 --- a/Gui/MainForm.cs +++ b/Gui/MainForm.cs @@ -21,7 +21,9 @@ namespace OpenLoco.ObjectEditor.Gui public partial class MainForm : Form { readonly MainFormModel model; +#pragma warning disable CA1859 // Use concrete types when possible for improved performance readonly ILogger logger; +#pragma warning restore CA1859 // Use concrete types when possible for improved performance public IUiObject? CurrentUIObject { @@ -85,10 +87,10 @@ int CurrentUIImagePageNumber const string GithubLatestReleaseDownloadPage = "https://github.com/OpenLoco/ObjectEditor/releases"; const string GithubLatestReleaseAPI = "https://api.github.com/repos/OpenLoco/ObjectEditor/releases/latest"; - string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName); - string SettingsFile => Path.Combine(SettingsPath, "settings.json"); + static string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName); + static string SettingsFile => Path.Combine(SettingsPath, "settings.json"); - Version ApplicationVersion; + readonly Version ApplicationVersion; public MainForm() { @@ -100,7 +102,7 @@ public MainForm() }; var assembly = Assembly.GetExecutingAssembly(); - var paletteFilename = "Gui.palette.png"; + const string paletteFilename = "Gui.palette.png"; using (var stream = assembly.GetManifestResourceStream(paletteFilename)) { //var paletteBitmap = (Bitmap)Image.FromStream(stream!); @@ -113,7 +115,7 @@ public MainForm() } // grab current appl version from assembly - var versionFilename = "Gui.version.txt"; + const string versionFilename = "Gui.version.txt"; using (var stream = assembly.GetManifestResourceStream(versionFilename)) { var buf = new byte[5]; @@ -145,27 +147,17 @@ Version GetLatestVersion() { var jsonResponse = response.Content.ReadAsStringAsync().Result; var body = JsonSerializer.Deserialize(jsonResponse); - var tagName = body?.tag_name; - var version = Version.Parse(tagName); - return version; + var tagName = body?.TagName; + if (tagName != null) + { + return Version.Parse(tagName); + } } + +#pragma warning disable CA2201 // Do not raise reserved exception types throw new Exception("Unable to get latest version"); +#pragma warning restore CA2201 // Do not raise reserved exception types } - //async Task GetLatestVersionAsync() - //{ - // var client = new HttpClient(); - // client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("ObjectEditor", ApplicationVersion.ToString())); - // var response = await client.GetAsync("https://api.github.com/repos/OpenLoco/ObjectEditor/releases/latest"); - // if (response.IsSuccessStatusCode) - // { - // var jsonResponse = await response.Content.ReadAsStringAsync(); - // var body = JsonSerializer.Deserialize(jsonResponse); - // var tagName = body?.tag_name; - // var version = Version.Parse(tagName); - // return version; - // } - // throw new Exception("Unable to get latest version"); - //} void MainForm_Load(object sender, EventArgs e) { @@ -352,7 +344,7 @@ void InitDataCategoryTree() // sound effects //foreach (var sfx in model.SoundEffects) { - var displayName = OriginalDataFiles.SoundEffect; + const string displayName = OriginalDataFiles.SoundEffect; _ = sfxNode.Nodes.Add(displayName, displayName, 1, 1); } @@ -1498,9 +1490,4 @@ void tstbImageScaling_TextChanged(object sender, EventArgs e) } } } - - public class VersionCheckBody - { - public string tag_name { get; set; } - } } diff --git a/Gui/VersionCheckBody.cs b/Gui/VersionCheckBody.cs new file mode 100644 index 00000000..14d1ea74 --- /dev/null +++ b/Gui/VersionCheckBody.cs @@ -0,0 +1,4 @@ +namespace OpenLoco.ObjectEditor.Gui +{ + public record VersionCheckBody(string TagName); +}