Esempio n. 1
0
        private void CutFiles(string filename, string id, string prevId, string splitFilename)
        {
            string prevIdAtt = prevId;
            string idAtt     = id;
            string html      = GetHtml(filename);

            if (!String.IsNullOrEmpty(html))
            {
                List <string> File          = GetHtmlBody(html);
                string        Head          = GetHead(html);
                List <string> ExtractedBody = new List <string>();
                idAtt     = id != "" ? "id=\"" + id : id;
                prevIdAtt = String.IsNullOrEmpty(prevId) ? "id=\"" + prevId : prevId;
                //string nameAtt = id != "" ? "name=\"" + id : id;
                //string prevNameAtt = !String.IsNullOrEmpty(prevId) ? "name=\"" + prevId : prevId;

                if (String.IsNullOrEmpty(idAtt))
                {
                    // Just for the last file
                    ExtractedBody = File.SkipWhile(x => !x.Contains(prevIdAtt)).ToList();
                }
                else
                {
                    ExtractedBody = File.SkipWhile(x => !x.Contains(prevIdAtt))
                                    .TakeWhile(x => !x.Contains(idAtt)).ToList();
                }


                StringBuilder sb = new StringBuilder();
                sb.Append(Head);
                //sb.AppendLine(BodyHeading);
                ExtractedBody.ForEach(x => sb.AppendLine(x));
                string newHtml = sb.ToString();

                if (ExtractedBody.Count <= 2 || prevIdAtt == "" && PreviousContainedAnchor)
                {
                    splitNumber--;
                }
                else
                {
                    MyHtmlDocument htmlDoc    = new MyHtmlDocument();
                    string         TidiedHTML = htmlDoc.TidyHtml(newHtml);
                    htmlDoc.fileOutStream = TidiedHTML.ToStream();

                    string file = ZipFileNames.Where(x => x == Variables.OPFpath + filename).Select(x => x).FirstOrDefault().Replace(filename, splitFilename);
                    htmlDoc.fileOutName = file;
                    htmlDoc.UpdateZip();
                }
            }
        }
Esempio n. 2
0
        private void ExportNewCover(object sender, CoverChangedArgs e)
        {
            using (new HourGlass())
            {
                if (e.Cover != null && ImageNode != null)
                {
                    bool ChangedCoverFile = false;

                    #region Replace Existing File with the New One if it is different
                    if (!ImageCompare(e.Cover, BookImage))
                    {
                        fileOutName   = Zip.GetFilePathInsideZip(ImageURL);
                        fileOutStream = e.Cover.ToStream(GetImageType(BookImage));
                        UpdateZip();
                        SaveOpfFixToFile();
                        e.Message        = SaveMessage;
                        ChangedCoverFile = true;
                    }
                    else
                    {
                        e.Message = "File has not changed, Aborting";
                    }
                    #endregion

                    //Make sure it is scaled to fit
                    bool FixedCoverWidth = FixHtml(e);

                    if (FixedCoverWidth)
                    {
                        MyHtmlDoc.fileOutStream = MyHtmlDoc.TidyHtml(ImageNode.OwnerDocument.DocumentNode.OuterHtml).ToStream();
                        MyHtmlDoc.UpdateZip();

                        if (PreserveAspectRatio)
                        {
                            e.Message = !ChangedCoverFile ? "File has not changed, But Fixing the dimensions" : e.Message;
                        }
                        else
                        {
                            e.Message = !ChangedCoverFile ? "File has not changed, But making sure that it is scaled to fit" : e.Message;
                        }
                    }

                    #region If guide is empty add it
                    if (IsGuideEmpty)
                    {
                        MyOPFDoc.AddCoverRef(CoverFile);
                        e.Message = !ChangedCoverFile && !FixedCoverWidth ? "File has not changed, But fixing missing Cover Tag in guide" : e.Message;
                    }
                    #endregion

                    //Check to see if the cover file is the first
                    if (!Variables.MassUpdate)
                    {
                        CheckPositionOfCover();
                    }

                    //Update the stream and BookImage with the new default
                    GetImage();

                    e.ChangedCoverFile = ChangedCoverFile;
                }
                else
                {
                    e.Message = "Cover is Empty, Aborting";
                }
            }
        }