|
|
@ -53,6 +53,7 @@ pub struct Archive { |
|
|
|
|
|
|
|
|
|
|
|
pub struct File { |
|
|
|
pub struct File { |
|
|
|
handle: u32, |
|
|
|
handle: u32, |
|
|
|
|
|
|
|
offset: u64, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub struct OpenOptions { |
|
|
|
pub struct OpenOptions { |
|
|
@ -111,6 +112,29 @@ impl Archive { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl File { |
|
|
|
|
|
|
|
pub fn read(&mut self, buf: &mut [u8]) -> Result<u32, i32> { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
|
|
|
let mut n_read = 0; |
|
|
|
|
|
|
|
let r = FSFILE_Read( |
|
|
|
|
|
|
|
self.handle, |
|
|
|
|
|
|
|
&mut n_read, |
|
|
|
|
|
|
|
self.offset, |
|
|
|
|
|
|
|
buf.as_mut_ptr() as _, |
|
|
|
|
|
|
|
buf.len() as u32 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.offset += n_read as u64; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if r < 0 { |
|
|
|
|
|
|
|
Err(r) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Ok(n_read) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl OpenOptions { |
|
|
|
impl OpenOptions { |
|
|
|
pub fn read(&mut self, read: bool) -> &mut OpenOptions { |
|
|
|
pub fn read(&mut self, read: bool) -> &mut OpenOptions { |
|
|
|
self.read = read; |
|
|
|
self.read = read; |
|
|
@ -140,7 +164,10 @@ impl OpenOptions { |
|
|
|
if ret < 0 { |
|
|
|
if ret < 0 { |
|
|
|
Err(ret) |
|
|
|
Err(ret) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Ok(File { handle: file_handle }) |
|
|
|
Ok(File { |
|
|
|
|
|
|
|
handle: file_handle, |
|
|
|
|
|
|
|
offset: 0, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|