If entry is for an SSID that exists, replace old with new. If entry is for SSID that doesn't exist, add to file.

This commit is contained in:
mmcwilliams 2018-01-01 00:04:49 -05:00
parent 781f6046e5
commit 7e58ac40aa
1 changed files with 11 additions and 9 deletions

View File

@ -83,24 +83,26 @@ class Wifi {
*/
_readConfigCb (err, data) {
let parsed
let current
if (err) {
console.error(err)
return _cb(err)
}
console.log(data)
parsed = parseConfig(data)
console.dir(parsed)
console.log(data)
console.log(data.search(networkPattern))
console.log(_entry)
if (data.search(networkPattern) === -1) {
data += `\n${_entry}`
current = parsed.filter(network => {
return (network.ssid + '').toLowerCase() === (_ssid + '').toLowerCase()
})
console.log(current)
if (typeof current !== 'undefined') {
data = data.replace(current.raw, _entry)
} else {
data = data.replace(networkPattern, _entry)
data += '\n\n' + _entry
}
console.dir(data)
console.log(data)
_entry = null
this._writeConfigCb(null)
//fs.writeFile(filePath, data, 'utf8', this._writeConfigCb)
}
/**