Skip to content

Instantly share code, notes, and snippets.

@moritzuehling
Created December 9, 2015 19:18
Show Gist options
  • Save moritzuehling/abdb5ecf81496ba768d9 to your computer and use it in GitHub Desktop.
Save moritzuehling/abdb5ecf81496ba768d9 to your computer and use it in GitHub Desktop.
Finds the installation directory of CS:GO
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