Skip to content

Commit d1755f7

Browse files
committed
- Fixed issue where restoring deeply nested external game files caused other game files to inadvertently be deleted by overwriting the existing outer dir with the backup dir instead of merging the two dirs.
- Fixed config path for Game Pass version of Oblivion Remastered. - Log text can now be selected.
1 parent 1fcfd89 commit d1755f7

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

game-db.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"rootDir": "C:\\XboxGames\\The Elder Scrolls IV- Oblivion Remastered\\Content",
118118
"modDir": ".",
119119
"pluginListPath": "OblivionRemastered\\Content\\Dev\\ObvData\\Data\\Plugins.txt",
120-
"configFilePath": "%USERPROFILE%\\Documents\\My Games\\Oblivion Remastered\\Saved\\Config\\Windows",
120+
"configFilePath": "%USERPROFILE%\\Documents\\My Games\\Oblivion Remastered\\Saved\\Config\\WinGDK",
121121
"saveFolderPath": "%USERPROFILE%\\Documents\\My Games\\Oblivion Remastered\\Saved\\SaveGames"
122122
},
123123
{

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Mychal Thompson <mychal.r.thompson@gmail.com>",
44
"repository": "https://github.com/lVlyke/stellar-mod-loader",
55
"license": "GPL-3.0",
6-
"version": "0.13.0",
6+
"version": "0.13.1",
77
"main": "electron.js",
88
"scripts": {
99
"app:build-dist-debug": "npm run build && npm run package",

src/app/components/app-log/app-log.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
}
3232
}
3333

34+
&, * {
35+
user-select: all;
36+
}
37+
3438
.log-level {
3539
font-weight: 600;
3640
font-size: 1.1em;

src/electron.js

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const path = require("path");
4444
const os = require("os");
4545
const { exec } = require("child_process");
4646
const fs = require("fs-extra");
47+
const fsPromises = require("fs/promises");
4748
const Seven = require("node-7z");
4849
const sevenBin = require("7zip-bin");
4950
const which = require("which");
@@ -3293,6 +3294,8 @@ class ElectronLoader {
32933294
const gameDetails = this.#getGameDetails(profile.gameId);
32943295
// Substitute variables for profile
32953296
const gameActionCmd = template(gameAction.actionScript)({ ...profile, gameDetails });
3297+
3298+
log.info("Running game action: ", gameActionCmd);
32963299

32973300
// Run the action
32983301
try {
@@ -3415,9 +3418,14 @@ class ElectronLoader {
34153418

34163419
if (fs.existsSync(destFilePath)) {
34173420
if (extFilesList?.includes(modFile)) {
3418-
// Backup original external file to temp directory for deploy and override
3419-
fs.moveSync(destFilePath, path.join(extFilesBackupDir, modFile));
3420-
remove(extFilesList, extFile => extFile === modFile);
3421+
if (!shouldCopy) {
3422+
log.warn("Original file to backup is a directory, this should not happen.");
3423+
} else {
3424+
// Backup original external file to temp directory for deploy and override
3425+
fs.moveSync(destFilePath, path.join(extFilesBackupDir, modFile));
3426+
remove(extFilesList, extFile => extFile === modFile);
3427+
}
3428+
34213429
} else {
34223430
// Don't override deployed files
34233431
shouldCopy = false;
@@ -3753,8 +3761,13 @@ class ElectronLoader {
37533761
// Recursively remove empty parent directories
37543762
let existingDir = path.dirname(fullExistingPath);
37553763
while (existingDir !== profile.gameInstallation.modDir && fs.existsSync(existingDir) && fs.readdirSync(existingDir).length === 0) {
3756-
fs.rmdirSync(existingDir);
3757-
existingDir = path.dirname(existingDir);
3764+
try {
3765+
fs.rmdirSync(existingDir);
3766+
existingDir = path.dirname(existingDir);
3767+
} catch (error) {
3768+
log.error("Failed to remove dir", existingDir, error);
3769+
break;
3770+
}
37583771
}
37593772
});
37603773

@@ -3776,25 +3789,38 @@ class ElectronLoader {
37763789

37773790
// Restore original external files, if any were moved
37783791
for (const extFilesBackupDir of extFilesBackupDirs) {
3779-
if (fs.existsSync(extFilesBackupDir)) {
3780-
const backupTransfers = fs.readdirSync(extFilesBackupDir).map((backupFile) => {
3781-
const backupSrc = path.join(extFilesBackupDir, backupFile);
3782-
const backupDest = path.join(path.dirname(extFilesBackupDir), backupFile);
3792+
if (await fs.exists(extFilesBackupDir)) {
3793+
const backupEntries = await fs.readdir(extFilesBackupDir);
37833794

3784-
if (fs.existsSync(backupDest)) {
3785-
fs.removeSync(backupDest);
3786-
}
3795+
for (const backupEntry of backupEntries) {
3796+
const backupSrc = path.join(extFilesBackupDir, backupEntry);
3797+
const backupSrcIsDir = (await fs.lstat(backupSrc)).isDirectory();
3798+
const backupDest = path.join(path.dirname(extFilesBackupDir), backupEntry);
3799+
const backupDestExists = await fs.exists(backupDest);
3800+
const backupDestIsDir = backupDestExists && (await fs.lstat(backupDest)).isDirectory();
3801+
3802+
if (backupDestIsDir) {
3803+
if (backupSrcIsDir) {
3804+
log.info("Merging restored game file backups with existing directory.");
37873805

3788-
// Use hardlinks for faster file restoration in link mode
3789-
if (profile.modLinkMode && !fs.lstatSync(backupSrc).isDirectory()) {
3790-
// TODO - Recursively do this when encountering directories
3791-
return fs.link(backupSrc, backupDest);
3806+
await fsPromises.cp(backupSrc, backupDest, { recursive: true });
3807+
} else {
3808+
throw new Error("Backup file is not a directory but write dest is. This should not happen.");
3809+
}
37923810
} else {
3793-
return fs.copy(backupSrc, backupDest);
3794-
}
3795-
});
3811+
if (backupDestExists) {
3812+
await fs.remove(backupDest);
3813+
}
37963814

3797-
await Promise.all(backupTransfers);
3815+
if (profile.modLinkMode && !backupSrcIsDir) {
3816+
// Use hardlinks for faster file restoration in link mode
3817+
// TODO - Recursively do this when encountering directories
3818+
await fs.link(backupSrc, backupDest);
3819+
} else {
3820+
await fs.copy(backupSrc, backupDest);
3821+
}
3822+
}
3823+
}
37983824
}
37993825
}
38003826

0 commit comments

Comments
 (0)