void MainFrame::on_rename_file(wxCommandEvent& WXUNUSED(event)) { MetalinkFile file = editor_.get_file(); wxString filename = wxGetTextFromUser( wxT("Please enter a file name:"), wxT("Rename file"), file.get_filename() ); if(filename == wxT("")) return; file.set_filename(filename); editor_.set_file(file); }
MetalinkFile Metalink3Writer::convert_hash_types(const MetalinkFile& file) { std::vector<MetalinkHash> hashes = file.get_file_hashes(); for(std::vector<MetalinkHash>::iterator i = hashes.begin(), eoi = hashes.end(); i != eoi; ++i) { (*i).type = convert_hash_type((*i).type); } wxString piece_type = convert_hash_type(file.get_piece_hash_type()); MetalinkFile file2 = file; file2.set_file_hashes(hashes); file2.set_piece_hash_type(piece_type); return file2; }
void Metalink4Writer::write_piece_hash(const MetalinkFile& file) { if(file.get_piece_hashes().empty()) return; if(file.get_piece_hash_type().empty()) return; start(wxT("pieces")); add_attr(wxT("length"), wxString::Format(wxT("%lu"), file.get_piece_length())); add_attr(wxT("type"), file.get_piece_hash_type()); close_start(); const std::vector<wxString>& hashes = file.get_piece_hashes(); for(std::vector<wxString>::const_iterator i = hashes.begin(), eoi = hashes.end(); i != eoi; ++i) { add_element(wxT("hash"), *i); } end(wxT("pieces")); }
void MetalinkEditorTest::testLoadTorrent3() { // Setup wxString filename = get_testfile(wxT("test2.metalink")); MetalinkEditor editor; // Exercise editor.open(filename); // Verify CPPUNIT_ASSERT_EQUAL(1, editor.num_files()); MetalinkFile file = editor.get_file(); CPPUNIT_ASSERT(file.get_filename() == wxT("test55")); CPPUNIT_ASSERT(file.get_sources().size() == 1); MetalinkSource src = file.get_sources().at(0); CPPUNIT_ASSERT(src.get_uri() == wxT("http://torrent.com/test.torrent")); CPPUNIT_ASSERT(src.get_priority() == 23); CPPUNIT_ASSERT(src.get_location().empty()); CPPUNIT_ASSERT(src.is_torrent()); }
void Metalink4Writer::write_hashes(const MetalinkFile& file) { const std::vector<MetalinkHash>& hashes = file.get_file_hashes(); for(std::vector<MetalinkHash>::const_iterator i = hashes.begin(), eoi = hashes.end(); i != eoi; ++i) { start(wxT("hash")); add_attr(wxT("type"), (*i).type); end(wxT("hash"), (*i).value); } }
void Metalink3Writer::write_piece_hashes(const MetalinkFile& file) { if(!has_piece_hashes(file)) return; start(wxT("pieces")); add_attr(wxT("length"), wxString::Format(wxT("%lu"), file.get_piece_length())); add_attr(wxT("type"), file.get_piece_hash_type()); close_start(); const std::vector<wxString>& hashes = file.get_piece_hashes(); long index = 0; for(std::vector<wxString>::const_iterator i = hashes.begin(), eoi = hashes.end(); i != eoi; ++i) { start(wxT("hash")); add_attr(wxT("piece"), wxString::Format(wxT("%ld"), index)); end(wxT("hash"), *i); index++; } end(wxT("pieces")); }
void ChunkPanel::update() { MetalinkFile file = editor_.get_file(); long num = file.get_piece_hashes().size(); if(num == 0) { label1_->SetLabel(wxT("This file has no chunk checksums.")); btn_delete_->Enable(false); } else { wxString type = file.get_piece_hash_type(); wxString msg; msg << wxT("This file has ") << num; msg << wxT(" chunk checksum"); if(num > 1) { msg << wxT("s"); } msg << wxT(" of type '") << type << wxT("'."); label1_->SetLabel(msg); btn_delete_->Enable(true); } }
void Metalink4Writer::write_file(const MetalinkFile& file) { start(wxT("file")); add_attr(wxT("name"), file.get_filename()); close_start(); add_element(wxT("identity"), file.get_identity()); add_element(wxT("description"), file.get_description()); add_element(wxT("version"), file.get_version()); add_element(wxT("size"), file.get_size()); write_hashes(file); write_piece_hash(file); const std::vector<MetalinkSource>& sources = file.get_sources(); for(std::vector<MetalinkSource>::const_iterator i = sources.begin(), eoi = sources.end(); i != eoi; ++i) { write_source(*i); } end(wxT("file")); }
bool Metalink3Writer::has_piece_hashes(const MetalinkFile& file) { if(file.get_piece_hashes().empty()) return false; if(file.get_piece_hash_type().empty()) return false; return true; }
bool Metalink3Writer::has_hashes(const MetalinkFile& file) { return !file.get_file_hashes().empty(); }
void ChunkPanel::on_delete(wxCommandEvent& WXUNUSED(event)) { MetalinkFile file = editor_.get_file(); file.set_piece_hash(wxT(""), 0, std::vector<wxString>()); editor_.set_file(file); }