Пример #1
0
        private bool CalculateLocalBranch(string remote, out string curLocalBranch, out string curRemoteBranch)
        {
            if (IsPullAll())
            {
                curLocalBranch  = null;
                curRemoteBranch = null;
                return(true);
            }

            curRemoteBranch = Branches.Text;

            if (DetachedHeadParser.IsDetachedHead(_branch))
            {
                curLocalBranch = null;
                return(true);
            }

            var currentBranchRemote = new Lazy <string>(() => Module.GetSetting(string.Format(SettingKeyString.BranchRemote, localBranch.Text)));

            if (_branch == localBranch.Text)
            {
                if (remote == currentBranchRemote.Value || string.IsNullOrEmpty(currentBranchRemote.Value))
                {
                    curLocalBranch = string.IsNullOrEmpty(Branches.Text) ? null : _branch;
                }
                else
                {
                    curLocalBranch = localBranch.Text;
                }
            }
            else
            {
                curLocalBranch = localBranch.Text;
            }

            if (string.IsNullOrEmpty(Branches.Text) && !string.IsNullOrEmpty(curLocalBranch) &&
                remote != currentBranchRemote.Value && !Fetch.Checked)
            {
                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = Handle,
                          Text               = string.Format(_noRemoteBranchMainInstruction.Text, remote),
                          Caption            = _noRemoteBranchCaption.Text,
                          InstructionText    = _noRemoteBranch.Text,
                          StandardButtons    = TaskDialogStandardButtons.Cancel,
                          Icon               = TaskDialogStandardIcon.Information,
                          FooterCheckBoxText = _dontShowAgain.Text,
                          FooterIcon         = TaskDialogStandardIcon.Information,
                          StartupLocation    = TaskDialogStartupLocation.CenterOwner,
                          Cancelable         = false
                      };

                var btnPullFrom = new TaskDialogCommandLink("PullFrom", null, string.Format(_noRemoteBranchButton.Text, remote + "/" + curLocalBranch));
                btnPullFrom.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                dialog.Controls.Add(btnPullFrom);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            if (string.IsNullOrEmpty(Branches.Text) && !string.IsNullOrEmpty(curLocalBranch) && Fetch.Checked)
            {
                // if local branch eq to current branch and remote branch is not specified
                // then run fetch with no refspec
                if (_branch == curLocalBranch)
                {
                    curLocalBranch = null;
                    return(true);
                }

                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = Handle,
                          Text            = string.Format(_noRemoteBranchForFetchMainInstruction.Text, remote),
                          Caption         = _noRemoteBranchCaption.Text,
                          InstructionText = _noRemoteBranch.Text,
                          StandardButtons = TaskDialogStandardButtons.Cancel,
                          Icon            = TaskDialogStandardIcon.Information,
                          StartupLocation = TaskDialogStartupLocation.CenterOwner,
                          Cancelable      = false
                      };

                var btnPullFrom = new TaskDialogCommandLink("PullFrom", null, string.Format(_noRemoteBranchForFetchButton.Text, remote + "/" + curLocalBranch));
                btnPullFrom.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                dialog.Controls.Add(btnPullFrom);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        private static bool LocateMissingGit()
        {
            int dialogResult = -1;

            using var dialog1 = new TaskDialog
                  {
                      InstructionText = ResourceManager.Strings.GitExecutableNotFound,
                      Icon            = TaskDialogStandardIcon.Error,
                      StandardButtons = TaskDialogStandardButtons.Cancel,
                      Cancelable      = true,
                  };
            var btnFindGitExecutable = new TaskDialogCommandLink("FindGitExecutable", null, ResourceManager.Strings.FindGitExecutable);

            btnFindGitExecutable.Click += (s, e) =>
            {
                dialogResult = 0;
                dialog1.Close();
            };
            var btnInstallGitInstructions = new TaskDialogCommandLink("InstallGitInstructions", null, ResourceManager.Strings.InstallGitInstructions);

            btnInstallGitInstructions.Click += (s, e) =>
            {
                dialogResult = 1;
                dialog1.Close();
            };
            dialog1.Controls.Add(btnFindGitExecutable);
            dialog1.Controls.Add(btnInstallGitInstructions);

            dialog1.Show();
            switch (dialogResult)
            {
            case 0:
            {
                using (var dialog = new OpenFileDialog
                    {
                        Filter = @"git.exe|git.exe|git.cmd|git.cmd",
                    })
                {
                    if (dialog.ShowDialog(null) == DialogResult.OK)
                    {
                        AppSettings.GitCommandValue = dialog.FileName;
                    }

                    if (CheckSettingsLogic.SolveGitCommand())
                    {
                        return(true);
                    }
                }

                return(false);
            }

            case 1:
            {
                Process.Start(@"https://github.com/gitextensions/gitextensions/wiki/Application-Dependencies#git");
                return(false);
            }

            default:
            {
                return(false);
            }
            }
        }
Пример #3
0
        private (AppSettings.PullAction pullAction, bool forcePush) AskForAutoPullOnPushRejectedAction(IWin32Window owner)
        {
            bool forcePush = false;

            AppSettings.PullAction?onRejectedPullAction = AppSettings.AutoPullOnPushRejectedAction;
            if (onRejectedPullAction == null)
            {
                string destination = _NO_TRANSLATE_Remotes.Text;
                string pullDefaultButtonText;
                switch (AppSettings.DefaultPullAction)
                {
                case AppSettings.PullAction.Fetch:
                case AppSettings.PullAction.FetchAll:
                case AppSettings.PullAction.FetchPruneAll:
                    pullDefaultButtonText = string.Format(_pullDefaultButton.Text, _pullActionFetch.Text);
                    break;

                case AppSettings.PullAction.Merge:
                    pullDefaultButtonText = string.Format(_pullDefaultButton.Text, _pullActionMerge.Text);
                    break;

                case AppSettings.PullAction.Rebase:
                    pullDefaultButtonText = string.Format(_pullDefaultButton.Text, _pullActionRebase.Text);
                    break;

                default:
                    pullDefaultButtonText = string.Format(_pullDefaultButton.Text, _pullActionNone.Text);
                    break;
                }

                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = owner.Handle,
                          Text               = _pullRepository.Text,
                          InstructionText    = _pullRepositoryMainInstruction.Text,
                          Caption            = string.Format(_pullRepositoryCaption.Text, destination),
                          StandardButtons    = TaskDialogStandardButtons.Cancel,
                          Icon               = TaskDialogStandardIcon.Error,
                          FooterCheckBoxText = _dontShowAgain.Text,
                          FooterIcon         = TaskDialogStandardIcon.Information,
                          StartupLocation    = TaskDialogStartupLocation.CenterOwner,
                          Cancelable         = true
                      };
                var btnPullDefault = new TaskDialogCommandLink("PullDefault", null, pullDefaultButtonText);
                btnPullDefault.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                var btnPullRebase = new TaskDialogCommandLink("PullRebase", null, _pullRebaseButton.Text);
                btnPullRebase.Click += (s, e) =>
                {
                    dialogResult = 1;
                    dialog.Close();
                };
                var btnPullMerge = new TaskDialogCommandLink("PullMerge", null, _pullMergeButton.Text);
                btnPullMerge.Click += (s, e) =>
                {
                    dialogResult = 2;
                    dialog.Close();
                };
                var btnPushForce = new TaskDialogCommandLink("PushForce", null, _pushForceButton.Text);
                btnPushForce.Click += (s, e) =>
                {
                    dialogResult = 3;
                    dialog.Close();
                };
                dialog.Controls.Add(btnPullDefault);
                dialog.Controls.Add(btnPullRebase);
                dialog.Controls.Add(btnPullMerge);
                dialog.Controls.Add(btnPushForce);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    onRejectedPullAction = AppSettings.PullAction.Default;
                    break;

                case 1:
                    onRejectedPullAction = AppSettings.PullAction.Rebase;
                    break;

                case 2:
                    onRejectedPullAction = AppSettings.PullAction.Merge;
                    break;

                case 3:
                    forcePush = true;
                    break;

                default:
                    onRejectedPullAction = AppSettings.PullAction.None;
                    break;
                }

                if (dialog.FooterCheckBoxChecked == true)
                {
                    AppSettings.AutoPullOnPushRejectedAction = onRejectedPullAction;
                }
            }

            return(onRejectedPullAction ?? AppSettings.PullAction.None, forcePush);
        }
