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