Skip to content

Commit 4701a21

Browse files
committed
cleanup code warnings
1 parent 01394a3 commit 4701a21

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

Core/Objects/Vehicle/VehicleObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)
256256

257257
// driving/start sounds
258258
StartSounds.Clear();
259-
var mask = 127;
259+
const int mask = 127;
260260
var count = NumStartSounds & mask;
261261
for (var i = 0; i < count; ++i)
262262
{

Core/Types/G1Dat.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public bool TryGetImageName(int id, out string? value)
1717
? BaseImageIdNameMap.TryGetValue(id, out value)
1818
: (IsSteamG1 ? SteamImageIdNameMap : OtherImageIdNameMap).TryGetValue(id, out value);
1919

20-
public static Dictionary<int, string> BaseImageIdNameMap = new()
20+
static readonly Dictionary<int, string> BaseImageIdNameMap = new()
2121
{
2222
{ 304, "default_palette" },
2323

@@ -2147,7 +2147,7 @@ public bool TryGetImageName(int id, out string? value)
21472147
{ 3549, "title_menu_lesson_l" },
21482148
};
21492149

2150-
public static Dictionary<int, string> SteamImageIdNameMap = new()
2150+
static readonly Dictionary<int, string> SteamImageIdNameMap = new()
21512151
{
21522152
{ 3550, "title_menu_globe_spin_0" },
21532153
{ 3551, "title_menu_globe_spin_1" },
@@ -2228,7 +2228,7 @@ public bool TryGetImageName(int id, out string? value)
22282228
{ 3628, "owner_jailed" },
22292229
};
22302230

2231-
public static Dictionary<int, string> OtherImageIdNameMap = new()
2231+
static readonly Dictionary<int, string> OtherImageIdNameMap = new()
22322232
{
22332233
// steam G1.dat doesn't have these 2
22342234
{ 3550, "title_menu_lesson_a" },

Gui/MainForm.cs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace OpenLoco.ObjectEditor.Gui
2121
public partial class MainForm : Form
2222
{
2323
readonly MainFormModel model;
24+
#pragma warning disable CA1859 // Use concrete types when possible for improved performance
2425
readonly ILogger logger;
26+
#pragma warning restore CA1859 // Use concrete types when possible for improved performance
2527

2628
public IUiObject? CurrentUIObject
2729
{
@@ -85,10 +87,10 @@ int CurrentUIImagePageNumber
8587
const string GithubLatestReleaseDownloadPage = "https://github.com/OpenLoco/ObjectEditor/releases";
8688
const string GithubLatestReleaseAPI = "https://api.github.com/repos/OpenLoco/ObjectEditor/releases/latest";
8789

88-
string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName);
89-
string SettingsFile => Path.Combine(SettingsPath, "settings.json");
90+
static string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName);
91+
static string SettingsFile => Path.Combine(SettingsPath, "settings.json");
9092

91-
Version ApplicationVersion;
93+
readonly Version ApplicationVersion;
9294

9395
public MainForm()
9496
{
@@ -100,7 +102,7 @@ public MainForm()
100102
};
101103

102104
var assembly = Assembly.GetExecutingAssembly();
103-
var paletteFilename = "Gui.palette.png";
105+
const string paletteFilename = "Gui.palette.png";
104106
using (var stream = assembly.GetManifestResourceStream(paletteFilename))
105107
{
106108
//var paletteBitmap = (Bitmap)Image.FromStream(stream!);
@@ -113,7 +115,7 @@ public MainForm()
113115
}
114116

115117
// grab current appl version from assembly
116-
var versionFilename = "Gui.version.txt";
118+
const string versionFilename = "Gui.version.txt";
117119
using (var stream = assembly.GetManifestResourceStream(versionFilename))
118120
{
119121
var buf = new byte[5];
@@ -145,27 +147,17 @@ Version GetLatestVersion()
145147
{
146148
var jsonResponse = response.Content.ReadAsStringAsync().Result;
147149
var body = JsonSerializer.Deserialize<VersionCheckBody>(jsonResponse);
148-
var tagName = body?.tag_name;
149-
var version = Version.Parse(tagName);
150-
return version;
150+
var tagName = body?.TagName;
151+
if (tagName != null)
152+
{
153+
return Version.Parse(tagName);
154+
}
151155
}
156+
157+
#pragma warning disable CA2201 // Do not raise reserved exception types
152158
throw new Exception("Unable to get latest version");
159+
#pragma warning restore CA2201 // Do not raise reserved exception types
153160
}
154-
//async Task<Version> GetLatestVersionAsync()
155-
//{
156-
// var client = new HttpClient();
157-
// client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("ObjectEditor", ApplicationVersion.ToString()));
158-
// var response = await client.GetAsync("https://api.github.com/repos/OpenLoco/ObjectEditor/releases/latest");
159-
// if (response.IsSuccessStatusCode)
160-
// {
161-
// var jsonResponse = await response.Content.ReadAsStringAsync();
162-
// var body = JsonSerializer.Deserialize<VersionCheckBody>(jsonResponse);
163-
// var tagName = body?.tag_name;
164-
// var version = Version.Parse(tagName);
165-
// return version;
166-
// }
167-
// throw new Exception("Unable to get latest version");
168-
//}
169161

170162
void MainForm_Load(object sender, EventArgs e)
171163
{
@@ -352,7 +344,7 @@ void InitDataCategoryTree()
352344
// sound effects
353345
//foreach (var sfx in model.SoundEffects)
354346
{
355-
var displayName = OriginalDataFiles.SoundEffect;
347+
const string displayName = OriginalDataFiles.SoundEffect;
356348
_ = sfxNode.Nodes.Add(displayName, displayName, 1, 1);
357349
}
358350

@@ -1498,9 +1490,4 @@ void tstbImageScaling_TextChanged(object sender, EventArgs e)
14981490
}
14991491
}
15001492
}
1501-
1502-
public class VersionCheckBody
1503-
{
1504-
public string tag_name { get; set; }
1505-
}
15061493
}

Gui/VersionCheckBody.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace OpenLoco.ObjectEditor.Gui
2+
{
3+
public record VersionCheckBody(string TagName);
4+
}

0 commit comments

Comments
 (0)