Added drag/drop functionality to the add mods button.
You can now drag one or more files onto the add mods button in order to add them to the mods directory. Only jar, litemod, and zip files will be moved. Changed eslint to use a single configuration file, with overrides for the UI scripts. Now using fs-extra, replace usages of rimraf and mkdirp with fs-extra functions.
This commit is contained in:
@@ -1545,13 +1545,15 @@ input:checked + .toggleSwitchSlider:before {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#settingsDropinFileSystemButton:hover,
|
||||
#settingsDropinFileSystemButton:focus {
|
||||
#settingsDropinFileSystemButton:focus,
|
||||
#settingsDropinFileSystemButton[drag] {
|
||||
background: rgba(54, 54, 54, 0.25);
|
||||
text-shadow: 0px 0px 20px white;
|
||||
}
|
||||
/* Refresh instructions on the file system button. */
|
||||
#settingsDropinRefreshNote {
|
||||
font-size: 10px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Button to remove drop-in mods. */
|
||||
@@ -2663,7 +2665,6 @@ input:checked + .toggleSwitchSlider:before {
|
||||
box-shadow: 0px 0px 10px 0px rgb(0, 0, 0);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
/*background-image: url('https://cdn.discordapp.com/avatars/169197209630277642/6650b5a50e1cb3d00a79b9b88b9a0cd4.png');*/
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: contain;
|
||||
|
||||
@@ -4,8 +4,7 @@ const async = require('async')
|
||||
const child_process = require('child_process')
|
||||
const crypto = require('crypto')
|
||||
const EventEmitter = require('events')
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const Registry = require('winreg')
|
||||
const request = require('request')
|
||||
@@ -360,7 +359,7 @@ class AssetGuard extends EventEmitter {
|
||||
const versionPath = path.join(commonPath, 'versions', forgeVersion.id)
|
||||
const versionFile = path.join(versionPath, forgeVersion.id + '.json')
|
||||
if(!fs.existsSync(versionFile)){
|
||||
mkpath.sync(versionPath)
|
||||
fs.ensureDirSync(versionPath)
|
||||
fs.writeFileSync(path.join(versionPath, forgeVersion.id + '.json'), zipEntries[i].getData())
|
||||
resolve(forgeVersion)
|
||||
} else {
|
||||
@@ -996,7 +995,7 @@ class AssetGuard extends EventEmitter {
|
||||
const url = await self._getVersionDataUrl(version)
|
||||
//This download will never be tracked as it's essential and trivial.
|
||||
console.log('Preparing download of ' + version + ' assets.')
|
||||
mkpath.sync(versionPath)
|
||||
fs.ensureDirSync(versionPath)
|
||||
const stream = request(url).pipe(fs.createWriteStream(versionFile))
|
||||
stream.on('finish', () => {
|
||||
resolve(JSON.parse(fs.readFileSync(versionFile)))
|
||||
@@ -1078,7 +1077,7 @@ class AssetGuard extends EventEmitter {
|
||||
let data = null
|
||||
if(!fs.existsSync(assetIndexLoc) || force){
|
||||
console.log('Downloading ' + versionData.id + ' asset index.')
|
||||
mkpath.sync(indexPath)
|
||||
fs.ensureDirSync(indexPath)
|
||||
const stream = request(assetIndex.url).pipe(fs.createWriteStream(assetIndexLoc))
|
||||
stream.on('finish', () => {
|
||||
data = JSON.parse(fs.readFileSync(assetIndexLoc, 'utf-8'))
|
||||
@@ -1457,7 +1456,7 @@ class AssetGuard extends EventEmitter {
|
||||
|
||||
async.eachLimit(dlQueue, limit, (asset, cb) => {
|
||||
|
||||
mkpath.sync(path.join(asset.to, '..'))
|
||||
fs.ensureDirSync(path.join(asset.to, '..'))
|
||||
|
||||
let req = request(asset.from)
|
||||
req.pause()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const fs = require('fs-extra')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
|
||||
@@ -98,7 +97,7 @@ exports.load = function(){
|
||||
|
||||
if(!fs.existsSync(filePath)){
|
||||
// Create all parent directories.
|
||||
mkpath.sync(path.join(filePath, '..'))
|
||||
fs.ensureDirSync(path.join(filePath, '..'))
|
||||
config = DEFAULT_CONFIG
|
||||
exports.save()
|
||||
} else {
|
||||
@@ -110,7 +109,7 @@ exports.load = function(){
|
||||
logger.error(err)
|
||||
logger.log('Configuration file contains malformed JSON or is corrupt.')
|
||||
logger.log('Generating a new configuration file.')
|
||||
mkpath.sync(path.join(filePath, '..'))
|
||||
fs.ensureDirSync(path.join(filePath, '..'))
|
||||
config = DEFAULT_CONFIG
|
||||
exports.save()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const { shell } = require('electron')
|
||||
|
||||
@@ -16,9 +15,7 @@ const DISABLED_EXT = '.disabled'
|
||||
* @param {string} modsDir The path to the mods directory.
|
||||
*/
|
||||
exports.validateModsDir = function(modsDir) {
|
||||
if(!fs.existsSync(modsDir)) {
|
||||
mkpath.sync(modsDir)
|
||||
}
|
||||
fs.ensureDirSync(modsDir)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +63,22 @@ exports.scanForDropinMods = function(modsDir, version) {
|
||||
return modsDiscovered
|
||||
}
|
||||
|
||||
/**
|
||||
* Add dropin mods.
|
||||
*
|
||||
* @param {FileList} files The files to add.
|
||||
* @param {string} modsDir The path to the mods directory.
|
||||
*/
|
||||
exports.addDropinMods = function(files, modsdir) {
|
||||
|
||||
for(let f of files) {
|
||||
if(MOD_REGEX.exec(f.name) != null) {
|
||||
fs.moveSync(f.path, path.join(modsdir, f.name))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a drop-in mod from the file system.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const {ipcRenderer} = require('electron')
|
||||
const fs = require('fs-extra')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const ConfigManager = require('./configmanager')
|
||||
const DistroManager = require('./distromanager')
|
||||
@@ -56,7 +56,7 @@ DistroManager.pullRemote().then((data) => {
|
||||
})
|
||||
|
||||
// Clean up temp dir incase previous launches ended unexpectedly.
|
||||
rimraf(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
|
||||
fs.remove(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
|
||||
if(err){
|
||||
logger.warn('Error while cleaning natives directory', err)
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
const AdmZip = require('adm-zip')
|
||||
const child_process = require('child_process')
|
||||
const crypto = require('crypto')
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const fs = require('fs-extra')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const rimraf = require('rimraf')
|
||||
const {URL} = require('url')
|
||||
|
||||
const { Library } = require('./assetguard')
|
||||
@@ -36,7 +34,7 @@ class ProcessBuilder {
|
||||
* Convienence method to run the functions typically used to build a process.
|
||||
*/
|
||||
build(){
|
||||
mkpath.sync(this.gameDir)
|
||||
fs.ensureDirSync(this.gameDir)
|
||||
const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
|
||||
process.throwDeprecation = true
|
||||
this.setupLiteLoader()
|
||||
@@ -74,7 +72,7 @@ class ProcessBuilder {
|
||||
})
|
||||
child.on('close', (code, signal) => {
|
||||
logger.log('Exited with code', code)
|
||||
rimraf(tempNativePath, (err) => {
|
||||
fs.remove(tempNativePath, (err) => {
|
||||
if(err){
|
||||
logger.warn('Error while deleting temp dir', err)
|
||||
} else {
|
||||
@@ -364,7 +362,7 @@ class ProcessBuilder {
|
||||
const libs = []
|
||||
|
||||
const libArr = this.versionData.libraries
|
||||
mkpath.sync(tempNativePath)
|
||||
fs.ensureDirSync(tempNativePath)
|
||||
for(let i=0; i<libArr.length; i++){
|
||||
const lib = libArr[i]
|
||||
if(Library.validateRules(lib.rules)){
|
||||
|
||||
@@ -643,6 +643,25 @@ function bindDropinModFileSystemButton(){
|
||||
DropinModUtil.validateModsDir(CACHE_SETTINGS_MODS_DIR)
|
||||
shell.openItem(CACHE_SETTINGS_MODS_DIR)
|
||||
}
|
||||
fsBtn.ondragenter = e => {
|
||||
e.dataTransfer.dropEffect = 'move'
|
||||
fsBtn.setAttribute('drag', '')
|
||||
e.preventDefault()
|
||||
}
|
||||
fsBtn.ondragover = e => {
|
||||
e.preventDefault()
|
||||
}
|
||||
fsBtn.ondragleave = e => {
|
||||
fsBtn.removeAttribute('drag')
|
||||
}
|
||||
|
||||
fsBtn.ondrop = e => {
|
||||
fsBtn.removeAttribute('drag')
|
||||
e.preventDefault()
|
||||
|
||||
DropinModUtil.addDropinMods(e.dataTransfer.files, CACHE_SETTINGS_MODS_DIR)
|
||||
reloadDropinMods()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,14 +695,18 @@ function saveDropinModConfiguration(){
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if(getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods'){
|
||||
if(e.key === 'F5'){
|
||||
resolveDropinModsForUI()
|
||||
bindDropinModsRemoveButton()
|
||||
bindDropinModFileSystemButton()
|
||||
bindModsToggleSwitch()
|
||||
reloadDropinMods()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function reloadDropinMods(){
|
||||
resolveDropinModsForUI()
|
||||
bindDropinModsRemoveButton()
|
||||
bindDropinModFileSystemButton()
|
||||
bindModsToggleSwitch()
|
||||
}
|
||||
|
||||
// Server status bar functions.
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user