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> {
|
export async function readNormalConfig (): Promise<NormalConfig> {
|
||||||
const version = await app.getVersion()
|
const version = await app.getVersion()
|
||||||
const options = {
|
try {
|
||||||
baseDir: BaseDirectory.AppLocalData
|
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)
|
|
||||||
}
|
}
|
||||||
const file = await create('config.dat', options)
|
const doesFolderExist = await exists('', options)
|
||||||
await file.write(
|
const doesConfigExist = await exists('config.dat', options)
|
||||||
new TextEncoder().encode(
|
if (!doesFolderExist || !doesConfigExist) {
|
||||||
await encrypt(
|
if (!doesFolderExist) {
|
||||||
JSON.stringify(new NormalConfig(version)),
|
await mkdir('', options)
|
||||||
await getKey(2)
|
}
|
||||||
|
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)
|
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) {
|
export async function writeNormalConfig (data: NormalConfig) {
|
||||||
@@ -69,31 +73,35 @@ export async function writeNormalConfig (data: NormalConfig) {
|
|||||||
|
|
||||||
export async function readVersionsConfig (): Promise<VersionsConfig> {
|
export async function readVersionsConfig (): Promise<VersionsConfig> {
|
||||||
const version = await app.getVersion()
|
const version = await app.getVersion()
|
||||||
const options = {
|
try {
|
||||||
baseDir: BaseDirectory.AppLocalData
|
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)
|
|
||||||
}
|
}
|
||||||
const file = await create('versions.dat', options)
|
const doesFolderExist = await exists('', options)
|
||||||
await file.write(
|
const doesConfigExist = await exists('versions.dat', options)
|
||||||
new TextEncoder().encode(
|
if (!doesFolderExist || !doesConfigExist) {
|
||||||
await encrypt(
|
if (!doesFolderExist) {
|
||||||
JSON.stringify(new VersionsConfig(version)),
|
await mkdir('', options)
|
||||||
await getKey(3)
|
}
|
||||||
|
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)
|
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) {
|
export async function writeVersionsConfig (data: VersionsConfig) {
|
||||||
|
|||||||
Reference in New Issue
Block a user