public async Task <bool> PackageIDPFFiles(ContentURI uri, string packageFilePathName, IDictionary <string, string> args) { bool bIsPackaged = false; string errorMsg = string.Empty; PackageIO packIO = new PackageIO(); packIO.CheckForPackageFileErrors(packageFilePathName, args, ref errorMsg); if (!string.IsNullOrEmpty(errorMsg)) { return(bIsPackaged); } //files are found in this directory and its subfolders CurrentDirectory = FileStorageIO.GetDirectoryName(packageFilePathName); //Directory.SetCurrentDirectory(Path.GetDirectoryName(packageFilePathName)); //1. copy container.xml file into a meta-inf subfolder string sContainerNewPath = await CopyContainerFile(uri, errorMsg); //2. copy mimetype.txt into root folder string sMimeTypeNewPath = await CopyEPubFile(uri, MIMETYPE_FILE, MIMETYPE_FILE, errorMsg); //3. create content.opf file and place in root folder //.opf extension is not liked when saving file so use temp.xml string sTempFileName = string.Concat(Helpers.GeneralHelpers.GetRandomInteger(0).ToString(), Helpers.GeneralHelpers.EXTENSION_XML); string sContentNewPath = await CopyEPubFile(uri, CONTENT_FILE, sTempFileName, errorMsg); //copy the files in args into content.opf if (errorMsg == string.Empty) { await MakeContentFile(uri, Path.GetFileNameWithoutExtension(packageFilePathName), args, sContentNewPath, errorMsg); //4. create toc.ncx file and place in root //.ncx extension is not liked when saving file so use temp.xml sTempFileName = string.Concat(Helpers.GeneralHelpers.GetRandomInteger(12223).ToString(), Helpers.GeneralHelpers.EXTENSION_XML); string sNavigationNewPath = await CopyEPubFile(uri, NCX_FILE, sTempFileName, errorMsg); //copy whatever files from args that are needed into the ncx file await MakeNavigationFile(uri, packageFilePathName, args, sNavigationNewPath, errorMsg); //copy misc. files string sTitlePath = await CopyEPubFile(uri, TITLEPAGE_FILE, TITLEPAGE_FILE, errorMsg); //add the epub files to args for zipping args.Add(sContainerNewPath, "epub"); args.Add(sMimeTypeNewPath, "epub"); args.Add(sContentNewPath, "epub"); args.Add(sNavigationNewPath, "epub"); args.Add(sTitlePath, "epub"); if (errorMsg == string.Empty) { bIsPackaged = true; } } return(bIsPackaged); }
public static string GetMiscDocURI(string existingURI) { string sMiscDocURI = string.Empty; string sDirectory = FileStorageIO.GetDirectoryName(existingURI); string sFileNameNoExt = Path.GetFileNameWithoutExtension(existingURI); string sExt = Path.GetExtension(existingURI); string sMiscFileName = string.Concat(sFileNameNoExt, GeneralHelpers.EXTENSION_MISC, sExt); sMiscDocURI = Path.Combine(sDirectory, sMiscFileName); return(sMiscDocURI); }
public bool ZipFiles(ContentURI uri, string zipFilePath, IDictionary <string, string> args) { bool bIsZipped = false; string errorMsg = string.Empty; PackageIO packIO = new PackageIO(); packIO.CheckForPackageFileErrors(zipFilePath, args, ref errorMsg); if (!string.IsNullOrEmpty(errorMsg)) { return(bIsZipped); } //filesystem //don't want the temp directory info in the file path, disrupts subfolders (i.e. in packages) Directory.SetCurrentDirectory(Path.GetDirectoryName(zipFilePath)); string sCurrentDirectory = FileStorageIO.GetDirectoryName(zipFilePath); //init the zip with the zip's file name using (FileStream zipToOpen = new FileStream(Path.GetFileName(zipFilePath), FileMode.Create)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update)) { string[] arrValues = { }; string sRelPartPath = string.Empty; string sKey = string.Empty; string sValue = string.Empty; foreach (KeyValuePair <string, string> kvp in args) { sKey = kvp.Key; sValue = kvp.Value; if (string.IsNullOrEmpty(sKey) == false && Helpers.FileStorageIO.URIAbsoluteExists( uri, sKey)) { //convert the absolute path of partFullPath into a path relative to the package root (getcurrentdirectory) sRelPartPath = AppSettings.ConvertAbsPathToRelPath(sCurrentDirectory, sKey); //will add files to the same directory as setcurrentdirectory //2.0.0 change required adding a reference to System.IO.Compression.FileSystem archive.CreateEntryFromFile(sKey, sRelPartPath); } } bIsZipped = true; } } return(bIsZipped); }
public bool PackageOpenXmlFiles(string packageFilePathName, string digitalSignatureType, IDictionary <string, string> args, out string errorMsg) { bool bIsZipped = false; errorMsg = string.Empty; CheckForPackageFileErrors(packageFilePathName, args, ref errorMsg); if (!string.IsNullOrEmpty(errorMsg)) { return(bIsZipped); } //package parts have a value with the filename of packageFilePathName string sPackagePartValue = Path.GetFileName(packageFilePathName); //files are found in this directory and it's subfolders CurrentDirectory = FileStorageIO.GetDirectoryName(packageFilePathName); Directory.SetCurrentDirectory(Path.GetDirectoryName(packageFilePathName)); //using (Package oPack = Package.Open(Path.GetFileName(packageFilePathName), // FileMode.Create)) //{ // //make a collection of std css and script files to relate to html files // List<Uri> colHeaderUris = new List<Uri>(); // AddHtmlHeadersToPackage(oPack, args, colHeaderUris, // errorMsg); // string sKey = string.Empty; // string sValue = string.Empty; // //parallel didn't work here // foreach (KeyValuePair<string, string> kvp in args) // { // sKey = kvp.Key; // sValue = kvp.Value; // if (sValue == sPackagePartValue) // { // if (string.IsNullOrEmpty(sKey) == false // && Helpers.FileStorageIO.URIAbsoluteExists(sKey)) // { // //these are all package parts // PackagePart oPackPart = null; // bool bIsPackagePart = AddPackagePart(oPack, sKey, // out oPackPart, errorMsg); // if (bIsPackagePart) // { // AddPackageRelationship(oPack, oPackPart.Uri); // //relate to std DevTreks headers // RelateHtmlHeadersToPart(oPack, oPackPart, // colHeaderUris, errorMsg); // //add resources and relationships // AddandRelateResource(sKey, args, oPack, // oPackPart, errorMsg); // } // } // } // } // //save all of the content // oPack.Flush(); // if (digitalSignatureType == DIGITAL_SIGNATURE_TYPES.all.ToString()) // { // //digitally sign all the parts and relationships in the package. // SignAllParts(oPack); // } // bIsZipped = true; //}//closes, saves, and disposes of Package return(bIsZipped); }