26
26
import java .io .File ;
27
27
import java .io .BufferedReader ;
28
28
import java .io .InputStreamReader ;
29
+ import java .io .IOException ;
29
30
30
31
import java .text .SimpleDateFormat ;
31
32
import java .util .Date ;
32
-
33
+ import java .lang .reflect .Field ;
34
+ import java .lang .reflect .InvocationTargetException ;
33
35
import javax .swing .JOptionPane ;
34
36
35
37
import processing .app .PreferencesData ;
38
40
import processing .app .BaseNoGui ;
39
41
import processing .app .Platform ;
40
42
import processing .app .Sketch ;
43
+ import processing .app .SketchData ;
41
44
import processing .app .tools .Tool ;
42
45
import processing .app .helpers .ProcessUtils ;
43
46
import processing .app .debug .TargetPlatform ;
44
47
48
+ import org .apache .commons .codec .digest .DigestUtils ;
49
+ import processing .app .helpers .FileUtils ;
50
+
51
+ import cc .arduino .files .DeleteFilesOnShutdown ;
45
52
46
53
/**
47
54
* Example Tools menu entry.
@@ -99,6 +106,36 @@ public void run() {
99
106
thread .start ();
100
107
}
101
108
109
+ private String getBuildFolderPath (Sketch s ) {
110
+ try {
111
+ File buildFolder = FileUtils .createTempFolder ("build" , DigestUtils .md5Hex (s .getMainFilePath ()) + ".spiffs" );
112
+ DeleteFilesOnShutdown .add (buildFolder );
113
+ return buildFolder .getAbsolutePath ();
114
+ }
115
+ catch (IOException e ) {
116
+ editor .statusError (e );
117
+ }
118
+ catch (NoSuchMethodError e ) {
119
+ // Arduino 1.6.5 doesn't have FileUtils.createTempFolder
120
+ // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
121
+ java .lang .reflect .Method method ;
122
+ try {
123
+ method = BaseNoGui .class .getMethod ("getBuildFolder" );
124
+ File f = (File ) method .invoke (null );
125
+ return f .getAbsolutePath ();
126
+ } catch (SecurityException ex ) {
127
+ editor .statusError (ex );
128
+ } catch (IllegalAccessException ex ) {
129
+ editor .statusError (ex );
130
+ } catch (InvocationTargetException ex ) {
131
+ editor .statusError (ex );
132
+ } catch (NoSuchMethodException ex ) {
133
+ editor .statusError (ex );
134
+ }
135
+ }
136
+ return "" ;
137
+ }
138
+
102
139
103
140
private long getIntPref (String name ){
104
141
String data = BaseNoGui .getBoardPreferences ().get (name );
@@ -150,7 +187,7 @@ private void createAndUpload(){
150
187
mkspiffsCmd = "mkspiffs.exe" ;
151
188
else
152
189
mkspiffsCmd = "mkspiffs" ;
153
-
190
+
154
191
File tool = new File (platform .getFolder () + "/tools" , mkspiffsCmd );
155
192
if (!tool .exists ()) {
156
193
tool = new File (PreferencesData .get ("runtime.tools.mkspiffs.path" ), mkspiffsCmd );
@@ -162,7 +199,10 @@ private void createAndUpload(){
162
199
}
163
200
164
201
int fileCount = 0 ;
165
- File dataFolder = editor .getSketch ().prepareDataFolder ();
202
+ File dataFolder = new File (editor .getSketch ().getFolder (), "data" );
203
+ if (!dataFolder .exists ()) {
204
+ dataFolder .mkdirs ();
205
+ }
166
206
if (dataFolder .exists () && dataFolder .isDirectory ()){
167
207
File [] files = dataFolder .listFiles ();
168
208
if (files .length > 0 ){
@@ -176,8 +216,7 @@ private void createAndUpload(){
176
216
String toolPath = tool .getAbsolutePath ();
177
217
String esptoolPath = esptool .getAbsolutePath ();
178
218
String sketchName = editor .getSketch ().getName ();
179
- String buildPath = BaseNoGui .getBuildFolder ().getAbsolutePath ();
180
- String imagePath = buildPath +"/" +sketchName +".spiffs.bin" ;
219
+ String imagePath = getBuildFolderPath (editor .getSketch ()) + "/" + sketchName + ".spiffs.bin" ;
181
220
String serialPort = PreferencesData .get ("serial.port" );
182
221
String resetMethod = BaseNoGui .getBoardPreferences ().get ("upload.resetmethod" );
183
222
String uploadSpeed = BaseNoGui .getBoardPreferences ().get ("upload.speed" );
0 commit comments