Add support for new release download, Fix bug with empty log file

This commit is contained in:
Manfred Karrer 2015-05-21 12:56:07 +02:00
parent 5cc6c5c552
commit 9594ab96cf
23 changed files with 165 additions and 139 deletions

View file

@ -64,7 +64,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
public static final String DEFAULT_APP_NAME = "Bitsquare";
public static final String APP_DATA_DIR_KEY = "app.data.dir";
public static final String DEFAULT_APP_DATA_DIR = appDataDir(DEFAULT_USER_DATA_DIR, DEFAULT_APP_NAME, BitcoinNetwork.DEFAULT, Version.VERSION);
public static final String DEFAULT_APP_DATA_DIR = appDataDir(DEFAULT_USER_DATA_DIR, DEFAULT_APP_NAME);
public static final String APP_DATA_DIR_CLEAN_KEY = "app.data.dir.clean";
public static final String DEFAULT_APP_DATA_DIR_CLEAN = "false";
@ -80,6 +80,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
protected final String appName;
protected final String userDataDir;
protected final String appDataDir;
protected final String btcNetworkDir;
protected final String bootstrapNodePort;
public BitsquareEnvironment(OptionSet options) {
@ -87,7 +88,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
}
public BitcoinNetwork getBtcNetworkProperty() {
String dirString = Paths.get(userDataDir, appName, Version.VERSION).toString();
String dirString = Paths.get(userDataDir, appName).toString();
String fileString = Paths.get(dirString, BITCOIN_NETWORK_PROP).toString();
File dir = new File(dirString);
File file = new File(fileString);
@ -114,7 +115,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
}
public void setBitcoinNetwork(BitcoinNetwork bitcoinNetwork) {
String path = Paths.get(userDataDir, appName, Version.VERSION, BITCOIN_NETWORK_PROP).toString();
String path = Paths.get(userDataDir, appName, BITCOIN_NETWORK_PROP).toString();
File file = new File(path);
try (FileOutputStream fos = new FileOutputStream(file)) {
Properties properties = new Properties();
@ -137,7 +138,12 @@ public class BitsquareEnvironment extends StandardEnvironment {
appDataDir = commandLineProperties.containsProperty(APP_DATA_DIR_KEY) ?
(String) commandLineProperties.getProperty(APP_DATA_DIR_KEY) :
appDataDir(userDataDir, appName, getBtcNetworkProperty(), Version.VERSION);
appDataDir(userDataDir, appName);
btcNetworkDir = Paths.get(appDataDir, getBtcNetworkProperty().name().toLowerCase()).toString();
File btcNetworkDirFile = new File(btcNetworkDir);
if (!btcNetworkDirFile.exists())
btcNetworkDirFile.mkdir();
bootstrapNodePort = commandLineProperties.containsProperty(TomP2PModule.BOOTSTRAP_NODE_PORT_KEY) ?
(String) commandLineProperties.getProperty(TomP2PModule.BOOTSTRAP_NODE_PORT_KEY) : "-1";
@ -155,7 +161,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
}
PropertySource<?> appDirProperties() throws Exception {
String location = String.format("file:%s/bitsquare.properties", appDataDir);
String location = String.format("file:%s/bitsquare.properties", btcNetworkDir);
Resource resource = resourceLoader.getResource(location);
if (!resource.exists())
@ -182,19 +188,22 @@ public class BitsquareEnvironment extends StandardEnvironment {
protected PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
private static final long serialVersionUID = -8478089705207326165L;
{
setProperty(APP_DATA_DIR_KEY, appDataDir);
setProperty(APP_DATA_DIR_CLEAN_KEY, DEFAULT_APP_DATA_DIR_CLEAN);
setProperty(APP_NAME_KEY, appName);
setProperty(USER_DATA_DIR_KEY, userDataDir);
setProperty(UserAgent.NAME_KEY, appName);
setProperty(UserAgent.VERSION_KEY, Version.VERSION);
setProperty(WalletService.DIR_KEY, appDataDir);
setProperty(WalletService.DIR_KEY, btcNetworkDir);
setProperty(WalletService.PREFIX_KEY, appName);
setProperty(Storage.DIR_KEY, Paths.get(appDataDir, "db").toString());
setProperty(KeyStorage.DIR_KEY, Paths.get(appDataDir, "keys").toString());
setProperty(Storage.DIR_KEY, Paths.get(btcNetworkDir, "db").toString());
setProperty(KeyStorage.DIR_KEY, Paths.get(btcNetworkDir, "keys").toString());
setProperty(TomP2PModule.BOOTSTRAP_NODE_PORT_KEY, bootstrapNodePort);
}
@ -210,7 +219,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
return Paths.get(System.getProperty("user.home"), ".local", "share").toString();
}
private static String appDataDir(String userDataDir, String appName, BitcoinNetwork bitcoinNetwork, String version) {
return Paths.get(userDataDir, appName, version, bitcoinNetwork.name().toLowerCase()).toString();
private static String appDataDir(String userDataDir, String appName) {
return Paths.get(userDataDir, appName).toString();
}
}

View file

@ -278,8 +278,10 @@ public class WalletService {
public void shutDown() {
if (wallet != null)
wallet.removeEventListener(walletEventListener);
if (walletAppKit != null)
if (walletAppKit != null) {
walletAppKit.stopAsync();
walletAppKit.awaitTerminated();
}
}
public ReadOnlyDoubleProperty downloadPercentageProperty() {

View file

@ -53,7 +53,7 @@ public class Preferences implements Serializable {
}
transient private final Storage<Preferences> storage;
transient private BitsquareEnvironment bitsquareEnvironment;
transient private final BitsquareEnvironment bitsquareEnvironment;
// Persisted fields
private String btcDenomination = MonetaryFormat.CODE_BTC;

View file

@ -21,6 +21,9 @@ import io.bitsquare.common.handlers.ResultHandler;
import org.bitcoinj.utils.Threading;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -32,6 +35,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
@ -39,6 +44,7 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.URI;
import java.net.URLConnection;
import java.util.Timer;
import java.util.TimerTask;
@ -54,7 +60,6 @@ public class Utilities {
private static final Logger log = LoggerFactory.getLogger(Utilities.class);
private static long lastTimeStamp = System.currentTimeMillis();
public static Timer setTimeout(long delay, ResultHandler handler) {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@ -299,4 +304,18 @@ public class Utilities {
}
}
public static String readTextFileFromServer(String url, String userAgent) throws IOException {
URLConnection connection = URI.create(url).toURL().openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setConnectTimeout(10 * 1000);
connection.addRequestProperty("User-Agent", userAgent);
connection.connect();
try (InputStream inputStream = connection.getInputStream();) {
return CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
}