07-19-2012, 18:53
So this is a method wich just, basically, well what the title says, it says you where MW3 is installed. All is explained in the code and in the end of the post you have an exmaple. All this code is made 99% by me. ( Just searched in google for help )
Example:
You can remake this for any game
Everyone can use this if you want
CSHARP Code
- using System.IO;
- using Microsoft.Win32;
-
- private string MW3Path()
- {
- //this searches the game in the registry (steam)
- RegistryKey regKey = Registry.CurrentUser;
- regKey = regKey.OpenSubKey(@"Software\Valve\Steam");
- bool canFindSteamPath = false;
- string steamInstallPath;
- string MW3Directory = String.Empty;
- //if the registry key exists then we probably know the MW3 directory
- if (regKey != null)
- {
- steamInstallPath = regKey.GetValue("SteamPath").ToString();
- MW3Directory = steamInstallPath + "/steamapps/common/call of duty modern warfare 3";
- //this checks if some needed file exists so the mod can be installed, and if all this exists then we found the MW3 directory
- if (File.Exists(MW3Directory + "/main/iw_00.iwd")) { canFindSteamPath = true; }
- //if it does not exist, then we did not find it
- else { canFindSteamPath = false; }
- }
- else { canFindSteamPath = false; }
- //if we cant find the folder automatically, then a folderbrowserdialog shows up
- if (!canFindSteamPath)
- {
- MessageBox.Show("Cant find Steam path, please select the MW3 folder");
- DialogResult result = MW3Folder.ShowDialog();
- if (result == DialogResult.OK) { MW3Directory = MW3Folder.SelectedPath; }
- //if the user hits cancel in the folderbrowserdialog then the MW3Directory will be NULL
- else { MW3Directory = null; }
- }
- return MW3Directory;
- }
Example:
CSHARP Code
- private void button1_Click(object sender, EventArgs e)
- {
- string MW3Directory = MW3Path();
- if (MW3Directory != null)
- {
- if (Directory.Exists(MW3Directory))
- {
- MessageBox.Show("Your mw3 directory is " + MW3Directory);
- }
- else
- {
- MessageBox.Show("Invalid folder");
- }
- }
- else
- {
- MessageBox.Show("You didnt select any folder");
- }
- }
You can remake this for any game
Everyone can use this if you want