1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

Faster recompilation of unsaved sketches

This commit is contained in:
Federico Fissore 2015-09-16 14:51:37 +02:00
parent f906d45de0
commit 682a5ec331
3 changed files with 24 additions and 9 deletions

View File

@ -28,6 +28,7 @@ import cc.arduino.CompilerProgressListener;
import cc.arduino.UploaderUtils; import cc.arduino.UploaderUtils;
import cc.arduino.files.DeleteFilesOnShutdown; import cc.arduino.files.DeleteFilesOnShutdown;
import cc.arduino.packages.Uploader; import cc.arduino.packages.Uploader;
import org.apache.commons.codec.digest.DigestUtils;
import processing.app.debug.RunnerException; import processing.app.debug.RunnerException;
import processing.app.forms.PasswordAuthorizationDialog; import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
@ -1130,7 +1131,7 @@ public class Sketch {
} }
private String saveSketchInTempFolder() throws IOException { private String saveSketchInTempFolder() throws IOException {
File tempFolder = FileUtils.createTempFolder(); File tempFolder = FileUtils.createTempFolder("arduino_", DigestUtils.md5Hex(data.getMainFilePath()));
DeleteFilesOnShutdown.add(tempFolder); DeleteFilesOnShutdown.add(tempFolder);
FileUtils.copy(getFolder(), tempFolder); FileUtils.copy(getFolder(), tempFolder);

View File

@ -109,7 +109,7 @@ public class LibraryInstaller {
progress.setStatus(I18n.format(tr("Installing library: {0}"), lib.getName())); progress.setStatus(I18n.format(tr("Installing library: {0}"), lib.getName()));
progressListener.onProgress(progress); progressListener.onProgress(progress);
File libsFolder = indexer.getSketchbookLibrariesFolder(); File libsFolder = indexer.getSketchbookLibrariesFolder();
File tmpFolder = FileUtils.createTempFolderIn(libsFolder); File tmpFolder = FileUtils.createTempFolder(libsFolder);
try { try {
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1); new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
} catch (Exception e) { } catch (Exception e) {

View File

@ -3,6 +3,8 @@ package processing.app.helpers;
import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.IOUtils;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -84,15 +86,27 @@ public class FileUtils {
} }
public static File createTempFolder() throws IOException { public static File createTempFolder() throws IOException {
return createTempFolderIn(new File(System.getProperty("java.io.tmpdir"))); return createTempFolder(new File(System.getProperty("java.io.tmpdir")));
} }
public static File createTempFolderIn(File parent) throws IOException { public static File createTempFolder(File parent) throws IOException {
File tmpFolder = new File(parent, "arduino_" + new Random().nextInt(1000000)); return createTempFolder(parent, "arduino_");
if (!tmpFolder.mkdir()) { }
throw new IOException("Unable to create temp folder " + tmpFolder);
} public static File createTempFolder(File parent, String prefix) throws IOException {
return tmpFolder; return createTempFolder(parent, prefix, Integer.toString(new Random().nextInt(1000000)));
}
public static File createTempFolder(String prefix) throws IOException {
return createTempFolder(new File(System.getProperty("java.io.tmpdir")), prefix);
}
public static File createTempFolder(String prefix, String suffix) throws IOException {
return createTempFolder(new File(System.getProperty("java.io.tmpdir")), prefix, suffix);
}
public static File createTempFolder(File parent, String prefix, String suffix) throws IOException {
return Files.createDirectories(Paths.get(parent.getAbsolutePath(), prefix + suffix)).toFile();
} }
// //