[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx:[772] trunk/fuse/fusepb/controllers/ FuseCont
Brought to you by:
fredm
From: <fr...@us...> - 2014-02-13 12:13:42
|
Revision: 772 http://sourceforge.net/p/fuse-for-macosx/code/772 Author: fredm Date: 2014-02-13 12:13:39 +0000 (Thu, 13 Feb 2014) Log Message: ----------- Add support for playing RZXs with no embedded snapshot from the File->Open menu and from the command line and drag-n-drop. Modified Paths: -------------- trunk/fuse/fusepb/controllers/FuseController.m Modified: trunk/fuse/fusepb/controllers/FuseController.m =================================================================== --- trunk/fuse/fusepb/controllers/FuseController.m 2014-02-12 10:16:52 UTC (rev 771) +++ trunk/fuse/fusepb/controllers/FuseController.m 2014-02-13 12:13:39 UTC (rev 772) @@ -642,10 +642,7 @@ - (IBAction)rzx_play:(id)sender { - char *recording, *snapshot; - utils_file file; - libspectrum_error libspec_error; int error; - libspectrum_snap* snap; + char *recording; if( rzx_playback || rzx_recording ) return; @@ -655,53 +652,12 @@ if( !recording ) { [[DisplayOpenGLView instance] unpause]; return; } - rzx = libspectrum_rzx_alloc(); + [self openFile:recording]; - error = utils_read_file( recording, &file ); - if( error ) { - free( recording ); - [[DisplayOpenGLView instance] unpause]; - return; - } - - libspec_error = libspectrum_rzx_read( rzx, file.buffer, file.length ); - utils_close_file( &file ); - if( libspec_error != LIBSPECTRUM_ERROR_NONE ) { - free( recording ); - [[DisplayOpenGLView instance] unpause]; - return; - } - - snap = rzx_get_initial_snapshot(); - if( !snap ) { - /* We need to load an external snapshot. */ - snapshot = cocoaui_openpanel_get_filename( @"Load Replay Snapshot", - snapFileTypes ); - if( !snapshot ) { - free( recording ); - [[DisplayOpenGLView instance] unpause]; - return; - } - - [[DisplayOpenGLView instance] snapOpen:snapshot]; - free( snapshot ); - } else { - // FIXME: snapless rzxs loaded from the menu would require a snapshot - // prompt when selecting from the recent files list which would deadlock - // right now - [self addRecentSnapshot:recording]; - } - - libspectrum_rzx_free( rzx ); - - [[DisplayOpenGLView instance] rzxStartPlayback:recording]; - free( recording ); display_refresh_all(); - if( rzx_playback ) ui_menu_activate( UI_MENU_ITEM_RECORDING, 1 ); - [[DisplayOpenGLView instance] unpause]; } @@ -1944,9 +1900,56 @@ - (void)openFile:(const char *)filename { + char *snapshot; + utils_file file; libspectrum_id_t type; + libspectrum_class_t lsclass; + libspectrum_error libspec_error; int error; + libspectrum_snap* snap; + if( !filename ) return; - [[DisplayOpenGLView instance] openFile:filename]; + if( utils_read_file( filename, &file ) ) fuse_abort(); + + if( libspectrum_identify_file( &type, filename, file.buffer, file.length ) ) { + utils_close_file( &file ); + fuse_abort(); + } + + if( libspectrum_identify_class( &lsclass, type ) ) fuse_abort(); + + if( lsclass != LIBSPECTRUM_CLASS_RECORDING ) { + utils_close_file( &file ); + [[DisplayOpenGLView instance] openFile:filename]; + return; + } + + if( rzx_playback || rzx_recording ) return; + + rzx = libspectrum_rzx_alloc(); + + libspec_error = libspectrum_rzx_read( rzx, file.buffer, file.length ); + utils_close_file( &file ); + if( libspec_error != LIBSPECTRUM_ERROR_NONE ) return; + + snap = rzx_get_initial_snapshot(); + if( !snap ) { + /* We need to load an external snapshot. */ + snapshot = cocoaui_openpanel_get_filename( @"Load Replay Snapshot", + snapFileTypes ); + if( !snapshot ) return; + + [[DisplayOpenGLView instance] snapOpen:snapshot]; + + free( snapshot ); + } + + [self addRecentSnapshot:filename]; + + libspectrum_rzx_free( rzx ); + + [[DisplayOpenGLView instance] rzxStartPlayback:filename]; + + if( rzx_playback ) ui_menu_activate( UI_MENU_ITEM_RECORDING, 1 ); } - (void)openRecent:(id)fileMenu This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |