2017-10-19 23:04:47 +00:00
|
|
|
/* eslint-disable no-sync */
|
2017-07-26 19:27:18 +00:00
|
|
|
|
|
|
|
import * as fs from 'fs'
|
|
|
|
import * as path from 'path'
|
2017-11-20 01:30:16 +00:00
|
|
|
import * as os from 'os'
|
|
|
|
import { getProductName } from '../app/package-info'
|
|
|
|
import { getExecutableName } from './dist-info'
|
|
|
|
|
|
|
|
function getUserDataPath() {
|
|
|
|
if (process.platform === 'win32') {
|
2018-06-22 13:44:22 +00:00
|
|
|
if (process.env.APPDATA) {
|
|
|
|
return path.join(process.env.APPDATA, getExecutableName())
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
`Unable to find the application data directory on Windows :(`
|
|
|
|
)
|
|
|
|
}
|
2017-11-20 01:30:16 +00:00
|
|
|
} else if (process.platform === 'darwin') {
|
|
|
|
const home = os.homedir()
|
|
|
|
return path.join(home, 'Library', 'Application Support', getProductName())
|
|
|
|
} else if (process.platform === 'linux') {
|
|
|
|
if (process.env.XDG_CONFIG_HOME) {
|
|
|
|
return path.join(process.env.XDG_CONFIG_HOME, getProductName())
|
|
|
|
}
|
|
|
|
const home = os.homedir()
|
|
|
|
return path.join(home, '.config', getProductName())
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
2020-06-24 18:28:06 +00:00
|
|
|
`I dunno how to resolve the user data path for ${process.platform} ${process.arch} :(`
|
2017-11-20 01:30:16 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-07-26 19:27:18 +00:00
|
|
|
|
|
|
|
export function getLogFiles(): ReadonlyArray<string> {
|
2017-09-24 00:01:43 +00:00
|
|
|
const directory = path.join(getUserDataPath(), 'logs')
|
2017-07-26 19:27:18 +00:00
|
|
|
if (!fs.existsSync(directory)) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileNames = fs.readdirSync(directory)
|
|
|
|
return fileNames
|
|
|
|
.filter(fileName => fileName.endsWith('.log'))
|
|
|
|
.map(fileName => path.join(directory, fileName))
|
|
|
|
}
|