Exemple #1
0
        /// <summary>
        /// Write current message metadata state to the index file.
        /// </summary>
        /// <param name="open">Indicates whether the file should be marked as OPEN or CLOSED.</param>
        private void SaveIndex(bool open)
        {
            fsIndex.Position = 0;
            fsIndex.SetLength(0);

            // Write the header

            fsIndex.WriteInt32(IndexMagic);     // Magic Number
            fsIndex.WriteInt32(0);              // Format Version
            fsIndex.WriteInt32(0);              // Reserved
            fsIndex.WriteInt32(0);              // Open Flag
            fsIndex.WriteInt32(messages.Count); // Message Count

            // Write the metadata.

            foreach (QueuedMsgInfo msgInfo in messages.Values)
            {
                fsIndex.WriteString16(msgInfo.ToString());
                fsIndex.WriteString16(((string)msgInfo.ProviderData).Substring(root.Length));  // Make the saved path relative
            }

            fsIndex.Position = OpenFlagOffset;
            fsIndex.WriteInt32(open ? 1 : 0);
            fsIndex.Flush();
        }
Exemple #2
0
        /// <summary>
        /// Writes a message file.
        /// </summary>
        /// <param name="path">The file path.</param>
        /// <param name="msg">The message.</param>
        /// <param name="msgInfo">The message metadata.</param>
        internal void WriteMessage(string path, QueuedMsg msg, QueuedMsgInfo msgInfo)
        {
            byte[] md5Hash;

            using (var fsMsg = new EnhancedFileStream(path, FileMode.Create, FileAccess.ReadWrite))
            {
                // Write the file header

                fsMsg.WriteInt32(MsgMagic);         // Magic Number
                fsMsg.WriteInt32(0);                // Format Version
                fsMsg.WriteInt32(0);                // Reserved
                fsMsg.WriteBytesNoLen(md5Zeros);    // MD5 hash placeholder

                // Write the message body.

                fsMsg.WriteBytes32(msg.BodyRaw);

                // Write the metadata.

                fsMsg.WriteString16(msgInfo.ToString());

                // Compute and save the MD5 hash

                fsMsg.Position = MsgHeaderSize;
                md5Hash        = MD5Hasher.Compute(fsMsg, fsMsg.Length - fsMsg.Position);
                fsMsg.Position = MsgMD5Offset;
                fsMsg.WriteBytesNoLen(md5Hash);
            }
        }
Exemple #3
0
        /// <summary>
        /// Updates a message file's metadata.
        /// </summary>
        /// <param name="path">The file path.</param>
        /// <param name="msgInfo">The message metadata.</param>
        internal void WriteMessageMetadata(string path, QueuedMsgInfo msgInfo)
        {
            using (var fsMsg = new EnhancedFileStream(path, FileMode.Open, FileAccess.ReadWrite))
            {
                // Seek past the message's header and body.

                int    cbBody;
                byte[] md5Hash;

                fsMsg.Position = MsgHeaderSize;
                cbBody         = fsMsg.ReadInt32();
                fsMsg.Position = fsMsg.Position + cbBody;

                // Write the metadata and truncate the file.

                fsMsg.WriteString16(msgInfo.ToString());
                fsMsg.SetLength(fsMsg.Position);

                // Regenerate the MD5 Hash

                fsMsg.Position = MsgMD5Offset + MD5Hasher.DigestSize;
                md5Hash        = MD5Hasher.Compute(fsMsg, fsMsg.Length - fsMsg.Position);
                fsMsg.Position = MsgMD5Offset;
                fsMsg.WriteBytesNoLen(md5Hash);
            }
        }
Exemple #4
0
        /// <summary>
        /// Writes the index file.
        /// </summary>
        /// <param name="path">The target file path.</param>
        /// <param name="phrases">The phrases to be written.</param>
        private void SaveIndexTo(string path, Phrase[] phrases)
        {
            using (var fs = new EnhancedFileStream(path, FileMode.Create))
            {
                fs.WriteInt32(Magic);
                fs.WriteInt32(phrases.Length);

                foreach (var phrase in phrases)
                {
                    fs.WriteString16(phrase.PhraseType.ToString());
                    fs.WriteString32(phrase.Text);
                    fs.WriteString16(phrase.Voice);
                    fs.WriteString16(phrase.ActualVoice);
                    fs.WriteString16(phrase.Encoding.ToString());
                    fs.WriteString16(phrase.SampleRate.ToString());
                    fs.WriteInt64(phrase.LastAccessUtc.Ticks);
                    fs.WriteString16(phrase.Path);
                }
            }
        }