{"size": 1135, "ext": "js", "max_stars_repo_path": "renderer.js", "max_stars_repo_name": "Sm3xx/PokeCode", "max_stars_repo_stars_event_min_datetime": "2019-01-22T10:21:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-22T10:21:16.000Z", "max_issues_repo_path": "renderer.js", "max_issues_repo_name": "Sm3xx/PokeCode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "renderer.js", "max_forks_repo_name": "Sm3xx/PokeCode", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.1489361702, "max_line_length": 96, "alphanum_fraction": 0.5568281938}
const {ipcRenderer} = require('electron');
const fs = require('fs');
const app = require('electron').remote;
const dialog = app.dialog;

var dataPath = ipcRenderer.sendSync('get-file-data');

PokeCodeInterpreter.init();

PokeCodeInterpreter.addConsole('console');

if (dataPath === null || dataPath == '.') {
    dialog.showOpenDialog({"filters": [
        {
            "name": "PokeCode file",
            "extensions": ["pokecode"]
        }
    ]},(fileNames) => { 
       dataPath = fileNames[0]; 
       loadDataPath(dataPath);
    });
} else {
    loadDataPath(dataPath);
}

function loadDataPath (dataPath) {

    if (dataPath ===  null) {
        PokeCodeInterpreter.writeErrorToConsole(`No file is selected`);
    } else {
        
        fs.readFile(dataPath, 'utf-8', (err, data) => {
            if (err) {
                PokeCodeInterpreter.writeErrorToConsole(`File ${dataPath} could not be loaded`);
                return;
            } 
            
            window.LoadedPokeCodePath = dataPath;

            data = data.split(/\n/);
    
            PokeCodeInterpreter.runCode(data);
    
        });
    }

}