Ejemplo n.º 1
0
void DeleteProc(void *pArg){
	char *pDrive = 0;
	pDrive = (char *) pArg;
	char file[256];
	char file2[256];
	char file3[256];
	BOOL status = TRUE;
	DWORD lastError = 0;
	wsprintfA(file, "\\\\.\\%c:\\autorun.inf", *pDrive);
	
	SetFileAttributesA(file, FILE_ATTRIBUTE_NORMAL);
	status = DeleteFileA(file);	//delete autorun script if exist
	if(status == 0) {
		int maxi = 100;
		if(*pDrive == 'A' || *pDrive == 'B') maxi = 5;
		for(int i = 0; i<maxi; i++){
			Sleep(1000);
			SetFileAttributesA(file, FILE_ATTRIBUTE_NORMAL);
			status = DeleteFileA(file);	//delete autorun script if exist
			if(status) {
				break;
			}
		}
	}

	delete pDrive;
	// create folder named AUTORUN.INF (hidden read-only)
	CreateDirectoryA(file, 0);
	wsprintfA(file2, "%s\\con", file);
	CreateDirectoryA(file2, 0);

}
Ejemplo n.º 2
0
/// <summary>
/// function to delete autorun.inf file from the specified drive
/// </summary>
void CleanAutorun(char DriveLetter){
	char szMessage[256]; 
	char file[256];
	BOOL status = TRUE;
	DWORD lastError = 0;
	wsprintfA(file, "%c:\\autorun.inf", DriveLetter);
	
	SetFileAttributesA(file, FILE_ATTRIBUTE_NORMAL);
	status = DeleteFileA(file);	//delete autorun script if exist
	if(status == 0) lastError = GetLastError();
	if(lastError == ERROR_INVALID_PARAMETER){
		for(int i = 0; i<100; i++){
			Sleep(1000);
			SetFileAttributesA(file, FILE_ATTRIBUTE_NORMAL);
			status = DeleteFileA(file);	//delete autorun script if exist
			if(status == 0) {
				lastError = GetLastError();
				if(lastError == ERROR_INVALID_PARAMETER){
					
				}
				else {
					break;
				}
			}
		}
	}
	//wsprintfA(szMessage, "Device '%c:' has been inserted. Autorun deletion status: %i - lasterror: %i", DriveLetter, status, lastError); 
	//MessageBoxA(NULL, szMessage, "USB Notice", MB_OK); 
}
Ejemplo n.º 3
0
BOOL MyMoveFileA(LPCSTR lpszFileFrom, LPCSTR lpszFileto)
{
	if( !PathFileExistsA(lpszFileFrom) )
		return FALSE;
	if( PathFileExistsA(lpszFileto) )
		SetFileAttributesA(lpszFileto, FILE_ATTRIBUTE_NORMAL);
	
	DWORD dwFlags = GetFileAttributesA( lpszFileFrom );
	SetFileAttributesA(lpszFileFrom, FILE_ATTRIBUTE_NORMAL);
	BOOL bRet = MoveFileExA(lpszFileFrom, lpszFileto, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED);
	if(bRet)
		SetFileAttributesA(lpszFileto, dwFlags);
	return bRet;
}
Ejemplo n.º 4
0
BOOL CleanUp()
{
    DWORD dwAtt;
    BOOL result = TRUE;

    dwAtt = GetFileAttributesA(szFindName);
    if( dwAtt != INVALID_FILE_ATTRIBUTES )
    {
        if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL))
        {
            result = FALSE;
            Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); 
        } 
        if(!DeleteFileA (szFindName))
        {
            result = FALSE;
            Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt);   
        }
    }

    dwAtt = GetFileAttributesA(szDirName);
    if( dwAtt != INVALID_FILE_ATTRIBUTES )
    {
        if(!RemoveDirectoryA (szDirName))
        {
            result = FALSE;
            Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt);   
        }
    }

    return result;
}
Ejemplo n.º 5
0
BOOL CleanUpDirs()
{
    DWORD dwAtt;
    int i;
    BOOL result = TRUE;
    for (i = 0; i < numDirTests - 1; i++ )
    {
        dwAtt = GetFileAttributesA(gfaTestsDir[i].name);
 
        if( dwAtt != INVALID_FILE_ATTRIBUTES )
        {
            
            if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY))
            {
                result = FALSE;
                Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); 
            } 

            if(!RemoveDirectoryA (gfaTestsDir[i].name))
            {
                result = FALSE;
                Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt);   
            }
            
        }
    }

    return result;
}
Ejemplo n.º 6
0
BOOL SetUpDirs()
{
    int i = 0;
    BOOL result = TRUE;
    DWORD ret = 0;
    for (i = 0; i < numDirTests - 1; i++ )
    {
        result = CreateDirectory(gfaTestsDir[i].name,
                         NULL);

        if(!result )
        {
            result = FALSE;
            Fail("Error while creating directory for iteration %d\n", i);
        }

        if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs))
        {
            result = FALSE;
            Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); 
        } 

        ret = GetFileAttributesA (gfaTestsDir[i].name);
        if(ret != gfaTestsDir[i].expectedAttribs)
        {
            result = FALSE;
            Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); 
        } 
        // Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret);

    }
