40
40
import processing .app .debug .TargetBoard ;
41
41
import processing .app .debug .TargetPackage ;
42
42
import processing .app .debug .TargetPlatform ;
43
- import processing .app .debug .TargetPlatformException ;
44
43
import processing .app .helpers .FileUtils ;
45
44
import processing .app .helpers .OSUtils ;
46
45
import processing .app .helpers .PreferencesMap ;
@@ -100,14 +99,12 @@ public class Base {
100
99
// found in the sketchbook)
101
100
static public String librariesClassPath ;
102
101
103
- static public Map <String , TargetPackage > packages ;
104
-
105
102
// Location for untitled items
106
103
static File untitledFolder ;
107
104
108
105
// Current directory to use for relative paths specified on the
109
106
// commandline
110
- static String currentDirectory = System . getProperty ( "user.dir" ) ;
107
+ static String currentDirectory = BaseNoGui . currentDirectory ;
111
108
112
109
// p5 icon for the window
113
110
// static Image icon;
@@ -116,7 +113,6 @@ public class Base {
116
113
List <Editor > editors = Collections .synchronizedList (new ArrayList <Editor >());
117
114
Editor activeEditor ;
118
115
119
- static File portableFolder = null ;
120
116
static final String portableSketchbookFolder = "sketchbook" ;
121
117
122
118
static public void main (String args []) throws Exception {
@@ -125,10 +121,7 @@ static public void main(String args[]) throws Exception {
125
121
126
122
initPlatform ();
127
123
128
- // Portable folder
129
- portableFolder = getContentFile ("portable" );
130
- if (!portableFolder .exists ())
131
- portableFolder = null ;
124
+ BaseNoGui .initPortableFolder ();
132
125
133
126
String preferencesFile = null ;
134
127
@@ -283,13 +276,7 @@ static protected void initRequirements() {
283
276
// directory when starting the IDE (which is not the same as the
284
277
// current working directory!).
285
278
static public File absoluteFile (String path ) {
286
- if (path == null ) return null ;
287
-
288
- File file = new File (path );
289
- if (!file .isAbsolute ()) {
290
- file = new File (currentDirectory , path );
291
- }
292
- return file ;
279
+ return BaseNoGui .absoluteFile (path );
293
280
}
294
281
295
282
protected static enum ACTION { GUI , NOOP , VERIFY , UPLOAD , GET_PREF };
@@ -304,8 +291,8 @@ public Base(String[] args) throws Exception {
304
291
// If it doesn't, warn the user that the sketchbook folder is being reset.
305
292
if (sketchbookPath != null ) {
306
293
File sketchbookFolder ;
307
- if (portableFolder != null )
308
- sketchbookFolder = new File (portableFolder , sketchbookPath );
294
+ if (BaseNoGui . getPortableFolder () != null )
295
+ sketchbookFolder = new File (BaseNoGui . getPortableFolder () , sketchbookPath );
309
296
else
310
297
sketchbookFolder = Base .absoluteFile (sketchbookPath );
311
298
if (!sketchbookFolder .exists ()) {
@@ -322,7 +309,7 @@ public Base(String[] args) throws Exception {
322
309
// If no path is set, get the default sketchbook folder for this platform
323
310
if (sketchbookPath == null ) {
324
311
File defaultFolder = getDefaultSketchbookFolder ();
325
- if (portableFolder != null )
312
+ if (BaseNoGui . getPortableFolder () != null )
326
313
Preferences .set ("sketchbook.path" , portableSketchbookFolder );
327
314
else
328
315
Preferences .set ("sketchbook.path" , defaultFolder .getAbsolutePath ());
@@ -331,13 +318,7 @@ public Base(String[] args) throws Exception {
331
318
}
332
319
}
333
320
334
- packages = new HashMap <String , TargetPackage >();
335
- loadHardware (getHardwareFolder ());
336
- loadHardware (getSketchbookHardwareFolder ());
337
- if (packages .size () == 0 ) {
338
- System .out .println (_ ("No valid configured cores found! Exiting..." ));
339
- System .exit (3 );
340
- }
321
+ BaseNoGui .initPackages ();
341
322
342
323
// Setup board-dependent variables.
343
324
onBoardOrPortChange ();
@@ -643,8 +624,8 @@ protected boolean restoreSketches() throws Exception {
643
624
int opened = 0 ;
644
625
for (int i = 0 ; i < count ; i ++) {
645
626
String path = Preferences .get ("last.sketch" + i + ".path" );
646
- if (portableFolder != null ) {
647
- File absolute = new File (portableFolder , path );
627
+ if (BaseNoGui . getPortableFolder () != null ) {
628
+ File absolute = new File (BaseNoGui . getPortableFolder () , path );
648
629
try {
649
630
path = absolute .getCanonicalPath ();
650
631
} catch (IOException e ) {
@@ -689,8 +670,8 @@ protected void storeSketches() {
689
670
!editor .getSketch ().isModified ()) {
690
671
continue ;
691
672
}
692
- if (portableFolder != null ) {
693
- path = FileUtils .relativePath (portableFolder .toString (), path );
673
+ if (BaseNoGui . getPortableFolder () != null ) {
674
+ path = FileUtils .relativePath (BaseNoGui . getPortableFolder () .toString (), path );
694
675
if (path == null )
695
676
continue ;
696
677
}
@@ -713,8 +694,8 @@ protected void storeSketchPath(Editor editor, int index) {
713
694
if (path .startsWith (untitledPath )) {
714
695
path = "" ;
715
696
} else
716
- if (portableFolder != null ) {
717
- path = FileUtils .relativePath (portableFolder .toString (), path );
697
+ if (BaseNoGui . getPortableFolder () != null ) {
698
+ path = FileUtils .relativePath (BaseNoGui . getPortableFolder () .toString (), path );
718
699
if (path == null )
719
700
path = "" ;
720
701
}
@@ -1456,15 +1437,15 @@ public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
1456
1437
1457
1438
// Generate custom menus for all platforms
1458
1439
Set <String > titles = new HashSet <String >();
1459
- for (TargetPackage targetPackage : packages .values ()) {
1440
+ for (TargetPackage targetPackage : BaseNoGui . packages .values ()) {
1460
1441
for (TargetPlatform targetPlatform : targetPackage .platforms ())
1461
1442
titles .addAll (targetPlatform .getCustomMenus ().values ());
1462
1443
}
1463
1444
for (String title : titles )
1464
1445
makeBoardCustomMenu (toolsMenu , _ (title ));
1465
1446
1466
1447
// Cycle through all packages
1467
- for (TargetPackage targetPackage : packages .values ()) {
1448
+ for (TargetPackage targetPackage : BaseNoGui . packages .values ()) {
1468
1449
// For every package cycle through all platform
1469
1450
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1470
1451
@@ -1674,7 +1655,7 @@ public static void selectSerialPort(String port) {
1674
1655
public void rebuildProgrammerMenu (JMenu menu ) {
1675
1656
menu .removeAll ();
1676
1657
ButtonGroup group = new ButtonGroup ();
1677
- for (TargetPackage targetPackage : packages .values ()) {
1658
+ for (TargetPackage targetPackage : BaseNoGui . packages .values ()) {
1678
1659
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1679
1660
for (String programmer : targetPlatform .getProgrammers ().keySet ()) {
1680
1661
String id = targetPackage .getId () + ":" + programmer ;
@@ -1860,30 +1841,7 @@ static public String[] headerListFromIncludePath(File path) throws IOException {
1860
1841
}
1861
1842
1862
1843
protected void loadHardware (File folder ) {
1863
- if (!folder .isDirectory ()) return ;
1864
-
1865
- String list [] = folder .list (new OnlyDirs ());
1866
-
1867
- // if a bad folder or something like that, this might come back null
1868
- if (list == null ) return ;
1869
-
1870
- // alphabetize list, since it's not always alpha order
1871
- // replaced hella slow bubble sort with this feller for 0093
1872
- Arrays .sort (list , String .CASE_INSENSITIVE_ORDER );
1873
-
1874
- for (String target : list ) {
1875
- // Skip reserved 'tools' folder.
1876
- if (target .equals ("tools" ))
1877
- continue ;
1878
- File subfolder = new File (folder , target );
1879
-
1880
- try {
1881
- packages .put (target , new TargetPackage (target , subfolder ));
1882
- } catch (TargetPlatformException e ) {
1883
- System .out .println ("WARNING: Error loading hardware folder " + target );
1884
- System .out .println (" " + e .getMessage ());
1885
- }
1886
- }
1844
+ BaseNoGui .loadHardware (folder );
1887
1845
}
1888
1846
1889
1847
@@ -1987,8 +1945,8 @@ static public String getPlatformName() {
1987
1945
1988
1946
1989
1947
static public File getSettingsFolder () {
1990
- if (portableFolder != null )
1991
- return portableFolder ;
1948
+ if (BaseNoGui . getPortableFolder () != null )
1949
+ return BaseNoGui . getPortableFolder () ;
1992
1950
1993
1951
File settingsFolder = null ;
1994
1952
@@ -2120,7 +2078,7 @@ static public String getAvrBasePath() {
2120
2078
* @return
2121
2079
*/
2122
2080
static public TargetPackage getTargetPackage (String packageName ) {
2123
- return packages .get (packageName );
2081
+ return BaseNoGui . packages .get (packageName );
2124
2082
}
2125
2083
2126
2084
/**
@@ -2129,9 +2087,7 @@ static public TargetPackage getTargetPackage(String packageName) {
2129
2087
* @return
2130
2088
*/
2131
2089
static public TargetPlatform getTargetPlatform () {
2132
- String packageName = Preferences .get ("target_package" );
2133
- String platformName = Preferences .get ("target_platform" );
2134
- return getTargetPlatform (packageName , platformName );
2090
+ return BaseNoGui .getTargetPlatform ();
2135
2091
}
2136
2092
2137
2093
/**
@@ -2143,10 +2099,7 @@ static public TargetPlatform getTargetPlatform() {
2143
2099
*/
2144
2100
static public TargetPlatform getTargetPlatform (String packageName ,
2145
2101
String platformName ) {
2146
- TargetPackage p = packages .get (packageName );
2147
- if (p == null )
2148
- return null ;
2149
- return p .get (platformName );
2102
+ return BaseNoGui .getTargetPlatform (packageName , platformName );
2150
2103
}
2151
2104
2152
2105
static public TargetPlatform getCurrentTargetPlatformFromPackage (String pack ) {
@@ -2176,7 +2129,7 @@ public static TargetBoard getTargetBoard() {
2176
2129
}
2177
2130
2178
2131
static public File getPortableFolder () {
2179
- return portableFolder ;
2132
+ return BaseNoGui . getPortableFolder () ;
2180
2133
}
2181
2134
2182
2135
@@ -2186,9 +2139,7 @@ static public String getPortableSketchbookFolder() {
2186
2139
2187
2140
2188
2141
static public File getSketchbookFolder () {
2189
- if (portableFolder != null )
2190
- return new File (portableFolder , Preferences .get ("sketchbook.path" ));
2191
- return absoluteFile (Preferences .get ("sketchbook.path" ));
2142
+ return BaseNoGui .getSketchbookFolder ();
2192
2143
}
2193
2144
2194
2145
@@ -2215,13 +2166,13 @@ static public String getSketchbookLibrariesPath() {
2215
2166
2216
2167
2217
2168
static public File getSketchbookHardwareFolder () {
2218
- return new File ( getSketchbookFolder (), "hardware" );
2169
+ return BaseNoGui . getSketchbookHardwareFolder ( );
2219
2170
}
2220
2171
2221
2172
2222
2173
protected File getDefaultSketchbookFolder () {
2223
- if (portableFolder != null )
2224
- return new File (portableFolder , portableSketchbookFolder );
2174
+ if (BaseNoGui . getPortableFolder () != null )
2175
+ return new File (BaseNoGui . getPortableFolder () , portableSketchbookFolder );
2225
2176
2226
2177
File sketchbookFolder = null ;
2227
2178
try {
0 commit comments