-
Notifications
You must be signed in to change notification settings - Fork 29
/
ME2Directory.cs
87 lines (79 loc) · 3.07 KB
/
ME2Directory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using UsefulThings;
namespace ME3Explorer
{
public static class ME2Directory
{
private static string _gamePath;
public static string gamePath
{
get
{
if (_gamePath == null)
return null;
return Path.GetFullPath(_gamePath); //normalize
}
set
{
if (value != null)
{
if (value.Contains("BioGame", StringComparison.OrdinalIgnoreCase))
value = value.Substring(0, value.LastIndexOf("BioGame", StringComparison.OrdinalIgnoreCase));
}
_gamePath = value;
}
}
public static string BioGamePath => gamePath != null ? gamePath.Contains("biogame", StringComparison.OrdinalIgnoreCase) ? gamePath : Path.Combine(gamePath, @"BioGame\") : null;
public static string cookedPath => gamePath != null ? Path.Combine(gamePath, @"BioGame\CookedPC\") : "Not Found";
public static string DLCPath => gamePath != null ? Path.Combine(gamePath, @"BioGame\DLC\") : "Not Found";
// "C:\...\MyDocuments\BioWare\Mass Effect 2\" folder
public static string BioWareDocPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), @"\BioWare\Mass Effect 2\");
public static string GamerSettingsIniFile => BioWareDocPath + @"BIOGame\Config\GamerSettings.ini";
public static string DLCFilePath(string DLCName)
{
string fullPath = DLCPath + DLCName + @"\CookedPC";
if (File.Exists(fullPath))
return fullPath;
else
throw new FileNotFoundException("Invalid DLC path " + fullPath);
}
static ME2Directory()
{
if (!string.IsNullOrEmpty(Properties.Settings.Default.ME2Directory))
{
gamePath = Properties.Settings.Default.ME2Directory;
}
else
{
string hkey32 = @"HKEY_LOCAL_MACHINE\SOFTWARE\";
string hkey64 = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\";
string subkey = @"BioWare\Mass Effect 2";
string keyName = hkey32 + subkey;
string test = (string)Microsoft.Win32.Registry.GetValue(keyName, "Path", null);
if (test != null)
{
gamePath = test;
return;
}
/*if (gamePath != null)
{
gamePath = gamePath + "\\";
return;
}*/
keyName = hkey64 + subkey;
gamePath = (string)Microsoft.Win32.Registry.GetValue(keyName, "Path", null);
if (gamePath != null)
{
gamePath = gamePath + "\\";
return;
}
}
}
}
}