Beispiel #1
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");
            }
        }
Beispiel #2
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");
            }
        }