diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index 8b7d7ac62..f8c0d7985 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java @@ -109,6 +109,11 @@ public class LibrariesIndexer { // Clear all installed flags installedLibraries.clear(); installedLibrariesWithDuplicates.clear(); + + if (index.getLibraries() == null) { + return; + } + for (ContributedLibrary lib : index.getLibraries()) { lib.setInstalled(false); } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 753898286..d45ef1b30 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -592,11 +592,7 @@ public class BaseNoGui { try { indexer.parseIndex(); - } catch (JsonProcessingException e) { - FileUtils.deleteIfExists(indexFile); - FileUtils.deleteIfExists(indexSignatureFile); - throw e; - } catch (SignatureVerificationFailedException e) { + } catch (JsonProcessingException | SignatureVerificationFailedException e) { FileUtils.deleteIfExists(indexFile); FileUtils.deleteIfExists(indexSignatureFile); throw e; @@ -611,6 +607,17 @@ public class BaseNoGui { librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), indexer); File librariesIndexFile = librariesIndexer.getIndexFile(); + copyStockLibraryIndexIfUpstreamIsMissing(librariesIndexFile); + try { + librariesIndexer.parseIndex(); + } catch (JsonProcessingException e) { + FileUtils.deleteIfExists(librariesIndexFile); + copyStockLibraryIndexIfUpstreamIsMissing(librariesIndexFile); + librariesIndexer.parseIndex(); + } + } + + private static void copyStockLibraryIndexIfUpstreamIsMissing(File librariesIndexFile) throws IOException { if (!librariesIndexFile.isFile()) { File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json"); if (defaultLibraryJsonFile.isFile()) { @@ -628,12 +635,6 @@ public class BaseNoGui { } } } - try { - librariesIndexer.parseIndex(); - } catch (JsonProcessingException e) { - FileUtils.deleteIfExists(librariesIndexFile); - throw e; - } } static protected void initPlatform() {