Exemple #1
0
CString MainWindow::CreateFileList(SelectionSet* pSelSet)
{
    SelectionEntry* pSelEntry;
    GenericEntry* pEntry;
    CString tmpStr, fullStr;
    WCHAR fileTypeBuf[ContentList::kFileTypeBufLen];
    WCHAR auxTypeBuf[ContentList::kAuxTypeBufLen];
    CString fileName, subVol, fileType, auxType, modDate, format, length;

    pSelEntry = pSelSet->IterNext();
    while (pSelEntry != NULL) {
        pEntry = pSelEntry->GetEntry();
        ASSERT(pEntry != NULL);

        fileName = DblDblQuote(pEntry->GetPathNameUNI());
        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();
        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;
}
Exemple #2
0
HGLOBAL MainWindow::CreateFileCollection(SelectionSet* pSelSet)
{
    SelectionEntry* pSelEntry;
    GenericEntry* pEntry;
    HGLOBAL hGlobal = NULL;
    HGLOBAL hResult = NULL;
    LPVOID pGlobal;
    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();
    while (pSelEntry != NULL) {
        pEntry = pSelEntry->GetEntry();
        ASSERT(pEntry != NULL);

        //LOGI("+++ Examining '%s'", pEntry->GetDisplayName());

        if (pEntry->GetRecordKind() != GenericEntry::kRecordKindVolumeDir) {
            totalLength += sizeof(FileCollectionEntry);
            totalLength += (wcslen(pEntry->GetPathNameUNI()) +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!
            return NULL;
        }

        pSelEntry = pSelSet->IterNext();
    }

#if 0
    {
        CString msg;
        msg.Format("totalLength is %ld+%ld = %ld",
            totalLength, priorLength, totalLength+priorLength);
        if (MessageBox(msg, NULL, MB_OKCANCEL) == IDCANCEL)
            goto bail;
    }
#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);
    if (hGlobal == NULL) {
        CString errMsg;
        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);

    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.
     */
    ASSERT(fpActionProgress == NULL);
    fpActionProgress = new ActionProgressDialog;
    fpActionProgress->Create(ActionProgressDialog::kActionExtract, this);
    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();
    while (pSelEntry != NULL) {
        CString errStr;

        pEntry = pSelEntry->GetEntry();
        ASSERT(pEntry != NULL);

        fpActionProgress->SetArcName(pEntry->GetDisplayName());

        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;
    hGlobal = NULL;

bail:
    if (hGlobal != NULL) {
        ASSERT(hResult == NULL);
        ::GlobalUnlock(hGlobal);
        ::GlobalFree(hGlobal);
    }
    if (fpActionProgress != NULL) {
        fpActionProgress->Cleanup(this);
        fpActionProgress = NULL;
    }
    return hResult;
}