Files
tuiche/lib/config/ConfigReader.dart
2025-12-30 15:58:19 +08:00

37 lines
1.1 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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; // 默认值
}
}