Ignore:
Timestamp:
Mar 19, 2000, 4:35:32 PM (25 years ago)
Author:
davidr
Message:

Ported changes from wine/corel sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/filemoniker.cpp

    r1033 r3167  
    1 /* $Id: filemoniker.cpp,v 1.1 1999-09-24 21:49:43 davidr Exp $ */
     1/* $Id: filemoniker.cpp,v 1.2 2000-03-19 15:33:06 davidr Exp $ */
    22/*
    33 *  FileMonikers functions.
     
    1515#include "debugtools.h"
    1616#include "filemoniker.h"
     17#include "winnls.h"
    1718
    1819DEFAULT_DEBUG_CHANNEL(ole)
     
    212213{
    213214    HRESULT res;
    214     CHAR* filePathA;
    215     WCHAR* filePathW;
     215    CHAR* filePathA=NULL;
     216    WCHAR* filePathW=NULL;
    216217    ULONG bread;
    217218    WORD  wbuffer;
    218     DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
    219 
     219    DWORD i;
     220    DWORD dwAnsiLength, dwUnicodeLength;
     221    DWORD dwOffsetToEndUnicodeStr;
     222    WCHAR tempUnicodePath[MAX_PATH];
    220223    ICOM_THIS(FileMonikerImpl,iface);
    221224
     
    230233   
    231234    /* read filePath string length (plus one) */
    232     res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
     235    res=IStream_Read(pStm,&dwAnsiLength,sizeof(DWORD),&bread);
    233236    if (bread != sizeof(DWORD))
    234237        return E_FAIL;
    235238
    236     /* read filePath string */
    237     filePathA=(CHAR*)HeapAlloc(GetProcessHeap(),0,length);
    238     res=IStream_Read(pStm,filePathA,length,&bread);
    239     if (bread != length)
     239    if(dwAnsiLength > 0)
     240    {
     241        /* read filePath string */
     242        filePathA=(CHAR *)HeapAlloc(GetProcessHeap(),0,dwAnsiLength);
     243        res=IStream_Read(pStm,filePathA,dwAnsiLength,&bread);
     244        if (bread != dwAnsiLength)
     245            return E_FAIL;
     246    }
     247    tempUnicodePath[0] = 0;
     248    if(filePathA != NULL)
     249    {
     250        MultiByteToWideChar(CP_ACP, 0, filePathA, -1, tempUnicodePath, MAX_PATH);
     251    }
     252    FileMonikerImpl_CheckFileFormat(This, tempUnicodePath);
     253
     254    IStream_Read(pStm, &(This->wNetworkDomainLenght), sizeof(WORD), &bread);
     255    if(bread != sizeof(WORD))
     256    {
    240257        return E_FAIL;
    241 
     258    }
    242259    /* read the first constant */
    243     IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
    244     if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
     260    IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
     261    if (bread != sizeof(WORD) || wbuffer != 0xDEAD)
    245262        return E_FAIL;
    246        
    247     length--;
    248263       
    249264    for(i=0;i<10;i++){
     
    253268    }
    254269   
    255     if (length>8)
    256         length=0;
    257        
    258     doubleLenHex=doubleLenDec=2*length;
    259     if (length > 5)
    260         doubleLenDec+=6;
    261 
    262     res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
    263     if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
     270    res=IStream_Read(pStm,&dwOffsetToEndUnicodeStr,sizeof(DWORD),&bread);
     271    if (bread != sizeof(DWORD))
    264272        return E_FAIL;
    265 
    266     if (length==0)
    267         return res;
    268        
    269     res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
    270     if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
    271         return E_FAIL;
    272 
    273     res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
    274     if (bread!=sizeof(WORD) || wbuffer!=0x3)
    275         return E_FAIL;
    276 
    277     filePathW=(WCHAR*)HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
    278     filePathW[length]=0;
    279     res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
    280     if (bread!=doubleLenHex)
    281         return E_FAIL;
     273    if(dwOffsetToEndUnicodeStr != 0)
     274    {
     275        res=IStream_Read(pStm,&dwUnicodeLength,sizeof(DWORD),&bread);
     276        if (bread!=sizeof(DWORD))
     277            return E_FAIL;
     278
     279
     280        res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
     281        if (bread!=sizeof(WORD) || wbuffer!=0x3)
     282            return E_FAIL;
     283
     284        if(dwUnicodeLength > 0)
     285        {
     286            filePathW=(WCHAR *)HeapAlloc(GetProcessHeap(),0,dwUnicodeLength + sizeof(WCHAR));
     287            res=IStream_Read(pStm, filePathW, dwUnicodeLength,&bread);
     288            filePathW[dwAnsiLength-1]=0;
     289            if (bread!=dwUnicodeLength)
     290                return E_FAIL;
     291        }
     292    }
     293    else
     294    {
     295        if(filePathA != NULL)
     296        {
     297            filePathW=(WCHAR *)HeapAlloc(GetProcessHeap(),0,dwAnsiLength*sizeof(WCHAR));
     298            MultiByteToWideChar(CP_ACP, 0, filePathA, -1, filePathW, dwAnsiLength);
     299            filePathW[dwAnsiLength-1]=0;
     300        }
     301    }
    282302
    283303    if (This->filePathName!=NULL)
     
    286306    This->filePathName=filePathW;
    287307
    288     HeapFree(GetProcessHeap(),0,filePathA);
     308    if(filePathA != NULL)
     309    {
     310        HeapFree(GetProcessHeap(),0,filePathA);
     311    }
    289312   
    290313    return res;
     
    313336    HRESULT res;
    314337    LPOLESTR filePathW=This->filePathName;
    315     CHAR*     filePathA;
    316     DWORD  len=1+lstrlenW(filePathW);
    317 
    318     DWORD  constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure writen by */
     338    CHAR*     filePathA=NULL;
     339    DWORD  len=0;
     340
     341    WORD  constant1 = 0xDEAD; /* these constants are detected after analysing the data structure writen by */
    319342    WORD   constant2 = 0x3;        /* FileMoniker_Save function in a windows program system */
     343    WORD wUnicodeLen=0xFFFF; 
     344    DWORD dwOffsetToEndUnicodeStr=0;
    320345
    321346    WORD   zero=0;
    322347    DWORD doubleLenHex;
    323     DWORD doubleLenDec;
    324348    int i=0;
     349    WCHAR temp = 0;
     350
    325351
    326352    TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
     
    328354    if (pStm==NULL)
    329355        return E_POINTER;
     356    if(filePathW == NULL)
     357    {
     358        return S_FALSE;  /* TODO: Check what windows returns */
     359    }
     360
     361    doubleLenHex=lstrlenW(filePathW) * sizeof(WCHAR); /* Doesn't include the "\0" */
     362    len = lstrlenW(filePathW)+1;
     363    filePathA=(CHAR *)HeapAlloc(GetProcessHeap(), 0,len);
     364    lstrcpyWtoA(filePathA,filePathW);
     365   
     366    if(!This->bIsLongFileName && len > 1)
     367    {
     368       
     369        dwOffsetToEndUnicodeStr = sizeof(DWORD) + sizeof(WORD) + doubleLenHex;
     370    }
    330371
    331372    /* write a DWORD seted to 0 : constant */
     373    /* TODO: Not Sure, but I believe that this is a constant for  char types */
     374    /* eg. 0000 for Ansi, 0003 for Unicode, will need to verify this  */
    332375    res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
    333376
     
    336379
    337380    /* write filePath string type A */
    338     filePathA=(CHAR *)HeapAlloc(GetProcessHeap(),0,len);
    339     lstrcpyWtoA(filePathA,filePathW);
    340381    res=IStream_Write(pStm,filePathA,len,NULL);
    341     HeapFree(GetProcessHeap(),0,filePathA);
    342 
    343     /* write a DWORD seted to 0xDEADFFFF: constant */
    344     res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
     382
     383    /*When the file path is a network path, it fills this value with */
     384    /*Lenght in of the domain/share drive name */
     385    res=IStream_Write(pStm, &(This->wNetworkDomainLenght), sizeof(wUnicodeLen), NULL);
     386    /* write a WORD seted to 0xDEAD: constant */
     387    res=IStream_Write(pStm,&constant1,sizeof(constant1),NULL);
    345388       
    346389    len--;
    347     /* write 10 times a DWORD seted to 0 : constants */
     390    /* write 10 times a WORD seted to 0 : constants */
    348391    for(i=0;i<10;i++)
    349392        res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
    350        
    351     if (len>8)
    352         len=0;
    353        
    354     doubleLenHex=doubleLenDec=2*len;
    355     if (len > 5)
    356         doubleLenDec+=6;
    357 
    358     /* write double-length of the path string ( "\0" included )*/
    359     res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
    360 
    361     if (len==0)
    362         return res;
    363 
    364     /* write double-length (hexa representation) of the path string ( "\0" included ) */
    365     res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
    366 
    367     /* write a WORD seted to 0x3: constant */
    368     res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
    369 
    370     /* write path unicode string */
    371     res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
    372 
     393
     394    /* when a file path is a file or network path that doesn't fallow the dos 8.3 format  */
     395    /* it creates the unicode data.  This value is offset */
     396    /* where the Unicode string ends.  If the file is a long dos filename (or network containing a long filename)*/
     397    /* it doesn't create it's unicode counterpart */   
     398    res=IStream_Write(pStm, &dwOffsetToEndUnicodeStr, sizeof(DWORD), NULL);
     399    if(dwOffsetToEndUnicodeStr != 0)
     400    {
     401        /* write double-length (hexa representation) of the path string*/
     402        res=IStream_Write(pStm, &doubleLenHex, sizeof(DWORD),NULL);
     403        /* write a WORD seted to 0x3: constant */
     404        /* TODO: (same as above) Not Sure, but I believe that this is a constant for  char types */
     405        /* eg. 0000 for Ansi, 0003 for Unicode, will need to verify this  */
     406        res=IStream_Write(pStm, &constant2, sizeof(WORD),NULL);
     407        /* write path unicode string */
     408        if(doubleLenHex > 0)
     409        {
     410            res=IStream_Write(pStm, filePathW, doubleLenHex,NULL);
     411        }
     412    }
     413    if(filePathA != NULL)
     414    {
     415        HeapFree(GetProcessHeap(),0,filePathA);
     416    }
    373417    return res;
    374418}
     
    386430    TRACE("(%p,%p)\n",iface,pcbSize);
    387431
    388     if (pcbSize!=NULL)
     432    if (pcbSize==NULL)
    389433        return E_POINTER;
    390434
     
    398442               sizeof(DWORD);           /* size of the unicode filePath: "\0" not included */
    399443
    400     if (len==0 || len > 8)
    401         return S_OK;
    402    
    403     sizeMAx += sizeof(DWORD)+           /* size of the unicode filePath: "\0" not included */
    404                sizeof(WORD)+            /* constant : 0x3 */
    405                len*sizeof(WCHAR);       /* unicde filePath string */
     444    if(!This->bIsLongFileName)
     445    {
     446       
     447        sizeMAx += sizeof(DWORD)+           /* size of the unicode filePath: "\0" not included */
     448                   sizeof(WORD)+            /* constant : 0x3 */
     449                   len*sizeof(WCHAR);       /* unicde filePath string */
     450    }
    406451   
    407452    pcbSize->LowPart=sizeMAx;
     
    411456}
    412457
     458void WINAPI FileMonikerImpl_CheckFileFormat(FileMonikerImpl* This, LPCOLESTR lpszPathName)
     459{
     460    int len;
     461    WCHAR tempShortPath[MAX_PATH];
     462
     463    This->bIsNetworkPath = FALSE;
     464    This->bIsLongFileName = FALSE;
     465    This->wNetworkDomainLenght = 0xFFFF;
     466
     467    /* TODO: Not handling invalid filesname  and invalid UNC Filenames */
     468    /* Filenames that doesn't conform to dos 8.3, are handled diffently when saving and loading */
     469    /* Same applies to network path, but only after the \\Domain\Share path */
     470
     471    if(lpszPathName == NULL)
     472    {
     473        return;
     474    }
     475    len = lstrlenW(lpszPathName);
     476    if(len == 0)
     477    {
     478        return;
     479    }
     480
     481    if( len >= 2)
     482    {
     483        /* Is this a network path */
     484        if(lpszPathName[0] == '\\' && lpszPathName[1] == '\\')
     485        {
     486            int i=2; /* Skip the \\ */
     487            int j=0;
     488            This->bIsNetworkPath = TRUE;
     489            /* Skip Domain name \ share drive name */
     490            for(j =0; j < 2; j++)
     491            {
     492                for(; i < len && lpszPathName[i] != '\\'; i++)
     493                {
     494                }
     495                i++;
     496            }
     497            This->wNetworkDomainLenght = i-1;
     498            if( i < len)
     499            {
     500                /* Check to see if the file fallows the dos file format (8.3)*/
     501                GetShortPathNameW(&(lpszPathName[i]), tempShortPath, MAX_PATH);
     502                if(lstrcmpiW(&(lpszPathName[i]), tempShortPath) != 0)
     503                {
     504                    This->bIsLongFileName = TRUE;
     505                }
     506            }
     507        }
     508       
     509        else
     510        {
     511            GetShortPathNameW(lpszPathName, tempShortPath, MAX_PATH);
     512            if(lstrcmpiW(lpszPathName, tempShortPath) != 0)
     513            {
     514                This->bIsLongFileName = TRUE;
     515            }
     516        }
     517    }
     518}
    413519/******************************************************************************
    414520 *         FileMoniker_Construct (local function)
     
    475581    }
    476582
     583    FileMonikerImpl_CheckFileFormat(This, This->filePathName);
    477584    for(i=0; tabStr[i]!=NULL;i++)
    478585        CoTaskMemFree(tabStr[i]);
     
    10481155{
    10491156    WCHAR bSlash[] = {'\\',0};
    1050     WCHAR word[100];
     1157    WCHAR word[MAX_PATH];
    10511158    int i=0,j,tabIndex=0;
    10521159    LPOLESTR *strgtable ;
Note: See TracChangeset for help on using the changeset viewer.