Struct ggez::filesystem::Filesystem
source · pub struct Filesystem { /* private fields */ }
Expand description
A structure that contains the filesystem state and cache.
Implementations§
source§impl Filesystem
impl Filesystem
sourcepub fn new<P: AsRef<Path>, Q: AsRef<Path>>(
id: &str,
author: &str,
resources_dir_name: P,
resources_zip_name: Q
) -> GameResult<Filesystem>
pub fn new<P: AsRef<Path>, Q: AsRef<Path>>( id: &str, author: &str, resources_dir_name: P, resources_zip_name: Q ) -> GameResult<Filesystem>
Create a new Filesystem
instance, using the given id
and (on
some platforms) the author
as a portion of the user
directory path. This function is called automatically by
ggez, the end user should never need to call it.
sourcepub fn open<P: AsRef<Path>>(&self, path: P) -> GameResult<File>
pub fn open<P: AsRef<Path>>(&self, path: P) -> GameResult<File>
Opens the given path
and returns the resulting File
in read-only mode.
sourcepub fn open_options<P: AsRef<Path>>(
&self,
path: P,
options: OpenOptions
) -> GameResult<File>
pub fn open_options<P: AsRef<Path>>( &self, path: P, options: OpenOptions ) -> GameResult<File>
Opens a file in the user directory with the given
filesystem::OpenOptions
.
Note that even if you open a file read-write, it can only
write to files in the “user” directory.
sourcepub fn create<P: AsRef<Path>>(&self, path: P) -> GameResult<File>
pub fn create<P: AsRef<Path>>(&self, path: P) -> GameResult<File>
Creates a new file in the user directory and opens it to be written to, truncating it if it already exists.
sourcepub fn create_dir<P: AsRef<Path>>(&self, path: P) -> GameResult
pub fn create_dir<P: AsRef<Path>>(&self, path: P) -> GameResult
Create an empty directory in the user dir with the given name. Any parents to that directory that do not exist will be created.
sourcepub fn delete<P: AsRef<Path>>(&self, path: P) -> GameResult
pub fn delete<P: AsRef<Path>>(&self, path: P) -> GameResult
Deletes the specified file in the user dir.
sourcepub fn delete_dir<P: AsRef<Path>>(&self, path: P) -> GameResult
pub fn delete_dir<P: AsRef<Path>>(&self, path: P) -> GameResult
Deletes the specified directory in the user dir, and all its contents!
sourcepub fn exists<P: AsRef<Path>>(&self, path: P) -> bool
pub fn exists<P: AsRef<Path>>(&self, path: P) -> bool
Check whether a file or directory exists.
sourcepub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
pub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
Check whether a path points at a directory.
sourcepub fn read_dir<P: AsRef<Path>>(
&self,
path: P
) -> GameResult<Box<dyn Iterator<Item = PathBuf>>>
pub fn read_dir<P: AsRef<Path>>( &self, path: P ) -> GameResult<Box<dyn Iterator<Item = PathBuf>>>
Returns a list of all files and directories in the resource directory, in no particular order.
Lists the base directory if an empty path is given.
sourcepub fn print_all(&self)
pub fn print_all(&self)
Prints the contents of all data directories to standard output. Useful for debugging.
sourcepub fn log_all(&self)
pub fn log_all(&self)
Outputs the contents of all data directories,
using the “info” log level of the log
crate.
Useful for debugging.
sourcepub fn mount(&self, path: &Path, readonly: bool)
pub fn mount(&self, path: &Path, readonly: bool)
Adds the given (absolute) path to the list of directories it will search to look for resources.
You probably shouldn’t use this in the general case, since it is
harder than it looks to make it bulletproof across platforms.
But it can be very nice for debugging and dev purposes, such as
by pushing $CARGO_MANIFEST_DIR/resources
to it
sourcepub fn add_zip_file<R: Read + Seek + 'static>(&self, reader: R) -> GameResult
pub fn add_zip_file<R: Read + Seek + 'static>(&self, reader: R) -> GameResult
Adds any object that implements Read + Seek as a zip file.
Note: This is not intended for system files for the same reasons as
for .mount()
. Rather, it can be used to read zip files from sources
such as std::io::Cursor::new(includes_bytes!(...))
in order to embed
resources into the game’s executable.
sourcepub fn read_config(&self) -> GameResult<Conf>
pub fn read_config(&self) -> GameResult<Conf>
Looks for a file named /conf.toml
in any resource directory and
loads it if it finds it.
If it can’t read it for some reason, returns an error.
sourcepub fn write_config(&self, conf: &Conf) -> GameResult
pub fn write_config(&self, conf: &Conf) -> GameResult
Takes a Conf
object and saves it to the user directory,
overwriting any file already there.
sourcepub fn resources_dir(&self) -> &Path
pub fn resources_dir(&self) -> &Path
Returns the full path to the resource directory (even if it doesn’t exist)
sourcepub fn user_config_dir(&self) -> &Path
pub fn user_config_dir(&self) -> &Path
Return the full path to the user config directory.
sourcepub fn user_data_dir(&self) -> &Path
pub fn user_data_dir(&self) -> &Path
Return the full path to the user data directory.