- SDL_AtomicLock( &global_skateshop.sl_cache_access );
- if( cache_ptr->state == k_cache_board_state_load_request ){
- if( cache_ptr->registry_id >= global_skateshop.registry_count ){
- /* should maybe have a different value for this case */
- cache_ptr->state = k_cache_board_state_none;
- SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
- continue;
- }
-
- /* continue with the request */
- SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-
- struct registry_board *reg =
- &global_skateshop.registry[ cache_ptr->registry_id ];
-
- if( reg->workshop_id ){
- vg_async_item *call =
- vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
-
- struct async_workshop_filepath_info *info = call->payload;
- info->buf = path_buf;
- info->id = reg->workshop_id;
- info->len = vg_list_size(path_buf);
- vg_async_dispatch( call, async_workshop_get_filepath );
- vg_async_stall(); /* too bad! */
-
- if( path_buf[0] == '\0' ){
- vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n",
- reg->workshop_id );
-
- goto file_is_broken;
- }
-
- folder.buffer = path_buf;
- folder.i = strlen(path_buf);
- folder.len = 4096;
- }
- else{
- vg_strnull( &folder, path_buf, 4096 );
- vg_strcat( &folder, "boards/" );
- vg_strcat( &folder, reg->foldername );
- }
-
- vg_str meta_path = folder;
- vg_strcat( &meta_path, "/addon.inf" );
-
- if( !vg_strgood( &meta_path ) ) {
- vg_error( "Metadata path too long\n" );
- goto file_is_broken;
- }
-
- u8 meta[512];
- FILE *fp = fopen( meta_path.buffer, "rb" );
-
- if( !fp ) goto file_is_broken;
-
- u32 l = fread( meta, 1, 512, fp );
- if( l != 512 ){
- if( !feof(fp) ){
- fclose(fp);
- vg_error( "unknown error codition" );
- goto file_is_broken;
- }
- }
- fclose(fp);
-
- /* load content files
- * --------------------------------- */
-
- vg_str content_path = folder;
-
- vg_msg msg;
- vg_msg_init( &msg, meta, l );
- vg_msg_cmd cmd;
- while( vg_msg_next( &msg, &cmd ) ){
- if( (msg.depth == 0) && (cmd.code == k_vg_msg_code_kvstring) ){
- if( VG_STRDJB2_EQ( "content", cmd.key, cmd.key_djb2 ) ){
- vg_strcat( &content_path, "/" );
- vg_strcat( &content_path, cmd.value._buf );
- break;
- }
- }
- }
- if( !vg_strgood( &content_path ) ) {
- vg_error( "Metadata path too long\n" );
- goto file_is_broken;
- }
-
- player_board_load( &cache_ptr->board, content_path.buffer );
- vg_async_call( skateshop_async_board_loaded, cache_ptr, 0 );
- continue;
-
-file_is_broken:;
- SDL_AtomicLock( &global_skateshop.sl_cache_access );
- cache_ptr->state = k_cache_board_state_none;
- SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
- }
- else
- SDL_AtomicUnlock( &global_skateshop.sl_cache_access );