/// <summary>
        ///     Validates packaged files, ensures target directory looks like a TR game.
        /// </summary>
        public void ValidateInstallation()
        {
            try
            {
                ValidatePackagedFiles();
                ProgramData.NLogger.Info("Successfully validated packaged files using MD5 hashes.");
                CheckGameDirLooksLikeATrInstall();
                ProgramData.NLogger.Info($"Parent directory seems like a {ProgramData.GameAbbreviation} game installation.");
            }
            catch (Exception e)
            {
                if (e is BadInstallationLocationException ||
                    e is RequiredFileMissingException ||
                    e is InvalidGameFileException)
                {
                    ProgramData.NLogger.Fatal($"Installation failed to validate. {e.Message}\n{e.StackTrace}");
                    ConsoleIO.PrintWithColor(e.Message, ConsoleColor.Red);
                    Console.WriteLine("You are advised to re-install the latest release to fix the issue:");
                    Console.WriteLine(ProgramData.MiscInfo.LatestReleaseLink);
                    TRVSProgramManager.EarlyPauseAndExit(2);
                }

                const string statement = "An unhandled exception occurred while validating your installation.";
                ProgramManager.GiveErrorMessageAndExit(statement, e, 1);
            }
        }
Пример #2
0
 /// <summary>
 ///     Try to prevent, but close program if errors occur while copying.
 /// </summary>
 /// <param name="srcDir">The directory to copy from</param>
 /// <param name="destDir">The directory to copy to</param>
 protected void TryCopyingDirectory(string srcDir, string destDir)
 {
     // If the EXE is in use, it will cause issues when trying to overwrite it.
     EnsureNoTrGameRunningFromGameDir(Directories.Game);
     // Try to perform the copy.
     try
     {
         ProgramData.NLogger.Debug($"Attempting a copy from \"{srcDir}\" to \"{destDir}\"");
         FileIO.CopyDirectory(srcDir, destDir, true);
     }
     catch (Exception e)
     {
         ProgramManager.GiveErrorMessageAndExit("Failed to copy files!", e, 3);
     }
 }
Пример #3
0
 /// <summary>
 ///     Try to prevent, but if errors occur while deleting <paramref name="dirs"/>, respond according to <paramref name="critical"/>.
 /// </summary>
 /// <param name="dirs">Directories to delete</param>
 /// <param name="recursive">Whether to recursively delete files and subdirectories inside of <paramref name="dirs"/></param>
 /// <param name="critical">Whether the program should halt upon exception</param>
 protected bool TryDeletingDirectories(IEnumerable <string> dirs, bool recursive = false, bool critical = false)
 {
     EnsureNoTrGameRunningFromGameDir(Directories.Game);
     try
     {
         ProgramData.NLogger.Debug($"Attempting to delete the following directories: {string.Join(", ", dirs)}");
         FileIO.DeleteDirectories(dirs, recursive);
     }
     catch (Exception e)
     {
         if (critical)
         {
             ProgramManager.GiveErrorMessageAndExit("Failed to delete directories!", e, 3);
         }
         else
         {
             ProgramData.NLogger.Error($"Failed to delete directories! {e.Message}\n{e.StackTrace}");
         }
         return(false);
     }
     return(true);
 }
Пример #4
0
        /// <summary>
        ///     Asks the user if they want the music fix, then acts appropriately.
        /// </summary>
        /// <remarks>
        ///     Checks if the music fix is already installed and takes the appropriate action.
        ///     If the fix is detected, simply reminds the user it is installed.
        /// </remarks>
        private void HandleMusicFix()
        {
            MusicFileType ext = DetermineMusicFileType();

            if (ext == MusicFileType.OtherOrUnknown)
            {
                ProgramData.NLogger.Debug("Could not determine which music file types are installed. Alerting user.");
                Console.WriteLine("I could not find MP3 or OGG files in your installation's music folder.");
                Console.WriteLine("Therefore, I cannot determine whether you have a correct music fix installed.");
                Console.WriteLine("I recommend you validate or reinstall from Steam/GOG to acquire music files");
                Console.WriteLine("that my supplied music fix utility can fix.");
                return;
            }

            bool correctMusicFixIsInstalled = IsCorrectMusicFixInstalled(ext);

            if (correctMusicFixIsInstalled)
            {
                ProgramData.NLogger.Debug("Music fix is already installed. Reminding the user they have it installed.");
                ConsoleIO.PrintHeader("You already have the music fix installed.", "Skipping music fix installation...", ConsoleColor.White);
                Console.WriteLine();
            }
            else
            {
                ProgramData.NLogger.Debug("Music fix is not installed. Asking the user if they want it to be installed.");
                Console.WriteLine("You switched to a non-shipped version. In-game will not work and/or");
                Console.WriteLine("the game might freeze or lag when it tries to load music. I can install a music");
                Console.WriteLine("fix to resolve these music issues.");
                Console.WriteLine("Please note that you are not required to install this optional fix. Any time you");
                Console.WriteLine("run this program and select a version, I will check for the fix and ask again");
                Console.WriteLine("if you want to install it. The fix works for all affected versions, so it only");
                Console.Write("needs to be installed once. "); // Omit '\n' and leave space for a clean, same-line prompt.
                bool installFix = ConsoleIO.UserPromptYesNo("Install the music fix? [Y/n]: ", ConsoleIO.DefaultOption.Yes);
                if (installFix)
                {
                    ProgramData.NLogger.Debug("User wants the music fix installed...");
                    FileInfo fmodex = new FileInfo(Path.Combine(Directories.MusicFix, "fmodex.dll"));
                    FileInfo winmm  = ext switch
                    {
                        MusicFileType.Mp3 => new FileInfo(Path.Combine(Directories.MusicFix, "winmm-mp3.dll")),
                        MusicFileType.Ogg => new FileInfo(Path.Combine(Directories.MusicFix, "winmm-ogg.dll")),
                        _ => throw new ArgumentException()
                    };
                    try
                    {
                        fmodex.CopyTo(Path.Combine(Directories.Game, "fmodex.dll"), overwrite: true);
                        winmm.CopyTo(Path.Combine(Directories.Game, "winmm.dll"), overwrite: true);
                    }
                    catch (Exception e)
                    {
                        ProgramManager.GiveErrorMessageAndExit("Failed to copy files!", e, 3);
                    }
                    correctMusicFixIsInstalled = true;
                    ProgramData.NLogger.Info("Installed music fix successfully.");
                    ConsoleIO.PrintHeader("Music fix successfully installed!", foregroundColor: ConsoleColor.Green);
                }
                else
                {
                    ProgramData.NLogger.Debug("User declined the music fix installation.");
                    ConsoleIO.PrintHeader("Skipping music fix.", "I'll ask again next time.", ConsoleColor.White);
                }
            }

            if (correctMusicFixIsInstalled)
            {
                if (IsFullscreenBorderFixInstalled(out RegistryKey compatibilityPatchKey))
                {
                    HandleFullscreenBorderFix(compatibilityPatchKey);
                }
                else
                {
                    ProgramData.NLogger.Debug("Fullscreen Border Fix compatibility patch not found. Music fix should work fine.");
                }
            }
        }