| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413 | 
							- //---------------------------------------------------------------------------
 
- #include <vcl.h>
 
- #pragma hdrstop
 
- #include "SessionData.h"
 
- #include "Common.h"
 
- #include "Exceptions.h"
 
- #include "FileBuffer.h"
 
- #include "CoreMain.h"
 
- #include "TextsCore.h"
 
- #include "PuttyIntf.h"
 
- #include "RemoteFiles.h"
 
- #include "SFTPFileSystem.h"
 
- #include "S3FileSystem.h"
 
- #include <Soap.EncdDecd.hpp>
 
- #include <StrUtils.hpp>
 
- #include <XMLDoc.hpp>
 
- #include <StrUtils.hpp>
 
- #include <algorithm>
 
- //---------------------------------------------------------------------------
 
- #pragma package(smart_init)
 
- //---------------------------------------------------------------------------
 
- #define SET_SESSION_PROPERTY_FROM(PROPERTY, FROM) \
 
-   if (F##PROPERTY != FROM) { F##PROPERTY = FROM; Modify(); }
 
- //---------------------------------------------------------------------------
 
- #define SET_SESSION_PROPERTY(PROPERTY) \
 
-   SET_SESSION_PROPERTY_FROM(PROPERTY, value)
 
- //---------------------------------------------------------------------------
 
- const wchar_t * PingTypeNames = L"Off;Null;Dummy";
 
- const wchar_t * ProxyMethodNames = L"None;SOCKS4;SOCKS5;HTTP;Telnet;Cmd";
 
- const wchar_t * DefaultName = L"Default Settings";
 
- const UnicodeString CipherNames[CIPHER_COUNT] = {L"WARN", L"3des", L"blowfish", L"aes", L"des", L"arcfour", L"chacha20"};
 
- const UnicodeString KexNames[KEX_COUNT] = {L"WARN", L"dh-group1-sha1", L"dh-group14-sha1", L"dh-gex-sha1", L"rsa", L"ecdh"};
 
- const UnicodeString HostKeyNames[HOSTKEY_COUNT] = {L"WARN", L"rsa", L"dsa", L"ecdsa", L"ed25519"};
 
- const UnicodeString GssLibNames[GSSLIB_COUNT] = {L"gssapi32", L"sspi", L"custom"};
 
- const wchar_t SshProtList[][10] = {L"1", L"1>2", L"2>1", L"2"};
 
- // Update also order in Ssh2CipherList()
 
- const TCipher DefaultCipherList[CIPHER_COUNT] =
 
-   { cipAES, cipChaCha20, cipBlowfish, cip3DES, cipWarn, cipArcfour, cipDES };
 
- // Update also order in SshKexList()
 
- const TKex DefaultKexList[KEX_COUNT] =
 
-   { kexECDH, kexDHGEx, kexDHGroup14, kexRSA, kexWarn, kexDHGroup1 };
 
- const THostKey DefaultHostKeyList[HOSTKEY_COUNT] =
 
-   { hkED25519, hkECDSA, hkRSA, hkDSA, hkWarn };
 
- const TGssLib DefaultGssLibList[GSSLIB_COUNT] =
 
-   { gssGssApi32, gssSspi, gssCustom };
 
- const wchar_t FSProtocolNames[FSPROTOCOL_COUNT][16] = { L"SCP", L"SFTP (SCP)", L"SFTP", L"", L"", L"FTP", L"WebDAV", L"S3" };
 
- const int SshPortNumber = 22;
 
- const int FtpPortNumber = 21;
 
- const int FtpsImplicitPortNumber = 990;
 
- const int HTTPPortNumber = 80;
 
- const int HTTPSPortNumber = 443;
 
- const int TelnetPortNumber = 23;
 
- const int DefaultSendBuf = 262144;
 
- const int ProxyPortNumber = 80;
 
- const UnicodeString AnonymousUserName(L"anonymous");
 
- const UnicodeString AnonymousPassword(L"[email protected]");
 
- const UnicodeString PuttySshProtocol(L"ssh");
 
- const UnicodeString PuttyTelnetProtocol(L"telnet");
 
- const UnicodeString SftpProtocol(L"sftp");
 
- const UnicodeString ScpProtocol(L"scp");
 
- const UnicodeString FtpProtocol(L"ftp");
 
- const UnicodeString FtpsProtocol(L"ftps");
 
- const UnicodeString FtpesProtocol(L"ftpes");
 
- const UnicodeString WebDAVProtocol(L"dav");
 
- const UnicodeString WebDAVSProtocol(L"davs");
 
- const UnicodeString S3Protocol(L"s3");
 
- const UnicodeString SshProtocol(L"ssh");
 
- const UnicodeString WinSCPProtocolPrefix(L"winscp-");
 
- const wchar_t UrlParamSeparator = L';';
 
- const wchar_t UrlParamValueSeparator = L'=';
 
- const UnicodeString UrlHostKeyParamName(L"fingerprint");
 
- const UnicodeString UrlSaveParamName(L"save");
 
- const UnicodeString UrlRawSettingsParamNamePrefix(L"x-");
 
- const UnicodeString PassphraseOption(L"passphrase");
 
- const UnicodeString RawSettingsOption(L"rawsettings");
 
- const UnicodeString S3HostName(S3LibDefaultHostName());
 
- //---------------------------------------------------------------------
 
- TDateTime __fastcall SecToDateTime(int Sec)
 
- {
 
-   return TDateTime(double(Sec) / SecsPerDay);
 
- }
 
- //--- TSessionData ----------------------------------------------------
 
- __fastcall TSessionData::TSessionData(UnicodeString aName):
 
-   TNamedObject(aName)
 
- {
 
-   Default();
 
-   FModified = true;
 
- }
 
- //---------------------------------------------------------------------
 
- _fastcall TSessionData::~TSessionData()
 
- {
 
- }
 
- //---------------------------------------------------------------------
 
- int __fastcall TSessionData::Compare(TNamedObject * Other)
 
- {
 
-   int Result;
 
-   // To avoid using CompareLogicalText on hex names of sessions in workspace.
 
-   // The session 000A would be sorted before 0001.
 
-   if (IsWorkspace && DebugNotNull(dynamic_cast<TSessionData *>(Other))->IsWorkspace)
 
-   {
 
-     Result = CompareText(Name, Other->Name);
 
-   }
 
-   else
 
-   {
 
-     Result = TNamedObject::Compare(Other);
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- TSessionData * __fastcall TSessionData::Clone()
 
- {
 
-   std::unique_ptr<TSessionData> Data(new TSessionData(L""));
 
-   Data->Assign(this);
 
-   return Data.release();
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::DefaultSettings()
 
- {
 
-   HostName = L"";
 
-   PortNumber = SshPortNumber;
 
-   UserName = L"";
 
-   Password = L"";
 
-   NewPassword = L"";
 
-   ChangePassword = false;
 
-   PingInterval = 30;
 
-   PingType = ptOff;
 
-   Timeout = 15;
 
-   TryAgent = true;
 
-   AgentFwd = false;
 
-   AuthTIS = false;
 
-   AuthKI = true;
 
-   AuthKIPassword = true;
 
-   AuthGSSAPI = true;
 
-   AuthGSSAPIKEX = false;
 
-   GSSAPIFwdTGT = false;
 
-   LogicalHostName = L"";
 
-   ChangeUsername = false;
 
-   Compression = false;
 
-   SshProt = ssh2only;
 
-   Ssh2DES = false;
 
-   SshNoUserAuth = false;
 
-   for (int Index = 0; Index < CIPHER_COUNT; Index++)
 
-   {
 
-     Cipher[Index] = DefaultCipherList[Index];
 
-   }
 
-   for (int Index = 0; Index < KEX_COUNT; Index++)
 
-   {
 
-     Kex[Index] = DefaultKexList[Index];
 
-   }
 
-   for (int Index = 0; Index < HOSTKEY_COUNT; Index++)
 
-   {
 
-     HostKeys[Index] = DefaultHostKeyList[Index];
 
-   }
 
-   for (int Index = 0; Index < GSSLIB_COUNT; Index++)
 
-   {
 
-     GssLib[Index] = DefaultGssLibList[Index];
 
-   }
 
-   GssLibCustom = L"";
 
-   PublicKeyFile = L"";
 
-   Passphrase = L"";
 
-   FPuttyProtocol = L"";
 
-   TcpNoDelay = false;
 
-   SendBuf = DefaultSendBuf;
 
-   SourceAddress = L"";
 
-   ProtocolFeatures = L"";
 
-   SshSimple = true;
 
-   HostKey = L"";
 
-   FingerprintScan = false;
 
-   FOverrideCachedHostKey = true;
 
-   Note = L"";
 
-   WinTitle = L"";
 
-   InternalEditorEncoding = -1;
 
-   EncryptKey = UnicodeString();
 
-   WebDavLiberalEscaping = false;
 
-   ProxyMethod = ::pmNone;
 
-   ProxyHost = L"proxy";
 
-   ProxyPort = ProxyPortNumber;
 
-   ProxyUsername = L"";
 
-   ProxyPassword = L"";
 
-   ProxyTelnetCommand = L"connect %host %port\\n";
 
-   ProxyLocalCommand = L"";
 
-   ProxyDNS = asAuto;
 
-   ProxyLocalhost = false;
 
-   for (unsigned int Index = 0; Index < LENOF(FBugs); Index++)
 
-   {
 
-     Bug[(TSshBug)Index] = asAuto;
 
-   }
 
-   Special = false;
 
-   FSProtocol = fsSFTP;
 
-   AddressFamily = afAuto;
 
-   RekeyData = L"1G";
 
-   RekeyTime = MinsPerHour;
 
-   // FS common
 
-   LocalDirectory = L"";
 
-   RemoteDirectory = L"";
 
-   SynchronizeBrowsing = false;
 
-   UpdateDirectories = true;
 
-   CacheDirectories = true;
 
-   CacheDirectoryChanges = true;
 
-   PreserveDirectoryChanges = true;
 
-   LockInHome = false;
 
-   ResolveSymlinks = true;
 
-   FollowDirectorySymlinks = false;
 
-   DSTMode = dstmUnix;
 
-   DeleteToRecycleBin = false;
 
-   OverwrittenToRecycleBin = false;
 
-   RecycleBinPath = L"";
 
-   Color = 0;
 
-   PostLoginCommands = L"";
 
-   // SCP
 
-   LookupUserGroups = asAuto;
 
-   EOLType = eolLF;
 
-   TrimVMSVersions = false;
 
-   Shell = L""; //default shell
 
-   ReturnVar = L"";
 
-   ExitCode1IsError = false;
 
-   ClearAliases = true;
 
-   UnsetNationalVars = true;
 
-   ListingCommand = L"ls -la";
 
-   IgnoreLsWarnings = true;
 
-   Scp1Compatibility = false;
 
-   TimeDifference = 0;
 
-   TimeDifferenceAuto = true;
 
-   SCPLsFullTime = asAuto;
 
-   NotUtf = asAuto;
 
-   S3DefaultRegion = L"";
 
-   S3SessionToken = L"";
 
-   S3UrlStyle = s3usVirtualHost;
 
-   S3MaxKeys = asAuto;
 
-   // SFTP
 
-   SftpServer = L"";
 
-   SFTPDownloadQueue = 32;
 
-   SFTPUploadQueue = 32;
 
-   SFTPListingQueue = 2;
 
-   SFTPMaxVersion = ::SFTPMaxVersion;
 
-   SFTPMaxPacketSize = 0;
 
-   SFTPRealPath = asAuto;
 
-   for (unsigned int Index = 0; Index < LENOF(FSFTPBugs); Index++)
 
-   {
 
-     SFTPBug[(TSftpBug)Index] = asAuto;
 
-   }
 
-   Tunnel = false;
 
-   TunnelHostName = L"";
 
-   TunnelPortNumber = SshPortNumber;
 
-   TunnelUserName = L"";
 
-   TunnelPassword = L"";
 
-   TunnelPublicKeyFile = L"";
 
-   TunnelLocalPortNumber = 0;
 
-   TunnelPortFwd = L"";
 
-   TunnelHostKey = L"";
 
-   // FTP
 
-   FtpPasvMode = true;
 
-   FtpForcePasvIp = asAuto;
 
-   FtpUseMlsd = asAuto;
 
-   FtpAccount = L"";
 
-   FtpPingInterval = 30;
 
-   FtpPingType = ptDummyCommand;
 
-   FtpTransferActiveImmediately = asAuto;
 
-   Ftps = ftpsNone;
 
-   MinTlsVersion = tls10;
 
-   MaxTlsVersion = tls13;
 
-   FtpListAll = asAuto;
 
-   FtpHost = asAuto;
 
-   FtpWorkFromCwd = asAuto;
 
-   SslSessionReuse = true;
 
-   TlsCertificateFile = L"";
 
-   FtpProxyLogonType = 0; // none
 
-   PuttySettings = UnicodeString();
 
-   CustomParam1 = L"";
 
-   CustomParam2 = L"";
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Default()
 
- {
 
-   DefaultSettings();
 
-   IsWorkspace = false;
 
-   Link = L"";
 
-   NameOverride = L"";
 
-   Selected = false;
 
-   FModified = false;
 
-   FSource = ::ssNone;
 
-   FSaveOnly = false;
 
-   // add also to TSessionLog::AddStartupInfo()
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::NonPersistant()
 
- {
 
-   UpdateDirectories = false;
 
-   PreserveDirectoryChanges = false;
 
- }
 
- //---------------------------------------------------------------------
 
- #define PROPERTY(P) PROPERTY_HANDLER(P, )
 
- #define BASE_PROPERTIES \
 
-   PROPERTY(HostName); \
 
-   PROPERTY(PortNumber); \
 
-   PROPERTY(UserName); \
 
-   PROPERTY_HANDLER(Password, F); \
 
-   PROPERTY(PublicKeyFile); \
 
-   PROPERTY_HANDLER(Passphrase, F); \
 
-   PROPERTY(FSProtocol); \
 
-   PROPERTY(Ftps); \
 
-   PROPERTY(LocalDirectory); \
 
-   PROPERTY(RemoteDirectory); \
 
-   PROPERTY(Color); \
 
-   PROPERTY(SynchronizeBrowsing); \
 
-   PROPERTY(Note);
 
- //---------------------------------------------------------------------
 
- #define ADVANCED_PROPERTIES \
 
-   PROPERTY_HANDLER(NewPassword, F); \
 
-   PROPERTY(ChangePassword); \
 
-   PROPERTY(PingInterval); \
 
-   PROPERTY(PingType); \
 
-   PROPERTY(Timeout); \
 
-   PROPERTY(TryAgent); \
 
-   PROPERTY(AgentFwd); \
 
-   PROPERTY(AuthTIS); \
 
-   PROPERTY(LogicalHostName); \
 
-   PROPERTY(ChangeUsername); \
 
-   PROPERTY(Compression); \
 
-   PROPERTY(SshProt); \
 
-   PROPERTY(Ssh2DES); \
 
-   PROPERTY(SshNoUserAuth); \
 
-   PROPERTY(CipherList); \
 
-   PROPERTY(KexList); \
 
-   PROPERTY(HostKeyList); \
 
-   PROPERTY(GssLibList); \
 
-   PROPERTY(GssLibCustom); \
 
-   PROPERTY(AddressFamily); \
 
-   PROPERTY(RekeyData); \
 
-   PROPERTY(RekeyTime); \
 
-   PROPERTY(HostKey); \
 
-   PROPERTY(FingerprintScan); \
 
-   PROPERTY(InternalEditorEncoding); \
 
-   \
 
-   PROPERTY(UpdateDirectories); \
 
-   PROPERTY(CacheDirectories); \
 
-   PROPERTY(CacheDirectoryChanges); \
 
-   PROPERTY(PreserveDirectoryChanges); \
 
-   \
 
-   PROPERTY(ResolveSymlinks); \
 
-   PROPERTY(FollowDirectorySymlinks); \
 
-   PROPERTY(DSTMode); \
 
-   PROPERTY(LockInHome); \
 
-   PROPERTY(Special); \
 
-   PROPERTY(Selected); \
 
-   PROPERTY(ReturnVar); \
 
-   PROPERTY(ExitCode1IsError); \
 
-   PROPERTY(LookupUserGroups); \
 
-   PROPERTY(EOLType); \
 
-   PROPERTY(TrimVMSVersions); \
 
-   PROPERTY(Shell); \
 
-   PROPERTY(ClearAliases); \
 
-   PROPERTY(Scp1Compatibility); \
 
-   PROPERTY(UnsetNationalVars); \
 
-   PROPERTY(ListingCommand); \
 
-   PROPERTY(IgnoreLsWarnings); \
 
-   PROPERTY(SCPLsFullTime); \
 
-   \
 
-   PROPERTY(TimeDifference); \
 
-   PROPERTY(TimeDifferenceAuto); \
 
-   PROPERTY(TcpNoDelay); \
 
-   PROPERTY(SendBuf); \
 
-   PROPERTY(SourceAddress); \
 
-   PROPERTY(ProtocolFeatures); \
 
-   PROPERTY(SshSimple); \
 
-   PROPERTY(AuthKI); \
 
-   PROPERTY(AuthKIPassword); \
 
-   PROPERTY(AuthGSSAPI); \
 
-   PROPERTY(AuthGSSAPIKEX); \
 
-   PROPERTY(GSSAPIFwdTGT); \
 
-   PROPERTY(DeleteToRecycleBin); \
 
-   PROPERTY(OverwrittenToRecycleBin); \
 
-   PROPERTY(RecycleBinPath); \
 
-   PROPERTY(NotUtf); \
 
-   PROPERTY(PostLoginCommands); \
 
-   \
 
-   PROPERTY(S3DefaultRegion); \
 
-   PROPERTY(S3SessionToken); \
 
-   PROPERTY(S3UrlStyle); \
 
-   PROPERTY(S3MaxKeys); \
 
-   \
 
-   PROPERTY(ProxyMethod); \
 
-   PROPERTY(ProxyHost); \
 
-   PROPERTY(ProxyPort); \
 
-   PROPERTY(ProxyUsername); \
 
-   PROPERTY_HANDLER(ProxyPassword, F); \
 
-   PROPERTY(ProxyTelnetCommand); \
 
-   PROPERTY(ProxyLocalCommand); \
 
-   PROPERTY(ProxyDNS); \
 
-   PROPERTY(ProxyLocalhost); \
 
-   \
 
-   for (unsigned int Index = 0; Index < LENOF(FBugs); Index++) \
 
-   { \
 
-     PROPERTY(Bug[(TSshBug)Index]); \
 
-   } \
 
-   \
 
-   PROPERTY(SftpServer); \
 
-   PROPERTY(SFTPDownloadQueue); \
 
-   PROPERTY(SFTPUploadQueue); \
 
-   PROPERTY(SFTPListingQueue); \
 
-   PROPERTY(SFTPMaxVersion); \
 
-   PROPERTY(SFTPMaxPacketSize); \
 
-   PROPERTY(SFTPRealPath); \
 
-   \
 
-   for (unsigned int Index = 0; Index < LENOF(FSFTPBugs); Index++) \
 
-   { \
 
-     PROPERTY(SFTPBug[(TSftpBug)Index]); \
 
-   } \
 
-   \
 
-   PROPERTY(Tunnel); \
 
-   PROPERTY(TunnelHostName); \
 
-   PROPERTY(TunnelPortNumber); \
 
-   PROPERTY(TunnelUserName); \
 
-   PROPERTY_HANDLER(TunnelPassword, F); \
 
-   PROPERTY(TunnelPublicKeyFile); \
 
-   PROPERTY(TunnelLocalPortNumber); \
 
-   PROPERTY(TunnelPortFwd); \
 
-   PROPERTY(TunnelHostKey); \
 
-   \
 
-   PROPERTY(FtpPasvMode); \
 
-   PROPERTY(FtpForcePasvIp); \
 
-   PROPERTY(FtpUseMlsd); \
 
-   PROPERTY(FtpAccount); \
 
-   PROPERTY(FtpPingInterval); \
 
-   PROPERTY(FtpPingType); \
 
-   PROPERTY(FtpTransferActiveImmediately); \
 
-   PROPERTY(FtpListAll); \
 
-   PROPERTY(FtpHost); \
 
-   PROPERTY(FtpWorkFromCwd); \
 
-   PROPERTY(SslSessionReuse); \
 
-   PROPERTY(TlsCertificateFile); \
 
-   \
 
-   PROPERTY(FtpProxyLogonType); \
 
-   \
 
-   PROPERTY(MinTlsVersion); \
 
-   PROPERTY(MaxTlsVersion); \
 
-   \
 
-   PROPERTY(WinTitle); \
 
-   \
 
-   PROPERTY_HANDLER(EncryptKey, F); \
 
-   \
 
-   PROPERTY(WebDavLiberalEscaping); \
 
-   \
 
-   PROPERTY(PuttySettings); \
 
-   \
 
-   PROPERTY(CustomParam1); \
 
-   PROPERTY(CustomParam2);
 
- #define META_PROPERTIES \
 
-   PROPERTY(IsWorkspace); \
 
-   PROPERTY(Link); \
 
-   PROPERTY(NameOverride);
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Assign(TPersistent * Source)
 
- {
 
-   if (Source && Source->InheritsFrom(__classid(TSessionData)))
 
-   {
 
-     TSessionData * SourceData = (TSessionData *)Source;
 
-     // Master password prompt shows implicitly here, when cloning the session data for a new terminal
 
-     CopyData(SourceData);
 
-     FSource = SourceData->FSource;
 
-   }
 
-   else
 
-   {
 
-     TNamedObject::Assign(Source);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::DoCopyData(TSessionData * SourceData, bool NoRecrypt)
 
- {
 
-   #define PROPERTY_HANDLER(P, F) \
 
-     if (NoRecrypt) \
 
-     { \
 
-       F##P = SourceData->F##P; \
 
-     } \
 
-     else \
 
-     { \
 
-       P = SourceData->P; \
 
-     }
 
-   PROPERTY(Name);
 
-   BASE_PROPERTIES;
 
-   ADVANCED_PROPERTIES;
 
-   META_PROPERTIES;
 
-   #undef PROPERTY_HANDLER
 
-   FOverrideCachedHostKey = SourceData->FOverrideCachedHostKey;
 
-   FModified = SourceData->Modified;
 
-   FSaveOnly = SourceData->FSaveOnly;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CopyData(TSessionData * SourceData)
 
- {
 
-   DoCopyData(SourceData, false);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CopyDataNoRecrypt(TSessionData * SourceData)
 
- {
 
-   DoCopyData(SourceData, true);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CopyDirectoriesStateData(TSessionData * SourceData)
 
- {
 
-   RemoteDirectory = SourceData->RemoteDirectory;
 
-   LocalDirectory = SourceData->LocalDirectory;
 
-   SynchronizeBrowsing = SourceData->SynchronizeBrowsing;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasStateData()
 
- {
 
-   return
 
-     !RemoteDirectory.IsEmpty() ||
 
-     !LocalDirectory.IsEmpty() ||
 
-     (Color != 0);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CopyStateData(TSessionData * SourceData)
 
- {
 
-   // Keep in sync with TCustomScpExplorerForm::UpdateSessionData.
 
-   CopyDirectoriesStateData(SourceData);
 
-   Color = SourceData->Color;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CopyNonCoreData(TSessionData * SourceData)
 
- {
 
-   CopyStateData(SourceData);
 
-   UpdateDirectories = SourceData->UpdateDirectories;
 
-   Note = SourceData->Note;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSame(
 
-   const TSessionData * Default, bool AdvancedOnly, TStrings * DifferentProperties, bool Decrypted)
 
- {
 
-   bool Result = true;
 
-   #define PROPERTY_HANDLER(P, F) \
 
-     if ((Decrypted && (P != Default->P)) || \
 
-         (!Decrypted && (F##P != Default->F##P))) \
 
-     { \
 
-       Result = false; \
 
-       if (DifferentProperties != NULL) \
 
-       { \
 
-         DifferentProperties->Add(#P); \
 
-       } \
 
-       else \
 
-       { \
 
-         return Result; \
 
-       } \
 
-     }
 
-   if (!AdvancedOnly)
 
-   {
 
-     BASE_PROPERTIES;
 
-     META_PROPERTIES;
 
-   }
 
-   ADVANCED_PROPERTIES;
 
-   #undef PROPERTY_HANDLER
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSame(const TSessionData * Default, bool AdvancedOnly)
 
- {
 
-   return IsSame(Default, AdvancedOnly, NULL, false);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSameDecrypted(const TSessionData * Default)
 
- {
 
-   return IsSame(Default, false, NULL, true);
 
- }
 
- //---------------------------------------------------------------------
 
- TFSProtocol NormalizeFSProtocol(TFSProtocol FSProtocol)
 
- {
 
-   if (FSProtocol == fsSFTPonly)
 
-   {
 
-     FSProtocol = fsSFTP;
 
-   }
 
-   return FSProtocol;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSameSite(const TSessionData * Other)
 
- {
 
-   return
 
-     // Particularly when handling /refresh,
 
-     // fsSFTPonly sites when compared against sftp:// URLs (fsSFTP) have to match.
 
-     // But similarly also falled back SCP sites.
 
-     (NormalizeFSProtocol(FSProtocol) == NormalizeFSProtocol(Other->FSProtocol)) &&
 
-     (HostName == Other->HostName) &&
 
-     (PortNumber == Other->PortNumber) &&
 
-     (UserName == Other->UserName);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsInFolderOrWorkspace(UnicodeString AFolder)
 
- {
 
-   return StartsText(UnixIncludeTrailingBackslash(AFolder), Name);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyImport, bool & RewritePassword, bool Unsafe)
 
- {
 
-   // Make sure we only ever use methods supported by TOptionsStorage
 
-   // (implemented by TOptionsIniFile)
 
-   PortNumber = Storage->ReadInteger(L"PortNumber", PortNumber);
 
-   UserName = Storage->ReadString(L"UserName", UserName);
 
-   // must be loaded after UserName, because HostName may be in format user@host
 
-   HostName = Storage->ReadString(L"HostName", HostName);
 
-   if (!Configuration->DisablePasswordStoring)
 
-   {
 
-     if (Storage->ValueExists(L"PasswordPlain"))
 
-     {
 
-       Password = Storage->ReadString(L"PasswordPlain", Password);
 
-       RewritePassword = true;
 
-     }
 
-     else
 
-     {
 
-       RawByteString APassword = Storage->ReadStringAsBinaryData(L"Password", FPassword);
 
-       SET_SESSION_PROPERTY_FROM(Password, APassword);
 
-     }
 
-   }
 
-   HostKey = Storage->ReadString(L"SshHostKey", HostKey); // probably never used
 
-   Note = Storage->ReadString(L"Note", Note);
 
-   // Putty uses PingIntervalSecs
 
-   int PingIntervalSecs = Storage->ReadInteger(L"PingIntervalSecs", -1);
 
-   if (PingIntervalSecs < 0)
 
-   {
 
-     PingIntervalSecs = Storage->ReadInteger(L"PingIntervalSec", PingInterval%SecsPerMin);
 
-   }
 
-   PingInterval =
 
-     Storage->ReadInteger(L"PingInterval", PingInterval/SecsPerMin)*SecsPerMin +
 
-     PingIntervalSecs;
 
-   if (PingInterval == 0)
 
-   {
 
-     PingInterval = 30;
 
-   }
 
-   PingType = static_cast<TPingType>(Storage->ReadInteger(L"PingType", PingType));
 
-   Timeout = Storage->ReadInteger(L"Timeout", Timeout);
 
-   TryAgent = Storage->ReadBool(L"TryAgent", TryAgent);
 
-   AgentFwd = Storage->ReadBool(L"AgentFwd", AgentFwd);
 
-   AuthTIS = Storage->ReadBool(L"AuthTIS", AuthTIS);
 
-   AuthKI = Storage->ReadBool(L"AuthKI", AuthKI);
 
-   AuthKIPassword = Storage->ReadBool(L"AuthKIPassword", AuthKIPassword);
 
-   // Continue to use setting keys of previous kerberos implementation (vaclav tomec),
 
-   // but fallback to keys of other implementations (official putty and vintela quest putty),
 
-   // to allow imports from all putty versions.
 
-   // Both vaclav tomec and official putty use AuthGSSAPI
 
-   AuthGSSAPI = Storage->ReadBool(L"AuthGSSAPI", Storage->ReadBool(L"AuthSSPI", AuthGSSAPI));
 
-   AuthGSSAPIKEX = Storage->ReadBool(L"AuthGSSAPIKEX", AuthGSSAPIKEX);
 
-   GSSAPIFwdTGT = Storage->ReadBool(L"GSSAPIFwdTGT", Storage->ReadBool(L"GssapiFwd", Storage->ReadBool(L"SSPIFwdTGT", GSSAPIFwdTGT)));
 
-   // KerbPrincipal was used by Quest PuTTY
 
-   // GSSAPIServerRealm was used by Vaclav Tomec
 
-   LogicalHostName = Storage->ReadString(L"LogicalHostName", Storage->ReadString(L"GSSAPIServerRealm", Storage->ReadString(L"KerbPrincipal", LogicalHostName)));
 
-   ChangeUsername = Storage->ReadBool(L"ChangeUsername", ChangeUsername);
 
-   Compression = Storage->ReadBool(L"Compression", Compression);
 
-   TSshProt ASshProt = (TSshProt)Storage->ReadInteger(L"SshProt", SshProt);
 
-   // Old sessions may contain the values correponding to the fallbacks we used to allow; migrate them
 
-   if (ASshProt == ssh2deprecated)
 
-   {
 
-     ASshProt = ssh2only;
 
-   }
 
-   else if (ASshProt == ssh1deprecated)
 
-   {
 
-     ASshProt = ssh1only;
 
-   }
 
-   SshProt = ASshProt;
 
-   Ssh2DES = Storage->ReadBool(L"Ssh2DES", Ssh2DES);
 
-   SshNoUserAuth = Storage->ReadBool(L"SshNoUserAuth", SshNoUserAuth);
 
-   CipherList = Storage->ReadString(L"Cipher", CipherList);
 
-   KexList = Storage->ReadString(L"KEX", KexList);
 
-   HostKeyList = Storage->ReadString(L"HostKey", HostKeyList);
 
-   if (!Unsafe)
 
-   {
 
-     GssLibList = Storage->ReadString(L"GSSLibs", GssLibList);
 
-   }
 
-   GssLibCustom = Storage->ReadString(L"GSSCustom", GssLibCustom);
 
-   PublicKeyFile = Storage->ReadString(L"PublicKeyFile", PublicKeyFile);
 
-   AddressFamily = static_cast<TAddressFamily>
 
-     (Storage->ReadInteger(L"AddressFamily", AddressFamily));
 
-   RekeyData = Storage->ReadString(L"RekeyBytes", RekeyData);
 
-   RekeyTime = Storage->ReadInteger(L"RekeyTime", RekeyTime);
 
-   FSProtocol = (TFSProtocol)Storage->ReadInteger(L"FSProtocol", FSProtocol);
 
-   LocalDirectory = Storage->ReadString(L"LocalDirectory", LocalDirectory);
 
-   RemoteDirectory = Storage->ReadString(L"RemoteDirectory", RemoteDirectory);
 
-   SynchronizeBrowsing = Storage->ReadBool(L"SynchronizeBrowsing", SynchronizeBrowsing);
 
-   UpdateDirectories = Storage->ReadBool(L"UpdateDirectories", UpdateDirectories);
 
-   CacheDirectories = Storage->ReadBool(L"CacheDirectories", CacheDirectories);
 
-   CacheDirectoryChanges = Storage->ReadBool(L"CacheDirectoryChanges", CacheDirectoryChanges);
 
-   PreserveDirectoryChanges = Storage->ReadBool(L"PreserveDirectoryChanges", PreserveDirectoryChanges);
 
-   ResolveSymlinks = Storage->ReadBool(L"ResolveSymlinks", ResolveSymlinks);
 
-   FollowDirectorySymlinks = Storage->ReadBool(L"FollowDirectorySymlinks", FollowDirectorySymlinks);
 
-   DSTMode = (TDSTMode)Storage->ReadInteger(L"ConsiderDST", DSTMode);
 
-   LockInHome = Storage->ReadBool(L"LockInHome", LockInHome);
 
-   Special = Storage->ReadBool(L"Special", Special);
 
-   if (!Unsafe)
 
-   {
 
-     Shell = Storage->ReadString(L"Shell", Shell);
 
-   }
 
-   ClearAliases = Storage->ReadBool(L"ClearAliases", ClearAliases);
 
-   UnsetNationalVars = Storage->ReadBool(L"UnsetNationalVars", UnsetNationalVars);
 
-   if (!Unsafe)
 
-   {
 
-     ListingCommand = Storage->ReadString(L"ListingCommand",
 
-       Storage->ReadBool(L"AliasGroupList", false) ? UnicodeString(L"ls -gla") : ListingCommand);
 
-   }
 
-   IgnoreLsWarnings = Storage->ReadBool(L"IgnoreLsWarnings", IgnoreLsWarnings);
 
-   SCPLsFullTime = Storage->ReadEnum(L"SCPLsFullTime", SCPLsFullTime, AutoSwitchMapping);
 
-   Scp1Compatibility = Storage->ReadBool(L"Scp1Compatibility", Scp1Compatibility);
 
-   TimeDifference = Storage->ReadFloat(L"TimeDifference", TimeDifference);
 
-   TimeDifferenceAuto = Storage->ReadBool(L"TimeDifferenceAuto", (TimeDifference == TDateTime()));
 
-   if (!Unsafe)
 
-   {
 
-     DeleteToRecycleBin = Storage->ReadBool(L"DeleteToRecycleBin", DeleteToRecycleBin);
 
-     OverwrittenToRecycleBin = Storage->ReadBool(L"OverwrittenToRecycleBin", OverwrittenToRecycleBin);
 
-     RecycleBinPath = Storage->ReadString(L"RecycleBinPath", RecycleBinPath);
 
-     PostLoginCommands = Storage->ReadString(L"PostLoginCommands", PostLoginCommands);
 
-     ReturnVar = Storage->ReadString(L"ReturnVar", ReturnVar);
 
-   }
 
-   ExitCode1IsError = Storage->ReadBool(L"ExitCode1IsError", ExitCode1IsError);
 
-   LookupUserGroups = Storage->ReadEnum(L"LookupUserGroups2", LookupUserGroups, AutoSwitchMapping);
 
-   EOLType = (TEOLType)Storage->ReadInteger(L"EOLType", EOLType);
 
-   TrimVMSVersions = Storage->ReadBool(L"TrimVMSVersions", TrimVMSVersions);
 
-   NotUtf = Storage->ReadEnum(L"Utf", Storage->ReadEnum(L"SFTPUtfBug", NotUtf), AutoSwitchReversedMapping);
 
-   InternalEditorEncoding = Storage->ReadInteger(L"InternalEditorEncoding", InternalEditorEncoding);
 
-   S3DefaultRegion = Storage->ReadString(L"S3DefaultRegion", S3DefaultRegion);
 
-   S3SessionToken = Storage->ReadString(L"S3SessionToken", S3SessionToken);
 
-   S3UrlStyle = (TS3UrlStyle)Storage->ReadInteger(L"S3UrlStyle", S3UrlStyle);
 
-   S3MaxKeys = Storage->ReadEnum(L"S3MaxKeys", S3MaxKeys, AutoSwitchMapping);
 
-   // PuTTY defaults to TcpNoDelay, but the psftp/pscp ignores this preference, and always set this to off (what is our default too)
 
-   if (!PuttyImport)
 
-   {
 
-     TcpNoDelay = Storage->ReadBool(L"TcpNoDelay", TcpNoDelay);
 
-   }
 
-   SendBuf = Storage->ReadInteger(L"SendBuf", Storage->ReadInteger("SshSendBuf", SendBuf));
 
-   SourceAddress = Storage->ReadString(L"SourceAddress", SourceAddress);
 
-   ProtocolFeatures = Storage->ReadString(L"ProtocolFeatures", ProtocolFeatures);
 
-   SshSimple = Storage->ReadBool(L"SshSimple", SshSimple);
 
-   ProxyMethod = (TProxyMethod)Storage->ReadInteger(L"ProxyMethod", ProxyMethod);
 
-   ProxyHost = Storage->ReadString(L"ProxyHost", ProxyHost);
 
-   ProxyPort = Storage->ReadInteger(L"ProxyPort", ProxyPort);
 
-   ProxyUsername = Storage->ReadString(L"ProxyUsername", ProxyUsername);
 
-   if (Storage->ValueExists(L"ProxyPassword"))
 
-   {
 
-     // encrypt unencrypted password
 
-     ProxyPassword = Storage->ReadString(L"ProxyPassword", L"");
 
-   }
 
-   else
 
-   {
 
-     // load encrypted password
 
-     RawByteString AProxyPassword = Storage->ReadStringAsBinaryData(L"ProxyPasswordEnc", FProxyPassword);
 
-     SET_SESSION_PROPERTY_FROM(ProxyPassword, AProxyPassword);
 
-   }
 
-   if (!Unsafe)
 
-   {
 
-     if (ProxyMethod == pmCmd)
 
-     {
 
-       ProxyLocalCommand = Storage->ReadStringRaw(L"ProxyTelnetCommand", ProxyLocalCommand);
 
-     }
 
-     else
 
-     {
 
-       ProxyTelnetCommand = Storage->ReadStringRaw(L"ProxyTelnetCommand", ProxyTelnetCommand);
 
-     }
 
-   }
 
-   ProxyDNS = TAutoSwitch((Storage->ReadInteger(L"ProxyDNS", (ProxyDNS + 2) % 3) + 1) % 3);
 
-   ProxyLocalhost = Storage->ReadBool(L"ProxyLocalhost", ProxyLocalhost);
 
-   #define READ_BUG(BUG) \
 
-     Bug[sb##BUG] = TAutoSwitch(2 - Storage->ReadInteger(L"Bug"#BUG, \
 
-       2 - Bug[sb##BUG]));
 
-   READ_BUG(Ignore1);
 
-   READ_BUG(PlainPW1);
 
-   READ_BUG(RSA1);
 
-   READ_BUG(HMAC2);
 
-   READ_BUG(DeriveKey2);
 
-   READ_BUG(RSAPad2);
 
-   READ_BUG(PKSessID2);
 
-   READ_BUG(Rekey2);
 
-   READ_BUG(MaxPkt2);
 
-   READ_BUG(Ignore2);
 
-   READ_BUG(OldGex2);
 
-   READ_BUG(WinAdj);
 
-   READ_BUG(ChanReq);
 
-   #undef READ_BUG
 
-   if ((Bug[sbHMAC2] == asAuto) &&
 
-       Storage->ReadBool(L"BuggyMAC", false))
 
-   {
 
-       Bug[sbHMAC2] = asOn;
 
-   }
 
-   if (!Unsafe)
 
-   {
 
-     SftpServer = Storage->ReadString(L"SftpServer", SftpServer);
 
-   }
 
-   #define READ_SFTP_BUG(BUG) \
 
-     SFTPBug[sb##BUG] = Storage->ReadEnum(L"SFTP" #BUG "Bug", SFTPBug[sb##BUG], AutoSwitchMapping);
 
-   READ_SFTP_BUG(Symlink);
 
-   READ_SFTP_BUG(SignedTS);
 
-   #undef READ_SFTP_BUG
 
-   SFTPMaxVersion = Storage->ReadInteger(L"SFTPMaxVersion", SFTPMaxVersion);
 
-   SFTPMaxPacketSize = Storage->ReadInteger(L"SFTPMaxPacketSize", SFTPMaxPacketSize);
 
-   SFTPDownloadQueue = Storage->ReadInteger(L"SFTPDownloadQueue", SFTPDownloadQueue);
 
-   SFTPUploadQueue = Storage->ReadInteger(L"SFTPUploadQueue", SFTPUploadQueue);
 
-   SFTPListingQueue = Storage->ReadInteger(L"SFTPListingQueue", SFTPListingQueue);
 
-   SFTPRealPath = Storage->ReadEnum(L"SFTPRealPath", SFTPRealPath, AutoSwitchMapping);
 
-   Color = Storage->ReadInteger(L"Color", Color);
 
-   PuttyProtocol = Storage->ReadString(L"Protocol", PuttyProtocol);
 
-   Tunnel = Storage->ReadBool(L"Tunnel", Tunnel);
 
-   TunnelPortNumber = Storage->ReadInteger(L"TunnelPortNumber", TunnelPortNumber);
 
-   TunnelUserName = Storage->ReadString(L"TunnelUserName", TunnelUserName);
 
-   // must be loaded after TunnelUserName,
 
-   // because TunnelHostName may be in format user@host
 
-   TunnelHostName = Storage->ReadString(L"TunnelHostName", TunnelHostName);
 
-   if (!Configuration->DisablePasswordStoring)
 
-   {
 
-     if (Storage->ValueExists(L"TunnelPasswordPlain"))
 
-     {
 
-       TunnelPassword = Storage->ReadString(L"TunnelPasswordPlain", TunnelPassword);
 
-       RewritePassword = true;
 
-     }
 
-     else
 
-     {
 
-       RawByteString ATunnelPassword = Storage->ReadStringAsBinaryData(L"TunnelPassword", FTunnelPassword);
 
-       SET_SESSION_PROPERTY_FROM(TunnelPassword, ATunnelPassword);
 
-     }
 
-   }
 
-   TunnelPublicKeyFile = Storage->ReadString(L"TunnelPublicKeyFile", TunnelPublicKeyFile);
 
-   TunnelLocalPortNumber = Storage->ReadInteger(L"TunnelLocalPortNumber", TunnelLocalPortNumber);
 
-   TunnelHostKey = Storage->ReadString(L"TunnelHostKey", TunnelHostKey);
 
-   // Ftp prefix
 
-   FtpPasvMode = Storage->ReadBool(L"FtpPasvMode", FtpPasvMode);
 
-   FtpForcePasvIp = Storage->ReadEnum(L"FtpForcePasvIp2", FtpForcePasvIp, AutoSwitchMapping);
 
-   FtpUseMlsd = Storage->ReadEnum(L"FtpUseMlsd", FtpUseMlsd, AutoSwitchMapping);
 
-   FtpAccount = Storage->ReadString(L"FtpAccount", FtpAccount);
 
-   FtpPingInterval = Storage->ReadInteger(L"FtpPingInterval", FtpPingInterval);
 
-   FtpPingType = static_cast<TPingType>(Storage->ReadInteger(L"FtpPingType", FtpPingType));
 
-   FtpTransferActiveImmediately = Storage->ReadEnum(L"FtpTransferActiveImmediately2", FtpTransferActiveImmediately, AutoSwitchMapping);
 
-   Ftps = static_cast<TFtps>(Storage->ReadInteger(L"Ftps", Ftps));
 
-   FtpListAll = Storage->ReadEnum(L"FtpListAll", FtpListAll, AutoSwitchMapping);
 
-   FtpHost = Storage->ReadEnum(L"FtpHost", FtpHost, AutoSwitchMapping);
 
-   FtpWorkFromCwd = Storage->ReadEnum(L"FtpWorkFromCwd", Storage->ReadEnum(L"FtpDeleteFromCwd", FtpWorkFromCwd), AutoSwitchMapping);
 
-   SslSessionReuse = Storage->ReadBool(L"SslSessionReuse", SslSessionReuse);
 
-   TlsCertificateFile = Storage->ReadString(L"TlsCertificateFile", TlsCertificateFile);
 
-   FtpProxyLogonType = Storage->ReadInteger(L"FtpProxyLogonType", FtpProxyLogonType);
 
-   MinTlsVersion = static_cast<TTlsVersion>(Storage->ReadInteger(L"MinTlsVersion", MinTlsVersion));
 
-   MaxTlsVersion = static_cast<TTlsVersion>(Storage->ReadInteger(L"MaxTlsVersion", MaxTlsVersion));
 
-   if (Storage->ValueExists(L"EncryptKeyPlain"))
 
-   {
 
-     EncryptKey = Storage->ReadString(L"EncryptKeyPlain", EncryptKey);
 
-     RewritePassword = true;
 
-   }
 
-   else
 
-   {
 
-     RawByteString AEncryptKey = Storage->ReadStringAsBinaryData(L"EncryptKey", FEncryptKey);
 
-     SET_SESSION_PROPERTY_FROM(EncryptKey, AEncryptKey);
 
-   }
 
-   WebDavLiberalEscaping = Storage->ReadBool(L"WebDavLiberalEscaping", WebDavLiberalEscaping);
 
-   IsWorkspace = Storage->ReadBool(L"IsWorkspace", IsWorkspace);
 
-   Link = Storage->ReadString(L"Link", Link);
 
-   NameOverride = Storage->ReadString(L"NameOverride", NameOverride);
 
-   PuttySettings = Storage->ReadString(L"PuttySettings", PuttySettings);
 
-   CustomParam1 = Storage->ReadString(L"CustomParam1", CustomParam1);
 
-   CustomParam2 = Storage->ReadString(L"CustomParam2", CustomParam2);
 
- #ifdef TEST
 
-   #define KEX_TEST(VALUE, EXPECTED) KexList = VALUE; DebugAssert(KexList == EXPECTED);
 
-   #define KEX_DEFAULT L"ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1"
 
-   // Empty source should result in default list
 
-   KEX_TEST(L"", KEX_DEFAULT);
 
-   // Default of pre 5.8.1
 
-   KEX_TEST(L"dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN", L"ecdh,dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN");
 
-   // Missing first two priority algos, and last non-priority algo
 
-   KEX_TEST(L"dh-group14-sha1,dh-group1-sha1,WARN", L"ecdh,dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN");
 
-   // Missing first two priority algos, last non-priority algo and WARN
 
-   KEX_TEST(L"dh-group14-sha1,dh-group1-sha1", L"ecdh,dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN");
 
-   // Old algos, with all but the first below WARN
 
-   KEX_TEST(L"dh-gex-sha1,WARN,dh-group14-sha1,dh-group1-sha1,rsa", L"ecdh,dh-gex-sha1,WARN,dh-group14-sha1,dh-group1-sha1,rsa");
 
-   // Unknown algo at front
 
-   KEX_TEST(L"unknown,ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1", KEX_DEFAULT);
 
-   // Unknown algo at back
 
-   KEX_TEST(L"ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1,unknown", KEX_DEFAULT);
 
-   // Unknown algo in the middle
 
-   KEX_TEST(L"ecdh,dh-gex-sha1,dh-group14-sha1,unknown,rsa,WARN,dh-group1-sha1", KEX_DEFAULT);
 
-   #undef KEX_DEFAULT
 
-   #undef KEX_TEST
 
-   #define CIPHER_TEST(VALUE, EXPECTED) CipherList = VALUE; DebugAssert(CipherList == EXPECTED);
 
-   #define CIPHER_DEFAULT L"aes,chacha20,blowfish,3des,WARN,arcfour,des"
 
-   // Empty source should result in default list
 
-   CIPHER_TEST(L"", CIPHER_DEFAULT);
 
-   // Default of pre 5.8.1
 
-   CIPHER_TEST(L"aes,blowfish,3des,WARN,arcfour,des", L"aes,blowfish,3des,chacha20,WARN,arcfour,des");
 
-   // Missing priority algo
 
-   CIPHER_TEST(L"chacha20,blowfish,3des,WARN,arcfour,des", CIPHER_DEFAULT);
 
-   // Missing non-priority algo
 
-   CIPHER_TEST(L"aes,chacha20,3des,WARN,arcfour,des", L"aes,chacha20,3des,blowfish,WARN,arcfour,des");
 
-   // Missing last warn algo
 
-   CIPHER_TEST(L"aes,blowfish,chacha20,3des,WARN,arcfour", L"aes,blowfish,chacha20,3des,WARN,arcfour,des");
 
-   // Missing first warn algo
 
-   CIPHER_TEST(L"aes,blowfish,chacha20,3des,WARN,des", L"aes,blowfish,chacha20,3des,WARN,des,arcfour");
 
-   #undef CIPHER_DEFAULT
 
-   #undef CIPHER_TEST
 
-   #define HOSTKEY_TEST(VALUE, EXPECTED) HostKeyList = VALUE; DebugAssert(HostKeyList == EXPECTED);
 
-   #define HOSTKEY_DEFAULT L"ed25519,ecdsa,rsa,dsa,WARN"
 
-   // Empty source should result in default list
 
-   HOSTKEY_TEST(L"", HOSTKEY_DEFAULT);
 
-   // Missing priority algo
 
-   HOSTKEY_TEST(L"ecdsa,rsa,dsa,WARN", HOSTKEY_DEFAULT);
 
-   // Missing non-priority algo
 
-   HOSTKEY_TEST(L"ed25519,ecdsa,dsa,WARN", L"ed25519,ecdsa,dsa,rsa,WARN");
 
-   #undef HOSTKEY_DEFAULT
 
-   #undef HOSTKEY_TEST
 
- #endif
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Load(THierarchicalStorage * Storage, bool PuttyImport)
 
- {
 
-   bool RewritePassword = false;
 
-   if (Storage->OpenSubKey(InternalStorageKey, False))
 
-   {
 
-     // In case we are re-loading, reset passwords, to avoid pointless
 
-     // re-cryption, while loading username/hostname. And moreover, when
 
-     // the password is wrongly encrypted (using a different master password),
 
-     // this breaks sites reload and consequently an overal operation,
 
-     // such as opening Sites menu
 
-     ClearSessionPasswords();
 
-     FProxyPassword = L"";
 
-     DoLoad(Storage, PuttyImport, RewritePassword, false);
 
-     Storage->CloseSubKey();
 
-   }
 
-   if (RewritePassword)
 
-   {
 
-     TStorageAccessMode AccessMode = Storage->AccessMode;
 
-     Storage->AccessMode = smReadWrite;
 
-     try
 
-     {
 
-       if (Storage->OpenSubKey(InternalStorageKey, true))
 
-       {
 
-         Storage->DeleteValue(L"PasswordPlain");
 
-         if (!Password.IsEmpty())
 
-         {
 
-           Storage->WriteBinaryDataAsString(L"Password", FPassword);
 
-         }
 
-         Storage->DeleteValue(L"TunnelPasswordPlain");
 
-         if (!TunnelPassword.IsEmpty())
 
-         {
 
-           Storage->WriteBinaryDataAsString(L"TunnelPassword", FTunnelPassword);
 
-         }
 
-         Storage->DeleteValue(L"EncryptKeyPlain");
 
-         if (!EncryptKey.IsEmpty())
 
-         {
 
-           Storage->WriteBinaryDataAsString(L"EncryptKey", FEncryptKey);
 
-         }
 
-         Storage->CloseSubKey();
 
-       }
 
-     }
 
-     catch(...)
 
-     {
 
-       // ignore errors (like read-only INI file)
 
-     }
 
-     Storage->AccessMode = AccessMode;
 
-   }
 
-   FModified = false;
 
-   FSource = ssStored;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,
 
-   bool PuttyExport, const TSessionData * Default, bool DoNotEncryptPasswords)
 
- {
 
-   // Same as in TCopyParamType::Save
 
-   #define WRITE_DATA_EX(TYPE, NAME, PROPERTY, CONV) \
 
-     if ((Default != NULL) && (CONV(Default->PROPERTY) == CONV(PROPERTY))) \
 
-     { \
 
-       Storage->DeleteValue(NAME); \
 
-     } \
 
-     else \
 
-     { \
 
-       Storage->Write ## TYPE(NAME, CONV(PROPERTY)); \
 
-     }
 
-   #define WRITE_DATA_CONV(TYPE, NAME, PROPERTY) WRITE_DATA_EX(TYPE, NAME, PROPERTY, WRITE_DATA_CONV_FUNC)
 
-   #define WRITE_DATA(TYPE, PROPERTY) WRITE_DATA_EX(TYPE, TEXT(#PROPERTY), PROPERTY, )
 
-   WRITE_DATA(String, HostName);
 
-   WRITE_DATA(Integer, PortNumber);
 
-   WRITE_DATA_EX(Integer, L"PingInterval", PingInterval / SecsPerMin, );
 
-   WRITE_DATA_EX(Integer, L"PingIntervalSecs", PingInterval % SecsPerMin, );
 
-   Storage->DeleteValue(L"PingIntervalSec"); // obsolete
 
-   WRITE_DATA(Integer, PingType);
 
-   WRITE_DATA(Integer, Timeout);
 
-   WRITE_DATA(Bool, TryAgent);
 
-   WRITE_DATA(Bool, AgentFwd);
 
-   WRITE_DATA(Bool, AuthTIS);
 
-   WRITE_DATA(Bool, AuthKI);
 
-   WRITE_DATA(Bool, AuthKIPassword);
 
-   WRITE_DATA(String, Note);
 
-   WRITE_DATA(Bool, AuthGSSAPI);
 
-   WRITE_DATA(Bool, AuthGSSAPIKEX);
 
-   WRITE_DATA(Bool, GSSAPIFwdTGT);
 
-   Storage->DeleteValue(L"TryGSSKEX");
 
-   Storage->DeleteValue(L"UserNameFromEnvironment");
 
-   Storage->DeleteValue("GSSAPIServerChoosesUserName");
 
-   Storage->DeleteValue(L"GSSAPITrustDNS");
 
-   WRITE_DATA(String, LogicalHostName);
 
-   if (PuttyExport)
 
-   {
 
-     // duplicate kerberos setting with keys of the vintela quest putty
 
-     WRITE_DATA_EX(Bool, L"AuthSSPI", AuthGSSAPI, );
 
-     WRITE_DATA_EX(Bool, L"SSPIFwdTGT", GSSAPIFwdTGT, );
 
-     WRITE_DATA_EX(String, L"KerbPrincipal", LogicalHostName, );
 
-     // duplicate kerberos setting with keys of the official putty
 
-     WRITE_DATA_EX(Bool, L"GssapiFwd", GSSAPIFwdTGT, );
 
-   }
 
-   WRITE_DATA(Bool, ChangeUsername);
 
-   WRITE_DATA(Bool, Compression);
 
-   WRITE_DATA(Integer, SshProt);
 
-   WRITE_DATA(Bool, Ssh2DES);
 
-   WRITE_DATA(Bool, SshNoUserAuth);
 
-   WRITE_DATA_EX(String, L"Cipher", CipherList, );
 
-   WRITE_DATA_EX(String, L"KEX", KexList, );
 
-   WRITE_DATA_EX(String, L"HostKey", HostKeyList, );
 
-   WRITE_DATA_EX(String, L"GSSLibs", GssLibList, );
 
-   WRITE_DATA_EX(String, L"GSSCustom", GssLibCustom, );
 
-   WRITE_DATA(Integer, AddressFamily);
 
-   WRITE_DATA_EX(String, L"RekeyBytes", RekeyData, );
 
-   WRITE_DATA(Integer, RekeyTime);
 
-   WRITE_DATA(Bool, TcpNoDelay);
 
-   if (PuttyExport)
 
-   {
 
-     WRITE_DATA(StringRaw, UserName);
 
-     // PuTTY is started in its binary directory to allow relative paths when opening PuTTY's own stored session.
 
-     // To allow relative paths in our sessions, we have to expand them for PuTTY.
 
-     WRITE_DATA_EX(StringRaw, L"PublicKeyFile", PublicKeyFile, ExpandFileName);
 
-   }
 
-   else
 
-   {
 
-     WRITE_DATA(String, UserName);
 
-     WRITE_DATA(String, PublicKeyFile);
 
-     WRITE_DATA(Integer, FSProtocol);
 
-     WRITE_DATA(String, LocalDirectory);
 
-     WRITE_DATA(String, RemoteDirectory);
 
-     WRITE_DATA(Bool, SynchronizeBrowsing);
 
-     WRITE_DATA(Bool, UpdateDirectories);
 
-     WRITE_DATA(Bool, CacheDirectories);
 
-     WRITE_DATA(Bool, CacheDirectoryChanges);
 
-     WRITE_DATA(Bool, PreserveDirectoryChanges);
 
-     WRITE_DATA(Bool, ResolveSymlinks);
 
-     WRITE_DATA(Bool, FollowDirectorySymlinks);
 
-     WRITE_DATA_EX(Integer, L"ConsiderDST", DSTMode, );
 
-     WRITE_DATA(Bool, LockInHome);
 
-     // Special is never stored (if it would, login dialog must be modified not to
 
-     // duplicate Special parameter when Special session is loaded and then stored
 
-     // under different name)
 
-     // WRITE_DATA(Bool, Special);
 
-     WRITE_DATA(String, Shell);
 
-     WRITE_DATA(Bool, ClearAliases);
 
-     WRITE_DATA(Bool, UnsetNationalVars);
 
-     WRITE_DATA(String, ListingCommand);
 
-     WRITE_DATA(Bool, IgnoreLsWarnings);
 
-     WRITE_DATA(Integer, SCPLsFullTime);
 
-     WRITE_DATA(Bool, Scp1Compatibility);
 
-     // TimeDifferenceAuto is valid for FTP protocol only.
 
-     // For other protocols it's typically true (default value),
 
-     // but ignored so TimeDifference is still taken into account (SCP only actually)
 
-     if (TimeDifferenceAuto && (FSProtocol == fsFTP))
 
-     {
 
-       // Have to delete it as TimeDifferenceAuto is not saved when enabled,
 
-       // but the default is derived from value of TimeDifference.
 
-       Storage->DeleteValue(L"TimeDifference");
 
-     }
 
-     else
 
-     {
 
-       WRITE_DATA(Float, TimeDifference);
 
-     }
 
-     WRITE_DATA(Bool, TimeDifferenceAuto);
 
-     WRITE_DATA(Bool, DeleteToRecycleBin);
 
-     WRITE_DATA(Bool, OverwrittenToRecycleBin);
 
-     WRITE_DATA(String, RecycleBinPath);
 
-     WRITE_DATA(String, PostLoginCommands);
 
-     WRITE_DATA(String, ReturnVar);
 
-     WRITE_DATA(Bool, ExitCode1IsError);
 
-     WRITE_DATA_EX(Integer, L"LookupUserGroups2", LookupUserGroups, );
 
-     WRITE_DATA(Integer, EOLType);
 
-     WRITE_DATA(Bool, TrimVMSVersions);
 
-     Storage->DeleteValue(L"SFTPUtfBug");
 
-     WRITE_DATA_EX(Integer, L"Utf", NotUtf, );
 
-     WRITE_DATA(Integer, InternalEditorEncoding);
 
-     WRITE_DATA(String, S3DefaultRegion);
 
-     WRITE_DATA(String, S3SessionToken);
 
-     WRITE_DATA(Integer, S3UrlStyle);
 
-     WRITE_DATA(Integer, S3MaxKeys);
 
-     WRITE_DATA(Integer, SendBuf);
 
-     WRITE_DATA(String, SourceAddress);
 
-     WRITE_DATA(String, ProtocolFeatures);
 
-     WRITE_DATA(Bool, SshSimple);
 
-   }
 
-   WRITE_DATA(Integer, ProxyMethod);
 
-   WRITE_DATA(String, ProxyHost);
 
-   WRITE_DATA(Integer, ProxyPort);
 
-   WRITE_DATA(String, ProxyUsername);
 
-   if (ProxyMethod == pmCmd)
 
-   {
 
-     WRITE_DATA_EX(StringRaw, L"ProxyTelnetCommand", ProxyLocalCommand, );
 
-   }
 
-   else
 
-   {
 
-     WRITE_DATA(StringRaw, ProxyTelnetCommand);
 
-   }
 
-   #define WRITE_DATA_CONV_FUNC(X) (((X) + 2) % 3)
 
-   WRITE_DATA_CONV(Integer, L"ProxyDNS", ProxyDNS);
 
-   #undef WRITE_DATA_CONV_FUNC
 
-   WRITE_DATA(Bool, ProxyLocalhost);
 
-   #define WRITE_DATA_CONV_FUNC(X) (2 - (X))
 
-   #define WRITE_BUG(BUG) WRITE_DATA_CONV(Integer, L"Bug" #BUG, Bug[sb##BUG]);
 
-   WRITE_BUG(Ignore1);
 
-   WRITE_BUG(PlainPW1);
 
-   WRITE_BUG(RSA1);
 
-   WRITE_BUG(HMAC2);
 
-   WRITE_BUG(DeriveKey2);
 
-   WRITE_BUG(RSAPad2);
 
-   WRITE_BUG(PKSessID2);
 
-   WRITE_BUG(Rekey2);
 
-   WRITE_BUG(MaxPkt2);
 
-   WRITE_BUG(Ignore2);
 
-   WRITE_BUG(OldGex2);
 
-   WRITE_BUG(WinAdj);
 
-   WRITE_BUG(ChanReq);
 
-   #undef WRITE_BUG
 
-   #undef WRITE_DATA_CONV_FUNC
 
-   Storage->DeleteValue(L"BuggyMAC");
 
-   Storage->DeleteValue(L"AliasGroupList");
 
-   if (PuttyExport)
 
-   {
 
-     WRITE_DATA_EX(String, L"Protocol", GetNormalizedPuttyProtocol(), );
 
-     WRITE_DATA(String, WinTitle);
 
-   }
 
-   if (!PuttyExport)
 
-   {
 
-     WRITE_DATA(String, SftpServer);
 
-     #define WRITE_SFTP_BUG(BUG) WRITE_DATA_EX(Integer, L"SFTP" #BUG "Bug", SFTPBug[sb##BUG], );
 
-     WRITE_SFTP_BUG(Symlink);
 
-     WRITE_SFTP_BUG(SignedTS);
 
-     #undef WRITE_SFTP_BUG
 
-     WRITE_DATA(Integer, SFTPMaxVersion);
 
-     WRITE_DATA(Integer, SFTPMaxPacketSize);
 
-     WRITE_DATA(Integer, SFTPDownloadQueue);
 
-     WRITE_DATA(Integer, SFTPUploadQueue);
 
-     WRITE_DATA(Integer, SFTPListingQueue);
 
-     WRITE_DATA(Integer, SFTPRealPath);
 
-     WRITE_DATA(Integer, Color);
 
-     WRITE_DATA(Bool, Tunnel);
 
-     WRITE_DATA(String, TunnelHostName);
 
-     WRITE_DATA(Integer, TunnelPortNumber);
 
-     WRITE_DATA(String, TunnelUserName);
 
-     WRITE_DATA(String, TunnelPublicKeyFile);
 
-     WRITE_DATA(Integer, TunnelLocalPortNumber);
 
-     WRITE_DATA(Bool, FtpPasvMode);
 
-     WRITE_DATA_EX(Integer, L"FtpForcePasvIp2", FtpForcePasvIp, );
 
-     WRITE_DATA(Integer, FtpUseMlsd);
 
-     WRITE_DATA(String, FtpAccount);
 
-     WRITE_DATA(Integer, FtpPingInterval);
 
-     WRITE_DATA(Integer, FtpPingType);
 
-     WRITE_DATA_EX(Integer, L"FtpTransferActiveImmediately2", FtpTransferActiveImmediately, );
 
-     WRITE_DATA(Integer, Ftps);
 
-     WRITE_DATA(Integer, FtpListAll);
 
-     WRITE_DATA(Integer, FtpHost);
 
-     WRITE_DATA(Integer, FtpWorkFromCwd);
 
-     WRITE_DATA(Bool, SslSessionReuse);
 
-     WRITE_DATA(String, TlsCertificateFile);
 
-     WRITE_DATA(Integer, FtpProxyLogonType);
 
-     WRITE_DATA(Integer, MinTlsVersion);
 
-     WRITE_DATA(Integer, MaxTlsVersion);
 
-     WRITE_DATA(Bool, WebDavLiberalEscaping);
 
-     WRITE_DATA(Bool, IsWorkspace);
 
-     WRITE_DATA(String, Link);
 
-     WRITE_DATA(String, NameOverride);
 
-     WRITE_DATA(String, PuttySettings);
 
-     WRITE_DATA(String, CustomParam1);
 
-     WRITE_DATA(String, CustomParam2);
 
-   }
 
-   // This is for collecting all keys for TSiteRawDialog::AddButtonClick.
 
-   // It should be enough to test for (Default == NULL),
 
-   // the DoNotEncryptPasswords and PuttyExport were added to limit a possible unintended impact.
 
-   bool SaveAll = (Default == NULL) && DoNotEncryptPasswords && !PuttyExport;
 
-   SavePasswords(Storage, PuttyExport, DoNotEncryptPasswords, SaveAll);
 
-   if (PuttyExport)
 
-   {
 
-     WritePuttySettings(Storage, PuttySettings);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- TStrings * __fastcall TSessionData::SaveToOptions(const TSessionData * Default, bool SaveName, bool PuttyExport)
 
- {
 
-   std::unique_ptr<TStringList> Options(new TStringList());
 
-   std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
 
-   if (SaveName)
 
-   {
 
-     OptionsStorage->WriteString(L"Name", Name);
 
-   }
 
-   DoSave(OptionsStorage.get(), PuttyExport, Default, true);
 
-   return Options.release();
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Save(THierarchicalStorage * Storage,
 
-   bool PuttyExport, const TSessionData * Default)
 
- {
 
-   if (Storage->OpenSubKey(InternalStorageKey, true))
 
-   {
 
-     DoSave(Storage, PuttyExport, Default, false);
 
-     Storage->CloseSubKey();
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::ReadXmlNode(_di_IXMLNode Node, const UnicodeString & Name, const UnicodeString & Default)
 
- {
 
-   _di_IXMLNode TheNode = Node->ChildNodes->FindNode(Name);
 
-   UnicodeString Result;
 
-   if (TheNode != NULL)
 
-   {
 
-     Result = TheNode->Text.Trim();
 
-   }
 
-   if (Result.IsEmpty())
 
-   {
 
-     Result = Default;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- int __fastcall TSessionData::ReadXmlNode(_di_IXMLNode Node, const UnicodeString & Name, int Default)
 
- {
 
-   _di_IXMLNode TheNode = Node->ChildNodes->FindNode(Name);
 
-   int Result;
 
-   if (TheNode != NULL)
 
-   {
 
-     Result = StrToIntDef(TheNode->Text.Trim(), Default);
 
-   }
 
-   else
 
-   {
 
-     Result = Default;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- _di_IXMLNode __fastcall TSessionData::FindSettingsNode(_di_IXMLNode Node, const UnicodeString & Name)
 
- {
 
-   for (int Index = 0; Index < Node->ChildNodes->Count; Index++)
 
-   {
 
-     _di_IXMLNode ChildNode = Node->ChildNodes->Get(Index);
 
-     if (ChildNode->NodeName == L"Setting")
 
-     {
 
-        OleVariant SettingName = ChildNode->GetAttribute(L"name");
 
-        if (SettingName == Name)
 
-        {
 
-          return ChildNode;
 
-        }
 
-     }
 
-   }
 
-   return NULL;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::ReadSettingsNode(_di_IXMLNode Node, const UnicodeString & Name, const UnicodeString & Default)
 
- {
 
-   _di_IXMLNode TheNode = FindSettingsNode(Node, Name);
 
-   UnicodeString Result;
 
-   if (TheNode != NULL)
 
-   {
 
-     Result = TheNode->Text.Trim();
 
-   }
 
-   if (Result.IsEmpty())
 
-   {
 
-     Result = Default;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- int __fastcall TSessionData::ReadSettingsNode(_di_IXMLNode Node, const UnicodeString & Name, int Default)
 
- {
 
-   _di_IXMLNode TheNode = FindSettingsNode(Node, Name);
 
-   int Result;
 
-   if (TheNode != NULL)
 
-   {
 
-     Result = StrToIntDef(TheNode->Text.Trim(), Default);
 
-   }
 
-   else
 
-   {
 
-     Result = Default;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ImportFromFilezilla(
 
-   _di_IXMLNode Node, const UnicodeString & Path, _di_IXMLNode SettingsNode)
 
- {
 
-   Name = UnixIncludeTrailingBackslash(Path) + MakeValidName(ReadXmlNode(Node, L"Name", Name));
 
-   HostName = ReadXmlNode(Node, L"Host", HostName);
 
-   PortNumber = ReadXmlNode(Node, L"Port", PortNumber);
 
-   int AProtocol = ReadXmlNode(Node, L"Protocol", 0);
 
-   // ServerProtocol enum
 
-   switch (AProtocol)
 
-   {
 
-     case 0: // FTP
 
-     default: // UNKNOWN, HTTP, HTTPS, INSECURE_FTP
 
-       FSProtocol = fsFTP;
 
-       break;
 
-     case 1: // SFTP
 
-       FSProtocol = fsSFTP;
 
-       break;
 
-     case 3: // FTPS
 
-       FSProtocol = fsFTP;
 
-       Ftps = ftpsImplicit;
 
-       break;
 
-     case 4: // FTPES
 
-       FSProtocol = fsFTP;
 
-       Ftps = ftpsExplicitTls;
 
-       break;
 
-   }
 
-   // LogonType enum
 
-   int LogonType = ReadXmlNode(Node, L"Logontype", 0);
 
-   if (LogonType == 0) // ANONYMOUS
 
-   {
 
-     UserName = AnonymousUserName;
 
-     Password = AnonymousPassword;
 
-   }
 
-   else
 
-   {
 
-     UserName = ReadXmlNode(Node, L"User", UserName);
 
-     FtpAccount = ReadXmlNode(Node, L"Account", FtpAccount);
 
-     _di_IXMLNode PassNode = Node->ChildNodes->FindNode(L"Pass");
 
-     if (PassNode != NULL)
 
-     {
 
-       UnicodeString APassword = PassNode->Text.Trim();
 
-       OleVariant EncodingValue = PassNode->GetAttribute(L"encoding");
 
-       if (!EncodingValue.IsNull())
 
-       {
 
-         UnicodeString EncodingValueStr = EncodingValue;
 
-         if (SameText(EncodingValueStr, L"base64"))
 
-         {
 
-           TBytes Bytes = DecodeBase64(APassword);
 
-           APassword = TEncoding::UTF8->GetString(Bytes);
 
-         }
 
-       }
 
-       Password = APassword;
 
-     }
 
-   }
 
-   PublicKeyFile = ReadXmlNode(Node, L"Keyfile", PublicKeyFile);
 
-   int DefaultTimeDifference = TimeToSeconds(TimeDifference);
 
-   TimeDifference =
 
-     (double(ReadXmlNode(Node, L"TimezoneOffset", DefaultTimeDifference) / SecsPerDay));
 
-   TimeDifferenceAuto = (TimeDifference == TDateTime());
 
-   UnicodeString PasvMode = ReadXmlNode(Node, L"PasvMode", L"");
 
-   if (SameText(PasvMode, L"MODE_PASSIVE"))
 
-   {
 
-     FtpPasvMode = true;
 
-   }
 
-   else if (SameText(PasvMode, L"MODE_ACTIVE"))
 
-   {
 
-     FtpPasvMode = false;
 
-   }
 
-   UnicodeString EncodingType = ReadXmlNode(Node, L"EncodingType", L"");
 
-   if (SameText(EncodingType, L"Auto"))
 
-   {
 
-     NotUtf = asAuto;
 
-   }
 
-   else if (SameText(EncodingType, L"UTF-8"))
 
-   {
 
-     NotUtf = asOff;
 
-   }
 
-   // todo PostLoginCommands
 
-   Note = ReadXmlNode(Node, L"Comments", Note);
 
-   LocalDirectory = ReadXmlNode(Node, L"LocalDir", LocalDirectory);
 
-   UnicodeString RemoteDir = ReadXmlNode(Node, L"RemoteDir", L"");
 
-   if (!RemoteDir.IsEmpty())
 
-   {
 
-     CutToChar(RemoteDir, L' ', false); // type
 
-     int PrefixSize = StrToIntDef(CutToChar(RemoteDir, L' ', false), 0); // prefix size
 
-     if (PrefixSize > 0)
 
-     {
 
-       RemoteDir.Delete(1, PrefixSize);
 
-     }
 
-     RemoteDirectory = L"/";
 
-     while (!RemoteDir.IsEmpty())
 
-     {
 
-       int SegmentSize = StrToIntDef(CutToChar(RemoteDir, L' ', false), 0);
 
-       UnicodeString Segment = RemoteDir.SubString(1, SegmentSize);
 
-       RemoteDirectory = UnixIncludeTrailingBackslash(RemoteDirectory) + Segment;
 
-       RemoteDir.Delete(1, SegmentSize + 1);
 
-     }
 
-   }
 
-   SynchronizeBrowsing = (ReadXmlNode(Node, L"SyncBrowsing", SynchronizeBrowsing ? 1 : 0) != 0);
 
-   if (SettingsNode != NULL)
 
-   {
 
-     if (UsesSsh && PublicKeyFile.IsEmpty())
 
-     {
 
-       UnicodeString KeyFiles = ReadSettingsNode(SettingsNode, L"SFTP keyfiles", UnicodeString());
 
-       UnicodeString KeyFile = CutToChar(KeyFiles, L'\n', true).Trim();
 
-       KeyFiles = KeyFiles.Trim();
 
-       // If there are more keys, ignore them, as we do not know which one to use
 
-       if (!KeyFile.IsEmpty() && KeyFiles.IsEmpty())
 
-       {
 
-         PublicKeyFile = KeyFile;
 
-       }
 
-     }
 
-     bool BypassProxy = (ReadXmlNode(Node, L"BypassProxy", 0) != 0);
 
-     if (!BypassProxy)
 
-     {
 
-       int FtpProxyType = ReadSettingsNode(SettingsNode, L"FTP Proxy type", -1);
 
-       if (FtpProxyType > 0)
 
-       {
 
-         switch (FtpProxyType)
 
-         {
 
-           case 1:
 
-             FtpProxyLogonType = 2;
 
-             break;
 
-           case 2:
 
-             FtpProxyLogonType = 1;
 
-             break;
 
-           case 3:
 
-             FtpProxyLogonType = 3;
 
-             break;
 
-           case 4:
 
-             // custom
 
-             // TODO: map known sequences to our enumeration
 
-             FtpProxyLogonType = 0;
 
-             break;
 
-           default:
 
-             DebugFail();
 
-             FtpProxyLogonType = 0;
 
-             break;
 
-         }
 
-         ProxyHost = ReadSettingsNode(SettingsNode, L"FTP Proxy host", ProxyHost);
 
-         ProxyUsername = ReadSettingsNode(SettingsNode, L"FTP Proxy user", ProxyUsername);
 
-         ProxyPassword = ReadSettingsNode(SettingsNode, L"FTP Proxy password", ProxyPassword);
 
-         // ProxyPort is not used with FtpProxyLogonType
 
-       }
 
-       else
 
-       {
 
-         int ProxyType = ReadSettingsNode(SettingsNode, L"Proxy type", -1);
 
-         if (ProxyType >= 0)
 
-         {
 
-           switch (ProxyType)
 
-           {
 
-             case 0:
 
-               ProxyMethod = ::pmNone;
 
-               break;
 
-             case 1:
 
-               ProxyMethod = pmHTTP;
 
-               break;
 
-             case 2:
 
-               ProxyMethod = pmSocks5;
 
-               break;
 
-             case 3:
 
-               ProxyMethod = pmSocks4;
 
-               break;
 
-             default:
 
-               DebugFail();
 
-               ProxyMethod = ::pmNone;
 
-               break;
 
-           }
 
-           ProxyHost = ReadSettingsNode(SettingsNode, L"Proxy host", ProxyHost);
 
-           ProxyPort = ReadSettingsNode(SettingsNode, L"Proxy port", ProxyPort);
 
-           ProxyUsername = ReadSettingsNode(SettingsNode, L"Proxy user", ProxyUsername);
 
-           ProxyPassword = ReadSettingsNode(SettingsNode, L"Proxy password", ProxyPassword);
 
-         }
 
-       }
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SavePasswords(THierarchicalStorage * Storage, bool PuttyExport, bool DoNotEncryptPasswords, bool SaveAll)
 
- {
 
-   if (!Configuration->DisablePasswordStoring && !PuttyExport && (!FPassword.IsEmpty() || SaveAll))
 
-   {
 
-     if (DoNotEncryptPasswords)
 
-     {
 
-       Storage->WriteString(L"PasswordPlain", Password);
 
-       Storage->DeleteValue(L"Password");
 
-     }
 
-     else
 
-     {
 
-       Storage->WriteBinaryDataAsString(L"Password", StronglyRecryptPassword(FPassword, UserName+HostName));
 
-       Storage->DeleteValue(L"PasswordPlain");
 
-     }
 
-   }
 
-   else
 
-   {
 
-     Storage->DeleteValue(L"Password");
 
-     Storage->DeleteValue(L"PasswordPlain");
 
-   }
 
-   if (PuttyExport)
 
-   {
 
-     // save password unencrypted
 
-     Storage->WriteString(L"ProxyPassword", ProxyPassword);
 
-   }
 
-   else
 
-   {
 
-     if (DoNotEncryptPasswords)
 
-     {
 
-       if (!FProxyPassword.IsEmpty() || SaveAll)
 
-       {
 
-         Storage->WriteString(L"ProxyPassword", ProxyPassword);
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"ProxyPassword");
 
-       }
 
-       Storage->DeleteValue(L"ProxyPasswordEnc");
 
-     }
 
-     else
 
-     {
 
-       // save password encrypted
 
-       if (!FProxyPassword.IsEmpty() || SaveAll)
 
-       {
 
-         Storage->WriteBinaryDataAsString(L"ProxyPasswordEnc", StronglyRecryptPassword(FProxyPassword, ProxyUsername+ProxyHost));
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"ProxyPasswordEnc");
 
-       }
 
-       Storage->DeleteValue(L"ProxyPassword");
 
-     }
 
-     if (DoNotEncryptPasswords)
 
-     {
 
-       if (!FTunnelPassword.IsEmpty() || SaveAll)
 
-       {
 
-         Storage->WriteString(L"TunnelPasswordPlain", TunnelPassword);
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"TunnelPasswordPlain");
 
-       }
 
-     }
 
-     else
 
-     {
 
-       if (!Configuration->DisablePasswordStoring && (!FTunnelPassword.IsEmpty() || SaveAll))
 
-       {
 
-         Storage->WriteBinaryDataAsString(L"TunnelPassword", StronglyRecryptPassword(FTunnelPassword, TunnelUserName+TunnelHostName));
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"TunnelPassword");
 
-       }
 
-     }
 
-     if (DoNotEncryptPasswords)
 
-     {
 
-       if (!FEncryptKey.IsEmpty() || SaveAll)
 
-       {
 
-         Storage->WriteString(L"EncryptKeyPlain", EncryptKey);
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"EncryptKeyPlain");
 
-       }
 
-       Storage->DeleteValue(L"EncryptKey");
 
-     }
 
-     else
 
-     {
 
-       if (!FEncryptKey.IsEmpty() || SaveAll)
 
-       {
 
-         Storage->WriteBinaryDataAsString(L"EncryptKey", StronglyRecryptPassword(FEncryptKey, UserName+HostName));
 
-       }
 
-       else
 
-       {
 
-         Storage->DeleteValue(L"EncryptKey");
 
-       }
 
-       Storage->DeleteValue(L"EncryptKeyPlain");
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::RecryptPasswords()
 
- {
 
-   Password = Password;
 
-   NewPassword = NewPassword;
 
-   ProxyPassword = ProxyPassword;
 
-   TunnelPassword = TunnelPassword;
 
-   Passphrase = Passphrase;
 
-   EncryptKey = EncryptKey;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasPassword()
 
- {
 
-   return !FPassword.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasAnySessionPassword()
 
- {
 
-   // Keep in sync with ClearSessionPasswords
 
-   return
 
-     HasPassword() ||
 
-     !FTunnelPassword.IsEmpty()  ||
 
-     // will probably be never used
 
-     !FNewPassword.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasAnyPassword()
 
- {
 
-   // Keep in sync with MaskPasswords
 
-   return
 
-     HasAnySessionPassword() ||
 
-     !FProxyPassword.IsEmpty() ||
 
-     !FEncryptKey.IsEmpty() ||
 
-     !FPassphrase.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ClearSessionPasswords()
 
- {
 
-   // Keep in sync with HasAnySessionPassword
 
-   FPassword = L"";
 
-   FNewPassword = L"";
 
-   FTunnelPassword = L"";
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Modify()
 
- {
 
-   FModified = true;
 
-   if (FSource == ssStored)
 
-   {
 
-     FSource = ssStoredModified;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetSource()
 
- {
 
-   switch (FSource)
 
-   {
 
-     case ::ssNone:
 
-       return L"Ad-Hoc site";
 
-     case ssStored:
 
-       return L"Site";
 
-     case ssStoredModified:
 
-       return L"Modified site";
 
-     default:
 
-       DebugFail();
 
-       return L"";
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SaveRecryptedPasswords(THierarchicalStorage * Storage)
 
- {
 
-   if (Storage->OpenSubKey(InternalStorageKey, true))
 
-   {
 
-     try
 
-     {
 
-       RecryptPasswords();
 
-       SavePasswords(Storage, false, false, false);
 
-     }
 
-     __finally
 
-     {
 
-       Storage->CloseSubKey();
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Remove(THierarchicalStorage * Storage, const UnicodeString & Name)
 
- {
 
-   Storage->RecursiveDeleteSubKey(Name);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::Remove()
 
- {
 
-   bool SessionList = true;
 
-   THierarchicalStorage * Storage = Configuration->CreateScpStorage(SessionList);
 
-   try
 
-   {
 
-     Storage->Explicit = true;
 
-     if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, false))
 
-     {
 
-       Remove(Storage, InternalStorageKey);
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     delete Storage;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::CacheHostKeyIfNotCached()
 
- {
 
-   UnicodeString KeyType = KeyTypeFromFingerprint(HostKey);
 
-   // Should allow importing to INI file as ImportHostKeys
 
-   UnicodeString TargetKey = Configuration->RegistryStorageKey + L"\\" + Configuration->SshHostKeysSubKey;
 
-   std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(TargetKey));
 
-   Storage->AccessMode = smReadWrite;
 
-   if (Storage->OpenRootKey(true))
 
-   {
 
-     UnicodeString HostKeyName = PuttyMungeStr(FORMAT(L"%s@%d:%s", (KeyType, PortNumber, HostName)));
 
-     if (!Storage->ValueExists(HostKeyName))
 
-     {
 
-       // fingerprint is a checksum of a host key, so it cannot be translated back to host key,
 
-       // so we store fingerprint and TSecureShell::VerifyHostKey was
 
-       // modified to accept also fingerprint
 
-       Storage->WriteString(HostKeyName, HostKey);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- inline void __fastcall MoveStr(UnicodeString & Source, UnicodeString * Dest, int Count)
 
- {
 
-   if (Dest != NULL)
 
-   {
 
-     (*Dest) += Source.SubString(1, Count);
 
-   }
 
-   Source.Delete(1, Count);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::DoIsProtocolUrl(
 
-   const UnicodeString & Url, const UnicodeString & Protocol, int & ProtocolLen)
 
- {
 
-   bool Result = SameText(Url.SubString(1, Protocol.Length() + 1), Protocol + L":");
 
-   if (Result)
 
-   {
 
-     ProtocolLen = Protocol.Length() + 1;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsProtocolUrl(
 
-   const UnicodeString & Url, const UnicodeString & Protocol, int & ProtocolLen)
 
- {
 
-   return
 
-     DoIsProtocolUrl(Url, Protocol, ProtocolLen) ||
 
-     DoIsProtocolUrl(Url, WinSCPProtocolPrefix + Protocol, ProtocolLen);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSensitiveOption(const UnicodeString & Option)
 
- {
 
-   return
 
-     SameText(Option, PassphraseOption) ||
 
-     SameText(Option, PASSWORD_SWITCH) ||
 
-     SameText(Option, NEWPASSWORD_SWITCH);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsOptionWithParameters(const UnicodeString & Option)
 
- {
 
-   return SameText(Option, RawSettingsOption);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::MaskPasswordInOptionParameter(const UnicodeString & Option, UnicodeString & Param)
 
- {
 
-   bool Result = false;
 
-   if (SameText(Option, RawSettingsOption))
 
-   {
 
-     int P = Param.Pos(L"=");
 
-     if (P > 0)
 
-     {
 
-       // TStrings.IndexOfName does not trim
 
-       UnicodeString Key = Param.SubString(1, P - 1);
 
-       if (SameText(Key, L"ProxyPassword") ||
 
-           SameText(Key, L"ProxyPasswordEnc") ||
 
-           SameText(Key, L"TunnelPassword") ||
 
-           SameText(Key, L"TunnelPasswordPlain") ||
 
-           SameText(Key, L"EncryptKey"))
 
-       {
 
-         Param = Key + L"=" + PasswordMask;
 
-         Result = true;
 
-       }
 
-     }
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::MaskPasswords()
 
- {
 
-   // Keep in sync with HasAnyPassword
 
-   if (!Password.IsEmpty())
 
-   {
 
-     Password = PasswordMask;
 
-   }
 
-   if (!NewPassword.IsEmpty())
 
-   {
 
-     NewPassword = PasswordMask;
 
-   }
 
-   if (!ProxyPassword.IsEmpty())
 
-   {
 
-     ProxyPassword = PasswordMask;
 
-   }
 
-   if (!TunnelPassword.IsEmpty())
 
-   {
 
-     TunnelPassword = PasswordMask;
 
-   }
 
-   if (!EncryptKey.IsEmpty())
 
-   {
 
-     EncryptKey = PasswordMask;
 
-   }
 
-   if (!Passphrase.IsEmpty())
 
-   {
 
-     Passphrase = PasswordMask;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- static bool IsDomainOrSubdomain(const UnicodeString & FullDomain, const UnicodeString & Domain)
 
- {
 
-   return
 
-     SameText(FullDomain, Domain) ||
 
-     EndsText(L"." + Domain, FullDomain);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
 
-   TStoredSessionList * StoredSessions, bool & DefaultsOnly, UnicodeString * FileName,
 
-   bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags)
 
- {
 
-   bool ProtocolDefined = false;
 
-   bool PortNumberDefined = false;
 
-   TFSProtocol AFSProtocol;
 
-   int APortNumber;
 
-   TFtps AFtps = ftpsNone;
 
-   int ProtocolLen = 0;
 
-   if (IsProtocolUrl(Url, ScpProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsSCPonly;
 
-     APortNumber = SshPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, SftpProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsSFTPonly;
 
-     APortNumber = SshPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, FtpProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsFTP;
 
-     Ftps = ftpsNone;
 
-     APortNumber = FtpPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, FtpsProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsFTP;
 
-     AFtps = ftpsImplicit;
 
-     APortNumber = FtpsImplicitPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, FtpesProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsFTP;
 
-     AFtps = ftpsExplicitTls;
 
-     APortNumber = FtpPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, WebDAVProtocol, ProtocolLen) ||
 
-            IsProtocolUrl(Url, HttpProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsWebDAV;
 
-     AFtps = ftpsNone;
 
-     APortNumber = HTTPPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, WebDAVSProtocol, ProtocolLen) ||
 
-            IsProtocolUrl(Url, HttpsProtocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsWebDAV;
 
-     AFtps = ftpsImplicit;
 
-     APortNumber = HTTPSPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, S3Protocol, ProtocolLen))
 
-   {
 
-     AFSProtocol = fsS3;
 
-     AFtps = ftpsImplicit;
 
-     APortNumber = HTTPSPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   else if (IsProtocolUrl(Url, SshProtocol, ProtocolLen))
 
-   {
 
-     // For most uses, handling ssh:// the same way as sftp://
 
-     // The only place where a difference is made is GetLoginData() in WinMain.cpp
 
-     AFSProtocol = fsSFTPonly;
 
-     PuttyProtocol = PuttySshProtocol;
 
-     APortNumber = SshPortNumber;
 
-     MoveStr(Url, MaskedUrl, ProtocolLen);
 
-     ProtocolDefined = true;
 
-   }
 
-   if (ProtocolDefined && (Url.SubString(1, 2) == L"//"))
 
-   {
 
-     MoveStr(Url, MaskedUrl, 2);
 
-   }
 
-   if (AProtocolDefined != NULL)
 
-   {
 
-     *AProtocolDefined = ProtocolDefined;
 
-   }
 
-   bool Unsafe = FLAGSET(Flags, pufUnsafe);
 
-   if (!Url.IsEmpty())
 
-   {
 
-     UnicodeString DecodedUrl = DecodeUrlChars(Url);
 
-     // lookup stored session even if protocol was defined
 
-     // (this allows setting for example default username for host
 
-     // by creating stored session named by host)
 
-     TSessionData * Data = NULL;
 
-     // When using to paste URL on Login dialog, we do not want to lookup the stored sites
 
-     if ((StoredSessions != NULL) &&
 
-         (!ProtocolDefined || FLAGSET(Flags, pufAllowStoredSiteWithProtocol)))
 
-     {
 
-       // this can be optimized as the list is sorted
 
-       for (Integer Index = 0; Index < StoredSessions->CountIncludingHidden; Index++)
 
-       {
 
-         TSessionData * AData = (TSessionData *)StoredSessions->Items[Index];
 
-         if (!AData->IsWorkspace)
 
-         {
 
-           bool Match = false;
 
-           // Comparison optimizations as this is called many times
 
-           // e.g. when updating jumplist
 
-           if ((AData->Name.Length() == DecodedUrl.Length()) &&
 
-               SameText(AData->Name, DecodedUrl))
 
-           {
 
-             Match = true;
 
-           }
 
-           else if ((AData->Name.Length() < DecodedUrl.Length()) &&
 
-                    (DecodedUrl[AData->Name.Length() + 1] == L'/') &&
 
-                    // StrLIComp is an equivalent of SameText
 
-                    (StrLIComp(AData->Name.c_str(), DecodedUrl.c_str(), AData->Name.Length()) == 0))
 
-           {
 
-             Match = true;
 
-           }
 
-           if (Match)
 
-           {
 
-             Data = AData;
 
-             break;
 
-           }
 
-         }
 
-       }
 
-     }
 
-     UnicodeString ARemoteDirectory;
 
-     if (Data != NULL)
 
-     {
 
-       Assign(Data);
 
-       int P = 1;
 
-       while (!AnsiSameText(DecodeUrlChars(Url.SubString(1, P)), Data->Name))
 
-       {
 
-         P++;
 
-         DebugAssert(P <= Url.Length());
 
-       }
 
-       ARemoteDirectory = Url.SubString(P + 1, Url.Length() - P);
 
-       if (Data->Hidden)
 
-       {
 
-         Data->Remove();
 
-         StoredSessions->Remove(Data);
 
-         // only modified, implicit
 
-         StoredSessions->Save(false, false);
 
-       }
 
-       if (MaskedUrl != NULL)
 
-       {
 
-         (*MaskedUrl) += Url;
 
-       }
 
-     }
 
-     else
 
-     {
 
-       // This happens when pasting URL on Login dialog
 
-       if (StoredSessions != NULL)
 
-       {
 
-         CopyData(StoredSessions->DefaultSettings);
 
-       }
 
-       Name = L"";
 
-       int PSlash = Url.Pos(L"/");
 
-       if (PSlash == 0)
 
-       {
 
-         PSlash = Url.Length() + 1;
 
-       }
 
-       UnicodeString ConnectInfo = Url.SubString(1, PSlash - 1);
 
-       int P = ConnectInfo.LastDelimiter(L"@");
 
-       UnicodeString UserInfo;
 
-       UnicodeString HostInfo;
 
-       if (P > 0)
 
-       {
 
-         UserInfo = ConnectInfo.SubString(1, P - 1);
 
-         HostInfo = ConnectInfo.SubString(P + 1, ConnectInfo.Length() - P);
 
-       }
 
-       else
 
-       {
 
-         HostInfo = ConnectInfo;
 
-       }
 
-       UnicodeString OrigHostInfo = HostInfo;
 
-       if ((HostInfo.Length() >= 2) && (HostInfo[1] == L'[') && ((P = HostInfo.Pos(L"]")) > 0))
 
-       {
 
-         HostName = HostInfo.SubString(2, P - 2);
 
-         HostInfo.Delete(1, P);
 
-         if (!HostInfo.IsEmpty() && (HostInfo[1] == L':'))
 
-         {
 
-           HostInfo.Delete(1, 1);
 
-         }
 
-       }
 
-       else
 
-       {
 
-         HostName = DecodeUrlChars(CutToChar(HostInfo, L':', true));
 
-       }
 
-       // expanded from ?: operator, as it caused strange "access violation" errors
 
-       if (!HostInfo.IsEmpty())
 
-       {
 
-         int APortNumber = StrToIntDef(DecodeUrlChars(HostInfo), -1);
 
-         if ((APortNumber > 0) && (APortNumber <= 65535))
 
-         {
 
-           PortNumber = APortNumber;
 
-           PortNumberDefined = true;
 
-         }
 
-       }
 
-       else if (ProtocolDefined)
 
-       {
 
-         if ((AFSProtocol == fsWebDAV) &&
 
-             (IsDomainOrSubdomain(HostName, S3LibDefaultHostName()) ||
 
-              IsDomainOrSubdomain(HostName, L"digitaloceanspaces.com") ||
 
-              IsDomainOrSubdomain(HostName, L"storage.googleapis.com")))
 
-         {
 
-           AFSProtocol = fsS3;
 
-         }
 
-         PortNumber = APortNumber;
 
-       }
 
-       if (ProtocolDefined)
 
-       {
 
-         Ftps = AFtps;
 
-       }
 
-       UnicodeString UserInfoWithoutConnectionParams = CutToChar(UserInfo, UrlParamSeparator, false);
 
-       UnicodeString ConnectionParams = UserInfo;
 
-       UserInfo = UserInfoWithoutConnectionParams;
 
-       std::unique_ptr<TStrings> RawSettings(new TStringList());
 
-       while (!ConnectionParams.IsEmpty())
 
-       {
 
-         UnicodeString ConnectionParam = CutToChar(ConnectionParams, UrlParamSeparator, false);
 
-         UnicodeString ConnectionParamName = CutToChar(ConnectionParam, UrlParamValueSeparator, false);
 
-         if (SameText(ConnectionParamName, UrlHostKeyParamName))
 
-         {
 
-           HostKey = DecodeUrlChars(ConnectionParam);
 
-           FOverrideCachedHostKey = false;
 
-         }
 
-         else if (StartsText(UrlRawSettingsParamNamePrefix, ConnectionParamName))
 
-         {
 
-           UnicodeString AName = RightStr(ConnectionParamName, ConnectionParamName.Length() - UrlRawSettingsParamNamePrefix.Length());
 
-           AName = DecodeUrlChars(AName);
 
-           UnicodeString Value = DecodeUrlChars(ConnectionParam);
 
-           if (SameText(AName, L"Name"))
 
-           {
 
-             Name = Value;
 
-           }
 
-           else
 
-           {
 
-             RawSettings->Values[AName] = Value;
 
-           }
 
-         }
 
-       }
 
-       if (RawSettings->Count > 0) // optimization
 
-       {
 
-         ApplyRawSettings(RawSettings.get(), FLAGSET(Flags, pufUnsafe));
 
-       }
 
-       bool HasPassword = (UserInfo.Pos(L':') > 0);
 
-       UnicodeString RawUserName = CutToChar(UserInfo, L':', false);
 
-       UserName = DecodeUrlChars(RawUserName);
 
-       Password = DecodeUrlChars(UserInfo);
 
-       if (HasPassword && Password.IsEmpty())
 
-       {
 
-         Password = EmptyString;
 
-       }
 
-       UnicodeString RemoteDirectoryWithSessionParams = Url.SubString(PSlash, Url.Length() - PSlash + 1);
 
-       ARemoteDirectory = CutToChar(RemoteDirectoryWithSessionParams, UrlParamSeparator, false);
 
-       UnicodeString SessionParams = RemoteDirectoryWithSessionParams;
 
-       // We should handle session params in "stored session" branch too.
 
-       // And particularly if there's a "save" param, we should actually not try to match the
 
-       // URL against site names
 
-       while (!SessionParams.IsEmpty())
 
-       {
 
-         UnicodeString SessionParam = CutToChar(SessionParams, UrlParamSeparator, false);
 
-         UnicodeString SessionParamName = CutToChar(SessionParam, UrlParamValueSeparator, false);
 
-         if (SameText(SessionParamName, UrlSaveParamName))
 
-         {
 
-           FSaveOnly = (StrToIntDef(SessionParam, 1) != 0);
 
-         }
 
-       }
 
-       if (MaskedUrl != NULL)
 
-       {
 
-         (*MaskedUrl) += RawUserName;
 
-         if (HasPassword)
 
-         {
 
-           (*MaskedUrl) += L":" + PasswordMask;
 
-         }
 
-         if (!RawUserName.IsEmpty() || HasPassword)
 
-         {
 
-           (*MaskedUrl) += L"@";
 
-         }
 
-         (*MaskedUrl) += OrigHostInfo + ARemoteDirectory;
 
-       }
 
-     }
 
-     if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory != L"/"))
 
-     {
 
-       if ((ARemoteDirectory[ARemoteDirectory.Length()] != L'/') &&
 
-           (FileName != NULL))
 
-       {
 
-         *FileName = DecodeUrlChars(UnixExtractFileName(ARemoteDirectory));
 
-         ARemoteDirectory = UnixExtractFilePath(ARemoteDirectory);
 
-       }
 
-       RemoteDirectory = DecodeUrlChars(ARemoteDirectory);
 
-     }
 
-     DefaultsOnly = false;
 
-   }
 
-   else
 
-   {
 
-     // This happens when pasting URL on Login dialog
 
-     if (StoredSessions != NULL)
 
-     {
 
-       CopyData(StoredSessions->DefaultSettings);
 
-     }
 
-     DefaultsOnly = true;
 
-   }
 
-   if (ProtocolDefined)
 
-   {
 
-     FSProtocol = AFSProtocol;
 
-   }
 
-   if (Options != NULL)
 
-   {
 
-     // we deliberately do keep defaultonly to false, in presence of any option,
 
-     // as the option should not make session "connectable"
 
-     UnicodeString Value;
 
-     if (Options->FindSwitch(USERNAME_SWITCH, Value))
 
-     {
 
-       UserName = Value;
 
-     }
 
-     if (Options->FindSwitch(PASSWORD_SWITCH, Value))
 
-     {
 
-       Password = Value;
 
-     }
 
-     if (Options->FindSwitch(SESSIONNAME_SWICH, Value))
 
-     {
 
-       Name = Value;
 
-     }
 
-     if (Options->FindSwitch(NEWPASSWORD_SWITCH, Value))
 
-     {
 
-       ChangePassword = true;
 
-       NewPassword = Value;
 
-     }
 
-     if (Options->FindSwitch(L"privatekey", Value))
 
-     {
 
-       PublicKeyFile = Value;
 
-     }
 
-     if (Options->FindSwitch(L"clientcert", Value))
 
-     {
 
-       TlsCertificateFile = Value;
 
-     }
 
-     if (Options->FindSwitch(PassphraseOption, Value))
 
-     {
 
-       Passphrase = Value;
 
-     }
 
-     if (Options->FindSwitch(L"timeout", Value))
 
-     {
 
-       Timeout = StrToInt(Value);
 
-     }
 
-     if (Options->FindSwitch(L"hostkey", Value) ||
 
-         Options->FindSwitch(L"certificate", Value))
 
-     {
 
-       HostKey = Value;
 
-       FOverrideCachedHostKey = true;
 
-     }
 
-     FtpPasvMode = Options->SwitchValue(L"passive", FtpPasvMode);
 
-     if (Options->FindSwitch(L"implicit"))
 
-     {
 
-       bool Enabled = Options->SwitchValue(L"implicit", true);
 
-       Ftps = Enabled ? ftpsImplicit : ftpsNone;
 
-       if (!PortNumberDefined && Enabled)
 
-       {
 
-         PortNumber = FtpsImplicitPortNumber;
 
-       }
 
-     }
 
-     // BACKWARD COMPATIBILITY with 5.5.x
 
-     if (Options->FindSwitch(L"explicitssl"))
 
-     {
 
-       bool Enabled = Options->SwitchValue(L"explicitssl", true);
 
-       Ftps = Enabled ? ftpsExplicitSsl : ftpsNone;
 
-       if (!PortNumberDefined && Enabled)
 
-       {
 
-         PortNumber = FtpPortNumber;
 
-       }
 
-     }
 
-     if (Options->FindSwitch(L"explicit") ||
 
-         // BACKWARD COMPATIBILITY with 5.5.x
 
-         Options->FindSwitch(L"explicittls"))
 
-     {
 
-       UnicodeString SwitchName =
 
-         Options->FindSwitch(L"explicit") ? L"explicit" : L"explicittls";
 
-       bool Enabled = Options->SwitchValue(SwitchName, true);
 
-       Ftps = Enabled ? ftpsExplicitTls : ftpsNone;
 
-       if (!PortNumberDefined && Enabled)
 
-       {
 
-         PortNumber = FtpPortNumber;
 
-       }
 
-     }
 
-     if (Options->FindSwitch(RawSettingsOption))
 
-     {
 
-       std::unique_ptr<TStrings> RawSettings(new TStringList());
 
-       if (Options->FindSwitch(RawSettingsOption, RawSettings.get()))
 
-       {
 
-         ApplyRawSettings(RawSettings.get(), Unsafe);
 
-       }
 
-     }
 
-   }
 
-   return true;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ApplyRawSettings(TStrings * RawSettings, bool Unsafe)
 
- {
 
-   std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(RawSettings, false));
 
-   ApplyRawSettings(OptionsStorage.get(), Unsafe);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ApplyRawSettings(THierarchicalStorage * Storage, bool Unsafe)
 
- {
 
-   bool Dummy;
 
-   DoLoad(Storage, false, Dummy, Unsafe);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ConfigureTunnel(int APortNumber)
 
- {
 
-   FOrigHostName = HostName;
 
-   FOrigPortNumber = PortNumber;
 
-   FOrigProxyMethod = ProxyMethod;
 
-   HostName = L"127.0.0.1";
 
-   PortNumber = APortNumber;
 
-   // proxy settings is used for tunnel
 
-   ProxyMethod = ::pmNone;
 
-   FLogicalHostName = FOrigHostName;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::RollbackTunnel()
 
- {
 
-   HostName = FOrigHostName;
 
-   PortNumber = FOrigPortNumber;
 
-   ProxyMethod = FOrigProxyMethod;
 
-   FLogicalHostName = L"";
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ExpandEnvironmentVariables()
 
- {
 
-   HostName = HostNameExpanded;
 
-   UserName = UserNameExpanded;
 
-   PublicKeyFile = ::ExpandEnvironmentVariables(PublicKeyFile);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ValidatePath(const UnicodeString Path)
 
- {
 
-   // noop
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::ValidateName(const UnicodeString Name)
 
- {
 
-   // keep consistent with MakeValidName
 
-   if (Name.LastDelimiter(L"/") > 0)
 
-   {
 
-     throw Exception(FMTLOAD(ITEM_NAME_INVALID, (Name, L"/")));
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::MakeValidName(const UnicodeString & Name)
 
- {
 
-   // keep consistent with ValidateName
 
-   return ReplaceStr(Name, L"/", L"\\");
 
- }
 
- //---------------------------------------------------------------------
 
- RawByteString __fastcall TSessionData::EncryptPassword(const UnicodeString & Password, UnicodeString Key)
 
- {
 
-   return Configuration->EncryptPassword(Password, Key);
 
- }
 
- //---------------------------------------------------------------------
 
- RawByteString __fastcall TSessionData::StronglyRecryptPassword(const RawByteString & Password, UnicodeString Key)
 
- {
 
-   return Configuration->StronglyRecryptPassword(Password, Key);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::DecryptPassword(const RawByteString & Password, UnicodeString Key)
 
- {
 
-   UnicodeString Result;
 
-   try
 
-   {
 
-     Result = Configuration->DecryptPassword(Password, Key);
 
-   }
 
-   catch(EAbort &)
 
-   {
 
-     // silently ignore aborted prompts for master password and return empty password
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::GetCanLogin()
 
- {
 
-   return !FHostName.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetSessionKey()
 
- {
 
-   UnicodeString Result = FORMAT(L"%s@%s", (UserName, HostName));
 
-   if (PortNumber != DefaultPort(FSProtocol, Ftps))
 
-   {
 
-     Result += FORMAT(L":%d", (PortNumber));
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetInternalStorageKey()
 
- {
 
-   // This is probably useless remnant of previous use of this method from OpenSessionInPutty
 
-   // that needs the method to return something even for ad-hoc sessions
 
-   if (Name.IsEmpty())
 
-   {
 
-     return SessionKey;
 
-   }
 
-   else
 
-   {
 
-     return Name;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetStorageKey()
 
- {
 
-   return SessionName;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::FormatSiteKey(const UnicodeString & HostName, int PortNumber)
 
- {
 
-   return FORMAT(L"%s:%d", (HostName, PortNumber));
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetSiteKey()
 
- {
 
-   return FormatSiteKey(HostNameExpanded, PortNumber);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetHostName(UnicodeString value)
 
- {
 
-   if (FHostName != value)
 
-   {
 
-     // HostName is key for password encryption
 
-     UnicodeString XPassword = Password;
 
-     UnicodeString XNewPassword = NewPassword;
 
-     UnicodeString XEncryptKey = EncryptKey;
 
-     // This is now hardly used as hostname is parsed directly on login dialog.
 
-     // But can be used when importing sites from PuTTY, as it allows same format too.
 
-     int P = value.LastDelimiter(L"@");
 
-     if (P > 0)
 
-     {
 
-       UserName = value.SubString(1, P - 1);
 
-       value = value.SubString(P + 1, value.Length() - P);
 
-     }
 
-     FHostName = value;
 
-     Modify();
 
-     Password = XPassword;
 
-     NewPassword = XNewPassword;
 
-     EncryptKey = XEncryptKey;
 
-     Shred(XPassword);
 
-     Shred(XNewPassword);
 
-     Shred(XEncryptKey);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetHostNameExpanded()
 
- {
 
-   return ::ExpandEnvironmentVariables(HostName);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString TSessionData::GetHostNameSource()
 
- {
 
-   UnicodeString Result;
 
-   if (HostName != HostNameExpanded)
 
-   {
 
-     Result = HostName;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPortNumber(int value)
 
- {
 
-   SET_SESSION_PROPERTY(PortNumber);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetShell(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(Shell);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSftpServer(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(SftpServer);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetClearAliases(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ClearAliases);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetListingCommand(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ListingCommand);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetIgnoreLsWarnings(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(IgnoreLsWarnings);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetUnsetNationalVars(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(UnsetNationalVars);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetUserName(UnicodeString value)
 
- {
 
-   // Avoid password recryption (what may popup master password prompt)
 
-   if (FUserName != value)
 
-   {
 
-     // UserName is key for password encryption
 
-     UnicodeString XPassword = Password;
 
-     UnicodeString XNewPassword = NewPassword;
 
-     UnicodeString XEncryptKey = EncryptKey;
 
-     SET_SESSION_PROPERTY(UserName);
 
-     Password = XPassword;
 
-     NewPassword = XNewPassword;
 
-     EncryptKey = XEncryptKey;
 
-     Shred(XPassword);
 
-     Shred(XNewPassword);
 
-     Shred(XEncryptKey);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetUserNameExpanded()
 
- {
 
-   return ::ExpandEnvironmentVariables(UserName);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString TSessionData::GetUserNameSource()
 
- {
 
-   UnicodeString Result;
 
-   if (UserName != UserNameExpanded)
 
-   {
 
-     Result = UserName;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPassword(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, UserName+HostName);
 
-   SET_SESSION_PROPERTY(Password);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetPassword() const
 
- {
 
-   return DecryptPassword(FPassword, UserName+HostName);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetNewPassword(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, UserName+HostName);
 
-   SET_SESSION_PROPERTY(NewPassword);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetNewPassword() const
 
- {
 
-   return DecryptPassword(FNewPassword, UserName+HostName);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetChangePassword(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ChangePassword);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPingInterval(int value)
 
- {
 
-   SET_SESSION_PROPERTY(PingInterval);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTryAgent(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(TryAgent);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAgentFwd(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AgentFwd);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAuthTIS(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AuthTIS);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAuthKI(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AuthKI);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAuthKIPassword(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AuthKIPassword);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAuthGSSAPI(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AuthGSSAPI);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAuthGSSAPIKEX(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(AuthGSSAPIKEX);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetGSSAPIFwdTGT(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(GSSAPIFwdTGT);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetChangeUsername(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ChangeUsername);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCompression(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(Compression);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSshProt(TSshProt value)
 
- {
 
-   SET_SESSION_PROPERTY(SshProt);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSsh2DES(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(Ssh2DES);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSshNoUserAuth(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(SshNoUserAuth);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetSshProtStr()
 
- {
 
-   return SshProtList[FSshProt];
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::GetUsesSsh()
 
- {
 
-   return IsSshProtocol(FSProtocol);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCipher(int Index, TCipher value)
 
- {
 
-   DebugAssert(Index >= 0 && Index < CIPHER_COUNT);
 
-   SET_SESSION_PROPERTY(Ciphers[Index]);
 
- }
 
- //---------------------------------------------------------------------
 
- TCipher __fastcall TSessionData::GetCipher(int Index) const
 
- {
 
-   DebugAssert(Index >= 0 && Index < CIPHER_COUNT);
 
-   return FCiphers[Index];
 
- }
 
- //---------------------------------------------------------------------
 
- template<class AlgoT>
 
- void __fastcall TSessionData::SetAlgoList(AlgoT * List, const AlgoT * DefaultList, const UnicodeString * Names,
 
-   int Count, AlgoT WarnAlgo, UnicodeString value)
 
- {
 
-   std::vector<bool> Used(Count); // initialized to false
 
-   std::vector<AlgoT> NewList(Count);
 
-   bool HasWarnAlgo = (WarnAlgo >= AlgoT());
 
-   const AlgoT * WarnPtr;
 
-   int WarnDefaultIndex;
 
-   if (!HasWarnAlgo)
 
-   {
 
-     WarnPtr = NULL;
 
-     WarnDefaultIndex = -1;
 
-   }
 
-   else
 
-   {
 
-     WarnPtr = std::find(DefaultList, DefaultList + Count, WarnAlgo);
 
-     DebugAssert(WarnPtr != NULL);
 
-     WarnDefaultIndex = (WarnPtr - DefaultList);
 
-   }
 
-   int Index = 0;
 
-   while (!value.IsEmpty())
 
-   {
 
-     UnicodeString AlgoStr = CutToChar(value, L',', true);
 
-     for (int Algo = 0; Algo < Count; Algo++)
 
-     {
 
-       if (!AlgoStr.CompareIC(Names[Algo]) &&
 
-           !Used[Algo] && DebugAlwaysTrue(Index < Count))
 
-       {
 
-         NewList[Index] = (AlgoT)Algo;
 
-         Used[Algo] = true;
 
-         Index++;
 
-         break;
 
-       }
 
-     }
 
-   }
 
-   if (HasWarnAlgo && !Used[WarnAlgo] && DebugAlwaysTrue(Index < Count))
 
-   {
 
-     NewList[Index] = WarnAlgo;
 
-     Used[WarnAlgo] = true;
 
-     Index++;
 
-   }
 
-   int WarnIndex = -1;
 
-   if (HasWarnAlgo)
 
-   {
 
-     WarnIndex = std::find(NewList.begin(), NewList.end(), WarnAlgo) - NewList.begin();
 
-   }
 
-   bool Priority = true;
 
-   for (int DefaultIndex = 0; (DefaultIndex < Count); DefaultIndex++)
 
-   {
 
-     AlgoT DefaultAlgo = DefaultList[DefaultIndex];
 
-     if (!Used[DefaultAlgo] && DebugAlwaysTrue(Index < Count))
 
-     {
 
-       int TargetIndex;
 
-       // Unused algs that are prioritized in the default list,
 
-       // should be merged before the existing custom list
 
-       if (Priority)
 
-       {
 
-         TargetIndex = DefaultIndex;
 
-       }
 
-       else
 
-       {
 
-         if (HasWarnAlgo && (DefaultIndex < WarnDefaultIndex))
 
-         {
 
-           TargetIndex = WarnIndex;
 
-         }
 
-         else
 
-         {
 
-           TargetIndex = Index;
 
-         }
 
-       }
 
-       NewList.insert(NewList.begin() + TargetIndex, DefaultAlgo);
 
-       DebugAssert(NewList.back() == AlgoT());
 
-       NewList.pop_back();
 
-       if (HasWarnAlgo && (TargetIndex <= WarnIndex))
 
-       {
 
-         WarnIndex++;
 
-       }
 
-       Index++;
 
-     }
 
-     else
 
-     {
 
-       Priority = false;
 
-     }
 
-   }
 
-   if (!std::equal(NewList.begin(), NewList.end(), List))
 
-   {
 
-     std::copy(NewList.begin(), NewList.end(), List);
 
-     Modify();
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCipherList(UnicodeString value)
 
- {
 
-   SetAlgoList(FCiphers, DefaultCipherList, CipherNames, CIPHER_COUNT, cipWarn, value);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetCipherList() const
 
- {
 
-   UnicodeString Result;
 
-   for (int Index = 0; Index < CIPHER_COUNT; Index++)
 
-   {
 
-     Result += UnicodeString(Index ? L"," : L"") + CipherNames[Cipher[Index]];
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetKex(int Index, TKex value)
 
- {
 
-   DebugAssert(Index >= 0 && Index < KEX_COUNT);
 
-   SET_SESSION_PROPERTY(Kex[Index]);
 
- }
 
- //---------------------------------------------------------------------
 
- TKex __fastcall TSessionData::GetKex(int Index) const
 
- {
 
-   DebugAssert(Index >= 0 && Index < KEX_COUNT);
 
-   return FKex[Index];
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetKexList(UnicodeString value)
 
- {
 
-   SetAlgoList(FKex, DefaultKexList, KexNames, KEX_COUNT, kexWarn, value);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetKexList() const
 
- {
 
-   UnicodeString Result;
 
-   for (int Index = 0; Index < KEX_COUNT; Index++)
 
-   {
 
-     Result += UnicodeString(Index ? L"," : L"") + KexNames[Kex[Index]];
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetHostKeys(int Index, THostKey value)
 
- {
 
-   DebugAssert(Index >= 0 && Index < HOSTKEY_COUNT);
 
-   SET_SESSION_PROPERTY(HostKeys[Index]);
 
- }
 
- //---------------------------------------------------------------------
 
- THostKey __fastcall TSessionData::GetHostKeys(int Index) const
 
- {
 
-   DebugAssert(Index >= 0 && Index < HOSTKEY_COUNT);
 
-   return FHostKeys[Index];
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetHostKeyList(UnicodeString value)
 
- {
 
-   SetAlgoList(FHostKeys, DefaultHostKeyList, HostKeyNames, HOSTKEY_COUNT, hkWarn, value);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetHostKeyList() const
 
- {
 
-   UnicodeString Result;
 
-   for (int Index = 0; Index < HOSTKEY_COUNT; Index++)
 
-   {
 
-     Result += UnicodeString(Index ? L"," : L"") + HostKeyNames[HostKeys[Index]];
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetGssLib(int Index, TGssLib value)
 
- {
 
-   DebugAssert(Index >= 0 && Index < GSSLIB_COUNT);
 
-   SET_SESSION_PROPERTY(GssLib[Index]);
 
- }
 
- //---------------------------------------------------------------------
 
- TGssLib __fastcall TSessionData::GetGssLib(int Index) const
 
- {
 
-   DebugAssert(Index >= 0 && Index < GSSLIB_COUNT);
 
-   return FGssLib[Index];
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetGssLibList(UnicodeString value)
 
- {
 
-   SetAlgoList(FGssLib, DefaultGssLibList, GssLibNames, GSSLIB_COUNT, TGssLib(-1), value);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetGssLibList() const
 
- {
 
-   UnicodeString Result;
 
-   for (int Index = 0; Index < GSSLIB_COUNT; Index++)
 
-   {
 
-     Result += UnicodeString(Index ? L"," : L"") + GssLibNames[GssLib[Index]];
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetGssLibCustom(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(GssLibCustom);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPublicKeyFile(UnicodeString value)
 
- {
 
-   if (FPublicKeyFile != value)
 
-   {
 
-     // PublicKeyFile is key for Passphrase encryption
 
-     UnicodeString XPassphrase = Passphrase;
 
-     // StripPathQuotes should not be needed as we do not feed quotes anymore
 
-     FPublicKeyFile = StripPathQuotes(value);
 
-     Modify();
 
-     Passphrase = XPassphrase;
 
-     Shred(XPassphrase);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPassphrase(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, PublicKeyFile);
 
-   SET_SESSION_PROPERTY(Passphrase);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetPassphrase() const
 
- {
 
-   return DecryptPassword(FPassphrase, PublicKeyFile);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetReturnVar(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ReturnVar);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetExitCode1IsError(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ExitCode1IsError);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetLookupUserGroups(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(LookupUserGroups);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetEOLType(TEOLType value)
 
- {
 
-   SET_SESSION_PROPERTY(EOLType);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTrimVMSVersions(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(TrimVMSVersions);
 
- }
 
- //---------------------------------------------------------------------------
 
- TDateTime __fastcall TSessionData::GetTimeoutDT()
 
- {
 
-   return SecToDateTime(Timeout);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTimeout(int value)
 
- {
 
-   SET_SESSION_PROPERTY(Timeout);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFSProtocol(TFSProtocol value)
 
- {
 
-   SET_SESSION_PROPERTY(FSProtocol);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetFSProtocolStr()
 
- {
 
-   DebugAssert(FSProtocol >= 0 && FSProtocol < FSPROTOCOL_COUNT);
 
-   return FSProtocolNames[FSProtocol];
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetDetectReturnVar(bool value)
 
- {
 
-   if (value != DetectReturnVar)
 
-   {
 
-     ReturnVar = value ? L"" : L"$?";
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TSessionData::GetDetectReturnVar()
 
- {
 
-   return ReturnVar.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetDefaultShell(bool value)
 
- {
 
-   if (value != DefaultShell)
 
-   {
 
-     Shell = value ? L"" : L"/bin/bash";
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TSessionData::GetDefaultShell()
 
- {
 
-   return Shell.IsEmpty();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPuttyProtocol(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(PuttyProtocol);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetNormalizedPuttyProtocol() const
 
- {
 
-   return DefaultStr(PuttyProtocol, PuttySshProtocol);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPingIntervalDT(TDateTime value)
 
- {
 
-   unsigned short hour, min, sec, msec;
 
-   value.DecodeTime(&hour, &min, &sec, &msec);
 
-   PingInterval = ((int)hour)*SecsPerHour + ((int)min)*SecsPerMin + sec;
 
- }
 
- //---------------------------------------------------------------------------
 
- TDateTime __fastcall TSessionData::GetPingIntervalDT()
 
- {
 
-   return SecToDateTime(PingInterval);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPingType(TPingType value)
 
- {
 
-   SET_SESSION_PROPERTY(PingType);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetAddressFamily(TAddressFamily value)
 
- {
 
-   SET_SESSION_PROPERTY(AddressFamily);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetRekeyData(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(RekeyData);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetRekeyTime(unsigned int value)
 
- {
 
-   SET_SESSION_PROPERTY(RekeyTime);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetDefaultSessionName()
 
- {
 
-   UnicodeString Result;
 
-   if (!HostName.IsEmpty() && !UserName.IsEmpty())
 
-   {
 
-     // If we ever choose to include port number,
 
-     // we have to escape IPv6 literals in HostName
 
-     Result = FORMAT(L"%s@%s", (UserName, HostName));
 
-   }
 
-   else if (!HostName.IsEmpty())
 
-   {
 
-     Result = HostName;
 
-   }
 
-   else
 
-   {
 
-     Result = L"session";
 
-   }
 
-   Result = MakeValidName(Result);
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetNameWithoutHiddenPrefix()
 
- {
 
-   UnicodeString Result = Name;
 
-   if (Hidden)
 
-   {
 
-     Result = Result.SubString(TNamedObjectList::HiddenPrefix.Length() + 1, Result.Length() - TNamedObjectList::HiddenPrefix.Length());
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasSessionName()
 
- {
 
-   return (!GetNameWithoutHiddenPrefix().IsEmpty() && (Name != DefaultName));
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetSessionName()
 
- {
 
-   UnicodeString Result;
 
-   if (HasSessionName())
 
-   {
 
-     Result = GetNameWithoutHiddenPrefix();
 
-   }
 
-   else
 
-   {
 
-     Result = DefaultSessionName;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::IsSecure()
 
- {
 
-   bool Result;
 
-   switch (FSProtocol)
 
-   {
 
-     case fsSCPonly:
 
-     case fsSFTP:
 
-     case fsSFTPonly:
 
-       Result = true;
 
-       break;
 
-     case fsFTP:
 
-     case fsWebDAV:
 
-     case fsS3:
 
-       Result = (Ftps != ftpsNone);
 
-       break;
 
-     default:
 
-       DebugFail();
 
-       break;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetProtocolUrl(bool HttpForWebDAV)
 
- {
 
-   UnicodeString Url;
 
-   switch (FSProtocol)
 
-   {
 
-     case fsSCPonly:
 
-       Url = ScpProtocol;
 
-       break;
 
-     default:
 
-       DebugFail();
 
-       // fallback
 
-     case fsSFTP:
 
-     case fsSFTPonly:
 
-       Url = SftpProtocol;
 
-       break;
 
-     case fsFTP:
 
-       if (Ftps == ftpsImplicit)
 
-       {
 
-         Url = FtpsProtocol;
 
-       }
 
-       else if ((Ftps == ftpsExplicitTls) || (Ftps == ftpsExplicitSsl))
 
-       {
 
-         Url = FtpesProtocol;
 
-       }
 
-       else
 
-       {
 
-         Url = FtpProtocol;
 
-       }
 
-       break;
 
-     case fsWebDAV:
 
-       if (HttpForWebDAV)
 
-       {
 
-         if (Ftps == ftpsImplicit)
 
-         {
 
-           Url = HttpsProtocol;
 
-         }
 
-         else
 
-         {
 
-           Url = HttpProtocol;
 
-         }
 
-       }
 
-       else
 
-       {
 
-         if (Ftps == ftpsImplicit)
 
-         {
 
-           Url = WebDAVSProtocol;
 
-         }
 
-         else
 
-         {
 
-           Url = WebDAVProtocol;
 
-         }
 
-       }
 
-       break;
 
-     case fsS3:
 
-       Url = S3Protocol;
 
-       break;
 
-   }
 
-   Url += ProtocolSeparator;
 
-   return Url;
 
- }
 
- //---------------------------------------------------------------------
 
- static bool HasIP6LiteralBrackets(const UnicodeString & HostName)
 
- {
 
-   return
 
-     (HostName.Length() >= 2) &&
 
-     (HostName[1] == L'[') &&
 
-     (HostName[HostName.Length()] == L']');
 
- }
 
- //---------------------------------------------------------------------
 
- static UnicodeString StripIP6LiteralBrackets(const UnicodeString & HostName)
 
- {
 
-   UnicodeString Result = HostName;
 
-   if (DebugAlwaysTrue(HasIP6LiteralBrackets(Result)))
 
-   {
 
-     Result = Result.SubString(2, Result.Length() - 2);
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall IsIPv6Literal(const UnicodeString & HostName)
 
- {
 
-   UnicodeString Buf = HostName;
 
-   if (HasIP6LiteralBrackets(Buf))
 
-   {
 
-     Buf = StripIP6LiteralBrackets(Buf);
 
-   }
 
-   int Colons = 0;
 
-   bool Result = true;
 
-   for (int Index = 1; Result && (Index <= Buf.Length()); Index++)
 
-   {
 
-     wchar_t C = Buf[Index];
 
-     if (C == L'%')
 
-     {
 
-       break;
 
-     }
 
-     else if (C == L':')
 
-     {
 
-       Colons++;
 
-     }
 
-     else
 
-     {
 
-       Result = IsHex(C);
 
-     }
 
-   }
 
-   Result = Result && (Colons >= 2);
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall EscapeIPv6Literal(const UnicodeString & IP)
 
- {
 
-   UnicodeString Result = IP;
 
-   if (!HasIP6LiteralBrackets(Result))
 
-   {
 
-     Result = L"[" + IP + L"]";
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- TStrings * __fastcall TSessionData::GetRawSettingsForUrl()
 
- {
 
-   std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
 
-   std::unique_ptr<TSessionData> SessionData(Clone());
 
-   SessionData->FSProtocol = FactoryDefaults->FSProtocol;
 
-   SessionData->HostName = FactoryDefaults->HostName;
 
-   SessionData->PortNumber = FactoryDefaults->PortNumber;
 
-   SessionData->UserName = FactoryDefaults->UserName;
 
-   SessionData->Password = FactoryDefaults->Password;
 
-   SessionData->Ftps = FactoryDefaults->Ftps;
 
-   SessionData->HostKey = FactoryDefaults->HostKey;
 
-   SessionData->CopyNonCoreData(FactoryDefaults.get());
 
-   // Cannot be decided in SaveToOptions as it does not have HostName and UserName, so it cannot calculate DefaultSessionName.
 
-   bool SaveName = HasSessionName() && (Name != DefaultSessionName);
 
-   return SessionData->SaveToOptions(FactoryDefaults.get(), SaveName, false);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::HasRawSettingsForUrl()
 
- {
 
-   std::unique_ptr<TStrings> RawSettings(GetRawSettingsForUrl());
 
-   return (RawSettings->Count > 0);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GenerateSessionUrl(unsigned int Flags)
 
- {
 
-   UnicodeString Url;
 
-   if (FLAGSET(Flags, sufSpecific))
 
-   {
 
-     Url += WinSCPProtocolPrefix;
 
-   }
 
-   Url += GetProtocolUrl(FLAGSET(Flags, sufHttpForWebDAV));
 
-   if (FLAGSET(Flags, sufUserName) && !UserNameExpanded.IsEmpty())
 
-   {
 
-     Url += EncodeUrlString(UserNameExpanded);
 
-     if (FLAGSET(Flags, sufPassword) && !Password.IsEmpty())
 
-     {
 
-       Url += L":" + EncodeUrlString(NormalizeString(Password));
 
-     }
 
-     if (FLAGSET(Flags, sufHostKey) && !HostKey.IsEmpty())
 
-     {
 
-       UnicodeString KeyName;
 
-       UnicodeString Fingerprint = HostKey;
 
-       NormalizeFingerprint(Fingerprint, KeyName);
 
-       UnicodeString S = Fingerprint;
 
-       if (!KeyName.IsEmpty())
 
-       {
 
-         S = KeyName + NormalizedFingerprintSeparator + S;
 
-       }
 
-       S = Base64ToUrlSafe(S); // Noop for MD5 (both in SSH host keys and TLS/SSL)
 
-       S = MD5ToUrlSafe(S); // TLS/SSL fingerprints
 
-       UnicodeString S2 = EncodeUrlString(S);
 
-       DebugAssert(S2 == S2); // There should be nothing left for encoding
 
-       Url +=
 
-         UnicodeString(UrlParamSeparator) + UrlHostKeyParamName +
 
-         UnicodeString(UrlParamValueSeparator) + S2;
 
-     }
 
-     if (FLAGSET(Flags, sufRawSettings))
 
-     {
 
-       std::unique_ptr<TStrings> RawSettings(GetRawSettingsForUrl());
 
-       for (int Index = 0; Index < RawSettings->Count; Index++)
 
-       {
 
-         Url +=
 
-           UnicodeString(UrlParamSeparator) +
 
-           UrlRawSettingsParamNamePrefix + EncodeUrlString(LowerCase(RawSettings->Names[Index])) +
 
-           UnicodeString(UrlParamValueSeparator) + EncodeUrlString(RawSettings->ValueFromIndex[Index]);
 
-       }
 
-     }
 
-     Url += L"@";
 
-   }
 
-   DebugAssert(!HostNameExpanded.IsEmpty());
 
-   if (IsIPv6Literal(HostNameExpanded))
 
-   {
 
-     Url += EscapeIPv6Literal(HostNameExpanded);
 
-   }
 
-   else
 
-   {
 
-     Url += EncodeUrlString(HostNameExpanded);
 
-   }
 
-   if (PortNumber != DefaultPort(FSProtocol, Ftps))
 
-   {
 
-     Url += L":" + IntToStr(PortNumber);
 
-   }
 
-   Url += L"/";
 
-   return Url;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString ScriptCommandOpenLink(TraceInitStr(ScriptCommandLink(L"open")));
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddSwitch(
 
-   UnicodeString & Result, const UnicodeString & Name, bool Rtf)
 
- {
 
-   Result += RtfSwitch(Name, ScriptCommandOpenLink, Rtf);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddSwitch(
 
-   UnicodeString & Result, const UnicodeString & Name, const UnicodeString & Value, bool Rtf)
 
- {
 
-   Result += RtfSwitch(Name, ScriptCommandOpenLink, Value, Rtf);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddSwitch(
 
-   UnicodeString & Result, const UnicodeString & Name, int Value, bool Rtf)
 
- {
 
-   Result += RtfSwitch(Name, ScriptCommandOpenLink, Value, Rtf);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::LookupLastFingerprint()
 
- {
 
-   UnicodeString FingerprintType;
 
-   if (IsSshProtocol(FSProtocol))
 
-   {
 
-     FingerprintType = SshFingerprintType;
 
-   }
 
-   else if (Ftps != ftpsNone)
 
-   {
 
-     FingerprintType = TlsFingerprintType;
 
-   }
 
-   if (!FingerprintType.IsEmpty())
 
-   {
 
-     HostKey = Configuration->LastFingerprint(SiteKey, FingerprintType);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GenerateOpenCommandArgs(bool Rtf)
 
- {
 
-   std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
 
-   std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
 
-   SessionData->Assign(this);
 
-   UnicodeString Result = SessionData->GenerateSessionUrl(sufOpen);
 
-   // Before we reset the FSProtocol
 
-   bool AUsesSsh = SessionData->UsesSsh;
 
-   // SFTP-only is not reflected by the protocol prefix, we have to use rawsettings for that
 
-   if (SessionData->FSProtocol != fsSFTPonly)
 
-   {
 
-     SessionData->FSProtocol = FactoryDefaults->FSProtocol;
 
-   }
 
-   SessionData->HostName = FactoryDefaults->HostName;
 
-   SessionData->PortNumber = FactoryDefaults->PortNumber;
 
-   SessionData->UserName = FactoryDefaults->UserName;
 
-   SessionData->Password = FactoryDefaults->Password;
 
-   SessionData->CopyNonCoreData(FactoryDefaults.get());
 
-   SessionData->Ftps = FactoryDefaults->Ftps;
 
-   if (SessionData->HostKey != FactoryDefaults->HostKey)
 
-   {
 
-     UnicodeString SwitchName = AUsesSsh ? L"hostkey" : L"certificate";
 
-     AddSwitch(Result, SwitchName, SessionData->HostKey, Rtf);
 
-     SessionData->HostKey = FactoryDefaults->HostKey;
 
-   }
 
-   if (SessionData->PublicKeyFile != FactoryDefaults->PublicKeyFile)
 
-   {
 
-     AddSwitch(Result, L"privatekey", SessionData->PublicKeyFile, Rtf);
 
-     SessionData->PublicKeyFile = FactoryDefaults->PublicKeyFile;
 
-   }
 
-   if (SessionData->TlsCertificateFile != FactoryDefaults->TlsCertificateFile)
 
-   {
 
-     AddSwitch(Result, L"clientcert", SessionData->TlsCertificateFile, Rtf);
 
-     SessionData->TlsCertificateFile = FactoryDefaults->TlsCertificateFile;
 
-   }
 
-   if (SessionData->Passphrase != FactoryDefaults->Passphrase)
 
-   {
 
-     AddSwitch(Result, PassphraseOption, SessionData->Passphrase, Rtf);
 
-     SessionData->Passphrase = FactoryDefaults->Passphrase;
 
-   }
 
-   if (SessionData->FtpPasvMode != FactoryDefaults->FtpPasvMode)
 
-   {
 
-     AddSwitch(Result, L"passive", SessionData->FtpPasvMode ? 1 : 0, Rtf);
 
-     SessionData->FtpPasvMode = FactoryDefaults->FtpPasvMode;
 
-   }
 
-   if (SessionData->Timeout != FactoryDefaults->Timeout)
 
-   {
 
-     AddSwitch(Result, L"timeout", SessionData->Timeout, Rtf);
 
-     SessionData->Timeout = FactoryDefaults->Timeout;
 
-   }
 
-   std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false, false));
 
-   if (RawSettings->Count > 0)
 
-   {
 
-     AddSwitch(Result, RawSettingsOption, Rtf);
 
-     Result += StringsToParams(RawSettings.get());
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString SessionOptionsClassName(L"SessionOptions");
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddAssemblyProperty(
 
-   UnicodeString & Result, TAssemblyLanguage Language,
 
-   const UnicodeString & Name, const UnicodeString & Type,
 
-   const UnicodeString & Member)
 
- {
 
-   Result += AssemblyProperty(Language, SessionOptionsClassName, Name, Type, Member, false);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddAssemblyProperty(
 
-   UnicodeString & Result, TAssemblyLanguage Language,
 
-   const UnicodeString & Name, const UnicodeString & Value)
 
- {
 
-   Result += AssemblyProperty(Language, SessionOptionsClassName, Name, Value, false);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddAssemblyProperty(
 
-   UnicodeString & Result, TAssemblyLanguage Language,
 
-   const UnicodeString & Name, int Value)
 
- {
 
-   Result += AssemblyProperty(Language, SessionOptionsClassName, Name, Value, false);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::AddAssemblyProperty(
 
-   UnicodeString & Result, TAssemblyLanguage Language,
 
-   const UnicodeString & Name, bool Value)
 
- {
 
-   Result += AssemblyProperty(Language, SessionOptionsClassName, Name, Value, false);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::GenerateAssemblyCode(
 
-   TAssemblyLanguage Language, UnicodeString & Head, UnicodeString & Tail, int & Indent)
 
- {
 
-   std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
 
-   std::unique_ptr<TSessionData> SessionData(Clone());
 
-   switch (Language)
 
-   {
 
-     case alCSharp:
 
-     case alVBNET:
 
-       // noop
 
-       break;
 
-     case alPowerShell:
 
-       Head +=
 
-         AssemblyCommentLine(Language, LoadStr(CODE_PS_ADD_TYPE)) +
 
-         RtfKeyword(L"Add-Type") + RtfText(" -Path ") + AssemblyString(Language, "WinSCPnet.dll") + RtfPara +
 
-         RtfPara;
 
-       break;
 
-     default:
 
-       DebugFail();
 
-       break;
 
-   }
 
-   Head +=
 
-     AssemblyCommentLine(Language, LoadStr(CODE_SESSION_OPTIONS)) +
 
-     AssemblyNewClassInstanceStart(Language, SessionOptionsClassName, false);
 
-   UnicodeString ProtocolMember;
 
-   switch (SessionData->FSProtocol)
 
-   {
 
-     case fsSCPonly:
 
-       ProtocolMember = "Scp";
 
-       break;
 
-     default:
 
-       DebugFail();
 
-       // fallback
 
-     case fsSFTP:
 
-     case fsSFTPonly:
 
-       ProtocolMember = "Sftp";
 
-       break;
 
-     case fsFTP:
 
-       ProtocolMember = "Ftp";
 
-       break;
 
-     case fsWebDAV:
 
-       ProtocolMember = "Webdav";
 
-       break;
 
-     case fsS3:
 
-       ProtocolMember = "S3";
 
-       break;
 
-   }
 
-   // Before we reset the FSProtocol
 
-   bool AUsesSsh = SessionData->UsesSsh;
 
-   // Protocol is set unconditionally, we want even the default SFTP
 
-   AddAssemblyProperty(Head, Language, L"Protocol", L"Protocol", ProtocolMember);
 
-   // SFTP-only is not reflected by the protocol prefix, we have to use rawsettings for that
 
-   if (SessionData->FSProtocol != fsSFTPonly)
 
-   {
 
-     SessionData->FSProtocol = FactoryDefaults->FSProtocol;
 
-   }
 
-   if (SessionData->HostName != FactoryDefaults->HostName)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"HostName", HostName);
 
-     SessionData->HostName = FactoryDefaults->HostName;
 
-   }
 
-   int ADefaultPort = DefaultPort(FSProtocol, Ftps);
 
-   if (SessionData->PortNumber != ADefaultPort)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"PortNumber", PortNumber);
 
-   }
 
-   SessionData->PortNumber = FactoryDefaults->PortNumber;
 
-   if (SessionData->UserName != FactoryDefaults->UserName)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"UserName", UserName);
 
-     SessionData->UserName = FactoryDefaults->UserName;
 
-   }
 
-   if (SessionData->Password != FactoryDefaults->Password)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"Password", NormalizeString(Password));
 
-     SessionData->Password = FactoryDefaults->Password;
 
-   }
 
-   SessionData->CopyNonCoreData(FactoryDefaults.get());
 
-   if (SessionData->Ftps != FactoryDefaults->Ftps)
 
-   {
 
-     // SessionData->FSProtocol is reset already
 
-     switch (FSProtocol)
 
-     {
 
-       case fsFTP:
 
-         {
 
-           UnicodeString FtpSecureMember;
 
-           switch (SessionData->Ftps)
 
-           {
 
-             case ftpsNone:
 
-               // noop
 
-               break;
 
-             case ftpsImplicit:
 
-               FtpSecureMember = L"Implicit";
 
-               break;
 
-             case ftpsExplicitTls:
 
-             case ftpsExplicitSsl:
 
-               FtpSecureMember = L"Explicit";
 
-               break;
 
-             default:
 
-               DebugFail();
 
-               break;
 
-           }
 
-           AddAssemblyProperty(Head, Language, L"FtpSecure", L"FtpSecure", FtpSecureMember);
 
-         }
 
-         break;
 
-       case fsWebDAV:
 
-         AddAssemblyProperty(Head, Language, L"WebdavSecure", (SessionData->Ftps != ftpsNone));
 
-         break;
 
-       case fsS3:
 
-         // implicit
 
-         break;
 
-       default:
 
-         DebugFail();
 
-         break;
 
-     }
 
-     SessionData->Ftps = FactoryDefaults->Ftps;
 
-   }
 
-   if (SessionData->HostKey != FactoryDefaults->HostKey)
 
-   {
 
-     UnicodeString PropertyName = AUsesSsh ? L"SshHostKeyFingerprint" : L"TlsHostCertificateFingerprint";
 
-     AddAssemblyProperty(Head, Language, PropertyName, SessionData->HostKey);
 
-     SessionData->HostKey = FactoryDefaults->HostKey;
 
-   }
 
-   if (SessionData->PublicKeyFile != FactoryDefaults->PublicKeyFile)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"SshPrivateKeyPath", SessionData->PublicKeyFile);
 
-     SessionData->PublicKeyFile = FactoryDefaults->PublicKeyFile;
 
-   }
 
-   if (SessionData->TlsCertificateFile != FactoryDefaults->TlsCertificateFile)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"TlsClientCertificatePath", SessionData->TlsCertificateFile);
 
-     SessionData->TlsCertificateFile = FactoryDefaults->TlsCertificateFile;
 
-   }
 
-   if (SessionData->Passphrase != FactoryDefaults->Passphrase)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"PrivateKeyPassphrase", SessionData->Passphrase);
 
-     SessionData->Passphrase = FactoryDefaults->Passphrase;
 
-   }
 
-   if (SessionData->FtpPasvMode != FactoryDefaults->FtpPasvMode)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"FtpMode", L"FtpMode", (SessionData->FtpPasvMode ? L"Passive" : L"Active"));
 
-     SessionData->FtpPasvMode = FactoryDefaults->FtpPasvMode;
 
-   }
 
-   if (SessionData->Timeout != FactoryDefaults->Timeout)
 
-   {
 
-     AddAssemblyProperty(Head, Language, L"TimeoutInMilliseconds", SessionData->Timeout * 1000);
 
-     SessionData->Timeout = FactoryDefaults->Timeout;
 
-   }
 
-   Head += AssemblyNewClassInstanceEnd(Language, false);
 
-   std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false, false));
 
-   UnicodeString SessionOptionsVariableName = AssemblyVariableName(Language, SessionOptionsClassName);
 
-   if (RawSettings->Count > 0)
 
-   {
 
-     Head +=
 
-       RtfPara +
 
-       AssemblyAddRawSettings(Language, RawSettings.get(), SessionOptionsClassName, L"AddRawSettings");
 
-   }
 
-   Head += RtfPara;
 
-   UnicodeString Indentation = L"    ";
 
-   UnicodeString SessionVariableName = AssemblyVariableName(Language, SessionClassName);
 
-   UnicodeString RtfSessionClass = RtfLibraryClass(SessionClassName);
 
-   UnicodeString RtfSessionOpenMethod = RtfLibraryMethod(SessionClassName, L"Open", false);
 
-   UnicodeString NewSessionInstance = AssemblyNewClassInstance(Language, SessionClassName, false);
 
-   UnicodeString OpenCall =
 
-     Indentation + AssemblyCommentLine(Language, LoadStr(CODE_CONNECT)) +
 
-     Indentation + RtfText(SessionVariableName + L".") + RtfSessionOpenMethod + RtfText(L"(" + SessionOptionsVariableName + L")") +
 
-       AssemblyStatementSeparator(Language) + RtfPara;
 
-   switch (Language)
 
-   {
 
-     case alCSharp:
 
-       Head +=
 
-         RtfKeyword(L"using") + RtfText(" (") + NewSessionInstance + RtfText(L"())") + RtfPara +
 
-         RtfText(L"{") + RtfPara +
 
-         OpenCall;
 
-       Tail =
 
-         RtfText(L"}") + RtfPara;
 
-       break;
 
-     case alVBNET:
 
-       Head +=
 
-         RtfKeyword(L"Using") + RtfText(L" ") + NewSessionInstance + RtfPara +
 
-         OpenCall;
 
-       Tail =
 
-         RtfKeyword(L"End Using") + RtfPara;
 
-       break;
 
-     case alPowerShell:
 
-       Head +=
 
-         NewSessionInstance + RtfPara +
 
-         RtfPara +
 
-         RtfKeyword(L"try") + RtfPara +
 
-         RtfText(L"{") + RtfPara +
 
-         OpenCall;
 
-       Tail =
 
-         RtfText(L"}") + RtfPara +
 
-         RtfKeyword(L"finally") + RtfPara +
 
-         RtfText(L"{") + RtfPara +
 
-         RtfText(Indentation + SessionVariableName + L".") +
 
-           RtfLibraryMethod(SessionClassName, L"Dispose", false) + RtfText(L"()") + RtfPara +
 
-         RtfText(L"}") + RtfPara;
 
-       break;
 
-   }
 
-   Head += RtfPara;
 
-   Indent = 4; // the same for all languages so far
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTimeDifference(TDateTime value)
 
- {
 
-   SET_SESSION_PROPERTY(TimeDifference);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTimeDifferenceAuto(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(TimeDifferenceAuto);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetLocalDirectory(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(LocalDirectory);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetLocalDirectoryExpanded()
 
- {
 
-   return ExpandFileName(::ExpandEnvironmentVariables(LocalDirectory));
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetRemoteDirectory(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(RemoteDirectory);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSynchronizeBrowsing(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(SynchronizeBrowsing);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetUpdateDirectories(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(UpdateDirectories);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCacheDirectories(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(CacheDirectories);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCacheDirectoryChanges(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(CacheDirectoryChanges);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPreserveDirectoryChanges(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(PreserveDirectoryChanges);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetResolveSymlinks(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ResolveSymlinks);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFollowDirectorySymlinks(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(FollowDirectorySymlinks);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetDSTMode(TDSTMode value)
 
- {
 
-   SET_SESSION_PROPERTY(DSTMode);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetDeleteToRecycleBin(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(DeleteToRecycleBin);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetOverwrittenToRecycleBin(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(OverwrittenToRecycleBin);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetRecycleBinPath(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(RecycleBinPath);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPostLoginCommands(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(PostLoginCommands);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetLockInHome(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(LockInHome);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSpecial(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(Special);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetScp1Compatibility(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(Scp1Compatibility);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTcpNoDelay(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(TcpNoDelay);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSendBuf(int value)
 
- {
 
-   SET_SESSION_PROPERTY(SendBuf);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSourceAddress(const UnicodeString & value)
 
- {
 
-   SET_SESSION_PROPERTY(SourceAddress);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProtocolFeatures(const UnicodeString & value)
 
- {
 
-   SET_SESSION_PROPERTY(ProtocolFeatures);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSshSimple(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(SshSimple);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyMethod(TProxyMethod value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyMethod);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyHost(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyHost);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyPort(int value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyPort);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyUsername(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyUsername);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyPassword(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, ProxyUsername+ProxyHost);
 
-   SET_SESSION_PROPERTY(ProxyPassword);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetProxyPassword() const
 
- {
 
-   return DecryptPassword(FProxyPassword, ProxyUsername+ProxyHost);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyTelnetCommand(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyTelnetCommand);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyLocalCommand(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyLocalCommand);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyDNS(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyDNS);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetProxyLocalhost(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(ProxyLocalhost);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpProxyLogonType(int value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpProxyLogonType);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetBug(TSshBug Bug, TAutoSwitch value)
 
- {
 
-   DebugAssert(Bug >= 0 && static_cast<unsigned int>(Bug) < LENOF(FBugs));
 
-   SET_SESSION_PROPERTY(Bugs[Bug]);
 
- }
 
- //---------------------------------------------------------------------
 
- TAutoSwitch __fastcall TSessionData::GetBug(TSshBug Bug) const
 
- {
 
-   DebugAssert(Bug >= 0 && static_cast<unsigned int>(Bug) < LENOF(FBugs));
 
-   return FBugs[Bug];
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetPuttySettings(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(PuttySettings);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCustomParam1(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(CustomParam1);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetCustomParam2(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(CustomParam2);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPDownloadQueue(int value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPDownloadQueue);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPUploadQueue(int value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPUploadQueue);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPListingQueue(int value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPListingQueue);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPMaxVersion(int value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPMaxVersion);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPMaxPacketSize(unsigned long value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPMaxPacketSize);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPRealPath(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(SFTPRealPath);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSFTPBug(TSftpBug Bug, TAutoSwitch value)
 
- {
 
-   DebugAssert(Bug >= 0 && static_cast<unsigned int>(Bug) < LENOF(FSFTPBugs));
 
-   SET_SESSION_PROPERTY(SFTPBugs[Bug]);
 
- }
 
- //---------------------------------------------------------------------
 
- TAutoSwitch __fastcall TSessionData::GetSFTPBug(TSftpBug Bug) const
 
- {
 
-   DebugAssert(Bug >= 0 && static_cast<unsigned int>(Bug) < LENOF(FSFTPBugs));
 
-   return FSFTPBugs[Bug];
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSCPLsFullTime(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(SCPLsFullTime);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetColor(int value)
 
- {
 
-   SET_SESSION_PROPERTY(Color);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnel(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(Tunnel);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelHostName(UnicodeString value)
 
- {
 
-   if (FTunnelHostName != value)
 
-   {
 
-     // HostName is key for password encryption
 
-     UnicodeString XTunnelPassword = TunnelPassword;
 
-     int P = value.LastDelimiter(L"@");
 
-     if (P > 0)
 
-     {
 
-       TunnelUserName = value.SubString(1, P - 1);
 
-       value = value.SubString(P + 1, value.Length() - P);
 
-     }
 
-     FTunnelHostName = value;
 
-     Modify();
 
-     TunnelPassword = XTunnelPassword;
 
-     Shred(XTunnelPassword);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelPortNumber(int value)
 
- {
 
-   SET_SESSION_PROPERTY(TunnelPortNumber);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelUserName(UnicodeString value)
 
- {
 
-   // Avoid password recryption (what may popup master password prompt)
 
-   if (FTunnelUserName != value)
 
-   {
 
-     // TunnelUserName is key for password encryption
 
-     UnicodeString XTunnelPassword = TunnelPassword;
 
-     SET_SESSION_PROPERTY(TunnelUserName);
 
-     TunnelPassword = XTunnelPassword;
 
-     Shred(XTunnelPassword);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelPassword(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, TunnelUserName+TunnelHostName);
 
-   SET_SESSION_PROPERTY(TunnelPassword);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetTunnelPassword() const
 
- {
 
-   return DecryptPassword(FTunnelPassword, TunnelUserName+TunnelHostName);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelPublicKeyFile(UnicodeString value)
 
- {
 
-   if (FTunnelPublicKeyFile != value)
 
-   {
 
-     // StripPathQuotes should not be needed as we do not feed quotes anymore
 
-     FTunnelPublicKeyFile = StripPathQuotes(value);
 
-     Modify();
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelLocalPortNumber(int value)
 
- {
 
-   SET_SESSION_PROPERTY(TunnelLocalPortNumber);
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSessionData::GetTunnelAutoassignLocalPortNumber()
 
- {
 
-   return (FTunnelLocalPortNumber <= 0);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelPortFwd(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(TunnelPortFwd);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTunnelHostKey(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(TunnelHostKey);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpPasvMode(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpPasvMode);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpForcePasvIp(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpForcePasvIp);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpUseMlsd(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpUseMlsd);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpAccount(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpAccount);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpPingInterval(int value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpPingInterval);
 
- }
 
- //---------------------------------------------------------------------------
 
- TDateTime __fastcall TSessionData::GetFtpPingIntervalDT()
 
- {
 
-   return SecToDateTime(FtpPingInterval);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpPingType(TPingType value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpPingType);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpTransferActiveImmediately(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpTransferActiveImmediately);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtps(TFtps value)
 
- {
 
-   SET_SESSION_PROPERTY(Ftps);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetMinTlsVersion(TTlsVersion value)
 
- {
 
-   SET_SESSION_PROPERTY(MinTlsVersion);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetMaxTlsVersion(TTlsVersion value)
 
- {
 
-   SET_SESSION_PROPERTY(MaxTlsVersion);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSessionData::SetLogicalHostName(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(LogicalHostName);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpListAll(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpListAll);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpHost(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpHost);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetFtpWorkFromCwd(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(FtpWorkFromCwd);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetSslSessionReuse(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(SslSessionReuse);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetTlsCertificateFile(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(TlsCertificateFile);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetNotUtf(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(NotUtf);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetInternalEditorEncoding(int value)
 
- {
 
-   SET_SESSION_PROPERTY(InternalEditorEncoding);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetS3DefaultRegion(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(S3DefaultRegion);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetS3SessionToken(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(S3SessionToken);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetS3UrlStyle(TS3UrlStyle value)
 
- {
 
-   SET_SESSION_PROPERTY(S3UrlStyle);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetS3MaxKeys(TAutoSwitch value)
 
- {
 
-   SET_SESSION_PROPERTY(S3MaxKeys);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetIsWorkspace(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(IsWorkspace);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetLink(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(Link);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetNameOverride(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(NameOverride);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetHostKey(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(HostKey);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetNote(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(Note);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetWinTitle(UnicodeString value)
 
- {
 
-   SET_SESSION_PROPERTY(WinTitle);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetEncryptKey() const
 
- {
 
-   return DecryptPassword(FEncryptKey, UserName+HostName);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetEncryptKey(UnicodeString avalue)
 
- {
 
-   RawByteString value = EncryptPassword(avalue, UserName+HostName);
 
-   SET_SESSION_PROPERTY(EncryptKey);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::SetWebDavLiberalEscaping(bool value)
 
- {
 
-   SET_SESSION_PROPERTY(WebDavLiberalEscaping);
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetInfoTip()
 
- {
 
-   if (UsesSsh)
 
-   {
 
-     return FMTLOAD(SESSION_INFO_TIP2,
 
-         (HostName, UserName,
 
-          (PublicKeyFile.IsEmpty() ? LoadStr(NO_STR) : LoadStr(YES_STR)),
 
-          FSProtocolStr));
 
-   }
 
-   else
 
-   {
 
-     return FMTLOAD(SESSION_INFO_TIP_NO_SSH,
 
-       (HostName, UserName, FSProtocolStr));
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::ExtractLocalName(const UnicodeString & Name)
 
- {
 
-   UnicodeString Result = Name;
 
-   int P = Result.LastDelimiter(L"/");
 
-   if (P > 0)
 
-   {
 
-     Result.Delete(1, P);
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetLocalName()
 
- {
 
-   UnicodeString Result;
 
-   if (HasSessionName())
 
-   {
 
-     Result = ExtractLocalName(Name);
 
-   }
 
-   else
 
-   {
 
-     Result = DefaultSessionName;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::ExtractFolderName(const UnicodeString & Name)
 
- {
 
-   UnicodeString Result;
 
-   int P = Name.LastDelimiter(L"/");
 
-   if (P > 0)
 
-   {
 
-     Result = Name.SubString(1, P - 1);
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::GetFolderName()
 
- {
 
-   UnicodeString Result;
 
-   if (HasSessionName() || IsWorkspace)
 
-   {
 
-     Result = ExtractFolderName(Name);
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString __fastcall TSessionData::ComposePath(
 
-   const UnicodeString & Path, const UnicodeString & Name)
 
- {
 
-   return UnixIncludeTrailingBackslash(Path) + Name;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSessionData::DisableAuthentationsExceptPassword()
 
- {
 
-   SshNoUserAuth = false;
 
-   AuthTIS = false;
 
-   AuthKI = false;
 
-   AuthKIPassword = false;
 
-   AuthGSSAPI = false;
 
-   AuthGSSAPIKEX = false;
 
-   PublicKeyFile = L"";
 
-   TlsCertificateFile = L"";
 
-   Passphrase = L"";
 
-   TryAgent = false;
 
- }
 
- //---------------------------------------------------------------------
 
- TStrings * TSessionData::GetAllOptionNames(bool PuttyExport)
 
- {
 
-   std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
 
-   return FactoryDefaults->SaveToOptions(NULL, false, PuttyExport);
 
- }
 
- //=== TStoredSessionList ----------------------------------------------
 
- __fastcall TStoredSessionList::TStoredSessionList(bool aReadOnly):
 
-   TNamedObjectList(), FReadOnly(aReadOnly)
 
- {
 
-   DebugAssert(Configuration);
 
-   FDefaultSettings = new TSessionData(DefaultName);
 
-   FPendingRemovals.reset(new TStringList());
 
- }
 
- //---------------------------------------------------------------------
 
- __fastcall TStoredSessionList::~TStoredSessionList()
 
- {
 
-   DebugAssert(Configuration);
 
-   delete FDefaultSettings;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Load(THierarchicalStorage * Storage,
 
-   bool AsModified, bool UseDefaults, bool PuttyImport)
 
- {
 
-   TStringList *SubKeys = new TStringList();
 
-   TList * Loaded = new TList;
 
-   try
 
-   {
 
-     DebugAssert(AutoSort);
 
-     AutoSort = false;
 
-     bool WasEmpty = (Count == 0);
 
-     Storage->GetSubKeyNames(SubKeys);
 
-     for (int Index = 0; Index < SubKeys->Count; Index++)
 
-     {
 
-       UnicodeString SessionName = SubKeys->Strings[Index];
 
-       bool ValidName = true;
 
-       try
 
-       {
 
-         TSessionData::ValidatePath(SessionName);
 
-       }
 
-       catch(...)
 
-       {
 
-         ValidName = false;
 
-       }
 
-       if (ValidName)
 
-       {
 
-         TSessionData * SessionData;
 
-         if (SessionName == FDefaultSettings->Name)
 
-         {
 
-           SessionData = FDefaultSettings;
 
-         }
 
-         else
 
-         {
 
-           // if the list was empty before loading, do not waste time trying to
 
-           // find existing sites to overwrite (we rely on underlying storage
 
-           // to secure uniqueness of the key names)
 
-           if (WasEmpty)
 
-           {
 
-             SessionData = NULL;
 
-           }
 
-           else
 
-           {
 
-             SessionData = (TSessionData*)FindByName(SessionName);
 
-           }
 
-         }
 
-         if ((SessionData != FDefaultSettings) || !UseDefaults)
 
-         {
 
-           if (SessionData == NULL)
 
-           {
 
-             SessionData = new TSessionData(L"");
 
-             if (UseDefaults)
 
-             {
 
-               SessionData->CopyData(DefaultSettings);
 
-             }
 
-             SessionData->Name = SessionName;
 
-             Add(SessionData);
 
-           }
 
-           Loaded->Add(SessionData);
 
-           SessionData->Load(Storage, PuttyImport);
 
-           if (AsModified)
 
-           {
 
-             SessionData->Modified = true;
 
-           }
 
-         }
 
-       }
 
-     }
 
-     if (!AsModified)
 
-     {
 
-       for (int Index = 0; Index < TObjectList::Count; Index++)
 
-       {
 
-         if (Loaded->IndexOf(Items[Index]) < 0)
 
-         {
 
-           Delete(Index);
 
-           Index--;
 
-         }
 
-       }
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     AutoSort = true;
 
-     AlphaSort();
 
-     delete SubKeys;
 
-     delete Loaded;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Reload()
 
- {
 
-   if (Count <= Configuration->DontReloadMoreThanSessions)
 
-   {
 
-     bool SessionList = true;
 
-     std::unique_ptr<THierarchicalStorage> Storage(Configuration->CreateScpStorage(SessionList));
 
-     if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, False))
 
-     {
 
-       Load(Storage.get());
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::DoSave(THierarchicalStorage * Storage,
 
-   TSessionData * Data, bool All, bool RecryptPasswordOnly,
 
-   TSessionData * FactoryDefaults)
 
- {
 
-   if (All || Data->Modified)
 
-   {
 
-     if (RecryptPasswordOnly)
 
-     {
 
-       Data->SaveRecryptedPasswords(Storage);
 
-     }
 
-     else
 
-     {
 
-       Data->Save(Storage, false, FactoryDefaults);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::DoSave(THierarchicalStorage * Storage,
 
-   bool All, bool RecryptPasswordOnly, TStrings * RecryptPasswordErrors)
 
- {
 
-   TSessionData * FactoryDefaults = new TSessionData(L"");
 
-   try
 
-   {
 
-     while (FPendingRemovals->Count > 0)
 
-     {
 
-       TSessionData::Remove(Storage, FPendingRemovals->Strings[0]);
 
-       FPendingRemovals->Delete(0);
 
-     }
 
-     DoSave(Storage, FDefaultSettings, All, RecryptPasswordOnly, FactoryDefaults);
 
-     for (int Index = 0; Index < CountIncludingHidden; Index++)
 
-     {
 
-       TSessionData * SessionData = (TSessionData *)Items[Index];
 
-       try
 
-       {
 
-         DoSave(Storage, SessionData, All, RecryptPasswordOnly, FactoryDefaults);
 
-       }
 
-       catch (Exception & E)
 
-       {
 
-         UnicodeString Message;
 
-         if (RecryptPasswordOnly && DebugAlwaysTrue(RecryptPasswordErrors != NULL) &&
 
-             ExceptionMessage(&E, Message))
 
-         {
 
-           RecryptPasswordErrors->Add(FORMAT("%s: %s", (SessionData->SessionName, Message)));
 
-         }
 
-         else
 
-         {
 
-           throw;
 
-         }
 
-       }
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     delete FactoryDefaults;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Save(THierarchicalStorage * Storage, bool All)
 
- {
 
-   DoSave(Storage, All, false, NULL);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::DoSave(bool All, bool Explicit,
 
-   bool RecryptPasswordOnly, TStrings * RecryptPasswordErrors)
 
- {
 
-   bool SessionList = true;
 
-   THierarchicalStorage * Storage = Configuration->CreateScpStorage(SessionList);
 
-   try
 
-   {
 
-     Storage->AccessMode = smReadWrite;
 
-     Storage->Explicit = Explicit;
 
-     if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, true))
 
-     {
 
-       DoSave(Storage, All, RecryptPasswordOnly, RecryptPasswordErrors);
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     delete Storage;
 
-   }
 
-   Saved();
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Save(bool All, bool Explicit)
 
- {
 
-   DoSave(All, Explicit, false, NULL);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::RecryptPasswords(TStrings * RecryptPasswordErrors)
 
- {
 
-   DoSave(true, true, true, RecryptPasswordErrors);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Saved()
 
- {
 
-   FDefaultSettings->Modified = false;
 
-   for (int Index = 0; Index < CountIncludingHidden; Index++)
 
-   {
 
-     ((TSessionData *)Items[Index])->Modified = false;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportLevelFromFilezilla(
 
-   _di_IXMLNode Node, const UnicodeString & Path, _di_IXMLNode SettingsNode)
 
- {
 
-   for (int Index = 0; Index < Node->ChildNodes->Count; Index++)
 
-   {
 
-     _di_IXMLNode ChildNode = Node->ChildNodes->Get(Index);
 
-     if (ChildNode->NodeName == L"Server")
 
-     {
 
-       std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
 
-       SessionData->CopyData(DefaultSettings);
 
-       SessionData->ImportFromFilezilla(ChildNode, Path, SettingsNode);
 
-       Add(SessionData.release());
 
-     }
 
-     else if (ChildNode->NodeName == L"Folder")
 
-     {
 
-       UnicodeString Name;
 
-       for (int Index = 0; Index < ChildNode->ChildNodes->Count; Index++)
 
-       {
 
-         _di_IXMLNode PossibleTextMode = ChildNode->ChildNodes->Get(Index);
 
-         if (PossibleTextMode->NodeType == ntText)
 
-         {
 
-           UnicodeString NodeValue = PossibleTextMode->NodeValue;
 
-           AddToList(Name, NodeValue.Trim(), L" ");
 
-         }
 
-       }
 
-       Name = TSessionData::MakeValidName(Name).Trim();
 
-       ImportLevelFromFilezilla(ChildNode, TSessionData::ComposePath(Path, Name), SettingsNode);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportFromFilezilla(
 
-   const UnicodeString FileName, const UnicodeString ConfigurationFileName)
 
- {
 
-   // not sure if the document must exists if we want to use its node
 
-   _di_IXMLDocument ConfigurationDocument;
 
-   _di_IXMLNode SettingsNode;
 
-   if (FileExists(ApiPath(ConfigurationFileName)))
 
-   {
 
-     ConfigurationDocument = interface_cast<Xmlintf::IXMLDocument>(new TXMLDocument(NULL));
 
-     ConfigurationDocument->LoadFromFile(ConfigurationFileName);
 
-     _di_IXMLNode FileZilla3Node = ConfigurationDocument->ChildNodes->FindNode(L"FileZilla3");
 
-     if (FileZilla3Node != NULL)
 
-     {
 
-       SettingsNode = FileZilla3Node->ChildNodes->FindNode(L"Settings");
 
-     }
 
-   }
 
-   const _di_IXMLDocument Document = interface_cast<Xmlintf::IXMLDocument>(new TXMLDocument(NULL));
 
-   Document->LoadFromFile(FileName);
 
-   _di_IXMLNode FileZilla3Node = Document->ChildNodes->FindNode(L"FileZilla3");
 
-   if (FileZilla3Node != NULL)
 
-   {
 
-     _di_IXMLNode ServersNode = FileZilla3Node->ChildNodes->FindNode(L"Servers");
 
-     if (ServersNode != NULL)
 
-     {
 
-       ImportLevelFromFilezilla(ServersNode, L"", SettingsNode);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportFromKnownHosts(TStrings * Lines)
 
- {
 
-   bool SessionList = false;
 
-   std::unique_ptr<THierarchicalStorage> HostKeyStorage(Configuration->CreateScpStorage(SessionList));
 
-   std::unique_ptr<TStrings> KeyList(new TStringList());
 
-   if (OpenHostKeysSubKey(HostKeyStorage.get(), false))
 
-   {
 
-     HostKeyStorage->GetValueNames(KeyList.get());
 
-   }
 
-   HostKeyStorage.reset(NULL);
 
-   UnicodeString FirstError;
 
-   for (int Index = 0; Index < Lines->Count; Index++)
 
-   {
 
-     try
 
-     {
 
-       UnicodeString Line = Lines->Strings[Index];
 
-       Line = Trim(Line);
 
-       if (!Line.IsEmpty() && (Line[1] != L';'))
 
-       {
 
-         int P = Pos(L' ', Line);
 
-         if (P > 0)
 
-         {
 
-           UnicodeString HostNameStr = Line.SubString(1, P - 1);
 
-           Line = Line.SubString(P + 1, Line.Length() - P);
 
-           P = Pos(L',', HostNameStr);
 
-           if (P > 0)
 
-           {
 
-             HostNameStr.SetLength(P - 1);
 
-           }
 
-           P = Pos(L':', HostNameStr);
 
-           int PortNumber = -1;
 
-           if (P > 0)
 
-           {
 
-             UnicodeString PortNumberStr = HostNameStr.SubString(P + 1, HostNameStr.Length() - P);
 
-             PortNumber = StrToInt(PortNumberStr);
 
-             HostNameStr.SetLength(P - 1);
 
-           }
 
-           if (HasIP6LiteralBrackets(HostNameStr))
 
-           {
 
-             HostNameStr = StripIP6LiteralBrackets(HostNameStr);
 
-           }
 
-           UnicodeString NameStr = HostNameStr;
 
-           if (PortNumber >= 0)
 
-           {
 
-             NameStr = FORMAT(L"%s:%d", (NameStr, PortNumber));
 
-           }
 
-           std::unique_ptr<TSessionData> SessionDataOwner;
 
-           TSessionData * SessionData = dynamic_cast<TSessionData *>(FindByName(NameStr));
 
-           if (SessionData == NULL)
 
-           {
 
-             SessionData = new TSessionData(L"");
 
-             SessionDataOwner.reset(SessionData);
 
-             SessionData->CopyData(DefaultSettings);
 
-             SessionData->Name = NameStr;
 
-             SessionData->HostName = HostNameStr;
 
-             if (PortNumber >= 0)
 
-             {
 
-               SessionData->PortNumber = PortNumber;
 
-             }
 
-           }
 
-           const struct ssh_keyalg * Algorithm;
 
-           UnicodeString Key = ParseOpenSshPubLine(Line, Algorithm);
 
-           UnicodeString KeyKey =
 
-             FORMAT(L"%s@%d:%s", (Algorithm->cache_id, SessionData->PortNumber, HostNameStr));
 
-           UnicodeString HostKey =
 
-             FORMAT(L"%s:%s=%s", (Algorithm->ssh_id, KeyKey, Key));
 
-           UnicodeString HostKeyList = SessionData->HostKey;
 
-           AddToList(HostKeyList, HostKey, L";");
 
-           SessionData->HostKey = HostKeyList;
 
-           // If there's at least one unknown key type for this host, select it
 
-           if (KeyList->IndexOf(KeyKey) < 0)
 
-           {
 
-             SessionData->Selected = true;
 
-           }
 
-           if (SessionDataOwner.get() != NULL)
 
-           {
 
-             Add(SessionDataOwner.release());
 
-           }
 
-         }
 
-       }
 
-     }
 
-     catch (Exception & E)
 
-     {
 
-       if (FirstError.IsEmpty())
 
-       {
 
-         FirstError = E.Message;
 
-       }
 
-     }
 
-   }
 
-   if (Count == 0)
 
-   {
 
-     UnicodeString Message = LoadStr(KNOWN_HOSTS_NO_SITES);
 
-     if (!FirstError.IsEmpty())
 
-     {
 
-       Message = FORMAT(L"%s\n(%s)", (Message, FirstError));
 
-     }
 
-     throw Exception(Message);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Export(const UnicodeString FileName)
 
- {
 
-   THierarchicalStorage * Storage = TIniFileStorage::CreateFromPath(FileName);
 
-   try
 
-   {
 
-     Storage->AccessMode = smReadWrite;
 
-     if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, true))
 
-     {
 
-       Save(Storage, true);
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     delete Storage;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::SelectAll(bool Select)
 
- {
 
-   for (int Index = 0; Index < Count; Index++)
 
-     Sessions[Index]->Selected = Select;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Import(TStoredSessionList * From,
 
-   bool OnlySelected, TList * Imported)
 
- {
 
-   for (int Index = 0; Index < From->Count; Index++)
 
-   {
 
-     if (!OnlySelected || From->Sessions[Index]->Selected)
 
-     {
 
-       TSessionData *Session = new TSessionData(L"");
 
-       Session->Assign(From->Sessions[Index]);
 
-       Session->Modified = true;
 
-       Session->MakeUniqueIn(this);
 
-       Add(Session);
 
-       if (Imported != NULL)
 
-       {
 
-         Imported->Add(Session);
 
-       }
 
-     }
 
-   }
 
-   // only modified, explicit
 
-   Save(false, true);
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::SelectSessionsToImport
 
-   (TStoredSessionList * Dest, bool SSHOnly)
 
- {
 
-   for (int Index = 0; Index < Count; Index++)
 
-   {
 
-     Sessions[Index]->Selected =
 
-       (!SSHOnly || (Sessions[Index]->GetNormalizedPuttyProtocol() == PuttySshProtocol)) &&
 
-       !Dest->FindByName(Sessions[Index]->Name);
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::Cleanup()
 
- {
 
-   try
 
-   {
 
-     if (Configuration->Storage == stRegistry) Clear();
 
-     TRegistryStorage * Storage = new TRegistryStorage(Configuration->RegistryStorageKey);
 
-     try
 
-     {
 
-       Storage->AccessMode = smReadWrite;
 
-       if (Storage->OpenRootKey(False))
 
-         Storage->RecursiveDeleteSubKey(Configuration->StoredSessionsSubKey);
 
-     }
 
-     __finally
 
-     {
 
-       delete Storage;
 
-     }
 
-   }
 
-   catch (Exception &E)
 
-   {
 
-     throw ExtException(&E, LoadStr(CLEANUP_SESSIONS_ERROR));
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::UpdateStaticUsage()
 
- {
 
-   int SCP = 0;
 
-   int SFTP = 0;
 
-   int FTP = 0;
 
-   int FTPS = 0;
 
-   int WebDAV = 0;
 
-   int WebDAVS = 0;
 
-   int S3 = 0;
 
-   int Password = 0;
 
-   int Advanced = 0;
 
-   int Color = 0;
 
-   int Note = 0;
 
-   int Tunnel = 0;
 
-   bool Folders = false;
 
-   bool Workspaces = false;
 
-   std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
 
-   std::unique_ptr<TStringList> DifferentAdvancedProperties(CreateSortedStringList());
 
-   for (int Index = 0; Index < Count; Index++)
 
-   {
 
-     TSessionData * Data = Sessions[Index];
 
-     if (Data->IsWorkspace)
 
-     {
 
-       Workspaces = true;
 
-     }
 
-     else
 
-     {
 
-       switch (Data->FSProtocol)
 
-       {
 
-         case fsSCPonly:
 
-           SCP++;
 
-           break;
 
-         case fsSFTP:
 
-         case fsSFTPonly:
 
-           SFTP++;
 
-           break;
 
-         case fsFTP:
 
-           if (Data->Ftps == ftpsNone)
 
-           {
 
-             FTP++;
 
-           }
 
-           else
 
-           {
 
-             FTPS++;
 
-           }
 
-           break;
 
-         case fsWebDAV:
 
-           if (Data->Ftps == ftpsNone)
 
-           {
 
-             WebDAV++;
 
-           }
 
-           else
 
-           {
 
-             WebDAVS++;
 
-           }
 
-           break;
 
-         case fsS3:
 
-           S3++;
 
-           break;
 
-       }
 
-       if (Data->HasAnySessionPassword())
 
-       {
 
-         Password++;
 
-       }
 
-       if (Data->Color != 0)
 
-       {
 
-         Color++;
 
-       }
 
-       if (!Data->Note.IsEmpty())
 
-       {
 
-         Note++;
 
-       }
 
-       // This would not work for passwords, as they are compared in their encrypted form.
 
-       // But there are no passwords set in factory defaults anyway.
 
-       if (!Data->IsSame(FactoryDefaults.get(), true, DifferentAdvancedProperties.get(), false))
 
-       {
 
-         Advanced++;
 
-       }
 
-       if (Data->Tunnel)
 
-       {
 
-         Tunnel++;
 
-       }
 
-       if (!Data->FolderName.IsEmpty())
 
-       {
 
-         Folders = true;
 
-       }
 
-     }
 
-   }
 
-   Configuration->Usage->Set(L"StoredSessionsCountSCP", SCP);
 
-   Configuration->Usage->Set(L"StoredSessionsCountSFTP", SFTP);
 
-   Configuration->Usage->Set(L"StoredSessionsCountFTP", FTP);
 
-   Configuration->Usage->Set(L"StoredSessionsCountFTPS", FTPS);
 
-   Configuration->Usage->Set(L"StoredSessionsCountWebDAV", WebDAV);
 
-   Configuration->Usage->Set(L"StoredSessionsCountWebDAVS", WebDAVS);
 
-   Configuration->Usage->Set(L"StoredSessionsCountS3", S3);
 
-   Configuration->Usage->Set(L"StoredSessionsCountPassword", Password);
 
-   Configuration->Usage->Set(L"StoredSessionsCountColor", Color);
 
-   Configuration->Usage->Set(L"StoredSessionsCountNote", Note);
 
-   Configuration->Usage->Set(L"StoredSessionsCountAdvanced", Advanced);
 
-   DifferentAdvancedProperties->Delimiter = L',';
 
-   Configuration->Usage->Set(L"StoredSessionsAdvancedSettings", DifferentAdvancedProperties->DelimitedText);
 
-   Configuration->Usage->Set(L"StoredSessionsCountTunnel", Tunnel);
 
-   // actually default might be true, see below for when the default is actually used
 
-   bool CustomDefaultStoredSession = false;
 
-   try
 
-   {
 
-     // this can throw, when the default session settings have password set
 
-     // (and no other basic property, like hostname/username),
 
-     // and master password is enabled as we are called before master password
 
-     // handler is set
 
-     CustomDefaultStoredSession = !FDefaultSettings->IsSame(FactoryDefaults.get(), false);
 
-   }
 
-   catch (...)
 
-   {
 
-   }
 
-   Configuration->Usage->Set(L"UsingDefaultStoredSession", CustomDefaultStoredSession);
 
-   Configuration->Usage->Set(L"UsingStoredSessionsFolders", Folders);
 
-   Configuration->Usage->Set(L"UsingWorkspaces", Workspaces);
 
- }
 
- //---------------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::FindSame(TSessionData * Data)
 
- {
 
-   TSessionData * Result;
 
-   if (Data->Hidden || Data->Name.IsEmpty() || Data->IsWorkspace)
 
-   {
 
-     Result = NULL;
 
-   }
 
-   else
 
-   {
 
-     Result = dynamic_cast<TSessionData *>(FindByName(Data->Name));
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------------
 
- int __fastcall TStoredSessionList::IndexOf(TSessionData * Data)
 
- {
 
-   for (int Index = 0; Index < Count; Index++)
 
-     if (Data == Sessions[Index]) return Index;
 
-   return -1;
 
- }
 
- //---------------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::NewSession(
 
-   UnicodeString SessionName, TSessionData * Session)
 
- {
 
-   TSessionData * DuplicateSession = (TSessionData*)FindByName(SessionName);
 
-   if (!DuplicateSession)
 
-   {
 
-     DuplicateSession = new TSessionData(L"");
 
-     DuplicateSession->Assign(Session);
 
-     DuplicateSession->Name = SessionName;
 
-     // make sure, that new stored session is saved to registry
 
-     DuplicateSession->Modified = true;
 
-     Add(DuplicateSession);
 
-   }
 
-   else
 
-   {
 
-     DuplicateSession->Assign(Session);
 
-     DuplicateSession->Name = SessionName;
 
-     DuplicateSession->Modified = true;
 
-   }
 
-   // list was saved here before to default storage, but it would not allow
 
-   // to work with special lists (export/import) not using default storage
 
-   return DuplicateSession;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::SetDefaultSettings(TSessionData * value)
 
- {
 
-   DebugAssert(FDefaultSettings);
 
-   if (FDefaultSettings != value)
 
-   {
 
-     FDefaultSettings->Assign(value);
 
-     // make sure default settings are saved
 
-     FDefaultSettings->Modified = true;
 
-     FDefaultSettings->Name = DefaultName;
 
-     if (!FReadOnly)
 
-     {
 
-       // only modified, explicit
 
-       Save(false, true);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::OpenHostKeysSubKey(THierarchicalStorage * Storage, bool CanCreate)
 
- {
 
-   return
 
-     Storage->OpenRootKey(CanCreate) &&
 
-     Storage->OpenSubKey(Configuration->SshHostKeysSubKey, CanCreate);
 
- }
 
- //---------------------------------------------------------------------------
 
- THierarchicalStorage * __fastcall TStoredSessionList::CreateHostKeysStorageForWritting()
 
- {
 
-   bool SessionList = false;
 
-   std::unique_ptr<THierarchicalStorage> Storage(Configuration->CreateScpStorage(SessionList));
 
-   Storage->Explicit = true;
 
-   Storage->AccessMode = smReadWrite;
 
-   return Storage.release();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportHostKeys(
 
-   THierarchicalStorage * SourceStorage, THierarchicalStorage * TargetStorage, TStoredSessionList * Sessions, bool OnlySelected)
 
- {
 
-   if (OpenHostKeysSubKey(SourceStorage, false) &&
 
-       OpenHostKeysSubKey(TargetStorage, true))
 
-   {
 
-     std::auto_ptr<TStringList> KeyList(new TStringList());
 
-     SourceStorage->GetValueNames(KeyList.get());
 
-     DebugAssert(Sessions != NULL);
 
-     for (int Index = 0; Index < Sessions->Count; Index++)
 
-     {
 
-       TSessionData * Session = Sessions->Sessions[Index];
 
-       if (!OnlySelected || Session->Selected)
 
-       {
 
-         UnicodeString HostKeyName = PuttyMungeStr(FORMAT(L"@%d:%s", (Session->PortNumber, Session->HostNameExpanded)));
 
-         for (int KeyIndex = 0; KeyIndex < KeyList->Count; KeyIndex++)
 
-         {
 
-           UnicodeString KeyName = KeyList->Strings[KeyIndex];
 
-           if (EndsText(HostKeyName, KeyName))
 
-           {
 
-             TargetStorage->WriteStringRaw(KeyName, SourceStorage->ReadStringRaw(KeyName, L""));
 
-           }
 
-         }
 
-       }
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportHostKeys(
 
-   const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected)
 
- {
 
-   std::auto_ptr<THierarchicalStorage> TargetStorage(CreateHostKeysStorageForWritting());
 
-   std::auto_ptr<THierarchicalStorage> SourceStorage(new TRegistryStorage(SourceKey));
 
-   ImportHostKeys(SourceStorage.get(), TargetStorage.get(), Sessions, OnlySelected);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::ImportSelectedKnownHosts(TStoredSessionList * Sessions)
 
- {
 
-   std::unique_ptr<THierarchicalStorage> Storage(CreateHostKeysStorageForWritting());
 
-   if (OpenHostKeysSubKey(Storage.get(), true))
 
-   {
 
-     for (int Index = 0; Index < Sessions->Count; Index++)
 
-     {
 
-       TSessionData * Session = Sessions->Sessions[Index];
 
-       if (Session->Selected)
 
-       {
 
-         UnicodeString Algs;
 
-         UnicodeString HostKeys = Session->HostKey;
 
-         while (!HostKeys.IsEmpty())
 
-         {
 
-           UnicodeString HostKey = CutToChar(HostKeys, L';', true);
 
-           // skip alg
 
-           CutToChar(HostKey, L':', true);
 
-           UnicodeString Key = CutToChar(HostKey, L'=', true);
 
-           Storage->WriteStringRaw(Key, HostKey);
 
-         }
 
-       }
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::IsFolderOrWorkspace(
 
-   const UnicodeString & Name, bool Workspace)
 
- {
 
-   bool Result = false;
 
-   TSessionData * FirstData = NULL;
 
-   if (!Name.IsEmpty())
 
-   {
 
-     for (int Index = 0; !Result && (Index < Count); Index++)
 
-     {
 
-       Result = Sessions[Index]->IsInFolderOrWorkspace(Name);
 
-       if (Result)
 
-       {
 
-         FirstData = Sessions[Index];
 
-       }
 
-     }
 
-   }
 
-   return
 
-     Result &&
 
-     DebugAlwaysTrue(FirstData != NULL) &&
 
-     (FirstData->IsWorkspace == Workspace);
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::IsFolder(const UnicodeString & Name)
 
- {
 
-   return IsFolderOrWorkspace(Name, false);
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::IsWorkspace(const UnicodeString & Name)
 
- {
 
-   return IsFolderOrWorkspace(Name, true);
 
- }
 
- //---------------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::CheckIsInFolderOrWorkspaceAndResolve(
 
-   TSessionData * Data, const UnicodeString & Name)
 
- {
 
-   if (Data->IsInFolderOrWorkspace(Name))
 
-   {
 
-     Data = ResolveWorkspaceData(Data);
 
-     if ((Data != NULL) && Data->CanLogin &&
 
-         DebugAlwaysTrue(Data->Link.IsEmpty()))
 
-     {
 
-       return Data;
 
-     }
 
-   }
 
-   return NULL;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::GetFolderOrWorkspace(const UnicodeString & Name, TList * List)
 
- {
 
-   DoGetFolderOrWorkspace(Name, List, false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::DoGetFolderOrWorkspace(const UnicodeString & Name, TList * List, bool NoRecrypt)
 
- {
 
-   for (int Index = 0; (Index < Count); Index++)
 
-   {
 
-     TSessionData * RawData = Sessions[Index];
 
-     TSessionData * Data =
 
-       CheckIsInFolderOrWorkspaceAndResolve(RawData, Name);
 
-     if (Data != NULL)
 
-     {
 
-       TSessionData * Data2 = new TSessionData(L"");
 
-       if (NoRecrypt)
 
-       {
 
-         Data2->CopyDataNoRecrypt(Data);
 
-       }
 
-       else
 
-       {
 
-         Data2->Assign(Data);
 
-       }
 
-       if (!RawData->Link.IsEmpty() && (DebugAlwaysTrue(Data != RawData)) &&
 
-           // BACKWARD COMPATIBILITY
 
-           // When loading pre-5.6.4 workspace, that does not have state saved,
 
-           // do not overwrite the site "state" defaults
 
-           // with (empty) workspace state
 
-           RawData->HasStateData())
 
-       {
 
-         Data2->CopyStateData(RawData);
 
-       }
 
-       if (!RawData->NameOverride.IsEmpty())
 
-       {
 
-         Data2->Name = RawData->NameOverride;
 
-       }
 
-       else if (RawData->Link.IsEmpty() && RawData->IsWorkspace)
 
-       {
 
-         // Newly opened ad-hoc session has no name, so restore the workspace that way too.
 
-         // Otherwise we would persist the generated internal workspace name as a real name.
 
-         Data2->Name = UnicodeString();
 
-       }
 
-       List->Add(Data2);
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- TStrings * __fastcall TStoredSessionList::GetFolderOrWorkspaceList(
 
-   const UnicodeString & Name)
 
- {
 
-   std::unique_ptr<TObjectList> DataList(new TObjectList());
 
-   DoGetFolderOrWorkspace(Name, DataList.get(), true);
 
-   std::unique_ptr<TStringList> Result(new TStringList());
 
-   for (int Index = 0; (Index < DataList->Count); Index++)
 
-   {
 
-     Result->Add(dynamic_cast<TSessionData *>(DataList->Items[Index])->SessionName);
 
-   }
 
-   return Result.release();
 
- }
 
- //---------------------------------------------------------------------------
 
- TStrings * __fastcall TStoredSessionList::GetWorkspaces()
 
- {
 
-   std::unique_ptr<TStringList> Result(CreateSortedStringList());
 
-   for (int Index = 0; (Index < Count); Index++)
 
-   {
 
-     TSessionData * Data = Sessions[Index];
 
-     if (Data->IsWorkspace)
 
-     {
 
-       Result->Add(Data->FolderName);
 
-     }
 
-   }
 
-   return Result.release();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TStoredSessionList::NewWorkspace(
 
-   UnicodeString Name, TList * DataList)
 
- {
 
-   for (int Index = 0; (Index < Count); Index++)
 
-   {
 
-     TSessionData * Data = Sessions[Index];
 
-     if (Data->IsInFolderOrWorkspace(Name))
 
-     {
 
-       FPendingRemovals->Add(Data->Name);
 
-       Remove(Data);
 
-       Index--;
 
-     }
 
-   }
 
-   for (int Index = 0; (Index < DataList->Count); Index++)
 
-   {
 
-     TSessionData * Data = static_cast<TSessionData *>(DataList->Items[Index]);
 
-     TSessionData * Data2 = new TSessionData(L"");
 
-     Data2->Assign(Data);
 
-     Data2->Name = TSessionData::ComposePath(Name, Data->Name);
 
-     // make sure, that new stored session is saved to registry
 
-     Data2->Modified = true;
 
-     Add(Data2);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::HasAnyWorkspace()
 
- {
 
-   bool Result = false;
 
-   for (int Index = 0; !Result && (Index < Count); Index++)
 
-   {
 
-     TSessionData * Data = Sessions[Index];
 
-     Result = Data->IsWorkspace;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::ParseUrl(UnicodeString Url,
 
-   TOptions * Options, bool & DefaultsOnly, UnicodeString * FileName,
 
-   bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags)
 
- {
 
-   TSessionData * Data = new TSessionData(L"");
 
-   try
 
-   {
 
-     Data->ParseUrl(Url, Options, this, DefaultsOnly, FileName, AProtocolDefined, MaskedUrl, Flags);
 
-   }
 
-   catch(...)
 
-   {
 
-     delete Data;
 
-     throw;
 
-   }
 
-   return Data;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::IsUrl(UnicodeString Url)
 
- {
 
-   bool DefaultsOnly;
 
-   bool ProtocolDefined = false;
 
-   std::unique_ptr<TSessionData> ParsedData(ParseUrl(Url, NULL, DefaultsOnly, NULL, &ProtocolDefined));
 
-   bool Result = ProtocolDefined;
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::ResolveWorkspaceData(TSessionData * Data)
 
- {
 
-   if (!Data->Link.IsEmpty())
 
-   {
 
-     Data = dynamic_cast<TSessionData *>(FindByName(Data->Link));
 
-     if (Data != NULL)
 
-     {
 
-       Data = ResolveWorkspaceData(Data);
 
-     }
 
-   }
 
-   return Data;
 
- }
 
- //---------------------------------------------------------------------
 
- TSessionData * __fastcall TStoredSessionList::SaveWorkspaceData(TSessionData * Data, int Index)
 
- {
 
-   std::unique_ptr<TSessionData> Result(new TSessionData(L""));
 
-   TSessionData * SameData = StoredSessions->FindSame(Data);
 
-   if (SameData != NULL)
 
-   {
 
-     Result->CopyStateData(Data);
 
-     Result->Link = Data->Name;
 
-   }
 
-   else
 
-   {
 
-     Result->Assign(Data);
 
-     Result->NameOverride = Data->Name;
 
-   }
 
-   Result->IsWorkspace = true;
 
-   Result->Name = IntToHex(Index, 4); // See HasSessionName()
 
-   return Result.release();
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TStoredSessionList::CanLogin(TSessionData * Data)
 
- {
 
-   Data = ResolveWorkspaceData(Data);
 
-   return (Data != NULL) && Data->CanLogin;
 
- }
 
- //---------------------------------------------------------------------
 
- UnicodeString GetExpandedLogFileName(UnicodeString LogFileName, TDateTime Started, TSessionData * SessionData)
 
- {
 
-   // StripPathQuotes should not be needed as we do not feed quotes anymore
 
-   UnicodeString ANewFileName = StripPathQuotes(ExpandEnvironmentVariables(LogFileName));
 
-   for (int Index = 1; Index < ANewFileName.Length(); Index++)
 
-   {
 
-     if (ANewFileName[Index] == L'!')
 
-     {
 
-       UnicodeString Replacement;
 
-       // keep consistent with TFileCustomCommand::PatternReplacement
 
-       switch (tolower(ANewFileName[Index + 1]))
 
-       {
 
-         case L'y':
 
-           Replacement = FormatDateTime(L"yyyy", Started);
 
-           break;
 
-         case L'm':
 
-           Replacement = FormatDateTime(L"mm", Started);
 
-           break;
 
-         case L'd':
 
-           Replacement = FormatDateTime(L"dd", Started);
 
-           break;
 
-         case L't':
 
-           Replacement = FormatDateTime(L"hhnnss", Started);
 
-           break;
 
-         case 'p':
 
-           Replacement = IntToStr(static_cast<int>(GetCurrentProcessId()));
 
-           break;
 
-         case L'@':
 
-           if (SessionData != NULL)
 
-           {
 
-             Replacement = MakeValidFileName(SessionData->HostNameExpanded);
 
-           }
 
-           else
 
-           {
 
-             Replacement = L"nohost";
 
-           }
 
-           break;
 
-         case L's':
 
-           if (SessionData != NULL)
 
-           {
 
-             Replacement = MakeValidFileName(SessionData->SessionName);
 
-           }
 
-           else
 
-           {
 
-             Replacement = L"nosession";
 
-           }
 
-           break;
 
-         case L'!':
 
-           Replacement = L"!";
 
-           break;
 
-         default:
 
-           Replacement = UnicodeString(L"!") + ANewFileName[Index + 1];
 
-           break;
 
-       }
 
-       ANewFileName.Delete(Index, 2);
 
-       ANewFileName.Insert(Replacement, Index);
 
-       Index += Replacement.Length() - 1;
 
-     }
 
-   }
 
-   return ANewFileName;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall IsSshProtocol(TFSProtocol FSProtocol)
 
- {
 
-   return
 
-     (FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP) ||
 
-     (FSProtocol == fsSCPonly);
 
- }
 
- //---------------------------------------------------------------------------
 
- int __fastcall DefaultPort(TFSProtocol FSProtocol, TFtps Ftps)
 
- {
 
-   int Result;
 
-   switch (FSProtocol)
 
-   {
 
-     case fsFTP:
 
-       if (Ftps == ftpsImplicit)
 
-       {
 
-         Result = FtpsImplicitPortNumber;
 
-       }
 
-       else
 
-       {
 
-         Result = FtpPortNumber;
 
-       }
 
-       break;
 
-     case fsWebDAV:
 
-     case fsS3:
 
-       if (Ftps == ftpsNone)
 
-       {
 
-         Result = HTTPPortNumber;
 
-       }
 
-       else
 
-       {
 
-         Result = HTTPSPortNumber;
 
-       }
 
-       break;
 
-     default:
 
-       if (IsSshProtocol(FSProtocol))
 
-       {
 
-         Result = SshPortNumber;
 
-       }
 
-       else
 
-       {
 
-         DebugFail();
 
-         Result = -1;
 
-       }
 
-       break;
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
 
  |