Пример #4
0
        public DialogResult PullChanges(IWin32Window owner)
        {
            if (!ShouldPullChanges())
            {
                return(DialogResult.No);
            }

            UpdateSettingsDuringPull();

            DialogResult dr = ShouldRebaseMergeCommit();

            if (dr != DialogResult.Yes)
            {
                return(dr);
            }

            if (!Fetch.Checked && string.IsNullOrWhiteSpace(Branches.Text) && Module.IsDetachedHead())
            {
                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = owner.Handle,
                          Text            = _notOnBranch.Text,
                          InstructionText = Strings.ErrorInstructionNotOnBranch,
                          Caption         = Strings.ErrorCaptionNotOnBranch,
                          StandardButtons = TaskDialogStandardButtons.Cancel,
                          Icon            = TaskDialogStandardIcon.Error,
                          Cancelable      = true,
                      };
                var btnCheckout = new TaskDialogCommandLink("Checkout", null, Strings.ButtonCheckoutBranch);
                btnCheckout.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                var btnContinue = new TaskDialogCommandLink("Continue", null, Strings.ButtonContinue);
                btnContinue.Click += (s, e) =>
                {
                    dialogResult = 1;
                    dialog.Close();
                };
                dialog.Controls.Add(btnCheckout);
                dialog.Controls.Add(btnContinue);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    if (!UICommands.StartCheckoutBranch(owner))
                    {
                        return(DialogResult.Cancel);
                    }

                    break;

                case -1:
                    return(DialogResult.Cancel);
                }
            }

            if (PullFromUrl.Checked && Directory.Exists(comboBoxPullSource.Text))
            {
                var path = comboBoxPullSource.Text;
                ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(path));
            }

            var source = CalculateSource();

            if (!CalculateLocalBranch(source, out var curLocalBranch, out var curRemoteBranch))
            {
                return(DialogResult.No);
            }

            executeBeforeScripts();

            var stashed = CalculateStashedValue(owner);

            using (var form = CreateFormProcess(source, curLocalBranch, curRemoteBranch))
            {
                if (!IsPullAll())
                {
                    form.Remote = source;
                }

                form.ShowDialog(owner);
                ErrorOccurred = form.ErrorOccurred();

                bool executeScripts = false;
                try
                {
                    bool aborted = form.DialogResult == DialogResult.Abort;
                    executeScripts = !aborted && !ErrorOccurred;

                    if (!aborted && !Fetch.Checked)
                    {
                        if (!ErrorOccurred)
                        {
                            if (!InitModules())
                            {
                                UICommands.UpdateSubmodules(owner);
                            }
                        }
                        else
                        {
                            executeScripts |= CheckMergeConflictsOnError();
                        }
                    }
                }
                finally
                {
                    if (stashed)
                    {
                        PopStash();
                    }

                    if (executeScripts)
                    {
                        executeAfterScripts();
                    }
                }
            }

            return(DialogResult.OK);

            bool ShouldPullChanges()
            {
                if (PullFromUrl.Checked && string.IsNullOrEmpty(comboBoxPullSource.Text))
                {
                    MessageBox.Show(this, _selectSourceDirectory.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text) && !IsPullAll())
                {
                    MessageBox.Show(this, _selectRemoteRepository.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                if (!Fetch.Checked && Branches.Text == "*")
                {
                    MessageBox.Show(this, _fetchAllBranchesCanOnlyWithFetch.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                return(true);
            }

            string CalculateSource()
            {
                if (PullFromUrl.Checked)
                {
                    return(comboBoxPullSource.Text);
                }

                LoadPuttyKey();
                return(IsPullAll() ? "--all" : _NO_TRANSLATE_Remotes.Text);
            }

            bool InitModules()
            {
                if (!File.Exists(_fullPathResolver.Resolve(".gitmodules")))
                {
                    return(false);
                }

                if (!IsSubmodulesInitialized())
                {
                    if (AskIfSubmodulesShouldBeInitialized())
                    {
                        UICommands.StartUpdateSubmodulesDialog(this);
                    }

                    return(true);
                }

                return(false);

                bool IsSubmodulesInitialized()
                {
                    // Fast submodules check
                    return(Module.GetSubmodulesLocalPaths()
                           .Select(submoduleName => Module.GetSubmodule(submoduleName))
                           .All(submodule => submodule.IsValidGitWorkingDir()));
                }

                bool AskIfSubmodulesShouldBeInitialized()
                {
                    return(MessageBox.Show(this, _questionInitSubmodules.Text, _questionInitSubmodulesCaption.Text,
                                           MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                }
            }

            bool CheckMergeConflictsOnError()
            {
                // Rebase failed -> special 'rebase' merge conflict
                if (Rebase.Checked && Module.InTheMiddleOfRebase())
                {
                    return(UICommands.StartTheContinueRebaseDialog(owner));
                }
                else if (Module.InTheMiddleOfAction())
                {
                    return(MergeConflictHandler.HandleMergeConflicts(UICommands, owner));
                }

                return(false);
            }

            void PopStash()
            {
                if (ErrorOccurred || Module.InTheMiddleOfAction())
                {
                    return;
                }

                bool?messageBoxResult = AppSettings.AutoPopStashAfterPull;

                if (messageBoxResult is null)
                {
                    using var dialog = new TaskDialog
                          {
                              OwnerWindowHandle = owner.Handle,
                              Text               = _applyStashedItemsAgain.Text,
                              Caption            = _applyStashedItemsAgainCaption.Text,
                              StandardButtons    = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No,
                              Icon               = TaskDialogStandardIcon.Information,
                              FooterCheckBoxText = _dontShowAgain.Text,
                              FooterIcon         = TaskDialogStandardIcon.Information,
                              StartupLocation    = TaskDialogStartupLocation.CenterOwner,
                          };

                    messageBoxResult = dialog.Show() == TaskDialogResult.Yes;

                    if (dialog.FooterCheckBoxChecked == true)
                    {
                        AppSettings.AutoPopStashAfterPull = messageBoxResult;
                    }
                }

                if ((bool)messageBoxResult)
                {
                    UICommands.StashPop(owner);
                }
            }

            void executeBeforeScripts()
            {
                // Request to pull/merge in addition to the fetch
                if (!Fetch.Checked)
                {
                    ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull);
                }

                ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch);
            }

            void executeAfterScripts()
            {
                ScriptManager.RunEventScripts(this, ScriptEvent.AfterFetch);

                // Request to pull/merge in addition to the fetch
                if (!Fetch.Checked)
                {
                    ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull);
                }
            }
        }
Пример #5
0
        public void FirstInstall()
        {
            Enable(false);
            RegistryKey reg = ParentalControlsRegistry.GetRegistryKey();

            reg.SetValue("Path", Application.StartupPath, RegistryValueKind.String);
            reg.SetValue("AlarmFile", Application.StartupPath + @"\" + ALARMS_FILE);

            TaskDialog dialog = new TaskDialog();

            dialog.Caption         = Application.ProductName + " Setup";
            dialog.InstructionText = Application.ProductName + " is mostly setup!";
            dialog.Text            = "What you need to do is setup a password for any cases that you need to force close an alarm.";

            TaskDialogButton button = new TaskDialogButton("btnOne", "Continue");

            button.Click += (aa, ab) =>
            {
                TaskDialogButton tdb = (TaskDialogButton)aa;
                ((TaskDialog)tdb.HostingDialog).Close(TaskDialogResult.Ok);

                if (file2.ParentalControlsCredentials.Count > 0)
                {
                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text            = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();

                    return;
                }

                NetworkCredential cred = null;
                WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm.", out cred);
                while (cred == null || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                {
                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm. (Credentials must not be empty)", out cred);
                }
                ParentalControlsCredential c;
                try
                {
                    c = (ParentalControlsCredential)cred;
                    c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    file2.Add(c);
                    file2.Save();
                }
                catch {  }
                TaskDialog ndialog = new TaskDialog();
                ndialog.Caption         = Application.ProductName + " Setup";
                ndialog.InstructionText = "Want to test your credentials?";
                ndialog.FooterText      = "Fun Fact: You can create as many accounts as you want!";
                ndialog.FooterIcon      = TaskDialogStandardIcon.Information;

                TaskDialogCommandLink linka = new TaskDialogCommandLink("linkA", "Test Credentials");

                linka.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.Yes);

                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                    c = new ParentalControlsCredential();
                    try
                    {
                        c = (ParentalControlsCredential)cred;
                        c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    }
                    catch { }

                    bool wevalidated = true;

                    while (cred == null || !file2.Validate(c) || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                    {
                        TaskDialog ddialog = new TaskDialog();

                        ddialog.InstructionText = "Credentials Invalid";
                        ddialog.Text            = "You want to stop testing credentials?";

                        ddialog.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;

                        if (ddialog.Show() == TaskDialogResult.Yes)
                        {
                            wevalidated = false;
                            break;
                        }
                        else
                        {
                            WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                        }
                    }
                    TaskDialog dadialog = new TaskDialog();
                    if (wevalidated)
                    {
                        dadialog.InstructionText = "Credentials Valid!";
                    }
                    else
                    {
                        dadialog.InstructionText = "Setup Complete!";
                    }
                    dadialog.Text = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                TaskDialogCommandLink linkb = new TaskDialogCommandLink("linkB", "Skip Test");

                linkb.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.No);

                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text            = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                ndialog.Controls.Add(linka);
                ndialog.Controls.Add(linkb);

                ndialog.Show();
                file2.Save();
            };
            dialog.Controls.Add(button);

            dialog.Show();
            Enable(true);
            // Kind of an hacky way of making this window get focused after showing dialogs.
            SwitchToSelf();
        }
Пример #6
0
        internal static void checkForUpdate(object sender, EventArgs e)
        {
            try {
                var client = new WebClientWithTimeout();

                Uri StringToUri = new Uri("http://launcher.soapboxrace.world/checkUpdate.php?version=" + Application.ProductVersion);
                client.CancelAsync();
                client.DownloadStringAsync(StringToUri);
                client.DownloadStringCompleted += (sender2, e2) => {
                    try {
                        CheckVersion json = JsonConvert.DeserializeObject <CheckVersion>(e2.Result);

                        if (json.update.info == true)
                        {
                            IniFile SettingFile = new IniFile("Settings.ini");
                            if (SettingFile.Read("IgnoreUpdateVersion") != json.github_build)
                            {
                                TaskDialog dia = new TaskDialog();
                                dia.Caption               = "Update";
                                dia.InstructionText       = "An update is available!";
                                dia.DetailsExpanded       = true;
                                dia.Icon                  = TaskDialogStandardIcon.Information;
                                dia.DetailsCollapsedLabel = "Show Changelog";
                                dia.Text                  = "An update is available. Do you wanna download it?\nYour version: " + Application.ProductVersion + "\nUpdated version: " + json.github_build;
                                dia.DetailsExpandedText   = new WebClientWithTimeout().DownloadString("https://launcher.soapboxrace.world/changelog/text.php");
                                dia.ExpansionMode         = TaskDialogExpandedDetailsLocation.ExpandFooter;

                                TaskDialogCommandLink update     = new TaskDialogCommandLink("update", "Yes", "Launcher will be updated to " + json.github_build + ".");
                                TaskDialogCommandLink cancel     = new TaskDialogCommandLink("cancel", "No", "Launcher will ask for update on next launch.");
                                TaskDialogCommandLink skipupdate = new TaskDialogCommandLink("skipupdate", "Ignore", "This update will be skipped. Will ask again if new update will appear");

                                update.UseElevationIcon = true;

                                skipupdate.Click += (sender3, e3) => {
                                    SettingFile.Write("IgnoreUpdateVersion", json.github_build);
                                    dia.Close();
                                };

                                cancel.Click += (sender3, e3) => {
                                    dia.Close();
                                };

                                update.Click += (sender3, e3) => {
                                    if (File.Exists("GL_Update.exe"))
                                    {
                                        Process.Start(@"GL_Update.exe", Process.GetCurrentProcess().Id.ToString());
                                    }
                                    else
                                    {
                                        Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases/latest");
                                    }

                                    dia.Close();
                                };

                                dia.Controls.Add(update);
                                dia.Controls.Add(cancel);
                                dia.Controls.Add(skipupdate);

                                dia.Show();

                                //new UpdatePopup(json.github_build).Show();
                            }
                        }
                        else
                        {
                            try {
                                if (((Form)sender).Name == "mainScreen")
                                {
                                }
                            } catch {
                                MessageBox.Show("Your launcher is up-to-date");
                            }
                        }
                    } catch {
                        try {
                            if (((Form)sender).Name == "mainScreen")
                            {
                            }
                        } catch {
                            MessageBox.Show("Failed to check for update");
                        }
                    }
                };
            } catch {
                MessageBox.Show("Failed to check for update");
            }
        }
Пример #7
0
        internal static void CheckForUpdate(object sender, EventArgs e)
        {
            try
            {
                var client = new WebClientWithTimeout();

                var uri = new Uri(Self.mainserver + "/launcher/update?version=" + Application.ProductVersion);
                client.CancelAsync();
                client.DownloadStringAsync(uri);
                client.DownloadStringCompleted += (sender2, e2) =>
                {
                    try
                    {
                        var json = JsonConvert.DeserializeObject <UpdateCheckResponse>(e2.Result);

                        if (json.Code != 0)
                        {
                            MessageBox.Show("Launchpad update service returned an error: " + json.Code);
                            return;
                        }

                        if (json.Payload.UpdateExists)
                        {
                            var settingFile = new IniFile("Settings.ini");
                            if (settingFile.Read("IgnoreUpdateVersion") != json.Payload.LatestVersion)
                            {
                                var dia = new TaskDialog
                                {
                                    Caption               = "Update",
                                    InstructionText       = "An update is available!",
                                    DetailsExpanded       = true,
                                    Icon                  = TaskDialogStandardIcon.Information,
                                    DetailsCollapsedLabel = "Show Changelog",
                                    Text                  = "An update is available. Do you want to download it?\nYour version: " +
                                                            Application.ProductVersion + "\nUpdated version: " + json.Payload.LatestVersion,
                                    DetailsExpandedText =
                                        new WebClientWithTimeout().DownloadString(Self.mainserver + "/launcher/changelog"),
                                    ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter
                                };

                                var update     = new TaskDialogCommandLink("update", "Yes", "Launcher will be updated to " + json.Payload.LatestVersion + ".");
                                var cancel     = new TaskDialogCommandLink("cancel", "No", "Launcher will ask you to update on the next launch.");
                                var skipupdate = new TaskDialogCommandLink("skipupdate", "Ignore", "This update will be skipped. A new prompt will apear as soon as a newer update is available.");

                                update.UseElevationIcon = true;

                                skipupdate.Click += (sender3, e3) =>
                                {
                                    settingFile.Write("IgnoreUpdateVersion", json.Payload.LatestVersion);
                                    dia.Close();
                                };

                                cancel.Click += (sender3, e3) =>
                                {
                                    dia.Close();
                                };

                                update.Click += (sender3, e3) =>
                                {
                                    if (File.Exists("GameLauncherUpdater.exe"))
                                    {
                                        Process.Start(@"GameLauncherUpdater.exe", Process.GetCurrentProcess().Id.ToString());
                                    }
                                    else
                                    {
                                        Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases/latest");
                                    }

                                    dia.Close();
                                };

                                dia.Controls.Add(update);
                                dia.Controls.Add(cancel);
                                dia.Controls.Add(skipupdate);

                                dia.Show();

                                //new UpdatePopup(json.github_build).Show();
                            }
                        }
                        else
                        {
                            try
                            {
                                if (((Form)sender).Name == "mainScreen")
                                {
                                }
                            }
                            catch
                            {
                                MessageBox.Show("Your launcher is up-to-date");
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            if (((Form)sender).Name == "mainScreen")
                            {
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Failed to check for update!");
                        }
                    }
                };
            }
            catch
            {
                MessageBox.Show("Failed to check for update!");
            }
        }
Пример #8
0
        private void FrmSqlWorksheet_FormClosing(object sender, FormClosingEventArgs e)
        {
            // If there are no modifications to the worksheet, exit
            if (!IsModified || CloseAction.Instance.OnCloseSaveAction == OnCloseSaveAction.DiscardAll)
            {
                return;
            }

            // Prompt to save
            var taskdlg = new TaskDialog
            {
                Icon            = TaskDialogStandardIcon.Information,
                Caption         = Application.ProductName,
                InstructionText = "Do you want to save changes you made to the SQL worksheet " + Title + " ?"
            };

            //var saveButton = new TaskDialogButton("btnYes", "Save");
            //saveButton.Click += (o, args) =>
            //{
            //    try
            //    {
            //        if (!Save())
            //        {
            //            taskdlg.Close(TaskDialogResult.Cancel);
            //        }
            //        else
            //        {
            //            taskdlg.Close(TaskDialogResult.Ok);
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        _log.Error("Error saving worksheet.");
            //        _log.Error(ex.Message, ex);
            //        Dialog.ShowErrorDialog(Application.ProductName, "Error occurred saving the document. ", ex.Message, ex.StackTrace);
            //        taskdlg.Close(TaskDialogResult.Cancel);
            //    }
            //};
            //taskdlg.Controls.Add(saveButton);

            //var discardButton = new TaskDialogButton("btnDisard", "Discard");
            //discardButton.Click += (o, args) => taskdlg.Close(TaskDialogResult.No);
            //taskdlg.Controls.Add(discardButton);

            //if (e.CloseReason != CloseReason.UserClosing)
            //{
            //    var discardAllButton = new TaskDialogButton("btnDisardAll", "Discard All");
            //    discardAllButton.Click += (o, args) => {
            //        CloseAction.Instance.OnCloseSaveAction = OnCloseSaveAction.DiscardAll;
            //        taskdlg.Close(TaskDialogResult.No);
            //    };
            //    taskdlg.Controls.Add(discardAllButton);
            //}

            //var cancelButton = new TaskDialogButton("btnCancel", "Cancel");
            //cancelButton.Click += (o, args) => taskdlg.Close(TaskDialogResult.Cancel);
            //taskdlg.Controls.Add(cancelButton);

            //var dialogResult = taskdlg.Show();
            //if (dialogResult == TaskDialogResult.Cancel)
            //{
            //    e.Cancel = true;
            //}


            var commandLinkSave = new TaskDialogCommandLink("buttonSave", "Save", "Save changes made to the worksheet.");

            commandLinkSave.Click += (o, args) =>
            {
                try
                {
                    if (!Save())
                    {
                        taskdlg.Close(TaskDialogResult.Cancel);
                    }
                    else
                    {
                        taskdlg.Close(TaskDialogResult.Ok);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error("Error saving worksheet.");
                    _log.Error(ex.Message, ex);
                    Dialog.ShowErrorDialog(Application.ProductName, "Error occurred saving the document. ", ex.Message, ex.StackTrace);
                    taskdlg.Close(TaskDialogResult.Cancel);
                }
            };
            taskdlg.Controls.Add(commandLinkSave);

            var commandLinkDiscard = new TaskDialogCommandLink("buttonDiscard", "Discard", "Discard changes made to this worksheet.");

            commandLinkDiscard.Click += (o, args) => taskdlg.Close(TaskDialogResult.No);
            taskdlg.Controls.Add(commandLinkDiscard);

            if (e.CloseReason != CloseReason.UserClosing)
            {
                var commandLinkDiscardAll = new TaskDialogCommandLink("buttonDiscardAll", "Discard All",
                                                                      "Discard changes on all worksheets.");
                commandLinkDiscardAll.Click += (o, args) =>
                {
                    CloseAction.Instance.OnCloseSaveAction =
                        OnCloseSaveAction.DiscardAll;
                    taskdlg.Close(TaskDialogResult.No);
                };
                taskdlg.Controls.Add(commandLinkDiscardAll);
            }
            var commandLinkCancel = new TaskDialogCommandLink("buttonCancel", "Cancel", "Cancel and return to the worksheet.");

            commandLinkCancel.Click += (o, args) => taskdlg.Close(TaskDialogResult.Cancel);
            taskdlg.Controls.Add(commandLinkCancel);

            var dialogResult = taskdlg.Show();

            if (dialogResult == TaskDialogResult.Cancel)
            {
                e.Cancel = true;
            }
        }
Пример #9
0
        private static void CreateTaskDialogDemo()
        {
            TaskDialog taskDialogMain = new TaskDialog();

            taskDialogMain.Caption         = "TaskDialog Samples";
            taskDialogMain.InstructionText = "Pick a sample to try:";
            taskDialogMain.FooterText      = "Demo application as part of <a href=\"http://code.msdn.microsoft.com/WindowsAPICodePack\">Windows API Code Pack for .NET Framework</a>";
            taskDialogMain.Cancelable      = true;

            // Enable the hyperlinks
            taskDialogMain.HyperlinksEnabled = true;
            taskDialogMain.HyperlinkClick   += new EventHandler <TaskDialogHyperlinkClickedEventArgs>(taskDialogMain_HyperlinkClick);

            // Add a close button so user can close our dialog
            taskDialogMain.StandardButtons = TaskDialogStandardButtons.Close;

            #region Creating and adding command link buttons

            TaskDialogCommandLink buttonTestHarness = new TaskDialogCommandLink("test_harness", "TaskDialog Test Harness");
            buttonTestHarness.Click += new EventHandler(buttonTestHarness_Click);

            TaskDialogCommandLink buttonCommon = new TaskDialogCommandLink("common_buttons", "Common Buttons Sample");
            buttonCommon.Click += new EventHandler(buttonCommon_Click);

            TaskDialogCommandLink buttonElevation = new TaskDialogCommandLink("elevation", "Elevation Required Sample");
            buttonElevation.Click           += new EventHandler(buttonElevation_Click);
            buttonElevation.UseElevationIcon = true;

            TaskDialogCommandLink buttonError = new TaskDialogCommandLink("error", "Error Sample");
            buttonError.Click += new EventHandler(buttonError_Click);

            TaskDialogCommandLink buttonIcons = new TaskDialogCommandLink("icons", "Icons Sample");
            buttonIcons.Click += new EventHandler(buttonIcons_Click);

            TaskDialogCommandLink buttonProgress = new TaskDialogCommandLink("progress", "Progress Sample");
            buttonProgress.Click += new EventHandler(buttonProgress_Click);

            TaskDialogCommandLink buttonProgressEffects = new TaskDialogCommandLink("progress_effects", "Progress Effects Sample");
            buttonProgressEffects.Click += new EventHandler(buttonProgressEffects_Click);

            TaskDialogCommandLink buttonTimer = new TaskDialogCommandLink("timer", "Timer Sample");
            buttonTimer.Click += new EventHandler(buttonTimer_Click);

            TaskDialogCommandLink buttonCustomButtons = new TaskDialogCommandLink("customButtons", "Custom Buttons Sample");
            buttonCustomButtons.Click += new EventHandler(buttonCustomButtons_Click);

            TaskDialogCommandLink buttonEnableDisable = new TaskDialogCommandLink("enableDisable", "Enable/Disable sample");
            buttonEnableDisable.Click += new EventHandler(buttonEnableDisable_Click);

            taskDialogMain.Controls.Add(buttonTestHarness);
            taskDialogMain.Controls.Add(buttonCommon);
            taskDialogMain.Controls.Add(buttonCustomButtons);
            taskDialogMain.Controls.Add(buttonEnableDisable);
            taskDialogMain.Controls.Add(buttonElevation);
            taskDialogMain.Controls.Add(buttonError);
            taskDialogMain.Controls.Add(buttonIcons);
            taskDialogMain.Controls.Add(buttonProgress);
            taskDialogMain.Controls.Add(buttonProgressEffects);
            taskDialogMain.Controls.Add(buttonTimer);

            #endregion

            // Show the taskdialog
            taskDialogMain.Show();
        }