Created
December 9, 2015 19:18
-
-
Save moritzuehling/abdb5ecf81496ba768d9 to your computer and use it in GitHub Desktop.
Finds the installation directory of CS:GO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string GetCSGODir() | |
{ | |
string steamPath = (string)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Valve\\Steam", "SteamPath", ""); | |
string pathsFile = Path.Combine(steamPath, "steamapps", "libraryfolders.vdf"); | |
if (!File.Exists(pathsFile)) | |
return null; | |
List<string> libraries = new List<string>(); | |
libraries.Add(Path.Combine(steamPath)); | |
var pathVDF = File.ReadAllLines(pathsFile); | |
// Okay, this is not a full vdf-parser, but it seems to work pretty much, since the | |
// vdf-grammar is pretty easy. Hopefully it never breaks. I'm too lazy to write a full vdf-parser though. | |
Regex pathRegex = new Regex(@"\""(([^\""]*):\\([^\""]*))\"""); | |
foreach (var line in pathVDF) | |
{ | |
if(pathRegex.IsMatch(line)) | |
{ | |
string match = pathRegex.Matches(line)[0].Groups[1].Value; | |
// De-Escape vdf. | |
libraries.Add(match.Replace("\\\\", "\\")); | |
} | |
} | |
foreach(var library in libraries) | |
{ | |
string csgoPath = Path.Combine(library, "steamapps\\common\\Counter-Strike Global Offensive\\csgo"); | |
if (!Directory.Exists(csgoPath)) | |
{ | |
return csgoPath; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment