Skip to content

Commit

Permalink
fixed settings.inin locations
Browse files Browse the repository at this point in the history
  • Loading branch information
infeeeee committed Aug 11, 2019
1 parent 5df2a7a commit acd5d97
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions kimai2-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,23 +546,17 @@ function uiAutocompleteSelect(thelist, message) {
* @returns false: If no settings found
*/
function iniPath() {
//different settings.ini path for developement and pkg and windows installer version
const iniRoot = [
path.dirname(process.execPath),//This is for pkg version
__dirname//This is for npm version
]

if (appdata) { iniRoot.push(path.join(appdata, '/kimai2-cmd')) }

if (program.verbose) {
console.log('Looking for settings.ini in the following places:')
console.log(iniRoot)
}

for (let i = 0; i < iniRoot.length; i++) {
const currentIniPath = path.join(iniRoot[i], '/settings.ini')
if (fs.existsSync(currentIniPath)) {
return currentIniPath
for (var key in iniRoot) {
if (iniRoot.hasOwnProperty(key)) {
const currentIniPath = path.join(iniRoot[key], '/settings.ini')
if (fs.existsSync(currentIniPath)) {
return currentIniPath
}
}
}

Expand Down Expand Up @@ -655,15 +649,15 @@ function iniFullPath() {
if (!fs.existsSync(path.join(appdata, 'kimai2-cmd'))) {
fs.mkdirSync(path.join(appdata, 'kimai2-cmd'))
}
return path.join(appdata, 'kimai2-cmd', 'settings.ini')
return path.join(iniRoot.wininstaller, 'settings.ini')
} else if (dirArr[0] == 'snapshot' || dirArr[1] == 'snapshot') {
if (program.verbose) {console.log('This is a pkg version')}
if (program.verbose) { console.log('This is a pkg version') }
//for pkg version:
return path.join(path.dirname(process.execPath), 'settings.ini')
return path.join(iniRoot.pkg, 'settings.ini')
} else {
if (program.verbose) {console.log('This is an npm version')}
if (program.verbose) { console.log('This is an npm version') }
//For npm version:
return 'settings.ini'
return path.join(iniRoot.npm, 'settings.ini')
}
}

Expand All @@ -677,6 +671,20 @@ function sanitizeServerUrl(kimaiurl) {
return kimaiurl.replace(/\/+$/, "");
}

/* -------------------------------------------------------------------------- */
/* Settings.ini locations */
/* -------------------------------------------------------------------------- */

//different settings.ini path for developement and pkg and windows installer version
const iniRoot = {
pkg: path.dirname(process.execPath),//This is for pkg version
npm: __dirname//This is for npm version
}

if (appdata) {
iniRoot.wininstaller = path.join(appdata, '/kimai2-cmd')
}

/* -------------------------------------------------------------------------- */
/* Commander */
/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit acd5d97

Please sign in to comment.