-
- for( u32 j=0; j<workshop_count; j++ ){
- PublishedFileId_t id = workshop_ids[j];
-
- for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
- struct registry_board *reg = &global_skateshop.registry[i];
-
- if( reg->workshop_id == id ){
- reg->state = k_registry_board_state_indexed;
- goto next_file_workshop;
- }
- }
-
- if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
- vg_error( "You have too many boards installed!\n" );
- break;
- }
-
- vg_info( "new listing from the steam workshop!: "PRINTF_U64"\n", id );
-
- struct registry_board *reg = &global_skateshop.registry[
- global_skateshop.t1_registry_count ++ ];
-
- reg->cache_ptr = NULL;
- snprintf( reg->filename, 64, PRINTF_U64, id );
- reg->filename_hash = vg_strdjb2( reg->filename );
- reg->workshop_id = id;
- reg->state = k_registry_board_state_indexed;
-
- workshop_file_info_clear( ®->workshop );
- strcpy( reg->workshop.title, "Workshop file" );
-
- /* load the metadata off the disk */
- vg_async_item *call =
- vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
-
- const char *meta_file = "/board.mdl.inf";
- char path[ 1024 ];
- struct async_workshop_filepath_info *info = call->payload;
- info->buf = path;
- info->id = reg->workshop_id;
- info->len = vg_list_size(path) - strlen(meta_file)-1;
- vg_async_dispatch( call, async_workshop_get_filepath );
- vg_async_stall(); /* too bad! */
-
- strcat( path, meta_file );
- workshop_load_metadata( path, ®->workshop );
-
-next_file_workshop:;
- }
-}
-
-/*
- * Async thread which scans local files for boards, as well as scheduling
- * synchronous calls to the workshop
- */
-VG_STATIC void workshop_scan_thread( void *_args )
-{
- vg_linear_clear( vg_mem.scratch );
-
- for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
- struct registry_board *reg = &global_skateshop.registry[i];
- reg->state = k_registry_board_state_indexed_absent;
- }
-
- /*
- * Local disk scan
- */
- vg_info( "Scanning models/boards/*.mdl\n" );
- tinydir_dir dir;
- tinydir_open( &dir, "models/boards" );
-
- while( dir.has_next ){
- tinydir_file file;
- tinydir_readfile( &dir, &file );
-
- if( file.is_reg ){
- u32 hash = vg_strdjb2( file.name );
-
- for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
- struct registry_board *reg = &global_skateshop.registry[i];
-
- if( const_str_eq( hash, file.name, reg->filename ) ){
- reg->state = k_registry_board_state_indexed;
- goto next_file;
- }
- }
-
- if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
- vg_error( "You have too many boards installed!\n" );
- break;
- }
-
- vg_info( "new listing!: %s\n", file.name );
-
- struct registry_board *reg =
- &global_skateshop.registry[global_skateshop.t1_registry_count ++];
-
- reg->cache_ptr = NULL;
- vg_strncpy( file.name, reg->filename, 64, k_strncpy_always_add_null );
- vg_strncpy( file.name, reg->workshop.title,
- 64, k_strncpy_always_add_null );
- reg->filename_hash = hash;
- reg->workshop_id = 0;
- reg->state = k_registry_board_state_indexed;
- reg->workshop.author = 0;
- strcpy( reg->workshop.author_name, "custom" );
- }
-
-next_file: tinydir_next( &dir );
- }
-
- tinydir_close(&dir);
-
- if( steam_ready ) workshop_steam_scan();
-
- vg_async_call( workshop_async_reg_update, NULL, 0 );
- vg_async_stall();
- workshop_visibile_load_loop_thread(NULL);