Search in sources :

Example 21 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class MenuFactory method handleTorrentFixup.

private static void handleTorrentFixup() {
    // had some OSX SWT crash issues in this code so moved everything async
    final Shell shell = Utils.findAnyShell();
    try {
        FileDialog dialog = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.OPEN);
        dialog.setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD });
        dialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD });
        dialog.setFilterPath(TorrentOpener.getFilterPathTorrent());
        dialog.setText(MessageText.getString("torrent.fix.corrupt.browse"));
        String str = dialog.open();
        if (str != null) {
            TorrentOpener.setFilterPathTorrent(str);
            File file = new File(str);
            byte[] bytes = FileUtil.readFileAsByteArray(file);
            Map existing_map = BDecoder.decode(bytes);
            Map existing_info = (Map) existing_map.get("info");
            byte[] existing_info_encoded = BEncoder.encode(existing_info);
            final TOTorrent t = TOTorrentFactory.deserialiseFromMap(existing_map);
            final byte[] old_hash = t.getHash();
            byte[] new_hash = null;
            for (int i = 0; i < bytes.length - 5; i++) {
                if (bytes[i] == ':' && bytes[i + 1] == 'i' && bytes[i + 2] == 'n' && bytes[i + 3] == 'f' && bytes[i + 4] == 'o') {
                    new_hash = new SHA1Simple().calculateHash(bytes, i + 5, existing_info_encoded.length);
                    break;
                }
            }
            if (new_hash != null) {
                final byte[] f_new_hash = new_hash;
                Utils.execSWTThreadLater(1, new Runnable() {

                    @Override
                    public void run() {
                        String title = MessageText.getString("torrent.fix.corrupt.result.title");
                        if (Arrays.equals(old_hash, f_new_hash)) {
                            MessageBoxShell mb = new MessageBoxShell(SWT.OK, title, MessageText.getString("torrent.fix.corrupt.result.nothing"));
                            mb.setParent(shell);
                            mb.open(null);
                        } else {
                            MessageBoxShell mb = new MessageBoxShell(SWT.OK, title, MessageText.getString("torrent.fix.corrupt.result.fixed", new String[] { ByteFormatter.encodeString(f_new_hash) }));
                            mb.setParent(shell);
                            mb.open(null);
                            mb.waitUntilClosed();
                            try {
                                t.setHashOverride(f_new_hash);
                                Utils.execSWTThreadLater(1, new Runnable() {

                                    @Override
                                    public void run() {
                                        FileDialog dialog2 = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.SAVE);
                                        dialog2.setFilterPath(TorrentOpener.getFilterPathTorrent());
                                        dialog2.setFilterExtensions(new String[] { "*.torrent" });
                                        String str2 = dialog2.open();
                                        if (str2 != null) {
                                            if (!(str2.toLowerCase(Locale.US).endsWith(".tor") || str2.toLowerCase(Locale.US).endsWith(".torrent"))) {
                                                str2 += ".torrent";
                                            }
                                            try {
                                                t.serialiseToBEncodedFile(new File(str2));
                                            } catch (Throwable e) {
                                                Debug.out(e);
                                            }
                                        }
                                    }
                                });
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    }
                });
            }
        }
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class UISWTInstanceImpl method promptUser.

// @see com.biglybt.pif.ui.UIInstance#promptUser(java.lang.String, java.lang.String, java.lang.String[], int)
@Override
public int promptUser(String title, String text, String[] options, int defaultOption) {
    MessageBoxShell mb = new MessageBoxShell(title, text, options, defaultOption);
    mb.open(null);
    // bah, no way to change this to use the UserPrompterResultListener trigger
    return mb.waitUntilClosed();
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 23 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class FilesViewMenuUtil method checkRetargetOK.

private static boolean checkRetargetOK(DiskManagerFileInfo info, File target) {
    if (!target.exists()) {
        return (true);
    }
    if (info.getTorrentFile().getLength() == target.length()) {
        return (true);
    }
    MessageBoxShell mb = new MessageBoxShell(SWT.OK | SWT.CANCEL, MessageText.getString("FilesView.retarget.confirm.title"), MessageText.getString("FilesView.retarget.confirm.text"));
    mb.setDefaultButtonUsingStyle(SWT.OK);
    mb.setLeftImage(SWT.ICON_WARNING);
    mb.open(null);
    return mb.waitUntilClosed() == SWT.OK;
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 24 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class FilesViewMenuUtil method changePriorityManual.

private static void changePriorityManual(final List<DiskManagerFileInfo> file_list) {
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("FilesView.dialog.priority.title", "FilesView.dialog.priority.text");
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String sReturn = entryWindow.getSubmittedInput();
            if (sReturn == null)
                return;
            int priority = 0;
            try {
                priority = Integer.valueOf(sReturn).intValue();
            } catch (NumberFormatException er) {
                Debug.out("Invalid priority: " + sReturn);
                new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilePriority.invalid.title"), MessageText.getString("FilePriority.invalid.text", new String[] { sReturn })).open(null);
                return;
            }
            Map<DownloadManager, ArrayList<DiskManagerFileInfo>> mapDMtoDMFI = new IdentityHashMap<>();
            for (DiskManagerFileInfo file : file_list) {
                DownloadManager dm = file.getDownloadManager();
                ArrayList<DiskManagerFileInfo> listFileInfos = mapDMtoDMFI.get(dm);
                if (listFileInfos == null) {
                    listFileInfos = new ArrayList<>(1);
                    mapDMtoDMFI.put(dm, listFileInfos);
                }
                listFileInfos.add(file);
                file.setPriority(priority);
            }
            for (DownloadManager dm : mapDMtoDMFI.keySet()) {
                ArrayList<DiskManagerFileInfo> list = mapDMtoDMFI.get(dm);
                DiskManagerFileInfo[] fileInfos = list.toArray(new DiskManagerFileInfo[0]);
                boolean paused = setSkipped(dm, fileInfos, false, false);
                if (paused) {
                    dm.resume();
                }
            }
        }
    });
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 25 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class FilesViewMenuUtil method askCanOverwrite.

private static boolean askCanOverwrite(File file) {
    MessageBoxShell mb = new MessageBoxShell(SWT.OK | SWT.CANCEL, MessageText.getString("FilesView.rename.confirm.delete.title"), MessageText.getString("FilesView.rename.confirm.delete.text", new String[] { file.toString() }));
    mb.setDefaultButtonUsingStyle(SWT.OK);
    mb.setRememberOnlyIfButton(0);
    mb.setRemember("FilesView.messagebox.rename.id", true, null);
    mb.setLeftImage(SWT.ICON_WARNING);
    mb.open(null);
    return mb.waitUntilClosed() == SWT.OK;
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Aggregations

MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)53 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)24 File (java.io.File)10 ArrayList (java.util.ArrayList)7 GridData (org.eclipse.swt.layout.GridData)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Map (java.util.Map)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)4 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)4 AERunnable (com.biglybt.core.util.AERunnable)4 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)4 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)4 URL (java.net.URL)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Point (org.eclipse.swt.graphics.Point)4