Skip to content

Commit

Permalink
Update 1.5.0
Browse files Browse the repository at this point in the history
- Added Modrinth (Modding platform)
- Fixxed FTB infinity loading
- Fixxed a bug that deletes all instances if name was clear
- Fixxed authlib usage in client
- some tiny changes
  • Loading branch information
tribbedev committed Jul 20, 2022
1 parent 398d048 commit d06268b
Show file tree
Hide file tree
Showing 33 changed files with 3,312 additions and 982 deletions.
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["src/**/*.js"]
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rplauncher",
"version": "1.4.5",
"version": "1.5.0",
"description": "rPLauncher is simple, yet powerful Minecraft custom launcher with a strong focus on the user experience",
"keywords": [
"minecraft",
Expand Down
105 changes: 105 additions & 0 deletions src/app/desktop/utils/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,111 @@ const downloadFileInstance = async (fileName, url, sha1, legacyPath) => {
}
};

/**
* @param {{ path: string, hashes: { sha1: string, sha512: string }, downloads: string[] }[]} files
* @param {string} instancePath
* @param {number} updatePercentage
* @param {number} threads
*/
export const downloadInstanceFilesWithFallbacks = async (
files,
instancePath,
updatePercentage,
threads = 4
) => {
let downloaded = 0;
await pMap(
files,
async file => {
let counter = 0;
let res = false;
do {
counter += 1;
if (counter !== 1) {
await new Promise(resolve => setTimeout(resolve, 5000));
}

try {
res = await downloadFileInstanceWithFallbacks(file, instancePath);
} catch {
// Do nothing
}
} while (!res && counter < 3);
downloaded += 1;
if (
updatePercentage &&
(downloaded % 5 === 0 || downloaded === files.length)
) {
updatePercentage(downloaded);
}
},
{ concurrency: threads }
);
};

/**
* @param {{ path: string, hashes: { [algo: string]: string }, downloads: string[] }[]} file
* @param {string} instancePath
*/
const downloadFileInstanceWithFallbacks = async (file, instancePath) => {
const filePath = path.join(instancePath, file.path);
const dirPath = path.dirname(filePath);
try {
await fs.access(filePath);

let allChecksumsMatch = false;
for (const algo of Object.keys(file.hashes)) {
const checksum = await computeFileHash(filePath, algo);
if (file.hashes[algo] === checksum) {
allChecksumsMatch = true;
}
}
if (allChecksumsMatch) {
// the file already exists on disk, skip it
return true;
}
} catch {
await makeDir(dirPath);
}

// this loop exits as soon as a download has been successful
for (const url of file.downloads) {
const encodedUrl = getUri(url);
try {
const { data } = await axios.get(encodedUrl, {
responseType: 'stream',
responseEncoding: null,
adapter,
timeout: 60000 * 20
});

const wStream = fss.createWriteStream(filePath, {
encoding: null
});

data.pipe(wStream);

await new Promise((resolve, reject) => {
data.on('error', err => {
console.error(err);
reject(err);
});

data.on('end', () => {
wStream.end();
resolve();
});
});

return true;
} catch (e) {
console.error(
`Error while downloading <${url} | ${encodedUrl}> to <${file.path}> --> ${e.message}`
);
}
}
};

