2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Binary II support.
|
|
|
|
*/
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
#ifndef APP_BNYARCHIVE_H
|
|
|
|
#define APP_BNYARCHIVE_H
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#include "GenericArchive.h"
|
|
|
|
|
|
|
|
|
|
|
|
class BnyArchive;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One file in a BNY archive.
|
|
|
|
*/
|
|
|
|
class BnyEntry : public GenericEntry {
|
|
|
|
public:
|
2014-11-04 00:26:53 +00:00
|
|
|
BnyEntry(BnyArchive* pArchive) :
|
|
|
|
fpArchive(pArchive), fIsSqueezed(false), fOffset(-1)
|
|
|
|
{}
|
|
|
|
virtual ~BnyEntry(void) {}
|
|
|
|
|
|
|
|
virtual int ExtractThreadToBuffer(int which, char** ppText, long* pLength,
|
2014-11-21 21:18:20 +00:00
|
|
|
CString* pErrMsg) const override;
|
2014-11-04 00:26:53 +00:00
|
|
|
virtual int ExtractThreadToFile(int which, FILE* outfp, ConvertEOL conv,
|
2014-11-21 21:18:20 +00:00
|
|
|
ConvertHighASCII convHA, CString* pErrMsg) const override;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual long GetSelectionSerial(void) const override
|
|
|
|
{ return -1; } // doesn't matter
|
|
|
|
|
|
|
|
virtual bool GetFeatureFlag(Feature feature) const override {
|
2014-11-04 00:26:53 +00:00
|
|
|
if (feature == kFeaturePascalTypes || feature == kFeatureDOSTypes ||
|
|
|
|
feature == kFeatureHasSimpleAccess)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* Test this entry by extracting it.
|
|
|
|
*
|
|
|
|
* If the file isn't compressed, just make sure the file is big enough. If
|
|
|
|
* it's squeezed, invoke the un-squeeze function with a "NULL" buffer pointer.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError TestEntry(CWnd* pMsgWnd);
|
|
|
|
|
|
|
|
bool GetSqueezed(void) const { return fIsSqueezed; }
|
|
|
|
void SetSqueezed(bool val) { fIsSqueezed = val; }
|
|
|
|
long GetOffset(void) const { return fOffset; }
|
|
|
|
void SetOffset(long offset) { fOffset = offset; }
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kBNYBlockSize = 128,
|
|
|
|
};
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* Copy data from the seeked archive to outfp, possibly converting EOL along
|
|
|
|
* the way.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError CopyData(FILE* outfp, ConvertEOL conv, ConvertHighASCII convHA,
|
|
|
|
CString* pMsg) const;
|
|
|
|
//NuError BNYUnSqueeze(ExpandBuffer* outExp) const;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
BnyArchive* fpArchive; // holds FILE* for archive
|
|
|
|
bool fIsSqueezed;
|
|
|
|
long fOffset;
|
2007-03-27 17:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BNY archive definition.
|
|
|
|
*/
|
|
|
|
class BnyArchive : public GenericArchive {
|
|
|
|
public:
|
2014-11-18 05:13:13 +00:00
|
|
|
BnyArchive(void) : fIsReadOnly(false), fFp(NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
{}
|
|
|
|
virtual ~BnyArchive(void) { (void) Close(); }
|
|
|
|
|
|
|
|
// One-time initialization; returns an error string.
|
|
|
|
static CString AppInit(void);
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
virtual OpenResult Open(const WCHAR* filename, bool readOnly,
|
2014-11-21 21:18:20 +00:00
|
|
|
CString* pErrMsg) override;
|
|
|
|
virtual CString New(const WCHAR* filename, const void* options) override;
|
|
|
|
virtual CString Flush(void) override { return ""; }
|
|
|
|
virtual CString Reload(void) override;
|
|
|
|
virtual bool IsReadOnly(void) const override { return fIsReadOnly; };
|
|
|
|
virtual bool IsModified(void) const override { return false; }
|
2015-01-13 23:54:10 +00:00
|
|
|
virtual CString GetDescription() const override { return L"Binary II"; }
|
2014-11-04 00:26:53 +00:00
|
|
|
virtual bool BulkAdd(ActionProgressDialog* pActionProgress,
|
2014-11-21 21:18:20 +00:00
|
|
|
const AddFilesDialog* pAddOpts) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual bool AddDisk(ActionProgressDialog* pActionProgress,
|
2014-11-21 21:18:20 +00:00
|
|
|
const AddFilesDialog* pAddOpts) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual bool CreateSubdir(CWnd* pMsgWnd, GenericEntry* pParentEntry,
|
2014-11-21 21:18:20 +00:00
|
|
|
const WCHAR* newName) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual bool TestSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override;
|
|
|
|
virtual bool DeleteSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual bool RenameSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual bool RenameVolume(CWnd* pMsgWnd, DiskFS* pDiskFS,
|
2014-11-21 21:18:20 +00:00
|
|
|
const WCHAR* newName) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual CString TestVolumeName(const DiskFS* pDiskFS,
|
2014-11-21 21:18:20 +00:00
|
|
|
const WCHAR* newName) const override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return "!"; }
|
|
|
|
virtual CString TestPathName(const GenericEntry* pGenericEntry,
|
2014-11-21 21:18:20 +00:00
|
|
|
const CString& basePath, const CString& newName,
|
|
|
|
char newFssep) const override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return "!"; }
|
|
|
|
virtual bool RecompressSelection(CWnd* pMsgWnd, SelectionSet* pSelSet,
|
2014-11-21 21:18:20 +00:00
|
|
|
const RecompressOptionsDialog* pRecompOpts) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual XferStatus XferSelection(CWnd* pMsgWnd, SelectionSet* pSelSet,
|
2014-11-21 21:18:20 +00:00
|
|
|
ActionProgressDialog* pActionProgress,
|
|
|
|
const XferFileOptions* pXferOpts) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return kXferFailed; }
|
|
|
|
virtual bool GetComment(CWnd* pMsgWnd, const GenericEntry* pEntry,
|
2014-11-21 21:18:20 +00:00
|
|
|
CString* pStr) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual bool SetComment(CWnd* pMsgWnd, GenericEntry* pEntry,
|
2014-11-21 21:18:20 +00:00
|
|
|
const CString& str) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual bool DeleteComment(CWnd* pMsgWnd, GenericEntry* pEntry) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
|
|
|
virtual bool SetProps(CWnd* pMsgWnd, GenericEntry* pEntry,
|
2014-11-21 21:18:20 +00:00
|
|
|
const FileProps* pProps) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return false; }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual void PreferencesChanged(void) override {}
|
|
|
|
virtual long GetCapability(Capability cap) override;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
friend class BnyEntry;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-04 00:26:53 +00:00
|
|
|
virtual CString Close(void) {
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fFp != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
fclose(fFp);
|
2014-11-18 05:13:13 +00:00
|
|
|
fFp = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual void XferPrepare(const XferFileOptions* pXferOpts) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); }
|
2015-01-05 05:04:01 +00:00
|
|
|
virtual CString XferFile(LocalFileDetails* pDetails, uint8_t** pDataBuf,
|
2014-11-21 21:18:20 +00:00
|
|
|
long dataLen, uint8_t** pRsrcBuf, long rsrcLen) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return "!"; }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual void XferAbort(CWnd* pMsgWnd) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); }
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual void XferFinish(CWnd* pMsgWnd) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); }
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
virtual ArchiveKind GetArchiveKind(void) override { return kArchiveBNY; }
|
2014-11-04 00:26:53 +00:00
|
|
|
virtual NuError DoAddFile(const AddFilesDialog* pAddOpts,
|
2015-01-05 05:04:01 +00:00
|
|
|
LocalFileDetails* pDetails) override
|
2014-11-04 00:26:53 +00:00
|
|
|
{ ASSERT(false); return kNuErrGeneric; }
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kBNYBlockSize = BnyEntry::kBNYBlockSize,
|
|
|
|
kBNYMaxFileName = 64,
|
|
|
|
kBNYMaxNativeName = 48,
|
|
|
|
kBNYFlagCompressed = (1<<7),
|
|
|
|
kBNYFlagEncrypted = (1<<6),
|
|
|
|
kBNYFlagSparse = (1),
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An entry in a Binary II archive. Each archive is essentially a stream
|
|
|
|
* of files; only the "filesToFollow" value gives any indication that
|
|
|
|
* something else follows this entry.
|
|
|
|
*
|
|
|
|
* We read this from the archive and then unpack it into GenericEntry
|
|
|
|
* fields in a BnyEntry.
|
|
|
|
*/
|
2014-11-21 21:18:20 +00:00
|
|
|
// struct BnyFileEntry; // VC++6 needs these to access private enums
|
|
|
|
// friend struct BnyFileEntry; // in this class
|
2014-11-04 00:26:53 +00:00
|
|
|
typedef struct BnyFileEntry {
|
2014-11-21 21:18:20 +00:00
|
|
|
uint16_t access;
|
|
|
|
uint16_t fileType;
|
|
|
|
uint32_t auxType;
|
|
|
|
uint8_t storageType;
|
|
|
|
uint32_t fileSize; /* in 512-byte blocks */
|
|
|
|
uint16_t prodosModDate;
|
|
|
|
uint16_t prodosModTime;
|
2014-11-04 00:26:53 +00:00
|
|
|
NuDateTime modWhen; /* computed from previous two fields */
|
2014-11-21 21:18:20 +00:00
|
|
|
uint16_t prodosCreateDate;
|
|
|
|
uint16_t prodosCreateTime;
|
2014-11-04 00:26:53 +00:00
|
|
|
NuDateTime createWhen; /* computed from previous two fields */
|
2014-11-21 21:18:20 +00:00
|
|
|
uint32_t eof;
|
|
|
|
uint32_t realEOF; /* eof is bogus for directories */
|
2014-11-04 00:26:53 +00:00
|
|
|
char fileName[kBNYMaxFileName+1];
|
|
|
|
char nativeName[kBNYMaxNativeName+1];
|
2014-11-21 21:18:20 +00:00
|
|
|
uint32_t diskSpace; /* in 512-byte blocks */
|
|
|
|
uint8_t osType; /* not exactly same as NuFileSysID */
|
|
|
|
uint16_t nativeFileType;
|
|
|
|
uint8_t phantomFlag;
|
|
|
|
uint8_t dataFlags; /* advisory flags */
|
|
|
|
uint8_t version;
|
|
|
|
uint8_t filesToFollow; /* #of files after this one */
|
|
|
|
|
|
|
|
uint8_t blockBuf[kBNYBlockSize];
|
2014-11-04 00:26:53 +00:00
|
|
|
} BnyFileEntry;
|
|
|
|
|
|
|
|
int LoadContents(void);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a BnyFileEntry structure, add an appropriate entry to the list.
|
|
|
|
*
|
|
|
|
* Note this can mangle pEntry (notably the filename).
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError LoadContentsCallback(BnyFileEntry* pEntry);
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* Test for the magic number on a file in SQueezed format.
|
|
|
|
*/
|
|
|
|
bool IsSqueezed(uint8_t one, uint8_t two);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test if this entry is a directory.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
bool IsDir(BnyFileEntry* pEntry);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for fread(). Note the arguments resemble read(2) rather
|
|
|
|
* than fread(3S).
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError BNYRead(void* buf, size_t nbyte);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Seek within an archive. Because we need to handle streaming archives,
|
|
|
|
* and don't need to special-case anything, we only allow relative
|
|
|
|
* forward seeks.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError BNYSeek(long offset);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert from ProDOS compact date format to the expanded DateTime format.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
void BNYConvertDateTime(unsigned short prodosDate,
|
|
|
|
unsigned short prodosTime, NuDateTime* pWhen);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a Binary II header.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError BNYDecodeHeader(BnyFileEntry* pEntry);
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate through a Binary II archive, loading the data.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError BNYIterate(void);
|
|
|
|
|
|
|
|
FILE* fFp;
|
|
|
|
bool fIsReadOnly;
|
2007-03-27 17:47:10 +00:00
|
|
|
};
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
#endif /*APP_BNYARCHIVE_H*/
|