BOOL STDCALL gcabe_addfile( HFCI hfci, pubyte fullname, pubyte filename, pcabinfo pcabi ) { return FCIAddFile( hfci, fullname, filename, 0, // exe get_next_cabinet, progress, get_open_info, ( ushort )pcabi->lztype ); }
static void add_file(HFCI hfci, char *file) { char path[MAX_PATH]; BOOL res; lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\"); lstrcatA(path, file); res = FCIAddFile(hfci, path, file, FALSE, get_next_cabinet, progress, get_open_info, tcompTYPE_MSZIP); ok(res, "Expected FCIAddFile to succeed\n"); }
static BOOL add_file( HFCI fci, WCHAR *name ) { BOOL ret; char *filename, *path = strdupWtoA( CP_UTF8, name ); if (!opt_preserve_paths) { if ((filename = strrchr( path, '\\' ))) filename++; else filename = path; } else { filename = path; while (*filename == '\\') filename++; /* remove leading backslashes */ } ret = FCIAddFile( fci, path, filename, FALSE, fci_get_next_cab, fci_status, fci_get_open_info, opt_compression ); cab_free( path ); return ret; }
static PyObject* fcicreate(PyObject* obj, PyObject* args) { char *cabname, *p; PyObject *files; CCAB ccab; HFCI hfci; ERF erf; Py_ssize_t i; if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files)) return NULL; if (!PyList_Check(files)) { PyErr_SetString(PyExc_TypeError, "FCICreate expects a list"); return NULL; } ccab.cb = INT_MAX; /* no need to split CAB into multiple media */ ccab.cbFolderThresh = 1000000; /* flush directory after this many bytes */ ccab.cbReserveCFData = 0; ccab.cbReserveCFFolder = 0; ccab.cbReserveCFHeader = 0; ccab.iCab = 1; ccab.iDisk = 1; ccab.setID = 0; ccab.szDisk[0] = '\0'; for (i = 0, p = cabname; *p; p = CharNext(p)) if (*p == '\\' || *p == '/') i = p - cabname + 1; if (i >= sizeof(ccab.szCabPath) || strlen(cabname+i) >= sizeof(ccab.szCab)) { PyErr_SetString(PyExc_ValueError, "path name too long"); return 0; } if (i > 0) { memcpy(ccab.szCabPath, cabname, i); ccab.szCabPath[i] = '\0'; strcpy(ccab.szCab, cabname+i); } else { strcpy(ccab.szCabPath, ".\\"); strcpy(ccab.szCab, cabname); } hfci = FCICreate(&erf, cb_fileplaced, cb_alloc, cb_free, cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete, cb_gettempfile, &ccab, NULL); if (hfci == NULL) { PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); return NULL; } for (i=0; i < PyList_GET_SIZE(files); i++) { PyObject *item = PyList_GET_ITEM(files, i); char *filename, *cabname; if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) { PyErr_SetString(PyExc_TypeError, "FCICreate expects a list of tuples containing two strings"); FCIDestroy(hfci); return NULL; } if (!FCIAddFile(hfci, filename, cabname, FALSE, cb_getnextcabinet, cb_status, cb_getopeninfo, tcompTYPE_MSZIP)) goto err; } if (!FCIFlushCabinet(hfci, FALSE, cb_getnextcabinet, cb_status)) goto err; if (!FCIDestroy(hfci)) goto err; Py_RETURN_NONE; err: if(erf.fError) PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ else PyErr_SetString(PyExc_ValueError, "FCI general error"); FCIDestroy(hfci); return NULL; }
/* instead of using just "test.exe" as the file name (LPSTR)getFileNameOnly(s).c_str() I use the whole path. Looks much better in Winrar and with the MS Cab viewer as one ca see the entier file paths Except that it doesn't always work....*sigh*. So you'll have to use the filename to determine what the full path was. */ bool MakeCab(const std::wstring& in_Where, const std::string& in_Why, DWORD& o_NumFilesInCab, const std::wstring& in_StrThisFileOnly, const bool in_bDontRecurse = false) { g_CurrentDescription = in_Why; ERF erf = { 0 }; CCAB cab_parameters = { 0 }; client_state cs = { 0 }; set_cab_parameters(&cab_parameters); HFCI hfci = FCICreate( &erf, file_placed, mem_alloc, mem_free, fci_open, fci_read, fci_write, fci_close, fci_seek, fci_delete, get_temp_file, &cab_parameters, &cs ); if (hfci == NULL) { printf("FCICreate() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); return false; } o_NumFilesInCab = 0; std::vector<std::wstring> VecFiles; std::list<std::wstring> SkippedExtensions; if(in_StrThisFileOnly.empty()) { if( GetFileCount(in_Where.c_str(), o_NumFilesInCab, VecFiles, SkippedExtensions, in_bDontRecurse) && o_NumFilesInCab) { wprintf(L"Ready to create a CAB using [%s] with [%d] files in it...\r\n", in_Where.c_str(), o_NumFilesInCab); printf("Destination CAB: [%s]\r\n", GetExeDir().c_str()); } else { wprintf(L"Cannot perform under [%s]...Specify a valid, non-empty folder\r\n", in_Where.c_str()); printf("Destination CAB: [%s]\r\n", GetExeDir().c_str()); return false; } } else { ++o_NumFilesInCab; VecFiles.push_back(in_StrThisFileOnly); } // For each file in 'in_Where' folder and subfolder, unless 'in_StrThisFileOnly' param was specified for each(std::wstring s in VecFiles) { if (FALSE == FCIAddFile( hfci, (LPSTR)wide2Ansi(s).c_str(), // file to add, can't be a folder, needs full path (LPSTR)getFileNameOnly(s).c_str(), // file name in cabinet file, and should not include any path information (e.g. “TEST.EXE”). FALSE, // specifies whether the file should be executed automatically when the cabinet is extracted get_next_cabinet, progress, // should point to a function which is called periodically by FCI so that the application may send a progress report to the user get_open_info, // point to a function which opens a file and returns its datestamp, timestamp, and attributes COMPRESSION_TYPE)) { printf("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); TRACE3("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); //FCIDestroy(hfci); //return false; // Try to keep a possible good file created so far... o_NumFilesInCab--; } } /* The FCIFlushCabinet API forces the current cabinet under construction to be completed immediately and written to disk. Further calls to FCIAddFile will cause files to be added to another cabinet. It is also possible that there exists pending data in FCI’s internal buffers that will may require spillover into another cabinet, if the current cabinet has reached the application-specified media size limit. */ if(o_NumFilesInCab > 0) { if (FALSE == FCIFlushCabinet( hfci, FALSE, // The fGetNextCab flag determines whether the function pointed to by the supplied GetNextCab parameter, will be called. get_next_cabinet, // If fGetNextCab is TRUE, then GetNextCab will be called to obtain continuation information progress)) { printf("FCIFlushCabinet() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); FCIDestroy(hfci); return false; } } if (FCIDestroy(hfci) != TRUE) { printf("FCIDestroy() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); return false; } return o_NumFilesInCab > 0; }