Exemplo n.º 1
0
        /// <summary>
        /// Create a new project with given settings.
        /// </summary>
        /// <param name="options">Project creation option</param>
        /// <param name="environment">Creating environment</param>
        /// <returns>Whether if the creation is succeed</returns>
        public static bool CreateProject(CreationOptions options, EnvironmentSetting environment)
        {
            if (!_SanityCheck(options, environment))
            {
                return(false);
            }

            CreationContext ctx = new CreationContext();

            ctx.InitializeGeneratingValues();

            CreationVariables variables = new CreationVariables(options, ctx);
            FilterProcessor   filter    = new FilterProcessor(variables);

            TemplateList templateListData = TemplateList.ReadFile(Path.Combine(environment.templatePath, "Template.txt"), filter);

            if (templateListData == null)
            {
                Console.Error.WriteLine("  [E] Cannot read template index data.");
                return(false);
            }

            if (!_DoCopyWorks(templateListData, filter, options, environment))
            {
                Console.Error.WriteLine("  [E] Copy process failed!!");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private static bool _DoCopyWorks(TemplateList templateListData, FilterProcessor filter, CreationOptions options, EnvironmentSetting environment)
        {
            // Create Project Directory
            string projectRoot = Path.Combine(environment.engineRootPath, options.projectDirctoryName);

            try
            {
                Directory.CreateDirectory(projectRoot);
            }
            catch
            {
                Console.Error.WriteLine("  [E] Cannot create project directory.");
                return(false);
            }

            string templateProjectPath = Path.Combine(environment.templatePath, "Project");

            if (!Directory.Exists(templateProjectPath))
            {
                Console.Error.WriteLine("  [E] Template project data not exists.");
            }

            templateListData.mainWorkSet.DoCopyWorks(templateProjectPath, projectRoot, filter);

            switch (options.creatingScene)
            {
            case CreationOptions.SceneGenerationType.kNone:
            {
                const string kNoneSceneGameSectionName = "None";
                if (templateListData.conditionalWorkSets.ContainsKey(kNoneSceneGameSectionName))
                {
                    templateListData.conditionalWorkSets[kNoneSceneGameSectionName].DoCopyWorks(templateProjectPath, projectRoot, filter);
                }
            }
            break;

            case CreationOptions.SceneGenerationType.kEmptyScene:
            {
                const string kEmptySceneGameSectionName = "EmptyScene";
                if (templateListData.conditionalWorkSets.ContainsKey(kEmptySceneGameSectionName))
                {
                    templateListData.conditionalWorkSets[kEmptySceneGameSectionName].DoCopyWorks(templateProjectPath, projectRoot, filter);
                }
            }
            break;

            case CreationOptions.SceneGenerationType.kUIBaseScene:
            {
                const string kUIBaseSceneGameSectionName = "UIBaseScene";
                if (templateListData.conditionalWorkSets.ContainsKey(kUIBaseSceneGameSectionName))
                {
                    templateListData.conditionalWorkSets[kUIBaseSceneGameSectionName].DoCopyWorks(templateProjectPath, projectRoot, filter);
                }
            }
            break;
            }

            return(true);
        }
Exemplo n.º 3
0
            public void DoCopyWorks(string templateDataRoot, string targetProjectRoot, FilterProcessor filter)
            {
                foreach (Tuple <PathData, PathData> currentEntry in copyAllEntries)
                {
                    _CopyAllIn(currentEntry.Item1.CombineWith(templateDataRoot), currentEntry.Item2.CombineWith(targetProjectRoot));
                }

                foreach (Tuple <PathData, PathData> currentEntry in copyEntries)
                {
                    string sourceFilePath = currentEntry.Item1.CombineWith(templateDataRoot);
                    if (!File.Exists(sourceFilePath))
                    {
                        Console.Error.WriteLine("  [W] Template project data file not exists: {0}", sourceFilePath);
                        continue;
                    }
                    string targetFilePath = currentEntry.Item2.CombineWith(targetProjectRoot);
                    try
                    {
                        string parentDir = Directory.GetParent(targetFilePath).FullName;
                        Directory.CreateDirectory(parentDir);
                        File.Copy(sourceFilePath, targetFilePath);
                    }
                    catch
                    {
                        Console.Error.WriteLine("  [W] An error occured during copy {0} to {1}", sourceFilePath, targetFilePath);
                    }
                }

                var utf8WithoutBOM = new UTF8Encoding(false);

                foreach (Tuple <PathData, PathData> currentEntry in filterEntries)
                {
                    string sourceFilePath = currentEntry.Item1.CombineWith(templateDataRoot);
                    if (!File.Exists(sourceFilePath))
                    {
                        Console.Error.WriteLine("  [W] Template project data file not exists: {0}", sourceFilePath);
                        continue;
                    }

                    string fileContents = null;
                    try
                    {
                        fileContents = File.ReadAllText(sourceFilePath, Encoding.UTF8);
                    }
                    catch
                    {
                        Console.Error.WriteLine("  [W] An error occured during reading file data in {0}", sourceFilePath);
                        continue;
                    }

                    string filteredContents = filter.Filter(fileContents);

                    string targetFilePath = currentEntry.Item2.CombineWith(targetProjectRoot);
                    string fileExtension  = Path.GetExtension(targetFilePath);

                    bool isNeedBOM = false;
                    switch (fileExtension.ToLower())
                    {
                    case ".cpp":
                    case ".h":
                        isNeedBOM = true;
                        break;
                    }

                    try
                    {
                        string parentDir = Directory.GetParent(targetFilePath).FullName;
                        Directory.CreateDirectory(parentDir);
                        if (isNeedBOM)
                        {
                            File.WriteAllText(targetFilePath, filteredContents, Encoding.UTF8);
                        }
                        else
                        {
                            File.WriteAllText(targetFilePath, filteredContents, utf8WithoutBOM);
                        }
                    }
                    catch
                    {
                        Console.Error.WriteLine("  [W] An error occured during writing to project file in {0}", targetFilePath);
                    }
                }
            }
Exemplo n.º 4
0
        public static TemplateList ReadFile(string templateListFilePath, FilterProcessor contentsFilter)
        {
            if (string.IsNullOrWhiteSpace(templateListFilePath))
            {
                return(null);
            }

            TemplateList listData = new TemplateList();

            try
            {
                using (FileStream fs = new FileStream(templateListFilePath, FileMode.Open, FileAccess.Read))
                    using (TextReader rd = new StreamReader(fs))
                    {
                        WorkSet currentTargetSet = listData.mainWorkSet;

                        string lineBuffer = rd.ReadLine();
                        while (lineBuffer != null)
                        {
                            if (string.IsNullOrWhiteSpace(lineBuffer) || lineBuffer.StartsWith('#'))
                            {
                                lineBuffer = rd.ReadLine();
                                continue;
                            }
                            lineBuffer = contentsFilter.Filter(lineBuffer).Trim();

                            string[] lineTokens = lineBuffer.Split(':', StringSplitOptions.TrimEntries);
                            if (lineTokens.Length > 0)
                            {
                                if (lineTokens[0].StartsWith('['))
                                {
                                    // Section Descriptor
                                    string sectionName = _PopSectionName(lineTokens[0]);
                                    if (sectionName != null)
                                    {
                                        sectionName = sectionName.Trim();
                                        if (sectionName == string.Empty)
                                        {
                                            currentTargetSet = listData.mainWorkSet;
                                        }
                                        else
                                        {
                                            if (!listData.conditionalWorkSets.ContainsKey(sectionName))
                                            {
                                                listData.conditionalWorkSets.Add(sectionName, new WorkSet());
                                            }
                                            currentTargetSet = listData.conditionalWorkSets[sectionName];
                                        }
                                    }
                                }
                                else
                                {
                                    switch (lineTokens[0])
                                    {
                                    case "C":   // Copy
                                    {
                                        if (lineTokens.Length > 1)
                                        {
                                            PathData srcPathData    = PathData.ParsePathString(lineTokens[1]);
                                            PathData targetPathData = null;
                                            if (lineTokens.Length > 2)
                                            {
                                                targetPathData = PathData.ParsePathString(lineTokens[2]);
                                            }
                                            else
                                            {
                                                targetPathData = srcPathData;
                                            }

                                            if (lineTokens[1].EndsWith("/*"))
                                            {
                                                currentTargetSet.copyAllEntries.Add(new Tuple <PathData, PathData>(srcPathData, targetPathData));
                                            }
                                            else
                                            {
                                                currentTargetSet.copyEntries.Add(new Tuple <PathData, PathData>(srcPathData, targetPathData));
                                            }
                                        }
                                    }
                                    break;

                                    case "F":   // Filter
                                    {
                                        if (lineTokens.Length > 1)
                                        {
                                            PathData srcPathData    = PathData.ParsePathString(lineTokens[1]);
                                            PathData targetPathData = null;
                                            if (lineTokens.Length > 2)
                                            {
                                                targetPathData = PathData.ParsePathString(lineTokens[2]);
                                            }
                                            else
                                            {
                                                targetPathData = srcPathData;
                                            }
                                            currentTargetSet.filterEntries.Add(new Tuple <PathData, PathData>(srcPathData, targetPathData));
                                        }
                                    }
                                    break;
                                    }
                                }
                            }

                            lineBuffer = rd.ReadLine();
                        }
                    }
            }
            catch
            {
                return(null);
            }

            return(listData);
        }