Skip to content

Commit b8c7e77

Browse files
committed
fix ftb apis & napi build
1 parent 273d4cb commit b8c7e77

File tree

5 files changed

+126
-9
lines changed

5 files changed

+126
-9
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# rust target
2020
/target
2121
/napi/target
22-
/public/napi.node
22+
napi.node
2323
/napi/napi.node
2424
/napi/node_modules
2525
/napi/index.d.ts

napi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "./index.node",
55
"types": "./index.d.ts",
66
"scripts": {
7-
"build": "node ../node_modules/cross-env/src/bin/cross-env-shell.js RUSTFLAGS=-Csymbol-mangling-version=v0 node ../node_modules/@napi-rs/cli/scripts/index.js build --js false --release"
7+
"build": "node ../node_modules/cross-env/src/bin/cross-env-shell.js node ../node_modules/@napi-rs/cli/scripts/index.js build --js true --release"
88
},
99
"napi": {
1010
"name": "napi"

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"release:setup": "cross-env-shell NODE_ENV=production APP_TYPE=electron REACT_APP_RELEASE_TYPE=setup \"npm run build\" && npm run build-electron:setup && npm run deploy setup",
4949
"release:portable": "cross-env-shell NODE_ENV=production APP_TYPE=electron REACT_APP_RELEASE_TYPE=portable \"npm run build\" && npm run build-electron:portable && npm run deploy portable",
5050
"upload": "node ./scripts/uploadRelease.js",
51-
"release": "rimraf ./deploy && npm run release:setup && npm run release:portable",
51+
"release": "npm run napi-build && rimraf ./deploy && npm run release:setup && npm run release:portable",
5252
"prepare": "husky install",
5353
"napi-build": "cd napi && npm run build && node ../scripts/moveNapi.js"
5454
},
@@ -184,7 +184,7 @@
184184
"node-machine-id": "^1.1.12",
185185
"p-map": "^5.3.0",
186186
"polished": "^4.1.3",
187-
"preact": "^10.6.5",
187+
"preact": "^10.8.2",
188188
"ps-tree": "^1.2.0",
189189
"randomstring": "^1.2.2",
190190
"react": "^17.0.2",

src/common/reducers/actions.js

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,10 +1565,128 @@ export function processFTBManifest(instanceName) {
15651565
const instancePath = path.join(instancesPath, instanceName);
15661566
const fileHashes = {};
15671567

1568-
const { files } = manifest;
1568+
const { files: allFiles } = manifest;
15691569
const concurrency = state.settings.concurrentDownloads;
15701570

1571+
const files = allFiles.filter(v => v.url !== '');
1572+
const CFFiles = allFiles.filter(v => v.url === '');
1573+
1574+
dispatch(updateDownloadStatus(instanceName, 'Downloading CF files...'));
1575+
const addonsHashmap = {};
1576+
const addonsFilesHashmap = {};
1577+
1578+
// DOWNLOAD CF FILES
1579+
1580+
const _getAddons = async () => {
1581+
const addons = await getMultipleAddons(
1582+
CFFiles.map(v => v.curseforge?.project)
1583+
);
1584+
1585+
addons.forEach(v => {
1586+
addonsHashmap[v.id] = v;
1587+
});
1588+
};
1589+
1590+
const _getAddonFiles = async () => {
1591+
await pMap(
1592+
CFFiles,
1593+
async item => {
1594+
const modManifest = await getAddonFile(
1595+
item.curseforge?.project,
1596+
item.curseforge?.file
1597+
);
1598+
1599+
addonsFilesHashmap[item.curseforge?.project] = modManifest;
1600+
},
1601+
{ concurrency: concurrency + 10 }
1602+
);
1603+
};
1604+
1605+
await Promise.all([_getAddons(), _getAddonFiles()]);
1606+
15711607
let modManifests = [];
1608+
const optedOutMods = [];
1609+
await pMap(
1610+
CFFiles,
1611+
async item => {
1612+
if (!addonsHashmap[item.curseforge?.project]) return;
1613+
let ok = false;
1614+
let tries = 0;
1615+
/* eslint-disable no-await-in-loop */
1616+
do {
1617+
tries += 1;
1618+
if (tries !== 1) {
1619+
await new Promise(resolve => setTimeout(resolve, 5000));
1620+
}
1621+
1622+
const addon = addonsHashmap[item.curseforge?.project];
1623+
const isResourcePack = addon.classId === 12;
1624+
const modManifest = addonsFilesHashmap[item.curseforge?.project];
1625+
const destFile = path.join(
1626+
_getInstancesPath(state),
1627+
instanceName,
1628+
isResourcePack ? 'resourcepacks' : 'mods',
1629+
modManifest.fileName
1630+
);
1631+
1632+
const fileExists = await fse.pathExists(destFile);
1633+
1634+
if (!fileExists) {
1635+
if (!modManifest.downloadUrl) {
1636+
const normalizedModData = normalizeModData(
1637+
modManifest,
1638+
item.curseforge?.project,
1639+
addon.name
1640+
);
1641+
1642+
optedOutMods.push({ addon, modManifest: normalizedModData });
1643+
return;
1644+
}
1645+
await downloadFile(destFile, modManifest.downloadUrl);
1646+
modManifests = modManifests.concat(
1647+
normalizeModData(
1648+
modManifest,
1649+
item.curseforge?.project,
1650+
addon.name
1651+
)
1652+
);
1653+
}
1654+
const percentage = (modManifests.length * 100) / CFFiles.length - 1;
1655+
1656+
dispatch(updateDownloadProgress(percentage > 0 ? percentage : 0));
1657+
ok = true;
1658+
} while (!ok && tries <= 3);
1659+
/* eslint-enable no-await-in-loop */
1660+
},
1661+
{ concurrency }
1662+
);
1663+
1664+
if (optedOutMods.length) {
1665+
await new Promise((resolve, reject) => {
1666+
dispatch(
1667+
openModal('OptedOutModsList', {
1668+
optedOutMods,
1669+
instancePath: path.join(_getInstancesPath(state), instanceName),
1670+
resolve,
1671+
reject,
1672+
abortCallback: () => {
1673+
setTimeout(
1674+
() => reject(new Error('Download Aborted by the user')),
1675+
300
1676+
);
1677+
}
1678+
})
1679+
);
1680+
});
1681+
}
1682+
1683+
modManifests = modManifests.concat(
1684+
...optedOutMods.map(v =>
1685+
normalizeModData(v.modManifest, v.modManifest.projectID, v.addon.name)
1686+
)
1687+
);
1688+
1689+
// DOWNLOAD FTB FILES
15721690

15731691
let prev = 0;
15741692
const updatePercentage = downloaded => {
@@ -1586,7 +1704,6 @@ export function processFTBManifest(instanceName) {
15861704
path: path.join(instancePath, item.path, item.name)
15871705
};
15881706
});
1589-
15901707
dispatch(updateDownloadStatus(instanceName, 'Downloading FTB files...'));
15911708
await downloadInstanceFiles(
15921709
mappedFiles,

0 commit comments

Comments
 (0)