diff --git a/app-core/pom.xml b/app-core/pom.xml
index e6f06c66..9906e445 100644
--- a/app-core/pom.xml
+++ b/app-core/pom.xml
@@ -39,6 +39,14 @@
commons-io
commons-io
+
+ io.reactivex
+ rxjava
+
+
+ com.google.code.gson
+ gson
+
junit
junit
diff --git a/app-core/src/main/java/com/mercury/platform/core/AppStarter.java b/app-core/src/main/java/com/mercury/platform/core/AppStarter.java
index 00e4d658..f9cb631b 100644
--- a/app-core/src/main/java/com/mercury/platform/core/AppStarter.java
+++ b/app-core/src/main/java/com/mercury/platform/core/AppStarter.java
@@ -4,13 +4,18 @@
import com.mercury.platform.core.update.UpdateClientStarter;
import com.mercury.platform.core.utils.error.ErrorHandler;
import com.mercury.platform.shared.ConfigManager;
-import com.mercury.platform.shared.FrameStates;
+import com.mercury.platform.shared.FrameVisibleState;
import com.mercury.platform.shared.HistoryManager;
import com.mercury.platform.shared.UpdateManager;
+import com.mercury.platform.shared.config.BaseConfigManager;
+import com.mercury.platform.shared.config.Configuration;
+import com.mercury.platform.shared.config.MercuryDataSource;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
+import com.mercury.platform.shared.store.MercuryStore;
import com.sun.jna.Native;
import com.sun.jna.PointerType;
+import com.sun.jna.platform.win32.WinDef;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -19,18 +24,20 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
-/**
- * Created by Константин on 31.12.2016.
- */
public class AppStarter {
private static final Logger logger = LogManager.getLogger(AppStarter.class.getSimpleName());
- public static FrameStates APP_STATUS = FrameStates.HIDE;
+ public static FrameVisibleState APP_STATUS = FrameVisibleState.HIDE;
+ public static WinDef.HWND poeWindow;
private User32 user32 = User32.INSTANCE;
private boolean shutdown = false;
private volatile int delay = 100;
private boolean updating = false;
public void startApplication(){
+ BaseConfigManager configuration = new BaseConfigManager(new MercuryDataSource());
+ configuration.load();
+ Configuration.set(configuration);
+
ConfigManager.INSTANCE.load();
new SoundNotifier();
new ChatHelper();
@@ -40,8 +47,9 @@ public void startApplication(){
UpdateClientStarter updateClientStarter = new UpdateClientStarter();
executor.execute(updateClientStarter);
HistoryManager.INSTANCE.load();
+ UpdateManager updateManager = new UpdateManager();
- EventRouter.CORE.registerHandler(UILoadedEvent.class, event -> {
+ MercuryStore.INSTANCE.uiLoadedSubject.subscribe(state -> {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
@@ -50,27 +58,28 @@ public void run() {
timer.cancel();
updateClientStarter.shutdown();
if(updating){
- UpdateManager.INSTANCE.doUpdate();
+ updateManager.doUpdate();
}
System.exit(0);
}
- byte[] windowText = new byte[512];
- PointerType hwnd = user32.GetForegroundWindow();
- User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512);
- if(!Native.toString(windowText).equals("Path of Exile")){
- if(APP_STATUS == FrameStates.SHOW) {
- APP_STATUS = FrameStates.HIDE;
- EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.HIDE));
+ byte[] className = new byte[512];
+ WinDef.HWND hwnd = user32.GetForegroundWindow();
+ User32.INSTANCE.GetClassNameA(hwnd, className, 512);
+ if(!Native.toString(className).equals("POEWindowClass")){
+ if(APP_STATUS == FrameVisibleState.SHOW) {
+ APP_STATUS = FrameVisibleState.HIDE;
+ MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.HIDE);
}
}else{
- if(APP_STATUS == FrameStates.HIDE) {
+ poeWindow = hwnd;
+ if(APP_STATUS == FrameVisibleState.HIDE) {
try {
Thread.sleep(delay);
delay = 100;
} catch (InterruptedException e) {
}
- APP_STATUS = FrameStates.SHOW;
- EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.SHOW));
+ APP_STATUS = FrameVisibleState.SHOW;
+ MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.SHOW);
}
}
}
diff --git a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
index 16b08cdb..345a614d 100644
--- a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
+++ b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
@@ -2,24 +2,14 @@
import com.mercury.platform.shared.ConfigManager;
import com.mercury.platform.shared.HasEventHandlers;
-import com.mercury.platform.shared.events.EventRouter;
-import com.mercury.platform.shared.events.custom.ChatCommandEvent;
-import com.mercury.platform.shared.events.custom.DndModeEvent;
-import com.mercury.platform.shared.events.custom.OpenChatEvent;
-import com.sun.jna.Native;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import com.mercury.platform.shared.store.MercuryStore;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
-import java.util.*;
-import java.util.List;
public class ChatHelper implements HasEventHandlers {
- private final Logger logger = LogManager.getLogger(ChatHelper.class.getSimpleName());
- private User32 user32 = User32.INSTANCE;
private Robot robot;
public ChatHelper() {
@@ -36,8 +26,6 @@ private void executeMessage(String message) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);
- gameToFront();
-
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
@@ -57,8 +45,6 @@ private void executeMessage(String message) {
robot.keyRelease(KeyEvent.VK_ENTER);
}
private void openChat(String whisper) {
- gameToFront();
-
StringSelection selection = new StringSelection("@" + whisper);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
@@ -81,40 +67,14 @@ private void openChat(String whisper) {
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
}
- /**
- * NEED REFACTORING
- */
- private void gameToFront(){
- List titles = new ArrayList<>();
- titles.add("Path of Exile");
- user32.EnumWindows((hWnd, arg1) -> {
- byte[] windowText = new byte[512];
- user32.GetWindowTextA(hWnd, windowText, 512);
- String wText = Native.toString(windowText);
-
- if (wText.isEmpty()) {
- return true;
- }
- if (titles.contains(wText)) {
- user32.SetForegroundWindow(hWnd);
- return false;
- }
- return true;
- }, null);
- }
@Override
public void initHandlers() {
- EventRouter.CORE.registerHandler(ChatCommandEvent.class, event
- -> executeMessage(((ChatCommandEvent)event).getMessage()));
-
- EventRouter.CORE.registerHandler(OpenChatEvent.class, event -> {
- openChat(((OpenChatEvent) event).getWhisper());
- });
- EventRouter.CORE.registerHandler(DndModeEvent.class, event -> {
- boolean dnd = ((DndModeEvent) event).isDnd();
+ MercuryStore.INSTANCE.chatCommandSubject.subscribe(this::executeMessage);
+ MercuryStore.INSTANCE.openChatSubject.subscribe(this::openChat);
+ MercuryStore.INSTANCE.dndSubject.subscribe(state -> {
if(ConfigManager.INSTANCE.isInGameDnd()){
- if(dnd) {
+ if(state) {
executeMessage("/dnd " + ConfigManager.INSTANCE.getDndResponseText());
}else {
executeMessage("/dnd");
diff --git a/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java b/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java
index e6522f55..93e1aa94 100644
--- a/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java
+++ b/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java
@@ -1,7 +1,7 @@
package com.mercury.platform.core;
public class MercuryConstants {
- public static final String APP_VERSION = "1.0.1.2";
+ public static final String APP_VERSION = "1.0.1.3";
public static final String SERVER_HOST = "exslims.ddns.net";
public static final int PORT = 5555;
}
diff --git a/app-core/src/main/java/com/mercury/platform/core/User32.java b/app-core/src/main/java/com/mercury/platform/core/User32.java
index 9805511f..f7219e01 100644
--- a/app-core/src/main/java/com/mercury/platform/core/User32.java
+++ b/app-core/src/main/java/com/mercury/platform/core/User32.java
@@ -14,6 +14,7 @@
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
+ int GetClassNameA(WinDef.HWND hwnd, byte[] lpString,int nMaxCount);
WinDef.HWND SetFocus(WinDef.HWND hWnd);
int GetWindowTextA(WinDef.HWND hWnd, byte[] lpString, int nMaxCount);
int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount);
diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java
index b69d2a76..5bffeb13 100644
--- a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java
+++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java
@@ -1,10 +1,9 @@
package com.mercury.platform.core.misc;
-import com.mercury.platform.core.AppStarter;
-import com.mercury.platform.shared.ConfigManager;
-import com.mercury.platform.shared.FrameStates;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
+import com.mercury.platform.shared.store.DataTransformers;
+import com.mercury.platform.shared.store.MercuryStore;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -12,46 +11,31 @@
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
-import java.util.Random;
public class SoundNotifier {
private final Logger logger = LogManager.getLogger(SoundNotifier.class);
private boolean dnd = false;
public SoundNotifier() {
- EventRouter.CORE.registerHandler(WhisperNotificationEvent.class, event -> {
- WhisperNotifierStatus status = ConfigManager.INSTANCE.getWhisperNotifier();
- if (status == WhisperNotifierStatus.ALWAYS ||
- ((status == WhisperNotifierStatus.ALTAB) && (AppStarter.APP_STATUS == FrameStates.HIDE))) {
- play("app/notification.wav");
- }
- });
- EventRouter.CORE.registerHandler(UpdateInfoEvent.class, event -> {
- play("app/patch_tone.wav");
- });
- EventRouter.CORE.registerHandler(ChatFilterMessageEvent.class, event -> {
- play("app/chat-filter.wav");
- });
- EventRouter.CORE.registerHandler(DndModeEvent.class, event -> {
- this.dnd = ((DndModeEvent)event).isDnd();
- });
- EventRouter.CORE.registerHandler(ButtonPressedEvent.class, event -> {
- String[] clicks = {
- "app/sounds/click1/button-pressed-10.wav",
- "app/sounds/click1/button-pressed-20.wav",
- "app/sounds/click1/button-pressed-30.wav"};
- play(clicks[new Random().nextInt(3)]);
- });
+ MercuryStore.INSTANCE.soundSubject
+ .compose(DataTransformers.transformSoundData())
+ .subscribe(data -> play(data.getWavPath(), data.getDb()));
+ MercuryStore.INSTANCE.soundSettingsSubject
+ .subscribe(data -> play(data.getWavPath(), data.getDb()));
+ MercuryStore.INSTANCE.dndSubject
+ .subscribe(value -> this.dnd = value);
}
- private void play(String wavPath){
- if(!dnd) {
+ private void play(String wavPath, float db){
+ if(!dnd && db > -40) {
ClassLoader classLoader = getClass().getClassLoader();
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
Clip clip = AudioSystem.getClip();
clip.open(stream);
- FloatControl gainControl =
- (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
- gainControl.setValue(-5.0f);
+ if(db != 0.0) {
+ FloatControl gainControl =
+ (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
+ gainControl.setValue(db);
+ }
clip.start();
} catch (Exception e) {
logger.error("Cannot start playing wav file: ",e);
diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java
new file mode 100644
index 00000000..72d214e0
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java
@@ -0,0 +1,6 @@
+package com.mercury.platform.core.misc;
+
+
+public enum SoundType {
+ MESSAGE,UPDATE,CHAT_SCANNER,CLICKS
+}
diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java
index 1315b6d9..b355e1aa 100644
--- a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java
+++ b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java
@@ -1,10 +1,12 @@
package com.mercury.platform.core.update.core.handlers;
+import com.mercury.platform.core.misc.SoundType;
import com.mercury.platform.core.update.core.holder.ApplicationHolder;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.AlertEvent;
import com.mercury.platform.shared.events.custom.ShowPatchNotesEvent;
import com.mercury.platform.shared.events.custom.UpdateInfoEvent;
+import com.mercury.platform.shared.store.MercuryStore;
import com.mercury.platform.update.AlreadyLatestUpdateMessage;
import com.mercury.platform.update.PatchNotesDescriptor;
import com.mercury.platform.update.UpdateDescriptor;
@@ -19,8 +21,8 @@ public void process(Object object){
EventRouter.CORE.fireEvent(new ShowPatchNotesEvent(notes));
}
if(object instanceof UpdateDescriptor){
- int nextVersion = ((UpdateDescriptor) object).getVersion();
- EventRouter.CORE.fireEvent(new UpdateInfoEvent(nextVersion));
+ MercuryStore.INSTANCE.soundSubject.onNext(SoundType.UPDATE);
+ EventRouter.CORE.fireEvent(new UpdateInfoEvent(((UpdateDescriptor) object).getVersion()));
}
if(object instanceof AlreadyLatestUpdateMessage){
if(ApplicationHolder.getInstance().isManualRequest()) {
diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java
index e701451f..94ea7119 100644
--- a/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java
+++ b/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java
@@ -4,6 +4,7 @@
import com.mercury.platform.shared.HasEventHandlers;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
+import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -81,12 +82,12 @@ public void parse() {
@Override
public void initHandlers() {
- EventRouter.CORE.registerHandler(AddInterceptorEvent.class, event -> {
- interceptors.add(((AddInterceptorEvent) event).getInterceptor());
+ MercuryStore.INSTANCE.addInterceptorSubject.subscribe(interceptor -> {
+ interceptors.add(interceptor);
lastMessageDate = new Date();
});
- EventRouter.CORE.registerHandler(RemoveInterceptorEvent.class, event -> {
- interceptors.remove(((RemoveInterceptorEvent) event).getInterceptor());
+ MercuryStore.INSTANCE.removeInterceptorSubject.subscribe(interceptor -> {
+ interceptors.remove(interceptor);
});
}
}
diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java
index 3de7fef7..61a8d618 100644
--- a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java
+++ b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java
@@ -1,7 +1,6 @@
package com.mercury.platform.core.utils.error;
-import com.mercury.platform.shared.events.EventRouter;
-import com.mercury.platform.shared.events.custom.HideLoadingFrame;
+import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -10,7 +9,7 @@ public class ErrorHandler {
private Logger logger = LogManager.getLogger(ErrorHandler.class.getSimpleName());
public ErrorHandler(){
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
- EventRouter.CORE.fireEvent(new HideLoadingFrame());
+ MercuryStore.INSTANCE.appLoadingSubject.onNext(false);
logger.error(ExceptionUtils.getStackTrace(throwable));
});
}
diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java
index e1534595..5944dff8 100644
--- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java
+++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java
@@ -1,16 +1,12 @@
package com.mercury.platform.core.utils.interceptor;
+import com.mercury.platform.core.misc.SoundType;
import com.mercury.platform.core.utils.interceptor.filter.MessageFilter;
import com.mercury.platform.shared.MessageParser;
-import com.mercury.platform.shared.events.EventRouter;
-import com.mercury.platform.shared.events.custom.NewWhispersEvent;
-import com.mercury.platform.shared.events.custom.WhisperNotificationEvent;
-import com.mercury.platform.shared.pojo.Message;
+import com.mercury.platform.shared.entity.Message;
+import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.StringUtils;
-/**
- * Created by Константин on 11.01.2017.
- */
public class IncTradeMessagesInterceptor extends MessageInterceptor {
private MessageParser messageParser = new MessageParser();
@@ -18,8 +14,8 @@ public class IncTradeMessagesInterceptor extends MessageInterceptor {
protected void process(String message) {
Message parsedMessage = messageParser.parse(StringUtils.substringAfter(message,"@"));
if(parsedMessage != null) {
- EventRouter.CORE.fireEvent(new WhisperNotificationEvent());
- EventRouter.CORE.fireEvent(new NewWhispersEvent(parsedMessage));
+ MercuryStore.INSTANCE.soundSubject.onNext(SoundType.MESSAGE);
+ MercuryStore.INSTANCE.messageSubject.onNext(parsedMessage);
}
}
diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java
index 93f5126e..22c562a2 100644
--- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java
+++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java
@@ -4,7 +4,7 @@
import com.mercury.platform.shared.MessageParser;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.OutTradeMessageEvent;
-import com.mercury.platform.shared.pojo.Message;
+import com.mercury.platform.shared.entity.Message;
/**
* Created by Константин on 12.01.2017.
diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java
new file mode 100644
index 00000000..570e012f
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java
@@ -0,0 +1,61 @@
+package com.mercury.platform.experimental;
+
+import rx.Observable;
+import rx.Subscriber;
+import rx.functions.Action1;
+
+/**
+ * Created by Константин on 07.04.2017.
+ */
+public class RxJavaBasic {
+ public static void main(String[] args) {
+ method5();
+ }
+ public static void method1(){
+ Observable observable = Observable.create(subscriber -> {
+ subscriber.onNext("Hello World!");
+ subscriber.onCompleted();
+ });
+
+ Subscriber subscriber = new Subscriber() {
+ @Override
+ public void onCompleted() {
+
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+
+ }
+
+ @Override
+ public void onNext(String s) {
+ System.out.println(s);
+ }
+ };
+ observable.subscribe(subscriber);
+ }
+ public static void method2(){
+ Observable observable = Observable.just("Hello world");
+ Action1 onNextAction = System.out::println;
+ observable.subscribe(onNextAction);
+ }
+ public static void method3(){
+ Observable.just("Hello world").subscribe(System.out::println);
+ }
+
+ //Operators
+ public static void method4(){
+ Observable.just("Hello world").map(s -> s + " -Dan").subscribe(System.out::println);
+ }
+ public static void method5(){
+ Observable.just("Hello world")
+ .map(s -> s + " -Dan")
+ .map(String::hashCode)
+ .map(i -> Integer.toString(i))
+ .subscribe(System.out::println);
+ }
+ public static void method6(){
+ Observable.just("Hello world").subscribe(System.out::println);
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java
new file mode 100644
index 00000000..3a7b1077
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java
@@ -0,0 +1,22 @@
+package com.mercury.platform.experimental;
+
+/**
+ * Created by Константин on 07.04.2017.
+ */
+public class RxJavaOperators {
+ public static void main(String[] args) {
+
+ }
+ public static void method1(){
+
+ }
+ public static void method2(){
+
+ }
+ public static void method3(){
+
+ }
+ public static void method4(){
+
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java
index 1dde8c05..36444741 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java
@@ -1,10 +1,9 @@
package com.mercury.platform.shared;
import com.mercury.platform.core.misc.WhisperNotifierStatus;
-import com.mercury.platform.shared.pojo.FrameSettings;
-import com.mercury.platform.shared.pojo.ResponseButton;
-import com.mercury.platform.shared.pojo.ScaleData;
-import com.mercury.platform.shared.pojo.StashTab;
+import com.mercury.platform.shared.entity.FrameSettings;
+import com.mercury.platform.shared.entity.ResponseButton;
+import com.mercury.platform.shared.entity.StashTab;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
@@ -23,6 +22,7 @@
*/
//todo generalization
@SuppressWarnings("unchecked")
+@Deprecated
public class ConfigManager {
private Logger logger = LogManager.getLogger(ConfigManager.class);
@@ -38,7 +38,6 @@ private static class ConfigManagerHolder {
private List cachedButtonsConfig;
private Map cachedFramesSettings;
private Map minimumFrameSize;
- private Map defaultFramesSettings;
private Map defaultAppSettings;
@Getter
@@ -69,7 +68,7 @@ private static class ConfigManagerHolder {
@Getter
private boolean checkUpdateOnStartUp = true;
@Getter
- private boolean dismissAfterKick = false;
+ private boolean dismissAfterKick = true;
@Getter
private boolean showLeague = false;
@Getter
@@ -78,17 +77,19 @@ private static class ConfigManagerHolder {
private String dndResponseText = "Response text";
@Getter
private String defaultWords = "!wtb, uber, boss, perandus";
+ @Getter
+ private String quickResponse = "invite me pls";
public ConfigManager() {
minimumFrameSize = new HashMap<>();
minimumFrameSize.put("TaskBarFrame",new Dimension(109,20));
- minimumFrameSize.put("IncMessageFrame",new Dimension(315,10));
+ minimumFrameSize.put("IncMessageFrame",new Dimension(360,10));
minimumFrameSize.put("OutMessageFrame",new Dimension(280,115));
minimumFrameSize.put("TestCasesFrame",new Dimension(400,100));
minimumFrameSize.put("SettingsFrame",new Dimension(540,400));
minimumFrameSize.put("HistoryFrame",new Dimension(280,400));
minimumFrameSize.put("TimerFrame",new Dimension(240,102));
- minimumFrameSize.put("ChatFilterFrame",new Dimension(400,200));
+ minimumFrameSize.put("ChatFilterFrame",new Dimension(400,100));
minimumFrameSize.put("ItemsGridFrame",new Dimension(150,150));
minimumFrameSize.put("NotesFrame",new Dimension(540,100));
minimumFrameSize.put("ChatFilterSettingsFrame",new Dimension(300,200));
@@ -114,6 +115,7 @@ public ConfigManager() {
defaultAppSettings.put("showLeague",false);
defaultAppSettings.put("dndResponseText","Response text");
defaultAppSettings.put("defaultWords","!wtb, uber, boss, perandus");
+ defaultAppSettings.put("quickResponse","invite me pls");
}
@@ -158,8 +160,9 @@ public void load() {
saveProperty("inGameDnd", String.valueOf(defaultAppSettings.get("inGameDnd")));
saveProperty("dndResponseText", defaultAppSettings.get("dndResponseText"));
saveProperty("defaultWords", defaultAppSettings.get("defaultWords"));
+ saveProperty("quickResponse", defaultAppSettings.get("quickResponse"));
saveProperty("scaleData", defaultAppSettings.get("scaleData"));
- saveProperty("showLeague", defaultAppSettings.get("showLeague"));
+ saveProperty("showLeague", String.valueOf(defaultAppSettings.get("showLeague")));
} catch (Exception e) {
logger.error(e);
@@ -219,6 +222,7 @@ private void loadConfigFile(){
showLeague = Boolean.valueOf(loadProperty("showLeague"));
dndResponseText = loadProperty("dndResponseText");
defaultWords = loadProperty("defaultWords");
+ quickResponse = loadProperty("quickResponse");
} catch (Exception e) {
logger.error("Error in loadConfigFile: ",e);
}
@@ -257,8 +261,9 @@ private String loadProperty(String key){
}
}catch (Exception e){
logger.error("Error while loading property: " + key,e);
+ saveProperty(key,String.valueOf(defaultAppSettings.get(key)));
+ return String.valueOf(defaultAppSettings.get(key));
}
- return null;
}
private void saveProperty(String token, T object){
JSONParser parser = new JSONParser();
@@ -275,7 +280,7 @@ private void saveProperty(String token, T object){
fileWriter.flush();
fileWriter.close();
} catch (Exception e) {
- logger.error("Error in ConfigManager.saveProperty",e);
+ logger.error("Error in ConfigManager.saveProperty with \"" + token + "\" token.",e);
}
}
@@ -394,7 +399,6 @@ public Map getScaleData(){
return scaleData;
}
-
public void setCheckUpdateOnStartUp(boolean checkUpdateOnStartUp) {
this.checkUpdateOnStartUp = checkUpdateOnStartUp;
saveProperty("checkUpdateOnStartUp", String.valueOf(this.checkUpdateOnStartUp));
@@ -436,10 +440,6 @@ public void setFlowDirection(String flowDirection) {
this.flowDirection = flowDirection;
saveProperty("flowDirection",flowDirection);
}
- public void setTradeMode(String tradeMode) {
- this.tradeMode = tradeMode;
- saveProperty("tradeMode",tradeMode);
- }
public void setLimitMsgCount(int limitMsgCount) {
this.limitMsgCount = limitMsgCount;
saveProperty("limitMsgCount",String.valueOf(this.limitMsgCount));
@@ -470,6 +470,10 @@ public void setDefaultWords(String defaultWords) {
this.defaultWords = defaultWords;
saveProperty("defaultWords",defaultWords);
}
+ public void setQuickResponse(String quickResponse) {
+ this.quickResponse = quickResponse;
+ saveProperty("quickResponse",quickResponse);
+ }
private List getDefaultButtons(){
List defaultButtons = new ArrayList<>();
@@ -480,7 +484,7 @@ private List getDefaultButtons(){
return defaultButtons;
}
public Map getDefaultFramesSettings(){
- defaultFramesSettings = new HashMap<>();
+ Map defaultFramesSettings = new HashMap<>();
defaultFramesSettings.put("TaskBarFrame",new FrameSettings(new Point(400, 500),new Dimension(109,20)));
defaultFramesSettings.put("IncMessageFrame",new FrameSettings(new Point(700, 600),new Dimension(315,0)));
defaultFramesSettings.put("OutMessageFrame",new FrameSettings(new Point(200, 500),new Dimension(280,115)));
diff --git a/app-core/src/main/java/com/mercury/platform/shared/FrameStates.java b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java
similarity index 77%
rename from app-core/src/main/java/com/mercury/platform/shared/FrameStates.java
rename to app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java
index 468805a8..d5286d9f 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/FrameStates.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java
@@ -3,6 +3,6 @@
/**
* Created by Константин on 09.12.2016.
*/
-public enum FrameStates {
+public enum FrameVisibleState {
SHOW,HIDE
}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java b/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java
index 2d5716ff..93f3fcef 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java
@@ -1,21 +1,17 @@
package com.mercury.platform.shared;
-import com.mercury.platform.shared.pojo.Message;
+import com.mercury.platform.shared.entity.Message;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
/**
* Created by Константин on 11.02.2017.
diff --git a/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java b/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java
index 8965983e..fa47eb48 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java
@@ -1,8 +1,8 @@
package com.mercury.platform.shared;
-import com.mercury.platform.shared.pojo.CurrencyMessage;
-import com.mercury.platform.shared.pojo.ItemMessage;
-import com.mercury.platform.shared.pojo.Message;
+import com.mercury.platform.shared.entity.CurrencyMessage;
+import com.mercury.platform.shared.entity.ItemMessage;
+import com.mercury.platform.shared.entity.Message;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
diff --git a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java
index a6f726e7..c06d0100 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java
@@ -6,24 +6,17 @@
import java.io.File;
-/**
- * Created by Константин on 21.02.2017.
- */
public class UpdateManager {
private final static Logger logger = LogManager.getLogger(UpdateManager.class.getSimpleName());
private final static String LOCAL_UPDATER_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\local-updater.jar";
private static final String JAR_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp\\MercuryTrade.jar";
- private static class UpdateManagerHolder {
- static final UpdateManager HOLDER_INSTANCE = new UpdateManager();
- }
- public static UpdateManager INSTANCE = UpdateManagerHolder.HOLDER_INSTANCE;
-
public void doUpdate(){
try {
String path = StringUtils.substringAfter(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath(), "/");
logger.debug("Execute local updater, source path: {}",path);
if(new File(JAR_FILE_PATH).exists()) {
Runtime.getRuntime().exec("java -jar " + LOCAL_UPDATER_PATH + " " + "\"" + path + "\"");
+ System.exit(0);
}
} catch (Exception e1) {
logger.error("Error while execute local-updater: ", e1);
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java
new file mode 100644
index 00000000..9215f68f
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java
@@ -0,0 +1,49 @@
+package com.mercury.platform.shared.config;
+
+import com.mercury.platform.shared.config.service.ConfigurationService;
+import com.mercury.platform.shared.config.service.FramesConfigurationService;
+import com.mercury.platform.shared.config.service.SoundConfigurationService;
+import com.mercury.platform.shared.entity.FrameSettings;
+import com.mercury.platform.shared.entity.SoundDescriptor;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+
+
+public class BaseConfigManager implements ConfigManager {
+ private Logger logger = LogManager.getLogger(BaseConfigManager.class.getSimpleName());
+
+ private DataSource dataSource;
+ private ConfigurationService framesConfigurationService;
+ private ConfigurationService soundConfigurationService;
+
+ public BaseConfigManager(DataSource dataSource){
+ this.dataSource = dataSource;
+
+ this.framesConfigurationService = new FramesConfigurationService(dataSource);
+ this.soundConfigurationService = new SoundConfigurationService(dataSource);
+ }
+ @Override
+ public ConfigurationService framesConfiguration() {
+ return framesConfigurationService;
+ }
+ @Override
+ public ConfigurationService soundConfiguration() {
+ return soundConfigurationService;
+ }
+ public void load(){
+ try {
+ File file = new File(dataSource.getConfigurationFilePath());
+
+ if(!file.exists()){
+ file.createNewFile();
+ }
+ this.framesConfigurationService.load();
+ this.soundConfigurationService.load();
+ }catch (IOException e) {
+ logger.error("Error while processing file:{}",dataSource.getConfigurationFilePath(),e);
+ }
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java
new file mode 100644
index 00000000..3ca29bda
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java
@@ -0,0 +1,11 @@
+package com.mercury.platform.shared.config;
+
+import com.mercury.platform.shared.config.service.ConfigurationService;
+import com.mercury.platform.shared.entity.FrameSettings;
+import com.mercury.platform.shared.entity.SoundDescriptor;
+
+
+public interface ConfigManager {
+ ConfigurationService framesConfiguration();
+ ConfigurationService soundConfiguration();
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java
new file mode 100644
index 00000000..7e80bf6b
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java
@@ -0,0 +1,12 @@
+package com.mercury.platform.shared.config;
+
+public class Configuration {
+ private static ConfigManager configManager;
+
+ public static ConfigManager get() {
+ return configManager;
+ }
+ public static void set(ConfigManager configManager){
+ Configuration.configManager = configManager;
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java b/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java
new file mode 100644
index 00000000..515a88ca
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java
@@ -0,0 +1,10 @@
+package com.mercury.platform.shared.config;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public abstract class DataSource {
+ private String configurationFilePath;
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java b/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java
new file mode 100644
index 00000000..536016f5
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java
@@ -0,0 +1,53 @@
+package com.mercury.platform.shared.config;
+
+import com.google.gson.*;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Map;
+
+public class JSONHelper {
+ private Logger logger = LogManager.getLogger(JSONHelper.class.getSimpleName());
+ private DataSource dataSource;
+
+ public JSONHelper(DataSource dataSource){
+ this.dataSource = dataSource;
+ }
+ public T readMapData(String key,TypeToken typeToken){
+ try {
+ Gson gson = new Gson();
+ JsonParser jsonParser = new JsonParser();
+ try(JsonReader reader = new JsonReader(new FileReader(dataSource.getConfigurationFilePath()))) {
+ return gson.fromJson(
+ jsonParser.parse(reader)
+ .getAsJsonObject()
+ .get(key),
+ typeToken.getType());
+ }
+ }catch (IOException e){
+ logger.error(e);
+ return null;
+ }catch (IllegalStateException e1) {
+ return null;
+ }
+ }
+ public void writeMapObject(String key, Map,?> object){
+ try {
+ Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create();
+
+ try(JsonWriter writer = new JsonWriter(new FileWriter(dataSource.getConfigurationFilePath()))) {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add(key,gson.toJsonTree(object));
+ gson.toJson(jsonObject,writer);
+ }
+ }catch (IOException e){
+ logger.error(e);
+ }
+
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java
new file mode 100644
index 00000000..5cbb6e49
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java
@@ -0,0 +1,10 @@
+package com.mercury.platform.shared.config;
+
+/**
+ * Created by Константин on 08.04.2017.
+ */
+public class MercuryDataSource extends DataSource {
+ public MercuryDataSource() {
+ super(System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\configuration.json");
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java
new file mode 100644
index 00000000..6c97fa1b
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java
@@ -0,0 +1,15 @@
+package com.mercury.platform.shared.config.service;
+
+import com.mercury.platform.shared.config.DataSource;
+import com.mercury.platform.shared.config.JSONHelper;
+
+
+public abstract class BaseConfigurationService implements ConfigurationService{
+ protected DataSource dataSource;
+ protected JSONHelper jsonHelper;
+
+ protected BaseConfigurationService(DataSource dataSource){
+ this.dataSource = dataSource;
+ this.jsonHelper = new JSONHelper(dataSource);
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java
new file mode 100644
index 00000000..ecfca38c
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java
@@ -0,0 +1,12 @@
+package com.mercury.platform.shared.config.service;
+
+
+import java.io.IOException;
+import java.util.Map;
+
+public interface ConfigurationService {
+ void load() throws IOException;
+ T get(K key);
+ Map getMap();
+ void save();
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java
new file mode 100644
index 00000000..a446b205
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java
@@ -0,0 +1,33 @@
+package com.mercury.platform.shared.config.service;
+
+import com.mercury.platform.shared.config.DataSource;
+import com.mercury.platform.shared.entity.FrameSettings;
+
+import java.util.Map;
+
+
+public class FramesConfigurationService extends BaseConfigurationService {
+ public FramesConfigurationService(DataSource dataSource) {
+ super(dataSource);
+ }
+
+ @Override
+ public void load() {
+
+ }
+
+ @Override
+ public FrameSettings get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map getMap() {
+ return null;
+ }
+
+ @Override
+ public void save() {
+
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java
new file mode 100644
index 00000000..dd55f658
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java
@@ -0,0 +1,55 @@
+package com.mercury.platform.shared.config.service;
+
+import com.google.gson.reflect.TypeToken;
+import com.mercury.platform.shared.config.DataSource;
+import com.mercury.platform.shared.entity.SoundDescriptor;
+
+import java.util.*;
+
+
+public class SoundConfigurationService extends BaseConfigurationService {
+ private static final String OBJECT_KEY = "sound";
+ private Map data;
+ public SoundConfigurationService(DataSource dataSource) {
+ super(dataSource);
+ this.data = new HashMap<>();
+ }
+
+ @Override
+ public void load(){
+ this.data = jsonHelper.readMapData(OBJECT_KEY, new TypeToken
-
+
+ io.reactivex
+ rxjava
+ ${rxjava.version}
+
+
+ com.google.code.gson
+ gson
+ 2.8.0
+
org.apache.logging.log4j
log4j-core