-/*
- * Async thread for rearranging files into a reasonable workshop folder
- */
-struct workshop_package_thread_args{
- PublishedFileId_t file_id;
-
- u64_steamid steamid;
- char username[32];
-};
-VG_STATIC void _workshop_package_thread( void *_args )
-{
- struct workshop_package_thread_args *args = _args;
- PublishedFileId_t file_id = args->file_id;
-
- vg_info( "Packaging workshop content folder\n" );
-
- vg_async_item *call = vg_async_alloc( sizeof(struct workshop_package_info) );
- struct workshop_package_info *info = call->payload;
- info->publishing_file_id = file_id;
- info->failure_reason = "Unknown failure reason";
-
- /* build content folder path */
- snprintf( info->abs_content_folder, 1024, "%smodels/boards/workshop/%lu",
- vg.base_path, file_id );
-
- /* build content file path */
- snprintf( info->abs_content_file, 1024, "%s/%s", info->abs_content_folder,
- "board.mdl" );
-
- /* build workshop preview file path */
- snprintf( info->abs_preview_image, 1024, "%sworkshop_preview.jpg",
- vg.base_path );
-
- /* arange files */
- if( !vg_mkdir( info->abs_content_folder ) ){
- info->success = 0;
- info->failure_reason = "Could not make directory.";
- vg_async_dispatch( call, workshop_form_async_package_complete );
- return;
- }
-
- vg_linear_clear( vg_mem.scratch );
- if( !vg_file_copy( workshop_form.model_path, info->abs_content_file,
- vg_mem.scratch ) ){
- info->success = 0;
- info->failure_reason = "Copy file failed.";
- vg_async_dispatch( call, workshop_form_async_package_complete );
- 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 );
-}
-
-/*
- * Begins the packaging thread using file_id. Thread definition above.
- */
-VG_STATIC void workshop_package_submission( PublishedFileId_t file_id )
-{
- vg_linear_clear( vg_mem.scratch );
- struct workshop_package_thread_args *args =
- 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 );
-}
-