Skip to content

Commit

Permalink
Merge pull request #93 from gorilla-devs/develop
Browse files Browse the repository at this point in the history
v0.6.9
  • Loading branch information
blarfoon authored Oct 20, 2018
2 parents 8c0c358 + 9a7f420 commit 1e700b9
Show file tree
Hide file tree
Showing 63 changed files with 2,482 additions and 563 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ matrix:
# Removing unpacked builds before deploy
- sudo rm -rf $TRAVIS_BUILD_DIR/release/win-unpacked
- sudo rm -rf $TRAVIS_BUILD_DIR/release/linux-unpacked
- sudo chown -R travis:travis $TRAVIS_BUILD_DIR/release
- ls
- cd release
- ls
# - node $TRAVIS_BUILD_DIR/scripts/preDeploy.js
deploy:
provider: releases
Expand Down
4 changes: 2 additions & 2 deletions antd/lib/style/themes/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
@zindex-modal : 1000;
@zindex-notification : 1010;
@zindex-message : 10012;
@zindex-popover : 1030;
@zindex-popover : 10000;
@zindex-picker : 1050;
@zindex-dropdown : 10010;
@zindex-tooltip : 10011;
Expand Down Expand Up @@ -490,7 +490,7 @@

// Skeleton
// ---
@skeleton-color: #f2f2f2;
@skeleton-color: @midnight;

// Message
// ---
Expand Down
194 changes: 144 additions & 50 deletions app/actions/downloadManager.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import path from 'path';
import { remote, ipcRenderer } from 'electron';
import { message } from 'antd';
import { APPPATH, PACKS_PATH, INSTANCES_PATH, MAVEN_REPO } from '../constants';
import { promisify } from 'util';
import axios from 'axios';
import request from 'request';
import makeDir from 'make-dir';
import fs from 'fs';
import _ from 'lodash';
import zip from 'adm-zip';
import Zip from 'adm-zip';
import { downloadFile, downloadArr } from '../utils/downloader';
import { extractAssets, extractMainJar, extractNatives, computeLibraries } from '../utils/getMCFilesList';
//Getting colors from scss theme file
import colors from '../style/theme/index.scss';
import { PACKS_PATH, INSTANCES_PATH, META_PATH } from '../constants';
import {
extractAssets,
extractMainJar,
extractNatives,
computeVanillaAndForgeLibraries
} from '../utils/getMCFilesList';
import { arraify } from '../utils/strings';

