mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Implemented "Update List" button of Boards Installer.
This commit is contained in:
parent
5d1e4e3f70
commit
fe2d087ebd
@ -91,7 +91,7 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
private String category;
|
private String category;
|
||||||
private String[] filters;
|
private String[] filters;
|
||||||
|
|
||||||
public ContributionManagerUI(Frame parent, ContributionsIndexer indexer) {
|
public ContributionManagerUI(Frame parent) {
|
||||||
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
setResizable(true);
|
setResizable(true);
|
||||||
@ -238,7 +238,9 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexer(ContributionsIndexer indexer) {
|
||||||
contribModel.setIndex(indexer.getIndex());
|
contribModel.setIndex(indexer.getIndex());
|
||||||
setCategories(indexer.getIndex().getCategories());
|
setCategories(indexer.getIndex().getCategories());
|
||||||
|
|
||||||
@ -305,11 +307,6 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
progressBar.setString(text);
|
progressBar.setString(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdatePressed() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
System.out.println("Update pressed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Installer methods follows
|
* Installer methods follows
|
||||||
*/
|
*/
|
||||||
@ -322,6 +319,25 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
installerThread.interrupt();
|
installerThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onUpdatePressed() {
|
||||||
|
installerThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
setProgressVisible(true);
|
||||||
|
installer.updateIndex();
|
||||||
|
onIndexesUpdated();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Show ERROR
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
setProgressVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
installerThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
public void onInstallPressed(final ContributedPlatform platform) {
|
public void onInstallPressed(final ContributedPlatform platform) {
|
||||||
installerThread = new Thread(new Runnable() {
|
installerThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -358,4 +374,8 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onIndexesUpdated() throws Exception {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1110,15 @@ public class Base {
|
|||||||
|
|
||||||
private void openInstallBoardDialog() {
|
private void openInstallBoardDialog() {
|
||||||
// Create dialog for contribution manager
|
// Create dialog for contribution manager
|
||||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.indexer);
|
@SuppressWarnings("serial")
|
||||||
|
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
||||||
|
@Override
|
||||||
|
protected void onIndexesUpdated() throws Exception {
|
||||||
|
BaseNoGui.reloadAllHardware();
|
||||||
|
setIndexer(BaseNoGui.indexer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
managerUI.setIndexer(BaseNoGui.indexer);
|
||||||
managerUI.setVisible(true);
|
managerUI.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2769,12 +2769,14 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
protected void onBoardOrPortChange() {
|
protected void onBoardOrPortChange() {
|
||||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||||
lineStatus.setBoardName(boardPreferences.get("name"));
|
if (boardPreferences != null)
|
||||||
|
lineStatus.setBoardName(boardPreferences.get("name"));
|
||||||
|
else
|
||||||
|
lineStatus.setBoardName("-");
|
||||||
lineStatus.setSerialPort(Preferences.get("serial.port"));
|
lineStatus.setSerialPort(Preferences.get("serial.port"));
|
||||||
lineStatus.repaint();
|
lineStatus.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the edit popup menu.
|
* Returns the edit popup menu.
|
||||||
*/
|
*/
|
||||||
|
@ -234,4 +234,39 @@ public class ContributionInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateIndex() throws Exception {
|
||||||
|
final String statusText = _("Downloading platforms index...");
|
||||||
|
updateProgress(0, statusText);
|
||||||
|
|
||||||
|
URL url = new URL("http://arduino.cc/package_index.json");
|
||||||
|
File tmpFile = File.createTempFile("package_index", ".json");
|
||||||
|
FileDownloader downloader = new FileDownloader(url, tmpFile);
|
||||||
|
downloader.addObserver(new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable o, Object arg) {
|
||||||
|
FileDownloader me = (FileDownloader) o;
|
||||||
|
String msg = "";
|
||||||
|
if (me.getDownloadSize() != null) {
|
||||||
|
long downloaded = me.getInitialSize() + me.getDownloaded() / 1000;
|
||||||
|
long total = me.getInitialSize() + me.getDownloadSize() / 1000;
|
||||||
|
msg = format(_("Downloaded {0}kb of {1}kb."), downloaded, total);
|
||||||
|
}
|
||||||
|
updateProgress((int) progress + progressStepsDelta * me.getProgress() /
|
||||||
|
100.0, statusText + " " + msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
downloader.download();
|
||||||
|
if (!downloader.isCompleted())
|
||||||
|
throw new Exception("Error dowloading " + url, downloader.getError());
|
||||||
|
|
||||||
|
// TODO: Check downloaded index
|
||||||
|
|
||||||
|
// Replace old index with the updated one
|
||||||
|
File outputFile = indexer.getIndexFile();
|
||||||
|
if (outputFile.exists())
|
||||||
|
outputFile.delete();
|
||||||
|
if (!tmpFile.renameTo(outputFile))
|
||||||
|
throw new Exception("An error occurred while updating platforms index!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import static processing.app.I18n._;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -19,6 +20,7 @@ import cc.arduino.packages.DiscoveryManager;
|
|||||||
import cc.arduino.packages.Uploader;
|
import cc.arduino.packages.Uploader;
|
||||||
import processing.app.debug.Compiler;
|
import processing.app.debug.Compiler;
|
||||||
import cc.arduino.packages.contributions.ContributionsIndexer;
|
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||||
|
import cc.arduino.utils.ArchiveExtractor;
|
||||||
import processing.app.debug.TargetBoard;
|
import processing.app.debug.TargetBoard;
|
||||||
import processing.app.debug.LegacyTargetPackage;
|
import processing.app.debug.LegacyTargetPackage;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
@ -585,10 +587,30 @@ public class BaseNoGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void initPackages() throws Exception {
|
static public void initPackages() throws Exception {
|
||||||
|
reloadAllHardware();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void reloadAllHardware() throws Exception {
|
||||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||||
if (!indexer.getIndexFile().isFile())
|
File indexFile = indexer.getIndexFile();
|
||||||
// TODO: run first setup
|
if (!indexFile.isFile()) {
|
||||||
;
|
try {
|
||||||
|
File distFile = getContentFile("dist/default_package.tar.bz2");
|
||||||
|
if (distFile.isFile()) {
|
||||||
|
// If present, unpack distribution file into preferences folder
|
||||||
|
ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 1);
|
||||||
|
|
||||||
|
// TODO: The first distribution file may be removed after extraction?
|
||||||
|
} else {
|
||||||
|
// Otherwise create an empty packages index
|
||||||
|
FileOutputStream out = new FileOutputStream(indexFile);
|
||||||
|
out.write("{ \"packages\" : [ ] }".getBytes());
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
indexer.parseIndex();
|
indexer.parseIndex();
|
||||||
indexer.syncWithFilesystem();
|
indexer.syncWithFilesystem();
|
||||||
System.out.println(indexer);
|
System.out.println(indexer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user