Skip to content

Commit 6fa5eed

Browse files
committed
fix: Remove unnecessary Windows.Forms usage
1 parent f4ac1a5 commit 6fa5eed

File tree

10 files changed

+32
-29
lines changed

10 files changed

+32
-29
lines changed

Source/ContentChecker/ContentChecker.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<TargetFrameworks Condition="'$(BuildDotNet)' == 'true'">net6-windows</TargetFrameworks>
44
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472</TargetFrameworks>
55
<OutputType>Exe</OutputType>
6-
<UseWindowsForms>true</UseWindowsForms>
7-
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
86
<IsPublishable>False</IsPublishable>
97
<AssemblyTitle>Open Rails Content Checker</AssemblyTitle>
108
<Description>Open Rails Transport Simulator</Description>

Source/ContentChecker/Loader.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
using System.Linq;
4444
using System.Text;
4545
using Microsoft.Xna.Framework.Graphics;
46-
using System.Windows.Forms;
4746

4847
namespace ContentChecker
4948
{
@@ -70,7 +69,7 @@ abstract class Loader
7069
/// <summary> The number of files that were actually loaded </summary>
7170
public int FilesLoaded { get; protected set; }
7271
/// <summary> The number of files that were not loaded but skipped </summary>
73-
public int FilesSkipped {get; protected set;}
72+
public int FilesSkipped { get; protected set; }
7473

7574
/// <summary> The action to take when an additonal file has been identified. This is intended to be set externally </summary>
7675
protected Action<string, Loader> AddAdditionalFileAction { get; set; }
@@ -158,17 +157,13 @@ protected static GraphicsDevice GetGraphicsDevice()
158157
{
159158
if (_graphicsDevice == null)
160159
{
161-
// We use a Windows.Forms Control instead of an xna GAME because it is much easier to use.
162-
var _c = new Control();
163-
164160
// Details probably do not matter too much
165161
PresentationParameters parameters = new PresentationParameters()
166162
{
167163
BackBufferWidth = 100,
168164
BackBufferHeight = 100,
169165
BackBufferFormat = SurfaceFormat.Color,
170166
//DepthStencilFormat = DepthFormat.Depth24,
171-
DeviceWindowHandle = _c.Handle,
172167
PresentationInterval = PresentInterval.Immediate,
173168
IsFullScreen = false,
174169
};

Source/Contrib/SimulatorTester/SimulatorTester.csproj

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
<RootNamespace>Orts.SimulatorTester</RootNamespace>
77
<AssemblyName>Contrib.SimulatorTester</AssemblyName>
88
<ApplicationIcon>..\..\ORTS.ico</ApplicationIcon>
9-
<UseWindowsForms>true</UseWindowsForms>
10-
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
11-
<OutputPath>..\..\..\Program\</OutputPath>
129
<IsPublishable>False</IsPublishable>
1310
<AssemblyTitle>Open Rails Simulator Tester (Contributed)</AssemblyTitle>
1411
<Description>Open Rails Transport Simulator</Description>

Source/ORTS.Common/ORTS.Common.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<TargetFrameworks Condition="'$(BuildDotNet)' == 'true'">net6-windows</TargetFrameworks>
44
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472</TargetFrameworks>
55
<OutputType>Library</OutputType>
6-
<UseWindowsForms>true</UseWindowsForms>
7-
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
86
<IsPublishable>False</IsPublishable>
97
<AssemblyTitle>Open Rails Common Library</AssemblyTitle>
108
<Description>Open Rails Transport Simulator</Description>

Source/ORTS.Common/SystemInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static SystemInfo()
4040
{
4141
Application = new Platform
4242
{
43-
Name = System.Windows.Forms.Application.ProductName,
43+
Name = ApplicationInfo.ProductName,
4444
Version = VersionInfo.VersionOrBuild,
4545
Architecture = RuntimeInformation.ProcessArchitecture.ToString(),
4646
};

Source/ORTS.Settings/ORTS.Settings.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472</TargetFrameworks>
55
<OutputType>Library</OutputType>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7-
<UseWindowsForms>true</UseWindowsForms>
8-
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
97
<IsPublishable>False</IsPublishable>
108
<AssemblyTitle>Open Rails Settings Library</AssemblyTitle>
119
<Description>Open Rails Transport Simulator</Description>

Source/ORTS.Settings/UserSettings.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using System.Reflection;
2323
using System.Security.Cryptography;
2424
using System.Text;
25-
using System.Windows.Forms;
2625
using ORTS.Common;
2726

2827
namespace ORTS.Settings
@@ -60,7 +59,7 @@ static UserSettings()
6059
else
6160
SettingsFilePath = null;
6261

63-
UserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName);
62+
UserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationInfo.ProductName);
6463
// TODO: If using INI file, move these to application directory as well.
6564
if (!Directory.Exists(UserDataFolder)) Directory.CreateDirectory(UserDataFolder);
6665
DeletedSaveFolder = Path.Combine(UserDataFolder, "Deleted Saves");
@@ -490,7 +489,7 @@ public UserSettings(IEnumerable<string> options)
490489
: base(SettingsStore.GetSettingStore(SettingsFilePath, RegistryKey, null))
491490
{
492491
CustomDefaultValues["LoggingPath"] = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
493-
CustomDefaultValues["ScreenshotPath"] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), Application.ProductName);
492+
CustomDefaultValues["ScreenshotPath"] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), ApplicationInfo.ProductName);
494493
CustomDefaultValues["Multiplayer_User"] = Environment.UserName;
495494
Load(options);
496495
Folders = new FolderSettings(options);

