@openwf/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib.js +8 -3
- package/openwf.js +15 -1
- package/package.json +2 -1
package/lib.js
CHANGED
|
@@ -59,10 +59,13 @@ const downloadFileFromMega = async (url, out) => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
// For single-file torrents, downloadDir is the folder that contains the file.
|
|
62
|
-
const verifyLocalTorrentDownload = (torrentFilePath, downloadDir) => {
|
|
62
|
+
const verifyLocalTorrentDownload = (torrentFilePath, downloadDir, infoHash) => {
|
|
63
63
|
return new Promise(resolve => {
|
|
64
64
|
const nt = require("nt");
|
|
65
65
|
nt.read(torrentFilePath, (_err, torrent) => {
|
|
66
|
+
if (infoHash && torrent.infoHash() != infoHash) {
|
|
67
|
+
throw new Error(`${torrentFilePath} does not seem to match infohash ${infoHash}`);
|
|
68
|
+
}
|
|
66
69
|
const hasher = torrent.hashCheck(downloadDir);
|
|
67
70
|
let p;
|
|
68
71
|
hasher.on("match", (i, hash, percent) => {
|
|
@@ -77,6 +80,7 @@ const verifyLocalTorrentDownload = (torrentFilePath, downloadDir) => {
|
|
|
77
80
|
|
|
78
81
|
const downloadUpdatePatch = async (version, btConsent) => {
|
|
79
82
|
const params = new URLSearchParams(new URL(version.attributes.magnet).search);
|
|
83
|
+
const infoHash = params.get("xt").substring(9);
|
|
80
84
|
const torrentFilePath = `depot/${params.get("dn")}.torrent`;
|
|
81
85
|
if (!fs.existsSync(torrentFilePath)) {
|
|
82
86
|
const torrentFileUrl = `https://about.openwf.io/supplementals/torrents/patches/${params.get("dn")}.torrent`;
|
|
@@ -102,13 +106,14 @@ const downloadUpdatePatch = async (version, btConsent) => {
|
|
|
102
106
|
await downloadFileFromMega(version.attributes.mega, `depot/${params.get("dn")}`);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
|
-
if (await verifyLocalTorrentDownload(torrentFilePath, "depot")) {
|
|
109
|
+
if (await verifyLocalTorrentDownload(torrentFilePath, "depot", infoHash)) {
|
|
106
110
|
return `depot/${params.get("dn")}`;
|
|
107
111
|
}
|
|
108
112
|
if (needToDownload) {
|
|
109
113
|
// This was a fresh download, no point in retrying.
|
|
110
|
-
throw new Error(`Failed to download ${
|
|
114
|
+
throw new Error(`Failed to download ${version.attributes.mega}`);
|
|
111
115
|
}
|
|
116
|
+
//console.log("File is locally available but failed to verify against .torrent");
|
|
112
117
|
needToDownload = true;
|
|
113
118
|
}
|
|
114
119
|
};
|
package/openwf.js
CHANGED
|
@@ -100,7 +100,21 @@ switch (tool) {
|
|
|
100
100
|
|
|
101
101
|
console.log("Applying update patch...");
|
|
102
102
|
const sz = require("7zip-min");
|
|
103
|
-
|
|
103
|
+
if (patchArchivePath.endsWith(".wim.7z")) {
|
|
104
|
+
await sz.unpack(patchArchivePath, "depot");
|
|
105
|
+
const wimPath = patchArchivePath.substr(0, patchArchivePath.length - 3);
|
|
106
|
+
{
|
|
107
|
+
const { Wim } = require("wim-parser");
|
|
108
|
+
const wim = await Wim.open(wimPath);
|
|
109
|
+
const root = await wim.getRootDirectoryEntry();
|
|
110
|
+
const targetDir = (await wim.listDirectory(root)).find(entry => entry.file_name == target);
|
|
111
|
+
await wim.extract(targetDir, `install/${target}`);
|
|
112
|
+
await wim.close();
|
|
113
|
+
}
|
|
114
|
+
await fs.promises.unlink(wimPath);
|
|
115
|
+
} else {
|
|
116
|
+
await sz.unpackSome(patchArchivePath, [target], "install");
|
|
117
|
+
}
|
|
104
118
|
}
|
|
105
119
|
if (tool == "install") {
|
|
106
120
|
console.log("Downloading Bootstrapper manifest...");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openwf/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "lib.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"nt": "^0.7.1",
|
|
17
17
|
"steam-manifest-tools": "^0.1.11",
|
|
18
18
|
"webtorrent": "^2.3.0",
|
|
19
|
+
"wim-parser": "^0.1.0",
|
|
19
20
|
"yesno": "^0.4.0"
|
|
20
21
|
}
|
|
21
22
|
}
|