コード例 #1
0
        private bool PickAGame()
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = Environment.ExpandEnvironmentVariables(gGame != null ? gGame.Uri : "");
                openFileDialog.Filter           = "exe files (*.exe)|*.exe";
                openFileDialog.FilterIndex      = 2;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string     filePath = openFileDialog.FileName;
                    DockerGame newGame  = new DockerGame(filePath);

                    // are we picking a new executable ?
                    if (gGame != null)
                    {
                        newGame.Settings      = gGame.Settings;
                        newGame.PowerProfiles = gGame.PowerProfiles;
                    }

                    field_Name.Text          = newGame.ProductName;
                    field_Version.Text       = newGame.Version;
                    field_Filename.Text      = newGame.Executable;
                    field_Developer.Text     = newGame.Company;
                    field_GUID.Text          = newGame.GUID;
                    GameIcon.BackgroundImage = newGame.Image;

                    gGame = new DockerGame(newGame);

                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: Valkirie/Thunderbolt-Switch
        public string GetUri(DockerGame thisGame)
        {
            string filename = this.Uri;

            if (this.IsRelative)
            {
                filename = Path.Combine(thisGame.Uri, filename);
            }

            return(filename);
        }
コード例 #3
0
        public static void UpdateFilesAndRegistries(DockerGame game, string path_dest, string path_game, bool updateDB, bool updateFILE, bool pushToast, string crc_value)
        {
            foreach (GameSettings setting in game.Settings.Values.Where(a => a.IsEnabled))
            {
                UpdateFileAndRegistry(game, path_dest, path_game, updateDB, updateFILE, pushToast, crc_value, setting);
            }

            game.SetCrc(crc_value);
            game.Serialize();

            string content = string.Format(MainForm.CurrentResource.GetString("DatabaseUpdate"), game.Name);

            MainForm.SendNotification(content, pushToast);
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: Valkirie/Thunderbolt-Switch
        public DockerGame(DockerGame other)
        {
            this.Arguments   = other.Arguments;
            this.Company     = other.Company;
            this.crc_value   = other.crc_value;
            this.Enabled     = other.Enabled;
            this.ErrorCode   = other.ErrorCode;
            this.Executable  = other.Executable;
            this.FolderName  = other.FolderName;
            this.GUID        = other.GUID;
            this.IGDB_Url    = other.IGDB_Url;
            this.Image       = other.Image;
            this.LastCheck   = other.LastCheck;
            this.Name        = other.Name;
            this.Platform    = other.Platform;
            this.ProductName = other.ProductName;
            this.Uri         = other.Uri;
            this.Version     = other.Version;

            this.PowerProfiles = new Dictionary <Guid, PowerProfile>();
            if (other.PowerProfiles != null)
            {
                foreach (PowerProfile profile in other.PowerProfiles.Values)
                {
                    this.PowerProfiles.Add(profile.ProfileGuid, profile);
                }
            }

            this.Settings = new Dictionary <string, GameSettings>();
            if (other.Settings != null)
            {
                foreach (GameSettings settings in other.Settings.Values)
                {
                    this.Settings.Add(settings.FileName, settings);
                }
            }

            this.PowerSpecific = other.PowerSpecific;

            this.SanityCheck();
        }
コード例 #5
0
        public static List <DockerGame> SearchUniversal()
        {
            List <DockerGame> listofGames = new List <DockerGame>();

            // HKEY_CURRENT_USER\System\GameConfigStore\Children
            string      regkey = "System\\GameConfigStore\\Children";
            RegistryKey key    = Registry.LocalMachine.OpenSubKey(regkey);

            // HKEY_CURRENT_USER\System\GameConfigStore\Children
            regkey = "System\\GameConfigStore\\Children";
            key    = Registry.CurrentUser.OpenSubKey(regkey);

            foreach (string ksubKey in key.GetSubKeyNames())
            {
                using (RegistryKey subKey = key.OpenSubKey(ksubKey))
                {
                    Dictionary <string, string> subKeys = new Dictionary <string, string>();

                    foreach (string subkeyname in subKey.GetValueNames())
                    {
                        subKeys.Add(subkeyname, subKey.GetValue(subkeyname).ToString());
                    }

                    if (subKeys.ContainsKey("MatchedExeFullPath"))
                    {
                        string filePath = subKeys["MatchedExeFullPath"];

                        if (File.Exists(filePath))
                        {
                            DockerGame thisGame = new DockerGame(filePath);
                            thisGame.Platform = PlatformCode.Steam;
                            thisGame.SanityCheck();
                            listofGames.Add(thisGame);
                        }
                    }
                }
            }

            return(listofGames);
        }
コード例 #6
0
        public static List <DockerGame> SearchBattleNet()
        {
            List <DockerGame> listofGames = new List <DockerGame>();

            // HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
            string      regkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
            RegistryKey key    = Registry.LocalMachine.OpenSubKey(regkey);

            foreach (string ksubKey in key.GetSubKeyNames())
            {
                using (RegistryKey subKey = key.OpenSubKey(ksubKey))
                {
                    Dictionary <string, string> subKeys = new Dictionary <string, string>();

                    foreach (string subkeyname in subKey.GetValueNames())
                    {
                        subKeys.Add(subkeyname, subKey.GetValue(subkeyname).ToString());
                    }

                    if (subKeys.ContainsKey("UninstallString"))
                    {
                        string UninstallString = subKeys["UninstallString"];

                        if (UninstallString.Contains("Battle.net"))
                        {
                            string filePath = subKeys["DisplayIcon"];
                            if (File.Exists(filePath))
                            {
                                DockerGame thisGame = new DockerGame(filePath);
                                thisGame.Platform = PlatformCode.BattleNet;
                                thisGame.SanityCheck();
                                listofGames.Add(thisGame);
                            }
                        }
                    }
                }
            }

            return(listofGames);
        }
コード例 #7
0
        public static void UpdateFileAndRegistry(DockerGame game, string path_dest, string path_game, bool updateDB, bool updateFILE, bool pushToast, string crc_value, GameSettings setting)
        {
            string filename = Environment.ExpandEnvironmentVariables(setting.GetUri(game));
            string file     = Path.GetFileName(filename);

            if (setting.Type == SettingsType.File)
            {
                if (!File.Exists(filename))
                {
                    setting.IsEnabled = false;
                    string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsDisabled"), game.Name, file, path_dest, "file");
                    LogManager.UpdateLog(content);
                    return;
                }

                // 1. Save current settings
                if (updateDB)
                {
                    setting.data[path_game] = File.ReadAllBytes(filename);
                    string content = string.Format(MainForm.CurrentResource.GetString("DatabaseFileUpdate"), game.Name, file, path_game, "file");
                    LogManager.UpdateLog(content);
                }

                // 2. Restore proper settings
                if (updateFILE)
                {
                    if (setting.data.ContainsKey(path_dest))
                    {
                        File.WriteAllBytes(filename, setting.data[path_dest]);
                        File.SetLastWriteTime(filename, game.LastCheck);
                        string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsUpdate"), game.Name, file, path_dest, "file");
                        LogManager.UpdateLog(content);
                    }
                    else
                    {
                        string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsSkipped"), game.Name, file, path_dest, "file");
                        LogManager.UpdateLog(content);
                    }
                }
            }
            else if (setting.Type == SettingsType.Registry)
            {
                // We generate a temporary reg file
                string tempfile = Path.Combine(MainForm.path_application, "temp.reg");
                RegistryManager.ExportKey(filename, tempfile);

                if (!File.Exists(tempfile))
                {
                    setting.IsEnabled = false;
                    string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsDisabled"), game.Name, filename, path_dest, "registry entry");
                    LogManager.UpdateLog(content);
                    return;
                }

                // 1. Save current settings
                if (updateDB)
                {
                    setting.data[path_game] = File.ReadAllBytes(tempfile);
                    string content = string.Format(MainForm.CurrentResource.GetString("DatabaseFileUpdate"), game.Name, filename, path_game, "registry entry");
                    LogManager.UpdateLog(content);
                }

                // 2. Restore proper settings
                if (updateFILE)
                {
                    if (setting.data.ContainsKey(path_dest))
                    {
                        File.WriteAllBytes(tempfile, setting.data[path_dest]);
                        RegistryManager.RestoreKey(tempfile);
                        string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsUpdate"), game.Name, filename, path_dest, "registry entry");
                        LogManager.UpdateLog(content);
                    }
                    else
                    {
                        string content = string.Format(MainForm.CurrentResource.GetString("DatabaseSettingsSkipped"), game.Name, filename, path_dest, "registry entry");
                        LogManager.UpdateLog(content);
                    }
                }

                // Delete the temporary reg file
                File.Delete(tempfile);
            }
        }
コード例 #8
0
        public static List <DockerGame> SearchMicrosoftStore()
        {
            List <DockerGame> listofGames = new List <DockerGame>();
            string            foldername  = "C:\\Program Files\\WindowsApps";

            foreach (string folder in Directory.GetDirectories(foldername).Where(a => a.Contains("x86") || a.Contains("x64")))
            {
                foreach (string file in Directory.GetFiles(folder))
                {
                    FileInfo myFile = new FileInfo(file);
                    if (myFile.Name.Equals("AppxManifest.xml", StringComparison.OrdinalIgnoreCase))
                    {
                        XmlDocument doc = new XmlDocument();
                        // prevent crash if file is being read/write by Microsoft Store
                        try
                        {
                            doc.Load(file);
                        }
                        catch (Exception e)
                        {
                            LogManager.UpdateLog($"SearchMicrosoftStore(): {e.Message}", true);
                        }

                        string IdentityName         = "";
                        string IdentityVersion      = "";
                        string DisplayName          = "";
                        string PublisherDisplayName = "";
                        string Executable           = "";
                        string StoreLogo            = "";
                        string StoreLogoScale       = "";

                        XmlNodeList Identity = doc.GetElementsByTagName("Identity");
                        foreach (XmlNode node in Identity)
                        {
                            if (node.Attributes != null)
                            {
                                foreach (XmlAttribute attribute in node.Attributes)
                                {
                                    switch (attribute.Name)
                                    {
                                    case "Name":
                                        IdentityName = attribute.InnerText;
                                        break;

                                    case "Version":
                                        IdentityVersion = attribute.InnerText;
                                        break;
                                    }
                                }
                            }
                        }

                        Identity = doc.GetElementsByTagName("Properties");
                        foreach (XmlNode node in Identity)
                        {
                            foreach (XmlNode child in node.ChildNodes)
                            {
                                switch (child.Name)
                                {
                                case "DisplayName":
                                    DisplayName = child.InnerText;
                                    break;

                                case "PublisherDisplayName":
                                    PublisherDisplayName = child.InnerText;
                                    break;
                                }
                            }
                        }

                        Identity = doc.GetElementsByTagName("Resources");
                        foreach (XmlNode node in Identity)
                        {
                            foreach (XmlNode child in node.ChildNodes)
                            {
                                if (child.Attributes != null)
                                {
                                    foreach (XmlAttribute attribute in child.Attributes)
                                    {
                                        if (attribute.Name.Equals("uap:Scale"))
                                        {
                                            StoreLogoScale = attribute.InnerText;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        Identity = doc.GetElementsByTagName("Applications");
                        foreach (XmlNode node in Identity)
                        {
                            foreach (XmlNode child in node.ChildNodes)
                            {
                                if (child.Name.Equals("Application"))
                                {
                                    if (child.Attributes != null)
                                    {
                                        foreach (XmlAttribute attribute in child.Attributes)
                                        {
                                            switch (attribute.Name)
                                            {
                                            case "Executable":
                                                Executable = attribute.InnerText;
                                                break;
                                            }
                                            continue;
                                        }
                                    }

                                    foreach (XmlNode subchild in child.ChildNodes)
                                    {
                                        if (subchild.Attributes != null)
                                        {
                                            foreach (XmlAttribute attribute in subchild.Attributes)
                                            {
                                                if (attribute.Name.Contains("Logo"))
                                                {
                                                    if (attribute.Name.Contains("Square"))
                                                    {
                                                        StoreLogo = attribute.InnerText;
                                                        break;
                                                    }
                                                    else if (attribute.Name.Contains("Wide"))
                                                    {
                                                        StoreLogo = attribute.InnerText;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (!StoreLogoScale.Equals(""))
                        {
                            StoreLogo = StoreLogo.Replace(".", ".scale-" + StoreLogoScale + ".");
                        }

                        string filePath = Path.Combine(folder, Executable);
                        if (File.Exists(filePath))
                        {
                            DockerGame thisGame = new DockerGame(filePath);
                            thisGame.Platform = PlatformCode.Microsoft;
                            thisGame.Name     = DisplayName.Contains("ms-resource") ? IdentityName : DisplayName;
                            thisGame.Company  = PublisherDisplayName;

                            string filename = Path.Combine(folder, StoreLogo);
                            if (File.Exists(filename))
                            {
                                thisGame.Image = FileManager.GetImage(filename);
                            }
                            listofGames.Add(thisGame);
                        }
                    }
                }
            }

            return(listofGames);
        }
コード例 #9
0
        public GameProperties(MainForm form, DockerGame game)
        {
            InitializeComponent();
            InitializeForm();

            // instances
            gGame       = new DockerGame(game);
            gForm       = form;
            gProperties = this;
            SetStartPos();

            field_Name.Text      = gGame.Name;
            field_GUID.Text      = gGame.GUID;
            field_Filename.Text  = gGame.Executable;
            field_Version.Text   = gGame.Version;
            field_Developer.Text = gGame.Company;
            field_Arguments.Text = gGame.Arguments;

            GameIcon.BackgroundImage = gGame.Image;

            // Settings tab
            foreach (GameSettings setting in gGame.Settings.Values)
            {
                string FileName = System.IO.Path.GetFileName(setting.Uri);

                if (setting.Type == SettingsType.Registry)
                {
                    FileName = setting.Uri;
                }

                ListViewItem newSetting = new ListViewItem(new string[] { FileName, setting.Uri, Enum.GetName(typeof(SettingsType), setting.Type) }, setting.FileName);
                newSetting.Checked = setting.IsEnabled;
                newSetting.Tag     = setting.IsRelative;
                SettingsList.Items.Add(newSetting);
            }

            // General tab
            checkBoxPowerSpecific.Checked        = gGame.PowerSpecific;
            checkBoxPowerProfileSpecific.Checked = gGame.PowerProfileSpecific;

            // Power Profiles tab
            groupBoxPowerProfile.Enabled = MainForm.MonitorProcesses;

            foreach (PowerProfile profile in MainForm.ProfileDB.Values)
            {
                bool isOnBattery      = profile._ApplyMask.HasFlag(ProfileMask.OnBattery);
                bool isPluggedIn      = profile._ApplyMask.HasFlag(ProfileMask.PluggedIn);
                bool isExtGPU         = profile._ApplyMask.HasFlag(ProfileMask.ExternalGPU);
                bool isOnBoot         = profile._ApplyMask.HasFlag(ProfileMask.OnStartup);
                bool isOnStatusChange = profile._ApplyMask.HasFlag(ProfileMask.OnStatusChange);
                bool isOnScreen       = profile._ApplyMask.HasFlag(ProfileMask.ExternalScreen);
                bool isGameBounds     = profile._ApplyMask.HasFlag(ProfileMask.GameBounds);

                ListViewItem newProfile = new ListViewItem(new string[] { profile.ProfileName, isOnBattery.ToString(), isPluggedIn.ToString(), isExtGPU.ToString(), isOnScreen.ToString() }, profile.ProfileName);
                newProfile.Tag = profile.ProfileGuid;

                // skip default
                if (profile.ApplyPriority == -1)
                {
                    continue;
                }

                if (!isGameBounds)
                {
                    continue;
                }

                if (gGame.PowerProfiles.ContainsKey(profile.ProfileGuid))
                {
                    newProfile.Checked = true;
                }

                ProfilesList.Items.Add(newProfile);
            }

            gIsReady = true;
        }
コード例 #10
0
        public static string ContractEnvironmentVariables(string path, ref bool IsRelative, DockerGame thisGame)
        {
            string filename = path.ToLower();

            Dictionary <string, string> sortedDict = new Dictionary <string, string>();

            foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
            {
                string key   = (string)de.Key.ToString().ToLower();
                string value = (string)de.Value.ToString().ToLower();
                sortedDict.Add("%" + key + "%" + @"\", value + @"\");
            }

            foreach (KeyValuePair <string, string> item in sortedDict.OrderByDescending(key => key.Value))
            {
                if (filename.Contains(item.Value))
                {
                    filename = filename.Replace(item.Value, item.Key);
                    break;
                }
            }

            if (!filename.Contains("%"))
            {
                string pathrelative = GetRelativePath(filename, thisGame.Uri);
                if (!path.Equals(pathrelative))
                {
                    filename   = pathrelative;
                    IsRelative = true;
                }
            }

            return(filename);
        }