Skip to content

Commit

Permalink
cleanup code warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LeftofZen committed Apr 8, 2024
1 parent 01394a3 commit 4701a21
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Core/Objects/Vehicle/VehicleObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)

// driving/start sounds
StartSounds.Clear();
var mask = 127;
const int mask = 127;
var count = NumStartSounds & mask;
for (var i = 0; i < count; ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions Core/Types/G1Dat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string> BaseImageIdNameMap = new()
static readonly Dictionary<int, string> BaseImageIdNameMap = new()
{
{ 304, "default_palette" },

Expand Down Expand Up @@ -2147,7 +2147,7 @@ public bool TryGetImageName(int id, out string? value)
{ 3549, "title_menu_lesson_l" },
};

public static Dictionary<int, string> SteamImageIdNameMap = new()
static readonly Dictionary<int, string> SteamImageIdNameMap = new()
{
{ 3550, "title_menu_globe_spin_0" },
{ 3551, "title_menu_globe_spin_1" },
Expand Down Expand Up @@ -2228,7 +2228,7 @@ public bool TryGetImageName(int id, out string? value)
{ 3628, "owner_jailed" },
};

public static Dictionary<int, string> OtherImageIdNameMap = new()
static readonly Dictionary<int, string> OtherImageIdNameMap = new()
{
// steam G1.dat doesn't have these 2
{ 3550, "title_menu_lesson_a" },
Expand Down
45 changes: 16 additions & 29 deletions Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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!);
Expand All @@ -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];
Expand Down Expand Up @@ -145,27 +147,17 @@ Version GetLatestVersion()
{
var jsonResponse = response.Content.ReadAsStringAsync().Result;
var body = JsonSerializer.Deserialize<VersionCheckBody>(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<Version> 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<VersionCheckBody>(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)
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1498,9 +1490,4 @@ void tstbImageScaling_TextChanged(object sender, EventArgs e)
}
}
}

public class VersionCheckBody
{
public string tag_name { get; set; }
}
}
4 changes: 4 additions & 0 deletions Gui/VersionCheckBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace OpenLoco.ObjectEditor.Gui
{
public record VersionCheckBody(string TagName);
}

0 comments on commit 4701a21

Please sign in to comment.