Prime modifiche per compatibilita' UNIX

git-svn-id: svn://10.65.10.50/trunk@33 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1994-08-18 10:40:18 +00:00
parent 80624b0d87
commit ea150a8931
4 changed files with 955 additions and 952 deletions

View File

@ -59,6 +59,7 @@
// //
#include "arclib.h" #include "arclib.h"
#include <utility.h>
#pragma hdrstop #pragma hdrstop
// //
@ -193,7 +194,7 @@ void AL_DLL_FAR * AL_PROTO ALEntryList::operator new( size_t size )
AL_PROTO ALEntry::ALEntry( ALEntryList &list, AL_PROTO ALEntry::ALEntry( ALEntryList &list,
ALStorage *object, ALStorage *object,
ALCompressionEngine *engine ) ALCompressionEngine *engine )
: mrList( list ) // Initialize our own pointer to the list we will : mrList( list ) // Initialize our own pointer to the list we will
// be a member of. // be a member of.
{ {
mpNextItem = this; mpNextItem = this;
@ -204,19 +205,19 @@ AL_PROTO ALEntry::ALEntry( ALEntryList &list,
mlCompressedObjectPosition = -1; mlCompressedObjectPosition = -1;
miMark = 1; //Always construct with the mark turned on miMark = 1; //Always construct with the mark turned on
mszComment = 0; mszComment = 0;
// //
// I check for the object member to be non-zero because of a clunky design // 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 // 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 // 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, // 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 // 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 // from the valid entries by virtue of the fact that it has a null
// pointer in its object pointer. // pointer in its object pointer.
// //
// So anyway, when I create this dummy object, I don't want to try to add // 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 // 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. // I do a check before adding any ALEntry to the list.
// //
if ( object ) if ( object )
InsertBefore( *list.mpListHead ); InsertBefore( *list.mpListHead );
} }
@ -270,12 +271,12 @@ AL_PROTO ALEntry::~ALEntry()
next_job->mpPreviousItem = previous_job; next_job->mpPreviousItem = previous_job;
previous_job->mpNextItem = next_job; previous_job->mpNextItem = next_job;
} }
// //
// Note that I check the object twice, one at the start of the dtor, and // 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 // 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 // being done here, it seems like it would be really easy to hose things
// up if any mistakes were made. // up if any mistakes were made.
// //
AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" ); AL_ASSERT( GoodTag(), "~ALEntry: Attempting to delete invalid object" );
} }
@ -481,7 +482,7 @@ int AL_PROTO ALEntry::CompressionRatio()
ALMonitor ALDefaultMonitor( AL_MONITOR_OBJECTS ); ALMonitor ALDefaultMonitor( AL_MONITOR_OBJECTS );
AL_PROTO ALEntryList::ALEntryList( ALMonitor AL_DLL_FAR * monitor /* = 0 */ ) 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 );
} }
@ -640,10 +641,10 @@ int AL_PROTO ALEntryList::ToggleMarks()
ALEntry AL_DLL_FAR * AL_PROTO ALEntry::GetNextEntry() ALEntry AL_DLL_FAR * AL_PROTO ALEntry::GetNextEntry()
{ {
ALEntry *next_entry = this->mpNextItem; ALEntry *next_entry = this->mpNextItem;
// //
// The list head has the special case where both the compression engine // 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. // and storage object pointers are 0, and that makes the end of the list.
// //
if ( mpNextItem->mpStorageObject == 0 ) if ( mpNextItem->mpStorageObject == 0 )
return 0; return 0;
else else
@ -908,6 +909,6 @@ int AL_PROTO ALEntryList::SetMarksFromListBox( HWND hDlg, int list_box /* = -1 *
} }
delete[] items; delete[] items;
return count; return count;
} }
#endif #endif

View File

@ -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 ) 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 ) AL_PROTO ALArchive::ALArchive( ALStorage AL_DLL_FAR &so )
: ALArchiveBase( &so, 0 ) : ALArchiveBase( &so, 0 )
{ {
} }
@ -333,9 +333,9 @@ ALArchive::AddWildCardFiles( ALEntryList AL_DLL_FAR & list,
ALWildCardExpander files( wild_spec, traverse_flag ); ALWildCardExpander files( wild_spec, traverse_flag );
int count = 0; int count = 0;
char *new_name; char *new_name; ALEntry* dummy;
while ( ( new_name = files.GetNextFile() ) != 0 ) { while ( ( new_name = files.GetNextFile() ) != 0 ) {
new ALEntry( list, dummy = new ALEntry( list,
new ALFile( new_name ), new ALFile( new_name ),
new ALGreenleafEngine( compression_level ) ); new ALGreenleafEngine( compression_level ) );
count++; count++;
@ -428,6 +428,6 @@ MakeEntriesFromListBox( ALEntryList AL_DLL_FAR &list,
} }
delete items; delete items;
return count; return count;
} }
#endif //#ifdef AL_WINDOWS_GUI #endif //#ifdef AL_WINDOWS_GUI

View File

@ -130,7 +130,7 @@ void AL_DLL_FAR * AL_PROTO ALArchiveBase::operator new( size_t size )
AL_PROTO ALArchiveBase::ALArchiveBase( ALStorage AL_DLL_FAR *storage_object, AL_PROTO ALArchiveBase::ALArchiveBase( ALStorage AL_DLL_FAR *storage_object,
short int delete_in_dtor ) short int delete_in_dtor )
: miDeleteStorageObject( delete_in_dtor ) : miDeleteStorageObject( delete_in_dtor )
{ {
mpArchiveStorageObject = storage_object; mpArchiveStorageObject = storage_object;
mszComment = 0; mszComment = 0;
@ -353,38 +353,38 @@ void AL_PROTO ALArchiveBase::ScanStatus( ALEntryList AL_DLL_FAR &list )
int AL_PROTO ALArchiveBase::Extract( 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 // Open the input storage object, if not already open. Let the monitor
// know about it. // know about it.
// //
ALOpenInputFile archive( *mpArchiveStorageObject ); ALOpenInputFile archive( *mpArchiveStorageObject );
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 );
// //
// Get rid of any duplicate entries, and set up the monitor sizes. // Get rid of any duplicate entries, and set up the monitor sizes.
// //
list.UnmarkDuplicates( list, "Duplicate entry in list passed to Extract()" ); list.UnmarkDuplicates( list, "Duplicate entry in list passed to Extract()" );
list.mrMonitor.mlJobSoFar = 0L; list.mrMonitor.mlJobSoFar = 0L;
if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB )
list.mrMonitor.mlJobSize = CalculateCompressedJobSize( list ); list.mrMonitor.mlJobSize = CalculateCompressedJobSize( list );
// //
// This loop iterates through the entire ALEntryList. We only care about // This loop iterates through the entire ALEntryList. We only care about
// ALEntry objects that have their mark set. // ALEntry objects that have their mark set.
// //
ALEntry *job = list.GetFirstEntry(); ALEntry *job = list.GetFirstEntry();
while ( job ) { while ( job ) {
if ( job->miMark ) { if ( job->miMark ) {
// //
// Go to the correct input position in this, and set up the monitor for // Go to the correct input position in this, and set up the monitor for
// this particular object. // this particular object.
// //
list.mrMonitor.ArchiveOperation( AL_EXTRACTION_OPEN, this, job ); list.mrMonitor.ArchiveOperation( AL_EXTRACTION_OPEN, this, job );
mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition );
list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition;
list.mrMonitor.mlObjectSize = job->mlCompressedSize; list.mrMonitor.mlObjectSize = job->mlCompressedSize;
mpArchiveStorageObject->mpMonitor = &list.mrMonitor; mpArchiveStorageObject->mpMonitor = &list.mrMonitor;
// //
// Extract it, then check the CRC. // Extract it, then check the CRC.
// //
job->mpCompressionEngine->Decompress( *mpArchiveStorageObject, job->mpCompressionEngine->Decompress( *mpArchiveStorageObject,
*job->mpStorageObject, *job->mpStorageObject,
job->mlCompressedSize ); job->mlCompressedSize );
@ -394,11 +394,11 @@ int AL_PROTO ALArchiveBase::Extract( ALEntryList AL_DLL_FAR &list )
"CRC32 was supposed to be %08lx, was %08lx", "CRC32 was supposed to be %08lx, was %08lx",
job->GetCrc32(), job->GetCrc32(),
job->mpStorageObject->GetCrc32() ); job->mpStorageObject->GetCrc32() );
// //
// Update the monitor data, and yield some time. Note that I turn off // 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 // the monitor at this point so it doesn't jump around while I seek to the
// next position in the archive. // next position in the archive.
// //
list.mrMonitor.mlJobSoFar += job->mlCompressedSize; list.mrMonitor.mlJobSoFar += job->mlCompressedSize;
mpArchiveStorageObject->YieldTime(); mpArchiveStorageObject->YieldTime();
mpArchiveStorageObject->mpMonitor = 0; mpArchiveStorageObject->mpMonitor = 0;
@ -407,9 +407,9 @@ int AL_PROTO ALArchiveBase::Extract( ALEntryList AL_DLL_FAR &list )
} }
job = job->GetNextEntry(); job = job->GetNextEntry();
} }
// //
// Update the monitor, then scan the list for status errors. // Update the monitor, then scan the list for status errors.
// //
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
ScanStatus( list ); ScanStatus( list );
return mStatus; return mStatus;
@ -460,22 +460,22 @@ int AL_PROTO ALArchiveBase::AddJobs( ALEntryList AL_DLL_FAR &list )
ALEntry *job = list.GetFirstEntry(); ALEntry *job = list.GetFirstEntry();
while ( job ) { while ( job ) {
if ( job->miMark ) { if ( job->miMark ) {
// //
// We need to keep track of the position in the archive where the compressed // We need to keep track of the position in the archive where the compressed
// data is going to go. // data is going to go.
// //
job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell();
// //
// Attach the monitor to the storage object that is going to be inserted // Attach the monitor to the storage object that is going to be inserted
// in the archive. // in the archive.
// //
list.mrMonitor.ArchiveOperation( AL_INSERTION_OPEN, this, job ); 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 list.mrMonitor.mlObjectSize = -1L; // This means we ask for it in ALMonitor, after the object is opened
job->mpStorageObject->mpMonitor = &list.mrMonitor; job->mpStorageObject->mpMonitor = &list.mrMonitor;
// //
// Compress the object into the archive. Then store the resulting CRC // Compress the object into the archive. Then store the resulting CRC
// the compressed size in the ALEntry object. // the compressed size in the ALEntry object.
// //
job->mpCompressionEngine->Compress( *job->mpStorageObject, job->mpCompressionEngine->Compress( *job->mpStorageObject,
*mpArchiveStorageObject ); *mpArchiveStorageObject );
job->mlCrc32 = job->mpStorageObject->GetCrc32(); job->mlCrc32 = job->mpStorageObject->GetCrc32();
@ -484,9 +484,9 @@ int AL_PROTO ALArchiveBase::AddJobs( ALEntryList AL_DLL_FAR &list )
return mStatus = job->mpCompressionEngine->mStatus; return mStatus = job->mpCompressionEngine->mStatus;
job->mlCompressedSize = mpArchiveStorageObject->Tell() - job->mlCompressedSize = mpArchiveStorageObject->Tell() -
job->mlCompressedObjectPosition; job->mlCompressedObjectPosition;
// //
// Update the monitor // Update the monitor
// //
list.mrMonitor.mlJobSoFar += job->mpStorageObject->GetSize(); list.mrMonitor.mlJobSoFar += job->mpStorageObject->GetSize();
list.mrMonitor.ArchiveOperation( AL_INSERTION_CLOSE, this, job ); list.mrMonitor.ArchiveOperation( AL_INSERTION_CLOSE, this, job );
} }
@ -499,7 +499,7 @@ int AL_PROTO ALArchiveBase::AddJobs( ALEntryList AL_DLL_FAR &list )
// PRIVATE MEMBER FUNCTION // PRIVATE MEMBER FUNCTION
// //
// int ALArchiveBase::AddDirectoryEntries( ALEntryList &list ) // int ALArchiveBase::AddDirectoryEntries( ALEntryList &list )
// //
// ARGUMENTS: // ARGUMENTS:
// //
@ -561,11 +561,11 @@ int AL_PROTO ALArchiveBase::AddDirectoryEntries( ALEntryList AL_DLL_FAR &list )
} }
job = job->GetNextEntry(); job = job->GetNextEntry();
} }
// //
// I write out the end of directory string here. But then I back up the // 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 // 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. // The end of the directory is denoted by an entry with an empty name.
// //
mpArchiveStorageObject->WriteString( "" ); mpArchiveStorageObject->WriteString( "" );
mpArchiveStorageObject->Seek( mpArchiveStorageObject->Tell() - 2 ); mpArchiveStorageObject->Seek( mpArchiveStorageObject->Tell() - 2 );
@ -709,60 +709,60 @@ long AL_PROTO ALArchiveBase::CalculateCompressedJobSize( ALEntryList AL_DLL_FAR
int AL_PROTO ALArchiveBase::Create( ALEntryList AL_DLL_FAR &list ) int AL_PROTO ALArchiveBase::Create( ALEntryList AL_DLL_FAR &list )
{ {
// //
// Miscellaneous: open the archive, set the archive version, initialize // Miscellaneous: open the archive, set the archive version, initialize
// the monitor. If the storage object is broken, quite now! // the monitor. If the storage object is broken, quite now!
// //
ALOpenOutputFile archive( *mpArchiveStorageObject ); ALOpenOutputFile archive( *mpArchiveStorageObject );
miVersion = 0x100; miVersion = 0x100;
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 );
if ( mpArchiveStorageObject->mStatus < 0 ) if ( mpArchiveStorageObject->mStatus < 0 )
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
// //
// We don't want to create an archive with duplicate entries, so we check here. // We don't want to create an archive with duplicate entries, so we check here.
// //
list.UnmarkDuplicates( list, list.UnmarkDuplicates( list,
"Duplicate entry in list passed to Create()" ); "Duplicate entry in list passed to Create()" );
// //
// The first four bytes in the archive are a long that points to the // 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 // 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. // going to be, so I just reserve space at this time with a dummy value.
// //
mpArchiveStorageObject->WritePortableLong( 0x12345678L ); mpArchiveStorageObject->WritePortableLong( 0x12345678L );
// //
// Set up the monitor. // Set up the monitor.
// //
list.mrMonitor.mlJobSoFar = 0L; list.mrMonitor.mlJobSoFar = 0L;
if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB )
list.mrMonitor.mlJobSize = CalculateJobSize( list ); list.mrMonitor.mlJobSize = CalculateJobSize( list );
// //
// AddJobs() takes care of actually adding the jobs to the archive. // AddJobs() takes care of actually adding the jobs to the archive.
// //
AddJobs( list ); AddJobs( list );
// //
// All the jobs are written, now I can figure out where the // All the jobs are written, now I can figure out where the
// directory is in the storage object. I copy it, then write // directory is in the storage object. I copy it, then write
// it out to the storage object at position 0. // it out to the storage object at position 0.
// //
mlDirectoryOffset = mpArchiveStorageObject->Tell(); mlDirectoryOffset = mpArchiveStorageObject->Tell();
mpArchiveStorageObject->Seek( 0L ); mpArchiveStorageObject->Seek( 0L );
mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset );
// //
// Return without writing the directory if there is an error in the // Return without writing the directory if there is an error in the
// archive storage object. // archive storage object.
// //
if ( mpArchiveStorageObject->mStatus < 0 ) { if ( mpArchiveStorageObject->mStatus < 0 ) {
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
} }
// //
// Finally, write out the directory to the storage object. // Finally, write out the directory to the storage object.
// //
list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 );
WriteDirectory( list ); WriteDirectory( list );
// //
// Update the monitor, check for errors, and blow. // Update the monitor, check for errors, and blow.
// //
list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 );
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
ScanStatus( list ); ScanStatus( list );
@ -815,39 +815,39 @@ int AL_PROTO ALArchiveBase::Create( ALEntryList AL_DLL_FAR &list )
int AL_PROTO ALArchiveBase::CopyJobs( ALArchiveBase AL_DLL_FAR &source_archive, 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 // Open the storage object attached to the input archive. The storage object
// attached to this is already open. // attached to this is already open.
// //
ALOpenInputFile input( *(source_archive.mpArchiveStorageObject) ); ALOpenInputFile input( *(source_archive.mpArchiveStorageObject) );
// //
// Iterate through the list of entries in the list, selecting only the // Iterate through the list of entries in the list, selecting only the
// marked entries. // marked entries.
// //
ALEntry *job = source_list.GetFirstEntry(); ALEntry *job = source_list.GetFirstEntry();
while ( job ) { while ( job ) {
if ( job->miMark ) { if ( job->miMark ) {
// //
// Seek the compressed object in the source archive, then update the monitor // Seek the compressed object in the source archive, then update the monitor
// to work properly during the copy operation. // to work properly during the copy operation.
// //
source_archive.mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition ); source_archive.mpArchiveStorageObject->Seek( job->mlCompressedObjectPosition );
source_list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition; source_list.mrMonitor.mlObjectStart = job->mlCompressedObjectPosition;
source_list.mrMonitor.mlObjectSize = job->mlCompressedSize; source_list.mrMonitor.mlObjectSize = job->mlCompressedSize;
source_list.mrMonitor.ArchiveOperation( AL_COPY_OPEN, this, job ); source_list.mrMonitor.ArchiveOperation( AL_COPY_OPEN, this, job );
source_archive.mpArchiveStorageObject->mpMonitor = &source_list.mrMonitor; source_archive.mpArchiveStorageObject->mpMonitor = &source_list.mrMonitor;
// //
// Save the new position in the destination archive, then copy the // Save the new position in the destination archive, then copy the
// whole thing across. // whole thing across.
// //
job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell(); job->mlCompressedObjectPosition = mpArchiveStorageObject->Tell();
for ( long i = 0 ; i < job->mlCompressedSize ; i++ ) { for ( long i = 0 ; i < job->mlCompressedSize ; i++ ) {
int c = source_archive.mpArchiveStorageObject->ReadChar(); int c = source_archive.mpArchiveStorageObject->ReadChar();
mpArchiveStorageObject->WriteChar( c ); mpArchiveStorageObject->WriteChar( c );
} }
// //
// Update the monitor now that the copy is complete. // Update the monitor now that the copy is complete.
// //
source_list.mrMonitor.ArchiveOperation( AL_COPY_CLOSE, this, job ); source_list.mrMonitor.ArchiveOperation( AL_COPY_CLOSE, this, job );
source_archive.mpArchiveStorageObject->YieldTime(); source_archive.mpArchiveStorageObject->YieldTime();
source_list.mrMonitor.mlJobSoFar += job->mlCompressedSize; source_list.mrMonitor.mlJobSoFar += job->mlCompressedSize;
@ -897,23 +897,23 @@ int AL_PROTO ALArchiveBase::CopyJobs( ALArchiveBase AL_DLL_FAR &source_archive,
int AL_PROTO ALArchiveBase::Create( 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 // Open the source archive, set the version, and blow if for some reason
// the storage object I am writing to isn't working right. // the storage object I am writing to isn't working right.
// //
ALOpenOutputFile archive( *mpArchiveStorageObject ); ALOpenOutputFile archive( *mpArchiveStorageObject );
miVersion = 0x100; miVersion = 0x100;
if ( mpArchiveStorageObject->mStatus < 0 ) if ( mpArchiveStorageObject->mStatus < 0 )
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
// //
// I don't want to create an archive with duplicates, that would be bad. // 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()" ); 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 // 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 // compressed size of the jobs I am copying. Hey, it looks like I
// could substitute a call to CalculateCompressedSize() here! // could substitute a call to CalculateCompressedSize() here!
// //
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 );
source_list.mrMonitor.mlJobSoFar = 0L; source_list.mrMonitor.mlJobSoFar = 0L;
source_list.mrMonitor.mlJobSize = 0L; source_list.mrMonitor.mlJobSize = 0L;
@ -923,19 +923,19 @@ int AL_PROTO ALArchiveBase::Create( ALArchiveBase AL_DLL_FAR &source_archive,
if ( job->GetMark() ) if ( job->GetMark() )
source_list.mrMonitor.mlJobSize += job->mlCompressedSize; source_list.mrMonitor.mlJobSize += job->mlCompressedSize;
} }
// //
// Since I am creating a new archive, I write a long out as a place // 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, // holder for the directory pointer. When I am done copying jobs,
// I'll come back here and write a pointer to the directory. // I'll come back here and write a pointer to the directory.
// //
mpArchiveStorageObject->WritePortableLong( 0x12345678L ); mpArchiveStorageObject->WritePortableLong( 0x12345678L );
// //
// Now copy the data. // Now copy the data.
// //
CopyJobs( source_archive, source_list ); CopyJobs( source_archive, source_list );
// //
// Write out the directory offset, then the directory itself. // Write out the directory offset, then the directory itself.
// //
mlDirectoryOffset = mpArchiveStorageObject->Tell(); mlDirectoryOffset = mpArchiveStorageObject->Tell();
mpArchiveStorageObject->Seek( 0L ); mpArchiveStorageObject->Seek( 0L );
mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset );
@ -947,9 +947,9 @@ int AL_PROTO ALArchiveBase::Create( ALArchiveBase AL_DLL_FAR &source_archive,
WriteDirectory( source_list ); WriteDirectory( source_list );
source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 );
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
// //
// Update the error status, and then we are done. // Update the error status, and then we are done.
// //
ScanStatus( source_list ); ScanStatus( source_list );
return mStatus; return mStatus;
} }
@ -984,49 +984,49 @@ int AL_PROTO ALArchiveBase::Create( ALArchiveBase AL_DLL_FAR &source_archive,
int AL_PROTO ALArchiveBase::Append( ALEntryList AL_DLL_FAR &list ) int AL_PROTO ALArchiveBase::Append( ALEntryList AL_DLL_FAR &list )
{ {
ALEntryList old_list; ALEntryList old_list;
// //
// Open the storage object for this. // Open the storage object for this.
// //
ALOpenInputFile archive( *mpArchiveStorageObject ); ALOpenInputFile archive( *mpArchiveStorageObject );
// //
// I read in the current directory for this archive. I am going to // 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 // write over the directory with new stuff, so I will have to write it
// back out later. // back out later.
// //
ReadDirectory( old_list ); ReadDirectory( old_list );
if ( mStatus < 0 ) if ( mStatus < 0 )
return mStatus; return mStatus;
// //
// The list of new objects I am going to add needs to be scanned for // 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. // duplicates. First I clear duplicate entries from the list itself.
// Then I clear any duplicates between the current list and the // Then I clear any duplicates between the current list and the
// stuff already in the archive. // stuff already in the archive.
// //
list.UnmarkDuplicates( list, "Duplicate entry in list passed to Append()" ); list.UnmarkDuplicates( list, "Duplicate entry in list passed to Append()" );
list.UnmarkDuplicates( old_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. // 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.ArchiveOperation( AL_ARCHIVE_OPEN, this, 0 );
list.mrMonitor.mlJobSoFar = 0L; list.mrMonitor.mlJobSoFar = 0L;
if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB ) if ( list.mrMonitor.miMonitorType == AL_MONITOR_JOB )
list.mrMonitor.mlJobSize = CalculateJobSize( list ); list.mrMonitor.mlJobSize = CalculateJobSize( list );
// //
// The new entries start at the position currently occupied by the // The new entries start at the position currently occupied by the
// directory. I seek to that point, then call AddJobs() to do the // directory. I seek to that point, then call AddJobs() to do the
// dirty work. // dirty work.
// //
mpArchiveStorageObject->Seek( mlDirectoryOffset ); mpArchiveStorageObject->Seek( mlDirectoryOffset );
AddJobs( list ); AddJobs( list );
if ( mStatus < 0 ) { if ( mStatus < 0 ) {
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
return mStatus; return mStatus;
} }
// //
// Now that all the new stuff is in the archive, I can figure // Now that all the new stuff is in the archive, I can figure
// out where the directory belongs, and write it out to position // out where the directory belongs, and write it out to position
// 0 in the archive. // 0 in the archive.
// //
mlDirectoryOffset = mpArchiveStorageObject->Tell(); mlDirectoryOffset = mpArchiveStorageObject->Tell();
mpArchiveStorageObject->Seek( 0L ); mpArchiveStorageObject->Seek( 0L );
mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset );
@ -1034,16 +1034,16 @@ int AL_PROTO ALArchiveBase::Append( ALEntryList AL_DLL_FAR &list )
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
} }
// //
// Now I write the old directory out, and then add in the new // Now I write the old directory out, and then add in the new
// directory entries. // directory entries.
// //
list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 );
WriteDirectory( old_list ); WriteDirectory( old_list );
AddDirectoryEntries( list ); AddDirectoryEntries( list );
// //
// Update the monitor, check for errors, then leave. // Update the monitor, check for errors, then leave.
// //
list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 );
list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
ScanStatus( list ); ScanStatus( list );
@ -1083,42 +1083,42 @@ 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; ALEntryList old_list;
// //
// Open the storage object associated with this. // Open the storage object associated with this.
// //
ALOpenInputFile archive( *mpArchiveStorageObject ); ALOpenInputFile archive( *mpArchiveStorageObject );
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_OPEN, 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 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 // I start to write objects out to this, I am going to obliterate
// the directory. // the directory.
// //
ReadDirectory( old_list ); ReadDirectory( old_list );
if ( mStatus < 0 ) { if ( mStatus < 0 ) {
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
return mStatus; return mStatus;
} }
// //
// We don't want to create an archive that has duplicate entries, that would // 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 // 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 // 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 // the list of objects already in the library, and comb out any matches
// there as well. // there as well.
// //
source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Append()" ); source_list.UnmarkDuplicates( source_list, "Duplicate entry in list passed to Append()" );
source_list.UnmarkDuplicates( old_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 // I am going to start writing new stuff at the location where the
// the directory starts right now. // the directory starts right now.
// //
mpArchiveStorageObject->Seek( mlDirectoryOffset ); mpArchiveStorageObject->Seek( mlDirectoryOffset );
// //
// Before starting to copy jobs, I have to set up the monitor. // Before starting to copy jobs, I have to set up the monitor.
// This includes calculating the total number of compressed bytes // This includes calculating the total number of compressed bytes
// in all the marked jobs. I could do this a lot easier by calling // 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. // the CalculateCompressedBytes() function, but it's too late to change now.
// //
source_list.mrMonitor.mlJobSoFar = 0L; source_list.mrMonitor.mlJobSoFar = 0L;
source_list.mrMonitor.mlJobSize = 0L; source_list.mrMonitor.mlJobSize = 0L;
for ( ALEntry *job = source_list.GetFirstEntry(); for ( ALEntry *job = source_list.GetFirstEntry();
@ -1127,18 +1127,18 @@ int AL_PROTO ALArchiveBase::Append( ALArchiveBase AL_DLL_FAR &source_archive,
if ( job->GetMark() ) if ( job->GetMark() )
source_list.mrMonitor.mlJobSize += job->mlCompressedSize; source_list.mrMonitor.mlJobSize += job->mlCompressedSize;
} }
// //
// CopyJobs() does the hard work for me. // CopyJobs() does the hard work for me.
// //
CopyJobs( source_archive, source_list ); CopyJobs( source_archive, source_list );
if ( mStatus < 0 ) { if ( mStatus < 0 ) {
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
return mStatus; return mStatus;
} }
// //
// The jobs are now in, I just have to update the directory with // The jobs are now in, I just have to update the directory with
// the old files and the new files. // the old files and the new files.
// //
mlDirectoryOffset = mpArchiveStorageObject->Tell(); mlDirectoryOffset = mpArchiveStorageObject->Tell();
mpArchiveStorageObject->Seek( 0L ); mpArchiveStorageObject->Seek( 0L );
mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset ); mpArchiveStorageObject->WritePortableLong( mlDirectoryOffset );
@ -1149,9 +1149,9 @@ int AL_PROTO ALArchiveBase::Append( ALArchiveBase AL_DLL_FAR &source_archive,
source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_START_DIRECTORY_WRITE, this, 0 );
WriteDirectory( old_list ); WriteDirectory( old_list );
AddDirectoryEntries( source_list ); AddDirectoryEntries( source_list );
// //
// Wrap it up. // Wrap it up.
// //
source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_END_DIRECTORY_WRITE, this, 0 );
source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 ); source_list.mrMonitor.ArchiveOperation( AL_ARCHIVE_CLOSE, this, 0 );
ScanStatus( source_list ); ScanStatus( source_list );
@ -1188,11 +1188,11 @@ int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list )
ALOpenInputFile archive( *mpArchiveStorageObject ); ALOpenInputFile archive( *mpArchiveStorageObject );
if ( mpArchiveStorageObject->mStatus < 0 ) if ( mpArchiveStorageObject->mStatus < 0 )
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
// //
// First I seek to the start of the directory (offset found at 0), and // First I seek to the start of the directory (offset found at 0), and
// read in the version. This function only supports the directory // read in the version. This function only supports the directory
// structure defined in version 0x100. // structure defined in version 0x100.
// //
mpArchiveStorageObject->Seek( 0 ); mpArchiveStorageObject->Seek( 0 );
mpArchiveStorageObject->ReadPortableLong( mlDirectoryOffset ); mpArchiveStorageObject->ReadPortableLong( mlDirectoryOffset );
mpArchiveStorageObject->Seek( mlDirectoryOffset ); mpArchiveStorageObject->Seek( mlDirectoryOffset );
@ -1201,40 +1201,40 @@ int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list )
return mStatus.SetError( AL_INVALID_ARCHIVE, return mStatus.SetError( AL_INVALID_ARCHIVE,
"%s is not a valid archive file", "%s is not a valid archive file",
mpArchiveStorageObject->mName.GetSafeName() ); mpArchiveStorageObject->mName.GetSafeName() );
// //
// Read in any customized archive data defined by a derived class. // Read in any customized archive data defined by a derived class.
// //
ReadArchiveData(); ReadArchiveData();
// //
// Read in the comment, deleting the old one if necessary. // Read in the comment, deleting the old one if necessary.
// //
if ( mszComment ) if ( mszComment )
delete[] mszComment; delete[] mszComment;
mszComment = mpArchiveStorageObject->ReadString(); mszComment = mpArchiveStorageObject->ReadString();
// //
// Now, the big loop. I have to read in each entry, one at a time, and // 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 // add it to the list. If I broke this out into a separate routine it
// would make the whole thing a lot more manageable. // would make the whole thing a lot more manageable.
// //
for ( ; ; ) { for ( ; ; ) {
if ( mpArchiveStorageObject->mStatus < 0 ) if ( mpArchiveStorageObject->mStatus < 0 )
return mStatus = mpArchiveStorageObject->mStatus; return mStatus = mpArchiveStorageObject->mStatus;
char *name = mpArchiveStorageObject->ReadString(); char *name = mpArchiveStorageObject->ReadString();
if ( name == 0 ) if ( name == 0 )
break; break;
// //
// The directory ends with a blank name. // The directory ends with a blank name.
// //
if ( strlen( name ) == 0 ) { if ( strlen( name ) == 0 ) {
delete[] name; delete[] name;
break; break;
} }
// //
// Derived classes are responsible for providing a version of // Derived classes are responsible for providing a version of
// CreateCompressionEngine() that will convert the engine_type // CreateCompressionEngine() that will convert the engine_type
// integer into a created compression engine. The derived class is // integer into a created compression engine. The derived class is
// then also responsible for reading in the engine data from the archive. // then also responsible for reading in the engine data from the archive.
// //
int engine_type = mpArchiveStorageObject->ReadChar(); int engine_type = mpArchiveStorageObject->ReadChar();
ALCompressionEngine *engine = CreateCompressionEngine( engine_type ); ALCompressionEngine *engine = CreateCompressionEngine( engine_type );
if ( engine ) if ( engine )
@ -1247,13 +1247,13 @@ int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list )
"Failure creating compression engine for object %s", "Failure creating compression engine for object %s",
name ); name );
} }
// //
// Now we go through a nearly identical process to create the storage object. // Now we go through a nearly identical process to create the storage object.
// The derived class is responsible for writing a CreateStorageObject() // The derived class is responsible for writing a CreateStorageObject()
// function that converts an object_type integer to a created storage // function that converts an object_type integer to a created storage
// object. The derived class also has to read in the storage object // object. The derived class also has to read in the storage object
// data. // data.
// //
int object_type = mpArchiveStorageObject->ReadChar(); int object_type = mpArchiveStorageObject->ReadChar();
ALStorage *storage_object = CreateStorageObject( name, object_type ); ALStorage *storage_object = CreateStorageObject( name, object_type );
delete[] name; // Don't need it any more delete[] name; // Don't need it any more
@ -1268,9 +1268,9 @@ int AL_PROTO ALArchiveBase::ReadDirectory( ALEntryList AL_DLL_FAR &list )
"Failure creating storage object for object %s", "Failure creating storage object for object %s",
name ); name );
} }
// //
// The rest of the stuff in the entry is pretty straightforward. // The rest of the stuff in the entry is pretty straightforward.
// //
mpArchiveStorageObject->ReadPortableLong( storage_object->mlSize ); mpArchiveStorageObject->ReadPortableLong( storage_object->mlSize );
ALEntry *job = new ALEntry( list, storage_object, engine ); ALEntry *job = new ALEntry( list, storage_object, engine );
mpArchiveStorageObject->ReadPortableLong( job->mlCompressedSize ); mpArchiveStorageObject->ReadPortableLong( job->mlCompressedSize );
@ -1396,7 +1396,7 @@ int AL_PROTO ALArchiveBase::Delete( ALEntryList AL_DLL_FAR &list,
list.ToggleMarks(); list.ToggleMarks();
ALName temp = mpArchiveStorageObject->mName; ALName temp = mpArchiveStorageObject->mName;
mpArchiveStorageObject->RenameToBackup(); mpArchiveStorageObject->RenameToBackup();
destination.mpArchiveStorageObject->Rename( temp ); destination.mpArchiveStorageObject->Rename( (const char*)temp );
if ( destination.mStatus < 0 ) if ( destination.mStatus < 0 )
return mStatus = destination.mStatus; return mStatus = destination.mStatus;
return mStatus; return mStatus;

View File

@ -34,7 +34,9 @@
#include "arclib.h" #include "arclib.h"
#pragma hdrstop #pragma hdrstop
#if XVT_OS != XVT_OS_SCOUNIX
#include <dos.h> #include <dos.h>
#endif
#include "fileattr.h" #include "fileattr.h"