Skip to content

Commit a0e154c

Browse files
Merge pull request #32 from mstew20/Windows
Moved magic strings to appsettings
2 parents 5083b71 + f4e4155 commit a0e154c

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

src/HyperMC/HyperMcView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public HyperMcView(IForgeClient forgeClient, IServiceProvider provider, IFileMan
4545
private async void HyperMcView_Load(object sender, EventArgs e)
4646
{
4747
SetView(new ControlView(pnl_MainArea));
48-
var mods = await _fileManager.ReadFile<ModpackData[]>($@"{_settings.ModPacksPath}\packs.json");
48+
var mods = await _fileManager.ReadFile<ModpackData[]>(_settings.ModPacksFile);
4949
if (mods != null)
5050
{
5151
foreach (var mod in mods)
@@ -126,7 +126,7 @@ private async void ModpacksUpdated(object? sender, NotifyCollectionChangedEventA
126126
}
127127

128128
SortModpacks();
129-
await _fileManager.WriteToFile(_modpacks.ToArray(), $@"{_settings.ModPacksPath}\packs.json");
129+
await _fileManager.WriteToFile(_modpacks.ToArray(), _settings.ModPacksFile);
130130
}
131131

132132
private ModpackBox CreateModpackBox(ModpackData data)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 class ApplicationSettings
10+
{
11+
public AppSettings AppSettings { get; set; }
12+
}
13+
14+
public class AppSettings
15+
{
16+
public string AppPath { get; set; }
17+
public string DeafultMinecraftPath { get; set; }
18+
public string ModPacksFile { get; set; }
19+
public string DefaultModPacksPath { get; set; }
20+
public string SettingsFile { get; set; }
21+
}
22+
}

src/HyperMC/Settings/IUserSettings.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace Hypermc.Settings
88
{
99
public interface IUserSettings
1010
{
11-
string MinecraftPath { get; set; }
12-
string ModPacksPath { get; set; }
11+
string MinecraftPath { get; }
12+
string ModPacksPath { get; }
13+
string ModPacksFile { get; }
1314

1415
Task Initialize();
1516
}

src/HyperMC/Settings/UserSettings.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Hypermc.Services;
2+
using Microsoft.Extensions.Configuration;
23
using System;
34
using System.Collections.Generic;
45
using System.IO;
56
using System.Linq;
67
using System.Text;
78
using System.Text.Json;
89
using System.Threading.Tasks;
10+
using System.Windows.Forms;
911

1012
namespace Hypermc.Settings
1113
{
@@ -15,18 +17,21 @@ public class UserSettings : IUserSettings
1517
private readonly string _settingsFile;
1618
private readonly IFileManager _fileManager;
1719

18-
public string MinecraftPath { get; set; }
19-
public string ModPacksPath { get; set; }
20+
public string MinecraftPath { get; private set; }
21+
public string ModPacksPath { get; private set; }
22+
public string ModPacksFile { get; }
2023

21-
public UserSettings(IFileManager fileManager)
24+
public UserSettings(IFileManager fileManager, IConfiguration config)
2225
{
23-
// TODO: possibly move the file names to the appsettings.
24-
_appPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\.hypermc";
25-
_settingsFile = $@"{_appPath}\settings.json";
26+
var settings = config.Get<ApplicationSettings>().AppSettings;
27+
_appPath = string.Format(settings.AppPath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
28+
_settingsFile = string.Format(settings.SettingsFile, _appPath);
29+
2630
_fileManager = fileManager;
2731

28-
MinecraftPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\.minecraft";
29-
ModPacksPath = $@"{MinecraftPath}\ModPacks";
32+
MinecraftPath = string.Format(settings.DeafultMinecraftPath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
33+
ModPacksPath = string.Format(settings.DefaultModPacksPath, MinecraftPath);
34+
ModPacksFile = string.Format(settings.ModPacksFile, ModPacksPath);
3035
}
3136

3237
public async Task Initialize()

src/HyperMC/UI/Views/SettingView.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public partial class SettingView : Form, IView
1818

1919
public SettingView(IUserSettings settings)
2020
{
21-
string env_flder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
22-
string mc_flder = $"{env_flder}\\.minecraft";
23-
//game_path.Text = $"{mc_flder}";
24-
2521
InitializeComponent();
2622
_settings = settings;
2723
game_path.Text = settings.MinecraftPath;

src/HyperMC/appsettings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"test": 15
2+
"AppSettings": {
3+
"AppPath": "{0}\\.hypermc",
4+
"DeafultMinecraftPath": "{0}\\.minecraft",
5+
"DefaultModPacksPath": "{0}\\ModPacks",
6+
"ModPacksFile": "{0}\\packs.json",
7+
"SettingsFile": "{0}\\settings.json"
8+
}
39
}

0 commit comments

Comments
 (0)