1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

Let Sketch.getPrimaryFile return a SketchFile

Previously, it returned a File object, which the Sketch separately
stored from the primary SketchFile. By letting it just return the
SketchFile, and let callers query that for the filename, Sketch does not
need to store the File object itself and there is less chance of info
getting out of sync.
This commit is contained in:
Matthijs Kooijman 2015-12-18 15:21:30 +01:00 committed by Martino Facchin
parent 86d20b8726
commit 959fba7865
3 changed files with 8 additions and 14 deletions

View File

@ -864,7 +864,7 @@ public class SketchController {
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes());
}
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getName()).toString();
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toString();
}
protected boolean exportApplet(boolean usingProgrammer) throws Exception {

View File

@ -157,7 +157,7 @@ public class Compiler implements MessageConsumer {
size(prefs);
return sketch.getPrimaryFile().getName();
return sketch.getPrimaryFile().getFileName();
}
private String VIDPID() {

View File

@ -20,11 +20,6 @@ public class Sketch {
public static final List<String> OTHER_ALLOWED_EXTENSIONS = Arrays.asList("c", "cpp", "h", "hh", "hpp", "s");
public static final List<String> EXTENSIONS = Stream.concat(SKETCH_EXTENSIONS.stream(), OTHER_ALLOWED_EXTENSIONS.stream()).collect(Collectors.toList());
/**
* main pde file for this sketch.
*/
private File primaryFile;
/**
* folder that contains this sketch
*/
@ -57,8 +52,6 @@ public class Sketch {
* The primary file for this sketch.
*/
Sketch(File file) throws IOException {
primaryFile = file;
// get the name of the sketch by chopping .pde or .java
// off of the main file name
String mainFilename = primaryFile.getName();
@ -122,7 +115,9 @@ public class Sketch {
Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {
if (BaseNoGui.isSanitaryName(file.getName())) {
result.add(new SketchFile(file, file.equals(primaryFile)));
FileUtils.SplitFile split = FileUtils.splitFilename(file);
boolean isPrimary = split.basename.equals(folder.getName()) && SKETCH_EXTENSIONS.contains(split.extension);
result.add(new SketchFile(file, isPrimary));
} else if (showWarnings) {
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
}
@ -165,16 +160,15 @@ public class Sketch {
/**
* Returns a file object for the primary .pde of this sketch.
*/
public File getPrimaryFile() {
return primaryFile;
public SketchFile getPrimaryFile() {
return files.get(0);
}
/**
* Returns path to the main .pde file for this sketch.
*/
public String getMainFilePath() {
return primaryFile.getAbsolutePath();
//return code[0].file.getAbsolutePath();
return getPrimaryFile().getFile().getAbsolutePath();
}
public void addFile(SketchFile file) {