use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class Utils method setQuickViewActive.
public static void setQuickViewActive(DiskManagerFileInfo file, boolean active) {
synchronized (quick_view_active) {
if (!active) {
quick_view_active.remove(file);
return;
}
if (quick_view_active.contains(file)) {
return;
}
String ext = file.getExtension().toLowerCase();
boolean file_complete = file.getDownloaded() == file.getLength();
if (ext.equals(".rar")) {
quick_view_active.add(file);
quickViewRAR(file);
} else {
if (file_complete) {
quickView(file);
} else {
quick_view_active.add(file);
if (file.isSkipped()) {
file.setSkipped(false);
}
file.setPriority(1);
DiskManagerFileInfo[] all_files = file.getDownloadManager().getDiskManagerFileInfoSet().getFiles();
for (DiskManagerFileInfo f : all_files) {
if (!quick_view_active.contains(f)) {
f.setPriority(0);
}
}
if (quick_view_event == null) {
quick_view_event = SimpleTimer.addPeriodicEvent("qv_checker", 5 * 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
synchronized (quick_view_active) {
Iterator<DiskManagerFileInfo> it = quick_view_active.iterator();
while (it.hasNext()) {
DiskManagerFileInfo file = it.next();
if (file.getDownloadManager().isDestroyed()) {
it.remove();
} else {
if (file.getDownloaded() == file.getLength()) {
quickView(file);
it.remove();
}
}
}
if (quick_view_active.isEmpty()) {
quick_view_event.cancel();
quick_view_event = null;
}
}
}
});
}
}
}
if (!file_complete) {
execSWTThreadLater(10, new Runnable() {
@Override
public void run() {
MessageBoxShell mb = new MessageBoxShell(SWT.OK, MessageText.getString("quick.view.scheduled.title"), MessageText.getString("quick.view.scheduled.text"));
mb.setDefaultButtonUsingStyle(SWT.OK);
mb.setRemember("quick.view.inform.activated.id", false, MessageText.getString("label.dont.show.again"));
mb.setLeftImage(SWT.ICON_INFORMATION);
mb.open(null);
}
});
}
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class MenuFactory method addAlertsMenu.
public static void addAlertsMenu(Menu menu, final DownloadManager dm, final DiskManagerFileInfo[] files) {
if (files.length == 0) {
return;
}
String[][] alert_keys = { { "Play File Finished", "playfilefinished" }, { "Play File Finished Announcement", "playfilespeech" }, { "Popup File Finished", "popupfilefinished" } };
Menu alert_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem alerts_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(alerts_item, "ConfigView.section.interface.alerts");
alerts_item.setMenu(alert_menu);
boolean[] all_enabled = new boolean[alert_keys.length];
DownloadManagerState state = dm.getDownloadState();
Map map = state.getMapAttribute(DownloadManagerState.AT_DL_FILE_ALERTS);
if (map != null) {
Arrays.fill(all_enabled, true);
for (DiskManagerFileInfo file : files) {
for (int i = 0; i < alert_keys.length; i++) {
String key = String.valueOf(file.getIndex()) + "." + alert_keys[i][0];
if (!map.containsKey(key)) {
all_enabled[i] = false;
}
}
}
}
for (int i = 0; i < alert_keys.length; i++) {
final String[] entry = alert_keys[i];
if (i != 1 || Constants.isOSX) {
final MenuItem item = new MenuItem(alert_menu, SWT.CHECK);
item.setText(MessageText.getString("ConfigView.label." + entry[1]));
item.setSelection(all_enabled[i]);
item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
DownloadManagerState state = dm.getDownloadState();
Map map = state.getMapAttribute(DownloadManagerState.AT_DL_FILE_ALERTS);
if (map == null) {
map = new HashMap();
} else {
map = new HashMap(map);
}
boolean selected = item.getSelection();
for (DiskManagerFileInfo file : files) {
String key = String.valueOf(file.getIndex()) + "." + entry[0];
if (selected) {
map.put(key, "");
} else {
map.remove(key);
}
}
state.setMapAttribute(DownloadManagerState.AT_DL_FILE_ALERTS, map);
}
});
}
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class TorrentOpener method addTorrent.
/**
* @param torrentOptions
* @return
* @since 5.0.0.1
*
* @TODO: Remove SWT UI parts (use UIFunctions) and move out of SWT tree
*/
public static final boolean addTorrent(final TorrentOpenOptions torrentOptions) {
try {
if (torrentOptions.getTorrent() == null) {
return false;
}
final DownloadManagerInitialisationAdapter dmia = new DownloadManagerInitialisationAdapter() {
@Override
public int getActions() {
return (ACT_ASSIGNS_TAGS);
}
@Override
public void initialised(DownloadManager dm, boolean for_seeding) {
DiskManagerFileInfoSet file_info_set = dm.getDiskManagerFileInfoSet();
DiskManagerFileInfo[] fileInfos = file_info_set.getFiles();
boolean reorder_mode = COConfigurationManager.getBooleanParameter("Enable reorder storage mode");
int reorder_mode_min_mb = COConfigurationManager.getIntParameter("Reorder storage mode min MB");
try {
dm.getDownloadState().suppressStateSave(true);
boolean[] toSkip = new boolean[fileInfos.length];
boolean[] toCompact = new boolean[fileInfos.length];
boolean[] toReorderCompact = new boolean[fileInfos.length];
int[] priorities = null;
int comp_num = 0;
int reorder_comp_num = 0;
final TorrentOpenFileOptions[] files = torrentOptions.getFiles();
for (int iIndex = 0; iIndex < fileInfos.length; iIndex++) {
DiskManagerFileInfo fileInfo = fileInfos[iIndex];
if (iIndex >= 0 && iIndex < files.length && files[iIndex].lSize == fileInfo.getLength()) {
// Always pull destination file from fileInfo and not from
// TorrentFileInfo because the destination may have changed
// by magic code elsewhere
File fDest = fileInfo.getFile(true);
if (files[iIndex].isLinked()) {
fDest = files[iIndex].getDestFileFullName();
// Can't use fileInfo.setLink(fDest) as it renames
// the existing file if there is one
dm.getDownloadState().setFileLink(iIndex, fileInfo.getFile(false), fDest);
}
if (files[iIndex].isToDownload()) {
int priority = files[iIndex].getPriority();
if (priority != 0) {
if (priorities == null) {
priorities = new int[fileInfos.length];
}
priorities[iIndex] = priority;
}
} else {
toSkip[iIndex] = true;
if (!fDest.exists()) {
if (reorder_mode && (fileInfo.getLength() / (1024 * 1024)) >= reorder_mode_min_mb) {
toReorderCompact[iIndex] = true;
reorder_comp_num++;
} else {
toCompact[iIndex] = true;
comp_num++;
}
}
}
}
}
if (files.length == 1) {
TorrentOpenFileOptions file = files[0];
if (file.isManualRename()) {
String fileRename = file.getDestFileName();
if (fileRename != null && fileRename.length() > 0) {
dm.getDownloadState().setDisplayName(fileRename);
}
}
} else {
String folderRename = torrentOptions.getManualRename();
if (folderRename != null && folderRename.length() > 0) {
dm.getDownloadState().setDisplayName(folderRename);
}
}
if (comp_num > 0) {
file_info_set.setStorageTypes(toCompact, DiskManagerFileInfo.ST_COMPACT);
}
if (reorder_comp_num > 0) {
file_info_set.setStorageTypes(toReorderCompact, DiskManagerFileInfo.ST_REORDER_COMPACT);
}
file_info_set.setSkipped(toSkip, true);
if (priorities != null) {
file_info_set.setPriority(priorities);
}
int maxUp = torrentOptions.getMaxUploadSpeed();
int kInB = DisplayFormatters.getKinB();
if (maxUp > 0) {
dm.getStats().setUploadRateLimitBytesPerSecond(maxUp * kInB);
}
int maxDown = torrentOptions.getMaxDownloadSpeed();
if (maxDown > 0) {
dm.getStats().setDownloadRateLimitBytesPerSecond(maxDown * kInB);
}
DownloadManagerState dm_state = dm.getDownloadState();
if (torrentOptions.disableIPFilter) {
dm_state.setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, true);
}
if (torrentOptions.peerSource != null) {
for (String peerSource : torrentOptions.peerSource.keySet()) {
boolean enable = torrentOptions.peerSource.get(peerSource);
dm_state.setPeerSourceEnabled(peerSource, enable);
}
}
Map<String, Boolean> enabledNetworks = torrentOptions.getEnabledNetworks();
if (enabledNetworks != null) {
if (!dm_state.getFlag(DownloadManagerState.FLAG_INITIAL_NETWORKS_SET)) {
for (String net : enabledNetworks.keySet()) {
boolean enable = enabledNetworks.get(net);
dm_state.setNetworkEnabled(net, enable);
}
}
}
List<Tag> initialTags = torrentOptions.getInitialTags();
for (Tag t : initialTags) {
t.addTaggable(dm);
}
List<List<String>> trackers = torrentOptions.getTrackers(true);
if (trackers != null) {
TOTorrent torrent = dm.getTorrent();
TorrentUtils.listToAnnounceGroups(trackers, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e2) {
Debug.printStackTrace(e2);
}
}
if (torrentOptions.bSequentialDownload) {
dm_state.setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, true);
}
File moc = torrentOptions.getMoveOnComplete();
if (moc != null) {
dm_state.setAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR, moc.getAbsolutePath());
}
} finally {
dm.getDownloadState().suppressStateSave(false);
}
}
};
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
TOTorrent torrent = torrentOptions.getTorrent();
byte[] hash = null;
try {
hash = torrent.getHash();
} catch (TOTorrentException e1) {
}
int iStartState = (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_STOPPED) ? DownloadManager.STATE_STOPPED : DownloadManager.STATE_QUEUED;
GlobalManager gm = core.getGlobalManager();
DownloadManager dm = gm.addDownloadManager(torrentOptions.sFileName, hash, torrentOptions.getParentDir(), torrentOptions.getSubDir(), iStartState, true, torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_SEEDING, dmia);
// since gm.addDown.. will handle it.
if (dm == null) {
return;
}
if (torrentOptions.iQueueLocation == TorrentOpenOptions.QUEUELOCATION_TOP) {
gm.moveTop(new DownloadManager[] { dm });
}
if (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_FORCESTARTED) {
dm.setForceStart(true);
}
}
});
} catch (Exception e) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { torrentOptions.sOriginatingLocation, e.getMessage() });
}
return false;
}
return true;
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class FilesView method initYourTableView.
@Override
public TableViewSWT<DiskManagerFileInfo> initYourTableView() {
tv = TableViewFactory.createTableViewSWT(com.biglybt.pif.disk.DiskManagerFileInfo.class, TableManager.TABLE_TORRENT_FILES, getPropertiesPrefix(), basicItems, "firstpiece", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
if (allowTabViews) {
tv.setEnableTabViews(enable_tabs, true, null);
}
basicItems = new TableColumnCore[0];
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
tv.addTableDataSourceChangedListener(this, true);
tv.addRefreshListener(this, true);
tv.addSelectionListener(this, false);
tv.addMenuFillListener(this);
tv.addLifeCycleListener(this);
tv.addKeyListener(this);
tv.addRefreshListener(new TableRowRefreshListener() {
@Override
public void rowRefresh(TableRow row) {
if (row instanceof TableRowSWT) {
Object ds = ((TableRowSWT) row).getDataSource(true);
if (ds instanceof FilesViewNodeInner) {
((TableRowSWT) row).setFontStyle(SWT.ITALIC);
((TableRowSWT) row).setAlpha(220);
}
}
}
});
return tv;
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method revertFiles.
public static void revertFiles(final TableView<?> tv, List<DiskManagerFileInfo> files) {
final List<DownloadManager> paused = new ArrayList<>();
final AESemaphore task_sem = new AESemaphore("tasksem");
final List<DiskManagerFileInfo> affected_files = new ArrayList<>();
try {
for (int i = 0; i < files.size(); i++) {
final DiskManagerFileInfo file_info = files.get(i);
if (file_info == null) {
continue;
}
final File file_nolink = file_info.getFile(false);
final DownloadManager manager = file_info.getDownloadManager();
File target = file_info.getDownloadManager().getDownloadState().getFileLink(file_info.getIndex(), file_nolink);
if (target != null) {
if (target != file_nolink) {
if (!target.equals(file_nolink)) {
if (!paused.contains(manager)) {
if (manager.pause()) {
paused.add(manager);
}
}
affected_files.add(file_info);
moveFile(manager, file_info, file_nolink, true, new Runnable() {
@Override
public void run() {
task_sem.release();
}
});
}
}
}
}
} finally {
if (affected_files.size() > 0) {
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
for (int i = 0; i < affected_files.size(); i++) {
task_sem.reserve();
}
for (DownloadManager manager : paused) {
manager.resume();
}
invalidateRows(tv, affected_files);
}
});
}
}
}
Aggregations