|
@ -29,32 +29,63 @@ public class FinanceConfigUtils { |
|
|
// 配置文件路径 |
|
|
// 配置文件路径 |
|
|
public static String filePath; |
|
|
public static String filePath; |
|
|
|
|
|
|
|
|
public static final String folder2 = Environment.getExternalStorageDirectory() + File.separator + "Settings"; |
|
|
|
|
|
// 配置文件路径 |
|
|
|
|
|
public static final String filePath_gate = folder2 + "/" + "gateFaceConfig.txt"; |
|
|
|
|
|
|
|
|
// 动态获取外部存储路径,避免在类加载时初始化 |
|
|
|
|
|
public static String getFolder2() { |
|
|
|
|
|
if (isSDCardEnable()) { |
|
|
|
|
|
return Environment.getExternalStorageDirectory() + File.separator + "Settings"; |
|
|
|
|
|
} else { |
|
|
|
|
|
Log.w(TAG, "外部存储不可用,使用内部存储"); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 动态获取门禁配置文件路径 |
|
|
|
|
|
public static String getFilePathGate() { |
|
|
|
|
|
String externalFolder = getFolder2(); |
|
|
|
|
|
return externalFolder != null ? externalFolder + "/" + "gateFaceConfig.txt" : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static boolean isConfigExit(Context context) { |
|
|
public static boolean isConfigExit(Context context) { |
|
|
folder = context.getFilesDir() + File.separator + "Settings"; |
|
|
folder = context.getFilesDir() + File.separator + "Settings"; |
|
|
filePath = folder2 + "/" + "financeFaceConfig.txt"; |
|
|
|
|
|
// filePath = filePath_gate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 优先使用外部存储,如果不可用则使用内部存储 |
|
|
|
|
|
String externalFolder = getFolder2(); |
|
|
|
|
|
String configDir; |
|
|
|
|
|
if (externalFolder != null) { |
|
|
|
|
|
filePath = externalFolder + "/" + "financeFaceConfig.txt"; |
|
|
|
|
|
configDir = externalFolder; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 回退到内部存储 |
|
|
|
|
|
filePath = folder + "/" + "financeFaceConfig.txt"; |
|
|
|
|
|
configDir = folder; |
|
|
|
|
|
Log.d(TAG, "使用内部存储路径: " + filePath); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Log.d(TAG, "filePath_isConfigExit: "+filePath); |
|
|
Log.d(TAG, "filePath_isConfigExit: "+filePath); |
|
|
File file1 = new File(folder); |
|
|
|
|
|
if (!file1.exists()) { |
|
|
|
|
|
file1.mkdirs(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 确保配置目录存在 |
|
|
|
|
|
File configDirFile = new File(configDir); |
|
|
|
|
|
if (!configDirFile.exists()) { |
|
|
|
|
|
boolean mkdirResult = configDirFile.mkdirs(); |
|
|
|
|
|
Log.d(TAG, "创建配置目录 " + configDir + ": " + mkdirResult); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
File file = new File(filePath); |
|
|
File file = new File(filePath); |
|
|
if (file.exists()) { |
|
|
if (file.exists()) { |
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
try { |
|
|
try { |
|
|
file.createNewFile(); |
|
|
|
|
|
|
|
|
boolean createResult = file.createNewFile(); |
|
|
|
|
|
Log.d(TAG, "创建配置文件 " + filePath + ": " + createResult); |
|
|
|
|
|
if (createResult) { |
|
|
modityJson(); |
|
|
modityJson(); |
|
|
|
|
|
} |
|
|
|
|
|
return createResult; |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
|
|
|
Log.e(TAG, "创建配置文件失败: " + filePath, e); |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -353,6 +384,12 @@ public class FinanceConfigUtils { |
|
|
* 修改配置文件内容并重新读取配置 |
|
|
* 修改配置文件内容并重新读取配置 |
|
|
*/ |
|
|
*/ |
|
|
public static boolean modityJson() { |
|
|
public static boolean modityJson() { |
|
|
|
|
|
// 确保文件路径已初始化 |
|
|
|
|
|
if (filePath == null || filePath.contains("null")) { |
|
|
|
|
|
Log.e(TAG, "文件路径未初始化或无效: " + filePath); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 检查文件路径是否有效 |
|
|
// 检查文件路径是否有效 |
|
|
if (filePath == null || filePath.contains("null")) { |
|
|
if (filePath == null || filePath.contains("null")) { |
|
|
Log.e(TAG, "文件路径无效,无法写入配置文件: " + filePath); |
|
|
Log.e(TAG, "文件路径无效,无法写入配置文件: " + filePath); |
|
|