export const downloadFile = async (fileName, url, onProgress) => {
await makeDir(path.dirname(fileName));

Expand Down
80 changes: 64 additions & 16 deletions src/app/desktop/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fss, { promises as fs } from 'fs';
import originalFs from 'original-fs';
import fse from 'fs-extra';
import axios from 'axios';
import { extractFull } from 'node-7z';
import * as Seven from 'node-7z';
import jimp from 'jimp/es';
import makeDir from 'make-dir';
import { promisify } from 'util';
Expand All @@ -16,11 +16,12 @@ import {
FORGE,
LATEST_JAVA_VERSION
} from '../../../common/utils/constants';

import {
addQuotes,
removeDuplicates,
sortByForgeVersionDesc
} from '../../../common/utils';
// eslint-disable-next-line import/no-cycle
import {
getAddon,
getAddonFile,
Expand Down Expand Up @@ -400,14 +401,46 @@ export const get7zPath = async () => {

get7zPath();

export const extract = async (source, destination, args = {}, funcs = {}) => {
const sevenZipPath = await get7zPath();
const extraction = Seven.extract(source, destination, {
...args,
yes: true,
$bin: sevenZipPath,
$spawnOptions: { shell: true }
});
let extractedParentDir = null;
await new Promise((resolve, reject) => {
if (funcs.progress) {
extraction.on('progress', ({ percent }) => {
funcs.progress(percent);
});
}
extraction.on('data', data => {
if (!extractedParentDir) {
[extractedParentDir] = data.file.split('/');
}
});
extraction.on('end', () => {
funcs.end?.();
resolve(extractedParentDir);
});
extraction.on('error', err => {
funcs.error?.();
reject(err);
});
});
return { extraction, extractedParentDir };
};

export const extractAll = async (
source,
destination,
args = {},
funcs = {}
) => {
const sevenZipPath = await get7zPath();
const extraction = extractFull(source, destination, {
const extraction = Seven.extractFull(source, destination, {
...args,
yes: true,
$bin: sevenZipPath,
Expand Down Expand Up @@ -576,13 +609,14 @@ export const getJVMArguments112 = (
hideAccessToken,
jvmOptions = []
) => {
const needsQuote = process.platform !== 'win32';
const args = [];
args.push('-cp');

args.push(
[...libraries, mcjar]
.filter(l => !l.natives)
.map(l => `"${l.path}"`)
.map(l => `${addQuotes(needsQuote, l.path)}`)
.join(process.platform === 'win32' ? ';' : ':')
);

Expand All @@ -594,8 +628,15 @@ export const getJVMArguments112 = (
args.push(`-Xmx${memory}m`);
args.push(`-Xms${memory}m`);
args.push(...jvmOptions);
args.push(`-Djava.library.path="${path.join(instancePath, 'natives')}"`);
args.push(`-Dminecraft.applet.TargetDirectory="${instancePath}"`);
args.push(
`-Djava.library.path=${addQuotes(
needsQuote,
path.join(instancePath, 'natives')
)}`
);
args.push(
`-Dminecraft.applet.TargetDirectory=${addQuotes(needsQuote, instancePath)}`
);
if (mcJson.logging) {
args.push(mcJson?.logging?.client?.argument || '');
}
Expand All @@ -617,13 +658,13 @@ export const getJVMArguments112 = (
val = mcJson.id;
break;
case 'game_directory':
val = `"${instancePath}"`;
val = `${addQuotes(needsQuote, instancePath)}`;
break;
case 'assets_root':
val = `"${assetsPath}"`;
val = `${addQuotes(needsQuote, assetsPath)}`;
break;
case 'game_assets':
val = `"${path.join(assetsPath, 'virtual', 'legacy')}"`;
val = `${path.join(assetsPath, 'virtual', 'legacy')}`;
break;
case 'assets_index_name':
val = mcJson.assets;
Expand Down Expand Up @@ -652,6 +693,9 @@ export const getJVMArguments112 = (
if (val != null) {
mcArgs[i] = val;
}
if (typeof args[i] === 'string' && !needsQuote) {
args[i] = args[i].replaceAll('"', '');
}
}
}

Expand Down Expand Up @@ -679,6 +723,7 @@ export const getJVMArguments113 = (
) => {
const argDiscovery = /\${*(.*)}/;
let args = mcJson.arguments.jvm.filter(v => !skipLibrary(v));
const needsQuote = process.platform !== 'win32';

// if (process.platform === "darwin") {
// args.push("-Xdock:name=instancename");
Expand All @@ -687,7 +732,9 @@ export const getJVMArguments113 = (

args.push(`-Xmx${memory}m`);
args.push(`-Xms${memory}m`);
args.push(`-Dminecraft.applet.TargetDirectory="${instancePath}"`);
args.push(
`-Dminecraft.applet.TargetDirectory=${addQuotes(needsQuote, instancePath)}`
);
if (mcJson.logging) {
args.push(mcJson?.logging?.client?.argument || '');
}
Expand All @@ -705,9 +752,9 @@ export const getJVMArguments113 = (
for (let i = 0; i < args.length; i += 1) {
if (typeof args[i] === 'object' && args[i].rules) {
if (typeof args[i].value === 'string') {
args[i] = `"${args[i].value}"`;
args[i] = `${addQuotes(needsQuote, args[i].value)}`;
} else if (typeof args[i].value === 'object') {
args.splice(i, 1, ...args[i].value.map(v => `"${v}"`));
args.splice(i, 1, ...args[i].value.map(v => `${v}`));
}
i -= 1;
} else if (typeof args[i] === 'string') {
Expand All @@ -722,10 +769,10 @@ export const getJVMArguments113 = (
val = mcJson.id;
break;
case 'game_directory':
val = `"${instancePath}"`;
val = `${addQuotes(needsQuote, instancePath)}`;
break;
case 'assets_root':
val = `"${assetsPath}"`;
val = `${addQuotes(needsQuote, assetsPath)}`;
break;
case 'assets_index_name':
val = mcJson.assets;
Expand All @@ -751,7 +798,7 @@ export const getJVMArguments113 = (
case 'natives_directory':
val = args[i].replace(
argDiscovery,
`"${path.join(instancePath, 'natives')}"`
`${addQuotes(needsQuote, path.join(instancePath, 'natives'))}`
);
break;
case 'launcher_name':
Expand All @@ -763,7 +810,7 @@ export const getJVMArguments113 = (
case 'classpath':
val = [...libraries, mcjar]
.filter(l => !l.natives)
.map(l => `"${l.path}"`)
.map(l => `${addQuotes(needsQuote, l.path)}`)
.join(process.platform === 'win32' ? ';' : ':');
break;
default:
Expand All @@ -773,6 +820,7 @@ export const getJVMArguments113 = (
args[i] = val;
}
}
if (!needsQuote) args[i] = args[i].replaceAll('"', '');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/desktop/views/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const Login = () => {
</div>
<div>
<Input
placeholder="2FA (just if needed)"
placeholder="2FA (optional)"
value={twofactor}
onChange={({ target: { value } }) => setTwofactor(value)}
css={`
Expand Down
Loading

0 comments on commit d06268b

Please sign in to comment.