internal static bool IsZipArchive(Uri location) { if (!location.IsFile) { return(false); } return(TemplateBase.IsZipArchive(location.LocalPath)); }
protected Stream OpenRead(string file, Uri root) { if (TemplateBase.IsZipArchive(root)) { return(this.ZipArchive.OpenRead(file)); } Uri uri = this.ResolveFileUri(file, root); if (!uri.IsFile || !File.Exists(uri.LocalPath)) { return(null); } return(File.OpenRead(uri.LocalPath)); }
public string ParseTemplate(string templateName, ICollection <TemplateArgument> arguments) { string end; if (!TemplateBase.IsZipArchive(this.templateLocation)) { using (StreamReader streamReader = new StreamReader(Path.Combine(this.templateLocation, templateName))) { end = streamReader.ReadToEnd(); } } else { using (StreamReader streamReader1 = ZipHelper.CreateZipArchive(this.templateLocation).OpenText(templateName)) { end = streamReader1.ReadToEnd(); } } return(TemplateParser.EvaluateTemplate(TemplateParser.ReplaceTemplateArguments(end, arguments))); }
protected StreamReader OpenText(string file, Uri root) { if (!TemplateBase.IsZipArchive(root)) { return(new StreamReader(this.ResolveFileUri(file, root).LocalPath)); } Microsoft.Expression.SubsetFontTask.Zip.ZipArchive zipArchive = this.ZipArchive; if (zipArchive[file] != null) { return(zipArchive.OpenText(file)); } string str = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (zipArchive[str] == null) { CultureInfo currentCulture = CultureInfo.CurrentCulture; string couldNotFindFile = ExceptionStringTable.CouldNotFindFile; object[] objArray = new object[] { string.Concat(this.TemplateLocation.LocalPath, "[", file, "]") }; throw new FileNotFoundException(string.Format(currentCulture, couldNotFindFile, objArray)); } return(zipArchive.OpenText(str)); }
protected bool CreateFile(string source, Uri sourceLocation, Uri destination, bool replaceParameters, IEnumerable <TemplateArgument> templateArguments) { bool flag; string str = TemplateParser.ReplaceTemplateArguments(destination.LocalPath, templateArguments); string directoryName = Path.GetDirectoryName(str); if (!string.IsNullOrEmpty(directoryName) && !Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(directoryName)) { try { Directory.CreateDirectory(directoryName); } catch (IOException oException) { flag = false; return(flag); } catch (UnauthorizedAccessException unauthorizedAccessException) { flag = false; return(flag); } } if (!replaceParameters) { try { if (!TemplateBase.IsZipArchive(sourceLocation)) { File.Copy(this.ResolveFileUri(source, sourceLocation).LocalPath, str, true); } else if (!this.ZipArchive.Exists(source)) { flag = false; return(flag); } else { this.ZipArchive.CopyToFile(source, str); } return(true); } catch (IOException oException1) { flag = false; } catch (UnauthorizedAccessException unauthorizedAccessException1) { flag = false; } } else { StreamReader streamReader = this.OpenText(source, sourceLocation); try { File.WriteAllText(str, TemplateParser.ParseTemplate(streamReader, templateArguments), Encoding.UTF8); return(true); } catch (IOException oException2) { flag = false; } catch (UnauthorizedAccessException unauthorizedAccessException2) { flag = false; } catch (SecurityException securityException) { flag = false; } } return(flag); }