Beispiel #1
0
        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();
        }