-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
97 lines (87 loc) · 2.72 KB
/
Form1.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
88
89
90
91
92
93
94
95
96
97
using Microsoft.Win32;
namespace SongAnalyser
{
public partial class Form1 : Form
{
public Results ExistingResults;
public static string path = "";
public Form1()
{
InitializeComponent();
}
private void btnAnalyse_Click(object sender, EventArgs e)
{
path = tbPath.Text;
if(Directory.Exists(path))
{
if(ExistingResults == null)
{
Results results = new(this);
results.Show();
}
else
{
ExistingResults.Show();
ExistingResults.btnRefresh_Click(null, null);
}
Hide();
}
else
{
MessageBox.Show("Path does not exist");
}
}
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey? steamKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Valve\\Steam");
if(steamKey == null)
{
steamKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Valve\\Steam");
if(steamKey == null)
{
return;
}
}
object? o = steamKey.GetValue("InstallPath");
if(o == null)
{
return;
}
string? installPath = o as string; // where steam.exe is
string vdfFile = installPath + "/steamapps/libraryfolders.vdf";
if(!File.Exists(vdfFile))
{
return;
}
List<string> lines = new();
string path = "";
foreach(string line in File.ReadLines(vdfFile))
{
lines.Add(line);
// we have beat saber
if(line.Contains("\"620980\""))
{
// traverse lines backwards
for(int i = lines.Count - 1; i >= 0; i--)
{
if (lines[i].Contains("path"))
{
// same as lines[i].Substring(11, lines[i].Length - 12)
path = lines[i][11..^1] + "/steamapps/common/Beat Saber/Beat Saber_Data/CustomLevels";
break;
}
}
break;
}
}
tbPath.Text = path;
}
private void tbPath_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
btnAnalyse_Click(sender, e);
}
}
}
}