public static string[] GetSteamLibraryPaths() { string[] libraryPaths = Array.Empty <string>(); using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))// Doesn't work in 32 bit mode without this { using (RegistryKey steamKey = hklm?.OpenSubKey(STEAM_PATH_KEY)) { string path = (string)steamKey?.GetValue("InstallPath", string.Empty); if (path != null && path.Length > 0) { string configPath = Path.Combine(path, STEAM_CONFIG_PATH); if (File.Exists(configPath)) { VProperty v = VdfConvert.Deserialize(File.ReadAllText(configPath)); VToken ics = v?.Value; VToken soft = ics?["Software"]; VToken valve = soft?["Valve"]; VObject steamSettings = valve?["Steam"] as VObject; VProperty[] settings = steamSettings?.Children <VProperty>()?.ToArray(); if (settings != null) { libraryPaths = settings.Where(p => p.Key.StartsWith("BaseInstallFolder")) .Select(p => p.Value.ToString()).ToArray(); } } } } } return(libraryPaths); }
private void Parse(string path) { VObject vObject = (VObject)VdfConvert.Deserialize(File.ReadAllText(path).Replace(@"\", @"\\")).Value; DepotId = int.Parse(vObject["DepotID"].ToString()); ContentRoot = vObject["ContentRoot"].ToString(); foreach (VProperty child in vObject.Children()) { switch (child.Key) { case "FileMapping": VObject mapping = (VObject)child.Value; FileMappings.Add(new FileMapping { LocalPath = mapping["LocalPath"].ToString(), DepotPath = mapping["DepotPath"].ToString(), Recursive = int.Parse(mapping["recursive"].ToString()) }); break; case "FileExclusion": FileExclusions.Add(new FileExclusion(child.Value.ToString())); break; default: continue; } } }
static private VProperty CaseInsensitiveParameterCheck(VObject vObject, string stringToCheck) { IEnumerable <VProperty> match = vObject.Children().Where(x => x.Key.Equals(stringToCheck, StringComparison.OrdinalIgnoreCase)); if (match.Count() > 0) { return(match.First()); } return(new VProperty(stringToCheck, null)); }
public Solid(VObject sol) { solid = sol; Sides = new List <Side>(); // get the sides and add them here foreach (var child in solid.Children()) { if (child.Key == "side") { // this is a side add it Sides.Add(new Side(child.ToVObject())); } } }
static string ScanSystemForValheim() { try { int valheimInstalled = (int)Microsoft.Win32.Registry.GetValue(Properties.Settings.Default.Registry_SteamValheimApp, "Installed", 0); if (valheimInstalled == 1) { string steamInstallPath = (string)Microsoft.Win32.Registry.GetValue(Properties.Settings.Default.Registry_SteamInstallDirectory, "SteamPath", null); if (steamInstallPath != null) { steamInstallPath = steamInstallPath.Replace('/', '\\'); if (Directory.Exists(string.Format("{0}{1}", steamInstallPath, @"\steamapps\common\Valheim"))) // Check inside steam install directory { return(string.Format("{0}{1}", steamInstallPath, @"\steamapps\common\Valheim")); } else if (File.Exists(string.Format("{0}{1}", steamInstallPath, @"\config\config.vdf"))) // Check outside libraries { dynamic steamConfig = VdfConvert.Deserialize(File.ReadAllText(string.Format("{0}{1}", steamInstallPath, @"\config\config.vdf"))); VObject sConfigObject = steamConfig.Value.Software.Valve.Steam; foreach (VProperty vp in sConfigObject.Children()) { if (vp.ToString().ToUpper().Contains("BASEINSTALLFOLDER")) { string secondaryLibrary = Convert.ToString(vp.Value); if (Directory.Exists(string.Format("{0}{1}", secondaryLibrary, @"\steamapps\common\Valheim"))) { return(string.Format("{0}{1}", secondaryLibrary, @"\steamapps\common\Valheim")); } } } } } } return(null); }catch (Exception e) { if (Program.SentryEnabled) { Sentry.SentrySdk.CaptureException(e); } Console.WriteLine(e.StackTrace); return(null); } }
/// <summary> /// Steam library paths, including SteamInstallPath bath /// </summary> /// <returns>Enumerable set of path strings</returns> public static IEnumerable <string> GetSteamLibraryPaths() { yield return(SteamInstallPath); string LibraryFile = Path.Combine(SteamInstallPath, "steamapps", "libraryfolders.vdf"); if (File.Exists(LibraryFile)) { VProperty data = VdfConvert.Deserialize(File.ReadAllText(LibraryFile)); VObject data2 = data.Value as VObject; foreach (VProperty child in data2.Children()) { if (int.TryParse(child.Key, out _)) { yield return(child.Value.Value <string>()); } } } }
/// <summary> /// Checks a material object for matching proxies. Returns the matching proxy. /// </summary> /// <param name="material"></param> /// <param name="proxy"></param> /// <returns></returns> static public bool ContainsProxy(dynamic material, string proxy) { string proxyKey = CaseInsensitiveProxyCheck(material); if (proxyKey == null) { return(false); } VObject objectValue = material.Value[proxyKey]; IEnumerable <VProperty> match = objectValue.Children().Where(x => x.Key.Equals(proxy, StringComparison.OrdinalIgnoreCase)); if (match.Count() > 0) { return(true); } else { return(false); } }
public StarSettings() { string steamPath; // Find Steam Install Path // HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam\InstallPath try { using (RegistryKey Reg32Base = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) { using (RegistryKey Reg32Steam = Reg32Base.OpenSubKey(@"SOFTWARE\Valve\Steam")) { steamPath = Reg32Steam.GetValue("InstallPath").ToString(); } } } catch (Exception ex) { throw new Exception("Failed to open registry. Please report this issue." + Environment.NewLine + ex.Message); } // Find Steam Library Folders List <string> libraryFolders = new List <string>(); libraryFolders.Add(steamPath + @"\SteamApps"); try { string libraryFile = steamPath + @"\SteamApps\libraryfolders.vdf"; if (File.Exists(libraryFile)) { string vdfText = File.ReadAllText(libraryFile); VObject vdfObject = VdfConvert.Deserialize(vdfText); if (vdfObject.Count >= 3) { vdfObject.Remove("TimeNextStatsReport"); vdfObject.Remove("ContentStatsID"); foreach (VProperty child in vdfObject.Children()) { libraryFolders.Add(child.Value.ToString()); } } } else { throw new Exception("Failed to find libraryfolders.vdf. Please report this issue."); } } catch (Exception ex) { throw new Exception("Failed to parse libraryfolders.vdf. Please report this issue." + Environment.NewLine + ex.Message); } // Find Starbound App Manifest string libraryPath = String.Empty; foreach (string library in libraryFolders) { if (File.Exists(library + @"\appmanifest_211820.acf")) { libraryPath = library; break; } } if (libraryPath == String.Empty) { throw new Exception("Failed to find Starbound appmanifest! Please report this issue."); } string manifestPath = libraryPath + @"\appmanifest_211820.acf"; // Find Starbound Install Directory string installDir = String.Empty; string[] acfLines = File.ReadAllLines(manifestPath); foreach (string line in acfLines) { if (line.Contains("installdir")) { Globals.GameStoragePath = libraryPath + @"\common\" + line.Replace("\"installdir\"", "").Trim().Trim('"') + @"\storage"; break; } } if (Globals.GameStoragePath == String.Empty) { Globals.GameStoragePath = libraryPath + @"\common\Starbound\storage"; } Globals.GameConfigPath = Globals.GameStoragePath + @"\starbound.config"; if (File.Exists(Globals.GameConfigPath)) { Globals.StarboundSettings = JsonConvert.DeserializeObject <SettingsRoot>(File.ReadAllText(Globals.GameConfigPath)); } else { throw new Exception("Failed to read starbound.config! Please report this issue."); } InitializeComponent(); }