示例#1
0
        private void FinishBtn_Click(object sender, EventArgs e)
        {
            string composants = "";

            if (Composants.Items.Count == 0)
            {
                composants = "Aucun composant utilisé pour l'instant...";
            }
            else
            {
                foreach (string comp in Composants.Items)
                {
                    composants += "* " + comp + Environment.NewLine;
                }
            }

            string librairies = "";

            if (Libraries.Items.Count == 0)
            {
                librairies = "Aucune librairie utilisée pour l'instant...";
            }
            else
            {
                foreach (string lib in Libraries.Items)
                {
                    librairies += "* " + lib + Environment.NewLine;
                }
            }

            // Create thread
            Thread dl = new Thread(() =>
            {
                // Write on README.md
                ManageFile readme     = new ManageFile(project.Full_path + "\\README.md");
                string readme_content = readme.ReadInFile();
                readme_content        = readme_content.Replace("<ListeComposant>", composants);
                readme_content        = readme_content.Replace("<ListeLibrairie>", librairies);
                readme.WriteToFile(readme_content);

                // Dl all of librairies
                Directory.CreateDirectory(project.Full_path + "\\Libraries");
                foreach (string lib in Libraries.Items)
                {
                    string url = LIB.Value <string>(lib);
                    ManageFile.DlFile(url, project.Full_path + "\\Libraries", lib + ".zip");
                }

                // Dl all of datasheets
                Directory.CreateDirectory(project.Full_path + "\\Datasheets");
                foreach (string data in Datasheets.Items)
                {
                    string url = DATA.Value <string>(data);
                    ManageFile.DlFile(url, project.Full_path + "\\Datasheets", data + ".pdf");
                }

                Finish(OpenFolder.Checked);
            });

            FinishBtn.Visible  = false;
            LoadingGif.Visible = true;

            dl.Start();
        }
示例#2
0
文件: Form1.cs 项目: MartDel/CodeGen
        private void ValidateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                // Check all of txtbox
                if (NameTxtBox.Text == "")
                {
                    throw new Exception("Donnez un nom au projet");
                }
                if (DescriptionTxtBox.Text == "")
                {
                    throw new Exception("Donnez une description au projet");
                }
                if (FolderTxtBox.Text == "")
                {
                    throw new Exception("Indiquez le dossier du projet");
                }
                else if (!Directory.Exists(FolderTxtBox.Text))
                {
                    throw new Exception("Le dossier indiqué n'éxiste pas");
                }
                if (TechnoTxtBox.Text != "Arduino")
                {
                    throw new Exception("Template invalide");
                }

                Uri remote;
                if (RemoteTxtBox.Text != "")
                {
                    try { remote = new Uri(RemoteTxtBox.Text); }
                    catch (UriFormatException) { throw new Exception("L'url du remote n'est pas correct"); }
                }
                else
                {
                    remote = null;
                }

                project = new Project(NameTxtBox.Text, DescriptionTxtBox.Text, TechnoTxtBox.Text, FolderTxtBox.Text, remote);

                // Create thread
                Thread configure = new Thread(() =>
                {
                    // Clone the template
                    execCmd("git clone " + project.Template_link, project.Path);

                    // Configure the project folder
                    execCmd("ren " + project.Techno.ToLower() + "template " + project.Name, project.Path);
                    execCmd("git remote remove origin", project.Full_path);
                    ManageFile readme     = new ManageFile(project.Full_path + "\\README.md");
                    string readme_content = readme.ReadInFile();
                    readme_content        = readme_content.Replace("<NomDuProjet>", project.Name);

                    // Optionals features
                    if (project.Remote != null)
                    {
                        execCmd("git remote add origin " + project.Remote.AbsoluteUri, project.Full_path);
                        readme_content = readme_content.Replace("<InsérerDescription>", project.Description + Environment.NewLine + Environment.NewLine + "**Lien du remote :** [" + project.Name + "](" + project.Remote.AbsoluteUri + ")");
                    }
                    else
                    {
                        readme_content = readme_content.Replace("<InsérerDescription>", project.Description);
                    }

                    readme.WriteToFile(readme_content);
                    OpenNewForm(project.Techno);
                });

                ValidateBtn.Visible = false;
                LoadingGif.Visible  = true;

                configure.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }