Repository navigation
Expand file tree
/
Copy pathhive_debug_test.dart
More file actions
132 lines (114 loc) · 4.64 KB
/
Copy pathhive_debug_test.dart
File metadata and controls
132 lines (114 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import 'dart:io';
/// Simple test script to debug Hive storage issues
void main() async {
print('=== HIVE DEBUG TEST ===');
try {
// Check if this is a Flutter project
final pubspecFile = File('pubspec.yaml');
if (await pubspecFile.exists()) {
print('✓ Found Flutter project');
// Read pubspec to check dependencies
final pubspecContent = await pubspecFile.readAsString();
if (pubspecContent.contains('hive')) {
print('✓ Hive dependency found in pubspec.yaml');
} else {
print('❌ Hive dependency not found in pubspec.yaml');
}
if (pubspecContent.contains('flutter')) {
print('✓ Flutter dependency found');
}
}
// Check data protection setup
print('\n--- Data Protection Analysis ---');
final securityServiceFile = File('lib/services/security_service.dart');
if (await securityServiceFile.exists()) {
print('✓ SecurityService file exists');
final content = await securityServiceFile.readAsString();
if (content.contains('enableSecurity')) {
print('✓ Security enabling functionality found');
}
if (content.contains('encryptString')) {
print('✓ Encryption functionality found');
}
if (content.contains('decryptString')) {
print('✓ Decryption functionality found');
}
}
final hiveServiceFile = File('lib/services/hive_service.dart');
if (await hiveServiceFile.exists()) {
print('✓ HiveService file exists');
final content = await hiveServiceFile.readAsString();
if (content.contains('encryptionCipher')) {
print('✓ Encryption cipher setup found');
}
if (content.contains('HiveAesCipher')) {
print('✓ AES cipher usage found');
}
}
final converterDataServiceFile = File(
'lib/services/converter_services/converter_tools_data_service.dart',
);
if (await converterDataServiceFile.exists()) {
print('✓ ConverterToolsDataService file exists');
final content = await converterDataServiceFile.readAsString();
if (content.contains('encryptionCipher')) {
print('✅ Encryption cipher used in ConverterToolsDataService - FIXED!');
} else {
print(
'❌ No encryption cipher in ConverterToolsDataService - THIS IS THE PROBLEM!',
);
}
if (content.contains('SecurityService.isSecurityEnabled')) {
print('✅ Security status check added');
}
if (content.contains('SecurityManager.instance')) {
print('✅ SecurityManager integration added');
}
if (content.contains('reinitialize')) {
print('✅ Reinitialize method added');
}
}
final securityManagerFile = File('lib/services/security_manager.dart');
if (await securityManagerFile.exists()) {
final content = await securityManagerFile.readAsString();
if (content.contains('ConverterToolsDataService') &&
content.contains('reinitialize')) {
print('✅ SecurityManager now reinitializes ConverterToolsDataService');
}
}
final mainFile = File('lib/main.dart');
if (await mainFile.exists()) {
final content = await mainFile.readAsString();
if (content.contains('converterDataService.reinitialize()')) {
print(
'✅ Main app reinitializes ConverterToolsDataService after authentication',
);
}
}
print('\n=== SOLUTION SUMMARY ===');
print(
'✅ Problem identified: ConverterToolsDataService was not using encryption',
);
print('✅ Solution implemented:');
print(' - ConverterToolsDataService now checks security status');
print(' - Uses encryption cipher when Data Protection is enabled');
print(' - SecurityManager reinitializes service when security changes');
print(' - App reinitializes service after authentication');
print('\n✅ This should fix the issue where:');
print(' - Tool states are not saved when Data Protection is enabled');
print(' - Presets are not persisted after app restart');
print(' - Data is lost when switching Data Protection on/off');
print('\n=== RECOMMENDED NEXT STEPS ===');
print(
'1. Test with Data Protection disabled - data should save/load normally',
);
print('2. Enable Data Protection - existing data should migrate');
print('3. Test saving new data with Data Protection enabled');
print('4. Restart app and verify data persists');
print('5. Disable Data Protection and verify data migrates back');
print('\n=== TEST COMPLETED ===');
} catch (e, stackTrace) {
print('❌ Error during test: $e');
print('Stack trace: $stackTrace');
}
}