michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDecodeAppleFile_h__ michael@0: #define nsDecodeAppleFile_h__ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIFile.h" michael@0: #include "nsILocalFileMac.h" michael@0: #include "nsIOutputStream.h" michael@0: michael@0: /* michael@0: ** applefile definitions used michael@0: */ michael@0: #if PRAGMA_STRUCT_ALIGN michael@0: #pragma options align=mac68k michael@0: #endif michael@0: michael@0: #define APPLESINGLE_MAGIC 0x00051600L michael@0: #define APPLEDOUBLE_MAGIC 0x00051607L michael@0: #define VERSION 0x00020000 michael@0: michael@0: #define NUM_ENTRIES 6 michael@0: michael@0: #define ENT_DFORK 1L michael@0: #define ENT_RFORK 2L michael@0: #define ENT_NAME 3L michael@0: #define ENT_COMMENT 4L michael@0: #define ENT_DATES 8L michael@0: #define ENT_FINFO 9L michael@0: michael@0: #define CONVERT_TIME 1265437696L michael@0: michael@0: /* michael@0: ** data type used in the header decoder. michael@0: */ michael@0: typedef struct ap_header michael@0: { michael@0: int32_t magic; michael@0: int32_t version; michael@0: int32_t fill[4]; michael@0: int16_t entriesCount; michael@0: michael@0: } ap_header; michael@0: michael@0: typedef struct ap_entry michael@0: { michael@0: int32_t id; michael@0: int32_t offset; michael@0: int32_t length; michael@0: michael@0: } ap_entry; michael@0: michael@0: typedef struct ap_dates michael@0: { michael@0: int32_t create, modify, backup, access; michael@0: michael@0: } ap_dates; michael@0: michael@0: #if PRAGMA_STRUCT_ALIGN michael@0: #pragma options align=reset michael@0: #endif michael@0: michael@0: /* michael@0: **Error codes michael@0: */ michael@0: enum { michael@0: errADNotEnoughData = -12099, michael@0: errADNotSupported, michael@0: errADBadVersion michael@0: }; michael@0: michael@0: michael@0: class nsDecodeAppleFile : public nsIOutputStream michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOUTPUTSTREAM michael@0: michael@0: nsDecodeAppleFile(); michael@0: virtual ~nsDecodeAppleFile(); michael@0: michael@0: nsresult Initialize(nsIOutputStream *output, nsIFile *file); michael@0: michael@0: private: michael@0: #define MAX_BUFFERSIZE 1024 michael@0: enum ParserState {parseHeaders, parseEntries, parseLookupPart, parsePart, parseSkipPart, michael@0: parseDataFork, parseResourceFork, parseWriteThrough}; michael@0: michael@0: nsCOMPtr m_output; michael@0: FSSpec m_fsFileSpec; michael@0: SInt16 m_rfRefNum; michael@0: michael@0: unsigned char * m_dataBuffer; michael@0: int32_t m_dataBufferLength; michael@0: ParserState m_state; michael@0: ap_header m_headers; michael@0: ap_entry * m_entries; michael@0: int32_t m_offset; michael@0: int32_t m_dataForkOffset; michael@0: int32_t m_totalDataForkWritten; michael@0: int32_t m_totalResourceForkWritten; michael@0: bool m_headerOk; michael@0: michael@0: int32_t m_currentPartID; michael@0: int32_t m_currentPartLength; michael@0: int32_t m_currentPartCount; michael@0: michael@0: Str255 m_comment; michael@0: ap_dates m_dates; michael@0: FInfo m_finderInfo; michael@0: FXInfo m_finderExtraInfo; michael@0: }; michael@0: michael@0: #endif