Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel Scalzi
3837588ecd
Add doc. 2022-11-26 23:21:38 -05:00
Daniel Scalzi
21756de784
Fix refresh of java exec details. 2022-11-26 21:59:41 -05:00
Daniel Scalzi
8e76d6a2b9
Support 1.19. 2022-11-26 21:36:49 -05:00
Daniel Scalzi
a6e3d2b85c
Use classpath flag instead of hardcode. 2022-11-26 18:54:09 -05:00
5 changed files with 88 additions and 25 deletions

View File

@ -5,7 +5,7 @@
}, },
"extends": "eslint:recommended", "extends": "eslint:recommended",
"parserOptions": { "parserOptions": {
"ecmaVersion": 2019, "ecmaVersion": 2021,
"sourceType": "module" "sourceType": "module"
}, },
"rules": { "rules": {

View File

@ -118,7 +118,7 @@ class Module {
* @returns {Module} The parsed Module. * @returns {Module} The parsed Module.
*/ */
static fromJSON(json, serverid){ static fromJSON(json, serverid){
return new Module(json.id, json.name, json.type, json.required, json.artifact, json.subModules, serverid) return new Module(json.id, json.name, json.type, json.classpath, json.required, json.artifact, json.subModules, serverid)
} }
/** /**
@ -143,9 +143,10 @@ class Module {
} }
} }
constructor(id, name, type, required, artifact, subModules, serverid) { constructor(id, name, type, classpath, required, artifact, subModules, serverid) {
this.identifier = id this.identifier = id
this.type = type this.type = type
this.classpath = classpath
this._resolveMetaData() this._resolveMetaData()
this.name = name this.name = name
this.required = Required.fromJSON(required) this.required = Required.fromJSON(required)
@ -306,6 +307,13 @@ class Module {
return this.type return this.type
} }
/**
* @returns {boolean} Whether or not this library should be on the classpath.
*/
getClasspath(){
return this.classpath ?? true
}
} }
exports.Module exports.Module

View File

@ -709,6 +709,7 @@ class ProcessBuilder {
* @returns {{[id: string]: string}} An object containing the paths of each library mojang declares. * @returns {{[id: string]: string}} An object containing the paths of each library mojang declares.
*/ */
_resolveMojangLibraries(tempNativePath){ _resolveMojangLibraries(tempNativePath){
const nativesRegex = /.+:natives-([^-]+)(?:-(.+))?/
const libs = {} const libs = {}
const libArr = this.versionData.libraries const libArr = this.versionData.libraries
@ -716,27 +717,23 @@ class ProcessBuilder {
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, lib.natives)){ if(Library.validateRules(lib.rules, lib.natives)){
if(lib.natives == null){
const dlInfo = lib.downloads // Pre-1.19 has a natives object.
const artifact = dlInfo.artifact if(lib.natives != null) {
const to = path.join(this.libPath, artifact.path)
const versionIndependentId = lib.name.substring(0, lib.name.lastIndexOf(':'))
libs[versionIndependentId] = to
} else {
// Extract the native library. // Extract the native library.
const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/'] const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/']
const artifact = lib.downloads.classifiers[lib.natives[Library.mojangFriendlyOS()].replace('${arch}', process.arch.replace('x', ''))] const artifact = lib.downloads.classifiers[lib.natives[Library.mojangFriendlyOS()].replace('${arch}', process.arch.replace('x', ''))]
// Location of native zip. // Location of native zip.
const to = path.join(this.libPath, artifact.path) const to = path.join(this.libPath, artifact.path)
let zip = new AdmZip(to) let zip = new AdmZip(to)
let zipEntries = zip.getEntries() let zipEntries = zip.getEntries()
// Unzip the native zip. // Unzip the native zip.
for(let i=0; i<zipEntries.length; i++){ for(let i=0; i<zipEntries.length; i++){
const fileName = zipEntries[i].entryName const fileName = zipEntries[i].entryName
let shouldExclude = false let shouldExclude = false
// Exclude noted files. // Exclude noted files.
@ -754,9 +751,68 @@ class ProcessBuilder {
} }
}) })
} }
} }
} }
// 1.19+ logic
else if(lib.name.includes('natives-')) {
const regexTest = nativesRegex.exec(lib.name)
// const os = regexTest[1]
const arch = regexTest[2] ?? 'x64'
if(arch != process.arch) {
continue
}
// Extract the native library.
const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/', '.git', '.sha1']
const artifact = lib.downloads.artifact
// Location of native zip.
const to = path.join(this.libPath, artifact.path)
let zip = new AdmZip(to)
let zipEntries = zip.getEntries()
// Unzip the native zip.
for(let i=0; i<zipEntries.length; i++){
if(zipEntries[i].isDirectory) {
continue
}
const fileName = zipEntries[i].entryName
let shouldExclude = false
// Exclude noted files.
exclusionArr.forEach(function(exclusion){
if(fileName.indexOf(exclusion) > -1){
shouldExclude = true
}
})
const extractName = fileName.includes('/') ? fileName.substring(fileName.lastIndexOf('/')) : fileName
// Extract the file.
if(!shouldExclude){
fs.writeFile(path.join(tempNativePath, extractName), zipEntries[i].getData(), (err) => {
if(err){
logger.error('Error while extracting native library:', err)
}
})
}
}
}
// No natives
else {
const dlInfo = lib.downloads
const artifact = dlInfo.artifact
const to = path.join(this.libPath, artifact.path)
const versionIndependentId = lib.name.substring(0, lib.name.lastIndexOf(':'))
libs[versionIndependentId] = to
}
} }
} }
@ -816,15 +872,9 @@ class ProcessBuilder {
for(let sm of mdl.getSubModules()){ for(let sm of mdl.getSubModules()){
if(sm.getType() === DistroManager.Types.Library){ if(sm.getType() === DistroManager.Types.Library){
// TODO Add as file or something. if(sm.getClasspath()) {
const x = sm.getIdentifier() libs.push(sm.getArtifact().getPath())
console.log(x)
if(x.includes(':universal') || x.includes(':slim') || x.includes(':extra') || x.includes(':srg') || x.includes(':client')) {
console.log('SKIPPING ' + x)
continue
} }
libs.push(sm.getArtifact().getPath())
} }
// If this module has submodules, we need to resolve the libraries for those. // If this module has submodules, we need to resolve the libraries for those.
// To avoid unnecessary recursive calls, base case is checked here. // To avoid unnecessary recursive calls, base case is checked here.

View File

@ -138,8 +138,8 @@ function initSettingsValues(){
if(v.type === 'number' || v.type === 'text'){ if(v.type === 'number' || v.type === 'text'){
// Special Conditions // Special Conditions
if(cVal === 'JavaExecutable'){ if(cVal === 'JavaExecutable'){
populateJavaExecDetails(v.value)
v.value = gFn.apply(null, gFnOpts) v.value = gFn.apply(null, gFnOpts)
populateJavaExecDetails(v.value)
} else if (cVal === 'DataDirectory'){ } else if (cVal === 'DataDirectory'){
v.value = gFn.apply(null, gFnOpts) v.value = gFn.apply(null, gFnOpts)
} else if(cVal === 'JVMOptions'){ } else if(cVal === 'JVMOptions'){
@ -1380,7 +1380,6 @@ function prepareJavaTab(){
bindRangeSlider() bindRangeSlider()
populateMemoryStatus() populateMemoryStatus()
populateJavaReqDesc() populateJavaReqDesc()
populateJavaExecDetails()
} }
/** /**

View File

@ -208,6 +208,12 @@ The name of the module. Used on the UI.
The type of the module. The type of the module.
### `Module.classpath: boolean`
**OPTIONAL**
If the module is of type `Library`, whether the library should be added to the classpath. Defaults to true.
### `Module.required: Required` ### `Module.required: Required`
**OPTIONAL** **OPTIONAL**