Beispiel #1
0
        static int Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Upgrade application settings across the version increment
            ClassUtils.UpgradeApplicationSettingsIfNecessary();

            // Make sure the application data folder directory exists
            Directory.CreateDirectory(AppHome);

            // Get and process command line arguments
            Arguments commandLine = new Arguments(args);

            // If the processing requested program termination,
            // return using the error code created by that class
            if (ClassCommandLine.Execute(commandLine) == false)
            {
                return(ClassCommandLine.ReturnCode);
            }

            // Check that only one application instance is running
            bool  mAcquired;
            Mutex mAppMutex = new Mutex(true, "gitforce", out mAcquired);

            if (!mAcquired && Properties.Settings.Default.WarnMultipleInstances)
            {
                if (MessageBox.Show("GitForce is already running.\n\nDo you want to open a new instance?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return(-1);
                }
            }

            // Check if the application has been run as Admin/root
            if (ClassUtils.IsAdmin())
            {
                if (MessageBox.Show("GitForce has been run with elevated privileges which is not a recomended way to run it.\n\nDo you still want to continue?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return(-1);
                }
            }

            // Initialize logging and git execute support
            Log = new FormLog();
            Log.ShowWindow(Properties.Settings.Default.ShowLogWindow);

            Git = new ClassGit();

            // Before we can start, we need to have a functional git executable);
            if (Git.Initialize())
            {
                // Initialize external diff program
                Diff = new ClassDiff();
                if (Diff.Initialize())
                {
                    Merge = new ClassMerge();
                    // Initialize external Merge program
                    if (Merge.Initialize())
                    {
                        // Add known text editors
                        Settings.Panels.ControlViewEdit.AddKnownEditors();

                        if (ClassUtils.IsMono())
                        {
                            Ssh = new ClassSSH();           // Instantiate SSH support only on Linux (Mono)
                        }
                        else
                        {
                            Putty = new ClassPutty();         // Instantiate PuTTY support only on Windows
                        }
                        HttpsPasswd = new ClassHttpsPasswd(); // Create HTTPS password helper file
                        Repos       = new ClassRepos();       // Create repository canvas
                        Version     = new ClassVersion();     // Start the new version check process
                        MainForm    = new FormMain();         // Create the main form
                        MainForm.Show();                      // Show the main window so the handles get created
                        if (MainForm.Initialize())            // Load repos, custom tools etc.
                        {
                            DoRefresh();                      // Initial global refresh
                            Application.Run(MainForm);        // Run the main form

                            Properties.Settings.Default.Save();

                            GC.KeepAlive(mAppMutex);
                            return(0);
                        }
                    }
                }
            }
            return(-1);
        }