コード例 #1
0
        /// <summary>
        /// Convert the current record to a GZipped Base64 string
        /// </summary>
        /// <returns></returns>
        public string ToRawForm()
        {
            var rawDoc = Serializers.PxzRecordToXml(this);
            var rawXml = rawDoc.OuterXml;

            return(GZipCompressor.CompressString(rawXml));
        }
コード例 #2
0
        /// <summary>
        /// Save this PXZ file to disk
        /// </summary>
        /// <param name="path">The file to save to/create</param>
        public void Save(string path)
        {
            //delete the existing file (if it exists)
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            //new index attributes (don't override records though)
            FileIndex.Author = PxzAuthor.FromCurrent();

            var idxDoc = FileIndex.ToXml();

            //deflate the content to save room (poster isn't compressed via Zlib)
            var idxByte = GZipCompressor.CompressString(idxDoc.OuterXml);

            //names of root format items
            const string idxName = @"index";
            const string recName = @"records";

            //create a new temporary Zip file (in memory, not on disk)
            using var archive = new ZipFile(path, Encoding.Default);

            //add the indexing information to the PXZ
            archive.AddEntry(idxName, idxByte);

            //add records folder
            archive.AddDirectoryByName(recName);

            //traverse the records list
            foreach (var r in Records)
            {
                //null records are skipped
                if (r == null)
                {
                    continue;
                }

                //convert to record string
                var raw = r.ToRawForm();

                //record name
                var fileName = $"{recName}/{r.Header.Naming.StoredName}";

                //add the ZIP entry of the file
                if (!archive.Any(entry => entry.FileName.EndsWith(fileName)))
                {
                    archive.AddEntry(fileName, raw);
                }
            }

            //finalise ZIP file
            archive.Save(path);

            //cull the residual archive from memory
            archive.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// rawData should NOT contain encrypted bytes; this is done here if applicable.
        /// </summary>
        /// <param name="rawData"></param>
        /// <param name="protectedData"></param>
        private void GenericConstructor(byte[] rawData, bool protectedData = false)
        {
            Encrypted = protectedData;

            //we'll need to encrypt everything if it's true
            if (protectedData)
            {
                var provider = new ProtectedBytes(rawData, ProtectionMode.Encrypt);
                rawData = provider.ProcessedValue;
            }

            RawRecord = GZipCompressor.CompressString(rawData);
        }