Ignore:
Timestamp:
May 6, 2003, 12:12:00 PM (22 years ago)
Author:
sandervl
Message:

KSO: OpenFile fix for OF_PARSE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/hmfile.cpp

    r10064 r10071  
    1 /* $Id: hmfile.cpp,v 1.43 2003-05-05 10:51:05 sandervl Exp $ */
     1/* $Id: hmfile.cpp,v 1.44 2003-05-06 10:12:00 sandervl Exp $ */
    22
    33/*
     
    164164        LPSTR filenameinpath;
    165165
    166         if(SearchPathA(NULL, lpFileName, NULL, sizeof(filepath), filepath, &filenameinpath) == 0
    167            && !(fuMode & OF_CREATE) )
     166        if (SearchPathA(NULL, lpFileName, NULL, sizeof(filepath), filepath, &filenameinpath) == 0)
    168167        {
    169             pOFStruct->nErrCode = ERROR_FILE_NOT_FOUND;
    170             SetLastError(ERROR_FILE_NOT_FOUND);
    171             return HFILE_ERROR;
     168            if (!(fuMode & (OF_CREATE | OF_PARSE)))
     169            {
     170                pOFStruct->nErrCode = ERROR_FILE_NOT_FOUND; /* What about initializing the struct? */
     171                SetLastError(ERROR_FILE_NOT_FOUND);
     172                return HFILE_ERROR;
     173            }
     174
     175            /*
     176             * OF_PARSE | OF_CREATE:
     177             *  Assume file in current directory.
     178             */
     179            GetCurrentDirectoryA(sizeof(filepath), filepath);
     180            strcat(strcat(filepath, "\\"), lpFileName);
     181            GetLongPathNameA(filepath, filepath, sizeof(filepath));
    172182        }
    173183        lpFileName = filepath;
    174184    }
    175185    else {
     186        #if 1 /* Canonicalize the path should be the right thing to do I think... */
     187        GetFullPathNameA(lpFileName, sizeof(filepath), filepath, NULL);
     188        #else                       
    176189        ParsePath(lpFileName, filepath, sizeof(filepath));
     190        #endif
    177191
    178192        //convert to long file name if in 8.3 hashed format
    179193        GetLongPathNameA(filepath, filepath, sizeof(filepath));
    180 
    181194        lpFileName = filepath;
    182195    }
     
    187200    strncpy((char *)pOFStruct->szPathName, lpFileName, OFS_MAXPATHNAME);
    188201    pOFStruct->szPathName[OFS_MAXPATHNAME-1] = 0;
     202   
     203
     204    /*
     205     * Do the parse stuff now and do a quick exit.
     206     * Based on testcase (5) and MSDN:
     207     *      "OF_PARSE   Fills the OFSTRUCT structure but carries out no other action."
     208     */
     209    if (fuMode & OF_PARSE)
     210    {
     211        CHAR    szDrive[4];
     212        *(PULONG)&szDrive[0] = *(PULONG)&pOFStruct->szPathName[0];
     213        szDrive[3] = '\0';
     214        pOFStruct->fFixedDisk = (GetDriveTypeA(szDrive) != DRIVE_REMOVABLE);
     215        SetLastError(NO_ERROR);
     216        return NO_ERROR;
     217    }
     218   
    189219
    190220    hFile = OSLibDosOpenFile((LPSTR)lpFileName, fuMode);
    191 
     221   
    192222    if(hFile != INVALID_HANDLE_ERROR)
    193223    {
     
    198228                    NULL,
    199229                    &filetime );
    200 
    201                 /* UTC Time or Localtime ? GetFileTime Returns UTC-time yet ? !!!!! */
     230   
     231        /* UTC Time or Localtime ? GetFileTime Returns UTC-time yet ? !!!!! */
    202232        FileTimeToDosDateTime(&filetime,
    203233                              &filedatetime[0],
    204234                              &filedatetime[1] );
    205235        memcpy(pOFStruct->reserved, filedatetime, sizeof(pOFStruct->reserved));
    206 
     236   
    207237        if(fuMode & OF_DELETE)
    208238        {
     
    216246            hFile = HFILE_ERROR;
    217247        }
    218         if(fuMode & OF_PARSE)
    219         {
    220             CHAR drive[4];
    221 
    222             drive[0] = pOFStruct->szPathName[0];
    223             drive[1] = pOFStruct->szPathName[1];
    224             drive[2] = pOFStruct->szPathName[2];
    225             drive[3] = 0;
    226 
    227             pOFStruct->fFixedDisk = (GetDriveTypeA(drive) != DRIVE_REMOVABLE);
    228 
    229             OSLibDosClose(hFile);
    230             hFile = HFILE_ERROR;
    231         }
    232 
     248   
    233249        if((fuMode & OF_VERIFY))
    234         {
     250        {//TODO: what's this?? we copy the time above...
    235251            if(memcmp(pOFStruct->reserved, filedatetime, sizeof(pOFStruct->reserved)))
    236252            {
     
    240256            hFile = HFILE_ERROR;
    241257        }
    242 
     258   
    243259        pOFStruct->nErrCode = GetLastError();
    244260        pHMHandleData->hHMHandle = hFile;
    245 
     261   
    246262        if(hFile != HFILE_ERROR) {
    247263            pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, NULL);
     
    251267    else {
    252268        DWORD rc = GetLastError();
    253 
     269   
    254270        if(fuMode & OF_EXIST)
    255271        {
Note: See TracChangeset for help on using the changeset viewer.