ciderpress/app/Clipboard.cpp

1031 lines
32 KiB
C++
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* 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"
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;
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 {
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 {
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).
*
* TODO: filename should be 8-bit from original, not 16-bit conversion
2007-03-27 17:47:10 +00:00
*/
typedef struct FileCollectionEntry {
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;
/*
* ==========================================================================
* Copy
2007-03-27 17:47:10 +00:00
* ==========================================================================
*/
void MainWindow::OnEditCopy(void)
2007-03-27 17:47:10 +00:00
{
CString errStr, fileList;
SelectionSet selSet;
UINT myFormat;
bool isOpen = false;
HGLOBAL hGlobal;
LPVOID pGlobal;
uint8_t* buf = NULL;
long bufLen = -1;
/* associate a number with the format name */
myFormat = RegisterClipboardFormat(kClipboardFmtName);
if (myFormat == 0) {
CheckedLoadString(&errStr, IDS_CLIPBOARD_REGFAILED);
ShowFailureMsg(this, errStr, IDS_FAILED);
goto bail;
}
LOGI("myFormat = %u", myFormat);
/* open & empty the clipboard, even if we fail later */
if (OpenClipboard() == false) {
CheckedLoadString(&errStr, IDS_CLIPBOARD_OPENFAILED);
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) {
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);
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) {
LOGI("Failed allocating %d bytes", neededLen);
CheckedLoadString(&errStr, IDS_CLIPBOARD_ALLOCFAILED);
ShowFailureMsg(this, errStr, IDS_FAILED);
goto bail;
}
LOGI(" Allocated %ld bytes for file list on clipboard", neededLen);
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);
::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);
/*
* 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) {
SetClipboardData(myFormat, hGlobal);
// beep annoys me on copy
//SuccessBeep();
}
2007-03-27 17:47:10 +00:00
bail:
CloseClipboard();
2007-03-27 17:47:10 +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 &&
fpContentList->GetSelectedCount() > 0);
2007-03-27 17:47:10 +00:00
}
CString MainWindow::CreateFileList(SelectionSet* pSelSet)
2007-03-27 17:47:10 +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];
CString fileName, subVol, fileType, auxType, modDate, format, length;
pSelEntry = pSelSet->IterNext();
2014-11-18 05:13:13 +00:00
while (pSelEntry != NULL) {
pEntry = pSelEntry->GetEntry();
2014-11-18 05:13:13 +00:00
ASSERT(pEntry != NULL);
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());
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);
fullStr += tmpStr;
pSelEntry = pSelSet->IterNext();
}
return fullStr;
2007-03-27 17:47:10 +00:00
}
/*static*/ CString MainWindow::DblDblQuote(const WCHAR* str)
2007-03-27 17:47:10 +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;
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);
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
}
long MainWindow::GetClipboardContentLen(void)
2007-03-27 17:47:10 +00:00
{
long len = 0;
UINT format = 0;
HGLOBAL hGlobal;
2007-03-27 17:47:10 +00:00
while ((format = EnumClipboardFormats(format)) != 0) {
hGlobal = GetClipboardData(format);
2014-11-18 05:13:13 +00:00
ASSERT(hGlobal != NULL);
len += GlobalSize(hGlobal);
}
2007-03-27 17:47:10 +00:00
return len;
2007-03-27 17:47:10 +00:00
}
HGLOBAL MainWindow::CreateFileCollection(SelectionSet* pSelSet)
2007-03-27 17:47:10 +00:00
{
SelectionEntry* pSelEntry;
GenericEntry* pEntry;
2014-11-18 05:13:13 +00:00
HGLOBAL hGlobal = NULL;
HGLOBAL hResult = NULL;
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;
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) {
pEntry = pSelEntry->GetEntry();
2014-11-18 05:13:13 +00:00
ASSERT(pEntry != NULL);
//LOGI("+++ Examining '%s'", pEntry->GetDisplayName());
if (pEntry->GetRecordKind() != GenericEntry::kRecordKindVolumeDir) {
totalLength += sizeof(FileCollectionEntry);
totalLength += (wcslen(pEntry->GetPathName()) +1) * sizeof(WCHAR);
numFiles++;
if (pEntry->GetRecordKind() != GenericEntry::kRecordKindDirectory) {
totalLength += (long) pEntry->GetDataForkLen();
totalLength += (long) pEntry->GetRsrcForkLen();
}
}
if (totalLength < 0) {
DebugBreak();
LOGI("Overflow"); // pretty hard to do right now!
2014-11-18 05:13:13 +00:00
return NULL;
}
pSelEntry = pSelSet->IterNext();
}
2007-03-27 17:47:10 +00:00
#if 0
{
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)
goto bail;
}
2007-03-27 17:47:10 +00:00
#endif
LOGI("Total length required is %ld + %ld = %ld",
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) {
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",
totalLength);
LOGI("%ls", (LPCWSTR) errMsg);
ShowFailureMsg(this, errMsg, IDS_FAILED);
goto bail;
}
pGlobal = ::GlobalLock(hGlobal);
2014-11-18 05:13:13 +00:00
ASSERT(pGlobal != NULL);
ASSERT(GlobalSize(hGlobal) >= (DWORD) totalLength);
LOGI("hGlobal=0x%08lx pGlobal=0x%08lx size=%ld",
(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);
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");
/*
* Extract the data into the buffer.
*/
long remainingLen;
void* buf;
remainingLen = totalLength - sizeof(FileCollection);
buf = (uint8_t*) pGlobal + sizeof(FileCollection);
pSelSet->IterReset();
pSelEntry = pSelSet->IterNext();
2014-11-18 05:13:13 +00:00
while (pSelEntry != NULL) {
CString errStr;
pEntry = pSelEntry->GetEntry();
2014-11-18 05:13:13 +00:00
ASSERT(pEntry != 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
CString displayName(pEntry->GetDisplayName());
fpActionProgress->SetArcName(displayName);
errStr = CopyToCollection(pEntry, &buf, &remainingLen);
if (!errStr.IsEmpty()) {
ShowFailureMsg(fpActionProgress, errStr, IDS_MB_APP_NAME);
goto bail;
}
//LOGI("remainingLen now %ld", remainingLen);
pSelEntry = pSelSet->IterNext();
}
ASSERT(remainingLen == 0);
ASSERT(buf == (uint8_t*) pGlobal + totalLength);
/*
* 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);
::GlobalUnlock(hGlobal);
::GlobalFree(hGlobal);
}
2014-11-18 05:13:13 +00:00
if (fpActionProgress != NULL) {
fpActionProgress->Cleanup(this);
2014-11-18 05:13:13 +00:00
fpActionProgress = NULL;
}
return hResult;
2007-03-27 17:47:10 +00:00
}
CString MainWindow::CopyToCollection(GenericEntry* pEntry, void** pBuf,
long* pBufLen)
2007-03-27 17:47:10 +00:00
{
FileCollectionEntry collEnt;
CString errStr;
uint8_t* buf = (uint8_t*) *pBuf;
long remLen = *pBufLen;
CheckedLoadString(&errStr, IDS_CLIPBOARD_WRITEFAILURE);
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindVolumeDir) {
LOGI("Not copying volume dir to collection");
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);
collEnt.fileNameLen = (wcslen(pEntry->GetPathName()) +1) * sizeof(WCHAR);
if (pEntry->GetRecordKind() == GenericEntry::kRecordKindDirectory) {
collEnt.dataLen = collEnt.rsrcLen = collEnt.cmmtLen = 0;
} else {
collEnt.dataLen = (uint32_t) pEntry->GetDataForkLen();
collEnt.rsrcLen = (uint32_t) pEntry->GetRsrcForkLen();
collEnt.cmmtLen = 0; // CMMT FIX -- length unknown??
}
collEnt.fileType = pEntry->GetFileType();
collEnt.auxType = pEntry->GetAuxType();
collEnt.createWhen = pEntry->GetCreateWhen();
collEnt.modWhen = pEntry->GetModWhen();
collEnt.access = (uint8_t) pEntry->GetAccess();
collEnt.entryKind = (uint8_t) entryKind;
collEnt.sourceFS = pEntry->GetSourceFS();
collEnt.fssep = pEntry->GetFssep();
/* verify there's enough space to hold everything */
if ((uint32_t) remLen < collEnt.fileNameLen +
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;
CString extractErrStr;
result = pEntry->ExtractThreadToBuffer(which, &bufCopy, &lenCopy,
&extractErrStr);
if (result == IDCANCEL) {
CheckedLoadString(&errStr, IDS_CANCELLED);
return errStr;
} else if (result != IDOK) {
LOGW("ExtractThreadToBuffer (data) failed: %ls",
(LPCWSTR) extractErrStr);
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;
CString extractErrStr;
result = pEntry->ExtractThreadToBuffer(which, &bufCopy, &lenCopy,
&extractErrStr);
if (result == IDCANCEL) {
CheckedLoadString(&errStr, IDS_CANCELLED);
return errStr;
} else if (result != IDOK) {
LOGI("ExtractThreadToBuffer (rsrc) failed: %ls",
(LPCWSTR) extractErrStr);
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
ASSERT(collEnt.cmmtLen == 0);
2007-03-27 17:47:10 +00:00
#endif
}
2007-03-27 17:47:10 +00:00
*pBuf = buf;
*pBufLen = remLen;
return "";
2007-03-27 17:47:10 +00:00
}
/*
* ==========================================================================
* Paste
2007-03-27 17:47:10 +00:00
* ==========================================================================
*/
void MainWindow::OnEditPaste(void)
2007-03-27 17:47:10 +00:00
{
bool pasteJunkPaths = fPreferences.GetPrefBool(kPrPasteJunkPaths);
2007-03-27 17:47:10 +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
void MainWindow::OnUpdateEditPaste(CCmdUI* pCmdUI)
2007-03-27 17:47:10 +00:00
{
bool dataAvailable = false;
UINT myFormat;
2007-03-27 17:47:10 +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() &&
dataAvailable);
2007-03-27 17:47:10 +00:00
}
void MainWindow::OnEditPasteSpecial(void)
2007-03-27 17:47:10 +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
void MainWindow::OnUpdateEditPasteSpecial(CCmdUI* pCmdUI)
2007-03-27 17:47:10 +00:00
{
OnUpdateEditPaste(pCmdUI);
2007-03-27 17:47:10 +00:00
}
void MainWindow::DoPaste(bool pasteJunkPaths)
2007-03-27 17:47:10 +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()) {
ASSERT(false);
return;
}
myFormat = RegisterClipboardFormat(kClipboardFmtName);
if (myFormat == 0) {
CheckedLoadString(&errStr, IDS_CLIPBOARD_REGFAILED);
ShowFailureMsg(this, errStr, IDS_FAILED);
goto bail;
}
LOGI("myFormat = %u", myFormat);
if (OpenClipboard() == false) {
CheckedLoadString(&errStr, IDS_CLIPBOARD_OPENFAILED);
ShowFailureMsg(this, errStr, IDS_FAILED);
goto bail;;
}
isOpen = true;
LOGI("Found %d clipboard formats", CountClipboardFormats());
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);
buildStr += tmpStr;
}
LOGI(" %ls", (LPCWSTR) buildStr);
2007-03-27 17:47:10 +00:00
#if 0
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
/* impossible unless OnUpdateEditPaste was bypassed */
if (!IsClipboardFormatAvailable(myFormat)) {
CheckedLoadString(&errStr, IDS_CLIPBOARD_NOTFOUND);
ShowFailureMsg(this, errStr, IDS_FAILED);
goto bail;
}
2007-03-27 17:47:10 +00:00
LOGI("+++ total data on clipboard: %ld bytes",
GetClipboardContentLen());
2007-03-27 17:47:10 +00:00
HGLOBAL hGlobal;
LPVOID pGlobal;
2007-03-27 17:47:10 +00:00
hGlobal = GetClipboardData(myFormat);
2014-11-18 05:13:13 +00:00
if (hGlobal == NULL) {
ASSERT(false);
goto bail;
}
pGlobal = GlobalLock(hGlobal);
2014-11-18 05:13:13 +00:00
ASSERT(pGlobal != NULL);
errStr = ProcessClipboard(pGlobal, GlobalSize(hGlobal), pasteJunkPaths);
fpContentList->Reload();
2007-03-27 17:47:10 +00:00
if (!errStr.IsEmpty())
ShowFailureMsg(this, errStr, IDS_FAILED);
else
SuccessBeep();
2007-03-27 17:47:10 +00:00
GlobalUnlock(hGlobal);
2007-03-27 17:47:10 +00:00
bail:
if (isOpen)
CloseClipboard();
2007-03-27 17:47:10 +00:00
}
CString MainWindow::ProcessClipboard(const void* vbuf, long bufLen,
bool pasteJunkPaths)
2007-03-27 17:47:10 +00:00
{
FileCollection fileColl;
CString errMsg, storagePrefix;
const uint8_t* buf = (const uint8_t*) vbuf;
2014-11-18 05:13:13 +00:00
DiskImgLib::A2File* pTargetSubdir = NULL;
XferFileOptions xferOpts;
bool xferPrepped = false;
/* set a standard error message */
CheckedLoadString(&errMsg, IDS_CLIPBOARD_READFAILURE);
/*
* Pull the header out.
*/
if (bufLen < sizeof(fileColl)) {
LOGW("Clipboard contents too small!");
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) {
LOGW("GLITCH: stored len=%ld, clip len=%ld",
fileColl.length, bufLen);
goto bail;
}
if (bufLen > (long) fileColl.length) {
/* trim off extra */
LOGI("NOTE: Windows reports excess length (%ld vs %ld)",
fileColl.length, bufLen);
bufLen = fileColl.length;
}
buf += sizeof(fileColl);
bufLen -= sizeof(fileColl);
LOGI("FileCollection found: vers=%d off=%d len=%ld count=%ld",
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"";
}
fpOpenArchive->XferPrepare(&xferOpts);
xferPrepped = true;
2014-11-18 05:13:13 +00:00
if (pTargetSubdir != NULL) {
storagePrefix = pTargetSubdir->GetPathName();
LOGD("--- using storagePrefix '%ls'", (LPCWSTR) storagePrefix);
}
/*
* Set up a progress dialog to track it.
*/
2014-11-18 05:13:13 +00:00
ASSERT(fpActionProgress == NULL);
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");
/*
* Loop over all files.
*/
LOGI("+++ Starting paste, bufLen=%ld", bufLen);
while (bufLen > 0) {
FileCollectionEntry collEnt;
CString fileName;
CString processErrStr;
/* read the entry info */
if (bufLen < sizeof(collEnt)) {
LOGW("GLITCH: bufLen=%ld, sizeof(collEnt)=%d",
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;
}
// TODO: consider moving filename as raw 8-bit data
fileName = (const WCHAR*) buf;
buf += collEnt.fileNameLen;
bufLen -= collEnt.fileNameLen;
LOGD("+++ pasting '%ls'", (LPCWSTR) fileName);
/* strip the path (if requested) and prepend the storage prefix */
ASSERT((fileName.GetLength() +1 ) * sizeof(WCHAR) == collEnt.fileNameLen);
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);
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:
if (xferPrepped) {
if (errMsg.IsEmpty())
fpOpenArchive->XferFinish(this);
else
fpOpenArchive->XferAbort(this);
}
2014-11-18 05:13:13 +00:00
if (fpActionProgress != NULL) {
fpActionProgress->Cleanup(this);
2014-11-18 05:13:13 +00:00
fpActionProgress = NULL;
}
return errMsg;
2007-03-27 17:47:10 +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
{
GenericArchive::FileDetails::FileKind entryKind;
GenericArchive::FileDetails details;
uint8_t* dataBuf = NULL;
uint8_t* rsrcBuf = NULL;
long dataLen, rsrcLen, cmmtLen;
CString errMsg;
entryKind = (GenericArchive::FileDetails::FileKind) pCollEnt->entryKind;
LOGI(" Processing '%ls' (%d)", pathName, entryKind);
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";
details.storageName = pathName; // TODO MacRoman convert
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);
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) {
dataBuf = new uint8_t[1];
dataLen = 0;
} else {
dataLen = pCollEnt->dataLen;
dataBuf = new uint8_t[dataLen];
2014-11-18 05:13:13 +00:00
if (dataBuf == NULL)
return "memory allocation failed.";
memcpy(dataBuf, buf, dataLen);
buf += dataLen;
remLen -= dataLen;
}
} else {
2014-11-18 05:13:13 +00:00
ASSERT(dataBuf == NULL);
dataLen = -1;
}
if (hasRsrc) {
if (pCollEnt->rsrcLen == 0) {
rsrcBuf = new uint8_t[1];
rsrcLen = 0;
} else {
rsrcLen = pCollEnt->rsrcLen;
rsrcBuf = new uint8_t[rsrcLen];
2014-11-18 05:13:13 +00:00
if (rsrcBuf == NULL)
return "Memory allocation failed.";
memcpy(rsrcBuf, buf, rsrcLen);
buf += rsrcLen;
remLen -= rsrcLen;
}
} else {
2014-11-18 05:13:13 +00:00
ASSERT(rsrcBuf == NULL);
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;
return errMsg;
2007-03-27 17:47:10 +00:00
}