Fix broken preferences path

This commit is contained in:
Manfred Karrer 2014-11-07 00:17:21 +01:00
parent 5d56dc62c9
commit 7049ab3a78
7 changed files with 20 additions and 18 deletions

View file

@ -30,7 +30,7 @@ class MainModule extends BitsquareModule {
private final Stage primaryStage;
public MainModule(String appName, Stage primaryStage) {
super(ConfigLoader.loadConfig());
super(ConfigLoader.loadConfig(appName));
this.appName = appName;
this.primaryStage = primaryStage;
}

View file

@ -140,7 +140,7 @@ public class WalletFacade {
Threading.USER_THREAD = Platform::runLater;
// If seed is non-null it means we are restoring from backup.
walletAppKit = new WalletAppKit(params, AppDirectory.dir().toFile(), appName) {
walletAppKit = new WalletAppKit(params, AppDirectory.dir(appName).toFile(), appName) {
@Override
protected void onSetupCompleted() {
// Don't make the user wait for confirmations for now, as the intention is they're sending it

View file

@ -79,6 +79,7 @@ public class TomP2PNode {
private static final Logger log = LoggerFactory.getLogger(TomP2PNode.class);
private KeyPair keyPair;
private String appName;
private final Boolean useDiskStorage;
private MessageBroker messageBroker;
@ -94,8 +95,10 @@ public class TomP2PNode {
@Inject
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory,
@Named("appName") String appName,
@Named("useDiskStorage") Boolean useDiskStorage) {
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
this.appName = appName;
this.useDiskStorage = useDiskStorage;
}
@ -391,7 +394,7 @@ public class TomP2PNode {
private void useDiscStorage(boolean useDiscStorage) {
if (useDiscStorage) {
File path = new File(AppDirectory.dir().toFile() + "/tomP2P");
File path = new File(AppDirectory.dir(appName).toFile() + "/tomP2P");
if (!path.exists()) {
boolean created = path.mkdir();
if (!created)

View file

@ -57,6 +57,7 @@ public class Persistence {
private final String prefix;
private final File storageFile;
private String appName;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -64,8 +65,9 @@ public class Persistence {
@Inject
public Persistence(@Named("appName") String appName) {
this.prefix = appName + "_pref";
this.storageFile = FileUtil.getFile(prefix, "ser");
this.appName = appName;
this.prefix = appName + "_pref";
this.storageFile = FileUtil.getFile(appName, prefix, "ser");
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -218,7 +220,7 @@ public class Persistence {
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try {
tempFile = FileUtil.getTempFile(prefix);
tempFile = FileUtil.getTempFile(appName, prefix);
// Don't use auto closeable resources in try() as we would need too many try/catch clauses (for tempFile)
// and we need to close it

View file

@ -31,9 +31,10 @@ import lighthouse.files.AppDirectory;
public class ConfigLoader {
private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class);
private static final String configFilePath = AppDirectory.dir() + "/bitsquare.conf";
private static String configFilePath;
public static Properties loadConfig() {
public static Properties loadConfig(String appName) {
configFilePath = AppDirectory.dir(appName) + "/bitsquare.conf";
InputStream inputStream = null;
// load default properties from class path

View file

@ -30,12 +30,12 @@ import lighthouse.files.AppDirectory;
public class FileUtil {
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
public static File getFile(String name, String suffix) {
return new File(AppDirectory.dir().toFile(), name + "." + suffix);
public static File getFile(String appName, String name, String suffix) {
return new File(AppDirectory.dir(appName).toFile(), name + "." + suffix);
}
public static File getTempFile(String prefix) throws IOException {
return File.createTempFile("temp_" + prefix, null, AppDirectory.dir().toFile());
public static File getTempFile(String appName, String prefix) throws IOException {
return File.createTempFile("temp_" + prefix, null, AppDirectory.dir(appName).toFile());
}
public static void writeTempFileToFile(File tempFile, File file) throws IOException {

View file

@ -50,9 +50,7 @@ public class AppDirectory {
}
public static Path initAppDir(String appName) throws IOException {
AppDirectory.appName = appName;
Path dir = dir();
Path dir = dir(appName);
if (!Files.exists(dir))
Files.createDirectory(dir);
else if (!Files.isWritable(dir))
@ -60,11 +58,9 @@ public class AppDirectory {
return dir;
}
private static String appName = "";
private static Path dir;
public static Path dir() {
public static Path dir(String appName) {
if (dir == null)
return getUserDataDir(appName);
else