Configuration.h 16 KB

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