Esempio n. 1
0
void ItemPreviewComponent::tryToLoadImage()
{
    facts.clear();
    facts.add (file.getFullPathName());
    image = Image();

    ScopedPointer <InputStream> input (file.createInputStream());

    if (input != nullptr)
    {
        const int64 totalSize = input->getTotalLength();
        ImageFileFormat* format = ImageFileFormat::findImageFormatForStream (*input);
        input = nullptr;

        String formatName;
        if (format != nullptr)
            formatName = " " + format->getFormatName();

        image = ImageCache::getFromFile (file);

        if (image.isValid())
            facts.add (String (image.getWidth()) + " x " + String (image.getHeight()) + formatName);

        if (totalSize > 0)
            facts.add (File::descriptionOfSizeInBytes (totalSize));
    }

    facts.removeEmptyStrings (true);
}
Esempio n. 2
0
void CtrlrFileDownloader::run()
{
	ScopedPointer <InputStream> is (fileToDownload.createInputStream (false));
	const int totalLength = is->getTotalLength();
	int bytesSoFar = 0;
	const String packageFile = CtrlrUpdateManager::getMyPackage();

	if (outputFile.exists())
	{
		outputFile.deleteFile();
		outputFile.create();
	}

	while (! (is->isExhausted()))
	{
		if (threadShouldExit())
		{
			return;
		}

		MemoryBlock buffer(8192);
		const int num = is->read (buffer.getData(), 8192);

		if (num == 0)
			break;

		bytesSoFar += num;
		outputFile.appendData(buffer.getData(), buffer.getSize());

		setStatusMessage ("File: " + packageFile + "\nTotal size: " + File::descriptionOfSizeInBytes (totalLength) + " Got size: " + File::descriptionOfSizeInBytes (bytesSoFar));
		setProgress (bytesSoFar / (double)totalLength);
	}
}
Esempio n. 3
0
bool OwlNestSettings::downloadFromServer(CommandID commandID) {
    String nodeString, optionString, warningString;
    PropertySet* props = ApplicationConfiguration::getApplicationProperties();
    switch (commandID){
    case ApplicationCommands::checkForFirmwareUpdates:
      warningString = "Beware that this procedure can make your OWL unresponsive!";
      nodeString = "firmwares";
      optionString = props->getValue("firmware-dfu-options");
      break;
    case ApplicationCommands::checkForBootloaderUpdates:
      warningString = "Beware that this procedure can brick your OWL!";
      nodeString = "bootloaders";
      optionString = props->getValue("bootloader-dfu-options");
      break;
    default:
      return false;
    }
    
    String xmlFilename ("updates.xml");
    URL url(props->getValue("owl-updates-dir-url")+xmlFilename);
    ScopedPointer<XmlElement> xmlUpdates;
    if(url.isWellFormed())
      xmlUpdates = url.readEntireXmlStream(0);
    if(xmlUpdates == NULL) {
      AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "Connection Error", "Server connection failed");
      return false;
    }
    XmlElement* filesNode = xmlUpdates->getChildByName(nodeString);
    StringArray names;
    XmlElement* child = filesNode->getFirstChildElement();
    while(child != nullptr){
      names.add(child->getStringAttribute("name"));
      child = child->getNextElement();
    }
    AlertWindow popup("Download File From Server", "Choose file:", juce::AlertWindow::InfoIcon);
    popup.addButton("Cancel", 0, juce::KeyPress(), juce::KeyPress());
    popup.addButton("Download", 1, juce::KeyPress(), juce::KeyPress());
    popup.addComboBox("box", names);
    if(popup.runModalLoop()==0)
      return false;
    popup.setVisible(false);
    String selectedFilename(popup.getComboBoxComponent("box")->getText());
    URL fwUrl(props->getValue("owl-updates-dir-url")+selectedFilename);
    ScopedPointer<InputStream> strm;
    strm = fwUrl.createInputStream(0);
    if(strm == NULL){
      AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "Connection Error", "File unavailable", "Continue");
      return false;
    }
    File theTargetFile(ApplicationConfiguration::getApplicationDirectory().getChildFile(selectedFilename));
    FileChooser chooser("Save As", theTargetFile, "*.bin");
    bool succeeded = false;
    if(!chooser.browseForFileToSave(true))
      return false;
    theTargetFile = chooser.getResult();
    TemporaryFile temp (theTargetFile);
    ScopedPointer<FileOutputStream> out(temp.getFile().createOutputStream());
    if(out != nullptr) {
      out->writeFromInputStream(*strm, strm->getTotalLength());
      out = nullptr; // deletes the stream
      succeeded = temp.overwriteTargetFileWithTemporary();
    }
    if(!succeeded){
      AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "File Error", "Failed to save file", "Continue");
      return false;
    }
    if(AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon, "Update Device", 
				    "Would you like to update your OWL with this binary now? "+warningString, "Yes", "No"))
    {
        DBG("pathName"<< theTargetFile.getFullPathName());
        DBG("optionString " << optionString);
        return deviceFirmwareUpdate(theTargetFile, optionString);
    }
    return true;
}