Skip to content

Commit

Permalink
0.5.2: Fixed issue where non-default profile pluginListPath was bei…
Browse files Browse the repository at this point in the history
…ng ignored during mod deployment.
  • Loading branch information
lVlyke committed Dec 3, 2023
1 parent ac1a789 commit f8b90ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Mychal Thompson <mychal.r.thompson@gmail.com>",
"repository": "https://github.com/lVlyke/starfield-mod-loader",
"license": "GPL-3.0",
"version": "0.5.1",
"version": "0.5.2",
"main": "electron.js",
"scripts": {
"app:build-dist": "npm run build:release && npm run package",
Expand Down
60 changes: 24 additions & 36 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,50 +1094,38 @@ class ElectronLoader {

log.info("Deploying profile", profile.name);

const gameDb = this.loadGameDatabase();
const gameDetails = gameDb[profile.gameId];

// Deploy plugin list
if (deployPlugins && profile.plugins.length > 0) {
const pluginListPaths = gameDetails?.pluginListPaths ?? [];
let wrotePluginList = false;

for (let pluginListPath of pluginListPaths) {
pluginListPath = path.resolve(this.#expandPath(pluginListPath));

if (fs.existsSync(path.dirname(pluginListPath))) {
// Backup any existing plugins file
if (fs.existsSync(pluginListPath)) {
const backupFile = `${pluginListPath}.sml_bak`;
if (fs.existsSync(backupFile)) {
fs.moveSync(backupFile, `${backupFile}_${new Date().toISOString().replace(/[:.]/g, "_")}`);
}

fs.copyFileSync(pluginListPath, backupFile);
const pluginListPath = profile.pluginListPath ? path.resolve(this.#expandPath(profile.pluginListPath)) : "";

if (pluginListPath && fs.existsSync(path.dirname(pluginListPath))) {
// Backup any existing plugins file
if (fs.existsSync(pluginListPath)) {
const backupFile = `${pluginListPath}.sml_bak`;
if (fs.existsSync(backupFile)) {
fs.moveSync(backupFile, `${backupFile}_${new Date().toISOString().replace(/[:.]/g, "_")}`);
}

// TODO - Allow customization of this logic per-gameid
const header = `# This file was generated automatically by Starfield Mod Loader for profile "${profile.name}"\n`
const pluginsListData = profile.plugins.reduce((data, pluginRef) => {
if (pluginRef.enabled) {
data += "*";
}
fs.copyFileSync(pluginListPath, backupFile);
}

data += pluginRef.plugin;
data += "\n";
return data;
}, header);
// TODO - Allow customization of this logic per-gameid
const header = `# This file was generated automatically by Starfield Mod Loader for profile "${profile.name}"\n`
const pluginsListData = profile.plugins.reduce((data, pluginRef) => {
if (pluginRef.enabled) {
data += "*";
}

fs.writeFileSync(pluginListPath, pluginsListData);
data += pluginRef.plugin;
data += "\n";
return data;
}, header);

wrotePluginList = true;
profileModFiles.push(pluginListPath);
break;
}
}
fs.writeFileSync(pluginListPath, pluginsListData);

if (!wrotePluginList) {
throw new Error("Unable to write plugins list.");
profileModFiles.push(pluginListPath);
} else {
throw new Error(`Unable to write plugins list: path ${pluginListPath} does not exist.`);
}
}

Expand Down

0 comments on commit f8b90ce

Please sign in to comment.