CPlan.W3LF.Loader.RunW3 C# (CSharp) Метод

RunW3() публичный статический Метод

public static RunW3 ( ) : bool
Результат bool
        public static bool RunW3()
#endif
        {
            try
            {
                // Check if war3.exe and w3lh.dll exist.
                try
                {
                    if (!File.Exists(Path.Combine(Settings.W3Path, "war3.exe")))
                    {
                        MessageBox.Show("The given directory does not contain war3.exe, please make sure your registry contains the right information.\r\n\r\nPath: " + Settings.W3Path, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    if (!File.Exists(Path.Combine(Settings.W3Path + "w3lh.dll")))
                    {
                        if (File.Exists(Path.Combine(Environment.CurrentDirectory + "w3lh.dll")))
                        {
                            File.Copy(Path.Combine(Environment.CurrentDirectory + "w3lh.dll"), Path.Combine(Settings.W3Path + "w3lh.dll"));
                        }
                        else
                        {
                            MessageBox.Show("w3lh.dll copy in the directory \"" + Environment.CurrentDirectory + "\\w3lh.dll\" does not exist.\r\nPlease reinstall EuroLoader.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show("The application does not have the rights to either read or write to the source/destination directory.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("w3lh.dll was not found, please reinstall the application.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An unhandled exception was thrown.\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK);
                    return false;
                }
                // Checks the registry for a server.eurobattle.net entry.
                List<string> Entries = new List<string>((string[])Registry.CurrentUser.OpenSubKey("Software\\Blizzard Entertainment\\Warcraft III").GetValue("Battle.net Gateways"));
                //int count = (Entries.Count - 2) / 3;
                int server = 0;
                bool hasServer = false;
                for (int i = 2; i < Entries.Count; i += 3)
                {
                    if (!hasServer) ++server;
                    foreach (Gateway gw in gateways)
                    {
                        if (Entries[i].Equals(gw.Hostname.ToString()) || Entries[i + 2].Equals(gw.Name))
                        {
                            if (!Entries[i].Equals(gw.Hostname.ToString())) Entries[i + 1] = gw.Hostname.ToString();
                            if (!Entries[i + 1].Equals(gw.TimeZone)) Entries[i + 1] = gw.TimeZone.ToString();
                            if (!Entries[i + 2].Equals(gw.Name)) Entries[i + 1] = gw.Name;
                            hasServer = true;
                        }
                    }
                }
                Entries[1] = (server.ToString().Length == 2 ? server.ToString() : "0" + server.ToString());
                Registry.CurrentUser.OpenSubKey("Software\\Blizzard Entertainment\\Warcraft III", true).SetValue("Battle.net Gateways", Entries.ToArray(), RegistryValueKind.MultiString);
                // Checks for the given arguments.
                StartOptions StartOption = Settings.StartupOptions;
                string Args = "";
                if ((StartOption & StartOptions.Window) == StartOptions.Window) Args += " -window ";
                if ((StartOption & StartOptions.OpenGl) == StartOptions.OpenGl) Args += " -opengl ";
                if ((StartOption & StartOptions.SWTNL) == StartOptions.SWTNL) Args += " -swtnl ";
                if ((StartOption & StartOptions.Classic) == StartOptions.Classic) Args += " -classic ";
                string Msg;
                /*
                 * Why Settings.W3Path + "\\war3.exe":
                 *  The command line will not accept one argument.
                 *  Structure:
                 *      <Path of the to-execute application> [arguments]
                 *  If you do:
                 *      -window
                 *  Windows/Warcraft III will think you're starting up -window with no arguments.
                 *  Therefore you must have at least two arguments.
                 */
                switch (DoInject('"' + Path.Combine(Settings.W3Path, "war3.exe") + '"' + Args, Path.Combine(Settings.W3Path, "war3.exe"), out Msg))
                {
                    case 0: if (Msg != null) MessageBox.Show(Msg, "Startup message"); return true; // No error.
                    case 2: MessageBox.Show("Unable to find war3.exe in\r\n" + Msg, "Error", MessageBoxButtons.OK); return false;
                    case 1:
                    default: MessageBox.Show(Msg, "Error", MessageBoxButtons.OK); return false;
                }
            }
            catch (AccessViolationException)
            {
                MessageBox.Show("An exception was thrown: Access Violation.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Loader was unable to find w3l.dll.\r\nReinstalling the application could solve the issue.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("An exception was thrown:\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK);
                return false;
            }
        }
    }

Same methods

Loader::RunW3 ( bool RunGP ) : bool

Usage Example

Пример #1
0
 static void Main()
 {
     // Initializes the variable that keeps the Warcraft III path.
     Settings.InitPath();
     if (Environment.CommandLine.ToLower().Contains("-launch"))
     {
         Loader.RunW3(); return;
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new frmMain());
 }
All Usage Examples Of CPlan.W3LF.Loader::RunW3