<commit_before>import path from 'path';
import pathWatcher from 'pathwatcher';
import fs from 'fs-plus';
import {BrowserWindow, dialog, app} from 'electron';

let _ = require('underscore');
_ = _.extend(_, require('../config-utils'));

export default class ConfigPersistenceManager {
  constructor({configDirPath, resourcePath} = {}) {
    this.configDirPath = configDirPath;
    this.resourcePath = resourcePath;

    this.userWantsToPreserveErrors = false
    this.configFilePath = path.join(this.configDirPath, 'config.json')
    this.settings = {};

    this.initializeConfigDirectory();
    this.load();
    this.observe();
  }

  initializeConfigDirectory() {
    if (!fs.existsSync(this.configDirPath)) {
      fs.makeTreeSync(this.configDirPath);
      const templateConfigDirPath = fs.resolve(this.resourcePath, 'dot-nylas');
      fs.copySync(templateConfigDirPath, this.configDirPath);
    }

    if (!fs.existsSync(this.configFilePath)) {
      const templateConfigPath = fs.resolve(this.resourcePath, 'dot-nylas', 'config.json');
      const templateConfig = fs.readFileSync(templateConfigPath);
      fs.writeFileSync(this.configFilePath, templateConfig);
    }
  }

  load() {
    this.userWantsToPreserveErrors = false;

    try {
      const json = JSON.parse(fs.readFileSync(this.configFilePath)) || {};
      this.settings = json['*'];
      this.emitChangeEvent();
    } catch (error) {
      const message = `Failed to load "${path.basename(this.configFilePath)}"`;
      let detail = (error.location) ? error.stack : error.message;
      detail += `\n\nFix the formatting of ${this.configFilePath} to resolve this error, or reset your settings to continue using N1.`

      const clickedIndex = dialog.showMessageBox({<commit_msg>fix(config): Using fs.resolve as path.join<commit_after>import path from 'path';
import pathWatcher from 'pathwatcher';
import fs from 'fs-plus';
import {BrowserWindow, dialog, app} from 'electron';

let _ = require('underscore');
_ = _.extend(_, require('../config-utils'));

export default class ConfigPersistenceManager {
  constructor({configDirPath, resourcePath} = {}) {
    this.configDirPath = configDirPath;
    this.resourcePath = resourcePath;

    this.userWantsToPreserveErrors = false
    this.configFilePath = path.join(this.configDirPath, 'config.json')
    this.settings = {};

    this.initializeConfigDirectory();
    this.load();
    this.observe();
  }

  initializeConfigDirectory() {
    if (!fs.existsSync(this.configDirPath)) {
      fs.makeTreeSync(this.configDirPath);
      const templateConfigDirPath = path.join(this.resourcePath, 'dot-nylas');
      fs.copySync(templateConfigDirPath, this.configDirPath);
    }

    if (!fs.existsSync(this.configFilePath)) {
      const templateConfigPath = path.join(this.resourcePath, 'dot-nylas', 'config.json');
      const templateConfig = fs.readFileSync(templateConfigPath);
      fs.writeFileSync(this.configFilePath, templateConfig);
    }
  }

  load() {
    this.userWantsToPreserveErrors = false;

    try {
      const json = JSON.parse(fs.readFileSync(this.configFilePath)) || {};
      this.settings = json['*'];
      this.emitChangeEvent();
    } catch (error) {
      const message = `Failed to load "${path.basename(this.configFilePath)}"`;
      let detail = (error.location) ? error.stack : error.message;
      detail += `\n\nFix the formatting of ${this.configFilePath} to resolve this error, or reset your settings to continue using N1.`

      const clickedIndex = dialog.showMessageBox({
{'fraction_non_alphanumeric': 0.13055791560464458, 'fraction_numerical': 0.0005664117813650524, 'mean_word_length': 3.953716690042076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2355636', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1025, 'n_words': 217}