Esempio n. 1
0
void Stencil::parse()
{
  std::ifstream infile (source_filename());
  if (infile.is_open()) {
    parse_header(infile);

    // Both stencil dimensions must be odd
    assert(rows() == columns());
    assert(rows() % 2 != 0);
    assert(columns() % 2 != 0);

    kernel = std::make_shared<Array2d>(rows(), columns());

    parse_body(infile);
    infile.close();

    normalize();
  } else{
    std::cerr << "Unable to open file " << source_filename() << "\n";
  }
}
Esempio n. 2
0
bool WmdmDevice::CopyToStorage(const CopyJob& job) {
  if (!storage_control_ || !storage_)
    return false;

  // Create the song metadata
  IWMDMMetaData* metadata_iface = NULL;
  storage_->CreateEmptyMetadataObject(&metadata_iface);
  job.metadata_.ToWmdm(metadata_iface);

  // Convert the filenames to wchars
  ScopedWCharArray source_filename(QDir::toNativeSeparators(job.source_));
  ScopedWCharArray dest_filename(job.metadata_.basefilename());

  // Create the progress object
  WmdmProgress progress(job.progress_);

  // Copy the file
  IWMDMStorage* new_storage = NULL;
  if (storage_control_->Insert3(
      WMDM_MODE_BLOCK | WMDM_STORAGECONTROL_INSERTINTO |
      WMDM_FILE_CREATE_OVERWRITE | WMDM_CONTENT_FILE,
      WMDM_FILE_ATTR_FOLDER,
      source_filename,
      dest_filename,
      NULL, // operation
      &progress, // progress
      metadata_iface,
      NULL, // data
      &new_storage)) {
    qLog(Warning) << "Couldn't copy file to WMDM device";
    metadata_iface->Release();
    return false;
  }
  metadata_iface->Release();

  if (!new_storage)
    return false;

  // Get the metadata from the newly copied file
  IWMDMStorage3* new_storage3 = NULL;
  IWMDMMetaData* new_metadata = NULL;

  new_storage->QueryInterface(IID_IWMDMStorage3, (void**)&new_storage3);
  new_storage3->GetMetadata(&new_metadata);

  new_storage->Release();
  new_storage3->Release();

  if (!new_metadata)
    return false;

  // Add it to our LibraryModel
  Song new_song;
  new_song.InitFromWmdm(new_metadata);
  new_song.set_directory_id(1);
  songs_to_add_ << new_song;

  new_metadata->Release();

  // Remove the original if requested
  if (job.remove_original_) {
    if (!QFile::remove(job.source_))
      return false;
  }

  return true;
}