예제 #1
0
        public static void EmptyProject()
        {
            WithDisposable(script =>
            {
                Project project = CSScriptHelper.GenerateProjectFor(new SourceInfo(script));

                Assert.NotEmpty(project.Refs);
                Assert.NotEmpty(project.SearchDirs);
                Assert.NotEmpty(project.Files);
                Assert.Equal(project.Files.First(), script);
            });
        }
        public UpdateOptionsPanel(string version)
        {
            InitializeComponent();

            DoLayout();

            this.version    = version;
            versionLbl.Text = version;

            updateAfterExit.Checked  = Config.Instance.UpdateAfterExit;
            customDeployment.Checked = (Config.Instance.UpdateMode == (string)customDeployment.Tag);
            msiDeployment.Checked    = (Config.Instance.UpdateMode == (string)msiDeployment.Tag);
            manualDeployment.Checked = (Config.Instance.UpdateMode == (string)manualDeployment.Tag);

            releaseInfo.Text = CSScriptHelper.GetLatestReleaseInfo(version);
        }
예제 #3
0
        public static void WithMultiRefsProject() => WithDisposable(script =>
        {
            var search_dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            File.WriteAllText(script, $@"
                    //css_dir {search_dir}
                    //css_ref {csscript.cscs_path}
                    //css_ref {Assembly.GetExecutingAssembly().Location}");

            Project project = CSScriptHelper.GenerateProjectFor(new SourceInfo(script));

            Assert.NotEmpty(project.Files);
            Assert.Equal(project.Files.First(), script);
            Assert.Equal(project.Files.First(), script);
            Assert.Contains(csscript.cscs_path, project.Refs);
            Assert.Contains(Assembly.GetExecutingAssembly().Location, project.Refs);
            Assert.Contains(search_dir, project.SearchDirs);
        });
예제 #4
0
        public static Intellisense.Common.CodeMapItem[] GetMapOf(string code)
        {
            bool injected = CSScriptHelper.DecorateIfRequired(ref code);
            var  map      = GetMapOfImpl(code, injected);

            if (injected)
            {
                int injectedLineOffset = CSScriptHelper.GetDecorationInfo(code).Item1;
                int injectedLineNumber = code.Substring(0, injectedLineOffset).Split('\n').Count();

                map = map.Where(i => i.Line != injectedLineNumber).ToArray();

                foreach (Intellisense.Common.CodeMapItem item in map)
                {
                    if (item.Line >= injectedLineNumber)
                    {
                        item.Line -= 1;
                    }
                }
            }
            return(map);
        }
예제 #5
0
        public static Intellisense.Common.CodeMapItem[] GetMapOf(string code)
        {
            bool injected = CSScriptHelper.DecorateIfRequired(ref code);
            var  map      = GetMapOfImpl(code, injected);

            if (injected)
            {
                int injectedLineOffset = CSScriptHelper.GetDecorationInfo(code).Item1;
                int injectedLineNumber = code.Substring(0, injectedLineOffset).Split('\n').Count();

                map = map.Where(i => i.Line != injectedLineNumber).ToArray();

                foreach (Intellisense.Common.CodeMapItem item in map)
                {
                    if (item.Line >= injectedLineNumber)
                    {
                        item.Line -= (1 + 1); // new AutoClass generator injects at least 2 lines, though ideally syntaxer.AutoclassGenerator should handle it...
                    }
                }
            }
            return(map);
        }
        void okBtn_Click(object sender, EventArgs e)
        {
            skipBtn.Enabled              =
                okBtn.Enabled            =
                    optionsGroup.Enabled = false;

            //progressBar.Visible =
            progressLbl.Visible = true;
            progressBar.Style   = ProgressBarStyle.Continuous;

            if (customDeployment.Checked && updateAfterExit.Checked)
            {
                Close();
            }

            Task.Factory.StartNew(() =>
            {
                try
                {
                    string distroFile = null;
                    if (msiDeployment.Checked)
                    {
                        distroFile = CSScriptHelper.DownloadDistro(distro.MsiUrl, UpdateProgress);
                    }
                    else if (customDeployment.Checked || manualDeployment.Checked)
                    {
                        if (customDeployment.Checked && updateAfterExit.Checked)
                        {
                            distroFile = distro.ZipUrl;
                        }
                        else
                        {
                            distroFile = CSScriptHelper.DownloadDistro(distro.ZipUrl, UpdateProgress);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please select the update mode.", "CS-Script");
                        return;
                    }

                    if (Closed && !updateAfterExit.Checked)
                    {
                        return;
                    }

                    if (distroFile == null || (!File.Exists(distroFile) && distroFile != distro.ZipUrl))
                    {
                        MessageBox.Show(this, "Cannot download the binaries. The latest release Web page will be opened instead.", "CS-Script");
                        try
                        {
                            Process.Start(Plugin.HomeUrl);
                        }
                        catch { }
                    }
                    else
                    {
                        if (msiDeployment.Checked)
                        {
                            Config.Instance.UpdateMode = (string)msiDeployment.Tag;
                            Process.Start("explorer.exe", "/select,\"" + distroFile + "\"");
                        }
                        else if (manualDeployment.Checked)
                        {
                            Config.Instance.UpdateMode = (string)manualDeployment.Tag;
                            Process.Start(distroFile);
                        }
                        else if (customDeployment.Checked)
                        {
                            Config.Instance.UpdateMode = (string)customDeployment.Tag;

                            string downloadDir = KnownFolders.UserDownloads;

                            string targetDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                            string updater   = DeployUpdater(targetDir, downloadDir);

                            try { Invoke((Action)Close); }
                            catch { }

                            if (updateAfterExit.Checked)
                            {
                                Process.Start(updater, string.Format("\"{0}\" \"{1}\" /asynch_update", distro.ZipUrl, targetDir));
                                MessageBox.Show("The plugin will be updated after you close Notepad++", "CS-Script");
                            }
                            else
                            {
                                if (DialogResult.Yes == MessageBox.Show(new Form {
                                    TopMost = true
                                }, @"Some installation steps still need to be completed. Notepad++ needs to be restarted in older to complete these steeps. Would you like to restart now?",
                                                                        "CS-Script", MessageBoxButtons.YesNo))
                                {
                                    Process updater_proc = Process.Start(updater, string.Format("\"{0}\" \"{1}\"", distroFile, targetDir));

                                    string npp_exe = Process.GetCurrentProcess().MainModule.FileName;

                                    // launcher.exe is already deployed (along with 7z.exe)
                                    string restarter = Path.Combine(Path.GetDirectoryName(updater), "launcher.exe");

                                    //the re-starter will also wait for updater process to exit
                                    Process.Start(restarter, $"/start {updater_proc.Id} \"{npp_exe}\"");

                                    PluginBase.Editor.FileExit();
                                }
                            }
                        }

                        Config.Instance.Save();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Cannot execute install update: " + ex.Message, "CS-Script");
                }

                try { Invoke((Action)Close); }
                catch { }
            });
        }