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); } } }
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; } }
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; }
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; } }
private async void StartupForm_Load(object sender, EventArgs e) { //Download SAMPCTL await SampCtl.EnsureLatestInstalled(Application.StartupPath); //Add event. pathTextBox.PathText.TextChanged += pathTextBox_TextChanged; //Check for updates AutoUpdater.ParseUpdateInfoEvent += AutoUpdater_ParseUpdateInfoEvent; DownloadForm.DownloadFile(translations.StartupForm_StartupForm_Load_Checking_for_updates, "https://api.github.com/repos/Ahmad45123/ExtremeStudio/releases/latest", Application.StartupPath + "/latest.txt"); AutoUpdater.Start(Application.StartupPath + "/latest.txt"); //If the interop files don't exist, Extract the files. /*if (IsFirst && * (!File.Exists( * Application.StartupPath + "/x64/SQLite.Interop.dll") || * !File.Exists( * Application.StartupPath + "/x86/SQLite.Interop.dll"))) * { * //Remove old. * if (File.Exists( * Application.StartupPath + "/x64/SQLite.Interop.dll")) * { * File.Delete( * Application.StartupPath + "/x64/SQLite.Interop.dll"); * } * * if (File.Exists( * Application.StartupPath + "/x86/SQLite.Interop.dll")) * { * File.Delete( * Application.StartupPath + "/x86/SQLite.Interop.dll"); * } * * //Extract New * File.WriteAllBytes( * Application.StartupPath + "/interop.zip", Properties.Resources.SQLite_Interop); //Write the file. * GeneralFunctions.FastZipUnpack(Application.StartupPath + "/interop.zip", * Application.StartupPath); //Extract it. * File.Delete( * Application.StartupPath + "/interop.zip"); //Delete the temp file. * }*/ //Create needed folders and files. if (!Directory.Exists( Application.StartupPath + "/cache")) { Directory.CreateDirectory( Application.StartupPath + "/cache"); } if (!Directory.Exists( Application.StartupPath + "/cache/serverPackages")) { Directory.CreateDirectory( Application.StartupPath + "/cache/serverPackages"); } if (!Directory.Exists( Application.StartupPath + "/cache/includes")) { Directory.CreateDirectory( Application.StartupPath + "/cache/includes"); } if (!Directory.Exists( Application.StartupPath + "/configs")) { Directory.CreateDirectory( Application.StartupPath + "/configs"); File.WriteAllText( Application.StartupPath + "/configs/recent.json", ""); } //Setting the IsGlobal in Settings will make sure the settings are in place and correct. Program.SettingsForm.IsGlobal = true; //Load all the recent. if (File.Exists( Application.StartupPath + "/configs/recent.json")) { try { Recent = JsonConvert.DeserializeObject <List <string> >( File.ReadAllText( Application.StartupPath + "/configs/recent.json")); if (ReferenceEquals(Recent, null)) { Recent = new List <string>(); } } catch (Exception) { } } if (ProjectToOpen != "") { if (GeneralFunctions.IsValidExtremeProject(ProjectToOpen)) { Program.MainForm.CurrentProject.ProjectPath = ProjectToOpen; Program.MainForm.CurrentProject.ReadInfo(); projectName.Text = Program.MainForm.CurrentProject.ProjectName; string projVersion = Convert.ToString(Program.MainForm.CurrentProject.ProjectVersion); string progVersion = Convert.ToString(_versionHandler.CurrentVersion); VersionReader.CompareVersionResult versionCompare = VersionReader.CompareVersions(projVersion, progVersion); if (versionCompare == VersionReader.CompareVersionResult.VersionSame) { loadProjectBtn_Click(null, EventArgs.Empty); } else if (versionCompare == VersionReader.CompareVersionResult.VersionNew) { loadProjectBtn_Click(null, EventArgs.Empty); } else if (versionCompare == VersionReader.CompareVersionResult.VersionOld) { MessageBox.Show(translations.StartupForm_pathTextBox_TextChanged_ProjectVersionNewer); Application.Exit(); } } else { MessageBox.Show(Convert.ToString(translations.StartupForm_pathTextBox_TextChanged_InvalidESPrj)); Application.Exit(); } } }
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; } } }