Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
Add shortcut key to mods.json, add dow mod installer icon to desktop, transform tyranids mod into zip file, removed progress bar
  • Loading branch information
Kazon Wilson committed Jul 17, 2020
1 parent f4d393f commit 4580131
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 38 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ I personally use this app to ease the set up process for the 7+ group of friends
## Usage

1. Download the latest version of Dow Mod Installer from the [releases page](https://github.com/kwilson21/DoW_Mod_Installer/releases)
2. Extract `DoW Mod Installer-1.0.0-win.zip` into a folder
2. Extract `DoW Mod Installer-2.0.1-win.zip` into a folder
3. Run `DoW Mod Installer.exe` as administrator
4. Make sure your DoW directory is correct, if not search for the correct directory
5. Download and search for each individual mod file
Expand All @@ -32,6 +32,7 @@ Users are free to modify the `mods.json` with their own mods, which they can the
| `download_link` | `string` | A downlink link to the mod |
| `extract_locations` | `list of string` | A list of locations in the DoW Directory to extract to |
| `modifiers` | `list of string` | A list of values to be passed directly to 7zip as a command line argument when extracting the mod see the [7zip command line documentation](https://sevenzip.osdn.jp/chm/cmdline/index.htm) for more info. |
| `shortcut` | `string` | A file name used to create a shortcut on the user's desktop |

## Authors

Expand Down
7 changes: 4 additions & 3 deletions mods.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
{
"file_name": "DoW_Mod_Manager_v2.0.1.zip",
"download_link": "https://github.com/Fragjacker/DoW-Mod-Manager/releases/download/v2.0.1/DoW_Mod_Manager_v2.0.1.zip"
"download_link": "https://github.com/Fragjacker/DoW-Mod-Manager/releases/download/v2.0.1/DoW_Mod_Manager_v2.0.1.zip",
"shortcut": "DoW Mod Manager v2.0.1.exe"
},
{
"file_name": "Red_I_Map_Compilation_Revision_III.zip",
Expand Down Expand Up @@ -47,7 +48,7 @@
"download_link": "https://www.mediafire.com/file/uuoa4a8x1fvxovf/ChaosDaemons2.0.2.zip/file"
},
{
"file_name": "Tyranid_Mod_0.5b2_Installer.exe",
"download_link": "https://www.moddb.com/mods/tyranid-mod/downloads/tyranid-mod-v05b2-for-soulstorm"
"file_name": "Tyranid_Mod_0.5b2_Installer.zip",
"download_link": "https://www.mediafire.com/file/8c0ue9ytbky1rur/Tyranid_Mod_0.5b2_Installer.zip/file"
}
]
102 changes: 68 additions & 34 deletions renderer/components/Mods.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import isArchive from "is-archive";
import { isEmpty } from "lodash";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import path from "path";
import os from "os";

import electron from "electron";
const unhandled =
Expand Down Expand Up @@ -69,40 +71,47 @@ export default function Mods() {
streams: [],
});
const [installing, setInstalling] = useState(false);
const [percent, setPercent] = useState(0);
// const [percent, setPercent] = useState(0);
const [installed, setInstalled] = useState(false);

const isProd = process.env.NODE_ENV === "production";
let pathTo7zip = `${process.cwd()}\\resources\\app.asar.unpacked\\node_modules\\7zip-bin${
let pathTo7zip = path.join(
process.cwd(),
"resources\\app.asar.unpacked\\node_modules\\7zip-bin",
sevenBin.path7za
}`;
);

if (!isProd) {
pathTo7zip = `${process.cwd()}\\node_modules\\7zip-bin${sevenBin.path7za}`;
pathTo7zip = path.join(
process.cwd(),
"node_modules\\7zip-bin",
sevenBin.path7za
);
}

