Configuration.h 16 KB

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