|
5 | 5 | import java.io.File;
|
6 | 6 | import java.io.FileInputStream;
|
7 | 7 | import java.io.FileWriter;
|
| 8 | +import java.io.FileOutputStream; |
8 | 9 | import java.io.IOException;
|
9 | 10 | import java.io.InputStream;
|
10 | 11 | import java.net.URISyntaxException;
|
|
19 | 20 | import cc.arduino.packages.Uploader;
|
20 | 21 | import processing.app.debug.Compiler;
|
21 | 22 | import cc.arduino.packages.contributions.ContributionsIndexer;
|
| 23 | +import cc.arduino.utils.ArchiveExtractor; |
22 | 24 | import processing.app.debug.TargetBoard;
|
23 | 25 | import processing.app.debug.LegacyTargetPackage;
|
24 | 26 | import processing.app.debug.TargetPackage;
|
@@ -585,14 +587,34 @@ static public void initLogger() {
|
585 | 587 | }
|
586 | 588 |
|
587 | 589 | static public void initPackages() throws Exception {
|
| 590 | + reloadAllHardware(); |
| 591 | + } |
| 592 | + |
| 593 | + static public void reloadAllHardware() throws Exception { |
588 | 594 | indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
589 |
| - if (!indexer.getIndexFile().isFile()) |
590 |
| - // TODO: run first setup |
591 |
| - ; |
| 595 | + File indexFile = indexer.getIndexFile(); |
| 596 | + if (!indexFile.isFile()) { |
| 597 | + try { |
| 598 | + File distFile = getContentFile("dist/default_package.tar.bz2"); |
| 599 | + if (distFile.isFile()) { |
| 600 | + // If present, unpack distribution file into preferences folder |
| 601 | + ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 1); |
| 602 | + |
| 603 | + // TODO: The first distribution file may be removed after extraction? |
| 604 | + } else { |
| 605 | + // Otherwise create an empty packages index |
| 606 | + FileOutputStream out = new FileOutputStream(indexFile); |
| 607 | + out.write("{ \"packages\" : [ ] }".getBytes()); |
| 608 | + out.close(); |
| 609 | + } |
| 610 | + } catch (IOException e) { |
| 611 | + e.printStackTrace(); |
| 612 | + } |
| 613 | + } |
592 | 614 | indexer.parseIndex();
|
593 | 615 | indexer.syncWithFilesystem();
|
594 | 616 | System.out.println(indexer);
|
595 |
| - |
| 617 | + |
596 | 618 | packages = new HashMap<String, TargetPackage>();
|
597 | 619 | loadHardware(getHardwareFolder());
|
598 | 620 | loadHardware(getSketchbookHardwareFolder());
|
|
0 commit comments