public GameMetadata UpdateGameWithMetadata(Game game) { var metadata = new GameMetadata(); var product = BattleNetGames.GetAppDefinition(game.GameId); if (product == null) { return(metadata); } if (string.IsNullOrEmpty(product.IconUrl)) { return(metadata); } game.Name = product.Name; var icon = HttpDownloader.DownloadData(product.IconUrl); var iconFile = Path.GetFileName(product.IconUrl); metadata.Icon = new MetadataFile(iconFile, icon); var cover = HttpDownloader.DownloadData(product.CoverUrl); var coverFile = Path.GetFileName(product.CoverUrl); metadata.Image = new MetadataFile(coverFile, cover); game.BackgroundImage = product.BackgroundUrl; metadata.BackgroundImage = product.BackgroundUrl; game.Links = new ObservableCollection <Link>(product.Links); return(metadata); }
public async void StartUninstallWatcher() { watcherToken = new CancellationTokenSource(); await Task.Run(async() => { var app = BattleNetGames.GetAppDefinition(Game.GameId); 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); } }); }
public override async void Play() { ReleaseResources(); stopWatch = Stopwatch.StartNew(); procMon = new ProcessMonitor(); procMon.TreeDestroyed += Monitor_TreeDestroyed; var app = BattleNetGames.GetAppDefinition(Game.GameId); if (Game.PlayAction.Type == GameActionType.URL && Game.PlayAction.Path.StartsWith("battlenet", StringComparison.OrdinalIgnoreCase)) { if (!BattleNet.IsInstalled) { throw new Exception("Cannot start game, Battle.net launcher is not installed properly."); } var bnetRunning = BattleNet.IsRunning; if (!bnetRunning) { logger.Info("Battle.net is not running, starting it first."); BattleNet.StartClient(); while (BattleNet.RunningProcessesCount < 3) { await Task.Delay(500); } } OnStarting(this, new GameControllerEventArgs(this, 0)); var task = new GameAction() { Path = BattleNet.ClientExecPath, Arguments = string.Format("--exec=\"launch {0}\"", Game.GameId) }; GameActionActivator.ActivateAction(task, Game); procMon.TreeStarted += ProcMon_TreeStarted; procMon.WatchDirectoryProcesses(Game.InstallDirectory, false); } else if (app.Type == BNetAppType.Classic && Game.PlayAction.Path.Contains(app.ClassicExecutable)) { OnStarting(this, new GameControllerEventArgs(this, 0)); var proc = GameActionActivator.ActivateAction(Game.PlayAction, Game); procMon.WatchDirectoryProcesses(Game.InstallDirectory, true); OnStarted(this, new GameControllerEventArgs(this, 0)); } else { throw new Exception("Unknoww Play action configuration"); } }
public async void StartInstallWatcher() { watcherToken = new CancellationTokenSource(); await Task.Run(async() => { var app = BattleNetGames.GetAppDefinition(Game.GameId); while (true) { if (watcherToken.IsCancellationRequested) { return; } var install = BattleNetLibrary.GetUninstallEntry(app); if (install == null) { await Task.Delay(2000); continue; } else { if (Game.PlayAction == null) { if (app.Type == BNetAppType.Classic) { Game.PlayAction = new GameAction() { Type = GameActionType.File, WorkingDir = @"{InstallDir}", Path = app.ClassicExecutable }; } else { Game.PlayAction = BattleNetLibrary.GetGamePlayTask(Game.GameId); } } Game.InstallDirectory = install.InstallLocation; OnInstalled(this, new GameControllerEventArgs(this, 0)); return; } } }); }
public override void Uninstall() { ReleaseResources(); var product = BattleNetGames.GetAppDefinition(Game.GameId); 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(); var app = BattleNetGames.GetAppDefinition(Game.GameId); while (true) { if (watcherToken.IsCancellationRequested) { return; } var install = BattleNetLibrary.GetUninstallEntry(app); if (install == null) { await Task.Delay(2000); continue; } else { var installInfo = new GameInfo() { InstallDirectory = install.InstallLocation }; if (app.Type == BNetAppType.Classic) { installInfo.PlayAction = new GameAction() { Type = GameActionType.File, WorkingDir = ExpandableVariables.InstallationDirectory, Path = app.ClassicExecutable }; } else { installInfo.PlayAction = BattleNetLibrary.GetGamePlayTask(Game.GameId); } OnInstalled(this, new GameInstalledEventArgs(installInfo, this, 0)); return; } } }
public override void Install() { ReleaseResources(); var product = BattleNetGames.GetAppDefinition(Game.GameId); if (product.Type == BNetAppType.Classic) { ProcessStarter.StartUrl(@"https://battle.net/account/management/download/"); } else { if (!BattleNet.IsInstalled) { throw new Exception("Cannot install game, Battle.net launcher is not installed properly."); } ProcessStarter.StartProcess(BattleNet.ClientExecPath, $"--game={product.InternalId}"); } StartInstallWatcher(); }
public override GameMetadata GetMetadata(Game game) { var product = BattleNetGames.GetAppDefinition(game.GameId); if (product == null) { return(null); } var gameInfo = new GameInfo { Name = product.Name, Links = new List <Link>(product.Links) }; gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + product.Name)); var metadata = new GameMetadata() { GameInfo = gameInfo }; if (!string.IsNullOrEmpty(product.IconUrl)) { metadata.Icon = new MetadataFile(product.IconUrl); } if (!string.IsNullOrEmpty(product.CoverUrl)) { metadata.CoverImage = new MetadataFile(product.CoverUrl); } if (!string.IsNullOrEmpty(product.BackgroundUrl)) { metadata.BackgroundImage = new MetadataFile(product.BackgroundUrl); } return(metadata); }
public override void Play() { ReleaseResources(); stopWatch = Stopwatch.StartNew(); procMon = new ProcessMonitor(); procMon.TreeDestroyed += Monitor_TreeDestroyed; var app = BattleNetGames.GetAppDefinition(Game.GameId); if (Game.PlayAction.Type == GameActionType.URL && Game.PlayAction.Path.StartsWith("battlenet", StringComparison.OrdinalIgnoreCase)) { if (!BattleNet.IsInstalled) { throw new Exception("Cannot start game, Battle.net launcher is not installed properly."); } OnStarting(this, new GameControllerEventArgs(this, 0)); StartBnetRunningWatcher(); } else if (app.Type == BNetAppType.Classic && Game.PlayAction.Path.Contains(app.ClassicExecutable)) { var playAction = api.ExpandGameVariables(Game, Game.PlayAction); OnStarting(this, new GameControllerEventArgs(this, 0)); GameActionActivator.ActivateAction(playAction); OnStarted(this, new GameControllerEventArgs(this, 0)); if (Directory.Exists(Game.InstallDirectory)) { procMon.WatchDirectoryProcesses(Game.InstallDirectory, true, true); } else { OnStopped(this, new GameControllerEventArgs(this, 0)); } } else { throw new Exception("Unknown Play action configuration."); } }