public override void Play(List <Emulator> emulators)
        {
            ReleaseResources();
            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += Monitor_TreeDestroyed;
            var app = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

            if (Game.PlayTask.Type == GameTaskType.URL && Game.PlayTask.Path.StartsWith("battlenet", StringComparison.InvariantCultureIgnoreCase))
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var task = new GameTask()
                {
                    Path      = BattleNetSettings.ClientExecPath,
                    Arguments = string.Format("--exec=\"launch {0}\"", Game.ProviderId)
                };

                GameHandler.ActivateTask(task, Game, emulators);
                procMon.TreeStarted += ProcMon_TreeStarted;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else if (app.Type == BattleNetLibrary.BNetAppType.Classic && Game.PlayTask.Path.Contains(app.ClassicExecutable))
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));
                var proc = GameHandler.ActivateTask(Game.PlayTask, Game, emulators);
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, true);
                OnStarted(this, new GameControllerEventArgs(this, 0));
            }
            else
            {
                base.Play(emulators);
            }
        }
        public async void StartUninstallWatcher()
        {
            watcherToken = new CancellationTokenSource();
            await Task.Run(async() =>
            {
                var app = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }

                    var entry = BattleNetLibrary.GetUninstallEntry(app);
                    if (entry == null)
                    {
                        OnUninstalled(this, new GameControllerEventArgs(this, 0));
                        return;
                    }

                    await Task.Delay(2000);
                }
            });
        }
示例#3
0
        public override void Play(List <Emulator> emulators)
        {
            Dispose();
            stopWatch              = Stopwatch.StartNew();
            procMon                = new ProcessMonitor();
            procMon.TreeDestroyed += Monitor_TreeDestroyed;
            var app = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

            if (Game.PlayTask.Type == GameTaskType.URL && Game.PlayTask.Path.StartsWith("battlenet", StringComparison.InvariantCultureIgnoreCase))
            {
                GameHandler.ActivateTask(Game.PlayTask, Game, emulators);
                procMon.TreeStarted += ProcMon_TreeStarted;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else if (app.Type == BattleNetLibrary.BNetAppType.Classic && Game.PlayTask.Path.Contains(app.ClassicExecutable))
            {
                var proc = GameHandler.ActivateTask(Game.PlayTask, Game, emulators);
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, true);
                OnStarted(this, new GameControllerEventArgs(this, 0));
            }
            else
            {
                base.Play(emulators);
            }
        }
        public GameMetadata GetGameData(string gameId)
        {
            var gameData = new Game("BattleNetGame")
            {
                Provider   = Provider.Steam,
                ProviderId = gameId
            };

            var steamLib = new BattleNetLibrary();
            var data     = steamLib.UpdateGameWithMetadata(gameData);

            return(new GameMetadata(gameData, data.Icon, data.Image, data.BackgroundImage));
        }
        public override void Install()
        {
            ReleaseResources();
            var product = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

            if (product.Type == BattleNetLibrary.BNetAppType.Classic)
            {
                ProcessStarter.StartUrl(@"https://battle.net/account/management/download/");
            }
            else
            {
                ProcessStarter.StartProcess(BattleNetSettings.ClientExecPath, $"--game={product.InternalId}");
            }

            StartInstallWatcher();
        }
        public override void Uninstall()
        {
            ReleaseResources();
            var product = BattleNetLibrary.GetAppDefinition(Game.ProviderId);
            var entry   = BattleNetLibrary.GetUninstallEntry(product);

            if (entry != null)
            {
                var args = string.Format("/C \"{0}\"", entry.UninstallString);
                ProcessStarter.StartProcess("cmd", args);
                StartUninstallWatcher();
            }
            else
            {
                OnUninstalled(this, new GameControllerEventArgs(this, 0));
            }
        }
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();
            await Task.Run(async() =>
            {
                var app = BattleNetLibrary.GetAppDefinition(Game.ProviderId);

                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }

                    var install = BattleNetLibrary.GetUninstallEntry(app);
                    if (install == null)
                    {
                        await Task.Delay(2000);
                        continue;
                    }
                    else
                    {
                        if (Game.PlayTask == null)
                        {
                            if (app.Type == BattleNetLibrary.BNetAppType.Classic)
                            {
                                Game.PlayTask = new GameTask()
                                {
                                    Type       = GameTaskType.File,
                                    WorkingDir = @"{InstallDir}",
                                    Path       = @"{InstallDir}\" + app.ClassicExecutable
                                };
                            }
                            else
                            {
                                Game.PlayTask = battleNet.GetGamePlayTask(Game.ProviderId);
                            }
                        }

                        Game.InstallDirectory = install.InstallLocation;
                        OnInstalled(this, new GameControllerEventArgs(this, 0));
                        return;
                    }
                }
            });
        }
        public void StartInstallMonitoring()
        {
            logger.Info("Starting install monitoring of BattleNet app " + app.ProductId);
            Dispose();

            cancelToken = new CancellationTokenSource();

            Task.Factory.StartNew(() =>
            {
                while (!cancelToken.Token.IsCancellationRequested)
                {
                    var entry = BattleNetLibrary.GetUninstallEntry(app);
                    if (entry != null)
                    {
                        logger.Info($"BattleNet app {app.ProductId} has been installed.");

                        GameTask playTask;
                        if (app.Type == BattleNetLibrary.BNetAppType.Classic)
                        {
                            playTask = new GameTask()
                            {
                                Type       = GameTaskType.File,
                                WorkingDir = @"{InstallDir}",
                                Path       = @"{InstallDir}\" + app.ClassicExecutable
                            };
                        }
                        else
                        {
                            playTask = library.GetGamePlayTask(app.ProductId);
                        }

                        GameInstalled?.Invoke(this, new GameInstalledEventArgs(new Game()
                        {
                            PlayTask         = playTask,
                            InstallDirectory = entry.InstallLocation
                        }));
                        return;
                    }

                    Thread.Sleep(5000);
                }
            }, cancelToken.Token);
        }
        public void StartUninstallMonitoring()
        {
            logger.Info("Starting uninstall monitoring of BattleNet app " + app.ProductId);
            Dispose();

            cancelToken = new CancellationTokenSource();

            Task.Factory.StartNew(() =>
            {
                while (!cancelToken.Token.IsCancellationRequested)
                {
                    var entry = BattleNetLibrary.GetUninstallEntry(app);
                    if (entry == null)
                    {
                        logger.Info($"BattleNet app {app.ProductId} has been uninstalled.");
                        GameUninstalled?.Invoke(this, null);
                        return;
                    }

                    Thread.Sleep(5000);
                }
            }, cancelToken.Token);
        }