Add a file to the sketch. .pde or .java files will be added to the sketch folder. .jar, .class, .dll, .jnilib, and .so files will all be added to the "code" folder. All other files will be added to the "data" folder. If they don't exist already, the "code" or "data" folder will
(File sourceFile)
| 1279 | * @return true if successful. |
| 1280 | */ |
| 1281 | public boolean addFile(File sourceFile) { |
| 1282 | String filename = sourceFile.getName(); |
| 1283 | File destFile = null; |
| 1284 | String codeExtension = null; |
| 1285 | boolean replacement = false; |
| 1286 | |
| 1287 | boolean isCode = false; |
| 1288 | |
| 1289 | // if the file appears to be code related, drop it |
| 1290 | // into the code folder, instead of the data folder |
| 1291 | if (filename.toLowerCase().endsWith(".class") || |
| 1292 | filename.toLowerCase().endsWith(".jar") || |
| 1293 | filename.toLowerCase().endsWith(".dll") || |
| 1294 | filename.toLowerCase().endsWith(".dylib") || |
| 1295 | filename.toLowerCase().endsWith(".jnilib") || |
| 1296 | filename.toLowerCase().endsWith(".so")) { |
| 1297 | |
| 1298 | //if (!codeFolder.exists()) codeFolder.mkdirs(); |
| 1299 | prepareCodeFolder(); |
| 1300 | destFile = new File(codeFolder, filename); |
| 1301 | isCode = true; |
| 1302 | } else { |
| 1303 | for (String extension : mode.getExtensions()) { |
| 1304 | String lower = filename.toLowerCase(); |
| 1305 | if (lower.endsWith("." + extension)) { |
| 1306 | destFile = new File(this.folder, filename); |
| 1307 | codeExtension = extension; |
| 1308 | } |
| 1309 | } |
| 1310 | if (codeExtension == null) { |
| 1311 | prepareDataFolder(); |
| 1312 | destFile = new File(dataFolder, filename); |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | // check whether this file already exists |
| 1317 | if (destFile.exists()) { |
| 1318 | Object[] options = { Language.text("prompt.ok"), Language.text("prompt.cancel") }; |
| 1319 | String prompt = Language.interpolate("add_file.messages.confirm_replace", |
| 1320 | filename); |
| 1321 | int result = JOptionPane.showOptionDialog(editor, |
| 1322 | prompt, |
| 1323 | "Replace", |
| 1324 | JOptionPane.YES_NO_OPTION, |
| 1325 | JOptionPane.QUESTION_MESSAGE, |
| 1326 | null, |
| 1327 | options, |
| 1328 | options[0]); |
| 1329 | if (result == JOptionPane.YES_OPTION) { |
| 1330 | replacement = true; |
| 1331 | } else { |
| 1332 | return false; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | // If it's a replacement, delete the old file first, |
| 1337 | // otherwise case changes will not be preserved. |
| 1338 | // http://dev.processing.org/bugs/show_bug.cgi?id=969 |
no test coverage detected