1 // AppState.h 2 3 #ifndef ZIP7_INC_APP_STATE_H 4 #define ZIP7_INC_APP_STATE_H 5 6 #include "../../../Windows/Synchronization.h" 7 8 #include "ViewSettings.h" 9 10 class CFastFolders 11 { 12 NWindows::NSynchronization::CCriticalSection _criticalSection; 13 public: 14 UStringVector Strings; SetString(unsigned index,const UString & s)15 void SetString(unsigned index, const UString &s) 16 { 17 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 18 while (Strings.Size() <= index) 19 Strings.AddNew(); 20 Strings[index] = s; 21 } GetString(unsigned index)22 UString GetString(unsigned index) 23 { 24 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 25 if (index >= Strings.Size()) 26 return UString(); 27 return Strings[index]; 28 } Save()29 void Save() 30 { 31 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 32 SaveFastFolders(Strings); 33 } Read()34 void Read() 35 { 36 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 37 ReadFastFolders(Strings); 38 } 39 }; 40 41 class CFolderHistory 42 { 43 NWindows::NSynchronization::CCriticalSection _criticalSection; 44 UStringVector Strings; 45 46 void Normalize(); 47 48 public: 49 GetList(UStringVector & foldersHistory)50 void GetList(UStringVector &foldersHistory) 51 { 52 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 53 foldersHistory = Strings; 54 } 55 56 void AddString(const UString &s); 57 RemoveAll()58 void RemoveAll() 59 { 60 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 61 Strings.Clear(); 62 } 63 Save()64 void Save() 65 { 66 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 67 SaveFolderHistory(Strings); 68 } 69 Read()70 void Read() 71 { 72 NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 73 ReadFolderHistory(Strings); 74 Normalize(); 75 } 76 }; 77 78 struct CAppState 79 { 80 CFastFolders FastFolders; 81 CFolderHistory FolderHistory; 82 SaveCAppState83 void Save() 84 { 85 FastFolders.Save(); 86 FolderHistory.Save(); 87 } ReadCAppState88 void Read() 89 { 90 FastFolders.Read(); 91 FolderHistory.Read(); 92 } 93 }; 94 95 #endif 96