示例#1
0
文件: Main.cs 项目: Schumix/Schumix2
        /// <summary>
        ///     A Main függvény. Itt indul el a program.
        /// </summary>
        public static void Main(string[] args)
        {
            sRuntime.SetProcessName(Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().ManifestModule.Name));
            bool help = false;
            string console_encoding = Encoding.UTF8.BodyName;
            string dumpsdir = "Dumps";
            string logsdir = "Logs";
            int loglevel = 3;
            string schumix2dir = "Schumix2";
            string addonsdir = "Addons";
            string configdir = "Configs";
            Console.CursorVisible = false;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

            var os = new OptionSet()
            {
                { "h|?|help", "Display help.", v => help = true },
                { "console-encoding=", "Set up the program's character encoding.", v => console_encoding = v },
                { "dumps-dir=", "Set up the dumps folder's path and name.", v => dumpsdir = v },
                { "logs-dir=", "Set up the logs folder's path and name.", v => dumpsdir = v },
                { "loglevel=", "Log level's setting.", v => loglevel = v.ToInt32() },
                { "schumix2-dir=", "Set up the Schumix2 folder's path and name.", v => schumix2dir = v },
                { "addons-dir=", "Set up the addons folder's path and name.", v => addonsdir = v },
                { "config-dir=", "Set up the config folder's path and name.", v => configdir = v },
            };

            try
            {
                os.Parse(args);

                if(help)
                {
                    ShowHelp(os);
                    return;
                }
            }
            catch(OptionException oe)
            {
                Console.Error.WriteLine("{0} for options '{1}'", oe.Message, oe.OptionName);
                return;
            }

            if(!console_encoding.IsNumber())
                Console.OutputEncoding = Encoding.GetEncoding(console_encoding);
            else
                Console.OutputEncoding = Encoding.GetEncoding(console_encoding.ToInt32());

            sCrashDumper.SetDirectory(dumpsdir);

            Console.Title = "Schumix2 Config";
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("[Config]");
            Console.WriteLine("To shut down the program use the <Ctrl+C> command!");
            Console.WriteLine("Config Version: {0}", sUtilities.GetVersion());
            Console.WriteLine("Website: {0}", Consts.ConfigWebsite);
            Console.WriteLine("Programmed by: {0}", Consts.ConfigProgrammedBy);
            Console.WriteLine("================================================================================"); // 80
            Console.ForegroundColor = ConsoleColor.Gray;

            Log.SetLogLevel(loglevel);
            Log.Initialize("Config.log", logsdir);

            if(!sPlatform.IsWindows)
                Console.WriteLine();

            Log.Notice("Main", "System is starting...");

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Log.LargeError("FATAL ERROR");
                Log.Error("Main", "An unhandled exception has been thrown. ({0})", (eventArgs.ExceptionObject as Exception).Message);
                sCrashDumper.CreateCrashDump(eventArgs.ExceptionObject);
                Shutdown();
            };

            var cbase = new ConfigBase();
            cbase.Clean(schumix2dir, addonsdir, configdir);
            sRuntime.Exit();
        }
示例#2
0
        /// <summary>
        ///     A Main függvény. Itt indul el a program.
        /// </summary>
        public static void Main(string[] args)
        {
            sRuntime.SetProcessName("Config");
            bool   help             = false;
            string console_encoding = Encoding.UTF8.BodyName;
            string dumpsdir         = "Dumps";
            string logsdir          = "Logs";
            int    loglevel         = 3;
            string schumix2dir      = "Schumix2";
            string addonsdir        = "Addons";
            string configdir        = "Configs";

            Console.CursorVisible   = false;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

            var os = new OptionSet()
            {
                { "h|?|help", "Display help.", v => help = true },
                { "console-encoding=", "Set up the program's character encoding.", v => console_encoding = v },
                { "dumps-dir=", "Set up the dumps folder's path and name.", v => dumpsdir = v },
                { "logs-dir=", "Set up the logs folder's path and name.", v => dumpsdir = v },
                { "loglevel=", "Log level's setting.", v => loglevel = v.ToInt32() },
                { "schumix2-dir=", "Set up the Schumix2 folder's path and name.", v => schumix2dir = v },
                { "addons-dir=", "Set up the addons folder's path and name.", v => addonsdir = v },
                { "config-dir=", "Set up the config folder's path and name.", v => configdir = v },
            };

            try
            {
                os.Parse(args);

                if (help)
                {
                    ShowHelp(os);
                    return;
                }
            }
            catch (OptionException oe)
            {
                Console.WriteLine("{0} for options '{1}'", oe.Message, oe.OptionName);
                return;
            }

            if (!console_encoding.IsNumber())
            {
                Console.OutputEncoding = Encoding.GetEncoding(console_encoding);
            }
            else
            {
                Console.OutputEncoding = Encoding.GetEncoding(console_encoding.ToInt32());
            }

            sCrashDumper.SetDirectory(dumpsdir);

            Console.Title           = "Schumix2 Config";
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("[Config]");
            Console.WriteLine("To shut down the program use the <Ctrl+C> command!");
            Console.WriteLine("Config Version: {0}", sUtilities.GetVersion());
            Console.WriteLine("Website: {0}", Consts.ConfigWebsite);
            Console.WriteLine("Programmed by: {0}", Consts.ConfigProgrammedBy);
            Console.WriteLine("================================================================================");             // 80
            Console.ForegroundColor = ConsoleColor.Gray;

            Log.SetLogLevel(loglevel);
            Log.Initialize("Config.log", logsdir);

            if (!sPlatform.IsWindows)
            {
                Console.WriteLine();
            }

            Log.Notice("Main", "System is starting...");

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Log.LargeError("FATAL ERROR");
                Log.Error("Main", "An unhandled exception has been thrown. ({0})", (eventArgs.ExceptionObject as Exception).Message);
                sCrashDumper.CreateCrashDump(eventArgs.ExceptionObject);
                Shutdown();
            };

            var cbase = new ConfigBase();

            cbase.Clean(schumix2dir, addonsdir, configdir);
            sRuntime.Exit();
        }