Search in sources :

Example 1 with ClientRestarter

use of com.biglybt.core.update.ClientRestarter 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);
    }
}
Also used : UpdateInstaller(com.biglybt.pif.update.UpdateInstaller) ClientRestarter(com.biglybt.core.update.ClientRestarter) UpdateException(com.biglybt.pif.update.UpdateException)

Aggregations

ClientRestarter (com.biglybt.core.update.ClientRestarter)1 UpdateException (com.biglybt.pif.update.UpdateException)1 UpdateInstaller (com.biglybt.pif.update.UpdateInstaller)1