home *** CD-ROM | disk | FTP | other *** search
- /*
- * generate.c
- *
- * Do the actual floppy generation
- *
- */
- #include <exec/types.h>
-
- #include <utility/tagitem.h>
- #include <dos/dostags.h>
-
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
-
- #include <stdio.h>
- #include <string.h>
-
- #include "PufferFish.h"
-
- /*
- * generate_disk()
- *
- * Actually does the disk creation (format, uncompress, verify)
- *
- * Several of these will be started as tasks
- *
- */
- __saveds void generate_disk( void )
- {
- struct GFMessage msg, *reply;
- struct MsgPort *port;
- BPTR console_window;
- ULONG error;
- BOOL done = FALSE;
- char echo_command[255], system_command[255], diskname[255], diskpath[255];
- ULONG disknum;
-
- if( port = CreateMsgPort() )
- {
- msg.gf_Msg.mn_Length = sizeof( struct GFMessage );
- msg.gf_Msg.mn_ReplyPort = port;
- msg.gf_DriveNum = -1;
-
- PutMsg( myPort, (struct Message *)&msg );
-
- WaitPort( port );
- if( reply = (struct GFMessage *)GetMsg( port ) )
- {
- // Find out which drive we're going to use
- msg.gf_DriveNum = reply->gf_DriveNum;
- }
-
- if( msg.gf_DriveNum < 4 )
- {
- sprintf( echo_command, "CON:0/%ld/640/50/PufferFish Output DF%ld:/CLOSE/WAIT/SCREEN %s",
- 100 + (msg.gf_DriveNum * 50),
- msg.gf_DriveNum,
- screen->Title );
- }
- else
- {
- sprintf( echo_command, "CON:0/%ld/640/50/PufferFish Output %s/CLOSE/WAIT/SCREEN %s",
- 100 + (msg.gf_DriveNum * 50),
- additional_device,
- screen->Title );
- }
- if( console_window = Open( echo_command, MODE_NEWFILE ) )
- {
- PutMsg( port, (struct Message *)&msg );
- while( !done )
- {
- WaitPort( port );
- if( reply = (struct GFMessage *)GetMsg( port ) )
- {
- disknum = reply->gf_DiskNumber;
- if( disknum > lastdisk )
- {
- // Received 'quit' message
- done = TRUE;
- }
- else
- {
- if( disknum > 0 )
- {
- strcpy( diskname, reply->gf_DiskName );
- strcpy( diskpath, reply->gf_DiskPath );
-
- sprintf( echo_command,
- "\033[1;2mCreating AmigaLibDisk %03d\033[0m\n",
- disknum );
- Write( console_window, echo_command, strlen( echo_command ) );
- if( msg.gf_DriveNum < 4 )
- {
- sprintf( system_command,
- "%s DRIVE DF%ld: NAME %s\n",
- formatpath,
- msg.gf_DriveNum,
- diskname );
- }
- else
- {
- sprintf( system_command,
- "%s DRIVE %s NAME %s\n",
- formatpath,
- additional_device,
- diskname );
- }
- if( verbose )
- {
- Write( console_window, system_command, strlen( system_command ) );
- }
- if( !( error = SystemTags( system_command,
- SYS_Asynch, FALSE,
- SYS_Input, console_window,
- SYS_Output, NULL,
- TAG_END ) ) )
- {
- int i = 0;
-
- // Add : to disk name
- for( i = 0; i < strlen( diskname ) - 1; i += 1 );
- if( diskname[0] == '\"')
- {
- diskname[i] = ':';
- diskname[i+1] = '\"';
- }
- else
- {
- diskname[i+1] = ':';
- }
- diskname[i+2] = '\0';
-
- sprintf( system_command,
- "%s %s/#?.lha %s\n",
- lhapath,
- diskpath,
- diskname );
- if( verbose )
- {
- Write( console_window, system_command, strlen( system_command ) );
- }
- if( !( error = SystemTags( system_command,
- SYS_Asynch, FALSE,
- SYS_Input, console_window,
- SYS_Output, NULL,
- TAG_END ) ) )
- {
- sprintf( system_command,
- "CD %s\n%s %s/Disk%03d.crc\n",
- diskname,
- brikpath,
- diskpath,
- disknum );
- if( verbose )
- {
- Write( console_window, system_command, strlen( system_command ) );
- }
- if( !( error = SystemTags( system_command,
- SYS_Asynch, FALSE,
- SYS_Input, console_window,
- SYS_Output, NULL,
- NP_StackSize, 20000,
- TAG_END ) ) )
- {
- sprintf( echo_command,
- "\033[1;2mAmigaLibDisk %03d successfully generated!\033[0m\n",
- disknum );
- }
- else
- {
- DisplayBeep( screen );
- sprintf( echo_command,
- "\033[1mBrik failed to verify disk\033[0m\n" );
- }
- }
- else
- {
- DisplayBeep( screen );
- sprintf( echo_command,
- "\033[1mLhA failed to extract disk contents\033[0m\n" );
- }
- }
- else
- {
- DisplayBeep( screen );
- sprintf( echo_command,
- "\033[1mFormat failed to initialize disk\033[0m\n" );
- }
- Write( console_window, echo_command, strlen( echo_command ) );
- }
- PutMsg( myPort, (struct Message *)&msg );
- }
- }
- }
- // Close console_window handle
- Close( console_window );
- }
- DeleteMsgPort( port );
- }
- else
- {
- // Couldn't create message port: should report error (else calling task will wait forever)
- }
- }
-