瀏覽代碼

Add sdl3_filesystem.odin and sdl3_storage.odin

gingerBill 7 月之前
父節點
當前提交
84cb2440b2
共有 2 個文件被更改,包括 137 次插入0 次删除
  1. 67 0
      vendor/sdl3/sdl3_filesystem.odin
  2. 70 0
      vendor/sdl3/sdl3_storage.odin

+ 67 - 0
vendor/sdl3/sdl3_filesystem.odin

@@ -0,0 +1,67 @@
+package sdl3
+
+import "core:c"
+
+Folder :: enum c.int {
+	HOME,        /**< The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents. */
+	DESKTOP,     /**< The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons. */
+	DOCUMENTS,   /**< User document files, possibly application-specific. This is a good place to save a user's projects. */
+	DOWNLOADS,   /**< Standard folder for user files downloaded from the internet. */
+	MUSIC,       /**< Music files that can be played using a standard music player (mp3, ogg...). */
+	PICTURES,    /**< Image files that can be displayed using a standard viewer (png, jpg...). */
+	PUBLICSHARE, /**< Files that are meant to be shared with other users on the same computer. */
+	SAVEDGAMES,  /**< Save files for games. */
+	SCREENSHOTS, /**< Application screenshots. */
+	TEMPLATES,   /**< Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt".  Any file in the Templates folder can be used as a starting point for a new file. */
+	VIDEOS,      /**< Video files that can be played using a standard video player (mp4, webm...). */
+}
+
+PathType :: enum c.int {
+	NONE,      /**< path does not exist */
+	FILE,      /**< a normal file */
+	DIRECTORY, /**< a directory */
+	OTHER,     /**< something completely different like a device node (not a symlink, those are always followed) */
+}
+
+PathInfo :: struct {
+	type:        PathType,  /**< the path type */
+	size:        Uint64,    /**< the file size in bytes */
+	create_time: Time,      /**< the time when the path was created */
+	modify_time: Time,      /**< the last time the path was modified */
+	access_time: Time,      /**< the last time the path was read */
+}
+
+
+GlobFlags :: distinct bit_set[GlobFlag; Uint32]
+GlobFlag :: enum Uint32 {
+	CASEINSENSITIVE  = 0,
+}
+
+GLOB_CASEINSENSITIVE :: GlobFlags{.CASEINSENSITIVE}
+
+EnumerationResult :: enum c.int {
+	CONTINUE,   /**< Value that requests that enumeration continue. */
+	SUCCESS,    /**< Value that requests that enumeration stop, successfully. */
+	FAILURE,    /**< Value that requests that enumeration stop, as a failure. */
+}
+
+
+EnumerateDirectoryCallback :: #type proc "c" (userdata: rawptr, dirname, fname: cstring) -> EnumerationResult
+
+
+
+@(default_calling_convention="c", link_prefix="SDL_")
+foreign lib {
+
+	GetBasePath         :: proc() -> cstring ---
+	GetPrefPath         :: proc(org, app: cstring) -> [^]c.char ---
+	GetUserFolder       :: proc(folder: Folder) -> cstring ---
+	CreateDirectory     :: proc(path: cstring) -> bool ---
+	EnumerateDirectory  :: proc(path: cstring, callback: EnumerateDirectoryCallback, userdata: rawptr) -> bool ---
+	RemovePath          :: proc(path: cstring) -> bool ---
+	RenamePath          :: proc(oldpath, newpath: cstring) -> bool ---
+	CopyFile            :: proc(oldpath, newpath: cstring) -> bool ---
+	GetPathInfo         :: proc(path: cstring, info: ^PathInfo) -> bool ---
+	GlobDirectory       :: proc(path: cstring, pattern: cstring, flags: GlobFlags, count: ^c.int) -> [^][^]c.char ---
+	GetCurrentDirectory :: proc() -> [^]c.char ---
+}

+ 70 - 0
vendor/sdl3/sdl3_storage.odin

