diff --git a/electron.js b/electron.js index 44af439..5ee5e07 100644 --- a/electron.js +++ b/electron.js @@ -84,7 +84,7 @@ function doCompile(code,board,sketch, cb) { OPTIONS.platform = platform.getDefaultPlatform(); OPTIONS.platform.installIfNeeded(function() { OPTIONS.name = sketch; - compile.compile(sketchpath,outpath,OPTIONS, publishEvent, path.join(settings.usersketches, sketch), cb); + compile.compile(sketchpath,outpath,OPTIONS, publishEvent, path.join(OPTIONS.platform.getUserSketchesDir(), sketch), cb); }); } diff --git a/libraries.js b/libraries.js index 603ba16..9192ca9 100644 --- a/libraries.js +++ b/libraries.js @@ -2,26 +2,28 @@ var fs = require('fs'); var spawn = require('child_process').spawn; var http = require('http'); var AdmZip = require('adm-zip'); +var platform = require('./platform'); var settings = require('./settings.js'); var master = null; var libs = null; +var plat = platform.getDefaultPlatform(); function isInstalled() { console.log('checking if',this.id,'is installed'); if(this.source == 'ide') return true; - var path = settings.repos+'/'+this.id; + var path = plat.getReposPath()+'/'+this.id; console.log('checking if path exists',path); - if(fs.existsSync(settings.repos+'/'+this.id)) return true; + if(fs.existsSync(plat.getReposPath()+'/'+this.id)) return true; return false; } function getIncludePaths(platform) { if(this.source == 'ide') { - var path = platform.getArduinoLibrariesPath()+'/'+this.location; + var path = platform.getStandardLibraryPath()+'/'+this.location; //console.log("files = ",fs.readdirSync(path)); var paths = []; paths.push(path); @@ -36,14 +38,14 @@ function getIncludePaths(platform) { return paths; } if(this.path) { - return [settings.repos+'/'+this.id+'/'+this.path]; + return [plat.getReposPath()+'/'+this.id+'/'+this.path]; } - return [settings.repos+'/'+this.id]; + return [plat.getReposPath()+'/'+this.id]; } function install(cb) { - if(!fs.existsSync(settings.repos)) { - fs.mkdirSync(settings.repos); + if(!fs.existsSync(plat.getReposPath())) { + fs.mkdirSync(plat.getReposPath()); } console.log('installing',this.id); @@ -52,7 +54,7 @@ function install(cb) { var cmd = [ 'clone', this.location, - settings.repos+'/'+this.id, + plat.getReposPath()+'/'+this.id, ]; console.log("execing",bin,cmd); var proc = spawn(bin,cmd); @@ -70,8 +72,8 @@ function install(cb) { if(this.source == 'http'){ console.log("source is http",this.location); - var outpath = settings.repos; - var outfile = settings.repos+'/'+this.location.substring(this.location.lastIndexOf('/')+1); + var outpath = plat.getReposPath(); + var outfile = plat.getReposPath()+'/'+this.location.substring(this.location.lastIndexOf('/')+1); console.log("output file = ",outfile); var req = http.get(this.location) .on('response',function(res){ @@ -83,9 +85,9 @@ function install(cb) { var rootpath = zipEntries[0].entryName; rootpath = rootpath.substring(0,rootpath.indexOf('/')); console.log("rootpath of the zip is",rootpath); - zip.extractAllTo(settings.repos,true); - console.log('done extracting from ',outfile, 'to',settings.repos); - fs.renameSync(settings.repos+'/'+rootpath, settings.repos+'/'+rootpath.toLowerCase()); + zip.extractAllTo(plat.getReposPath(),true); + console.log('done extracting from ',outfile, 'to',plat.getReposPath()); + fs.renameSync(plat.getReposPath()+'/'+rootpath, plat.getReposPath()+'/'+rootpath.toLowerCase()); if(cb) cb(null); }); }); diff --git a/platform.js b/platform.js index 817bff6..86e8d7f 100644 --- a/platform.js +++ b/platform.js @@ -13,7 +13,31 @@ function Platform() { this.os = process.platform; console.log("os = ",this.os); - this.root = settings.repos + '/platforms/1.0.5/'+this.os; + + this.getUserHome = function() { + return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; + } + + this.getReposPath = function() { + if(this.os == 'darwin') { + return this.getUserHome() + '/Library/ElectronIDE/downloads'; + } + return this.getUserHome() + '/ElectronIDE/downloads'; + } + + this.getUserSketchesDir = function() { + if(settings.usersketches) return settings.usersketches; + + if(this.os == 'darwin') { + return this.getUserHome()+'/Documents/Arduino'; + } + if(this.os == 'window') { + return this.getUserHome()+'/My Documents/Arduino'; + } + return this.getUserHome() + '/Sketchbook'; + } + + this.root = this.getReposPath() + '/platforms/1.0.5/'+this.os; console.log("root should be ", this.root); this.getStandardLibraryPath = function() { @@ -34,9 +58,6 @@ function Platform() { this.getAvrDudeConf = function(device) { return this.root + '/hardware/tools/avr/etc/avrdude.conf'; } - this.getArduinoLibrariesPath = function() { - return this.root + '/libraries'; - } this.isInstalled = function() { return fs.existsSync(this.root); } diff --git a/settings.js b/settings.js index 826bdcf..64dd729 100644 --- a/settings.js +++ b/settings.js @@ -1,14 +1,16 @@ //where your sketches live -exports.usersketches = "/Users/josh/Documents/Arduino/"; +//set only if you want to change the default +//exports.usersketches = "/Users/josh/Documents/Arduino/"; //where your personal libraries live. new libs will *not* go here -exports.userlibs = "/Users/josh/Documents/Arduino/Libraries"; +//set only if you want to change the default +//exports.userlibs = "/Users/josh/Documents/Arduino/Libraries"; // root of the regular Arduino IDE app -exports.root = "/Applications/Arduino.app/Contents/Resources/Java"; //where new libs will be downlaoded to -exports.repos = "/Users/josh/projects/junkrepos"; +//set only if you want to change the default +//exports.repos = "/Users/josh/projects/junkrepos"; // ============== // you shouldn't need to modify anything below this line diff --git a/sketches.js b/sketches.js index 862489e..b2b7a54 100644 --- a/sketches.js +++ b/sketches.js @@ -1,21 +1,23 @@ var fs = require('fs'); var settings = require('./settings.js'); +var platform = require('./platform'); +var plat = platform.getDefaultPlatform(); exports.makeNewSketch = function(name,cb) { - var dir = settings.usersketches+'/'+name; + var dir = plat.getUserSketchesDir()+'/'+name; if(fs.existsSync(dir)) { if(cb)cb(null); return; } fs.mkdirSync(dir); var example = fs.readFileSync(settings.sketchtemplate).toString(); - fs.writeFileSync(settings.usersketches+'/'+name+'/'+name+'.ino',example); + fs.writeFileSync(plat.getUserSketchesDir()+'/'+name+'/'+name+'.ino',example); if(cb) cb(name,example); } exports.deleteSketch = function(name, cb) { - var dir = settings.usersketches+'/'+name; + var dir = plat.getUserSketchesDir()+'/'+name; fs.readdirSync(dir).forEach(function(file) { console.log("deleting file = ",file); fs.unlinkSync(dir+'/'+file); @@ -25,7 +27,7 @@ exports.deleteSketch = function(name, cb) { } exports.listSketches = function(cb) { - var list = fs.readdirSync(settings.usersketches); + var list = fs.readdirSync(plat.getUserSketchesDir()); list = list.filter(function(file) { if(file.toLowerCase() == 'libraries') return false; if(file.toLowerCase() == '.ds_store') return false; @@ -35,7 +37,7 @@ exports.listSketches = function(cb) { } exports.getSketch = function(name, cb) { - var dir = settings.usersketches + '/' + name; + var dir = plat.getUserSketchesDir() + '/' + name; var obj = { name:name, files:[] @@ -63,7 +65,7 @@ exports.getSketch = function(name, cb) { exports.saveSketch = function(name, code, cb) { console.log("saving to ",name); - var dir = settings.usersketches + '/' + name; + var dir = plat.getUserSketchesDir() + '/' + name; console.log("dir = ",dir); var file = dir+'/'+name+'.ino'; console.log("file = ",file);