diff --git a/arch/arcentry.cpp b/arch/arcentry.cpp index 436d26082..9cbbe91fc 100755 --- a/arch/arcentry.cpp +++ b/arch/arcentry.cpp @@ -59,6 +59,7 @@ // #include "arclib.h" +#include #pragma hdrstop // @@ -100,7 +101,7 @@ #if defined( AL_BUILDING_DLL ) void AL_DLL_FAR * AL_PROTO ALEntry::operator new( size_t size ) { - return ::new char[ size ]; + return ::new char[ size ]; } #endif @@ -130,7 +131,7 @@ void AL_DLL_FAR * AL_PROTO ALEntry::operator new( size_t size ) #if defined( AL_BUILDING_DLL ) void AL_DLL_FAR * AL_PROTO ALEntryList::operator new( size_t size ) { - return ::new char[ size ]; + return ::new char[ size ]; } #endif @@ -191,34 +192,34 @@ void AL_DLL_FAR * AL_PROTO ALEntryList::operator new( size_t size ) // AL_PROTO ALEntry::ALEntry( ALEntryList &list, - ALStorage *object, - ALCompressionEngine *engine ) - : mrList( list ) // Initialize our own pointer to the list we will - // be a member of. + ALStorage *object, + ALCompressionEngine *engine ) +: mrList( list ) // Initialize our own pointer to the list we will + // be a member of. { - mpNextItem = this; - mpPreviousItem = this; - mpStorageObject = object; - mpCompressionEngine = engine; - mlCompressedSize = -1; - mlCompressedObjectPosition = -1; - miMark = 1; //Always construct with the mark turned on - mszComment = 0; -// -// I check for the object member to be non-zero because of a clunky design -// choice I made a while back. Each ALEntryList has an ALEntry member that -// points to the first and last members of the list. I could have (and -// probably should have) made the root of the list just be a pair of pointers, -// instead of a dummy ALEntry. Anyway, I can tell that dummy entry apart -// from the valid entries by virtue of the fact that it has a null -// pointer in its object pointer. -// -// So anyway, when I create this dummy object, I don't want to try to add -// it to the list, because by definition it is already in the list. So -// I do a check before adding any ALEntry to the list. -// - if ( object ) - InsertBefore( *list.mpListHead ); + mpNextItem = this; + mpPreviousItem = this; + mpStorageObject = object; + mpCompressionEngine = engine; + mlCompressedSize = -1; + mlCompressedObjectPosition = -1; + miMark = 1; //Always construct with the mark turned on + mszComment = 0; + // + // I check for the object member to be non-zero because of a clunky design + // choice I made a while back. Each ALEntryList has an ALEntry member that + // points to the first and last members of the list. I could have (and + // probably should have) made the root of the list just be a pair of pointers, + // instead of a dummy ALEntry. Anyway, I can tell that dummy entry apart + // from the valid entries by virtue of the fact that it has a null + // pointer in its object pointer. + // + // So anyway, when I create this dummy object, I don't want to try to add + // it to the list, because by definition it is already in the list. So + // I do a check before adding any ALEntry to the list. + // + if ( object ) + InsertBefore( *list.mpListHead ); } // @@ -253,30 +254,30 @@ AL_PROTO ALEntry::ALEntry( ALEntryList &list, AL_PROTO ALEntry::~ALEntry() { - AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" ); - if ( mszComment ) - delete[] mszComment; - if ( mpStorageObject != 0 ) - delete mpStorageObject; - if ( mpCompressionEngine != 0 ) - delete mpCompressionEngine; - AL_ASSERT( mpNextItem != 0 ,"~ALEntry: next item is null" ); - AL_ASSERT( mpPreviousItem != 0, "~ALEntry: previous item is null" ); + AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" ); + if ( mszComment ) + delete[] mszComment; + if ( mpStorageObject != 0 ) + delete mpStorageObject; + if ( mpCompressionEngine != 0 ) + delete mpCompressionEngine; + AL_ASSERT( mpNextItem != 0 ,"~ALEntry: next item is null" ); + AL_ASSERT( mpPreviousItem != 0, "~ALEntry: previous item is null" ); - ALEntry *next_job = mpNextItem; - ALEntry *previous_job = mpPreviousItem; + ALEntry *next_job = mpNextItem; + ALEntry *previous_job = mpPreviousItem; - if ( next_job != this ) { - next_job->mpPreviousItem = previous_job; - previous_job->mpNextItem = next_job; - } -// -// Note that I check the object twice, one at the start of the dtor, and -// once again at the end. With all the linked list and dynamic deletion -// being done here, it seems like it would be really easy to hose things -// up if any mistakes were made. -// - AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" ); + if ( next_job != this ) { + next_job->mpPreviousItem = previous_job; + previous_job->mpNextItem = next_job; + } + // + // Note that I check the object twice, one at the start of the dtor, and + // once again at the end. With all the linked list and dynamic deletion + // being done here, it seems like it would be really easy to hose things + // up if any mistakes were made. + // + AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" ); } // @@ -306,22 +307,22 @@ AL_PROTO ALEntry::~ALEntry() int AL_PROTO ALEntry::Duplicate( ALEntryList &list ) { - char *name = mpStorageObject->mName; - int case_sensitive = mpStorageObject->mName.mCase == AL_MIXED; - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->GetMark() && job != this ) { - if ( case_sensitive ) { - if ( strcmp( name, job->mpStorageObject->mName ) == 0 ) - return 1; - } else { - if ( stricmp( name, job->mpStorageObject->mName ) == 0 ) - return 1; - } - } - job = job->GetNextEntry(); + char *name = mpStorageObject->mName; + int case_sensitive = mpStorageObject->mName.mCase == AL_MIXED; + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->GetMark() && job != this ) { + if ( case_sensitive ) { + if ( strcmp( name, job->mpStorageObject->mName ) == 0 ) + return 1; + } else { + if ( stricmp( name, job->mpStorageObject->mName ) == 0 ) + return 1; + } } - return 0; + job = job->GetNextEntry(); + } + return 0; } // @@ -352,10 +353,10 @@ int AL_PROTO ALEntry::Duplicate( ALEntryList &list ) void AL_PROTO ALEntry::InsertBefore( ALEntry &job ) { - mpNextItem = &job; - mpPreviousItem = job.mpPreviousItem; - (job.mpPreviousItem)->mpNextItem = this; - job.mpPreviousItem = this; + mpNextItem = &job; + mpPreviousItem = job.mpPreviousItem; + (job.mpPreviousItem)->mpNextItem = this; + job.mpPreviousItem = this; } // @@ -387,20 +388,20 @@ void AL_PROTO ALEntry::InsertBefore( ALEntry &job ) int AL_PROTO ALEntry::SetComment( const char AL_DLL_FAR *comment ) { + if ( mszComment ) + delete[] mszComment; + if ( comment ) { + mszComment = new char[ strlen( comment ) + 1 ]; if ( mszComment ) - delete[] mszComment; - if ( comment ) { - mszComment = new char[ strlen( comment ) + 1 ]; - if ( mszComment ) - strcpy( mszComment, comment ); - else - return mrList.mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, - "Failed to allocate memory when " - "adding comment to storage object %s", - (char *) mpStorageObject->mName ); - } else - mszComment = 0; - return AL_SUCCESS; + strcpy( mszComment, comment ); + else + return mrList.mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, + "Failed to allocate memory when " + "adding comment to storage object %s", + (char *) mpStorageObject->mName ); + } else + mszComment = 0; + return AL_SUCCESS; } // @@ -434,13 +435,13 @@ int AL_PROTO ALEntry::SetComment( const char AL_DLL_FAR *comment ) int AL_PROTO ALEntry::CompressionRatio() { - long uncompressed_size = mpStorageObject->GetSize(); + long uncompressed_size = mpStorageObject->GetSize(); - if ( uncompressed_size <= 0 ) - return -1; - if ( mlCompressedSize <= 0 ) - return -1; - return (int) ( 100 * mlCompressedSize / uncompressed_size ); + if ( uncompressed_size <= 0 ) + return -1; + if ( mlCompressedSize <= 0 ) + return -1; + return (int) ( 100 * mlCompressedSize / uncompressed_size ); } @@ -481,9 +482,9 @@ int AL_PROTO ALEntry::CompressionRatio() ALMonitor ALDefaultMonitor( AL_MONITOR_OBJECTS ); AL_PROTO ALEntryList::ALEntryList( ALMonitor AL_DLL_FAR * monitor /* = 0 */ ) - : mrMonitor( monitor ? *monitor : ALDefaultMonitor ) +: mrMonitor( monitor ? *monitor : ALDefaultMonitor ) { - mpListHead = new ALEntry( *this, 0, 0 ); + mpListHead = new ALEntry( *this, 0, 0 ); } // @@ -512,16 +513,16 @@ AL_PROTO ALEntryList::ALEntryList( ALMonitor AL_DLL_FAR * monitor /* = 0 */ ) AL_PROTO ALEntryList::~ALEntryList() { - AL_ASSERT( GoodTag(), "~ALEntryList: attempting to delete invalid object" ); - ALEntry *job = GetFirstEntry(); - while ( job ) { - ALEntry *next_job = job->GetNextEntry(); - delete job; - job = next_job; - } - if ( mpListHead ) - delete mpListHead; - AL_ASSERT( GoodTag(), "~ALEntryList: attempting to delete invalid object" ); + AL_ASSERT( GoodTag(), "~ALEntryList: attempting to delete invalid object" ); + ALEntry *job = GetFirstEntry(); + while ( job ) { + ALEntry *next_job = job->GetNextEntry(); + delete job; + job = next_job; + } + if ( mpListHead ) + delete mpListHead; + AL_ASSERT( GoodTag(), "~ALEntryList: attempting to delete invalid object" ); } // PROTECTED FUNCTION @@ -555,24 +556,24 @@ AL_PROTO ALEntryList::~ALEntryList() // int AL_PROTO ALEntryList::SetMarkState( const char AL_DLL_FAR *name, - short int new_state ) + short int new_state ) { - int count = 0; + int count = 0; - ALEntry *job = GetFirstEntry(); - while ( job ) { - if ( name ) { - if ( job->mpStorageObject->mName.WildCardMatch( name ) ) { - job->SetMarkState( new_state ); - count++; - } - } else { - job->SetMarkState( new_state ); - count++; - } - job = job->GetNextEntry(); + ALEntry *job = GetFirstEntry(); + while ( job ) { + if ( name ) { + if ( job->mpStorageObject->mName.WildCardMatch( name ) ) { + job->SetMarkState( new_state ); + count++; + } + } else { + job->SetMarkState( new_state ); + count++; } - return count; + job = job->GetNextEntry(); + } + return count; } // @@ -600,14 +601,14 @@ int AL_PROTO ALEntryList::SetMarkState( const char AL_DLL_FAR *name, int AL_PROTO ALEntryList::ToggleMarks() { - int count = 0; - ALEntry *job = GetFirstEntry(); - while ( job ) { - job->SetMarkState( (short int) !job->GetMark() ); - job = job->GetNextEntry(); - count++; - } - return count; + int count = 0; + ALEntry *job = GetFirstEntry(); + while ( job ) { + job->SetMarkState( (short int) !job->GetMark() ); + job = job->GetNextEntry(); + count++; + } + return count; } // @@ -639,15 +640,15 @@ int AL_PROTO ALEntryList::ToggleMarks() ALEntry AL_DLL_FAR * AL_PROTO ALEntry::GetNextEntry() { - ALEntry *next_entry = this->mpNextItem; -// -// The list head has the special case where both the compression engine -// and storage object pointers are 0, and that makes the end of the list. -// - if ( mpNextItem->mpStorageObject == 0 ) - return 0; - else - return next_entry; + ALEntry *next_entry = this->mpNextItem; + // + // The list head has the special case where both the compression engine + // and storage object pointers are 0, and that makes the end of the list. + // + if ( mpNextItem->mpStorageObject == 0 ) + return 0; + else + return next_entry; } // @@ -677,7 +678,7 @@ ALEntry AL_DLL_FAR * AL_PROTO ALEntry::GetNextEntry() ALEntry AL_DLL_FAR * AL_PROTO ALEntryList::GetFirstEntry() { - return mpListHead->GetNextEntry(); + return mpListHead->GetNextEntry(); } // @@ -720,21 +721,21 @@ ALEntry AL_DLL_FAR * AL_PROTO ALEntryList::GetFirstEntry() // void AL_PROTO ALEntryList::UnmarkDuplicates( ALEntryList &list, - const char *error_message /* = 0 */ ) + const char *error_message /* = 0 */ ) { - ALEntry *job = GetFirstEntry(); - while ( job ) { - if ( job->GetMark() ) { - if ( job->Duplicate( list ) ) { - job->ClearMark(); - if ( error_message && error_message[ 0 ] != '\0' ) - job->mpStorageObject->mStatus.SetError( - AL_DUPLICATE_ENTRY, - error_message ); - } - } - job = job->GetNextEntry(); + ALEntry *job = GetFirstEntry(); + while ( job ) { + if ( job->GetMark() ) { + if ( job->Duplicate( list ) ) { + job->ClearMark(); + if ( error_message && error_message[ 0 ] != '\0' ) + job->mpStorageObject->mStatus.SetError( + AL_DUPLICATE_ENTRY, + error_message ); + } } + job = job->GetNextEntry(); + } } // @@ -762,19 +763,19 @@ void AL_PROTO ALEntryList::UnmarkDuplicates( ALEntryList &list, int AL_PROTO ALEntryList::DeleteUnmarked() { - ALEntry *job; - int count = 0; + ALEntry *job; + int count = 0; - job = GetFirstEntry(); - while ( job ) { - ALEntry *next_job = job->GetNextEntry(); - if ( job->GetMark() == 0 ) { - count++; - delete job; - } - job = next_job; + job = GetFirstEntry(); + while ( job ) { + ALEntry *next_job = job->GetNextEntry(); + if ( job->GetMark() == 0 ) { + count++; + delete job; } - return count; + job = next_job; + } + return count; } // @@ -811,31 +812,31 @@ int AL_PROTO ALEntryList::DeleteUnmarked() #if defined( AL_WINDOWS_GUI ) int AL_PROTO ALEntryList::FillListBox( HWND hDlg, int list_box /* = -1 */ ) { - HWND window; + HWND window; - if ( list_box != -1 ) - window = GetDlgItem( hDlg, (short int) list_box ); - else - window = hDlg; - SendMessage( window, LB_RESETCONTENT, 0, 0 ); - ALEntry *job = GetFirstEntry(); - int count = 0; - while ( job ) { - if ( job->GetMark() ) { - count++; - SendMessage( window, - LB_ADDSTRING, - 0, - (LPARAM)( (LPSTR) job->mpStorageObject->mName ) ); - } - job = job->GetNextEntry(); + if ( list_box != -1 ) + window = GetDlgItem( hDlg, (short int) list_box ); + else + window = hDlg; + SendMessage( window, LB_RESETCONTENT, 0, 0 ); + ALEntry *job = GetFirstEntry(); + int count = 0; + while ( job ) { + if ( job->GetMark() ) { + count++; + SendMessage( window, + LB_ADDSTRING, + 0, + (LPARAM)( (LPSTR) job->mpStorageObject->mName ) ); } - if ( count == 0 ) - SendMessage( window, - LB_ADDSTRING, - 0, - (LPARAM)( (LPSTR) "" ) ); - return count; + job = job->GetNextEntry(); + } + if ( count == 0 ) + SendMessage( window, + LB_ADDSTRING, + 0, + (LPARAM)( (LPSTR) "" ) ); + return count; } @@ -871,43 +872,43 @@ int AL_PROTO ALEntryList::FillListBox( HWND hDlg, int list_box /* = -1 */ ) int AL_PROTO ALEntryList::SetMarksFromListBox( HWND hDlg, int list_box /* = -1 */ ) { - HWND window; + HWND window; - if ( list_box != -1 ) - window = GetDlgItem( hDlg, (short int) list_box ); - else - window = hDlg; + if ( list_box != -1 ) + window = GetDlgItem( hDlg, (short int) list_box ); + else + window = hDlg; - WORD count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L ); - int *items = new int[ count ]; - if ( items == 0 ) - return mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, - "Memory allocation failure in SetMarksFromListBox()" ); + WORD count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L ); + int *items = new int[ count ]; + if ( items == 0 ) + return mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, + "Memory allocation failure in SetMarksFromListBox()" ); #ifdef AL_FLAT_MODEL - if ( count != (WORD) SendMessage( window, LB_GETSELITEMS, count, (LPARAM) ( items ) ) ) { + if ( count != (WORD) SendMessage( window, LB_GETSELITEMS, count, (LPARAM) ( items ) ) ) { #else if ( count != (WORD) SendMessage( window, LB_GETSELITEMS, count, (LPARAM) ( (int _far * ) items ) ) ) { #endif - mStatus.SetError( AL_LOGIC_ERROR, - "Logic error in SetMarksFromListBox()." - "Mismatch in select count from list box." ); - delete[] items; - return AL_LOGIC_ERROR; + mStatus.SetError( AL_LOGIC_ERROR, + "Logic error in SetMarksFromListBox()." + "Mismatch in select count from list box." ); + delete[] items; + return AL_LOGIC_ERROR; } for ( WORD i = 0 ; i < count ; i++ ) { - WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L ); - AL_ASSERT( length != (WORD) LB_ERR, "SetMarksFromListBox: LB_ERR returned from list box" ); - if ( length > 0 ) { - char *name = new char[ length + 1 ]; - if ( name ) { - if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 ) - SetMarks( name ); - delete[] name; - } + WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L ); + AL_ASSERT( length != (WORD) LB_ERR, "SetMarksFromListBox: LB_ERR returned from list box" ); + if ( length > 0 ) { + char *name = new char[ length + 1 ]; + if ( name ) { + if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 ) + SetMarks( name ); + delete[] name; } + } } delete[] items; return count; -} + } #endif diff --git a/arch/archive.cpp b/arch/archive.cpp index c72a1caec..cdd1ceb3e 100755 --- a/arch/archive.cpp +++ b/arch/archive.cpp @@ -78,7 +78,7 @@ #if defined( AL_BUILDING_DLL ) void AL_DLL_FAR * AL_PROTO ALArchive::operator new( size_t size ) { - return ::new char[ size ]; + return ::new char[ size ]; } #endif @@ -110,7 +110,7 @@ void AL_DLL_FAR * AL_PROTO ALArchive::operator new( size_t size ) // AL_PROTO ALArchive::ALArchive( const char AL_DLL_FAR *file_name ) - : ALArchiveBase( new ALFile( file_name ), 1 ) +: ALArchiveBase( new ALFile( file_name ), 1 ) { } @@ -143,7 +143,7 @@ AL_PROTO ALArchive::ALArchive( const char AL_DLL_FAR *file_name ) // AL_PROTO ALArchive::ALArchive( ALStorage AL_DLL_FAR &so ) - : ALArchiveBase( &so, 0 ) +: ALArchiveBase( &so, 0 ) { } @@ -173,7 +173,7 @@ AL_PROTO ALArchive::ALArchive( ALStorage AL_DLL_FAR &so ) AL_PROTO ALArchive::~ALArchive() { - AL_ASSERT( GoodTag(), "~ALArchive: attempt to delete invalid object" ); + AL_ASSERT( GoodTag(), "~ALArchive: attempt to delete invalid object" ); } // @@ -206,18 +206,18 @@ AL_PROTO ALArchive::~ALArchive() ALCompressionEngine AL_DLL_FAR * AL_PROTO ALArchive::CreateCompressionEngine( int engine_type ) { - switch ( engine_type ) { - case AL_COMPRESSION_COPY : - return new ALCopyEngine(); - case AL_COMPRESSION_GREENLEAF : - return new ALGreenleafEngine(); - default : - mStatus.SetError( AL_UNKNOWN_COMPRESSION_TYPE, - "Unknown compression type (%d) found in archive", - engine_type ); - break; //Break instead of return because of bogus warnings - } - return 0; + switch ( engine_type ) { + case AL_COMPRESSION_COPY : + return new ALCopyEngine(); + case AL_COMPRESSION_GREENLEAF : + return new ALGreenleafEngine(); + default : + mStatus.SetError( AL_UNKNOWN_COMPRESSION_TYPE, + "Unknown compression type (%d) found in archive", + engine_type ); + break; //Break instead of return because of bogus warnings + } + return 0; } // @@ -251,22 +251,22 @@ AL_PROTO ALArchive::CreateCompressionEngine( int engine_type ) ALStorage AL_DLL_FAR * AL_PROTO ALArchive::CreateStorageObject( const char AL_DLL_FAR *name, - int object_type ) + int object_type ) { - switch ( object_type ) { - case AL_MEMORY_OBJECT : - return new ALMemory( name ); - case AL_FILE_OBJECT : - return new ALFile( name ); - default : - mStatus.SetError( AL_UNKNOWN_STORAGE_OBJECT, - "Unknown storage object type (%d) " - "found in archive", - object_type ); + switch ( object_type ) { + case AL_MEMORY_OBJECT : + return new ALMemory( name ); + case AL_FILE_OBJECT : + return new ALFile( name ); + default : + mStatus.SetError( AL_UNKNOWN_STORAGE_OBJECT, + "Unknown storage object type (%d) " + "found in archive", + object_type ); - break; - } - return 0; + break; + } + return 0; } // STATIC MEMBER FUNCTION @@ -325,22 +325,22 @@ ALArchive::CreateStorageObject( const char AL_DLL_FAR *name, int AL_PROTO ALArchive::AddWildCardFiles( ALEntryList AL_DLL_FAR & list, - const char AL_DLL_FAR *wild_spec /* = "*.*" */, - int traverse_flag /* = 0 */, - short int compression_level /* = AL_GREENLEAF_LEVEL_2 */ ) + const char AL_DLL_FAR *wild_spec /* = "*.*" */, + int traverse_flag /* = 0 */, + short int compression_level /* = AL_GREENLEAF_LEVEL_2 */ ) { - AL_ASSERT( wild_spec != 0, "AddWildCardFiles: null parameter for wild_spec" ); - ALWildCardExpander files( wild_spec, traverse_flag ); - int count = 0; - - char *new_name; - while ( ( new_name = files.GetNextFile() ) != 0 ) { - new ALEntry( list, - new ALFile( new_name ), - new ALGreenleafEngine( compression_level ) ); - count++; - } - return count; + AL_ASSERT( wild_spec != 0, "AddWildCardFiles: null parameter for wild_spec" ); + ALWildCardExpander files( wild_spec, traverse_flag ); + int count = 0; + + char *new_name; ALEntry* dummy; + while ( ( new_name = files.GetNextFile() ) != 0 ) { + dummy = new ALEntry( list, + new ALFile( new_name ), + new ALGreenleafEngine( compression_level ) ); + count++; + } + return count; } // @@ -385,49 +385,49 @@ ALArchive::AddWildCardFiles( ALEntryList AL_DLL_FAR & list, int AL_PROTO ALArchive:: MakeEntriesFromListBox( ALEntryList AL_DLL_FAR &list, - HWND hDlg, - int list_box /* = -1 */ ) + HWND hDlg, + int list_box /* = -1 */ ) { - HWND window; + HWND window; - if ( list_box != -1 ) - window = GetDlgItem( hDlg, (short int) list_box ); - else - window = hDlg; - int count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L ); - if ( count == LB_ERR ) - return AL_GETSEL_ERROR; - int *items = new int[ count ]; - if ( items == 0 ) - return AL_CANT_ALLOCATE_MEMORY; + if ( list_box != -1 ) + window = GetDlgItem( hDlg, (short int) list_box ); + else + window = hDlg; + int count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L ); + if ( count == LB_ERR ) + return AL_GETSEL_ERROR; + int *items = new int[ count ]; + if ( items == 0 ) + return AL_CANT_ALLOCATE_MEMORY; #ifdef AL_FLAT_MODEL - if ( count != SendMessage( window, LB_GETSELITEMS, (short int) count, (LPARAM) items ) ) { + if ( count != SendMessage( window, LB_GETSELITEMS, (short int) count, (LPARAM) items ) ) { #else if ( count != SendMessage( window, LB_GETSELITEMS, (short int) count, (LPARAM)(int _far *) items ) ) { #endif - delete items; - return AL_GETSEL_ERROR; + delete items; + return AL_GETSEL_ERROR; } for ( WORD i = 0 ; i < (WORD) count ; i++ ) { - WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L ); - if ( length > 0 ) { - char *name = new char[ length + 1 ]; - if ( name ) { - if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 ) { - new ALEntry( list, - new ALFile( name ), - new ALGreenleafEngine() ); - } - delete name; - SendMessage( window, - LB_SETSEL, - 0, - items[ i ] ); - } + WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L ); + if ( length > 0 ) { + char *name = new char[ length + 1 ]; + if ( name ) { + if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 ) { + new ALEntry( list, + new ALFile( name ), + new ALGreenleafEngine() ); + } + delete name; + SendMessage( window, + LB_SETSEL, + 0, + items[ i ] ); } + } } delete items; return count; -} + } #endif //#ifdef AL_WINDOWS_GUI diff --git a/arch/archiveb.cpp b/arch/archiveb.cpp index 7057febd8..2863ca9cb 100755 --- a/arch/archiveb.cpp +++ b/arch/archiveb.cpp @@ -90,7 +90,7 @@ #if defined( AL_BUILDING_DLL ) void AL_DLL_FAR * AL_PROTO ALArchiveBase::operator new( size_t size ) { - return ::new char[ size ]; + return ::new char[ size ]; } #endif @@ -129,13 +129,13 @@ void AL_DLL_FAR * AL_PROTO ALArchiveBase::operator new( size_t size ) // AL_PROTO ALArchiveBase::ALArchiveBase( ALStorage AL_DLL_FAR *storage_object, - short int delete_in_dtor ) - : miDeleteStorageObject( delete_in_dtor ) + short int delete_in_dtor ) +: miDeleteStorageObject( delete_in_dtor ) { - mpArchiveStorageObject = storage_object; - mszComment = 0; - mlDirectoryOffset = -1L; - miVersion = -1; + mpArchiveStorageObject = storage_object; + mszComment = 0; + mlDirectoryOffset = -1L; + miVersion = -1; } // @@ -163,12 +163,12 @@ AL_PROTO ALArchiveBase::ALArchiveBase( ALStorage AL_DLL_FAR *storage_object, AL_PROTO ALArchiveBase::~ALArchiveBase() { - AL_ASSERT( GoodTag(), "~Archive(): Attempting to delete invalid ALArchiveBase" ); - if ( mszComment ) - delete[] mszComment; - if ( mpArchiveStorageObject && miDeleteStorageObject ) - delete mpArchiveStorageObject; - AL_ASSERT( GoodTag(), "~Archive::Attempting to delete invalid ALArchiveBase" ); + AL_ASSERT( GoodTag(), "~Archive(): Attempting to delete invalid ALArchiveBase" ); + if ( mszComment ) + delete[] mszComment; + if ( mpArchiveStorageObject && miDeleteStorageObject ) + delete mpArchiveStorageObject; + AL_ASSERT( GoodTag(), "~Archive::Attempting to delete invalid ALArchiveBase" ); } // @@ -197,21 +197,21 @@ AL_PROTO ALArchiveBase::~ALArchiveBase() int AL_PROTO ALArchiveBase::SetComment( char AL_DLL_FAR * comment ) { + if ( mszComment ) + delete[] mszComment; + if ( comment == 0 ) + mszComment = 0; + else { + mszComment = new char[ strlen( comment ) + 1 ]; if ( mszComment ) - delete[] mszComment; - if ( comment == 0 ) - mszComment = 0; - else { - mszComment = new char[ strlen( comment ) + 1 ]; - if ( mszComment ) - strcpy( mszComment, comment ); - else - return mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, - "Failed to allocate memory for " - "comment in archive %s", - mpArchiveStorageObject->mName.GetName() ); - } - return mStatus; + strcpy( mszComment, comment ); + else + return mStatus.SetError( AL_CANT_ALLOCATE_MEMORY, + "Failed to allocate memory for " + "comment in archive %s", + mpArchiveStorageObject->mName.GetName() ); + } + return mStatus; } // @@ -246,15 +246,15 @@ int AL_PROTO ALArchiveBase::SetComment( char AL_DLL_FAR * comment ) // int AL_PROTO ALArchiveBase::WriteDirectory( ALEntryList AL_DLL_FAR &list ) { - ALOpenInputFile archive( *mpArchiveStorageObject ); + ALOpenInputFile archive( *mpArchiveStorageObject ); - mpArchiveStorageObject->Seek( mlDirectoryOffset ); - mpArchiveStorageObject->WritePortableShort( miVersion ); - WriteArchiveData(); - mpArchiveStorageObject->WriteString( mszComment ); + mpArchiveStorageObject->Seek( mlDirectoryOffset ); + mpArchiveStorageObject->WritePortableShort( miVersion ); + WriteArchiveData(); + mpArchiveStorageObject->WriteString( mszComment ); - AddDirectoryEntries( list ); - return mStatus; + AddDirectoryEntries( list ); + return mStatus; } // PRIVATE MEMBER FUNCTION @@ -288,19 +288,19 @@ int AL_PROTO ALArchiveBase::WriteDirectory( ALEntryList AL_DLL_FAR &list ) void AL_PROTO ALArchiveBase::ScanStatus( ALEntryList AL_DLL_FAR &list ) { - if ( mStatus < AL_SUCCESS ) - return; - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->mpStorageObject->mStatus < AL_SUCCESS ) { - mStatus.SetError( job->mpStorageObject->mStatus, - "%s: %s", - job->mpStorageObject->mName.GetSafeName(), - job->mpStorageObject->mStatus.GetStatusDetail() ); - return; - } - job = job->GetNextEntry(); + if ( mStatus < AL_SUCCESS ) + return; + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->mpStorageObject->mStatus < AL_SUCCESS ) { + mStatus.SetError( job->mpStorageObject->mStatus, + "%s: %s", + job->mpStorageObject->mName.GetSafeName(), + job->mpStorageObject->mStatus.GetStatusDetail() ); + return; } + job = job->GetNextEntry(); + } } // @@ -353,66 +353,66 @@ void AL_PROTO ALArchiveBase::ScanStatus( ALEntryList AL_DLL_FAR &list ) int AL_PROTO ALArchiveBase::Extract( ALEntryList AL_DLL_FAR &list ) { -// -// Open the input storage object, if not already open. Let the monitor -// know about it. -// - ALOpenInputFile archive( *mpArchiveStorageObject ); - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); -// -// Get rid of any duplicate entries, and set up the monitor sizes. -// - list.UnmarkDuplicates( list, "Duplicate entry in list passed to Extract()" ); - list.mrMonitor.mlJobSoFar = 0L; - if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) - list.mrMonitor.mlJobSize = CalculateCompressedJobSize( list ); -// -// This loop iterates through the entire ALEntryList. We only care about -// ALEntry objects that have their mark set. -// - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { -// -// Go to the correct input position in this, and set up the monitor for -// this particular object. -// - list.mrMonitor.ArchiveOperation( AL_EXTRACTION_OPEN, this, job ); - mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); - list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; - list.mrMonitor.mlObjectSize = job->mlCompressedSize; - mpArchiveStorageObject->mpMonitor = &list.mrMonitor; -// -// Extract it, then check the CRC. -// - job->mpCompressionEngine->Decompress( *mpArchiveStorageObject, - *job->mpStorageObject, - job->mlCompressedSize ); - if ( job->mpStorageObject->GetCrc32() != job->GetCrc32() ) - job->mpStorageObject->mStatus.SetError( - AL_CRC_ERROR, - "CRC32 was supposed to be %08lx, was %08lx", - job->GetCrc32(), - job->mpStorageObject->GetCrc32() ); -// -// Update the monitor data, and yield some time. Note that I turn off -// the monitor at this point so it doesn't jump around while I seek to the -// next position in the archive. -// - list.mrMonitor.mlJobSoFar += job->mlCompressedSize; - mpArchiveStorageObject->YieldTime(); - mpArchiveStorageObject->mpMonitor = 0; - list.mrMonitor.ArchiveOperation( AL_EXTRACTION_CLOSE, this, job ); - job->mpStorageObject->mpMonitor = 0; - } - job = job->GetNextEntry(); + // + // Open the input storage object, if not already open. Let the monitor + // know about it. + // + ALOpenInputFile archive( *mpArchiveStorageObject ); + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); + // + // Get rid of any duplicate entries, and set up the monitor sizes. + // + list.UnmarkDuplicates( list, "Duplicate entry in list passed to Extract()" ); + list.mrMonitor.mlJobSoFar = 0L; + if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) + list.mrMonitor.mlJobSize = CalculateCompressedJobSize( list ); + // + // This loop iterates through the entire ALEntryList. We only care about + // ALEntry objects that have their mark set. + // + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + // + // Go to the correct input position in this, and set up the monitor for + // this particular object. + // + list.mrMonitor.ArchiveOperation( AL_EXTRACTION_OPEN, this, job ); + mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); + list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; + list.mrMonitor.mlObjectSize = job->mlCompressedSize; + mpArchiveStorageObject->mpMonitor = &list.mrMonitor; + // + // Extract it, then check the CRC. + // + job->mpCompressionEngine->Decompress( *mpArchiveStorageObject, + *job->mpStorageObject, + job->mlCompressedSize ); + if ( job->mpStorageObject->GetCrc32() != job->GetCrc32() ) + job->mpStorageObject->mStatus.SetError( + AL_CRC_ERROR, + "CRC32 was supposed to be %08lx, was %08lx", + job->GetCrc32(), + job->mpStorageObject->GetCrc32() ); + // + // Update the monitor data, and yield some time. Note that I turn off + // the monitor at this point so it doesn't jump around while I seek to the + // next position in the archive. + // + list.mrMonitor.mlJobSoFar += job->mlCompressedSize; + mpArchiveStorageObject->YieldTime(); + mpArchiveStorageObject->mpMonitor = 0; + list.mrMonitor.ArchiveOperation( AL_EXTRACTION_CLOSE, this, job ); + job->mpStorageObject->mpMonitor = 0; } -// -// Update the monitor, then scan the list for status errors. -// - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - ScanStatus( list ); - return mStatus; + job = job->GetNextEntry(); + } + // + // Update the monitor, then scan the list for status errors. + // + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + ScanStatus( list ); + return mStatus; } // PRIVATE MEMBER FUNCTION @@ -452,54 +452,54 @@ int AL_PROTO ALArchiveBase::Extract( ALEntryList AL_DLL_FAR &list ) int AL_PROTO ALArchiveBase::AddJobs( ALEntryList AL_DLL_FAR &list ) { - list.mrMonitor.mlObjectStart = 0L; // This will be true for all input jobs - // - // This loop iterates through all of the entries in the list, picking off - // only the marked entries. - // - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { -// -// We need to keep track of the position in the archive where the compressed -// data is going to go. -// - job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); -// -// Attach the monitor to the storage object that is going to be inserted -// in the archive. -// - list.mrMonitor.ArchiveOperation( AL_INSERTION_OPEN, this, job ); - list.mrMonitor.mlObjectSize = -1L; // This means we ask for it in ALMonitor, after the object is opened - job->mpStorageObject->mpMonitor = &list.mrMonitor; -// -// Compress the object into the archive. Then store the resulting CRC -// the compressed size in the ALEntry object. -// - job->mpCompressionEngine->Compress( *job->mpStorageObject, - *mpArchiveStorageObject ); - job->mlCrc32 = job->mpStorageObject->GetCrc32(); - job->mpStorageObject->mpMonitor = 0; - if ( job->mpCompressionEngine->mStatus < 0 ) - return mStatus = job->mpCompressionEngine->mStatus; - job->mlCompressedSize = mpArchiveStorageObject->Tell() - - job->mlCompressedObjectPosition; -// -// Update the monitor -// - list.mrMonitor.mlJobSoFar += job->mpStorageObject->GetSize(); - list.mrMonitor.ArchiveOperation( AL_INSERTION_CLOSE, this, job ); - } - job = job->GetNextEntry(); - if ( mStatus < 0 ) - break; + list.mrMonitor.mlObjectStart = 0L; // This will be true for all input jobs + // + // This loop iterates through all of the entries in the list, picking off + // only the marked entries. + // + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + // + // We need to keep track of the position in the archive where the compressed + // data is going to go. + // + job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); + // + // Attach the monitor to the storage object that is going to be inserted + // in the archive. + // + list.mrMonitor.ArchiveOperation( AL_INSERTION_OPEN, this, job ); + list.mrMonitor.mlObjectSize = -1L; // This means we ask for it in ALMonitor, after the object is opened + job->mpStorageObject->mpMonitor = &list.mrMonitor; + // + // Compress the object into the archive. Then store the resulting CRC + // the compressed size in the ALEntry object. + // + job->mpCompressionEngine->Compress( *job->mpStorageObject, + *mpArchiveStorageObject ); + job->mlCrc32 = job->mpStorageObject->GetCrc32(); + job->mpStorageObject->mpMonitor = 0; + if ( job->mpCompressionEngine->mStatus < 0 ) + return mStatus = job->mpCompressionEngine->mStatus; + job->mlCompressedSize = mpArchiveStorageObject->Tell() - + job->mlCompressedObjectPosition; + // + // Update the monitor + // + list.mrMonitor.mlJobSoFar += job->mpStorageObject->GetSize(); + list.mrMonitor.ArchiveOperation( AL_INSERTION_CLOSE, this, job ); } - return mStatus; + job = job->GetNextEntry(); + if ( mStatus < 0 ) + break; + } + return mStatus; } // PRIVATE MEMBER FUNCTION // - // int ALArchiveBase::AddDirectoryEntries( ALEntryList &list ) +// int ALArchiveBase::AddDirectoryEntries( ALEntryList &list ) // // ARGUMENTS: // @@ -540,36 +540,36 @@ int AL_PROTO ALArchiveBase::AddJobs( ALEntryList AL_DLL_FAR &list ) // int AL_PROTO ALArchiveBase::AddDirectoryEntries( ALEntryList AL_DLL_FAR &list ) { - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { - mpArchiveStorageObject->WriteString( job->mpStorageObject->mName.GetSafeName() ); - mpArchiveStorageObject->WriteChar( job->mpCompressionEngine->miCompressionType ); - job->mpCompressionEngine->WriteEngineData( mpArchiveStorageObject ); - mpArchiveStorageObject->WriteChar( job->mpStorageObject->miStorageObjectType ); - job->mpStorageObject->WriteStorageObjectData( mpArchiveStorageObject ); + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + mpArchiveStorageObject->WriteString( job->mpStorageObject->mName.GetSafeName() ); + mpArchiveStorageObject->WriteChar( job->mpCompressionEngine->miCompressionType ); + job->mpCompressionEngine->WriteEngineData( mpArchiveStorageObject ); + mpArchiveStorageObject->WriteChar( job->mpStorageObject->miStorageObjectType ); + job->mpStorageObject->WriteStorageObjectData( mpArchiveStorageObject ); - mpArchiveStorageObject->WritePortableLong( job->mpStorageObject->GetSize() ); - mpArchiveStorageObject->WritePortableLong( job->GetCompressedSize() ); - mpArchiveStorageObject->WritePortableLong( job->GetCrc32() ); - mpArchiveStorageObject->WritePortableLong( job->mlCompressedObjectPosition ); - mpArchiveStorageObject->WriteString( job->GetComment() ); - mpArchiveStorageObject->WritePortableLong( job->mpStorageObject->mTimeDate.GetUnixTime() ); - mpArchiveStorageObject->WritePortableShort( job->mpStorageObject->mAttributes.PackedAttributes() ); - if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; - } - job = job->GetNextEntry(); + mpArchiveStorageObject->WritePortableLong( job->mpStorageObject->GetSize() ); + mpArchiveStorageObject->WritePortableLong( job->GetCompressedSize() ); + mpArchiveStorageObject->WritePortableLong( job->GetCrc32() ); + mpArchiveStorageObject->WritePortableLong( job->mlCompressedObjectPosition ); + mpArchiveStorageObject->WriteString( job->GetComment() ); + mpArchiveStorageObject->WritePortableLong( job->mpStorageObject->mTimeDate.GetUnixTime() ); + mpArchiveStorageObject->WritePortableShort( job->mpStorageObject->mAttributes.PackedAttributes() ); + if ( mpArchiveStorageObject->mStatus < 0 ) + return mStatus = mpArchiveStorageObject->mStatus; } -// -// I write out the end of directory string here. But then I back up the -// file pointer so new entries can be appended without causing any trouble -// The end of the directory is denoted by an entry with an empty name. -// - mpArchiveStorageObject->WriteString( "" ); - mpArchiveStorageObject->Seek( mpArchiveStorageObject->Tell() - 2 ); + job = job->GetNextEntry(); + } + // + // I write out the end of directory string here. But then I back up the + // file pointer so new entries can be appended without causing any trouble + // The end of the directory is denoted by an entry with an empty name. + // + mpArchiveStorageObject->WriteString( "" ); + mpArchiveStorageObject->Seek( mpArchiveStorageObject->Tell() - 2 ); - return AL_SUCCESS; + return AL_SUCCESS; } // PRIVATE MEMBER FUNCTION @@ -605,23 +605,23 @@ int AL_PROTO ALArchiveBase::AddDirectoryEntries( ALEntryList AL_DLL_FAR &list ) long AL_PROTO ALArchiveBase::CalculateJobSize( ALEntryList AL_DLL_FAR &list ) { - long total = 0; - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { - long obj_size; - if ( ( obj_size = job->mpStorageObject->GetSize() ) == -1 ) { - job->mpStorageObject->Open(); - obj_size = job->mpStorageObject->GetSize(); - job->mpStorageObject->Close(); - if ( obj_size == -1 ) - return -1; - } - total += obj_size; - } - job = job->GetNextEntry(); + long total = 0; + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + long obj_size; + if ( ( obj_size = job->mpStorageObject->GetSize() ) == -1 ) { + job->mpStorageObject->Open(); + obj_size = job->mpStorageObject->GetSize(); + job->mpStorageObject->Close(); + if ( obj_size == -1 ) + return -1; + } + total += obj_size; } - return total; + job = job->GetNextEntry(); + } + return total; } // PRIVATE MEMBER FUNCTION @@ -654,18 +654,18 @@ long AL_PROTO ALArchiveBase::CalculateJobSize( ALEntryList AL_DLL_FAR &list ) long AL_PROTO ALArchiveBase::CalculateCompressedJobSize( ALEntryList AL_DLL_FAR &list ) { - long total = 0; - ALEntry *job = list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { - if ( job->mlCompressedSize == -1 ) - return -1; - else - total += job->mlCompressedSize; - } - job = job->GetNextEntry(); + long total = 0; + ALEntry *job = list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + if ( job->mlCompressedSize == -1 ) + return -1; + else + total += job->mlCompressedSize; } - return total; + job = job->GetNextEntry(); + } + return total; } // @@ -709,64 +709,64 @@ long AL_PROTO ALArchiveBase::CalculateCompressedJobSize( ALEntryList AL_DLL_FAR int AL_PROTO ALArchiveBase::Create( ALEntryList AL_DLL_FAR &list ) { -// -// Miscellaneous: open the archive, set the archive version, initialize -// the monitor. If the storage object is broken, quite now! -// - ALOpenOutputFile archive( *mpArchiveStorageObject ); - miVersion = 0x100; - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); - if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; -// -// We don't want to create an archive with duplicate entries, so we check here. -// - list.UnmarkDuplicates( list, - "Duplicate entry in list passed to Create()" ); -// -// The first four bytes in the archive are a long that points to the -// first byte of the directory. I don't know where the directory is -// going to be, so I just reserve space at this time with a dummy value. -// - mpArchiveStorageObject->WritePortableLong( 0x12345678L ); -// -// Set up the monitor. -// - list.mrMonitor.mlJobSoFar = 0L; - if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) - list.mrMonitor.mlJobSize = CalculateJobSize( list ); -// -// AddJobs() takes care of actually adding the jobs to the archive. -// - AddJobs( list ); -// -// All the jobs are written, now I can figure out where the -// directory is in the storage object. I copy it, then write -// it out to the storage object at position 0. -// - mlDirectoryOffset = mpArchiveStorageObject->Tell(); - mpArchiveStorageObject->Seek( 0L ); - mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); -// -// Return without writing the directory if there is an error in the -// archive storage object. -// - if ( mpArchiveStorageObject->mStatus < 0 ) { - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus = mpArchiveStorageObject->mStatus; - } -// -// Finally, write out the directory to the storage object. -// - list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); - WriteDirectory( list ); -// -// Update the monitor, check for errors, and blow. -// - list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + // + // Miscellaneous: open the archive, set the archive version, initialize + // the monitor. If the storage object is broken, quite now! + // + ALOpenOutputFile archive( *mpArchiveStorageObject ); + miVersion = 0x100; + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); + if ( mpArchiveStorageObject->mStatus < 0 ) + return mStatus = mpArchiveStorageObject->mStatus; + // + // We don't want to create an archive with duplicate entries, so we check here. + // + list.UnmarkDuplicates( list, + "Duplicate entry in list passed to Create()" ); + // + // The first four bytes in the archive are a long that points to the + // first byte of the directory. I don't know where the directory is + // going to be, so I just reserve space at this time with a dummy value. + // + mpArchiveStorageObject->WritePortableLong( 0x12345678L ); + // + // Set up the monitor. + // + list.mrMonitor.mlJobSoFar = 0L; + if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) + list.mrMonitor.mlJobSize = CalculateJobSize( list ); + // + // AddJobs() takes care of actually adding the jobs to the archive. + // + AddJobs( list ); + // + // All the jobs are written, now I can figure out where the + // directory is in the storage object. I copy it, then write + // it out to the storage object at position 0. + // + mlDirectoryOffset = mpArchiveStorageObject->Tell(); + mpArchiveStorageObject->Seek( 0L ); + mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); + // + // Return without writing the directory if there is an error in the + // archive storage object. + // + if ( mpArchiveStorageObject->mStatus < 0 ) { list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - ScanStatus( list ); - return mStatus; + return mStatus = mpArchiveStorageObject->mStatus; + } + // + // Finally, write out the directory to the storage object. + // + list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); + WriteDirectory( list ); + // + // Update the monitor, check for errors, and blow. + // + list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + ScanStatus( list ); + return mStatus; } // PRIVATE MEMBER FUNCTIONS @@ -813,55 +813,55 @@ int AL_PROTO ALArchiveBase::Create( ALEntryList AL_DLL_FAR &list ) // int AL_PROTO ALArchiveBase::CopyJobs( ALArchiveBase AL_DLL_FAR &source_archive, - ALEntryList AL_DLL_FAR &source_list ) + ALEntryList AL_DLL_FAR &source_list ) { -// -// Open the storage object attached to the input archive. The storage object -// attached to this is already open. -// - ALOpenInputFile input( *(source_archive.mpArchiveStorageObject) ); -// -// Iterate through the list of entries in the list, selecting only the -// marked entries. -// - ALEntry *job = source_list.GetFirstEntry(); - while ( job ) { - if ( job->miMark ) { -// -// Seek the compressed object in the source archive, then update the monitor -// to work properly during the copy operation. -// - source_archive.mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); - source_list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; - source_list.mrMonitor.mlObjectSize = job->mlCompressedSize; - source_list.mrMonitor.ArchiveOperation( AL_COPY_OPEN, this, job ); - source_archive.mpArchiveStorageObject->mpMonitor = &source_list.mrMonitor; -// -// Save the new position in the destination archive, then copy the -// whole thing across. -// - job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); - for ( long i = 0 ; i < job->mlCompressedSize ; i++ ) { - int c = source_archive.mpArchiveStorageObject->ReadChar(); - mpArchiveStorageObject->WriteChar( c ); - } -// -// Update the monitor now that the copy is complete. -// - source_list.mrMonitor.ArchiveOperation( AL_COPY_CLOSE, this, job ); - source_archive.mpArchiveStorageObject->YieldTime(); - source_list.mrMonitor.mlJobSoFar += job->mlCompressedSize; - source_archive.mpArchiveStorageObject->mpMonitor = 0; - if ( source_archive.mpArchiveStorageObject->mStatus < 0 ) - return mStatus = source_archive.mpArchiveStorageObject->mStatus; - if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; - } - job = job->GetNextEntry(); - if ( mStatus < 0 ) - break; + // + // Open the storage object attached to the input archive. The storage object + // attached to this is already open. + // + ALOpenInputFile input( *(source_archive.mpArchiveStorageObject) ); + // + // Iterate through the list of entries in the list, selecting only the + // marked entries. + // + ALEntry *job = source_list.GetFirstEntry(); + while ( job ) { + if ( job->miMark ) { + // + // Seek the compressed object in the source archive, then update the monitor + // to work properly during the copy operation. + // + source_archive.mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); + source_list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; + source_list.mrMonitor.mlObjectSize = job->mlCompressedSize; + source_list.mrMonitor.ArchiveOperation( AL_COPY_OPEN, this, job ); + source_archive.mpArchiveStorageObject->mpMonitor = &source_list.mrMonitor; + // + // Save the new position in the destination archive, then copy the + // whole thing across. + // + job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); + for ( long i = 0 ; i < job->mlCompressedSize ; i++ ) { + int c = source_archive.mpArchiveStorageObject->ReadChar(); + mpArchiveStorageObject->WriteChar( c ); + } + // + // Update the monitor now that the copy is complete. + // + source_list.mrMonitor.ArchiveOperation( AL_COPY_CLOSE, this, job ); + source_archive.mpArchiveStorageObject->YieldTime(); + source_list.mrMonitor.mlJobSoFar += job->mlCompressedSize; + source_archive.mpArchiveStorageObject->mpMonitor = 0; + if ( source_archive.mpArchiveStorageObject->mStatus < 0 ) + return mStatus = source_archive.mpArchiveStorageObject->mStatus; + if ( mpArchiveStorageObject->mStatus < 0 ) + return mStatus = mpArchiveStorageObject->mStatus; } - return mStatus; + job = job->GetNextEntry(); + if ( mStatus < 0 ) + break; + } + return mStatus; } // @@ -895,63 +895,63 @@ int AL_PROTO ALArchiveBase::CopyJobs( ALArchiveBase AL_DLL_FAR &source_archive, // int AL_PROTO ALArchiveBase::Create( ALArchiveBase AL_DLL_FAR &source_archive, - ALEntryList AL_DLL_FAR &source_list ) + ALEntryList AL_DLL_FAR &source_list ) { -// -// Open the source archive, set the version, and blow if for some reason -// the storage object I am writing to isn't working right. -// - ALOpenOutputFile archive( *mpArchiveStorageObject ); - miVersion = 0x100; - if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; -// -// I don't want to create an archive with duplicates, that would be bad. -// - source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Create()" ); -// -// At this point, just for fun, I am going to calculate the total -// compressed size of the jobs I am copying. Hey, it looks like I -// could substitute a call to CalculateCompressedSize() here! -// - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); - source_list.mrMonitor.mlJobSoFar = 0L; - source_list.mrMonitor.mlJobSize = 0L; - for ( ALEntry *job = source_list.GetFirstEntry(); - job != 0; - job = job->GetNextEntry() ) { - if ( job->GetMark() ) - source_list.mrMonitor.mlJobSize += job->mlCompressedSize; - } -// -// Since I am creating a new archive, I write a long out as a place -// holder for the directory pointer. When I am done copying jobs, -// I'll come back here and write a pointer to the directory. -// - mpArchiveStorageObject->WritePortableLong( 0x12345678L ); -// -// Now copy the data. -// - CopyJobs( source_archive, source_list ); -// -// Write out the directory offset, then the directory itself. -// - mlDirectoryOffset = mpArchiveStorageObject->Tell(); - mpArchiveStorageObject->Seek( 0L ); - mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); - if ( mpArchiveStorageObject->mStatus < 0 ) { - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus = mpArchiveStorageObject->mStatus; - } - source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE,this, 0 ); - WriteDirectory( source_list ); - source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + // + // Open the source archive, set the version, and blow if for some reason + // the storage object I am writing to isn't working right. + // + ALOpenOutputFile archive( *mpArchiveStorageObject ); + miVersion = 0x100; + if ( mpArchiveStorageObject->mStatus < 0 ) + return mStatus = mpArchiveStorageObject->mStatus; + // + // I don't want to create an archive with duplicates, that would be bad. + // + source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Create()" ); + // + // At this point, just for fun, I am going to calculate the total + // compressed size of the jobs I am copying. Hey, it looks like I + // could substitute a call to CalculateCompressedSize() here! + // + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); + source_list.mrMonitor.mlJobSoFar = 0L; + source_list.mrMonitor.mlJobSize = 0L; + for ( ALEntry *job = source_list.GetFirstEntry(); + job != 0; + job = job->GetNextEntry() ) { + if ( job->GetMark() ) + source_list.mrMonitor.mlJobSize += job->mlCompressedSize; + } + // + // Since I am creating a new archive, I write a long out as a place + // holder for the directory pointer. When I am done copying jobs, + // I'll come back here and write a pointer to the directory. + // + mpArchiveStorageObject->WritePortableLong( 0x12345678L ); + // + // Now copy the data. + // + CopyJobs( source_archive, source_list ); + // + // Write out the directory offset, then the directory itself. + // + mlDirectoryOffset = mpArchiveStorageObject->Tell(); + mpArchiveStorageObject->Seek( 0L ); + mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); + if ( mpArchiveStorageObject->mStatus < 0 ) { source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); -// -// Update the error status, and then we are done. -// - ScanStatus( source_list ); - return mStatus; + return mStatus = mpArchiveStorageObject->mStatus; + } + source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE,this, 0 ); + WriteDirectory( source_list ); + source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + // + // Update the error status, and then we are done. + // + ScanStatus( source_list ); + return mStatus; } // @@ -983,71 +983,71 @@ int AL_PROTO ALArchiveBase::Create( ALArchiveBase AL_DLL_FAR &source_archive, int AL_PROTO ALArchiveBase::Append( ALEntryList AL_DLL_FAR &list ) { - ALEntryList old_list; -// -// Open the storage object for this. -// - ALOpenInputFile archive( *mpArchiveStorageObject ); -// -// I read in the current directory for this archive. I am going to -// write over the directory with new stuff, so I will have to write it -// back out later. -// - ReadDirectory( old_list ); - if ( mStatus < 0 ) - return mStatus; -// -// The list of new objects I am going to add needs to be scanned for -// duplicates. First I clear duplicate entries from the list itself. -// Then I clear any duplicates between the current list and the -// stuff already in the archive. -// - list.UnmarkDuplicates( list, "Duplicate entry in list passed to Append()" ); - list.UnmarkDuplicates( old_list, "Duplicate entry in list passed to Append()" ); -// -// I get the monitor set up, for the batch of entries I am about to do. -// - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); - list.mrMonitor.mlJobSoFar = 0L; - if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) - list.mrMonitor.mlJobSize = CalculateJobSize( list ); -// -// The new entries start at the position currently occupied by the -// directory. I seek to that point, then call AddJobs() to do the -// dirty work. -// - mpArchiveStorageObject->Seek( mlDirectoryOffset ); - AddJobs( list ); - if ( mStatus < 0 ) { - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus; - } -// -// Now that all the new stuff is in the archive, I can figure -// out where the directory belongs, and write it out to position -// 0 in the archive. -// - mlDirectoryOffset = mpArchiveStorageObject->Tell(); - mpArchiveStorageObject->Seek( 0L ); - mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); - if ( mpArchiveStorageObject->mStatus < 0 ) { - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus = mpArchiveStorageObject->mStatus; - } -// -// Now I write the old directory out, and then add in the new -// directory entries. -// - list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); - WriteDirectory( old_list ); - AddDirectoryEntries( list ); -// -// Update the monitor, check for errors, then leave. -// - list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); - list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - ScanStatus( list ); + ALEntryList old_list; + // + // Open the storage object for this. + // + ALOpenInputFile archive( *mpArchiveStorageObject ); + // + // I read in the current directory for this archive. I am going to + // write over the directory with new stuff, so I will have to write it + // back out later. + // + ReadDirectory( old_list ); + if ( mStatus < 0 ) return mStatus; + // + // The list of new objects I am going to add needs to be scanned for + // duplicates. First I clear duplicate entries from the list itself. + // Then I clear any duplicates between the current list and the + // stuff already in the archive. + // + list.UnmarkDuplicates( list, "Duplicate entry in list passed to Append()" ); + list.UnmarkDuplicates( old_list, "Duplicate entry in list passed to Append()" ); + // + // I get the monitor set up, for the batch of entries I am about to do. + // + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); + list.mrMonitor.mlJobSoFar = 0L; + if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) + list.mrMonitor.mlJobSize = CalculateJobSize( list ); + // + // The new entries start at the position currently occupied by the + // directory. I seek to that point, then call AddJobs() to do the + // dirty work. + // + mpArchiveStorageObject->Seek( mlDirectoryOffset ); + AddJobs( list ); + if ( mStatus < 0 ) { + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + return mStatus; + } + // + // Now that all the new stuff is in the archive, I can figure + // out where the directory belongs, and write it out to position + // 0 in the archive. + // + mlDirectoryOffset = mpArchiveStorageObject->Tell(); + mpArchiveStorageObject->Seek( 0L ); + mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); + if ( mpArchiveStorageObject->mStatus < 0 ) { + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + return mStatus = mpArchiveStorageObject->mStatus; + } + // + // Now I write the old directory out, and then add in the new + // directory entries. + // + list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); + WriteDirectory( old_list ); + AddDirectoryEntries( list ); + // + // Update the monitor, check for errors, then leave. + // + list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + ScanStatus( list ); + return mStatus; } // @@ -1080,82 +1080,82 @@ int AL_PROTO ALArchiveBase::Append( ALEntryList AL_DLL_FAR &list ) // int AL_PROTO ALArchiveBase::Append( ALArchiveBase AL_DLL_FAR &source_archive, - ALEntryList AL_DLL_FAR &source_list ) + ALEntryList AL_DLL_FAR &source_list ) { - ALEntryList old_list; -// -// Open the storage object associated with this. -// - ALOpenInputFile archive( *mpArchiveStorageObject ); + ALEntryList old_list; + // + // Open the storage object associated with this. + // + ALOpenInputFile archive( *mpArchiveStorageObject ); - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); -// -// I have to read the current directory into memory, because as soon as -// I start to write objects out to this, I am going to obliterate -// the directory. -// - ReadDirectory( old_list ); - if ( mStatus < 0 ) { - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus; - } -// -// We don't want to create an archive that has duplicate entries, that would -// be a bad thing. So I first comb all the duplicate entries out of the list -// of objects to append. I then compare that list for duplicates against -// the list of objects already in the library, and comb out any matches -// there as well. -// - source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Append()" ); - source_list.UnmarkDuplicates( old_list, "Duplicate entry in list passed to Append()" ); -// -// I am going to start writing new stuff at the location where the -// the directory starts right now. -// - mpArchiveStorageObject->Seek( mlDirectoryOffset ); -// -// Before starting to copy jobs, I have to set up the monitor. -// This includes calculating the total number of compressed bytes -// in all the marked jobs. I could do this a lot easier by calling -// the CalculateCompressedBytes() function, but it's too late to change now. -// - source_list.mrMonitor.mlJobSoFar = 0L; - source_list.mrMonitor.mlJobSize = 0L; - for ( ALEntry *job = source_list.GetFirstEntry(); - job != 0; - job = job->GetNextEntry() ) { - if ( job->GetMark() ) - source_list.mrMonitor.mlJobSize += job->mlCompressedSize; - } -// -// CopyJobs() does the hard work for me. -// - CopyJobs( source_archive, source_list ); - if ( mStatus < 0 ) { - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus; - } -// -// The jobs are now in, I just have to update the directory with -// the old files and the new files. -// - mlDirectoryOffset = mpArchiveStorageObject->Tell(); - mpArchiveStorageObject->Seek( 0L ); - mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); - if ( mpArchiveStorageObject->mStatus < 0 ) { - source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - return mStatus = mpArchiveStorageObject->mStatus; - } - source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); - WriteDirectory( old_list ); - AddDirectoryEntries( source_list ); -// -// Wrap it up. -// - source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); + // + // I have to read the current directory into memory, because as soon as + // I start to write objects out to this, I am going to obliterate + // the directory. + // + ReadDirectory( old_list ); + if ( mStatus < 0 ) { source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); - ScanStatus( source_list ); return mStatus; + } + // + // We don't want to create an archive that has duplicate entries, that would + // be a bad thing. So I first comb all the duplicate entries out of the list + // of objects to append. I then compare that list for duplicates against + // the list of objects already in the library, and comb out any matches + // there as well. + // + source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Append()" ); + source_list.UnmarkDuplicates( old_list, "Duplicate entry in list passed to Append()" ); + // + // I am going to start writing new stuff at the location where the + // the directory starts right now. + // + mpArchiveStorageObject->Seek( mlDirectoryOffset ); + // + // Before starting to copy jobs, I have to set up the monitor. + // This includes calculating the total number of compressed bytes + // in all the marked jobs. I could do this a lot easier by calling + // the CalculateCompressedBytes() function, but it's too late to change now. + // + source_list.mrMonitor.mlJobSoFar = 0L; + source_list.mrMonitor.mlJobSize = 0L; + for ( ALEntry *job = source_list.GetFirstEntry(); + job != 0; + job = job->GetNextEntry() ) { + if ( job->GetMark() ) + source_list.mrMonitor.mlJobSize += job->mlCompressedSize; + } + // + // CopyJobs() does the hard work for me. + // + CopyJobs( source_archive, source_list ); + if ( mStatus < 0 ) { + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + return mStatus; + } + // + // The jobs are now in, I just have to update the directory with + // the old files and the new files. + // + mlDirectoryOffset = mpArchiveStorageObject->Tell(); + mpArchiveStorageObject->Seek( 0L ); + mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); + if ( mpArchiveStorageObject->mStatus < 0 ) { + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + return mStatus = mpArchiveStorageObject->mStatus; + } + source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); + WriteDirectory( old_list ); + AddDirectoryEntries( source_list ); + // + // Wrap it up. + // + source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); + source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); + ScanStatus( source_list ); + return mStatus; } // @@ -1184,111 +1184,111 @@ int AL_PROTO ALArchiveBase::Append( ALArchiveBase AL_DLL_FAR &source_archive, int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list ) { - list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_READ, this, 0 ); - ALOpenInputFile archive( *mpArchiveStorageObject ); + list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_READ, this, 0 ); + ALOpenInputFile archive( *mpArchiveStorageObject ); + if ( mpArchiveStorageObject->mStatus < 0 ) + return mStatus = mpArchiveStorageObject->mStatus; + // + // First I seek to the start of the directory (offset found at 0), and + // read in the version. This function only supports the directory + // structure defined in version 0x100. + // + mpArchiveStorageObject->Seek( 0 ); + mpArchiveStorageObject->ReadPortableLong( mlDirectoryOffset ); + mpArchiveStorageObject->Seek( mlDirectoryOffset ); + mpArchiveStorageObject->ReadPortableShort( miVersion ); + if ( miVersion != 0x100 ) + return mStatus.SetError( AL_INVALID_ARCHIVE, + "%s is not a valid archive file", + mpArchiveStorageObject->mName.GetSafeName() ); + // + // Read in any customized archive data defined by a derived class. + // + ReadArchiveData(); + // + // Read in the comment, deleting the old one if necessary. + // + if ( mszComment ) + delete[] mszComment; + mszComment = mpArchiveStorageObject->ReadString(); + // + // Now, the big loop. I have to read in each entry, one at a time, and + // add it to the list. If I broke this out into a separate routine it + // would make the whole thing a lot more manageable. + // + for ( ; ; ) { if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; -// -// First I seek to the start of the directory (offset found at 0), and -// read in the version. This function only supports the directory -// structure defined in version 0x100. -// - mpArchiveStorageObject->Seek( 0 ); - mpArchiveStorageObject->ReadPortableLong( mlDirectoryOffset ); - mpArchiveStorageObject->Seek( mlDirectoryOffset ); - mpArchiveStorageObject->ReadPortableShort( miVersion ); - if ( miVersion != 0x100 ) - return mStatus.SetError( AL_INVALID_ARCHIVE, - "%s is not a valid archive file", - mpArchiveStorageObject->mName.GetSafeName() ); -// -// Read in any customized archive data defined by a derived class. -// - ReadArchiveData(); -// -// Read in the comment, deleting the old one if necessary. -// - if ( mszComment ) - delete[] mszComment; - mszComment = mpArchiveStorageObject->ReadString(); -// -// Now, the big loop. I have to read in each entry, one at a time, and -// add it to the list. If I broke this out into a separate routine it -// would make the whole thing a lot more manageable. -// - for ( ; ; ) { - if ( mpArchiveStorageObject->mStatus < 0 ) - return mStatus = mpArchiveStorageObject->mStatus; - char *name = mpArchiveStorageObject->ReadString(); - if ( name == 0 ) - break; -// -// The directory ends with a blank name. -// - if ( strlen( name ) == 0 ) { - delete[] name; - break; - } -// -// Derived classes are responsible for providing a version of -// CreateCompressionEngine() that will convert the engine_type -// integer into a created compression engine. The derived class is -// then also responsible for reading in the engine data from the archive. -// - int engine_type = mpArchiveStorageObject->ReadChar(); - ALCompressionEngine *engine = CreateCompressionEngine( engine_type ); - if ( engine ) - engine->ReadEngineData( mpArchiveStorageObject ); - else { - char *temp = mpArchiveStorageObject->ReadString(); - if ( temp ) - delete[] temp; - return mStatus.SetError( AL_CANT_CREATE_ENGINE, - "Failure creating compression engine for object %s", - name ); - } -// -// Now we go through a nearly identical process to create the storage object. -// The derived class is responsible for writing a CreateStorageObject() -// function that converts an object_type integer to a created storage -// object. The derived class also has to read in the storage object -// data. -// - int object_type = mpArchiveStorageObject->ReadChar(); - ALStorage *storage_object = CreateStorageObject( name, object_type ); - delete[] name; // Don't need it any more - name = 0; - if ( storage_object ) - storage_object->ReadStorageObjectData( mpArchiveStorageObject ); - else { - char *temp = mpArchiveStorageObject->ReadString(); - if ( temp ) - delete[] temp; - return mStatus.SetError( AL_CANT_CREATE_STORAGE_OBJECT, - "Failure creating storage object for object %s", - name ); - } -// -// The rest of the stuff in the entry is pretty straightforward. -// - mpArchiveStorageObject->ReadPortableLong( storage_object->mlSize ); - ALEntry *job = new ALEntry( list, storage_object, engine ); - mpArchiveStorageObject->ReadPortableLong( job->mlCompressedSize ); - mpArchiveStorageObject->ReadPortableLong( job->mlCrc32 ); - mpArchiveStorageObject->ReadPortableLong( job->mlCompressedObjectPosition ); - char *comment = mpArchiveStorageObject->ReadString(); - job->SetComment( comment ); - if ( comment ) - delete[] comment; - long unix_time; - mpArchiveStorageObject->ReadPortableLong( unix_time ); - storage_object->mTimeDate.SetTimeDate( unix_time ); - short int packed_attributes; - mpArchiveStorageObject->ReadPortableShort( packed_attributes ); - storage_object->mAttributes.SetFromPackedAttributes( packed_attributes ); + return mStatus = mpArchiveStorageObject->mStatus; + char *name = mpArchiveStorageObject->ReadString(); + if ( name == 0 ) + break; + // + // The directory ends with a blank name. + // + if ( strlen( name ) == 0 ) { + delete[] name; + break; } - list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_READ, this, 0 ); - return mStatus; + // + // Derived classes are responsible for providing a version of + // CreateCompressionEngine() that will convert the engine_type + // integer into a created compression engine. The derived class is + // then also responsible for reading in the engine data from the archive. + // + int engine_type = mpArchiveStorageObject->ReadChar(); + ALCompressionEngine *engine = CreateCompressionEngine( engine_type ); + if ( engine ) + engine->ReadEngineData( mpArchiveStorageObject ); + else { + char *temp = mpArchiveStorageObject->ReadString(); + if ( temp ) + delete[] temp; + return mStatus.SetError( AL_CANT_CREATE_ENGINE, + "Failure creating compression engine for object %s", + name ); + } + // + // Now we go through a nearly identical process to create the storage object. + // The derived class is responsible for writing a CreateStorageObject() + // function that converts an object_type integer to a created storage + // object. The derived class also has to read in the storage object + // data. + // + int object_type = mpArchiveStorageObject->ReadChar(); + ALStorage *storage_object = CreateStorageObject( name, object_type ); + delete[] name; // Don't need it any more + name = 0; + if ( storage_object ) + storage_object->ReadStorageObjectData( mpArchiveStorageObject ); + else { + char *temp = mpArchiveStorageObject->ReadString(); + if ( temp ) + delete[] temp; + return mStatus.SetError( AL_CANT_CREATE_STORAGE_OBJECT, + "Failure creating storage object for object %s", + name ); + } + // + // The rest of the stuff in the entry is pretty straightforward. + // + mpArchiveStorageObject->ReadPortableLong( storage_object->mlSize ); + ALEntry *job = new ALEntry( list, storage_object, engine ); + mpArchiveStorageObject->ReadPortableLong( job->mlCompressedSize ); + mpArchiveStorageObject->ReadPortableLong( job->mlCrc32 ); + mpArchiveStorageObject->ReadPortableLong( job->mlCompressedObjectPosition ); + char *comment = mpArchiveStorageObject->ReadString(); + job->SetComment( comment ); + if ( comment ) + delete[] comment; + long unix_time; + mpArchiveStorageObject->ReadPortableLong( unix_time ); + storage_object->mTimeDate.SetTimeDate( unix_time ); + short int packed_attributes; + mpArchiveStorageObject->ReadPortableShort( packed_attributes ); + storage_object->mAttributes.SetFromPackedAttributes( packed_attributes ); + } + list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_READ, this, 0 ); + return mStatus; } // @@ -1317,7 +1317,7 @@ int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list ) int AL_PROTO ALArchiveBase::WriteArchiveData() { - return mpArchiveStorageObject->WritePortableShort( 0 ); + return mpArchiveStorageObject->WritePortableShort( 0 ); } // @@ -1348,10 +1348,10 @@ int AL_PROTO ALArchiveBase::WriteArchiveData() int AL_PROTO ALArchiveBase::ReadArchiveData() { - short temp; - mpArchiveStorageObject->ReadPortableShort( temp ); - AL_ASSERT( temp == 0, "ReadArchiveData(): archive data != 0" ); - return mpArchiveStorageObject->mStatus; + short temp; + mpArchiveStorageObject->ReadPortableShort( temp ); + AL_ASSERT( temp == 0, "ReadArchiveData(): archive data != 0" ); + return mpArchiveStorageObject->mStatus; } // @@ -1388,18 +1388,18 @@ int AL_PROTO ALArchiveBase::ReadArchiveData() // int AL_PROTO ALArchiveBase::Delete( ALEntryList AL_DLL_FAR &list, - ALArchiveBase AL_DLL_FAR &destination ) + ALArchiveBase AL_DLL_FAR &destination ) { - destination.SetComment( mszComment ); - list.ToggleMarks(); - destination.Create( *this, list ); - list.ToggleMarks(); - ALName temp = mpArchiveStorageObject->mName; - mpArchiveStorageObject->RenameToBackup(); - destination.mpArchiveStorageObject->Rename( temp ); - if ( destination.mStatus < 0 ) - return mStatus = destination.mStatus; - return mStatus; + destination.SetComment( mszComment ); + list.ToggleMarks(); + destination.Create( *this, list ); + list.ToggleMarks(); + ALName temp = mpArchiveStorageObject->mName; + mpArchiveStorageObject->RenameToBackup(); + destination.mpArchiveStorageObject->Rename( (const char*)temp ); + if ( destination.mStatus < 0 ) + return mStatus = destination.mStatus; + return mStatus; } // @@ -1434,23 +1434,23 @@ int AL_PROTO ALArchiveBase::Delete( ALEntryList AL_DLL_FAR &list, #if defined( AL_WINDOWS_GUI ) int AL_PROTO ALArchiveBase::FillListBox( HWND hDlg, int list_box /* = -1 */ ) { - ALEntryList list; - HWND window; - ReadDirectory( list ); - if ( list_box != -1 ) - window = GetDlgItem( hDlg, (short int) list_box ); - else - window = hDlg; - int count; - if ( ( count = list.FillListBox( window ) ) == 0 ) { - if ( mStatus < 0 ) { - SendMessage( window, LB_RESETCONTENT, 0, 0 ); - SendMessage( window, - LB_ADDSTRING, - 0, - (LPARAM)( (LPSTR) "Error!" ) ); - } + ALEntryList list; + HWND window; + ReadDirectory( list ); + if ( list_box != -1 ) + window = GetDlgItem( hDlg, (short int) list_box ); + else + window = hDlg; + int count; + if ( ( count = list.FillListBox( window ) ) == 0 ) { + if ( mStatus < 0 ) { + SendMessage( window, LB_RESETCONTENT, 0, 0 ); + SendMessage( window, + LB_ADDSTRING, + 0, + (LPARAM)( (LPSTR) "Error!" ) ); } - return count; + } + return count; } #endif diff --git a/arch/fileattr.cpp b/arch/fileattr.cpp index a2e277f9c..b3a2c7196 100755 --- a/arch/fileattr.cpp +++ b/arch/fileattr.cpp @@ -34,7 +34,9 @@ #include "arclib.h" #pragma hdrstop +#if XVT_OS != XVT_OS_SCOUNIX #include +#endif #include "fileattr.h" @@ -72,7 +74,7 @@ #if defined( AL_BUILDING_DLL ) void AL_DLL_FAR * AL_PROTO ALFileAttributes::operator new( size_t size ) { - return ::new char[ size ]; + return ::new char[ size ]; } #endif @@ -103,10 +105,10 @@ void AL_DLL_FAR * AL_PROTO ALFileAttributes::operator new( size_t size ) AL_PROTO ALFileAttributes::ALFileAttributes() { - miReadOnly = 0; - miSystem = 0; - miHidden = 0; - miArchive = 0; + miReadOnly = 0; + miSystem = 0; + miHidden = 0; + miArchive = 0; } // @@ -164,10 +166,10 @@ AL_PROTO ALFileAttributes::~ALFileAttributes() void AL_PROTO ALFileAttributes:: SetFromPackedAttributes( short int attributes ) { - miReadOnly = ( attributes & 1 ) != 0; - miSystem = ( attributes & 2 ) != 0; - miHidden = ( attributes & 4 ) != 0; - miArchive = ( attributes & 8 ) != 0; + miReadOnly = ( attributes & 1 ) != 0; + miSystem = ( attributes & 2 ) != 0; + miHidden = ( attributes & 4 ) != 0; + miArchive = ( attributes & 8 ) != 0; } // @@ -203,10 +205,10 @@ SetFromPackedAttributes( short int attributes ) void AL_PROTO ALFileAttributes:: SetFromWin32Attributes( DWORD win32_attributes ) { - miReadOnly = ( win32_attributes & FILE_ATTRIBUTE_READONLY ) != 0; - miSystem = ( win32_attributes & FILE_ATTRIBUTE_SYSTEM ) != 0; - miHidden = ( win32_attributes & FILE_ATTRIBUTE_HIDDEN ) != 0; - miArchive = ( win32_attributes & FILE_ATTRIBUTE_ARCHIVE ) != 0; + miReadOnly = ( win32_attributes & FILE_ATTRIBUTE_READONLY ) != 0; + miSystem = ( win32_attributes & FILE_ATTRIBUTE_SYSTEM ) != 0; + miHidden = ( win32_attributes & FILE_ATTRIBUTE_HIDDEN ) != 0; + miArchive = ( win32_attributes & FILE_ATTRIBUTE_ARCHIVE ) != 0; } #endif @@ -243,10 +245,10 @@ SetFromWin32Attributes( DWORD win32_attributes ) void AL_PROTO ALFileAttributes::SetFromDosAttributes( unsigned dos_attributes ) { - miReadOnly = ( dos_attributes & _A_RDONLY ) != 0; - miSystem = ( dos_attributes & _A_SYSTEM ) != 0; - miHidden = ( dos_attributes & _A_HIDDEN ) != 0; - miArchive = ( dos_attributes & _A_ARCH ) != 0; + miReadOnly = ( dos_attributes & _A_RDONLY ) != 0; + miSystem = ( dos_attributes & _A_SYSTEM ) != 0; + miHidden = ( dos_attributes & _A_HIDDEN ) != 0; + miArchive = ( dos_attributes & _A_ARCH ) != 0; } #endif @@ -279,13 +281,13 @@ void AL_PROTO ALFileAttributes::SetFromDosAttributes( unsigned dos_attributes ) unsigned short int AL_PROTO ALFileAttributes::PackedAttributes() { - int result = 0; + int result = 0; - result |= miReadOnly ? 1 : 0; - result |= miSystem ? 2 : 0; - result |= miHidden ? 4 : 0; - result |= miArchive ? 8 : 0; - return (unsigned short int ) result; + result |= miReadOnly ? 1 : 0; + result |= miSystem ? 2 : 0; + result |= miHidden ? 4 : 0; + result |= miArchive ? 8 : 0; + return (unsigned short int ) result; } // @@ -316,12 +318,12 @@ unsigned short int AL_PROTO ALFileAttributes::PackedAttributes() unsigned short int AL_PROTO ALFileAttributes::GetDosAttributes() { - int result = 0; - result |= miReadOnly ? _A_RDONLY : 0; - result |= miSystem ? _A_SYSTEM : 0; - result |= miHidden ? _A_HIDDEN : 0; - result |= miArchive ? _A_ARCH : 0; - return (unsigned short int) result; + int result = 0; + result |= miReadOnly ? _A_RDONLY : 0; + result |= miSystem ? _A_SYSTEM : 0; + result |= miHidden ? _A_HIDDEN : 0; + result |= miArchive ? _A_ARCH : 0; + return (unsigned short int) result; } #endif //#if !defined( AL_WIN32S ) @@ -353,11 +355,11 @@ unsigned short int AL_PROTO ALFileAttributes::GetDosAttributes() DWORD AL_PROTO ALFileAttributes::GetWin32Attributes() { - DWORD result = 0; - result |= miReadOnly ? FILE_ATTRIBUTE_READONLY : 0; - result |= miSystem ? FILE_ATTRIBUTE_SYSTEM : 0; - result |= miHidden ? FILE_ATTRIBUTE_HIDDEN : 0; - result |= miArchive ? FILE_ATTRIBUTE_ARCHIVE : 0; - return result; + DWORD result = 0; + result |= miReadOnly ? FILE_ATTRIBUTE_READONLY : 0; + result |= miSystem ? FILE_ATTRIBUTE_SYSTEM : 0; + result |= miHidden ? FILE_ATTRIBUTE_HIDDEN : 0; + result |= miArchive ? FILE_ATTRIBUTE_ARCHIVE : 0; + return result; } #endif //#if !defined( AL_WIN32S )