Skip to content

Commit

Permalink
Remove debug code, prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
incentivetoken committed May 19, 2014
1 parent a937290 commit d2b03d4
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import it.sauronsoftware.junique.JUnique;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
Expand All @@ -29,6 +32,9 @@
import org.osgi.service.event.EventHandler;

import com.dgex.offspring.application.dialogs.StartupDialog;
import com.dgex.offspring.application.dialogs.UpdateCenterDialog;
import com.dgex.offspring.application.lifecycle.UpgradeManager;
import com.dgex.offspring.application.lifecycle.VersionData;
import com.dgex.offspring.config.Config;
import com.dgex.offspring.dataprovider.service.IDataProviderPool;
import com.dgex.offspring.nxtCore.service.INxtService;
Expand Down Expand Up @@ -56,6 +62,9 @@ public class StartHandlerAddon {

private final Logger logger = Logger.getLogger(StartHandlerAddon.class);

private final ScheduledExecutorService scheduledThreadPool = Executors
.newScheduledThreadPool(2);

@Inject
private IEventBroker broker;

Expand Down Expand Up @@ -125,8 +134,7 @@ public void run() {
/* Kick off NXT startup */

monitor.beginTask("Initializing NXT " + Nxt.VERSION
+ " (might take several minutes)",
IProgressMonitor.UNKNOWN);
+ " (might take several minutes)", IProgressMonitor.UNKNOWN);
nxt.initialize(broker, sync);

/* Immediately register for shutdown */
Expand Down Expand Up @@ -173,6 +181,30 @@ public void run() {

DONE = true;
monitor.done();

/* Schedule the update checker every N seconds */
scheduledThreadPool.scheduleWithFixedDelay(new Runnable() {

@Override
public void run() {
if (UpdateCenterDialog.isOpened()) {
return;
}
VersionData data = UpgradeManager.getVersionData();
if (data != null) {
if (data.isOutdatedVersion(Config.VERSION)) {
sync.asyncExec(new Runnable() {

@Override
public void run() {
UpdateCenterDialog.show(sync);
}
});
}
}
}

}, 30, Config.UPDATE_CHECK_INTERVAL_SECS, TimeUnit.SECONDS);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

import nxt.Alias;
import nxt.Block;
import nxt.Nxt;
import nxt.util.Convert;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
Expand All @@ -43,6 +38,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
Expand All @@ -51,22 +47,20 @@
import org.eclipse.swt.widgets.Text;

import com.dgex.offspring.application.lifecycle.CountingOutputStream;
import com.dgex.offspring.application.lifecycle.UpgradeManager;
import com.dgex.offspring.application.lifecycle.VersionData;
import com.dgex.offspring.config.Config;
import com.dgex.offspring.config.Formatter;
import com.dgex.offspring.config.VersionComprator;


public class UpdateCenterDialog extends TitleAreaDialog {

static final String wikiURL = "https://github.com/incentivetoken/offspring/wiki/8.-Installation-of-ZIP-files#zip-file-installation-instructions";
static Logger logger = Logger.getLogger(UpdateCenterDialog.class);
static final String ALIAS_ID = "offspringversiondata";
static final int MIN_ALIAS_AGE = 60 * 60;
boolean DEBUG = true;
static UpdateCenterDialog INSTANCE = null;
static VersionData versionData = null;

private Composite mainContainer;
private final VersionData versionData;
private ProgressIndicator progressIndicator;
private final UISynchronize sync;
private final ArrayList<Link> downloadLinks = new ArrayList<Link>();
Expand Down Expand Up @@ -132,40 +126,74 @@ public void run() {

public UpdateCenterDialog(Shell shell, UISynchronize sync) {
super(shell);
this.versionData = getVersionData();
this.sync = sync;
}

/**
* Static method that opens a new dialog or switches to the existing dialog.
*
* @param accountId
* @return
*/
public static void show(final UISynchronize sync) {
sync.syncExec(new Runnable() {

@Override
public void run() {
Shell shell = Display.getCurrent().getActiveShell();
if (shell != null) {
while (shell.getParent() != null) {
shell = shell.getParent().getShell();
}
}

INSTANCE.versionData = UpgradeManager.getVersionData();
if (INSTANCE.versionData != null) {
if (INSTANCE == null) {
INSTANCE = new UpdateCenterDialog(shell, sync);
INSTANCE.open();
}
else {
INSTANCE.getShell().forceActive();
}
}
}
});
}

public static boolean isOpened() {
return INSTANCE != null;
}

@Override
public void create() {
super.create();
setTitle("Update Center");
setMessage("Wellcome to the Offspring Update Center");
}

@Override
public int open() {
int ret = super.open();
if (UpgradeManager.getVersionData() == null) {
MessageDialog
.openInformation(getShell(), "Blockchain Incomplete",
"Update Center is disabled because your blockchain is still downloading.");
close();
}
return ret;
}

@Override
public boolean close() {
if (currentJob != null) {
currentJob.cancel();
}
return super.close();
}

private VersionData getVersionData() {
Alias alias = Alias.getAlias(ALIAS_ID);
Block last = Nxt.getBlockchain().getLastBlock();
if (alias == null || last == null || last.getTimestamp() < (Convert.getEpochTime() - MIN_ALIAS_AGE)) {
if (DEBUG) {
System.out.println("Using DEBUG JSON");
return new VersionData(getDebugJSON());
}
MessageDialog.openInformation(getShell(), "Blockchain Incomplete", "Update Center is disabled because your blockchain is still downloading.");
close();
return null;
boolean closed = super.close();
if (closed) {
INSTANCE = null;
}

String json = alias.getURI();
return new VersionData(json);
return closed;
}

@Override
Expand All @@ -192,18 +220,17 @@ protected Control createDialogArea(Composite parent) {
mainContainer.setLayout(layout);

Label label;
boolean up_to_date = !versionData.isOutdatedVersion(Config.VERSION);

int result = new VersionComprator().compare(getCurrentVersion(), versionData.getVersion());
if (result >= 0) {
if (up_to_date) {
label = new Label(mainContainer, SWT.NONE);
label.setText("YOUR OFFSPRING VERSION " + getCurrentVersion() + " IS UP TO DATE");
label.setText("YOUR OFFSPRING VERSION " + Config.VERSION + " IS UP TO DATE");
label.setFont(JFaceResources.getFontRegistry().getBold(""));
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL)
.grab(true, false).applyTo(label);

final Button check = new Button(mainContainer, SWT.CHECK);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL)
.applyTo(check);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).applyTo(check);
check.setText("Let me download anyway.");
check.addSelectionListener(new SelectionAdapter() {

Expand All @@ -223,7 +250,7 @@ public void widgetSelected(SelectionEvent e) {
}

downloadComposite = new Composite(mainContainer, SWT.NONE);
downloadComposite.setVisible(result < 0);
downloadComposite.setVisible(up_to_date == false);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(downloadComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(downloadComposite);

Expand Down Expand Up @@ -258,12 +285,9 @@ public void widgetSelected(SelectionEvent e) {
GridDataFactory.fillDefaults().exclude(true).span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(finalizeComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(finalizeComposite);

new Label(finalizeComposite, SWT.NONE)
.setText("Installation Instructions..");
new Label(finalizeComposite, SWT.NONE)
.setText("Windows users execute the installer and follow instructions.");
new Label(finalizeComposite, SWT.NONE)
.setText("All users who downloaded the ZIP file check out our WIKI.");
new Label(finalizeComposite, SWT.NONE).setText("Installation Instructions..");
new Label(finalizeComposite, SWT.NONE).setText("Windows users execute the installer and follow instructions.");
new Label(finalizeComposite, SWT.NONE).setText("All users who downloaded the ZIP file check out our WIKI.");

Link link = new Link(finalizeComposite, SWT.NONE);
link.setText("<A>Click to visit WIKI</a>");
Expand Down Expand Up @@ -447,23 +471,6 @@ public void run() {
});
}

private String getCurrentVersion() {
if (DEBUG) {
return "0.4.5";
}
return Config.VERSION;
}

private static String getDebugJSON() {
try {
return FileUtils.readFileToString(new File("/home/dirk/git/offspring/com.dgex.offspring.application/src/com/dgex/offspring/application/lifecycle/version.json"));
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}

private void showError(final String message, final Throwable t) {
sync.syncExec(new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.dgex.offspring.application.dialogs.UpdateCenterDialog;

Expand All @@ -16,9 +14,7 @@ public boolean canExecute() {
}

@Execute
public void execute(Display display, Shell shell, UISynchronize sync) {
UpdateCenterDialog dialog = new UpdateCenterDialog(shell, sync);
dialog.create();
dialog.open();
public void execute(UISynchronize sync) {
UpdateCenterDialog.show(sync);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,59 @@
import java.io.File;
import java.io.IOException;

import nxt.Alias;
import nxt.Block;
import nxt.Nxt;
import nxt.util.Convert;

import org.apache.commons.io.FileDeleteStrategy;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.dgex.offspring.config.Config;
import com.dgex.offspring.messages.Messages;

public class UpgradeManager {

static String sJSONAlias = "OFFSPRING-LATEST-VERSION-DATA";
static int MIN_SECONDS_OLD_FOR_ALIAS = 60 * 60;
static boolean DEBUG = true;

static Logger logger = Logger.getLogger(UpgradeManager.class);
static UISynchronize sync = null;

public static void init(UISynchronize sync) {
UpgradeManager.sync = sync;
}

public static VersionData getVersionData() {
Alias alias = Alias.getAlias(Config.ALIAS_ID);
Block last = Nxt.getBlockchain().getLastBlock();
if (alias == null || last == null || (last.getTimestamp()-Convert.getEpochTime()) > 10*60) {

Shell shell = Display.getCurrent().getActiveShell();
if (shell != null) {
while (shell.getParent() != null) {
shell = shell.getParent().getShell();
}
}
if (shell != null) {
MessageDialog
.openWarning(
shell,
"Please wait",
"Blockchain has to be downloaded completely before you can use the update center");
}
else {
System.out.println("Blockchain not fully downloaded yet");
}
return null;
}

String json = alias.getURI();
return new VersionData(json);
}

/*
* Checks at startup if there has been a NXT update. Offers to delete the
* blockchain if it was updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import com.dgex.offspring.config.VersionComprator;

public class VersionData {

private static String OS = System.getProperty("os.name").toLowerCase();
Expand Down Expand Up @@ -39,6 +41,11 @@ public boolean platformSupported(int platform) {
return false;
}

public boolean isOutdatedVersion(String version) {
int ret = new VersionComprator().compare(version, getVersion());
return ret < 0;
}

public String getFilename(int platform) {
return createFileName(platform, getVersion());
}
Expand Down

This file was deleted.

Loading

0 comments on commit d2b03d4

Please sign in to comment.