|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Environment;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
@ -43,6 +44,54 @@ public class MicroPhotoContext {
|
|
|
|
public int heartbeatDuration;
|
|
|
|
public int heartbeatDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String readTextFile(String path) {
|
|
|
|
|
|
|
|
FileInputStream fis = null;
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
File appCfgFile = new File(path);
|
|
|
|
|
|
|
|
if (appCfgFile.exists()) {
|
|
|
|
|
|
|
|
fis = new FileInputStream(appCfgFile);
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(fis, "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fis != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fis.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder == null ? null : stringBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String buildAppDir(Context contxt) {
|
|
|
|
public static String buildAppDir(Context contxt) {
|
|
|
|
|
|
|
|
|
|
|
|
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
|
|
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
|
@ -80,22 +129,10 @@ public class MicroPhotoContext {
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File appCfgFile = new File(appPath + "data/App.json");
|
|
|
|
String content = readTextFile(appPath + "data/App.json");
|
|
|
|
if (appCfgFile.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(appCfgFile), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder == null ? new JSONObject() : new JSONObject(stringBuilder.toString());
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
appConfig.cmdid = jsonObject.optString("CMDID", "");
|
|
|
|
appConfig.cmdid = jsonObject.optString("CMDID", "");
|
|
|
|
appConfig.server = jsonObject.optString("Server", "");
|
|
|
|
appConfig.server = jsonObject.optString("Server", "");
|
|
|
|
appConfig.port = jsonObject.optInt("Port", 0);
|
|
|
|
appConfig.port = jsonObject.optInt("Port", 0);
|
|
|
@ -108,27 +145,9 @@ public class MicroPhotoContext {
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return appConfig;
|
|
|
|
return appConfig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -138,22 +157,10 @@ public class MicroPhotoContext {
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = buildMpAppDir(context);
|
|
|
|
String appPath = buildMpAppDir(context);
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File appCfgFile = new File(appPath + "data/App.json");
|
|
|
|
String content = readTextFile(appPath + "data/App.json");
|
|
|
|
if (appCfgFile.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(appCfgFile), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder == null ? new JSONObject() : new JSONObject(stringBuilder.toString());
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
appConfig.cmdid = jsonObject.optString("CMDID", "");
|
|
|
|
appConfig.cmdid = jsonObject.optString("CMDID", "");
|
|
|
|
appConfig.server = jsonObject.optString("Server", "");
|
|
|
|
appConfig.server = jsonObject.optString("Server", "");
|
|
|
|
appConfig.port = jsonObject.optInt("Port", 0);
|
|
|
|
appConfig.port = jsonObject.optInt("Port", 0);
|
|
|
@ -166,25 +173,8 @@ public class MicroPhotoContext {
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return appConfig;
|
|
|
|
return appConfig;
|
|
|
@ -193,8 +183,7 @@ public class MicroPhotoContext {
|
|
|
|
public static void saveAppConfig(Context context, AppConfig appConfig) {
|
|
|
|
public static void saveAppConfig(Context context, AppConfig appConfig) {
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -203,20 +192,9 @@ public class MicroPhotoContext {
|
|
|
|
dataPath.mkdirs();
|
|
|
|
dataPath.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
String content = readTextFile(appPath + "data/App.json");
|
|
|
|
File file = new File(dataPath, "App.json");
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
jsonObject.put("CMDID", appConfig.cmdid);
|
|
|
|
jsonObject.put("CMDID", appConfig.cmdid);
|
|
|
|
jsonObject.put("Server", appConfig.server);
|
|
|
|
jsonObject.put("Server", appConfig.server);
|
|
|
|
jsonObject.put("Port", appConfig.port);
|
|
|
|
jsonObject.put("Port", appConfig.port);
|
|
|
@ -235,7 +213,8 @@ public class MicroPhotoContext {
|
|
|
|
jsonObject.remove("packetSize");
|
|
|
|
jsonObject.remove("packetSize");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
fos = new FileOutputStream(new File(appPath + "data/App.json"));
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -244,24 +223,17 @@ public class MicroPhotoContext {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader.close();
|
|
|
|
outputStreamWriter.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
if (fos != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
outputStreamWriter.close();
|
|
|
|
fos.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -269,48 +241,18 @@ public class MicroPhotoContext {
|
|
|
|
public static MasterConfig getMasterConfig(Context context) {
|
|
|
|
public static MasterConfig getMasterConfig(Context context) {
|
|
|
|
|
|
|
|
|
|
|
|
MasterConfig masterConfig = new MasterConfig();
|
|
|
|
MasterConfig masterConfig = new MasterConfig();
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File appCfgFile = new File(appPath + "data/Master.json");
|
|
|
|
String content = readTextFile(appPath + "data/Master.json");
|
|
|
|
if (appCfgFile.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(appCfgFile), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder == null ? new JSONObject() : new JSONObject(stringBuilder.toString());
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
masterConfig.url = jsonObject.optString("url", "");
|
|
|
|
masterConfig.url = jsonObject.optString("url", "");
|
|
|
|
masterConfig.mntnMode = jsonObject.optInt("mntnMode", 0);
|
|
|
|
masterConfig.mntnMode = jsonObject.optInt("mntnMode", 0);
|
|
|
|
masterConfig.quickHbMode = jsonObject.optInt("quickHbMode", 0);
|
|
|
|
masterConfig.quickHbMode = jsonObject.optInt("quickHbMode", 0);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return masterConfig;
|
|
|
|
return masterConfig;
|
|
|
@ -319,8 +261,7 @@ public class MicroPhotoContext {
|
|
|
|
public static void saveMasterConfig(Context context, MasterConfig masterConfig) {
|
|
|
|
public static void saveMasterConfig(Context context, MasterConfig masterConfig) {
|
|
|
|
|
|
|
|
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
String appPath = buildAppDir(context);
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -329,51 +270,32 @@ public class MicroPhotoContext {
|
|
|
|
dataPath.mkdirs();
|
|
|
|
dataPath.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
String content = readTextFile(appPath + "data/Master.json");
|
|
|
|
File file = new File(dataPath, "Master.json");
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
jsonObject.put("url", masterConfig.url);
|
|
|
|
jsonObject.put("url", masterConfig.url);
|
|
|
|
jsonObject.put("Server", masterConfig.mntnMode);
|
|
|
|
jsonObject.put("Server", masterConfig.mntnMode);
|
|
|
|
jsonObject.put("Port", masterConfig.quickHbMode);
|
|
|
|
jsonObject.put("Port", masterConfig.quickHbMode);
|
|
|
|
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(appPath + "data/App.json")), "UTF-8");
|
|
|
|
fos = new FileOutputStream(new File(appPath + "data/App.json"));
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader.close();
|
|
|
|
outputStreamWriter.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
if (fos != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
outputStreamWriter.close();
|
|
|
|
fos.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -406,8 +328,7 @@ public class MicroPhotoContext {
|
|
|
|
|
|
|
|
|
|
|
|
public static void saveMpAppConfig(String path, AppConfig appConfig) {
|
|
|
|
public static void saveMpAppConfig(String path, AppConfig appConfig) {
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -416,20 +337,9 @@ public class MicroPhotoContext {
|
|
|
|
dataPath.mkdirs();
|
|
|
|
dataPath.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
String content = readTextFile(path + "data/App.json");
|
|
|
|
File file = new File(dataPath, "App.json");
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
|
|
|
|
|
|
|
bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
jsonObject.put("CMDID", appConfig.cmdid);
|
|
|
|
jsonObject.put("CMDID", appConfig.cmdid);
|
|
|
|
jsonObject.put("Server", appConfig.server);
|
|
|
|
jsonObject.put("Server", appConfig.server);
|
|
|
|
jsonObject.put("Port", appConfig.port);
|
|
|
|
jsonObject.put("Port", appConfig.port);
|
|
|
@ -448,33 +358,25 @@ public class MicroPhotoContext {
|
|
|
|
jsonObject.remove("packetSize");
|
|
|
|
jsonObject.remove("packetSize");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(path + "data/App.json")), "UTF-8");
|
|
|
|
fos = new FileOutputStream(new File(path + "data/App.json"));
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
inputStreamReader.close();
|
|
|
|
outputStreamWriter.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
if (fos != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
outputStreamWriter.close();
|
|
|
|
fos.close();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|