Login.cpp 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <CoreMain.h>
  6. #include <Common.h>
  7. #include <PuttyTools.h>
  8. #include <TextsWin.h>
  9. #include <TextsCore.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include "WinInterface.h"
  13. #include "Login.h"
  14. #include "GUITools.h"
  15. #include "Tools.h"
  16. #include "Setup.h"
  17. #include "WinConfiguration.h"
  18. //---------------------------------------------------------------------
  19. #pragma link "ComboEdit"
  20. #pragma link "GeneralSettings"
  21. #pragma link "LogSettings"
  22. #pragma link "PasswordEdit"
  23. #pragma link "UpDownEdit"
  24. #ifndef NO_RESOURCES
  25. #pragma resource "*.dfm"
  26. #endif
  27. //---------------------------------------------------------------------------
  28. // Sheet tag:
  29. // 01 top, 02 indented
  30. //---------------------------------------------------------------------------
  31. bool __fastcall DoLoginDialog(TStoredSessionList *SessionList,
  32. TSessionData * Data, int Options)
  33. {
  34. assert(Data);
  35. TLoginDialog * LoginDialog = SafeFormCreate<TLoginDialog>();
  36. TSessionData * Data2;
  37. bool Result;
  38. bool Owned;
  39. try
  40. {
  41. try
  42. {
  43. LoginDialog->Init(SessionList, Options);
  44. Data2 = Data;
  45. Result = LoginDialog->Execute(Data2, Owned);
  46. }
  47. __finally
  48. {
  49. delete LoginDialog;
  50. }
  51. if (Result)
  52. {
  53. // this may popup master pasword dialog,
  54. // if it happens before login dialog is destroyed
  55. // (from within try ...finally block above)
  56. // the next window will appear in background for some reason
  57. Data->Assign(Data2);
  58. }
  59. }
  60. __finally
  61. {
  62. if (Result && Owned)
  63. {
  64. delete Data2;
  65. }
  66. }
  67. return Result;
  68. }
  69. //---------------------------------------------------------------------
  70. static const TFSProtocol FSOrder[] = { fsSFTPonly, fsSCPonly, fsFTP };
  71. static const UnicodeString DefaultRecycleBinPath = L"/tmp";
  72. //---------------------------------------------------------------------
  73. __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
  74. : TForm(AOwner)
  75. {
  76. FSessionData = new TSessionData(L"");
  77. NoUpdate = 0;
  78. FLanguagesPopupMenu = NULL;
  79. FInitialized = false;
  80. FSavedTab = NULL;
  81. FSavedSession = -1;
  82. FOptions = loStartup;
  83. FLocaleChanging = false;
  84. FColor = (TColor)0;
  85. FEditingSessionData = NULL;
  86. FTreeLabels = new TStringList();
  87. FHintNode = NULL;
  88. FScrollOnDragOver = new TTreeViewScrollOnDragOver(SessionTree, true);
  89. // we need to make sure that window procedure is set asap
  90. // (so that CM_SHOWINGCHANGED handling is applied)
  91. UseSystemSettingsPre(this, &FSystemSettings);
  92. InitControls();
  93. }
  94. //---------------------------------------------------------------------
  95. __fastcall TLoginDialog::~TLoginDialog()
  96. {
  97. delete FScrollOnDragOver;
  98. assert(FSystemSettings);
  99. DeleteSystemSettings(this, FSystemSettings);
  100. FSystemSettings = NULL;
  101. delete FTreeLabels;
  102. delete FSessionData;
  103. delete FLanguagesPopupMenu;
  104. }
  105. //---------------------------------------------------------------------
  106. void __fastcall TLoginDialog::Init(TStoredSessionList *SessionList,
  107. int Options)
  108. {
  109. FStoredSessions = SessionList;
  110. LoadSessions();
  111. FOptions = Options;
  112. UnicodeString Dummy;
  113. PageantAction->Visible = FindTool(PageantTool, Dummy);
  114. PuttygenAction->Visible = FindTool(PuttygenTool, Dummy);
  115. UpdateControls();
  116. }
  117. //---------------------------------------------------------------------
  118. void __fastcall TLoginDialog::InitControls()
  119. {
  120. LoggingFrame->Init();
  121. ComboAutoSwitchInitialize(UtfCombo);
  122. ComboAutoSwitchInitialize(BugIgnore1Combo);
  123. ComboAutoSwitchInitialize(BugPlainPW1Combo);
  124. ComboAutoSwitchInitialize(BugRSA1Combo);
  125. ComboAutoSwitchInitialize(BugHMAC2Combo);
  126. ComboAutoSwitchInitialize(BugDeriveKey2Combo);
  127. ComboAutoSwitchInitialize(BugRSAPad2Combo);
  128. ComboAutoSwitchInitialize(BugPKSessID2Combo);
  129. ComboAutoSwitchInitialize(BugRekey2Combo);
  130. ComboAutoSwitchInitialize(BugMaxPkt2Combo);
  131. ComboAutoSwitchInitialize(BugIgnore2Combo);
  132. ComboAutoSwitchInitialize(SFTPBugSymlinkCombo);
  133. ComboAutoSwitchInitialize(SFTPBugSignedTSCombo);
  134. ComboAutoSwitchInitialize(FtpListAllCombo);
  135. InstallPathWordBreakProc(RemoteDirectoryEdit);
  136. InstallPathWordBreakProc(LocalDirectoryEdit);
  137. InstallPathWordBreakProc(PrivateKeyEdit);
  138. InstallPathWordBreakProc(RecycleBinPathEdit);
  139. TunnelLocalPortNumberEdit->Items->BeginUpdate();
  140. try
  141. {
  142. UnicodeString TunnelLocalPortNumberAutoassign = TunnelLocalPortNumberEdit->Items->Strings[0];
  143. TunnelLocalPortNumberEdit->Items->Clear();
  144. TunnelLocalPortNumberEdit->Items->Add(TunnelLocalPortNumberAutoassign);
  145. for (int Index = Configuration->TunnelLocalPortNumberLow;
  146. Index <= Configuration->TunnelLocalPortNumberHigh; Index++)
  147. {
  148. TunnelLocalPortNumberEdit->Items->Add(IntToStr(Index));
  149. }
  150. }
  151. __finally
  152. {
  153. TunnelLocalPortNumberEdit->Items->EndUpdate();
  154. }
  155. HintLabel(ProxyTelnetCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  156. HintLabel(ProxyLocalCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  157. if (SessionTree->WindowProc != SessionTreeProc)
  158. {
  159. FOldSessionTreeProc = SessionTree->WindowProc;
  160. SessionTree->WindowProc = SessionTreeProc;
  161. }
  162. FtpsCombo->Items->Strings[1] = LoadStr(FTPS_IMPLICIT);
  163. FtpsCombo->Items->Strings[2] = LoadStr(FTPS_EXPLICIT_SSL);
  164. FtpsCombo->Items->Strings[3] = LoadStr(FTPS_EXPLICIT_TLS);
  165. int FtpControlsShift = FtpAccountLabel->Top - PrivateKeyLabel->Top;
  166. FtpAccountLabel->Top -= FtpControlsShift;
  167. FtpAccountEdit->Top -= FtpControlsShift;
  168. AnonymousLoginCheck->Top -= FtpControlsShift;
  169. BasicGroup->Height -= FtpControlsShift;
  170. ColorButton->Top -= FtpControlsShift;
  171. }
  172. //---------------------------------------------------------------------
  173. void __fastcall TLoginDialog::Init()
  174. {
  175. if (!FInitialized)
  176. {
  177. UseSystemSettingsPost(this, FSystemSettings);
  178. }
  179. else
  180. {
  181. UseSystemSettings(this, &FSystemSettings);
  182. }
  183. FInitialized = true;
  184. Caption = FORMAT(L"%s %s", (AppName, Caption));
  185. InitControls();
  186. FTreeLabels->Clear();
  187. int Index = 0;
  188. while (Index < PageControl->PageCount)
  189. {
  190. FTreeLabels->Add(PageControl->Pages[Index]->Hint);
  191. PageControl->Pages[Index]->Hint = L"";
  192. Index++;
  193. }
  194. UpdateNavigationTree();
  195. if ((FOptions & loLocalDirectory) == 0)
  196. {
  197. LocalDirectoryLabel->Visible = false;
  198. LocalDirectoryEdit->Visible = false;
  199. LocalDirectoryDescLabel->Visible = false;
  200. DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + 12;
  201. DirectoryOptionsGroup->Top = DirectoriesGroup->Top + DirectoriesGroup->Height + 8;
  202. }
  203. #ifdef NO_FILEZILLA
  204. assert(TransferProtocolCombo->Items->Count == FSPROTOCOL_COUNT - 2 - 1);
  205. TransferProtocolCombo->Items->Delete(TransferProtocolCombo->Items->Count - 1);
  206. #endif
  207. if (StoredSessions && StoredSessions->Count &&
  208. (FSessionData->Name == StoredSessions->DefaultSettings->Name))
  209. {
  210. ChangePage(SessionListSheet);
  211. ActiveControl = SessionTree;
  212. assert(SessionTree->Items->Count > 0);
  213. if (SessionTree->Items->Count > 0)
  214. {
  215. SessionTree->Selected = SessionTree->Items->GetFirstNode();
  216. }
  217. }
  218. else
  219. {
  220. EditSession();
  221. }
  222. UpdateControls();
  223. }
  224. //---------------------------------------------------------------------
  225. TTreeNode * __fastcall TLoginDialog::AddSessionPath(UnicodeString Path, bool CanCreate)
  226. {
  227. TTreeNode * Parent = NULL;
  228. while (!Path.IsEmpty())
  229. {
  230. UnicodeString Folder = ::CutToChar(Path, L'/', false);
  231. TTreeNode * Node =
  232. ((Parent == NULL) ? SessionTree->Items->GetFirstNode() : Parent->getFirstChild());
  233. // note that we allow folder with the same name as existing session
  234. // on the same level (see also SessionTreeEdited)
  235. while ((Node != NULL) && ((Node->Data != NULL) || !AnsiSameText(Node->Text, Folder)))
  236. {
  237. Node = Node->getNextSibling();
  238. }
  239. if (Node == NULL)
  240. {
  241. if (!CanCreate)
  242. {
  243. return NULL;
  244. }
  245. else
  246. {
  247. TTreeNode * AParent = Parent;
  248. Parent = SessionTree->Items->AddChild(Parent, Folder);
  249. UpdateFolderNode(Parent);
  250. // folders seem not to be sorted automatically (not having set the data property)
  251. if (AParent == NULL)
  252. {
  253. SessionTree->Items->AlphaSort();
  254. }
  255. else
  256. {
  257. AParent->AlphaSort();
  258. }
  259. }
  260. }
  261. else
  262. {
  263. Parent = Node;
  264. }
  265. }
  266. return Parent;
  267. }
  268. //---------------------------------------------------------------------
  269. TTreeNode * __fastcall TLoginDialog::AddSession(TSessionData * Data)
  270. {
  271. TTreeNode * Parent = AddSessionPath(UnixExtractFilePath(Data->Name));
  272. TTreeNode * Node = SessionTree->Items->AddChild(Parent, UnixExtractFileName(Data->Name));
  273. Node->Data = Data;
  274. return Node;
  275. }
  276. //---------------------------------------------------------------------
  277. void __fastcall TLoginDialog::DestroySession(TSessionData * Data)
  278. {
  279. if (FEditingSessionData == Data)
  280. {
  281. FEditingSessionData = NULL;
  282. }
  283. StoredSessions->Remove(Data);
  284. }
  285. //---------------------------------------------------------------------
  286. void __fastcall TLoginDialog::LoadSessions()
  287. {
  288. SessionTree->Items->BeginUpdate();
  289. try
  290. {
  291. SessionTree->Items->Clear();
  292. assert(StoredSessions != NULL);
  293. for (int Index = 0; Index < StoredSessions->Count; Index++)
  294. {
  295. AddSession(StoredSessions->Sessions[Index]);
  296. }
  297. }
  298. __finally
  299. {
  300. // folders seem not to be sorted automatically (not having set the data property)
  301. SessionTree->AlphaSort();
  302. SessionTree->Items->EndUpdate();
  303. }
  304. SessionTree->Selected = SessionTree->Items->GetFirstNode();
  305. UpdateControls();
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TLoginDialog::UpdateFolderNode(TTreeNode * Node)
  309. {
  310. Node->StateIndex = (Node->Expanded ? 2 : 3);
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TLoginDialog::Default()
  314. {
  315. if (StoredSessions)
  316. {
  317. FSessionData->Assign(StoredSessions->DefaultSettings);
  318. }
  319. else
  320. {
  321. FSessionData->Default();
  322. }
  323. FEditingSessionData = NULL;
  324. LoadSession(FSessionData);
  325. FCurrentSessionName = "";
  326. }
  327. //---------------------------------------------------------------------
  328. void __fastcall TLoginDialog::LoadSession(TSessionData * aSessionData)
  329. {
  330. // it was always true
  331. assert(aSessionData == FSessionData);
  332. NoUpdate++;
  333. try
  334. {
  335. // Basic tab
  336. UserNameEdit->Text = aSessionData->UserName;
  337. PortNumberEdit->AsInteger = aSessionData->PortNumber;
  338. HostNameEdit->Text = aSessionData->HostName;
  339. PasswordEdit->Text = aSessionData->Password;
  340. FtpAccountEdit->Text = aSessionData->FtpAccount;
  341. PrivateKeyEdit->Text = aSessionData->PublicKeyFile;
  342. FtpsCombo->ItemIndex = aSessionData->Ftps;
  343. FColor = (TColor)aSessionData->Color;
  344. bool AllowScpFallback;
  345. TransferProtocolCombo->ItemIndex =
  346. FSProtocolToIndex(aSessionData->FSProtocol, AllowScpFallback);
  347. AllowScpFallbackCheck->Checked = AllowScpFallback;
  348. FDefaultPort = DefaultPort();
  349. // Directories tab
  350. SynchronizeBrowsingCheck->Checked = aSessionData->SynchronizeBrowsing;
  351. LocalDirectoryEdit->Text = aSessionData->LocalDirectory;
  352. RemoteDirectoryEdit->Text = aSessionData->RemoteDirectory;
  353. UpdateDirectoriesCheck->Checked = aSessionData->UpdateDirectories;
  354. CacheDirectoriesCheck->Checked = aSessionData->CacheDirectories;
  355. CacheDirectoryChangesCheck->Checked = aSessionData->CacheDirectoryChanges;
  356. PreserveDirectoryChangesCheck->Checked = aSessionData->PreserveDirectoryChanges;
  357. ResolveSymlinksCheck->Checked = aSessionData->ResolveSymlinks;
  358. // Environment tab
  359. switch (aSessionData->DSTMode)
  360. {
  361. case dstmWin:
  362. DSTModeWinCheck->Checked = true;
  363. break;
  364. case dstmKeep:
  365. DSTModeKeepCheck->Checked = true;
  366. break;
  367. default:
  368. case dstmUnix:
  369. DSTModeUnixCheck->Checked = true;
  370. break;
  371. }
  372. if (aSessionData->EOLType == eolLF)
  373. {
  374. EOLTypeCombo->ItemIndex = 0;
  375. }
  376. else
  377. {
  378. EOLTypeCombo->ItemIndex = 1;
  379. }
  380. switch (aSessionData->NotUtf)
  381. {
  382. case asOn:
  383. UtfCombo->ItemIndex = 1;
  384. break;
  385. case asOff:
  386. UtfCombo->ItemIndex = 2;
  387. break;
  388. default:
  389. UtfCombo->ItemIndex = 0;
  390. break;
  391. }
  392. int TimeDifferenceMin = DateTimeToTimeStamp(aSessionData->TimeDifference).Time / (SecsPerMin * MSecsPerSec);
  393. if (double(aSessionData->TimeDifference) < 0)
  394. {
  395. TimeDifferenceMin = -TimeDifferenceMin;
  396. }
  397. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / MinsPerHour;
  398. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % MinsPerHour;
  399. // Environment/Recycle bin tab
  400. DeleteToRecycleBinCheck->Checked = aSessionData->DeleteToRecycleBin;
  401. OverwrittenToRecycleBinCheck->Checked = aSessionData->OverwrittenToRecycleBin;
  402. RecycleBinPathEdit->Text =
  403. !aSessionData->RecycleBinPath.IsEmpty() ?
  404. aSessionData->RecycleBinPath : DefaultRecycleBinPath;
  405. // SFTP tab
  406. if (aSessionData->SftpServer.IsEmpty())
  407. {
  408. SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
  409. }
  410. else
  411. {
  412. SftpServerEdit->Text = aSessionData->SftpServer;
  413. }
  414. // hide selection, which is wrongly shown initially even when the box has not focus
  415. SftpServerEdit->SelLength = 0;
  416. SFTPMaxVersionCombo->ItemIndex = aSessionData->SFTPMaxVersion;
  417. #define LOAD_SFTP_BUG_COMBO(BUG) \
  418. ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, aSessionData->SFTPBug[sb ## BUG])
  419. LOAD_SFTP_BUG_COMBO(Symlink);
  420. LOAD_SFTP_BUG_COMBO(SignedTS);
  421. #undef LOAD_SFTP_BUG_COMBO
  422. // FTP tab
  423. PostLoginCommandsMemo->Lines->Text = aSessionData->PostLoginCommands;
  424. ComboAutoSwitchLoad(FtpListAllCombo, aSessionData->FtpListAll);
  425. CheckBoxAutoSwitchLoad(FtpForcePasvIpCheck, aSessionData->FtpForcePasvIp);
  426. // Authentication tab
  427. SshNoUserAuthCheck->Checked = aSessionData->SshNoUserAuth;
  428. TryAgentCheck->Checked = aSessionData->TryAgent;
  429. AuthTISCheck->Checked = aSessionData->AuthTIS;
  430. AuthKICheck->Checked = aSessionData->AuthKI;
  431. AuthKIPasswordCheck->Checked = aSessionData->AuthKIPassword;
  432. AuthGSSAPICheck3->Checked = aSessionData->AuthGSSAPI;
  433. GSSAPIFwdTGTCheck->Checked = aSessionData->GSSAPIFwdTGT;
  434. AgentFwdCheck->Checked = aSessionData->AgentFwd;
  435. // SSH tab
  436. Ssh2LegacyDESCheck->Checked = aSessionData->Ssh2DES;
  437. CompressionCheck->Checked = aSessionData->Compression;
  438. switch (aSessionData->SshProt) {
  439. case ssh1only: SshProt1onlyButton->Checked = true; break;
  440. case ssh1: SshProt1Button->Checked = true; break;
  441. case ssh2: SshProt2Button->Checked = true; break;
  442. case ssh2only: SshProt2onlyButton->Checked = true; break;
  443. }
  444. CipherListBox->Items->Clear();
  445. assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_ARCFOUR);
  446. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  447. {
  448. CipherListBox->Items->AddObject(
  449. LoadStr(CIPHER_NAME_WARN+aSessionData->Cipher[Index]),
  450. (TObject*)aSessionData->Cipher[Index]);
  451. }
  452. // KEX tab
  453. KexListBox->Items->Clear();
  454. assert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_RSA);
  455. for (int Index = 0; Index < KEX_COUNT; Index++)
  456. {
  457. KexListBox->Items->AddObject(
  458. LoadStr(KEX_NAME_WARN+aSessionData->Kex[Index]),
  459. (TObject*)aSessionData->Kex[Index]);
  460. }
  461. RekeyTimeEdit->AsInteger = aSessionData->RekeyTime;
  462. RekeyDataEdit->Text = aSessionData->RekeyData;
  463. // Connection tab
  464. FtpPasvModeCheck->Checked = aSessionData->FtpPasvMode;
  465. BufferSizeCheck->Checked = (aSessionData->SendBuf > 0) && aSessionData->SshSimple;
  466. switch (aSessionData->PingType)
  467. {
  468. case ptNullPacket:
  469. PingNullPacketButton->Checked = true;
  470. break;
  471. case ptDummyCommand:
  472. PingDummyCommandButton->Checked = true;
  473. break;
  474. default:
  475. PingOffButton->Checked = true;
  476. break;
  477. }
  478. PingIntervalSecEdit->AsInteger = aSessionData->PingInterval;
  479. switch (aSessionData->FtpPingType)
  480. {
  481. case ptDummyCommand:
  482. FtpPingDummyCommandButton->Checked = true;
  483. break;
  484. default:
  485. FtpPingOffButton->Checked = true;
  486. break;
  487. }
  488. FtpPingIntervalSecEdit->AsInteger = aSessionData->FtpPingInterval;
  489. TimeoutEdit->AsInteger = aSessionData->Timeout;
  490. switch (aSessionData->AddressFamily)
  491. {
  492. case afIPv4:
  493. IPv4Button->Checked = true;
  494. break;
  495. case afIPv6:
  496. IPv6Button->Checked = true;
  497. break;
  498. case afAuto:
  499. default:
  500. IPAutoButton->Checked = true;
  501. break;
  502. }
  503. // Shell tab
  504. if (aSessionData->DefaultShell)
  505. {
  506. ShellEdit->Text = ShellEdit->Items->Strings[0];
  507. }
  508. else
  509. {
  510. ShellEdit->Text = aSessionData->Shell;
  511. }
  512. // hide selection, which is wrongly shown initially even when the box has not focus
  513. ShellEdit->SelLength = 0;
  514. if (aSessionData->DetectReturnVar)
  515. {
  516. ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
  517. }
  518. else
  519. {
  520. ReturnVarEdit->Text = aSessionData->ReturnVar;
  521. }
  522. ReturnVarEdit->SelLength = 0;
  523. ListingCommandEdit->Text = aSessionData->ListingCommand;
  524. ListingCommandEdit->SelLength = 0;
  525. CheckBoxAutoSwitchLoad(LookupUserGroupsCheck, aSessionData->LookupUserGroups);
  526. ClearAliasesCheck->Checked = aSessionData->ClearAliases;
  527. IgnoreLsWarningsCheck->Checked = aSessionData->IgnoreLsWarnings;
  528. Scp1CompatibilityCheck->Checked = aSessionData->Scp1Compatibility;
  529. UnsetNationalVarsCheck->Checked = aSessionData->UnsetNationalVars;
  530. SCPLsFullTimeAutoCheck->Checked = (aSessionData->SCPLsFullTime != asOff);
  531. // Proxy tab
  532. SshProxyMethodCombo->ItemIndex = aSessionData->ProxyMethod;
  533. if (SupportedFtpProxyMethod(aSessionData->ProxyMethod))
  534. {
  535. FtpProxyMethodCombo->ItemIndex = aSessionData->ProxyMethod;
  536. }
  537. else
  538. {
  539. FtpProxyMethodCombo->ItemIndex = ::pmNone;
  540. }
  541. if (aSessionData->FtpProxyLogonType != 0)
  542. {
  543. FtpProxyMethodCombo->ItemIndex = LastSupportedFtpProxyMethod() + aSessionData->FtpProxyLogonType;
  544. }
  545. ProxyHostEdit->Text = aSessionData->ProxyHost;
  546. ProxyPortEdit->AsInteger = aSessionData->ProxyPort;
  547. ProxyUsernameEdit->Text = aSessionData->ProxyUsername;
  548. ProxyPasswordEdit->Text = aSessionData->ProxyPassword;
  549. ProxyTelnetCommandEdit->Text = aSessionData->ProxyTelnetCommand;
  550. ProxyLocalCommandEdit->Text = aSessionData->ProxyLocalCommand;
  551. ProxyLocalhostCheck->Checked = aSessionData->ProxyLocalhost;
  552. ProxyDNSCombo->ItemIndex = 2 - aSessionData->ProxyDNS;
  553. // Bugs tab
  554. #define LOAD_BUG_COMBO(BUG) \
  555. ComboAutoSwitchLoad(Bug ## BUG ## Combo, aSessionData->Bug[sb ## BUG])
  556. LOAD_BUG_COMBO(Ignore1);
  557. LOAD_BUG_COMBO(PlainPW1);
  558. LOAD_BUG_COMBO(RSA1);
  559. LOAD_BUG_COMBO(HMAC2);
  560. LOAD_BUG_COMBO(DeriveKey2);
  561. LOAD_BUG_COMBO(RSAPad2);
  562. LOAD_BUG_COMBO(PKSessID2);
  563. LOAD_BUG_COMBO(Rekey2);
  564. LOAD_BUG_COMBO(MaxPkt2);
  565. LOAD_BUG_COMBO(Ignore2);
  566. #undef LOAD_BUG_COMBO
  567. // Tunnel tab
  568. TunnelCheck->Checked = aSessionData->Tunnel;
  569. TunnelUserNameEdit->Text = aSessionData->TunnelUserName;
  570. TunnelPortNumberEdit->AsInteger = aSessionData->TunnelPortNumber;
  571. TunnelHostNameEdit->Text = aSessionData->TunnelHostName;
  572. TunnelPasswordEdit->Text = aSessionData->TunnelPassword;
  573. TunnelPrivateKeyEdit->Text = aSessionData->TunnelPublicKeyFile;
  574. if (aSessionData->TunnelAutoassignLocalPortNumber)
  575. {
  576. TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
  577. }
  578. else
  579. {
  580. TunnelLocalPortNumberEdit->Text = IntToStr(aSessionData->TunnelLocalPortNumber);
  581. }
  582. // hide selection, which is wrongly shown initially even when the box has not focus
  583. TunnelLocalPortNumberEdit->SelLength = 0;
  584. }
  585. __finally
  586. {
  587. NoUpdate--;
  588. UpdateControls();
  589. }
  590. if (UnixExtractFileName(aSessionData->Name) != aSessionData->DefaultSessionName)
  591. {
  592. FCurrentSessionName = aSessionData->Name;
  593. }
  594. else
  595. {
  596. FCurrentSessionName = L"";
  597. }
  598. }
  599. //---------------------------------------------------------------------
  600. void __fastcall TLoginDialog::SaveSession(TSessionData * aSessionData)
  601. {
  602. // it was always true
  603. assert(aSessionData == FSessionData);
  604. // Basic tab
  605. aSessionData->UserName = UserNameEdit->Text.Trim();
  606. aSessionData->PortNumber = PortNumberEdit->AsInteger;
  607. // must be loaded after UserName, because HostName may be in format user@host
  608. aSessionData->HostName = HostNameEdit->Text.Trim();
  609. aSessionData->Password = PasswordEdit->Text;
  610. aSessionData->FtpAccount = FtpAccountEdit->Text;
  611. aSessionData->PublicKeyFile = PrivateKeyEdit->Text;
  612. aSessionData->Ftps = (TFtps)FtpsCombo->ItemIndex;
  613. aSessionData->Color = FColor;
  614. aSessionData->FSProtocol = IndexToFSProtocol(
  615. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  616. // SSH tab
  617. aSessionData->Compression = CompressionCheck->Checked;
  618. aSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  619. if (SshProt1onlyButton->Checked) aSessionData->SshProt = ssh1only;
  620. else
  621. if (SshProt1Button->Checked) aSessionData->SshProt = ssh1;
  622. else
  623. if (SshProt2Button->Checked) aSessionData->SshProt = ssh2;
  624. else aSessionData->SshProt = ssh2only;
  625. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  626. {
  627. aSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  628. }
  629. // Kex tab
  630. for (int Index = 0; Index < KEX_COUNT; Index++)
  631. {
  632. aSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  633. }
  634. aSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  635. aSessionData->RekeyData = RekeyDataEdit->Text;
  636. // Authentication tab
  637. aSessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
  638. aSessionData->TryAgent = TryAgentCheck->Checked;
  639. aSessionData->AuthTIS = AuthTISCheck->Checked;
  640. aSessionData->AuthKI = AuthKICheck->Checked;
  641. aSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  642. aSessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
  643. aSessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  644. aSessionData->AgentFwd = AgentFwdCheck->Checked;
  645. // Connection tab
  646. aSessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  647. aSessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
  648. aSessionData->SshSimple = BufferSizeCheck->Checked;
  649. if (PingNullPacketButton->Checked)
  650. {
  651. aSessionData->PingType = ptNullPacket;
  652. }
  653. else if (PingDummyCommandButton->Checked)
  654. {
  655. aSessionData->PingType = ptDummyCommand;
  656. }
  657. else
  658. {
  659. aSessionData->PingType = ptOff;
  660. }
  661. aSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  662. aSessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
  663. aSessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
  664. aSessionData->Timeout = TimeoutEdit->AsInteger;
  665. if (IPv4Button->Checked)
  666. {
  667. aSessionData->AddressFamily = afIPv4;
  668. }
  669. else if (IPv6Button->Checked)
  670. {
  671. aSessionData->AddressFamily = afIPv6;
  672. }
  673. else
  674. {
  675. aSessionData->AddressFamily = afAuto;
  676. }
  677. // Directories tab
  678. aSessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
  679. aSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  680. aSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  681. aSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  682. aSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  683. aSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  684. aSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  685. aSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  686. // Environment tab
  687. if (DSTModeUnixCheck->Checked) aSessionData->DSTMode = dstmUnix;
  688. else
  689. if (DSTModeKeepCheck->Checked) aSessionData->DSTMode = dstmKeep;
  690. else aSessionData->DSTMode = dstmWin;
  691. if (EOLTypeCombo->ItemIndex == 0) aSessionData->EOLType = eolLF;
  692. else aSessionData->EOLType = eolCRLF;
  693. switch (UtfCombo->ItemIndex)
  694. {
  695. case 1:
  696. aSessionData->NotUtf = asOn;
  697. break;
  698. case 2:
  699. aSessionData->NotUtf = asOff;
  700. break;
  701. default:
  702. aSessionData->NotUtf = asAuto;
  703. break;
  704. }
  705. aSessionData->TimeDifference =
  706. (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
  707. (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
  708. // Environment/Recycle bin tab
  709. aSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  710. aSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  711. aSessionData->RecycleBinPath =
  712. aSessionData->DeleteToRecycleBin || aSessionData->OverwrittenToRecycleBin ||
  713. (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
  714. RecycleBinPathEdit->Text : UnicodeString();
  715. // SCP tab
  716. aSessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  717. aSessionData->Shell = (aSessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
  718. aSessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  719. aSessionData->ReturnVar = (aSessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
  720. aSessionData->ListingCommand = ListingCommandEdit->Text;
  721. aSessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
  722. aSessionData->ClearAliases = ClearAliasesCheck->Checked;
  723. aSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  724. aSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  725. aSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  726. aSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  727. // SFTP tab
  728. aSessionData->SftpServer =
  729. ((SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]) ?
  730. UnicodeString() : SftpServerEdit->Text);
  731. aSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  732. #define SAVE_SFTP_BUG_COMBO(BUG) aSessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
  733. SAVE_SFTP_BUG_COMBO(Symlink);
  734. SAVE_SFTP_BUG_COMBO(SignedTS);
  735. #undef SAVE_SFTP_BUG_COMBO
  736. // FTP tab
  737. aSessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
  738. aSessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
  739. aSessionData->FtpForcePasvIp = CheckBoxAutoSwitchSave(FtpForcePasvIpCheck);
  740. // Proxy tab
  741. aSessionData->ProxyMethod = GetProxyMethod();
  742. aSessionData->FtpProxyLogonType = GetFtpProxyLogonType();
  743. aSessionData->ProxyHost = ProxyHostEdit->Text;
  744. aSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  745. aSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  746. aSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  747. aSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  748. aSessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
  749. aSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  750. aSessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
  751. // Bugs tab
  752. #define SAVE_BUG_COMBO(BUG) aSessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
  753. SAVE_BUG_COMBO(Ignore1);
  754. SAVE_BUG_COMBO(PlainPW1);
  755. SAVE_BUG_COMBO(RSA1);
  756. SAVE_BUG_COMBO(HMAC2);
  757. SAVE_BUG_COMBO(DeriveKey2);
  758. SAVE_BUG_COMBO(RSAPad2);
  759. SAVE_BUG_COMBO(PKSessID2);
  760. SAVE_BUG_COMBO(Rekey2);
  761. SAVE_BUG_COMBO(MaxPkt2);
  762. SAVE_BUG_COMBO(Ignore2);
  763. #undef SAVE_BUG_COMBO
  764. // Tunnel tab
  765. aSessionData->Tunnel = TunnelCheck->Checked;
  766. aSessionData->TunnelUserName = TunnelUserNameEdit->Text;
  767. aSessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  768. aSessionData->TunnelHostName = TunnelHostNameEdit->Text;
  769. aSessionData->TunnelPassword = TunnelPasswordEdit->Text;
  770. aSessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit->Text;
  771. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  772. {
  773. aSessionData->TunnelLocalPortNumber = 0;
  774. }
  775. else
  776. {
  777. aSessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  778. }
  779. UnicodeString Name = FCurrentSessionName;
  780. if (Name.IsEmpty())
  781. {
  782. Name = UnixIncludeTrailingBackslash(SessionNodePath(CurrentSessionFolderNode())) +
  783. aSessionData->DefaultSessionName;
  784. }
  785. aSessionData->Name = Name;
  786. }
  787. //---------------------------------------------------------------------
  788. void __fastcall TLoginDialog::UpdateNavigationTree()
  789. {
  790. TTreeNode * ActiveNode = NULL;
  791. NoUpdate++;
  792. try
  793. {
  794. int Index = 0;
  795. TTreeNode * PrevNode = NULL;
  796. while (Index < PageControl->PageCount)
  797. {
  798. TTabSheet * Tab = PageControl->Pages[Index];
  799. if (Tab->Enabled)
  800. {
  801. bool Indented = ((Tab->Tag % 100) == 2);
  802. UnicodeString Label = FTreeLabels->Strings[Index];
  803. TTreeNode * Node;
  804. if (PrevNode == NULL)
  805. {
  806. assert(!Indented);
  807. Node = NavigationTree->Items->GetFirstNode();
  808. }
  809. else
  810. {
  811. if (Indented)
  812. {
  813. if (PrevNode->Level == 0)
  814. {
  815. Node = PrevNode->getFirstChild();
  816. if (Node == NULL)
  817. {
  818. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  819. }
  820. }
  821. else
  822. {
  823. Node = PrevNode->getNextSibling();
  824. if (Node == NULL)
  825. {
  826. Node = NavigationTree->Items->Add(PrevNode, Label);
  827. }
  828. }
  829. }
  830. else
  831. {
  832. if (PrevNode->Level == 0)
  833. {
  834. // delete all excess children of previous top level node
  835. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  836. {
  837. Node->Delete();
  838. }
  839. Node = PrevNode->getNextSibling();
  840. if (Node == NULL)
  841. {
  842. Node = NavigationTree->Items->Add(PrevNode, Label);
  843. }
  844. }
  845. else
  846. {
  847. // delete all excess children of previous top level node
  848. while ((Node = PrevNode->getNextSibling()) != NULL)
  849. {
  850. Node->Delete();
  851. }
  852. Node = PrevNode->GetNext();
  853. if (Node == NULL)
  854. {
  855. Node = NavigationTree->Items->Add(NULL, Label);
  856. }
  857. }
  858. }
  859. }
  860. Node->Text = Label;
  861. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  862. PrevNode = Node;
  863. if (PageControl->ActivePage == Tab)
  864. {
  865. Node->Selected = true;
  866. ActiveNode = Node;
  867. }
  868. }
  869. Index++;
  870. }
  871. TTreeNode * Node;
  872. while ((Node = PrevNode->GetNext()) != NULL)
  873. {
  874. Node->Delete();
  875. }
  876. NavigationTree->FullExpand();
  877. }
  878. __finally
  879. {
  880. NoUpdate--;
  881. }
  882. // node of active page was hidden
  883. if (ActiveNode == NULL)
  884. {
  885. ChangePage(BasicSheet);
  886. }
  887. }
  888. //---------------------------------------------------------------------
  889. void __fastcall TLoginDialog::UpdateControls()
  890. {
  891. if (Visible && FInitialized)
  892. {
  893. NoUpdate++;
  894. try
  895. {
  896. TFSProtocol FSProtocol = IndexToFSProtocol(
  897. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  898. bool SshProtocol =
  899. (FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP) || (FSProtocol == fsSCPonly);
  900. bool FtpProtocol = (FSProtocol == fsFTP);
  901. assert(SshProtocol != FtpProtocol); // xor, some of the code below rely on this
  902. bool Advanced = ShowAdvancedLoginOptionsCheck->Checked;
  903. // basic/session sheet
  904. FtpsCombo->Visible = (FSProtocol == fsFTP);
  905. FtpsLabel->Visible = FtpsCombo->Visible;
  906. PrivateKeyEdit->Visible = SshProtocol;
  907. PrivateKeyLabel->Visible = PrivateKeyEdit->Visible;
  908. FtpAccountEdit->Visible = FtpProtocol;
  909. FtpAccountLabel->Visible = FtpAccountEdit->Visible;
  910. AnonymousLoginCheck->Visible = FtpProtocol;
  911. AnonymousLoginCheck->Checked =
  912. SameText(UserNameEdit->Text, AnonymousUserName) &&
  913. SameText(PasswordEdit->Text, AnonymousPassword);
  914. // log sheet
  915. LogSheet->Enabled = Advanced;
  916. // connection sheet
  917. ConnSheet->Enabled = Advanced;
  918. EnableControl(FtpPasvModeCheck, FtpProtocol);
  919. if (FtpProtocol &&
  920. (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
  921. SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
  922. !FtpPasvModeCheck->Checked)
  923. {
  924. FtpPasvModeCheck->Checked = true;
  925. MessageDialog(LoadStr(FTP_PASV_MODE_REQUIRED), qtInformation, qaOK);
  926. }
  927. EnableControl(BufferSizeCheck, SshProtocol);
  928. PingGroup->Visible = SshProtocol;
  929. EnableControl(PingIntervalSecEdit, !PingOffButton->Checked);
  930. EnableControl(PingIntervalLabel, PingIntervalSecEdit->Enabled);
  931. FtpPingGroup->Visible = FtpProtocol;
  932. EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
  933. EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
  934. EnableControl(IPAutoButton, SshProtocol);
  935. // stored sessions sheet
  936. EnableControl(SessionTree, SessionTree->Items->Count > 0);
  937. // ssh/authentication sheet
  938. AuthSheet->Enabled = SshProtocol && Advanced;
  939. EnableControl(SshNoUserAuthCheck, !SshProt1onlyButton->Checked);
  940. EnableControl(AuthenticationGroup,
  941. !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
  942. EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && !SshProt2onlyButton->Checked);
  943. EnableControl(AuthKICheck, AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
  944. EnableControl(AuthKIPasswordCheck,
  945. AuthenticationGroup->Enabled &&
  946. ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  947. (AuthKICheck->Enabled && AuthKICheck->Checked)));
  948. EnableControl(AuthGSSAPICheck3,
  949. AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
  950. EnableControl(GSSAPIFwdTGTCheck,
  951. AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
  952. // ssh sheet
  953. AdvancedSheet->Enabled = SshProtocol;
  954. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  955. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  956. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  957. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  958. // ssh/kex sheet
  959. KexSheet->Enabled = SshProtocol && Advanced && !SshProt1onlyButton->Checked &&
  960. (BugRekey2Combo->ItemIndex != 2);
  961. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  962. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  963. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  964. // ssh/bugs sheet
  965. BugsSheet->Enabled = SshProtocol && Advanced;
  966. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  967. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  968. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  969. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  970. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  971. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  972. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  973. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  974. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  975. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  976. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  977. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  978. EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
  979. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  980. EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
  981. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  982. EnableControl(BugMaxPkt2Combo, !SshProt1onlyButton->Checked);
  983. EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
  984. EnableControl(BugIgnore2Combo, !SshProt1onlyButton->Checked);
  985. EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
  986. // connection/proxy sheet
  987. TComboBox * ProxyMethodCombo = (SshProtocol ? SshProxyMethodCombo : FtpProxyMethodCombo);
  988. ProxyMethodCombo->Visible = true;
  989. ProxyMethodLabel->FocusControl = ProxyMethodCombo;
  990. TComboBox * OtherProxyMethodCombo = (!SshProtocol ? SshProxyMethodCombo : FtpProxyMethodCombo);
  991. OtherProxyMethodCombo->Visible = false;
  992. if (SupportedFtpProxyMethod(ProxyMethodCombo->ItemIndex))
  993. {
  994. OtherProxyMethodCombo->ItemIndex = ProxyMethodCombo->ItemIndex;
  995. }
  996. else
  997. {
  998. OtherProxyMethodCombo->ItemIndex = ::pmNone;
  999. }
  1000. ProxySheet->Enabled = Advanced;
  1001. TProxyMethod ProxyMethod = GetProxyMethod();
  1002. int FtpProxyLogonType = GetFtpProxyLogonType();
  1003. UnicodeString ProxyCommand =
  1004. ((ProxyMethod == pmCmd) ?
  1005. ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
  1006. EnableControl(ProxyHostEdit,
  1007. (ProxyMethod == pmSocks4) ||
  1008. (ProxyMethod == pmSocks5) ||
  1009. (ProxyMethod == pmHTTP) ||
  1010. (ProxyMethod == pmTelnet) ||
  1011. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
  1012. (FtpProxyLogonType > 0));
  1013. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  1014. EnableControl(ProxyPortEdit,
  1015. (ProxyMethod == pmSocks4) ||
  1016. (ProxyMethod == pmSocks5) ||
  1017. (ProxyMethod == pmHTTP) ||
  1018. (ProxyMethod == pmTelnet) ||
  1019. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
  1020. (FtpProxyLogonType > 0));
  1021. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  1022. EnableControl(ProxyUsernameEdit,
  1023. // FZAPI does not support username for SOCKS4
  1024. ((ProxyMethod == pmSocks4) && SshProtocol) ||
  1025. (ProxyMethod == pmSocks5) ||
  1026. (ProxyMethod == pmHTTP) ||
  1027. (((ProxyMethod == pmTelnet) ||
  1028. (ProxyMethod == pmCmd)) &&
  1029. AnsiContainsText(ProxyCommand, L"%user")) ||
  1030. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  1031. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  1032. EnableControl(ProxyPasswordEdit,
  1033. (ProxyMethod == pmSocks5) ||
  1034. (ProxyMethod == pmHTTP) ||
  1035. (((ProxyMethod == pmTelnet) ||
  1036. (ProxyMethod == pmCmd)) &&
  1037. AnsiContainsText(ProxyCommand, L"%pass")) ||
  1038. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  1039. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  1040. bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
  1041. EnableControl(ProxySettingsGroup, ProxySettings);
  1042. EnableControl(ProxyTelnetCommandEdit,
  1043. ProxySettings && (ProxyMethod == pmTelnet));
  1044. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  1045. EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
  1046. ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
  1047. ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
  1048. ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
  1049. ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
  1050. ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
  1051. ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
  1052. ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
  1053. // environment/directories sheet
  1054. DirectoryOptionsGroup->Visible = Advanced;
  1055. EnableControl(SynchronizeBrowsingCheck,
  1056. WinConfiguration->PreservePanelState &&
  1057. !WinConfiguration->ScpCommander.PreserveLocalDirectory);
  1058. EnableControl(CacheDirectoryChangesCheck,
  1059. ((FSProtocol != fsSCPonly) || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  1060. EnableControl(PreserveDirectoryChangesCheck,
  1061. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  1062. DirectoriesSheet->Enabled);
  1063. EnableControl(ResolveSymlinksCheck, (FSProtocol != fsFTP) && DirectoriesSheet->Enabled);
  1064. // environment sheet
  1065. EnableControl(EOLTypeCombo, (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  1066. EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
  1067. EnableControl(DSTModeGroup, (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  1068. EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
  1069. EnableControl(UtfCombo, (FSProtocol != fsSCPonly) && EnvironmentSheet->Enabled);
  1070. EnableControl(UtfLabel, UtfCombo->Enabled);
  1071. // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
  1072. EnableControl(TimeDifferenceEdit, (((FSProtocol == fsFTP) || (FSProtocol == fsSCPonly)) && EnvironmentSheet->Enabled));
  1073. EnableControl(TimeDifferenceLabel, TimeDifferenceEdit->Enabled);
  1074. EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
  1075. EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
  1076. EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
  1077. // environment/recycle bin sheet
  1078. RecycleBinSheet->Enabled =
  1079. ShowAdvancedLoginOptionsCheck->Checked;
  1080. EnableControl(OverwrittenToRecycleBinCheck, (FSProtocol != fsSCPonly) &&
  1081. (FSProtocol != fsFTP) && RecycleBinSheet->Enabled);
  1082. EnableControl(RecycleBinPathEdit,
  1083. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  1084. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  1085. RecycleBinSheet->Enabled);
  1086. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  1087. RecycleBinSheet->Enabled);
  1088. // environment/sftp sheet
  1089. SftpSheet->Enabled = Advanced && ((FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP));
  1090. // environment/scp/shell
  1091. ScpSheet->Enabled = Advanced && SshProtocol;
  1092. // disable also for SFTP with SCP fallback, as if someone wants to configure
  1093. // these he/she probably intends to use SCP and should explicitly select it.
  1094. // (note that these are not used for secondary shell session)
  1095. EnableControl(ScpLsOptionsGroup, (FSProtocol == fsSCPonly));
  1096. EnableControl(OtherShellOptionsGroup, (FSProtocol == fsSCPonly));
  1097. // environment/ftp
  1098. FtpSheet->Enabled = Advanced && FtpProtocol;
  1099. EnableControl(FtpForcePasvIpCheck,
  1100. FtpPasvModeCheck->Checked &&
  1101. (IPAutoButton->Checked || IPv4Button->Checked));
  1102. // tunnel sheet
  1103. TunnelSheet->Enabled = Advanced && SshProtocol;
  1104. // probably needless
  1105. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  1106. EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
  1107. // preferences sheet
  1108. GeneralSheet->Enabled = FLAGSET(FOptions, loPreferences);
  1109. // this methods saves us from calling GetSessionData,
  1110. // which breaks changing locale (session data are not preserved,
  1111. // as we would overwrite them with non-initialized control data)
  1112. if (PageControl->ActivePage == SessionListSheet)
  1113. {
  1114. LoginButton->Default = (SelectedSession != NULL) && SelectedSession->CanLogin;
  1115. }
  1116. else
  1117. {
  1118. LoginButton->Default = true;
  1119. }
  1120. LoadButton->Default = !LoginButton->Default;
  1121. SetDefaultSessionButton->Visible = !SupportsSplitButton();
  1122. AboutButton->Visible = (FOptions & loAbout);
  1123. LanguagesButton->Visible = (FOptions & loLanguage);
  1124. ShellIconsButton->Visible = (FOptions & loTools);
  1125. ToolsMenuButton->Visible = (FOptions & loTools);
  1126. LoggingFrame->EnableLogWindow = (FOptions & loLogWindow);
  1127. ColorButton->Visible = (FOptions & loColor);
  1128. UpdateNavigationTree();
  1129. }
  1130. __finally
  1131. {
  1132. NoUpdate--;
  1133. }
  1134. }
  1135. }
  1136. //---------------------------------------------------------------------------
  1137. void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
  1138. {
  1139. if (!NoUpdate) UpdateControls();
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
  1143. {
  1144. if (!FInitialized)
  1145. {
  1146. Init();
  1147. TSessionData * Data = GetSessionData();
  1148. if (Data == FSessionData)
  1149. {
  1150. LoadSession(Data);
  1151. }
  1152. else
  1153. {
  1154. Default();
  1155. }
  1156. }
  1157. if (FLocaleChanging)
  1158. {
  1159. Init();
  1160. LoadSession(FSessionData);
  1161. ChangePage(FSavedTab);
  1162. if (FSavedSession >= 0)
  1163. {
  1164. SessionTree->Selected = SessionTree->Items->Item[FSavedSession];
  1165. SessionTree->Selected->MakeVisible();
  1166. }
  1167. LoadConfiguration();
  1168. }
  1169. // among other this makes the expanded nodes look like expanded,
  1170. // because the LoadState call in Execute is too early,
  1171. // and some stray call to collapsed event during showing process,
  1172. // make the image be set to collapsed
  1173. LoadState();
  1174. UpdateControls();
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TLoginDialog::SessionTreeChange(TObject * /*Sender*/,
  1178. TTreeNode * /*Node*/)
  1179. {
  1180. UpdateControls();
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
  1184. {
  1185. FSessionData->Assign(value);
  1186. FSessionData->Special = false;
  1187. FEditingSessionData = value;
  1188. LoadSession(FSessionData);
  1189. }
  1190. //---------------------------------------------------------------------------
  1191. TSessionData * __fastcall TLoginDialog::GetSessionData()
  1192. {
  1193. if (PageControl->ActivePage == SessionListSheet)
  1194. {
  1195. return SelectedSession;
  1196. }
  1197. else
  1198. {
  1199. SaveSession(FSessionData);
  1200. return FSessionData;
  1201. }
  1202. }
  1203. //---------------------------------------------------------------------------
  1204. void __fastcall TLoginDialog::SessionTreeDblClick(TObject * /*Sender*/)
  1205. {
  1206. TPoint P = SessionTree->ScreenToClient(Mouse->CursorPos);
  1207. if (SelectedSession && (SessionTree->GetNodeAt(P.x, P.y) == SessionTree->Selected))
  1208. {
  1209. if (SelectedSession->CanLogin)
  1210. {
  1211. ModalResult = mrOk;
  1212. }
  1213. else
  1214. {
  1215. SetSessionData(SelectedSession);
  1216. EditSession();
  1217. }
  1218. }
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. TSessionData * __fastcall TLoginDialog::GetSelectedSession()
  1222. {
  1223. if (SessionTree->Selected != NULL)
  1224. {
  1225. return (TSessionData *)SessionTree->Selected->Data;
  1226. }
  1227. else
  1228. {
  1229. return NULL;
  1230. }
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TLoginDialog::SessionTreeKeyDown(TObject * /*Sender*/,
  1234. WORD & Key, TShiftState /*Shift*/)
  1235. {
  1236. if (!SessionTree->IsEditing())
  1237. {
  1238. if (Key == VK_DELETE)
  1239. {
  1240. DeleteSessionAction->Execute();
  1241. Key = 0;
  1242. }
  1243. else if (Key == VK_F2)
  1244. {
  1245. RenameSessionAction->Execute();
  1246. Key = 0;
  1247. }
  1248. }
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. void __fastcall TLoginDialog::EditSession()
  1252. {
  1253. ChangePage(BasicSheet);
  1254. HostNameEdit->SetFocus();
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. void __fastcall TLoginDialog::EditSessionActionExecute(TObject * /*Sender*/)
  1258. {
  1259. if (SelectedSession)
  1260. {
  1261. SetSessionData(SelectedSession);
  1262. EditSession();
  1263. }
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
  1267. {
  1268. SaveSession(FSessionData);
  1269. bool SavePassword;
  1270. bool * PSavePassword;
  1271. bool NotRecommendedSavingPassword =
  1272. !CustomWinConfiguration->UseMasterPassword &&
  1273. !SameText(UserNameEdit->Text, AnonymousUserName);
  1274. if (Configuration->DisablePasswordStoring ||
  1275. !FSessionData->HasAnyPassword())
  1276. {
  1277. PSavePassword = NULL;
  1278. }
  1279. else
  1280. {
  1281. PSavePassword = &SavePassword;
  1282. SavePassword =
  1283. ((FEditingSessionData != NULL) &&
  1284. (FEditingSessionData->Password == FSessionData->Password)) ||
  1285. !NotRecommendedSavingPassword;
  1286. }
  1287. UnicodeString SessionName = FSessionData->SessionName;
  1288. if (DoSaveSessionDialog(SessionName, PSavePassword, FEditingSessionData, NotRecommendedSavingPassword))
  1289. {
  1290. if ((PSavePassword != NULL) && !*PSavePassword)
  1291. {
  1292. FSessionData->Password = L"";
  1293. }
  1294. TSessionData * NewSession =
  1295. StoredSessions->NewSession(SessionName, FSessionData);
  1296. // modified only, explicit
  1297. StoredSessions->Save(false, true);
  1298. SaveConfiguration();
  1299. TTreeNode * Node = SessionTree->Items->GetFirstNode();
  1300. while ((Node != NULL) && (Node->Data != NewSession))
  1301. {
  1302. Node = Node->GetNext();
  1303. }
  1304. if (Node == NULL)
  1305. {
  1306. Node = AddSession(NewSession);
  1307. }
  1308. SessionTree->Selected = Node;
  1309. SetSessionData(NewSession);
  1310. ChangePage(SessionListSheet);
  1311. SessionTree->SetFocus();
  1312. }
  1313. }
  1314. //---------------------------------------------------------------------------
  1315. UnicodeString __fastcall TLoginDialog::SessionNodePath(TTreeNode * Node)
  1316. {
  1317. UnicodeString Path;
  1318. if (Node != NULL)
  1319. {
  1320. Path = Node->Text;
  1321. Node = Node->Parent;
  1322. while (Node != NULL)
  1323. {
  1324. Path.Insert(UnixIncludeTrailingBackslash(Node->Text), 1);
  1325. Node = Node->Parent;
  1326. }
  1327. }
  1328. return Path;
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TLoginDialog::DeleteSessionActionExecute(TObject * /*Sender*/)
  1332. {
  1333. assert(SessionTree->Selected != NULL);
  1334. TSessionData * Session = SelectedSession;
  1335. if (Session != NULL)
  1336. {
  1337. if (MessageDialog(FMTLOAD(CONFIRM_DELETE_SESSION, (Session->SessionName)),
  1338. qtConfirmation, qaOK | qaCancel, HELP_DELETE_SESSION) == qaOK)
  1339. {
  1340. WinConfiguration->DeleteSessionFromJumpList(Session->SessionName);
  1341. Session->Remove();
  1342. DestroySession(Session);
  1343. SessionTree->Selected->Delete();
  1344. }
  1345. }
  1346. else
  1347. {
  1348. TTreeNode * Node = SessionTree->Selected;
  1349. int Sessions = 0;
  1350. TTreeNode * ANode = Node->GetNext();
  1351. while ((ANode != NULL) && ANode->HasAsParent(Node))
  1352. {
  1353. if (ANode->Data != NULL)
  1354. {
  1355. TSessionData * Session = static_cast<TSessionData *>(ANode->Data);
  1356. if (Session->Special)
  1357. {
  1358. SessionTree->Selected = ANode;
  1359. ANode->MakeVisible();
  1360. throw Exception(FMTLOAD(LOGIN_DELETE_SPECIAL_SESSION, (Session->SessionName)));
  1361. }
  1362. Sessions++;
  1363. }
  1364. ANode = ANode->GetNext();
  1365. }
  1366. UnicodeString Path = SessionNodePath(Node);
  1367. if ((Sessions == 0) ||
  1368. (MessageDialog(FMTLOAD(LOGIN_DELETE_SESSION_FOLDER, (Path, Sessions)),
  1369. qtConfirmation, qaOK | qaCancel, HELP_DELETE_SESSION_FOLDER) == qaOK))
  1370. {
  1371. Node = SessionTree->Selected;
  1372. TTreeNode * ANode = Node->GetNext();
  1373. while ((ANode != NULL) && ANode->HasAsParent(Node))
  1374. {
  1375. if (ANode->Data != NULL)
  1376. {
  1377. TSessionData * Session = static_cast<TSessionData *>(ANode->Data);
  1378. Session->Remove();
  1379. DestroySession(Session);
  1380. }
  1381. ANode = ANode->GetNext();
  1382. }
  1383. SessionTree->Selected->Delete();
  1384. }
  1385. }
  1386. }
  1387. //---------------------------------------------------------------------------
  1388. void __fastcall TLoginDialog::ImportSessionsActionExecute(TObject * /*Sender*/)
  1389. {
  1390. if (DoImportSessionsDialog(StoredSessions))
  1391. {
  1392. SaveState();
  1393. LoadSessions();
  1394. LoadState();
  1395. if (SessionTree->Items->Count > 0)
  1396. {
  1397. SessionTree->Items->GetFirstNode()->MakeVisible();
  1398. }
  1399. }
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TLoginDialog::CleanUpActionExecute(TObject * /*Sender*/)
  1403. {
  1404. if (DoCleanupDialog(StoredSessions, Configuration))
  1405. {
  1406. SaveState();
  1407. LoadSessions();
  1408. LoadState();
  1409. }
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. void __fastcall TLoginDialog::AboutActionExecute(TObject * /*Sender*/)
  1413. {
  1414. DoAboutDialog(Configuration);
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. void __fastcall TLoginDialog::ActionListUpdate(TBasicAction *Action,
  1418. bool &Handled)
  1419. {
  1420. bool SessionSelected =
  1421. (SessionTree->Selected != NULL) && (SessionTree->Selected->Data != NULL);
  1422. if (Action == EditSessionAction)
  1423. {
  1424. EditSessionAction->Enabled = SessionSelected;
  1425. }
  1426. else if (Action == DeleteSessionAction)
  1427. {
  1428. TSessionData * Data = GetSessionData();
  1429. DeleteSessionAction->Enabled =
  1430. (SessionSelected && !Data->Special) ||
  1431. ((SessionTree->Selected != NULL) && (SessionTree->Selected->Data == NULL));
  1432. }
  1433. else if (Action == RenameSessionAction)
  1434. {
  1435. TSessionData * Data = GetSessionData();
  1436. RenameSessionAction->Enabled =
  1437. (SessionSelected && !Data->Special) ||
  1438. ((SessionTree->Selected != NULL) && (SessionTree->Selected->Data == NULL));
  1439. }
  1440. else if (Action == DesktopIconAction)
  1441. {
  1442. DesktopIconAction->Enabled = SessionSelected;
  1443. }
  1444. else if (Action == SendToHookAction)
  1445. {
  1446. SendToHookAction->Enabled = SessionSelected;
  1447. }
  1448. else if (Action == LoginAction)
  1449. {
  1450. TSessionData * Data = GetSessionData();
  1451. LoginAction->Enabled =
  1452. Data && Data->CanLogin &&
  1453. (PageControl->ActivePage != GeneralSheet);
  1454. }
  1455. else if (Action == SaveSessionAction)
  1456. {
  1457. SaveSessionAction->Enabled =
  1458. (PageControl->ActivePage != SessionListSheet) &&
  1459. (PageControl->ActivePage != LogSheet) &&
  1460. (PageControl->ActivePage != GeneralSheet);
  1461. }
  1462. else if (Action == ShellIconSessionAction)
  1463. {
  1464. ShellIconSessionAction->Enabled = SessionSelected;
  1465. }
  1466. else if (Action == NewSessionFolderAction)
  1467. {
  1468. NewSessionFolderAction->Enabled = true;
  1469. }
  1470. Handled = true;
  1471. if (!SessionTree->IsEditing())
  1472. {
  1473. // default property setter does not have guard for "the same value"
  1474. if (!LoginButton->Default)
  1475. {
  1476. LoginButton->Default = true;
  1477. }
  1478. CloseButton->Cancel = true;
  1479. }
  1480. }
  1481. //---------------------------------------------------------------------------
  1482. bool __fastcall TLoginDialog::Execute(TSessionData *& Data, bool & Owned)
  1483. {
  1484. SetSessionData(Data);
  1485. LoadConfiguration();
  1486. LoadState();
  1487. bool Result = (ShowModal() == mrOk);
  1488. SaveState();
  1489. if (Result)
  1490. {
  1491. SaveConfiguration();
  1492. Data = GetSessionData();
  1493. // FSessionData ceases to exist with the dialog
  1494. if (Data == FSessionData)
  1495. {
  1496. Owned = true;
  1497. Data = new TSessionData(L"");
  1498. Data->Assign(FSessionData);
  1499. // we carry the name of the edited stored session around while on the dialog,
  1500. // but we do not want it to leave the dialog, so that we can distinguish
  1501. // stored and ad-hoc sessions
  1502. Data->Name = L"";
  1503. }
  1504. else
  1505. {
  1506. Owned = false;
  1507. }
  1508. }
  1509. return Result;
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. void __fastcall TLoginDialog::SaveOpenedStoredSessionFolders(
  1513. TTreeNode * Node, TStrings * OpenedStoredSessionFolders)
  1514. {
  1515. if (Node->Data == NULL)
  1516. {
  1517. if (Node->Expanded)
  1518. {
  1519. OpenedStoredSessionFolders->Add(SessionNodePath(Node));
  1520. }
  1521. for (int Index = 0; Index < Node->Count; Index++)
  1522. {
  1523. SaveOpenedStoredSessionFolders(Node->Item[Index], OpenedStoredSessionFolders);
  1524. }
  1525. }
  1526. }
  1527. //---------------------------------------------------------------------------
  1528. void __fastcall TLoginDialog::SaveState()
  1529. {
  1530. assert(WinConfiguration != NULL);
  1531. TStringList * OpenedStoredSessionFolders = new TStringList();
  1532. WinConfiguration->BeginUpdate();
  1533. try
  1534. {
  1535. CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
  1536. OpenedStoredSessionFolders->CaseSensitive = false;
  1537. OpenedStoredSessionFolders->Sorted = true;
  1538. for (int Index = 0; Index < SessionTree->Items->Count; Index++)
  1539. {
  1540. SaveOpenedStoredSessionFolders(
  1541. SessionTree->Items->Item[Index], OpenedStoredSessionFolders);
  1542. }
  1543. WinConfiguration->OpenedStoredSessionFolders = OpenedStoredSessionFolders->CommaText;
  1544. }
  1545. __finally
  1546. {
  1547. WinConfiguration->EndUpdate();
  1548. delete OpenedStoredSessionFolders;
  1549. }
  1550. WinConfiguration->LastStoredSession = SessionNodePath(SessionTree->Selected);
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. void __fastcall TLoginDialog::LoadOpenedStoredSessionFolders(
  1554. TTreeNode * Node, TStrings * OpenedStoredSessionFolders)
  1555. {
  1556. if (Node->Data == NULL)
  1557. {
  1558. UnicodeString Path = SessionNodePath(Node);
  1559. if (OpenedStoredSessionFolders->IndexOf(Path) >= 0)
  1560. {
  1561. Node->Expand(false);
  1562. UpdateFolderNode(Node);
  1563. }
  1564. }
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. void __fastcall TLoginDialog::LoadState()
  1568. {
  1569. ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
  1570. TStringList * OpenedStoredSessionFolders = new TStringList();
  1571. try
  1572. {
  1573. OpenedStoredSessionFolders->CaseSensitive = false;
  1574. OpenedStoredSessionFolders->Sorted = true;
  1575. OpenedStoredSessionFolders->CommaText = WinConfiguration->OpenedStoredSessionFolders;
  1576. for (int Index = 0; Index < SessionTree->Items->Count; Index++)
  1577. {
  1578. LoadOpenedStoredSessionFolders(
  1579. SessionTree->Items->Item[Index], OpenedStoredSessionFolders);
  1580. }
  1581. // tree view tried to make expanded node children all visible, what
  1582. // may scroll the selected node (what should be the first one here),
  1583. // out of the view
  1584. if (SessionTree->Selected != NULL)
  1585. {
  1586. SessionTree->Selected->MakeVisible();
  1587. }
  1588. }
  1589. __finally
  1590. {
  1591. delete OpenedStoredSessionFolders;
  1592. }
  1593. if (!WinConfiguration->LastStoredSession.IsEmpty())
  1594. {
  1595. UnicodeString Path = WinConfiguration->LastStoredSession;
  1596. UnicodeString ParentPath = UnixExtractFilePath(Path);
  1597. TTreeNode * Node;
  1598. if (ParentPath.IsEmpty())
  1599. {
  1600. Node = SessionTree->Items->GetFirstNode();
  1601. }
  1602. else
  1603. {
  1604. TTreeNode * Parent = AddSessionPath(ParentPath, false);
  1605. Node = (Parent != NULL) ? Parent->getFirstChild() : NULL;
  1606. }
  1607. if (Node != NULL)
  1608. {
  1609. UnicodeString Name = UnixExtractFileName(Path);
  1610. // actually we cannot distinguish folder and session here
  1611. // (note that we allow folder and session with the same name),
  1612. // this is pending for future improvements
  1613. while ((Node != NULL) && !AnsiSameText(Node->Text, Name))
  1614. {
  1615. Node = Node->getNextSibling();
  1616. }
  1617. if (Node != NULL)
  1618. {
  1619. SessionTree->Selected = Node;
  1620. SessionTree->Selected->MakeVisible();
  1621. }
  1622. }
  1623. }
  1624. }
  1625. //---------------------------------------------------------------------------
  1626. void __fastcall TLoginDialog::SaveConfiguration()
  1627. {
  1628. assert(CustomWinConfiguration);
  1629. CustomWinConfiguration->BeginUpdate();
  1630. try
  1631. {
  1632. LoggingFrame->SaveConfiguration();
  1633. GeneralSettingsFrame->SaveConfiguration();
  1634. }
  1635. __finally
  1636. {
  1637. CustomWinConfiguration->EndUpdate();
  1638. }
  1639. }
  1640. //---------------------------------------------------------------------------
  1641. void __fastcall TLoginDialog::LoadConfiguration()
  1642. {
  1643. assert(CustomWinConfiguration);
  1644. LoggingFrame->LoadConfiguration();
  1645. GeneralSettingsFrame->LoadConfiguration();
  1646. UpdateControls();
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
  1650. {
  1651. ShowPreferencesDialog();
  1652. UpdateControls();
  1653. }
  1654. //---------------------------------------------------------------------------
  1655. void __fastcall TLoginDialog::MasterPasswordRecrypt(TObject * /*Sender*/)
  1656. {
  1657. FSessionData->RecryptPasswords();
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. void __fastcall TLoginDialog::ShowPreferencesDialog()
  1661. {
  1662. assert(CustomWinConfiguration->OnMasterPasswordRecrypt == NULL);
  1663. CustomWinConfiguration->OnMasterPasswordRecrypt = MasterPasswordRecrypt;
  1664. try
  1665. {
  1666. DoPreferencesDialog(pmLogin);
  1667. }
  1668. __finally
  1669. {
  1670. assert(CustomWinConfiguration->OnMasterPasswordRecrypt == MasterPasswordRecrypt);
  1671. CustomWinConfiguration->OnMasterPasswordRecrypt = NULL;
  1672. }
  1673. }
  1674. //---------------------------------------------------------------------------
  1675. void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
  1676. {
  1677. Default();
  1678. EditSession();
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
  1682. TTreeNode *Node)
  1683. {
  1684. if (NoUpdate == 0)
  1685. {
  1686. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  1687. // should happen only while loading language
  1688. // (UpdateNavigationTree may not be called yet)
  1689. if (Tab != NULL)
  1690. {
  1691. PageControl->ActivePage = Tab;
  1692. // reshow the accelerators, etc
  1693. ResetSystemSettings(this);
  1694. }
  1695. }
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
  1699. {
  1700. PageControl->ActivePage = Tab;
  1701. PageControlChange(PageControl);
  1702. }
  1703. //---------------------------------------------------------------------------
  1704. void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
  1705. {
  1706. bool Found = false;
  1707. if (PageControl->ActivePage)
  1708. {
  1709. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1710. {
  1711. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1712. reinterpret_cast<int>(PageControl->ActivePage))
  1713. {
  1714. NavigationTree->Items->Item[Index]->Selected = true;
  1715. Found = true;
  1716. }
  1717. }
  1718. }
  1719. if (!Found)
  1720. {
  1721. assert(false);
  1722. ChangePage(BasicSheet);
  1723. }
  1724. else
  1725. {
  1726. DataChange(Sender);
  1727. }
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
  1731. {
  1732. if (Message.CharCode == VK_TAB)
  1733. {
  1734. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1735. if (Shift.Contains(ssCtrl))
  1736. {
  1737. TTreeNode * Node = NavigationTree->Selected;
  1738. if (!Shift.Contains(ssShift))
  1739. {
  1740. Node = Node->GetNext();
  1741. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1742. }
  1743. else
  1744. {
  1745. if (Node->GetPrev()) Node = Node->GetPrev();
  1746. else
  1747. while (Node->GetNext()) Node = Node->GetNext();
  1748. }
  1749. Node->Selected = True;
  1750. Message.Result = 1;
  1751. return;
  1752. }
  1753. }
  1754. TForm::Dispatch(&Message);
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TLoginDialog::WMHelp(TWMHelp & Message)
  1758. {
  1759. assert(Message.HelpInfo != NULL);
  1760. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1761. {
  1762. // invoke help for active page (not for whole form), regardless of focus
  1763. // (e.g. even if focus is on control outside pagecontrol)
  1764. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1765. }
  1766. TForm::Dispatch(&Message);
  1767. }
  1768. //---------------------------------------------------------------------------
  1769. void __fastcall TLoginDialog::Dispatch(void * Message)
  1770. {
  1771. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1772. assert(M);
  1773. if (M->Msg == CM_DIALOGKEY)
  1774. {
  1775. CMDialogKey(*((TWMKeyDown *)Message));
  1776. }
  1777. else if (M->Msg == WM_LOCALE_CHANGE)
  1778. {
  1779. if (M->WParam == 0)
  1780. {
  1781. SaveConfiguration();
  1782. SaveState();
  1783. SaveSession(FSessionData);
  1784. FSavedTab = PageControl->ActivePage;
  1785. FSavedSession = ((SessionTree->Selected != NULL) ?
  1786. SessionTree->Selected->AbsoluteIndex : -1);
  1787. assert(FSystemSettings);
  1788. RevokeSystemSettings(this, FSystemSettings);
  1789. FSystemSettings = NULL;
  1790. Hide();
  1791. }
  1792. else
  1793. {
  1794. FLocaleChanging = true;
  1795. try
  1796. {
  1797. Show();
  1798. }
  1799. __finally
  1800. {
  1801. FLocaleChanging = false;
  1802. }
  1803. }
  1804. }
  1805. else if (M->Msg == WM_HELP)
  1806. {
  1807. WMHelp(*((TWMHelp *)Message));
  1808. }
  1809. else
  1810. {
  1811. TForm::Dispatch(Message);
  1812. }
  1813. }
  1814. //---------------------------------------------------------------------------
  1815. void __fastcall TLoginDialog::AlgListBoxStartDrag(TObject * Sender,
  1816. TDragObject *& /*DragObject*/)
  1817. {
  1818. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1819. FAlgDragDest = -1;
  1820. }
  1821. //---------------------------------------------------------------------------
  1822. void __fastcall TLoginDialog::AlgListBoxDragOver(TObject * Sender,
  1823. TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
  1824. {
  1825. if (Source == Sender)
  1826. {
  1827. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1828. }
  1829. else
  1830. {
  1831. Accept = false;
  1832. }
  1833. }
  1834. //---------------------------------------------------------------------------
  1835. void __fastcall TLoginDialog::AlgListBoxDragDrop(TObject * Sender,
  1836. TObject * Source, int X, int Y)
  1837. {
  1838. if (Source == Sender)
  1839. {
  1840. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1841. if (AllowAlgDrag(AlgListBox, X, Y))
  1842. {
  1843. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1844. }
  1845. }
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
  1849. {
  1850. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1851. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1852. }
  1853. //---------------------------------------------------------------------------
  1854. void __fastcall TLoginDialog::KexButtonClick(TObject *Sender)
  1855. {
  1856. AlgMove(KexListBox, KexListBox->ItemIndex,
  1857. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1858. }
  1859. //---------------------------------------------------------------------------
  1860. bool __fastcall TLoginDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1861. {
  1862. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1863. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1864. }
  1865. //---------------------------------------------------------------------------
  1866. void __fastcall TLoginDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1867. {
  1868. if (Source >= 0 && Source < AlgListBox->Items->Count &&
  1869. Dest >= 0 && Dest < AlgListBox->Items->Count)
  1870. {
  1871. AlgListBox->Items->Move(Source, Dest);
  1872. AlgListBox->ItemIndex = Dest;
  1873. AlgListBox->SetFocus();
  1874. }
  1875. UpdateControls();
  1876. }
  1877. //---------------------------------------------------------------------------
  1878. void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
  1879. TObject * /*Sender*/)
  1880. {
  1881. if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
  1882. qaOK | qaCancel, HELP_SESSION_SAVE_DEFAULT) == qaOK)
  1883. {
  1884. SaveSession(FSessionData);
  1885. if (!Configuration->DisablePasswordStoring &&
  1886. FSessionData->HasAnyPassword() &&
  1887. CustomWinConfiguration->UseMasterPassword)
  1888. {
  1889. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  1890. }
  1891. StoredSessions->DefaultSettings = FSessionData;
  1892. }
  1893. }
  1894. //---------------------------------------------------------------------------
  1895. void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
  1896. {
  1897. MenuPopup(ToolsPopupMenu, ToolsMenuButton);
  1898. }
  1899. //---------------------------------------------------------------------------
  1900. void __fastcall TLoginDialog::ShellIconSessionActionExecute(
  1901. TObject * /*Sender*/)
  1902. {
  1903. MenuPopup(IconsPopupMenu, ShellIconsButton);
  1904. }
  1905. //---------------------------------------------------------------------------
  1906. void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
  1907. {
  1908. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SHORTCUT, (SelectedSession->Name)),
  1909. qtConfirmation, qaYes | qaNo, HELP_CREATE_SHORTCUT) == qaYes)
  1910. {
  1911. assert(SelectedSession);
  1912. CreateDesktopSessionShortCut(SelectedSession, SelectedSession->LocalName,
  1913. L"/UploadIfAny");
  1914. }
  1915. }
  1916. //---------------------------------------------------------------------------
  1917. void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
  1918. {
  1919. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
  1920. qtConfirmation, qaYes | qaNo, HELP_CREATE_SENDTO) == qaYes)
  1921. {
  1922. assert(SelectedSession);
  1923. CreateDesktopSessionShortCut(SelectedSession,
  1924. FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->LocalName)),
  1925. L"/Upload", CSIDL_SENDTO);
  1926. }
  1927. }
  1928. //---------------------------------------------------------------------------
  1929. void __fastcall TLoginDialog::SessionTreeCustomDrawItem(
  1930. TCustomTreeView * Sender, TTreeNode * Node, TCustomDrawState State,
  1931. bool & DefaultDraw)
  1932. {
  1933. TSessionData * Data = (TSessionData *)Node->Data;
  1934. TFontStyles Styles = Sender->Canvas->Font->Style;
  1935. if ((Data != NULL) && Data->Special)
  1936. {
  1937. Styles = Styles << fsBold << fsUnderline;
  1938. }
  1939. else
  1940. {
  1941. Styles = Styles >> fsBold >> fsUnderline;
  1942. }
  1943. if (State.Empty() && !Node->DropTarget)
  1944. {
  1945. if (Data == NULL)
  1946. {
  1947. bool AnySession = false;
  1948. TTreeNode * ANode = Node->GetNext();
  1949. while (!AnySession && (ANode != NULL) && ANode->HasAsParent(Node))
  1950. {
  1951. AnySession = (ANode->Data != NULL);
  1952. ANode = ANode->GetNext();
  1953. }
  1954. if (!AnySession)
  1955. {
  1956. Sender->Canvas->Font->Color = clGrayText;
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if (Data->Color != 0)
  1962. {
  1963. Sender->Canvas->Brush->Color = (TColor)Data->Color;
  1964. }
  1965. }
  1966. }
  1967. Sender->Canvas->Font->Style = Styles;
  1968. DefaultDraw = true;
  1969. }
  1970. //---------------------------------------------------------------------------
  1971. void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
  1972. {
  1973. CheckForUpdates(false);
  1974. }
  1975. //---------------------------------------------------------------------------
  1976. void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
  1977. {
  1978. delete FLanguagesPopupMenu;
  1979. FLanguagesPopupMenu = new TPopupMenu(this);
  1980. TMenuItem * Item;
  1981. TStrings * Locales = GUIConfiguration->Locales;
  1982. for (int Index = 0; Index < Locales->Count; Index++)
  1983. {
  1984. Item = new TMenuItem(FLanguagesPopupMenu);
  1985. FLanguagesPopupMenu->Items->Add(Item);
  1986. Item->Caption = Locales->Strings[Index];
  1987. Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
  1988. Item->OnClick = LocaleClick;
  1989. Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
  1990. GUIConfiguration->Locale);
  1991. }
  1992. Item = new TMenuItem(FLanguagesPopupMenu);
  1993. FLanguagesPopupMenu->Items->Add(Item);
  1994. Item->Caption = L"-";
  1995. Item = new TMenuItem(FLanguagesPopupMenu);
  1996. FLanguagesPopupMenu->Items->Add(Item);
  1997. Item->Caption = LoadStr(LOGIN_GET_LOCALES);
  1998. Item->OnClick = LocaleGetClick;
  1999. MenuPopup(FLanguagesPopupMenu, LanguagesButton);
  2000. }
  2001. //---------------------------------------------------------------------------
  2002. void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
  2003. {
  2004. assert(Sender);
  2005. GUIConfiguration->Locale =
  2006. static_cast<LCID>(dynamic_cast<TComponent*>(Sender)->Tag);
  2007. LanguagesButton->SetFocus();
  2008. }
  2009. //---------------------------------------------------------------------------
  2010. void __fastcall TLoginDialog::LocaleGetClick(TObject * /*Sender*/)
  2011. {
  2012. OpenBrowser(LoadStr(LOCALES_URL));
  2013. }
  2014. //---------------------------------------------------------------------------
  2015. void __fastcall TLoginDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
  2016. {
  2017. if (!NoUpdate)
  2018. {
  2019. UpdateControls();
  2020. if (AuthGSSAPICheck3->Checked && !Configuration->GSSAPIInstalled)
  2021. {
  2022. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
  2023. }
  2024. }
  2025. }
  2026. //---------------------------------------------------------------------------
  2027. void __fastcall TLoginDialog::HelpButtonClick(TObject * /*Sender*/)
  2028. {
  2029. FormHelp(this);
  2030. }
  2031. //---------------------------------------------------------------------------
  2032. void __fastcall TLoginDialog::VerifyKey(UnicodeString FileName, bool TypeOnly)
  2033. {
  2034. if (!FileName.Trim().IsEmpty())
  2035. {
  2036. FileName = ExpandEnvironmentVariables(FileName);
  2037. TKeyType Type = KeyType(FileName);
  2038. UnicodeString Message;
  2039. switch (Type)
  2040. {
  2041. case ktOpenSSH:
  2042. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, L"OpenSSH SSH-2"));
  2043. break;
  2044. case ktSSHCom:
  2045. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, L"ssh.com SSH-2"));
  2046. break;
  2047. case ktSSH1:
  2048. case ktSSH2:
  2049. // on file select do not check for SSH version as user may
  2050. // intend to change it only after he/she selects key file
  2051. if (!TypeOnly)
  2052. {
  2053. TSessionData * Data = GetSessionData();
  2054. if ((Type == ktSSH1) !=
  2055. ((Data->SshProt == ssh1only) || (Data->SshProt == ssh1)))
  2056. {
  2057. Message = FMTLOAD(KEY_TYPE_DIFFERENT_SSH,
  2058. (FileName, (Type == ktSSH1 ? L"SSH-1" : L"PuTTY SSH-2")));
  2059. }
  2060. }
  2061. break;
  2062. default:
  2063. assert(false);
  2064. // fallthru
  2065. case ktUnopenable:
  2066. case ktUnknown:
  2067. Message = FMTLOAD(KEY_TYPE_UNKNOWN, (FileName));
  2068. break;
  2069. }
  2070. if (!Message.IsEmpty())
  2071. {
  2072. if (MessageDialog(Message, qtWarning, qaIgnore | qaAbort,
  2073. HELP_LOGIN_KEY_TYPE) == qaAbort)
  2074. {
  2075. Abort();
  2076. }
  2077. }
  2078. }
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TLoginDialog::PrivateKeyEditAfterDialog(TObject * Sender,
  2082. UnicodeString & Name, bool & /*Action*/)
  2083. {
  2084. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2085. {
  2086. Name = FBeforeDialogPath;
  2087. }
  2088. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  2089. if (Name != Edit->Text)
  2090. {
  2091. VerifyKey(Name, true);
  2092. }
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TLoginDialog::FormCloseQuery(TObject * /*Sender*/,
  2096. bool & /*CanClose*/)
  2097. {
  2098. if (ModalResult != mrCancel)
  2099. {
  2100. VerifyKey(GetSessionData()->PublicKeyFile, false);
  2101. // for tunnel key do not check SSH version as it is not configurable
  2102. VerifyKey(GetSessionData()->TunnelPublicKeyFile, true);
  2103. }
  2104. }
  2105. //---------------------------------------------------------------------------
  2106. void __fastcall TLoginDialog::ColorButtonClick(TObject * /*Sender*/)
  2107. {
  2108. ColorDefaultItem->Checked = (FColor == 0);
  2109. PickColorItem->Checked = (FColor != 0);
  2110. PickColorItem->ImageIndex = (FColor != 0 ? 0 : -1);
  2111. ColorImageList->BkColor = FColor;
  2112. MenuPopup(ColorPopupMenu, ColorButton);
  2113. }
  2114. //---------------------------------------------------------------------------
  2115. void __fastcall TLoginDialog::ColorDefaultItemClick(TObject * /*Sender*/)
  2116. {
  2117. FColor = (TColor)0;
  2118. }
  2119. //---------------------------------------------------------------------------
  2120. void __fastcall TLoginDialog::PickColorItemClick(TObject * /*Sender*/)
  2121. {
  2122. TColorDialog * Dialog = new TColorDialog(this);
  2123. try
  2124. {
  2125. Dialog->Options = Dialog->Options << cdFullOpen;
  2126. Dialog->Color = (FColor != 0 ? FColor : clSkyBlue);
  2127. if (Dialog->Execute())
  2128. {
  2129. FColor = Dialog->Color;
  2130. }
  2131. }
  2132. __finally
  2133. {
  2134. delete Dialog;
  2135. }
  2136. }
  2137. //---------------------------------------------------------------------------
  2138. void __fastcall TLoginDialog::SessionTreeEditing(TObject * /*Sender*/,
  2139. TTreeNode * Node, bool & AllowEdit)
  2140. {
  2141. TSessionData * Data = static_cast<TSessionData *>(Node->Data);
  2142. AllowEdit = (Data == NULL) || !Data->Special;
  2143. if (AllowEdit)
  2144. {
  2145. LoginButton->Default = false;
  2146. CloseButton->Cancel = false;
  2147. }
  2148. }
  2149. //---------------------------------------------------------------------------
  2150. void __fastcall TLoginDialog::RenameSessionActionExecute(TObject * /*Sender*/)
  2151. {
  2152. if (SessionTree->Selected != NULL)
  2153. {
  2154. SessionTree->Selected->EditText();
  2155. }
  2156. }
  2157. //---------------------------------------------------------------------------
  2158. void __fastcall TLoginDialog::CheckDuplicateFolder(TTreeNode * Parent,
  2159. UnicodeString Text, TTreeNode * Node)
  2160. {
  2161. TTreeNode * ANode =
  2162. ((Parent == NULL) ? SessionTree->Items->GetFirstNode() :
  2163. Parent->getFirstChild());
  2164. // note that we allow folder with the same name as existing session
  2165. // on the same level (see also AddSession)
  2166. while ((ANode != NULL) &&
  2167. ((ANode == Node) || (ANode->Data != NULL) || !AnsiSameText(ANode->Text, Text)))
  2168. {
  2169. ANode = ANode->getNextSibling();
  2170. }
  2171. if (ANode != NULL)
  2172. {
  2173. throw Exception(FMTLOAD(LOGIN_DUPLICATE_SESSION_FOLDER, (Text)));
  2174. }
  2175. }
  2176. //---------------------------------------------------------------------------
  2177. void __fastcall TLoginDialog::SessionTreeEdited(TObject * /*Sender*/,
  2178. TTreeNode * Node, UnicodeString & S)
  2179. {
  2180. if (Node->Text != S)
  2181. {
  2182. TSessionData * Session = SelectedSession;
  2183. TSessionData::ValidateName(S);
  2184. if (Session != NULL)
  2185. {
  2186. UnicodeString Path = UnixExtractFilePath(Session->Name) + S;
  2187. SessionNameValidate(Path, Session);
  2188. // remove from storage
  2189. Session->Remove();
  2190. TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
  2191. // modified, only explicit
  2192. StoredSessions->Save(false, true);
  2193. // the session may be the same, if only letter case has changed
  2194. if (Session != NewSession)
  2195. {
  2196. // if we overwrite existing session, remove the original item
  2197. // (we must not delete the node we are editing)
  2198. TTreeNode * ANode =
  2199. ((Node->Parent == NULL) ? SessionTree->Items->GetFirstNode() :
  2200. Node->Parent->getFirstChild());
  2201. while ((ANode != NULL) && (ANode->Data != NewSession))
  2202. {
  2203. ANode = ANode->getNextSibling();
  2204. }
  2205. if (ANode != NULL)
  2206. {
  2207. ANode->Delete();
  2208. }
  2209. Node->Data = NewSession;
  2210. DestroySession(Session);
  2211. }
  2212. SetSessionData(NewSession);
  2213. }
  2214. else
  2215. {
  2216. CheckDuplicateFolder(Node->Parent, S, Node);
  2217. UnicodeString ParentPath = UnixIncludeTrailingBackslash(SessionNodePath(Node->Parent));
  2218. UnicodeString OldRoot = ParentPath + Node->Text;
  2219. UnicodeString NewRoot = ParentPath + S;
  2220. bool AnySession = false;
  2221. TSortType PrevSortType = SessionTree->SortType;
  2222. // temporarily disable automatic sorting, so that nodes are kept in order
  2223. // while we traverse them. otherwise it may happen that we omit some.
  2224. SessionTree->SortType = Comctrls::stNone;
  2225. try
  2226. {
  2227. TTreeNode * ANode = Node->GetNext();
  2228. while ((ANode != NULL) && ANode->HasAsParent(Node))
  2229. {
  2230. if (ANode->Data != NULL)
  2231. {
  2232. AnySession = true;
  2233. TSessionData * Session = static_cast<TSessionData *>(ANode->Data);
  2234. // remove from storage
  2235. Session->Remove();
  2236. UnicodeString Path = Session->Name;
  2237. assert(Path.SubString(1, OldRoot.Length()) == OldRoot);
  2238. Path.Delete(1, OldRoot.Length());
  2239. Path.Insert(NewRoot, 1);
  2240. TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
  2241. // the session may be the same, if only letter case has changed
  2242. if (NewSession != Session)
  2243. {
  2244. ANode->Data = NewSession;
  2245. DestroySession(Session);
  2246. }
  2247. }
  2248. ANode = ANode->GetNext();
  2249. }
  2250. }
  2251. __finally
  2252. {
  2253. SessionTree->SortType = PrevSortType;
  2254. }
  2255. if (AnySession)
  2256. {
  2257. // modified, only explicit
  2258. StoredSessions->Save(false, true);
  2259. }
  2260. }
  2261. }
  2262. }
  2263. //---------------------------------------------------------------------------
  2264. void __fastcall TLoginDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  2265. UnicodeString & Name, bool & /*Action*/)
  2266. {
  2267. FBeforeDialogPath = Name;
  2268. Name = ExpandEnvironmentVariables(Name);
  2269. }
  2270. //---------------------------------------------------------------------------
  2271. int __fastcall TLoginDialog::FSProtocolToIndex(TFSProtocol FSProtocol,
  2272. bool & AllowScpFallback)
  2273. {
  2274. if (FSProtocol == fsSFTP)
  2275. {
  2276. AllowScpFallback = true;
  2277. bool Dummy;
  2278. return FSProtocolToIndex(fsSFTPonly, Dummy);
  2279. }
  2280. else
  2281. {
  2282. AllowScpFallback = false;
  2283. for (int Index = 0; Index < TransferProtocolCombo->Items->Count; Index++)
  2284. {
  2285. if (FSOrder[Index] == FSProtocol)
  2286. {
  2287. return Index;
  2288. }
  2289. }
  2290. // SFTP is always present
  2291. return FSProtocolToIndex(fsSFTP, AllowScpFallback);
  2292. }
  2293. }
  2294. //---------------------------------------------------------------------------
  2295. TFSProtocol __fastcall TLoginDialog::IndexToFSProtocol(int Index, bool AllowScpFallback)
  2296. {
  2297. bool InBounds = (Index >= 0) && (Index < static_cast<int>(LENOF(FSOrder)));
  2298. // can be temporary "unselected" while new language is being loaded
  2299. assert(InBounds || (Index == -1));
  2300. TFSProtocol Result = fsSFTP;
  2301. if (InBounds)
  2302. {
  2303. Result = FSOrder[Index];
  2304. if ((Result == fsSFTPonly) && AllowScpFallback)
  2305. {
  2306. Result = fsSFTP;
  2307. }
  2308. }
  2309. return Result;
  2310. }
  2311. //---------------------------------------------------------------------------
  2312. int __fastcall TLoginDialog::LastSupportedFtpProxyMethod()
  2313. {
  2314. return pmHTTP;
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. bool __fastcall TLoginDialog::SupportedFtpProxyMethod(int Method)
  2318. {
  2319. return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. TProxyMethod __fastcall TLoginDialog::GetProxyMethod()
  2323. {
  2324. TProxyMethod Result;
  2325. if (IndexToFSProtocol(TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked) != fsFTP)
  2326. {
  2327. Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
  2328. }
  2329. else
  2330. {
  2331. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  2332. {
  2333. Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
  2334. }
  2335. else
  2336. {
  2337. Result = ::pmNone;
  2338. }
  2339. }
  2340. return Result;
  2341. }
  2342. //---------------------------------------------------------------------------
  2343. int __fastcall TLoginDialog::GetFtpProxyLogonType()
  2344. {
  2345. int Result;
  2346. if (IndexToFSProtocol(TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked) != fsFTP)
  2347. {
  2348. Result = 0;
  2349. }
  2350. else
  2351. {
  2352. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  2353. {
  2354. Result = 0;
  2355. }
  2356. else
  2357. {
  2358. Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
  2359. }
  2360. }
  2361. return Result;
  2362. }
  2363. //---------------------------------------------------------------------------
  2364. int __fastcall TLoginDialog::DefaultPort()
  2365. {
  2366. TFSProtocol FSProtocol = IndexToFSProtocol(
  2367. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  2368. int Result;
  2369. switch (FSProtocol)
  2370. {
  2371. case fsSCPonly:
  2372. case fsSFTP:
  2373. case fsSFTPonly:
  2374. Result = 22;
  2375. break;
  2376. case fsFTP:
  2377. if (FtpsCombo->ItemIndex == ftpsImplicit)
  2378. {
  2379. Result = 990;
  2380. }
  2381. else
  2382. {
  2383. Result = 21;
  2384. }
  2385. break;
  2386. default:
  2387. assert(false);
  2388. Result = -1;
  2389. break;
  2390. }
  2391. return Result;
  2392. }
  2393. //---------------------------------------------------------------------------
  2394. void __fastcall TLoginDialog::TransferProtocolComboChange(TObject * Sender)
  2395. {
  2396. int ADefaultPort = DefaultPort();
  2397. if (!NoUpdate)
  2398. {
  2399. if (PortNumberEdit->AsInteger == FDefaultPort)
  2400. {
  2401. PortNumberEdit->AsInteger = ADefaultPort;
  2402. }
  2403. }
  2404. FDefaultPort = ADefaultPort;
  2405. DataChange(Sender);
  2406. }
  2407. //---------------------------------------------------------------------------
  2408. void __fastcall TLoginDialog::NavigationTreeCollapsing(
  2409. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2410. {
  2411. AllowCollapse = false;
  2412. }
  2413. //---------------------------------------------------------------------------
  2414. void __fastcall TLoginDialog::ProxyLocalCommandBrowseButtonClick(
  2415. TObject * /*Sender*/)
  2416. {
  2417. BrowseForExecutable(ProxyLocalCommandEdit,
  2418. LoadStr(LOGIN_SELECT_LOCAL_PROXY),
  2419. LoadStr(EXECUTABLE_FILTER), false, true);
  2420. }
  2421. //---------------------------------------------------------------------------
  2422. void __fastcall TLoginDialog::SessionTreeExpandedCollapsed(TObject * /*Sender*/,
  2423. TTreeNode * Node)
  2424. {
  2425. UpdateFolderNode(Node);
  2426. }
  2427. //---------------------------------------------------------------------------
  2428. void __fastcall TLoginDialog::SessionTreeCompare(TObject * /*Sender*/,
  2429. TTreeNode * Node1, TTreeNode * Node2, int /*Data*/, int & Compare)
  2430. {
  2431. if ((Node1->Data == NULL) && (Node2->Data != NULL))
  2432. {
  2433. Compare = -1;
  2434. }
  2435. else if ((Node1->Data != NULL) && (Node2->Data == NULL))
  2436. {
  2437. Compare = 1;
  2438. }
  2439. else if (Node1->Data == NULL)
  2440. {
  2441. Compare = AnsiCompareText(Node1->Text, Node2->Text);
  2442. }
  2443. else
  2444. {
  2445. Compare = NamedObjectSortProc(Node1->Data, Node2->Data);
  2446. }
  2447. }
  2448. //---------------------------------------------------------------------------
  2449. void __fastcall TLoginDialog::NewSessionFolderInputDialogInitialize(
  2450. TObject * /*Sender*/, TInputDialogData * Data)
  2451. {
  2452. TEdit * Edit = Data->Edit;
  2453. int P = Edit->Text.LastDelimiter(L"/");
  2454. if (P > 0)
  2455. {
  2456. Edit->SetFocus();
  2457. Edit->SelStart = P;
  2458. Edit->SelLength = Edit->Text.Length() - P;
  2459. }
  2460. }
  2461. //---------------------------------------------------------------------------
  2462. TTreeNode * __fastcall TLoginDialog::SessionFolderNode(TTreeNode * Node)
  2463. {
  2464. TTreeNode * Parent;
  2465. if (Node == NULL)
  2466. {
  2467. Parent = NULL;
  2468. }
  2469. else if (Node->Data != NULL)
  2470. {
  2471. Parent = Node->Parent;
  2472. }
  2473. else
  2474. {
  2475. Parent = Node;
  2476. }
  2477. return Parent;
  2478. }
  2479. //---------------------------------------------------------------------------
  2480. TTreeNode * __fastcall TLoginDialog::CurrentSessionFolderNode()
  2481. {
  2482. return SessionFolderNode(SessionTree->Selected);
  2483. }
  2484. //---------------------------------------------------------------------------
  2485. void __fastcall TLoginDialog::NewSessionFolderActionExecute(
  2486. TObject * /*Sender*/)
  2487. {
  2488. UnicodeString Name =
  2489. UnixIncludeTrailingBackslash(SessionNodePath(CurrentSessionFolderNode())) +
  2490. LoadStr(NEW_FOLDER);
  2491. if (InputDialog(LoadStr(LOGIN_NEW_SESSION_FOLDER_CAPTION),
  2492. LoadStr(LOGIN_NEW_SESSION_FOLDER_PROMPT), Name, HELP_NEW_SESSION_FOLDER,
  2493. NULL, true, NewSessionFolderInputDialogInitialize))
  2494. {
  2495. Name = UnixExcludeTrailingBackslash(Name);
  2496. if (!Name.IsEmpty())
  2497. {
  2498. TTreeNode * Parent = AddSessionPath(UnixExtractFilePath(Name));
  2499. CheckDuplicateFolder(Parent, UnixExtractFileName(Name), NULL);
  2500. TTreeNode * Node = AddSessionPath(Name);
  2501. SessionTree->Selected = Node;
  2502. Node->MakeVisible();
  2503. }
  2504. }
  2505. }
  2506. //---------------------------------------------------------------------------
  2507. bool __fastcall TLoginDialog::SessionAllowDrop(TTreeNode * DropTarget)
  2508. {
  2509. assert(SessionTree->Selected != NULL);
  2510. return (SessionTree->Selected->Parent != DropTarget);
  2511. }
  2512. //---------------------------------------------------------------------------
  2513. void __fastcall TLoginDialog::SessionTreeProc(TMessage & AMessage)
  2514. {
  2515. if (AMessage.Msg == CM_DRAG)
  2516. {
  2517. TCMDrag & Message = reinterpret_cast<TCMDrag &>(AMessage);
  2518. // reimplement dmDragMove to avoid TCustomTreeView.DoDragOver,
  2519. // which resets DropTarget to pointed-to node
  2520. // (note that this disables OnDragOver event handler)
  2521. if ((Message.DragMessage == dmDragMove) ||
  2522. (Message.DragMessage == dmDragEnter) ||
  2523. (Message.DragMessage == dmDragLeave))
  2524. {
  2525. if (Message.DragMessage != dmDragMove)
  2526. {
  2527. // must call it at least for dmDragLeave, because it does some cleanup,
  2528. // but we need to override result below, as it defaults to "not accepted"
  2529. FOldSessionTreeProc(AMessage);
  2530. }
  2531. TDragControlObject * DragObject = dynamic_cast<TDragControlObject *>(Message.DragRec->Source);
  2532. if ((DragObject != NULL) && (DragObject->Control == SessionTree))
  2533. {
  2534. TPoint P = SessionTree->ScreenToClient(Message.DragRec->Pos);
  2535. TTreeNode * DropTarget = SessionFolderNode(SessionTree->GetNodeAt(P.x, P.y));
  2536. if (!SessionAllowDrop(DropTarget))
  2537. {
  2538. DropTarget = NULL;
  2539. Message.Result = 0;
  2540. }
  2541. else
  2542. {
  2543. Message.Result = 1;
  2544. }
  2545. if (Message.DragMessage == dmDragMove)
  2546. {
  2547. SessionTree->DropTarget = DropTarget;
  2548. }
  2549. FScrollOnDragOver->DragOver(P);
  2550. }
  2551. else
  2552. {
  2553. Message.Result = 0;
  2554. }
  2555. }
  2556. else
  2557. {
  2558. FOldSessionTreeProc(AMessage);
  2559. }
  2560. }
  2561. else
  2562. {
  2563. FOldSessionTreeProc(AMessage);
  2564. }
  2565. }
  2566. //---------------------------------------------------------------------------
  2567. void __fastcall TLoginDialog::SessionTreeStartDrag(TObject * /*Sender*/,
  2568. TDragObject *& /*DragObject*/)
  2569. {
  2570. assert(SessionTree->Selected != NULL);
  2571. // neither session folders not special sessions can be dragged
  2572. if ((SessionTree->Selected == NULL) ||
  2573. (SessionTree->Selected->Data == NULL) ||
  2574. ((SessionTree->Selected->Data != NULL) &&
  2575. SelectedSession->Special))
  2576. {
  2577. Abort();
  2578. }
  2579. FScrollOnDragOver->StartDrag();
  2580. }
  2581. //---------------------------------------------------------------------------
  2582. void __fastcall TLoginDialog::SessionTreeDragDrop(TObject * Sender,
  2583. TObject * Source, int /*X*/, int /*Y*/)
  2584. {
  2585. if ((Sender == Source) &&
  2586. (SessionTree->Selected != NULL) &&
  2587. (SessionTree->Selected->Parent != SessionTree->DropTarget))
  2588. {
  2589. TTreeNode * DropTarget = SessionTree->DropTarget;
  2590. TSessionData * Session = SelectedSession;
  2591. UnicodeString Path =
  2592. UnixIncludeTrailingBackslash(SessionNodePath(DropTarget)) +
  2593. UnixExtractFileName(Session->SessionName);
  2594. SessionNameValidate(Path, Session);
  2595. // remove from storage
  2596. Session->Remove();
  2597. TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
  2598. // modified, only explicit
  2599. StoredSessions->Save(false, true);
  2600. // this should aways be the case
  2601. if (Session != NewSession)
  2602. {
  2603. TTreeNode * Node = SessionTree->Selected;
  2604. // look for overwritten node (if any)
  2605. TTreeNode * ANode = SessionTree->Items->GetFirstNode();
  2606. while (ANode != NULL)
  2607. {
  2608. if (ANode->Data == NewSession)
  2609. {
  2610. ANode->Delete();
  2611. break;
  2612. }
  2613. ANode = ANode->GetNext();
  2614. }
  2615. Node->MoveTo(DropTarget, naAddChild);
  2616. Node->Data = NewSession;
  2617. // try to make both visible
  2618. if (DropTarget != NULL)
  2619. {
  2620. DropTarget->MakeVisible();
  2621. }
  2622. Node->MakeVisible();
  2623. DestroySession(Session);
  2624. }
  2625. else
  2626. {
  2627. assert(false);
  2628. }
  2629. SetSessionData(NewSession);
  2630. }
  2631. else
  2632. {
  2633. assert(false);
  2634. }
  2635. }
  2636. //---------------------------------------------------------------------------
  2637. void __fastcall TLoginDialog::SessionTreeMouseMove(TObject * /*Sender*/,
  2638. TShiftState /*Shift*/, int X, int Y)
  2639. {
  2640. TTreeNode * Node = SessionTree->GetNodeAt(X, Y);
  2641. THitTests HitTest = SessionTree->GetHitTestInfoAt(X, Y);
  2642. if (Node != FHintNode)
  2643. {
  2644. Application->CancelHint();
  2645. UnicodeString Hint;
  2646. if (HitTest.Contains(htOnItem) || HitTest.Contains(htOnIcon) ||
  2647. HitTest.Contains(htOnLabel) || HitTest.Contains(htOnStateIcon))
  2648. {
  2649. FHintNode = Node;
  2650. if (Node->Data != NULL)
  2651. {
  2652. Hint = static_cast<TSessionData *>(Node->Data)->InfoTip;
  2653. }
  2654. else
  2655. {
  2656. Hint = L"";
  2657. }
  2658. }
  2659. else
  2660. {
  2661. FHintNode = NULL;
  2662. Hint = L"";
  2663. }
  2664. SessionTree->Hint = Hint;
  2665. }
  2666. }
  2667. //---------------------------------------------------------------------------
  2668. void __fastcall TLoginDialog::SessionTreeEndDrag(TObject * /*Sender*/,
  2669. TObject * /*Target*/, int /*X*/, int /*Y*/)
  2670. {
  2671. FScrollOnDragOver->EndDrag();
  2672. }
  2673. //---------------------------------------------------------------------------
  2674. void __fastcall TLoginDialog::AnonymousLoginCheckClick(TObject * /*Sender*/)
  2675. {
  2676. if (AnonymousLoginCheck->Checked)
  2677. {
  2678. UserNameEdit->Text = AnonymousUserName;
  2679. PasswordEdit->Text = AnonymousPassword;
  2680. }
  2681. UpdateControls();
  2682. }
  2683. //---------------------------------------------------------------------------
  2684. void __fastcall TLoginDialog::SaveButtonDropDownClick(TObject * /*Sender*/)
  2685. {
  2686. MenuPopup(SaveDropDownMenu, SaveButton);
  2687. }
  2688. //---------------------------------------------------------------------------
  2689. void __fastcall TLoginDialog::ExecuteTool(const UnicodeString & Name)
  2690. {
  2691. UnicodeString Path;
  2692. if (!FindTool(Name, Path) ||
  2693. !ExecuteShell(Path, L""))
  2694. {
  2695. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Name)));
  2696. }
  2697. }
  2698. //---------------------------------------------------------------------------
  2699. void __fastcall TLoginDialog::PageantActionExecute(TObject * /*Sender*/)
  2700. {
  2701. ExecuteTool(PageantTool);
  2702. }
  2703. //---------------------------------------------------------------------------
  2704. void __fastcall TLoginDialog::PuttygenActionExecute(TObject * /*Sender*/)
  2705. {
  2706. ExecuteTool(PuttygenTool);
  2707. }
  2708. //---------------------------------------------------------------------------