From 2836bc3c6e5392e48a16af85c14217c49e5baae1 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Wed, 21 Sep 2016 16:26:09 -0700 Subject: [PATCH] Add remove_file function --- src/services/fs.rs | 27 ++++++++++++++++++++------- 1 file 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 { - 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::>(); 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>(arch: &Archive, path: P) -> Result<(), i32> { + unsafe { + let wide = path.as_ref().as_os_str().encode_wide().collect::>(); + 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 {