bool CloudReconnectWorker::getDecryptedConnectionData(std::string& decryptedData)
    {
      bool newEncryptedDataFileUsed = false;

      std::string encryptedDataFile;
      std::string newEncryptedDataFile;

      m_cloudStatus.getPathCloudServerDataFile(encryptedDataFile);
      m_cloudStatus.getPathNewCloudServerDataFile(newEncryptedDataFile);
      std::ifstream binaryFile(newEncryptedDataFile.c_str(), std::ifstream::binary);
      if (binaryFile.is_open())
      {
        LOG_VNotice(core, "Using new encrypted data to reconnect.\n");
        binaryFile.close();
        newEncryptedDataFileUsed = true;
      }
      else
      {
        LOG_VNotice(core, "Using old encrypted data to reconnect.\n");
        std::ifstream binaryFile(encryptedDataFile.c_str(), std::ifstream::binary);
        if (binaryFile.is_open())
        {
         binaryFile.close();
        }
        else
        {
         LOG_VError(core, "Could not open encrypted binary file [%s]\n", encryptedDataFile.c_str());
         return false;
        }
      }

      bool decryptOk = false;
      EncryptData encryptData(*m_pSpotSession);
      if(newEncryptedDataFileUsed)
      {
        decryptOk = encryptData.decryptConnectionData(newEncryptedDataFile, decryptedData);
        if(decryptOk)
        {
          replaceOldEncryptedConnectionData(encryptedDataFile, newEncryptedDataFile);
        }
      }
      else
      {
        decryptOk = encryptData.decryptConnectionData(encryptedDataFile, decryptedData);
      }
      return decryptOk;
    }
void ErrorReportDialog::onShowFileContent(const QItemSelection& newSelection, const QItemSelection & oldSelection)
{
	ARX_UNUSED(oldSelection);
	const QModelIndexList selectedIndexes = newSelection.indexes();
	if(selectedIndexes.empty())
		return;

	const QModelIndex selectedIndex = selectedIndexes.at(0);
	if(!selectedIndex.isValid())
		return;
	
	fs::path fileName = m_errorReport.GetAttachedFiles()[selectedIndex.row()].path;
	QString ext = fileName.ext().c_str();
	if(ext == ".txt" || ext == ".log" || ext == ".ini" || ext == ".xml")
	{
		QFile textFile(fileName.string().c_str());
		textFile.open(QIODevice::ReadOnly | QIODevice::Text);
		
		QByteArray data;
		data = textFile.readAll();
		
		ui->fileViewText->setText(QString::fromUtf8(data));
		ui->stackedFileViews->setCurrentIndex(0);
	}
	else if(ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".png" || ext == ".gif")
	{
		m_fileViewImage.load(fileName.string().c_str());
		ui->stackedFileViews->setCurrentIndex(1);
	}
	else
	{
		QFile binaryFile(fileName.string().c_str());
		binaryFile.open(QIODevice::ReadOnly);
		
		if(binaryFile.size() > 20 * 1024 * 1024) {
			ui->stackedFileViews->setCurrentIndex(3);
			return;
		}

		QByteArray data;
		data = binaryFile.readAll();

		m_fileViewHex.setData(data);
		ui->stackedFileViews->setCurrentIndex(2);
	}
}
void ResourceCompiler::loadBinaryData()
{
    map<string, string>::iterator pos;

    // iterate over all resource file mappings we have
    for(pos = m_ResourceFileMap.begin(); pos != m_ResourceFileMap.end(); ++pos) {

        // open given resource file
        ifstream binaryFile(pos->second.c_str(), ios::in | ios::binary);
        if(!binaryFile) {
            cerr << "Couldn't open binary file \"" <<  pos->second << "\"!" << endl,
            exit(1);
        }

        // let's get some exceptions
        binaryFile.exceptions(ios::failbit | ios::badbit);

        try {
            // store binary resource file using stream iterators
            //			copy(	istream_iterator<unsigned char>(binaryFile),
            //					istream_iterator<unsigned char>(),
            //					back_inserter(m_ResourceDataMap[pos->first])
            //			);

            // "copy" ends prematurely, so use the crude way instead
            char c = 0;
            while(binaryFile.get(c)) {
                m_ResourceDataMap[pos->first].push_back(c);
            }
        }
        catch(const ios::failure& error) {
            // check stream state for real error
            if(!binaryFile.eof()) {
                cerr << "Error during binary file processing: " << error.what();
            }
        }

        // close current file
        binaryFile.close();
    }
}
Пример #4
0
bool Program::loadBinary()
{
  // don't load if not explicitly enabled
  if (util::envVarValue("SKELCL_LOAD_BINARY") != "YES") return false;

  // if hash is empty no binary is loaded (maybe be more gentle and just return)
  ASSERT(!_hash.empty());

  for (auto& devicePtr : globalDeviceList) {
    std::ifstream binaryFile(binaryFilename(_hash, devicePtr),
                               std::ios_base::in
                             | std::ios_base::binary
                             | std::ios_base::ate);
    if (binaryFile.fail()) {
      _clPrograms.clear();
      return false;
    }

    // get the size of the file
    std::ifstream::pos_type size = binaryFile.tellg();
    // allocate memory
    std::unique_ptr<char[]> binary(new char[size]);
    // set position in file to the beginning
    binaryFile.seekg(0, std::ios::beg);
    // read the hole file
    binaryFile.read(binary.get(), size);
    // close it
    binaryFile.close();
    // push the binary on the vector
    cl::Program::Binaries binaries(1, std::make_pair(binary.get(), size));
    std::vector<cl::Device> devices{ devicePtr->clDevice() };
    _clPrograms.push_back( cl::Program( devicePtr->clContext(),
                                        devices, binaries ) );

    LOG_DEBUG_INFO("Load binary for device ", devicePtr->id(),
                   " from file ", binaryFilename(_hash, devicePtr));
  }
  ASSERT(_clPrograms.size() == globalDeviceList.size());
  return true;
}