📄 opentorrentwindow.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: OpenTorrentWindow.java
package org.gudy.azureus2.ui.swt;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.ui.UIFunctions;
import com.aelitis.azureus.ui.UIFunctionsManager;
import com.aelitis.azureus.ui.common.updater.UIUpdatable;
import com.aelitis.azureus.ui.common.updater.UIUpdater;
import com.aelitis.azureus.ui.swt.imageloader.ImageLoader;
import java.io.*;
import java.util.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.*;
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
import org.gudy.azureus2.core3.disk.DiskManagerFileInfoSet;
import org.gudy.azureus2.core3.download.*;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.internat.*;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.torrentdownloader.TorrentDownloader;
import org.gudy.azureus2.core3.torrentdownloader.TorrentDownloaderCallBackInterface;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.ui.swt.components.shell.ShellFactory;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.mainwindow.TorrentOpener;
import org.gudy.azureus2.ui.swt.shells.MessageSlideShell;
// Referenced classes of package org.gudy.azureus2.ui.swt:
// FileDownloadWindow, Messages, OpenUrlWindow, TorrentUtil,
// Utils
public class OpenTorrentWindow
implements TorrentDownloaderCallBackInterface, UIUpdatable
{
private static final class FileStatsCacheItem
{
boolean exists;
long freeSpace;
public FileStatsCacheItem(File f)
{
exists = f.exists();
if (exists)
freeSpace = FileUtil.getUsableSpace(f);
else
freeSpace = -1L;
}
}
private static final class Partition
{
long bytesToConsume;
long freeSpace;
final File root;
public Partition(File root)
{
bytesToConsume = 0L;
freeSpace = 0L;
this.root = root;
}
}
private class TorrentFileInfo
{
final String orgFullName;
final String orgFileName;
long lSize;
boolean bDownload;
private String destFileName;
private String destPathName;
long iIndex;
boolean isValid;
final TorrentInfo parent;
final OpenTorrentWindow this$0;
public void setFullDestName(String newFullName)
{
if (newFullName == null)
{
setDestPathName(null);
setDestFileName(null);
return;
} else
{
File newPath = new File(newFullName);
setDestPathName(newPath.getParent());
setDestFileName(newPath.getName());
return;
}
}
public void setDestPathName(String newPath)
{
if (parent.torrent.isSimpleTorrent())
parent.setParentDir(newPath);
else
destPathName = newPath;
}
public void setDestFileName(String newFileName)
{
if (orgFileName.equals(newFileName))
destFileName = null;
else
destFileName = newFileName;
}
public String getDestPathName()
{
if (destPathName != null)
return destPathName;
if (parent.torrent.isSimpleTorrent())
return parent.getParentDir();
else
return (new File(parent.getDataDir(), orgFullName)).getParent();
}
public String getDestFileName()
{
return destFileName != null ? destFileName : orgFileName;
}
public File getDestFileFullName()
{
String path = getDestPathName();
String file = getDestFileName();
return new File(path, file);
}
public boolean okToDisable()
{
return parent.okToDisableAll();
}
public boolean isLinked()
{
return destFileName != null || destPathName != null;
}
public TorrentFileInfo(TorrentInfo parent, TOTorrentFile torrentFile, int iIndex)
{
this$0 = OpenTorrentWindow.this;
super();
this.parent = parent;
lSize = torrentFile.getLength();
this.iIndex = iIndex;
bDownload = true;
isValid = true;
orgFullName = torrentFile.getRelativePath();
orgFileName = (new File(orgFullName)).getName();
}
}
private class TorrentInfo
{
String sOriginatingLocation;
String sFileName;
String sDestDir;
String sDestSubDir;
TOTorrent torrent;
int iStartID;
int iQueueLocation;
boolean isValid;
boolean bDeleteFileOnCancel;
private TorrentFileInfo files[];
final OpenTorrentWindow this$0;
public String getParentDir()
{
return sDestDir;
}
public void setParentDir(String parentDir)
{
sDestDir = parentDir;
}
public String getDataDir()
{
if (torrent.isSimpleTorrent())
return sDestDir;
else
return (new File(sDestDir, sDestSubDir != null ? sDestSubDir : FileUtil.convertOSSpecificChars(getTorrentName(), true))).getPath();
}
public String getSmartDestDir()
{
String sSmartDir = sDestDir;
try
{
String name = getTorrentName();
String torrentFileName = (new File(sFileName)).getName().replaceFirst("\\.torrent$", "");
int totalSegmentsLengths = 0;
String segments[][] = {
name.split("[^a-zA-Z]+"), torrentFileName.split("[^a-zA-Z]+")
};
List downloadManagers = gm.getDownloadManagers();
for (int x = 0; x < segments.length; x++)
{
String segmentArray[] = segments[x];
for (int i = 0; i < segmentArray.length; i++)
{
int l = segmentArray[i].length();
if (l > 1)
{
segmentArray[i] = segmentArray[i].toLowerCase();
totalSegmentsLengths += l;
}
}
}
int maxMatches = 0;
DownloadManager match = null;
Iterator iter = downloadManagers.iterator();
do
{
if (!iter.hasNext())
break;
DownloadManager dm = (DownloadManager)iter.next();
if (dm.getState() != 100)
{
int numMatches = 0;
String dmName = dm.getDisplayName().toLowerCase();
for (int x = 0; x < segments.length; x++)
{
String segmentArray[] = segments[x];
for (int i = 0; i < segmentArray.length; i++)
{
int l = segmentArray[i].length();
if (l <= 1)
continue;
String segment = segmentArray[i];
if (dmName.indexOf(segment) >= 0)
numMatches += l;
}
}
if (numMatches > maxMatches)
{
maxMatches = numMatches;
match = dm;
}
}
} while (true);
if (match != null)
{
int iMatchLevel = (maxMatches * 100) / totalSegmentsLengths;
if (iMatchLevel >= 30)
{
File f = match.getSaveLocation();
if (!f.isDirectory() || match.getDiskManagerFileInfo().length > 1)
f = f.getParentFile();
if (f != null && f.isDirectory())
sSmartDir = f.getAbsolutePath();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return sSmartDir;
}
public TorrentFileInfo[] getFiles()
{
if (files == null && torrent != null)
{
TOTorrentFile tfiles[] = torrent.getFiles();
files = new TorrentFileInfo[tfiles.length];
for (int i = 0; i < files.length; i++)
files[i] = new TorrentFileInfo(this, tfiles[i], i);
}
return files;
}
public String getTorrentName()
{
if (torrent == null)
return "";
LocaleUtilDecoder decoder = LocaleTorrentUtil.getTorrentEncodingIfAvailable(torrent);
if (decoder != null)
return decoder.decodeString(torrent.getName());
break MISSING_BLOCK_LABEL_42;
Exception e;
e;
return new String(torrent.getName());
e;
return "TextDecodingError";
}
public boolean allFilesMoving()
{
TorrentFileInfo files[] = getFiles();
for (int j = 0; j < files.length; j++)
if (files[j].isLinked())
return false;
return true;
}
public boolean allFilesExist()
{
TorrentFileInfo files[] = getFiles();
for (int i = 0; i < files.length; i++)
{
TorrentFileInfo fileInfo = files[i];
if (!fileInfo.bDownload)
continue;
File file = fileInfo.getDestFileFullName();
if (!file.exists() || file.length() != fileInfo.lSize)
return false;
}
return true;
}
public void renameDuplicates()
{
if (iStartID == 3 || !COConfigurationManager.getBooleanParameter("DefaultDir.AutoSave.AutoRename") || allFilesExist())
return;
if (!torrent.isSimpleTorrent())
{
if ((new File(getDataDir())).isDirectory())
{
int idx = 0;
File f;
do
{
idx++;
f = new File((new StringBuilder()).append(getDataDir()).append("-").append(idx).toString());
} while (f.isDirectory());
sDestSubDir = f.getName();
}
} else
{
TorrentFileInfo fileInfos[] = getFiles();
for (int i = 0; i < fileInfos.length; i++)
{
TorrentFileInfo info = fileInfos[i];
File file = info.getDestFileFullName();
int idx = 0;
for (; file.exists(); file = new File(info.getDestPathName(), (new StringBuilder()).append(idx).append("-").append(info.getDestFileName()).toString()))
idx++;
info.setDestFileName(file.getName());
}
}
}
public boolean okToDisableAll()
{
return true;
}
public TorrentInfo(String sFileName, TOTorrent torrent, boolean bDeleteFileOnCancel)
{
this$0 = OpenTorrentWindow.this;
super();
files = null;
this.bDeleteFileOnCancel = bDeleteFileOnCancel;
this.sFileName = sFileName;
sOriginatingLocation = sFileName;
this.torrent = torrent;
sDestDir = OpenTorrentWindow.this.sDestDir;
iStartID = getDefaultStartMode();
iQueueLocation = 1;
isValid = true;
try
{
LocaleTorrentUtil.getTorrentEncoding(this.torrent);
}
catch (Exception e)
{
e.printStackTrace();
}
if (OpenTorrentWindow.getSaveSilentlyDir() == null && COConfigurationManager.getBooleanParameter("DefaultDir.BestGuess") && !COConfigurationManager.getBooleanParameter("Move Completed When Done"))
sDestDir = getSmartDestDir();
}
}
private static final int MIN_BUTTON_HEIGHT;
private static final String PARAM_DEFSAVEPATH = "Default save path";
private static final String PARAM_MOVEWHENDONE = "Move Completed When Done";
private static final String PARAM_VIEWMODE = "OpenTorrentWindow.viewMode";
private static final String MSG_ALREADY_EXISTS = "OpenTorrentWindow.mb.alreadyExists";
private static final String MSG_ALREADY_EXISTS_NAME = "OpenTorrentWindow.mb.alreadyExists.default.name";
private static final int STARTMODE_QUEUED = 0;
private static final int STARTMODE_STOPPED = 1;
private static final int STARTMODE_FORCESTARTED = 2;
private static final int STARTMODE_SEEDING = 3;
private static final int QUEUELOCATION_TOP = 0;
private static final int QUEUELOCATION_BOTTOM = 1;
private static final String startModes[] = {
"queued", "stopped", "forceStarted", "seeding"
};
private static final String queueLocations[] = {
"first", "last"
};
private static OpenTorrentWindow stOpenTorrentWindow = null;
private Shell shell;
private Table dataFileTable;
private TableEditor dataFileTableEditor;
private Table torrentTable;
private Button ok;
private Combo cmbDataDir;
private Composite cSaveTo;
private Combo cmbStartMode;
private Combo cmbQueueLocation;
private GlobalManager gm;
private ArrayList dataFiles;
private ArrayList torrentList;
private ArrayList downloaders;
private boolean bOverrideStartModeToStopped;
private boolean bDefaultForSeeding;
private ArrayList disposeList;
private boolean bClosed;
private Shell shellForChildren;
private String sDestDir;
protected boolean bSkipDataDirModify;
private static final AzureusCore core = AzureusCoreFactory.getSingleton();
private StringList dirList;
private Label dataFileTableLabel;
private Composite diskspaceComp;
private int activeTorrentCount;
private static final int EDIT_COLUMN_INDEX = 1;
private final Map fileStatCache = new WeakHashMap(20);
private final Map parentToRootCache = new WeakHashMap(20);
private volatile boolean diskFreeInfoRefreshPending;
private volatile boolean diskFreeInfoRefreshRunning;
public static final synchronized void invoke(Shell parent, GlobalManager gm, String sPathOfFilesToOpen, String sFilesToOpen[], boolean bDefaultStopped, boolean bForSeeding, boolean bPopupOpenURL)
{
String saveSilentlyDir = null;
if (stOpenTorrentWindow == null)
{
boolean bMustOpen = sPathOfFilesToOpen == null && sFilesToOpen == null || bForSeeding;
if (!bMustOpen)
{
saveSilentlyDir = getSaveSilentlyDir();
bMustOpen = saveSilentlyDir == null;
}
stOpenTorrentWindow = new OpenTorrentWindow(parent, gm, bMustOpen);
} else
if (stOpenTorrentWindow.shell != null)
stOpenTorrentWindow.shell.forceActive();
if (stOpenTorrentWindow != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -