Skip to content

Commit fd5eaef

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 f6e346f commit fd5eaef

5 files changed

Lines changed: 32 additions & 31 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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn activate_with_blueprint_ships_plugin<T: MutableLoadOrder>(
255255

256256
if let Some(index) = blueprint_ships_plugin_index {
257257
if let Some(plugin) = load_order.plugins_mut().get_mut(index) {
258-
plugin.implicitly_activate()?;
258+
plugin.set_implicitly_active_if_inactive();
259259
}
260260
}
261261

@@ -969,8 +969,7 @@ mod tests {
969969
load_order
970970
.find_plugin_mut(plugin_name)
971971
.unwrap()
972-
.implicitly_activate()
973-
.unwrap();
972+
.set_implicitly_active_if_inactive();
974973

975974
assert!(load_order.is_active(plugin_name));
976975
assert!(!load_order
@@ -1031,8 +1030,7 @@ mod tests {
10311030
load_order
10321031
.find_plugin_mut(plugin_name)
10331032
.unwrap()
1034-
.implicitly_activate()
1035-
.unwrap();
1033+
.set_implicitly_active_if_inactive();
10361034

10371035
let blueprint_ships = "BlueprintShips-Blank.esm";
10381036
copy_to_test_dir(
@@ -1240,7 +1238,7 @@ mod tests {
12401238
load_order.game_settings(),
12411239
);
12421240
let index = add(&mut load_order, blueprint_ships).unwrap();
1243-
load_order.plugins[index].implicitly_activate().unwrap();
1241+
load_order.plugins[index].set_implicitly_active_if_inactive();
12441242

12451243
let plugin_name = "Blank.esp";
12461244
assert!(load_order.is_active(plugin_name));
@@ -1294,7 +1292,7 @@ mod tests {
12941292
load_order.game_settings(),
12951293
);
12961294
let index = add(&mut load_order, blueprint_ships).unwrap();
1297-
load_order.plugins[index].implicitly_activate().unwrap();
1295+
load_order.plugins[index].set_implicitly_active_if_inactive();
12981296

12991297
let plugin_name = "Blank.esp";
13001298
assert!(load_order.is_active(plugin_name));
@@ -1319,7 +1317,7 @@ mod tests {
13191317
load_order.game_settings(),
13201318
);
13211319
let index = add(&mut load_order, blueprint_ships).unwrap();
1322-
load_order.plugins[index].implicitly_activate().unwrap();
1320+
load_order.plugins[index].set_implicitly_active_if_inactive();
13231321

13241322
std::fs::write(
13251323
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)