Ejemplo n.º 1
0
        public async static Task<bool> newProject(ConfigNewProject config)
        {
            Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f..");
            try
            {
                config.JavaHome = config.JavaHome.Replace("%JAVA_HOME%", Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine));
                config.PathHomeGradle = config.PathHomeGradle.Replace("%USER_PROFILE%", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
                if (!Directory.Exists(".cc"))
                {
                    DirectoryInfo inf = Directory.CreateDirectory(".cc");
                    inf.Attributes = FileAttributes.Hidden | FileAttributes.NotContentIndexed;
                }
                Project pr = new Project();
                Guid gu = Guid.NewGuid();
                pr.GUIDProject = gu.ToString();
                pr.arraySniffer = gu.ToByteArray();
                pr.ProjectID = config.ProjectID;
                pr.NameProject = config.NameProject;
                pr.Domen = config.Domen;
                pr.build = config.startBuild;
                pr.versionMajor = config.startVersionMajor;
                pr.versionMinor = config.startVersionMinor;
                pr.versionRef = config.startVersionRef;
                pr.versionState = config.startVersionState;
                pr.versionMine = config.versionMine;
                pr.versionForge = config.verionForge;

                Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 14%..");

                new YamlSerializer().SerializeToFile($"{config.ProjectID.Replace(' ', '_')}.ccproj", pr);

                if(!File.Exists(".cc\\gradle.ccsln"))
                {
                    Gradle gradlConf = new Gradle();
                    gradlConf.HomePath = config.GetPathGradle();
                    gradlConf.Target = config.GetTargetGradle();
                    if (!File.Exists(config.GetTargetGradle()))
                    {
                        using (StreamWriter writer = File.CreateText(config.GetTargetGradle()))
                        {
                            writer.WriteLine($"project_domen={config.Domen}");
                            writer.WriteLine($"project_id={config.ProjectID}");
                            writer.WriteLine($"project_version={config.AssemblyVersion()}");
                            writer.WriteLine($"project_build={config.startBuild}");
                            writer.WriteLine($"project_mine_version={config.versionMine}");
                            writer.WriteLine($"project_forge_version={config.verionForge}");
                            writer.Flush();
                        }
                        Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 31%..");
                    }
                    gradlConf.isOffline = config.isOfflineGradle;

                    new YamlSerializer().SerializeToFile($".cc\\gradle.ccsln", gradlConf);
                    File.SetAttributes($".cc\\gradle.ccsln", FileAttributes.Hidden | FileAttributes.NotContentIndexed);
                    Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 56%..");
                }
                if (!File.Exists(".cc\\idea.ccsln"))
                {
                    IDEA idea = new IDEA();
                    idea.ArtifacteTarget = config.GetArtifacteTarget().Replace("%ProjectID%", config.ProjectID).Replace("%PROJECT_ROOT%", Environment.CurrentDirectory);

                    new YamlSerializer().SerializeToFile($".cc\\idea.ccsln", idea);
                    File.SetAttributes($".cc\\idea.ccsln", FileAttributes.Hidden | FileAttributes.NotContentIndexed);
                    Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 65%..");
                }
                if(!File.Exists(".cc\\java.ccsln"))
                {
                    Java j = new Java();
                    j.PathHome = config.GetJavaHome();
                    j.JVMOpt = config.GetJVMOpt();
                    new YamlSerializer().SerializeToFile($".cc\\java.ccsln", j);
                    File.SetAttributes($".cc\\java.ccsln", FileAttributes.Hidden | FileAttributes.NotContentIndexed);
                    Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 76%..");
                }
                if(!Directory.Exists(".cc\\wrapper"))
                {
                    DirectoryInfo inf = Directory.CreateDirectory(".cc\\wrapper");
                    inf.Attributes = FileAttributes.Hidden | FileAttributes.NotContentIndexed;
                    using (FileStream writer = File.Create(".cc\\wrapper\\gradle-wrapper.jar"))
                    {
                        await writer.WriteAsync(GradleWrapper.gradle_wrapper, 0, GradleWrapper.gradle_wrapper.Length);
                        Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 95%..");
                    }
                    using (FileStream writer = File.Create(".cc\\wrapper\\gradle-wrapper.properties"))
                    {
                        await writer.WriteAsync(Prop.gradle_wrapper, 0, Prop.gradle_wrapper.Length);
                        Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstruct§f 97%..");
                    }
                    File.SetAttributes(".cc\\wrapper\\gradle-wrapper.jar", FileAttributes.Hidden | FileAttributes.NotContentIndexed);
                    File.SetAttributes(".cc\\wrapper\\gradle-wrapper.properties", FileAttributes.Hidden | FileAttributes.NotContentIndexed);
                }

                GradleConfig = YamlSerializer.Deserialize<Gradle>(".cc\\gradle.ccsln");
                ideaConfig = YamlSerializer.Deserialize<IDEA>(".cc\\idea.ccsln");
                javaConfig = YamlSerializer.Deserialize<Java>(".cc\\java.ccsln");

                RunGradle(GradlewRunType.setupWorkSpace);
                RunGradle(GradlewRunType.makeIdea);
                Terminal.WriteLine($"Project §8{config.NameProject}§f §aConstructed§f");
                return true;
            }
            catch (Exception ex)
            {
                Terminal.WriteLine(ex);
                return false;
            }
        }
Ejemplo n.º 2
0
 public static bool loadProject(string path)
 {
     try
     {
         ProjectConfig = YamlSerializer.Deserialize<Project>(path);
         GradleConfig = YamlSerializer.Deserialize<Gradle>(".cc\\gradle.ccsln");
         ideaConfig = YamlSerializer.Deserialize<IDEA>(".cc\\idea.ccsln");
         javaConfig = YamlSerializer.Deserialize<Java>(".cc\\java.ccsln");
         Terminal.Windows.Title = $"CodeClimate - {VersionModule} <{ProjectConfig.NameProject}({ProjectConfig.ProjectID}) - ";
         Terminal.Windows.Title += $"{ProjectConfig.AssemblyVersion()}-{ProjectConfig.versionMine}{ProjectConfig.versionForge}> Domen: {ProjectConfig.Domen}";
         Runtime.ShowGradleCop();
         Terminal.WriteLine($"Project §8{Path.GetFileName(path).Replace("_", " ")}§f §aloaded§f.");
         return true;
     }
     catch (Exception ex)
     {
         Terminal.WriteLine(ex);
         return false;
     }
 }