forked from joshmarinacci/ElectronIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.js
More file actions
102 lines (89 loc) · 3.23 KB
/
Copy pathplatform.js
File metadata and controls
102 lines (89 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var fs = require('fs');
var settings = require('./settings');
var zlib = require('zlib');
var tar = require('tar');
var http = require('http');
//var CLOUDPATH = "/Users/josh/projects/ArduinoZips";
var CLOUDPATH = 'http://joshondesign.com/p/apps/electron/platforms';
var VERSION = "1.0.5";
function Platform() {
this.os = process.platform;
console.log("os = ",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() {
return this.root + '/libraries';
}
this.getCorePath = function(device) {
return this.root + '/hardware/arduino/cores/'+device.build.core;
}
this.getVariantPath = function(device) {
return this.root + '/hardware/arduino/variants/'+device.build.variant;
}
this.getCompilerBinaryPath = function(device) {
return this.root + '/hardware/tools/avr/bin';
}
this.getAvrDudeBinary = function(device) {
return this.root + '/hardware/tools/avr/bin/avrdude';
}
this.getAvrDudeConf = function(device) {
return this.root + '/hardware/tools/avr/etc/avrdude.conf';
}
this.isInstalled = function() {
return fs.existsSync(this.root);
}
this.installIfNeeded = function(cb,update) {
if(this.isInstalled()) {
cb();
return;
}
console.log("not installed. installing now");
var zippath = CLOUDPATH+'/'+VERSION+'/arduino-'+VERSION+'-'+this.os+'-trimmed.tar.gz';
console.log('zip path = ',zippath);
var outpath = this.root;
console.log('unziping to ',outpath);
var req = http.get(zippath);
req.on('response', function(res) {
var total = res.headers['content-length']; //total byte length
var count = 0;
res
.on('data', function(data) {
count += data.length;
if(update) update( {message:count/total});
})
.pipe(zlib.createGunzip())
.pipe(tar.Extract({path:outpath, strip: 1}))
.on('error',function() {
console.log('there was an error');
})
.on('close',function() {
console.log('unzipped the files');
if(cb) cb();
});
});
}
}
var _default = new Platform();
exports.getDefaultPlatform = function() {
console.log('getting the default platform');
return _default;
}