Exemplo n.º 1
0
        private async void CompilerWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //We will use the progress event to do stuff in the UI.

            //1 = Save
            if (e.ProgressPercentage == 1)
            {
                SaveAllFiles(this, null);
            }

            //2 = Started Compiling
            if (e.ProgressPercentage == 2)
            {
                ShowStatus(Convert.ToString(translations.MainForm_CompilerWorker_ProgressChanged_Compiling), -1,
                           false);

                //3 = Failed Compiling With Errors/Warnings.
            }
            else if (e.ProgressPercentage == 3)
            {
                ShowStatus(
                    Convert.ToString(translations
                                     .MainForm_CompilerWorker_ProgressChanged_CompilingFailedWithErrors), 5000, true);

                //4 = Finished Compiling With Warnings.
            }
            else if (e.ProgressPercentage == 4)
            {
                ShowStatus(
                    Convert.ToString(translations
                                     .MainForm_CompilerWorker_ProgressChanged_CompilingDoneWithWarnings), 5000, true);

                Program.ProjExplorerDock.RefreshList();

                if (isAwaitingRunServer)
                {
                    isAwaitingRunServer = false;
                    await SampCtl.SendCommand(ApplicationFiles + "/sampctl.exe", CurrentProject.ProjectPath,
                                              "p run", false);
                }

                //5 = Finished Compiling.
            }
            else if (e.ProgressPercentage == 5)
            {
                ShowStatus(
                    Convert.ToString(translations
                                     .MainForm_CompilerWorker_ProgressChanged_CompilingDoneWithNoErrorsWarnings), 5000, true);

                Program.ProjExplorerDock.RefreshList();

                if (isAwaitingRunServer)
                {
                    isAwaitingRunServer = false;
                    await SampCtl.SendCommand(ApplicationFiles + "/sampctl.exe", CurrentProject.ProjectPath,
                                              "p run", false);
                }
            }
        }
Exemplo n.º 2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (Program.MainForm.CurrentProject.SampCtlData.dependencies.Contains(PackagesList.SelectedItem.ToString()))
            {
                ActionButton.Enabled = false;
                ActionButton.Text    = translations.PackagesForm_button1_Click_Uninstalling;
                PackagesList.Enabled = false;
                ControlBox           = false;

                DownloadForm frm = new DownloadForm
                {
                    progressBar1 = { Style = ProgressBarStyle.Marquee },
                    descLabel    = { Text = translations.PackagesForm_button1_Click_Removing_package___ }
                };
                frm.Show();
                Enabled = false;
                await SampCtl.SendCommand(Application.StartupPath + "/sampctl.exe",
                                          Program.MainForm.CurrentProject.ProjectPath, "p uninstall " + PackagesList.SelectedItem);

                Program.MainForm.CurrentProject.LoadSampCtlData();
                frm.Close();
                Enabled = true;

                ActionButton.Text    = translations.PackagesForm_button1_Click_InstallPackage;
                ActionButton.Enabled = true;
                PackagesList.Enabled = true;
                ControlBox           = true;
            }
            else
            {
                ActionButton.Enabled = false;
                ActionButton.Text    = translations.PackagesForm_button1_Click_Installing;
                PackagesList.Enabled = false;
                ControlBox           = false;

                DownloadForm frm = new DownloadForm
                {
                    progressBar1 = { Style = ProgressBarStyle.Marquee },
                    descLabel    = { Text = translations.PackagesForm_button1_Click_Downloading_package___ }
                };
                frm.Show();
                Enabled = false;
                await SampCtl.SendCommand(Application.StartupPath + "/sampctl.exe",
                                          Program.MainForm.CurrentProject.ProjectPath, "p install " + PackagesList.SelectedItem);

                frm.Close();
                Enabled = true;


                Program.MainForm.CurrentProject.LoadSampCtlData();

                ActionButton.Text    = translations.PackagesForm_button1_Click_UninstallPackage;
                ActionButton.Enabled = true;
                PackagesList.Enabled = true;
                ControlBox           = true;
            }
        }
