If unable to load config, simply don't
This commit is contained in:
@@ -14,29 +14,33 @@ import { getKey } from './KeysHelper'
|
||||
|
||||
export async function readNormalConfig (): Promise<NormalConfig> {
|
||||
const version = await app.getVersion()
|
||||
const options = {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
}
|
||||
const doesFolderExist = await exists('', options)
|
||||
const doesConfigExist = await exists('config.dat', options)
|
||||
if (!doesFolderExist || !doesConfigExist) {
|
||||
if (!doesFolderExist) {
|
||||
await mkdir('', options)
|
||||
try {
|
||||
const options = {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
}
|
||||
const file = await create('config.dat', options)
|
||||
await file.write(
|
||||
new TextEncoder().encode(
|
||||
await encrypt(
|
||||
JSON.stringify(new NormalConfig(version)),
|
||||
await getKey(2)
|
||||
const doesFolderExist = await exists('', options)
|
||||
const doesConfigExist = await exists('config.dat', options)
|
||||
if (!doesFolderExist || !doesConfigExist) {
|
||||
if (!doesFolderExist) {
|
||||
await mkdir('', options)
|
||||
}
|
||||
const file = await create('config.dat', options)
|
||||
await file.write(
|
||||
new TextEncoder().encode(
|
||||
await encrypt(
|
||||
JSON.stringify(new NormalConfig(version)),
|
||||
await getKey(2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
await file.close()
|
||||
await file.close()
|
||||
return new NormalConfig(version)
|
||||
}
|
||||
const config = await readTextFile('config.dat', options)
|
||||
return NormalConfig.import(JSON.parse(await decrypt(config, await getKey(2))))
|
||||
} catch (_) {
|
||||
return new NormalConfig(version)
|
||||
}
|
||||
const config = await readTextFile('config.dat', options)
|
||||
return NormalConfig.import(JSON.parse(await decrypt(config, await getKey(2))))
|
||||
}
|
||||
|
||||
export async function writeNormalConfig (data: NormalConfig) {
|
||||
@@ -69,31 +73,35 @@ export async function writeNormalConfig (data: NormalConfig) {
|
||||
|
||||
export async function readVersionsConfig (): Promise<VersionsConfig> {
|
||||
const version = await app.getVersion()
|
||||
const options = {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
}
|
||||
const doesFolderExist = await exists('', options)
|
||||
const doesConfigExist = await exists('versions.dat', options)
|
||||
if (!doesFolderExist || !doesConfigExist) {
|
||||
if (!doesFolderExist) {
|
||||
await mkdir('', options)
|
||||
try {
|
||||
const options = {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
}
|
||||
const file = await create('versions.dat', options)
|
||||
await file.write(
|
||||
new TextEncoder().encode(
|
||||
await encrypt(
|
||||
JSON.stringify(new VersionsConfig(version)),
|
||||
await getKey(3)
|
||||
const doesFolderExist = await exists('', options)
|
||||
const doesConfigExist = await exists('versions.dat', options)
|
||||
if (!doesFolderExist || !doesConfigExist) {
|
||||
if (!doesFolderExist) {
|
||||
await mkdir('', options)
|
||||
}
|
||||
const file = await create('versions.dat', options)
|
||||
await file.write(
|
||||
new TextEncoder().encode(
|
||||
await encrypt(
|
||||
JSON.stringify(new VersionsConfig(version)),
|
||||
await getKey(3)
|
||||
)
|
||||
)
|
||||
)
|
||||
await file.close()
|
||||
return new VersionsConfig(version)
|
||||
}
|
||||
const config = await readTextFile('versions.dat', options)
|
||||
return VersionsConfig.import(
|
||||
JSON.parse(await decrypt(config, await getKey(3)))
|
||||
)
|
||||
await file.close()
|
||||
} catch (_) {
|
||||
return new VersionsConfig(version)
|
||||
}
|
||||
const config = await readTextFile('versions.dat', options)
|
||||
return VersionsConfig.import(
|
||||
JSON.parse(await decrypt(config, await getKey(3)))
|
||||
)
|
||||
}
|
||||
|
||||
export async function writeVersionsConfig (data: VersionsConfig) {
|
||||
|
||||
Reference in New Issue
Block a user