예제 #1
0
        public static void Main(string[] args)
        {
            #if !DEBUG && FORCE_MONO
            if (OSUtils.Windows && !OSUtils.IsOnMono())
            {
                Console.WriteLine("Switching to Mono...");
                string pfdir = null;
                if (Directory.Exists(@"C:\Program Files (x86)\"))
                    pfdir = @"C:\Program Files (x86)";
                else
                    pfdir = @"C:\Program Files";
                string monoPath = Path.Combine(pfdir, "Mono-2.10.8", "bin", "mono.exe");
                if (!File.Exists(monoPath))
                {
                    string monodir = null;
                    foreach (string dir in Directory.GetFileSystemEntries(pfdir))
                        if (Path.GetFileName(dir).ToLower().StartsWith("mono-"))
                            monodir = Path.Combine(pfdir, dir);
                    monoPath = Path.Combine(monodir, "bin", "mono.exe");
                }

                if (!string.IsNullOrEmpty(monoPath))
                {
                    try
                    {
                        ProcessStartInfo info = new ProcessStartInfo(monoPath,
                                                                     Resources.ExecutableFileName);
                        info.UseShellExecute = false;
                        info.CreateNoWindow = true;
                        Process.Start(info);
                    } catch (Exception e)
                    {
                        File.WriteAllText("LaunchError.txt",
                                          "MultiMC failed to start. Please report this problem." +
                                          "\nPath: " +
                                          monoPath + "\n" + e.ToString());
                    }
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("Failed to switch to mono.");
                }
            }
            #endif

            if (OSUtils.Linux)
            {
                if (Environment.CurrentDirectory.Equals(Environment.GetEnvironmentVariable("HOME")))
                {
                    string workingDir = Resources.ExecutableFileName;
                    Environment.CurrentDirectory = workingDir;
                    Console.WriteLine("Set working directory to {0}", workingDir);
                }
            }

            Application.Init();

            if (args.Length > 0)
            {
                if (args[0].Equals("-u"))
                {
                    Console.WriteLine("Updating MultiMC...");
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid number of arguments for -u.");
                        Environment.Exit(-1);
                    }
                    else
                    {
                        DoUpdate(args[1]);
                    }
                    Environment.Exit(0);
                }
                else if (args[0].Equals("-v"))
                {
                    Console.WriteLine(AppUtils.GetVersion());
                    return;
                }
                else
                {
                    Console.WriteLine("Unknown argument: " + args[0]);
                }
            }

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledError);

            GLib.ExceptionManager.UnhandledException += (GLib.UnhandledExceptionArgs ueArgs) =>
            {
                OnException(ueArgs.ExceptionObject as Exception);
            };

            if (File.Exists(Resources.NewVersionFileName))
                File.Delete(Resources.NewVersionFileName);

            using (MainWindow win = new MainWindow())
            {
                win.Show();

                Application.Run();
            }

            if (InstallUpdates)
            {
                string currentFile = Resources.ExecutableFileName;
                Console.WriteLine(string.Format("{0} -u \"{1}\"",
                                                Resources.NewVersionFileName, currentFile));
                if (OSUtils.Linux)
                {
                    Process.Start("sudo chmod",
                                  string.Format("+x \"{0}\"", Resources.NewVersionFileName));
                    ProcessStartInfo info =
                        new ProcessStartInfo(Resources.NewVersionFileName,
                                             string.Format("-u \"{0}\"", currentFile));
                    info.UseShellExecute = false;
                    Process.Start(info);
                }
                else
                {
                    Process.Start(Resources.NewVersionFileName,
                                  string.Format("-u \"{0}\"", currentFile));
                }
                Environment.Exit(0);
            }
        }
예제 #2
0
파일: Main.cs 프로젝트: GUIpsp/MultiMC
        public static void Main(string[] args)
        {
            Application.Init();

            if (args.Length > 0)
            {
                if (args[0].Equals("-u"))
                {
                    Console.WriteLine("Updating MultiMC...");
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid number of arguments for -u.");
                        Environment.Exit(-1);
                    }
                    else
                    {
                        DoUpdate(args[1]);
                    }
                    Environment.Exit(0);
                }
                else if (args[0].Equals("-v"))
                {
                    Console.WriteLine(AppUtils.GetVersion());
                    return;
                }
                else
                {
                    Console.WriteLine("Unknown argument: " + args[0]);
                }
            }

            //			AppDomain.CurrentDomain.UnhandledException += (sender, ueArgs) =>
            //			{
            //				if ((ueArgs.ExceptionObject as Exception) != null)
            //					FatalException(ueArgs.ExceptionObject as Exception);
            //				else
            //				{
            //					Console.WriteLine("Fatal error: " + ueArgs.ToString());
            //					Environment.Exit(1);
            //				}
            //			};
            //
            //			GLib.ExceptionManager.UnhandledException += (GLib.UnhandledExceptionArgs ueArgs) =>
            //			{
            //				if ((ueArgs.ExceptionObject as Exception) != null)
            //					FatalException(ueArgs.ExceptionObject as Exception);
            //				else
            //				{
            //					Console.WriteLine("Fatal error: " + ueArgs.ToString());
            //					Environment.Exit(1);
            //				}
            //			};

            if (File.Exists(Resources.NewVersionFileName))
                File.Delete(Resources.NewVersionFileName);

            MainWindow win = new MainWindow();
            win.Show();

            Application.Run();

            if (InstallUpdates)
            {
                string currentFile =
                    new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
                Console.WriteLine(string.Format("-u \"{0}\"", currentFile));

                Process.Start(Resources.NewVersionFileName,
                              string.Format("-u \"{0}\"", currentFile));
            }
        }