3131
3232#include <encodings/crc32.h>
3333
34+ #include "../retroarch.h"
3435#include "../msg_hash.h"
3536#include "../verbosity.h"
37+ #include "../configuration.h"
3638
3739enum bps_mode
3840{
@@ -613,6 +615,9 @@ static bool apply_patch_content(uint8_t **buf,
613615 ssize_t * size , const char * patch_desc , const char * patch_path ,
614616 patch_func_t func , void * patch_data , int64_t patch_size )
615617{
618+ settings_t * settings = config_get_ptr ();
619+ bool show_notification = settings ?
620+ settings -> bools .notification_show_patch_applied : false;
616621 enum patch_error err = PATCH_UNKNOWN ;
617622 ssize_t ret_size = * size ;
618623 uint8_t * ret_buf = * buf ;
@@ -628,6 +633,21 @@ static bool apply_patch_content(uint8_t **buf,
628633 free (ret_buf );
629634 * buf = patched_content ;
630635 * size = target_size ;
636+
637+ /* Show an OSD message */
638+ if (show_notification )
639+ {
640+ const char * patch_filename = path_basename (patch_path );
641+ char msg [256 ];
642+
643+ msg [0 ] = '\0' ;
644+
645+ snprintf (msg , sizeof (msg ), msg_hash_to_str (MSG_APPLYING_PATCH ),
646+ patch_filename ? patch_filename :
647+ msg_hash_to_str (MENU_ENUM_LABEL_VALUE_UNKNOWN ));
648+ runloop_msg_queue_push (msg , 1 , 180 , false, NULL ,
649+ MESSAGE_QUEUE_ICON_DEFAULT , MESSAGE_QUEUE_CATEGORY_INFO );
650+ }
631651 }
632652 else
633653 RARCH_ERR ("%s %s: %s #%u\n" ,
@@ -740,6 +760,7 @@ bool patch_content(
740760 bool allow_ups = !is_bps_pref && !is_ips_pref ;
741761 bool allow_ips = !is_ups_pref && !is_bps_pref ;
742762 bool allow_bps = !is_ups_pref && !is_ips_pref ;
763+ bool patch_found = false;
743764
744765 if ( (unsigned )is_ips_pref
745766 + (unsigned )is_bps_pref
@@ -750,14 +771,74 @@ bool patch_content(
750771 return false;
751772 }
752773
753- if ( !try_ips_patch (allow_ips , name_ips , buf , size )
754- && !try_bps_patch (allow_bps , name_bps , buf , size )
755- && !try_ups_patch (allow_ups , name_ups , buf , size ))
774+ /* Attempt to apply first (non-indexed) patch */
775+ if ( try_ips_patch (allow_ips , name_ips , buf , size )
776+ || try_bps_patch (allow_bps , name_bps , buf , size )
777+ || try_ups_patch (allow_ups , name_ups , buf , size ))
756778 {
779+ /* A patch has been found. Now attempt to apply
780+ * any additional 'indexed' patch files */
781+ size_t name_ips_len = strlen (name_ips );
782+ size_t name_bps_len = strlen (name_bps );
783+ size_t name_ups_len = strlen (name_ups );
784+ char * name_ips_indexed = (char * )malloc ((name_ips_len + 2 ) * sizeof (char ));
785+ char * name_bps_indexed = (char * )malloc ((name_bps_len + 2 ) * sizeof (char ));
786+ char * name_ups_indexed = (char * )malloc ((name_ups_len + 2 ) * sizeof (char ));
787+ /* First patch already applied -> index
788+ * for subsequent patches starts at 1 */
789+ size_t patch_index = 1 ;
790+
791+ name_ips_indexed [0 ] = '\0' ;
792+ name_bps_indexed [0 ] = '\0' ;
793+ name_ups_indexed [0 ] = '\0' ;
794+
795+ strlcpy (name_ips_indexed , name_ips , (name_ips_len + 1 ) * sizeof (char ));
796+ strlcpy (name_bps_indexed , name_bps , (name_bps_len + 1 ) * sizeof (char ));
797+ strlcpy (name_ups_indexed , name_ups , (name_ups_len + 1 ) * sizeof (char ));
798+
799+ /* Ensure that we NUL terminate *after* the
800+ * index character */
801+ name_ips_indexed [name_ips_len + 1 ] = '\0' ;
802+ name_bps_indexed [name_bps_len + 1 ] = '\0' ;
803+ name_ups_indexed [name_ups_len + 1 ] = '\0' ;
804+
805+ /* try to patch "*.ipsX" */
806+ while (patch_index < 10 )
807+ {
808+ /* Add index character to end of patch
809+ * file path string
810+ * > Note: This technique only works for
811+ * index values up to 9 (i.e. single
812+ * digit numbers)
813+ * > If we want to support more than 10
814+ * patches in total, will have to replace
815+ * this with an snprintf() implementation
816+ * (which will have significantly higher
817+ * performance overheads) */
818+ char index_char = '0' + patch_index ;
819+
820+ name_ips_indexed [name_ips_len ] = index_char ;
821+ name_bps_indexed [name_bps_len ] = index_char ;
822+ name_ups_indexed [name_ups_len ] = index_char ;
823+
824+ if ( !try_ips_patch (allow_ips , name_ips_indexed , buf , size )
825+ && !try_bps_patch (allow_bps , name_bps_indexed , buf , size )
826+ && !try_ups_patch (allow_ups , name_ups_indexed , buf , size ))
827+ break ;
828+
829+ patch_index ++ ;
830+ }
831+
832+ free (name_ips_indexed );
833+ free (name_bps_indexed );
834+ free (name_ups_indexed );
835+
836+ patch_found = true;
837+ }
838+
839+ if (!patch_found )
757840 RARCH_LOG ("%s\n" ,
758841 msg_hash_to_str (MSG_DID_NOT_FIND_A_VALID_CONTENT_PATCH ));
759- return false;
760- }
761842
762- return true ;
843+ return patch_found ;
763844}
0 commit comments