Beispiel #1
0
 public Dota2Item(string name, SteamGame game)
     : base(name, game)
 {
     _quality = GetItemQuality();
     _rarity = GetItemRarity();
     _type = GetItemType();
 }
Beispiel #2
0
 public Dota2Item(string name, SteamGame game, int qual, int rar, int type)
     : base(name, game)
 {
     _quality = qual;
     _rarity = rar;
     _type = type;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            int       exitCode  = 0;
            Arguments arguments = null;

            try
            {
                arguments = new Arguments(args);
                arguments.Parse();
                Game launcher = new NullGame();

                if (!arguments.ShowUsage)
                {
                    if (!string.IsNullOrEmpty(arguments.SteamPath))
                    {
                        Console.WriteLine("Setting steam install path.");
                        Configuration.SetSteamPath(arguments.SteamPath);
                    }
                    else if (arguments.UseRandom)
                    {
                        var picker = new Games();
                        launcher = picker.PickRandomGameFromPlaylist(0);
                    }
                    else if (arguments.ListGames)
                    {
                        var picker = new Games();
                        Console.WriteLine(picker.ToString());
                    }
                    else
                    {
                        launcher = new SteamGame(arguments.GameId);
                    }

                    if (launcher.IsReal())
                    {
                        launcher.Launch();
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("ERROR: " + e.Message);
                exitCode = 1;
            }
            finally
            {
                if (arguments != null && arguments.ShowUsage)
                {
                    Console.WriteLine(arguments.GetUsageStatement());
                }
            }

            if (exitCode != 0)
            {
                Environment.Exit(exitCode);
            }
        }
Beispiel #4
0
        private async Task InstallSteamWorkshopItems()
        {
            //var currentLib = "";
            SteamGame currentSteamGame = null;

            StoreHandler.Instance.SteamHandler.Games.Where(g => g.Game == GameInfo.Game).Do(s => currentSteamGame = (SteamGame)s);

            /*SteamHandler.Instance.InstallFolders.Where(f => f.Contains(currentSteamGame.InstallDir)).Do(s => currentLib = s);
             *
             * var downloadFolder = Path.Combine(currentLib, "workshop", "downloads", currentSteamGame.AppId.ToString());
             * var contentFolder = Path.Combine(currentLib, "workshop", "content", currentSteamGame.AppId.ToString());
             */
            if (!ModList.Directives.Any(s => s is SteamMeta))
            {
                return;
            }

            var result = await Utils.Log(new YesNoIntervention(
                                             "The ModList you are installing requires Steam Workshop items to exist. " +
                                             "You can check the Workshop Items in the manifest of this ModList. Wabbajack can start Steam for you " +
                                             "and download the Items automatically. Do you want to proceed with this step?",
                                             "Download Steam Workshop Items?")).Task;

            if (result != ConfirmationIntervention.Choice.Continue)
            {
                return;
            }

            await ModList.Directives.OfType <SteamMeta>()
            .PMap(Queue, item =>
            {
                Status("Extracting Steam meta file to temp folder");
                var path = Path.Combine(DownloadFolder, $"steamWorkshopItem_{item.ItemID}.meta");
                if (!File.Exists(path))
                {
                    File.WriteAllBytes(path, LoadBytesFromPath(item.SourceDataID));
                }

                Status("Downloading Steam Workshop Item through steam cmd");

                var p = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName       = Path.Combine(StoreHandler.Instance.SteamHandler.SteamPath, "steam.exe"),
                        CreateNoWindow = true,
                        Arguments      = $"console +workshop_download_item {currentSteamGame.ID} {currentSteamGame.ID}"
                    }
                };

                p.Start();
            });
        }
Beispiel #5
0
        private void lv_games_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lv_games.SelectedItems.Count > 0)
            {
                SteamGame = lv_games.SelectedItems[0].Tag as SteamGame;
            }
            else
            {
                SteamGame = null;
            }

            btn_ok.Enabled = SteamGame != null;
        }
Beispiel #6
0
        private string GetMultipleEntriesIMG(SteamGame game)
        {
            var scraper = new ScraperModels.Scraper();
            var item    = scraper.StartParse(game);
            var result  = "";

            foreach (var data in item)
            {
                result += Regex.Replace(data.Attributes["href"].Value, @"\s+", " ") + ",\n";
            }

            return(result);
        }
        public string StartGame(int id)
        {
            string baseURL     = ConfigurationManager.AppSettings["BaseURL"];
            string computerKey = ConfigurationManager.AppSettings["ComputerKey"];

            string    URL  = $"{baseURL}/game/checkout/{id}";
            SteamGame game = gc.GetSteamLogin(id, URL, computerKey, "");

            if (game.status == "ok")
            {
                LauncherInfo.StartGame(game);

                gc.StartSteam(LauncherInfo.game);
            }
            return(game.status);
        }
Beispiel #8
0
        /// <summary>
        /// Override this method to create the default Response handler for your web scraper.
        /// If you have multiple page types, you can add additional similar methods.

        /// <param name="response">The http Response object to parse</param>
        public override void Parse(Response response)
        {
            List <SteamGame> gameList = new List <SteamGame>();
            int count = 0;

            /// Loop on all anchor tags
            foreach (var gameRow in response.Css("#search_result_container > div > a"))
            {
                SteamGame game = new SteamGame();

                game.Url   = gameRow.GetAttribute("href");
                game.AppId = gameRow.GetAttribute("data-ds-appid");
                game.Title = gameRow.Css("span.title")[0].TextContentClean;
                game.Image = gameRow.Css("div > img")[0].Attributes["src"];

                if (gameRow.Css("div.search_released")[0].InnerText != "")
                {
                    game.ReleaseDate = Convert.ToDateTime(gameRow.Css("div.search_released")[0].InnerText);
                }
                else
                {
                    game.ReleaseDate = null;
                }

                if (gameRow.Css(".search_price.discounted").Length != 0)
                {
                    string[] combinedPrices = gameRow.Css("div.search_price.discounted")[0].InnerTextClean.Split("$");
                    game.RetailPrice = float.Parse(combinedPrices[1]);
                    game.SalePrice   = float.Parse(combinedPrices[2]);
                }
                else if (gameRow.Css(".search_price").Length != 0)
                {
                    game.RetailPrice = float.Parse(gameRow.Css("div.search_price")[0].InnerTextClean.TrimStart('$'));
                }


                gameList.Add(game);
                //count++;
                //if(count == response.Css("#search_result_container > div > a").Length -1)
                //{
                //    Scrape(gameList, "SteamScraper.Jsonl");
                //}
            }

            //File.WriteAllText(@"Output/SteamScraper.Jsonl", gameList);
            Scrape(gameList, "SteamScraper.Jsonl");
        }
Beispiel #9
0
        private void editBtn_Click(object sender, RoutedEventArgs e)
        {
            bool?steamChecked = steamRadio.IsChecked;
            bool newBool      = steamChecked.HasValue && steamChecked.Value;

            if (newBool)
            {
                SteamGame sg = new SteamGame(new[] { gameNewName.Text, gameNewAppID.Text });
                _mw.SwapGameInList(sg, _index);
            }
            else
            {
                NonSteam ns = new NonSteam(new[] { gameNewName.Text, gameNewPath.Text });
                _mw.SwapGameInList(ns, _index);
            }
            Close();
        }
Beispiel #10
0
        public Task Refresh()
        {
            var ProgramList = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
                              .OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\", RegistryRights.ReadKey)
                              .GetSubKeyNames();
            var Regex = new Regex(@"Steam App (\d+)");

            foreach (var v in ProgramList)
            {
                var a = Regex.Match(v);
                if (a.Success)
                {
                    var game = new SteamGame
                    {
                        id   = Convert.ToInt32(a.Groups[1].Value),
                        path = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
                               .OpenSubKey($"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{v}",
                                           RegistryRights.ReadKey).GetValue("InstallLocation").ToString()
                    };
                    string json;
                    using (var cl = new WebClient())
                    {
                        json = cl.DownloadString(
                            $"https://store.steampowered.com/api/appdetails?appids={a.Groups[1].Value}");
                    }

                    var jObject = JObject.Parse(json);
                    var root    = jObject[a.Groups[1].ToString()].Value <JObject>().ToObject <Root>();
                    if (root.success)
                    {
                        Console.WriteLine(root.data.name);
                        game.Name      = root.data.name;
                        game.photolink = root.data.header_image;
                    }

                    if (!GamesList.Items.Contains(game))
                    {
                        dispatcher.Invoke(() => GamesList.Items.Add(game));
                    }
                }
            }


            return(Task.CompletedTask);
        }
