/// <summary> /// Extracts a file's contents from the embedded zip archive into memory. /// </summary> private static void ExtractTemplateZipToMemory() { string appJavaPath = BuildTargetAndroid.Instance.GetCompiledPath(BuildTargetAndroid.STUDIO_PROJECT_DIR, "app", "src", "main", "java", AndroidMetadata.PackageName.Replace('.', System.IO.Path.DirectorySeparatorChar)); using (MemoryStream zipStream = new MemoryStream(Properties.Resources.templateZip)) using (ZipStorer zip = ZipStorer.Open(zipStream, FileAccess.Read)) { List <ZipStorer.ZipFileEntry> files = zip.ReadCentralDir(); // get list of files in the zip foreach (ZipStorer.ZipFileEntry entry in files) { string filenameInZip = entry.FilenameInZip; string fullPath = BuildTargetAndroid.Instance.GetCompiledPath(BuildTargetAndroid.STUDIO_PROJECT_DIR, filenameInZip); bool isAppJavaFile = filenameInZip.StartsWith("app") && filenameInZip.EndsWith(".java"); if (isAppJavaFile) { fullPath = System.IO.Path.Combine(appJavaPath, System.IO.Path.GetFileName(filenameInZip)); } TemplateFilePath shortName = new TemplateFilePath(filenameInZip, fullPath); using (MemoryStream stream = new MemoryStream((int)entry.FileSize)) { zip.ExtractFile(entry, stream); _files.Add(shortName, new TemplateFile(shortName, stream.ToArray())); } } } }
/// <summary> /// Create a template file from the given TemplateFilePath and contents. /// </summary> private TemplateFile(TemplateFilePath path, byte[] contents) { Path = path; Contents = contents; _tags = GetTemplateTagsForFile(path); foreach (TemplateTag tag in _tags) { tag.AddFile(this); } }