示例#1
0
        internal override void UpdateFile()
        {
            //if (File.Exists(Variables.SigilDefaultPath))
            //{
            //    Properties.Settings.Default.SigilPath = Variables.SigilDefaultPath;
            //    Properties.Settings.Default.Save();
            //}

            if (Properties.Settings.Default.SigilPath == "")
            {
                System.Windows.Forms.MessageBox.Show("Sigil path not set!");
                return;
            }

            if (!File.Exists(Properties.Settings.Default.SigilPath))
            {
                System.Windows.Forms.MessageBox.Show("Sigil not found");
                return;
            }

            SaveOpfFixToFile();

            //GetBackupTOC
            string ncxFile   = Variables.NCXFile;
            Stream BackupTOC = GetStreamOPF(ncxFile);

            base.SaveBackup();
            ProcessStartInfo start = new ProcessStartInfo(Properties.Settings.Default.SigilPath);

            start.Arguments       = "\"" + Variables.Filename + "\"";
            start.UseShellExecute = false;

            Cursor.Current = Cursors.WaitCursor;
            Process proc = Process.Start(start);

            Cursor.Current = Cursors.Default;
            proc.WaitForExit();

            Variables.OPFfile          = string.Empty;
            Variables.NCXFile          = string.Empty;
            Variables.ZipFileList      = new List <string>();
            Variables.FilesPathFromOPF = new List <string>();
            OpfDocument doc = new OpfDocument();

            FileList = doc.GetFilesList("html");

            XElement NavMap = GetXmlElement(BackupTOC, "navMap");

            RearrangeTOC(NavMap);
            if (!ReplaceNavMap(NavMap))
            {
                return;
            }


            WriteXML();

            //Find toc.ncx path in Zip
            //fileOutName = Utils.GetFilePathInsideZip(ncxFile);
            fileOutName = Zip.GetFilePathInsideZip(Variables.NCXFile);

            UpdateZip(fileOutStream);
        }
示例#2
0
 private void ExtractFiles()
 {
     Zip zip = new Zip();
     zip.ExtractProgress += new EventHandler<ExtractProgressArgs>(Utils_ExtractProgress);
     t = new Thread(new ThreadStart(zip.ExtractZip));
     t.IsBackground = true;
     t.Start();
     FilesExtracted = true;
 }
示例#3
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";
                }
            }
        }