37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
// lib/utils/config_reader.dart
|
||
import 'dart:io';
|
||
import 'package:path/path.dart' as path;
|
||
|
||
class ConfigReader {
|
||
static int getAppType() {
|
||
try {
|
||
// 获取当前Dart文件所在目录
|
||
final scriptDir = File(Platform.script.toFilePath()).parent.path;
|
||
|
||
// 从lib目录向上回退到项目根目录,再进入android目录
|
||
final projectRoot = path.dirname(path.dirname(scriptDir));
|
||
final localPropertiesPath = path.join(projectRoot, 'android', 'local.properties');
|
||
|
||
final file = File(localPropertiesPath);
|
||
|
||
if (file.existsSync()) {
|
||
final content = file.readAsStringSync();
|
||
final lines = content.split('\n');
|
||
|
||
for (final line in lines) {
|
||
final trimmedLine = line.trim();
|
||
if (trimmedLine.startsWith('app.type=')) {
|
||
final value = trimmedLine.split('=')[1].trim();
|
||
return int.tryParse(value) ?? 3;
|
||
}
|
||
}
|
||
} else {
|
||
print('配置文件不存在: $localPropertiesPath');
|
||
}
|
||
} catch (e) {
|
||
print('读取配置文件失败: $e');
|
||
}
|
||
|
||
return 3; // 默认值
|
||
}
|
||
} |