use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class SystemProperties method getUserPath.
/**
* Returns the full path to the user's home directory for this app.
* Under unix, this is usually ~/.[lowercase AppName]/
* Under Windows, this is usually .../Documents and Settings/username/Application Data/[AppName]/
* Under OSX, this is usually /Users/username/Library/Application Support/[AppName]/
*/
public static String getUserPath() {
if (user_path != null) {
return user_path;
}
// WATCH OUT!!!! possible recursion here if logging is changed so that it messes with
// config initialisation - that's why we don't assign the user_path variable until it
// is complete - an earlier bug resulted in us half-assigning it and using it due to
// recursion. At least with this approach we'll get (worst case) stack overflow if
// a similar change is made, and we'll spot it!!!!
// Super Override -- no AZ_DIR or xxx_DEFAULT added at all.
String temp_user_path = System.getProperty(SYS_PROP_CONFIG_OVERRIDE);
try {
if (temp_user_path != null) {
if (!temp_user_path.endsWith(SEP)) {
temp_user_path += SEP;
}
File dir = new File(temp_user_path);
if (!dir.exists()) {
FileUtil.mkdirs(dir);
}
return temp_user_path;
}
try {
PlatformManager platformManager = PlatformManagerFactory.getPlatformManager();
File loc = platformManager.getLocation(PlatformManager.LOC_USER_DATA);
if (loc != null) {
temp_user_path = loc.getPath() + SEP;
// Called within initialization.. no logger!
// if (Logger.isEnabled()) {
// Logger.log(new LogEvent(LOGID,
// "SystemProperties::getUserPath: user_path = " + temp_user_path));
// }
}
} catch (Throwable e) {
System.err.println("Unable to retrieve user config path from " + "the platform manager. " + "Make sure aereg.dll is present.");
// Called within initialization.. no logger!
// if (Logger.isEnabled()) {
// Logger.log(new LogEvent(LOGID,
// "Unable to retrieve user config path from "
// + "the platform manager. "
// + "Make sure aereg.dll is present."));
// }
}
// If platform failed, try some hackery
if (temp_user_path == null) {
String userhome = System.getProperty("user.home");
temp_user_path = userhome + SEP + "." + APPLICATION_NAME.toLowerCase() + SEP;
}
// if the directory doesn't already exist, create it
File dir = new File(temp_user_path);
if (!dir.exists()) {
FileUtil.mkdirs(dir);
}
return temp_user_path;
} finally {
user_path = temp_user_path;
}
}
use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class SystemProperties method getDocPath.
public static String getDocPath() {
String explicit_dir = System.getProperty(SYSPROP_DOC_PATH, null);
if (explicit_dir != null) {
File temp = new File(explicit_dir);
if (!temp.exists()) {
if (!temp.mkdirs()) {
System.err.println("Failed to create document dir: " + temp);
}
} else if (!(temp.isDirectory() && temp.canWrite())) {
System.err.println("Document dir is not a directory or not writable: " + temp);
}
return (temp.getAbsolutePath());
}
if (PORTABLE) {
return (getUserPath());
}
File fDocPath = null;
try {
PlatformManager platformManager = PlatformManagerFactory.getPlatformManager();
fDocPath = platformManager.getLocation(PlatformManager.LOC_DOCUMENTS);
} catch (Throwable e) {
}
if (fDocPath == null) {
System.err.println("This is BAD - fix me!");
new Throwable().printStackTrace();
// should never happen.. but if we are missing a dll..
fDocPath = new File(getUserPath(), "Documents");
}
return fDocPath.getAbsolutePath();
}
use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class ConfigSectionStartShutdown method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
GridData gridData;
GridLayout layout;
Label label;
final Composite cDisplay = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(cDisplay, gridData);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
cDisplay.setLayout(layout);
final PlatformManager platform = PlatformManagerFactory.getPlatformManager();
int userMode = COConfigurationManager.getIntParameter("User Mode");
// ***** start group
boolean can_ral = platform.hasCapability(PlatformManagerCapabilities.RunAtLogin);
if (can_ral || userMode > 0) {
Group gStartStop = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gStartStop, "ConfigView.label.start");
layout = new GridLayout(2, false);
gStartStop.setLayout(layout);
Utils.setLayoutData(gStartStop, new GridData(GridData.FILL_HORIZONTAL));
if (can_ral) {
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter start_on_login = new BooleanParameter(gStartStop, "Start On Login", "ConfigView.label.start.onlogin");
try {
start_on_login.setSelected(platform.getRunAtLogin());
start_on_login.addChangeListener(new ParameterChangeAdapter() {
@Override
public void booleanParameterChanging(Parameter p, boolean toValue) {
try {
platform.setRunAtLogin(toValue);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} catch (Throwable e) {
start_on_login.setEnabled(false);
Debug.out(e);
}
start_on_login.setLayoutData(gridData);
}
if (userMode > 0) {
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter start_in_lr_mode = new BooleanParameter(gStartStop, "Start In Low Resource Mode", "ConfigView.label.start.inlrm");
start_in_lr_mode.setLayoutData(gridData);
Composite lr_comp = new Composite(gStartStop, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalIndent = 20;
Utils.setLayoutData(lr_comp, gridData);
layout = new GridLayout(3, false);
lr_comp.setLayout(layout);
BooleanParameter lr_ui = new BooleanParameter(lr_comp, "LRMS UI", "lrms.deactivate.ui");
BooleanParameter lr_udp_net = new BooleanParameter(lr_comp, "LRMS UDP Peers", "lrms.udp.peers");
BooleanParameter lr_dht_sleep = new BooleanParameter(lr_comp, "LRMS DHT Sleep", "lrms.dht.sleep");
// start_in_lr_mode.setAdditionalActionPerformer( new ChangeSelectionActionPerformer( lr_ui ));
// this must always be selected as it is coming out of the deactivated UI mode that enable the others as well
lr_ui.setEnabled(false);
start_in_lr_mode.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(lr_udp_net));
start_in_lr_mode.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(lr_dht_sleep));
}
}
if (platform.hasCapability(PlatformManagerCapabilities.PreventComputerSleep)) {
Group gSleep = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gSleep, "ConfigView.label.sleep");
layout = new GridLayout(2, false);
gSleep.setLayout(layout);
Utils.setLayoutData(gSleep, new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
gridData.horizontalSpan = 2;
label = new Label(gSleep, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.sleep.info");
Utils.setLayoutData(label, gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter no_sleep_dl = new BooleanParameter(gSleep, "Prevent Sleep Downloading", "ConfigView.label.sleep.download");
no_sleep_dl.setLayoutData(gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter no_sleep_se = new BooleanParameter(gSleep, "Prevent Sleep FP Seeding", "ConfigView.label.sleep.fpseed");
no_sleep_se.setLayoutData(gridData);
TagManager tm = TagManagerFactory.getTagManager();
if (tm.isEnabled()) {
List<Tag> tag_list = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
String[] tags = new String[tag_list.size() + 1];
tags[0] = "";
for (int i = 0; i < tag_list.size(); i++) {
tags[i + 1] = tag_list.get(i).getTagName(true);
}
label = new Label(gSleep, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.sleep.tag");
new StringListParameter(gSleep, "Prevent Sleep Tag", "", tags, tags);
}
}
if (userMode > 0) {
Group gPR = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gPR, "ConfigView.label.pauseresume");
layout = new GridLayout(2, false);
gPR.setLayout(layout);
Utils.setLayoutData(gPR, new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter pauseOnExit = new BooleanParameter(gPR, "Pause Downloads On Exit", "ConfigView.label.pause.downloads.on.exit");
pauseOnExit.setLayoutData(gridData);
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter resumeOnStart = new BooleanParameter(gPR, "Resume Downloads On Start", "ConfigView.label.resume.downloads.on.start");
resumeOnStart.setLayoutData(gridData);
}
if (userMode >= 0) {
Group gStop = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gStop, "ConfigView.label.stop");
layout = new GridLayout(5, false);
gStop.setLayout(layout);
Utils.setLayoutData(gStop, new GridData(GridData.FILL_HORIZONTAL));
// done downloading
addDoneDownloadingOption(gStop, true);
// done seeding
addDoneSeedingOption(gStop, true);
// reset on trigger
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter resetOnTrigger = new BooleanParameter(gStop, "Stop Triggers Auto Reset", "!" + MessageText.getString("ConfigView.label.stop.autoreset", new String[] { MessageText.getString("ConfigView.label.stop.Nothing") }) + "!");
resetOnTrigger.setLayoutData(gridData);
// prompt to allow abort
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter enablePrompt = new BooleanParameter(gStop, "Prompt To Abort Shutdown", "ConfigView.label.prompt.abort");
enablePrompt.setLayoutData(gridData);
}
if (userMode > 0) {
Group gRestart = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gRestart, "label.restart");
layout = new GridLayout(2, false);
gRestart.setLayout(layout);
Utils.setLayoutData(gRestart, new GridData(GridData.FILL_HORIZONTAL));
label = new Label(gRestart, SWT.NULL);
Messages.setLanguageText(label, "ConfigView.label.restart.auto");
new IntParameter(gRestart, "Auto Restart When Idle", 0, 100000);
}
if (userMode > 0 && platform.hasCapability(PlatformManagerCapabilities.AccessExplicitVMOptions)) {
Group gJVM = new Group(cDisplay, SWT.NULL);
Messages.setLanguageText(gJVM, "ConfigView.label.jvm");
layout = new GridLayout(2, false);
gJVM.setLayout(layout);
Utils.setLayoutData(gJVM, new GridData(GridData.FILL_HORIZONTAL));
// wiki link
gridData = new GridData();
gridData.horizontalSpan = 2;
LinkLabel link = new LinkLabel(gJVM, gridData, "ConfigView.label.please.visit.here", Constants.URL_WIKI + "w/Java_VM_memory_usage");
// info
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.info");
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
try {
final File option_file = platform.getVMOptionFile();
final Group gJVMOptions = new Group(gJVM, SWT.NULL);
layout = new GridLayout(3, false);
gJVMOptions.setLayout(layout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(gJVMOptions, gridData);
buildOptions(cDisplay, platform, gJVMOptions, false);
// show option file
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.show.file", new String[] { option_file.getAbsolutePath() });
Button show_folder_button = new Button(gJVM, SWT.PUSH);
Messages.setLanguageText(show_folder_button, "MyTorrentsView.menu.explore");
show_folder_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ManagerUtils.open(option_file);
}
});
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.reset");
Button reset_button = new Button(gJVM, SWT.PUSH);
Messages.setLanguageText(reset_button, "Button.reset");
reset_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
platform.setExplicitVMOptions(new String[0]);
buildOptions(cDisplay, platform, gJVMOptions, true);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} catch (Throwable e) {
Debug.out(e);
label = new Label(gJVM, SWT.NULL);
Messages.setLanguageText(label, "jvm.error", new String[] { Debug.getNestedExceptionMessage(e) });
gridData = new GridData();
gridData.horizontalSpan = 2;
Utils.setLayoutData(label, gridData);
}
}
return cDisplay;
}
Aggregations