Ejemplo n.º 1
0
 public void CreateZipTest1()
 {
     const string methodName = "CreateZipTest1";
     var zipObj = new ZipFolder();
     const string outputFileNoPath = "Input.zip";
     const int errCount = 0;
     TargetFolderWithFileName = Common.PathCombine(TargetFolderWithFileName, outputFileNoPath);
     zipObj.CreateZip(sourceFolder, TargetFolderWithFileName, errCount);
     bool result = File.Exists(TargetFolderWithFileName);
     Assert.IsTrue(result, methodName + " failed");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Compresses the selected folder's contents and saves the archive in the specified outputPath
        /// with the extension .epub.
        /// </summary>
        /// <param name="sourceFolder">Folder to compress</param>
        /// <param name="outputPath">Output path and filename (without extension)</param>
        public void Compress(string sourceFolder, string outputPath)
        {
            var mOdt = new ZipFolder();
            string outputPathWithFileName = outputPath + ".epub";

            // add the content to the existing epub.zip file
            string zipFile = Common.PathCombine(sourceFolder, "epub.zip");
            string contentFolder = Common.PathCombine(sourceFolder, "OEBPS");
            if (Directory.Exists(contentFolder))
            {
                string[] files = Directory.GetFiles(contentFolder);
                mOdt.AddToZip(files, zipFile);
                var sb = new StringBuilder();
                sb.Append(sourceFolder);
                sb.Append(Path.DirectorySeparatorChar);
                sb.Append("META-INF");
                sb.Append(Path.DirectorySeparatorChar);
                sb.Append("container.xml");
                var containerFile = new[] { sb.ToString() };
                mOdt.AddToZip(containerFile, zipFile);
                // copy the results to the output directory
                File.Copy(zipFile, outputPathWithFileName, true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Convert XHTML to ODT and ODM
        /// </summary>
        public bool ExportODT(PublicationInformation projInfo)
        {
            string defaultXhtml = projInfo.DefaultXhtmlFileWithPath;
            projInfo.OutputExtension = "odt";
            Common.OdType = Common.OdtType.OdtChild;
            bool returnValue = false;
            string strFromOfficeFolder = Common.PathCombine(Common.GetPSApplicationPath(), "OfficeFiles" + Path.DirectorySeparatorChar + projInfo.ProjectInputType);
            projInfo.TempOutputFolder = Common.PathCombine(Path.GetTempPath(), "OfficeFiles" + Path.DirectorySeparatorChar + projInfo.ProjectInputType);
            Common.DeleteDirectory(projInfo.TempOutputFolder);
            string strStylePath = Common.PathCombine(projInfo.TempOutputFolder, "styles.xml");
            string strContentPath = Common.PathCombine(projInfo.TempOutputFolder, "content.xml");
            CopyOfficeFolder(strFromOfficeFolder, projInfo.TempOutputFolder);
            string strMacroPath = Common.PathCombine(projInfo.TempOutputFolder, "Basic/Standard/Module1.xml");
            string outputFileName;
            string outputPath = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
            VerboseClass verboseClass = VerboseClass.GetInstance();
            if (projInfo.FileSequence != null && projInfo.FileSequence.Count > 1)
            {
                projInfo.OutputExtension = "odm";  // Master Document
                Common.OdType = Common.OdtType.OdtMaster;
                if (projInfo.DictionaryOutputName == null)
                    projInfo.DictionaryOutputName = projInfo.DefaultXhtmlFileWithPath.Replace(Path.GetExtension(projInfo.DefaultXhtmlFileWithPath), "");
                outputFileName = Common.PathCombine(outputPath, projInfo.DictionaryOutputName); // OdtMaster is created in Dictionary Name
            }
            else
            {
                // All other OdtChild files are created in the name of Xhtml or xml file Names.
                if (projInfo.DictionaryOutputName == null)
                {
                    outputFileName = projInfo.DefaultXhtmlFileWithPath.Replace(Path.GetExtension(projInfo.DefaultXhtmlFileWithPath), "");
                }
                else
                {
                    string inputFileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);
                    outputFileName = Common.PathCombine(outputPath, inputFileName);
                    Common.OdType = Common.OdtType.OdtNoMaster; // to all the Page property process
                }
            }

            string cssFile = projInfo.DefaultCssFileWithPath;
            SetBookReferenceDivInCss(cssFile);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(defaultXhtml);
            if (projInfo.DefaultRevCssFileWithPath != null && projInfo.DefaultRevCssFileWithPath.Trim().Length > 0)
            {
                if (fileNameWithoutExtension != null && fileNameWithoutExtension.ToLower() == "flexrev")
                {
                    cssFile = projInfo.DefaultRevCssFileWithPath;
                }
            }


            PreExportProcess preProcessor = new PreExportProcess(projInfo);
            if (fileNameWithoutExtension != null && fileNameWithoutExtension.ToLower() == "flexrev")
            {
                preProcessor.InsertEmptyDiv(preProcessor.ProcessedXhtml);
                preProcessor.InsertSpanAfterLetter(preProcessor.ProcessedXhtml);
            }
            preProcessor.IncludeHyphenWordsOnXhtml(preProcessor.ProcessedXhtml);
            preProcessor.GetTempFolderPath();
            preProcessor.GetDefaultLanguage(projInfo);
            projInfo.DefaultXhtmlFileWithPath = preProcessor.PreserveSpace();
            InsertFrontMatter(projInfo);
            preProcessor.MoveBookcodeFRTtoFront(projInfo.DefaultXhtmlFileWithPath);
            preProcessor.GetfigureNode();
            preProcessor.InsertKeepWithNextOnStyles(cssFile);
            preProcessor.InsertBookPageBreak();
            preProcessor.ArrangeImages();
            isMultiLanguageHeader = preProcessor.GetMultiLanguageHeader();

            Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>();
            CssTree cssTree = new CssTree();
            cssTree.OutputType = Common.OutputType.ODT;
            cssClass = cssTree.CreateCssProperty(cssFile, true);
            SetHeaderFontName(projInfo, cssClass);
            HandledInCss(ref projInfo, ref cssClass);
            int pageWidth = GetPictureWidth(cssClass);
            // BEGIN Generate Styles.Xml File
            Dictionary<string, Dictionary<string, string>> idAllClass = new Dictionary<string, Dictionary<string, string>>();
            LOStyles inStyles = new LOStyles();
            inStyles.MultiLanguageHeader = isMultiLanguageHeader;
            idAllClass = inStyles.CreateStyles(projInfo, cssClass, "styles.xml");
            projInfo.IncludeFootnoteSymbol = inStyles.CustomFootnoteCaller;
            projInfo.IncludeXRefSymbol = inStyles.CustomXRefCaller;
            projInfo.SplitFileByLetter = inStyles.SplitFileByLetter;
            projInfo.HideSpaceVerseNumber = inStyles.HideSpaceVerseNumber;
            //To set Constent variables for User Desire
            string fname = Common.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);
            string macroFileName = Common.PathCombine(projInfo.DictionaryPath, fname);

            string isToc;
            var isCoverImageInserted = EditCssValues(idAllClass, out isToc);


            _refFormat = Common.GetReferenceFormat(idAllClass, _refFormat);
            IncludeTextinMacro(strMacroPath, _refFormat, macroFileName, projInfo.IsExtraProcessing, isCoverImageInserted, isToc);

            // BEGIN Generate Meta.Xml File
            var metaXML = new LOMetaXML(projInfo.ProjectInputType);
            metaXML.CreateMeta(projInfo);
            // BEGIN Generate Content.Xml File 
            var cXML = new LOContent();
            preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml);
            preProcessor.ImagePreprocess(false);
            preProcessor.ReplaceSlashToREVERSE_SOLIDUS();
            if (projInfo.SwapHeadword)
                preProcessor.SwapHeadWordAndReversalForm();

            Dictionary<string, string> pageSize = new Dictionary<string, string>();
            pageSize["height"] = cssClass["@page"]["page-height"];
            pageSize["width"] = cssClass["@page"]["page-width"];

            projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml;

            AfterBeforeProcess afterBeforeProcess = new AfterBeforeProcess();
            afterBeforeProcess.RemoveAfterBefore(projInfo, cssClass, cssTree.SpecificityClass, cssTree.CssClassOrder);

            projInfo.TempOutputFolder += Path.DirectorySeparatorChar;
            cXML._multiLanguageHeader = isMultiLanguageHeader;

            cXML.CreateStory(projInfo, idAllClass, cssTree.SpecificityClass, cssTree.CssClassOrder, pageWidth, pageSize);
            PostProcess(projInfo);

            if (projInfo.FileSequence != null && projInfo.FileSequence.Count > 1)
            {
                var ul = new OOUtility();
                ul.CreateMasterContents(strContentPath, projInfo.FileSequence);
            }

            if (projInfo.MoveStyleToContent)
                MoveStylesToContent(strStylePath, strContentPath);

            var mODT = new ZipFolder();
            string fileNameNoPath = outputFileName + "." + projInfo.OutputExtension;
            mODT.CreateZip(projInfo.TempOutputFolder, fileNameNoPath, verboseClass.ErrorCount);

            projInfo.DictionaryOutputName = fileNameNoPath;
            try
            {
                if (File.Exists(fileNameNoPath))
                {
                    returnValue = true;
                    if (projInfo.IsOpenOutput)
                    {
                        Common.OpenOutput(fileNameNoPath);
                    }
                }
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                if (ex.NativeErrorCode == 1155)
                {
                    string installedLocation = string.Empty;
                    if (File.Exists(fileNameNoPath))
                    {
                        installedLocation = fileNameNoPath;
                        var msg = new[] { "LibreOffice application from http://www.libreoffice.org site.\nAfter downloading and installing Libre Office, please consult release notes about how to change the macro security setting to enable the macro that creates the headers." };
                        LocDB.Message("errInstallFile", "The output has been saved in " + installedLocation + ".", "Please install " + msg, msg, LocDB.MessageTypes.Error, LocDB.MessageDefault.First);
                        return false;
                    }
                    else
                    {
                        var msg = new[] { "LibreOffice application from http://www.libreoffice.org site.\nAfter downloading and installing Libre Office, please consult release notes about how to change the macro security setting to enable the macro that creates the headers." };
                        LocDB.Message("errInstallFile", "Please install " + msg, msg, LocDB.MessageTypes.Error, LocDB.MessageDefault.First);
                        return false;
                    }
                }
            }
            finally
            {
                projInfo.DefaultXhtmlFileWithPath = defaultXhtml;
                if (preProcessor != null)
                {
                    DirectoryInfo di = new DirectoryInfo(preProcessor.GetCreatedTempFolderPath);
                    Common.CleanDirectory(di);
                }
                if (projInfo.TempOutputFolder != null)
                {
                    DirectoryInfo di = new DirectoryInfo(projInfo.TempOutputFolder);
                    Common.CleanDirectory(di);
                }
            }
            return returnValue;
        }
Ejemplo n.º 4
0
 private void Compress(string sourceFolder, string ldmlFullName)
 {
     var mODT = new ZipFolder();
     mODT.CreateZip(sourceFolder, ldmlFullName, 0);
 }
Ejemplo n.º 5
0
		public void tsSend_ClickBL()
		{
			WriteCss();

			if (!_validateWebInput)
			{
				_validateWebInput = true;
				return;
			}

			string tempfolder = Path.GetTempPath();
			string folderName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
			string folderPath = Common.PathCombine(tempfolder, folderName);
			bool directoryCreated = CopyCustomStyleToSend(folderPath);
			if (directoryCreated)
			{
				try
				{
					ZipFolder zf = new ZipFolder();
					string projType = GetProjType();
					string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
					string zipFileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
					string zipOutput = Common.PathCombine(path, zipFileName + ".zip");
					zf.CreateZip(folderPath, zipOutput, 0);
					const string MailTo = "*****@*****.**";
					string MailSubject = projType + " Style Sheets and Setting file";
					string MailBody = "(Please attach the exported " + "%20" + zipOutput + " with this mail.)" +
									  "%0D%0A" + "%0D%0A";
					try
					{
						MailBody += "Extract the zip folder content to an appropriate folder on your hard drive." +
									"%0D%0A" + "%0D%0A";
						MailBody = GetMailBody(projType, MailBody);
					}
					catch
					{
					}

					Process.Start(string.Format("mailto:{0}?Subject={1}&Body={2}", MailTo,
										   MailSubject, MailBody));
				}
				catch (Exception ex)
				{

					Utils.MsgBox(ex.Message, _caption);
				}
			}
		}