Skip to content

Commit 99140ff

Browse files
2 parents 7471c21 + b6dbd39 commit 99140ff

File tree

5 files changed

+93
-67
lines changed

5 files changed

+93
-67
lines changed

ESPSharp GUI/DockableForms/LoadListWindow.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,10 @@ public LoadListWindow()
2626
/// </summary>
2727
private void ReadPluginFiles()
2828
{
29-
using (var reader = new StreamReader(Util.AllPluginsPath))
30-
{
31-
while (reader.Peek() >= 0)
32-
{
33-
var pluginName = reader.ReadLine();
34-
if (pluginName == null) continue;
35-
if (pluginName.EndsWith(".esp") || pluginName.EndsWith(".esm"))
36-
lvPluginList.Items.Add(pluginName);
37-
}
38-
}
39-
using (var reader = new StreamReader(Util.LoadedPluginsPath))
40-
{
41-
while (reader.Peek() >= 0)
42-
{
43-
var pluginName = reader.ReadLine();
44-
if (pluginName == null) continue;
45-
if (pluginName.EndsWith(".esp") || pluginName.EndsWith(".esm"))
46-
lvPluginList.FindItemWithText(pluginName).Checked = true;
47-
}
48-
}
29+
foreach (var plugin in Settings.AllPlugins)
30+
lvPluginList.Items.Add(Path.GetFileName(plugin));
31+
foreach (var plugin in Settings.ActivePlugins)
32+
lvPluginList.FindItemWithText(plugin).Checked = true;
4933
}
5034

