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 /log
/target /target
/bin /bin
/out
.idea .idea
bitsquare.iml bitsquare.iml
*.spvchain *.spvchain
*.wallet *.wallet
*.ser
*.wallet

15
pom.xml
View file

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

View file

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

View file

@ -1,5 +1,8 @@
package io.bitsquare; package io.bitsquare;
import java.io.IOException;
import javafx.application.Application;
import javafx.stage.Stage;
import net.tomp2p.p2p.Peer; import net.tomp2p.p2p.Peer;
import net.tomp2p.p2p.PeerMaker; import net.tomp2p.p2p.PeerMaker;
import net.tomp2p.peers.Number160; import net.tomp2p.peers.Number160;
@ -8,35 +11,38 @@ import net.tomp2p.peers.PeerMapChangeListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* Network node for relaying p2p msg public class Relay extends Application
*/
class RelayNode
{ {
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 final Number160 ID = Number160.createHash(1);
private static Peer masterPeer = null; 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) if (args != null && args.length == 1)
{ {
INSTANCE(new Integer(args[0])); port = new Integer(args[0]);
} }
else 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) if (masterPeer == null)
{ {
masterPeer = new PeerMaker(ID).setPorts(port).makeAndListen(); masterPeer = new PeerMaker(ID).setPorts(port).makeAndListen();
// masterPeer = new PeerMaker(ID).setPorts(port).setBagSize(100).makeAndListen(); // setBagSize cause sync problems... // 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() masterPeer.getConnectionHandler().getPeerBean().getPeerMap().addPeerMapChangeListener(new PeerMapChangeListener()
{ {
@Override @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 TEST_NET = "TEST_NET";
public static final String REG_TEST_NET = "REG_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); private static final Logger log = LoggerFactory.getLogger(WalletFacade.class);

View file

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

View file

@ -71,11 +71,11 @@ public class MessageFacade
public void init() public void init()
{ {
int port = Bindings.MAX_PORT - Math.abs(new Random().nextInt()) % (Bindings.MAX_PORT - Bindings.MIN_DYN_PORT); 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; port = 4501;
} }
else if (BitSquare.ID.contains("offerer")) else if (BitSquare.getAppName().contains("offerer"))
{ {
port = 4500; port = 4500;
} }
@ -665,7 +665,7 @@ public class MessageFacade
private void setupStorage() 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 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 Logger log = LoggerFactory.getLogger(Storage.class);
private static final ReentrantLock lock = Threading.lock("Storage"); 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"); private final File storageFile = FileUtil.getFile(prefix, "ser");
@GuardedBy("lock") @GuardedBy("lock")

View file

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

View file

@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
public class DSAKeyUtil public class DSAKeyUtil
{ {
private static final Logger log = LoggerFactory.getLogger(DSAKeyUtil.class); 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"); private static final ReentrantLock lock = Threading.lock("DSAKeyUtil");

View file

@ -1,5 +1,6 @@
package io.bitsquare.util; package io.bitsquare.util;
import io.bitsquare.BitSquare;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -20,4 +21,24 @@ public class FileUtil
return File.createTempFile("temp_" + prefix, null, StorageDirectory.getStorageDirectory()); 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()); File executionRoot = new File(StorageDirectory.class.getProtectionDomain().getCodeSource().getLocation().getFile());
log.trace("executionRoot " + executionRoot.getAbsolutePath()); 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") // 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(); return executionRoot.getParentFile().getParentFile().getParentFile().getParentFile();
else if (executionRoot.getAbsolutePath().endsWith("/target/classes")) else if (executionRoot.getAbsolutePath().endsWith("/target/classes"))
return executionRoot.getParentFile(); // dev e.g.: /Users/mk/Documents/_intellij/bitsquare/target/classes -> use target as root 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; return executionRoot;
} }
public static File getSystemApplicationDataDirectory() public static File getSystemApplicationDataDirectory()
{ {
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");