Skip to content

Commit

Permalink
fix for not correctly handling switching to content mod after deletin…
Browse files Browse the repository at this point in the history
…g the symbolic link of that mod in data
  • Loading branch information
Shazbot committed Apr 17, 2023
1 parent d1e075b commit 11753f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wh3mm",
"productName": "wh3mm",
"version": "1.34.1",
"version": "1.34.2",
"description": "WH3 Mod Manager",
"main": ".webpack/main",
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,19 @@ const appSlice = createSlice({
const removedMod = state.currentPreset.mods.find((iterMod) => iterMod.path == modPath);
if (!removedMod) return;

if (removedMod.isEnabled) {
// if this mod is in data and the actual mod is in content just switch to the content mod
const dataMod =
removedMod.isInData &&
state.allMods.find((iterMod) => !iterMod.isInData && iterMod.name == removedMod.name);

if (dataMod) {
state.currentPreset.mods.push(dataMod);
if (removedMod.isEnabled) {
dataMod.isEnabled = true;
}
}

if (!dataMod && removedMod.isEnabled) {
removedEnabledModPaths.push(removedMod.path);
}

Expand Down
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ if (!gotTheLock) {
});

ipcMain.on("copyToData", async (event, modPathsToCopy?: string[]) => {
if (!appData.gamePath) return;
console.log("copyToData: modPathsToCopy:", modPathsToCopy);
const mods = await getMods(log);
let withoutDataMods = mods.filter((mod) => !mod.isInData);
Expand All @@ -662,7 +663,8 @@ if (!gotTheLock) {
`COPYING ${mod.path} to ${appData.gamePath}\\data\\${mod.name}`
);

return fs.copyFile(mod.path, `${appData.gamePath}\\data\\${mod.name}`);
if (!appData.gamePath) throw new Error("game path not set");
return fs.copyFile(mod.path, nodePath.join(appData.gamePath, "/data/", mod.name));
});

await Promise.allSettled(copyPromises);
Expand All @@ -678,16 +680,26 @@ if (!gotTheLock) {
modPathsToCopy.some((modPathToCopy) => modPathToCopy == mod.path)
);
}

if (!appData.gamePath) return;
const pathsOfNewSymLinks = withoutDataMods.map((mod) =>
nodePath.join(appData.gamePath ?? "", "/data/", mod.name)
);
const copyPromises = withoutDataMods.map((mod) => {
mainWindow?.webContents.send(
"handleLog",
`CREATING SYMLINK of ${mod.path} to ${appData.gamePath}\\data\\${mod.name}`
);

return fsExtra.symlink(mod.path, `${appData.gamePath}\\data\\${mod.name}`);
if (!appData.gamePath) throw new Error("game path not set");
return fsExtra.symlink(mod.path, nodePath.join(appData.gamePath, "/data/", mod.name));
});

await Promise.allSettled(copyPromises);

for (const pathsOfNewSymLink of pathsOfNewSymLinks) {
onNewPackFound(pathsOfNewSymLink);
}
// getAllMods();
});

Expand Down Expand Up @@ -720,6 +732,10 @@ if (!gotTheLock) {
});

await Promise.allSettled(deletePromises);

for (const deletedSymLink of symLinksToDelete) {
onPackDeleted(deletedSymLink.path);
}
// getAllMods();
});

Expand Down

0 comments on commit 11753f5

Please sign in to comment.