Beispiel #11
0
 private void LoadGames(string path)
 {
     try
     {
         using (StreamReader sr = new StreamReader(path))
         {
             while (true)
             {
                 string line = sr.ReadLine();
                 if (string.IsNullOrEmpty(line))
                 {
                     return;
                 }
                 string[] data = line.Split(',');
                 Game     game;
                 if (data[0] == "steam")
                 {
                     game = new SteamGame(data.Skip(1).ToArray());
                 }
                 else
                 {
                     game = new NonSteam(data.Skip(1).ToArray());
                 }
                 _games.Add(game);
             }
         }
     }
     catch (Exception)
     {
         MessageBoxResult result = MessageBox.Show(
             "The save file is corrupted. Do you want to create a new one?", "Error",
             MessageBoxButton.YesNo, MessageBoxImage.Error);
         if (result == MessageBoxResult.Yes)
         {
             Task.WaitAll(Task.Run(() => File.Delete(DataFile)));
             Task.WaitAll(Task.Run(() => File.Create(DataFile)));
         }
         else
         {
             _emergency = true;
             this.AppClose(this, EventArgs.Empty);
         }
     }
 }
        public StatusMessage StartGame(int id, bool install = false)
        {
            StatusMessage returnMessage = new StatusMessage();

            string baseURL     = ConfigurationManager.AppSettings["BaseURL"];
            string computerKey = ConfigurationManager.AppSettings["ComputerKey"];

            string    URL  = $"{baseURL}/game/checkout/{id}";
            SteamGame game = gc.GetSteamLogin(id, URL, computerKey, "");

            returnMessage.message = game.message;
            returnMessage.status  = game.status;

            if (game.status == "ok")
            {
                LauncherInfo.isInstall = install;
                LauncherInfo.StartGame(game);

                gc.StartSteam(LauncherInfo.game);
            }
            return(returnMessage);
        }
