Skip to content

Commit 0cc05ea

Browse files
committed
[WIP] Don't unghost plugins when loading initial state
If a plugin is explicitly active then it should already be unghosted, and otherwise isn't actually active. If a plugin is implicitly active, then it's only actually implicitly active if the unghosted plugin exists. If a plugin is inactive then it can be ghosted or not. WIP because what I've implemented doesn't match the text above, but I'm also not sure that's the correct approach, it could be confusing since the ghost extension is stripped, so you could see a plugin in the load order that seems like it should be active, but it isn't because it's actually ghosted.
1 parent 23a4fe8 commit 0cc05ea

5 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/load_order/asterisk_based.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl AsteriskBasedLoadOrder {
7070
> self.game_settings.early_loading_plugins().len()
7171
}
7272

73-
fn implicitly_activate_blueprint_ships_plugins(&mut self) -> Result<(), Error> {
73+
fn implicitly_activate_blueprint_ships_plugins(&mut self) {
7474
let active_base_names: HashSet<UniCase<&str>> = self
7575
.plugins()
7676
.iter()
@@ -93,11 +93,9 @@ impl AsteriskBasedLoadOrder {
9393

9494
for index in indexes {
9595
if let Some(plugin) = self.plugins.get_mut(index) {
96-
plugin.implicitly_activate()?;
96+
plugin.set_implicitly_active_if_inactive();
9797
}
9898
}
99-
100-
Ok(())
10199
}
102100
}
103101

@@ -133,7 +131,7 @@ impl WritableLoadOrder for AsteriskBasedLoadOrder {
133131
self.add_implicitly_active_plugins()?;
134132

135133
if self.game_settings.id() == GameId::Starfield {
136-
self.implicitly_activate_blueprint_ships_plugins()?;
134+
self.implicitly_activate_blueprint_ships_plugins();
137135
}
138136

139137
hoist_masters(&mut self.plugins)?;

src/load_order/mutable.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ where
304304

305305
for plugin_name in plugin_names {
306306
if let Some(plugin) = load_order.find_plugin_mut(&plugin_name) {
307-
plugin.activate()?;
307+
// No need to un-ghost plugins since this is loading existing active
308+
// state so the plugins must already be non-ghosted.
309+
plugin.set_explicitly_active();
308310
}
309311
}
310312

@@ -769,7 +771,8 @@ fn implicitly_activate<T: MutableLoadOrder + ?Sized>(
769771
filename: &str,
770772
) -> Result<(), Error> {
771773
if let Some(plugin) = load_order.find_plugin_mut(filename) {
772-
plugin.implicitly_activate()
774+
plugin.set_implicitly_active_if_inactive();
775+
Ok(())
773776
} else {
774777
// Ignore any errors trying to load the plugin to save checking if it's
775778
// valid and then loading it if it is.

src/load_order/timestamp_based.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ impl TimestampBasedLoadOrder {
110110

111111
for plugin_name in plugin_names {
112112
if let Some(plugin) = self.find_plugin_mut(&plugin_name) {
113-
plugin.activate()?;
113+
// No need to un-ghost plugins since this is loading existing
114+
// active state so the plugins must already be non-ghosted.
115+
plugin.set_explicitly_active();
114116
}
115117
}
116118

src/load_order/writable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn activate_with_blueprint_ships_plugin<T: MutableLoadOrder>(
254254

255255
if let Some(index) = blueprint_ships_plugin_index {
256256
if let Some(plugin) = load_order.plugins_mut().get_mut(index) {
257-
plugin.implicitly_activate()?;
257+
plugin.set_implicitly_active_if_inactive();
258258
}
259259
}
260260
}
@@ -1170,7 +1170,7 @@ mod tests {
11701170
load_order.game_settings(),
11711171
);
11721172
let index = add(&mut load_order, blueprint_ships).unwrap();
1173-
load_order.plugins[index].implicitly_activate().unwrap();
1173+
load_order.plugins[index].set_implicitly_active_if_inactive();
11741174

11751175
let plugin_name = "Blank.esp";
11761176
assert!(load_order.is_active(plugin_name));
@@ -1224,7 +1224,7 @@ mod tests {
12241224
load_order.game_settings(),
12251225
);
12261226
let index = add(&mut load_order, blueprint_ships).unwrap();
1227-
load_order.plugins[index].implicitly_activate().unwrap();
1227+
load_order.plugins[index].set_implicitly_active_if_inactive();
12281228

12291229
let plugin_name = "Blank.esp";
12301230
assert!(load_order.is_active(plugin_name));
@@ -1249,7 +1249,7 @@ mod tests {
12491249
load_order.game_settings(),
12501250
);
12511251
let index = add(&mut load_order, blueprint_ships).unwrap();
1252-
load_order.plugins[index].implicitly_activate().unwrap();
1252+
load_order.plugins[index].set_implicitly_active_if_inactive();
12531253

12541254
std::fs::write(
12551255
load_order

src/plugin.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Plugin {
7878
use crate::ghostable_path::GhostablePath;
7979

8080
if active.is_active() {
81-
filepath.unghost()?
81+
filepath
8282
} else {
8383
filepath.resolve_path()?
8484
}
@@ -207,6 +207,18 @@ impl Plugin {
207207
Ok(())
208208
}
209209

210+
/// This does not un-ghost ghosted plugins.
211+
pub(crate) fn set_explicitly_active(&mut self) {
212+
self.active = ActiveState::ExplicitlyActive;
213+
}
214+
215+
pub(crate) fn set_implicitly_active_if_inactive(&mut self) {
216+
if self.active == ActiveState::Inactive {
217+
self.active = ActiveState::ImplicitlyActive;
218+
}
219+
}
220+
221+
/// This un-ghosts plugins that are currently inactive.
210222
pub fn activate(&mut self) -> Result<(), Error> {
211223
// A plugin only needs to be un-ghosted if it's currently inactive.
212224
if !self.is_active() && self.game_id.allow_plugin_ghosting() {
@@ -228,18 +240,6 @@ impl Plugin {
228240
Ok(())
229241
}
230242

231-
pub(crate) fn implicitly_activate(&mut self) -> Result<(), Error> {
232-
let was_inactive = self.active == ActiveState::Inactive;
233-
234-
self.activate()?;
235-
236-
if was_inactive {
237-
self.active = ActiveState::ImplicitlyActive;
238-
}
239-
240-
Ok(())
241-
}
242-
243243
/// This should only be called after checking that the plugin isn't
244244
/// considered implicitly active.
245245
pub fn deactivate(&mut self) {
@@ -765,7 +765,7 @@ mod tests {
765765
copy_to_test_dir("Blank.esp", "Blank.esp.ghost", &settings);
766766
let mut plugin = Plugin::new("Blank.esp", &settings).unwrap();
767767

768-
plugin.implicitly_activate().unwrap();
768+
plugin.set_implicitly_active_if_inactive();
769769

770770
assert!(plugin.is_active());
771771
assert_eq!(ActiveState::ImplicitlyActive, plugin.active);
@@ -784,7 +784,7 @@ mod tests {
784784
let mut plugin =
785785
Plugin::with_active("Blank.esp", &settings, ActiveState::ExplicitlyActive).unwrap();
786786

787-
plugin.implicitly_activate().unwrap();
787+
plugin.set_implicitly_active_if_inactive();
788788

789789
assert!(plugin.is_active());
790790
assert_eq!(ActiveState::ExplicitlyActive, plugin.active);

0 commit comments

Comments
 (0)