mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Merge pull request #3449 from ffissore/nightly-cores
Nightly cores support
This commit is contained in:
commit
bb3f7bfef4
@ -35,6 +35,10 @@ import cc.arduino.utils.network.FileDownloader;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.LinkOption;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
@ -49,36 +53,50 @@ public class DownloadableContributionsDownloader {
|
|||||||
stagingFolder = _stagingFolder;
|
stagingFolder = _stagingFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File download(DownloadableContribution contribution,
|
public File download(DownloadableContribution contribution, Progress progress, final String statusText) throws Exception {
|
||||||
final Progress progress, final String statusText)
|
|
||||||
throws Exception {
|
|
||||||
URL url = new URL(contribution.getUrl());
|
URL url = new URL(contribution.getUrl());
|
||||||
final File outputFile = new File(stagingFolder, contribution.getArchiveFileName());
|
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());
|
||||||
|
|
||||||
// Ensure the existence of staging folder
|
// Ensure the existence of staging folder
|
||||||
stagingFolder.mkdirs();
|
Files.createDirectories(stagingFolder.toPath());
|
||||||
|
|
||||||
|
if (!hasChecksum(contribution) && Files.exists(outputFile)) {
|
||||||
|
Files.delete(outputFile);
|
||||||
|
}
|
||||||
|
|
||||||
// Need to download or resume downloading?
|
// Need to download or resume downloading?
|
||||||
if (!outputFile.isFile() || (outputFile.length() < contribution.getSize())) {
|
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
|
||||||
download(url, outputFile, progress, statusText);
|
download(url, outputFile.toFile(), progress, statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test checksum
|
// Test checksum
|
||||||
progress.setStatus(_("Verifying archive integrity..."));
|
progress.setStatus(_("Verifying archive integrity..."));
|
||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
String checksum = contribution.getChecksum();
|
String checksum = contribution.getChecksum();
|
||||||
|
if (hasChecksum(contribution)) {
|
||||||
String algo = checksum.split(":")[0];
|
String algo = checksum.split(":")[0];
|
||||||
if (!FileHash.hash(outputFile, algo).equalsIgnoreCase(checksum)) {
|
if (!FileHash.hash(outputFile.toFile(), algo).equalsIgnoreCase(checksum)) {
|
||||||
throw new Exception(_("CRC doesn't match. File is corrupted."));
|
throw new Exception(_("CRC doesn't match. File is corrupted."));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contribution.setDownloaded(true);
|
contribution.setDownloaded(true);
|
||||||
contribution.setDownloadedFile(outputFile);
|
contribution.setDownloadedFile(outputFile.toFile());
|
||||||
return outputFile;
|
return outputFile.toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void download(URL url, File tmpFile, final Progress progress,
|
private boolean hasChecksum(DownloadableContribution contribution) {
|
||||||
final String statusText) throws Exception {
|
String checksum = contribution.getChecksum();
|
||||||
|
if (checksum == null || checksum.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String algo = checksum.split(":")[0];
|
||||||
|
|
||||||
|
return algo != null && algo.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void download(URL url, File tmpFile, Progress progress, String statusText) throws Exception {
|
||||||
FileDownloader downloader = new FileDownloader(url, tmpFile);
|
FileDownloader downloader = new FileDownloader(url, tmpFile);
|
||||||
downloader.addObserver(new Observer() {
|
downloader.addObserver(new Observer() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user