Search in sources :

Example 16 with LogAlert

use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.

the class UpdateInstallerImpl method checkForFailedInstalls.

protected static void checkForFailedInstalls(UpdateManagerImpl manager) {
    try {
        File update_dir = new File(manager.getUserDir() + File.separator + UPDATE_DIR);
        File[] dirs = update_dir.listFiles();
        if (dirs != null) {
            boolean found_failure = false;
            String files = "";
            for (int i = 0; i < dirs.length; i++) {
                File dir = dirs[i];
                if (dir.isDirectory()) {
                    // if somethings here then the install failed
                    found_failure = true;
                    File[] x = dir.listFiles();
                    if (x != null) {
                        for (int j = 0; j < x.length; j++) {
                            files += (files.length() == 0 ? "" : ",") + x[j].getName();
                        }
                    }
                    FileUtil.recursiveDelete(dir);
                }
            }
            if (found_failure) {
                Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, MessageText.getString("Alert.failed.update", new String[] { files })));
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : LogAlert(com.biglybt.core.logging.LogAlert)

Example 17 with LogAlert

use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.

the class UpdateInstallerImpl method addMoveAction.

@Override
public void addMoveAction(String from_file_or_resource, String to_file) throws UpdateException {
    if (!from_file_or_resource.contains(File.separator)) {
        from_file_or_resource = install_dir.toString() + File.separator + from_file_or_resource;
    }
    try {
        // see if this action has a chance of succeeding
        File to_f = new File(to_file);
        File parent = to_f.getParentFile();
        if (parent != null && !parent.exists()) {
            parent.mkdirs();
        }
        boolean log_perm_set_fail = true;
        if (parent != null) {
            if (!parent.canWrite()) {
                log_perm_set_fail = false;
                if (!Constants.isWindowsVistaOrHigher) {
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, "The location '" + parent.toString() + "' isn't writable, this update will probably fail." + " Check permissions and retry the update"));
                }
            }
            try {
                PlatformManager pm = PlatformManagerFactory.getPlatformManager();
                if (pm.hasCapability(PlatformManagerCapabilities.CopyFilePermissions)) {
                    String parent_str = parent.getAbsolutePath();
                    PlatformManagerFactory.getPlatformManager().copyFilePermissions(parent_str, from_file_or_resource);
                }
            } catch (Throwable e) {
                if (log_perm_set_fail) {
                    if (!Constants.isWindowsVistaOrHigher) {
                        Debug.out(e);
                    }
                }
            }
        }
    } catch (Throwable e) {
    }
    from_file_or_resource = escapeFile(from_file_or_resource);
    to_file = escapeFile(to_file);
    appendAction("move," + from_file_or_resource + "," + to_file);
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) LogAlert(com.biglybt.core.logging.LogAlert)

Example 18 with LogAlert

use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.

the class CorePatchChecker method patch.

protected void patch(UpdateCheckInstance instance, Update updater_update, PluginInterface updater_plugin) {
    try {
        // use the update plugin to log stuff....
        ResourceDownloader rd_log = updater_update.getDownloaders()[0];
        File[] files = new File(updater_plugin.getPluginDirectoryName()).listFiles();
        if (files == null) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: no files in plugin dir!!!"));
            return;
        }
        String patch_prefix = "BiglyBT_" + Constants.getBaseVersion() + "_P";
        int highest_p = -1;
        File highest_p_file = null;
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (name.startsWith(patch_prefix) && name.endsWith(".pat")) {
                if (Logger.isEnabled())
                    Logger.log(new LogEvent(LOGID, "Core Patcher: found patch file '" + name + "'"));
                try {
                    int this_p = Integer.parseInt(name.substring(patch_prefix.length(), name.indexOf(".pat")));
                    if (this_p > highest_p) {
                        highest_p = this_p;
                        highest_p_file = files[i];
                    }
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
            }
        }
        if (CorePatchLevel.getCurrentPatchLevel() >= highest_p) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: no applicable patch found (highest = " + highest_p + ")"));
            if (updater_update.getRestartRequired() == Update.RESTART_REQUIRED_MAYBE) {
                updater_update.setRestartRequired(Update.RESTART_REQUIRED_NO);
            }
        } else {
            rd_log.reportActivity("Applying patch '" + highest_p_file.getName() + "'");
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: applying patch '" + highest_p_file.toString() + "'"));
            InputStream pis = new FileInputStream(highest_p_file);
            try {
                patchBiglyBT(instance, pis, "P" + highest_p, plugin_interface.getLogger().getChannel("CorePatcher"));
                Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_INFORMATION, "Patch " + highest_p_file.getName() + " ready to be applied"));
                String done_file = highest_p_file.toString();
                done_file = done_file.substring(0, done_file.length() - 1) + "x";
                highest_p_file.renameTo(new File(done_file));
                // flip the original update over to 'restart required'
                updater_update.setRestartRequired(Update.RESTART_REQUIRED_YES);
            } finally {
                try {
                    pis.close();
                } catch (Throwable e) {
                }
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Core Patcher failed", e));
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) LogAlert(com.biglybt.core.logging.LogAlert)

