Created
December 12, 2015 23:08
-
-
Save moritzuehling/7f1c512871e193c0222f to your computer and use it in GitHub Desktop.
Gets the folder where CS:GO is installed.
This file contains 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
/// <summary> | |
/// Returns the location of the CS:GO installation, or null if it's unable to find it. | |
/// </summary> | |
/// <returns></returns> | |
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