ciderpress/app/NufxArchive.h

257 lines
9.0 KiB
C
Raw Normal View History

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.
*/
/*
* NuFX archive 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_NUFXARCHIVE_H
#define APP_NUFXARCHIVE_H
2007-03-27 17:47:10 +00:00
#include "GenericArchive.h"
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
#include "../nufxlib/NufxLib.h" // ideally this wouldn't be here, only in .cpp
2007-03-27 17:47:10 +00:00
/*
* One file in an NuFX archive.
*/
class NufxEntry : public GenericEntry {
public:
NufxEntry(NuArchive* pArchive) : fpArchive(pArchive)
{}
virtual ~NufxEntry(void) {}
NuRecordIdx GetRecordIdx(void) const { return fRecordIdx; }
void SetRecordIdx(NuRecordIdx idx) { fRecordIdx = idx; }
virtual int ExtractThreadToBuffer(int which, char** ppText, long* pLength,
CString* pErrMsg) const override;
virtual int ExtractThreadToFile(int which, FILE* outfp, ConvertEOL conv,
ConvertHighASCII convHA, CString* pErrMsg) const override;
virtual long GetSelectionSerial(void) const override { return fRecordIdx; }
virtual bool GetFeatureFlag(Feature feature) const override {
if (feature == kFeaturePascalTypes || feature == kFeatureDOSTypes ||
feature == kFeatureHasSimpleAccess)
2015-01-12 00:11:44 +00:00
{
return false;
2015-01-12 00:11:44 +00:00
} else {
return true;
2015-01-12 00:11:44 +00:00
}
}
/*
* Analyzes the contents of a record to determine if it's a disk, file,
* or "other". Computes the total compressed and uncompressed lengths
* of all data threads. Fills out several GenericEntry fields.
*/
void AnalyzeRecord(const NuRecord* pRecord);
friend class NufxArchive;
2007-03-27 17:47:10 +00:00
private:
/*
* Find info for the thread we're about to extract.
*
* Given the NuRecordIdx stored in the object, find the thread whose
* ThreadID matches "which". Copies the NuThread structure into
* "*pThread".
*
* On entry *pErrMsg must be an empty string. On failure, it will
* contain an error message describing the problem.
*/
void FindThreadInfo(int which, NuThread* pThread, CString* pErrMsg) const;
2007-03-27 17:47:10 +00:00
NuRecordIdx fRecordIdx; // unique record index
NuArchive* fpArchive;
2007-03-27 17:47:10 +00:00
};
/*
* A generic archive plus NuFX-specific goodies.
*/
class NufxArchive : public GenericArchive {
public:
NufxArchive(void) :
2014-11-18 05:13:13 +00:00
fpArchive(NULL),
fIsReadOnly(false),
fProgressAsRecompress(false),
fNumAdded(-1),
2014-11-18 05:13:13 +00:00
fpMsgWnd(NULL),
fpAddOpts(NULL)
{}
virtual ~NufxArchive(void) { (void) Close(); }
/*
* Perform one-time initialization of the NufxLib library.
*
* Returns with an error if the NufxLib version is off. Major version must
* match (since it indicates an interface change), minor version must be
* >= what we expect (in case we're relying on recent behavior changes).
*
* Returns 0 on success, nonzero on error.
*/
static CString AppInit(void);
/*
* Finish instantiating a NufxArchive object by opening an existing file.
*/
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,
CString* pErrMsg) override;
/*
* Finish instantiating a NufxArchive object by creating a new archive.
*
* Returns an error string on failure, or "" on success.
*/
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; }
virtual CString GetDescription() const override { return L"NuFX"; }
virtual bool BulkAdd(ActionProgressDialog* pActionProgress,
const AddFilesDialog* pAddOpts) override;
virtual bool AddDisk(ActionProgressDialog* pActionProgress,
const AddFilesDialog* pAddOpts) override;
virtual bool CreateSubdir(CWnd* pMsgWnd, GenericEntry* pParentEntry,
const WCHAR* newName) override
{ ASSERT(false); return false; }
virtual bool TestSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override;
virtual bool DeleteSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override;
virtual bool RenameSelection(CWnd* pMsgWnd, SelectionSet* pSelSet) override;
virtual CString TestPathName(const GenericEntry* pGenericEntry,
const CString& basePath, const CString& newName,
char newFssep) const override;
virtual bool RenameVolume(CWnd* pMsgWnd, DiskFS* pDiskFS,
const WCHAR* newName) override
{ ASSERT(false); return false; }
virtual CString TestVolumeName(const DiskFS* pDiskFS,
const WCHAR* newName) const override
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
{ ASSERT(false); return L"!"; }
virtual bool RecompressSelection(CWnd* pMsgWnd, SelectionSet* pSelSet,
const RecompressOptionsDialog* pRecompOpts) override;
virtual XferStatus XferSelection(CWnd* pMsgWnd, SelectionSet* pSelSet,
ActionProgressDialog* pActionProgress,
const XferFileOptions* pXferOpts) override;
virtual bool GetComment(CWnd* pMsgWnd, const GenericEntry* pEntry,
CString* pStr) override;
virtual bool SetComment(CWnd* pMsgWnd, GenericEntry* pEntry,
const CString& str) override;
virtual bool DeleteComment(CWnd* pMsgWnd, GenericEntry* pEntry) override;
virtual bool SetProps(CWnd* pMsgWnd, GenericEntry* pEntry,
const FileProps* pProps) override;
virtual void PreferencesChanged(void) override;
virtual long GetCapability(Capability cap) override;
// try not to use this
NuArchive* GetNuArchivePointer(void) const { return fpArchive; }
// determine whether a particular type of compression is supported
static bool IsCompressionSupported(NuThreadFormat format);
// convert from DateTime format to time_t
static time_t DateTimeToSeconds(const NuDateTime* pDateTime);
2007-03-27 17:47:10 +00:00
private:
virtual CString Close(void) {
2014-11-18 05:13:13 +00:00
if (fpArchive != NULL) {
LOGI("Closing archive (aborting any un-flushed changes)");
NuAbort(fpArchive);
NuClose(fpArchive);
2014-11-18 05:13:13 +00:00
fpArchive = NULL;
}
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
return L"";
}
// recompress one thread
bool RecompressThread(NufxEntry* pEntry, int threadKind,
const RecompressOptionsDialog* pRecompOpts, long* pSizeInMemory,
CString* pErrMsg);
virtual void XferPrepare(const XferFileOptions* pXferOpts) override;
virtual CString XferFile(LocalFileDetails* pDetails, uint8_t** pDataBuf,
long dataLen, uint8_t** pRsrcBuf, long rsrcLen) override;
virtual void XferAbort(CWnd* pMsgWnd) override;
virtual void XferFinish(CWnd* pMsgWnd) override;
virtual ArchiveKind GetArchiveKind(void) override { return kArchiveNuFX; }
// prepare to add files
void AddPrep(CWnd* pWnd, const AddFilesDialog* pAddOpts);
/*
* Reset some things after we finish adding files. We don't necessarily
* want these to stay in effect for other operations, e.g. extracting.
*/
void AddFinish(void);
virtual NuError DoAddFile(const AddFilesDialog* pAddOpts,
LocalFileDetails* pDetails) override;
/*
* Error handler callback for "bulk" adds.
*/
static NuResult BulkAddErrorHandler(NuArchive* pArchive, void* vErrorStatus);
/*
* Decide whether or not to replace an existing file (during extract)
* or record (during add).
*/
NuResult HandleReplaceExisting(const NuErrorStatus* pErrorStatus);
/*
* A file that used to be there isn't anymore.
*
* This should be exceedingly rare.
*/
NuResult HandleAddNotFound(const NuErrorStatus* pErrorStatus);
/*
* Load the contents of an archive into the GenericEntry/NufxEntry list.
*/
NuError LoadContents(void);
/*
* Reload the contents of the archive, showing an error message if the
* reload fails.
*/
NuError InternalReload(CWnd* pMsgWnd);
/*
* Static callback function. Used for scanning the contents of an archive.
*/
static NuResult ContentFunc(NuArchive* pArchive, void* vpRecord);
/*
* Set some standard callbacks and feature flags.
*/
NuError SetCallbacks(void);
// handle progress update messages
static NuResult ProgressUpdater(NuArchive* pArchive, void* vpProgress);
// handle error and debug messages from NufxLib.
static NuResult NufxErrorMsgHandler(NuArchive* pArchive,
void* vErrorMessage);
// handle a DataSource resource release request; used for memory allocated
// with new[]
static NuResult ArrayDeleteHandler(NuArchive* pArchive, void* ptr);
NuArchive* fpArchive;
bool fIsReadOnly;
bool fProgressAsRecompress; // tweak progress updater
/* state while adding files */
int fNumAdded;
CWnd* fpMsgWnd;
const AddFilesDialog* fpAddOpts;
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_NUFXARCHIVE_H*/