public static void writeToFile( TOTorrent torrent, File file, boolean force_backup ) throws TOTorrentException { torrent.setAdditionalStringProperty("torrent filename", file.toString()); writeToFile( torrent, force_backup ); }
@Override public void save() throws TorrentException { try{ TorrentUtils.writeToFile( torrent ); }catch( TOTorrentException e ){ throw( new TorrentException( "Torrent::save Fails", e )); } }
writeToFile( torrent );
public static void setObtainedFrom( File file, String str ) { try{ TOTorrent torrent = readFromFile( file, false, false ); setObtainedFrom( torrent, str ); writeToFile( torrent ); } catch (TOTorrentException e) { // ignore, file probably not torrent }catch( Throwable e ){ Debug.out( e ); } }
TorrentUtils.writeToFile( torrent );
public static void writeToFile( TOTorrent torrent, boolean force_backup ) throws TOTorrentException { try{ torrent.getMonitor().enter(); String str = torrent.getAdditionalStringProperty("torrent filename"); if ( str == null ){ throw (new TOTorrentException("TorrentUtils::writeToFile: no 'torrent filename' attribute defined", TOTorrentException.RT_FILE_NOT_FOUND)); } if ( str.equals( MEM_ONLY_TORRENT_PATH )){ return; } // save first to temporary file as serialisation may require state to be re-read from // the existing file first and if we rename to .bak first then this aint good File torrent_file_tmp = new File(str + "._az"); torrent.serialiseToBEncodedFile( torrent_file_tmp ); // now backup if required
protected void torrentRemoved( String torrent_file_str, TOTorrent torrent ) { TRHostTorrent host_torrent = host.getHostTorrent( torrent ); if ( host_torrent != null ){ // it we remove a torrent while it is hosted then we flip it into passive mode to // keep it around in a sensible state // we've got to ensure that the torrent's file location is available in the torrent itself // as we're moving from download-managed persistence to host managed :( // check file already exists - might have already been deleted as in the // case of shared resources File torrent_file = new File( torrent_file_str ); if ( torrent_file.exists()){ try{ TorrentUtils.writeToFile( host_torrent.getTorrent(), torrent_file, false ); host_torrent.setPassive( true ); }catch( Throwable e ){ Debug.out( "Failed to make torrent '" + torrent_file_str + "' passive: " + Debug.getNestedExceptionMessage(e)); } } } }
TorrentUtils.writeToFile(torrent);
private static void writeTorrentIfExists(TOTorrent torrent) { if (!CoreFactory.isCoreRunning()) { return; } Core core = CoreFactory.getSingleton(); if (core == null || !core.isStarted()) { return; } GlobalManager gm = core.getGlobalManager(); if (gm == null || gm.getDownloadManager(torrent) == null) { return; } try { TorrentUtils.writeToFile(torrent); } catch (TOTorrentException e) { Debug.out(e); } }
@Override public void handleEvent(Event e) { if (e.widget instanceof MenuItem) { String text = ((MenuItem) e.widget).getText(); TOTorrent torrent = manager.getTorrent(); TorrentUtils.announceGroupsSetFirst(torrent, text); try { TorrentUtils.writeToFile(torrent); } catch (TOTorrentException f) { Debug.printStackTrace(f); } TRTrackerAnnouncer tc = manager.getTrackerClient(); if (tc != null) { tc.resetTrackerUrl(false); } } } };
TorrentUtils.writeToFile(torrent);
protected void save( boolean force ) { if ( supressWrites > 0 && !force ){ return; } boolean do_write; try{ this_mon.enter(); do_write = write_required; write_required = false; }finally{ this_mon.exit(); } if ( do_write ){ try { // System.out.println( "writing download state for '" + new String(torrent.getName())); if (Logger.isEnabled()) Logger.log(new LogEvent(torrent, LOGID, "Saving state for download '" + TorrentUtils.getLocalisedName(torrent) + "'")); torrent.setAdditionalMapProperty( ATTRIBUTE_KEY, attributes ); TorrentUtils.writeToFile(torrent, true); } catch (Throwable e) { Logger.log(new LogEvent(torrent, LOGID, "Saving state", e)); } } else { // System.out.println( "not writing download state for '" + new String(torrent.getName())); } }
@Override public void run(TableRowCore row) { TRHostTorrent tr_torrent = (TRHostTorrent)row.getDataSource(true); final TOTorrent torrent = tr_torrent.getTorrent(); DownloadManager dm = core.getGlobalManager().getDownloadManager( torrent ); if ( dm != null ){ dm.getDownloadState().setCategory( category ); }else{ String cat_str; if ( category == null ){ cat_str = null; }else if ( category == CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED)){ cat_str = null; }else{ cat_str = category.getName(); } // bit of a hack-alert here TorrentUtils.setPluginStringProperty( torrent, "azcoreplugins.category", cat_str ); try{ TorrentUtils.writeToFile( torrent ); }catch( Throwable e ){ Debug.printStackTrace( e ); } } } });
TorrentUtils.writeToFile(torrent);