Source/ORTS.Updater/ORTS.Updater.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net472</TargetFrameworks>
55
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
66
<OutputType>Library</OutputType>
7-
<UseWindowsForms>true</UseWindowsForms>
8-
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
97
<IsPublishable>False</IsPublishable>
108
<AssemblyTitle>Open Rails Updater Library</AssemblyTitle>
119
<Description>Open Rails Transport Simulator</Description>

Source/ORTS.Updater/UpdateManager.cs

+21-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
using System.Security.Principal;
3434
using System.Text;
3535
using System.Threading;
36-
using System.Windows.Forms;
3736

3837
namespace ORTS.Updater
3938
{
@@ -50,6 +49,7 @@ public class UpdateManager
5049
const string TemporaryDirectoryName = "Open Rails Updater Temporary Files";
5150

5251
public event EventHandler<ProgressChangedEventArgs> ApplyProgressChanged;
52+
public event EventHandler<ProceedWithUpdateCheckEventArgs> ProceedWithUpdateCheck;
5353

5454
readonly string BasePath;
5555
readonly string ProductName;
@@ -463,14 +463,16 @@ void VerifyUpdate()
463463
var certificates = GetCertificatesFromFile(files[i]);
464464
if (!certificates.Any(c => IsMatchingCertificate(expectedCertificates, c)))
465465
{
466-
switch (MessageBox.Show("The downloaded update has no matching cryptographic certificates; proceed with update?\n\nCurrent version's certificates:\n\n" + FormatCertificateSubjectList(expectedCertificates) + "\n\nUpdate version's certificates:\n\n" + FormatCertificateSubjectList(certificates) + "\n\nProceed with update?", Application.ProductName + " " + VersionInfo.VersionOrBuild, MessageBoxButtons.YesNo))
466+
var args = new ProceedWithUpdateCheckEventArgs("The downloaded update has no matching cryptographic certificates; proceed with update?\n\nCurrent version's certificates:\n\n" + FormatCertificateSubjectList(expectedCertificates) + "\n\nUpdate version's certificates:\n\n" + FormatCertificateSubjectList(certificates) + "\n\nProceed with update?");
467+
ProceedWithUpdateCheck(this, args);
468+
if (args.Proceed)
467469
{
468-
case DialogResult.Yes:
469-
foreach (var cert in certificates)
470-
expectedCertificates.Add(cert);
471-
break;
472-
case DialogResult.No:
473-
throw new InvalidDataException("Cryptographic certificates don't match.\n\nCurrent certificates:\n\n" + FormatCertificateSubjectList(expectedCertificates) + "\n\nUpdate certificates:\n\n" + FormatCertificateSubjectList(certificates) + "\n");
470+
foreach (var cert in certificates)
471+
expectedCertificates.Add(cert);
472+
}
473+
else
474+
{
475+
throw new InvalidDataException("Cryptographic certificates don't match.\n\nCurrent certificates:\n\n" + FormatCertificateSubjectList(expectedCertificates) + "\n\nUpdate certificates:\n\n" + FormatCertificateSubjectList(certificates) + "\n");
474476
}
475477
}
476478
}
@@ -640,4 +642,15 @@ public class Update
640642
[JsonProperty]
641643
public string Version { get; private set; }
642644
}
645+
646+
public class ProceedWithUpdateCheckEventArgs
647+
{
648+
public string Message;
649+
public bool Proceed;
650+
651+
public ProceedWithUpdateCheckEventArgs(string message)
652+
{
653+
Message = message;
654+
}
655+
}
643656
}

Source/Updater/UpdaterProgress.cs

+7
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ void UpdaterThread()
128128
progressBarUpdater.Value = e.ProgressPercentage;
129129
}));
130130
};
131+
updateManager.ProceedWithUpdateCheck += (object sender, ProceedWithUpdateCheckEventArgs e) =>
132+
{
133+
Invoke((Action)(() =>
134+
{
135+
if (MessageBox.Show(e.Message, Application.ProductName + " " + VersionInfo.VersionOrBuild, MessageBoxButtons.YesNo) == DialogResult.Yes) e.Proceed = true;
136+
}));
137+
};
131138

132139
var channelName = Enumerable.FirstOrDefault(Environment.GetCommandLineArgs(), a => a.StartsWith(UpdateManager.ChannelCommandLine));
133140
if (channelName != null && channelName.Length > UpdateManager.ChannelCommandLine.Length)

0 commit comments

Comments
 (0)