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
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.º 3
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.º 4
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;
}