Exemplo n.º 3
0
        public async void DoIfUpdateNeeded(CurrentProjectClass project)
        {
            if (project.ProjectVersion == "1.0.0")
            {
                if (!Directory.Exists(project.ProjectPath + "/dependencies"))
                {
                    //Setup sampctl for it
                    project.SampCtlData = new PawnJson()
                    {
                        entry        = "gamemodes\\" + project.ProjectName + ".pwn",
                        output       = "gamemodes\\" + project.ProjectName + ".amx",
                        user         = Environment.UserName,
                        repo         = project.ProjectName,
                        dependencies = new List <string>()
                        {
                            "sampctl/samp-stdlib"
                        },
                        builds = new List <BuildInfo>()
                        {
                            new BuildInfo()
                            {
                                name = "main",
                                args = Program.SettingsForm.GetCompilerArgs().Split(' ').ToList()
                            }
                        },
                        runtime = new RuntimeInfo()
                        {
                            version = "latest"
                        },
                    };
                    project.SaveInfo();
                    project.LoadSampCtlData(); //to make sure pawno/includes is also supported.
                    DownloadForm frm = new DownloadForm
                    {
                        progressBar1 = { Style = ProgressBarStyle.Marquee },
                        descLabel    = { Text = translations.StartupForm_CreateProjectBtn_Click_Ensuring_packages }
                    };
                    frm.Show();
                    await SampCtl.SendCommand(Path.Combine(Application.StartupPath, "sampctl.exe"), project.ProjectPath, "p ensure");

                    frm.Close();
                }
            }
            project.ProjectVersion = CurrentVersion;
        }
Exemplo n.º 4
0
        private void CompilerWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            //First of all, Try and save all docs.
            if (CurrentScintilla?.Modified ?? false)
            {
                var msgRslt = MessageBox.Show(translations.MainForm_CompilerWorker_DoWork_WouldYouLikeToSaveFiles, "",
                                              MessageBoxButtons.YesNoCancel);
                if (msgRslt == DialogResult.Cancel)
                {
                    return;
                }

                if (msgRslt == DialogResult.Yes)
                {
                    CompilerWorker.ReportProgress(1); //Save all files.
                }
            }
            else
            {
                CompilerWorker.ReportProgress(1); //Save all files.
            }

            //First of all, update the pawn.json compiler args.
            CurrentProject.SampCtlData.builds[0].args = Program.SettingsForm.GetCompilerArgs().Split(' ').ToList();
            CurrentProject.SaveInfo();

            CompilerWorker.ReportProgress(2);
            string errs = SampCtl.SendCommand(ApplicationFiles + "/sampctl.exe", CurrentProject.ProjectPath,
                                              "p build").Result;

            //Now, Get the errors/warning then parse them and return.
            //string errs = Convert.ToString(compiler.StandardError.ReadToEnd());
            if (errs.Contains("success"))
            {
                e.Result = new List <ErrorsDock.ScriptErrorInfo>();
                CompilerWorker.ReportProgress(5); //Done sucessfully.
            }
            else
            {
                //Parse the list for the errors and warnings first.
                var errorLevel = 0;
                List <ErrorsDock.ScriptErrorInfo> errorList = new List <ErrorsDock.ScriptErrorInfo>();
                var matches = Regex.Matches(errs,
                                            @"(?<path>.+):(?<line>[0-9]+)\s\((?<type>fatal|error|warning)\)(?<text>.+)",
                                            RegexOptions.Multiline);
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        ErrorsDock.ScriptErrorInfo err = new ErrorsDock.ScriptErrorInfo
                        {
                            FileName   = Path.GetFileName(Convert.ToString(match.Groups["path"].Value)),
                            LineNumber = match.Groups["line"].Value
                        };
                        if (match.Groups["type"].Value == "error" || match.Groups["type"].Value == "fatal")
                        {
                            err.ErrorType = ErrorsDock.ScriptErrorInfo.ErrorTypes.Error;
                            errorLevel    = 2;
                        }
                        else
                        {
                            err.ErrorType = ErrorsDock.ScriptErrorInfo.ErrorTypes.Warning;
                            if (errorLevel < 2)
                            {
                                errorLevel = 1;
                            }
                        }

                        err.ErrorMessage = match.Groups["text"].Value;

                        errorList.Add(err);
                    }

                    //Report status.
                    if (errorLevel == 2)
                    {
                        CompilerWorker.ReportProgress(3); //Failed with errors and possible warnings.
                    }
                    else if (errorLevel == 1)
                    {
                        CompilerWorker.ReportProgress(4); //Sucess but warnings..
                    }
                }
                else
                {
                    MessageBox.Show(errs, translations.MainForm_CompilerWorker_DoWork_CompilationFailed, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    CompilerWorker.ReportProgress(3);
                }
                //Set result as the list.
                e.Result = errorList;
            }
        }
