Move files from core.mimis to relevant subprojects
This commit is contained in:
3
java/core.windows/build.gradle
Normal file
3
java/core.windows/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compile project(':core.mimis')
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mimis.application.cmd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import base.exception.worker.ActivateException;
|
||||
import base.exception.worker.DeactivateException;
|
||||
import mimis.Component;
|
||||
import mimis.application.Application;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Registry;
|
||||
|
||||
public abstract class CMDApplication extends Component implements Application {
|
||||
protected final static Registry REGISTRY = Registry.LOCAL_MACHINE;
|
||||
protected final static String KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
||||
|
||||
protected String program;
|
||||
protected String title;
|
||||
protected Process process;
|
||||
protected boolean detect, running;
|
||||
|
||||
public CMDApplication(String program, String title) {
|
||||
super(title);
|
||||
this.program = program;
|
||||
this.title = title;
|
||||
detect = true;
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
detect = true;
|
||||
if (!running) {
|
||||
String path = getPath();
|
||||
if (path == null) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
try {
|
||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||
command = replaceVariables(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (detect) {
|
||||
running = Native.isRunning(program);
|
||||
if (!running) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
return super.active();
|
||||
}
|
||||
|
||||
public synchronized void deactivate() throws DeactivateException {
|
||||
detect = false;
|
||||
super.deactivate();
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
String key = String.format("%s\\%s", KEY, program);
|
||||
System.out.println(Native.getValue(REGISTRY, key));
|
||||
return Native.getValue(REGISTRY, key);
|
||||
}
|
||||
|
||||
public static String replaceVariables(String string) {
|
||||
Map<String, String> env = System.getenv();
|
||||
for (String key : env.keySet()) {
|
||||
string = string.replace(String.format("%%%s%%", key), env.get(key));
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mimis.application.cmd.windows;
|
||||
|
||||
import base.exception.worker.ActivateException;
|
||||
import base.exception.worker.DeactivateException;
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Command;
|
||||
import mimis.value.Key;
|
||||
import mimis.value.Type;
|
||||
import mimis.value.Windows;
|
||||
|
||||
public abstract class WindowsApplication extends CMDApplication {
|
||||
protected final static int TERMINATE_SLEEP = 500;
|
||||
protected final static int START_SLEEP = 500;
|
||||
|
||||
protected String window;
|
||||
protected int handle;
|
||||
|
||||
public WindowsApplication(String title, String window) {
|
||||
this(null, title, window);
|
||||
}
|
||||
|
||||
public WindowsApplication(String program, String title, String window) {
|
||||
super(program, title);
|
||||
this.window = window;
|
||||
handle = 0;
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
if (program != null) {
|
||||
super.activate();
|
||||
}
|
||||
handle = Native.getHandle(window);
|
||||
if (handle < 1) {
|
||||
sleep(START_SLEEP);
|
||||
handle = Native.getHandle(window);
|
||||
}
|
||||
if (handle < 0) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (!super.active() || program == null) {
|
||||
handle = Native.getHandle(window);
|
||||
if (handle > 0 && program == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
return program == null ? handle > 0 : super.active();
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
if (process != null) {
|
||||
close();
|
||||
}
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
Native.sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
protected void command(Command command) {
|
||||
Native.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
||||
}
|
||||
|
||||
protected void command(int command) {
|
||||
Native.sendMessage(handle, Windows.WM_COMMAND, command, 0);
|
||||
}
|
||||
|
||||
protected int user(int wParam, int lParam) {
|
||||
return Native.sendMessage(handle, Windows.WM_USER, wParam, lParam);
|
||||
}
|
||||
|
||||
protected void system(Command.System system) {
|
||||
system(system, 0);
|
||||
}
|
||||
|
||||
protected void system(Command.System system, int lParam) {
|
||||
Native.sendMessage(handle, Windows.WM_SYSCOMMAND, system.getCode(), lParam);
|
||||
}
|
||||
|
||||
protected void key(Type type, int code) {
|
||||
int scanCode = Native.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
|
||||
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16) | 1 << 30);
|
||||
sleep(200);
|
||||
}
|
||||
|
||||
protected void key(Type type, char character) {
|
||||
key(type, (int) Character.toUpperCase(character));
|
||||
}
|
||||
|
||||
protected void key(Type key, Key virtualKey) {
|
||||
key(key, virtualKey.getCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mimis.exception.application.windows;
|
||||
|
||||
import mimis.exception.ApplicationException;
|
||||
|
||||
public class WindowsApplicationException extends ApplicationException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mimis.exception.util;
|
||||
|
||||
import mimis.exception.application.windows.WindowsApplicationException;
|
||||
|
||||
public class SendCommandException extends WindowsApplicationException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mimis.exception.util;
|
||||
|
||||
import mimis.exception.application.windows.WindowsApplicationException;
|
||||
|
||||
public class SendKeyException extends WindowsApplicationException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
Reference in New Issue
Block a user