Esempio n. 1
0
        public static Digest Create(string rootFolder, string outputFolder, RasterLib.DownSolver.enables enables)
        {
            DateTime startTime = DateTime.Now;

            Console.WriteLine("Starting at {0}", startTime);

            //Step : Get subfolders
            string[]      subFolders = Directory.GetDirectories(rootFolder);
            List <string> folders    = new List <string>(subFolders);

            folders.Insert(0, "./");

            Digest digest = new Digest();

            int filesAnalyzed = 0;

            //Step : Iterate through folders
            foreach (string folder in folders)
            {
                //Step : Gather input files
                string[] infiles = Directory.GetFiles(folder, "*.glyc");
                if (infiles.Length > 0)
                {
                    Directory.SetCurrentDirectory(folder);

                    Console.WriteLine("\nFolder '{0}'\n({1} files)", folder, infiles.Length);
                    if (infiles.Length == 0)
                    {
                        return(null);
                    }

                    //Step : Process input files
                    foreach (string infile in infiles)
                    {
                        filesAnalyzed++;

                        if (CodeCompiler.Analyze(infile, digest, outputFolder, enables) != 0)
                        {
                            Console.WriteLine("\n!!!!!!FAILED!!!!!!");
                            return(null);
                        }
                    }
                }
            }

            Console.WriteLine("\nTotal analyzed files = " + filesAnalyzed);

            //Step : Go back to original folder
            Directory.SetCurrentDirectory(rootFolder);

            //Step : Save digest
            string digestJson = Newtonsoft.Json.JsonConvert.SerializeObject(digest, Newtonsoft.Json.Formatting.Indented);

            Console.WriteLine("Saving digest.json");
            File.WriteAllText(outputFolder + "\\digest.json", digestJson);

            DateTime endTime = DateTime.Now;

            Console.WriteLine("Ending at {0}", endTime);
            Console.WriteLine("Time elapsed = {0}", endTime - startTime);

            return(digest);
        }
Esempio n. 2
0
        public static int Analyze(string inputFilenameWithPath, Digest digest, string outputFolder, RasterLib.DownSolver.enables enables)
        {
            string filename = Path.GetFileNameWithoutExtension(inputFilenameWithPath);
            List <CodeCompilerError> results = new List <CodeCompilerError>();

            Console.WriteLine("Analyzing: " + inputFilenameWithPath);

            string buildFolder = outputFolder;

            DateTime dt = File.GetLastWriteTime(inputFilenameWithPath);

            using (StreamReader reader = File.OpenText(inputFilenameWithPath))
            {
                string name = reader.ReadLine().TrimEnd().TrimEnd(',');

                if (name.CompareTo(filename) != 0)
                {
                    results.Add(new CodeCompilerError(inputFilenameWithPath, 0, String.Format("Filename '{0}' mismatch to '{1}'", filename, name), CodeCompilerError.Severity.Warning));
                }

                string fullcode = "";
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (line.Length > 0 && line[0] == '#')
                    {
                        //Ignore comment
                    }
                    else
                    {
                        fullcode += line + "\n";
                    }
                }
                DownSolver ds = new DownSolver(inputFilenameWithPath, enables);

                CompiledCode ca = new CompiledCode();
                ca.name        = name;
                ca.minimalCode = MultiLineCodeToSingleLineCode(fullcode);
                ca.filename    = filename + ".glyc";
                ca.path        = ".";// Path.GetDirectoryName(inputFilenameWithPath);
                ca.timestamp   = dt;

                if (digest.FindByName(ca.name) != null)
                {
                    results.Add(new CodeCompilerError(inputFilenameWithPath, 0, String.Format("{0} already exists in digest!", name), CodeCompilerError.Severity.Error));
                }
                else
                {
                    digest.codes.Add(ca);
                }

                ca.tokenCount = ds.Tokens.Count;
                if (ds.Rects != null)
                {
                    ca.rectCount = ds.Rects.Count;
                }
                if (ds.Quads != null)
                {
                    ca.quadCount = ds.Quads.Count;
                }
                if (ds.Triangles != null)
                {
                    ca.triCount = ds.Triangles.Count;
                }

                ca.SizeX = ds.Grid.SizeX;
                ca.SizeY = ds.Grid.SizeY;
                ca.SizeZ = ds.Grid.SizeZ;

                if (ds.SerializedRects != null)
                {
                    ca.SerializedRects = ds.SerializedRects.SerializedData;
                }

                if (ds.SerializedRectsMipMap != null)
                {
                    ca.SerializedRectsMipMapX16 = ds.SerializedRectsMipMap.SerializedData;
                }

                if (ds.GridIsometricLarge != null)
                {
                    ca.isometricGridLargeFilename = buildFolder + filename + "_isometric_large.png";
                    GraphicsApi.SaveFlatPng(ca.isometricGridLargeFilename, ds.GridIsometricLarge);
                }
                if (ds.GridIsometric != null)
                {
                    ca.isometricGridFilename = buildFolder + filename + "_isometric.png";
                    GraphicsApi.SaveFlatPng(ca.isometricGridFilename, ds.GridIsometric);
                }
                if (ds.GridIsometricThumb != null)
                {
                    ca.isometricGridThumbFilename = buildFolder + filename + "_isometric_thumb.png";
                    GraphicsApi.SaveFlatPng(ca.isometricGridThumbFilename, ds.GridIsometricThumb);
                }
                if (ds.GridOrthogonal != null)
                {
                    ca.orthogonalGridFilename = buildFolder + filename + "_orthogonal.png";
                    GraphicsApi.SaveFlatPng(ca.orthogonalGridFilename, ds.GridOrthogonal);
                }

                if ((enables & RasterLib.DownSolver.enables.DoDocs) != 0)
                {
                    GraphicsLib.Creators.DocumentationCreator.DocumentByCode(outputFolder, name, ca.minimalCode);
                }

                foreach (CodeCompilerError result in results)
                {
                    Console.WriteLine(result);
                    if (result.severity == CodeCompilerError.Severity.Error)
                    {
                        return(-1);
                    }
                }

                if (results.Count > 0)
                {
                    Console.WriteLine();
                }

                return(0);
            }
        }