export const START_DOWNLOAD = 'START_DOWNLOAD';
export const CLEAR_QUEUE = 'CLEAR_QUEUE';
Expand Down Expand Up @@ -45,7 +47,9 @@ export function clearQueue() {
// This needs to clear any instance that is already installed
return (dispatch, getState) => {
const { downloadManager } = getState();
const completed = Object.keys(downloadManager.downloadQueue).filter(act => downloadManager.downloadQueue[act].status === 'Completed');
const completed = Object.keys(downloadManager.downloadQueue).filter(
act => downloadManager.downloadQueue[act].status === 'Completed'
);
// It makes no sense to dispatch if no instance is to remove
if (completed.length !== 0) {
dispatch({
Expand All @@ -60,53 +64,126 @@ export function downloadPack(pack) {
return async (dispatch, getState) => {
const { downloadManager, packCreator } = getState();
const currPack = downloadManager.downloadQueue[pack];
let vnlJSON = null;
try {
vnlJSON = JSON.parse(
await promisify(fs.readFile)(
path.join(
META_PATH,
'net.minecraft',
currPack.version,
`${currPack.version}.json`
)
)
);
} catch (err) {
const versionURL = packCreator.versionsManifest.find(
v => v.id === currPack.version
).url;
vnlJSON = (await axios.get(versionURL)).data;
await makeDir(path.join(META_PATH, 'net.minecraft', currPack.version));
await promisify(fs.writeFile)(
path.join(
META_PATH,
'net.minecraft',
currPack.version,
`${currPack.version}.json`
),
JSON.stringify(vnlJSON)
);
}

const versionURL = packCreator.versionsManifest.find((v) => v.id === currPack.version).url;
console.log(versionURL);

const vnlJSON = (await axios.get(versionURL)).data;
let forgeJSON = null;
let forgeFileName = null;

const assets = await extractAssets(vnlJSON);
const mainJar = await extractMainJar(vnlJSON);

let forgeFileName = null;

if (currPack.forgeVersion !== null) {
forgeFileName = `${currPack.version}-${currPack.forgeVersion}`;
const forgeUrl = `https://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeFileName}/forge-${forgeFileName}-universal.jar`;

// Checks whether the filename is version-forge or version-forge-version
try { await axios.head(forgeUrl) }
catch (err) { forgeFileName = `${currPack.version}-${currPack.forgeVersion}-${currPack.version}-` }
const forgePath = path.join(INSTANCES_PATH, 'libraries', 'net', 'minecraftforge', 'forge', forgeFileName, `forge-${forgeFileName}.jar`);
try { await promisify(fs.access)(forgePath); }
catch (e) {
await makeDir(path.dirname(forgePath));
await downloadFile(forgePath, forgeUrl, (p) => {
dispatch({ type: UPDATE_PROGRESS, payload: { pack, percentage: p } });
});
const { branch } = packCreator.forgeManifest[
Object.keys(packCreator.forgeManifest).find(v => v === currPack.version)
].find(v => Object.keys(v)[0] === currPack.forgeVersion)[
currPack.forgeVersion
];

forgeFileName = `${currPack.version}-${currPack.forgeVersion}${
branch !== null ? `-${branch}` : ''
}`;
console.log(
`https://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeFileName}/forge-${forgeFileName}-installer.jar`
);
try {
forgeJSON = JSON.parse(
await promisify(fs.readFile)(
path.join(
META_PATH,
'net.minecraftforge',
forgeFileName,
`${forgeFileName}.json`
)
)
);
await promisify(fs.access)(
path.join(
INSTANCES_PATH,
'libraries',
...arraify(forgeJSON.versionInfo.libraries[0].name)
)
);
} catch (err) {
await downloadFile(
path.join(INSTANCES_PATH, 'temp', `${forgeFileName}.jar`),
`https://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeFileName}/forge-${forgeFileName}-installer.jar`,
p => {
dispatch({
type: UPDATE_PROGRESS,
payload: { pack, percentage: ((p * 18) / 100).toFixed(1) }
});
}
);
const zipFile = new Zip(
path.join(INSTANCES_PATH, 'temp', `${forgeFileName}.jar`)
);
forgeJSON = JSON.parse(zipFile.readAsText('install_profile.json'));
await makeDir(
path.dirname(
path.join(
INSTANCES_PATH,
'libraries',
...arraify(forgeJSON.versionInfo.libraries[0].name)
)
)
);
await promisify(fs.unlink)(
path.join(INSTANCES_PATH, 'temp', `${forgeFileName}.jar`)
);
await makeDir(
path.join(META_PATH, 'net.minecraftforge', forgeFileName)
);
await promisify(fs.writeFile)(
path.join(
META_PATH,
'net.minecraftforge',
forgeFileName,
`${forgeFileName}.json`
),
JSON.stringify(forgeJSON)
);
}
const zipFile = new zip(forgePath);
forgeJSON = JSON.parse(zipFile.readAsText("version.json"));
}
console.log(forgeJSON)
console.log(vnlJSON)

const libraries = await computeLibraries(vnlJSON, forgeJSON);
const libraries = await computeVanillaAndForgeLibraries(vnlJSON, forgeJSON);

// This is the main config file for the instance
await promisify(fs.writeFile)(path.join(PACKS_PATH, pack, 'config.json'), JSON.stringify({
instanceName: pack,
version: currPack.version,
forgeID: currPack.forgeVersion !== null ? forgeJSON.id : null,
forgeVersion: currPack.forgeVersion !== null ? forgeFileName : null,
minecraftArguments: currPack.forgeVersion !== null ? forgeJSON.minecraftArguments :
_.has(vnlJSON, 'arguments') ? vnlJSON.arguments.game.filter(lib => typeof lib === 'string' || lib instanceof String).join(' ') : vnlJSON.minecraftArguments,
mainClass: currPack.forgeVersion !== null ? forgeJSON.mainClass : vnlJSON.mainClass,
assets: vnlJSON.assets,
type: currPack.forgeVersion !== null ? "Forge" : vnlJSON.type,
libraries
}));
await promisify(fs.writeFile)(
path.join(PACKS_PATH, pack, 'config.json'),
JSON.stringify({
instanceName: pack,
version: currPack.version,
forgeVersion: forgeFileName
})
);

dispatch({
type: UPDATE_TOTAL_FILES_TO_DOWNLOAD,
Expand All @@ -116,11 +193,27 @@ export function downloadPack(pack) {
}
});

await downloadArr(libraries.filter(lib => !lib.path.includes('minecraftforge')), path.join(INSTANCES_PATH, 'libraries'), dispatch, pack);

await downloadArr(assets, path.join(INSTANCES_PATH, 'assets'), dispatch, pack, 10);

await downloadArr(mainJar, path.join(INSTANCES_PATH, 'versions'), dispatch, pack);
await downloadArr(
libraries,
path.join(INSTANCES_PATH, 'libraries'),
dispatch,
pack
);

await downloadArr(
assets,
path.join(INSTANCES_PATH, 'assets'),
dispatch,
pack,
10
);

await downloadArr(
mainJar,
path.join(INSTANCES_PATH, 'versions'),
dispatch,
pack
);

await extractNatives(libraries.filter(lib => 'natives' in lib), pack);

Expand All @@ -138,14 +231,15 @@ function addNextPackToActualDownload() {
const { downloadManager } = getState();
const queueArr = Object.keys(downloadManager.downloadQueue);
queueArr.some(pack => {
if (!downloadManager.downloadQueue[pack].status === 'Completed') {
if (downloadManager.downloadQueue[pack].status !== 'Completed') {
dispatch({
type: START_DOWNLOAD,
payload: pack
});
dispatch(downloadPack(pack));
return true;
}
return false;
});
};
}
}
33 changes: 20 additions & 13 deletions app/actions/instancesManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { message } from 'antd';
import log from 'electron-log';
import { exec } from 'child_process';
import launchCommand from '../utils/MCLaunchCommand';

export const SELECT_INSTANCE = 'SELECT_INSTANCE';
Expand Down Expand Up @@ -35,22 +36,28 @@ export function selectInstance(name) {
export function startInstance(instanceName) {
return async (dispatch, getState) => {
const { auth } = getState();
const util = require('util');
const exec = util.promisify(require('child_process').exec);
try {
dispatch({
type: START_INSTANCE,
payload: instanceName
});
const name = await exec(await launchCommand(instanceName, auth));
} catch (error) {
message.error('There was an error while starting the instance');
log.error(error);
} finally {
const start = exec(await launchCommand(instanceName, auth), (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
dispatch({
type: START_INSTANCE,
payload: instanceName,
pid: start.pid
});
start.on('exit', () => {
dispatch({
type: STOP_INSTANCE,
payload: instanceName
});
}
});
start.on('error', (err) => {
message.error('There was an error while starting the instance');
log.error(err);
});
};
}
Loading

0 comments on commit 1e700b9

Please sign in to comment.