Example #1
0
        private void DownloadNewVersion()
        {
            if (File.Exists(NetUtils.DownloadedTargetTempPath))
            {
                File.Delete(NetUtils.DownloadedTargetTempPath);
            }

            var downloadForm = new DownloadForm("Download Update");

            downloadForm.OnCancel += (o, e) =>
            {
                NetUtils.Cancel();
            };

            NetUtils.OnProgressChanged += (o, e) =>
            {
                downloadForm.SetValues(e.CurrentSpeed, e.TotalSize, e.TotalDownloaded, e.Remaining, e.CurrentPercentage);
            };
            NetUtils.OnError += (o, e) =>
            {
            };
            NetUtils.OnDownloadCompleted += (o, e) =>
            {
                downloadForm.Close();
                ApplyUpdate();
            };
            downloadForm.Show(this);
            NetUtils.DownloadLatestVersion();
        }
Example #2
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;
        }
        private void InstallSampleProject()
        {
            if (lstProjectTemplates.SelectedItem != null)
            {
                this.Cursor = Cursors.WaitCursor;
                downloadDialog.Show();

                IPackage pack = lstProjectTemplates.SelectedItem as IPackage;

                var inactiveExtensions = _app.Extensions.Where(a => a.IsActive == false).ToArray();

                IEnumerable <PackageDependency> dependency = pack.Dependencies;
                if (dependency.Count() > 0)
                {
                    foreach (PackageDependency dependentPackage in dependency)
                    {
                        _app.ProgressHandler.Progress(null, 0, "Downloading Dependency " + dependentPackage.Id);
                        downloadDialog.ShowDownloadStatus(dependentPackage);
                        downloadDialog.SetProgressBarPercent(0);
                        downloadDialog.Refresh();

                        var dependentpack = packages.Install(dependentPackage.Id);
                        if (dependentpack == null)
                        {
                            string message = "We cannot download " + dependentPackage.Id + " Please make sure you are connected to the Internet.";
                            MessageBox.Show(message);
                            return;
                        }
                    }
                }

                this._app.ProgressHandler.Progress(null, 0, "Downloading " + pack.Title);
                downloadDialog.ShowDownloadStatus(pack);
                downloadDialog.SetProgressBarPercent(0);
                downloadDialog.Refresh();

                this.packages.Install(pack.Id);

                _app.ProgressHandler.Progress(null, 0, "Installing " + pack.Title);
                // Load the extension.
                _app.RefreshExtensions();
                _app.ProgressHandler.Progress(null, 50, "Installing " + pack.Title);

                // Activate the extension(s) that was installed.
                var extensions = _app.Extensions.Where(a => !inactiveExtensions.Contains(a) && a.IsActive == false);

                if (extensions.Count() > 0 && !_app.EnsureRequiredImportsAreAvailable())
                {
                    return;
                }

                foreach (var item in extensions)
                {
                    item.TryActivate();
                }
                this._app.ProgressHandler.Progress(null, 0, "Ready.");
                downloadDialog.Visible = false;

                UpdateInstalledProjectsList();
                selectDownloadedPackage(pack);
                this.Cursor = Cursors.Default;
            }
        }
Example #4
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;
                }
            }
        }