Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional manifest support #4

Merged
merged 15 commits into from
Feb 6, 2024
12 changes: 10 additions & 2 deletions src/app/desktop/views/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ const createInstance = async localInstanceName => {
localInstanceName,
loader,
manifest,
imageURL ? `background${path.extname(imageURL)}` : null
imageURL ? `background${path.extname(imageURL)}` : null,
undefined,
undefined,
undefined,
version
)
);
} else if (isFabric) {
Expand All @@ -324,7 +328,11 @@ const createInstance = async localInstanceName => {
localInstanceName,
loader,
manifest,
imageURL ? `background${path.extname(imageURL)}` : null
imageURL ? `background${path.extname(imageURL)}` : null,
undefined,
undefined,
undefined,
version
)
);
} else if (isVanilla) {
Expand Down
23 changes: 23 additions & 0 deletions src/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MICROSOFT_XSTS_AUTH_URL,
MINECRAFT_SERVICES_URL,
FTB_API_URL,
MIRROR_API_URL,
JAVA_LATEST_MANIFEST_URL
} from './utils/constants';
import { sortByDate, getMcManifestUrl } from './utils';
Expand Down Expand Up @@ -409,3 +410,25 @@ export const getFTBSearch = async searchText => {
const url = `${FTB_API_URL}/modpack/search/1000?term=${searchText}`;
return axios.get(url);
};

// OxMIRROR API

export const getMirrorManifest = async modpackId => {
try {
const url = `${MIRROR_API_URL}/manifests/${modpackId}.json`;
const { data } = await axios.get(url);
return data;
} catch {
return { status: 'error' };
}
};

export const getMirrorAddon = async fileID => {
try {
const url = `${MIRROR_API_URL}/addons/${fileID}.json`;
const { data } = await axios.get(url);
return data;
} catch {
return { status: 'error' };
}
};
78 changes: 75 additions & 3 deletions src/common/reducers/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import {
getJavaLatestManifest,
getJavaManifest,
getMcManifest,
getMirrorManifest,
getMirrorAddon,
getMultipleAddons,
mcAuthenticate,
mcInvalidate,
Expand Down Expand Up @@ -1172,7 +1174,8 @@ export function addToQueue(
background,
timePlayed,
settings = {},
updateOptions
updateOptions,
version
) {
return async (dispatch, getState) => {
const state = getState();
Expand All @@ -1190,6 +1193,7 @@ export function addToQueue(
background,
isUpdate,
bypassCopy,
version,
...patchedSettings
});

Expand Down Expand Up @@ -1885,8 +1889,9 @@ export function processFTBManifest(instanceName) {
export function processForgeManifest(instanceName) {
return async (dispatch, getState) => {
const state = getState();
const { manifest, loader } = _getCurrentDownloadItem(state);
const { manifest, loader, version } = _getCurrentDownloadItem(state);
const concurrency = state.settings.concurrentDownloads;
let mirrorManifest;

dispatch(updateDownloadStatus(instanceName, 'Загружаю модификации...'));

Expand Down Expand Up @@ -1915,7 +1920,15 @@ export function processForgeManifest(instanceName) {
);
};

await Promise.all([_getAddons(), _getAddonFiles()]);
const _getMirrorManifest = async () => {
if (loader?.projectID == undefined) {
log.log('ProjectID is missed, skip mirror check');
} else {
mirrorManifest = await getMirrorManifest(loader?.projectID);
}
};

await Promise.all([_getAddons(), _getAddonFiles(), _getMirrorManifest()]);

let modManifests = [];
const optedOutMods = [];
Expand Down Expand Up @@ -1972,6 +1985,65 @@ export function processForgeManifest(instanceName) {
{ concurrency }
);

if (mirrorManifest) {
await pMap(
mirrorManifest?.files,
async item => {
let ok = false;
let tries = 0;
/* eslint-disable no-await-in-loop */
do {
tries += 1;
if (tries !== 1) {
await new Promise(resolve => setTimeout(resolve, 5000));
}

log.log('try to download mod from mirror:' + item.id);

const modManifest = await getMirrorAddon(item.id);
const isResourcePack = item.classId === 12;
const isShaderPack = item.classId === 6552;
const destFile = path.join(
_getInstancesPath(state),
instanceName,
isResourcePack ? 'resourcepacks' : isShaderPack ? 'shaderpacks' : 'mods',
modManifest.fileName
);

log.log('destFile:' + modManifest.fileName);

const fileExists = await fse.pathExists(destFile);

if (!fileExists) {
// if (!modManifest.downloadUrl) {
// const normalizedModData = normalizeModData(
// modManifest,
// item.id,
// addon.name
// );

// optedOutMods.push({ addon, modManifest: normalizedModData });
// return;
// }
log.log('download url:' + modManifest.downloadUrl);
await downloadFile(destFile, modManifest.downloadUrl);
log.log('downloaded!');
modManifests = modManifests.concat(
normalizeModData(modManifest, item.id, item.name)
);
}
const percentage =
(modManifests.length * 100) / manifest.files.length - 1;

dispatch(updateDownloadProgress(percentage > 0 ? percentage : 0));
ok = true;
} while (!ok && tries <= 3);
/* eslint-enable no-await-in-loop */
},
{ concurrency }
);
}

if (optedOutMods.length) {
await new Promise((resolve, reject) => {
dispatch(
Expand Down
1 change: 1 addition & 0 deletions src/common/reducers/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function downloadQueue(state = {}, action) {
status: null,
currentPhase: 1,
totalPhases: action.phases,
version: action.version,
manifest: action.manifest,
...(action.isUpdate && { isUpdate: action.isUpdate }),
...(action.bypassCopy && { isUpdate: action.bypassCopy }),
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const MC_LIBRARIES_URL = 'https://libraries.minecraft.net';
export const FORGESVC_URL = 'https://api.curseforge.com/v1';
export const FTB_API_URL = 'https://api.modpacks.ch/public';
export const FTB_MODPACK_URL = 'https://feed-the-beast.com/modpack';
export const MIRROR_API_URL = 'https://github.com/Proxwian/OxMIRROR/raw/main';
export const NEWS_URL =
'https://www.minecraft.net/en-us/feeds/community-content/rss';
export const FMLLIBS_OUR_BASE_URL = 'https://fmllibs.gdevs.io';
Expand Down
Loading