fix app path

This commit is contained in:
Manfred Karrer 2014-07-08 00:39:23 +02:00
parent 5a04af595b
commit d23a965cdc
13 changed files with 86 additions and 27 deletions

3
.gitignore vendored
View File

@ -2,7 +2,10 @@
/log
/target
/bin
/out
.idea
bitsquare.iml
*.spvchain
*.wallet
*.ser
*.wallet

15
pom.xml
View File

@ -11,6 +11,9 @@
<description>A P2P Fiat-Bitcoin Exchange</description>
<url>https://www.bitsquare.io</url>
<organization>
<name>bitsquare.io</name>
</organization>
<!--
<parent>
<groupId>com.google</groupId>
@ -88,6 +91,7 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -97,7 +101,18 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<mainClass>io.bitsquare.BitSquare</mainClass>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -1,3 +1,3 @@
Manifest-Version: 1.0
Main-Class: io.bitsquare.BitSquare
Main-Class: io.bitsquare.Relay

View File

@ -14,9 +14,11 @@ import io.bitsquare.settings.Settings;
import io.bitsquare.storage.Storage;
import io.bitsquare.user.User;
import io.bitsquare.util.AWTSystemTray;
import io.bitsquare.util.FileUtil;
import io.bitsquare.util.StorageDirectory;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
@ -36,15 +38,15 @@ public class BitSquare extends Application
{
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
public static String ID = "bitsquare";
private static String APP_NAME = "bitsquare";
private static Stage primaryStage;
private WalletFacade walletFacade;
private MessageFacade messageFacade;
public static void main(String[] args)
{
log.debug("Startup: main");
if (args != null && args.length > 0) ID = args[0];
log.debug("Startup: main " + Arrays.asList(args).toString());
if (args != null && args.length > 0) APP_NAME = args[0];
launch(args);
}
@ -54,6 +56,16 @@ public class BitSquare extends Application
return primaryStage;
}
public static String getAppName()
{
return APP_NAME;
}
public static String getUID()
{
return FileUtil.getApplicationFileName();
}
@Override
public void start(Stage primaryStage) throws IOException
{
@ -84,8 +96,7 @@ public class BitSquare extends Application
user.updateFromStorage((User) storage.read(user.getClass().getName()));
settings.updateFromStorage((Settings) storage.read(settings.getClass().getName()));
if (ID.isEmpty()) primaryStage.setTitle("BitSquare");
else primaryStage.setTitle("BitSquare (" + ID + ")");
primaryStage.setTitle("BitSquare (" + getUID() + ")");
GuiceFXMLLoader.setInjector(injector);
@ -119,7 +130,6 @@ public class BitSquare extends Application
scene.setOnKeyReleased(keyEvent -> {
if (keyCodeCombination.match(keyEvent)) AWTSystemTray.setStageHidden();
});
}
private MenuBar getMenuBar()

View File

@ -1,5 +1,8 @@
package io.bitsquare;
import java.io.IOException;
import javafx.application.Application;
import javafx.stage.Stage;
import net.tomp2p.p2p.Peer;
import net.tomp2p.p2p.PeerMaker;
import net.tomp2p.peers.Number160;
@ -8,35 +11,38 @@ import net.tomp2p.peers.PeerMapChangeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Network node for relaying p2p msg
*/
class RelayNode
public class Relay extends Application
{
private static final Logger log = LoggerFactory.getLogger(RelayNode.class);
private static final Logger log = LoggerFactory.getLogger(Relay.class);
private static final Number160 ID = Number160.createHash(1);
private static Peer masterPeer = null;
private static int port;
public static void main(String[] args) throws Exception
public static void main(String[] args)
{
if (args != null && args.length == 1)
{
INSTANCE(new Integer(args[0]));
port = new Integer(args[0]);
}
else
{
INSTANCE(5000);
port = 5000;
}
launch(args);
}
private static void INSTANCE(int port) throws Exception
@Override
public void start(Stage primaryStage) throws IOException
{
log.trace("Startup: start");
if (masterPeer == null)
{
masterPeer = new PeerMaker(ID).setPorts(port).makeAndListen();
// masterPeer = new PeerMaker(ID).setPorts(port).setBagSize(100).makeAndListen(); // setBagSize cause sync problems...
masterPeer.getBroadcastRPC().getConnectionBean().getConnectionReservation().reserve(3).awaitUninterruptibly();
masterPeer.getBroadcastRPC().getConnectionBean().getConnectionReservation().reserve(100).awaitUninterruptibly();
masterPeer.getConnectionHandler().getPeerBean().getPeerMap().addPeerMapChangeListener(new PeerMapChangeListener()
{
@Override
@ -59,4 +65,5 @@ class RelayNode
});
}
}
}

View File

@ -41,7 +41,7 @@ public class WalletFacade
public static final String TEST_NET = "TEST_NET";
public static final String REG_TEST_NET = "REG_TEST_NET";
public static final String WALLET_PREFIX = BitSquare.ID;
public static final String WALLET_PREFIX = BitSquare.getAppName();
private static final Logger log = LoggerFactory.getLogger(WalletFacade.class);

View File

