use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class ProgressPanel method makeTorrent.
public void makeTorrent() {
int tracker_type = wizard.getTrackerType();
if (tracker_type == NewTorrentWizard.TT_EXTERNAL) {
TrackersUtil.getInstance().addTracker(wizard.trackerURL);
}
File f;
if (wizard.create_mode == NewTorrentWizard.MODE_DIRECTORY) {
f = new File(wizard.directoryPath);
} else if (wizard.create_mode == NewTorrentWizard.MODE_SINGLE_FILE) {
f = new File(wizard.singlePath);
} else {
f = wizard.byo_desc_file;
}
try {
URL url = new URL(wizard.trackerURL);
final TOTorrent torrent;
if (wizard.getPieceSizeComputed()) {
wizard.creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(f, url, wizard.getAddOtherHashes());
wizard.creator.addListener(this);
wizard.creator.setFileIsLayoutDescriptor(wizard.create_mode == NewTorrentWizard.MODE_BYO);
torrent = wizard.creator.create();
} else {
wizard.creator = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(f, url, wizard.getAddOtherHashes(), wizard.getPieceSizeManual());
wizard.creator.addListener(this);
wizard.creator.setFileIsLayoutDescriptor(wizard.create_mode == NewTorrentWizard.MODE_BYO);
torrent = wizard.creator.create();
}
if (tracker_type == NewTorrentWizard.TT_DECENTRAL) {
TorrentUtils.setDecentralised(torrent);
}
torrent.setComment(wizard.getComment());
TorrentUtils.setDHTBackupEnabled(torrent, wizard.permitDHT);
TorrentUtils.setPrivate(torrent, wizard.getPrivateTorrent());
LocaleTorrentUtil.setDefaultTorrentEncoding(torrent);
// mark this newly created torrent as complete to avoid rechecking on open
final File save_dir;
if (wizard.create_mode == NewTorrentWizard.MODE_DIRECTORY) {
save_dir = f;
} else if (wizard.create_mode == NewTorrentWizard.MODE_SINGLE_FILE) {
save_dir = f.getParentFile();
} else {
String save_path = COConfigurationManager.getStringParameter("Default save path");
File f_save_path = new File(save_path);
if (!f_save_path.canWrite()) {
throw (new Exception("Default save path is not configured: See Tools->Options->File"));
}
save_dir = f_save_path;
}
if (wizard.useMultiTracker) {
this.reportCurrentTask(MessageText.getString("wizard.addingmt"));
TorrentUtils.listToAnnounceGroups(wizard.trackers, torrent);
}
if (wizard.useWebSeed && wizard.webseeds.size() > 0) {
this.reportCurrentTask(MessageText.getString("wizard.webseed.adding"));
Map ws = wizard.webseeds;
List getright = (List) ws.get("getright");
if (getright.size() > 0) {
for (int i = 0; i < getright.size(); i++) {
reportCurrentTask(" GetRight: " + getright.get(i));
}
torrent.setAdditionalListProperty("url-list", new ArrayList(getright));
}
List webseed = (List) ws.get("webseed");
if (webseed.size() > 0) {
for (int i = 0; i < webseed.size(); i++) {
reportCurrentTask(" WebSeed: " + webseed.get(i));
}
torrent.setAdditionalListProperty("httpseeds", new ArrayList(webseed));
}
}
// must do this last as it saves a copy of the torrent state for future opening...
/*
* actually, don't need to do this as the "open-for-seeding" option used when adding the download
* does the job. Reason I stopped doing this is
* https://sourceforge.net/tracker/index.php?func=detail&aid=1721917&group_id=84122&atid=575154
*
DownloadManagerState download_manager_state =
DownloadManagerStateFactory.getDownloadState( torrent );
TorrentUtils.setResumeDataCompletelyValid( download_manager_state );
download_manager_state.save();
*/
this.reportCurrentTask(MessageText.getString("wizard.maketorrent.savingfile"));
final File torrent_file = new File(wizard.savePath);
torrent.serialiseToBEncodedFile(torrent_file);
this.reportCurrentTask(MessageText.getString("wizard.maketorrent.filesaved"));
wizard.switchToClose(new Runnable() {
@Override
public void run() {
show_torrent_file.setEnabled(true);
}
});
if (wizard.autoOpen) {
CoreWaiterSWT.waitForCore(TriggerInThread.NEW_THREAD, new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
boolean start_stopped = COConfigurationManager.getBooleanParameter("Default Start Torrents Stopped");
byte[] hash = null;
try {
hash = torrent.getHash();
} catch (TOTorrentException e1) {
}
if (wizard.forceStart || wizard.superseed) {
// superseeding can only be set for an active download...
start_stopped = false;
}
DownloadManagerInitialisationAdapter dmia;
final String initialTags = wizard.getInitialTags(true);
if (initialTags.length() > 0) {
dmia = new DownloadManagerInitialisationAdapter() {
@Override
public int getActions() {
return (ACT_ASSIGNS_TAGS);
}
@Override
public void initialised(DownloadManager dm, boolean for_seeding) {
TagManager tm = TagManagerFactory.getTagManager();
TagType tag_type = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
String[] bits = initialTags.replace(';', ',').split(",");
for (String tag : bits) {
tag = tag.trim();
if (tag.length() > 0) {
try {
Tag t = tag_type.getTag(tag, true);
if (t == null) {
t = tag_type.createTag(tag, true);
}
t.addTaggable(dm);
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
};
} else {
dmia = null;
}
final DownloadManager dm = core.getGlobalManager().addDownloadManager(torrent_file.toString(), hash, save_dir.toString(), start_stopped ? DownloadManager.STATE_STOPPED : // persistent
DownloadManager.STATE_QUEUED, // persistent
true, // for seeding
true, dmia);
if (!start_stopped && dm != null) {
// We want this to move to seeding ASAP, so move it to the top
// of the download list, where it will do the quick check and
// move to the seeding list
// (the for seeding flag should really be smarter and verify
// it's a seeding torrent and set appropriately)
dm.getGlobalManager().moveTop(new DownloadManager[] { dm });
}
if (wizard.autoHost && wizard.getTrackerType() != NewTorrentWizard.TT_EXTERNAL) {
try {
core.getTrackerHost().hostTorrent(torrent, true, false);
} catch (TRHostException e) {
Logger.log(new LogAlert(LogAlert.REPEATABLE, "Host operation fails", e));
}
}
if (dm != null) {
if (wizard.forceStart) {
dm.setForceStart(true);
}
if (wizard.superseed) {
new AEThread2("startwait") {
@Override
public void run() {
long start = SystemTime.getMonotonousTime();
while (true) {
if (dm.isDestroyed()) {
break;
}
long elapsed = SystemTime.getMonotonousTime() - start;
if (elapsed > 60 * 1000) {
int state = dm.getState();
if (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED) {
break;
}
}
if (elapsed > 5 * 60 * 1000) {
break;
}
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
pm.setSuperSeedMode(true);
break;
}
try {
Thread.sleep(1000);
} catch (Throwable e) {
break;
}
}
}
}.start();
}
}
}
});
}
} catch (Exception e) {
if (e instanceof TOTorrentException) {
TOTorrentException te = (TOTorrentException) e;
if (te.getReason() == TOTorrentException.RT_CANCELLED) {
// expected failure, don't log exception
} else {
reportCurrentTask(MessageText.getString("wizard.operationfailed"));
reportCurrentTask(TorrentUtils.exceptionToText(te));
}
} else {
Debug.printStackTrace(e);
reportCurrentTask(MessageText.getString("wizard.operationfailed"));
reportCurrentTask(Debug.getStackTrace(e));
}
wizard.switchToClose();
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class BackupManagerImpl method checkSchedule.
private void checkSchedule(final BackupListener _listener, boolean force) {
final BackupListener listener = new BackupListener() {
@Override
public boolean reportProgress(String str) {
if (_listener != null) {
try {
return (_listener.reportProgress(str));
} catch (Throwable e) {
Debug.out(e);
}
}
return (true);
}
@Override
public void reportError(Throwable error) {
if (_listener != null) {
try {
_listener.reportError(error);
} catch (Throwable e) {
Debug.out(e);
}
}
}
@Override
public void reportComplete() {
if (_listener != null) {
try {
_listener.reportComplete();
} catch (Throwable e) {
Debug.out(e);
}
}
}
};
boolean enabled = COConfigurationManager.getBooleanParameter("br.backup.auto.enable");
boolean do_backup = false;
synchronized (this) {
if (backup_event != null) {
backup_event.cancel();
backup_event = null;
}
if (first_schedule_check) {
if (!enabled) {
String last_ver = COConfigurationManager.getStringParameter("br.backup.config.info.ver", "");
String current_ver = Constants.AZUREUS_VERSION;
if (!last_ver.equals(current_ver)) {
COConfigurationManager.setParameter("br.backup.config.info.ver", current_ver);
Logger.log(new LogAlert(false, LogAlert.AT_INFORMATION, MessageText.getString("br.backup.setup.info")));
}
}
first_schedule_check = false;
if (!force) {
if (enabled) {
backup_event = SimpleTimer.addEvent("BM:startup", SystemTime.getCurrentTime() + 5 * 60 * 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
checkSchedule();
}
});
}
return;
}
}
if (!enabled) {
listener.reportError(new Exception("Auto-backup not enabled"));
return;
}
long now_utc = SystemTime.getCurrentTime();
int offset = TimeZone.getDefault().getOffset(now_utc);
long now_local = now_utc + offset;
long HOUR = 60 * 60 * 1000L;
long DAY = 24 * HOUR;
long local_day_index = now_local / DAY;
long local_hour_index = now_local / HOUR;
long last_auto_backup_day = COConfigurationManager.getLongParameter("br.backup.auto.last_backup_day", 0);
long last_auto_backup_hour = COConfigurationManager.getLongParameter("br.backup.auto.last_backup_hour", 0);
if (last_auto_backup_day > local_day_index) {
last_auto_backup_day = local_day_index;
}
if (last_auto_backup_hour > local_hour_index) {
last_auto_backup_hour = local_hour_index;
}
long backup_every_days = COConfigurationManager.getLongParameter("br.backup.auto.everydays");
long backup_every_hours = COConfigurationManager.getLongParameter("br.backup.auto.everyhours");
backup_every_days = Math.max(0, backup_every_days);
long utc_next_backup;
long check_period;
if (backup_every_days == 0) {
backup_every_hours = Math.max(1, backup_every_hours);
utc_next_backup = (last_auto_backup_hour + backup_every_hours) * HOUR;
check_period = 10 * 60 * 1000;
} else {
utc_next_backup = (last_auto_backup_day + backup_every_days) * DAY;
check_period = 4 * 60 * 60 * 1000;
}
long time_to_next_backup = utc_next_backup - now_local;
if (time_to_next_backup <= 0 || force) {
if (now_utc - last_auto_backup >= check_period || force) {
do_backup = true;
last_auto_backup = now_utc;
COConfigurationManager.setParameter("br.backup.auto.last_backup_day", local_day_index);
COConfigurationManager.setParameter("br.backup.auto.last_backup_hour", local_hour_index);
} else {
time_to_next_backup = check_period;
}
}
if (!do_backup) {
time_to_next_backup = Math.max(time_to_next_backup, 60 * 1000);
listener.reportProgress("Scheduling next backup in " + TimeFormatter.format(time_to_next_backup / 1000));
backup_event = SimpleTimer.addEvent("BM:auto", now_utc + time_to_next_backup, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
checkSchedule();
}
});
}
}
if (do_backup) {
String backup_dir = COConfigurationManager.getStringParameter("br.backup.auto.dir", "");
listener.reportProgress("Auto backup starting: folder=" + backup_dir);
final File target_dir = new File(backup_dir);
backup(target_dir, new BackupListener() {
@Override
public boolean reportProgress(String str) {
return (listener.reportProgress(str));
}
@Override
public void reportComplete() {
try {
System.out.println("Auto backup completed");
COConfigurationManager.save();
if (COConfigurationManager.getBooleanParameter("br.backup.notify")) {
Logger.log(new LogAlert(true, LogAlert.AT_INFORMATION, "Backup completed at " + new Date()));
}
int backup_retain = COConfigurationManager.getIntParameter("br.backup.auto.retain");
backup_retain = Math.max(1, backup_retain);
File[] backups = target_dir.listFiles();
List<File> backup_dirs = new ArrayList<>();
for (File f : backups) {
if (f.isDirectory() && getBackupDirTime(f) > 0) {
File test_file = new File(f, ConfigurationManager.CONFIG_FILENAME);
if (test_file.exists()) {
backup_dirs.add(f);
}
}
}
Collections.sort(backup_dirs, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
long t1 = getBackupDirTime(o1);
long t2 = getBackupDirTime(o2);
long res = t2 - t1;
if (res < 0) {
return (-1);
} else if (res > 0) {
return (1);
} else {
Debug.out("hmm: " + o1 + "/" + o2);
return (0);
}
}
});
for (int i = backup_retain; i < backup_dirs.size(); i++) {
File f = backup_dirs.get(i);
listener.reportProgress("Deleting old backup: " + f);
FileUtil.recursiveDeleteNoCheck(f);
}
} finally {
listener.reportComplete();
checkSchedule();
}
}
@Override
public void reportError(Throwable error) {
try {
listener.reportProgress("Auto backup failed");
Logger.log(new LogAlert(true, LogAlert.AT_ERROR, "Backup failed at " + new Date(), error));
} finally {
listener.reportError(error);
checkSchedule();
}
}
});
} else {
listener.reportError(new Exception("Backup not scheduled to run now"));
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class CoreImpl method start.
@Override
public void start() throws CoreException {
if (!canStart()) {
throw (new CoreException("Core: already started (alternative process)"));
}
AEThread2.setOurThread();
try {
this_mon.enter();
if (started) {
throw (new CoreException("Core: already started"));
}
if (stopped) {
throw (new CoreException("Core: already stopped"));
}
started = true;
} finally {
this_mon.exit();
}
// If a user sets this property, it is an alias for the following settings.
if ("1".equals(System.getProperty(SystemProperties.SYSPROP_SAFEMODE))) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Safe mode enabled"));
Constants.isSafeMode = true;
System.setProperty(SystemProperties.SYSPROP_LOADPLUGINS, "0");
System.setProperty(SystemProperties.SYSPROP_DISABLEDOWNLOADS, "1");
System.setProperty(SystemProperties.SYSPROP_SKIP_SWTCHECK, "1");
// Not using localised text - not sure it's safe to this early.
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_WARNING, "You are running " + Constants.APP_NAME + " in safe mode - you " + "can change your configuration, but any downloads added will " + "not be remembered when you close " + Constants.APP_NAME + "."));
}
/**
* test to see if UI plays nicely with a really slow initialization
*/
String sDelayCore = System.getProperty("delay.core", null);
if (sDelayCore != null) {
try {
long delayCore = Long.parseLong(sDelayCore);
Thread.sleep(delayCore);
} catch (Exception e) {
e.printStackTrace();
}
}
// run plugin loading in parallel to the global manager loading
AEThread2 pluginload = new AEThread2("PluginLoader", true) {
@Override
public void run() {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Loading of Plugins starts"));
pi.loadPlugins(CoreImpl.this, false, !"0".equals(System.getProperty(SystemProperties.SYSPROP_LOADPLUGINS)), true, true);
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Loading of Plugins complete"));
}
};
if (LOAD_PLUGINS_IN_OTHER_THREAD) {
pluginload.start();
} else {
pluginload.run();
}
// Disable async loading of existing torrents, because there are many things
// (like hosting) that require all the torrents to be loaded. While we
// can write code for each of these cases to wait until the torrents are
// loaded, it's a pretty big job to find them all and fix all their quirks.
// Too big of a job for this late in the release stage.
// Other example is the tracker plugin that is coded in a way where it must
// always publish a complete rss feed
global_manager = GlobalManagerFactory.create(this, null, 0);
if (stopped) {
System.err.println("Core stopped while starting");
return;
}
// wait until plugin loading is done
if (LOAD_PLUGINS_IN_OTHER_THREAD) {
pluginload.join();
}
if (stopped) {
System.err.println("Core stopped while starting");
return;
}
VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {
@Override
public void process(VuzeFile[] files, int expected_types) {
for (int i = 0; i < files.length; i++) {
VuzeFile vf = files[i];
VuzeFileComponent[] comps = vf.getComponents();
for (int j = 0; j < comps.length; j++) {
VuzeFileComponent comp = comps[j];
int comp_type = comp.getType();
if (comp_type == VuzeFileComponent.COMP_TYPE_ADD_TORRENT) {
PluginInterface default_pi = getPluginManager().getDefaultPluginInterface();
Map map = comp.getContent();
try {
Torrent torrent;
String url = MapUtils.getMapString(map, "torrent_url", null);
if (url != null) {
TorrentDownloader dl = default_pi.getTorrentManager().getURLDownloader(new URL(url));
torrent = dl.download();
} else {
String tf = MapUtils.getMapString(map, "torrent_file", null);
if (tf != null) {
File file = new File(tf);
if (!file.canRead() || file.isDirectory()) {
throw (new Exception("torrent_file '" + tf + "' is invalid"));
}
torrent = default_pi.getTorrentManager().createFromBEncodedFile(file);
} else {
throw (new Exception("torrent_url or torrent_file must be specified"));
}
}
File dest = null;
String save_folder = MapUtils.getMapString(map, "save_folder", null);
if (save_folder != null) {
dest = new File(save_folder, torrent.getName());
} else {
String save_file = MapUtils.getMapString(map, "save_file", null);
if (save_file != null) {
dest = new File(save_file);
}
}
if (dest != null) {
dest.getParentFile().mkdirs();
}
default_pi.getDownloadManager().addDownload(torrent, null, dest);
} catch (Throwable e) {
Debug.out(e);
}
comp.setProcessed();
}
}
}
}
});
triggerLifeCycleComponentCreated(global_manager);
pi.initialisePlugins();
if (stopped) {
System.err.println("Core stopped while starting");
return;
}
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Initializing Plugins complete"));
try {
PluginInterface dht_pi = getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
if (dht_pi != null) {
dht_pi.addEventListener(new PluginEventListener() {
private boolean first_dht = true;
@Override
public void handleEvent(PluginEvent ev) {
if (ev.getType() == DHTPlugin.EVENT_DHT_AVAILABLE) {
if (first_dht) {
first_dht = false;
DHT dht = (DHT) ev.getValue();
dht.addListener(new DHTListener() {
@Override
public void speedTesterAvailable(DHTSpeedTester tester) {
if (speed_manager != null) {
speed_manager.setSpeedTester(tester);
}
}
});
global_manager.addListener(new GlobalManagerAdapter() {
@Override
public void seedingStatusChanged(boolean seeding_only_mode, boolean b) {
checkConfig();
}
});
COConfigurationManager.addAndFireParameterListeners(new String[] { TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY }, new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
checkConfig();
}
});
}
}
}
protected void checkConfig() {
if (speed_manager != null) {
speed_manager.setEnabled(TransferSpeedValidator.isAutoSpeedActive(global_manager));
}
}
});
}
} catch (Throwable e) {
}
if (COConfigurationManager.getBooleanParameter("Resume Downloads On Start")) {
global_manager.resumeDownloads();
}
VersionCheckClient.getSingleton().initialise();
instance_manager.initialize();
NetworkManager.getSingleton().initialize(this);
SpeedLimitHandler.getSingleton(this);
Runtime.getRuntime().addShutdownHook(new AEThread("Shutdown Hook") {
@Override
public void runSupport() {
Logger.log(new LogEvent(LOGID, "Shutdown hook triggered"));
CoreImpl.this.stop();
}
});
DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("Core", new Runnable() {
@Override
public void run() {
new AEThread2("core:delayTask", true) {
@Override
public void run() {
AEDiagnostics.checkDumpsAndNatives();
COConfigurationManager.setParameter("diags.enable.pending.writes", true);
AEDiagnostics.flushPendingLogs();
NetworkAdmin na = NetworkAdmin.getSingleton();
na.runInitialChecks(CoreImpl.this);
na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {
private String last_as;
@Override
public void propertyChanged(String property) {
NetworkAdmin na = NetworkAdmin.getSingleton();
if (property.equals(NetworkAdmin.PR_NETWORK_INTERFACES)) {
boolean found_usable = false;
NetworkAdminNetworkInterface[] intf = na.getInterfaces();
for (int i = 0; i < intf.length; i++) {
NetworkAdminNetworkInterfaceAddress[] addresses = intf[i].getAddresses();
for (int j = 0; j < addresses.length; j++) {
if (!addresses[j].isLoopback()) {
found_usable = true;
}
}
}
if (!found_usable) {
return;
}
Logger.log(new LogEvent(LOGID, "Network interfaces have changed (new=" + na.getNetworkInterfacesAsString() + ")"));
announceAll(false);
} else if (property.equals(NetworkAdmin.PR_AS)) {
String as = na.getCurrentASN().getAS();
if (last_as == null) {
last_as = as;
} else if (!as.equals(last_as)) {
Logger.log(new LogEvent(LOGID, "AS has changed (new=" + as + ")"));
last_as = as;
announceAll(false);
}
}
}
});
setupSleepAndCloseActions();
}
}.start();
}
});
delayed_task.queue();
if (stopped) {
System.err.println("Core stopped while starting");
return;
}
PairingManagerFactory.getSingleton();
CoreRunningListener[] runningListeners;
mon_coreRunningListeners.enter();
try {
if (coreRunningListeners == null) {
runningListeners = new CoreRunningListener[0];
} else {
runningListeners = coreRunningListeners.toArray(new CoreRunningListener[0]);
coreRunningListeners = null;
}
} finally {
mon_coreRunningListeners.exit();
}
// Trigger Listeners now that core is started
new AEThread2("Plugin Init Complete", false) {
@Override
public void run() {
try {
PlatformManagerFactory.getPlatformManager().startup(CoreImpl.this);
} catch (Throwable e) {
Debug.out("PlatformManager: init failed", e);
}
Iterator it = lifecycle_listeners.iterator();
while (it.hasNext()) {
try {
CoreLifecycleListener listener = (CoreLifecycleListener) it.next();
if (!listener.requiresPluginInitCompleteBeforeStartedEvent()) {
listener.started(CoreImpl.this);
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
pi.initialisationComplete();
it = lifecycle_listeners.iterator();
while (it.hasNext()) {
try {
CoreLifecycleListener listener = (CoreLifecycleListener) it.next();
if (listener.requiresPluginInitCompleteBeforeStartedEvent()) {
listener.started(CoreImpl.this);
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
}.start();
// Typically there are many runningListeners, most with quick execution, and
// a few longer ones. Let 3 run at a time, queue the rest. Without
// a ThreadPool, the slow ones would delay the startup processes that run
// after this start() method
ThreadPool tp = new ThreadPool("Trigger CoreRunning Listeners", 3);
for (final CoreRunningListener l : runningListeners) {
try {
tp.run(new AERunnable() {
@Override
public void runSupport() {
l.coreRunning(CoreImpl.this);
}
});
} catch (Throwable t) {
Debug.out(t);
}
}
// Debug.out("Core Start Complete");
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class CoreImpl method executeInternalCloseAction.
private void executeInternalCloseAction(final boolean obey_reset, final boolean download_trigger, final String action, final String reason) {
// prevent immediate retriggering if user aborts
ca_last_time_downloading = -1;
ca_last_time_seeding = -1;
String type_str = reason == null ? MessageText.getString(download_trigger ? "core.shutdown.dl" : "core.shutdown.se") : reason;
String action_str = MessageText.getString("ConfigView.label.stop." + action);
String message = MessageText.getString("core.shutdown.alert", new String[] { action_str, type_str });
UIFunctions ui_functions = UIFunctionsManager.getUIFunctions();
if (ui_functions != null) {
ui_functions.forceNotify(UIFunctions.STATUSICON_NONE, null, message, null, new Object[0], -1);
}
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_INFORMATION, message));
if (COConfigurationManager.getBooleanParameter("Prompt To Abort Shutdown")) {
UIManager ui_manager = StaticUtilities.getUIManager(30 * 1000);
if (ui_manager != null) {
Map<String, Object> options = new HashMap<>();
options.put(UIManager.MB_PARAM_AUTO_CLOSE_MS, 30 * 1000);
if (ui_manager.showMessageBox("core.shutdown.prompt.title", "core.shutdown.prompt.msg", UIManagerEvent.MT_OK_DEFAULT | UIManagerEvent.MT_CANCEL, options) == UIManagerEvent.MT_CANCEL) {
return;
}
}
}
executeCloseActionSupport(obey_reset, download_trigger, action, reason);
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class CoreImpl method executeScript.
void executeScript(String script, String action, boolean download_trigger) {
String script_type = "";
if (script.length() >= 10 && script.substring(0, 10).toLowerCase(Locale.US).startsWith("javascript")) {
int p1 = script.indexOf('(');
int p2 = script.lastIndexOf(')');
if (p1 != -1 && p2 != -1) {
script = script.substring(p1 + 1, p2).trim();
if (script.startsWith("\"") && script.endsWith("\"")) {
script = script.substring(1, script.length() - 1);
}
// allow people to escape " if it makes them feel better
script = script.replaceAll("\\\\\"", "\"");
script_type = ScriptProvider.ST_JAVASCRIPT;
}
}
File script_file = null;
if (script_type == "") {
script_file = new File(script.trim());
if (!script_file.isFile()) {
Logger.log(new LogEvent(LOGID, "Script failed to run - '" + script_file + "' isn't a valid script file"));
Debug.out("Invalid script: " + script_file);
return;
}
}
try {
boolean close_vuze = action.equals("RunScriptAndClose");
if (!close_vuze) {
// assume script might implement a sleep
announceAll(true);
}
if (script_file != null) {
getPluginManager().getDefaultPluginInterface().getUtilities().createProcess(script_file.getAbsolutePath());
} else {
boolean provider_found = false;
List<ScriptProvider> providers = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUtilities().getScriptProviders();
for (ScriptProvider p : providers) {
if (p.getScriptType() == script_type) {
provider_found = true;
Map<String, Object> bindings = new HashMap<>();
String intent = "shutdown" + "(\"" + action + "\")";
bindings.put("intent", intent);
bindings.put("is_downloading_complete", download_trigger);
p.eval(script, bindings);
}
}
if (!provider_found) {
if (!js_plugin_install_tried) {
js_plugin_install_tried = true;
PluginUtils.installJavaScriptPlugin();
}
}
}
if (close_vuze) {
requestStop();
}
} catch (Throwable e) {
Logger.log(new LogAlert(true, LogAlert.AT_ERROR, "Script failed to run - '" + script + "'", e));
Debug.out("Invalid script: " + script, e);
}
}
Aggregations