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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Directory dump.
|
|
|
|
*/
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Directory.h"
|
|
|
|
#include "../diskimg/DiskImgDetail.h"
|
|
|
|
#include "../app/FileNameConv.h"
|
|
|
|
|
|
|
|
using namespace DiskImgLib;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decide whether or not we want to handle this file.
|
|
|
|
*/
|
2014-11-25 22:34:14 +00:00
|
|
|
void ReformatDirectory::Examine(ReformatHolder* pHolder)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ReformatHolder::ReformatApplies applies = ReformatHolder::kApplicNot;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (pHolder->GetFileType() == kTypeDIR)
|
|
|
|
applies = ReformatHolder::kApplicProbably;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
pHolder->SetApplic(ReformatHolder::kReformatProDOSDirectory, applies,
|
|
|
|
ReformatHolder::kApplicNot, ReformatHolder::kApplicNot);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a ProDOS directory into a format resembling BASIC.System's
|
|
|
|
* 80-column "catalog" command.
|
|
|
|
*/
|
2014-11-25 22:34:14 +00:00
|
|
|
int ReformatDirectory::Process(const ReformatHolder* pHolder,
|
2014-11-04 00:26:53 +00:00
|
|
|
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
|
|
|
|
ReformatOutput* pOutput)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 02:10:18 +00:00
|
|
|
const uint8_t* srcBuf = pHolder->GetSourceBuf(part);
|
2014-11-04 00:26:53 +00:00
|
|
|
long srcLen = pHolder->GetSourceLen(part);
|
|
|
|
fUseRTF = false;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (srcLen < 512 || (srcLen % 512) != 0) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("ReformatDirectory: invalid len %d", srcLen);
|
2014-11-04 00:26:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
BufPrintf(" NAME TYPE BLOCKS MODIFIED "
|
|
|
|
" CREATED ENDFILE SUBTYPE\r\n\r\n");
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
PrintDirEntries(srcBuf, srcLen, false);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
BufPrintf("\r\nDeleted entries:\r\n");
|
|
|
|
PrintDirEntries(srcBuf, srcLen, true);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if ((srcBuf[0x04] & 0xf0) == 0xf0) {
|
|
|
|
/* this is the volume directory */
|
|
|
|
BufPrintf("\r\nTotal blocks: %d\n", srcBuf[0x29] | srcBuf[0x2a] << 8);
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
SetResultBuffer(pOutput);
|
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print all of the entries in the directory.
|
|
|
|
*
|
|
|
|
* The "showDeleted" flag determines whether we show active entries or
|
|
|
|
* deleted entries.
|
|
|
|
*/
|
2014-11-25 22:34:14 +00:00
|
|
|
void ReformatDirectory::PrintDirEntries(const uint8_t* srcBuf,
|
2014-11-04 00:26:53 +00:00
|
|
|
long srcLen, bool showDeleted)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
const int kEntriesPerBlock = 0x0d; // expected value for entries per blk
|
|
|
|
const int kEntryLength = 0x27; // expected value for dir entry len
|
|
|
|
const int kMaxFileName = 15;
|
2014-11-21 02:10:18 +00:00
|
|
|
const uint8_t* pDirEntry;
|
2014-11-04 00:26:53 +00:00
|
|
|
int blockIdx;
|
|
|
|
int entryIdx;
|
|
|
|
|
|
|
|
for (blockIdx = 0; blockIdx < srcLen / 512; blockIdx++) {
|
|
|
|
pDirEntry = srcBuf + 512*blockIdx + 4; // skip 4 bytes of prev/next
|
|
|
|
|
|
|
|
for (entryIdx = 0; entryIdx < kEntriesPerBlock;
|
|
|
|
entryIdx++, pDirEntry += kEntryLength)
|
|
|
|
{
|
|
|
|
/* skip directory header; should probably check entries_per_block */
|
|
|
|
if (blockIdx == 0 && entryIdx == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((showDeleted && (pDirEntry[0x00] & 0xf0) == 0) ||
|
|
|
|
(!showDeleted && (pDirEntry[0x00] & 0xf0) != 0))
|
|
|
|
{
|
|
|
|
if (pDirEntry[0x01] == 0) /* never-used entry */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int nameLen = pDirEntry[0x00] & 0x0f;
|
|
|
|
if (nameLen == 0) {
|
|
|
|
/* scan for it */
|
|
|
|
while (pDirEntry[0x01 + nameLen] != 0 && nameLen < kMaxFileName)
|
|
|
|
nameLen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char fileName[kMaxFileName +1];
|
|
|
|
strncpy(fileName, (const char*)&pDirEntry[0x01], kMaxFileName);
|
|
|
|
fileName[nameLen] = '\0';
|
|
|
|
|
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
|
|
|
CString createStrW, modStrW;
|
2014-11-04 00:26:53 +00:00
|
|
|
A2FileProDOS::ProDate prodosDateTime;
|
|
|
|
|
|
|
|
prodosDateTime = pDirEntry[0x18] | pDirEntry[0x19] << 8 |
|
|
|
|
pDirEntry[0x1a] << 16 | pDirEntry[0x1b] << 24;
|
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
|
|
|
FormatDate(A2FileProDOS::ConvertProDate(prodosDateTime), &createStrW);
|
|
|
|
CStringA createStr(createStrW);
|
2014-11-04 00:26:53 +00:00
|
|
|
prodosDateTime = pDirEntry[0x21] | pDirEntry[0x22] << 8 |
|
|
|
|
pDirEntry[0x23] << 16 | pDirEntry[0x24] << 24;
|
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
|
|
|
FormatDate(A2FileProDOS::ConvertProDate(prodosDateTime), &modStrW);
|
|
|
|
CStringA modStr(modStrW);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
char lockedFlag = '*';
|
|
|
|
if (pDirEntry[0x1e] & 0x80)
|
|
|
|
lockedFlag = ' ';
|
|
|
|
|
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
|
|
|
CStringA auxTypeStr;
|
2014-11-21 02:10:18 +00:00
|
|
|
uint16_t auxType = pDirEntry[0x1f] | pDirEntry[0x20] << 8;
|
2014-11-04 00:26:53 +00:00
|
|
|
if (pDirEntry[0x10] == 0x06) // bin
|
|
|
|
auxTypeStr.Format("A=$%04X", auxType);
|
|
|
|
else if (pDirEntry[0x10] == 0x04) // txt
|
|
|
|
auxTypeStr.Format("R=%5d", auxType);
|
|
|
|
|
2014-12-03 01:55:19 +00:00
|
|
|
BufPrintf("%c%-15s %-3ls %6d %16s %16s %8d %s\r\n",
|
2014-11-04 00:26:53 +00:00
|
|
|
lockedFlag,
|
|
|
|
fileName,
|
|
|
|
PathProposal::FileTypeString(pDirEntry[0x10]),
|
|
|
|
pDirEntry[0x13] | pDirEntry[0x14] << 8,
|
2014-12-03 01:55:19 +00:00
|
|
|
(LPCSTR) modStr,
|
|
|
|
(LPCSTR) createStr,
|
2014-11-04 00:26:53 +00:00
|
|
|
pDirEntry[0x15] | pDirEntry[0x16] << 8 | pDirEntry[0x17] << 16,
|
2014-12-03 01:55:19 +00:00
|
|
|
(LPCSTR) auxTypeStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|