mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Refactor Athena's Shield configuration handling
This commit is contained in:
parent
f0321e1f6d
commit
0348e83ffe
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"athenaShieldActivated": false,
|
|
||||||
"menuVisibility": "visible",
|
|
||||||
"debug": "false"
|
|
||||||
}
|
|
@ -2,75 +2,62 @@ const fs = require('fs')
|
|||||||
const readline = require('readline')
|
const readline = require('readline')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
// Path to the configuration file
|
const configPath = path.join(__dirname, 'variables.json')
|
||||||
const configPath = path.join(__dirname, 'variables.athshield')
|
|
||||||
|
|
||||||
// Load the variables from the file
|
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
const rawData = fs.readFileSync(configPath)
|
const rawData = fs.readFileSync(configPath)
|
||||||
return JSON.parse(rawData.toString()) // Convert Buffer to string
|
return JSON.parse(rawData.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the variables to the file
|
|
||||||
function saveConfig(config) {
|
function saveConfig(config) {
|
||||||
const data = JSON.stringify(config, null, 2)
|
const data = JSON.stringify(config, null, 2)
|
||||||
fs.writeFileSync(configPath, data)
|
fs.writeFileSync(configPath, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the readline interface
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
})
|
})
|
||||||
|
|
||||||
// Function to ask questions to the user
|
|
||||||
function startCLI() {
|
function startCLI() {
|
||||||
const config = loadConfig()
|
const config = loadConfig()
|
||||||
|
|
||||||
rl.question('Would you like to activate Athena\'s Shield? (yes/no): ', (answer) => {
|
rl.question('Would you like to activate extra file verification? (yes/no): ', (answer) => {
|
||||||
if (answer.trim().startsWith('//')) {
|
|
||||||
console.log('This is a comment; the line is ignored.')
|
|
||||||
rl.close()
|
rl.close()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
if (answer.toLowerCase() === 'yes') {
|
if (answer.toLowerCase() === 'yes') {
|
||||||
config.athenaShieldActivated = true
|
config.extraFileVerifActivated = true
|
||||||
|
|
||||||
rl.question('Would you like to activate debug mode? (yes/no): ', (debugAnswer) => {
|
rl.question('Would you like to activate debug mode? (yes/no): ', (debugAnswer) => {
|
||||||
config.debug = debugAnswer.toLowerCase() === 'yes' // Set debug to true or false
|
config.debug = debugAnswer.toLowerCase() === 'yes'
|
||||||
|
|
||||||
rl.question('Would you like to hide or block the menu? (hide/block): ', (menuAnswer) => {
|
rl.question('Would you like to hide or block the menu? (hide/block): ', (menuAnswer) => {
|
||||||
if (menuAnswer.trim().startsWith('//')) {
|
|
||||||
console.log('This is a comment; the line is ignored.')
|
|
||||||
rl.close()
|
rl.close()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
if (menuAnswer.toLowerCase() === 'hide') {
|
if (menuAnswer.toLowerCase() === 'hide') {
|
||||||
config.menuVisibility = 'hidden' // Set to 'hidden'
|
config.menuVisibility = 'hidden'
|
||||||
console.log('Athena\'s Shield activated. Menu hidden.')
|
console.log('Extra file verification is activated. Menu hidden.')
|
||||||
} else if (menuAnswer.toLowerCase() === 'block') {
|
} else if (menuAnswer.toLowerCase() === 'block') {
|
||||||
config.menuVisibility = 'blocked' // Set to 'blocked'
|
config.menuVisibility = 'blocked'
|
||||||
console.log('Athena\'s Shield activated. Menu blocked.')
|
console.log('Extra file verification is activated. Menu blocked.')
|
||||||
} else {
|
} else {
|
||||||
console.log('Invalid option for the menu.')
|
console.log('Invalid option for the menu.')
|
||||||
rl.close()
|
rl.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the modified configuration
|
|
||||||
saveConfig(config)
|
saveConfig(config)
|
||||||
rl.close()
|
rl.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else if (answer.toLowerCase() === 'no') {
|
} else if (answer.toLowerCase() === 'no') {
|
||||||
console.log('Athena\'s Shield not activated. Closing the CLI.')
|
console.log('Extra file verification is not activated. Closing the CLI.')
|
||||||
config.athenaShieldActivated = false
|
config.extraFileVerifActivated = false
|
||||||
config.menuVisibility = 'visible' // Reset to default
|
config.menuVisibility = 'visible'
|
||||||
config.debug = 'false'
|
config.debug = false
|
||||||
|
|
||||||
// Save the modified configuration
|
|
||||||
saveConfig(config)
|
saveConfig(config)
|
||||||
rl.close()
|
rl.close()
|
||||||
} else {
|
} else {
|
||||||
@ -80,5 +67,4 @@ function startCLI() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch the CLI
|
|
||||||
startCLI()
|
startCLI()
|
@ -1,37 +1,30 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
// Chemin vers le fichier de configuration
|
const configPath = path.join(__dirname, 'variables.json')
|
||||||
const configPath = path.join(__dirname, 'variables.athshield')
|
|
||||||
|
|
||||||
// Classe pour gérer Athena's Shield
|
class ExtraFileVerification {
|
||||||
class AthenaShield {
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.config = this.loadConfig()
|
this.config = this.loadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Charger les variables depuis le fichier
|
|
||||||
loadConfig() {
|
loadConfig() {
|
||||||
const rawData = fs.readFileSync(configPath)
|
const rawData = fs.readFileSync(configPath)
|
||||||
return JSON.parse(rawData.toString())
|
return JSON.parse(rawData.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer le statut d'Athena's Shield
|
|
||||||
get status() {
|
get status() {
|
||||||
return this.config.athenaShieldActivated
|
return this.config.extraFileVerifActivated
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer la visibilité du menu
|
|
||||||
get type() {
|
get type() {
|
||||||
return this.config.menuVisibility
|
return this.config.menuVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer le mode debug
|
|
||||||
get debug() {
|
get debug() {
|
||||||
return this.config.debug
|
return this.config.debug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exporter une instance de la classe
|
|
||||||
const athenaShieldInstance = new AthenaShield()
|
const athenaShieldInstance = new AthenaShield()
|
||||||
module.exports = athenaShieldInstance
|
module.exports = athenaShieldInstance
|
5
app/assets/extraverif/variables.json
Normal file
5
app/assets/extraverif/variables.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extraFileVerifActivated": false,
|
||||||
|
"menuVisibility": "visible",
|
||||||
|
"debug": "false"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user