Search in sources :

Example 51 with LogAlert

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

the class TagDownloadWithState method checkMaximumTaggables.

@Override
protected void checkMaximumTaggables() {
    if (getTagType().getTagType() != TagType.TT_DOWNLOAD_MANUAL) {
        return;
    }
    int max = getMaximumTaggables();
    if (max <= 0) {
        return;
    }
    if (max == 999999) {
        max = 0;
    }
    int removal_strategy = getRemovalStrategy();
    if (removal_strategy == RS_NONE) {
        return;
    }
    if (getTaggedCount() > max) {
        Set<DownloadManager> dms = getTaggedDownloads();
        List<DownloadManager> sorted_dms = new ArrayList<>(dms);
        final int order = getOrdering();
        Collections.sort(sorted_dms, new Comparator<DownloadManager>() {

            @Override
            public int compare(DownloadManager dm1, DownloadManager dm2) {
                if (order == OP_ADDED_TO_VUZE) {
                    long t1 = dm1.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
                    long t2 = dm2.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
                    if (t1 < t2) {
                        return (-1);
                    } else if (t1 > t2) {
                        return (1);
                    } else {
                        return (dm1.getInternalName().compareTo(dm2.getInternalName()));
                    }
                } else {
                    long t1 = getTaggableAddedTime(dm1);
                    long t2 = getTaggableAddedTime(dm2);
                    if (t1 < t2) {
                        return (-1);
                    } else if (t1 > t2) {
                        return (1);
                    } else {
                        return (dm1.getInternalName().compareTo(dm2.getInternalName()));
                    }
                }
            }
        });
        Iterator<DownloadManager> it = sorted_dms.iterator();
        while (it.hasNext() && sorted_dms.size() > max) {
            DownloadManager dm = it.next();
            if (dm.isPersistent()) {
                it.remove();
                try {
                    if (removal_strategy == RS_ARCHIVE) {
                        Download download = PluginCoreUtils.wrap(dm);
                        if (download.canStubbify()) {
                            // have to remove from tag otherwise when it is restored it will no doubt get re-archived!
                            removeTaggable(dm);
                            download.stubbify();
                        }
                    } else if (removal_strategy == RS_REMOVE_FROM_LIBRARY) {
                        dm.getGlobalManager().removeDownloadManager(dm, false, false);
                    } else if (removal_strategy == RS_DELETE_FROM_COMPUTER) {
                        boolean reallyDeleteData = !dm.getDownloadState().getFlag(Download.FLAG_DO_NOT_DELETE_DATA_ON_REMOVE);
                        dm.getGlobalManager().removeDownloadManager(dm, true, reallyDeleteData);
                    } else if (removal_strategy == RS_MOVE_TO_OLD_TAG) {
                        String old_tag = getTagName(true) + "_";
                        if (Character.isUpperCase(old_tag.charAt(0))) {
                            old_tag += "Old";
                        } else {
                            old_tag += "old";
                        }
                        Tag ot = getTagType().getTag(old_tag, true);
                        if (ot == null) {
                            ot = getTagType().createTag(old_tag, true);
                        }
                        ot.addTaggable(dm);
                        removeTaggable(dm);
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            } else {
                // can't remove/archive non-persistent downloads here so just ignore them
                Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, "Non-persistent downloads (e.g. shares) can't be automatically deleted or archived. Maximum entries not enforced for Tag '" + getTagName(true) + "'"));
            }
        }
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) LogAlert(com.biglybt.core.logging.LogAlert) Download(com.biglybt.pif.download.Download)

Example 52 with LogAlert

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

the class TagManagerImpl method onCompletion.

@Override
public void onCompletion(Download d) {
    final DownloadManager manager = PluginCoreUtils.unwrap(d);
    List<Tag> tags = getTagsForTaggable(manager);
    List<Tag> cc_tags = new ArrayList<>();
    for (Tag tag : tags) {
        if (tag.getTagType().hasTagTypeFeature(TagFeature.TF_FILE_LOCATION)) {
            TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
            if (fl.supportsTagCopyOnComplete()) {
                File save_loc = fl.getTagCopyOnCompleteFolder();
                if (save_loc != null) {
                    cc_tags.add(tag);
                }
            }
        }
    }
    if (cc_tags.size() > 0) {
        if (cc_tags.size() > 1) {
            Collections.sort(cc_tags, new Comparator<Tag>() {

                @Override
                public int compare(Tag o1, Tag o2) {
                    return (o1.getTagID() - o2.getTagID());
                }
            });
        }
        TagFeatureFileLocation fl = (TagFeatureFileLocation) cc_tags.get(0);
        final File new_loc = fl.getTagCopyOnCompleteFolder();
        long options = fl.getTagCopyOnCompleteOptions();
        boolean copy_data = (options & TagFeatureFileLocation.FL_DATA) != 0;
        boolean copy_torrent = (options & TagFeatureFileLocation.FL_TORRENT) != 0;
        if (copy_data) {
            File old_loc = manager.getSaveLocation();
            if (!new_loc.equals(old_loc)) {
                boolean do_it;
                synchronized (active_copy_on_complete) {
                    if (active_copy_on_complete.contains(manager)) {
                        do_it = false;
                    } else {
                        active_copy_on_complete.add(manager);
                        do_it = true;
                    }
                }
                if (do_it) {
                    new AEThread2("tm:copy") {

                        @Override
                        public void run() {
                            try {
                                long stopped_and_incomplete_start = 0;
                                long looks_good_start = 0;
                                while (true) {
                                    if (manager.isDestroyed()) {
                                        throw (new Exception("Download has been removed"));
                                    }
                                    DiskManager dm = manager.getDiskManager();
                                    if (dm == null) {
                                        looks_good_start = 0;
                                        if (!manager.getAssumedComplete()) {
                                            long now = SystemTime.getMonotonousTime();
                                            if (stopped_and_incomplete_start == 0) {
                                                stopped_and_incomplete_start = now;
                                            } else if (now - stopped_and_incomplete_start > 30 * 1000) {
                                                throw (new Exception("Download is stopped and incomplete"));
                                            }
                                        } else {
                                            break;
                                        }
                                    } else {
                                        stopped_and_incomplete_start = 0;
                                        if (manager.getAssumedComplete()) {
                                            if (dm.getMoveProgress() == -1 && dm.getCompleteRecheckStatus() == -1) {
                                                long now = SystemTime.getMonotonousTime();
                                                if (looks_good_start == 0) {
                                                    looks_good_start = now;
                                                } else if (now - looks_good_start > 5 * 1000) {
                                                    break;
                                                }
                                            }
                                        } else {
                                            looks_good_start = 0;
                                        }
                                    }
                                    // System.out.println( "Waiting" );
                                    Thread.sleep(1000);
                                }
                                manager.copyDataFiles(new_loc);
                                Logger.logTextResource(new LogAlert(manager, LogAlert.REPEATABLE, LogAlert.AT_INFORMATION, "alert.copy.on.comp.done"), new String[] { manager.getDisplayName(), new_loc.toString() });
                            } catch (Throwable e) {
                                Logger.logTextResource(new LogAlert(manager, LogAlert.REPEATABLE, LogAlert.AT_ERROR, "alert.copy.on.comp.fail"), new String[] { manager.getDisplayName(), new_loc.toString(), Debug.getNestedExceptionMessage(e) });
                            } finally {
                                synchronized (active_copy_on_complete) {
                                    active_copy_on_complete.remove(manager);
                                }
                            }
                        }
                    }.start();
                }
            }
        }
        if (copy_torrent) {
            File old_file = new File(manager.getTorrentFileName());
            if (old_file.exists()) {
                File new_file = new File(new_loc, old_file.getName());
                FileUtil.copyFile(old_file, new_file);
            }
        }
    }
}
Also used : DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) IOException(java.io.IOException) LogAlert(com.biglybt.core.logging.LogAlert) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 53 with LogAlert

