Configuration.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. //---------------------------------------------------------------------------
  2. #ifndef ConfigurationH
  3. #define ConfigurationH
  4. #include <set>
  5. #include "RemoteFiles.h"
  6. #include "FileBuffer.h"
  7. #include "HierarchicalStorage.h"
  8. #include "Usage.h"
  9. //---------------------------------------------------------------------------
  10. #define SET_CONFIG_PROPERTY_EX(PROPERTY, APPLY) \
  11. if (PROPERTY != value) { F ## PROPERTY = value; Changed(); APPLY; }
  12. #define SET_CONFIG_PROPERTY(PROPERTY) \
  13. SET_CONFIG_PROPERTY_EX(PROPERTY, )
  14. //---------------------------------------------------------------------------
  15. extern const wchar_t * AutoSwitchNames;
  16. extern const wchar_t * NotAutoSwitchNames;
  17. enum TAutoSwitch { asOn, asOff, asAuto };
  18. //---------------------------------------------------------------------------
  19. class TStoredSessionList;
  20. //---------------------------------------------------------------------------
  21. class TConfiguration : public TObject
  22. {
  23. private:
  24. bool FDontSave;
  25. bool FChanged;
  26. int FUpdating;
  27. TNotifyEvent FOnChange;
  28. void * FApplicationInfo;
  29. TUsage * FUsage;
  30. bool FLogging;
  31. bool FPermanentLogging;
  32. UnicodeString FLogFileName;
  33. UnicodeString FPermanentLogFileName;
  34. int FLogWindowLines;
  35. bool FLogFileAppend;
  36. bool FLogSensitive;
  37. bool FPermanentLogSensitive;
  38. __int64 FLogMaxSize;
  39. __int64 FPermanentLogMaxSize;
  40. int FLogMaxCount;
  41. int FPermanentLogMaxCount;
  42. int FLogProtocol;
  43. int FPermanentLogProtocol;
  44. int FActualLogProtocol;
  45. bool FLogActions;
  46. bool FPermanentLogActions;
  47. bool FLogActionsRequired;
  48. UnicodeString FActionsLogFileName;
  49. UnicodeString FPermanentActionsLogFileName;
  50. bool FConfirmOverwriting;
  51. bool FConfirmResume;
  52. bool FAutoReadDirectoryAfterOp;
  53. int FSessionReopenAuto;
  54. int FSessionReopenBackground;
  55. int FSessionReopenTimeout;
  56. int FSessionReopenAutoStall;
  57. UnicodeString FIniFileStorageName;
  58. UnicodeString FVirtualIniFileStorageName;
  59. std::unique_ptr<TStrings> FOptionsStorage;
  60. int FProgramIniPathWrittable;
  61. int FTunnelLocalPortNumberLow;
  62. int FTunnelLocalPortNumberHigh;
  63. int FCacheDirectoryChangesMaxSize;
  64. bool FShowFtpWelcomeMessage;
  65. UnicodeString FDefaultRandomSeedFile;
  66. UnicodeString FRandomSeedFile;
  67. UnicodeString FPuttyRegistryStorageKey;
  68. UnicodeString FExternalIpAddress;
  69. bool FTryFtpWhenSshFails;
  70. bool FScripting;
  71. bool FDisablePasswordStoring;
  72. bool FForceBanners;
  73. bool FDisableAcceptingHostKeys;
  74. bool FDefaultCollectUsage;
  75. TVSFixedFileInfo *__fastcall GetFixedApplicationInfo();
  76. void * __fastcall GetApplicationInfo();
  77. virtual UnicodeString __fastcall GetVersionStr();
  78. virtual UnicodeString __fastcall GetVersion();
  79. UnicodeString __fastcall GetProductVersion();
  80. UnicodeString __fastcall GetProductName();
  81. UnicodeString __fastcall GetCompanyName();
  82. UnicodeString __fastcall GetFileVersion(TVSFixedFileInfo * Info);
  83. UnicodeString __fastcall GetStoredSessionsSubKey();
  84. UnicodeString __fastcall GetPuttySessionsKey();
  85. void __fastcall SetRandomSeedFile(UnicodeString value);
  86. UnicodeString __fastcall GetRandomSeedFileName();
  87. void __fastcall SetPuttyRegistryStorageKey(UnicodeString value);
  88. UnicodeString __fastcall GetSshHostKeysSubKey();
  89. UnicodeString __fastcall GetRootKeyStr();
  90. UnicodeString __fastcall GetConfigurationSubKey();
  91. TEOLType __fastcall GetLocalEOLType();
  92. void __fastcall SetLogging(bool value);
  93. bool __fastcall GetLogging();
  94. void __fastcall SetLogFileName(UnicodeString value);
  95. UnicodeString __fastcall GetLogFileName();
  96. bool __fastcall GetLogToFile();
  97. void __fastcall SetLogWindowLines(int value);
  98. void __fastcall SetLogWindowComplete(bool value);
  99. bool __fastcall GetLogWindowComplete();
  100. void __fastcall SetLogFileAppend(bool value);
  101. void __fastcall SetLogSensitive(bool value);
  102. void __fastcall SetLogMaxSize(__int64 value);
  103. __int64 __fastcall GetLogMaxSize();
  104. void __fastcall SetLogMaxCount(int value);
  105. int __fastcall GetLogMaxCount();
  106. void __fastcall SetLogProtocol(int value);
  107. void __fastcall SetLogActions(bool value);
  108. bool __fastcall GetLogActions();
  109. void __fastcall SetActionsLogFileName(UnicodeString value);
  110. UnicodeString __fastcall GetPermanentActionsLogFileName();
  111. UnicodeString __fastcall GetActionsLogFileName();
  112. UnicodeString __fastcall GetDefaultLogFileName();
  113. UnicodeString __fastcall GetTimeFormat();
  114. void __fastcall SetStorage(TStorage value);
  115. UnicodeString __fastcall GetRegistryStorageKey();
  116. UnicodeString __fastcall GetIniFileStorageNameForReadingWriting();
  117. UnicodeString __fastcall GetIniFileStorageNameForReading();
  118. UnicodeString __fastcall GetIniFileStorageName(bool ReadingOnly);
  119. void __fastcall SetIniFileStorageName(UnicodeString value);
  120. void __fastcall SetOptionsStorage(TStrings * value);
  121. TStrings * __fastcall GetOptionsStorage();
  122. UnicodeString __fastcall GetPartialExt() const;
  123. UnicodeString __fastcall GetFileInfoString(const UnicodeString Key);
  124. void __fastcall SetSessionReopenAuto(int value);
  125. void __fastcall SetSessionReopenBackground(int value);
  126. void __fastcall SetSessionReopenTimeout(int value);
  127. void __fastcall SetSessionReopenAutoStall(int value);
  128. void __fastcall SetTunnelLocalPortNumberLow(int value);
  129. void __fastcall SetTunnelLocalPortNumberHigh(int value);
  130. void __fastcall SetCacheDirectoryChangesMaxSize(int value);
  131. void __fastcall SetShowFtpWelcomeMessage(bool value);
  132. int __fastcall GetCompoundVersion();
  133. void __fastcall UpdateActualLogProtocol();
  134. void __fastcall SetExternalIpAddress(UnicodeString value);
  135. void __fastcall SetTryFtpWhenSshFails(bool value);
  136. bool __fastcall GetCollectUsage();
  137. void __fastcall SetCollectUsage(bool value);
  138. bool __fastcall GetIsUnofficial();
  139. bool __fastcall GetPersistent();
  140. protected:
  141. TStorage FStorage;
  142. TCriticalSection * FCriticalSection;
  143. virtual TStorage __fastcall GetStorage();
  144. virtual void __fastcall Changed();
  145. virtual void __fastcall SaveData(THierarchicalStorage * Storage, bool All);
  146. virtual void __fastcall LoadData(THierarchicalStorage * Storage);
  147. virtual void __fastcall LoadFrom(THierarchicalStorage * Storage);
  148. virtual void __fastcall CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target);
  149. virtual void __fastcall LoadAdmin(THierarchicalStorage * Storage);
  150. virtual UnicodeString __fastcall GetDefaultKeyFile();
  151. virtual void __fastcall Saved();
  152. void __fastcall CleanupRegistry(UnicodeString CleanupSubKey);
  153. UnicodeString __fastcall BannerHash(const UnicodeString & Banner);
  154. static UnicodeString __fastcall PropertyToKey(const UnicodeString & Property);
  155. virtual void __fastcall DoSave(bool All, bool Explicit);
  156. UnicodeString __fastcall FormatFingerprintKey(const UnicodeString & SiteKey, const UnicodeString & FingerprintType);
  157. virtual bool __fastcall GetConfirmOverwriting();
  158. virtual void __fastcall SetConfirmOverwriting(bool value);
  159. bool __fastcall GetConfirmResume();
  160. void __fastcall SetConfirmResume(bool value);
  161. bool __fastcall GetAutoReadDirectoryAfterOp();
  162. void __fastcall SetAutoReadDirectoryAfterOp(bool value);
  163. virtual bool __fastcall GetRememberPassword();
  164. UnicodeString __fastcall GetReleaseType();
  165. virtual UnicodeString __fastcall ModuleFileName();
  166. UnicodeString __fastcall GetFileFileInfoString(const UnicodeString Key,
  167. const UnicodeString FileName, bool AllowEmpty = false);
  168. void * __fastcall GetFileApplicationInfo(const UnicodeString FileName);
  169. UnicodeString __fastcall GetFileProductVersion(const UnicodeString FileName);
  170. UnicodeString __fastcall GetFileProductName(const UnicodeString FileName);
  171. UnicodeString __fastcall GetFileCompanyName(const UnicodeString FileName);
  172. __property bool PermanentLogging = { read=GetLogging, write=SetLogging };
  173. __property UnicodeString PermanentLogFileName = { read=GetLogFileName, write=SetLogFileName };
  174. __property bool PermanentLogActions = { read=GetLogActions, write=SetLogActions };
  175. __property UnicodeString PermanentActionsLogFileName = { read=GetPermanentActionsLogFileName, write=SetActionsLogFileName };
  176. __property int PermanentLogProtocol = { read=FPermanentLogProtocol, write=SetLogProtocol };
  177. __property bool PermanentLogSensitive = { read=FPermanentLogSensitive, write=SetLogSensitive };
  178. __property __int64 PermanentLogMaxSize = { read=GetLogMaxSize, write=SetLogMaxSize };
  179. __property int PermanentLogMaxCount = { read=GetLogMaxCount, write=SetLogMaxCount };
  180. public:
  181. __fastcall TConfiguration();
  182. virtual __fastcall ~TConfiguration();
  183. virtual void __fastcall Default();
  184. virtual void __fastcall UpdateStaticUsage();
  185. void __fastcall Load(THierarchicalStorage * Storage);
  186. void __fastcall Save();
  187. void __fastcall SaveExplicit();
  188. void __fastcall SetNulStorage();
  189. void __fastcall SetDefaultStorage();
  190. void __fastcall Export(const UnicodeString & FileName);
  191. void __fastcall Import(const UnicodeString & FileName);
  192. void __fastcall CleanupConfiguration();
  193. void __fastcall CleanupIniFile();
  194. void __fastcall CleanupHostKeys();
  195. void __fastcall CleanupRandomSeedFile();
  196. void __fastcall BeginUpdate();
  197. void __fastcall EndUpdate();
  198. void __fastcall DontSave();
  199. void __fastcall LoadDirectoryChangesCache(const UnicodeString SessionKey,
  200. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  201. void __fastcall SaveDirectoryChangesCache(const UnicodeString SessionKey,
  202. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  203. bool __fastcall ShowBanner(const UnicodeString SessionKey, const UnicodeString & Banner);
  204. void __fastcall NeverShowBanner(const UnicodeString SessionKey, const UnicodeString & Banner);
  205. void __fastcall RememberLastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType, const UnicodeString & Fingerprint);
  206. UnicodeString __fastcall LastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType);
  207. THierarchicalStorage * CreateConfigStorage();
  208. virtual THierarchicalStorage * CreateScpStorage(bool & SessionList);
  209. void __fastcall TemporaryLogging(const UnicodeString ALogFileName);
  210. void __fastcall TemporaryActionsLogging(const UnicodeString ALogFileName);
  211. void __fastcall TemporaryLogProtocol(int ALogProtocol);
  212. void __fastcall TemporaryLogSensitive(bool ALogSensitive);
  213. void __fastcall TemporaryLogMaxSize(__int64 ALogMaxSize);
  214. void __fastcall TemporaryLogMaxCount(int ALogMaxCount);
  215. virtual RawByteString __fastcall EncryptPassword(UnicodeString Password, UnicodeString Key);
  216. virtual UnicodeString __fastcall DecryptPassword(RawByteString Password, UnicodeString Key);
  217. virtual RawByteString __fastcall StronglyRecryptPassword(RawByteString Password, UnicodeString Key);
  218. UnicodeString __fastcall GetFileDescription(const UnicodeString & FileName);
  219. UnicodeString __fastcall GetFileVersion(const UnicodeString & FileName);
  220. TStoredSessionList * __fastcall SelectFilezillaSessionsForImport(
  221. TStoredSessionList * Sessions, UnicodeString & Error);
  222. bool __fastcall AnyFilezillaSessionForImport(TStoredSessionList * Sessions);
  223. __property TVSFixedFileInfo *FixedApplicationInfo = { read=GetFixedApplicationInfo };
  224. __property void * ApplicationInfo = { read=GetApplicationInfo };
  225. __property TUsage * Usage = { read = FUsage };
  226. __property bool CollectUsage = { read = GetCollectUsage, write = SetCollectUsage };
  227. __property UnicodeString StoredSessionsSubKey = {read=GetStoredSessionsSubKey};
  228. __property UnicodeString PuttyRegistryStorageKey = { read=FPuttyRegistryStorageKey, write=SetPuttyRegistryStorageKey };
  229. __property UnicodeString PuttySessionsKey = { read=GetPuttySessionsKey };
  230. __property UnicodeString RandomSeedFile = { read=FRandomSeedFile, write=SetRandomSeedFile };
  231. __property UnicodeString RandomSeedFileName = { read=GetRandomSeedFileName };
  232. __property UnicodeString SshHostKeysSubKey = { read=GetSshHostKeysSubKey };
  233. __property UnicodeString RootKeyStr = { read=GetRootKeyStr };
  234. __property UnicodeString ConfigurationSubKey = { read=GetConfigurationSubKey };
  235. __property TEOLType LocalEOLType = { read = GetLocalEOLType };
  236. __property UnicodeString VersionStr = { read=GetVersionStr };
  237. __property UnicodeString Version = { read=GetVersion };
  238. __property int CompoundVersion = { read=GetCompoundVersion };
  239. __property UnicodeString ProductVersion = { read=GetProductVersion };
  240. __property UnicodeString ProductName = { read=GetProductName };
  241. __property UnicodeString CompanyName = { read=GetCompanyName };
  242. __property bool IsUnofficial = { read = GetIsUnofficial };
  243. __property bool Logging = { read=FLogging, write=SetLogging };
  244. __property UnicodeString LogFileName = { read=FLogFileName, write=SetLogFileName };
  245. __property bool LogToFile = { read=GetLogToFile };
  246. __property bool LogFileAppend = { read=FLogFileAppend, write=SetLogFileAppend };
  247. __property bool LogSensitive = { read=FLogSensitive, write=SetLogSensitive };
  248. __property __int64 LogMaxSize = { read=FLogMaxSize, write=SetLogMaxSize };
  249. __property int LogMaxCount = { read=FLogMaxCount, write=SetLogMaxCount };
  250. __property int LogProtocol = { read=FLogProtocol, write=SetLogProtocol };
  251. __property int ActualLogProtocol = { read=FActualLogProtocol };
  252. __property bool LogActions = { read=FLogActions, write=SetLogActions };
  253. __property bool LogActionsRequired = { read=FLogActionsRequired, write=FLogActionsRequired };
  254. __property UnicodeString ActionsLogFileName = { read=GetActionsLogFileName, write=SetActionsLogFileName };
  255. __property int LogWindowLines = { read=FLogWindowLines, write=SetLogWindowLines };
  256. __property bool LogWindowComplete = { read=GetLogWindowComplete, write=SetLogWindowComplete };
  257. __property UnicodeString DefaultLogFileName = { read=GetDefaultLogFileName };
  258. __property TNotifyEvent OnChange = { read = FOnChange, write = FOnChange };
  259. __property bool ConfirmOverwriting = { read = GetConfirmOverwriting, write = SetConfirmOverwriting};
  260. __property bool ConfirmResume = { read = GetConfirmResume, write = SetConfirmResume};
  261. __property bool AutoReadDirectoryAfterOp = { read = GetAutoReadDirectoryAfterOp, write = SetAutoReadDirectoryAfterOp};
  262. __property bool RememberPassword = { read = GetRememberPassword };
  263. __property UnicodeString PartialExt = {read=GetPartialExt};
  264. __property int SessionReopenAuto = { read = FSessionReopenAuto, write = SetSessionReopenAuto };
  265. __property int SessionReopenBackground = { read = FSessionReopenBackground, write = SetSessionReopenBackground };
  266. __property int SessionReopenTimeout = { read = FSessionReopenTimeout, write = SetSessionReopenTimeout };
  267. __property int SessionReopenAutoStall = { read = FSessionReopenAutoStall, write = SetSessionReopenAutoStall };
  268. __property int TunnelLocalPortNumberLow = { read = FTunnelLocalPortNumberLow, write = SetTunnelLocalPortNumberLow };
  269. __property int TunnelLocalPortNumberHigh = { read = FTunnelLocalPortNumberHigh, write = SetTunnelLocalPortNumberHigh };
  270. __property int CacheDirectoryChangesMaxSize = { read = FCacheDirectoryChangesMaxSize, write = SetCacheDirectoryChangesMaxSize };
  271. __property bool ShowFtpWelcomeMessage = { read = FShowFtpWelcomeMessage, write = SetShowFtpWelcomeMessage };
  272. __property UnicodeString ExternalIpAddress = { read = FExternalIpAddress, write = SetExternalIpAddress };
  273. __property bool TryFtpWhenSshFails = { read = FTryFtpWhenSshFails, write = SetTryFtpWhenSshFails };
  274. __property UnicodeString TimeFormat = { read = GetTimeFormat };
  275. __property TStorage Storage = { read=GetStorage, write=SetStorage };
  276. __property UnicodeString RegistryStorageKey = { read=GetRegistryStorageKey };
  277. __property UnicodeString IniFileStorageName = { read=GetIniFileStorageNameForReadingWriting, write=SetIniFileStorageName };
  278. __property UnicodeString IniFileStorageNameForReading = { read=GetIniFileStorageNameForReading };
  279. __property TStrings * OptionsStorage = { read = GetOptionsStorage, write = SetOptionsStorage };
  280. __property bool Persistent = { read = GetPersistent };
  281. __property bool Scripting = { read = FScripting, write = FScripting };
  282. __property UnicodeString DefaultKeyFile = { read = GetDefaultKeyFile };
  283. __property bool DisablePasswordStoring = { read = FDisablePasswordStoring };
  284. __property bool ForceBanners = { read = FForceBanners };
  285. __property bool DisableAcceptingHostKeys = { read = FDisableAcceptingHostKeys };
  286. };
  287. //---------------------------------------------------------------------------
  288. class TShortCuts
  289. {
  290. public:
  291. void __fastcall Add(TShortCut ShortCut);
  292. bool __fastcall Has(TShortCut ShortCut) const;
  293. private:
  294. std::set<TShortCut> FShortCuts;
  295. };
  296. //---------------------------------------------------------------------------
  297. extern const UnicodeString OriginalPuttyRegistryStorageKey;
  298. extern const UnicodeString KittyRegistryStorageKey;
  299. extern const UnicodeString OriginalPuttyExecutable;
  300. extern const UnicodeString KittyExecutable;
  301. //---------------------------------------------------------------------------
  302. extern const UnicodeString Sha1ChecksumAlg;
  303. extern const UnicodeString Sha224ChecksumAlg;
  304. extern const UnicodeString Sha256ChecksumAlg;
  305. extern const UnicodeString Sha384ChecksumAlg;
  306. extern const UnicodeString Sha512ChecksumAlg;
  307. extern const UnicodeString Md5ChecksumAlg;
  308. extern const UnicodeString Crc32ChecksumAlg;
  309. //---------------------------------------------------------------------------
  310. extern const UnicodeString SshFingerprintType;
  311. extern const UnicodeString TlsFingerprintType;
  312. //---------------------------------------------------------------------------
  313. #endif