@ -1,10 +1,13 @@
;; This file is somewhat misnamed. It handles taking categorized entries and processing them into a
;; format which can be exported. It also helps in cases where pure entries are desired
( import "FileHelper.cake" "FileSystem.cake"
"Dictionary.cake" "DynamicArray.cake"
"Dictionary.cake" "DynamicArray.cake" "TaskSystem.cake"
"Utilities.cake"
&comptime-only "CHelpers.cake" )
;; TODO Need infect
( add-c-search-directory-module "Dependencies/enkiTS/src" )
( c-import "<cstdio>" "<cassert>" )
( forward-declare ( struct directory-entry-userdata )
@ -177,8 +180,8 @@
( dynarray-free child-entries )
( set child-entries null ) )
( defun export-category-paths ( entries ( * directory-entry-userdata ) ;; strdict
categories ( * category-spec ) ) ;; dictionary
( def-task export-category-paths ( entries ( * directory-entry-userdata ) ;; strdict
categories ( * category-spec ) ) ;; dictionary
( var num-entries ( unsigned int ) ( strdict-length entries ) )
( unless num-entries
( return ) )
@ -258,3 +261,42 @@
( fclose ( path category-file > file-handle ) ) ) )
( dynarray-free category-out-files )
( dynarray-free sorted-entries ) )
( var g-is-export-running bool false )
( def-task on-export-complete ( entries ( * directory-entry-userdata ) ;; strdict
categories ( * category-spec ) ) ;; dictionary
( dict-free entries )
( strdict-free categories )
( fprintf stderr "Finished export\n" )
( set g-is-export-running false ) )
;; Do this on a separate thread because it takes a while. A quick scan of SDL code seems to suggest
;; this is fine. This isn't in on-export-complete because that's only on the main thread
( def-task open-userdata-system-file-explorer ( should-open bool )
( when should-open
( open-system-file-explorer g-userdata-output-dir ) ) )
( defun export-category-paths-start ( entries ( * directory-entry-userdata ) ;; strdict
categories ( * category-spec ) ;; dictionary
open-file-explorer-on-complete bool )
;; Only one can be running at a time. TODO: User feedback?
( when g-is-export-running
( fprintf stderr "Already running an export job\n" )
( return ) )
;; TODO: Use Introspection to more easily copy
( var copied-entries ( * directory-entry-userdata ) null ) ;; strdict
( var copied-categories ( * category-spec ) null ) ;; dictionary
( each-item-in-dict entries i entry ( * directory-entry-userdata )
( strdict-set-struct copied-entries ( deref entry ) ) )
( each-item-in-dict categories i category ( * category-spec )
( dict-set-struct copied-categories ( deref category ) ) )
( set g-is-export-running true )
( task-system-execute
( export-category-paths copied-entries copied-categories )
( parallel
( open-userdata-system-file-explorer open-file-explorer-on-complete )
( on-export-complete :pin-to-main-thread
copied-entries copied-categories ) ) ) )