Exemplo n.º 5
0
        private async void CreateProjectBtn_Click(object sender, EventArgs e)
        {
            string newPath = Convert.ToString(locTextBox.PathText.Text);

            if (preExistCheck.Checked)
            {
                if (!Directory.Exists(newPath) ||
                    GeneralFunctions.IsValidExtremeProject(newPath) || !GeneralFunctions.IsValidSAMPFolder(newPath))
                {
                    MessageBox.Show(
                        Convert.ToString(translations.StartupForm_CreateProjectBtn_Click_InvalidSampFolder));
                    return;
                }
                else
                {
                    //Create the default file
                    if (!File.Exists(newPath + "/gamemodes/" + nameTextBox.Text + ".pwn"))
                    {
                        File.WriteAllText(
                            newPath + "/gamemodes/" + nameTextBox.Text + ".pwn",
                            Convert.ToString(Properties.Resources.newfileTemplate));
                    }

                    //Fill pawnctl data
                    Program.MainForm.CurrentProject.SampCtlData = new PawnJson()
                    {
                        entry        = "gamemodes\\" + nameTextBox.Text + ".pwn",
                        output       = "gamemodes\\" + nameTextBox.Text + ".amx",
                        user         = Environment.UserName,
                        repo         = nameTextBox.Text,
                        dependencies = new List <string>()
                        {
                            "sampctl/samp-stdlib"
                        },
                        builds = new List <BuildInfo>()
                        {
                            new BuildInfo()
                            {
                                name = "main",
                                args = Program.SettingsForm.GetCompilerArgs().Split(' ').ToList()
                            }
                        },
                        runtime = new RuntimeInfo()
                        {
                            version = verListBox.SelectedItem?.ToString() ?? "latest"
                        },
                    };
                    Program.MainForm.CurrentProject.ProjectName    = nameTextBox.Text;
                    Program.MainForm.CurrentProject.ProjectPath    = newPath;
                    Program.MainForm.CurrentProject.ProjectVersion = _versionHandler.CurrentVersion;
                    Program.MainForm.CurrentProject.CreateTables();    //Create the tables of the db.
                    Program.MainForm.CurrentProject.SaveInfo();        //Write the default extremeStudio config.
                    Program.MainForm.CurrentProject.CopyGlobalConfig();
                    Program.MainForm.CurrentProject.LoadSampCtlData(); //to ensure pawno/includes is there.

                    //Ensure the packages are ready
                    DownloadForm frm = new DownloadForm
                    {
                        progressBar1 = { Style = ProgressBarStyle.Continuous },
                        descLabel    = { Text = translations.StartupForm_CreateProjectBtn_Click_Ensuring_packages }
                    };
                    frm.Show();
                    Enabled = false;
                    await SampCtl.SendCommand(Path.Combine(Application.StartupPath, "sampctl.exe"), newPath, "p ensure");

                    frm.Close();
                    Enabled = true;

                    AddNewRecent(
                        Convert.ToString(Program.MainForm.CurrentProject.ProjectPath)); //Add it to the recent list.
                    Program.MainForm.Show();
                    _isClosedProgram = true;
                    Close();
                }
            }
            else
            {
                //Add to the path folder name.
                if (nameTextBox.Text.IsValidFileName() == false)
                {
                    MessageBox.Show(
                        Convert.ToString(translations.StartupForm_CreateProjectBtn_Click_InvalidName));
                    return;
                }

                newPath = Path.Combine(Convert.ToString(locTextBox.PathText.Text),
                                       Convert.ToString(nameTextBox.Text));
                if (!string.IsNullOrEmpty(newPath) &&
                    Directory.Exists(newPath) == false)
                {
                    Directory.CreateDirectory(newPath);
                }

                //Check if entered path exist.
                if (Directory.Exists(newPath) &&
                    File.Exists(
                        newPath + "/extremeStudio.config") == false)
                {
                    if (verListBox.SelectedIndex != -1)
                    {
                        //Create directories.
                        Directory.CreateDirectory(newPath + "/gamemodes");
                        Directory.CreateDirectory(newPath + "/plugins");
                        Directory.CreateDirectory(newPath + "/scriptfiles");

                        //Create the default file
                        File.WriteAllText(
                            newPath + "/gamemodes/" + nameTextBox.Text + ".pwn",
                            Convert.ToString(Properties.Resources.newfileTemplate));

                        //Fill pawnctl data
                        Program.MainForm.CurrentProject.SampCtlData = new PawnJson()
                        {
                            entry        = "gamemodes\\" + nameTextBox.Text + ".pwn",
                            output       = "gamemodes\\" + nameTextBox.Text + ".amx",
                            user         = Environment.UserName,
                            repo         = nameTextBox.Text,
                            dependencies = new List <string>()
                            {
                                "sampctl/samp-stdlib"
                            },
                            builds = new List <BuildInfo>()
                            {
                                new BuildInfo()
                                {
                                    name = "main", args = Program.SettingsForm.GetCompilerArgs().Split(' ').ToList()
                                }
                            },
                            runtime = new RuntimeInfo()
                            {
                                version = verListBox.SelectedItem.ToString()
                            },
                        };
                        Program.MainForm.CurrentProject.ProjectName    = nameTextBox.Text;
                        Program.MainForm.CurrentProject.ProjectPath    = newPath;
                        Program.MainForm.CurrentProject.ProjectVersion = _versionHandler.CurrentVersion;
                        Program.MainForm.CurrentProject.CreateTables(); //Create the tables of the db.
                        Program.MainForm.CurrentProject.SaveInfo();     //Write the default extremeStudio config.
                        Program.MainForm.CurrentProject.CopyGlobalConfig();

                        //Ensure the packages are ready
                        DownloadForm frm = new DownloadForm
                        {
                            progressBar1 = { Style = ProgressBarStyle.Marquee },
                            descLabel    = { Text = translations.StartupForm_CreateProjectBtn_Click_Ensuring_packages }
                        };
                        frm.Show();
                        Enabled = false;
                        await SampCtl.SendCommand(Path.Combine(Application.StartupPath, "sampctl.exe"), newPath, "p ensure");

                        frm.Close();
                        Enabled = true;

                        AddNewRecent(
                            Convert.ToString(Program.MainForm.CurrentProject.ProjectPath)); //Add it to the recent list.
                        Program.MainForm.Show();
                        _isClosedProgram = true;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show(
                            Convert.ToString(translations.StartupForm_CreateProjectBtn_Click_NoSampSelected));
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(Convert.ToString(translations.StartupForm_CreateProjectBtn_Click_DirError));
                    return;
                }
            }
        }