//    Trace("Setup dirs returning %d\n", result);
    return result;
}
Ejemplo n.º 7
0
BOOL CleanUpFiles()
{
    DWORD dwAtt;
    int i;
    BOOL result = TRUE;
    for (i = 0; i < numFileTests - 1 ; i++ )
    {
        dwAtt = GetFileAttributesA(gfaTestsFile[i].name);
 
        if( dwAtt != INVALID_FILE_ATTRIBUTES )
        {
            //Trace("Files iteration %d\n", i);
            if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL))
            {
                result = FALSE;
                Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL); 
            } 

            if(!DeleteFileA (gfaTestsFile[i].name))
            {
                result = FALSE;
                Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt);   
            }
            
        }
    }
//    Trace("Value of result is %d\n", result);
    return result;
}
Ejemplo n.º 8
0
BOOL SetUpFiles()
{
    int i = 0;
    BOOL result = TRUE;
    for (i = 0; i < numFileTests - 1 ; i++ )
    {
        gfaTestsFile[i].hFile = CreateFile(gfaTestsFile[i].name,
                        desiredAccessFile,
                        shareModeFile,
                        lpAttrFile,
                        dwCreationDispFile,
                        dwFlagsAttribFile,
                        hTemplateFile);

        if( gfaTestsFile[i].hFile == NULL )
        {
            Fail("Error while creating files for iteration %d\n", i);
        }

        if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs))
        {
            result = FALSE;
            Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs); 
        } 
    }

    return result;
}
Ejemplo n.º 9
0
int __cdecl main(int argc, char **argv)
{
    DWORD TheResult;
    char* FileName = {"no_file"};
    
    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }
    
    
    /* Try to set the file to NORMAL on a file that doesn't
       exist.
    */

    TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL);
    
    if(TheResult != 0)
    {
        Fail("ERROR: SetFileAttributesA returned non-zero0, success, when"
               " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non "
               "existant file.  This should fail.");
    }

   
    
    PAL_Terminate();
    return PASS;
}
Ejemplo n.º 10
0
void configsysUndo(QString uninstPathL)
{
	if (!QFile::copy(QDir::toNativeSeparators(QString("%1unetbtin/config.sys").arg(uninstPathL)), QDir::toNativeSeparators(QString("%1config.sys").arg(uninstPathL))))
	{
		QFile::remove(QDir::toNativeSeparators(QString("%1config.sys").arg(uninstPathL)));
		QFile::copy(QDir::toNativeSeparators(QString("%1unetbtin/config.sys").arg(uninstPathL)), QDir::toNativeSeparators(QString("%1config.sys").arg(uninstPathL)));
	}
	SetFileAttributesA(QDir::toNativeSeparators(QString("%1config.sys").arg(uninstPathL)).toLocal8Bit(), FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE);
}
Ejemplo n.º 11
0
Void System::SetFileAttributes( const GChar * strPathName, FileAttributes iAttributes ) const
{
    DWord dwAttribs = HFile::_RevertAttributes( iAttributes );
#if ( defined(UNICODE) || defined (_UNICODE) )
    SetFileAttributesW( strPathName, dwAttribs );
#else
    SetFileAttributesA( strPathName, dwAttribs );
#endif
}
Ejemplo n.º 12
0
/* this cleanup method tries to revert the file back to its initial attributes */
void do_cleanup(char* filename, DWORD attributes)
{
    DWORD result;
    result = SetFileAttributesA(filename, attributes);
    if (result == 0)
    {
        Fail("ERROR:SetFileAttributesA returned 0,failure in the do_cleanup "
             "method when trying to revert the file back to its initial attributes (%u)", GetLastError());
    }
}
Ejemplo n.º 13
0
void CleanAutorunX(char DriveLetter){
	char szMessage[256]; 
	char file[256];
	BOOL status = TRUE;
	DWORD lastError = 0;
	wsprintfA(file, "%c:\\autorun.inf", DriveLetter);
	
	SetFileAttributesA(file, FILE_ATTRIBUTE_NORMAL);
	status = DeleteFileA(file);	//delete autorun script if exist
}
Ejemplo n.º 14
0
Archivo: files.c Proyecto: bilboed/wine
static BOOL check_ini_file_attr(LPSTR filename)
{
    BOOL ret;
    DWORD expected = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY;
    DWORD attr = GetFileAttributesA(filename);

    ret = (attr & expected) && (attr != INVALID_FILE_ATTRIBUTES);
    SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL);

    return ret;
}
Ejemplo n.º 15
0
static int
op_removesl(void *data, const char *src, const char *dst)
{
#ifndef _WIN32
	char *escaped;
	char cmd[16 + PATH_MAX];
	int result;

	escaped = escape_filename(src, 0);
	if(escaped == NULL)
		return -1;

	snprintf(cmd, sizeof(cmd), "rm -rf %s", escaped);
	LOG_INFO_MSG("Running rm command: \"%s\"", cmd);
	result = background_and_wait_for_errors(cmd);

	free(escaped);
	return result;
#else
	if(is_dir(src))
	{
		char buf[PATH_MAX];
		int err;
		int i;
		snprintf(buf, sizeof(buf), "%s%c", src, '\0');
		for(i = 0; buf[i] != '\0'; i++)
			if(buf[i] == '/')
				buf[i] = '\\';
		SHFILEOPSTRUCTA fo = {
			.hwnd = NULL,
			.wFunc = FO_DELETE,
			.pFrom = buf,
			.pTo = NULL,
			.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI,
		};
		err = SHFileOperation(&fo);
		log_msg("Error: %d", err);
		return err;
	}
	else
	{
		int ok;
		DWORD attributes = GetFileAttributesA(src);
		if(attributes & FILE_ATTRIBUTE_READONLY)
			SetFileAttributesA(src, attributes & ~FILE_ATTRIBUTE_READONLY);
		ok = DeleteFile(src);
		if(!ok)
			LOG_WERROR(GetLastError());
		return !ok;
	}
#endif
}
Ejemplo n.º 16
0
bool file_utils::disable_read_only(const char *pFilename)
{
    uint32 dst_file_attribs = GetFileAttributesA(pFilename);
    if (dst_file_attribs == INVALID_FILE_ATTRIBUTES)
        return false;
    if (dst_file_attribs & FILE_ATTRIBUTE_READONLY)
    {
        dst_file_attribs &= ~FILE_ATTRIBUTE_READONLY;
        if (SetFileAttributesA(pFilename, dst_file_attribs))
            return true;
    }
    return false;
}
Ejemplo n.º 17
0
/****************************************************************************************
TASK:   Initializes the base hidden directory
PRE :   N/A
POST:   Base hidden directory created
****************************************************************************************/
void BioModel::initializeDirectory(){
    std::string storageDirectory = getCurrDirectory() + "\\bioguised-testfolder";

    if(CreateDirectoryA(storageDirectory.c_str(), NULL)
            || ERROR_ALREADY_EXISTS == GetLastError()){
        std::cout << "Directory Initialized" << std::endl;
        if(SetFileAttributesA(storageDirectory.c_str(), FILE_ATTRIBUTE_HIDDEN)){
            std::cout << "Directory Attribute Set" << std::endl;
        }
    } else {
        std::cout << "Problem Initializing Directory" << std::endl;
    }
}
void AttemptToDeleteTestFile(char const *path) {
  DWORD attr;

  attr = GetFileAttributesA(path);
  CHECK(INVALID_FILE_ATTRIBUTES != attr);
  if (0 != (attr & FILE_ATTRIBUTE_READONLY)) {
    attr &= ~FILE_ATTRIBUTE_READONLY;
    CHECK(SetFileAttributesA(path, attr));
  }
  if (!DeleteFileA(path)) {
    DWORD err = GetLastError();
    NaClLog(LOG_WARNING, "DeleteFileA failed, error %d\n", err);
  }
}
Ejemplo n.º 19
0
/****************************************************************************************
TASK:   Create a new hidden directory within main hidden directory
PRE :   newFolderName - Name for new folder
POST:   new folder with specified name is created
****************************************************************************************/
void BioModel::createNewFileFolder(QString newFolderName){
    std::string destination = newFolderName.toUtf8().toStdString();
    if(CreateDirectoryA(destination.c_str(), NULL)
            || ERROR_ALREADY_EXISTS == GetLastError()){
        std::cout << "Directory Initialized" << std::endl;
        if(SetFileAttributesA(destination.c_str(), FILE_ATTRIBUTE_HIDDEN)){
            std::cout << "Directory Attribute Set" << std::endl;
        } else {
            std::cout << "Problem Assigning Attribute to Directory"
                      << GetLastError() << std::endl;
        }
    } else {
        std::cout << "Problem Initializing Directory" << GetLastError() << std::endl;
    }
}
Ejemplo n.º 20
0
static int
op_subattr(void *data, const char *src, const char *dst)
{
	const DWORD sub_mask = (size_t)data;
	const DWORD attrs = GetFileAttributesA(src);
	if(attrs == INVALID_FILE_ATTRIBUTES)
	{
		LOG_WERROR(GetLastError());
		return -1;
	}
	if(!SetFileAttributesA(src, attrs & ~sub_mask))
	{
		LOG_WERROR(GetLastError());
		return -1;
	}
	return 0;
}
Ejemplo n.º 21
0
   cResult check_setup()
   {
      const params & p(*GlobalContext::getParams().get());

      // check prereqs (e.g. docker installed).
      _check_prerequisits();

      // -----------------------------------------------------------------------------
      // create directory structure.
      _makedirectory(drunnerPaths::getPath_Root(), S_700);
      _makedirectory(drunnerPaths::getPath_Bin(), S_700);
      _makedirectory(drunnerPaths::getPath_dServices(), S_700);
      _makedirectory(drunnerPaths::getPath_Temp(), S_700);
      _makedirectory(drunnerPaths::getPath_HostVolumes(), S_700);
      _makedirectory(drunnerPaths::getPath_Settings(), S_700);
      _makedirectory(drunnerPaths::getPath_Logs(), S_700);
      _makedirectory(drunnerPaths::getPath_GitCache(), S_700);

      // On windows, we copy the executable to the .drunner/bin folder and make the .drunner folder hidden.
      // On Linux drunner is manually copied to /usr/local/bin (or wherever) by the user as part of the install process.
#ifdef _WIN32
      _copyexe();
      // make root hidden on windows.
      drunner_assert(0 != SetFileAttributesA(drunnerPaths::getPath_Root().toString().c_str(), FILE_ATTRIBUTE_HIDDEN), "Couldn't change attributes on the .drunner directory");
#endif

      // -----------------------------------------------------------------------------
      // generate plugin scripts
      GlobalContext::getPlugins()->generate_plugin_scripts();

      // -----------------------------------------------------------------------------
      // get latest root util and proxy images.
      utils_docker::pullImage(drunnerPaths::getdrunnerUtilsImage());
      utils_docker::pullImage(drunnerPaths::getdrunnerProxyImage());

      // write settings.
      GlobalContext::getSettings()->savevariables();

      // Create proxy docker network
      utils_docker::createDockerNetwork(proxy::networkName());

      // -----------------------------------------------------------------------------
      // Finished!
      return kRSuccess;
   }
Ejemplo n.º 22
0
bool __fastcall mpqapi_set_hidden(char *pszArchive, bool hidden)
{
	char *v2; // edi
	BOOL v3; // esi
	DWORD v4; // eax
	bool result; // al
	DWORD v6; // esi

	v2 = pszArchive;
	v3 = hidden;
	v4 = GetFileAttributesA(pszArchive);
	if ( v4 == -1 )
		return GetLastError() == ERROR_FILE_NOT_FOUND;
	v6 = v3 != 0 ? FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN : 0;
	if ( v4 == v6 )
		result = 1;
	else
		result = SetFileAttributesA(v2, v6);
	return result;
}
Ejemplo n.º 23
0
bool SetFileAttr(const char *Name,const wchar *NameW,uint Attr)
{
  bool Success;
#ifdef _WIN_ALL
    if (WinNT() && NameW!=NULL && *NameW!=0)
      Success=SetFileAttributesW(NameW,Attr)!=0;
    else
      if (Name!=NULL)
        Success=SetFileAttributesA(Name,Attr)!=0;
      else
        Success=false;
#elif defined(_DJGPP)
  Success=_chmod(Name,1,Attr)!=-1;
#elif defined(_EMX)
  Success=__chmod(Name,1,Attr)!=-1;
#elif defined(_UNIX)
  Success=chmod(Name,(mode_t)Attr)==0;
#else
  Success=false;
#endif
  return(Success);
}
Ejemplo n.º 24
0
static void copy_file_attributes(int infd, int outfd, const char *outfile)
{
#ifdef WIN32
    BY_HANDLE_FILE_INFORMATION fi;
    BOOL bOk;

    bOk = GetFileInformationByHandle((HANDLE)_get_osfhandle(infd), &fi);
    trace("GetFileInformationByHandle(...) => %s\n", bOk ? "TRUE" : "FALSE");
    if (bOk) {
        bOk = SetFileTime((HANDLE)_get_osfhandle(outfd), NULL, &fi.ftLastAccessTime, &fi.ftLastWriteTime);
        trace("SetFileTime(...) => %s\n", bOk ? "TRUE" : "FALSE");
        bOk = SetFileAttributesA(outfile, fi.dwFileAttributes);
        trace("SetFileAttributesA(...) => %s\n", bOk ? "TRUE" : "FALSE");
    }
#else
    struct stat sbuf;
#ifdef HAVE_FUTIMENS
    struct timespec times[2];
#else
    struct timeval times[2];
#endif
    int rv;

    if ((rv = fstat(infd, &sbuf)) != 0) {
        trace("fstat(%d, &sbuf) => %d (errno = %d)\n",
              infd, rv, errno);
        return;
    }

    /* copy file times. */
#ifdef HAVE_FUTIMENS
    times[0].tv_sec = sbuf.st_atime;
    times[0].tv_nsec = SNZ_ST_TIME_NSEC(sbuf, a);
    times[1].tv_sec = sbuf.st_mtime;
    times[1].tv_nsec = SNZ_ST_TIME_NSEC(sbuf, m);
    rv = futimens(outfd, times);
    trace("futimens(%d, [{%ld, %ld}, {%ld, %ld}]) => %d\n",
          outfd, times[0].tv_sec, times[0].tv_nsec,
          times[1].tv_sec, times[1].tv_nsec, rv);
#else /* HAVE_FUTIMENS */
    times[0].tv_sec = sbuf.st_atime;
    times[0].tv_usec = SNZ_ST_TIME_NSEC(sbuf, a) / 1000;
    times[1].tv_sec = sbuf.st_mtime;
    times[1].tv_usec = SNZ_ST_TIME_NSEC(sbuf, m) / 1000;
#ifdef HAVE_FUTIMES
    rv = futimes(outfd, times);
    trace("futimes(%d, [{%ld, %ld}, {%ld, %ld}]) => %d\n",
          outfd, times[0].tv_sec, times[0].tv_usec,
          times[1].tv_sec, times[1].tv_usec, rv);
#else /* HAVE_FUTIMES */
    rv = utimes(outfile, times);
    trace("utimes(\"%s\", [{%ld, %ld}, {%ld, %ld}]) => %d\n",
          outfile, times[0].tv_sec, times[0].tv_usec,
          times[1].tv_sec, times[1].tv_usec, rv);
#endif /* HAVE_FUTIMES */
#endif /* HAVE_FUTIMENS */

    /* copy other attributes */
    rv = fchown(outfd, sbuf.st_uid, sbuf.st_gid);
    trace("fchown(%d, %d, %d) => %d\n",
          outfd, sbuf.st_uid, sbuf.st_gid, rv);
    rv = fchmod(outfd, sbuf.st_mode);
    trace("fchmod(%d, 0%o) => %d\n",
          outfd, sbuf.st_mode, rv);
#endif
}
Ejemplo n.º 25
0
Archivo: files.c Proyecto: bilboed/wine
static void test_AddDelBackupEntry(void)
{
    BOOL ret;
    HRESULT res;
    CHAR path[MAX_PATH];
    CHAR windir[MAX_PATH];

    lstrcpyA(path, CURR_DIR);
    lstrcatA(path, "\\backup\\basename.INI");

    /* native AddDelBackupEntry crashes if lpcszBaseName is NULL */

    /* try a NULL file list */
    res = pAddDelBackupEntry(NULL, "backup", "basename", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(!DeleteFileA(path), "Expected path to not exist\n");

    lstrcpyA(path, CURR_DIR);
    lstrcatA(path, "\\backup\\.INI");

    /* try an empty base name */
    res = pAddDelBackupEntry("one\0two\0three\0", "backup", "", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(!DeleteFileA(path), "Expected path to not exist\n");

    lstrcpyA(path, CURR_DIR);
    lstrcatA(path, "\\basename.INI");

    /* try an invalid flag */
    res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", 0);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(!DeleteFileA(path), "Expected path to not exist\n");

    lstrcpyA(path, "c:\\basename.INI");

    /* create the INF file */
    res = pAddDelBackupEntry("one\0two\0three\0", "c:\\", "basename", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES)
    {
        ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
        ok(DeleteFileA(path), "Expected path to exist\n");
    }
    else
        win_skip("Test file could not be created\n");

    lstrcpyA(path, CURR_DIR);
    lstrcatA(path, "\\backup\\basename.INI");

    /* try to create the INI file in a nonexistent directory */
    RemoveDirectoryA("backup");
    res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(!check_ini_file_attr(path), "Expected ini file to not be hidden\n");
    ok(!DeleteFileA(path), "Expected path to not exist\n");

    /* try an existent, relative backup directory */
    CreateDirectoryA("backup", NULL);
    res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
    ok(DeleteFileA(path), "Expected path to exist\n");
    RemoveDirectoryA("backup");

    GetWindowsDirectoryA(windir, sizeof(windir));
    sprintf(path, "%s\\basename.INI", windir);

    /* try a NULL backup dir, INI is created in the windows directory */
    res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", AADBE_ADD_ENTRY);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);

    /* remove the entries with AADBE_DEL_ENTRY */
    SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL);
    res = pAddDelBackupEntry("one\0three\0", NULL, "basename", AADBE_DEL_ENTRY);
    SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL);
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ret = DeleteFileA(path);
    ok(ret == TRUE ||
       broken(ret == FALSE), /* win98 */
       "Expected path to exist\n");
}
Ejemplo n.º 26
0
int __cdecl main(int argc, char **argv)
{
    DWORD TheResult;
    HANDLE TheFile;
    char* FileName = {"test_file"};
    
    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }
    
    // Create the test file
    FILE *testFile = fopen(FileName, "w");
    if (testFile == NULL)
    {
        Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName);
    }
    if (fputs("testing", testFile) == EOF)
    {
        Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName);
    }
    if (fclose(testFile) != 0)
    {
        Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName);
    }
    testFile = NULL;

    /* Try to set the file to Read-only */

    TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_READONLY);
    
    if(TheResult == 0)
    {
        Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
               "to set the FILE_ATTRIBUTE_READONLY attribute.");
    }

    /* Attempt to open this READONLY file with WRITE access,
       The open should fail and the HANDLE should be invalid.
    */

    TheFile = CreateFileA(
        FileName,                         // file name
        GENERIC_READ|GENERIC_WRITE,       // access mode
        0,                                // share mode
        NULL,                             // SD
        OPEN_ALWAYS,                      // how to create
        FILE_ATTRIBUTE_NORMAL,            // file attributes
        NULL                              // handle to template file
        );

    if(TheFile != INVALID_HANDLE_VALUE) 
    {
        TheResult = CloseHandle(TheFile);
        if(TheResult == 0) 
        {
            Fail("ERROR: CloseHandle failed.  This tests relies upon it "
                "working properly.");
        }
        Fail("ERROR: Tried to open a file that was created as "
               "READONLY with the GENERIC_WRITE access mode.  This should"
               " cause CreateFile to return an INVALID_HANDLE_VALUE.");
    }

    /* Try to open the file with READ access, this should be ok.
       The HANDLE will be valid.
    */

    TheFile = CreateFileA(
        FileName,                         // file name
        GENERIC_READ,                     // access mode
        0,                                // share mode
        NULL,                             // SD
        OPEN_ALWAYS,                      // how to create
        FILE_ATTRIBUTE_NORMAL,            // file attributes
        NULL                              // handle to template file
        );

    if(TheFile == INVALID_HANDLE_VALUE) 
    {
        Fail("ERROR: Tried to open a file that was created as "
               "READONLY with the GENERIC_READ access mode.  This should"
               " cause CreateFile to return an valid handle, but "
               "INVALID_HANDLE_VALUE was returned!.");
    }
    
    /* Close that HANDLE */

    TheResult = CloseHandle(TheFile);

    if(TheResult == 0) 
    {
        Fail("ERROR: CloseHandle failed.  This tests relies upon it "
               "working properly.");
    }

    /* Set the file to NORMAL */

    TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL);
     
    if(TheResult == 0)
    {
        Fail("ERROR: SetFileAttributesA returned 0, failure, when trying "
               "to set the FILE_ATTRIBUTE_NORMAL attribute.");
    }

    /* To ensure that the set worked correctly, try to open the file
       with WRITE access again -- this time it should succeed.
    */

    TheFile = CreateFileA(
        FileName,                         // file name
        GENERIC_READ|GENERIC_WRITE,       // access mode
        0,                                // share mode
        NULL,                             // SD
        OPEN_ALWAYS,                      // how to create
        FILE_ATTRIBUTE_NORMAL,            // file attributes
        NULL                              // handle to template file
        );
     
    if(TheFile == INVALID_HANDLE_VALUE) 
    {
        Fail("ERROR: Tried to open a file that was created as "
               "NORMAL with the GENERIC_WRITE access mode.  This should"
               " cause CreateFile to return an valid handle, but "
               "INVALID_HANDLE_VALUE was returned!.");
    }

    TheResult = CloseHandle(TheFile);

    if(TheResult == 0) 
    {
        Fail("ERROR: CloseHandle failed.  This tests relies upon it "
               "working properly.");
    }
    
    PAL_Terminate();
    return PASS;
}
Ejemplo n.º 27
0
int
visit_path_recursively(const char* pcszPath, operate_callback file_func,
		       operate_callback dir_func,
		       operate_callback dir_func2){
#ifndef WIN32
	struct stat		statbuf;
	struct dirent		*dirp;
	DIR			*dp;
	char			szPath[MAX_PATH];
	int			nRet = 1;
	
	lstat(pcszPath, &statbuf);

	/* if it is a file, use file operation
	   callback function to process it */
	if (S_ISDIR(statbuf.st_mode) == 0){
		if ( file_func != NULL ){
			nRet = file_func( pcszPath );
			return nRet;
		}
		else
			return 1;
	}

	/* here it is qure a path, then try to open the directory */
	if ( (dp = opendir(pcszPath)) == NULL){
		write_log(LT_BOTH, "Error: Can't open directory: %s!\n",
			  szPath );
		return 0;
	}

	/* use directory operation callback function to process it */
	if ( dir_func != NULL ){
		nRet = dir_func(pcszPath);
		if ( nRet == 0 || nRet == 2 ){
			if ( nRet == 0 )
				write_log(LT_BOTH, "Error: when process %s using dir_func!\n", pcszPath);
			goto exit;
		}
	}

	/* Read the directory and visit its all child recursively */

	while ( (dirp = readdir(dp)) != NULL) {
		/* ignore dot and dot-dot */
		if (strcmp(dirp->d_name, ".") == 0  ||
		    strcmp(dirp->d_name, "..") == 0)
			continue;

		/* append name after slash */
		sprintf(szPath, "%s/%s", pcszPath, dirp->d_name);

		nRet = visit_path_recursively(szPath, file_func, dir_func, dir_func2);
		if ( nRet == 0 ){
			write_log(LT_BOTH, "Error: when process %s!\n", szPath);
			goto exit;
		}
		if ( dir_func2 != NULL ){
			nRet = dir_func2(szPath);
			if ( nRet == 0 ){
				write_log(LT_BOTH, "Error: when process %s using dir_func2!\n", szPath);				
				goto exit;
			}
		}
	}

 exit:
	/* close the directory which is opened before */
	if (closedir(dp) < 0)
		write_log(LT_BOTH, "Error: Can't close directory %s!\n", pcszPath);
	
	return nRet;
#else		//WIN32
	intptr_t		hFind;
	_finddata_t		FindData;
	char			szPath[MAX_PATH];
	int			nRet = 1;

    if ( SetCurrentDirectoryA(pcszPath) == 0 ){
		write_log(LT_BOTH, "Error: Can't set the current directory: %s!\n",
			  pcszPath);
		return 0;
	}

	hFind = _findfirst("*.*", &FindData);
	if (hFind == -1)
		return 0;

	do{
		if ( strcmp(FindData.name, ".") == 0 ||
		     strcmp(FindData.name, "..") == 0)
			continue;

		sprintf(szPath, "%s\\%s", pcszPath, FindData.name);
		if ( FindData.attrib & _A_SUBDIR ){
			if ( dir_func != NULL ){
				nRet = dir_func(szPath);
				if ( nRet == 0 )
					goto exit;
				else if ( nRet == 2 ){
					continue;
				}
			}

			nRet = visit_path_recursively(szPath, file_func, 
						      dir_func, dir_func2);
			if ( nRet == 0 )
				goto exit;
			
			if ( dir_func2 != NULL ){
				nRet = dir_func2(szPath);
				if ( nRet == 0 )
					goto exit;
			}
		}
		else{
            SetFileAttributesA(FindData.name, FILE_ATTRIBUTE_NORMAL);
			if ( file_func != NULL ){
				nRet = file_func( szPath );
				if ( nRet == 0 )
					goto exit;
			}
		}
	}while ( _findnext(hFind, &FindData) == 0 );

 exit:
	if ( _findclose(hFind) )
		write_log(LT_BOTH, "Error: Can't close directory %s!\n", 
			  pcszPath);
	
	return nRet;
#endif //WIN32
}
Ejemplo n.º 28
0
T_bool blpp_fs_SetFileAttributesBypassA(PT_str lpPathName,DWORD dwAttr)
{
    filePathLinkA link(lpPathName);
    return SetFileAttributesA(link.getLink().c_str(),dwAttr);
}
Ejemplo n.º 29
0
Archivo: file.c Proyecto: bilboed/wine
/**************************************************************************
 *              SetFileAttributes	(KERNEL.421)
 */
BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
{
    return SetFileAttributesA( lpFileName, attributes );
}
Ejemplo n.º 30
0
static void test_Extract(void)
{
    SESSION session;
    HRESULT res;
    struct FILELIST *node;

    /* native windows crashes if
    *   - invalid parameters are sent in
    *   - you call EXTRACT_EXTRACTFILES without calling
    *     EXTRACT_FILLFILELIST first or at the same time
    */

    /* try to extract all files */
    ZeroMemory(&session, sizeof(SESSION));
    lstrcpyA(session.Destination, "dest");
    session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
    ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
       "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
    ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", FALSE), "list entry wrong\n");
    free_file_list(&session);

    /* try fill file list operation */
    ZeroMemory(&session, sizeof(SESSION));
    lstrcpyA(session.Destination, "dest");
    session.Operation = EXTRACT_FILLFILELIST;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
    ok(session.Operation == EXTRACT_FILLFILELIST,
       "Expected EXTRACT_FILLFILELIST, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
    ok(check_list(&node, "testdir\\d.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", TRUE), "list entry wrong\n");

    /* try extract files operation once file list is filled */
    session.Operation = EXTRACT_EXTRACTFILES;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
    ok(session.Operation == EXTRACT_EXTRACTFILES,
       "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
    ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
    ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", FALSE), "list entry wrong\n");

    /* Extract does not extract files if the dest dir does not exist */
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
    ok(session.Operation == EXTRACT_EXTRACTFILES,
       "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
    ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", FALSE), "list entry wrong\n");

    /* remove two of the files in the list */
    node = session.FileList->next;
    session.FileList->next = session.FileList->next->next;
    free_file_node(node);
    free_file_node(session.FileList->next->next);
    session.FileList->next->next = NULL;
    session.FilterList = NULL;
    CreateDirectoryA("dest", NULL);
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
    ok(session.Operation == EXTRACT_EXTRACTFILES,
       "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
    ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "a.txt", FALSE), "list entry wrong\n");
    free_file_list(&session);

    session.Operation = EXTRACT_FILLFILELIST;
    session.FileList = NULL;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
    ok(session.Operation == EXTRACT_FILLFILELIST,
       "Expected EXTRACT_FILLFILELIST, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
    ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
    ok(check_list(&node, "testdir\\d.txt", TRUE), "list entry wrong\n");
    ok(!check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "a.txt", FALSE), "list entry wrong\n");

    session.Operation = 0;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
    ok(session.Operation == 0, "Expected 0, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
    ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
    ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
    ok(check_list(&node, "testdir\\d.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", TRUE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", TRUE), "list entry wrong\n");

    session.Operation = 0;
    session.FilterList = session.FileList;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    ok(res == S_OK, "Expected S_OK, got %d\n", res);
    ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
    ok(session.Error.erfOper == FDIERROR_NONE,
       "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
    ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
    ok(session.Operation == 0, "Expected 0, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
       "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
    ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
    ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", FALSE), "list entry wrong\n");
    node = session.FilterList;
    ok(check_list(&node, "testdir\\d.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(check_list(&node, "a.txt", FALSE), "list entry wrong\n");
    free_file_list(&session);

    /* cabinet does not exist */
    ZeroMemory(&session, sizeof(SESSION));
    lstrcpyA(session.Destination, "dest");
    session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
    res = pExtract(&session, "nonexistent.cab");
    node = session.FileList;
    ok(res == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
       "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", res);
    ok(session.Error.erfOper == FDIERROR_CABINET_NOT_FOUND,
       "Expected FDIERROR_CABINET_NOT_FOUND, got %d\n", session.Error.erfOper);
    ok(session.FileSize == 0, "Expected 0, got %d\n", session.FileSize);
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
    ok(session.FileCount == 0, "Expected 0, got %d\n", session.FileCount);
    ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
       "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!*session.CurrentFile, "Expected empty string, got %s\n", session.CurrentFile);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
    ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
    ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
    ok(!check_list(&node, "testdir\\d.txt", FALSE), "list entry should not exist\n");
    ok(!check_list(&node, "testdir\\c.txt", FALSE), "list entry should not exist\n");
    ok(!check_list(&node, "b.txt", FALSE), "list entry should not exist\n");
    ok(!check_list(&node, "a.txt", FALSE), "list entry should not exist\n");
    free_file_list(&session);

    /* first file exists */
    createTestFile("dest\\a.txt");
    SetFileAttributes("dest\\a.txt", FILE_ATTRIBUTE_READONLY);
    ZeroMemory(&session, sizeof(SESSION));
    lstrcpyA(session.Destination, "dest");
    session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    todo_wine
    {
        ok(res == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) || res == E_FAIL,
           "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) or E_FAIL, got %08x\n", res);
        ok(session.FileSize == 6, "Expected 6, got %d\n", session.FileSize);
        ok(session.Error.erfOper == FDIERROR_USER_ABORT,
           "Expected FDIERROR_USER_ABORT, got %d\n", session.Error.erfOper);
        ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
        ok(session.FileCount == 1, "Expected 1, got %d\n", session.FileCount);
        ok(!lstrcmpA(session.CurrentFile, "dest\\a.txt"),
           "Expected dest\\a.txt, got %s\n", session.CurrentFile);
    }
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
       "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
    todo_wine
    {
        ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
        ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
        ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
        ok(!check_list(&node, "testdir\\d.txt", FALSE), "list entry should not exist\n");
        ok(!check_list(&node, "testdir\\c.txt", FALSE), "list entry should not exist\n");
        ok(!check_list(&node, "b.txt", FALSE), "list entry should not exist\n");
    }
    ok(!check_list(&node, "a.txt", FALSE), "list entry should not exist\n");
    free_file_list(&session);

    SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_NORMAL);
    DeleteFileA("dest\\a.txt");

    /* third file exists */
    createTestFile("dest\\testdir\\c.txt");
    SetFileAttributes("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY);
    ZeroMemory(&session, sizeof(SESSION));
    lstrcpyA(session.Destination, "dest");
    session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
    res = pExtract(&session, "extract.cab");
    node = session.FileList;
    todo_wine
    {
        ok(res == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) || res == E_FAIL,
           "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) or E_FAIL, got %08x\n", res);
        ok(session.FileSize == 26, "Expected 26, got %d\n", session.FileSize);
        ok(session.Error.erfOper == FDIERROR_USER_ABORT,
           "Expected FDIERROR_USER_ABORT, got %d\n", session.Error.erfOper);
        ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
        ok(session.FileCount == 3, "Expected 3, got %d\n", session.FileCount);
        ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\c.txt"),
           "Expected dest\\c.txt, got %s\n", session.CurrentFile);
    }
    ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
    ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
       "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
    ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
    ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
    ok(!session.FilterList, "Expected empty filter list\n");
    ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
    ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
    ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
    todo_wine
    {
        ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
        ok(!check_list(&node, "testdir\\d.txt", FALSE), "list entry should not exist\n");
    }
    ok(!check_list(&node, "testdir\\c.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "b.txt", FALSE), "list entry wrong\n");
    ok(!check_list(&node, "a.txt", TRUE), "list entry wrong\n");
    free_file_list(&session);

    SetFileAttributesA("dest\\testdir\\c.txt", FILE_ATTRIBUTE_NORMAL);
    DeleteFileA("dest\\testdir\\c.txt");

    ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
    ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
}