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(id: &str, author: &str) -> Result<Filesystem>
pub fn new(id: &str, author: &str) -> Result<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>>(&mut self, path: P) -> Result<File>
pub fn open<P: AsRef<Path>>(&mut self, path: P) -> Result<File>
Opens the given path
and returns the resulting File
in read-only mode.
Sourcepub fn open_options<P: AsRef<Path>>(
&mut self,
path: P,
options: OpenOptions,
) -> Result<File>
pub fn open_options<P: AsRef<Path>>( &mut self, path: P, options: OpenOptions, ) -> Result<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>>(&mut self, path: P) -> Result<File>
pub fn create<P: AsRef<Path>>(&mut self, path: P) -> Result<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>>(&mut self, path: P) -> Result<()>
pub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
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>>(&mut self, path: P) -> Result<()>
pub fn delete<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Deletes the specified file in the user dir.
Sourcepub fn delete_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn delete_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
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>>(
&mut self,
path: P,
) -> Result<Box<dyn Iterator<Item = PathBuf>>>
pub fn read_dir<P: AsRef<Path>>( &mut self, path: P, ) -> Result<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(&mut self)
pub fn print_all(&mut self)
Prints the contents of all data directories to standard output. Useful for debugging.
Sourcepub fn log_all(&mut self)
pub fn log_all(&mut self)
Outputs the contents of all data directories,
using the “info” log level of the log
crate.
Useful for debugging.
Sourcepub fn mount(&mut self, path: &Path, readonly: bool)
pub fn mount(&mut 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>(
&mut self,
reader: R,
) -> Result<()>
pub fn add_zip_file<R: Read + Seek + 'static>( &mut self, reader: R, ) -> Result<()>
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.