Example #1
0
NuError AcuEntry::TestEntry(CWnd* pMsgWnd)
{
    NuError nerr = kNuErrNone;
    CString errMsg;
    long len;
    int result = -1;

    len = (long) GetUncompressedLen();
    if (len == 0)
        goto bail;

    errno = 0;
    if (fseek(fpArchive->fFp, fOffset, SEEK_SET) < 0) {
        nerr = kNuErrGeneric;
        errMsg.Format(L"Unable to seek to offset %ld: %hs\n",
            fOffset, strerror(errno));
        ShowFailureMsg(pMsgWnd, errMsg, IDS_FAILED);
        goto bail;
    }

    if (GetSqueezed()) {
        nerr = UnSqueeze(fpArchive->fFp, (unsigned long) GetCompressedLen(),
                    NULL, false, 0);
        if (nerr != kNuErrNone) {
            errMsg.Format(L"Unsqueeze failed: %hs.", NuStrError(nerr));
            ShowFailureMsg(pMsgWnd, errMsg, IDS_FAILED);
            goto bail;
        }
    } else {
        errno = 0;
        if (fseek(fpArchive->fFp, fOffset + len, SEEK_SET) < 0) {
            nerr = kNuErrGeneric;
            errMsg.Format(L"Unable to seek to offset %ld (file truncated?): %hs\n",
                fOffset, strerror(errno));
            ShowFailureMsg(pMsgWnd, errMsg, IDS_FAILED);
            goto bail;
        }
    }

    if (SET_PROGRESS_UPDATE(100) == IDCANCEL)
        nerr = kNuErrAborted;

bail:
    return nerr;
}
Example #2
0
bool AcuArchive::TestSelection(CWnd* pMsgWnd, SelectionSet* pSelSet)
{
    // TODO: this is essentially copy & paste from NufxArchive::TestSelection().
    // We can move the implementation to GenericArchive and just have an
    // archive-specific TestEntry() function.
    NuError nerr;
    AcuEntry* pEntry;
    CString errMsg;
    bool retVal = false;

    ASSERT(fFp != NULL);

    LOGI("Testing %d entries", pSelSet->GetNumEntries());

    SelectionEntry* pSelEntry = pSelSet->IterNext();
    while (pSelEntry != NULL) {
        pEntry = (AcuEntry*) pSelEntry->GetEntry();

        LOGD("  Testing '%ls' (offset=%ld)", (LPCWSTR) pEntry->GetDisplayName(),
            pEntry->GetOffset());

        SET_PROGRESS_UPDATE2(0, pEntry->GetDisplayName(), NULL);

        nerr = pEntry->TestEntry(pMsgWnd);
        if (nerr != kNuErrNone) {
            if (nerr == kNuErrAborted) {
                CString title;
                CheckedLoadString(&title, IDS_MB_APP_NAME);
                errMsg = L"Cancelled.";
                pMsgWnd->MessageBox(errMsg, title, MB_OK);
            } else {
                errMsg.Format(L"Failed while testing '%ls': %hs.",
                    (LPCWSTR) pEntry->GetPathNameUNI(), NuStrError(nerr));
                ShowFailureMsg(pMsgWnd, errMsg, IDS_FAILED);
            }
            goto bail;
        }

        pSelEntry = pSelSet->IterNext();
    }

    /* show success message */
    errMsg.Format(L"Tested %d file%ls, no errors found.",
        pSelSet->GetNumEntries(),
        pSelSet->GetNumEntries() == 1 ? L"" : L"s");
    pMsgWnd->MessageBox(errMsg);
    retVal = true;

bail:
    SET_PROGRESS_END();
    return retVal;
}
void ViewFilesDialog::OnFviewPrint(void)
{
    MainWindow* pMainWindow = GET_MAIN_WINDOW();
    CPrintDialog dlg(FALSE);    // use CPrintDialogEx for Win2K? CPageSetUpDialog?
    PrintRichEdit pre;
    CDC dc;
    int numPages;

    dlg.m_pd.nFromPage = dlg.m_pd.nMinPage = 1;
    dlg.m_pd.nToPage = dlg.m_pd.nMaxPage = 1;

    /*
     * Getting the expected number of pages requires a print test-run.
     * However, if we use GetDefaults to get the DC, the call to DoModal
     * returns immediately with IDCANCEL.  So, we do our pre-flighting
     * in a separate DC with a separate print dialog object.
     */
    {
        CPrintDialog countDlg(FALSE);
        CDC countDC;

        dlg.m_pd.hDevMode = pMainWindow->fhDevMode;
        dlg.m_pd.hDevNames = pMainWindow->fhDevNames;

        if (countDlg.GetDefaults() == TRUE) {
            CWaitCursor waitc;

            if (countDC.Attach(countDlg.GetPrinterDC()) != TRUE) {
                ASSERT(false);
            }
            pre.Setup(&countDC, this);
            pre.PrintPreflight(&fEditCtrl, &numPages);
            LOGI("Default printer generated %d pages", numPages);

            dlg.m_pd.nToPage = dlg.m_pd.nMaxPage = numPages;
        }

        pMainWindow->fhDevMode = dlg.m_pd.hDevMode;
        pMainWindow->fhDevNames = dlg.m_pd.hDevNames;
    }

    long startChar, endChar;
    fEditCtrl.GetSel(/*ref*/startChar, /*ref*/endChar);

    if (endChar != startChar) {
        LOGI("GetSel returned start=%ld end=%ld", startChar, endChar);
        dlg.m_pd.Flags &= ~(PD_NOSELECTION);
    }

    dlg.m_pd.hDevMode = pMainWindow->fhDevMode;
    dlg.m_pd.hDevNames = pMainWindow->fhDevNames;
    dlg.m_pd.Flags |= PD_USEDEVMODECOPIESANDCOLLATE;
    dlg.m_pd.Flags &= ~(PD_NOPAGENUMS);


    /*
     * Show them the print dialog.
     */
    if (dlg.DoModal() != IDOK)
        return;

    /*
     * Grab the chosen printer and prep ourselves.
     */
    if (dc.Attach(dlg.GetPrinterDC()) != TRUE) {
        CString msg;
        msg.LoadString(IDS_PRINTER_NOT_USABLE);
        ShowFailureMsg(this, msg, IDS_FAILED);
        return;
    }
    pre.Setup(&dc, this);

    /*
     * Do the printing.
     */
    if (dlg.PrintRange())
        pre.PrintPages(&fEditCtrl, fTitle, dlg.GetFromPage(), dlg.GetToPage());
    else if (dlg.PrintSelection())
        pre.PrintSelection(&fEditCtrl, fTitle, startChar, endChar);
    else    // dlg.PrintAll()
        pre.PrintAll(&fEditCtrl, fTitle);

    pMainWindow->fhDevMode = dlg.m_pd.hDevMode;
    pMainWindow->fhDevNames = dlg.m_pd.hDevNames;
}
Example #4
0
void MainWindow::DoPaste(bool pasteJunkPaths)
{
    CString errStr, buildStr;
    UINT format = 0;
    UINT myFormat;
    bool isOpen = false;

    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;
        tmpStr.Format(L" %u", format);
        buildStr += tmpStr;
    }
    LOGI("  %ls", (LPCWSTR) buildStr);

#if 0
    if (IsClipboardFormatAvailable(CF_HDROP)) {
        errStr.LoadString(IDS_CLIPBOARD_NO_HDROP);
        ShowFailureMsg(this, errStr, IDS_FAILED);
        goto bail;
    }
#endif

    /* impossible unless OnUpdateEditPaste was bypassed */
    if (!IsClipboardFormatAvailable(myFormat)) {
        CheckedLoadString(&errStr, IDS_CLIPBOARD_NOTFOUND);
        ShowFailureMsg(this, errStr, IDS_FAILED);
        goto bail;
    }

    LOGI("+++ total data on clipboard: %ld bytes",
        GetClipboardContentLen());

    HGLOBAL hGlobal;
    LPVOID pGlobal;

    hGlobal = GetClipboardData(myFormat);
    if (hGlobal == NULL) {
        ASSERT(false);
        goto bail;
    }
    pGlobal = GlobalLock(hGlobal);
    ASSERT(pGlobal != NULL);
    errStr = ProcessClipboard(pGlobal, GlobalSize(hGlobal), pasteJunkPaths);
    fpContentList->Reload();

    if (!errStr.IsEmpty())
        ShowFailureMsg(this, errStr, IDS_FAILED);
    else
        SuccessBeep();

    GlobalUnlock(hGlobal);

bail:
    if (isOpen)
        CloseClipboard();
}
Example #5
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;
}
Example #6
0
void MainWindow::OnEditCopy(void)
{
    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);
        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.
     */
    size_t neededLen = (fileList.GetLength() + 1) * sizeof(WCHAR);
    hGlobal = ::GlobalAlloc(GHND | GMEM_SHARE, neededLen);
    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);
    ASSERT(pGlobal != NULL);
    wcscpy((WCHAR*) pGlobal, fileList);
    ::GlobalUnlock(hGlobal);

    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);
    if (hGlobal != NULL) {
        SetClipboardData(myFormat, hGlobal);
        // beep annoys me on copy
        //SuccessBeep();
    }

bail:
    CloseClipboard();
}