diff options
| author | Fenrir <[email protected]> | 2016-09-21 16:26:09 -0700 |
|---|---|---|
| committer | Fenrir <[email protected]> | 2016-09-21 16:26:09 -0700 |
| commit | 2836bc3c6e5392e48a16af85c14217c49e5baae1 (patch) | |
| tree | 9973773e0f6c64955ef302edfb656ab158d30a5a | |
| parent | Update 3ds.json (diff) | |
| download | ctru-rs-2836bc3c6e5392e48a16af85c14217c49e5baae1.tar.xz ctru-rs-2836bc3c6e5392e48a16af85c14217c49e5baae1.zip | |
Add remove_file function
| -rw-r--r-- | src/services/fs.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/services/fs.rs b/src/services/fs.rs index c19e568..188fe4c 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -77,13 +77,13 @@ impl Fs { } pub fn sdmc(&self) -> Result<Archive, i32> { - let mut handle = 0; unsafe { + let mut handle = 0; let id = ArchiveID::Sdmc; let path = fsMakePath(PathType::Empty.into(), ptr::null() as _); - let ret = FSUSER_OpenArchive(&mut handle, id.into(), path); - if ret < 0 { - Err(ret) + let r = FSUSER_OpenArchive(&mut handle, id.into(), path); + if r < 0 { + Err(r) } else { Ok(Archive { handle: handle, @@ -211,9 +211,9 @@ impl OpenOptions { let mut file_handle = 0; let wide = path.as_os_str().encode_wide().collect::<Vec<_>>(); let ctr_path = fsMakePath(PathType::UTF16.into(), wide.as_ptr() as _); - let ret = FSUSER_OpenFile(&mut file_handle, self.arch_handle, ctr_path, flags, 0); - if ret < 0 { - Err(ret) + let r = FSUSER_OpenFile(&mut file_handle, self.arch_handle, ctr_path, flags, 0); + if r < 0 { + Err(r) } else { Ok(File { handle: file_handle, @@ -236,6 +236,19 @@ impl OpenOptions { } } +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<_>>(); + let ctr_path = fsMakePath(PathType::UTF16.into(), wide.as_ptr() as _); + let r = FSUSER_DeleteFile(arch.handle, ctr_path); + if r < 0 { + Err(r) + } else { + Ok(()) + } + } +} + impl Drop for Fs { fn drop(&mut self) { unsafe { |