mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-31 20:52:13 +01:00
Simplify SketchController.addFile using FileUtils.hasExtension
This commit is contained in:
parent
d70900e5ad
commit
b3ad637f8c
@ -703,19 +703,15 @@ public class SketchController {
|
|||||||
public boolean addFile(File sourceFile) {
|
public boolean addFile(File sourceFile) {
|
||||||
String filename = sourceFile.getName();
|
String filename = sourceFile.getName();
|
||||||
File destFile = null;
|
File destFile = null;
|
||||||
String codeExtension = null;
|
boolean isData = false;
|
||||||
boolean replacement = false;
|
boolean replacement = false;
|
||||||
|
|
||||||
for (String extension : Sketch.EXTENSIONS) {
|
if (FileUtils.hasExtension(sourceFile, Sketch.EXTENSIONS)) {
|
||||||
String lower = filename.toLowerCase();
|
destFile = new File(sketch.getFolder(), filename);
|
||||||
if (lower.endsWith("." + extension)) {
|
} else {
|
||||||
destFile = new File(sketch.getFolder(), filename);
|
|
||||||
codeExtension = extension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (codeExtension == null) {
|
|
||||||
prepareDataFolder();
|
prepareDataFolder();
|
||||||
destFile = new File(sketch.getDataFolder(), filename);
|
destFile = new File(sketch.getDataFolder(), filename);
|
||||||
|
isData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether this file already exists
|
// check whether this file already exists
|
||||||
@ -751,7 +747,7 @@ public class SketchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make sure they aren't the same file
|
// make sure they aren't the same file
|
||||||
if ((codeExtension == null) && sourceFile.equals(destFile)) {
|
if (isData && sourceFile.equals(destFile)) {
|
||||||
Base.showWarning(tr("You can't fool me"),
|
Base.showWarning(tr("You can't fool me"),
|
||||||
tr("This file has already been copied to the\n" +
|
tr("This file has already been copied to the\n" +
|
||||||
"location from which where you're trying to add it.\n" +
|
"location from which where you're trying to add it.\n" +
|
||||||
@ -773,7 +769,7 @@ public class SketchController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codeExtension != null) {
|
if (!isData) {
|
||||||
SketchCode newCode = new SketchCode(destFile, false);
|
SketchCode newCode = new SketchCode(destFile, false);
|
||||||
|
|
||||||
if (replacement) {
|
if (replacement) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user