|
|
|
@ -37,6 +37,7 @@ public class MicroPhotoContext {
|
|
|
|
|
public int network; // 0: SIM1 1: SIM2 2: WIFI
|
|
|
|
|
public int heartbeat;
|
|
|
|
|
public int packetSize;
|
|
|
|
|
public int encryption;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class MasterConfig {
|
|
|
|
@ -140,34 +141,6 @@ public class MicroPhotoContext {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AppConfig getAppConfig(Context context) {
|
|
|
|
|
|
|
|
|
|
AppConfig appConfig = new AppConfig();
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String content = readTextFile(appPath + "data/App.json");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
|
appConfig.cmdid = jsonObject.optString(jsonObject.has("cmdid") ? "cmdid" : "CMDID", "");
|
|
|
|
|
appConfig.server = jsonObject.optString(jsonObject.has("server") ? "server" : "Server", "");
|
|
|
|
|
appConfig.port = jsonObject.optInt(jsonObject.has("port") ? "port" : "Port", 0);
|
|
|
|
|
appConfig.protocol = jsonObject.optInt(jsonObject.has("protocol") ? "protocol" : "Protocol", DEFAULT_PROTOCOL);
|
|
|
|
|
appConfig.networkProtocol = jsonObject.optInt(jsonObject.has("networkProtocol") ? "networkProtocol" : "NetworkProtocol", 0);
|
|
|
|
|
appConfig.network = jsonObject.optInt(jsonObject.has("network") ? "network" : "Network", 0);
|
|
|
|
|
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
|
|
|
|
|
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
|
|
|
|
|
|
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
|
}
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AppConfig getMpAppConfig(Context context) {
|
|
|
|
|
|
|
|
|
|
AppConfig appConfig = new AppConfig();
|
|
|
|
@ -186,6 +159,7 @@ public class MicroPhotoContext {
|
|
|
|
|
appConfig.network = jsonObject.optInt(jsonObject.has("network") ? "network" : "Network", 0);
|
|
|
|
|
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
|
|
|
|
|
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
|
|
|
|
|
appConfig.encryption = jsonObject.optInt("encryption", 0);
|
|
|
|
|
|
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
@ -197,64 +171,6 @@ public class MicroPhotoContext {
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void saveAppConfig(Context context, AppConfig appConfig) {
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
File dataPath = new File(appPath + "data/");
|
|
|
|
|
if (!dataPath.exists()) {
|
|
|
|
|
dataPath.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String content = readTextFile(appPath + "data/App.json");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
|
jsonObject.put("CMDID", appConfig.cmdid);
|
|
|
|
|
jsonObject.put("server", appConfig.server);
|
|
|
|
|
jsonObject.put("port", appConfig.port);
|
|
|
|
|
jsonObject.put("protocol", appConfig.protocol);
|
|
|
|
|
jsonObject.put("networkProtocol", appConfig.networkProtocol);
|
|
|
|
|
jsonObject.put("network", appConfig.network);
|
|
|
|
|
|
|
|
|
|
if (appConfig.heartbeat > 0) {
|
|
|
|
|
jsonObject.put("heartbeat", appConfig.heartbeat);
|
|
|
|
|
} else {
|
|
|
|
|
jsonObject.remove("heartbeat");
|
|
|
|
|
}
|
|
|
|
|
if (appConfig.packetSize > 0) {
|
|
|
|
|
jsonObject.put("packetSize", appConfig.packetSize);
|
|
|
|
|
} else {
|
|
|
|
|
jsonObject.remove("packetSize");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fos = new FileOutputStream(new File(appPath + "data/App.json"));
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
|
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
|
try {
|
|
|
|
|
outputStreamWriter.close();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (fos != null) {
|
|
|
|
|
try {
|
|
|
|
|
fos.close();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MasterConfig getMasterConfig(Context context) {
|
|
|
|
|
|
|
|
|
|
MasterConfig masterConfig = new MasterConfig();
|
|
|
|
@ -386,6 +302,7 @@ public class MicroPhotoContext {
|
|
|
|
|
jsonObject.put("protocol", appConfig.protocol);
|
|
|
|
|
jsonObject.put("networkProtocol", appConfig.networkProtocol);
|
|
|
|
|
jsonObject.put("network", appConfig.network);
|
|
|
|
|
jsonObject.put("encryption", appConfig.encryption);
|
|
|
|
|
|
|
|
|
|
if (appConfig.heartbeat > 0) {
|
|
|
|
|
jsonObject.put("heartbeat", appConfig.heartbeat);
|
|
|
|
|