private bool SaveFile(Entrie entrie) { var filePath = CreatePath(entrie); if (String.IsNullOrEmpty(filePath)) return false; CreateDirectory(filePath); if (entrie.Response.Content.Text != null) if (entrie.Response.Content.Encoding == null) SaveFile(filePath, entrie.Response.Content.Text); else SaveByte(filePath, entrie.Response.Content.Text); return true; }
private string CreateFileName(Entrie entrie) { string name = ""; string extension = ""; switch (entrie.Response.Content.MimeType) { case "text/html": if (entrie.Response.Content.Text != null) { name = ExtractTitle(entrie.Response.Content.Text); extension = ".html"; } else return String.Empty; break; case "text/javascript": name = ""; extension = ".js"; break; case "x-unknown": name = ""; extension = ""; break; default: name = entrie.StartedDateTime; extension = String.Format(".{0}", entrie.Response.Content.MimeType.Split('/')[1]); break; } return String.Format("\\{0}{1}", illegalFileRegex.Replace(name, ""), extension); }
private string CreatePath(Entrie entrie) { return AddExtension(UrlToFilePAth(entrie.Request.Url), entrie); }
private string AddExtension(string filePath, Entrie entrie) { if (!String.IsNullOrEmpty(Path.GetExtension(filePath))) return filePath; var fileName = CreateFileName(entrie); if (String.IsNullOrEmpty(fileName)) return String.Empty; return filePath + fileName; }