1
0

WinMain.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <CoreMain.h>
  5. #include <TextsWin.h>
  6. #include <TextsCore.h>
  7. #include <HelpWin.h>
  8. #include "CustomScpExplorer.h"
  9. #include "TerminalManager.h"
  10. #include "NonVisual.h"
  11. #include "Glyphs.h"
  12. #include "ProgParams.h"
  13. #include "Setup.h"
  14. #include "WinConfiguration.h"
  15. #include "GUITools.h"
  16. #include "Tools.h"
  17. #include "WinApi.h"
  18. #include <DateUtils.hpp>
  19. //---------------------------------------------------------------------------
  20. #pragma package(smart_init)
  21. //---------------------------------------------------------------------------
  22. void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
  23. TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm, int Flags)
  24. {
  25. bool DefaultsOnly = false;
  26. UnicodeString FolderOrWorkspaceName = DecodeUrlChars(SessionName);
  27. if (StoredSessions->IsFolder(FolderOrWorkspaceName) ||
  28. StoredSessions->IsWorkspace(FolderOrWorkspaceName))
  29. {
  30. StoredSessions->GetFolderOrWorkspace(FolderOrWorkspaceName, DataList);
  31. }
  32. else
  33. {
  34. TSessionData * SessionData =
  35. StoredSessions->ParseUrl(SessionName, Options, DefaultsOnly, &DownloadFile, NULL, NULL, Flags);
  36. DataList->Add(SessionData);
  37. if (DataList->Count == 1)
  38. {
  39. TSessionData * SessionData = DebugNotNull(dynamic_cast<TSessionData *>(DataList->Items[0]));
  40. if (SessionData->SaveOnly)
  41. {
  42. Configuration->Usage->Inc(L"CommandLineSessionSave");
  43. TSessionData * SavedSession = DoSaveSession(SessionData, NULL, true, NULL);
  44. if (SavedSession == NULL)
  45. {
  46. Abort();
  47. }
  48. WinConfiguration->LastStoredSession = SavedSession->Name;
  49. DataList->Clear();
  50. }
  51. else if (!SessionData->PuttyProtocol.IsEmpty())
  52. {
  53. // putty does not support resolving environment variables in session settings
  54. // though it's hardly of any use here.
  55. SessionData->ExpandEnvironmentVariables();
  56. OpenSessionInPutty(GUIConfiguration->PuttyPath, SessionData);
  57. DataList->Clear();
  58. Abort();
  59. }
  60. }
  61. }
  62. if (DefaultsOnly && !NeedSession)
  63. {
  64. // No URL specified on command-line and no explicit command-line parameter
  65. // that requires session was specified => noop
  66. DataList->Clear();
  67. }
  68. else if ((DataList->Count == 0) ||
  69. !dynamic_cast<TSessionData *>(DataList->Items[0])->CanLogin ||
  70. DefaultsOnly)
  71. {
  72. // Note that GetFolderOrWorkspace never returns sites that !CanLogin,
  73. // so we should not get here with more then one site.
  74. // Though we should be good, if we ever do.
  75. // We get here when:
  76. // - we need session for explicit command-line operation
  77. // - after we handle "save" URL.
  78. // - the specified session does not contain enough information to login [= not even hostname]
  79. DebugAssert(DataList->Count <= 1);
  80. if (!DoLoginDialog(StoredSessions, DataList, LinkedForm))
  81. {
  82. Abort();
  83. }
  84. }
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall Upload(TTerminal * Terminal, TStrings * FileList, bool UseDefaults)
  88. {
  89. UnicodeString TargetDirectory;
  90. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  91. TargetDirectory = UnixIncludeTrailingBackslash(Terminal->CurrentDirectory);
  92. std::unique_ptr<TSessionData> Data(Terminal->SessionData->Clone());
  93. Terminal->FillSessionDataForCode(Data.get());
  94. int Options = coDisableQueue;
  95. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  96. if (UseDefaults ||
  97. DoCopyDialog(true, false, FileList, TargetDirectory, &CopyParam, Options,
  98. CopyParamAttrs, Data.get(), NULL))
  99. {
  100. // Setting parameter overrides only now, otherwise the dialog would present the parametes as non-default
  101. CopyParam.OnceDoneOperation = odoDisconnect;
  102. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, 0, NULL);
  103. }
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall Download(TTerminal * Terminal, const UnicodeString FileName,
  107. bool UseDefaults)
  108. {
  109. TRemoteFile * File = NULL;
  110. try
  111. {
  112. Terminal->ExceptionOnFail = true;
  113. try
  114. {
  115. Terminal->ReadFile(FileName, File);
  116. }
  117. __finally
  118. {
  119. Terminal->ExceptionOnFail = false;
  120. }
  121. File->FullFileName = FileName;
  122. UnicodeString LocalDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  123. if (LocalDirectory.IsEmpty())
  124. {
  125. LocalDirectory = GetPersonalFolder();
  126. }
  127. UnicodeString TargetDirectory = IncludeTrailingBackslash(LocalDirectory);
  128. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  129. UnicodeString DisplayName = File->FileName;
  130. bool CustomDisplayName =
  131. !File->DisplayName.IsEmpty() &&
  132. (File->DisplayName != DisplayName);
  133. if (CustomDisplayName)
  134. {
  135. DisplayName = File->DisplayName;
  136. }
  137. UnicodeString FriendyFileName = UnixIncludeTrailingBackslash(UnixExtractFilePath(FileName)) + DisplayName;
  138. std::unique_ptr<TStrings> FileListFriendly(new TStringList());
  139. FileListFriendly->AddObject(FriendyFileName, File);
  140. int Options = coDisableQueue;
  141. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Download;
  142. if (UseDefaults ||
  143. DoCopyDialog(false, false, FileListFriendly.get(), TargetDirectory, &CopyParam,
  144. Options, CopyParamAttrs, NULL, NULL))
  145. {
  146. // Setting parameter overrides only now, otherwise the dialog would present the parametes as non-default
  147. if (CustomDisplayName)
  148. {
  149. // Set only now, so that it is not redundantly displayed on the copy dialog.
  150. // We should escape the * and ?'s.
  151. CopyParam.FileMask = DisplayName;
  152. }
  153. CopyParam.OnceDoneOperation = odoDisconnect;
  154. std::unique_ptr<TStrings> FileList(new TStringList());
  155. FileList->AddObject(FileName, File);
  156. Terminal->CopyToLocal(FileList.get(), TargetDirectory, &CopyParam, 0, NULL);
  157. }
  158. UnicodeString Directory = UnixExtractFilePath(FileName);
  159. Terminal->AutoReadDirectory = true;
  160. Terminal->ChangeDirectory(Directory);
  161. }
  162. __finally
  163. {
  164. delete File;
  165. }
  166. }
  167. //---------------------------------------------------------------------------
  168. void __fastcall Edit(TCustomScpExplorerForm * ScpExplorer, TStrings * FileList)
  169. {
  170. ScpExplorer->StandaloneEdit(FileList->Strings[0]);
  171. Abort();
  172. }
  173. //---------------------------------------------------------------------------
  174. void __fastcall SynchronizeDirectories(TTerminal * Terminal,
  175. TStrings * CommandParams,
  176. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory)
  177. {
  178. if (CommandParams->Count >= 1)
  179. {
  180. LocalDirectory = CommandParams->Strings[0];
  181. }
  182. else if (!Terminal->SessionData->LocalDirectory.IsEmpty())
  183. {
  184. LocalDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  185. }
  186. else
  187. {
  188. LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  189. }
  190. if (CommandParams->Count >= 2)
  191. {
  192. RemoteDirectory = CommandParams->Strings[1];
  193. }
  194. else
  195. {
  196. RemoteDirectory = Terminal->CurrentDirectory;
  197. }
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall FullSynchronize(TTerminal * Terminal, TCustomScpExplorerForm * ScpExplorer,
  201. TStrings * CommandParams, bool UseDefaults)
  202. {
  203. UnicodeString LocalDirectory;
  204. UnicodeString RemoteDirectory;
  205. SynchronizeDirectories(Terminal, CommandParams, LocalDirectory, RemoteDirectory);
  206. bool SaveMode = true;
  207. // bit ugly
  208. TSynchronizeMode Mode = (TSynchronizeMode)GUIConfiguration->SynchronizeMode;
  209. int Params = GUIConfiguration->SynchronizeParams;
  210. // Undocumented syntax for "Start in New Window"
  211. if (CommandParams->Count >= 4)
  212. {
  213. Mode = (TSynchronizeMode)StrToIntDef(CommandParams->Strings[2], Mode);
  214. Params = StrToIntDef(CommandParams->Strings[3], Params);
  215. }
  216. int Result =
  217. ScpExplorer->DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, UseDefaults);
  218. if ((Result >= 0) && SaveMode)
  219. {
  220. GUIConfiguration->SynchronizeMode = Mode;
  221. }
  222. Abort();
  223. }
  224. //---------------------------------------------------------------------------
  225. void __fastcall Synchronize(TTerminal * Terminal, TCustomScpExplorerForm * ScpExplorer,
  226. TStrings * CommandParams, bool UseDefaults)
  227. {
  228. UnicodeString LocalDirectory;
  229. UnicodeString RemoteDirectory;
  230. SynchronizeDirectories(Terminal, CommandParams, LocalDirectory, RemoteDirectory);
  231. // Undocumented syntax for "Start in New Window"
  232. if (CommandParams->Count >= 4)
  233. {
  234. GUIConfiguration->SynchronizeParams = StrToIntDef(CommandParams->Strings[2], -1);
  235. GUIConfiguration->SynchronizeOptions = StrToIntDef(CommandParams->Strings[3], -1);
  236. Configuration->DontSave();
  237. }
  238. ScpExplorer->DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, UseDefaults);
  239. Abort();
  240. }
  241. //---------------------------------------------------------------------------
  242. void __fastcall ImportSitesIfAny()
  243. {
  244. if (!WinConfiguration->AutoImportedFromPuttyOrFilezilla)
  245. {
  246. bool AnyPuttySession = GUIConfiguration->AnyPuttySessionForImport(StoredSessions);
  247. bool AnyFilezillaSession = GUIConfiguration->AnyFilezillaSessionForImport(StoredSessions);
  248. if (AnyPuttySession || AnyFilezillaSession)
  249. {
  250. UnicodeString PuttySource = LoadStrPart(IMPORT_SESSIONS2, 2);
  251. UnicodeString FilezillaSource = LoadStrPart(IMPORT_SESSIONS2, 3);
  252. UnicodeString Source;
  253. if (AnyPuttySession && AnyFilezillaSession)
  254. {
  255. Source = FORMAT(LoadStrPart(IMPORT_SESSIONS2, 4), (PuttySource, FilezillaSource));
  256. }
  257. else if (AnyPuttySession)
  258. {
  259. Source = PuttySource;
  260. }
  261. else if (AnyFilezillaSession)
  262. {
  263. Source = FilezillaSource;
  264. }
  265. else
  266. {
  267. DebugFail();
  268. }
  269. UnicodeString Message = FORMAT(LoadStrPart(IMPORT_SESSIONS2, 1), (Source));
  270. if (MessageDialog(Message, qtConfirmation,
  271. qaYes | qaNo, HELP_IMPORT_SESSIONS) == qaYes)
  272. {
  273. DoImportSessionsDialog(NULL);
  274. }
  275. WinConfiguration->AutoImportedFromPuttyOrFilezilla = true;
  276. }
  277. }
  278. }
  279. //---------------------------------------------------------------------------
  280. void __fastcall Usage(UnicodeString Param)
  281. {
  282. while (!Param.IsEmpty())
  283. {
  284. UnicodeString Pair = CutToChar(Param, L',', true);
  285. if (!Pair.IsEmpty())
  286. {
  287. if (Pair[Pair.Length()] == L'+')
  288. {
  289. UnicodeString Key = Pair.SubString(1, Pair.Length() - 1).Trim();
  290. Configuration->Usage->Inc(Key);
  291. }
  292. else
  293. {
  294. UnicodeString Key = CutToChar(Pair, L':', true);
  295. Configuration->Usage->Set(Key, Pair.Trim());
  296. }
  297. }
  298. }
  299. }
  300. //---------------------------------------------------------------------------
  301. void __fastcall RecordWrapperVersions(UnicodeString ConsoleVersion, UnicodeString DotNetVersion)
  302. {
  303. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  304. if (!DotNetVersion.IsEmpty())
  305. {
  306. Updates.DotNetVersion = DotNetVersion;
  307. }
  308. if (!ConsoleVersion.IsEmpty())
  309. {
  310. Updates.ConsoleVersion = ConsoleVersion;
  311. }
  312. WinConfiguration->Updates = Updates;
  313. if (Configuration->Storage == stNul)
  314. {
  315. Configuration->SetDefaultStorage();
  316. try
  317. {
  318. THierarchicalStorage * Storage = Configuration->CreateConfigStorage();
  319. try
  320. {
  321. Storage->AccessMode = smReadWrite;
  322. if (Storage->OpenSubKey(Configuration->ConfigurationSubKey, true) &&
  323. Storage->OpenSubKeyPath(L"Interface\\Updates", true))
  324. {
  325. if (!DotNetVersion.IsEmpty())
  326. {
  327. Storage->WriteString(L"DotNetVersion", DotNetVersion);
  328. }
  329. if (!ConsoleVersion.IsEmpty())
  330. {
  331. Storage->WriteString(L"ConsoleVersion", ConsoleVersion);
  332. }
  333. }
  334. }
  335. __finally
  336. {
  337. delete Storage;
  338. }
  339. }
  340. __finally
  341. {
  342. Configuration->SetNulStorage();
  343. }
  344. }
  345. }
  346. //---------------------------------------------------------------------------
  347. static UnicodeString ColorToRGBStr(TColor Color)
  348. {
  349. int RGB = ColorToRGB(Color);
  350. int R = GetRValue(RGB);
  351. int G = GetGValue(RGB);
  352. int B = GetBValue(RGB);
  353. UnicodeString Result = FORMAT(L"%.2x%.2x%.2x", (R, G, B));
  354. return Result;
  355. }
  356. //---------------------------------------------------------------------------
  357. void __fastcall UpdateStaticUsage()
  358. {
  359. Configuration->Usage->Inc(L"Runs");
  360. Configuration->Usage->UpdateCurrentVersion();
  361. Configuration->Usage->Set(L"WindowsVersion", (WindowsVersionLong()));
  362. Configuration->Usage->Set(L"WindowsProductName", (WindowsProductName()));
  363. DWORD Type;
  364. GetWindowsProductType(Type);
  365. Configuration->Usage->Set(L"WindowsProductType", (static_cast<int>(Type)));
  366. Configuration->Usage->Set(L"Windows64", IsWin64());
  367. Configuration->Usage->Set(L"UWP", IsUWP());
  368. Configuration->Usage->Set(L"DefaultLocale",
  369. // See TGUIConfiguration::GetAppliedLocaleHex()
  370. IntToHex(static_cast<int>(GetDefaultLCID()), 4));
  371. Configuration->Usage->Set(L"Locale", WinConfiguration->AppliedLocaleHex);
  372. Configuration->Usage->Set(L"EncodingMultiByteAnsi", !TEncoding::Default->IsSingleByte);
  373. Configuration->Usage->Set(L"PixelsPerInch", Screen->PixelsPerInch);
  374. bool PixelsPerInchSystemDiffers = false;
  375. bool PixelsPerInchMonitorsDiffer = false;
  376. bool PixelsPerInchAxesDiffer = false;
  377. HINSTANCE ShCoreLibrary = LoadLibrary(L"shcore.dll");
  378. if (ShCoreLibrary != NULL)
  379. {
  380. GetDpiForMonitorProc GetDpiForMonitor =
  381. (GetDpiForMonitorProc)GetProcAddress(ShCoreLibrary, "GetDpiForMonitor");
  382. if (GetDpiForMonitor != NULL)
  383. {
  384. unsigned int PrimaryDpiX;
  385. unsigned int PrimaryDpiY;
  386. for (int Index = 0; Index < Screen->MonitorCount; Index++)
  387. {
  388. unsigned int DpiX;
  389. unsigned int DpiY;
  390. GetDpiForMonitor(Screen->Monitors[Index]->Handle, MDT_Default, &DpiX, &DpiY);
  391. if (DpiX != DpiY)
  392. {
  393. PixelsPerInchAxesDiffer = true;
  394. }
  395. if (Index == 0)
  396. {
  397. PrimaryDpiX = DpiX;
  398. PrimaryDpiY = DpiY;
  399. // PixelsPerInch is GetDeviceCaps(DC, LOGPIXELSY)
  400. if (DpiY != (unsigned int)Screen->PixelsPerInch)
  401. {
  402. PixelsPerInchSystemDiffers = true;
  403. }
  404. }
  405. else
  406. {
  407. if ((DpiX != PrimaryDpiX) ||
  408. (DpiY != PrimaryDpiY))
  409. {
  410. PixelsPerInchMonitorsDiffer = true;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. if (PixelsPerInchSystemDiffers)
  417. {
  418. Configuration->Usage->Inc(L"PixelsPerInchSystemDiffered");
  419. }
  420. Configuration->Usage->Set(L"PixelsPerInchMonitorsDiffer", PixelsPerInchMonitorsDiffer);
  421. Configuration->Usage->Set(L"PixelsPerInchAxesDiffer", PixelsPerInchAxesDiffer);
  422. Configuration->Usage->Set(L"WorkAreaWidth", Screen->WorkAreaWidth);
  423. Configuration->Usage->Set(L"WorkAreaHeight", Screen->WorkAreaHeight);
  424. HDC DC = GetDC(NULL);
  425. int Planes = GetDeviceCaps(DC, PLANES);
  426. int BitsPixel = GetDeviceCaps(DC, BITSPIXEL);
  427. Configuration->Usage->Set(L"ColorDepth", Planes * BitsPixel);
  428. Configuration->Usage->Set(L"MonitorCount", Screen->MonitorCount);
  429. Configuration->Usage->Set(L"NotUseThemes", !UseThemes());
  430. Configuration->Usage->Set(L"ThemeDefaultFontSize", Application->DefaultFont->Size);
  431. Configuration->Usage->Set(L"ThemeIconFontSize", Screen->IconFont->Size);
  432. Configuration->Usage->Set(L"SysColorWindow", ColorToRGBStr(clWindow));
  433. Configuration->Usage->Set(L"SysColorBtnFace", ColorToRGBStr(clBtnFace));
  434. Configuration->Usage->Set(L"SysColorWindowText", ColorToRGBStr(clWindowText));
  435. UnicodeString ProgramsFolder;
  436. ::SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  437. ProgramsFolder = IncludeTrailingBackslash(ExpandFileName(ProgramsFolder));
  438. UnicodeString ExeName = ExpandFileName(Application->ExeName);
  439. bool InProgramFiles = AnsiSameText(ExeName.SubString(1, ProgramsFolder.Length()), ProgramsFolder);
  440. Configuration->Usage->Set(L"InProgramFiles", InProgramFiles);
  441. Configuration->Usage->Set(L"IsInstalled", IsInstalled());
  442. Configuration->Usage->Set(L"Wine", IsWine());
  443. Configuration->Usage->Set(L"NetFrameworkVersion", GetNetVersionStr());
  444. Configuration->Usage->Set(L"PowerShellVersion", GetPowerShellVersionStr());
  445. WinConfiguration->UpdateStaticUsage();
  446. }
  447. //---------------------------------------------------------------------------
  448. void __fastcall MaintenanceTask()
  449. {
  450. CoreMaintenanceTask();
  451. }
  452. //---------------------------------------------------------------------------
  453. typedef std::vector<HWND> THandles;
  454. typedef std::map<unsigned long, THandles> TProcesses;
  455. //---------------------------------------------------------------------------
  456. BOOL __stdcall EnumOtherInstances(HWND Handle, LPARAM AParam)
  457. {
  458. TProcesses & Processes = *reinterpret_cast<TProcesses *>(AParam);
  459. unsigned long ProcessId;
  460. if (GetWindowThreadProcessId(Handle, &ProcessId) != 0)
  461. {
  462. Processes[ProcessId].push_back(Handle);
  463. }
  464. return TRUE;
  465. }
  466. //---------------------------------------------------------------------------
  467. static bool __fastcall SendCopyDataMessage(HWND Window, TCopyDataMessage & Message)
  468. {
  469. COPYDATASTRUCT CopyData;
  470. CopyData.cbData = sizeof(Message);
  471. CopyData.lpData = &Message;
  472. LRESULT SendResult =
  473. SendMessage(Window, WM_COPYDATA,
  474. reinterpret_cast<WPARAM>(HInstance), reinterpret_cast<LPARAM>(&CopyData));
  475. bool Result = (SendResult > 0);
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. static void __fastcall FindOtherInstances(THandles & OtherInstances)
  480. {
  481. TProcesses Processes;
  482. // FindWindow is optimization (if there's no hidden window, no point enumerating all windows to find some)
  483. if ((FindWindow(HIDDEN_WINDOW_NAME, NULL) != NULL) &&
  484. EnumWindows(EnumOtherInstances, reinterpret_cast<LPARAM>(&Processes)))
  485. {
  486. TCopyDataMessage Message;
  487. Message.Command = TCopyDataMessage::MainWindowCheck;
  488. TProcesses::const_iterator ProcessI = Processes.begin();
  489. while (ProcessI != Processes.end())
  490. {
  491. HWND HiddenWindow = NULL;
  492. THandles::const_iterator WindowI = ProcessI->second.begin();
  493. while ((HiddenWindow == NULL) && (WindowI != ProcessI->second.end()))
  494. {
  495. wchar_t ClassName[1024];
  496. if (GetClassName(*WindowI, ClassName, LENOF(ClassName)) != 0)
  497. {
  498. NULL_TERMINATE(ClassName);
  499. if (wcscmp(ClassName, HIDDEN_WINDOW_NAME) == 0)
  500. {
  501. HiddenWindow = *WindowI;
  502. }
  503. }
  504. WindowI++;
  505. }
  506. if (HiddenWindow != NULL)
  507. {
  508. WindowI = ProcessI->second.begin();
  509. while (WindowI != ProcessI->second.end())
  510. {
  511. if (*WindowI != HiddenWindow) // optimization
  512. {
  513. if (SendCopyDataMessage(*WindowI, Message))
  514. {
  515. OtherInstances.push_back(*WindowI);
  516. break;
  517. }
  518. }
  519. WindowI++;
  520. }
  521. }
  522. ProcessI++;
  523. }
  524. }
  525. }
  526. //---------------------------------------------------------------------------
  527. bool __fastcall SendToAnotherInstance()
  528. {
  529. THandles OtherInstances;
  530. FindOtherInstances(OtherInstances);
  531. bool Result = false;
  532. THandles::const_iterator I = OtherInstances.begin();
  533. while (!Result && (I != OtherInstances.end()))
  534. {
  535. HWND Handle = *I;
  536. TCopyDataMessage Message;
  537. Message.Command = TCopyDataMessage::CommandCanCommandLine;
  538. if (SendCopyDataMessage(Handle, Message))
  539. {
  540. // Restore window, if minimized
  541. ShowWindow(Handle, SW_RESTORE);
  542. // bring it to foreground
  543. SetForegroundWindow(Handle);
  544. Message.Command = TCopyDataMessage::CommandCommandLine;
  545. wcsncpy(Message.CommandLine, CmdLine, LENOF(Message.CommandLine));
  546. NULL_TERMINATE(Message.CommandLine);
  547. Result = SendCopyDataMessage(Handle, Message);
  548. }
  549. I++;
  550. }
  551. return Result;
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall Refresh(const UnicodeString & Session, const UnicodeString & Path)
  555. {
  556. THandles OtherInstances;
  557. FindOtherInstances(OtherInstances);
  558. THandles::const_iterator I = OtherInstances.begin();
  559. while (I != OtherInstances.end())
  560. {
  561. HWND Handle = *I;
  562. TCopyDataMessage Message;
  563. Message.Command = TCopyDataMessage::RefreshPanel;
  564. wcsncpy(Message.Refresh.Session, Session.c_str(), LENOF(Message.Refresh.Session));
  565. NULL_TERMINATE(Message.Refresh.Session);
  566. wcsncpy(Message.Refresh.Path, Path.c_str(), LENOF(Message.Refresh.Path));
  567. NULL_TERMINATE(Message.Refresh.Path);
  568. SendCopyDataMessage(Handle, Message);
  569. I++;
  570. }
  571. }
  572. //---------------------------------------------------------------------------
  573. bool __fastcall ShowUpdatesIfAvailable()
  574. {
  575. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  576. int CurrentCompoundVer = Configuration->CompoundVersion;
  577. bool NoPopup = true;
  578. bool Result =
  579. !IsUWP() &&
  580. Updates.ShowOnStartup &&
  581. Updates.HaveValidResultsForVersion(CurrentCompoundVer) &&
  582. !Updates.Results.Disabled &&
  583. ((Updates.Results.Version > CurrentCompoundVer) || !Updates.Results.Message.IsEmpty()) &&
  584. !Updates.ShownResults;
  585. if (Result)
  586. {
  587. Configuration->Usage->Inc(L"UpdateStartup");
  588. Result = CheckForUpdates(true);
  589. if (Result)
  590. {
  591. Configuration->Usage->Inc(L"UpdateDownloadOpensStartup");
  592. }
  593. NoPopup = false;
  594. }
  595. else if (WinConfiguration->ShowTips)
  596. {
  597. int Days = DaysBetween(WinConfiguration->TipsShown, Now());
  598. if ((Days >= Updates.Results.TipsIntervalDays) &&
  599. (WinConfiguration->RunsSinceLastTip >= Updates.Results.TipsIntervalDays))
  600. {
  601. UnicodeString Tip = FirstUnshownTip();
  602. if (!Tip.IsEmpty())
  603. {
  604. AutoShowNewTip();
  605. NoPopup = false;
  606. }
  607. else
  608. {
  609. Configuration->Usage->Inc(L"TipsNoUnseen");
  610. }
  611. }
  612. }
  613. if (NoPopup)
  614. {
  615. WinConfiguration->RunsSinceLastTip = WinConfiguration->RunsSinceLastTip + 1;
  616. }
  617. return Result;
  618. }
  619. //---------------------------------------------------------------------------
  620. int __fastcall Execute()
  621. {
  622. DebugAssert(StoredSessions);
  623. TProgramParams * Params = TProgramParams::Instance();
  624. DebugAssert(Params);
  625. // do not flash message boxes on startup
  626. SetOnForeground(true);
  627. // let installer know, that some instance of application is running
  628. CreateMutex(NULL, False, AppName.c_str());
  629. bool OnlyInstance = (GetLastError() == 0);
  630. UpdateStaticUsage();
  631. UnicodeString KeyFile;
  632. if (Params->FindSwitch(L"PrivateKey", KeyFile))
  633. {
  634. WinConfiguration->DefaultKeyFile = KeyFile;
  635. }
  636. UnicodeString ConsoleVersion;
  637. UnicodeString DotNetVersion;
  638. Params->FindSwitch(L"Console", ConsoleVersion);
  639. Params->FindSwitch(L"DotNet", DotNetVersion);
  640. if (!ConsoleVersion.IsEmpty() || !DotNetVersion.IsEmpty())
  641. {
  642. RecordWrapperVersions(ConsoleVersion, DotNetVersion);
  643. }
  644. if (!DotNetVersion.IsEmpty())
  645. {
  646. Configuration->Usage->Inc(L"ConsoleDotNet");
  647. }
  648. UnicodeString SwitchValue;
  649. if (Params->FindSwitch(L"loglevel", SwitchValue))
  650. {
  651. int StarPos = SwitchValue.Pos(L"*");
  652. if (StarPos > 0)
  653. {
  654. bool LogSensitive = true;
  655. SwitchValue.Delete(StarPos, 1);
  656. if ((StarPos <= SwitchValue.Length()) &&
  657. (SwitchValue[StarPos] == L'-'))
  658. {
  659. LogSensitive = false;
  660. SwitchValue.Delete(StarPos, 1);
  661. }
  662. SwitchValue = SwitchValue.Trim();
  663. Configuration->TemporaryLogSensitive(LogSensitive);
  664. }
  665. int LogProtocol;
  666. if (!SwitchValue.IsEmpty() && TryStrToInt(SwitchValue, LogProtocol) && (LogProtocol >= -1))
  667. {
  668. Configuration->TemporaryLogProtocol(LogProtocol);
  669. }
  670. }
  671. if (Params->FindSwitch(LOGSIZE_SWITCH, SwitchValue))
  672. {
  673. int StarPos = SwitchValue.Pos(LOGSIZE_SEPARATOR);
  674. int LogMaxCount = 0;
  675. if (StarPos > 1)
  676. {
  677. if (!TryStrToInt(SwitchValue.SubString(1, StarPos - 1), LogMaxCount))
  678. {
  679. LogMaxCount = -1;
  680. }
  681. SwitchValue.Delete(1, StarPos);
  682. SwitchValue = SwitchValue.Trim();
  683. }
  684. __int64 LogMaxSize;
  685. if ((LogMaxCount >= 0) &&
  686. !SwitchValue.IsEmpty() &&
  687. TryStrToSize(SwitchValue, LogMaxSize))
  688. {
  689. Configuration->TemporaryLogMaxCount(LogMaxCount);
  690. Configuration->TemporaryLogMaxSize(LogMaxSize);
  691. }
  692. }
  693. std::unique_ptr<TStrings> RawSettings(new TStringList());
  694. if (Params->FindSwitch(RAWTRANSFERSETTINGS_SWITCH, RawSettings.get()))
  695. {
  696. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(RawSettings.get(), false));
  697. GUIConfiguration->LoadDefaultCopyParam(OptionsStorage.get());
  698. }
  699. TConsoleMode Mode = cmNone;
  700. if (Params->FindSwitch(L"help") || Params->FindSwitch(L"h") || Params->FindSwitch(L"?"))
  701. {
  702. Mode = cmHelp;
  703. }
  704. else if (Params->FindSwitch(L"batchsettings"))
  705. {
  706. Mode = cmBatchSettings;
  707. }
  708. else if (Params->FindSwitch(KEYGEN_SWITCH))
  709. {
  710. Mode = cmKeyGen;
  711. }
  712. else if (Params->FindSwitch(FINGERPRINTSCAN_SWITCH))
  713. {
  714. Mode = cmFingerprintScan;
  715. }
  716. else if (Params->FindSwitch(DUMPCALLSTACK_SWITCH))
  717. {
  718. Mode = cmDumpCallstack;
  719. }
  720. else if (Params->FindSwitch(INFO_SWITCH))
  721. {
  722. Mode = cmInfo;
  723. }
  724. else if (Params->FindSwitch(COMREGISTRATION_SWITCH))
  725. {
  726. Mode = cmComRegistration;
  727. }
  728. // We have to check for /console only after the other options,
  729. // as the /console is always used when we are run by winscp.com
  730. // (ambiguous use to pass console version)
  731. else if (Params->FindSwitch(L"Console") || Params->FindSwitch(SCRIPT_SWITCH) ||
  732. Params->FindSwitch(COMMAND_SWITCH))
  733. {
  734. Mode = cmScripting;
  735. }
  736. if (Mode != cmNone)
  737. {
  738. return Console(Mode);
  739. }
  740. TTerminalManager * TerminalManager = NULL;
  741. GlyphsModule = NULL;
  742. NonVisualDataModule = NULL;
  743. TStrings * CommandParams = new TStringList;
  744. try
  745. {
  746. TerminalManager = TTerminalManager::Instance();
  747. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  748. try
  749. {
  750. GlyphsModule = new TGlyphsModule(Application);
  751. }
  752. __finally
  753. {
  754. GUIConfiguration->ChangeResourceModule(ResourceModule);
  755. }
  756. NonVisualDataModule = new TNonVisualDataModule(Application);
  757. // The default is 2.5s.
  758. // 20s is used by Office 2010 and Windows 10 Explorer.
  759. // Some applications use an infinite (Thunderbird, Firefox).
  760. // Overriden for some controls using THintInfo.HideTimeout
  761. Application->HintHidePause = 20000;
  762. HintWindowClass = __classid(TScreenTipHintWindow);
  763. UnicodeString IniFileName = Params->SwitchValue(INI_SWITCH);
  764. if (!IniFileName.IsEmpty() && (IniFileName != INI_NUL))
  765. {
  766. UnicodeString IniFileNameExpanded = ExpandEnvironmentVariables(IniFileName);
  767. if (!FileExists(ApiPath(IniFileNameExpanded)))
  768. {
  769. // this should be displayed rather at the very beginning.
  770. // however for simplicity (GUI-only), we do it only here.
  771. MessageDialog(FMTLOAD(FILE_NOT_EXISTS, (IniFileNameExpanded)), qtError, qaOK);
  772. }
  773. }
  774. if (Params->FindSwitch(L"UninstallCleanup"))
  775. {
  776. MaintenanceTask();
  777. // The innosetup cannot skip UninstallCleanup run task for silent uninstalls,
  778. // workaround is that we create mutex in uninstaller, if it runs silent, and
  779. // ignore the UninstallCleanup, when the mutex exists.
  780. if ((OpenMutex(SYNCHRONIZE, false, L"WinSCPSilentUninstall") == NULL) &&
  781. (MessageDialog(LoadStr(UNINSTALL_CLEANUP), qtConfirmation,
  782. qaYes | qaNo, HELP_UNINSTALL_CLEANUP) == qaYes))
  783. {
  784. DoCleanupDialog(StoredSessions, Configuration);
  785. }
  786. }
  787. else if (Params->FindSwitch(L"RegisterForDefaultProtocols") ||
  788. Params->FindSwitch(L"RegisterAsUrlHandler")) // BACKWARD COMPATIBILITY
  789. {
  790. MaintenanceTask();
  791. if (CheckSafe(Params))
  792. {
  793. RegisterForDefaultProtocols();
  794. Configuration->DontSave();
  795. }
  796. }
  797. else if (Params->FindSwitch(L"UnregisterForProtocols"))
  798. {
  799. MaintenanceTask();
  800. if (CheckSafe(Params))
  801. {
  802. UnregisterForProtocols();
  803. Configuration->DontSave();
  804. }
  805. }
  806. else if (Params->FindSwitch(L"AddSearchPath"))
  807. {
  808. MaintenanceTask();
  809. if (CheckSafe(Params))
  810. {
  811. AddSearchPath(ExtractFilePath(Application->ExeName));
  812. Configuration->DontSave();
  813. }
  814. }
  815. else if (Params->FindSwitch(L"RemoveSearchPath"))
  816. {
  817. MaintenanceTask();
  818. if (CheckSafe(Params))
  819. {
  820. try
  821. {
  822. RemoveSearchPath(ExtractFilePath(Application->ExeName));
  823. }
  824. catch(...)
  825. {
  826. // ignore errors
  827. // (RemoveSearchPath is called always on uninstallation,
  828. // even if AddSearchPath was not used, so we would get the error
  829. // always for non-priviledged user)
  830. }
  831. Configuration->DontSave();
  832. }
  833. }
  834. else if (Params->FindSwitch(L"ImportSitesIfAny"))
  835. {
  836. MaintenanceTask();
  837. ImportSitesIfAny();
  838. }
  839. else if (Params->FindSwitch(L"Usage", SwitchValue))
  840. {
  841. MaintenanceTask();
  842. Usage(SwitchValue);
  843. }
  844. else if (Params->FindSwitch(L"Update"))
  845. {
  846. MaintenanceTask();
  847. CheckForUpdates(false);
  848. }
  849. else if (ShowUpdatesIfAvailable())
  850. {
  851. // noop
  852. }
  853. else if (Params->FindSwitch(L"Exit"))
  854. {
  855. // noop
  856. MaintenanceTask();
  857. Configuration->DontSave();
  858. }
  859. else if (Params->FindSwitch(L"MaintenanceTask"))
  860. {
  861. // Parameter /MaintenanceTask can be added to command-line when executing maintenance tasks
  862. // (e.g. from installer) just in case old version of WinSCP is called by mistake
  863. MaintenanceTask();
  864. Configuration->DontSave();
  865. }
  866. else
  867. {
  868. enum { pcNone, pcUpload, pcFullSynchronize, pcSynchronize, pcEdit, pcRefresh } ParamCommand;
  869. ParamCommand = pcNone;
  870. UnicodeString AutoStartSession;
  871. UnicodeString DownloadFile;
  872. bool UseDefaults = false;
  873. // do not check for temp dirs for service tasks (like RegisterAsUrlHandler)
  874. if (OnlyInstance &&
  875. WinConfiguration->TemporaryDirectoryCleanup)
  876. {
  877. TemporaryDirectoryCleanup();
  878. }
  879. WinConfiguration->CheckDefaultTranslation();
  880. // Loading shell image lists here (rather than only on demand when file controls are being created)
  881. // reduces risk of an occasional crash.
  882. // It seems that the point is to load the lists before any call to SHGetFileInfoWithTimeout.
  883. InitFileControls();
  884. if (!Params->Empty)
  885. {
  886. if (Params->FindSwitch(DEFAULTS_SWITCH) && CheckSafe(Params))
  887. {
  888. UseDefaults = true;
  889. }
  890. if (Params->FindSwitch(UPLOAD_SWITCH, CommandParams))
  891. {
  892. ParamCommand = pcUpload;
  893. if (CommandParams->Count == 0)
  894. {
  895. throw Exception(NO_UPLOAD_LIST_ERROR);
  896. }
  897. }
  898. if (Params->FindSwitch(UPLOAD_IF_ANY_SWITCH, CommandParams))
  899. {
  900. if (CommandParams->Count > 0)
  901. {
  902. ParamCommand = pcUpload;
  903. }
  904. }
  905. else if (Params->FindSwitch(SYNCHRONIZE_SWITCH, CommandParams, 4))
  906. {
  907. ParamCommand = pcFullSynchronize;
  908. }
  909. else if (Params->FindSwitch(KEEP_UP_TO_DATE_SWITCH, CommandParams, 4))
  910. {
  911. ParamCommand = pcSynchronize;
  912. }
  913. else if (Params->FindSwitch(L"Edit", CommandParams, 1) &&
  914. (CommandParams->Count == 1))
  915. {
  916. ParamCommand = pcEdit;
  917. }
  918. else if (Params->FindSwitch(REFRESH_SWITCH, CommandParams, 1))
  919. {
  920. ParamCommand = pcRefresh;
  921. }
  922. }
  923. if (Params->ParamCount > 0)
  924. {
  925. AutoStartSession = Params->Param[1];
  926. Params->ParamsProcessed(1, 1);
  927. if ((ParamCommand == pcNone) &&
  928. (WinConfiguration->ExternalSessionInExistingInstance != OpenInNewWindow()) &&
  929. !Params->FindSwitch(NEWINSTANCE_SWICH) &&
  930. SendToAnotherInstance())
  931. {
  932. Configuration->Usage->Inc(L"SendToAnotherInstance");
  933. return 0;
  934. }
  935. UnicodeString CounterName;
  936. if (Params->FindSwitch(JUMPLIST_SWITCH))
  937. {
  938. CounterName = L"CommandLineJumpList";
  939. }
  940. else if (Params->FindSwitch(DESKTOP_SWITCH))
  941. {
  942. CounterName = L"CommandLineDesktop";
  943. }
  944. else if (Params->FindSwitch(SEND_TO_HOOK_SWITCH))
  945. {
  946. CounterName = L"CommandLineSendToHook";
  947. }
  948. else
  949. {
  950. CounterName = L"CommandLineSession2";
  951. }
  952. Configuration->Usage->Inc(CounterName);
  953. }
  954. else if (WinConfiguration->EmbeddedSessions && StoredSessions->Count)
  955. {
  956. AutoStartSession = StoredSessions->Sessions[0]->Name;
  957. }
  958. else
  959. {
  960. AutoStartSession = WinConfiguration->AutoStartSession;
  961. }
  962. if (ParamCommand == pcRefresh)
  963. {
  964. Refresh(AutoStartSession, (CommandParams->Count > 0 ? CommandParams->Strings[0] : UnicodeString()));
  965. return 0;
  966. }
  967. // from now flash message boxes on background
  968. SetOnForeground(false);
  969. bool NeedSession = (ParamCommand != pcNone);
  970. bool Retry;
  971. do
  972. {
  973. Retry = false;
  974. std::unique_ptr<TObjectList> DataList(new TObjectList());
  975. try
  976. {
  977. GetLoginData(AutoStartSession, Params, DataList.get(), DownloadFile, NeedSession, NULL, pufAllowStoredSiteWithProtocol);
  978. // GetLoginData now Aborts when session is needed and none is selected
  979. if (DebugAlwaysTrue(!NeedSession || (DataList->Count > 0)))
  980. {
  981. if (CheckSafe(Params))
  982. {
  983. UnicodeString LogFile;
  984. if (Params->FindSwitch(LOG_SWITCH, LogFile))
  985. {
  986. Configuration->TemporaryLogging(LogFile);
  987. }
  988. if (Params->FindSwitch(L"XmlLog", LogFile))
  989. {
  990. Configuration->TemporaryActionsLogging(LogFile);
  991. }
  992. }
  993. try
  994. {
  995. DebugAssert(!TerminalManager->ActiveTerminal);
  996. bool CanStart;
  997. if (DataList->Count > 0)
  998. {
  999. TManagedTerminal * Terminal = TerminalManager->NewTerminals(DataList.get());
  1000. if (!DownloadFile.IsEmpty())
  1001. {
  1002. Terminal->AutoReadDirectory = false;
  1003. DownloadFile = UnixIncludeTrailingBackslash(Terminal->SessionData->RemoteDirectory) + DownloadFile;
  1004. Terminal->SessionData->RemoteDirectory = L"";
  1005. Terminal->StateData->RemoteDirectory = Terminal->SessionData->RemoteDirectory;
  1006. }
  1007. TerminalManager->ActiveTerminal = Terminal;
  1008. CanStart = (TerminalManager->Count > 0);
  1009. }
  1010. else
  1011. {
  1012. DebugAssert(!NeedSession);
  1013. CanStart = true;
  1014. }
  1015. if (!CanStart)
  1016. {
  1017. // do not prompt with login dialog, if connection of
  1018. // auto-start session (typically from command line) failed
  1019. if (AutoStartSession.IsEmpty())
  1020. {
  1021. Retry = true;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. // from now on, we do not support runtime interface change
  1027. CustomWinConfiguration->CanApplyInterfaceImmediately = false;
  1028. TCustomScpExplorerForm * ScpExplorer = CreateScpExplorer();
  1029. CustomWinConfiguration->AppliedInterface = CustomWinConfiguration->Interface;
  1030. try
  1031. {
  1032. // moved inside try .. __finally, because it can fail as well
  1033. TerminalManager->ScpExplorer = ScpExplorer;
  1034. if ((ParamCommand != pcNone) || !DownloadFile.IsEmpty())
  1035. {
  1036. Configuration->Usage->Inc(L"CommandLineOperation");
  1037. }
  1038. if (ParamCommand == pcUpload)
  1039. {
  1040. Upload(TerminalManager->ActiveTerminal, CommandParams, UseDefaults);
  1041. }
  1042. else if (ParamCommand == pcFullSynchronize)
  1043. {
  1044. FullSynchronize(TerminalManager->ActiveTerminal, ScpExplorer,
  1045. CommandParams, UseDefaults);
  1046. }
  1047. else if (ParamCommand == pcSynchronize)
  1048. {
  1049. Synchronize(TerminalManager->ActiveTerminal, ScpExplorer,
  1050. CommandParams, UseDefaults);
  1051. }
  1052. else if (ParamCommand == pcEdit)
  1053. {
  1054. Edit(ScpExplorer, CommandParams);
  1055. }
  1056. else if (!DownloadFile.IsEmpty())
  1057. {
  1058. Download(TerminalManager->ActiveTerminal, DownloadFile,
  1059. UseDefaults);
  1060. }
  1061. Application->Run();
  1062. // to allow dialog boxes show later (like from CheckConfigurationForceSave)
  1063. SetAppTerminated(False);
  1064. }
  1065. __finally
  1066. {
  1067. TerminalManager->ScpExplorer = NULL;
  1068. SAFE_DESTROY(ScpExplorer);
  1069. }
  1070. }
  1071. }
  1072. catch (Exception &E)
  1073. {
  1074. ShowExtendedException(&E);
  1075. }
  1076. }
  1077. }
  1078. // Catch EAbort from Synchronize() and similar functions, so that CheckConfigurationForceSave is processed
  1079. catch (EAbort & E)
  1080. {
  1081. Retry = false; // unlikely to be true, but just in case
  1082. }
  1083. }
  1084. while (Retry);
  1085. }
  1086. // In GUI mode only
  1087. CheckConfigurationForceSave();
  1088. }
  1089. __finally
  1090. {
  1091. delete NonVisualDataModule;
  1092. NonVisualDataModule = NULL;
  1093. ReleaseImagesModules();
  1094. delete GlyphsModule;
  1095. GlyphsModule = NULL;
  1096. TTerminalManager::DestroyInstance();
  1097. delete CommandParams;
  1098. }
  1099. return 0;
  1100. }