Ejemplo n.º 1
0
        /// <summary>
        /// Verifies a FF7 install is a Full/Max install by checking if specific files are in the game dir.
        /// They will automatically be copied from discs if not found.
        /// Returns false if failed to find/copy all files
        /// </summary>
        /// <returns> Returns true if all files found and/or copied; false otherwise </returns>
        public bool VerifyFullInstallation()
        {
            bool foundAllFiles = true;

            string[] expectedFiles = new string[]
            {
                @"wm\world_us.lgp",
                @"field\char.lgp",
                @"field\flevel.lgp",
                @"minigame\chocobo.lgp",
                @"minigame\coaster.lgp",
                @"minigame\condor.lgp",
                @"minigame\high-us.lgp",
                @"minigame\snowboard-us.lgp",
                @"minigame\sub.lgp"
            };

            string[] volumeLabels = new string[]
            {
                "ff7install",
                "ff7disc1",
                "ff7disc2",
                "ff7disc3"
            };

            foreach (string file in expectedFiles)
            {
                string fullTargetPath = Path.Combine(InstallPath, "data", file);

                if (File.Exists(fullTargetPath))
                {
                    // file already exists at install path so continue
                    continue;
                }

                SendMessage($"...\t {file} not found. Scanning disc(s) for files ...", NLog.LogLevel.Warn);

                // search all drives for the file
                bool foundFileOnDrive = false;
                foreach (string label in volumeLabels)
                {
                    string driveLetter = GameLauncher.GetDriveLetter(label);

                    if (!string.IsNullOrWhiteSpace(driveLetter))
                    {
                        string fullSourcePath = Path.Combine(driveLetter, "ff7", file);
                        if (label == "ff7install")
                        {
                            fullSourcePath = Path.Combine(driveLetter, "data", file); // ff7install disc has a different path then disc1-3
                        }


                        if (File.Exists(fullSourcePath))
                        {
                            foundFileOnDrive = true;
                            SendMessage($"... \t found file on {label} at {driveLetter}. Copying file ...");
                            try
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(fullTargetPath)); // ensure all subfolders are created
                                File.Copy(fullSourcePath, fullTargetPath, true);
                                SendMessage($"... \t\t copied!");
                            }
                            catch (Exception e)
                            {
                                Logger.Error(e);
                                SendMessage($"... \t\t failed to copy. Error has been logged", NLog.LogLevel.Warn);
                            }
                        }
                    }

                    if (foundFileOnDrive)
                    {
                        break; // done searching drives as file found/copied
                    }
                }

                // at this point if file not found/copied on any drive then failed verification
                if (!foundFileOnDrive)
                {
                    SendMessage($"... \t failed to find {file} on any disc ...", NLog.LogLevel.Warn);
                    foundAllFiles = false;
                }
            }

            return(foundAllFiles);
        }