use of com.biglybt.core.logging.LogAlert 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 54 with LogAlert

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

the class AEDiagnostics method checkDumpsAndNatives.

public static void checkDumpsAndNatives() {
    try {
        PlatformManager p_man = PlatformManagerFactory.getPlatformManager();
        if (p_man.getPlatformType() == PlatformManager.PT_WINDOWS && p_man.hasCapability(PlatformManagerCapabilities.TestNativeAvailability)) {
            for (int i = 0; i < bad_dlls.length; i++) {
                String dll = bad_dlls[i][0];
                String load = bad_dlls[i][1];
                if (load.equalsIgnoreCase("n")) {
                    continue;
                }
                if (!COConfigurationManager.getBooleanParameter("platform.win32.dll_found." + dll, false)) {
                    try {
                        if (p_man.testNativeAvailability(dll + ".dll")) {
                            COConfigurationManager.setParameter("platform.win32.dll_found." + dll, true);
                            String detail = MessageText.getString("platform.win32.baddll." + dll);
                            Logger.logTextResource(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_WARNING, "platform.win32.baddll.info"), new String[] { dll + ".dll", detail });
                        }
                    } catch (Throwable e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
        List<File> fdirs_to_check = new ArrayList<>();
        fdirs_to_check.add(new File(SystemProperties.getApplicationPath()));
        try {
            File temp_file = File.createTempFile("AZU", "tmp");
            fdirs_to_check.add(temp_file.getParentFile());
            temp_file.delete();
        } catch (Throwable e) {
        }
        File most_recent_dump = null;
        long most_recent_time = 0;
        for (File dir : fdirs_to_check) {
            if (dir.canRead()) {
                File[] files = dir.listFiles(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String name) {
                        return (name.startsWith("hs_err_pid") && name.endsWith(".log"));
                    }
                });
                if (files != null) {
                    long now = SystemTime.getCurrentTime();
                    long one_week_ago = now - 7 * 24 * 60 * 60 * 1000;
                    for (int i = 0; i < files.length; i++) {
                        File f = files[i];
                        long last_mod = f.lastModified();
                        if (last_mod > most_recent_time && last_mod > one_week_ago) {
                            most_recent_dump = f;
                            most_recent_time = last_mod;
                        }
                    }
                }
            }
        }
        if (most_recent_dump != null) {
            long last_done = COConfigurationManager.getLongParameter("diagnostics.dump.lasttime", 0);
            if (last_done < most_recent_time) {
                COConfigurationManager.setParameter("diagnostics.dump.lasttime", most_recent_time);
                analyseDump(most_recent_dump);
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    } finally {
        dump_check_done_sem.releaseForever();
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) LogAlert(com.biglybt.core.logging.LogAlert)

Example 55 with LogAlert

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

the class UpdaterUtils method writePluginProperties.

protected static void writePluginProperties(File target, String[] lines) {
    try {
        PrintWriter pw = null;
        try {
            target.getParentFile().mkdirs();
            pw = new PrintWriter(new FileWriter(target));
            for (int i = 0; i < lines.length; i++) {
                pw.println(lines[i]);
            }
            pw.println("plugin.install_if_missing=yes");
        } finally {
            if (pw != null) {
                pw.close();
            }
        }
        if (!target.exists()) {
            throw (new Exception("Failed to write '" + target.toString() + "'"));
        }
    } catch (Throwable e) {
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Plugin bootstrap: initialisation error for " + target, e));
    }
}
Also used : FileWriter(java.io.FileWriter) LogAlert(com.biglybt.core.logging.LogAlert) PrintWriter(java.io.PrintWriter)

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