Ejemplo n.º 1
0
Archivo: files.c Proyecto: bilboed/wine
static void create_cab_file(void)
{
    CCAB cabParams;
    HFCI hfci;
    ERF erf;
    static CHAR a_txt[] = "a.txt",
                b_txt[] = "b.txt",
                testdir_c_txt[] = "testdir\\c.txt",
                testdir_d_txt[] = "testdir\\d.txt";
    BOOL res;

    set_cab_parameters(&cabParams);

    hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
                      fci_read, fci_write, fci_close, fci_seek, fci_delete,
                      get_temp_file, &cabParams, NULL);

    ok(hfci != NULL, "Failed to create an FCI context\n");

    add_file(hfci, a_txt);
    add_file(hfci, b_txt);
    add_file(hfci, testdir_c_txt);
    add_file(hfci, testdir_d_txt);

    res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
    ok(res, "Failed to flush the cabinet\n");

    res = FCIDestroy(hfci);
    ok(res, "Failed to destroy the cabinet\n");
}
Ejemplo n.º 2
0
HFCI STDCALL gcabe_create( PCCAB cab, uint param )
{
	return FCICreate(
	   (PERF)param, //must begin with ERF, &erf
		file_placed, mem_alloc,	mem_free,
      fci_open, fci_read, fci_write, fci_close, fci_seek, fci_delete,
		get_temp_file, cab, ( pvoid )param );
}
Ejemplo n.º 3
0
static int new_cabinet( char *cab_dir )
{
    static const WCHAR plusW[] = {'+',0};
    WCHAR **file;
    ERF erf;
    BOOL ret = FALSE;
    HFCI fci;
    CCAB cab;

    cab.cb                = opt_cabinet_size;
    cab.cbFolderThresh    = CB_MAX_DISK;
    cab.cbReserveCFHeader = opt_reserve_space;
    cab.cbReserveCFFolder = 0;
    cab.cbReserveCFData   = 0;
    cab.iCab              = 0;
    cab.iDisk             = 0;
    cab.setID             = opt_cabinet_id;
    cab.szDisk[0]         = 0;

    strcpy( cab.szCabPath, cab_dir );
    strcat( cab.szCabPath, "\\" );
    format_cab_name( cab.szCab, 1, opt_cab_file );

    fci = FCICreate( &erf, fci_file_placed, cab_alloc, cab_free,fci_open, fci_read,
                     fci_write, fci_close, fci_lseek, fci_delete, fci_get_temp, &cab, NULL );

    for (file = opt_files; *file; file++)
    {
        if (!strcmpW( *file, plusW ))
            FCIFlushFolder( fci, fci_get_next_cab, fci_status );
        else
            if (!(ret = add_file_or_directory( fci, *file ))) break;
    }

    if (ret)
    {
        if (!(ret = FCIFlushCabinet( fci, FALSE, fci_get_next_cab, fci_status )))
            WINE_MESSAGE( "cabarc: Failed to create cabinet %s\n", wine_dbgstr_a(opt_cab_file) );
    }
    FCIDestroy( fci );
    return !ret;
}
Ejemplo n.º 4
0
bool MsCab::createFromFolder(LPWSTR outputFile, LPWSTR sourceFolder, LPWSTR tempFolder, LPWSTR *fileMask, DWORD fileMaskCount, DWORD flags)
{
    CFFSTRUCT cs;
    bool r = false;
    cs.fci = FCICreate(outputFile, NULL, tempFolder);
    if(cs.fci != NULL)
    {
        cs.filesCount    = 0;
        cs.cabPathOffset = Str::_LengthW(sourceFolder);

        //If the path does not end on a slash.
        if(cs.cabPathOffset > 0 && sourceFolder[cs.cabPathOffset - 1] != '\\')cs.cabPathOffset++;

        Fs::_findFiles(sourceFolder, fileMask, fileMaskCount, (flags & MsCab::CFF_RECURSE ? Fs::FFFLAG_RECURSIVE : 0) | Fs::FFFLAG_SEARCH_FILES, createFromFolderProc, &cs, NULL, 0, 0);

        if(cs.filesCount > 0 && FCIFlush(cs.fci))r = true;
        FCIClose(cs.fci);
    }
    return r;
}
Ejemplo n.º 5
0
Archivo: fdi.c Proyecto: devyn/wine
static void test_FDICopy(void)
{
    CCAB cabParams;
    HFDI hfdi;
    HFCI hfci;
    ERF erf;
    BOOL ret;
    char name[] = "extract.cab";
    char path[MAX_PATH + 1];

    GetCurrentDirectoryA(MAX_PATH, path);

    set_cab_parameters(&cabParams);

    hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
                     fci_read, fci_write, fci_close, fci_seek,
                     fci_delete, get_temp_file, &cabParams, NULL);

    ret = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
    ok(ret, "Failed to flush the cabinet\n");

    FCIDestroy(hfci);

    hfdi = FDICreate(fdi_alloc, fdi_free, fdi_open, fdi_read,
                     fdi_write, fdi_close, fdi_seek,
                     cpuUNKNOWN, &erf);

    /* cabinet with no files or folders */
    SetLastError(0xdeadbeef);
    ret = FDICopy(hfdi, name, path, 0, CopyProgress, NULL, 0);
    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
    todo_wine
    {
        ok(GetLastError() == ERROR_INVALID_HANDLE,
           "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
    }

    FDIDestroy(hfdi);
    DeleteFileA(name);
}
Ejemplo n.º 6
0
static void create_cab_file(const CHAR *name)
{
    CCAB cabParams;
    HFCI hfci;
    ERF erf;
    BOOL res;

    set_cab_parameters(&cabParams, name);

    hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
                      fci_read, fci_write, fci_close, fci_seek, fci_delete,
                      get_temp_file, &cabParams, NULL);

    ok(hfci != NULL, "Failed to create an FCI context\n");

    add_file(hfci, "four.txt");
    add_file(hfci, "five.txt");

    res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
    ok(res, "Failed to flush the cabinet\n");

    res = FCIDestroy(hfci);
    ok(res, "Failed to destroy the cabinet\n");
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
/*
	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;
}