mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 19:52:14 -08:00
Native files are now stored in the OS temp directory.
Temp folder is deleted when minecraft is closed. If the Node.js process ends abruptly, the folder will not delete. As a dirty way to counter this, the directory we extract native files to is cleaned in the preloader. Maybe we'll come up with a more elegant solution in the future.
This commit is contained in:
parent
5475ac0c69
commit
be39d60705
@ -1350,7 +1350,7 @@ p {
|
|||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* *
|
* *
|
||||||
* Overlay View (app.ejs) *
|
* Overlay View (overlay.ejs) *
|
||||||
* *
|
* *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ function asyncSystemScan(launchAfter = true){
|
|||||||
|
|
||||||
sysAEx.on('message', (m) => {
|
sysAEx.on('message', (m) => {
|
||||||
if(m.content === 'validateJava'){
|
if(m.content === 'validateJava'){
|
||||||
m.result = null
|
|
||||||
if(m.result == null){
|
if(m.result == null){
|
||||||
// If the result is null, no valid Java installation was found.
|
// If the result is null, no valid Java installation was found.
|
||||||
// Show this information to the user.
|
// Show this information to the user.
|
||||||
|
@ -100,6 +100,16 @@ exports.isFirstLaunch = function(){
|
|||||||
return firstLaunch
|
return firstLaunch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the folder in the OS temp directory which we
|
||||||
|
* will use to extract and store native dependencies for game launch.
|
||||||
|
*
|
||||||
|
* @returns {string} The name of the folder.
|
||||||
|
*/
|
||||||
|
exports.getTempNativeFolder = function(){
|
||||||
|
return 'WCNatives'
|
||||||
|
}
|
||||||
|
|
||||||
// System Settings (Unconfigurable on UI)
|
// System Settings (Unconfigurable on UI)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
const {AssetGuard} = require('./assetguard.js')
|
const {AssetGuard} = require('./assetguard.js')
|
||||||
const ConfigManager = require('./configmanager.js')
|
const ConfigManager = require('./configmanager.js')
|
||||||
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
console.log('Preloading')
|
console.log('Preloading')
|
||||||
|
|
||||||
@ -16,3 +18,12 @@ if(ConfigManager.getSelectedServer() == null){
|
|||||||
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getGameDirectory()))
|
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getGameDirectory()))
|
||||||
ConfigManager.save()
|
ConfigManager.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up temp dir.
|
||||||
|
rimraf(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
|
||||||
|
if(err){
|
||||||
|
console.warn('Error while cleaning temp dir', err)
|
||||||
|
} else {
|
||||||
|
console.log('Cleaned temp dir.')
|
||||||
|
}
|
||||||
|
})
|
@ -6,9 +6,12 @@ const AdmZip = require('adm-zip')
|
|||||||
const {AssetGuard, Library} = require('./assetguard.js')
|
const {AssetGuard, Library} = require('./assetguard.js')
|
||||||
const child_process = require('child_process')
|
const child_process = require('child_process')
|
||||||
const ConfigManager = require('./configmanager.js')
|
const ConfigManager = require('./configmanager.js')
|
||||||
|
const crypto = require('crypto')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const mkpath = require('mkdirp')
|
const mkpath = require('mkdirp')
|
||||||
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const rimraf = require('rimraf')
|
||||||
const {URL} = require('url')
|
const {URL} = require('url')
|
||||||
|
|
||||||
class ProcessBuilder {
|
class ProcessBuilder {
|
||||||
@ -32,10 +35,11 @@ class ProcessBuilder {
|
|||||||
* Convienence method to run the functions typically used to build a process.
|
* Convienence method to run the functions typically used to build a process.
|
||||||
*/
|
*/
|
||||||
build(){
|
build(){
|
||||||
|
const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
|
||||||
process.throwDeprecation = true
|
process.throwDeprecation = true
|
||||||
const mods = this.resolveDefaultMods()
|
const mods = this.resolveDefaultMods()
|
||||||
this.constructFMLModList(mods, true)
|
this.constructFMLModList(mods, true)
|
||||||
const args = this.constructJVMArguments(mods)
|
const args = this.constructJVMArguments(mods, tempNativePath)
|
||||||
|
|
||||||
console.log(args)
|
console.log(args)
|
||||||
|
|
||||||
@ -51,6 +55,13 @@ class ProcessBuilder {
|
|||||||
})
|
})
|
||||||
child.on('close', (code, signal) => {
|
child.on('close', (code, signal) => {
|
||||||
console.log('Exited with code', code)
|
console.log('Exited with code', code)
|
||||||
|
rimraf(tempNativePath, (err) => {
|
||||||
|
if(err){
|
||||||
|
console.warn('Error while deleting temp dir', err)
|
||||||
|
} else {
|
||||||
|
console.log('Temp dir deleted successfully.')
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return child
|
return child
|
||||||
@ -93,15 +104,16 @@ class ProcessBuilder {
|
|||||||
* Construct the argument array that will be passed to the JVM process.
|
* Construct the argument array that will be passed to the JVM process.
|
||||||
*
|
*
|
||||||
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
||||||
|
* @param {string} tempNativePath The path to store the native libraries.
|
||||||
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
||||||
*/
|
*/
|
||||||
constructJVMArguments(mods){
|
constructJVMArguments(mods, tempNativePath){
|
||||||
|
|
||||||
let args = ['-Xmx' + ConfigManager.getMaxRAM(),
|
let args = ['-Xmx' + ConfigManager.getMaxRAM(),
|
||||||
'-Xms' + ConfigManager.getMinRAM(),,
|
'-Xms' + ConfigManager.getMinRAM(),,
|
||||||
'-Djava.library.path=' + path.join(this.dir, 'natives'),
|
'-Djava.library.path=' + tempNativePath,
|
||||||
'-cp',
|
'-cp',
|
||||||
this.classpathArg(mods).join(';'),
|
this.classpathArg(mods, tempNativePath).join(';'),
|
||||||
this.forgeData.mainClass]
|
this.forgeData.mainClass]
|
||||||
|
|
||||||
// For some reason this will add an undefined value unless
|
// For some reason this will add an undefined value unless
|
||||||
@ -196,9 +208,10 @@ class ProcessBuilder {
|
|||||||
* this method requires all enabled mods as an input
|
* this method requires all enabled mods as an input
|
||||||
*
|
*
|
||||||
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
||||||
|
* @param {string} tempNativePath The path to store the native libraries.
|
||||||
* @returns {Array.<string>} An array containing the paths of each library required by this process.
|
* @returns {Array.<string>} An array containing the paths of each library required by this process.
|
||||||
*/
|
*/
|
||||||
classpathArg(mods){
|
classpathArg(mods, tempNativePath){
|
||||||
let cpArgs = []
|
let cpArgs = []
|
||||||
|
|
||||||
// Add the version.jar to the classpath.
|
// Add the version.jar to the classpath.
|
||||||
@ -206,7 +219,7 @@ class ProcessBuilder {
|
|||||||
cpArgs.push(path.join(this.dir, 'versions', version, version + '.jar'))
|
cpArgs.push(path.join(this.dir, 'versions', version, version + '.jar'))
|
||||||
|
|
||||||
// Resolve the Mojang declared libraries.
|
// Resolve the Mojang declared libraries.
|
||||||
const mojangLibs = this._resolveMojangLibraries()
|
const mojangLibs = this._resolveMojangLibraries(tempNativePath)
|
||||||
cpArgs = cpArgs.concat(mojangLibs)
|
cpArgs = cpArgs.concat(mojangLibs)
|
||||||
|
|
||||||
// Resolve the server declared libraries.
|
// Resolve the server declared libraries.
|
||||||
@ -222,13 +235,14 @@ class ProcessBuilder {
|
|||||||
*
|
*
|
||||||
* TODO - clean up function
|
* TODO - clean up function
|
||||||
*
|
*
|
||||||
|
* @param {string} tempNativePath The path to store the native libraries.
|
||||||
* @returns {Array.<string>} An array containing the paths of each library mojang declares.
|
* @returns {Array.<string>} An array containing the paths of each library mojang declares.
|
||||||
*/
|
*/
|
||||||
_resolveMojangLibraries(){
|
_resolveMojangLibraries(tempNativePath){
|
||||||
const libs = []
|
const libs = []
|
||||||
|
|
||||||
const libArr = this.versionData.libraries
|
const libArr = this.versionData.libraries
|
||||||
const nativePath = path.join(this.dir, 'natives')
|
mkpath.sync(tempNativePath)
|
||||||
for(let i=0; i<libArr.length; i++){
|
for(let i=0; i<libArr.length; i++){
|
||||||
const lib = libArr[i]
|
const lib = libArr[i]
|
||||||
if(Library.validateRules(lib.rules)){
|
if(Library.validateRules(lib.rules)){
|
||||||
@ -269,8 +283,7 @@ class ProcessBuilder {
|
|||||||
|
|
||||||
// Extract the file.
|
// Extract the file.
|
||||||
if(!shouldExclude){
|
if(!shouldExclude){
|
||||||
mkpath.sync(path.join(nativePath, fileName, '..'))
|
fs.writeFile(path.join(tempNativePath, fileName), zipEntries[i].getData(), (err) => {
|
||||||
fs.writeFile(path.join(nativePath, fileName), zipEntries[i].getData(), (err) => {
|
|
||||||
if(err){
|
if(err){
|
||||||
console.error('Error while extracting native library:', err)
|
console.error('Error while extracting native library:', err)
|
||||||
}
|
}
|
||||||
@ -278,8 +291,6 @@ class ProcessBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
libs.push(to)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@ -222,8 +222,7 @@
|
|||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"base64-js": {
|
"base64-js": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
@ -361,7 +360,6 @@
|
|||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "1.0.0",
|
"balanced-match": "1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@ -580,8 +578,7 @@
|
|||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"concat-stream": {
|
"concat-stream": {
|
||||||
"version": "1.6.0",
|
"version": "1.6.0",
|
||||||
@ -1409,8 +1406,7 @@
|
|||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"get-caller-file": {
|
"get-caller-file": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -1443,7 +1439,6 @@
|
|||||||
"version": "7.1.2",
|
"version": "7.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"fs.realpath": "1.0.0",
|
"fs.realpath": "1.0.0",
|
||||||
"inflight": "1.0.6",
|
"inflight": "1.0.6",
|
||||||
@ -1581,7 +1576,6 @@
|
|||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"once": "1.4.0",
|
"once": "1.4.0",
|
||||||
"wrappy": "1.0.2"
|
"wrappy": "1.0.2"
|
||||||
@ -1974,7 +1968,6 @@
|
|||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "1.1.11"
|
"brace-expansion": "1.1.11"
|
||||||
}
|
}
|
||||||
@ -2170,8 +2163,7 @@
|
|||||||
"path-is-absolute": {
|
"path-is-absolute": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"path-is-inside": {
|
"path-is-inside": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -2475,7 +2467,6 @@
|
|||||||
"version": "2.6.2",
|
"version": "2.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
|
||||||
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
|
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"glob": "7.1.2"
|
"glob": "7.1.2"
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
"jquery": "^3.3.1",
|
"jquery": "^3.3.1",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"request-promise-native": "^1.0.5",
|
"request-promise-native": "^1.0.5",
|
||||||
|
"rimraf": "^2.6.2",
|
||||||
"tar-fs": "^1.16.0",
|
"tar-fs": "^1.16.0",
|
||||||
"uuid": "^3.2.1",
|
"uuid": "^3.2.1",
|
||||||
"winreg": "^1.2.4"
|
"winreg": "^1.2.4"
|
||||||
|
Loading…
Reference in New Issue
Block a user