Пример #1
0
        private void userInput(MessageArgs message, Editor editor)
        {
            Logger.Write("Getting state for userinput fallback");
            var state = new ConfigReader(_endpoint.Token).Get("oi.userinput.ui.fallback");

            Logger.Write("State is " + state);
            if (state == "disabled")
            {
                return;
            }
            _ctx.Post((s) =>
            {
                Logger.Write("Launching user input form");
                try {
                    var args         = new CommandStringParser().Parse(message.Message).ToArray();
                    var defaultValue = "";
                    if (args.Length > 3)
                    {
                        defaultValue = args[3];
                    }
                    var form = new UserInputForm(defaultValue, (item) => {
                        if (item != null)
                        {
                            _endpoint.PublishEvent("user-inputted '" + args[2] + "' '" + item + "'");
                        }
                        else
                        {
                            _endpoint.PublishEvent("user-inputted '" + args[2] + "' 'user-cancelled'");
                        }
                        editor.SetFocus();
                    });
                    form.Show(this);
                    setToForeground(form);
                } catch (Exception ex) {
                    Logger.Write(ex);
                }
            }, null);
        }
        private static bool TryGetCredentialProfileName(out string credentialProfileName)
        {
            credentialProfileName = null;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            UserInputForm profileManagementForm = new UserInputForm();
            Application.Run(profileManagementForm);

            if (null == profileManagementForm.SelectedAccount)
            {
                return false;
            }

            string credentialProfileNameBuffer = profileManagementForm.SelectedAccount.Name;
            if (string.IsNullOrWhiteSpace(credentialProfileNameBuffer))
            {
                return false;
            }

            credentialProfileName = credentialProfileNameBuffer;
            return true;
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                if (Environment.GetEnvironmentVariable("CSS_NPP_UPDATE_DEBUG") != null)
                {
                    Debug.Assert(false);
                }

                // "C:\Users\osh\Downloads\CSScriptNpp.1.7.7.3.x64 (7).zip" "C:\Program Files\Notepad++\plugins\CSScriptNpp"

                if (!args.Any())
                {
                    if (IsRunningDistroFolder())
                    {
                        if (!IsAdmin())
                        {
                            var p = new Process();
                            p.StartInfo.FileName        = Assembly.GetExecutingAssembly().Location;
                            p.StartInfo.Verb            = "runas";
                            p.StartInfo.UseShellExecute = true;
                            p.Start();
                        }
                        else
                        {
                            var distroDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                            var targetDir = GetTargerDirForDistro(distroDir);
                            if (DialogResult.OK != MessageBox.Show("The plugin will be installed in the \"" + targetDir + "\" folder.", "CS-Script Update", MessageBoxButtons.OKCancel))
                            {
                                return;
                            }

                            if (EnsureNoUpdateInProgress())
                            {
                                StopVBCSCompilers();
                                if (EnsureNppNotRunning(false) && EnsureVBCSCompilerNotLocked(false))
                                {
                                    DeployFromCurrentFolder();
                                    MessageBox.Show("The update process has been completed.", "CS-Script Update");
                                }
                            }
                        }
                        return;
                    }

                    string distroFile = UserInputForm.GetDistro();
                    if (!string.IsNullOrEmpty(distroFile))
                    {
                        Debug.Assert(false);
                        StopVBCSCompilers();
                        if (EnsureNppNotRunning(false) && EnsureVBCSCompilerNotLocked(false))
                        {
                            if (distroFile.StartsWith("http"))
                            {
                                var url = distroFile;
                                distroFile = Path.Combine(KnownFolders.UserDownloads, "CSScriptNpp.ManualUpdate", Path.GetFileName(distroFile));
                                WebHelper.DownloadBinary(url, distroFile);
                            }
                            DeployItselfAndRestart(distroFile, FindPluginDir(distroFile));
                        }
                    }
                    return;
                }

                if (!EnsureNoUpdateInProgress())
                {
                    return;
                }

                // <zipFile> [<pluginDir>] [/asynchUpdateArg]
                string zipFile   = args[0];
                string pluginDir = args.Length > 1 ? args[1] : FindPluginDir(zipFile);

                string updaterDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                if (updaterDir.StartsWith(pluginDir, StringComparison.OrdinalIgnoreCase))
                {
                    DeployItselfAndRestart(zipFile, pluginDir);
                    return;
                }
                else
                {
                    DeployDependencies();
                }

                if (IsAdmin())
                {
                    StopVBCSCompilers();

                    bool isAsynchUpdate = args.Contains(asynchUpdateArg) || args.First().IsUrl() || args.First().IsVersion();
                    args = args.Where(x => x != asynchUpdateArg).ToArray();

                    if (pluginDir == null)
                    {
                        throw new Exception($"Cannot find Notepad++ installation.");
                    }

                    // Debug.Assert(false);

                    if (EnsureNppNotRunning(isAsynchUpdate) && EnsureVBCSCompilerNotLocked(isAsynchUpdate))
                    {
                        if (isAsynchUpdate)
                        {
                            WaitPrompt.Show();

                            string arg = args[0];
                            zipFile = WebHelper.DownloadDistro(args[0], WaitPrompt.OnProgress);
                        }

                        // pluginDir: C:\Program Files\Notepad++\plugins\CSScriptNpp
                        Updater.Deploy(zipFile, Path.GetDirectoryName(pluginDir));

                        WaitPrompt.Hide();

                        if (EnsureNppNotRunning(isAsynchUpdate) && EnsureVBCSCompilerNotLocked(isAsynchUpdate))
                        {
                            MessageBox.Show("The update process has been completed.", "CS-Script Update");
                        }
                    }
                }
                else
                {
                    throw new Exception("You need admin rights to start CS-Script updater.");
                }
            }
            catch (Exception e)
            {
                WaitPrompt.Hide();
                MessageBox.Show("Update has not succeeded.\nError: " + e.Message, "CS-Script Update");
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            try
            {
                Debug.Assert(false);

                if (!args.Any())
                {
                    string distroFile = UserInputForm.GetDistro();
                    if (!string.IsNullOrEmpty(distroFile))
                    {
                        // Debug.Assert(false);
                        StopVBCSCompilers();
                        if (EnsureNppNotRunning(false) && EnsureVBCSCompilerNotLocked(false))
                        {
                            if (distroFile.StartsWith("http"))
                            {
                                var url = distroFile;
                                distroFile = Path.Combine(KnownFolders.UserDownloads, "CSScriptNpp.ManualUpdate", Path.GetFileName(distroFile));
                                WebHelper.DownloadBinary(url, distroFile);
                            }
                            DeployItselfAndRestart(distroFile, FindPluginDir(distroFile));
                        }
                    }
                    return;
                }

                bool createdNew;
                appSingleInstanceMutex = new Mutex(true, "Npp.CSScript.PluginUpdater", out createdNew);

                if (!createdNew)
                {
                    MessageBox.Show($"Another Notepad++ plugin update in progress. Either wait or stop {Path.GetFileName(Assembly.GetExecutingAssembly().Location)}", "CS-Script");
                    return;
                }

                // <zipFile> [<pluginDir>] [/asynchUpdateArg]
                string zipFile   = args[0];
                string pluginDir = args.Length > 1 ? args[1] : FindPluginDir(zipFile);

                string updaterDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                if (updaterDir.StartsWith(pluginDir, StringComparison.OrdinalIgnoreCase))
                {
                    DeployItselfAndRestart(zipFile, pluginDir);
                    return;
                }
                else
                {
                    DeployDependencies();
                }

                if (IsAdmin())
                {
                    StopVBCSCompilers();

                    bool isAsynchUpdate = args.Contains(asynchUpdateArg) || args.First().IsUrl() || args.First().IsVersion();
                    args = args.Where(x => x != asynchUpdateArg).ToArray();

                    if (pluginDir == null)
                    {
                        throw new Exception($"Cannot find Notepad++ installation.");
                    }

                    // Debug.Assert(false);

                    if (EnsureNppNotRunning(isAsynchUpdate) && EnsureVBCSCompilerNotLocked(isAsynchUpdate))
                    {
                        if (isAsynchUpdate)
                        {
                            WaitPrompt.Show();

                            string arg = args[0];
                            zipFile = WebHelper.DownloadDistro(args[0], WaitPrompt.OnProgress);
                        }

                        // pluginDir: C:\Program Files\Notepad++\plugins\CSScriptNpp
                        Updater.Deploy(zipFile, Path.GetDirectoryName(pluginDir));

                        WaitPrompt.Hide();

                        if (EnsureNppNotRunning(isAsynchUpdate) && EnsureVBCSCompilerNotLocked(isAsynchUpdate))
                        {
                            MessageBox.Show("The update process has been completed.", "CS-Script Update");
                        }
                    }
                }
                else
                {
                    throw new Exception("You need admin rights to start CS-Script updater.");
                }
            }
            catch (Exception e)
            {
                WaitPrompt.Hide();
                MessageBox.Show("Update has not succeeded.\nError: " + e.Message, "CS-Script Update");
            }
        }