示例#1
0
        private void ReadAllFilesCryPkg(Wax.CryPkgDecoder pkg, Dictionary <string, byte[]> output, string prefix)
        {
            string currentDir = prefix.Length == 0 ? "." : prefix;

            foreach (string dir in pkg.ListDirectory(currentDir, false, true))
            {
                string path = currentDir == "." ? dir : currentDir + "/" + dir;
                ReadAllFilesCryPkg(pkg, output, path);
            }

            foreach (string file in pkg.ListDirectory(currentDir, true, false))
            {
                string path = currentDir == "." ? file : currentDir + "/" + file;
                output[path] = pkg.ReadFileBytes(path);
            }
        }
示例#2
0
        public TemplateSet GetVmTemplates()
        {
            Dictionary <string, byte[]> output = new Dictionary <string, byte[]>();

            string crayonHome = Wax.Util.EnvironmentVariables.Get("CRAYON_HOME");

            if (crayonHome != null)
            {
                // Search %CRAYON_HOME%/vmsrc directory for the VM files for the given platforms.
                // Files associated with more specific platforms will overwrite the less specific ones.
                foreach (string platformName in this.platformNamesMostGeneralFirst)
                {
                    string packagedVmSource = Path.Join(crayonHome, "vmsrc", platformName + ".crypkg");
                    if (File.Exists(packagedVmSource))
                    {
                        byte[]            pkgBytes   = File.ReadBytes(packagedVmSource);
                        Wax.CryPkgDecoder pkgDecoder = new Wax.CryPkgDecoder(pkgBytes);
                        ReadAllFilesCryPkg(pkgDecoder, output, "");
                    }
                }
            }

#if DEBUG
            // If you're running a debug build and have the source directory present,
            // then use the Interpreter/gen files instead of the crypkg versions in CRAYON_HOME.
            if (this.activeCrayonSourceRoot != null)
            {
                output.Clear(); // reset.

                foreach (string platformName in this.platformNamesMostGeneralFirst)
                {
                    string vmTemplateDir = Path.Join(this.activeCrayonSourceRoot, "Interpreter", "gen", platformName);
                    if (Directory.Exists(vmTemplateDir))
                    {
                        ReadAllFiles(output, System.IO.Path.GetFullPath(vmTemplateDir).Length + 1, vmTemplateDir);
                    }
                }
            }
#endif

            if (output.Count == 0)
            {
                throw new System.InvalidOperationException("Could not find VM templates. Is the CRAYON_HOME environment variable set correctly?");
            }

            return(new TemplateSet(output));
        }
示例#3
0
 private void EnsureCachePopulated(string path, bool isDir)
 {
     foreach (string pkgPath in GetAllPossiblePkgPaths(path, isDir))
     {
         if (!packageStatuses.ContainsKey(pkgPath))
         {
             string pkgRealPath = pkgPath.Replace("/", Path.Separator);
             if (File.Exists(pkgRealPath))
             {
                 Wax.CryPkgDecoder pkg = new Wax.CryPkgDecoder(File.ReadBytes(pkgRealPath));
                 packageStatuses[pkgPath] = pkg;
             }
             else
             {
                 packageStatuses[pkgPath] = null;
             }
         }
     }
 }
示例#4
0
        private CryPkgPath GetPackagedPath(string fullPath, bool isDir)
        {
            string canonicalPath = fullPath.Replace('\\', '/');

            this.EnsureCachePopulated(canonicalPath, isDir);

            string pkgPath = this.GetPathOfHighestCryPkg(canonicalPath, isDir);

            if (pkgPath == null)
            {
                return(null);
            }
            string pkgDir = pkgPath.Substring(0, pkgPath.Length - ".crypkg".Length);

            Wax.CryPkgDecoder pkg         = packageStatuses[pkgPath];
            string            relativeDir = (pkgDir == canonicalPath)
                ? "."
                : canonicalPath.Substring(pkgDir.Length + 1);

            return(new CryPkgPath(relativeDir, pkg));
        }
示例#5
0
 public CryPkgPath(string path, Wax.CryPkgDecoder package)
 {
     this.Package = package;
     this.Path    = path;
 }