コード例 #1
0
        public static string GetInstallLocation(FF7Version installedVersion)
        {
            string installPath = null;

            switch (installedVersion)
            {
            case FF7Version.Unknown:
                return("");

            case FF7Version.Steam:

                if (Environment.Is64BitOperatingSystem)
                {
                    // on 64-bit OS, Steam release registry key could be at 64bit path or 32bit path so check both
                    installPath = RegistryHelper.GetValue(RegistryHelper.SteamKeyPath32Bit, "InstallLocation", "") as string;

                    if (string.IsNullOrEmpty(installPath))
                    {
                        installPath = RegistryHelper.GetValue(RegistryHelper.SteamKeyPath64Bit, "InstallLocation", "") as string;
                    }
                }
                else
                {
                    installPath = RegistryHelper.GetValue(RegistryHelper.SteamKeyPath32Bit, "InstallLocation", "") as string;
                }

                return(installPath);

            case FF7Version.ReRelease:
                // check 32-bit then 64-bit registry if not exists
                installPath = RegistryHelper.GetValue(RegistryHelper.RereleaseKeyPath32Bit, "InstallLocation", "") as string;

                if (string.IsNullOrWhiteSpace(installPath))
                {
                    installPath = RegistryHelper.GetValue(RegistryHelper.RereleaseKeyPath64Bit, "InstallLocation", "") as string;
                }

                return(installPath);

            case FF7Version.Original98:
                return(RegistryHelper.GetValue(FF7RegKey.FF7AppKeyPath, "Path", "") as string);

            default:
                return("");
            }
        }
コード例 #2
0
        public static void AutoDetectSystemPaths(Settings settings)
        {
            if (string.IsNullOrEmpty(settings.FF7Exe) || !File.Exists(settings.FF7Exe))
            {
                Logger.Info("FF7 Exe path is empty or ff7.exe is missing. Auto detecting paths ...");

                string     registry_path = @"HKEY_LOCAL_MACHINE\SOFTWARE\Square Soft, Inc.\Final Fantasy VII";
                string     ff7           = null;
                FF7Version foundVersion  = FF7Version.Unknown;

                try
                {
                    // first try to detect 1998 game or a "converted" game from the old 7H game converter
                    ff7          = (string)Registry.GetValue(registry_path, "AppPath", null);
                    foundVersion = !string.IsNullOrWhiteSpace(ff7) ? FF7Version.Original98 : FF7Version.Unknown;

                    if (!Directory.Exists(ff7))
                    {
                        Logger.Warn($"Deleting invalid 'AppPath' registry key since path does not exist: {ff7}");
                        RegistryHelper.DeleteValueFromKey(registry_path, "AppPath");   // delete old paths set
                        RegistryHelper.DeleteValueFromKey(registry_path, "DataPath");  // delete old paths set
                        RegistryHelper.DeleteValueFromKey(registry_path, "MoviePath"); // delete old paths set
                        foundVersion = FF7Version.Unknown;                             // set back to Unknown to check other registry keys
                    }


                    if (foundVersion == FF7Version.Unknown)
                    {
                        // next check Steam registry keys and then Re-Release registry keys for installation path
                        ff7          = GameConverter.GetInstallLocation(FF7Version.Steam);
                        foundVersion = !string.IsNullOrWhiteSpace(ff7) ? FF7Version.Steam : FF7Version.Unknown;


                        if (foundVersion == FF7Version.Unknown)
                        {
                            ff7          = GameConverter.GetInstallLocation(FF7Version.ReRelease);
                            foundVersion = !string.IsNullOrWhiteSpace(ff7) ? FF7Version.ReRelease : FF7Version.Unknown;
                        }
                    }

                    string versionStr = foundVersion == FF7Version.Original98 ? $"{foundVersion.ToString()} (or Game Converted)" : foundVersion.ToString();

                    Logger.Info($"FF7Version Detected: {versionStr} with installation path: {ff7}");

                    if (!Directory.Exists(ff7))
                    {
                        Logger.Warn("Found installation path does not exist. Ignoring...");
                        return;
                    }
                }
                catch
                {
                    // could fail if game not installed
                }

                if (foundVersion != FF7Version.Unknown)
                {
                    settings.SetPathsFromInstallationPath(ff7);

                    // copy ff7.exe to install path if not found since Steam & Re-Release installation does not provide a ff7.exe
                    if (!File.Exists(settings.FF7Exe) && Path.GetFileName(settings.FF7Exe).Equals("ff7.exe", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Logger.Info($"Copying ff7.exe from {Sys.PathToPatchedExeFolder} to {settings.FF7Exe}");

                        try
                        {
                            File.Copy(Path.Combine(Sys.PathToPatchedExeFolder, "ff7.exe"), settings.FF7Exe, true);
                            Logger.Info($"\tcopied succesfully.");
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                    }
                }
                else
                {
                    Logger.Warn("Auto detect paths failed - could not get ff7.exe path from Windows Registry.");
                }
            }
        }