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.
|
|
|
|
*/
|
|
|
|
/*
|
2014-11-21 21:18:20 +00:00
|
|
|
* Handle clipboard functions (copy, paste). This is part of MainWindow,
|
|
|
|
* split out into a separate file for clarity.
|
2007-03-27 17:47:10 +00:00
|
|
|
*/
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Main.h"
|
|
|
|
#include "PasteSpecialDialog.h"
|
|
|
|
|
|
|
|
|
2014-12-11 01:10:13 +00:00
|
|
|
static const WCHAR kClipboardFmtName[] = L"faddenSoft:CiderPress:v2";
|
|
|
|
const int kClipVersion = 2; // should match "vN" in fmt name
|
|
|
|
const uint16_t kEntrySignature = 0x4350;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Win98 is quietly dying on large (20MB-ish) copies. Everything
|
|
|
|
* runs along nicely and then, the next time we try to interact with
|
|
|
|
* Windows, the entire system locks up and must be Ctrl-Alt-Deleted.
|
|
|
|
*
|
|
|
|
* In tests, it blew up on 16762187 but not 16682322, both of which
|
|
|
|
* are shy of the 16MB mark (the former by about 15K). This includes the
|
|
|
|
* text version, which is potentially copied multiple times. Windows doesn't
|
|
|
|
* create the additional stuff (CF_OEMTEXT and CF_LOCALE; Win2K also creates
|
|
|
|
* CF_UNICODETEXT) until after the clipboard is closed. We can open & close
|
|
|
|
* the clipboard to get an exact count, or just multiply by a small integer
|
|
|
|
* to get a reasonable estimate (1x for alternate text, 2x for UNICODE).
|
|
|
|
*
|
|
|
|
* Microsoft Excel limits its clipboard to 4MB on small systems, and 8MB
|
|
|
|
* on systems with at least 64MB of physical memory. My guess is they
|
|
|
|
* haven't really tried larger values.
|
|
|
|
*
|
|
|
|
* The description of GlobalAlloc suggests that it gets a little weird
|
|
|
|
* when you go above 4MB, which makes me a little nervous about using
|
|
|
|
* anything larger. However, it seems to work very reliably until you
|
|
|
|
* cross 16MB, at which point it seizes up 100% of the time. It's possible
|
|
|
|
* we're stomping on stuff and just getting lucky, but it's too-reliably
|
|
|
|
* successful and too-reliably failing for me to believe that.
|
|
|
|
*/
|
|
|
|
const long kWin98ClipboardMax = 16 * 1024 * 1024;
|
2014-11-04 00:26:53 +00:00
|
|
|
const long kWin98NeutralZone = 512; // extra padding
|
|
|
|
const int kClipTextMult = 4; // CF_OEMTEXT, CF_LOCALE, CF_UNICODETEXT*2
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* File collection header.
|
|
|
|
*/
|
|
|
|
typedef struct FileCollection {
|
2014-12-11 01:10:13 +00:00
|
|
|
uint16_t version; // currently 1
|
|
|
|
uint16_t dataOffset; // offset to start of data
|
|
|
|
uint32_t length; // total length;
|
|
|
|
uint32_t count; // #of entries
|
2007-03-27 17:47:10 +00:00
|
|
|
} FileCollection;
|
|
|
|
|
|
|
|
/* what kind of entry is this */
|
|
|
|
typedef enum EntryKind {
|
2014-11-04 00:26:53 +00:00
|
|
|
kEntryKindUnknown = 0,
|
|
|
|
kEntryKindFileDataFork,
|
|
|
|
kEntryKindFileRsrcFork,
|
|
|
|
kEntryKindFileBothForks,
|
|
|
|
kEntryKindDirectory,
|
|
|
|
kEntryKindDiskImage,
|
2007-03-27 17:47:10 +00:00
|
|
|
} EntryKind;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One of these per entry in the collection.
|
|
|
|
*
|
|
|
|
* The next file starts at (start + dataOffset + dataLen + rsrcLen + cmmtLen).
|
2014-12-11 01:10:13 +00:00
|
|
|
*
|
|
|
|
* TODO: filename should be 8-bit from original, not 16-bit conversion
|
2007-03-27 17:47:10 +00:00
|
|
|
*/
|
|
|
|
typedef struct FileCollectionEntry {
|
2014-12-11 01:10:13 +00:00
|
|
|
uint16_t signature; // let's be paranoid
|
|
|
|
uint16_t dataOffset; // offset to start of data
|
|
|
|
uint16_t fileNameLen; // len of filename, in bytes
|
|
|
|
uint32_t dataLen; // len of data fork
|
|
|
|
uint32_t rsrcLen; // len of rsrc fork
|
|
|
|
uint32_t cmmtLen; // len of comments
|
|
|
|
uint32_t fileType;
|
|
|
|
uint32_t auxType;
|
|
|
|
int64_t createWhen; // time_t
|
|
|
|
int64_t modWhen; // time_t
|
|
|
|
uint8_t access; // ProDOS access flags
|
|
|
|
uint8_t entryKind; // GenericArchive::FileDetails::FileKind
|
|
|
|
uint8_t sourceFS; // DiskImgLib::DiskImg::FSFormat
|
|
|
|
uint8_t fssep; // filesystem separator char, e.g. ':'
|
|
|
|
|
|
|
|
/* data comes next: null-terminated WCHAR filename, then data fork, then
|
|
|
|
resource fork, then comment */
|
2007-03-27 17:47:10 +00:00
|
|
|
} FileCollectionEntry;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* Copy
|
2007-03-27 17:47:10 +00:00
|
|
|
* ==========================================================================
|
|
|
|
*/
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::OnEditCopy(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CString errStr, fileList;
|
|
|
|
SelectionSet selSet;
|
|
|
|
UINT myFormat;
|
|
|
|
bool isOpen = false;
|
|
|
|
HGLOBAL hGlobal;
|
|
|
|
LPVOID pGlobal;
|
2014-12-11 01:10:13 +00:00
|
|
|
uint8_t* buf = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
long bufLen = -1;
|
|
|
|
|
|
|
|
/* associate a number with the format name */
|
|
|
|
myFormat = RegisterClipboardFormat(kClipboardFmtName);
|
|
|
|
if (myFormat == 0) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_REGFAILED);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("myFormat = %u", myFormat);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* open & empty the clipboard, even if we fail later */
|
|
|
|
if (OpenClipboard() == false) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_OPENFAILED);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
isOpen = true;
|
|
|
|
EmptyClipboard();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a selection set with the entries.
|
|
|
|
*
|
|
|
|
* Strictly speaking we don't need the directories, since we recreate
|
|
|
|
* them as needed. However, storing them explicitly will allow us
|
|
|
|
* to preserve empty subdirs.
|
|
|
|
*/
|
|
|
|
selSet.CreateFromSelection(fpContentList,
|
|
|
|
GenericEntry::kAnyThread | GenericEntry::kAllowDirectory);
|
|
|
|
if (selSet.GetNumEntries() == 0) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_NOITEMS);
|
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
|
|
|
MessageBox(errStr, L"No match", MB_OK | MB_ICONEXCLAMATION);
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a big string with a file listing.
|
|
|
|
*/
|
|
|
|
fileList = CreateFileList(&selSet);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the string to the clipboard. The clipboard will own the memory we
|
|
|
|
* allocate.
|
|
|
|
*/
|
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
|
|
|
size_t neededLen = (fileList.GetLength() + 1) * sizeof(WCHAR);
|
|
|
|
hGlobal = ::GlobalAlloc(GHND | GMEM_SHARE, neededLen);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hGlobal == NULL) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Failed allocating %d bytes", neededLen);
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_ALLOCFAILED);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" Allocated %ld bytes for file list on clipboard", neededLen);
|
2014-11-04 00:26:53 +00:00
|
|
|
pGlobal = ::GlobalLock(hGlobal);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pGlobal != 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
|
|
|
wcscpy((WCHAR*) pGlobal, fileList);
|
2014-11-04 00:26:53 +00:00
|
|
|
::GlobalUnlock(hGlobal);
|
|
|
|
|
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
|
|
|
SetClipboardData(CF_UNICODETEXT, hGlobal);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a (potentially very large) buffer with the contents of the
|
|
|
|
* files in it. This may fail for any number of reasons.
|
|
|
|
*/
|
|
|
|
hGlobal = CreateFileCollection(&selSet);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hGlobal != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
SetClipboardData(myFormat, hGlobal);
|
|
|
|
// beep annoys me on copy
|
|
|
|
//SuccessBeep();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
bail:
|
2014-11-04 00:26:53 +00:00
|
|
|
CloseClipboard();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
void MainWindow::OnUpdateEditCopy(CCmdUI* pCmdUI)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
pCmdUI->Enable(fpContentList != NULL &&
|
2014-11-04 00:26:53 +00:00
|
|
|
fpContentList->GetSelectedCount() > 0);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
CString MainWindow::CreateFileList(SelectionSet* pSelSet)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
SelectionEntry* pSelEntry;
|
|
|
|
GenericEntry* pEntry;
|
|
|
|
CString tmpStr, fullStr;
|
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
|
|
|
WCHAR fileTypeBuf[ContentList::kFileTypeBufLen];
|
|
|
|
WCHAR auxTypeBuf[ContentList::kAuxTypeBufLen];
|
2014-11-04 00:26:53 +00:00
|
|
|
CString fileName, subVol, fileType, auxType, modDate, format, length;
|
|
|
|
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
2014-11-18 05:13:13 +00:00
|
|
|
while (pSelEntry != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
pEntry = pSelEntry->GetEntry();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEntry != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
fileName = DblDblQuote(pEntry->GetPathName());
|
|
|
|
subVol = pEntry->GetSubVolName();
|
|
|
|
ContentList::MakeFileTypeDisplayString(pEntry, fileTypeBuf);
|
|
|
|
fileType = DblDblQuote(fileTypeBuf); // Mac HFS types might have '"'?
|
|
|
|
ContentList::MakeAuxTypeDisplayString(pEntry, auxTypeBuf);
|
|
|
|
auxType = DblDblQuote(auxTypeBuf);
|
|
|
|
FormatDate(pEntry->GetModWhen(), &modDate);
|
|
|
|
format = pEntry->GetFormatStr();
|
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
|
|
|
length.Format(L"%I64d", (LONGLONG) pEntry->GetUncompressedLen());
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-11-19 22:54:24 +00:00
|
|
|
tmpStr.Format(L"\"%ls\"\t%ls\t\"%ls\"\t\"%ls\"\t%ls\t%ls\t%ls\r\n",
|
|
|
|
(LPCWSTR) fileName, (LPCWSTR) subVol, (LPCWSTR) fileType,
|
|
|
|
(LPCWSTR) auxType, (LPCWSTR) modDate, (LPCWSTR) format,
|
|
|
|
(LPCWSTR) length);
|
2014-11-04 00:26:53 +00:00
|
|
|
fullStr += tmpStr;
|
|
|
|
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullStr;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
/*static*/ CString MainWindow::DblDblQuote(const WCHAR* str)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CString result;
|
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
|
|
|
WCHAR* buf;
|
2014-11-04 00:26:53 +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
|
|
|
buf = result.GetBuffer(wcslen(str) * 2 +1);
|
2014-11-04 00:26:53 +00:00
|
|
|
while (*str != '\0') {
|
|
|
|
if (*str == '"') {
|
|
|
|
*buf++ = *str;
|
|
|
|
*buf++ = *str;
|
|
|
|
} else {
|
|
|
|
*buf++ = *str;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
*buf = *str;
|
|
|
|
|
|
|
|
result.ReleaseBuffer();
|
|
|
|
|
|
|
|
return result;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
long MainWindow::GetClipboardContentLen(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
long len = 0;
|
|
|
|
UINT format = 0;
|
|
|
|
HGLOBAL hGlobal;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
while ((format = EnumClipboardFormats(format)) != 0) {
|
|
|
|
hGlobal = GetClipboardData(format);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(hGlobal != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
len += GlobalSize(hGlobal);
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return len;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
HGLOBAL MainWindow::CreateFileCollection(SelectionSet* pSelSet)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
SelectionEntry* pSelEntry;
|
|
|
|
GenericEntry* pEntry;
|
2014-11-18 05:13:13 +00:00
|
|
|
HGLOBAL hGlobal = NULL;
|
|
|
|
HGLOBAL hResult = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
LPVOID pGlobal;
|
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
|
|
|
size_t totalLength, numFiles;
|
2014-11-04 00:26:53 +00:00
|
|
|
long priorLength;
|
|
|
|
|
|
|
|
/* get len of text version(s), with kluge to avoid close & reopen */
|
|
|
|
priorLength = GetClipboardContentLen() * kClipTextMult;
|
|
|
|
/* add some padding -- textmult doesn't work for fixed-size CF_LOCALE */
|
|
|
|
priorLength += kWin98NeutralZone;
|
|
|
|
|
|
|
|
totalLength = sizeof(FileCollection);
|
|
|
|
numFiles = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the amount of space required to hold it all.
|
|
|
|
*/
|
|
|
|
pSelSet->IterReset();
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
2014-11-18 05:13:13 +00:00
|
|
|
while (pSelEntry != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
pEntry = pSelEntry->GetEntry();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEntry != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI("+++ Examining '%s'", pEntry->GetDisplayName());
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (pEntry->GetRecordKind() != GenericEntry::kRecordKindVolumeDir) {
|
|
|
|
totalLength += sizeof(FileCollectionEntry);
|
2014-12-11 01:10:13 +00:00
|
|
|
totalLength += (wcslen(pEntry->GetPathName()) +1) * sizeof(WCHAR);
|
2014-11-04 00:26:53 +00:00
|
|
|
numFiles++;
|
|
|
|
if (pEntry->GetRecordKind() != GenericEntry::kRecordKindDirectory) {
|
|
|
|
totalLength += (long) pEntry->GetDataForkLen();
|
|
|
|
totalLength += (long) pEntry->GetRsrcForkLen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalLength < 0) {
|
|
|
|
DebugBreak();
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Overflow"); // pretty hard to do right now!
|
2014-11-18 05:13:13 +00:00
|
|
|
return NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
|
|
|
CString msg;
|
|
|
|
msg.Format("totalLength is %ld+%ld = %ld",
|
|
|
|
totalLength, priorLength, totalLength+priorLength);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (MessageBox(msg, NULL, MB_OKCANCEL) == IDCANCEL)
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Total length required is %ld + %ld = %ld",
|
2014-11-04 00:26:53 +00:00
|
|
|
totalLength, priorLength, totalLength+priorLength);
|
|
|
|
if (IsWin9x() && totalLength+priorLength >= kWin98ClipboardMax) {
|
|
|
|
CString errMsg;
|
|
|
|
errMsg.Format(IDS_CLIPBOARD_WIN9XMAX,
|
|
|
|
kWin98ClipboardMax / (1024*1024),
|
|
|
|
((float) (totalLength+priorLength)) / (1024.0*1024.0));
|
|
|
|
ShowFailureMsg(this, errMsg, IDS_MB_APP_NAME);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a big buffer to hold it all.
|
|
|
|
*/
|
|
|
|
hGlobal = ::GlobalAlloc(GHND | GMEM_SHARE, totalLength);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hGlobal == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
CString errMsg;
|
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
|
|
|
errMsg.Format(L"ERROR: unable to allocate %ld bytes for copy",
|
2014-11-04 00:26:53 +00:00
|
|
|
totalLength);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("%ls", (LPCWSTR) errMsg);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errMsg, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pGlobal = ::GlobalLock(hGlobal);
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pGlobal != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(GlobalSize(hGlobal) >= (DWORD) totalLength);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("hGlobal=0x%08lx pGlobal=0x%08lx size=%ld",
|
2014-11-04 00:26:53 +00:00
|
|
|
(long) hGlobal, (long) pGlobal, GlobalSize(hGlobal));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a progress dialog to track it.
|
|
|
|
*/
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpActionProgress == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
fpActionProgress = new ActionProgressDialog;
|
|
|
|
fpActionProgress->Create(ActionProgressDialog::kActionExtract, this);
|
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
|
|
|
fpActionProgress->SetFileName(L"Clipboard");
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the data into the buffer.
|
|
|
|
*/
|
|
|
|
long remainingLen;
|
|
|
|
void* buf;
|
|
|
|
|
|
|
|
remainingLen = totalLength - sizeof(FileCollection);
|
2014-12-11 01:10:13 +00:00
|
|
|
buf = (uint8_t*) pGlobal + sizeof(FileCollection);
|
2014-11-04 00:26:53 +00:00
|
|
|
pSelSet->IterReset();
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
2014-11-18 05:13:13 +00:00
|
|
|
while (pSelEntry != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
CString errStr;
|
|
|
|
|
|
|
|
pEntry = pSelEntry->GetEntry();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEntry != NULL);
|
2014-11-04 00:26:53 +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
|
|
|
CString displayName(pEntry->GetDisplayName());
|
|
|
|
fpActionProgress->SetArcName(displayName);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
errStr = CopyToCollection(pEntry, &buf, &remainingLen);
|
|
|
|
if (!errStr.IsEmpty()) {
|
|
|
|
ShowFailureMsg(fpActionProgress, errStr, IDS_MB_APP_NAME);
|
|
|
|
goto bail;
|
|
|
|
}
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI("remainingLen now %ld", remainingLen);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
pSelEntry = pSelSet->IterNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(remainingLen == 0);
|
2014-12-11 01:10:13 +00:00
|
|
|
ASSERT(buf == (uint8_t*) pGlobal + totalLength);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the header.
|
|
|
|
*/
|
|
|
|
FileCollection fileColl;
|
|
|
|
fileColl.version = kClipVersion;
|
|
|
|
fileColl.dataOffset = sizeof(FileCollection);
|
|
|
|
fileColl.length = totalLength;
|
|
|
|
fileColl.count = numFiles;
|
|
|
|
memcpy(pGlobal, &fileColl, sizeof(fileColl));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Success!
|
|
|
|
*/
|
|
|
|
::GlobalUnlock(hGlobal);
|
|
|
|
|
|
|
|
hResult = hGlobal;
|
2014-11-18 05:13:13 +00:00
|
|
|
hGlobal = NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
bail:
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hGlobal != NULL) {
|
|
|
|
ASSERT(hResult == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
::GlobalUnlock(hGlobal);
|
|
|
|
::GlobalFree(hGlobal);
|
|
|
|
}
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpActionProgress != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
fpActionProgress->Cleanup(this);
|
2014-11-18 05:13:13 +00:00
|
|
|
fpActionProgress = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
return hResult;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
CString MainWindow::CopyToCollection(GenericEntry* pEntry, void** pBuf,
|
|
|
|
long* pBufLen)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
FileCollectionEntry collEnt;
|
2014-12-11 01:10:13 +00:00
|
|
|
CString errStr;
|
|
|
|
uint8_t* buf = (uint8_t*) *pBuf;
|
2014-11-04 00:26:53 +00:00
|
|
|
long remLen = *pBufLen;
|
|
|
|
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_WRITEFAILURE);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindVolumeDir) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Not copying volume dir to collection");
|
2014-11-04 00:26:53 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remLen < sizeof(collEnt)) {
|
|
|
|
ASSERT(false);
|
|
|
|
return errStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GenericArchive::FileDetails::FileKind entryKind;
|
|
|
|
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindDirectory)
|
|
|
|
entryKind = GenericArchive::FileDetails::kFileKindDirectory;
|
|
|
|
else if (pEntry->GetHasDataFork() && pEntry->GetHasRsrcFork())
|
|
|
|
entryKind = GenericArchive::FileDetails::kFileKindBothForks;
|
|
|
|
else if (pEntry->GetHasDataFork())
|
|
|
|
entryKind = GenericArchive::FileDetails::kFileKindDataFork;
|
|
|
|
else if (pEntry->GetHasRsrcFork())
|
|
|
|
entryKind = GenericArchive::FileDetails::kFileKindRsrcFork;
|
|
|
|
else if (pEntry->GetHasDiskImage())
|
|
|
|
entryKind = GenericArchive::FileDetails::kFileKindDiskImage;
|
|
|
|
else {
|
|
|
|
ASSERT(false);
|
|
|
|
return errStr;
|
|
|
|
}
|
|
|
|
ASSERT((int) entryKind >= 0 && (int) entryKind <= 255);
|
|
|
|
|
|
|
|
memset(&collEnt, 0x99, sizeof(collEnt));
|
|
|
|
collEnt.signature = kEntrySignature;
|
|
|
|
collEnt.dataOffset = sizeof(collEnt);
|
2014-12-11 01:10:13 +00:00
|
|
|
collEnt.fileNameLen = (wcslen(pEntry->GetPathName()) +1) * sizeof(WCHAR);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindDirectory) {
|
|
|
|
collEnt.dataLen = collEnt.rsrcLen = collEnt.cmmtLen = 0;
|
|
|
|
} else {
|
2014-12-11 01:10:13 +00:00
|
|
|
collEnt.dataLen = (uint32_t) pEntry->GetDataForkLen();
|
|
|
|
collEnt.rsrcLen = (uint32_t) pEntry->GetRsrcForkLen();
|
2014-11-04 00:26:53 +00:00
|
|
|
collEnt.cmmtLen = 0; // CMMT FIX -- length unknown??
|
|
|
|
}
|
|
|
|
collEnt.fileType = pEntry->GetFileType();
|
|
|
|
collEnt.auxType = pEntry->GetAuxType();
|
|
|
|
collEnt.createWhen = pEntry->GetCreateWhen();
|
|
|
|
collEnt.modWhen = pEntry->GetModWhen();
|
2014-12-11 01:10:13 +00:00
|
|
|
collEnt.access = (uint8_t) pEntry->GetAccess();
|
|
|
|
collEnt.entryKind = (uint8_t) entryKind;
|
2014-11-04 00:26:53 +00:00
|
|
|
collEnt.sourceFS = pEntry->GetSourceFS();
|
|
|
|
collEnt.fssep = pEntry->GetFssep();
|
|
|
|
|
|
|
|
/* verify there's enough space to hold everything */
|
2014-12-11 01:10:13 +00:00
|
|
|
if ((uint32_t) remLen < collEnt.fileNameLen +
|
2014-11-04 00:26:53 +00:00
|
|
|
collEnt.dataLen + collEnt.rsrcLen + collEnt.cmmtLen)
|
|
|
|
{
|
|
|
|
ASSERT(false);
|
|
|
|
return errStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buf, &collEnt, sizeof(collEnt));
|
|
|
|
buf += sizeof(collEnt);
|
|
|
|
remLen -= sizeof(collEnt);
|
|
|
|
|
|
|
|
/* copy string with terminating null */
|
|
|
|
memcpy(buf, pEntry->GetPathName(), collEnt.fileNameLen);
|
|
|
|
buf += collEnt.fileNameLen;
|
|
|
|
remLen -= collEnt.fileNameLen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract data forks, resource forks, and disk images as appropriate.
|
|
|
|
*/
|
|
|
|
char* bufCopy;
|
|
|
|
long lenCopy;
|
|
|
|
int result, which;
|
|
|
|
|
|
|
|
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindDirectory) {
|
|
|
|
ASSERT(collEnt.dataLen == 0);
|
|
|
|
ASSERT(collEnt.rsrcLen == 0);
|
|
|
|
ASSERT(collEnt.cmmtLen == 0);
|
|
|
|
ASSERT(!pEntry->GetHasRsrcFork());
|
|
|
|
} else if (pEntry->GetHasDataFork() || pEntry->GetHasDiskImage()) {
|
|
|
|
bufCopy = (char*) buf;
|
|
|
|
lenCopy = remLen;
|
|
|
|
if (pEntry->GetHasDiskImage())
|
|
|
|
which = GenericEntry::kDiskImageThread;
|
|
|
|
else
|
|
|
|
which = GenericEntry::kDataThread;
|
|
|
|
|
2014-12-11 01:10:13 +00:00
|
|
|
CString extractErrStr;
|
2014-11-04 00:26:53 +00:00
|
|
|
result = pEntry->ExtractThreadToBuffer(which, &bufCopy, &lenCopy,
|
2014-12-11 01:10:13 +00:00
|
|
|
&extractErrStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (result == IDCANCEL) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CANCELLED);
|
2014-11-04 00:26:53 +00:00
|
|
|
return errStr;
|
|
|
|
} else if (result != IDOK) {
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGW("ExtractThreadToBuffer (data) failed: %ls",
|
|
|
|
(LPCWSTR) extractErrStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
return errStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(lenCopy == (long) collEnt.dataLen);
|
|
|
|
buf += collEnt.dataLen;
|
|
|
|
remLen -= collEnt.dataLen;
|
|
|
|
} else {
|
|
|
|
ASSERT(collEnt.dataLen == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pEntry->GetHasRsrcFork()) {
|
|
|
|
bufCopy = (char*) buf;
|
|
|
|
lenCopy = remLen;
|
|
|
|
which = GenericEntry::kRsrcThread;
|
|
|
|
|
2014-12-11 01:10:13 +00:00
|
|
|
CString extractErrStr;
|
2014-11-04 00:26:53 +00:00
|
|
|
result = pEntry->ExtractThreadToBuffer(which, &bufCopy, &lenCopy,
|
2014-12-11 01:10:13 +00:00
|
|
|
&extractErrStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (result == IDCANCEL) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CANCELLED);
|
2014-11-04 00:26:53 +00:00
|
|
|
return errStr;
|
|
|
|
} else if (result != IDOK) {
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGI("ExtractThreadToBuffer (rsrc) failed: %ls",
|
|
|
|
(LPCWSTR) extractErrStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
return errStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(lenCopy == (long) collEnt.rsrcLen);
|
|
|
|
buf += collEnt.rsrcLen;
|
|
|
|
remLen -= collEnt.rsrcLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pEntry->GetHasComment()) {
|
|
|
|
#if 0 // CMMT FIX
|
|
|
|
bufCopy = (char*) buf;
|
|
|
|
lenCopy = remLen;
|
|
|
|
which = GenericEntry::kCommentThread;
|
|
|
|
|
|
|
|
result = pEntry->ExtractThreadToBuffer(which, &bufCopy, &lenCopy);
|
|
|
|
if (result == IDCANCEL) {
|
|
|
|
errStr.LoadString(IDS_CANCELLED);
|
|
|
|
return errStr;
|
|
|
|
} else if (result != IDOK)
|
|
|
|
return errStr;
|
|
|
|
|
|
|
|
ASSERT(lenCopy == (long) collEnt.cmmtLen);
|
|
|
|
buf += collEnt.cmmtLen;
|
|
|
|
remLen -= collEnt.cmmtLen;
|
2007-03-27 17:47:10 +00:00
|
|
|
#else
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(collEnt.cmmtLen == 0);
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
*pBuf = buf;
|
|
|
|
*pBufLen = remLen;
|
|
|
|
return "";
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* Paste
|
2007-03-27 17:47:10 +00:00
|
|
|
* ==========================================================================
|
|
|
|
*/
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::OnEditPaste(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
bool pasteJunkPaths = fPreferences.GetPrefBool(kPrPasteJunkPaths);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
DoPaste(pasteJunkPaths);
|
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
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::OnUpdateEditPaste(CCmdUI* pCmdUI)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
bool dataAvailable = false;
|
|
|
|
UINT myFormat;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
myFormat = RegisterClipboardFormat(kClipboardFmtName);
|
|
|
|
if (myFormat != 0 && IsClipboardFormatAvailable(myFormat))
|
|
|
|
dataAvailable = true;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
pCmdUI->Enable(fpContentList != NULL && !fpOpenArchive->IsReadOnly() &&
|
2014-11-04 00:26:53 +00:00
|
|
|
dataAvailable);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::OnEditPasteSpecial(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
PasteSpecialDialog dlg;
|
|
|
|
bool pasteJunkPaths = fPreferences.GetPrefBool(kPrPasteJunkPaths);
|
|
|
|
|
|
|
|
// invert the meaning, so non-default mode is default in dialog
|
|
|
|
if (pasteJunkPaths)
|
|
|
|
dlg.fPasteHow = PasteSpecialDialog::kPastePaths;
|
|
|
|
else
|
|
|
|
dlg.fPasteHow = PasteSpecialDialog::kPasteNoPaths;
|
|
|
|
if (dlg.DoModal() != IDOK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (dlg.fPasteHow) {
|
|
|
|
case PasteSpecialDialog::kPastePaths:
|
|
|
|
pasteJunkPaths = false;
|
|
|
|
break;
|
|
|
|
case PasteSpecialDialog::kPasteNoPaths:
|
|
|
|
pasteJunkPaths = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DoPaste(pasteJunkPaths);
|
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
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::OnUpdateEditPasteSpecial(CCmdUI* pCmdUI)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
OnUpdateEditPaste(pCmdUI);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MainWindow::DoPaste(bool pasteJunkPaths)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CString errStr, buildStr;
|
|
|
|
UINT format = 0;
|
|
|
|
UINT myFormat;
|
|
|
|
bool isOpen = false;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpContentList == NULL || fpOpenArchive->IsReadOnly()) {
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
myFormat = RegisterClipboardFormat(kClipboardFmtName);
|
|
|
|
if (myFormat == 0) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_REGFAILED);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("myFormat = %u", myFormat);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (OpenClipboard() == false) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_OPENFAILED);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;;
|
|
|
|
}
|
|
|
|
isOpen = true;
|
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Found %d clipboard formats", CountClipboardFormats());
|
2014-11-04 00:26:53 +00:00
|
|
|
while ((format = EnumClipboardFormats(format)) != 0) {
|
|
|
|
CString tmpStr;
|
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
|
|
|
tmpStr.Format(L" %u", format);
|
2014-11-04 00:26:53 +00:00
|
|
|
buildStr += tmpStr;
|
|
|
|
}
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" %ls", (LPCWSTR) buildStr);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
if (IsClipboardFormatAvailable(CF_HDROP)) {
|
|
|
|
errStr.LoadString(IDS_CLIPBOARD_NO_HDROP);
|
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* impossible unless OnUpdateEditPaste was bypassed */
|
|
|
|
if (!IsClipboardFormatAvailable(myFormat)) {
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errStr, IDS_CLIPBOARD_NOTFOUND);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
goto bail;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("+++ total data on clipboard: %ld bytes",
|
2014-11-04 00:26:53 +00:00
|
|
|
GetClipboardContentLen());
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
HGLOBAL hGlobal;
|
|
|
|
LPVOID pGlobal;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
hGlobal = GetClipboardData(myFormat);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hGlobal == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pGlobal = GlobalLock(hGlobal);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pGlobal != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
errStr = ProcessClipboard(pGlobal, GlobalSize(hGlobal), pasteJunkPaths);
|
|
|
|
fpContentList->Reload();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (!errStr.IsEmpty())
|
|
|
|
ShowFailureMsg(this, errStr, IDS_FAILED);
|
|
|
|
else
|
|
|
|
SuccessBeep();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
GlobalUnlock(hGlobal);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
bail:
|
2014-11-04 00:26:53 +00:00
|
|
|
if (isOpen)
|
|
|
|
CloseClipboard();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
CString MainWindow::ProcessClipboard(const void* vbuf, long bufLen,
|
|
|
|
bool pasteJunkPaths)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
FileCollection fileColl;
|
|
|
|
CString errMsg, storagePrefix;
|
2014-12-11 01:10:13 +00:00
|
|
|
const uint8_t* buf = (const uint8_t*) vbuf;
|
2014-11-18 05:13:13 +00:00
|
|
|
DiskImgLib::A2File* pTargetSubdir = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
XferFileOptions xferOpts;
|
|
|
|
bool xferPrepped = false;
|
|
|
|
|
|
|
|
/* set a standard error message */
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&errMsg, IDS_CLIPBOARD_READFAILURE);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull the header out.
|
|
|
|
*/
|
|
|
|
if (bufLen < sizeof(fileColl)) {
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGW("Clipboard contents too small!");
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
memcpy(&fileColl, buf, sizeof(fileColl));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the length. Win98 seems to like to round things up to 16-byte
|
|
|
|
* boundaries, which screws up our "bufLen > 0" while condition below.
|
|
|
|
*/
|
|
|
|
if ((long) fileColl.length > bufLen) {
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGW("GLITCH: stored len=%ld, clip len=%ld",
|
2014-11-04 00:26:53 +00:00
|
|
|
fileColl.length, bufLen);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
if (bufLen > (long) fileColl.length) {
|
|
|
|
/* trim off extra */
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("NOTE: Windows reports excess length (%ld vs %ld)",
|
2014-11-04 00:26:53 +00:00
|
|
|
fileColl.length, bufLen);
|
|
|
|
bufLen = fileColl.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += sizeof(fileColl);
|
|
|
|
bufLen -= sizeof(fileColl);
|
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("FileCollection found: vers=%d off=%d len=%ld count=%ld",
|
2014-11-04 00:26:53 +00:00
|
|
|
fileColl.version, fileColl.dataOffset, fileColl.length,
|
|
|
|
fileColl.count);
|
|
|
|
if (fileColl.count == 0) {
|
|
|
|
/* nothing to do? */
|
|
|
|
ASSERT(false);
|
|
|
|
return errMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out where we want to put the files. For a disk archive
|
|
|
|
* this can be complicated.
|
|
|
|
*
|
|
|
|
* The target DiskFS (which could be a sub-volume) gets tucked into
|
|
|
|
* the xferOpts.
|
|
|
|
*/
|
|
|
|
if (fpOpenArchive->GetArchiveKind() == GenericArchive::kArchiveDiskImage) {
|
|
|
|
if (!ChooseAddTarget(&pTargetSubdir, &xferOpts.fpTargetFS))
|
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"";
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
fpOpenArchive->XferPrepare(&xferOpts);
|
|
|
|
xferPrepped = true;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pTargetSubdir != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
storagePrefix = pTargetSubdir->GetPathName();
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGD("--- using storagePrefix '%ls'", (LPCWSTR) storagePrefix);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a progress dialog to track it.
|
|
|
|
*/
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpActionProgress == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
fpActionProgress = new ActionProgressDialog;
|
|
|
|
fpActionProgress->Create(ActionProgressDialog::kActionAdd, this);
|
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
|
|
|
fpActionProgress->SetArcName(L"Clipboard data");
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop over all files.
|
|
|
|
*/
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("+++ Starting paste, bufLen=%ld", bufLen);
|
2014-11-04 00:26:53 +00:00
|
|
|
while (bufLen > 0) {
|
|
|
|
FileCollectionEntry collEnt;
|
2014-12-11 01:10:13 +00:00
|
|
|
CString fileName;
|
|
|
|
CString processErrStr;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* read the entry info */
|
|
|
|
if (bufLen < sizeof(collEnt)) {
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGW("GLITCH: bufLen=%ld, sizeof(collEnt)=%d",
|
2014-11-04 00:26:53 +00:00
|
|
|
bufLen, sizeof(collEnt));
|
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
memcpy(&collEnt, buf, sizeof(collEnt));
|
|
|
|
if (collEnt.signature != kEntrySignature) {
|
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* advance to the start of data */
|
|
|
|
if (bufLen < collEnt.dataOffset) {
|
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
buf += collEnt.dataOffset;
|
|
|
|
bufLen -= collEnt.dataOffset;
|
|
|
|
|
|
|
|
/* extract the filename */
|
|
|
|
if (bufLen < collEnt.fileNameLen) {
|
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
2014-12-11 01:10:13 +00:00
|
|
|
// TODO: consider moving filename as raw 8-bit data
|
|
|
|
fileName = (const WCHAR*) buf;
|
2014-11-04 00:26:53 +00:00
|
|
|
buf += collEnt.fileNameLen;
|
|
|
|
bufLen -= collEnt.fileNameLen;
|
|
|
|
|
2014-12-11 01:10:13 +00:00
|
|
|
LOGD("+++ pasting '%ls'", (LPCWSTR) fileName);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* strip the path (if requested) and prepend the storage prefix */
|
2014-12-11 01:10:13 +00:00
|
|
|
ASSERT((fileName.GetLength() +1 ) * sizeof(WCHAR) == collEnt.fileNameLen);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (pasteJunkPaths && collEnt.fssep != '\0') {
|
|
|
|
int idx;
|
|
|
|
idx = fileName.ReverseFind(collEnt.fssep);
|
|
|
|
if (idx >= 0)
|
|
|
|
fileName = fileName.Right(fileName.GetLength() - idx -1);
|
|
|
|
}
|
|
|
|
if (!storagePrefix.IsEmpty()) {
|
|
|
|
CString tmpStr, tmpFileName;
|
|
|
|
tmpFileName = fileName;
|
|
|
|
if (collEnt.fssep == '\0') {
|
|
|
|
tmpFileName.Replace(':', '_'); // strip any ':'s in the name
|
|
|
|
collEnt.fssep = ':'; // define an fssep
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpStr = storagePrefix;
|
|
|
|
|
|
|
|
/* storagePrefix fssep is always ':'; change it to match */
|
|
|
|
if (collEnt.fssep != ':')
|
|
|
|
tmpStr.Replace(':', collEnt.fssep);
|
|
|
|
|
|
|
|
tmpStr += collEnt.fssep;
|
|
|
|
tmpStr += tmpFileName;
|
|
|
|
fileName = tmpStr;
|
|
|
|
|
|
|
|
}
|
|
|
|
fpActionProgress->SetFileName(fileName);
|
|
|
|
|
|
|
|
/* make sure the data is there */
|
|
|
|
if (bufLen < (long) (collEnt.dataLen + collEnt.rsrcLen + collEnt.cmmtLen))
|
|
|
|
{
|
|
|
|
ASSERT(false);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the entry.
|
|
|
|
*
|
|
|
|
* If the user hits "cancel" in the progress dialog we'll get thrown
|
|
|
|
* back out. For the time being I'm just treating it like any other
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
processErrStr = ProcessClipboardEntry(&collEnt, fileName, buf, bufLen);
|
|
|
|
if (!processErrStr.IsEmpty()) {
|
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
|
|
|
errMsg.Format(L"Unable to paste '%ls': %ls.",
|
|
|
|
(LPCWSTR) fileName, (LPCWSTR) processErrStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += collEnt.dataLen + collEnt.rsrcLen + collEnt.cmmtLen;
|
|
|
|
bufLen -= collEnt.dataLen + collEnt.rsrcLen + collEnt.cmmtLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(bufLen == 0);
|
|
|
|
errMsg = "";
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
bail:
|
2014-11-04 00:26:53 +00:00
|
|
|
if (xferPrepped) {
|
|
|
|
if (errMsg.IsEmpty())
|
|
|
|
fpOpenArchive->XferFinish(this);
|
|
|
|
else
|
|
|
|
fpOpenArchive->XferAbort(this);
|
|
|
|
}
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpActionProgress != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
fpActionProgress->Cleanup(this);
|
2014-11-18 05:13:13 +00:00
|
|
|
fpActionProgress = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
return errMsg;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
CString MainWindow::ProcessClipboardEntry(const FileCollectionEntry* pCollEnt,
|
|
|
|
const WCHAR* pathName, const uint8_t* buf, long remLen)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
GenericArchive::FileDetails::FileKind entryKind;
|
|
|
|
GenericArchive::FileDetails details;
|
2014-12-11 01:10:13 +00:00
|
|
|
uint8_t* dataBuf = NULL;
|
|
|
|
uint8_t* rsrcBuf = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
long dataLen, rsrcLen, cmmtLen;
|
|
|
|
CString errMsg;
|
|
|
|
|
|
|
|
entryKind = (GenericArchive::FileDetails::FileKind) pCollEnt->entryKind;
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" Processing '%ls' (%d)", pathName, entryKind);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
details.entryKind = entryKind;
|
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
|
|
|
details.origName = L"Clipboard";
|
2014-12-11 01:10:13 +00:00
|
|
|
details.storageName = pathName; // TODO MacRoman convert
|
2014-11-04 00:26:53 +00:00
|
|
|
details.fileSysFmt = (DiskImg::FSFormat) pCollEnt->sourceFS;
|
|
|
|
details.fileSysInfo = pCollEnt->fssep;
|
|
|
|
details.access = pCollEnt->access;
|
|
|
|
details.fileType = pCollEnt->fileType;
|
|
|
|
details.extraType = pCollEnt->auxType;
|
|
|
|
GenericArchive::UNIXTimeToDateTime(&pCollEnt->createWhen,
|
|
|
|
&details.createWhen);
|
|
|
|
GenericArchive::UNIXTimeToDateTime(&pCollEnt->modWhen,
|
|
|
|
&details.modWhen);
|
2014-11-18 05:13:13 +00:00
|
|
|
time_t now = time(NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
GenericArchive::UNIXTimeToDateTime(&now, &details.archiveWhen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because of the way XferFile works, we need to make a copy of
|
|
|
|
* the data. (For NufxLib, it's going to gather up all of the
|
|
|
|
* data and flush it all at once, so it needs to own the memory.)
|
|
|
|
*
|
|
|
|
* Ideally we'd use a different interface that didn't require a
|
|
|
|
* data copy -- NufxLib can do it that way as well -- but it's
|
|
|
|
* not worth maintaining two separate interfaces.
|
|
|
|
*
|
|
|
|
* This approach does allow the xfer code to handle DOS high-ASCII
|
|
|
|
* text conversions in place, though. If we didn't do it this way
|
|
|
|
* we'd have to make a copy in the xfer code to avoid contaminating
|
|
|
|
* the clipboard data. That would be more efficient, but probably
|
|
|
|
* a bit messier.
|
|
|
|
*
|
|
|
|
* The stuff below figures out which forks we're expected to have based
|
|
|
|
* on the file type info. This helps us distinguish between a file
|
|
|
|
* with a zero-length fork and a file without that kind of fork.
|
|
|
|
*/
|
|
|
|
bool hasData = false;
|
|
|
|
bool hasRsrc = false;
|
|
|
|
if (details.entryKind == GenericArchive::FileDetails::kFileKindDataFork) {
|
|
|
|
hasData = true;
|
|
|
|
details.storageType = kNuStorageSeedling;
|
|
|
|
} else if (details.entryKind == GenericArchive::FileDetails::kFileKindRsrcFork) {
|
|
|
|
hasRsrc = true;
|
|
|
|
details.storageType = kNuStorageExtended;
|
|
|
|
} else if (details.entryKind == GenericArchive::FileDetails::kFileKindBothForks) {
|
|
|
|
hasData = hasRsrc = true;
|
|
|
|
details.storageType = kNuStorageExtended;
|
|
|
|
} else if (details.entryKind == GenericArchive::FileDetails::kFileKindDiskImage) {
|
|
|
|
hasData = true;
|
|
|
|
details.storageType = kNuStorageSeedling;
|
|
|
|
} else if (details.entryKind == GenericArchive::FileDetails::kFileKindDirectory) {
|
|
|
|
details.storageType = kNuStorageDirectory;
|
|
|
|
} else {
|
|
|
|
ASSERT(false);
|
|
|
|
return "Internal error.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasData) {
|
|
|
|
if (pCollEnt->dataLen == 0) {
|
2014-12-11 01:10:13 +00:00
|
|
|
dataBuf = new uint8_t[1];
|
2014-11-04 00:26:53 +00:00
|
|
|
dataLen = 0;
|
|
|
|
} else {
|
|
|
|
dataLen = pCollEnt->dataLen;
|
2014-12-11 01:10:13 +00:00
|
|
|
dataBuf = new uint8_t[dataLen];
|
2014-11-18 05:13:13 +00:00
|
|
|
if (dataBuf == NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
return "memory allocation failed.";
|
|
|
|
memcpy(dataBuf, buf, dataLen);
|
|
|
|
buf += dataLen;
|
|
|
|
remLen -= dataLen;
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(dataBuf == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
dataLen = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasRsrc) {
|
|
|
|
if (pCollEnt->rsrcLen == 0) {
|
2014-12-11 01:10:13 +00:00
|
|
|
rsrcBuf = new uint8_t[1];
|
2014-11-04 00:26:53 +00:00
|
|
|
rsrcLen = 0;
|
|
|
|
} else {
|
|
|
|
rsrcLen = pCollEnt->rsrcLen;
|
2014-12-11 01:10:13 +00:00
|
|
|
rsrcBuf = new uint8_t[rsrcLen];
|
2014-11-18 05:13:13 +00:00
|
|
|
if (rsrcBuf == NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
return "Memory allocation failed.";
|
|
|
|
memcpy(rsrcBuf, buf, rsrcLen);
|
|
|
|
buf += rsrcLen;
|
|
|
|
remLen -= rsrcLen;
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(rsrcBuf == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
rsrcLen = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pCollEnt->cmmtLen > 0) {
|
|
|
|
cmmtLen = pCollEnt->cmmtLen;
|
|
|
|
/* CMMT FIX -- not supported by XferFile */
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(remLen >= 0);
|
|
|
|
|
|
|
|
errMsg = fpOpenArchive->XferFile(&details, &dataBuf, dataLen,
|
|
|
|
&rsrcBuf, rsrcLen);
|
|
|
|
delete[] dataBuf;
|
|
|
|
delete[] rsrcBuf;
|
2014-11-18 05:13:13 +00:00
|
|
|
dataBuf = rsrcBuf = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
return errMsg;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|