Skip to content

Commit 9e7cb8c

Browse files
authored
Feature user settings (#5)
* created basic user settings to store and maintain throughout the application * Implemented the current user settings into the SettingView * added todo item in the initialize of the settings
1 parent 76afd9e commit 9e7cb8c

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed

src/HyperMC/HyperMcView.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
using Hypermc.UI.Views;
1717
using Hypermc.Utility;
1818
using HyperMC.CurseForge;
19+
using Microsoft.Extensions.DependencyInjection;
1920

2021
namespace Hypermc
2122
{
2223
public partial class HyperMcView : Form, IViewHost
2324
{
2425

2526
private readonly IForgeClient _forgeClient;
27+
private readonly IServiceProvider _provider;
2628

27-
public HyperMcView(IForgeClient forgeClient)
29+
public HyperMcView(IForgeClient forgeClient, IServiceProvider provider)
2830
{
2931
InitializeComponent();
3032

3133
_forgeClient = forgeClient;
34+
_provider = provider;
3235
_modpacks = new();
3336
_modpacks.CollectionChanged += ModpacksUpdated;
3437
}
@@ -181,7 +184,7 @@ private void Hbtn_Minimize_Click(object sender, EventArgs e)
181184
private void Hbtn_Options_Click(object sender, EventArgs e)
182185
{
183186
//Utils.NotImplAlert("Options Menu");
184-
SetView(new SettingView());
187+
SetView(_provider.GetRequiredService<SettingView>());
185188
}
186189

187190
#endregion Minimize Button

src/HyperMC/Program.cs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Hypermc.Settings;
2+
using Hypermc.UI.Views;
13
using Microsoft.Extensions.DependencyInjection;
24
using System;
35
using System.Collections.Generic;
@@ -7,31 +9,36 @@
79

810
namespace Hypermc
911
{
10-
static class Program
11-
{
12-
private static IServiceProvider Provider;
13-
/// <summary>
14-
/// The main entry point for the application.
15-
/// </summary>
16-
[STAThread]
17-
static void Main()
18-
{
19-
Provider = ConfigureService();
12+
static class Program
13+
{
14+
private static IServiceProvider Provider;
15+
/// <summary>
16+
/// The main entry point for the application.
17+
/// </summary>
18+
[STAThread]
19+
static void Main()
20+
{
21+
Provider = ConfigureService();
22+
Provider.GetRequiredService<IUserSettings>().Initialize();
2023

21-
Application.SetHighDpiMode(HighDpiMode.SystemAware);
22-
Application.EnableVisualStyles();
23-
Application.SetCompatibleTextRenderingDefault(false);
24-
Application.Run(Provider.GetRequiredService<HyperMcView>());
25-
}
24+
Application.SetHighDpiMode(HighDpiMode.SystemAware);
25+
Application.EnableVisualStyles();
26+
Application.SetCompatibleTextRenderingDefault(false);
27+
Application.Run(Provider.GetRequiredService<HyperMcView>());
28+
}
2629

27-
private static IServiceProvider ConfigureService()
28-
{
29-
IServiceCollection services = new ServiceCollection();
30+
private static IServiceProvider ConfigureService()
31+
{
32+
IServiceCollection services = new ServiceCollection();
3033

31-
services.AddSingleton<HyperMcView>();
32-
services.AddForgeClient();
34+
services.AddSingleton<HyperMcView>()
35+
.AddSingleton<IUserSettings, UserSettings>();
3336

34-
return services.BuildServiceProvider();
35-
}
36-
}
37+
services.AddTransient<SettingView>();
38+
39+
services.AddForgeClient();
40+
41+
return services.BuildServiceProvider();
42+
}
43+
}
3744
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Hypermc.Settings
8+
{
9+
public interface IUserSettings
10+
{
11+
string MinecraftPath { get; set; }
12+
13+
void Initialize();
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Hypermc.Settings
9+
{
10+
public class UserSettings : IUserSettings
11+
{
12+
public string MinecraftPath { get; set; } = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\.minecraft";
13+
14+
// TODO: intialize settings by getting the users saved settings for this application
15+
public void Initialize()
16+
{
17+
18+
}
19+
}
20+
}

src/HyperMC/UI/Views/SettingView.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@
77
using System.Text;
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
10+
using Hypermc.Settings;
1011
using Hypermc.Utility;
1112

1213
namespace Hypermc.UI.Views
1314
{
1415
public partial class SettingView : Form, IView
1516
{
16-
public SettingView()
17+
private readonly IUserSettings _settings;
18+
19+
public SettingView(IUserSettings settings)
1720
{
1821
string env_flder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
1922
string mc_flder = $"{env_flder}\\.minecraft";
2023
//game_path.Text = $"{mc_flder}";
2124

2225
InitializeComponent();
23-
}
26+
_settings = settings;
27+
game_path.Text = settings.MinecraftPath;
28+
}
2429

2530
public event IView.ViewMessageCallback OnMessage;
2631

0 commit comments

Comments
 (0)