Beispiel #1
0
        public void StartUninstallMonitoring()
        {
            logger.Info("Starting uninstall monitoring of Uplay app " + id);
            Dispose();

            cancelToken = new CancellationTokenSource();
            var gameInstalled = library.GetInstalledGames().FirstOrDefault(a => a.ProviderId == id) != null;

            Task.Factory.StartNew(() =>
            {
                // Uplay is currently 32bit only, but this will future proof this feature
                var root32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                var root64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

                while (!cancelToken.Token.IsCancellationRequested)
                {
                    var installsKey32 = root32.OpenSubKey(@"SOFTWARE\ubisoft\Launcher\Installs\");
                    if (installsKey32 != null)
                    {
                        var gameKey = installsKey32.OpenSubKey(id);
                        if (gameKey == null)
                        {
                            logger.Info($"Uplay app {id} has been uninstalled.");
                            GameUninstalled?.Invoke(this, null);
                            return;
                        }
                    }

                    if (Environment.Is64BitOperatingSystem)
                    {
                        var installsKey64 = root64.OpenSubKey(@"SOFTWARE\ubisoft\Launcher\Installs\");
                        if (installsKey64 != null)
                        {
                            var gameKey = installsKey64.OpenSubKey(id);
                            if (gameKey == null)
                            {
                                logger.Info($"Uplay app {id} has been uninstalled.");
                                GameUninstalled?.Invoke(this, null);
                                return;
                            }
                        }
                    }

                    Thread.Sleep(5000);
                }
            }, cancelToken.Token);
        }
Beispiel #2
0
        public List <IGame> UpdateInstalledGames(Provider provider)
        {
            List <IGame> installedGames = null;
            List <IGame> newGames       = new List <IGame>();

            switch (provider)
            {
            case Provider.Custom:
                return(newGames);

            case Provider.GOG:
                var source = InstalledGamesSource.Registry;
                if (AppSettings.GOGSettings.RunViaGalaxy)
                {
                    source = InstalledGamesSource.Galaxy;
                }

                installedGames = gogLibrary.GetInstalledGames(source);
                break;

            case Provider.Origin:
                installedGames = originLibrary.GetInstalledGames(true);
                break;

            case Provider.Steam:
                installedGames = steamLibrary.GetInstalledGames();
                break;

            case Provider.Uplay:
                installedGames = uplayLibrary.GetInstalledGames();
                break;

            case Provider.BattleNet:
                installedGames = battleNetLibrary.GetInstalledGames();
                break;

            default:
                return(newGames);
            }

            foreach (var newGame in installedGames)
            {
                var existingGame = GamesCollection.FindOne(a => a.ProviderId == newGame.ProviderId && a.Provider == provider);
                if (existingGame == null)
                {
                    logger.Info("Adding new installed game {0} from {1} provider", newGame.ProviderId, newGame.Provider);
                    AssignPcPlatform(newGame);
                    AddGame(newGame);
                    newGames.Add(newGame);
                }
                else
                {
                    existingGame.PlayTask         = newGame.PlayTask;
                    existingGame.InstallDirectory = newGame.InstallDirectory;

                    // Don't import custom action if imported already (user may changed them manually and this would overwrite it)
                    if (existingGame.OtherTasks?.FirstOrDefault(a => a.IsBuiltIn) == null && newGame.OtherTasks != null)
                    {
                        if (existingGame.OtherTasks == null)
                        {
                            existingGame.OtherTasks = new ObservableCollection <GameTask>();
                        }
                        else
                        {
                            existingGame.OtherTasks = new ObservableCollection <GameTask>(existingGame.OtherTasks.Where(a => !a.IsBuiltIn));
                        }

                        foreach (var task in newGame.OtherTasks.Reverse())
                        {
                            existingGame.OtherTasks.Insert(0, task);
                        }

                        if (provider == Provider.Steam)
                        {
                            foreach (var task in existingGame.OtherTasks.Where(a => a.Type == GameTaskType.File && a.IsBuiltIn))
                            {
                                task.WorkingDir = newGame.InstallDirectory;
                            }
                        }
                    }

                    UpdateGameInDatabase(existingGame);
                }
            }

            foreach (var game in GamesCollection.Find(a => a.Provider == provider))
            {
                if (installedGames.FirstOrDefault(a => a.ProviderId == game.ProviderId) == null)
                {
                    game.PlayTask         = null;
                    game.InstallDirectory = string.Empty;
                    UpdateGameInDatabase(game);
                }
            }

            return(newGames);
        }