private static void Cleanup(OfflineFile file) { string path = file.OfflinePath; // Create Process object var tidyProcess = new Process(); tidyProcess.StartInfo.FileName = Statics.ExecutablePath + "/tidy/tidy.exe"; tidyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; try { // IMPROVE HTML Tidy settings from ui List <string> args = new List <string>(); args.Add("-quiet"); // do not print to console; maybe faster? args.Add("--tidy-mark false"); // dont create tidy meta args.Add("--write-back true"); // save formatted content to file args.Add("--output-xml true"); args.Add("--drop-proprietary-attributes true"); args.Add("--numeric-entities true"); // "ü" --> "ü" args.Add("--doctype html5"); args.Add("--uppercase-tags true"); args.Add(path); var argStr = string.Empty; foreach (var arg in args) { argStr += arg + " "; } tidyProcess.StartInfo.Arguments = argStr; Statics.Logger.Debug("Starting html tidy: " + tidyProcess.StartInfo.FileName + " " + tidyProcess.StartInfo.Arguments); // Start tidy, wait for exit tidyProcess.Start(); tidyProcess.WaitForExit(); } catch (Exception e) { Statics.Logger.Error("Some error occured: " + e.Message); tidyProcess.Dispose(); throw e; } tidyProcess.Dispose(); Statics.Logger.Debug("HtmlEditor - Tidy finished"); // manual cleanup var text = file.ContentText; // Remove tags like "<![if gt IE 7]>" so Xml does not throw an error text = Regex.Replace(text, @"<!\[(\w|\s|(\[(\w|\s)*\]))*\]>", string.Empty); // ensure that the doctype is written in caps text = Regex.Replace(text, "<!doctype html>", "<!DOCTYPE html>"); // dunno why, but the google play website is weird /*text = Regex.Replace(text, "\\\"", "\""); * text = Regex.Replace(text, "/(\\r\\n)|(\\n\\r)|\\r|\\n/g", "\n");*/ // Save changes file.ContentText = text; }
internal void Enqueue(OfflineFile file) { file.FileState = OfflineFile.State.EDIT; this.editQueue.Enqueue(file); }
internal void Enqueue(OfflineFile file) { file.FileState = OfflineFile.State.DOWNLOAD; this.downloadQueue.Enqueue(file); }
// Add files that are refered to by the file to UrisToDownload and point links to local paths private void ParseAndEdit(OfflineFile file) { Statics.Logger.Debug("HtmlEditor - Starting Parse of " + file.OfflinePath); // Load Xml XmlDocument doc = new XmlDocument(); using (var sr = new StringReader(file.ContentText)) using (var xtr = new XmlTextReader(sr) { Namespaces = false, DtdProcessing = DtdProcessing.Ignore, Normalization = true, WhitespaceHandling = WhitespaceHandling.None }) { doc.Load(xtr); } // Add direct links this.ChangeUris(doc, file, "a", "href"); // Add images if (Statics.DownloadImages) { this.ChangeUris(doc, file, "img", "src"); } // Add scripts if (Statics.DownloadScripts) { this.ChangeUris(doc, file, "script", "src"); } // Add objects if (Statics.DownloadObjects) { this.ChangeUris(doc, file, "object", "src"); } // Add styles if (Statics.DownloadStyles) { this.ChangeUris(doc, file, "link", "href"); } // Save changes using (var sw = new StringWriter()) { using (var xtw = new XmlTextWriter(sw) { Namespaces = false }) { doc.Save(xtw); xtw.Flush(); } file.ContentText = sw.ToString(); } Statics.Logger.Debug("HtmlEditor - Finished Parse of " + file.OfflinePath); }
internal void AddFile(OfflineFile file) { this.files.Add(file); }