diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-06-30 16:54:43 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-06-30 16:54:43 +1200 |
commit | 1380a14177fc07f9d09df937b20487137aab4d4f (patch) | |
tree | 914f1f2aeb7d1cb7456f0562abf2455e769fc5e9 | |
parent | c99d7600c5add0829333c2d844ca03a5112a27d1 (diff) | |
download | bedrock-pc-1380a14177fc07f9d09df937b20487137aab4d4f.zip |
Set file operation success flag when ascending and descending
This is to allow the program to detect whether the previous ascend or
descend operation succeeded.
-rw-r--r-- | src/devices.rs | 2 | ||||
-rw-r--r-- | src/devices/file.rs | 27 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/devices.rs b/src/devices.rs index e0c4280..864e1ba 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -204,7 +204,7 @@ impl DeviceBus for StandardDevices { // 0x8F => todo!(), // File 0x90 => read_b!(self.file.entry.is_some()), - 0x91 => read_b!(self.file.move_success), + 0x91 => read_b!(self.file.op_success), 0x92 => self.file.name_buffer.read_byte(), 0x93 => read_b!(self.file.entry_type()), 0x94 => self.file.read_byte(), diff --git a/src/devices/file.rs b/src/devices/file.rs index 234da7c..e8db41a 100644 --- a/src/devices/file.rs +++ b/src/devices/file.rs @@ -32,7 +32,7 @@ pub struct FileDevice { pub entry: Option<(Entry, PathBuf)>, - pub move_success: bool, + pub op_success: bool, pub new_pointer: u32, pub new_length: u32, @@ -57,7 +57,7 @@ impl FileDevice { entry: None, - move_success: false, + op_success: false, new_pointer: 0, new_length: 0, @@ -137,22 +137,22 @@ impl FileDevice { if let Some((_, source)) = &self.entry { if is_blank_path(&dest) { match self.enable_delete { - true => self.move_success = delete_entry(&source), - false => self.move_success = false, + true => self.op_success = delete_entry(&source), + false => self.op_success = false, } } else if let Ok(destination) = self.attach_base(&dest) { match self.enable_move { - true => self.move_success = move_entry(&source, &destination), - false => self.move_success = false, + true => self.op_success = move_entry(&source, &destination), + false => self.op_success = false, } } } else { if is_blank_path(&dest) { - self.move_success = false; + self.op_success = false; } else if let Ok(destination) = self.attach_base(&dest) { match self.enable_create { - true => self.move_success = create_file(&destination), - false => self.move_success = false, + true => self.op_success = create_file(&destination), + false => self.op_success = false, } } } @@ -164,12 +164,10 @@ impl FileDevice { pub fn ascend_to_parent(&mut self) { if let Some((_, path)) = &self.entry { if let Some(parent_path) = path.parent() { - let path = parent_path.to_owned(); - let _ = self.open_entry(&path); + self.op_success = self.open_entry(&parent_path.to_owned()).is_ok(); } } else { - let default_path = self.default_path.to_owned(); - let _ = self.open_entry(&default_path); + self.op_success = self.open_entry(&self.default_path.to_owned()).is_ok(); } } @@ -178,8 +176,7 @@ impl FileDevice { if let Some((Entry::Directory(listing), _)) = &self.entry { if let Some(child_path) = listing.child_path() { if let Ok(child_path) = self.attach_base(&child_path) { - let child_path = child_path.to_owned(); - let _ = self.open_entry(&child_path); + self.op_success = self.open_entry(&child_path).is_ok(); } }; } |