MCPcopy
hub / github.com/arduino/Arduino / saveAs

Method saveAs

arduino-core/src/processing/app/Sketch.java:336–370  ·  view source on GitHub ↗

Save this sketch under the new name given. Unlike renameTo(), this leaves the existing sketch in place. @param newFolder The new folder name for this sketch. The new primary file's name will be derived from this. @throws IOException When a problem occurs. The error mess

(File newFolder)

Source from the content-addressed store, hash-verified

334 * already translated.
335 */
336 public void saveAs(File newFolder) throws IOException {
337 // Check intented rename (throws if there is a problem)
338 File newPrimary = checkNewFoldername(newFolder);
339
340 // Create the folder
341 if (!newFolder.mkdirs()) {
342 String msg = I18n.format(tr("Could not create directory \"{0}\""), newFolder.getAbsolutePath());
343 throw new IOException(msg);
344 }
345
346 // Save the files to their new location
347 for (SketchFile file : files) {
348 if (file.isPrimary())
349 file.saveAs(newPrimary);
350 else
351 file.saveAs(new File(newFolder, file.getFileName()));
352 }
353
354
355 // Copy the data folder (this may take a while.. add progress bar?)
356 if (getDataFolder().exists()) {
357 File newDataFolder = new File(newFolder, "data");
358 // Check if data folder exits, if not try to create the data folder
359 if (!newDataFolder.exists() && !newDataFolder.mkdirs()) {
360 String msg = I18n.format(tr("Could not create directory \"{0}\""), newFolder.getAbsolutePath());
361 throw new IOException(msg);
362 }
363 // Copy the data files into the new folder
364 FileUtils.copy(getDataFolder(), newDataFolder);
365 }
366
367 // Change folder to the new folder
368 folder = newFolder;
369
370 }
371
372 /**
373 * Deletes this entire sketch from disk.

Callers

nothing calls this directly

Calls 8

checkNewFoldernameMethod · 0.95
formatMethod · 0.95
getDataFolderMethod · 0.95
copyMethod · 0.95
trMethod · 0.80
isPrimaryMethod · 0.80
getFileNameMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected