1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Introducing bundled_library_index.json

This commit is contained in:
Federico Fissore
2015-03-26 16:02:33 +01:00
parent a1d99b9a9b
commit 74a8ccdeb4
4 changed files with 284 additions and 17 deletions

View File

@ -609,13 +609,18 @@ public class BaseNoGui {
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
File librariesIndexFile = librariesIndexer.getIndexFile();
if (!librariesIndexFile.isFile()) {
try {
// Otherwise create an empty packages index
FileOutputStream out = new FileOutputStream(librariesIndexFile);
out.write("{ \"libraries\" : [ ] }".getBytes());
out.close();
} catch (IOException e) {
e.printStackTrace();
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
if (defaultLibraryJsonFile.isFile()) {
FileUtils.copyFile(defaultLibraryJsonFile, librariesIndexFile);
} else {
try {
// Otherwise create an empty packages index
FileOutputStream out = new FileOutputStream(librariesIndexFile);
out.write("{ \"libraries\" : [ ] }".getBytes());
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
librariesIndexer.parseIndex();
@ -626,16 +631,11 @@ public class BaseNoGui {
if (!distFolder.exists()) {
return null;
}
File[] files = distFolder.listFiles();
File[] files = distFolder.listFiles(new OnlyFilesWithExtension("tar.bz2", "zip", "tar.gz", "tar"));
if (files.length > 1) {
throw new IllegalStateException("More than one file in " + distFolder);
}
File file = files[0];
if (!file.isFile() || !(file.getName().contains(".tar.") || file.getName().endsWith(".zip"))) {
throw new IllegalStateException(file + " must be a valid .tar.* or .zip file");
}
return file;
return files[0];
}
static protected void initPlatform() {

View File

@ -29,13 +29,15 @@ public class OnlyFilesWithExtension implements FilenameFilter {
String extensions[];
public OnlyFilesWithExtension(String... ext) {
extensions = ext;
this.extensions = ext;
}
public boolean accept(File dir, String name) {
for (String ext : extensions)
if (name.endsWith(ext))
for (String ext : extensions) {
if (name.endsWith(ext)) {
return true;
}
}
return false;
}