public static PushStreamContent CreateClientZip(MobileClientPlatform platform, string templateName, Dictionary <string, string> replacements) { var clientPath = HostingEnvironment.MapPath(string.Format(CultureInfo.InvariantCulture, "~/App_Data/MobileClientApp/{0}/{1}", templateName, platform.ToString())); return(CreateZip(string.Format(CultureInfo.InvariantCulture, "{0}.zip", platform.ToString()), zip => { foreach (var fileName in Directory.GetFiles(clientPath, "*", SearchOption.AllDirectories)) { var replacedFileName = fileName; if (string.IsNullOrEmpty(Path.GetExtension(fileName)) || new[] { ".png", ".jpg", ".keystore", ".exe", ".dll", ".sketch" } .Any(ext => ext.Equals(Path.GetExtension(fileName), StringComparison.OrdinalIgnoreCase))) { foreach (var pair in replacements) { replacedFileName = replacedFileName.Replace(pair.Key, pair.Value); } zip.AddFile(fileName, replacedFileName, clientPath); } else { var fileEncoding = GetEncoding(fileName); var content = File.ReadAllText(fileName, fileEncoding); foreach (var pair in replacements) { content = content.Replace(pair.Key, pair.Value); replacedFileName = replacedFileName.Replace(pair.Key, pair.Value); } using (var contentStream = content.AsStream(fileEncoding)) { zip.AddFile(replacedFileName, clientPath, contentStream); } } } })); }
public static PushStreamContent CreateClientZip(MobileClientPlatform platform, Dictionary<string, string> replacements) { var clientPath = HostingEnvironment.MapPath(string.Format("~/App_Data/MobileClientApp/{0}", platform.ToString())); return CreateZip(string.Format("{0}.zip", platform.ToString()), zip => { foreach (var fileName in Directory.GetFiles(clientPath, "*", SearchOption.AllDirectories)) { var replacedFileName = fileName; if (string.IsNullOrEmpty(Path.GetExtension(fileName)) || Path.GetExtension(fileName) == ".png") { foreach (var pair in replacements) { replacedFileName = replacedFileName.Replace(pair.Key, pair.Value); } zip.AddFile(fileName, replacedFileName, clientPath); } else { var fileEncoding = GetEncoding(fileName); var content = File.ReadAllText(fileName, fileEncoding); foreach (var pair in replacements) { content = content.Replace(pair.Key, pair.Value); replacedFileName = replacedFileName.Replace(pair.Key, pair.Value); } using (var contentStream = content.AsStream(fileEncoding)) { zip.AddFile(replacedFileName, clientPath, contentStream); } } } }); }