📄 shareresourcefileordirimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: ShareResourceFileOrDirImpl.java
package org.gudy.azureus2.pluginsimpl.local.sharing;
import java.io.*;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.download.DownloadManagerState;
import org.gudy.azureus2.core3.download.DownloadManagerStateFactory;
import org.gudy.azureus2.core3.internat.LocaleTorrentUtil;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.TorrentUtils;
import org.gudy.azureus2.plugins.sharing.*;
import org.gudy.azureus2.pluginsimpl.local.torrent.TorrentImpl;
import org.gudy.azureus2.pluginsimpl.local.torrent.TorrentManagerImpl;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.sharing:
// ShareResourceImpl, ShareItemImpl, ShareManagerImpl, ShareResourceDirImpl,
// ShareResourceFileImpl, ShareResourceDirContentsImpl
public abstract class ShareResourceFileOrDirImpl extends ShareResourceImpl
{
protected File file;
protected ShareItemImpl item;
protected static ShareResourceImpl getResourceSupport(ShareManagerImpl _manager, File _file)
throws ShareException
{
return _manager.getResource(_file.getCanonicalFile());
IOException e;
e;
throw new ShareException("getCanonicalFile fails", e);
}
protected ShareResourceFileOrDirImpl(ShareManagerImpl _manager, ShareResourceDirContentsImpl _parent, int _type, File _file)
throws ShareException
{
super(_manager, _type);
file = _file;
if (getType() == 1)
{
if (!file.exists())
throw new ShareException("File '".concat(file.getName()).concat("' not found"));
if (!file.isFile())
throw new ShareException("Not a file");
} else
{
if (!file.exists())
throw new ShareException("Dir '".concat(file.getName()).concat("' not found"));
if (file.isFile())
throw new ShareException("Not a directory");
}
try
{
file = file.getCanonicalFile();
}
catch (IOException e)
{
throw new ShareException("ShareResourceFile: failed to get canonical name", e);
}
if (_parent != null)
{
setParent(_parent);
inheritAttributes(_parent);
}
createTorrent();
}
protected ShareResourceFileOrDirImpl(ShareManagerImpl _manager, int _type, File _file, Map _map)
throws ShareException
{
super(_manager, _type, _map);
file = _file;
item = ShareItemImpl.deserialiseItem(this, _map);
}
public boolean canBeDeleted()
throws ShareResourceDeletionVetoException
{
for (int i = 0; i < deletion_listeners.size(); i++)
((ShareResourceWillBeDeletedListener)deletion_listeners.get(i)).resourceWillBeDeleted(this);
return true;
}
protected abstract byte[] getFingerPrint()
throws ShareException;
protected void createTorrent()
throws ShareException
{
URL urls[];
TOTorrentCreator creator;
manager.reportCurrentTask((item != null ? "Re-creating" : "Creating").concat(" torrent for '").concat(file.toString()).concat("'"));
urls = manager.getAnnounceURLs();
creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(file, urls[0], manager.getAddHashes());
creator.addListener(manager);
TOTorrent to_torrent;
manager.setTorrentCreator(creator);
to_torrent = creator.create();
manager.setTorrentCreator(null);
break MISSING_BLOCK_LABEL_116;
Exception exception;
exception;
manager.setTorrentCreator(null);
throw exception;
String comment;
boolean private_torrent;
boolean dht_backup_enabled;
LocaleTorrentUtil.setDefaultTorrentEncoding(to_torrent);
for (int i = 1; i < urls.length; i++)
TorrentUtils.announceGroupsInsertLast(to_torrent, new URL[] {
urls[i]
});
comment = COConfigurationManager.getStringParameter("Sharing Torrent Comment").trim();
private_torrent = COConfigurationManager.getBooleanParameter("Sharing Torrent Private");
dht_backup_enabled = COConfigurationManager.getBooleanParameter("Sharing Permit DHT");
org.gudy.azureus2.plugins.torrent.TorrentAttribute ta_props = TorrentManagerImpl.getSingleton().getAttribute("ShareProperties");
String props = getAttribute(ta_props);
if (props == null)
break MISSING_BLOCK_LABEL_389;
StringTokenizer tok = new StringTokenizer(props, ";");
do
{
if (!tok.hasMoreTokens())
break MISSING_BLOCK_LABEL_389;
String token = tok.nextToken();
int pos = token.indexOf('=');
if (pos == -1)
{
Debug.out((new StringBuilder()).append("ShareProperty invalid: ").append(props).toString());
continue;
}
String lhs = token.substring(0, pos).trim().toLowerCase();
String rhs = token.substring(pos + 1).trim().toLowerCase();
boolean set = rhs.equals("true");
if (lhs.equals("private"))
{
private_torrent = set;
continue;
}
if (lhs.equals("dht_backup"))
{
dht_backup_enabled = set;
continue;
}
if (!lhs.equals("comment"))
break;
comment = rhs;
} while (true);
Debug.out((new StringBuilder()).append("ShareProperty invalid: ").append(props).toString());
if (comment.length() > 0)
to_torrent.setComment(comment);
TorrentUtils.setDHTBackupEnabled(to_torrent, dht_backup_enabled);
TorrentUtils.setPrivate(to_torrent, private_torrent);
if (TorrentUtils.isDecentralised(to_torrent))
TorrentUtils.setDecentralised(to_torrent);
DownloadManagerState download_manager_state = DownloadManagerStateFactory.getDownloadState(to_torrent);
TorrentUtils.setResumeDataCompletelyValid(download_manager_state);
download_manager_state.save();
if (item == null)
{
byte fingerprint[] = getFingerPrint();
item = new ShareItemImpl(this, fingerprint, new TorrentImpl(to_torrent));
} else
{
item.setTorrent(new TorrentImpl(to_torrent));
item.writeTorrent();
}
break MISSING_BLOCK_LABEL_553;
TOTorrentException e;
e;
if (e.getReason() == 9)
throw new ShareException("ShareResource: Operation cancelled", e);
else
throw new ShareException("ShareResource: Torrent create failed", e);
e;
throw new ShareException("ShareResource: Torrent create failed", e);
}
protected void checkConsistency()
throws ShareException
{
try
{
if (Arrays.equals(getFingerPrint(), item.getFingerPrint()))
{
if (!manager.torrentExists(item))
createTorrent();
} else
{
manager.addFileOrDir(null, file, getType(), true);
}
}
catch (Throwable e)
{
manager.delete(this);
}
}
protected static ShareResourceImpl deserialiseResource(ShareManagerImpl manager, Map map, int type)
throws ShareException
{
File file = new File(new String((byte[])(byte[])map.get("file"), "UTF8"));
if (type == 1)
return new ShareResourceFileImpl(manager, file, map);
return new ShareResourceDirImpl(manager, file, map);
UnsupportedEncodingException e;
e;
throw new ShareException("internal error", e);
}
protected void serialiseResource(Map map)
{
super.serialiseResource(map);
map.put("type", new Long(getType()));
try
{
map.put("file", file.toString().getBytes("UTF8"));
}
catch (UnsupportedEncodingException e)
{
Debug.printStackTrace(e);
}
item.serialiseItem(map);
}
protected void deleteInternal()
{
item.delete();
}
public String getName()
{
return file.toString();
}
public File getFile()
{
return file;
}
public ShareItem getItem()
{
return item;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -