Esempio n. 1
0
        private void DoUpdateCheck()
        {
            if (updater != null &&
                updater.Running)
            {
                return;
            }

            updater            = new Updater();
            updater.Completed += (sender, e) =>
            {
                MainWindow.Invoke(
                    (sender2, e2) =>
                {
                    updateVersion = updater.NewVersion;
                    if (updateVersion != null &&
                        updater.NewVersion.CompareTo(AppUtils.GetVersion()) > 0)
                    {
                        DownloadNewVersion();
                    }
                });
            };
            Console.WriteLine("Checking for updates...");
            StartTask(updater);
        }
Esempio n. 2
0
        public static void LogError(Exception e, string logFileName = null)
        {
            if (string.IsNullOrEmpty(logFileName))
            {
                logFileName = string.Format("error_{0}-{1}-{2}_{3}.{4}.{5}.txt",
                                            DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year,
                                            DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.AppendLine(string.Format("Error report for {0}", DateTime.Now));
            sb.AppendLine();
            sb.AppendLine(string.Format("Exception type: {0}", e.GetType()));
            sb.AppendLine(string.Format("MultiMC Version: {0}", AppUtils.GetVersion()));
            sb.AppendLine();
            sb.AppendLine("Computer info:");
            sb.AppendLine(string.Format("\tOperating System: {0}", OSUtils.OSName));
            sb.AppendLine(string.Format("\tRuntime: {0}", OSUtils.Runtime.ToString()));
            sb.AppendLine();
            sb.AppendLine("---------- BEGIN STACK TRACE ----------");
            sb.AppendLine(e.ToString());
            sb.AppendLine("----------- END STACK TRACE -----------");

            // Write the data to an error log.
            File.WriteAllText(logFileName, sb.ToString());
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Initialize AppUtils
            AppUtils.Init();

            if (!args.Contains("-v"))
            {
                Console.WriteLine("Operating System: {0}", OSUtils.OS.ToString());
            }

            if (OSUtils.OS == OSEnum.Linux && !args.Contains("-v"))
            {
                if (Environment.CurrentDirectory.Equals(Environment.GetEnvironmentVariable("HOME")))
                {
                    string workingDir = Path.GetDirectoryName(AppUtils.ExecutableFileName);
                    Environment.CurrentDirectory = workingDir;
                    Console.WriteLine("Set working directory to {0}", workingDir);
                }
            }

            if (!File.Exists(AppSettings.Main.JavaPath) ||
                AppSettings.Main.JavaPath == "java")
            {
                Console.WriteLine("Detecting Java path.");
                try
                {
                    AppSettings.Main.AutoDetectJavaPath();
                    AppSettings.Main.Save();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            // -u or --update
            if (args.Length > 0 && (args[0] == "-u" || args[0] == "--update"))
            {
                Console.WriteLine("Updating MultiMC...");
                if (args.Length < 2)
                {
                    Console.WriteLine("Invalid number of arguments for -u.");
                    Environment.Exit(-1);
                }
                else
                {
                    InstallUpdate(args[1]);
                }
                Environment.Exit(0);
            }

            if (args.Contains("-v") || args.Contains("--version"))
            {
                Console.WriteLine(AppUtils.GetVersion());
                return;
            }

            // If we're not on Windows or not using Mono, use GTK#.
            if (OSUtils.OS != OSEnum.Windows ||
                OSUtils.Runtime == Runtime.Mono)
            {
                Toolkit = WindowToolkit.GtkSharp;
            }
            else
            {
                Toolkit = WindowToolkit.WinForms;
            }

            if (args.Contains("--gtk"))
            {
                Toolkit = WindowToolkit.GtkSharp;
            }
            else if (args.Contains("--winforms"))
            {
                Toolkit = WindowToolkit.WinForms;
            }

            Main main = new Main();

            if (args.Length > 0 && (args[0] == "-l" || args[0] == "--launch"))
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Usage: MultiMC --launch <instance name>");
                    return;
                }

                string instName = args[1];

                Console.WriteLine("Launching instance '{0}'", instName);
                main.Run(instName);
            }
            else
            {
                main.Run();
            }

            if (InstallUpdates)
            {
                string currentFile = AppUtils.ExecutableFileName;
                Console.WriteLine(string.Format("{0} -u \"{1}\"",
                                                Properties.Resources.NewVersionFileName,
                                                currentFile));
                if (OSUtils.OS == OSEnum.Linux)
                {
                    Process.Start("gksudo chmod",
                                  string.Format("+x \"{0}\"",
                                                Properties.Resources.NewVersionFileName));
                    ProcessStartInfo info =
                        new ProcessStartInfo(Properties.Resources.NewVersionFileName,
                                             string.Format("-u \"{0}\"", currentFile));
                    info.UseShellExecute = false;
                    Process.Start(info);
                }
                else
                {
                    Process.Start(Properties.Resources.NewVersionFileName,
                                  string.Format("-u \"{0}\"", currentFile));
                }
                Environment.Exit(0);
            }
        }
Esempio n. 4
0
        public Main()
        {
            GUIManager.Create();
            GUIManager.Main.Initialize();

            MainWindow = GUIManager.Main.MainWindow();

            MainWindow.Title = string.Format("MultiMC Beta {0} for {1}",
                                             AppUtils.GetVersion().ToString(2), OSUtils.OSName);

            MainWindow.DefaultPosition = DefWindowPosition.CenterScreen;

            // Main toolbar
            MainWindow.AddInstClicked           += AddInstClicked;
            MainWindow.RefreshClicked           += (o, args) => MainWindow.LoadInstances();
            MainWindow.ViewFolderClicked        += ViewFolderClicked;
            MainWindow.CentralModsFolderClicked += CentralModsClicked;

            MainWindow.SettingsClicked     += SettingsClicked;
            MainWindow.CheckUpdatesClicked += UpdateClicked;

            MainWindow.AboutClicked += AboutClicked;

            // Instance context menu
            MainWindow.InstanceLaunched += LaunchInstance;

            MainWindow.ChangeIconClicked += ChangeIconClicked;
            MainWindow.EditNotesClicked  += EditNotesClicked;

            MainWindow.ManageSavesClicked    += ManageSavesClicked;
            MainWindow.EditModsClicked       += EditModsClicked;
            MainWindow.RebuildJarClicked     += RebuildClicked;
            MainWindow.ViewInstFolderClicked += ViewInstFolderClicked;

            MainWindow.DeleteInstClicked += DeleteInstClicked;
            // on linux, provide the possiblity to nuke OpenAL libs
            if (OSUtils.OS == OSEnum.Linux)
            {
                MainWindow.RemoveOpenALClicked += RemoveOpenALClicked;
            }

            // Try to load the icon list.
            int  tries = 0;
            bool keepTryingToLoadIcons = true;

            customIconLoadError = false;
            while (tries < 2 && keepTryingToLoadIcons)
            {
                try
                {
                    InstIconList         = GUIManager.Main.LoadInstIcons(tries == 0);
                    MainWindow.ImageList = InstIconList;

                    // If none of the above return false, stop trying to load icons.
                    keepTryingToLoadIcons = false;
                }
                catch (ArgumentException)
                {
                    keepTryingToLoadIcons = true;
                    customIconLoadError   = true;
                }
                finally
                {
                    tries++;
                }
            }

            MainWindow.LoadInstances();

            MainWindow.Closed += new EventHandler(MainWindow_Closed);

            // Initialize problem detection
            try
            {
                Console.WriteLine("Initializing problem detection system...");
                ProblemDetection.Problems.InitProblems();
            }
            catch (System.Reflection.ReflectionTypeLoadException e)
            {
                Console.WriteLine("Problem detection failed to initialize:\n{0}", e);
            }
        }