Skip to content

Commit c072290

Browse files
committed
Make sure the file extention of the file matches a supported file format
1 parent a0fa4ff commit c072290

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingEngine.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,16 @@ public static List<String> getAllLangauges() {
20872087
}
20882088
return langs;
20892089
}
2090-
2090+
public static List<String> getAllExtentions() {
2091+
ArrayList<String> langs = new ArrayList<>();
2092+
for (String L : getLangaugesMap().keySet()) {
2093+
IScriptingLanguage lang = getLangaugesMap().get(L);
2094+
for(String s:lang.getFileExtenetion()) {
2095+
langs.add(s);
2096+
}
2097+
}
2098+
return langs;
2099+
}
20912100
public static HashMap<String, IScriptingLanguage> getLangaugesMap() {
20922101
return langauges;
20932102
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/AddFromFile.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public class AddFromFile extends AbstractAddFrom implements ICaDoodleOpperation
3333
@Expose(serialize = true, deserialize = true)
3434
private Boolean preventBoM =false;
3535
public AddFromFile set(File source) {
36-
toLocal(source,getName());
37-
return this;
36+
for(String s:ScriptingEngine.getAllExtentions()) {
37+
if(source.getName().toLowerCase().endsWith(s.toLowerCase())) {
38+
toLocal(source,getName());
39+
return this;
40+
}
41+
}
42+
throw new RuntimeException("File Extention not supported: "+source.getName());
3843
}
3944

4045
@Override
@@ -156,8 +161,12 @@ public static File getFile(String name) {
156161
File parentFile = new File(loc.getStrValue()).getParentFile();
157162
for(String f:parentFile.list()) {
158163
if(f.contains(name)) {
159-
String pathname = parentFile.getAbsolutePath() + DownloadManager.delim() + f;
160-
return new File(pathname);
164+
for(String s:ScriptingEngine.getAllExtentions()) {
165+
if(f.toLowerCase().endsWith(s.toLowerCase())) {
166+
String pathname = parentFile.getAbsolutePath() + DownloadManager.delim() + f;
167+
return new File(pathname);
168+
}
169+
}
161170
}
162171
}
163172
throw new RuntimeException("File not found! "+name);

0 commit comments

Comments
 (0)