Ejemplo n.º 1
0
void Profile::Copy ( Profile &Source ) {

   #ifdef __OS2__

      // If either profile isn't really open, return w/o doing anything at all.
      if ( !Handle || !Source.IsReady() ) {
         Log ( "Profile::Copy: Either the source or the target handle is invalid." ) ;
         return ;
      } /* endif */

      // Find out how much memory is needed to get the entire list of keys for this application.
      ULONG KeyListSize ;
      if ( !PrfQueryProfileSize ( Source.Handle, Source.QueryName(), 0, &KeyListSize ) ) {
         ERRORID Error = Sys_GetLastError ( 0 ) ;
         Log ( "Profile::Copy: Unable to query for the list of defined keys.  Status %08X.", Error ) ;
         return ;
      } /* endif */

      // Allocate memory to hold the key list.
      char *KeyList = new char [ ++KeyListSize ] ;
      if ( !KeyList ) {
         Log ( "Profile::Copy: Unable to allocate memory for the key list." ) ;
         return ;
      } /* endif */

      // Fetch the list of keys.
      if ( !PrfQueryProfileData ( Source.Handle, Source.QueryName(), 0, KeyList, &KeyListSize ) ) {
         ERRORID Error = Sys_GetLastError ( 0 ) ;
         Log ( "Profile::Copy: Unable to query for the key list.  Status %08X.", Error ) ;
         delete [] KeyList ;
         return ;
      } /* endif */

      // Scan the key list, copying the data to the new profile.
      char *Key = KeyList ;
      while ( *Key ) {
         ULONG ItemSize ;
         if ( !PrfQueryProfileSize ( Source.Handle, Source.QueryName(), Key, &ItemSize ) ) 
            break ;
         char *Item = new char [ ItemSize ] ;
         if ( !Item ) 
            break ;
         if ( !PrfQueryProfileData ( Source.Handle, Source.QueryName(), Key, Item, &ItemSize ) )  {
            delete [] Item ;
            break ;
         } /* endif */
         if ( !PrfWriteProfileData ( Handle, Name, Key, Item, ItemSize ) ) {
            delete [] Item ;
            break ;
         } /* endif */
         Key += strlen(Key) + 1 ;
      } /* endwhile */
  
      // Release the memory for the key list.
      delete [] KeyList ;

   #else // __NT__

      // We're not going to implement this one for now, as the only reason for it was
      //   to convert from MemSize 3.31's INI file to MemSize 4.00's file, and the Win32
      //   version had no version before 4.00.
      Source.QueryName ( ) ;

   #endif // __OS2__ vs __NT__

} /* endmethod */