This class implements the version related functions. It also checks for a new version of the program off the web.
コード例 #1
0
        public FormAbout()
        {
            InitializeComponent();
            ClassWinGeometry.Restore(this);

            // Add the version number and the build date from the assembly info file
            labelVersion.Text = "Version " + ClassVersion.GetVersion();
            labelBuild.Text   = ClassVersion.GetBuild();

            // If there is a new version available, show the label and a button
            labelNewVersionAvailable.Visible = btDownload.Visible = App.Version.NewVersionAvailable;

            textLic.Text =
                "THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " +
                "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," +
                "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " +
                "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " +
                "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, " +
                "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN " +
                "THE SOFTWARE.";
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: orf53975/GitForce
        /// <summary>
        /// This is the main entry point to the application main form.
        /// </summary>
        public FormMain()
        {
            InitializeComponent();
            ClassWinGeometry.Restore(this);

            // Initialize panels
            // Left panel:
            splitContainer2.Panel1.Controls.Add(PanelView);
            PanelView.Dock = DockStyle.Fill;

            // Right set of panels:
            foreach (var panel in PanelsR)
            {
                var tabPage = new TabPage(panel.Key)
                {
                    Name = panel.Key, Tag = panel.Key, ToolTipText = panel.Key + " (" + PanelsRShortcuts[panel.Key] + ")"
                };
                panel.Value.Dock = DockStyle.Fill;
                tabPage.Controls.Add(panel.Value);
                rightTabControl.TabPages.Add(tabPage);
            }

            // Show or hide command line
            menuViewCommandLine.Checked = cmdBox.Visible = Properties.Settings.Default.ShowCommandLine;

            UpdateRightPaneTabsShowState();

            // Enable SSH only if the PuTTY support class has been instantiated
            if (App.Putty != null)
            {
                btSsh.Enabled = true;
                menuMainManageKeys.Enabled = true;
            }

            // We prevent Log window form closing by getting a FormClosing event within which we set "e.Cancel" to True
            App.Log.FormClosing      += LogWindowToolStripMenuItemClick;
            menuViewLogWindow.Checked = Properties.Settings.Default.ShowLogWindow;

            // Add all callback handlers
            App.Refresh            += FormMainRefresh; // Refresh, when any component wants to update the global state
            App.PrintStatusMessage += PrintStatus;     // Print a line of status message
            App.StatusBusy         += SetBusy;         // Busy flag set or reset

            // Register toolbar file buttons with the View panel
            PanelView.RegisterToolstripFileButtons(new Dictionary
                                                   <PanelView.FileOps, ToolStripButton>
            {
                { PanelView.FileOps.Add, btAdd },
                { PanelView.FileOps.Update, btUpdate },
                { PanelView.FileOps.UpdateAll, btUpdateAll },
                { PanelView.FileOps.Revert, btRevert },
                { PanelView.FileOps.Delete, btDelete },
                { PanelView.FileOps.DeleteFs, btDeleteFs },
                { PanelView.FileOps.Edit, btEdit }
            });

            PrintStatus("GitForce version " + ClassVersion.GetVersion(), MessageType.General);

            // Arm the timer that will check for the result of the new version test
            // Since the network access, implemented in ClassVersion, can take some time to
            // provide with the version check result, we will simply repaint our icon after a delay
            Timer versionCheckTimer = new Timer {
                Interval = 10000, Enabled = true
            };

            versionCheckTimer.Tick += VersionCheckTimerTick;
        }
コード例 #3
0
ファイル: ClassCommandLine.cs プロジェクト: pausan/GitForce
        /// <summary>
        /// The main execution function for command line arguments.
        /// Returns 'false' if the main program should not continue with the execution, in which
        /// case ReturnCode contains the return code to return to the OS.
        /// </summary>
        public static bool Execute(Arguments commandLine)
        {
            // WAR: On Windows, re-attach the console so we can print. Mono does not need that to use Console class.
            if (!ClassUtils.IsMono())
            {
                NativeMethods.AttachConsole();
                Console.WriteLine(Environment.NewLine);
            }

            if (commandLine["help"] == "true" || commandLine["?"] == "true")
            {
                Console.WriteLine(Environment.NewLine +
                                  "GitForce optional arguments:" + Environment.NewLine +
                                  "  --version             Show the application version number." + Environment.NewLine +
                                  "  --reset-windows       Reset stored locations of windows and dialogs." + Environment.NewLine +
                                  "  --reset-config        Reset program configuration (repos etc.)." + Environment.NewLine +
                                  "  --log                 Logs debug output to file." + Environment.NewLine);
                ReturnCode  = 0;
                runGitForce = false;
            }

            // --version Show the application version number and quit
            if (commandLine["version"] == "true")
            {
                Console.WriteLine("GitForce version " + ClassVersion.GetVersion());
                ReturnCode  = 0;
                runGitForce = false;
            }

            // --reset-windows  Reset stored locations and sizes of all windows and dialogs
            if (commandLine["reset-windows"] == "true")
            {
                Properties.Settings.Default.WindowsGeometries = new StringCollection();
                Properties.Settings.Default.Save();
                Console.WriteLine("GitForce windows and dialogs geometries have been reset.");
                ReturnCode  = 0;
                runGitForce = true;
            }

            // --reset-config   Reset stored configuration items (repos, settings)
            if (commandLine["reset-config"] == "true")
            {
                List <string> toWhack = new List <string>();

                // This is very much dependent on the platform, load a list of directories to whack appropriately
                if (ClassUtils.IsMono())
                {
                    string home = Environment.GetEnvironmentVariable("HOME");
                    if (!string.IsNullOrEmpty(home))
                    {
                        toWhack.Add(Path.Combine(home, ".config/GitForce"));
                        toWhack.Add(Path.Combine(home, ".local/share/GitForce"));
                    }
                }
                else
                {
                    toWhack.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GitForce"));
                    toWhack.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GitForce"));
                }
                // Now that we have a list of directories to remove, delete them
                foreach (var dir in toWhack)
                {
                    DirectoryInfo dirInfo = new DirectoryInfo(dir);
                    if (ClassUtils.DeleteFolder(dirInfo, false, false) == false)
                    {
                        Console.Write("Unable to delete some files!");
                    }
                }
                Console.WriteLine("Configuration has been reset.");
                ReturnCode  = 0;
                runGitForce = false;
            }

            // --log   Create a log file and append all debug log messages to it
            if (commandLine["log"] == "true")
            {
                App.AppLog = Path.Combine(App.AppHome, "gitforce.log");
                File.WriteAllText(App.AppLog, "Log created on " + DateTime.Now.ToShortDateString() + Environment.NewLine);
                Console.WriteLine("Logging: " + App.AppLog);
            }

            // --passwd  This is not a user option. It is used when the app is called to provide password echoed on a command line.
            if (commandLine["passwd"] == "true")
            {
                ReturnCode = -1;
                FormHttpsAuth httpsAuth = new FormHttpsAuth(false);
                if (httpsAuth.ShowDialog() == DialogResult.OK)
                {
                    Console.WriteLine(httpsAuth.Password);
                    ReturnCode = 0;
                }
                runGitForce = false;
            }

            // WAR: On Windows, detach the console when we are done. Mono does not need that to use Console class.
            if (!ClassUtils.IsMono())
            {
                NativeMethods.FreeConsole();
            }

            return(runGitForce);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: runt18/GitForce
        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.\nDo you want to open a new instance?", "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();

                        // Instantiate PuTTY support only on Windows OS
                        if (!ClassUtils.IsMono())
                            Putty = new ClassPutty();

                        GitPasswd = new ClassGitPasswd();   // 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
                        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;
        }
コード例 #5
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);
        }