@@ -788,7 +788,6 @@ static BOOL examineFolder(char *path)
788788 return FALSE;
789789 }
790790
791- // TODO: Clear that if possible
792791 char * igameDataPath = malloc (sizeof (char ) * MAX_PATH_SIZE );
793792 if (!isPathFolder (path ))
794793 {
@@ -815,6 +814,8 @@ static BOOL examineFolder(char *path)
815814 node -> players = 0 ;
816815
817816 getIGameDataInfo (igameDataPath , node );
817+ free (igameDataPath );
818+
818819 strncpy (buf , node -> path , bufSize );
819820 if (!isPathFolder (path ))
820821 {
@@ -825,7 +826,8 @@ static BOOL examineFolder(char *path)
825826 snprintf (node -> path , sizeof (char ) * MAX_PATH_SIZE , "%s/%s" , path , buf );
826827 }
827828
828- // Check the node->path and skip the save if the buf is empty, it is a slave or the file does not exist. Free the node before move on.
829+ // Check the node->path and skip the save if the buf is empty, it is a slave that aleady exists in the slaves list
830+ // or there is no executable file defined. Free the node before move on.
829831 if (
830832 isStringEmpty (buf ) || !check_path_exists (node -> path ) ||
831833 (slavesListSearchByPath (node -> path , sizeof (char ) * MAX_PATH_SIZE ) != NULL )
@@ -870,6 +872,7 @@ static BOOL examineFolder(char *path)
870872 node -> instance = 0 ;
871873 node -> title [0 ] = '\0' ;
872874 node -> genre [0 ] = '\0' ;
875+ sprintf (node -> genre ,"Unknown" );
873876 node -> user_title [0 ] = '\0' ;
874877 node -> chipset [0 ] = '\0' ;
875878 node -> times_played = 0 ;
@@ -915,33 +918,58 @@ static BOOL examineFolder(char *path)
915918 {
916919 if (current_settings -> useIgameDataTitle )
917920 {
918- slavesList * node = malloc (sizeof (slavesList ) );
919- if (node == NULL )
921+ char * igameDataPath = malloc (sizeof (char ) * MAX_PATH_SIZE );
922+ if (igameDataPath == NULL )
920923 {
921924 msg_box ((const char * )GetMBString (MSG_NotEnoughMemory ));
922- FreeVec (FIblock );
923- UnLock (lock );
924- free (buf );
925925 return FALSE;
926926 }
927927
928- char * igameDataPath = malloc ( sizeof (char ) * MAX_PATH_SIZE );
929- snprintf (igameDataPath , sizeof (char ) * MAX_PATH_SIZE , "%s/%s" , existingNode -> path , DEFAULT_IGAMEDATA_FILE );
928+ getParentPath ( existingNode -> path , igameDataPath , sizeof (char ) * MAX_PATH_SIZE );
929+ snprintf (igameDataPath , sizeof (char ) * MAX_PATH_SIZE , "%s/%s" , igameDataPath , DEFAULT_IGAMEDATA_FILE ); // cppcheck-suppress sprintfOverlappingData
930930 if (check_path_exists (igameDataPath ))
931931 {
932- getIGameDataInfo (igameDataPath , node );
933- }
934- free (igameDataPath );
932+ slavesList * node = malloc (sizeof (slavesList ));
933+ if (node == NULL )
934+ {
935+ msg_box ((const char * )GetMBString (MSG_NotEnoughMemory ));
936+ FreeVec (FIblock );
937+ UnLock (lock );
938+ free (buf );
939+ return FALSE;
940+ }
941+
942+ node -> instance = 0 ;
943+ node -> title [0 ] = '\0' ;
944+ node -> genre [0 ] = '\0' ;
945+ sprintf (node -> genre ,"Unknown" );
946+ node -> user_title [0 ] = '\0' ;
947+ node -> chipset [0 ] = '\0' ;
948+ node -> times_played = 0 ;
949+ node -> favourite = 0 ;
950+ node -> last_played = 0 ;
951+ node -> exists = 1 ;
952+ node -> hidden = 0 ;
953+ node -> deleted = 0 ;
954+ node -> year = 0 ;
955+ node -> players = 0 ;
935956
936- if (!isStringEmpty (node -> genre ))
937- strncpy (existingNode -> genre , node -> genre , MAX_GENRE_NAME_SIZE );
957+ getIGameDataInfo (igameDataPath , node );
938958
939- if (!isStringEmpty (node -> chipset ))
940- strncpy (existingNode -> chipset , node -> chipset , MAX_CHIPSET_SIZE );
959+ if (!isStringEmpty (node -> genre ))
960+ {
961+ strncpy (existingNode -> genre , node -> genre , MAX_GENRE_NAME_SIZE );
962+ addGenreInList (node -> genre );
963+ }
964+ if (!isStringEmpty (node -> chipset ))
965+ {
966+ strncpy (existingNode -> chipset , node -> chipset , MAX_CHIPSET_SIZE );
967+ addChipsetInList (node -> chipset );
968+ }
969+ free (node );
970+ }
941971
942- addGenreInList (node -> genre );
943- addChipsetInList (node -> chipset );
944- free (node );
972+ free (igameDataPath );
945973 }
946974
947975 // Generate title and add in the list
0 commit comments