private void button2_Click(object sender, EventArgs e) { string s = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath", ""); if (s == "") { s = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", ""); } if (s != "") { if (Directory.Exists(s + "/steamapps/common/SpaceEngineers")) { MessageBox.Show("Detected SE game directory at: " + s + "\\steamapps\\common\\SpaceEngineers"); SaveDir(s + "/steamapps/common/SpaceEngineers"); } else { AcfReader acf = new AcfReader(s + "/steamapps/libraryfolders.vdf"); acf.CheckIntegrity(); ACF_Struct acfStruct = acf.ACFFileToStruct(); var folders = acfStruct.SubACF.Values.First().SubACF; foreach (var folder in folders) { foreach (var subItem in folder.Value.SubItems) { if (Directory.Exists(subItem.Value + "/steamapps/common/SpaceEngineers")) { MessageBox.Show("Detected SE game directory at: " + subItem.Value + "\\steamapps\\common\\SpaceEngineers"); SaveDir(subItem.Value + "/steamapps/common/SpaceEngineers"); break; } } } } return; } else { MessageBox.Show("Couldnt detect steam directory, set SE location manually"); } folderBrowserDialog1.ShowDialog(); SaveDir(folderBrowserDialog1.SelectedPath); }
private ACF_Struct ACFFileToStruct(string RegionToReadIn) { ACF_Struct ACF = new ACF_Struct(); int LengthOfRegion = RegionToReadIn.Length; int CurrentPos = 0; while (LengthOfRegion > CurrentPos) { int FirstItemStart = RegionToReadIn.IndexOf('"', CurrentPos); if (FirstItemStart == -1) { break; } int FirstItemEnd = RegionToReadIn.IndexOf('"', FirstItemStart + 1); CurrentPos = FirstItemEnd + 1; string FirstItem = RegionToReadIn.Substring(FirstItemStart + 1, FirstItemEnd - FirstItemStart - 1); int SecondItemStartQuote = RegionToReadIn.IndexOf('"', CurrentPos); int SecondItemStartBraceleft = RegionToReadIn.IndexOf('{', CurrentPos); if (SecondItemStartBraceleft == -1 || SecondItemStartQuote < SecondItemStartBraceleft) { int SecondItemEndQuote = RegionToReadIn.IndexOf('"', SecondItemStartQuote + 1); string SecondItem = RegionToReadIn.Substring(SecondItemStartQuote + 1, SecondItemEndQuote - SecondItemStartQuote - 1); CurrentPos = SecondItemEndQuote + 1; ACF.SubItems.Add(FirstItem, SecondItem); } else { int SecondItemEndBraceright = RegionToReadIn.NextEndOf('{', '}', SecondItemStartBraceleft + 1); ACF_Struct ACFS = ACFFileToStruct(RegionToReadIn.Substring(SecondItemStartBraceleft + 1, SecondItemEndBraceright - SecondItemStartBraceleft - 1)); CurrentPos = SecondItemEndBraceright + 1; ACF.SubACF.Add(FirstItem, ACFS); } } return(ACF); }