diff options
| author | Fenrir <[email protected]> | 2016-09-23 13:16:47 -0700 |
|---|---|---|
| committer | Fenrir <[email protected]> | 2016-09-23 13:19:44 -0700 |
| commit | 93760035f71b77949eff3fd876fd24d9d52c32f3 (patch) | |
| tree | 1196bc0048140089a50863d504966a73b6b28d52 | |
| parent | Prolly shouldn't flush on every write (diff) | |
| download | ctru-rs-93760035f71b77949eff3fd876fd24d9d52c32f3.tar.xz ctru-rs-93760035f71b77949eff3fd876fd24d9d52c32f3.zip | |
Add directory create and delete functions
| -rw-r--r-- | src/services/fs.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/services/fs.rs b/src/services/fs.rs index 6fbdb62..e088a6e 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -243,6 +243,45 @@ impl OpenOptions { } } +pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { + unsafe { + let wide = path.as_ref().as_os_str().encode_wide().collect::<Vec<_>>(); + let ctr_path = fsMakePath(PathType::UTF16.into(), wide.as_ptr() as _); + let r = FSUSER_CreateDirectory(arch.handle, ctr_path, FS_ATTRIBUTE_DIRECTORY); + if r < 0 { + Err(r) + } else { + Ok(()) + } + } +} + +pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { + unsafe { + let wide = path.as_ref().as_os_str().encode_wide().collect::<Vec<_>>(); + let ctr_path = fsMakePath(PathType::UTF16.into(), wide.as_ptr() as _); + let r = FSUSER_DeleteDirectory(arch.handle, ctr_path); + if r < 0 { + Err(r) + } else { + Ok(()) + } + } +} + +pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { + unsafe { + let wide = path.as_ref().as_os_str().encode_wide().collect::<Vec<_>>(); + let ctr_path = fsMakePath(PathType::UTF16.into(), wide.as_ptr() as _); + let r = FSUSER_DeleteDirectoryRecursively(arch.handle, ctr_path); + if r < 0 { + Err(r) + } else { + Ok(()) + } + } +} + pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { unsafe { let wide = path.as_ref().as_os_str().encode_wide().collect::<Vec<_>>(); |