*/
char model_path[128];
-
struct player_board board_model;
/* what does the user want to do with the image preview? */
*/
struct workshop_package_thread_args{
PublishedFileId_t file_id;
+
+ u64_steamid steamid;
+ char username[32];
};
VG_STATIC void _workshop_package_thread( void *_args )
{
return;
}
+ /* write the metadata file */
+ struct workshop_file_info meta;
+ meta.author = args->steamid;
+ vg_strncpy( args->username, meta.author_name, vg_list_size(meta.author_name),
+ k_strncpy_always_add_null );
+ vg_strncpy( workshop_form.submission.title, meta.title,
+ vg_list_size(meta.title), k_strncpy_always_add_null );
+
+ char _path[1024];
+ vg_str path;
+ vg_strnull( &path, _path, vg_list_size( _path ) );
+ vg_strcat( &path, info->abs_content_file );
+ vg_strcat( &path, ".inf" );
+
+ if( vg_strgood( &path ) ){
+ FILE *fp = fopen( _path, "wb" );
+
+ if( fp ){
+ fwrite( &meta, sizeof(struct workshop_file_info), 1, fp );
+ fclose( fp );
+ }
+ else{
+ info->success = 0;
+ info->failure_reason = "Cant write .inf file";
+ vg_async_dispatch( call, workshop_form_async_package_complete );
+ }
+ }
+ else{
+ info->success = 0;
+ info->failure_reason = "Path too long";
+ vg_async_dispatch( call, workshop_form_async_package_complete );
+ return;
+ }
+
info->success = 1;
vg_async_dispatch( call, workshop_form_async_package_complete );
}
vg_linear_alloc( vg_mem.scratch,
sizeof(struct workshop_package_thread_args));
+ ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
+ ISteamUser *hSteamUser = SteamAPI_SteamUser();
+
+ args->steamid = SteamAPI_ISteamUser_GetSteamID( hSteamUser );
+
+ const char *username = SteamAPI_ISteamFriends_GetPersonaName(hSteamFriends);
+ str_utf8_collapse( username, args->username, vg_list_size( args->username ));
+ vg_info( "Steamid: "PRINTF_U64", Name: %s(%s)\n",
+ args->steamid, username, args->username );
+
args->file_id = file_id;
vg_loader_start( _workshop_package_thread, args );
}
workshop_end_op();
}
+/*
+ * Reciever for failure to load
+ */
+VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size )
+{
+ workshop_end_op();
+}
+
/*
* Thread which loads the model from the disk
*/
VG_STATIC void _workshop_form_load_thread( void *data )
{
- player_board_load( &workshop_form.board_model, workshop_form.model_path );
- vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 );
+ FILE *test = fopen( workshop_form.model_path, "rb" );
+ if( test ){
+ fclose( test );
+ player_board_load( &workshop_form.board_model, workshop_form.model_path );
+ vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 );
+ }
+ else{
+ vg_error( "workshop async load failed: file not found\n" );
+ vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 );
+ }
}
/*
.change = workshop_changed_description
};
ui_rect desc_entry;
- /* TODO: Tommora, new split_px_gap and split_px() */
ui_split( content, k_ui_axis_h, 8, 0, null, content );
ui_split( content, k_ui_axis_h, 28, 0, label, content );
ui_split( content, k_ui_axis_h, 28*4, 0, desc_entry, content );
char buf[32];
strcpy( buf, "page " );
int i = 5;
-
- /* TODO: for what it is, this code is getting a bit.. special */
i += highscore_intl( buf+i, workshop_form.view_published_page_id+1, 4 );
buf[ i ++ ] = '/';
i += highscore_intl( buf+i, workshop_form.view_published_page_count, 4 );
*info->len = j;
}
+VG_STATIC void vg_strsan_ascii( char *buf, u32 len )
+{
+ for( u32 i=0; i<len-1; i ++ ){
+ if( buf[i] == 0 ) return;
+
+ if( buf[i] < 32 || buf[i] > 126 ){
+ buf[i] = '?';
+ }
+ }
+ buf[len-1] = '\0';
+}
+
+#define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) )
+
+VG_STATIC void workshop_load_metadata( const char *path,
+ struct workshop_file_info *info )
+{
+ FILE *fp = fopen( path, "rb" );
+
+ if( fp ){
+ if( fread( info, sizeof( struct workshop_file_info ), 1, fp ) ){
+ VG_STRSAN_ASCII( info->author_name );
+ VG_STRSAN_ASCII( info->title );
+ }
+ fclose( fp );
+ }
+}
+
#endif /* WORKSHOP_C */