/// <summary> /// Locates the game /// </summary> /// <returns>Null if the game was not found. Otherwise a valid or empty path for the install directory</returns> public override async Task <FileSystemPath?> LocateAsync() { FileSystemPath installDir; try { // Get the key path var keyPath = RegistryHelpers.CombinePaths(CommonRegistryPaths.InstalledPrograms, $"Steam App {SteamID}"); using var key = RegistryHelpers.GetKeyFromFullPath(keyPath, RegistryView.Registry64); // Get the install directory if (!(key?.GetValue("InstallLocation") is string dir)) { RL.Logger?.LogInformationSource($"The {Game} was not found under Steam Apps"); await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error); return(null); } installDir = dir; } catch (Exception ex) { ex.HandleError("Getting Steam game install directory"); await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error); return(null); } // Make sure the game is valid if (!await IsValidAsync(installDir)) { RL.Logger?.LogInformationSource($"The {Game} install directory was not valid"); await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error); return(null); } return(installDir); }
/// <summary> /// Runs the post-update code /// </summary> private async Task PostUpdateAsync() { if (Data.LastVersion < new Version(4, 0, 0, 6)) { Data.EnableAnimations = true; } if (Data.LastVersion < new Version(4, 1, 1, 0)) { Data.ShowIncompleteTranslations = false; } if (Data.LastVersion < new Version(4, 5, 0, 0)) { Data.LinkItemStyle = LinkItemStyles.List; Data.ApplicationPath = Assembly.GetEntryAssembly()?.Location; Data.ForceUpdate = false; Data.GetBetaUpdates = false; } if (Data.LastVersion < new Version(4, 6, 0, 0)) { Data.LinkListHorizontalAlignment = HorizontalAlignment.Left; } if (Data.LastVersion < new Version(5, 0, 0, 0)) { Data.CompressBackups = true; Data.FiestaRunVersion = FiestaRunEdition.Default; // Due to the fiesta run version system being changed the game has to be removed and then re-added Data.Games.Remove(Games.RaymanFiestaRun); // If a Fiesta Run backup exists the name needs to change to the new standard var fiestaBackupDir = Data.BackupLocation + AppViewModel.BackupFamily + "Rayman Fiesta Run"; if (fiestaBackupDir.DirectoryExists) { try { // Read the app data file JObject appData = new StringReader(File.ReadAllText(CommonPaths.AppUserDataPath)).RunAndDispose(x => new JsonTextReader(x).RunAndDispose(y => JsonSerializer.Create().Deserialize(y))).CastTo <JObject>(); // Get the previous Fiesta Run version var isWin10 = appData["IsFiestaRunWin10Edition"].Value <bool>(); // Set the current edition Data.FiestaRunVersion = isWin10 ? FiestaRunEdition.Win10 : FiestaRunEdition.Default; RCPServices.File.MoveDirectory(fiestaBackupDir, Data.BackupLocation + AppViewModel.BackupFamily + Games.RaymanFiestaRun.GetGameInfo().BackupName, true, true); } catch (Exception ex) { ExceptionExtensions.HandleError(ex, "Moving Fiesta Run backups to 5.0.0 standard"); await Services.MessageUI.DisplayMessageAsync(Metro.Resources.PostUpdate_MigrateFiestaRunBackup5Error, Metro.Resources.PostUpdate_MigrateBackupErrorHeader, MessageType.Error); } } // Remove old temp dir try { RCPServices.File.DeleteDirectory(Path.Combine(Path.GetTempPath(), "RCP_Metro")); } catch (Exception ex) { ExceptionExtensions.HandleError(ex, "Cleaning pre-5.0.0 temp"); } Data.DisableDowngradeWarning = false; } if (Data.LastVersion < new Version(6, 0, 0, 0)) { Data.EducationalDosBoxGames = null; Data.RRR2LaunchMode = RRR2LaunchMode.AllGames; Data.RabbidsGoHomeLaunchData = null; } if (Data.LastVersion < new Version(6, 0, 0, 2)) { // By default, add all games to the jump list collection Data.JumpListItemIDCollection = RCPServices.App.GetGames. Where(x => x.IsAdded()). Select(x => x.GetManager().GetJumpListItems().Select(y => y.ID)). SelectMany(x => x). ToList(); } if (Data.LastVersion < new Version(7, 0, 0, 0)) { Data.IsUpdateAvailable = false; if (Data.UserLevel == UserLevel.Normal) { Data.UserLevel = UserLevel.Advanced; } } if (Data.LastVersion < new Version(7, 1, 0, 0)) { Data.InstalledGames = new HashSet <Games>(); } if (Data.LastVersion < new Version(7, 1, 1, 0)) { Data.CategorizeGames = true; } if (Data.LastVersion < new Version(7, 2, 0, 0)) { Data.ShownRabbidsActivityCenterLaunchMessage = false; } if (Data.LastVersion < new Version(9, 0, 0, 0)) { const string regUninstallKeyName = "RCP_Metro"; // Since support has been removed for showing the program under installed programs we now have to remove the key var keyPath = RegistryHelpers.CombinePaths(CommonRegistryPaths.InstalledPrograms, regUninstallKeyName); // Check if the key exists if (RegistryHelpers.KeyExists(keyPath)) { // Make sure the user is running as admin if (RCPServices.App.IsRunningAsAdmin) { try { // Open the parent key using var parentKey = RegistryHelpers.GetKeyFromFullPath(CommonRegistryPaths.InstalledPrograms, RegistryView.Default, true); // Delete the sub-key parentKey.DeleteSubKey(regUninstallKeyName); RL.Logger?.LogInformationSource("The program Registry key has been deleted"); } catch (Exception ex) { ExceptionExtensions.HandleError(ex, "Removing uninstall Registry key"); await Services.MessageUI.DisplayMessageAsync($"The Registry key {keyPath} could not be removed", MessageType.Error); } } else { await Services.MessageUI.DisplayMessageAsync($"The Registry key {keyPath} could not be removed", MessageType.Error); } } if (Data.TPLSData != null) { Data.TPLSData.IsEnabled = false; await Services.MessageUI.DisplayMessageAsync(Metro.Resources.PostUpdate_TPLSUpdatePrompt); } } if (Data.LastVersion < new Version(9, 4, 0, 0)) { Data.Archive_GF_GenerateMipmaps = true; Data.Archive_GF_UpdateTransparency = Archive_GF_TransparencyMode.PreserveFormat; } if (Data.LastVersion < new Version(9, 5, 0, 0)) { Data.BinarySerializationFileLogPath = FileSystemPath.EmptyPath; } if (Data.LastVersion < new Version(10, 0, 0, 0)) { Data.SyncTheme = false; } // Re-deploy files await RCPServices.App.DeployFilesAsync(true); // Refresh the jump list RefreshJumpList(); // Close the splash screen CloseSplashScreen(); // Show app news new AppNewsDialog().ShowDialog(); }