Changed to remove DI to optimise binary size

This commit is contained in:
Ray 2026-05-15 22:18:15 +01:00
parent b05e718993
commit 86344e34bf
3 changed files with 6 additions and 31 deletions

View File

@ -6,7 +6,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Extensions.DependencyInjection;
using RokettoLaunch.Models.SaveFile; using RokettoLaunch.Models.SaveFile;
using RokettoLaunch.Windows.Forms; using RokettoLaunch.Windows.Forms;
using RyzStudio; using RyzStudio;
@ -18,7 +17,6 @@ namespace RokettoLaunch
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
private readonly IServiceProvider _provider;
private readonly IFileSessionManager _fileSessionManager; private readonly IFileSessionManager _fileSessionManager;
private bool _isBusy = false; private bool _isBusy = false;
@ -30,22 +28,10 @@ namespace RokettoLaunch
InitializeComponent(); InitializeComponent();
this.AutoScaleMode = AutoScaleMode.None; this.AutoScaleMode = AutoScaleMode.None;
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
this.Text = Application.ProductName; this.Text = Application.ProductName;
this.CurrentSession = new App4Options(); _fileSessionManager = new FileSessionManager();
//#if DEBUG
//flowLayoutPanel1.BackColor = Color.LightGreen;
//#endif
notifyIcon1.Text = Application.ProductName;
}
public MainForm(IServiceProvider provider, IFileSessionManager fileSessionManager) : this()
{
_provider = provider;
_fileSessionManager = fileSessionManager;
_fileSessionManager.OpenFileDialog = openFileDialog1; _fileSessionManager.OpenFileDialog = openFileDialog1;
_fileSessionManager.SaveFileDialog = saveFileDialog1; _fileSessionManager.SaveFileDialog = saveFileDialog1;
_fileSessionManager.OnNewing += fileSessionManager_OnNewSession; _fileSessionManager.OnNewing += fileSessionManager_OnNewSession;
@ -53,6 +39,8 @@ namespace RokettoLaunch
_fileSessionManager.OnSaving += fileSessionManager_OnSaveSession; _fileSessionManager.OnSaving += fileSessionManager_OnSaveSession;
_fileSessionManager.OnClearing += fileSessionManager_OnClearSession; _fileSessionManager.OnClearing += fileSessionManager_OnClearSession;
_fileSessionManager.OnFilenameChanged += fileSessionManager_OnFilenameChanged; _fileSessionManager.OnFilenameChanged += fileSessionManager_OnFilenameChanged;
notifyIcon1.Text = Application.ProductName;
} }
protected async override void OnShown(EventArgs e) protected async override void OnShown(EventArgs e)
@ -435,8 +423,7 @@ namespace RokettoLaunch
private async Task<bool> fileSessionManager_OnLoadSession(FileSessionManager sender, string filename, int formatType) private async Task<bool> fileSessionManager_OnLoadSession(FileSessionManager sender, string filename, int formatType)
{ {
// Progress indicator var loadingForm = new LoadingForm();
var loadingForm = _provider.GetRequiredService<LoadingForm>();
var result = await loadingForm.ShowDialog(filename); var result = await loadingForm.ShowDialog(filename);
if (result != DialogResult.OK) if (result != DialogResult.OK)
{ {

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Extensions.DependencyInjection;
using RyzStudio.Windows.Forms;
namespace RokettoLaunch namespace RokettoLaunch
{ {
@ -13,19 +11,10 @@ namespace RokettoLaunch
[STAThread] [STAThread]
static void Main() static void Main()
{ {
var services = new ServiceCollection();
services.AddSingleton<IFileSessionManager, FileSessionManager>();
services.AddTransient<MainForm>();
services.AddTransient<LoadingForm>();
var provider = services.BuildServiceProvider();
Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new MainForm()); Application.Run(new MainForm());
Application.Run(provider.GetRequiredService<MainForm>());
} }
} }
} }

View File

@ -79,7 +79,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
<PackageReference Include="RyzStudio" Version="10.1.0.128" /> <PackageReference Include="RyzStudio" Version="10.1.0.128" />
<PackageReference Include="RyzStudio.Windows.Forms" Version="10.1.0.140" /> <PackageReference Include="RyzStudio.Windows.Forms" Version="10.1.0.140" />
</ItemGroup> </ItemGroup>