Esempio n. 1
0
        public GameData(MeType type, ConfIni configIni, bool force = false, bool installerMode = false)
        {
            gameType   = type;
            _configIni = configIni;

            string key  = "ME" + (int)gameType;
            string path = configIni.Read(key, "GameDataPath");

            if (path != null && path != "" && !force)
            {
                _path = path.TrimEnd(Path.DirectorySeparatorChar);
                if (File.Exists(GameExePath))
                {
                    return;
                }
                else
                {
                    _path = null;
                }
            }

            string registryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\BioWare\Mass Effect";
            string entry       = "Path";

            if (type == MeType.ME2_TYPE)
            {
                registryKey += " 2";
            }
            else if (type == MeType.ME3_TYPE)
            {
                registryKey += " 3";
                entry        = "Install Dir";
            }

            path = (string)Registry.GetValue(registryKey, entry, null);
            if (path != null && !force)
            {
                _path = path.TrimEnd(Path.DirectorySeparatorChar);
                if (File.Exists(GameExePath))
                {
                    configIni.Write(key, _path, "GameDataPath");
                    return;
                }
                else
                {
                    _path = null;
                }
            }
            if (_path != null)
            {
                _configIni.Write(key, _path, "GameDataPath");
            }
        }
        public GameData(MeType type, ConfIni configIni, bool force = false)
        {
            gameType   = type;
            _configIni = configIni;

            string key  = "ME" + (int)gameType;
            string path = configIni.Read(key, "GameDataPath");

            if (path != null && path != "" && !force)
            {
                _path = path.TrimEnd(Path.DirectorySeparatorChar);
                if (File.Exists(GameExePath))
                {
                    return;
                }
                else
                {
                    _path = null;
                }
            }

            string softwareKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\";
            string key64       = @"Wow6432Node\";
            string gameKey     = @"BioWare\Mass Effect";
            string entry       = "Path";

            if (type == MeType.ME2_TYPE)
            {
                gameKey += @" 2";
            }
            else if (type == MeType.ME3_TYPE)
            {
                gameKey += @" 3";
                entry    = "Install Dir";
            }

            path = (string)Registry.GetValue(softwareKey + gameKey, entry, null);
            if (path == null)
            {
                path = (string)Registry.GetValue(softwareKey + key64 + gameKey, entry, null);
            }
            if (path != null && !force)
            {
                _path = path.TrimEnd(Path.DirectorySeparatorChar);
                if (File.Exists(GameExePath))
                {
                    configIni.Write(key, _path, "GameDataPath");
                    return;
                }
                else
                {
                    _path = null;
                }
            }

            OpenFileDialog selectExe = new OpenFileDialog();

            selectExe.Title = "Please select the Mass Effect " + (int)gameType + " executable file";
            if (_path != null)
            {
                selectExe.FileName = _path;
            }
            switch (gameType)
            {
            case MeType.ME1_TYPE:
                selectExe.Filter   = "ME1 exe file|MassEffect.exe";
                selectExe.FileName = "MassEffect.exe";
                break;

            case MeType.ME2_TYPE:
                selectExe.Filter   = "ME2 exe file|MassEffect2.exe";
                selectExe.FileName = "MassEffect2.exe";
                break;

            case MeType.ME3_TYPE:
                selectExe.Filter   = "ME3 exe file|MassEffect3.exe";
                selectExe.FileName = "MassEffect3.exe";
                break;
            }
            if (selectExe.ShowDialog() == DialogResult.OK)
            {
                if (gameType == MeType.ME3_TYPE)
                {
                    _path = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(selectExe.FileName)));
                }
                else
                {
                    _path = Path.GetDirectoryName(Path.GetDirectoryName(selectExe.FileName));
                }
            }
            if (_path != null)
            {
                _configIni.Write(key, _path, "GameDataPath");
            }
        }