Ignore:
Timestamp:
Sep 15, 2001, 11:32:00 AM (24 years ago)
Author:
sandervl
Message:

restored old version + wine update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/stg_stream.c

    r6648 r6711  
    1 /* $Id: stg_stream.c,v 1.3 2001-09-05 13:17:12 bird Exp $ */
    21/*
    32 * Compound Storage (32 bit version)
     
    2827
    2928#include "storage32.h"
     29
     30#ifdef __WIN32OS2__
     31#undef FIXME
     32#undef TRACE
     33#ifdef DEBUG
     34#define TRACE WriteLog("OLE32: %s", __FUNCTION__); WriteLog
     35#define FIXME WriteLog("FIXME OLE32: %s", __FUNCTION__); WriteLog
     36#else
     37#define TRACE 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
     38#define FIXME 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
     39#endif
     40#endif
    3041
    3142DEFAULT_DEBUG_CHANNEL(storage);
     
    6677 */
    6778StgStreamImpl* StgStreamImpl_Construct(
    68         StorageBaseImpl* parentStorage,
     79                StorageBaseImpl* parentStorage,
    6980    DWORD            grfMode,
    7081    ULONG            ownerProperty)
     
    7384
    7485  newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
    75 
     86 
    7687  if (newStream!=0)
    7788  {
     
    8192    ICOM_VTBL(newStream) = &StgStreamImpl_Vtbl;
    8293    newStream->ref       = 0;
    83 
     94   
    8495    /*
    8596     * We want to nail-down the reference to the storage in case the
     
    89100    IStorage_AddRef((IStorage*)newStream->parentStorage);
    90101
    91     newStream->grfMode = grfMode;
     102    newStream->grfMode = grfMode;   
    92103    newStream->ownerProperty = ownerProperty;
    93 
     104   
    94105    /*
    95106     * Start the stream at the begining.
     
    97108    newStream->currentPosition.s.HighPart = 0;
    98109    newStream->currentPosition.s.LowPart = 0;
    99 
     110   
    100111    /*
    101112     * Initialize the rest of the data.
     
    105116    newStream->bigBlockChain       = 0;
    106117    newStream->smallBlockChain     = 0;
    107 
     118   
    108119    /*
    109120     * Read the size from the property and determine if the blocks forming
     
    112123    StgStreamImpl_OpenBlockChain(newStream);
    113124  }
    114 
     125 
    115126  return newStream;
    116127}
     
    119130 * This is the destructor of the StgStreamImpl class.
    120131 *
    121  * This method will clean-up all the resources used-up by the given StgStreamImpl
     132 * This method will clean-up all the resources used-up by the given StgStreamImpl 
    122133 * class. The pointer passed-in to this function will be freed and will not
    123134 * be valid anymore.
     
    151162   * Finally, free the memory used-up by the class.
    152163   */
    153   HeapFree(GetProcessHeap(), 0, This);
     164  HeapFree(GetProcessHeap(), 0, This); 
    154165}
    155166
     
    159170 */
    160171HRESULT WINAPI StgStreamImpl_QueryInterface(
    161           IStream*     iface,
    162           REFIID         riid,        /* [in] */
    163           void**         ppvObject)   /* [iid_is][out] */
     172                  IStream*     iface,
     173                  REFIID         riid,        /* [in] */         
     174                  void**         ppvObject)   /* [iid_is][out] */
    164175{
    165176  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    170181  if (ppvObject==0)
    171182    return E_INVALIDARG;
    172 
     183 
    173184  /*
    174185   * Initialize the return parameter.
    175186   */
    176187  *ppvObject = 0;
    177 
     188 
    178189  /*
    179190   * Compare the riid with the interface IDs implemented by this object.
    180191   */
    181   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
     192  if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 
    182193  {
    183194    *ppvObject = (IStream*)This;
    184195  }
    185   else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0)
     196  else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) 
    186197  {
    187198    *ppvObject = (IStream*)This;
    188199  }
    189 
     200 
    190201  /*
    191202   * Check that we obtained an interface.
     
    193204  if ((*ppvObject)==0)
    194205    return E_NOINTERFACE;
    195 
     206 
    196207  /*
    197208   * Query Interface always increases the reference count by one when it is
     
    199210   */
    200211  StgStreamImpl_AddRef(iface);
    201 
     212 
    202213  return S_OK;;
    203214}
     
    208219 */
    209220ULONG WINAPI StgStreamImpl_AddRef(
    210         IStream* iface)
     221                IStream* iface)
    211222{
    212223  StgStreamImpl* const This=(StgStreamImpl*)iface;
    213224
    214225  This->ref++;
    215 
     226 
    216227  return This->ref;
    217228}
     
    222233 */
    223234ULONG WINAPI StgStreamImpl_Release(
    224         IStream* iface)
     235                IStream* iface)
    225236{
    226237  StgStreamImpl* const This=(StgStreamImpl*)iface;
    227238
    228239  ULONG newRef;
    229 
     240 
    230241  This->ref--;
    231 
     242 
    232243  newRef = This->ref;
    233 
     244 
    234245  /*
    235246   * If the reference count goes down to 0, perform suicide.
     
    239250    StgStreamImpl_Destroy(This);
    240251  }
    241 
     252 
    242253  return newRef;
    243254}
     
    273284   */
    274285  readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
    275                          This->ownerProperty,
    276                          &curProperty);
    277 
     286                                             This->ownerProperty,
     287                                             &curProperty);
     288 
    278289  if (readSucessful)
    279290  {
    280291    This->streamSize = curProperty.size;
    281 
     292   
    282293    /*
    283294     * This code supports only streams that are <32 bits in size.
    284295     */
    285296    assert(This->streamSize.s.HighPart == 0);
    286 
     297   
    287298    if(curProperty.startingBlock == BLOCK_END_OF_CHAIN)
    288299    {
     
    292303    {
    293304      if ( (This->streamSize.s.HighPart == 0) &&
    294        (This->streamSize.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
     305           (This->streamSize.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
    295306      {
    296     This->smallBlockChain = SmallBlockChainStream_Construct(
    297                                 This->parentStorage->ancestorStorage,
    298                                 This->ownerProperty);
     307        This->smallBlockChain = SmallBlockChainStream_Construct(
     308                                                                This->parentStorage->ancestorStorage,   
     309                                                                This->ownerProperty);
    299310      }
    300311      else
    301312      {
    302     This->bigBlockChain = BlockChainStream_Construct(
    303                             This->parentStorage->ancestorStorage,
    304                             NULL,
    305                             This->ownerProperty);
     313        This->bigBlockChain = BlockChainStream_Construct(
     314                                                        This->parentStorage->ancestorStorage,
     315                                                        NULL,
     316                                                        This->ownerProperty);
    306317      }
    307318    }
     
    318329 * See the documentation of ISequentialStream for more info.
    319330 */
    320 HRESULT WINAPI StgStreamImpl_Read(
    321           IStream*     iface,
    322           void*          pv,        /* [length_is][size_is][out] */
    323           ULONG          cb,        /* [in] */
    324           ULONG*         pcbRead)   /* [out] */
     331HRESULT WINAPI StgStreamImpl_Read( 
     332                  IStream*     iface,
     333                  void*          pv,        /* [length_is][size_is][out] */
     334                  ULONG          cb,        /* [in] */                     
     335                  ULONG*         pcbRead)   /* [out] */                   
    325336{
    326337  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    330341
    331342  TRACE("(%p, %p, %ld, %p)\n",
    332     iface, pv, cb, pcbRead);
    333 
    334   /*
     343        iface, pv, cb, pcbRead);
     344
     345  /* 
    335346   * If the caller is not interested in the nubmer of bytes read,
    336347   * we use another buffer to avoid "if" statements in the code.
     
    338349  if (pcbRead==0)
    339350    pcbRead = &bytesReadBuffer;
    340 
     351 
    341352  /*
    342353   * Using the known size of the stream, calculate the number of bytes
     
    344355   */
    345356  bytesToReadFromBuffer = min( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
    346 
     357 
    347358  /*
    348359   * Depending on the type of chain that was opened when the stream was constructed,
     
    352363  {
    353364    SmallBlockChainStream_ReadAt(This->smallBlockChain,
    354                 This->currentPosition,
    355                 bytesToReadFromBuffer,
    356                 pv,
    357                 pcbRead);
    358 
     365                                This->currentPosition,
     366                                bytesToReadFromBuffer,
     367                                pv,
     368                                pcbRead);
     369   
    359370  }
    360371  else if (This->bigBlockChain!=0)
    361372  {
    362373    BlockChainStream_ReadAt(This->bigBlockChain,
    363                 This->currentPosition,
    364                 bytesToReadFromBuffer,
    365                 pv,
    366                 pcbRead);
     374                            This->currentPosition,
     375                            bytesToReadFromBuffer,
     376                            pv,
     377                            pcbRead);
    367378  }
    368379  else
     
    387398   */
    388399  This->currentPosition.s.LowPart += *pcbRead;
    389 
     400 
    390401  /*
    391402   * The function returns S_OK if the buffer was filled completely
     
    395406  if(*pcbRead == cb)
    396407    return S_OK;
    397 
     408 
    398409  return S_FALSE;
    399410}
    400 
     411       
    401412/***
    402413 * This method is part of the ISequentialStream interface.
     
    410421 */
    411422HRESULT WINAPI StgStreamImpl_Write(
    412               IStream*     iface,
    413           const void*    pv,          /* [size_is][in] */
    414           ULONG          cb,          /* [in] */
    415           ULONG*         pcbWritten)  /* [out] */
     423                  IStream*     iface,
     424                  const void*    pv,          /* [size_is][in] */
     425                  ULONG          cb,          /* [in] */         
     426                  ULONG*         pcbWritten)  /* [out] */         
    416427{
    417428  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    421432
    422433  TRACE("(%p, %p, %ld, %p)\n",
    423     iface, pv, cb, pcbWritten);
    424 
     434        iface, pv, cb, pcbWritten);
     435 
    425436  /*
    426437   * Do we have permission to write to this stream?
     
    436447  if (pcbWritten == 0)
    437448    pcbWritten = &bytesWritten;
    438 
     449 
    439450  /*
    440451   * Initialize the out parameter
     
    451462    newSize.s.LowPart = This->currentPosition.s.LowPart + cb;
    452463  }
    453 
     464 
    454465  /*
    455466   * Verify if we need to grow the stream
     
    460471    IStream_SetSize(iface, newSize);
    461472  }
    462 
     473 
    463474  /*
    464475   * Depending on the type of chain that was opened when the stream was constructed,
     
    468479  {
    469480    SmallBlockChainStream_WriteAt(This->smallBlockChain,
    470                   This->currentPosition,
    471                   cb,
    472                   pv,
    473                   pcbWritten);
    474 
     481                                  This->currentPosition,
     482                                  cb,
     483                                  pv,
     484                                  pcbWritten);
     485   
    475486  }
    476487  else if (This->bigBlockChain!=0)
    477488  {
    478489    BlockChainStream_WriteAt(This->bigBlockChain,
    479                  This->currentPosition,
    480                  cb,
    481                  pv,
    482                  pcbWritten);
     490                             This->currentPosition,
     491                             cb,
     492                             pv,
     493                             pcbWritten);
    483494  }
    484495  else
    485496    assert(FALSE);
    486 
     497 
    487498  /*
    488499   * Advance the position pointer for the number of positions written.
    489500   */
    490501  This->currentPosition.s.LowPart += *pcbWritten;
    491 
     502 
    492503  return S_OK;
    493504}
     
    500511 *
    501512 * See the documentation of IStream for more info.
    502  */
    503 HRESULT WINAPI StgStreamImpl_Seek(
    504           IStream*      iface,
    505           LARGE_INTEGER   dlibMove,         /* [in] */
    506           DWORD           dwOrigin,         /* [in] */
    507           ULARGE_INTEGER* plibNewPosition) /* [out] */
     513 */       
     514HRESULT WINAPI StgStreamImpl_Seek( 
     515                  IStream*      iface,
     516                  LARGE_INTEGER   dlibMove,         /* [in] */
     517                  DWORD           dwOrigin,         /* [in] */
     518                  ULARGE_INTEGER* plibNewPosition) /* [out] */
    508519{
    509520  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    512523
    513524  TRACE("(%p, %ld, %ld, %p)\n",
    514     iface, dlibMove.s.LowPart, dwOrigin, plibNewPosition);
    515 
    516   /*
     525        iface, dlibMove.s.LowPart, dwOrigin, plibNewPosition);
     526
     527  /* 
    517528   * The caller is allowed to pass in NULL as the new position return value.
    518529   * If it happens, we assign it to a dynamic variable to avoid special cases
     
    556567      /* ... and subtract with carry */
    557568      if (dlibMove.s.LowPart > plibNewPosition->s.LowPart) {
    558       /* carry needed, This accounts for any underflows at [1]*/
    559       plibNewPosition->s.HighPart -= 1;
     569          /* carry needed, This accounts for any underflows at [1]*/
     570          plibNewPosition->s.HighPart -= 1;
    560571      }
    561572      plibNewPosition->s.LowPart -= dlibMove.s.LowPart; /* [1] */
    562       plibNewPosition->s.HighPart -= dlibMove.s.HighPart;
     573      plibNewPosition->s.HighPart -= dlibMove.s.HighPart; 
    563574  } else {
    564575      /* add directly */
     
    566577      plibNewPosition->s.LowPart += dlibMove.s.LowPart;
    567578      if((plibNewPosition->s.LowPart < initialLowPart) ||
    568     (plibNewPosition->s.LowPart < dlibMove.s.LowPart)) {
    569       /* LowPart has rolled over => add the carry digit to HighPart */
    570       plibNewPosition->s.HighPart++;
     579        (plibNewPosition->s.LowPart < dlibMove.s.LowPart)) {
     580          /* LowPart has rolled over => add the carry digit to HighPart */
     581          plibNewPosition->s.HighPart++;
    571582      }
    572       plibNewPosition->s.HighPart += dlibMove.s.HighPart;
    573   }
    574   /*
    575    * Check if we end-up before the beginning of the file. That should
     583      plibNewPosition->s.HighPart += dlibMove.s.HighPart; 
     584  }
     585  /*
     586   * Check if we end-up before the beginning of the file. That should 
    576587   * trigger an error.
    577588   */
     
    581592
    582593    /*
    583    * We currently don't support files with offsets of >32 bits.
     594   * We currently don't support files with offsets of >32 bits. 
    584595   * Note that we have checked for a negative offset already
    585596     */
     
    594605   */
    595606  This->currentPosition = *plibNewPosition;
    596 
     607 
    597608  return S_OK;
    598609}
     
    607618 * See the documentation of IStream for more info.
    608619 */
    609 HRESULT WINAPI StgStreamImpl_SetSize(
    610                      IStream*      iface,
    611                      ULARGE_INTEGER  libNewSize)   /* [in] */
     620HRESULT WINAPI StgStreamImpl_SetSize( 
     621                                     IStream*      iface,
     622                                     ULARGE_INTEGER  libNewSize)   /* [in] */
    612623{
    613624  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    658669  Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
    659670                                       This->ownerProperty,
    660                                        &curProperty);
     671                                       &curProperty); 
    661672  /*
    662673   * Determine if we have to switch from small to big blocks or vice versa
    663    */
    664   if ( (This->smallBlockChain!=0) &&
     674   */ 
     675  if ( (This->smallBlockChain!=0) && 
    665676       (curProperty.size.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
    666677  {
     
    694705  curProperty.size.s.HighPart = libNewSize.s.HighPart;
    695706  curProperty.size.s.LowPart = libNewSize.s.LowPart;
    696 
     707 
    697708  if (Success)
    698709  {
    699710    StorageImpl_WriteProperty(This->parentStorage->ancestorStorage,
    700                 This->ownerProperty,
    701                 &curProperty);
    702   }
    703 
     711                                This->ownerProperty,
     712                                &curProperty);
     713  }
     714 
    704715  This->streamSize = libNewSize;
    705 
     716 
    706717  return S_OK;
    707718}
    708 
     719       
    709720/***
    710721 * This method is part of the IStream interface.
     
    714725 * See the documentation of IStream for more info.
    715726 */
    716 HRESULT WINAPI StgStreamImpl_CopyTo(
    717                     IStream*      iface,
    718                     IStream*      pstm,         /* [unique][in] */
    719                     ULARGE_INTEGER  cb,           /* [in] */
    720                     ULARGE_INTEGER* pcbRead,      /* [out] */
    721                     ULARGE_INTEGER* pcbWritten)   /* [out] */
     727HRESULT WINAPI StgStreamImpl_CopyTo( 
     728                                    IStream*      iface,
     729                                    IStream*      pstm,         /* [unique][in] */
     730                                    ULARGE_INTEGER  cb,           /* [in] */         
     731                                    ULARGE_INTEGER* pcbRead,      /* [out] */       
     732                                    ULARGE_INTEGER* pcbWritten)   /* [out] */       
    722733{
    723734  HRESULT        hr = S_OK;
     
    727738  ULARGE_INTEGER totalBytesWritten;
    728739
    729   TRACE("(%p, %p, %ld, %p, %p)\n",
    730     iface, pstm, cb.s.LowPart, pcbRead, pcbWritten);
     740  TRACE("(%p, %p, %ld, %p, %p)\n", 
     741        iface, pstm, cb.s.LowPart, pcbRead, pcbWritten);
    731742
    732743  /*
     
    750761    else
    751762      copySize = cb.s.LowPart;
    752 
     763   
    753764    IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
    754765
    755766    totalBytesRead.s.LowPart += bytesRead;
    756 
     767   
    757768    IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
    758769
     
    767778      break;
    768779    }
    769 
     780   
    770781    if (bytesRead!=copySize)
    771782      cb.s.LowPart = 0;
     
    798809 *
    799810 * See the documentation of IStream for more info.
    800  */
    801 HRESULT WINAPI StgStreamImpl_Commit(
    802           IStream*      iface,
    803           DWORD           grfCommitFlags)  /* [in] */
     811 */       
     812HRESULT WINAPI StgStreamImpl_Commit( 
     813                  IStream*      iface,
     814                  DWORD           grfCommitFlags)  /* [in] */
    804815{
    805816  return S_OK;
     
    813824 *
    814825 * See the documentation of IStream for more info.
    815  */
    816 HRESULT WINAPI StgStreamImpl_Revert(
    817           IStream* iface)
     826 */       
     827HRESULT WINAPI StgStreamImpl_Revert( 
     828                  IStream* iface)
    818829{
    819830  return S_OK;
    820831}
    821832
    822 HRESULT WINAPI StgStreamImpl_LockRegion(
    823                     IStream*     iface,
    824                     ULARGE_INTEGER libOffset,   /* [in] */
    825                     ULARGE_INTEGER cb,          /* [in] */
    826                     DWORD          dwLockType)  /* [in] */
     833HRESULT WINAPI StgStreamImpl_LockRegion( 
     834                                        IStream*     iface,
     835                                        ULARGE_INTEGER libOffset,   /* [in] */
     836                                        ULARGE_INTEGER cb,          /* [in] */
     837                                        DWORD          dwLockType)  /* [in] */
    827838{
    828839  FIXME("not implemented!\n");
     
    830841}
    831842
    832 HRESULT WINAPI StgStreamImpl_UnlockRegion(
    833                       IStream*     iface,
    834                       ULARGE_INTEGER libOffset,   /* [in] */
    835                       ULARGE_INTEGER cb,          /* [in] */
    836                       DWORD          dwLockType)  /* [in] */
     843HRESULT WINAPI StgStreamImpl_UnlockRegion( 
     844                                          IStream*     iface,
     845                                          ULARGE_INTEGER libOffset,   /* [in] */
     846                                          ULARGE_INTEGER cb,          /* [in] */
     847                                          DWORD          dwLockType)  /* [in] */
    837848{
    838849  FIXME("not implemented!\n");
     
    847858 *
    848859 * See the documentation of IStream for more info.
    849  */
    850 HRESULT WINAPI StgStreamImpl_Stat(
    851           IStream*     iface,
    852           STATSTG*       pstatstg,     /* [out] */
    853           DWORD          grfStatFlag)  /* [in] */
     860 */       
     861HRESULT WINAPI StgStreamImpl_Stat( 
     862                  IStream*     iface,
     863                  STATSTG*       pstatstg,     /* [out] */
     864                  DWORD          grfStatFlag)  /* [in] */
    854865{
    855866  StgStreamImpl* const This=(StgStreamImpl*)iface;
     
    857868  StgProperty    curProperty;
    858869  BOOL         readSucessful;
    859 
     870 
    860871  /*
    861872   * Read the information from the property.
    862873   */
    863874  readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
    864                          This->ownerProperty,
    865                          &curProperty);
    866 
     875                                             This->ownerProperty,
     876                                             &curProperty);
     877 
    867878  if (readSucessful)
    868879  {
    869     StorageUtl_CopyPropertyToSTATSTG(pstatstg,
    870                      &curProperty,
    871                      grfStatFlag);
     880    StorageUtl_CopyPropertyToSTATSTG(pstatstg, 
     881                                     &curProperty,
     882                                     grfStatFlag);
    872883
    873884    pstatstg->grfMode = This->grfMode;
    874 
     885   
    875886    return S_OK;
    876887  }
    877 
     888 
    878889  return E_FAIL;
    879890}
    880 
    881 HRESULT WINAPI StgStreamImpl_Clone(
    882                    IStream*     iface,
    883                    IStream**    ppstm) /* [out] */
    884 {
    885   FIXME("not implemented!\n");
    886   return E_NOTIMPL;
    887 }
     891       
     892/***
     893 * This method is part of the IStream interface.
     894 *
     895 * This method returns a clone of the interface that allows for
     896 * another seek pointer
     897 *
     898 * See the documentation of IStream for more info.
     899 *
     900 * I am not totally sure what I am doing here but I presume that this
     901 * should be basically as simple as creating a new stream with the same
     902 * parent etc and positioning its seek cursor.
     903 */       
     904HRESULT WINAPI StgStreamImpl_Clone(
     905                                   IStream*     iface,
     906                                   IStream**    ppstm) /* [out] */
     907{
     908  StgStreamImpl* const This=(StgStreamImpl*)iface;
     909  HRESULT hres;
     910  StgStreamImpl* new_stream;
     911  LARGE_INTEGER seek_pos;
     912
     913  /*
     914   * Sanity check
     915   */
     916  if ( ppstm == 0 )
     917    return STG_E_INVALIDPOINTER;
     918
     919  new_stream = StgStreamImpl_Construct (This->parentStorage, This->grfMode, This->ownerProperty);
     920
     921  if (!new_stream)
     922    return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
     923
     924  *ppstm = (IStream*) new_stream;
     925  seek_pos.QuadPart = This->currentPosition.QuadPart;
     926 
     927  hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
     928 
     929  assert (SUCCEEDED(hres));
     930
     931  return S_OK;
     932}
Note: See TracChangeset for help on using the changeset viewer.