use of com.biglybt.pif.update.UpdateInstaller in project BiglyBT by BiglySoftware.
the class PlatformManagerUpdateChecker method installUpdate.
protected void installUpdate(UpdateChecker checker, Update update, ResourceDownloader rd, InputStream data) {
ZipInputStream zip = null;
try {
data = update.verifyData(data, true);
rd.reportActivity("Data verified successfully");
UpdateInstaller installer = checker.createInstaller();
zip = new ZipInputStream(data);
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName();
if (name.toLowerCase().startsWith("osx/")) {
// OSX only files
name = name.substring(4);
if (name.length() > 0) {
rd.reportActivity("Adding update action for '" + name + "'");
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "PlatformManager:OSX adding action for '" + name + "'"));
// handle sub-dirs
String resource_name = name.replaceAll("/", "-");
installer.addResource(resource_name, zip, false);
String appDir = installer.getInstallDir();
String contentsResourceJava = "Contents/Resources/Java/";
if (name.startsWith(contentsResourceJava)) {
// trying to install something into the "Java" dir
// New installs have the "Java" dir as the Install dir.
name = name.substring(contentsResourceJava.length());
}
String target = appDir + File.separator + name;
installer.addMoveAction(resource_name, target);
if (name.endsWith(".jnilib") || name.endsWith("JavaApplicationStub")) {
installer.addChangeRightsAction("755", target);
}
}
}
}
update.complete(true);
} catch (Throwable e) {
update.complete(false);
rd.reportActivity("Update install failed:" + e.getMessage());
} finally {
if (zip != null) {
try {
zip.close();
} catch (Throwable e) {
}
}
}
}
use of com.biglybt.pif.update.UpdateInstaller in project BiglyBT by BiglySoftware.
the class BackupManagerImpl method restoreSupport.
void restoreSupport(File backup_folder, BackupListener listener) {
try {
UpdateInstaller installer = null;
File temp_dir = null;
boolean ok = false;
try {
listener.reportProgress("Reading from " + backup_folder.getAbsolutePath());
if (!backup_folder.isDirectory()) {
throw (new Exception("Location '" + backup_folder.getAbsolutePath() + "' must be a directory"));
}
listener.reportProgress("Analysing backup");
File config = new File(backup_folder, ConfigurationManager.CONFIG_FILENAME);
if (!config.exists()) {
throw (new Exception("Invalid backup: " + ConfigurationManager.CONFIG_FILENAME + " not found"));
}
Map config_map = BDecoder.decode(FileUtil.readFileAsByteArray(config));
byte[] temp = (byte[]) config_map.get("azureus.user.directory");
if (temp == null) {
throw (new Exception("Invalid backup: " + ConfigurationManager.CONFIG_FILENAME + " doesn't contain user directory details"));
}
File current_user_dir = new File(SystemProperties.getUserPath());
File backup_user_dir = new File(new String(temp, "UTF-8"));
listener.reportProgress("Current user directory:\t" + current_user_dir.getAbsolutePath());
listener.reportProgress("Backup's user directory:\t" + backup_user_dir.getAbsolutePath());
temp_dir = AETemporaryFileHandler.createTempDir();
PluginInterface pi = core.getPluginManager().getDefaultPluginInterface();
installer = pi.getUpdateManager().createInstaller();
File[] files = backup_folder.listFiles();
if (current_user_dir.equals(backup_user_dir)) {
listener.reportProgress("Directories are the same, no patching required");
for (File f : files) {
File source = new File(temp_dir, f.getName());
listener.reportProgress("Creating restore action for '" + f.getName() + "'");
copyFiles(f, source);
File target = new File(current_user_dir, f.getName());
addActions(installer, source, target);
}
} else {
listener.reportProgress("Directories are different, backup requires patching");
for (File f : files) {
File source = new File(temp_dir, f.getName());
listener.reportProgress("Creating restore action for '" + f.getName() + "'");
if (f.isDirectory() || !f.getName().contains(".config")) {
copyFiles(f, source);
} else {
boolean patched = false;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f), 1024 * 1024);
try {
Map m = BDecoder.decode(bis);
bis.close();
bis = null;
if (m.size() > 0) {
int applied = patch(m, backup_user_dir.getAbsolutePath(), current_user_dir.getAbsolutePath());
if (applied > 0) {
listener.reportProgress(" Applied " + applied + " patches");
patched = FileUtil.writeBytesAsFile2(source.getAbsolutePath(), BEncoder.encode(m));
if (!patched) {
throw (new Exception("Failed to write " + source));
}
}
}
} catch (Throwable e) {
String name = f.getName();
if (name.contains(".bad") || name.contains(".bak")) {
listener.reportProgress(" Ignored failure to patch bad configuration file");
} else {
throw (e);
}
} finally {
if (bis != null) {
try {
bis.close();
} catch (Throwable e) {
}
}
}
if (!patched) {
copyFiles(f, source);
}
}
File target = new File(current_user_dir, f.getName());
addActions(installer, source, target);
}
}
listener.reportProgress("Restore action creation complete, restart required to complete the operation");
listener.reportComplete();
ok = true;
} finally {
if (!ok) {
if (installer != null) {
installer.destroy();
}
if (temp_dir != null) {
FileUtil.recursiveDeleteNoCheck(temp_dir);
}
}
}
} catch (Throwable e) {
listener.reportError(e);
}
}
use of com.biglybt.pif.update.UpdateInstaller in project BiglyBT by BiglySoftware.
the class UI method processArgs.
@Override
public String[] processArgs(CommandLine commands, String[] args) {
boolean showMainWindow = args.length == 0 || COConfigurationManager.getBooleanParameter("Activate Window On External Download");
boolean open = true;
if (commands.hasOption("closedown") || commands.hasOption("shutdown")) {
try {
UpdateManager um = core.getPluginManager().getDefaultPluginInterface().getUpdateManager();
UpdateInstaller[] installers = um.getInstallers();
for (UpdateInstaller installer : installers) {
installer.destroy();
}
} catch (Throwable e) {
}
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(false, false);
}
return null;
}
if (commands.hasOption("restart")) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(true, false);
}
return null;
}
if (commands.hasOption("share")) {
showMainWindow = true;
open = false;
}
if (commands.hasOption("open")) {
showMainWindow = true;
}
String[] rest = commands.getArgs();
for (int i = 0; i < rest.length; i++) {
String filename = rest[i];
File file = new File(filename);
boolean isURI;
if (!file.exists() && !isURI(filename)) {
String magnet_uri = UrlUtils.normaliseMagnetURI(filename);
isURI = magnet_uri != null;
if (isURI) {
filename = magnet_uri;
}
} else {
isURI = isURI(filename);
}
if (isURI) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "StartServer: args[" + i + "] handling as a URI: " + filename));
} else {
try {
if (!file.exists()) {
throw (new Exception("File '" + file + "' not found"));
}
filename = file.getCanonicalPath();
Logger.log(new LogEvent(LOGID, "StartServer: file = " + filename));
} catch (Throwable e) {
Logger.log(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_ERROR, "Failed to access torrent file '" + filename + "'. Ensure sufficient temporary " + "file space available (check browser cache usage)."));
}
}
boolean queued = false;
try {
this_mon.enter();
if (queueTorrents) {
queued_torrents.add(new Object[] { filename, Boolean.valueOf(open) });
queued = true;
}
} finally {
this_mon.exit();
}
if (!queued) {
handleFile(filename, open);
}
}
if (showMainWindow) {
showMainWindow();
}
return args;
}
use of com.biglybt.pif.update.UpdateInstaller in project BiglyBT by BiglySoftware.
the class SWTUpdateChecker method processData.
private boolean processData(UpdateChecker checker, Update update, ResourceDownloader rd, InputStream data) {
ZipInputStream zip = null;
try {
data = update.verifyData(data, true);
rd.reportActivity("Data verified successfully");
UpdateInstaller installer = checker.createInstaller();
zip = new ZipInputStream(data);
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName();
if (name.endsWith(".jar")) {
installer.addResource(name, zip, false);
if (Constants.isUnix) {
// unix SWT goes in <appdir>/swt
installer.addMoveAction(name, installer.getInstallDir() + File.separator + "swt" + File.separator + name);
} else {
installer.addMoveAction(name, installer.getInstallDir() + File.separator + name);
}
} else if (name.endsWith(".jnilib") && Constants.isOSX) {
// on OS X, any .jnilib
installer.addResource(name, zip, false);
installer.addMoveAction(name, installer.getInstallDir() + "/dll/" + name);
} else if (name.endsWith(".dll") || name.endsWith(".so") || name.contains(".so.")) {
// native stuff for windows and linux
installer.addResource(name, zip, false);
installer.addMoveAction(name, installer.getInstallDir() + File.separator + name);
} else if (name.equals("javaw.exe.manifest") || name.equals("azureus.sig")) {
// silently ignore this one
} else {
Debug.outNoStack("SWTUpdate: ignoring zip entry '" + name + "'");
}
}
update.complete(true);
} catch (Throwable e) {
update.complete(false);
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "SWT Update failed", e));
return false;
} finally {
if (zip != null) {
try {
zip.close();
} catch (Throwable e) {
}
}
}
return true;
}
use of com.biglybt.pif.update.UpdateInstaller in project BiglyBT by BiglySoftware.
the class UpdateInstallerImpl method installNow.
@Override
public void installNow(final UpdateInstallerListener listener) throws UpdateException {
try {
UpdateInstaller[] installers = manager.getInstallers();
if (installers.length != 1 || installers[0] != this) {
throw (new UpdateException("Other installers exist - aborting"));
}
listener.reportProgress("Update starts");
ClientRestarter ar = ClientRestarterFactory.create(manager.getCore());
ar.updateNow();
new AEThread2("installNow:waiter", true) {
@Override
public void run() {
try {
long start = SystemTime.getMonotonousTime();
UpdateException pending_error = null;
while (true) {
Thread.sleep(1000);
listener.reportProgress("Checking progress");
if (!install_dir.exists()) {
break;
}
File fail_file = new File(install_dir, "install.fail");
if (fail_file.exists()) {
try {
String error = FileUtil.readFileAsString(fail_file, 1024);
throw (new UpdateException(error));
} catch (Throwable e) {
if (e instanceof UpdateException) {
throw (e);
}
if (pending_error != null) {
throw (pending_error);
}
pending_error = new UpdateException("Install failed, reason unknown");
}
}
if (SystemTime.getMonotonousTime() - start >= 5 * 60 * 1000) {
listener.reportProgress("Timeout");
throw (new UpdateException("Timeout waiting for update to apply"));
}
}
listener.reportProgress("Complete");
listener.complete();
} catch (Throwable e) {
UpdateException fail;
if (e instanceof UpdateException) {
fail = (UpdateException) e;
} else {
fail = new UpdateException("install failed", e);
}
listener.reportProgress(fail.getMessage());
listener.failed(fail);
} finally {
deleteInstaller();
}
}
}.start();
} catch (Throwable e) {
deleteInstaller();
UpdateException fail;
if (e instanceof UpdateException) {
fail = (UpdateException) e;
} else {
fail = new UpdateException("install failed", e);
}
listener.reportProgress(fail.getMessage());
listener.failed(fail);
throw (fail);
}
}
Aggregations