Example 19 with LogAlert

use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.

the class CoreUpdateChecker method displayUserMessage.

/**
 * Log and display a user message if contained within reply.
 * @param reply from server
 */
private void displayUserMessage(Map reply) {
    try {
        Iterator it = reply.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            if (key.startsWith("message_sig") || !key.startsWith("message")) {
                continue;
            }
            byte[] message_bytes = (byte[]) reply.get(key);
            if (message_bytes != null && message_bytes.length > 0) {
                String message;
                try {
                    message = new String(message_bytes, "UTF-8");
                } catch (Throwable e) {
                    message = new String(message_bytes);
                }
                String sig_key;
                int pos = key.indexOf('_');
                if (pos == -1) {
                    sig_key = "message_sig";
                } else {
                    sig_key = "message_sig" + key.substring(pos);
                }
                String last_message_key = "CoreUpdateChecker.last" + key;
                String last = COConfigurationManager.getStringParameter(last_message_key, "");
                if (!message.equals(last)) {
                    boolean repeatable = false;
                    byte[] signature = (byte[]) reply.get(sig_key);
                    if (signature == null) {
                        Logger.log(new LogEvent(LogIDs.LOGGER, "Signature missing from message"));
                        return;
                    }
                    try {
                        AEVerifier.verifyData(message, signature);
                    } catch (Throwable e) {
                        Logger.log(new LogEvent(LogIDs.LOGGER, "Message signature check failed", e));
                        return;
                    }
                    boolean completed = false;
                    if (message.startsWith("x:") || message.startsWith("y:")) {
                        // emergency patch application
                        repeatable = message.startsWith("y:");
                        try {
                            URL jar_url = new URL(message.substring(2));
                            if (!repeatable) {
                                Logger.log(new LogEvent(LogIDs.LOGGER, "Patch application requsted: url=" + jar_url));
                            }
                            File temp_dir = AETemporaryFileHandler.createTempDir();
                            File jar_file = new File(temp_dir, "patch.jar");
                            InputStream is = rdf.create(jar_url).download();
                            try {
                                FileUtil.copyFile(is, jar_file);
                                is = null;
                                AEVerifier.verifyData(jar_file);
                                ClassLoader cl = CoreUpdateChecker.class.getClassLoader();
                                if (cl instanceof URLClassLoader) {
                                    URL[] old = ((URLClassLoader) cl).getURLs();
                                    URL[] new_urls = new URL[old.length + 1];
                                    System.arraycopy(old, 0, new_urls, 1, old.length);
                                    new_urls[0] = jar_file.toURL();
                                    cl = new URLClassLoader(new_urls, cl);
                                } else {
                                    cl = new URLClassLoader(new URL[] { jar_file.toURL() }, cl);
                                }
                                Class cla = cl.loadClass("com.biglybt.update.version.Patch");
                                cla.newInstance();
                                completed = true;
                            } finally {
                                if (is != null) {
                                    is.close();
                                }
                                jar_file.delete();
                                temp_dir.delete();
                            }
                        } catch (Throwable e) {
                            if (!repeatable) {
                                Logger.log(new LogEvent(LogIDs.LOGGER, "Patch application failed", e));
                            }
                        }
                    } else if (message.startsWith("u:") && message.length() > 4) {
                        try {
                            String type = message.substring(2, 3);
                            String url = message.substring(4);
                            UIFunctions uif = UIFunctionsManager.getUIFunctions();
                            if (uif != null) {
                                uif.viewURL(url, null, 0.9, 0.9, true, type.equals("1"));
                            }
                        } catch (Throwable t) {
                            Logger.log(new LogEvent(LogIDs.LOGGER, "URL message failed", t));
                        }
                        // mark as complete even if errored
                        completed = true;
                    } else {
                        int alert_type = LogAlert.AT_WARNING;
                        String alert_text = message;
                        boolean force = false;
                        if (alert_text.startsWith("f:")) {
                            force = true;
                            alert_text = alert_text.substring(2);
                        }
                        if (alert_text.startsWith("i:")) {
                            alert_type = LogAlert.AT_INFORMATION;
                            alert_text = alert_text.substring(2);
                        }
                        plugin_interface.getPluginProperties().setProperty(MESSAGE_PROPERTY, alert_text);
                        if (force) {
                            UIFunctions uif = UIFunctionsManager.getUIFunctions();
                            if (uif != null) {
                                try {
                                    uif.forceNotify(UIFunctions.STATUSICON_NONE, null, alert_text, null, null, 0);
                                    completed = true;
                                } catch (Throwable e) {
                                }
                            }
                        }
                        if (!completed) {
                            Logger.log(new LogAlert(LogAlert.UNREPEATABLE, alert_type, alert_text, 0));
                        }
                        completed = true;
                    }
                    if (completed) {
                        if (!repeatable) {
                            COConfigurationManager.setParameter(last_message_key, message);
                            COConfigurationManager.save();
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ZipInputStream(java.util.zip.ZipInputStream) URL(java.net.URL) LogAlert(com.biglybt.core.logging.LogAlert) UIFunctions(com.biglybt.ui.UIFunctions) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader)

Example 20 with LogAlert

use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method getAuthentication.

public PasswordAuthentication getAuthentication(String realm, String protocol, String host, int port) {
    try {
        URL tracker_url = new URL(protocol + "://" + host + ":" + port + "/");
        if (protocol.toLowerCase().startsWith("socks")) {
            // give explicit thread-based listeners a chance to override the hack
            SEPasswordListener thread_listener = (SEPasswordListener) tls.get();
            if (thread_listener != null) {
                PasswordAuthentication temp = thread_listener.getAuthentication(realm, tracker_url);
                if (temp != null) {
                    return (temp);
                }
            }
            String socks_user = COConfigurationManager.getStringParameter("Proxy.Username").trim();
            String socks_pw = COConfigurationManager.getStringParameter("Proxy.Password").trim();
            if (socks_user.equalsIgnoreCase("<none>")) {
                return (new PasswordAuthentication("", "".toCharArray()));
            }
            if (socks_user.length() == 0) {
                Logger.log(new LogAlert(false, LogAlert.AT_WARNING, "Socks server is requesting authentication, please setup user and password in config"));
            }
            return (new PasswordAuthentication(socks_user, socks_pw.toCharArray()));
        }
        return (getPasswordAuthentication(realm, tracker_url));
    } catch (MalformedURLException e) {
        Debug.printStackTrace(e);
        return (null);
    }
}
Also used : SEPasswordListener(com.biglybt.core.security.SEPasswordListener) LogAlert(com.biglybt.core.logging.LogAlert)

Aggregations

LogAlert (com.biglybt.core.logging.LogAlert)72 File (java.io.File)21 LogEvent (com.biglybt.core.logging.LogEvent)20 URL (java.net.URL)7 Core (com.biglybt.core.Core)5 ParameterListener (com.biglybt.core.config.ParameterListener)5 DownloadManager (com.biglybt.core.download.DownloadManager)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 UIFunctions (com.biglybt.ui.UIFunctions)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)4 Method (java.lang.reflect.Method)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 URLClassLoader (java.net.URLClassLoader)3 CoreException (com.biglybt.core.CoreException)2 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)2 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)2