const installMod = (installStream) => {
let { streams, modsToInstall } = installStream;
const mod = modsToInstall.pop();
const idx = configurations.installed_mods.findIndex((e) => e === mod);
const temp = mod.file_path.split("\\");
const file_path = temp[temp.length - 1];

if (fs.existsSync(configurations.dow_directory)) {
if (mod.file_name.endsWith(".exe")) {
child.execFileSync(mod.file_path);
if (file_path.endsWith(".exe")) {
const res = child.execFileSync(mod.file_path);

setPercent(
Math.round((idx / configurations.installed_mods.length) * 100) +
percent
);
} else if (!isArchive(mod.file_name)) {
toast(`Incompatible file type!: ${mod.file_name}`);
// setPercent(
// Math.floor((idx + 1 / configurations.installed_mods.length) * 100)
// );
} else if (!isArchive(file_path)) {
toast(`Incompatible file type!: ${file_path}`);
} else if ("extract_locations" in mod) {
mod.extract_locations.forEach((loc) => {
const modifiers = "modifiers" in mod ? mod.modifiers : [];
streams.push(
extractFull(
mod.file_path,
`${configurations.dow_directory}/${loc}`,
path.join(configurations.dow_directory, loc),
{
$bin: pathTo7zip,
$raw: ["-aoa", ...modifiers],
Expand Down Expand Up @@ -135,23 +144,33 @@ export default function Mods() {
throw err;
});

stream.on("progress", (progress) => {
const newPercent =
Math.round(
(progress.percent / 100) *
(((-installStream.modsToInstall.length +
installStream.modsToInstall.length +
1) /
configurations.installed_mods.length) *
100)
) + percent;
if (newPercent !== percent) setPercent(newPercent);
});
// stream.on("progress", (progress) => {
// const max = (idx / configurations.installed_mods.length) * 100;
// const min = percent;
// const percentage = progress.percent;

// const newPercent = Math.floor((percentage * (max - min)) / 100 + min);

// setPercent(newPercent);
// });

stream.on("end", () => {
const idx = streams.findIndex((s) => s === stream);
streams[idx].done = true;
const _idx = streams.findIndex((s) => s === stream);
streams[_idx].done = true;
setInstallStream({ ...installStream, streams });
if ("shortcut" in mod && (electron.remote || false)) {
const res = electron.shell.writeShortcutLink(
path.join(
os.homedir(),
"Desktop",
mod.shortcut.replace("exe", "lnk")
),
{
target: path.join(configurations.dow_directory, mod.shortcut),
}
);
if (!res) toast(`Unable to create shortcut for ${mod.shortcut}`);
}
});
});

Expand All @@ -175,7 +194,7 @@ export default function Mods() {
setInstalled(true);
}
}
}, [installing, percent, installStream]);
}, [installing, installStream]);

const handleModSearch = (item) => {
if (typeof window !== "undefined") {
Expand Down Expand Up @@ -255,9 +274,15 @@ export default function Mods() {
<Row align="bottom" gutter={12} style={{ margin: "0 auto" }}>
<Col flex="auto">
{item.file_path && fs.existsSync(item.file_path) ? (
<CheckCircleTwoTone style={{ fontSize: "28px" }} />
<CheckCircleTwoTone
twoToneColor="#52c41a"
style={{ fontSize: "28px" }}
/>
) : (
<ExclamationCircleTwoTone style={{ fontSize: "28px" }} />
<ExclamationCircleTwoTone
twoToneColor="#eb2f96"
style={{ fontSize: "28px" }}
/>
)}
</Col>
<Col>
Expand All @@ -282,23 +307,32 @@ export default function Mods() {
</List.Item>
)}
/>
{(installing || installed) && (
{/* {(installing || installed) && (
<Progress type="circle" percent={percent} />
)}
)} */}
{configurations.installed_mods.every((mod) =>
fs.existsSync(mod.file_path)
) && (
<Button
type="primary"
shape="round"
size="large"
icon={<DownloadOutlined />}
icon={!installed && <DownloadOutlined />}
onClick={() => handleInstall()}
loading={installing}
disabled={installed}
>
{installing && !installed ? "Installing Mods..." : "Install Mods"}
{installed
? " Mods installed"
: [installing ? "Installing Mods..." : "Install Mods"]}
</Button>
)}
{installed && (
<CheckCircleTwoTone
style={{ fontSize: "28px" }}
twoToneColor="#52c41a"
/>
)}
</Space>
</Fragment>
);
Expand Down

0 comments on commit 4580131

Please sign in to comment.