Beispiel #13
0
        public StatusMessage StartGame(int id, bool install = false)
        {
            StatusMessage returnMessage = new StatusMessage();

            string baseURL     = ConfigurationManager.AppSettings["BaseURL"];
            string computerKey = ConfigurationManager.AppSettings["ComputerKey"];
            string secretKey   = ConfigurationManager.AppSettings["Secret"];

            // We must decrypt the secret key using the machine key
            //machineKeyEncryption = new Encryption("the machine key");
            try
            {
                secretKey = MachineKeyEncryption.UnProtect(secretKey, $"Secret for computer {computerKey}");
            }
            catch (Exception e)
            {
                MessageBox.Show($"Error: Unable to load settings. Contact an administrator.\n\n{e.Message}");
                throw;
            }

            // Then, we can Encrypt/Decrypt using that decrypted secret key
            encryption = new Encryption(secretKey);

            string    URL  = $"{baseURL}/game/checkout/{id}";
            SteamGame game = gc.GetSteamLogin(id, URL, computerKey, "");

            returnMessage.message = game.message;
            returnMessage.status  = game.status;

            if (game.status == "ok")
            {
                game.password          = encryption.Decrypt(game.password);
                LauncherInfo.isInstall = install;
                LauncherInfo.StartGame(game);

                gc.StartSteam(LauncherInfo.game);
            }
            return(returnMessage);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Make sure the user inputs good data
            if (string.IsNullOrEmpty(AppIdTextBox.Text) || !long.TryParse(AppIdTextBox.Text, out long _))
            {
                MessageBox.Show("Please enter an integer app ID.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Load the Steam game data
            SteamGame game = GetSteamGame(AppIdTextBox.Text);

            // Make sure a game is found
            if (game == null)
            {
                MessageBox.Show($"No game found for app ID {AppIdTextBox.Text}.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Dump the data to a text file
            string fileName     = $"{Path.GetTempPath()}{Guid.NewGuid()}.txt";
            string fileContents = FormatForForumPost(game);

            // Cleaer input
            AppIdTextBox.Text = UrlTextBox.Text = string.Empty;

            // Try to open temp file
            try
            {
                File.WriteAllText(fileName, fileContents);
                Process.Start("notepad.exe", fileName);
            }
            catch (Exception)
            {
                Clipboard.SetText(fileContents);
                MessageBox.Show("Failed to create/open temp file. Results are copied to clipboard instead.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #15
0
 static public void StopGame()
 {
     LauncherInfo.game = null;
     gameIsNew         = false;
 }
 /// <summary>
 /// Constructs an instruction set to select the daily reward
 /// </summary>
 /// <param name="game"></param>
 public InGameRewardInstructionSet(SteamGame game) : base(game)
 {
     // Load an image to help validate if we are on the game screen with the rewards up
     _screenValidationImage = ImageWizard.LoadImage("Paladins\\images\\DailyRewardScreenThumbnail.png");
 }
 /// <summary>
 /// Constructs the instruction set
 /// </summary>
 /// <param name="game">the Steam game to run the instructions on</param>
 public LoadingGameScreenInstructionSet(SteamGame game) : base(game)
 {
     // Load an image to help validate if we are on the pre-game after-login screen
     _screenValidationImage = ImageWizard.LoadImage("Paladins\\images\\ReadyToPlayScreenThumbnail.png");
 }
        // ReSharper disable once FunctionComplexityOverflow
        // ReSharper disable once CyclomaticComplexity
        private bool CreateShortcut(string fileName)
        {
            var programName = Path.GetFileNameWithoutExtension(txt_executable.Text);
            var description = string.Empty;
            var icon        = string.Empty;
            var args        = new List <string>
            {
                $"-a {HeliosStartupAction.SwitchProfile}",
                $"-p \"{dv_profile.Profile.Name}\""
            };

            if (!Directory.Exists(IconCache))
            {
                try
                {
                    Directory.CreateDirectory(IconCache);
                }
                catch
                {
                    // ignored
                }
            }
            if (cb_temp.Checked)
            {
                if (rb_standalone.Checked)
                {
                    if (string.IsNullOrWhiteSpace(txt_executable.Text))
                    {
                        throw new Exception(Language.Executable_address_can_not_be_empty);
                    }
                    if (!File.Exists(txt_executable.Text))
                    {
                        throw new Exception(Language.Executable_file_not_found);
                    }
                    args.Add($"-e \"{txt_executable.Text.Trim()}\"");
                    if (!string.IsNullOrWhiteSpace(txt_process.Text))
                    {
                        args.Add($"-w \"{txt_process.Text.Trim()}\"");
                        args.Add($"-t {(int) nud_timeout.Value}");
                    }
                    description = string.Format(Language.Executing_application_with_profile, programName, Profile.Name);
                    try
                    {
                        icon = Path.Combine(IconCache, Guid.NewGuid() + ".ico");
                        new ProfileIcon(Profile).ToIconOverly(txt_executable.Text)
                        .Save(icon, MultiIconFormat.ICO);
                    }
                    catch (Exception)
                    {
                        icon = $"{txt_executable.Text.Trim()},0";
                    }
                }
                else if (rb_steam.Checked)
                {
                    if (!SteamGame.SteamInstalled)
                    {
                        throw new Exception(Language.Steam_is_not_installed);
                    }
                    var steamGame = new SteamGame((uint)nud_steamappid.Value);
                    args.Add($"-s {(int) nud_steamappid.Value}");
                    args.Add($"-t {(int) nud_steamtimeout.Value}");
                    description = string.Format(Language.Executing_application_with_profile, steamGame.Name,
                                                Profile.Name);
                    var steamIcon = steamGame.GetIcon().Result;
                    if (!string.IsNullOrWhiteSpace(steamIcon))
                    {
                        try
                        {
                            icon = Path.Combine(IconCache, Guid.NewGuid() + ".ico");
                            new ProfileIcon(Profile).ToIconOverly(steamIcon)
                            .Save(icon, MultiIconFormat.ICO);
                        }
                        catch (Exception)
                        {
                            icon = steamIcon;
                        }
                    }
                    else
                    {
                        icon = $"{SteamGame.SteamAddress},0";
                    }
                }
                if (cb_args.Checked && !string.IsNullOrWhiteSpace(txt_args.Text))
                {
                    args.Add($"--arguments \"{txt_args.Text.Trim()}\"");
                }
            }
            else
            {
                description = string.Format(Language.Switching_display_profile_to_profile, Profile.Name);
                try
                {
                    icon = Path.Combine(IconCache, Guid.NewGuid() + ".ico");
                    new ProfileIcon(Profile).ToIcon().Save(icon, MultiIconFormat.ICO);
                }
                catch
                {
                    icon = string.Empty;
                }
            }

            fileName = Path.ChangeExtension(fileName, @"lnk");
            if (fileName != null)
            {
                try
                {
                    // Remove the old file to replace it
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    var     wshShellType = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8"));
                    dynamic wshShell     = Activator.CreateInstance(wshShellType);
                    try
                    {
                        var shortcut = wshShell.CreateShortcut(fileName);
                        try
                        {
                            shortcut.TargetPath       = Application.ExecutablePath;
                            shortcut.Arguments        = string.Join(" ", args);
                            shortcut.Description      = description;
                            shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath) ??
                                                        string.Empty;
                            if (!string.IsNullOrWhiteSpace(icon))
                            {
                                shortcut.IconLocation = icon;
                            }
                            shortcut.Save();
                        }
                        finally
                        {
                            Marshal.FinalReleaseComObject(shortcut);
                        }
                    }
                    finally
                    {
                        Marshal.FinalReleaseComObject(wshShell);
                    }
                }
                catch
                {
                    // Clean up a failed attempt
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
            }
            return((fileName != null) && File.Exists(fileName));
        }
 public SteamGameListViewItem(SteamGame steamGame)
 {
     SteamGameItem = steamGame;
     Text          = SteamGameItem.AppId;
     SubItems.Add(SteamGameItem.GameName);
 }
        private string FormatForForumPost(SteamGame game)
        {
            StringBuilder b        = new StringBuilder();
            TextInfo      textInfo = new CultureInfo("en-US", false).TextInfo;

            // Create the header of the post
            b.AppendLine("[center]");
            b.AppendLine("[img]");
            b.AppendLine(game.HeaderImage);
            b.AppendLine("[/img]");
            b.AppendLine("[size=150]");
            b.AppendLine(game.Name);
            b.AppendLine("[/size]");
            b.AppendLine("[/center]");
            b.AppendLine(string.Empty);

            // Create game description
            if (!string.IsNullOrEmpty(game.DetailedDescription))
            {
                b.AppendLine("[quote]");
                b.AppendLine(StripHtml(game.DetailedDescription));
                b.AppendLine("[/quote]");
                b.AppendLine(string.Empty);
            }

            // Controller support
            if (!string.IsNullOrEmpty(game.ControllerSupport))
            {
                b.Append("[i]Controller Support: ");
                b.Append(textInfo.ToTitleCase(game.ControllerSupport));
                b.AppendLine("[/i]");
            }

            // Metacritic
            if (game.Metacritic != null)
            {
                b.Append("[i]Metacritic Score: ");
                b.Append("[url=");
                b.Append(game.Metacritic.Url);
                b.Append("]");
                b.Append(game.Metacritic.Score);
                b.Append("[/url]");
                b.AppendLine("[/i]");
            }

            // Developers
            if (game.Developers != null && game.Developers.Length > 0)
            {
                b.Append("[i]Developers: ");
                b.Append(string.Join(", ", game.Developers));
                b.AppendLine("[/i]");
            }

            // Publishers
            if (game.Publishers != null && game.Publishers.Length > 0)
            {
                b.Append("[i]Publishers: ");
                b.Append(string.Join(", ", game.Publishers));
                b.AppendLine("[/i]");
            }

            // Genres
            if (game.Genres != null && game.Genres.Length > 0)
            {
                b.Append("[i]Genres: ");
                b.Append(string.Join(", ", game.Genres.Select(x => x.Description).ToArray()));
                b.AppendLine("[/i]");
            }

            // Store page
            b.Append("[i]Store Page: ");
            b.Append("[url=");
            b.Append("https://store.steampowered.com/app/");
            b.Append(AppIdTextBox.Text);
            b.Append("/");
            b.Append("]Steam[/url]");
            b.AppendLine("[/i]");
            b.AppendLine(string.Empty);

            // Create share tag
            if (!string.IsNullOrEmpty(UrlTextBox.Text) && UrlTextBox.Text.Length > 0)
            {
                b.AppendLine("[hide]");
                b.AppendLine("[code]");
                b.AppendLine(UrlTextBox.Text);
                b.AppendLine("[/code]");
                b.AppendLine("[/hide]");
                b.AppendLine(string.Empty);
            }

            // Create screenshots
            b.AppendLine("[center]");
            foreach (SteamScreenshot screenshot in game.Screenshots)
            {
                b.Append("[img]");
                b.Append(screenshot.PathThumbnail); // Thumbnail to save bandwith
                b.Append("[/img]");
            }
            b.AppendLine("[/center]");

            return(b.ToString());
        }
Beispiel #21
0
 static public void StartGame(SteamGame game)
 {
     LauncherInfo.game = game;
     gameIsNew         = true;
 }
 public State(SteamGame game)
 {
     _game = game;
 }
Beispiel #23
0
 /// <summary>
 /// Constructs the login instruction set
 /// </summary>
 /// <param name="game">the Steam game to run the instructions on</param>
 public LoginInstructionSet(SteamGame game) : base(game)
 {
     // Load an image to help validate if we are on the login screen
     _screenValidationImage = ImageWizard.LoadImage("Paladins\\images\\LoginScreenThumbnail.png");
 }
Beispiel #24
0
        // ReSharper disable once CyclomaticComplexity
        private static void SwitchProfile(IReadOnlyList <Profile> profiles, int profileIndex)
        {
            var rollbackProfile = Profile.GetCurrent(string.Empty);

            if (profileIndex < 0)
            {
                throw new Exception(Language.Selected_profile_is_invalid_or_not_found);
            }
            if (!profiles[profileIndex].IsPossible)
            {
                throw new Exception(Language.Selected_profile_is_not_possible);
            }
            if (
                IPCClient.QueryAll()
                .Any(
                    client =>
                    (client.Status == InstanceStatus.Busy) ||
                    (client.Status == InstanceStatus.OnHold)))
            {
                throw new Exception(
                          Language
                          .Another_instance_of_this_program_is_in_working_state_Please_close_other_instances_before_trying_to_switch_profile);
            }
            if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteFilename))
            {
                if (!File.Exists(CommandLineOptions.Default.ExecuteFilename))
                {
                    throw new Exception(Language.Executable_file_not_found);
                }
                if (!GoProfile(profiles[profileIndex]))
                {
                    throw new Exception(Language.Can_not_change_active_profile);
                }
                var process = Process.Start(CommandLineOptions.Default.ExecuteFilename,
                                            CommandLineOptions.Default.ExecuteArguments);
                var processes = new Process[0];
                if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteProcessName))
                {
                    var ticks = 0;
                    while (ticks < CommandLineOptions.Default.ExecuteProcessTimeout * 1000)
                    {
                        processes = Process.GetProcessesByName(CommandLineOptions.Default.ExecuteProcessName);
                        if (processes.Length > 0)
                        {
                            break;
                        }
                        Thread.Sleep(300);
                        ticks += 300;
                    }
                }
                if (processes.Length == 0)
                {
                    processes = new[] { process }
                }
                ;
                IPCService.GetInstance().HoldProcessId = processes.FirstOrDefault()?.Id ?? 0;
                IPCService.GetInstance().Status        = InstanceStatus.OnHold;
                NotifyIcon notify = null;
                try
                {
                    notify = new NotifyIcon
                    {
                        Icon = Properties.Resources.Icon,
                        Text = string.Format(
                            Language.Waiting_for_the_0_to_terminate,
                            processes[0].ProcessName),
                        Visible = true
                    };
                    Application.DoEvents();
                }
                catch
                {
                    // ignored
                }
                foreach (var p in processes)
                {
                    try
                    {
                        p.WaitForExit();
                    }
                    catch
                    {
                        // ignored
                    }
                }
                if (notify != null)
                {
                    notify.Visible = false;
                    notify.Dispose();
                    Application.DoEvents();
                }
                IPCService.GetInstance().Status = InstanceStatus.Busy;
                if (!rollbackProfile.IsActive)
                {
                    if (!GoProfile(rollbackProfile))
                    {
                        throw new Exception(Language.Can_not_change_active_profile);
                    }
                }
            }
            else if (CommandLineOptions.Default.ExecuteSteamApp > 0)
            {
                var steamGame = new SteamGame(CommandLineOptions.Default.ExecuteSteamApp);
                if (!SteamGame.SteamInstalled)
                {
                    throw new Exception(Language.Steam_is_not_installed);
                }
                if (!File.Exists(SteamGame.SteamAddress))
                {
                    throw new Exception(Language.Steam_executable_file_not_found);
                }
                if (!steamGame.IsInstalled)
                {
                    throw new Exception(Language.Steam_game_is_not_installed);
                }
                if (!steamGame.IsOwned)
                {
                    throw new Exception(Language.Steam_game_is_not_owned);
                }
                if (!GoProfile(profiles[profileIndex]))
                {
                    throw new Exception(Language.Can_not_change_active_profile);
                }
                var address = $"steam://rungameid/{steamGame.AppId}";
                if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteArguments))
                {
                    address += "/" + CommandLineOptions.Default.ExecuteArguments;
                }
                var steamProcess = Process.Start(address);
                // Wait for steam game to update and then run
                var ticks = 0;
                while (ticks < CommandLineOptions.Default.ExecuteProcessTimeout * 1000)
                {
                    if (steamGame.IsRunning)
                    {
                        break;
                    }
                    Thread.Sleep(300);
                    if (!steamGame.IsUpdating)
                    {
                        ticks += 300;
                    }
                }
                IPCService.GetInstance().HoldProcessId = steamProcess?.Id ?? 0;
                IPCService.GetInstance().Status        = InstanceStatus.OnHold;
                NotifyIcon notify = null;
                try
                {
                    notify = new NotifyIcon
                    {
                        Icon = Properties.Resources.Icon,
                        Text = string.Format(
                            Language.Waiting_for_the_0_to_terminate,
                            steamGame.Name),
                        Visible = true
                    };
                    Application.DoEvents();
                }
                catch
                {
                    // ignored
                }
                // Wait for the game to exit
                if (steamGame.IsRunning)
                {
                    while (true)
                    {
                        if (!steamGame.IsRunning)
                        {
                            break;
                        }
                        Thread.Sleep(300);
                    }
                }
                if (notify != null)
                {
                    notify.Visible = false;
                    notify.Dispose();
                    Application.DoEvents();
                }
                IPCService.GetInstance().Status = InstanceStatus.Busy;
                if (!rollbackProfile.IsActive)
                {
                    if (!GoProfile(rollbackProfile))
                    {
                        throw new Exception(Language.Can_not_change_active_profile);
                    }
                }
            }
            else
            {
                if (!GoProfile(profiles[profileIndex]))
                {
                    throw new Exception(Language.Can_not_change_active_profile);
                }
            }
        }
    }
Beispiel #25
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name">Item name as string</param>
 /// <param name="game">Item game</param>
 public SteamItem(string name, SteamGame game)
 {
     _game = game;
     _name = name;
     _marketable = GetMarketStatus();
     _tradable = GetTradingStatus();
 }
 public IncludeSteamWorkshopItems(ACompiler compiler, SteamGame steamGame) : base(compiler)
 {
     _game = steamGame;
 }