@ -121,7 +121,6 @@
</padding>
<Label text="Trade completed" id="form-header-text"/>
<Label text="Summary:" GridPane.rowIndex="1"/>
<Label text="You have sold (BTC):" GridPane.rowIndex="2"/>
<ValidatedTextField fx:id="summaryPaidTextField" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
@ -129,8 +128,7 @@
<Label text="You have received (EUR):" GridPane.rowIndex="3"/>
<TextField fx:id="summaryReceivedTextField" editable="false" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
<Label text="Details:" GridPane.rowIndex="4"/>
<Label text="Details" GridPane.rowIndex="4" id="form-header-text"/>
<Label text="Total fees (take offer fee + tx fee):" GridPane.rowIndex="5"/>
<TextField fx:id="summaryFeesTextField" editable="false" GridPane.rowIndex="5" GridPane.columnIndex="1"/>

View File

@ -71,11 +71,11 @@ public class MessageFacade
public void init()
{
int port = Bindings.MAX_PORT - Math.abs(new Random().nextInt()) % (Bindings.MAX_PORT - Bindings.MIN_DYN_PORT);
if (BitSquare.ID.contains("taker"))
if (BitSquare.getAppName().contains("taker"))
{
port = 4501;
}
else if (BitSquare.ID.contains("offerer"))
else if (BitSquare.getAppName().contains("offerer"))
{
port = 4500;
}
@ -665,7 +665,7 @@ public class MessageFacade
private void setupStorage()
{
myPeer.getPeerBean().setStorage(new StorageDisk(StorageDirectory.getStorageDirectory().getAbsolutePath() + "/" + BitSquare.ID + "_tomP2P"));
myPeer.getPeerBean().setStorage(new StorageDisk(StorageDirectory.getStorageDirectory().getAbsolutePath() + "/" + BitSquare.getAppName() + "_tomP2P"));
}
private void saveMyAddressToDHT() throws IOException

View File

@ -22,7 +22,7 @@ public class Storage
private static final Logger log = LoggerFactory.getLogger(Storage.class);
private static final ReentrantLock lock = Threading.lock("Storage");
private final String prefix = BitSquare.ID + "_pref";
private final String prefix = BitSquare.getAppName() + "_pref";
private final File storageFile = FileUtil.getFile(prefix, "ser");
@GuardedBy("lock")

View File

@ -1,6 +1,7 @@
package io.bitsquare.util;
import io.bitsquare.BitSquare;
import java.awt.*;
import javafx.application.Platform;
import javafx.stage.Stage;
@ -29,6 +30,9 @@ public class AWTSystemTray
trayIcon.setToolTip("BitSquare P2P Fiat-Bitcoin exchange");
PopupMenu popupMenu = new PopupMenu();
MenuItem aboutItem = new MenuItem("Info about " + BitSquare.getUID());
popupMenu.add(aboutItem);
popupMenu.addSeparator();
showGuiItem = new MenuItem("Close exchange window");
popupMenu.add(showGuiItem);
popupMenu.addSeparator();

View File

@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
public class DSAKeyUtil
{
private static final Logger log = LoggerFactory.getLogger(DSAKeyUtil.class);
private static final String prefix = BitSquare.ID + "_";
private static final String prefix = BitSquare.getAppName() + "_";
private static final ReentrantLock lock = Threading.lock("DSAKeyUtil");

View File

@ -1,5 +1,6 @@
package io.bitsquare.util;
import io.bitsquare.BitSquare;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
@ -20,4 +21,24 @@ public class FileUtil
return File.createTempFile("temp_" + prefix, null, StorageDirectory.getStorageDirectory());
}
public static String getApplicationFileName()
{
File executionRoot = new File(StorageDirectory.class.getProtectionDomain().getCodeSource().getLocation().getFile());
log.trace("getApplicationFileName " + executionRoot.getAbsolutePath());
// check if it is packed into a mac app (e.g.: "/Users/mk/Desktop/bitsquare.app/Contents/Java/bitsquare.jar")
if (executionRoot.getAbsolutePath().endsWith(".app/Contents/Java/bitsquare.jar") && System.getProperty("os.name").startsWith("Mac"))
{
File appFile = executionRoot.getParentFile().getParentFile().getParentFile();
try
{
int lastSlash = appFile.getCanonicalPath().lastIndexOf("/") + 1;
return appFile.getCanonicalPath().substring(lastSlash).replace(".app", "");
} catch (IOException e)
{
e.printStackTrace();
}
}
return BitSquare.getAppName();
}
}

View File

@ -44,7 +44,7 @@ public class StorageDirectory
File executionRoot = new File(StorageDirectory.class.getProtectionDomain().getCodeSource().getLocation().getFile());
log.trace("executionRoot " + executionRoot.getAbsolutePath());
// check if it is packed into a mac app (e.g.: "/Users/mk/Desktop/bitsquare.app/Contents/Java/bitsquare.jar")
if (executionRoot.getAbsolutePath().endsWith("/bitsquare.app/Contents/Java/bitsquare.jar") && System.getProperty("os.name").startsWith("Mac"))
if (executionRoot.getAbsolutePath().endsWith(".app/Contents/Java/bitsquare.jar") && System.getProperty("os.name").startsWith("Mac"))
return executionRoot.getParentFile().getParentFile().getParentFile().getParentFile();
else if (executionRoot.getAbsolutePath().endsWith("/target/classes"))
return executionRoot.getParentFile(); // dev e.g.: /Users/mk/Documents/_intellij/bitsquare/target/classes -> use target as root
@ -54,6 +54,7 @@ public class StorageDirectory
return executionRoot;
}
public static File getSystemApplicationDataDirectory()
{
String osName = System.getProperty("os.name");