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