@@ -0,0 +1,70 @@
+package sdl3
+
+import "core:c"
+
+StorageInterface :: struct {
+	/* The version of this interface */
+	version: Uint32,
+
+	/* Called when the storage is closed */
+	close: proc "c" (userdata: rawptr) -> bool,
+
+	/* Optional, returns whether the storage is currently ready for access */
+	ready: proc "c" (userdata: rawptr) -> bool,
+
+	/* Enumerate a directory, optional for write-only storage */
+	enumerate: proc "c" (userdata: rawptr, path: cstring, callback: EnumerateDirectoryCallback, callback_userdata: rawptr) -> bool,
+
+	/* Get path information, optional for write-only storage */
+	info: proc "c" (userdata: rawptr, path: cstring, info: ^PathInfo) -> bool,
+
+	/* Read a file from storage, optional for write-only storage */
+	read_file: proc "c" (userdata: rawptr, path: cstring, destination: rawptr, length: Uint64) -> bool,
+
+	/* Write a file to storage, optional for read-only storage */
+	write_file: proc "c" (userdata: rawptr, path: cstring, source: rawptr, length: Uint64) -> bool,
+
+	/* Create a directory, optional for read-only storage */
+	mkdir: proc "c" (userdata: rawptr, path: cstring) -> bool,
+
+	/* Remove a file or empty directory, optional for read-only storage */
+	remove: proc "c" (userdata: rawptr, path: cstring) -> bool,
+
+	/* Rename a path, optional for read-only storage */
+	rename: proc "c" (userdata: rawptr, oldpath, newpath: cstring) -> bool,
+
+	/* Copy a file, optional for read-only storage */
+	copy: proc "c" (userdata: rawptr, oldpath, newpath: cstring) -> bool,
+
+	/* Get the space remaining, optional for read-only storage */
+	space_remaining: proc "c" (userdata: rawptr) -> Uint64,
+}
+
+#assert(
+        (size_of(StorageInterface) == 48 && size_of(rawptr) == 4) ||
+        (size_of(StorageInterface) == 96 && size_of(rawptr) == 8),
+)
+
+Storage :: struct {}
+
+
+@(default_calling_convention="c", link_prefix="SDL_")
+foreign lib {
+	OpenTitleStorage          :: proc(override: cstring, props: PropertiesID) -> ^Storage ---
+	OpenUserStorage           :: proc(org, app: cstring, props: PropertiesID) -> ^Storage ---
+	OpenFileStorage           :: proc(path: cstring) -> ^Storage ---
+	OpenStorage               :: proc(iface: ^StorageInterface, userdata: rawptr) -> ^Storage ---
+	CloseStorage              :: proc(storage: ^Storage) -> bool ---
+	StorageReady              :: proc(storage: ^Storage) -> bool ---
+	GetStorageFileSize        :: proc(storage: ^Storage, path: cstring, length: ^Uint64) -> bool ---
+	ReadStorageFile           :: proc(storage: ^Storage, path: cstring, destination: rawptr, length: Uint64) -> bool ---
+	WriteStorageFile          :: proc(storage: ^Storage, path: cstring, source:      rawptr, length: Uint64) -> bool ---
+	CreateStorageDirectory    :: proc(storage: ^Storage, path: cstring) -> bool ---
+	EnumerateStorageDirectory :: proc(storage: ^Storage, path: cstring, callback: EnumerateDirectoryCallback, userdata: rawptr) -> bool ---
+	RemoveStoragePath         :: proc(storage: ^Storage, path: cstring) -> bool ---
+	RenameStoragePath         :: proc(storage: ^Storage, oldpath, newpath: cstring) -> bool ---
+	CopyStorageFile           :: proc(storage: ^Storage, oldpath, newpath: cstring) -> bool ---
+	GetStoragePathInfo        :: proc(storage: ^Storage, path: cstring, info: ^PathInfo) -> bool ---
+	GetStorageSpaceRemaining  :: proc(storage: ^Storage) -> Uint64 ---
+	GlobStorageDirectory      :: proc(storage: ^Storage, path: cstring, pattern: cstring, flags: GlobFlags, count: ^c.int) -> [^][^]c.char ---
+}