WinMain.cpp 39 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, int 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 == 0) ||
  97. DoCopyDialog(true, false, FileList, TargetDirectory, &CopyParam, Options,
  98. CopyParamAttrs, Data.get(), NULL, UseDefaults))
  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, int UseDefaults)
  107. {
  108. TRemoteFile * File = NULL;
  109. try
  110. {
  111. Terminal->ExceptionOnFail = true;
  112. try
  113. {
  114. Terminal->ReadFile(FileName, File);
  115. }
  116. __finally
  117. {
  118. Terminal->ExceptionOnFail = false;
  119. }
  120. File->FullFileName = FileName;
  121. UnicodeString LocalDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  122. if (LocalDirectory.IsEmpty())
  123. {
  124. LocalDirectory = GetPersonalFolder();
  125. }
  126. UnicodeString TargetDirectory = IncludeTrailingBackslash(LocalDirectory);
  127. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  128. UnicodeString DisplayName = File->FileName;
  129. bool CustomDisplayName =
  130. !File->DisplayName.IsEmpty() &&
  131. (File->DisplayName != DisplayName);
  132. if (CustomDisplayName)
  133. {
  134. DisplayName = File->DisplayName;
  135. }
  136. UnicodeString FriendyFileName = UnixIncludeTrailingBackslash(UnixExtractFilePath(FileName)) + DisplayName;
  137. std::unique_ptr<TStrings> FileListFriendly(new TStringList());
  138. FileListFriendly->AddObject(FriendyFileName, File);
  139. int Options = coDisableQueue;
  140. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Download;
  141. if ((UseDefaults == 0) ||
  142. DoCopyDialog(false, false, FileListFriendly.get(), TargetDirectory, &CopyParam,
  143. Options, CopyParamAttrs, NULL, NULL, UseDefaults))
  144. {
  145. // Setting parameter overrides only now, otherwise the dialog would present the parametes as non-default
  146. if (CustomDisplayName)
  147. {
  148. // Set only now, so that it is not redundantly displayed on the copy dialog.
  149. // We should escape the * and ?'s.
  150. CopyParam.FileMask = DisplayName;
  151. }
  152. CopyParam.OnceDoneOperation = odoDisconnect;
  153. std::unique_ptr<TStrings> FileList(new TStringList());
  154. FileList->AddObject(FileName, File);
  155. Terminal->CopyToLocal(FileList.get(), TargetDirectory, &CopyParam, 0, NULL);
  156. }
  157. UnicodeString Directory = UnixExtractFilePath(FileName);
  158. Terminal->AutoReadDirectory = true;
  159. Terminal->ChangeDirectory(Directory);
  160. }
  161. __finally
  162. {
  163. delete File;
  164. }
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall Edit(TCustomScpExplorerForm * ScpExplorer, TStrings * FileList)
  168. {
  169. ScpExplorer->StandaloneEdit(FileList->Strings[0]);
  170. Abort();
  171. }
  172. //---------------------------------------------------------------------------
  173. void __fastcall SynchronizeDirectories(TTerminal * Terminal,
  174. TStrings * CommandParams,
  175. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory)
  176. {
  177. if (CommandParams->Count >= 1)
  178. {
  179. LocalDirectory = CommandParams->Strings[0];
  180. }
  181. else if (!Terminal->SessionData->LocalDirectory.IsEmpty())
  182. {
  183. LocalDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  184. }
  185. else
  186. {
  187. LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  188. }
  189. if (CommandParams->Count >= 2)
  190. {
  191. RemoteDirectory = CommandParams->Strings[1];
  192. }
  193. else
  194. {
  195. RemoteDirectory = Terminal->CurrentDirectory;
  196. }
  197. }
  198. //---------------------------------------------------------------------------
  199. void __fastcall FullSynchronize(
  200. TTerminal * Terminal, TCustomScpExplorerForm * ScpExplorer, TStrings * CommandParams, int UseDefaults)
  201. {
  202. UnicodeString LocalDirectory;
  203. UnicodeString RemoteDirectory;
  204. SynchronizeDirectories(Terminal, CommandParams, LocalDirectory, RemoteDirectory);
  205. bool SaveMode = true;
  206. // bit ugly
  207. TSynchronizeMode Mode = (TSynchronizeMode)GUIConfiguration->SynchronizeMode;
  208. int Params = GUIConfiguration->SynchronizeParams;
  209. // Undocumented syntax for "Start in New Window"
  210. if (CommandParams->Count >= 4)
  211. {
  212. Mode = (TSynchronizeMode)StrToIntDef(CommandParams->Strings[2], Mode);
  213. Params = StrToIntDef(CommandParams->Strings[3], Params);
  214. }
  215. int Result =
  216. ScpExplorer->DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, UseDefaults);
  217. if ((Result >= 0) && SaveMode)
  218. {
  219. GUIConfiguration->SynchronizeMode = Mode;
  220. }
  221. Abort();
  222. }
  223. //---------------------------------------------------------------------------
  224. void __fastcall Synchronize(
  225. TTerminal * Terminal, TCustomScpExplorerForm * ScpExplorer, TStrings * CommandParams, int UseDefaults)
  226. {
  227. UnicodeString LocalDirectory;
  228. UnicodeString RemoteDirectory;
  229. SynchronizeDirectories(Terminal, CommandParams, LocalDirectory, RemoteDirectory);
  230. // Undocumented syntax for "Start in New Window"
  231. if (CommandParams->Count >= 4)
  232. {
  233. GUIConfiguration->SynchronizeParams = StrToIntDef(CommandParams->Strings[2], -1);
  234. GUIConfiguration->SynchronizeOptions = StrToIntDef(CommandParams->Strings[3], -1);
  235. Configuration->DontSave();
  236. }
  237. ScpExplorer->DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, UseDefaults);
  238. Abort();
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall ImportSitesIfAny()
  242. {
  243. if (!WinConfiguration->AutoImportedFromPuttyOrFilezilla)
  244. {
  245. bool AnyPuttySession = GUIConfiguration->AnyPuttySessionForImport(StoredSessions);
  246. bool AnyFilezillaSession = GUIConfiguration->AnyFilezillaSessionForImport(StoredSessions);
  247. if (AnyPuttySession || AnyFilezillaSession)
  248. {
  249. UnicodeString PuttySource = LoadStrPart(IMPORT_SESSIONS2, 2);
  250. UnicodeString FilezillaSource = LoadStrPart(IMPORT_SESSIONS2, 3);
  251. UnicodeString Source;
  252. if (AnyPuttySession && AnyFilezillaSession)
  253. {
  254. Source = FORMAT(LoadStrPart(IMPORT_SESSIONS2, 4), (PuttySource, FilezillaSource));
  255. }
  256. else if (AnyPuttySession)
  257. {
  258. Source = PuttySource;
  259. }
  260. else if (AnyFilezillaSession)
  261. {
  262. Source = FilezillaSource;
  263. }
  264. else
  265. {
  266. DebugFail();
  267. }
  268. UnicodeString Message = FORMAT(LoadStrPart(IMPORT_SESSIONS2, 1), (Source));
  269. if (MessageDialog(Message, qtConfirmation,
  270. qaYes | qaNo, HELP_IMPORT_SESSIONS) == qaYes)
  271. {
  272. DoImportSessionsDialog(NULL);
  273. }
  274. WinConfiguration->AutoImportedFromPuttyOrFilezilla = true;
  275. }
  276. }
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall Usage(UnicodeString Param)
  280. {
  281. while (!Param.IsEmpty())
  282. {
  283. UnicodeString Pair = CutToChar(Param, L',', true);
  284. if (!Pair.IsEmpty())
  285. {
  286. if (Pair[Pair.Length()] == L'+')
  287. {
  288. UnicodeString Key = Pair.SubString(1, Pair.Length() - 1).Trim();
  289. Configuration->Usage->Inc(Key);
  290. }
  291. else
  292. {
  293. UnicodeString Key = CutToChar(Pair, L':', true);
  294. Configuration->Usage->Set(Key, Pair.Trim());
  295. }
  296. }
  297. }
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall RecordWrapperVersions(UnicodeString ConsoleVersion, UnicodeString DotNetVersion)
  301. {
  302. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  303. if (!DotNetVersion.IsEmpty())
  304. {
  305. Updates.DotNetVersion = DotNetVersion;
  306. }
  307. if (!ConsoleVersion.IsEmpty())
  308. {
  309. Updates.ConsoleVersion = ConsoleVersion;
  310. }
  311. WinConfiguration->Updates = Updates;
  312. if (Configuration->Storage == stNul)
  313. {
  314. Configuration->SetDefaultStorage();
  315. try
  316. {
  317. THierarchicalStorage * Storage = Configuration->CreateConfigStorage();
  318. try
  319. {
  320. Storage->AccessMode = smReadWrite;
  321. if (Storage->OpenSubKey(Configuration->ConfigurationSubKey, true) &&
  322. Storage->OpenSubKeyPath(L"Interface\\Updates", true))
  323. {
  324. if (!DotNetVersion.IsEmpty())
  325. {
  326. Storage->WriteString(L"DotNetVersion", DotNetVersion);
  327. }
  328. if (!ConsoleVersion.IsEmpty())
  329. {
  330. Storage->WriteString(L"ConsoleVersion", ConsoleVersion);
  331. }
  332. }
  333. }
  334. __finally
  335. {
  336. delete Storage;
  337. }
  338. }
  339. __finally
  340. {
  341. Configuration->SetNulStorage();
  342. }
  343. }
  344. }
  345. //---------------------------------------------------------------------------
  346. static UnicodeString ColorToRGBStr(TColor Color)
  347. {
  348. int RGB = ColorToRGB(Color);
  349. int R = GetRValue(RGB);
  350. int G = GetGValue(RGB);
  351. int B = GetBValue(RGB);
  352. UnicodeString Result = FORMAT(L"%.2x%.2x%.2x", (R, G, B));
  353. return Result;
  354. }
  355. //---------------------------------------------------------------------------
  356. void __fastcall UpdateStaticUsage()
  357. {
  358. Configuration->Usage->Inc(L"Runs");
  359. Configuration->Usage->UpdateCurrentVersion();
  360. Configuration->Usage->Set(L"WindowsVersion", (WindowsVersionLong()));
  361. Configuration->Usage->Set(L"WindowsProductName", (WindowsProductName()));
  362. DWORD Type;
  363. GetWindowsProductType(Type);
  364. Configuration->Usage->Set(L"WindowsProductType", (static_cast<int>(Type)));
  365. Configuration->Usage->Set(L"Windows64", IsWin64());
  366. Configuration->Usage->Set(L"UWP", IsUWP());
  367. Configuration->Usage->Set(L"DefaultLocale",
  368. // See TGUIConfiguration::GetAppliedLocaleHex()
  369. IntToHex(static_cast<int>(GetDefaultLCID()), 4));
  370. Configuration->Usage->Set(L"Locale", WinConfiguration->AppliedLocaleHex);
  371. Configuration->Usage->Set(L"EncodingMultiByteAnsi", !TEncoding::Default->IsSingleByte);
  372. Configuration->Usage->Set(L"PixelsPerInch", Screen->PixelsPerInch);
  373. bool PixelsPerInchSystemDiffers = false;
  374. bool PixelsPerInchMonitorsDiffer = false;
  375. bool PixelsPerInchAxesDiffer = false;
  376. HINSTANCE ShCoreLibrary = LoadLibrary(L"shcore.dll");
  377. if (ShCoreLibrary != NULL)
  378. {
  379. GetDpiForMonitorProc GetDpiForMonitor =
  380. (GetDpiForMonitorProc)GetProcAddress(ShCoreLibrary, "GetDpiForMonitor");
  381. if (GetDpiForMonitor != NULL)
  382. {
  383. unsigned int PrimaryDpiX;
  384. unsigned int PrimaryDpiY;
  385. for (int Index = 0; Index < Screen->MonitorCount; Index++)
  386. {
  387. unsigned int DpiX;
  388. unsigned int DpiY;
  389. GetDpiForMonitor(Screen->Monitors[Index]->Handle, MDT_Default, &DpiX, &DpiY);
  390. if (DpiX != DpiY)
  391. {
  392. PixelsPerInchAxesDiffer = true;
  393. }
  394. if (Index == 0)
  395. {
  396. PrimaryDpiX = DpiX;
  397. PrimaryDpiY = DpiY;
  398. // PixelsPerInch is GetDeviceCaps(DC, LOGPIXELSY)
  399. if (DpiY != (unsigned int)Screen->PixelsPerInch)
  400. {
  401. PixelsPerInchSystemDiffers = true;
  402. }
  403. }
  404. else
  405. {
  406. if ((DpiX != PrimaryDpiX) ||
  407. (DpiY != PrimaryDpiY))
  408. {
  409. PixelsPerInchMonitorsDiffer = true;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. if (PixelsPerInchSystemDiffers)
  416. {
  417. Configuration->Usage->Inc(L"PixelsPerInchSystemDiffered");
  418. }
  419. Configuration->Usage->Set(L"PixelsPerInchMonitorsDiffer", PixelsPerInchMonitorsDiffer);
  420. Configuration->Usage->Set(L"PixelsPerInchAxesDiffer", PixelsPerInchAxesDiffer);
  421. Configuration->Usage->Set(L"WorkAreaWidth", Screen->WorkAreaWidth);
  422. Configuration->Usage->Set(L"WorkAreaHeight", Screen->WorkAreaHeight);
  423. HDC DC = GetDC(NULL);
  424. int Planes = GetDeviceCaps(DC, PLANES);
  425. int BitsPixel = GetDeviceCaps(DC, BITSPIXEL);
  426. Configuration->Usage->Set(L"ColorDepth", Planes * BitsPixel);
  427. Configuration->Usage->Set(L"MonitorCount", Screen->MonitorCount);
  428. Configuration->Usage->Set(L"NotUseThemes", !UseThemes());
  429. Configuration->Usage->Set(L"ThemeDefaultFontSize", Application->DefaultFont->Size);
  430. Configuration->Usage->Set(L"ThemeIconFontSize", Screen->IconFont->Size);
  431. Configuration->Usage->Set(L"SysColorWindow", ColorToRGBStr(clWindow));
  432. Configuration->Usage->Set(L"SysColorBtnFace", ColorToRGBStr(clBtnFace));
  433. Configuration->Usage->Set(L"SysColorWindowText", ColorToRGBStr(clWindowText));
  434. UnicodeString ProgramsFolder;
  435. ::SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  436. ProgramsFolder = IncludeTrailingBackslash(ExpandFileName(ProgramsFolder));
  437. UnicodeString ExeName = ExpandFileName(Application->ExeName);
  438. bool InProgramFiles = AnsiSameText(ExeName.SubString(1, ProgramsFolder.Length()), ProgramsFolder);
  439. Configuration->Usage->Set(L"InProgramFiles", InProgramFiles);
  440. Configuration->Usage->Set(L"IsInstalled", IsInstalled());
  441. Configuration->Usage->Set(L"Wine", IsWine());
  442. Configuration->Usage->Set(L"NetFrameworkVersion", GetNetVersionStr());
  443. Configuration->Usage->Set(L"PowerShellVersion", GetPowerShellVersionStr());
  444. WinConfiguration->UpdateStaticUsage();
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall MaintenanceTask()
  448. {
  449. CoreMaintenanceTask();
  450. }
  451. //---------------------------------------------------------------------------
  452. typedef std::vector<HWND> THandles;
  453. typedef std::map<unsigned long, THandles> TProcesses;
  454. //---------------------------------------------------------------------------
  455. BOOL __stdcall EnumOtherInstances(HWND Handle, LPARAM AParam)
  456. {
  457. TProcesses & Processes = *reinterpret_cast<TProcesses *>(AParam);
  458. unsigned long ProcessId;
  459. if (GetWindowThreadProcessId(Handle, &ProcessId) != 0)
  460. {
  461. Processes[ProcessId].push_back(Handle);
  462. }
  463. return TRUE;
  464. }
  465. //---------------------------------------------------------------------------
  466. static bool __fastcall SendCopyDataMessage(HWND Window, TCopyDataMessage & Message)
  467. {
  468. COPYDATASTRUCT CopyData;
  469. CopyData.cbData = sizeof(Message);
  470. CopyData.lpData = &Message;
  471. LRESULT SendResult =
  472. SendMessage(Window, WM_COPYDATA,
  473. reinterpret_cast<WPARAM>(HInstance), reinterpret_cast<LPARAM>(&CopyData));
  474. bool Result = (SendResult > 0);
  475. return Result;
  476. }
  477. //---------------------------------------------------------------------------
  478. static void __fastcall FindOtherInstances(THandles & OtherInstances)
  479. {
  480. TProcesses Processes;
  481. // FindWindow is optimization (if there's no hidden window, no point enumerating all windows to find some)
  482. if ((FindWindow(HIDDEN_WINDOW_NAME, NULL) != NULL) &&
  483. EnumWindows(EnumOtherInstances, reinterpret_cast<LPARAM>(&Processes)))
  484. {
  485. TCopyDataMessage Message;
  486. Message.Command = TCopyDataMessage::MainWindowCheck;
  487. TProcesses::const_iterator ProcessI = Processes.begin();
  488. while (ProcessI != Processes.end())
  489. {
  490. HWND HiddenWindow = NULL;
  491. THandles::const_iterator WindowI = ProcessI->second.begin();
  492. while ((HiddenWindow == NULL) && (WindowI != ProcessI->second.end()))
  493. {
  494. wchar_t ClassName[1024];
  495. if (GetClassName(*WindowI, ClassName, LENOF(ClassName)) != 0)
  496. {
  497. NULL_TERMINATE(ClassName);
  498. if (wcscmp(ClassName, HIDDEN_WINDOW_NAME) == 0)
  499. {
  500. HiddenWindow = *WindowI;
  501. }
  502. }
  503. WindowI++;
  504. }
  505. if (HiddenWindow != NULL)
  506. {
  507. WindowI = ProcessI->second.begin();
  508. while (WindowI != ProcessI->second.end())
  509. {
  510. if (*WindowI != HiddenWindow) // optimization
  511. {
  512. if (SendCopyDataMessage(*WindowI, Message))
  513. {
  514. OtherInstances.push_back(*WindowI);
  515. break;
  516. }
  517. }
  518. WindowI++;
  519. }
  520. }
  521. ProcessI++;
  522. }
  523. }
  524. }
  525. //---------------------------------------------------------------------------
  526. bool __fastcall SendToAnotherInstance()
  527. {
  528. THandles OtherInstances;
  529. FindOtherInstances(OtherInstances);
  530. bool Result = false;
  531. THandles::const_iterator I = OtherInstances.begin();
  532. while (!Result && (I != OtherInstances.end()))
  533. {
  534. HWND Handle = *I;
  535. TCopyDataMessage Message;
  536. Message.Command = TCopyDataMessage::CommandCanCommandLine;
  537. if (SendCopyDataMessage(Handle, Message))
  538. {
  539. // Restore window, if minimized
  540. ShowWindow(Handle, SW_RESTORE);
  541. // bring it to foreground
  542. SetForegroundWindow(Handle);
  543. Message.Command = TCopyDataMessage::CommandCommandLine;
  544. wcsncpy(Message.CommandLine, CmdLine, LENOF(Message.CommandLine));
  545. NULL_TERMINATE(Message.CommandLine);
  546. Result = SendCopyDataMessage(Handle, Message);
  547. }
  548. I++;
  549. }
  550. return Result;
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall Refresh(const UnicodeString & Session, const UnicodeString & Path)
  554. {
  555. THandles OtherInstances;
  556. FindOtherInstances(OtherInstances);
  557. THandles::const_iterator I = OtherInstances.begin();
  558. while (I != OtherInstances.end())
  559. {
  560. HWND Handle = *I;
  561. TCopyDataMessage Message;
  562. Message.Command = TCopyDataMessage::RefreshPanel;
  563. wcsncpy(Message.Refresh.Session, Session.c_str(), LENOF(Message.Refresh.Session));
  564. NULL_TERMINATE(Message.Refresh.Session);
  565. wcsncpy(Message.Refresh.Path, Path.c_str(), LENOF(Message.Refresh.Path));
  566. NULL_TERMINATE(Message.Refresh.Path);
  567. SendCopyDataMessage(Handle, Message);
  568. I++;
  569. }
  570. }
  571. //---------------------------------------------------------------------------
  572. bool __fastcall ShowUpdatesIfAvailable()
  573. {
  574. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  575. int CurrentCompoundVer = Configuration->CompoundVersion;
  576. bool NoPopup = true;
  577. bool Result =
  578. !IsUWP() &&
  579. Updates.ShowOnStartup &&
  580. Updates.HaveValidResultsForVersion(CurrentCompoundVer) &&
  581. !Updates.Results.Disabled &&
  582. ((Updates.Results.Version > CurrentCompoundVer) || !Updates.Results.Message.IsEmpty()) &&
  583. !Updates.ShownResults;
  584. if (Result)
  585. {
  586. Configuration->Usage->Inc(L"UpdateStartup");
  587. Result = CheckForUpdates(true);
  588. if (Result)
  589. {
  590. Configuration->Usage->Inc(L"UpdateDownloadOpensStartup");
  591. }
  592. NoPopup = false;
  593. }
  594. else if (WinConfiguration->ShowTips)
  595. {
  596. int Days = DaysBetween(WinConfiguration->TipsShown, Now());
  597. if ((Days >= Updates.Results.TipsIntervalDays) &&
  598. (WinConfiguration->RunsSinceLastTip >= Updates.Results.TipsIntervalDays))
  599. {
  600. UnicodeString Tip = FirstUnshownTip();
  601. if (!Tip.IsEmpty())
  602. {
  603. AutoShowNewTip();
  604. NoPopup = false;
  605. }
  606. else
  607. {
  608. Configuration->Usage->Inc(L"TipsNoUnseen");
  609. }
  610. }
  611. }
  612. if (NoPopup)
  613. {
  614. WinConfiguration->RunsSinceLastTip = WinConfiguration->RunsSinceLastTip + 1;
  615. }
  616. return Result;
  617. }
  618. //---------------------------------------------------------------------------
  619. int __fastcall Execute()
  620. {
  621. DebugAssert(StoredSessions);
  622. TProgramParams * Params = TProgramParams::Instance();
  623. DebugAssert(Params);
  624. // do not flash message boxes on startup
  625. SetOnForeground(true);
  626. // let installer know, that some instance of application is running
  627. CreateMutex(NULL, False, AppName.c_str());
  628. bool OnlyInstance = (GetLastError() == 0);
  629. UpdateStaticUsage();
  630. UnicodeString KeyFile;
  631. if (Params->FindSwitch(L"PrivateKey", KeyFile))
  632. {
  633. WinConfiguration->DefaultKeyFile = KeyFile;
  634. }
  635. UnicodeString ConsoleVersion;
  636. UnicodeString DotNetVersion;
  637. Params->FindSwitch(L"Console", ConsoleVersion);
  638. Params->FindSwitch(L"DotNet", DotNetVersion);
  639. if (!ConsoleVersion.IsEmpty() || !DotNetVersion.IsEmpty())
  640. {
  641. RecordWrapperVersions(ConsoleVersion, DotNetVersion);
  642. }
  643. if (!DotNetVersion.IsEmpty())
  644. {
  645. Configuration->Usage->Inc(L"ConsoleDotNet");
  646. }
  647. UnicodeString SwitchValue;
  648. if (Params->FindSwitch(L"loglevel", SwitchValue))
  649. {
  650. int StarPos = SwitchValue.Pos(L"*");
  651. if (StarPos > 0)
  652. {
  653. bool LogSensitive = true;
  654. SwitchValue.Delete(StarPos, 1);
  655. if ((StarPos <= SwitchValue.Length()) &&
  656. (SwitchValue[StarPos] == L'-'))
  657. {
  658. LogSensitive = false;
  659. SwitchValue.Delete(StarPos, 1);
  660. }
  661. SwitchValue = SwitchValue.Trim();
  662. Configuration->TemporaryLogSensitive(LogSensitive);
  663. }
  664. int LogProtocol;
  665. if (!SwitchValue.IsEmpty() && TryStrToInt(SwitchValue, LogProtocol) && (LogProtocol >= -1))
  666. {
  667. Configuration->TemporaryLogProtocol(LogProtocol);
  668. }
  669. }
  670. if (Params->FindSwitch(LOGSIZE_SWITCH, SwitchValue))
  671. {
  672. int StarPos = SwitchValue.Pos(LOGSIZE_SEPARATOR);
  673. int LogMaxCount = 0;
  674. if (StarPos > 1)
  675. {
  676. if (!TryStrToInt(SwitchValue.SubString(1, StarPos - 1), LogMaxCount))
  677. {
  678. LogMaxCount = -1;
  679. }
  680. SwitchValue.Delete(1, StarPos);
  681. SwitchValue = SwitchValue.Trim();
  682. }
  683. __int64 LogMaxSize;
  684. if ((LogMaxCount >= 0) &&
  685. !SwitchValue.IsEmpty() &&
  686. TryStrToSize(SwitchValue, LogMaxSize))
  687. {
  688. Configuration->TemporaryLogMaxCount(LogMaxCount);
  689. Configuration->TemporaryLogMaxSize(LogMaxSize);
  690. }
  691. }
  692. std::unique_ptr<TStrings> RawSettings(new TStringList());
  693. if (Params->FindSwitch(RAWTRANSFERSETTINGS_SWITCH, RawSettings.get()))
  694. {
  695. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(RawSettings.get(), false));
  696. GUIConfiguration->LoadDefaultCopyParam(OptionsStorage.get());
  697. }
  698. TConsoleMode Mode = cmNone;
  699. if (Params->FindSwitch(L"help") || Params->FindSwitch(L"h") || Params->FindSwitch(L"?"))
  700. {
  701. Mode = cmHelp;
  702. }
  703. else if (Params->FindSwitch(L"batchsettings"))
  704. {
  705. Mode = cmBatchSettings;
  706. }
  707. else if (Params->FindSwitch(KEYGEN_SWITCH))
  708. {
  709. Mode = cmKeyGen;
  710. }
  711. else if (Params->FindSwitch(FINGERPRINTSCAN_SWITCH))
  712. {
  713. Mode = cmFingerprintScan;
  714. }
  715. else if (Params->FindSwitch(DUMPCALLSTACK_SWITCH))
  716. {
  717. Mode = cmDumpCallstack;
  718. }
  719. else if (Params->FindSwitch(INFO_SWITCH))
  720. {
  721. Mode = cmInfo;
  722. }
  723. else if (Params->FindSwitch(COMREGISTRATION_SWITCH))
  724. {
  725. Mode = cmComRegistration;
  726. }
  727. // We have to check for /console only after the other options,
  728. // as the /console is always used when we are run by winscp.com
  729. // (ambiguous use to pass console version)
  730. else if (Params->FindSwitch(L"Console") || Params->FindSwitch(SCRIPT_SWITCH) ||
  731. Params->FindSwitch(COMMAND_SWITCH))
  732. {
  733. Mode = cmScripting;
  734. }
  735. if (Mode != cmNone)
  736. {
  737. return Console(Mode);
  738. }
  739. TTerminalManager * TerminalManager = NULL;
  740. GlyphsModule = NULL;
  741. NonVisualDataModule = NULL;
  742. TStrings * CommandParams = new TStringList;
  743. try
  744. {
  745. TerminalManager = TTerminalManager::Instance();
  746. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  747. try
  748. {
  749. GlyphsModule = new TGlyphsModule(Application);
  750. }
  751. __finally
  752. {
  753. GUIConfiguration->ChangeResourceModule(ResourceModule);
  754. }
  755. NonVisualDataModule = new TNonVisualDataModule(Application);
  756. // The default is 2.5s.
  757. // 20s is used by Office 2010 and Windows 10 Explorer.
  758. // Some applications use an infinite (Thunderbird, Firefox).
  759. // Overriden for some controls using THintInfo.HideTimeout
  760. Application->HintHidePause = 20000;
  761. HintWindowClass = __classid(TScreenTipHintWindow);
  762. UnicodeString IniFileName = Params->SwitchValue(INI_SWITCH);
  763. if (!IniFileName.IsEmpty() && (IniFileName != INI_NUL))
  764. {
  765. UnicodeString IniFileNameExpanded = ExpandEnvironmentVariables(IniFileName);
  766. if (!FileExists(ApiPath(IniFileNameExpanded)))
  767. {
  768. // this should be displayed rather at the very beginning.
  769. // however for simplicity (GUI-only), we do it only here.
  770. MessageDialog(FMTLOAD(FILE_NOT_EXISTS, (IniFileNameExpanded)), qtError, qaOK);
  771. }
  772. }
  773. if (Params->FindSwitch(L"UninstallCleanup"))
  774. {
  775. MaintenanceTask();
  776. // The innosetup cannot skip UninstallCleanup run task for silent uninstalls,
  777. // workaround is that we create mutex in uninstaller, if it runs silent, and
  778. // ignore the UninstallCleanup, when the mutex exists.
  779. if ((OpenMutex(SYNCHRONIZE, false, L"WinSCPSilentUninstall") == NULL) &&
  780. (MessageDialog(LoadStr(UNINSTALL_CLEANUP), qtConfirmation,
  781. qaYes | qaNo, HELP_UNINSTALL_CLEANUP) == qaYes))
  782. {
  783. DoCleanupDialog(StoredSessions, Configuration);
  784. }
  785. }
  786. else if (Params->FindSwitch(L"RegisterForDefaultProtocols") ||
  787. Params->FindSwitch(L"RegisterAsUrlHandler")) // BACKWARD COMPATIBILITY
  788. {
  789. MaintenanceTask();
  790. if (CheckSafe(Params))
  791. {
  792. RegisterForDefaultProtocols();
  793. Configuration->DontSave();
  794. }
  795. }
  796. else if (Params->FindSwitch(L"UnregisterForProtocols"))
  797. {
  798. MaintenanceTask();
  799. if (CheckSafe(Params))
  800. {
  801. UnregisterForProtocols();
  802. Configuration->DontSave();
  803. }
  804. }
  805. else if (Params->FindSwitch(L"AddSearchPath"))
  806. {
  807. MaintenanceTask();
  808. if (CheckSafe(Params))
  809. {
  810. AddSearchPath(ExtractFilePath(Application->ExeName));
  811. Configuration->DontSave();
  812. }
  813. }
  814. else if (Params->FindSwitch(L"RemoveSearchPath"))
  815. {
  816. MaintenanceTask();
  817. if (CheckSafe(Params))
  818. {
  819. try
  820. {
  821. RemoveSearchPath(ExtractFilePath(Application->ExeName));
  822. }
  823. catch(...)
  824. {
  825. // ignore errors
  826. // (RemoveSearchPath is called always on uninstallation,
  827. // even if AddSearchPath was not used, so we would get the error
  828. // always for non-priviledged user)
  829. }
  830. Configuration->DontSave();
  831. }
  832. }
  833. else if (Params->FindSwitch(L"ImportSitesIfAny"))
  834. {
  835. MaintenanceTask();
  836. ImportSitesIfAny();
  837. }
  838. else if (Params->FindSwitch(L"Usage", SwitchValue))
  839. {
  840. MaintenanceTask();
  841. Usage(SwitchValue);
  842. }
  843. else if (Params->FindSwitch(L"Update"))
  844. {
  845. MaintenanceTask();
  846. CheckForUpdates(false);
  847. }
  848. else if (ShowUpdatesIfAvailable())
  849. {
  850. // noop
  851. }
  852. else if (Params->FindSwitch(L"Exit"))
  853. {
  854. // noop
  855. MaintenanceTask();
  856. Configuration->DontSave();
  857. }
  858. else if (Params->FindSwitch(L"MaintenanceTask"))
  859. {
  860. // Parameter /MaintenanceTask can be added to command-line when executing maintenance tasks
  861. // (e.g. from installer) just in case old version of WinSCP is called by mistake
  862. MaintenanceTask();
  863. Configuration->DontSave();
  864. }
  865. else
  866. {
  867. enum { pcNone, pcUpload, pcFullSynchronize, pcSynchronize, pcEdit, pcRefresh } ParamCommand;
  868. ParamCommand = pcNone;
  869. UnicodeString AutoStartSession;
  870. UnicodeString DownloadFile;
  871. int UseDefaults = -1;
  872. // do not check for temp dirs for service tasks (like RegisterAsUrlHandler)
  873. if (OnlyInstance &&
  874. WinConfiguration->TemporaryDirectoryCleanup)
  875. {
  876. TemporaryDirectoryCleanup();
  877. }
  878. WinConfiguration->CheckDefaultTranslation();
  879. // Loading shell image lists here (rather than only on demand when file controls are being created)
  880. // reduces risk of an occasional crash.
  881. // It seems that the point is to load the lists before any call to SHGetFileInfoWithTimeout.
  882. InitFileControls();
  883. if (!Params->Empty)
  884. {
  885. UnicodeString Value;
  886. if (Params->FindSwitch(DEFAULTS_SWITCH, Value) && CheckSafe(Params))
  887. {
  888. UseDefaults = StrToIntDef(Value, 0);
  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. }