5135
/// <summary>
@@ -57,8 +41,11 @@ private async void buttonOK_Click(object sender, EventArgs e)
5741
{
5842
_instance.Hide();
5943

60-
// Build paths using the local data directory and the known plugin names.
61-
var paths = (from ListViewItem item in lvPluginList.Items where item.Checked select Path.Combine(Util.DataPath, item.Text)).ToArray();
44+
// Build paths using the local data directory and the known plugin names.
45+
var paths = (from ListViewItem item
46+
in lvPluginList.Items
47+
where item.Checked
48+
select Path.Combine(Settings.DataPath, item.Text)).ToArray();
6249

6350
var progress = new Progress<string>(update =>
6451
{

ESPSharp GUI/ESPSharp GUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<Compile Include="Program.cs" />
160160
<Compile Include="Properties\AssemblyInfo.cs" />
161161
<Compile Include="Utilities\PluginData.cs" />
162+
<Compile Include="Utilities\Settings.cs" />
162163
<Compile Include="Utilities\Util.cs" />
163164
<EmbeddedResource Include="Controls\ButtonTextBox.resx">
164165
<DependentUpon>ButtonTextBox.cs</DependentUpon>

ESPSharp GUI/Utilities/PluginData.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public static void OpenPlugins(string[] files, IProgress<string> progress)
2525
Plugins = new List<ElderScrollsPlugin>();
2626
ElderScrollsPlugin.Clear();
2727

28-
ElderScrollsPlugin.pluginLocations.Add(new KeyValuePair<string, bool>(Util.DataPath, false));
29-
ElderScrollsPlugin.pluginLocations.Add(new KeyValuePair<string, bool>(Util.MOPath, true));
28+
ElderScrollsPlugin.pluginLocations.Add(new KeyValuePair<string, bool>(Settings.DataPath, false));
3029

3130
foreach (var file in files)
3231
{

ESPSharp GUI/Utilities/Settings.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
using System.Windows.Forms;
8+
9+
namespace ESPSharp_GUI.Utilities
10+
{
11+
public static class Settings
12+
{
13+
public static List<string> AllPlugins
14+
{
15+
get
16+
{
17+
return Directory.EnumerateFiles(DataPath)
18+
.Where(f => Path.GetExtension(f).ToLower() == ".esm" || Path.GetExtension(f).ToLower() == ".esp")
19+
.OrderBy(file => new FileInfo(file).LastWriteTime)
20+
.ToList();
21+
}
22+
}
23+
24+
public static List<string> ActivePlugins
25+
{
26+
get
27+
{
28+
using (FileStream stream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FalloutNV", "plugins.txt"), FileMode.Open, FileAccess.Read))
29+
using (StreamReader reader = new StreamReader(stream))
30+
{
31+
List<string> activePlugins = new List<string>();
32+
string line;
33+
do
34+
{
35+
line = reader.ReadLine();
36+
if (line == null)
37+
break;
38+
activePlugins.Add(line);
39+
}
40+
while (line != "" && !reader.EndOfStream);
41+
return activePlugins;
42+
}
43+
}
44+
}
45+
46+
public static string DataPath
47+
{
48+
get
49+
{
50+
return Path.Combine(Util.GamePath, "Data");
51+
}
52+
}
53+
}
54+
}

ESPSharp GUI/Utilities/Util.cs

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,33 @@ public class Util
1010
{
1111
public static string CurrentPath = Application.ExecutablePath;
1212

13-
//public static string AllPluginsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Fallout4", "loadorder.txt");
14-
15-
16-
//public static string LoadedPluginsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
17-
// "Fallout4", "plugins.txt");
18-
19-
// Because ModOrganizer keeps them in different locations
20-
public static string AllPluginsPath =
21-
@"G:\Games\Steam\steamapps\common\fallout new vegas\ModOrganizer\profiles\New Vegas\loadorder.txt";
22-
23-
public static string LoadedPluginsPath =
24-
@"G:\Games\Steam\steamapps\common\fallout new vegas\ModOrganizer\profiles\New Vegas\plugins.txt";
25-
26-
public static string DataPath = @"G:\Games\Steam\steamapps\common\fallout new vegas\Data";
27-
28-
public static string MOPath = @"G:\Games\Steam\steamapps\common\fallout new vegas\ModOrganizer\mods";
29-
30-
public RegistryKey GetBethKey()
31-
{
32-
using (var bethKey =
33-
Registry.LocalMachine.OpenSubKey(
34-
//determine software reg path (depends on architecture)
35-
Environment.Is64BitOperatingSystem ? "Software\\Wow6432Node" : "Software", RegistryKeyPermissionCheck.ReadWriteSubTree))
36-
//create or retrieve BethSoft path
37-
{
38-
Debug.Assert(bethKey != null, "bethKey != null");
39-
return bethKey.CreateSubKey("Bethesda Softworks", RegistryKeyPermissionCheck.ReadWriteSubTree);
40-
}
41-
}
42-
43-
public string GetPathFromKey(string keyName)
44-
{
45-
using (var bethKey = GetBethKey())
46-
using (var subKey = bethKey.CreateSubKey(keyName))
47-
{
48-
Debug.Assert(subKey != null, "subKey != null");
49-
return subKey.GetValue("Installed Path", "").ToString();
50-
}
51-
}
52-
53-
54-
55-
13+
public static RegistryKey BethesdaRegKey
14+
{
15+
get
16+
{
17+
using (var bethKey =
18+
Registry.LocalMachine.OpenSubKey(
19+
//determine software reg path (depends on architecture)
20+
Environment.Is64BitOperatingSystem ? "Software\\Wow6432Node" : "Software", RegistryKeyPermissionCheck.ReadWriteSubTree))
21+
//create or retrieve BethSoft path
22+
{
23+
Debug.Assert(bethKey != null, "bethKey != null");
24+
return bethKey.CreateSubKey("Bethesda Softworks", RegistryKeyPermissionCheck.ReadWriteSubTree);
25+
}
26+
}
27+
}
28+
29+
public static string GamePath
30+
{
31+
get
32+
{
33+
using (BethesdaRegKey)
34+
using (var subKey = BethesdaRegKey.CreateSubKey("falloutnv"))
35+
{
36+
Debug.Assert(subKey != null, "subKey != null");
37+
return subKey.GetValue("Installed Path", "").ToString();
38+
}
39+
}
40+
}
5641
}
5742
}

0 commit comments

Comments
 (0)