Search in sources :

Example 11 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class NetworkAdminImpl method pingTarget.

public NetworkAdminNode pingTarget(InetAddress interface_address, InetAddress target, final int max_millis, final NetworkAdminRouteListener listener) throws NetworkAdminException {
    PlatformManager pm = PlatformManagerFactory.getPlatformManager();
    if (!canPing()) {
        throw (new NetworkAdminException("No ping capability on platform"));
    }
    final NetworkAdminNode[] nodes = { null };
    try {
        pm.ping(interface_address, target, new PlatformManagerPingCallback() {

            private long start_time = SystemTime.getCurrentTime();

            @Override
            public boolean reportNode(int distance, InetAddress address, int millis) {
                boolean timeout = false;
                if (max_millis >= 0) {
                    long now = SystemTime.getCurrentTime();
                    if (now < start_time) {
                        start_time = now;
                    }
                    if (now - start_time >= max_millis) {
                        timeout = true;
                    }
                }
                NetworkAdminNode node = null;
                if (address != null) {
                    node = new networkNode(address, distance, millis);
                    nodes[0] = node;
                }
                boolean result;
                if (listener == null) {
                    result = false;
                } else {
                    if (node == null) {
                        result = listener.timeout(distance);
                    } else {
                        result = listener.foundNode(node, distance, millis);
                    }
                }
                return (result && !timeout);
            }
        });
    } catch (PlatformManagerException e) {
        throw (new NetworkAdminException("ping failed", e));
    }
    return (nodes[0]);
}
Also used : PlatformManagerPingCallback(com.biglybt.platform.PlatformManagerPingCallback) PlatformManager(com.biglybt.platform.PlatformManager) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 12 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method deleteDataFiles.

/**
 * Deletes all data files associated with torrent.
 * Currently, deletes all files, then tries to delete the path recursively
 * if the paths are empty.  An unexpected result may be that a empty
 * directory that the user created will be removed.
 *
 * TODO: only remove empty directories that are created for the torrent
 */
public static void deleteDataFiles(TOTorrent torrent, // enclosing dir, not for deletion
String torrent_save_dir, // file or dir for torrent
String torrent_save_file, boolean force_no_recycle) {
    if (torrent == null || torrent_save_file == null) {
        return;
    }
    try {
        if (torrent.isSimpleTorrent()) {
            File target = new File(torrent_save_dir, torrent_save_file);
            target = FMFileManagerFactory.getSingleton().getFileLink(torrent, 0, target.getCanonicalFile());
            FileUtil.deleteWithRecycle(target, force_no_recycle);
        } else {
            PlatformManager mgr = PlatformManagerFactory.getPlatformManager();
            if (Constants.isOSX && torrent_save_file.length() > 0 && COConfigurationManager.getBooleanParameter("Move Deleted Data To Recycle Bin") && (!force_no_recycle) && mgr.hasCapability(PlatformManagerCapabilities.RecoverableFileDelete)) {
                try {
                    String dir = torrent_save_dir + File.separatorChar + torrent_save_file + File.separatorChar;
                    // only delete the dir if there's only this torrent's files in it!
                    int numDataFiles = countDataFiles(torrent, torrent_save_dir, torrent_save_file);
                    if (countFiles(new File(dir), numDataFiles) == numDataFiles) {
                        mgr.performRecoverableFileDelete(dir);
                    } else {
                        deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
                    }
                } catch (PlatformManagerException ex) {
                    deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
                }
            } else {
                deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CacheFile(com.biglybt.core.diskmanager.cache.CacheFile) File(java.io.File)

Example 13 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class ClientRestarterImpl method restartViaEXE.

private boolean restartViaEXE(PrintWriter log, String exeUpdater, String[] properties, String[] parameters, String backupJavaRunString, boolean update_only) {
    String azRunner = null;
    File fileRestart = null;
    if (!update_only) {
        try {
            azRunner = PlatformManagerFactory.getPlatformManager().getApplicationCommandLine();
        } catch (PlatformManagerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        int result;
        AEWin32Access accessor = AEWin32Manager.getAccessor(true);
        if (accessor == null) {
            result = -123;
        } else {
            if (azRunner != null) {
                // create a batch file to run the updater, then to restart client
                // because the updater would restart client as administrator user
                // and confuse the user
                fileRestart = FileUtil.getUserFile("restart.bat");
                String s = "title BiglyBT Updater Runner\r\n";
                s += exeUpdater + " \"updateonly\"";
                for (int i = 1; i < parameters.length; i++) {
                    s += " \"" + parameters[i].replaceAll("\\\"", "") + "\"";
                }
                s += "\r\n";
                s += "start \"\" \"" + azRunner + "\"";
                byte[] bytes;
                String encoding = FileUtil.getScriptCharsetEncoding();
                if (encoding == null) {
                    bytes = s.getBytes();
                } else {
                    try {
                        bytes = s.getBytes(encoding);
                    } catch (Throwable e) {
                        e.printStackTrace();
                        bytes = s.getBytes();
                    }
                }
                FileUtil.writeBytesAsFile(fileRestart.getAbsolutePath(), bytes);
                result = accessor.shellExecute(null, fileRestart.getAbsolutePath(), null, SystemProperties.getApplicationPath(), AEWin32Access.SW_SHOWMINIMIZED);
            } else {
                String execEXE = "\"-J" + getClassPath().replaceAll("\\\"", "") + "\" ";
                for (int i = 0; i < properties.length; i++) {
                    execEXE += "\"-J" + properties[i].replaceAll("\\\"", "") + "\" ";
                }
                for (int i = 0; i < parameters.length; i++) {
                    execEXE += " \"" + parameters[i].replaceAll("\\\"", "") + "\"";
                }
                log.println("Launch via " + exeUpdater + " params " + execEXE);
                result = accessor.shellExecute(null, exeUpdater, execEXE, SystemProperties.getApplicationPath(), AEWin32Access.SW_NORMAL);
            }
        }
        /*
			 * Some results:
			 * 0: OOM
			 * 2: FNF
			 * 3: Path Not Foud
			 * 5: Access Denied (User clicked cancel on admin access dialog)
			 * 8: OOM
			 * 11: Bad Format
			 * 26: Sharing Violation
			 * 27: Association incomplete
			 * 28: DDE Timeout
			 * 29: DDE Fail
			 * 30: DDE Busy
			 * 31: No Association
			 * 32: DLL Not found
			 * >32: OK!
			 */
        log.println("   -> " + result);
        if (result <= 32) {
            String sErrorReason = "";
            String key = null;
            switch(result) {
                case 0:
                case 8:
                    key = "oom";
                    break;
                case 2:
                    key = "fnf";
                    break;
                case 3:
                    key = "pnf";
                    break;
                case 5:
                    key = "denied";
                    break;
                case 11:
                    key = "bad";
                    break;
                case -123:
                    key = "nowin32";
                    break;
                default:
                    sErrorReason = "" + result;
                    break;
            }
            if (key != null) {
                sErrorReason = MessageText.getString("restart.error." + key, new String[] { exeUpdater, SystemProperties.getApplicationPath() });
            }
            Logger.log(new LogAlert(false, LogAlert.AT_ERROR, MessageText.getString("restart.error", new String[] { sErrorReason })));
            return false;
        }
    } catch (Throwable f) {
        f.printStackTrace(log);
        return javaSpawn(log, backupJavaRunString);
    }
    return true;
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) File(java.io.File) AEWin32Access(com.biglybt.platform.win32.access.AEWin32Access) LogAlert(com.biglybt.core.logging.LogAlert)

Example 14 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class PlatformManagerImpl method setExplicitVMOptions.

@Override
public void setExplicitVMOptions(String[] options) throws PlatformManagerException {
    checkCapability(PlatformManagerCapabilities.AccessExplicitVMOptions);
    File local_options = getVMOptionFile();
    try {
        if (local_options.exists()) {
            File backup = new File(local_options.getParentFile(), local_options.getName() + ".bak");
            if (backup.exists()) {
                backup.delete();
            }
            if (!local_options.renameTo(backup)) {
                throw (new Exception("Failed to move " + local_options + " to " + backup));
            }
            boolean ok = false;
            try {
                PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(local_options), "UTF-8"));
                try {
                    for (String option : options) {
                        pw.println(option);
                    }
                    ok = true;
                } finally {
                    pw.close();
                }
            } finally {
                if (!ok) {
                    local_options.delete();
                    backup.renameTo(local_options);
                }
            }
        }
    } catch (Throwable e) {
        throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.accesserror", new String[] { Debug.getNestedExceptionMessage(e) })));
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 15 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class PlatformManagerImpl method getApplicationEXELocation.

protected File getApplicationEXELocation() throws PlatformManagerException {
    if (az_exe == null) {
        try {
            String az_home;
            // Try the app dir first, because we may not be using the one in the registry
            az_home = SystemProperties.getApplicationPath();
            az_exe = new File(az_home + File.separator + app_exe_name).getAbsoluteFile();
            if (!az_exe.exists()) {
                try {
                    az_home = access.getApplicationInstallDir(app_name);
                    az_exe = new File(az_home + File.separator + app_exe_name).getAbsoluteFile();
                    if (!az_exe.exists()) {
                        throw (new PlatformManagerException(app_exe_name + " not found in " + az_home + ", please re-install"));
                    }
                } catch (Throwable e) {
                }
            }
            if (!az_exe.exists()) {
                String msg = app_exe_name + " not found in " + az_home + " - can't check file associations. Please re-install " + app_name;
                az_exe = null;
                if (!az_exe_checked) {
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, msg));
                }
                throw (new PlatformManagerException(msg));
            }
        } finally {
            az_exe_checked = true;
        }
    }
    return (az_exe);
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) LogAlert(com.biglybt.core.logging.LogAlert)

Aggregations

PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)21 PlatformManager (com.biglybt.platform.PlatformManager)5 LogAlert (com.biglybt.core.logging.LogAlert)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 LogEvent (com.biglybt.core.logging.LogEvent)2 PlatformManagerPingCallback (com.biglybt.platform.PlatformManagerPingCallback)2 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 GridData (org.eclipse.swt.layout.GridData)2 CoreException (com.biglybt.core.CoreException)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 UtilitiesImpl.runnableWithException (com.biglybt.pifimpl.local.utils.UtilitiesImpl.runnableWithException)1 AEWin32Access (com.biglybt.platform.win32.access.AEWin32Access)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1