// This function adds one file to the current cabinet. // Parameters: // sw_FileToAdd = Full path to the file to be added to the cabinet. // sw_NameInCab = path and filename under which to store the file in the cabinet // "Install\Setup.exe" will create a subfolder "Install" inside the cabinet // b_Compress = FALSE --> store in CAB file without compression BOOL AddFileW(const CStrW& sw_FileToAdd, const CStrW& sw_NameInCab, BOOL b_Compress=TRUE) { // Every class must only be accessed by one and the same thread. See "Microsoft Cabinet.dll Doku.doc" if (mu32_ThreadID != GetCurrentThreadId()) { mi_Error.Set(FCIERR_INVAL_THREAD,0,0); return FALSE; } if (!mh_FCIContext) return FALSE; mb_AutoFlush = TRUE; // Flushing must be done #if _TraceCompress CTrace::TraceW(L"*** FCIAddFile('%s') ***", (WCHAR*)sw_FileToAdd); #endif ULONGLONG u64_Size; DWORD u32_Error = CFile::GetFileSizeW(sw_FileToAdd, &u64_Size); if (u32_Error) { mi_Error.Set(FCIERR_OPEN_SRC, u32_Error,0); return FALSE; } if (u64_Size > 0x7FFF0000) // Cabinet.dll supports max 2 GB { mi_Error.Set(FCIERR_FILE_TOO_BIG,0,0); return FALSE; } CStrA s_File, s_Name; if (mb_EncodeUtf) { mb_NameInCabIsUtf = !sw_NameInCab.IsAscii(); s_Name.EncodeUtf8(sw_NameInCab); } else // UTF8 encoding disabled by the caller { // Unicode filenames cannot be stored with UTF8 encoding disabled if (sw_NameInCab.IsUnicode()) { mi_Error.Set(FCIERR_UNICODE_NEEDS_UTF8, 0,0); return FALSE; } mb_NameInCabIsUtf = FALSE; s_Name = sw_NameInCab; } // When mf_FciAddFile returns FALSE the error code has already been written into mi_Error in one of the 3 callbacks. // If you want to debug with a Debugger to trap an error you MUST set a breakpoint in FCIGetNextCabinet, FCIUpdateStatus, FCIGetAttribsAndDate! // But it is much easier to enable _TraceCompress and observe in DebugView what's happening. return mf_FciAddFile(mh_FCIContext, s_File.EncodeUtf8(sw_FileToAdd), s_Name, FALSE, (PFNFCIGETNEXTCABINET) FCIGetNextCabinet, (PFNFCISTATUS) FCIUpdateStatus, (PFNFCIGETOPENINFO) FCIGetAttribsAndDate, b_Compress ? tcompTYPE_MSZIP : tcompTYPE_NONE); }