Esempio n. 1
0
        private static void Main(string[] args)
        {
            // Changes the CurrentCulture of the current thread to the invariant
            // culture.
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Setup any per-user folder structer that we need.
            SetupUserFolders();

            List<string> extraArguments = new List<string>();
            try
            {
                bool patch = true;
            #if PERFHUD_BUILD
                patch = false;
            #endif
                bool unhandledArguments = false;
                string logFileOverride = null;
                string updateUrl = null;
                string patchUrl = null;
                bool force_scan = false;
                bool exit_after_patch = false;
                for (int i = 0; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                        case "--noupdate":
                        case "--no_client_update":
                            patch = false;
                            break;
                        case "--update_url":
                            Debug.Assert(i + 1 < args.Length);
                            updateUrl = args[++i];
                            break;
                        case "--patch_url":
                        case "--patcher_url":
                            Debug.Assert(i + 1 < args.Length);
                            patchUrl = args[++i];
                            break;
                        case "--force_scan":
                            force_scan = true;
                            break;
                        // Now handle arguments we want to pass through
                        case "--master":
                        case "--world":
                        case "--login_page":
                        case "--world_settings_file":
                        case "--log_level":
                            Debug.Assert(i + 1 < args.Length);
                            extraArguments.Add(args[i]);
                            extraArguments.Add(args[++i]);
                            break;
                        case "--log_config":
                            Debug.Assert(i + 1 < args.Length);
                            logFileOverride = args[++i];
                            break;
                        default:
                            if (!exit_after_patch)
                                unhandledArguments = true;
                            exit_after_patch = true;
                            break;
                    }
                }

                // initialize logging
                bool interactive = System.Windows.Forms.SystemInformation.UserInteractive;
                string logConfigFile = Path.Combine(ConfigFolder, "LogConfig.xml");
                if (logFileOverride != null)
                    logConfigFile = logFileOverride;
                LogUtil.InitializeLogging(logConfigFile, Path.Combine("..", "DefaultLogConfig.xml"), FallbackLogfile, interactive);

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (string s in args)
                {
                    sb.AppendFormat("{0} ", s);
                }

                log.InfoFormat("Client command line arguments: {0}", sb.ToString());

                if (unhandledArguments)
                    log.Info("Got extra arguments; Will exit after patch if a client patch is required.");

                if (patch)
                {
                    log.Info("Checking if restart required");
                    try
                    {
                        if (Patch(updateUrl, patchUrl, extraArguments.ToArray(), force_scan, exit_after_patch))
                        {
                            log.Info("Restart required");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        LogUtil.ExceptionLog.ErrorFormat("Version determination failed: {0}", e);
                        throw;
                    }
                }

                string errorMessage = null;
                string errorPage = null;

                // this.Hide();
                // this.WindowState = FormWindowState.Minimized;
                // create an instance of the client class and start it up
                // We use the using declaration here so that we dispose of the object
                using (Client client = new Multiverse.Base.Client())
                {
            #if PERFHUD_BUILD
                    client.standalone = true;
                    client.PatchMedia = false;
                    client.Repository = "../../../Media/";
                    // Debug.Assert(false, "Breakpoint for Debug");
            #endif
                    for (int i = 0; i < args.Length; ++i)
                    {
                        switch (args[i])
                        {
                            case "--standalone":
                                client.standalone = true;
                                client.WorldId = "standalone";
                                break;
                            case "--debug":
                                client.doTraceConsole = true;
                                break;
                            case "--simple_terrain":
                                client.simpleTerrain = true;
                                break;
                            case "--config":
                                client.doDisplayConfig = true;
                                break;
                            case "--tocFile":
                                Debug.Assert(i + 1 < args.Length);
                                client.uiModules.Add(args[++i]);
                                break;
                            case "--master":
                                Debug.Assert(i + 1 < args.Length);
                                client.MasterServer = args[++i];
                                break;
                            case "--world":
                            case "--world_id":
                                Debug.Assert(i + 1 < args.Length);
                                client.WorldId = args[++i];
                                break;
                            case "--character":
                                Debug.Assert(i + 1 < args.Length);
                                client.CharacterId = long.Parse(args[++i]);
                                break;
                            case "--login_url":
                                Debug.Assert(i + 1 < args.Length);
                                client.LoginUrl = args[++i];
                                break;
                            case "--login_page":
                                Debug.Assert(i + 1 < args.Length);
                                client.LoginUrl = LoginBase + args[++i];
                                break;
                            case "--noupdate":
                            case "--no_media_update":
                                client.PatchMedia = false;
                                break;
                            case "--world_patcher_url":
                                Debug.Assert(i + 1 < args.Length);
                                log.Warn("--world_patcher_url argument will not be honored by the login patcher");
                                client.WorldPatcherUrl = args[++i];
                                break;
                            case "--world_update_url":
                                Debug.Assert(i + 1 < args.Length);
                                log.Warn("--world_update_url argument will not be honored by the login patcher");
                                client.WorldUpdateUrl = args[++i];
                                break;
                            case "--world_settings_file":
                                Debug.Assert(i + 1 < args.Length);
                                WorldSettingsFile = args[++i];
                                break;
                            case "--logcollisions":
                                client.logCollisions = true;
                                break;
                            case "--frames_between_sleeps":
                                Debug.Assert(i + 1 < args.Length);
                                client.FramesBetweenSleeps = int.Parse(args[++i]);
                                break;
                            case "--log_level":
                                Debug.Assert(i + 1 < args.Length);
                                SetLogLevel(args[++i], false);
                                break;
                            case "--development":
                                client.UseRepository = true;
                                client.FramesBetweenSleeps = 2;
                                client.PatchMedia = false;
                                break;
                            case "--use_default_repository":
                                client.UseRepository = true;
                                client.PatchMedia = false;
                                break;
                            case "--repository_path":
                                client.RepositoryPaths.Add(args[++i]);
                                client.PatchMedia = false;
                                client.UseRepository = true;
                                break;
                            case "--maxfps":
                                client.MaxFPS = int.Parse(args[++i]);
                                break;
                            case "--log_terrain":
                                client.LogTerrainConfig = true;
                                break;
                            case "--coop_input":
                                // Used when running from the debugger
                                client.UseCooperativeInput = true;
                                break;
                            case "--tcp":
                                client.UseTCP = true;
                                break;
                            case "--rdp":
                                client.UseTCP = false;
                                break;
                            case "--display_config":
                                client.manualDisplayConfigString = args[++i];
                                break;
                            case "--fullscreen":
                                client.manualFullscreen = true;
                                break;
                            case "--fixed_fps":
                                client.FixedFPS = int.Parse(args[++i]);
                                break;
                            case "--client_patch_only":
                                return;
                            case "--media_patch_only":
                                client.ExitAfterMediaPatch = true;
                                break;
                            case "--allow_resize":
                                Debug.Assert(i + 1 < args.Length);
                                client.AllowResize = bool.Parse(args[++i]);
                                break;
                            case "--log_config":
                                // this is handled up above, but ignore it here
                                Debug.Assert(i + 1 < args.Length);
                                ++i;
                                break;
                            // These are the arguments used by the patcher
                            case "--no_client_update":
                            case "--force_scan":
                                break;
                            case "--update_url":
                            case "--patch_url":
                            case "--patcher_url":
                                ++i;
                                break;
                            default:
                                // Handle -Dproperty=value arguments
                                if (args[i].StartsWith("-D") && args[i].Contains("="))
                                {
                                    char[] delims = { '=' };
                                    string[] tmp = args[i].Substring(2).Split(delims, 2);
                                    client.SetParameter(tmp[0], tmp[1]);
                                }
                                else
                                {
                                    Console.WriteLine("Invalid argument " + args[i]);
                                }
                                break;
                        }
                    }
                    client.GameWorld = new Multiverse.Base.MarsWorld(client);

                    client.SourceConfig(Path.Combine(ConfigFolder, WorldSettingsFile));
                    try
                    {
                        client.Start();
                    }
                    catch (Exception ex)
                    {
                        LogUtil.ExceptionLog.ErrorFormat("Exiting client due to exception: {0}", ex);
                        errorMessage = ex.Message;
                    }
                    log.Info("Exiting client");
                    if (errorPage == null)
                        errorPage = client.ErrorPage;
                    if (errorMessage == null)
                        errorMessage = client.ErrorMessage;
                } // using client
                bool errorShown = false;
                if (errorPage != null)
                {
                    string fullPath = Path.GetFullPath("../html/" + errorPage);
                    if (File.Exists(fullPath))
                    {
                        Multiverse.Base.HtmlWindow tmp = new Multiverse.Base.HtmlWindow("file://" + fullPath);
                        tmp.Text = "Multiverse Client Error";
                        tmp.ShowDialog();
                        errorShown = true;
                    }
                }
                if (!errorShown && errorMessage != null)
                {
                    Dialog tmp = new Dialog();
                    tmp.TopMost = true;
                    tmp.Text = "Client Shutting Down!";
                    tmp.Message = errorMessage;
                    tmp.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                // call the existing global exception handler
                LogUtil.ExceptionLog.ErrorFormat("Exited client due to exception: {0}", ex);
                Dialog tmp = new Dialog();
                tmp.TopMost = true;
                tmp.Text = "Alert";
                tmp.Message = ex.Message;
                tmp.ShowDialog();
            }
            finally
            {
                log.Info("Cleaning up");
                log.Info("Exiting Client");
                LogManager.Shutdown();
                GC.Collect();
                // Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
                // this.WindowState = FormWindowState.Normal;
                // this.Show();
                Application.Exit();
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            // Changes the CurrentCulture of the current thread to the invariant
            // culture.
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Setup any per-user folder structer that we need.
            SetupUserFolders();

            List <string> extraArguments = new List <string>();

            try
            {
                bool patch = true;
#if PERFHUD_BUILD
                patch = false;
#endif
                bool   unhandledArguments = false;
                string logFileOverride    = null;
                string updateUrl          = null;
                string patchUrl           = null;
                bool   force_scan         = false;
                bool   exit_after_patch   = false;
                for (int i = 0; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                    case "--noupdate":
                    case "--no_client_update":
                        patch = false;
                        break;

                    case "--update_url":
                        Debug.Assert(i + 1 < args.Length);
                        updateUrl = args[++i];
                        break;

                    case "--patch_url":
                    case "--patcher_url":
                        Debug.Assert(i + 1 < args.Length);
                        patchUrl = args[++i];
                        break;

                    case "--force_scan":
                        force_scan = true;
                        break;

                    // Now handle arguments we want to pass through
                    case "--master":
                    case "--world":
                    case "--login_page":
                    case "--world_settings_file":
                    case "--log_level":
                        Debug.Assert(i + 1 < args.Length);
                        extraArguments.Add(args[i]);
                        extraArguments.Add(args[++i]);
                        break;

                    case "--log_config":
                        Debug.Assert(i + 1 < args.Length);
                        logFileOverride = args[++i];
                        break;

                    default:
                        if (!exit_after_patch)
                        {
                            unhandledArguments = true;
                        }
                        exit_after_patch = true;
                        break;
                    }
                }

                // initialize logging
                bool   interactive   = System.Windows.Forms.SystemInformation.UserInteractive;
                string logConfigFile = Path.Combine(ConfigFolder, "LogConfig.xml");
                if (logFileOverride != null)
                {
                    logConfigFile = logFileOverride;
                }
                LogUtil.InitializeLogging(logConfigFile, Path.Combine("..", "DefaultLogConfig.xml"), FallbackLogfile, interactive);

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (string s in args)
                {
                    sb.AppendFormat("{0} ", s);
                }

                log.InfoFormat("Client command line arguments: {0}", sb.ToString());

                if (unhandledArguments)
                {
                    log.Info("Got extra arguments; Will exit after patch if a client patch is required.");
                }

                if (patch)
                {
                    log.Info("Checking if restart required");
                    try
                    {
                        if (Patch(updateUrl, patchUrl, extraArguments.ToArray(), force_scan, exit_after_patch))
                        {
                            log.Info("Restart required");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        LogUtil.ExceptionLog.ErrorFormat("Version determination failed: {0}", e);
                        throw;
                    }
                }

                string errorMessage = null;
                string errorPage    = null;

                // this.Hide();
                // this.WindowState = FormWindowState.Minimized;
                // create an instance of the client class and start it up
                // We use the using declaration here so that we dispose of the object
                using (Client client = new Multiverse.Base.Client())
                {
#if PERFHUD_BUILD
                    client.standalone = true;
                    client.PatchMedia = false;
                    client.Repository = "../../../Media/";
                    // Debug.Assert(false, "Breakpoint for Debug");
#endif
                    for (int i = 0; i < args.Length; ++i)
                    {
                        switch (args[i])
                        {
                        case "--standalone":
                            client.standalone = true;
                            client.WorldId    = "standalone";
                            break;

                        case "--debug":
                            client.doTraceConsole = true;
                            break;

                        case "--simple_terrain":
                            client.simpleTerrain = true;
                            break;

                        case "--config":
                            client.doDisplayConfig = true;
                            break;

                        case "--tocFile":
                            Debug.Assert(i + 1 < args.Length);
                            client.uiModules.Add(args[++i]);
                            break;

                        case "--master":
                            Debug.Assert(i + 1 < args.Length);
                            client.MasterServer = args[++i];
                            break;

                        case "--world":
                        case "--world_id":
                            Debug.Assert(i + 1 < args.Length);
                            client.WorldId = args[++i];
                            break;

                        case "--character":
                            Debug.Assert(i + 1 < args.Length);
                            client.CharacterId = long.Parse(args[++i]);
                            break;

                        case "--login_url":
                            Debug.Assert(i + 1 < args.Length);
                            client.LoginUrl = args[++i];
                            break;

                        case "--login_page":
                            Debug.Assert(i + 1 < args.Length);
                            client.LoginUrl = LoginBase + args[++i];
                            break;

                        case "--noupdate":
                        case "--no_media_update":
                            client.PatchMedia = false;
                            break;

                        case "--world_patcher_url":
                            Debug.Assert(i + 1 < args.Length);
                            log.Warn("--world_patcher_url argument will not be honored by the login patcher");
                            client.WorldPatcherUrl = args[++i];
                            break;

                        case "--world_update_url":
                            Debug.Assert(i + 1 < args.Length);
                            log.Warn("--world_update_url argument will not be honored by the login patcher");
                            client.WorldUpdateUrl = args[++i];
                            break;

                        case "--world_settings_file":
                            Debug.Assert(i + 1 < args.Length);
                            WorldSettingsFile = args[++i];
                            break;

                        case "--logcollisions":
                            client.logCollisions = true;
                            break;

                        case "--frames_between_sleeps":
                            Debug.Assert(i + 1 < args.Length);
                            client.FramesBetweenSleeps = int.Parse(args[++i]);
                            break;

                        case "--log_level":
                            Debug.Assert(i + 1 < args.Length);
                            SetLogLevel(args[++i], false);
                            break;

                        case "--development":
                            client.UseRepository       = true;
                            client.FramesBetweenSleeps = 2;
                            client.PatchMedia          = false;
                            break;

                        case "--use_default_repository":
                            client.UseRepository = true;
                            client.PatchMedia    = false;
                            break;

                        case "--repository_path":
                            client.RepositoryPaths.Add(args[++i]);
                            client.PatchMedia    = false;
                            client.UseRepository = true;
                            break;

                        case "--maxfps":
                            client.MaxFPS = int.Parse(args[++i]);
                            break;

                        case "--log_terrain":
                            client.LogTerrainConfig = true;
                            break;

                        case "--coop_input":
                            // Used when running from the debugger
                            client.UseCooperativeInput = true;
                            break;

                        case "--tcp":
                            client.UseTCP = true;
                            break;

                        case "--rdp":
                            client.UseTCP = false;
                            break;

                        case "--display_config":
                            client.manualDisplayConfigString = args[++i];
                            break;

                        case "--fullscreen":
                            client.manualFullscreen = true;
                            break;

                        case "--fixed_fps":
                            client.FixedFPS = int.Parse(args[++i]);
                            break;

                        case "--client_patch_only":
                            return;

                        case "--media_patch_only":
                            client.ExitAfterMediaPatch = true;
                            break;

                        case "--allow_resize":
                            Debug.Assert(i + 1 < args.Length);
                            client.AllowResize = bool.Parse(args[++i]);
                            break;

                        case "--log_config":
                            // this is handled up above, but ignore it here
                            Debug.Assert(i + 1 < args.Length);
                            ++i;
                            break;

                        // These are the arguments used by the patcher
                        case "--no_client_update":
                        case "--force_scan":
                            break;

                        case "--update_url":
                        case "--patch_url":
                        case "--patcher_url":
                            ++i;
                            break;

                        default:
                            // Handle -Dproperty=value arguments
                            if (args[i].StartsWith("-D") && args[i].Contains("="))
                            {
                                char[]   delims = { '=' };
                                string[] tmp    = args[i].Substring(2).Split(delims, 2);
                                client.SetParameter(tmp[0], tmp[1]);
                            }
                            else
                            {
                                Console.WriteLine("Invalid argument " + args[i]);
                            }
                            break;
                        }
                    }
                    client.GameWorld = new Multiverse.Base.MarsWorld(client);

                    client.SourceConfig(Path.Combine(ConfigFolder, WorldSettingsFile));
                    try
                    {
                        client.Start();
                    }
                    catch (Exception ex)
                    {
                        LogUtil.ExceptionLog.ErrorFormat("Exiting client due to exception: {0}", ex);
                        errorMessage = ex.Message;
                    }
                    log.Info("Exiting client");
                    if (errorPage == null)
                    {
                        errorPage = client.ErrorPage;
                    }
                    if (errorMessage == null)
                    {
                        errorMessage = client.ErrorMessage;
                    }
                } // using client
                bool errorShown = false;
                if (errorPage != null)
                {
                    string fullPath = Path.GetFullPath("../html/" + errorPage);
                    if (File.Exists(fullPath))
                    {
                        Multiverse.Base.HtmlWindow tmp = new Multiverse.Base.HtmlWindow("file://" + fullPath);
                        tmp.Text = "Multiverse Client Error";
                        tmp.ShowDialog();
                        errorShown = true;
                    }
                }
                if (!errorShown && errorMessage != null)
                {
                    Dialog tmp = new Dialog();
                    tmp.TopMost = true;
                    tmp.Text    = "Client Shutting Down!";
                    tmp.Message = errorMessage;
                    tmp.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                // call the existing global exception handler
                LogUtil.ExceptionLog.ErrorFormat("Exited client due to exception: {0}", ex);
                Dialog tmp = new Dialog();
                tmp.TopMost = true;
                tmp.Text    = "Alert";
                tmp.Message = ex.Message;
                tmp.ShowDialog();
            }
            finally
            {
                log.Info("Cleaning up");
                log.Info("Exiting Client");
                LogManager.Shutdown();
                GC.Collect();
                // Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
                // this.WindowState = FormWindowState.Normal;
                // this.Show();
                Application.Exit();
            }
        }