Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Finish Updating with symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
moehreag committed Dec 20, 2021
1 parent 962cf35 commit 650cf95
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/js/configmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ exports.getCommonDirectory = function(){
* @returns {string} The launcher's instance directory.
*/
exports.getInstanceDirectory = function(){
return path.join(exports.getDataDirectory(), 'minecraft')
return path.join(exports.getDataDirectory(), 'instances')
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/assets/js/distromanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Module {
break
case exports.Types.File:
default:
this.artifact.path = path.join(ConfigManager.getInstanceDirectory(), pth)
this.artifact.path = path.join(ConfigManager.getInstanceDirectory(), serverid, pth)
break
}

Expand Down
2 changes: 1 addition & 1 deletion app/assets/js/dropinmodutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports.addDropinMods = function(files, modsdir) {
* @returns {boolean} True if the mod was deleted, otherwise false.
*/
exports.deleteDropinMod = function(modsDir, fullName){
const res = shell.moveItemToTrash(path.join(modsDir, fullName))
const res = shell.trashItem(path.join(modsDir, fullName))
if(!res){
shell.beep()
}
Expand Down
40 changes: 39 additions & 1 deletion app/assets/js/processbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const logger = LoggerUtil('%c[ProcessBuilder]', 'color: #003996; font-weight: bo
class ProcessBuilder {

constructor(distroServer, versionData, forgeData, authUser, launcherVersion){
this.gameDir = path.join(ConfigManager.getInstanceDirectory())
this.gameDir = path.join(ConfigManager.getInstanceDirectory(), ConfigManager.getSelectedServer())
this.commonDir = ConfigManager.getCommonDirectory()
this.modDir = path.join(this.commonDir, 'modstore', distroServer.getID())
this.mcDir = path.join(ConfigManager.getDataDirectory(), 'minecraft')
this.server = distroServer
this.versionData = versionData
this.forgeData = forgeData
Expand All @@ -34,6 +35,10 @@ class ProcessBuilder {
*/
build(){
fs.ensureDirSync(this.gameDir)
fs.ensureDirSync(this.mcDir)

this.createSymlinks()

const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
process.throwDeprecation = true

Expand Down Expand Up @@ -83,6 +88,39 @@ class ProcessBuilder {
return child
}

/**
* creates symlinks for often-used folders for all Instances
*/
createSymlinks(){
this._createSymLinks('resourcepacks', 'dir')
this._createSymLinks('config', 'dir')
this._createSymLinks('saves', 'dir')
this._createSymLinks('servers.dat')
this._createSymLinks('shaderpacks', 'dir')
}

/**
* creates the symlinks
*/
_createSymLinks(folder, type = 'file'){
if (fs.existsSync(path.join(this.gameDir, folder))) {
logger.log('Won\'t create', folder, 'symlink because the folder/symlink already exists!')
} else {

if (type == 'dir'){
fs.ensureDirSync(path.join(this.mcDir, folder))
}

fs.symlink(path.join(this.mcDir, folder), path.join(this.gameDir, folder), type, (err) => {
if (err){
logger.warn('Failed to create', folder, 'symlink!')
} else {
logger.log('Successfully created symlink for the', folder, 'folder!')
}
})
}
}

/**
* resolves a full mod path from just the name
*
Expand Down
4 changes: 2 additions & 2 deletions app/assets/js/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ let CACHE_DROPIN_MODS
*/
function resolveDropinModsForUI(){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), 'mods')
CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), ConfigManager.getSelectedServer(), 'mods')
CACHE_DROPIN_MODS = DropinModUtil.scanForDropinMods(CACHE_SETTINGS_MODS_DIR, serv.getMinecraftVersion())

let dropinMods = ''
Expand Down Expand Up @@ -799,7 +799,7 @@ let CACHE_SELECTED_SHADERPACK
*/
function resolveShaderpacksForUI(){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory())
CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory(), ConfigManager.getSelectedServer())
CACHE_SHADERPACKS = DropinModUtil.scanForShaderpacks(CACHE_SETTINGS_INSTANCE_DIR)
CACHE_SELECTED_SHADERPACK = DropinModUtil.getEnabledShaderpack(CACHE_SETTINGS_INSTANCE_DIR)

Expand Down

0 comments on commit 650cf95

Please sign in to comment.