dolphin-tool
Version:
🐬 dolphin-tool binaries and wrapper for Node.js.
73 lines • 4.1 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import DolphinToolBin from './dolphinToolBin.js';
import { DigestAlgorithm } from './common.js';
import utils from './utils.js';
export default {
verify(options_1) {
return __awaiter(this, arguments, void 0, function* (options, attempt = 1) {
var _a, _b, _c, _d;
const runOptions = [
'verify',
'-i', options.inputFilename,
...(options.digestAlgorithm === undefined ? [] : ['-a', options.digestAlgorithm]),
];
let output;
// eslint-disable-next-line unicorn/prefer-ternary
if (process.platform === 'win32' && options.userFolderPath === undefined) {
/**
* Windows (and seemingly no other OS) has issues with concurrent or rapid execution of
* `DolphinTool.exe`, resulting in popups with messages such as:
* "IOS_FS: Failed to write new FST"
* "IOS_FS: Failed to rename temporary FST file"
* "File <userDir>/Wii/shared2/sys/SYSCONF could not be opened! This may happen with
* improper permissions or use by another process."
* To combat this, we have to use separate user directories per process.
*/
output = yield utils.wrapTempDir((temporaryDirectory) => __awaiter(this, void 0, void 0, function* () {
return DolphinToolBin.run([
...runOptions,
'-u', temporaryDirectory,
], options);
}));
}
else {
output = yield DolphinToolBin.run([
...runOptions,
...(options.userFolderPath ? ['-u', options.userFolderPath] : []),
], options);
}
const digests = {};
for (const line of output.split(/\r?\n/)) {
if (line.match(/^crc32\W/i) !== null || options.digestAlgorithm === DigestAlgorithm.CRC32) {
digests.crc32 = (_a = line.match(/[\da-f]{8}/i)) === null || _a === void 0 ? void 0 : _a.at(0);
}
if (line.match(/^md5\W/i) !== null || options.digestAlgorithm === DigestAlgorithm.MD5) {
digests.md5 = (_b = line.match(/[\da-f]{32}/i)) === null || _b === void 0 ? void 0 : _b.at(0);
}
if (line.match(/^sha1\W/i) !== null || options.digestAlgorithm === DigestAlgorithm.SHA1) {
digests.sha1 = (_c = line.match(/[\da-f]{40}/i)) === null || _c === void 0 ? void 0 : _c.at(0);
}
if (line.match(/^rchash\W/i) !== null || options.digestAlgorithm === DigestAlgorithm.RCHASH) {
digests.rchash = (_d = line.match(/[\da-f]{32}/i)) === null || _d === void 0 ? void 0 : _d.at(0);
}
}
// Try to detect failures, and then retry them automatically
if (Object.values(digests).filter((value) => value !== undefined).length === 0) {
yield new Promise((resolve) => {
setTimeout(resolve, Math.random() * (Math.pow(2, (attempt - 1)) * 20));
});
return this.verify(options, attempt + 1);
}
return digests;
});
},
};
//# sourceMappingURL=dolphinToolVerify.js.map