@@ -21,7 +21,9 @@ namespace OpenLoco.ObjectEditor.Gui
21
21
public partial class MainForm : Form
22
22
{
23
23
readonly MainFormModel model ;
24
+ #pragma warning disable CA1859 // Use concrete types when possible for improved performance
24
25
readonly ILogger logger ;
26
+ #pragma warning restore CA1859 // Use concrete types when possible for improved performance
25
27
26
28
public IUiObject ? CurrentUIObject
27
29
{
@@ -85,10 +87,10 @@ int CurrentUIImagePageNumber
85
87
const string GithubLatestReleaseDownloadPage = "https://github.com/OpenLoco/ObjectEditor/releases" ;
86
88
const string GithubLatestReleaseAPI = "https://api.github.com/repos/OpenLoco/ObjectEditor/releases/latest" ;
87
89
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" ) ;
90
92
91
- Version ApplicationVersion ;
93
+ readonly Version ApplicationVersion ;
92
94
93
95
public MainForm ( )
94
96
{
@@ -100,7 +102,7 @@ public MainForm()
100
102
} ;
101
103
102
104
var assembly = Assembly . GetExecutingAssembly ( ) ;
103
- var paletteFilename = "Gui.palette.png" ;
105
+ const string paletteFilename = "Gui.palette.png" ;
104
106
using ( var stream = assembly . GetManifestResourceStream ( paletteFilename ) )
105
107
{
106
108
//var paletteBitmap = (Bitmap)Image.FromStream(stream!);
@@ -113,7 +115,7 @@ public MainForm()
113
115
}
114
116
115
117
// grab current appl version from assembly
116
- var versionFilename = "Gui.version.txt" ;
118
+ const string versionFilename = "Gui.version.txt" ;
117
119
using ( var stream = assembly . GetManifestResourceStream ( versionFilename ) )
118
120
{
119
121
var buf = new byte [ 5 ] ;
@@ -145,27 +147,17 @@ Version GetLatestVersion()
145
147
{
146
148
var jsonResponse = response . Content . ReadAsStringAsync ( ) . Result ;
147
149
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
+ }
151
155
}
156
+
157
+ #pragma warning disable CA2201 // Do not raise reserved exception types
152
158
throw new Exception ( "Unable to get latest version" ) ;
159
+ #pragma warning restore CA2201 // Do not raise reserved exception types
153
160
}
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
- //}
169
161
170
162
void MainForm_Load ( object sender , EventArgs e )
171
163
{
@@ -352,7 +344,7 @@ void InitDataCategoryTree()
352
344
// sound effects
353
345
//foreach (var sfx in model.SoundEffects)
354
346
{
355
- var displayName = OriginalDataFiles . SoundEffect ;
347
+ const string displayName = OriginalDataFiles . SoundEffect ;
356
348
_ = sfxNode . Nodes . Add ( displayName , displayName , 1 , 1 ) ;
357
349
}
358
350
@@ -1498,9 +1490,4 @@ void tstbImageScaling_TextChanged(object sender, EventArgs e)
1498
1490
}
1499
1491
}
1500
1492
}
1501
-
1502
- public class VersionCheckBody
1503
- {
1504
- public string tag_name { get ; set ; }
1505
- }
1506
1493
}
0 commit comments