CustomScpExplorer.cpp 323 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. //---------------------------------------------------------------------------
  34. #pragma package(smart_init)
  35. #pragma link "CustomDirView"
  36. #pragma link "CustomUnixDirView"
  37. #pragma link "IEListView"
  38. #pragma link "NortonLikeListView"
  39. #pragma link "UnixDirView"
  40. #pragma link "CustomDriveView"
  41. #pragma link "UnixDriveView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "TB2Dock"
  44. #pragma link "TBXStatusBars"
  45. #pragma link "TB2Item"
  46. #pragma link "TB2Toolbar"
  47. #pragma link "ThemePageControl"
  48. #pragma link "PathLabel"
  49. #ifndef NO_RESOURCES
  50. #pragma resource "*.dfm"
  51. #endif
  52. //---------------------------------------------------------------------------
  53. #define SAVE_SELECTION(DIRVIEW) \
  54. UnicodeString FocusFile = L""; \
  55. UnicodeString LastFocusedFile = L""; \
  56. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  57. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  58. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  59. #define RESTORE_SELECTION(DIRVIEW) \
  60. if (!LastFocusedFile.IsEmpty() && \
  61. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  62. { \
  63. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  64. if (ItemToSelect) \
  65. { \
  66. DIRVIEW->ItemFocused = ItemToSelect; \
  67. DIRVIEW->ItemFocused->MakeVisible(False); \
  68. } \
  69. }
  70. //---------------------------------------------------------------------------
  71. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  72. static const int SessionPanelCount = 4;
  73. //---------------------------------------------------------------------------
  74. class TMutexGuard
  75. {
  76. public:
  77. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  78. int Timeout = 5000)
  79. {
  80. FMutex = NULL;
  81. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  82. if (WaitResult == WAIT_TIMEOUT)
  83. {
  84. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  85. }
  86. else
  87. {
  88. FMutex = AMutex;
  89. }
  90. }
  91. ~TMutexGuard()
  92. {
  93. if (FMutex != NULL)
  94. {
  95. ReleaseMutex(FMutex);
  96. }
  97. }
  98. private:
  99. HANDLE FMutex;
  100. };
  101. //---------------------------------------------------------------------------
  102. class TWindowLock
  103. {
  104. public:
  105. TWindowLock(TCustomScpExplorerForm * Form) :
  106. FForm(Form)
  107. {
  108. FForm->LockWindow();
  109. }
  110. ~TWindowLock()
  111. {
  112. FForm->UnlockWindow();
  113. }
  114. private:
  115. TCustomScpExplorerForm * FForm;
  116. };
  117. //---------------------------------------------------------------------------
  118. struct TTransferOperationParam
  119. {
  120. TTransferOperationParam();
  121. UnicodeString TargetDirectory;
  122. bool Temp;
  123. bool DragDrop;
  124. int Options;
  125. TAutoSwitch Queue;
  126. };
  127. //---------------------------------------------------------------------------
  128. TTransferOperationParam::TTransferOperationParam()
  129. {
  130. Temp = false;
  131. DragDrop = false;
  132. Options = 0;
  133. Queue = asAuto;
  134. }
  135. //---------------------------------------------------------------------------
  136. class TTransferPresetNoteData : public TObject
  137. {
  138. public:
  139. UnicodeString Message;
  140. };
  141. //---------------------------------------------------------------------------
  142. class TTerminalNoteData : public TObject
  143. {
  144. public:
  145. TTerminal * Terminal;
  146. };
  147. //---------------------------------------------------------------------------
  148. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  149. FFormRestored(false),
  150. TForm(Owner)
  151. {
  152. FCurrentSide = osRemote;
  153. FEverShown = false;
  154. FDocks = new TList();
  155. RestoreParams();
  156. ConfigurationChanged();
  157. RemoteDirView->Invalidate();
  158. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  159. NonVisualDataModule->ScpExplorer = this;
  160. FAutoOperation = false;
  161. FOnFileOperationFinished = NULL;
  162. FForceExecution = false;
  163. FIgnoreNextDialogChar = 0;
  164. FErrorList = NULL;
  165. FSynchronizeProgressForm = NULL;
  166. FProgressForm = NULL;
  167. FRefreshLocalDirectory = false;
  168. FRefreshRemoteDirectory = false;
  169. FDDMoveSlipped = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FEditorManager = new TEditorManager();
  201. FEditorManager->OnFileChange = ExecutedFileChanged;
  202. FEditorManager->OnFileReload = ExecutedFileReload;
  203. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  204. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  205. FLocalEditors = new TList();
  206. FQueueStatus = NULL;
  207. FQueueStatusSection = new TCriticalSection();
  208. FQueueStatusInvalidated = false;
  209. FQueueItemInvalidated = false;
  210. FQueueActedItem = NULL;
  211. FQueueController = new TQueueController(QueueView3);
  212. FUserActionTimer = new TTimer(this);
  213. FUserActionTimer->Enabled = false;
  214. FUserActionTimer->Interval = 10;
  215. FUserActionTimer->OnTimer = UserActionTimer;
  216. FNotes = new TStringList();
  217. FNoteTimer = new TTimer(this);
  218. FNoteTimer->Enabled = false;
  219. FNoteTimer->OnTimer = NoteTimer;
  220. FOnNoteClick = NULL;
  221. FOle32Library = LoadLibrary(L"Ole32.dll");
  222. FDragMoveCursor = FOle32Library != NULL ?
  223. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  224. UseSystemSettings(this);
  225. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  226. static_cast<TObject*>(GetComponent(fcTransferList)));
  227. DebugAssert(TransferList != NULL);
  228. FTransferListHoverIndex = -1;
  229. TransferList->OnChange = TransferListChange;
  230. TransferList->OnDrawItem = TransferListDrawItem;
  231. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  232. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  233. UseDesktopFont(SessionsPageControl);
  234. UpdateSessionsPageControlHeight();
  235. UseDesktopFont(RemoteDirView);
  236. UseDesktopFont(RemoteDriveView);
  237. UseDesktopFont(QueueView3);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. RemotePanelSplitter->ShowHint = true;
  243. UpdateImages();
  244. FCustomCommandMenu = CreateTBXPopupMenu(this);
  245. FCustomCommandLocalFileList = NULL;
  246. FCustomCommandRemoteFileList = NULL;
  247. FSessionColors = new TPngImageList(this);
  248. FSessionColors->ColorDepth = cd32Bit;
  249. AddFixedSessionImages();
  250. SessionsPageControl->Images = FSessionColors;
  251. QueueLabel->FocusControl = QueueView3;
  252. UpdateQueueLabel();
  253. FRemoteDirViewWasFocused = true;
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. // this has to be one of the very first things to do
  261. StopUpdateThread();
  262. SessionsPageControl->Images = NULL;
  263. SAFE_DESTROY(FSessionColors);
  264. SAFE_DESTROY(FSessionsDragDropFilesEx);
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SAFE_DESTROY(FHistoryMenu[0][0]);
  315. SAFE_DESTROY(FHistoryMenu[0][1]);
  316. SAFE_DESTROY(FHistoryMenu[1][0]);
  317. SAFE_DESTROY(FHistoryMenu[1][1]);
  318. if (FHiddenWindow != NULL)
  319. {
  320. DestroyWindow(FHiddenWindow);
  321. FHiddenWindow = NULL;
  322. }
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  326. {
  327. std::unique_ptr<TSessionData> Data;
  328. if (!Session.IsEmpty())
  329. {
  330. bool DefaultsOnly;
  331. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  332. }
  333. TTerminalManager * Manager = TTerminalManager::Instance();
  334. for (int Index = 0; Index < Manager->Count; Index++)
  335. {
  336. TTerminal * Terminal = Manager->Terminals[Index];
  337. if (Session.IsEmpty() ||
  338. Terminal->SessionData->IsSameSite(Data.get()))
  339. {
  340. if (Path.IsEmpty())
  341. {
  342. Terminal->ClearCaches();
  343. }
  344. else
  345. {
  346. Terminal->DirectoryModified(Path, true);
  347. }
  348. }
  349. }
  350. // We should flag a pending refresh for the background terminals or busy foreground terminals
  351. if ((Terminal != NULL) && Terminal->Active &&
  352. CanCommandLineFromAnotherInstance() &&
  353. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  354. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  355. {
  356. Terminal->ReloadDirectory();
  357. }
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  361. {
  362. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  363. size_t MessageSize = sizeof(TCopyDataMessage);
  364. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  365. if (Result)
  366. {
  367. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  368. Result = (Message.Version == TCopyDataMessage::Version1);
  369. if (Result)
  370. {
  371. switch (Message.Command)
  372. {
  373. case TCopyDataMessage::CommandCanCommandLine:
  374. Result = CanCommandLineFromAnotherInstance();
  375. break;
  376. case TCopyDataMessage::CommandCommandLine:
  377. {
  378. UnicodeString CommandLine(Message.CommandLine);
  379. Result = CommandLineFromAnotherInstance(CommandLine);
  380. }
  381. break;
  382. case TCopyDataMessage::RefreshPanel:
  383. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  384. break;
  385. case TCopyDataMessage::MainWindowCheck:
  386. Result = true;
  387. break;
  388. default:
  389. Result = false;
  390. break;
  391. }
  392. }
  393. }
  394. Message.Result = Result ? 1 : 0;
  395. }
  396. //---------------------------------------------------------------------------
  397. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  398. {
  399. WNDCLASS WindowClass = {0};
  400. WindowClass.lpfnWndProc = DefWindowProc;
  401. WindowClass.hInstance = HInstance;
  402. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  403. FHiddenWindow = NULL;
  404. if (RegisterClass(&WindowClass))
  405. {
  406. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  407. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  408. }
  409. }
  410. //---------------------------------------------------------------------------
  411. bool __fastcall TCustomScpExplorerForm::CanConsole()
  412. {
  413. return (Terminal != NULL) && (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  414. }
  415. //---------------------------------------------------------------------------
  416. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  417. {
  418. bool Result = Visible && !NonVisualDataModule->Busy;
  419. return Result;
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  423. const UnicodeString & CommandLine)
  424. {
  425. TProgramParams Params(CommandLine);
  426. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  427. if (Result)
  428. {
  429. NonVisualDataModule->StartBusy();
  430. try
  431. {
  432. // this action is initiated from another process,
  433. // so it's likely that our window is not visible,
  434. // and user won't see what is going on
  435. Application->BringToFront();
  436. // reload sessions as we may be asked to open a session
  437. // just stored by another instance
  438. StoredSessions->Reload();
  439. UnicodeString SessionName = Params.Param[1];
  440. std::unique_ptr<TObjectList> DataList(new TObjectList());
  441. UnicodeString DownloadFile; // unused
  442. try
  443. {
  444. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  445. }
  446. catch (EAbort &)
  447. {
  448. // Happens when opening session in PuTTY and in other situations,
  449. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  450. // to process the command-line on its own (or to pass it to yet another instance)
  451. }
  452. if (DataList->Count > 0)
  453. {
  454. TTerminalManager * Manager = TTerminalManager::Instance();
  455. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  456. }
  457. }
  458. __finally
  459. {
  460. NonVisualDataModule->EndBusy();
  461. }
  462. }
  463. return Result;
  464. }
  465. //---------------------------------------------------------------------------
  466. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  467. {
  468. if (FTerminal != value)
  469. {
  470. TerminalChanging();
  471. FTerminal = value;
  472. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  473. FAllowTransferPresetAutoSelect = false;
  474. try
  475. {
  476. TerminalChanged();
  477. }
  478. __finally
  479. {
  480. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  481. }
  482. if (Terminal != NULL)
  483. {
  484. TransferPresetAutoSelect();
  485. }
  486. }
  487. }
  488. //---------------------------------------------------------------------------
  489. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  490. {
  491. if (FTerminal != NULL)
  492. {
  493. UpdateTerminal(Terminal);
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  498. {
  499. RemoteDirView->Terminal = Terminal;
  500. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  501. TManagedTerminal * ManagedTerminal = NULL;
  502. if (Terminal != NULL)
  503. {
  504. if (Terminal->Active)
  505. {
  506. Terminal->RefreshDirectory();
  507. }
  508. ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  509. DebugAssert(ManagedTerminal != NULL);
  510. if (WinConfiguration->PreservePanelState)
  511. {
  512. if (ManagedTerminal->RemoteExplorerState != NULL)
  513. {
  514. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  515. }
  516. else
  517. {
  518. RemoteDirView->ClearState();
  519. }
  520. }
  521. InitStatusBar();
  522. }
  523. DoTerminalListChanged();
  524. if (ManagedTerminal != NULL)
  525. {
  526. // this has to be set only after the tab is switched from DoTerminalListChanged,
  527. // otherwise we are changing color of wrong tab
  528. SessionColor = (TColor)ManagedTerminal->StateData->Color;
  529. }
  530. UpdateTransferList();
  531. // Update panels Enable state before refreshing the labels
  532. UpdateControls();
  533. }
  534. //---------------------------------------------------------------------------
  535. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  536. {
  537. if (Queue != value)
  538. {
  539. if (FQueue != NULL)
  540. {
  541. FQueue->OnListUpdate = NULL;
  542. FQueue->OnQueueItemUpdate = NULL;
  543. }
  544. FQueue = value;
  545. if (FQueue != NULL)
  546. {
  547. DebugAssert(FQueue->OnListUpdate == NULL);
  548. FQueue->OnListUpdate = QueueListUpdate;
  549. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  550. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  551. }
  552. QueueChanged();
  553. }
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  557. TListItem * Item)
  558. {
  559. if (FQueueActedItem == Item)
  560. {
  561. FQueueActedItem = NULL;
  562. if ((QueueView3->PopupMenu != NULL) &&
  563. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  564. {
  565. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  566. ReleaseCapture();
  567. }
  568. }
  569. if (Item->Data == FPendingQueueActionItem)
  570. {
  571. FPendingQueueActionItem = NULL;
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  576. {
  577. {
  578. TGuard Guard(FQueueStatusSection);
  579. FQueueStatusInvalidated = false;
  580. if (FQueue != NULL)
  581. {
  582. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  583. }
  584. }
  585. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  586. {
  587. FMaxQueueLength = FQueueStatus->Count;
  588. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  589. }
  590. FQueueController->UpdateQueueStatus(FQueueStatus);
  591. SetQueueProgress();
  592. UpdateQueueView();
  593. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  594. if (IsEmpty && (Terminal != NULL))
  595. {
  596. TOnceDoneOperation OnceDoneOperation =
  597. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  598. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  599. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  600. {
  601. FQueue->Enabled = false;
  602. }
  603. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  604. {
  605. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  606. }
  607. }
  608. }
  609. //---------------------------------------------------------------------------
  610. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  611. {
  612. UnicodeString Result;
  613. if (FQueueStatus != NULL)
  614. {
  615. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  616. {
  617. TFileOperationProgressType * ProgressData =
  618. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  619. if ((ProgressData != NULL) && ProgressData->InProgress)
  620. {
  621. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  622. }
  623. }
  624. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  625. {
  626. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  627. }
  628. }
  629. return Result;
  630. }
  631. //---------------------------------------------------------------------------
  632. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  633. {
  634. ComponentVisible[fcQueueView] =
  635. (WinConfiguration->QueueView.Show == qvShow) ||
  636. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  637. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TCustomScpExplorerForm::QueueChanged()
  641. {
  642. if (FQueueStatus != NULL)
  643. {
  644. delete FQueueStatus;
  645. FQueueStatus = NULL;
  646. }
  647. UpdateQueueStatus(true);
  648. }
  649. //---------------------------------------------------------------------------
  650. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  651. {
  652. if (FQueue == Queue)
  653. {
  654. FQueueStatusInvalidated = true;
  655. }
  656. }
  657. //---------------------------------------------------------------------------
  658. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  659. TQueueItem * Item)
  660. {
  661. if (FQueue == Queue)
  662. {
  663. TGuard Guard(FQueueStatusSection);
  664. // this may be running in parallel with QueueChanged
  665. if (FQueueStatus != NULL)
  666. {
  667. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  668. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  669. {
  670. FRefreshLocalDirectory = (QueueItem == NULL) ||
  671. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  672. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  673. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  674. }
  675. if (QueueItem != NULL)
  676. {
  677. QueueItem->UserData = (void*)true;
  678. FQueueItemInvalidated = true;
  679. }
  680. }
  681. }
  682. }
  683. //---------------------------------------------------------------------------
  684. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  685. {
  686. // during standalone editing, we have no way to see/control queue,
  687. // so we have to always popup prompts automatically
  688. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  692. {
  693. if (FQueueStatus != NULL)
  694. {
  695. bool QueueAutoPopup = IsQueueAutoPopup();
  696. bool NeedRefresh = FQueueController->NeedRefresh();
  697. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  698. FQueueItemInvalidated = false;
  699. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  700. bool Updated = false;
  701. TQueueItemProxy * QueueItem;
  702. bool WasUserAction;
  703. for (int Index = 0; Index < Limit; Index++)
  704. {
  705. bool Update = false;
  706. QueueItem = FQueueStatus->Items[Index];
  707. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  708. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  709. (FPendingQueueActionItem == NULL))
  710. {
  711. FPendingQueueActionItem = QueueItem;
  712. FUserActionTimer->Enabled = true;
  713. }
  714. if ((bool)QueueItem->UserData)
  715. {
  716. QueueItem->UserData = (void*)false;
  717. QueueItem->Update();
  718. Updated = true;
  719. Update = true;
  720. }
  721. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  722. {
  723. Update = true;
  724. }
  725. if (Update)
  726. {
  727. FQueueController->RefreshQueueItem(QueueItem);
  728. }
  729. }
  730. if (Updated)
  731. {
  732. NonVisualDataModule->UpdateNonVisibleActions();
  733. SetQueueProgress();
  734. }
  735. }
  736. }
  737. //---------------------------------------------------------------------------
  738. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  739. {
  740. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  741. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  742. }
  743. //---------------------------------------------------------------------------
  744. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  745. {
  746. if (ProgressData->Operation != foCalculateSize)
  747. {
  748. int OverallProgress;
  749. // FProgressForm is null when this is called from SetQueueProgress
  750. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  751. {
  752. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  753. }
  754. else
  755. {
  756. OverallProgress = ProgressData->OverallProgress();
  757. }
  758. // implies TBPF_NORMAL
  759. FTaskbarList->SetProgressValue(GetMainForm()->Handle, OverallProgress, 100);
  760. }
  761. else
  762. {
  763. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  764. }
  765. }
  766. //---------------------------------------------------------------------------
  767. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  768. {
  769. TTerminalManager::Instance()->QueueStatusUpdated();
  770. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  771. {
  772. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  773. {
  774. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  775. {
  776. TFileOperationProgressType * ProgressData = NULL;
  777. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  778. {
  779. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  780. }
  781. if ((ProgressData != NULL) &&
  782. ProgressData->InProgress)
  783. {
  784. SetTaskbarListProgressValue(ProgressData);
  785. }
  786. else
  787. {
  788. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  789. }
  790. }
  791. else
  792. {
  793. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  799. }
  800. }
  801. UpdateQueueLabel();
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  805. {
  806. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  807. if (FQueueStatus != NULL)
  808. {
  809. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  810. if (ActiveAndPendingPrimaryCount > 0)
  811. {
  812. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  813. }
  814. }
  815. QueueLabel->Caption = Caption;
  816. }
  817. //---------------------------------------------------------------------------
  818. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  819. {
  820. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  821. static_cast<TComponent*>(GetComponent(fcTransferList)));
  822. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  823. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  824. TransferList->Strings->BeginUpdate();
  825. try
  826. {
  827. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  828. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  829. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  830. if (FTransferDropDownHint.IsEmpty())
  831. {
  832. FTransferDropDownHint = TransferDropDown->Hint;
  833. }
  834. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  835. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  836. TransferDropDown->Text = StripHotkey(Name);
  837. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  838. (FTransferDropDownHint, StripHotkey(Name),
  839. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  840. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General))));
  841. // update the label, otherwise when it is updated only on the first draw
  842. // of the list, it is drawn "bold" for some reason
  843. FTransferListHoverIndex = TransferList->ItemIndex;
  844. UpdateTransferLabel();
  845. }
  846. __finally
  847. {
  848. TransferList->Strings->EndUpdate();
  849. }
  850. }
  851. //---------------------------------------------------------------------------
  852. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  853. {
  854. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  855. DebugAssert(Toolbar != NULL);
  856. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  857. }
  858. //---------------------------------------------------------------------------
  859. void __fastcall TCustomScpExplorerForm::UpdateActions()
  860. {
  861. TForm::UpdateActions();
  862. if (ComponentVisible[fcCustomCommandsBand])
  863. {
  864. UpdateCustomCommandsToolbar();
  865. }
  866. }
  867. //---------------------------------------------------------------------------
  868. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  869. {
  870. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  874. {
  875. DebugAssert(Configuration && RemoteDirView);
  876. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  877. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  878. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  879. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  880. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  881. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  882. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  883. {
  884. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  885. // selection is not redrawn automatically when RowSelect changes
  886. RemoteDirView->Invalidate();
  887. }
  888. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  889. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  890. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  891. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  892. UpdateSessionsPageControlHeight();
  893. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  894. UpdateToolbarDisplayMode();
  895. UpdateTransferList();
  896. if (Terminal != NULL)
  897. {
  898. TransferPresetAutoSelect();
  899. }
  900. UpdateQueueView();
  901. UpdateControls();
  902. // this can be called even before constuctor finishes.
  903. if (FEditorManager != NULL)
  904. {
  905. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  906. }
  907. // this can be called even before constuctor finishes.
  908. if (FLocalEditors != NULL)
  909. {
  910. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  911. {
  912. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  913. }
  914. }
  915. if (ComponentVisible[fcCustomCommandsBand])
  916. {
  917. UpdateCustomCommandsToolbar();
  918. }
  919. // show only when keeping queue items forever,
  920. // otherwise, its enough to have in in the context menu
  921. QueueDeleteAllDoneQueueToolbarItem->Visible =
  922. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  926. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  927. void * /*Arg*/)
  928. {
  929. if (Token != NULL)
  930. {
  931. TForm * Editor = dynamic_cast<TForm*>(Token);
  932. DebugAssert(Editor != NULL);
  933. ReconfigureEditorForm(Editor);
  934. }
  935. }
  936. //---------------------------------------------------------------------------
  937. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  938. {
  939. WinConfiguration->DDTransferConfirmation = asOn;
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  943. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  944. {
  945. // noop
  946. }
  947. //---------------------------------------------------------------------------
  948. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  949. TTransferDirection Direction, TTransferType Type, bool Temp,
  950. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  951. bool Confirm, bool DragDrop, int Options)
  952. {
  953. bool Result = true;
  954. DebugAssert(Terminal && Terminal->Active);
  955. // Temp means d&d here so far, may change in future!
  956. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  957. !WinConfiguration->DDAllowMove)
  958. {
  959. TMessageParams Params(mpNeverAskAgainCheck);
  960. unsigned int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  961. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  962. if (Answer == qaNeverAskAgain)
  963. {
  964. WinConfiguration->DDAllowMove = true;
  965. }
  966. else if (Answer == qaCancel)
  967. {
  968. Result = false;
  969. }
  970. }
  971. // these parameters are known in advance
  972. int Params =
  973. FLAGMASK(Type == ttMove, cpDelete);
  974. bool ToTemp = (Temp && (Direction == tdToLocal));
  975. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  976. {
  977. bool DisableNewerOnly =
  978. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  979. ToTemp;
  980. Options |=
  981. FLAGMASK(ToTemp, coTemp) |
  982. FLAGMASK(!Terminal->IsCapable[fsBackgroundTransfers], coDisableQueue) |
  983. coDoNotShowAgain;
  984. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  985. int CopyParamAttrs = (Direction == tdToRemote ?
  986. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  987. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  988. int OutputOptions =
  989. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  990. cooDoNotShowAgain);
  991. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  992. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  993. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  994. if (Result)
  995. {
  996. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  997. {
  998. if (DragDrop)
  999. {
  1000. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1001. {
  1002. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1003. NULL, 0, EnableDDTransferConfirmation, NULL);
  1004. }
  1005. WinConfiguration->DDTransferConfirmation = asOff;
  1006. }
  1007. else
  1008. {
  1009. WinConfiguration->ConfirmTransferring = false;
  1010. }
  1011. }
  1012. else
  1013. {
  1014. // User exclicitly unchecked "do not show again",
  1015. // so show him the dialog the next time
  1016. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1017. {
  1018. WinConfiguration->DDTransferConfirmation = asOn;
  1019. }
  1020. }
  1021. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1022. }
  1023. }
  1024. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fsBackgroundTransfers])
  1025. {
  1026. Configuration->Usage->Inc(L"TransfersOnBackground");
  1027. // these parameter are known only after transfer dialog
  1028. Params |=
  1029. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1030. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1031. Result = false;
  1032. ClearTransferSourceSelection(Direction);
  1033. }
  1034. return Result;
  1035. }
  1036. //---------------------------------------------------------------------------
  1037. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1038. {
  1039. if (FOnFileOperationFinished != NULL)
  1040. {
  1041. FOnFileOperationFinished(UnicodeString(), true);
  1042. }
  1043. else
  1044. {
  1045. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1046. if (HasDirView[Side])
  1047. {
  1048. DirView(Side)->SelectAll(smNone);
  1049. }
  1050. }
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1054. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1055. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1056. int Params)
  1057. {
  1058. DebugAssert(Queue != NULL);
  1059. bool SingleFile = false;
  1060. if (FileList->Count == 1)
  1061. {
  1062. if (Direction == tdToRemote)
  1063. {
  1064. UnicodeString FileName = FileList->Strings[0];
  1065. SingleFile = FileExists(ApiPath(FileName));
  1066. }
  1067. else
  1068. {
  1069. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1070. SingleFile = !File->IsDirectory;
  1071. }
  1072. }
  1073. TQueueItem * QueueItem;
  1074. if (Direction == tdToRemote)
  1075. {
  1076. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1077. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1078. }
  1079. else
  1080. {
  1081. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1082. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1083. }
  1084. AddQueueItem(Queue, QueueItem, Terminal);
  1085. }
  1086. //---------------------------------------------------------------------------
  1087. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1088. {
  1089. if (Queue->IsEmpty)
  1090. {
  1091. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1092. ManagedTerminal->QueueOperationStart = Now();
  1093. }
  1094. Queue->AddItem(QueueItem);
  1095. }
  1096. //---------------------------------------------------------------------------
  1097. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1098. {
  1099. }
  1100. //---------------------------------------------------------------------------
  1101. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1102. {
  1103. DebugAssert(FDocks != NULL);
  1104. for (int Index = 0; Index < ComponentCount; Index++)
  1105. {
  1106. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1107. if ((Dock != NULL) && (Dock->Tag == 0))
  1108. {
  1109. FDocks->Add(Dock);
  1110. }
  1111. }
  1112. CollectItemsWithTextDisplayMode(this);
  1113. ConfigurationChanged();
  1114. QueuePanel->Height =
  1115. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1116. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1117. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1118. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. void __fastcall TCustomScpExplorerForm::StoreParams()
  1122. {
  1123. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1124. WinConfiguration->QueueView.HeightPixelsPerInch = GetControlPixelsPerInch(this);
  1125. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1126. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1127. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1128. }
  1129. //---------------------------------------------------------------------------
  1130. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1131. {
  1132. if (!FFormRestored)
  1133. {
  1134. FFormRestored = true;
  1135. RestoreFormParams();
  1136. }
  1137. TForm::CreateParams(Params);
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1141. {
  1142. DebugAssert(FDocks != NULL);
  1143. for (int Index = 0; Index < FDocks->Count; Index++)
  1144. {
  1145. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1146. }
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1150. {
  1151. SetDockAllowDrag(true);
  1152. while (!ButtonsStr.IsEmpty())
  1153. {
  1154. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1155. UnicodeString Name = CutToChar(S, L'=', true);
  1156. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1157. {
  1158. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1159. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1160. {
  1161. while (!S.IsEmpty())
  1162. {
  1163. UnicodeString S2 = CutToChar(S, L',', true);
  1164. UnicodeString Name = CutToChar(S2, L':', true);
  1165. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1166. {
  1167. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1168. if (SameText(GetToolbarItemName(Item), Name))
  1169. {
  1170. // forward compatibility
  1171. UnicodeString S3 = CutToChar(S2, L':', true);
  1172. bool Visible = StrToIntDef(S3, 0);
  1173. Item->Visible = Visible;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. }
  1180. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1181. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1185. {
  1186. UnicodeString Result;
  1187. SetDockAllowDrag(true);
  1188. Result = ::GetToolbarsLayoutStr(this);
  1189. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1190. return Result;
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1194. {
  1195. UnicodeString Result;
  1196. if (Item->Action != NULL)
  1197. {
  1198. Result = Item->Action->Name;
  1199. Result = RemoveSuffix(Result, L"Action");
  1200. }
  1201. else
  1202. {
  1203. Result = Item->Name;
  1204. Result = RemoveSuffix(Result, L"SubmenuItem");
  1205. Result = RemoveSuffix(Result, L"Item");
  1206. }
  1207. return Result;
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1211. {
  1212. UnicodeString Result;
  1213. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1214. {
  1215. UnicodeString ToolbarStr;
  1216. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1217. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1218. {
  1219. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1220. {
  1221. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1222. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1223. // Once we introduce any buttons that aer hidden by default, we would have to remember their initial state
  1224. // and save the changes here only.
  1225. if (!Item->Visible)
  1226. {
  1227. UnicodeString Name = GetToolbarItemName(Item);
  1228. DebugAssert(Name.Pos(L"TBX") == 0);
  1229. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1230. }
  1231. }
  1232. }
  1233. if (!ToolbarStr.IsEmpty())
  1234. {
  1235. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1236. }
  1237. }
  1238. return Result;
  1239. }
  1240. //---------------------------------------------------------------------------
  1241. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1242. {
  1243. DebugAssert(FProgressForm == NULL);
  1244. FProgressForm =
  1245. new TProgressForm(Application, (FTransferResumeList != NULL), Terminal->IsCapable[fsSkipTransfer], SynchronizeProgress);
  1246. FProgressForm->DeleteLocalToRecycleBin =
  1247. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1248. FProgressForm->DeleteRemoteToRecycleBin =
  1249. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1250. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1251. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1252. LockWindow();
  1253. if (FTaskbarList != NULL)
  1254. {
  1255. // Actually, do not know what hides the progress once the operation finishes
  1256. SetTaskbarListProgressState(TBPF_NORMAL);
  1257. }
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1261. {
  1262. UnlockWindow();
  1263. SAFE_DESTROY(FProgressForm);
  1264. SetQueueProgress();
  1265. }
  1266. //---------------------------------------------------------------------------
  1267. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1268. TFileOperationProgressType & ProgressData)
  1269. {
  1270. // Download to temporary local directory
  1271. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1272. {
  1273. bool Continue = true;
  1274. FPendingTempSpaceWarn = false;
  1275. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1276. if (!Continue)
  1277. {
  1278. Abort();
  1279. }
  1280. }
  1281. // operation is being executed and we still didn't show up progress form
  1282. if (ProgressData.InProgress && !FProgressForm)
  1283. {
  1284. CreateProgressForm(NULL);
  1285. // When main window is hidden, synchronisation form does not exist (we do not get here during synchronization - only comparing),
  1286. // we suppose "/upload" or URL download mode
  1287. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1288. (ProgressData.Operation != foCalculateChecksum) &&
  1289. (FSynchronizeProgressForm == NULL) &&
  1290. !FStandaloneEditing)
  1291. {
  1292. FProgressForm->OnceDoneOperation = odoDisconnect;
  1293. }
  1294. }
  1295. // operation is finished (or terminated), so we hide progress form
  1296. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1297. {
  1298. DestroyProgressForm();
  1299. if (ProgressData.Operation == foCalculateSize)
  1300. {
  1301. // When calculating size before transfer, the abort caused by
  1302. // cancel flag set due to "MoveToQueue" below,
  1303. // is not propagated back to us in ExecuteFileOperation,
  1304. // as it is silently swallowed.
  1305. // So we explicitly (re)throw it here.
  1306. if (FMoveToQueue)
  1307. {
  1308. Abort();
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if ((ProgressData.Cancel == csContinue) &&
  1314. !FAutoOperation)
  1315. {
  1316. OperationComplete(ProgressData.StartTime);
  1317. }
  1318. }
  1319. }
  1320. if (FProgressForm &&
  1321. // Can happen only during synchronization, when ending one of the operations
  1322. ProgressData.InProgress)
  1323. {
  1324. FProgressForm->SetProgressData(ProgressData);
  1325. if (FTaskbarList != NULL)
  1326. {
  1327. DebugAssert(ProgressData.InProgress);
  1328. SetTaskbarListProgressValue(&ProgressData);
  1329. }
  1330. if (FProgressForm->Cancel > csContinue)
  1331. {
  1332. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1333. if (FProgressForm->Cancel == csCancelFile)
  1334. {
  1335. FProgressForm->ClearCancel();
  1336. }
  1337. // cancel cancels even the move
  1338. FMoveToQueue = false;
  1339. }
  1340. else if (FProgressForm->MoveToQueue)
  1341. {
  1342. FMoveToQueue = true;
  1343. ProgressData.SetCancelAtLeast(csCancel);
  1344. }
  1345. if ((FTransferResumeList != NULL) &&
  1346. ProgressData.InProgress &&
  1347. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1348. !ProgressData.FullFileName.IsEmpty())
  1349. {
  1350. if ((FTransferResumeList->Count == 0) ||
  1351. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1352. {
  1353. // note that we do not recognize directories from files here
  1354. FTransferResumeList->Add(ProgressData.FullFileName);
  1355. }
  1356. }
  1357. }
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1361. const TDateTime & StartTime)
  1362. {
  1363. if (GUIConfiguration->BeepOnFinish &&
  1364. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1365. {
  1366. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1367. DWORD Sound;
  1368. if (!ExtractFileExt(BeepSound).IsEmpty())
  1369. {
  1370. Sound = SND_FILENAME;
  1371. }
  1372. else
  1373. {
  1374. Sound = SND_ALIAS;
  1375. }
  1376. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1377. }
  1378. }
  1379. //---------------------------------------------------------------------------
  1380. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1381. TFileOperationProgressType & ProgressData)
  1382. {
  1383. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1384. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1385. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1386. FileOperationProgress(ProgressData);
  1387. }
  1388. //---------------------------------------------------------------------------
  1389. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1390. {
  1391. UnicodeString Result;
  1392. if (FProgressForm != NULL)
  1393. {
  1394. Result = FProgressForm->ProgressStr();
  1395. }
  1396. return Result;
  1397. }
  1398. //---------------------------------------------------------------------------
  1399. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1400. bool DragDrop)
  1401. {
  1402. return (!DragDrop && (DropSourceControl == NULL)) ||
  1403. (DropSourceControl == RemoteDirView);
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1407. TFileOperation Operation, TOperationSide Side,
  1408. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1409. TOnceDoneOperation & OnceDoneOperation)
  1410. {
  1411. if (!FAutoOperation)
  1412. {
  1413. // no selection on "/upload", form servers only as event handler
  1414. // (it is not displayed)
  1415. if (PanelOperation(Side, FDragDropOperation) &&
  1416. Visible && (Operation != foCalculateSize) &&
  1417. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1418. {
  1419. if (FOnFileOperationFinished != NULL)
  1420. {
  1421. FOnFileOperationFinished(FileName, Success);
  1422. }
  1423. else
  1424. {
  1425. TCustomDirView * DView = DirView(Side);
  1426. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1427. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1428. // this can happen when local drive is unplugged in the middle of the operation
  1429. if (Item != NULL)
  1430. {
  1431. if (Success) Item->Selected = false;
  1432. DView->MakeProgressVisible(Item);
  1433. }
  1434. }
  1435. }
  1436. if ((Operation == foCopy) || (Operation == foMove))
  1437. {
  1438. if (Side == osLocal)
  1439. {
  1440. Configuration->Usage->Inc(L"UploadedFiles");
  1441. }
  1442. else
  1443. {
  1444. Configuration->Usage->Inc(L"DownloadedFiles");
  1445. }
  1446. }
  1447. }
  1448. if (Success && (FSynchronizeController != NULL))
  1449. {
  1450. if (Operation == foCopy)
  1451. {
  1452. DebugAssert(Side == osLocal);
  1453. FSynchronizeController->LogOperation(soUpload, FileName);
  1454. }
  1455. else if (Operation == foDelete)
  1456. {
  1457. DebugAssert(Side == osRemote);
  1458. FSynchronizeController->LogOperation(soDelete, FileName);
  1459. }
  1460. }
  1461. if (FProgressForm)
  1462. {
  1463. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1464. }
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1468. TFileOperation Operation, TOperationSide Side,
  1469. bool Temp, const UnicodeString & FileName, Boolean Success,
  1470. TOnceDoneOperation & OnceDoneOperation)
  1471. {
  1472. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1473. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1474. OnceDoneOperation);
  1475. }
  1476. //---------------------------------------------------------------------------
  1477. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1478. {
  1479. DebugAssert(GetSide(Side) == osRemote);
  1480. DebugUsedParam(Side);
  1481. return RemoteDirView;
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1485. {
  1486. DebugAssert(GetSide(Side) == osRemote);
  1487. DebugUsedParam(Side);
  1488. return (Terminal != NULL);
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1492. TOperationSide Side, int FilesOnly)
  1493. {
  1494. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1495. }
  1496. //---------------------------------------------------------------------------
  1497. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1498. TOperationSide Side, int FilesOnly)
  1499. {
  1500. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. struct THistoryItemData
  1504. {
  1505. short int Side;
  1506. short int Index;
  1507. };
  1508. //---------------------------------------------------------------------------
  1509. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1510. {
  1511. DirView(Side)->HistoryGo(Index);
  1512. }
  1513. //---------------------------------------------------------------------------
  1514. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1515. {
  1516. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1517. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1518. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1522. bool Back)
  1523. {
  1524. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1525. {
  1526. TCustomDirView * DView = DirView(Side);
  1527. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1528. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1529. if (ICount > 10)
  1530. {
  1531. ICount = 10;
  1532. }
  1533. Menu->Items->Clear();
  1534. THistoryItemData Data;
  1535. Data.Side = Side;
  1536. for (short int i = 1; i <= ICount; i++)
  1537. {
  1538. TTBCustomItem * Item = new TTBXItem(Menu);
  1539. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1540. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1541. Item->Hint = DView->HistoryPath[Data.Index];
  1542. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1543. Item->Tag = *reinterpret_cast<int*>(&Data);
  1544. Item->OnClick = HistoryItemClick;
  1545. Menu->Items->Add(Item);
  1546. }
  1547. }
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1551. TOperationSide Side, bool Back)
  1552. {
  1553. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1554. {
  1555. // workaround
  1556. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1557. // operator new allocates memory in Pascal code, but calls inline
  1558. // contructor in C++, leading in problems, the function does
  1559. // both in Pascal code
  1560. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1561. UpdateHistoryMenu(Side, Back);
  1562. }
  1563. return FHistoryMenu[Side == osLocal][Back];
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1567. TCustomDirView *Sender)
  1568. {
  1569. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1570. UpdateHistoryMenu(Side, true);
  1571. UpdateHistoryMenu(Side, false);
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1575. {
  1576. // remote custom commands can be executed only if the server supports shell commands
  1577. // or have secondary shell
  1578. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1582. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1583. {
  1584. int Result;
  1585. TFileCustomCommand RemoteCustomCommand;
  1586. TLocalCustomCommand LocalCustomCommand;
  1587. TFileCustomCommand * NonInteractiveCustomCommand =
  1588. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1589. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1590. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1591. if (FLAGCLEAR(Command.Params, ccLocal))
  1592. {
  1593. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1594. // custom command that does not operate with files can be executed anytime ...
  1595. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1596. {
  1597. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1598. {
  1599. // ... but do not show such command in remote file menu (TODO)
  1600. Result = AllowedState;
  1601. }
  1602. else
  1603. {
  1604. Result = -1;
  1605. }
  1606. }
  1607. else
  1608. {
  1609. if ((ListType == ccltAll) || (ListType == ccltFile))
  1610. {
  1611. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1612. }
  1613. else
  1614. {
  1615. Result = -1;
  1616. }
  1617. }
  1618. }
  1619. else
  1620. {
  1621. // custom command that does not operate with files can be executed anytime
  1622. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1623. {
  1624. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1625. }
  1626. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1627. {
  1628. if ((ListType == ccltAll) || (ListType == ccltFile))
  1629. {
  1630. // special case is "diff"-style command that can be executed over any side,
  1631. // if we have both sides
  1632. Result =
  1633. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1634. // directly (instead of EnableSelectedOperation) to pass
  1635. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1636. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1637. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1638. }
  1639. else if (ListType == ccltBoth)
  1640. {
  1641. Result = 1;
  1642. }
  1643. else
  1644. {
  1645. Result = -1;
  1646. }
  1647. }
  1648. else
  1649. {
  1650. if ((ListType == ccltAll) || (ListType == ccltFile))
  1651. {
  1652. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1653. }
  1654. else
  1655. {
  1656. Result = -1;
  1657. }
  1658. }
  1659. }
  1660. return Result;
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1664. TStrings * FileList, const TCustomCommandType & ACommand,
  1665. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1666. {
  1667. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1668. {
  1669. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1670. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1671. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1672. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1673. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1674. bool Capture =
  1675. FLAGSET(ACommand.Params, ccShowResults) ||
  1676. FLAGSET(ACommand.Params, ccCopyResults) ||
  1677. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1678. TCaptureOutputEvent OutputEvent = NULL;
  1679. DebugAssert(FCapturedLog == NULL);
  1680. if (Capture)
  1681. {
  1682. FCapturedLog = new TStringList();
  1683. OutputEvent = TerminalCaptureLog;
  1684. }
  1685. try
  1686. {
  1687. if (!RemoteCustomCommand.IsFileCommand(Command))
  1688. {
  1689. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1690. OutputEvent);
  1691. }
  1692. else
  1693. {
  1694. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1695. }
  1696. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1697. {
  1698. if (FLAGSET(ACommand.Params, ccCopyResults))
  1699. {
  1700. CopyToClipboard(FCapturedLog);
  1701. }
  1702. if (FLAGSET(ACommand.Params, ccShowResults))
  1703. {
  1704. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1705. }
  1706. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1707. {
  1708. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1709. }
  1710. }
  1711. }
  1712. __finally
  1713. {
  1714. SAFE_DESTROY(FCapturedLog);
  1715. }
  1716. }
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1720. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1721. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1722. {
  1723. TStrings * LocalFileList = NULL;
  1724. TStrings * RemoteFileList = NULL;
  1725. TStrings * RemoteFileListFull = NULL;
  1726. try
  1727. {
  1728. if (LocalFileCommand)
  1729. {
  1730. if (ALocalFileList == NULL)
  1731. {
  1732. DebugAssert(HasDirView[osLocal]);
  1733. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1734. // directly (instead of EnableSelectedOperation) to pass
  1735. // false to FocusedFileOnlyWhenFocused
  1736. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1737. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1738. }
  1739. else
  1740. {
  1741. LocalFileList = ALocalFileList;
  1742. }
  1743. if (FileListCommand)
  1744. {
  1745. if (LocalFileList->Count != 1)
  1746. {
  1747. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if ((LocalFileList->Count != 1) &&
  1753. (FileList->Count != 1) &&
  1754. (LocalFileList->Count != FileList->Count))
  1755. {
  1756. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1757. }
  1758. }
  1759. }
  1760. UnicodeString RootTempDir;
  1761. UnicodeString TempDir;
  1762. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1763. if (!RemoteFiles)
  1764. {
  1765. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1766. }
  1767. try
  1768. {
  1769. TDateTimes RemoteFileTimes;
  1770. if (RemoteFiles)
  1771. {
  1772. RemoteFileList = FileList;
  1773. }
  1774. else
  1775. {
  1776. RemoteFileList = new TStringList();
  1777. TMakeLocalFileListParams MakeFileListParam;
  1778. MakeFileListParam.FileList = RemoteFileList;
  1779. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1780. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1781. MakeFileListParam.Recursive =
  1782. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1783. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1784. if (!MakeFileListParam.Recursive)
  1785. {
  1786. RemoteFileTimes.clear();
  1787. RemoteFileListFull = new TStringList();
  1788. MakeFileListParam.FileList = RemoteFileListFull;
  1789. MakeFileListParam.Recursive = true;
  1790. MakeFileListParam.IncludeDirs = false;
  1791. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1792. }
  1793. else
  1794. {
  1795. RemoteFileListFull = RemoteFileList;
  1796. }
  1797. }
  1798. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1799. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1800. if (!NonBlocking)
  1801. {
  1802. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1803. DebugAssert(FProgressForm != NULL);
  1804. FProgressForm->ReadOnly = true;
  1805. }
  1806. try
  1807. {
  1808. if (FileListCommand)
  1809. {
  1810. UnicodeString LocalFile;
  1811. // MakeFileList does not delimit filenames
  1812. UnicodeString FileList = MakeFileList(RemoteFileList);
  1813. if (LocalFileCommand)
  1814. {
  1815. DebugAssert(LocalFileList->Count == 1);
  1816. LocalFile = LocalFileList->Strings[0];
  1817. }
  1818. TLocalCustomCommand CustomCommand(Data,
  1819. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1820. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1821. if (NonBlocking)
  1822. {
  1823. DebugAssert(!POutput);
  1824. ExecuteShellChecked(ShellCommand);
  1825. }
  1826. else
  1827. {
  1828. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1829. }
  1830. }
  1831. else if (LocalFileCommand)
  1832. {
  1833. if (LocalFileList->Count == 1)
  1834. {
  1835. UnicodeString LocalFile = LocalFileList->Strings[0];
  1836. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1837. {
  1838. UnicodeString FileName = RemoteFileList->Strings[Index];
  1839. TLocalCustomCommand CustomCommand(Data,
  1840. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1841. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1842. }
  1843. }
  1844. else if (RemoteFileList->Count == 1)
  1845. {
  1846. UnicodeString FileName = RemoteFileList->Strings[0];
  1847. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1848. {
  1849. TLocalCustomCommand CustomCommand(
  1850. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1851. FileName, LocalFileList->Strings[Index], L"");
  1852. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1853. }
  1854. }
  1855. else
  1856. {
  1857. if (LocalFileList->Count != RemoteFileList->Count)
  1858. {
  1859. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1860. }
  1861. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1862. {
  1863. UnicodeString FileName = RemoteFileList->Strings[Index];
  1864. TLocalCustomCommand CustomCommand(
  1865. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1866. FileName, LocalFileList->Strings[Index], L"");
  1867. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1868. }
  1869. }
  1870. }
  1871. else
  1872. {
  1873. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1874. {
  1875. TLocalCustomCommand CustomCommand(Data,
  1876. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1877. RemoteFileList->Strings[Index], L"", L"");
  1878. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1879. }
  1880. }
  1881. }
  1882. __finally
  1883. {
  1884. if (!NonBlocking)
  1885. {
  1886. Progress.Stop();
  1887. }
  1888. }
  1889. DebugAssert(!FAutoOperation);
  1890. if (!RemoteFiles)
  1891. {
  1892. TempDir = IncludeTrailingBackslash(TempDir);
  1893. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  1894. {
  1895. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  1896. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1897. // Skip directories, process only nested files.
  1898. // The check is redundant as FileAge fails for directories anyway.
  1899. !DirectoryExists(FileName))
  1900. {
  1901. UnicodeString RemoteDir =
  1902. UnixExtractFileDir(
  1903. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1904. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1905. TDateTime NewTime;
  1906. if (FileAge(FileName, NewTime) &&
  1907. (NewTime != RemoteFileTimes[Index]))
  1908. {
  1909. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1910. TemporaryFileCopyParam(CopyParam);
  1911. CopyParam.FileMask = L"";
  1912. FAutoOperation = true;
  1913. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1914. TemporaryFilesList->Add(FileName);
  1915. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  1916. }
  1917. }
  1918. }
  1919. }
  1920. }
  1921. __finally
  1922. {
  1923. FAutoOperation = false;
  1924. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  1925. {
  1926. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  1927. }
  1928. }
  1929. }
  1930. __finally
  1931. {
  1932. if (RemoteFileList != FileList)
  1933. {
  1934. delete RemoteFileList;
  1935. }
  1936. if (LocalFileList != ALocalFileList)
  1937. {
  1938. delete LocalFileList;
  1939. }
  1940. if (RemoteFileListFull != RemoteFileList)
  1941. {
  1942. delete RemoteFileListFull;
  1943. }
  1944. }
  1945. }
  1946. //---------------------------------------------------------------------------
  1947. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithRemoteFiles(
  1948. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  1949. bool FileListCommand, UnicodeString * POutput)
  1950. {
  1951. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  1952. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  1953. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  1954. {
  1955. UnicodeString FileName = SelectedFileList->Strings[Index];
  1956. if (DirectoryExists(FileName))
  1957. {
  1958. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  1959. {
  1960. LocalFileList->Add(FileName);
  1961. }
  1962. if (FLAGSET(ACommand.Params, ccRecursive))
  1963. {
  1964. TMakeLocalFileListParams MakeFileListParam;
  1965. MakeFileListParam.FileList = LocalFileList.get();
  1966. MakeFileListParam.FileTimes = NULL;
  1967. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1968. MakeFileListParam.Recursive = true;
  1969. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  1970. }
  1971. }
  1972. else
  1973. {
  1974. LocalFileList->Add(FileName);
  1975. }
  1976. }
  1977. if (FileListCommand)
  1978. {
  1979. UnicodeString FileList = MakeFileList(LocalFileList.get());
  1980. TLocalCustomCommand CustomCommand(
  1981. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1982. L"", L"", FileList);
  1983. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1984. }
  1985. else
  1986. {
  1987. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1988. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
  1989. DebugAssert(FProgressForm != NULL);
  1990. FProgressForm->ReadOnly = true;
  1991. try
  1992. {
  1993. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1994. {
  1995. UnicodeString FileName = LocalFileList->Strings[Index];
  1996. TLocalCustomCommand CustomCommand(
  1997. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1998. FileName, L"", L"");
  1999. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2000. }
  2001. }
  2002. __finally
  2003. {
  2004. Progress.Stop();
  2005. }
  2006. }
  2007. }
  2008. //---------------------------------------------------------------------------
  2009. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2010. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2011. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2012. {
  2013. TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
  2014. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2015. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2016. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2017. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2018. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2019. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2020. std::unique_ptr<UnicodeString> POutput;
  2021. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2022. FLAGSET(ACommand.Params, ccCopyResults))
  2023. {
  2024. POutput.reset(new UnicodeString());
  2025. }
  2026. if (!LocalCustomCommand.IsFileCommand(Command))
  2027. {
  2028. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2029. }
  2030. // remote files?
  2031. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2032. {
  2033. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2034. }
  2035. // local files
  2036. else
  2037. {
  2038. LocalCustomCommandWithRemoteFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2039. }
  2040. if (POutput.get() != NULL)
  2041. {
  2042. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2043. int P = POutput->Pos(sLineBreak);
  2044. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2045. {
  2046. POutput->SetLength(P - 1);
  2047. }
  2048. // Copy even empty output to clipboard
  2049. if (FLAGSET(ACommand.Params, ccCopyResults))
  2050. {
  2051. CopyToClipboard(*POutput);
  2052. }
  2053. // But do not show an empty message box.
  2054. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2055. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2056. !POutput->IsEmpty())
  2057. {
  2058. TClipboardHandler ClipboardHandler;
  2059. ClipboardHandler.Text = *POutput;
  2060. TMessageParams Params;
  2061. TQueryButtonAlias Aliases[1];
  2062. Aliases[0].Button = qaRetry;
  2063. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2064. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2065. Params.Aliases = Aliases;
  2066. Params.AliasesCount = LENOF(Aliases);
  2067. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2068. }
  2069. }
  2070. }
  2071. //---------------------------------------------------------------------------
  2072. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2073. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2074. {
  2075. TCustomCommandData Data(Terminal);
  2076. UnicodeString Site = Terminal->SessionData->SessionKey;
  2077. UnicodeString HelpKeyword = ACommand.HomePage;
  2078. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2079. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2080. {
  2081. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2082. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2083. {
  2084. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, Terminal->CurrentDirectory));
  2085. }
  2086. else
  2087. {
  2088. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
  2089. }
  2090. if (!DoCustomCommandOptionsDialog(
  2091. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2092. {
  2093. Abort();
  2094. }
  2095. }
  2096. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2097. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2098. {
  2099. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2100. }
  2101. else
  2102. {
  2103. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2104. }
  2105. }
  2106. //---------------------------------------------------------------------------
  2107. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2108. const TCustomCommandType & Command)
  2109. {
  2110. DebugAssert(FCustomCommandLocalFileList != NULL);
  2111. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2112. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2113. TStrings * LocalFileList = new TStringList();
  2114. TStrings * RemoteFileList = new TStringList();
  2115. try
  2116. {
  2117. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2118. {
  2119. LocalFileList->Clear();
  2120. LocalFileList->AddObject(
  2121. FCustomCommandLocalFileList->Strings[Index],
  2122. FCustomCommandLocalFileList->Objects[Index]);
  2123. RemoteFileList->Clear();
  2124. RemoteFileList->AddObject(
  2125. FCustomCommandRemoteFileList->Strings[Index],
  2126. FCustomCommandRemoteFileList->Objects[Index]);
  2127. CustomCommand(RemoteFileList, Command, LocalFileList);
  2128. }
  2129. }
  2130. __finally
  2131. {
  2132. delete LocalFileList;
  2133. delete RemoteFileList;
  2134. }
  2135. }
  2136. //---------------------------------------------------------------------------
  2137. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2138. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2139. {
  2140. delete FCustomCommandLocalFileList;
  2141. delete FCustomCommandRemoteFileList;
  2142. // takeover ownership,
  2143. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2144. FCustomCommandLocalFileList = LocalFileList;
  2145. FCustomCommandRemoteFileList = RemoteFileList;
  2146. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2147. if (Button != NULL)
  2148. {
  2149. FCustomCommandMenu->Items->Clear();
  2150. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  2151. MenuPopup(FCustomCommandMenu, Button);
  2152. }
  2153. else
  2154. {
  2155. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2156. }
  2157. }
  2158. //---------------------------------------------------------------------------
  2159. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2160. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2161. {
  2162. DebugAssert(FCapturedLog != NULL);
  2163. if ((OutputType == cotOutput) || (OutputType == cotError))
  2164. {
  2165. FCapturedLog->Add(AddedLine);
  2166. }
  2167. }
  2168. //---------------------------------------------------------------------------
  2169. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2170. TOperationSide Side)
  2171. {
  2172. return (Side == osRemote) &&
  2173. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2174. }
  2175. //---------------------------------------------------------------------------
  2176. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2177. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2178. {
  2179. TTBItemOptions O;
  2180. O = Item->Options;
  2181. TCustomDirView * DView = DirView(Side);
  2182. if ((DView->ItemFocused != NULL) &&
  2183. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2184. // when resolving links is disabled, default action is to enter the directory,
  2185. // no matter what DoubleClickAction is configured to
  2186. ((Side != osRemote) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2187. // Can only Edit files, but can Open/Copy even directories
  2188. ((DoubleClickAction != dcaEdit) ||
  2189. !DView->ItemIsDirectory(DView->ItemFocused)))
  2190. {
  2191. Item->Options = O << tboDefault;
  2192. }
  2193. else
  2194. {
  2195. Item->Options = O >> tboDefault;
  2196. }
  2197. }
  2198. //---------------------------------------------------------------------------
  2199. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2200. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2201. {
  2202. TCustomDirView * DView = DirView(Side);
  2203. TListItem * Item = DView->ItemFocused;
  2204. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2205. EnableFocusedOperation[Side])
  2206. {
  2207. TPoint ClientPoint;
  2208. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2209. TPoint(0, 0) : MousePos;
  2210. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2211. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2212. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2213. }
  2214. }
  2215. //---------------------------------------------------------------------------
  2216. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2217. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2218. {
  2219. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2220. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2221. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2222. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2223. Handled = true;
  2224. }
  2225. //---------------------------------------------------------------------------
  2226. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2227. {
  2228. }
  2229. //---------------------------------------------------------------------------
  2230. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2231. {
  2232. DebugAssert(FErrorList == NULL);
  2233. if (WinConfiguration->ContinueOnError)
  2234. {
  2235. FErrorList = new TStringList();
  2236. Configuration->Usage->Inc(L"ContinuationsOnError");
  2237. }
  2238. NonVisualDataModule->StartBusy();
  2239. }
  2240. //---------------------------------------------------------------------------
  2241. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2242. {
  2243. NonVisualDataModule->EndBusy();
  2244. if (FErrorList)
  2245. {
  2246. HandleErrorList(FErrorList);
  2247. }
  2248. }
  2249. //---------------------------------------------------------------------------
  2250. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2251. const TCopyParamType & CopyParam)
  2252. {
  2253. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2254. {
  2255. Configuration->Usage->Inc(L"FileMaskUses");
  2256. }
  2257. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2258. {
  2259. Configuration->Usage->Inc(L"OperationMaskUses");
  2260. }
  2261. }
  2262. //---------------------------------------------------------------------------
  2263. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2264. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2265. {
  2266. void * BatchStorage;
  2267. BatchStart(BatchStorage);
  2268. bool Result;
  2269. try
  2270. {
  2271. if ((Operation == foCopy) || (Operation == foMove))
  2272. {
  2273. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2274. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2275. UnicodeString TargetDirectory;
  2276. bool Temp = false;
  2277. bool DragDrop = false;
  2278. int Options = 0;
  2279. TAutoSwitch UseQueue = asAuto;
  2280. if (Param != NULL)
  2281. {
  2282. TTransferOperationParam& TParam =
  2283. *static_cast<TTransferOperationParam*>(Param);
  2284. TargetDirectory = TParam.TargetDirectory;
  2285. Temp = TParam.Temp;
  2286. DragDrop = TParam.DragDrop;
  2287. Options = TParam.Options;
  2288. UseQueue = TParam.Queue;
  2289. }
  2290. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2291. switch (UseQueue)
  2292. {
  2293. case asOn:
  2294. CopyParam.Queue = true;
  2295. break;
  2296. case asOff:
  2297. CopyParam.Queue = false;
  2298. break;
  2299. case asAuto:
  2300. default:
  2301. // keep default
  2302. break;
  2303. }
  2304. Result =
  2305. CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  2306. CopyParam, !NoConfirmation, DragDrop, Options);
  2307. if (Result)
  2308. {
  2309. DebugAssert(Terminal);
  2310. bool SelectionRestored = false;
  2311. TCustomDirView * DView = NULL;
  2312. if (HasDirView[Side])
  2313. {
  2314. DView = DirView(Side);
  2315. DView->SaveSelection();
  2316. DView->SaveSelectedNames();
  2317. }
  2318. UpdateCopyParamCounters(CopyParam);
  2319. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2320. DebugAssert(FTransferResumeList == NULL);
  2321. FTransferResumeList =
  2322. Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2323. FMoveToQueue = false;
  2324. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2325. try
  2326. {
  2327. TStrings * PermanentFileList;
  2328. std::unique_ptr<TStrings> PermanentFileListOwner;
  2329. try
  2330. {
  2331. if (Side == osLocal)
  2332. {
  2333. PermanentFileList = FileList;
  2334. Params |= FLAGMASK(Temp, cpTemporary);
  2335. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params, NULL);
  2336. if (Operation == foMove)
  2337. {
  2338. ReloadLocalDirectory();
  2339. if (DView != NULL)
  2340. {
  2341. DView->RestoreSelection();
  2342. }
  2343. SelectionRestored = true;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. // Clone the file list as it may refer to current directory files,
  2349. // which get destroyed, when the source directory is reloaded after foMove operation.
  2350. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2351. // But for a hotfix, we are not going to do such a big change.
  2352. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2353. PermanentFileList = PermanentFileListOwner.get();
  2354. try
  2355. {
  2356. Terminal->CopyToLocal(
  2357. FileList, TargetDirectory, &CopyParam, Params, NULL);
  2358. }
  2359. __finally
  2360. {
  2361. if (Operation == foMove)
  2362. {
  2363. if (DView != NULL)
  2364. {
  2365. DView->RestoreSelection();
  2366. }
  2367. SelectionRestored = true;
  2368. }
  2369. ReloadLocalDirectory(TargetDirectory);
  2370. }
  2371. }
  2372. }
  2373. catch (EAbort &)
  2374. {
  2375. if (FMoveToQueue)
  2376. {
  2377. Params |=
  2378. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2379. DebugAssert(CopyParam.TransferSkipList == NULL);
  2380. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2381. if (TransferResumeList->Count > 0)
  2382. {
  2383. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2384. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2385. }
  2386. CopyParam.TransferSkipList = TransferResumeList.release();
  2387. // not really needed, just to keep it consistent with TransferResumeList
  2388. FTransferResumeList = NULL;
  2389. FMoveToQueue = false;
  2390. Configuration->Usage->Inc("MovesToBackground");
  2391. AddQueueItem(Queue, Direction, PermanentFileList, TargetDirectory, CopyParam, Params);
  2392. ClearTransferSourceSelection(Direction);
  2393. }
  2394. throw;
  2395. }
  2396. }
  2397. __finally
  2398. {
  2399. if (!SelectionRestored && (DView != NULL))
  2400. {
  2401. DView->DiscardSavedSelection();
  2402. }
  2403. FTransferResumeList = NULL;
  2404. }
  2405. }
  2406. }
  2407. else if (Operation == foRename)
  2408. {
  2409. DebugAssert(DirView(Side)->ItemFocused);
  2410. DirView(Side)->ItemFocused->EditCaption();
  2411. Result = true;
  2412. }
  2413. else if (Operation == foDelete)
  2414. {
  2415. DebugAssert(FileList->Count);
  2416. // We deliberately do not toggle alternative flag (Param), but use OR,
  2417. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2418. // shortcut of CurrentDeleteAlternativeAction
  2419. bool Alternative =
  2420. bool(Param) || UseAlternativeFunction();
  2421. bool Recycle;
  2422. if (Side == osLocal)
  2423. {
  2424. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2425. }
  2426. else
  2427. {
  2428. Recycle = (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2429. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2430. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2431. }
  2432. Result =
  2433. !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2434. if (!Result)
  2435. {
  2436. UnicodeString Query;
  2437. if (FileList->Count == 1)
  2438. {
  2439. if (Side == osLocal)
  2440. {
  2441. Query = ExtractFileName(FileList->Strings[0]);
  2442. }
  2443. else
  2444. {
  2445. Query = UnixExtractFileName(FileList->Strings[0]);
  2446. }
  2447. Query = FMTLOAD(
  2448. (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2449. }
  2450. else
  2451. {
  2452. Query = FMTLOAD(
  2453. (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2454. }
  2455. TMessageParams Params(mpNeverAskAgainCheck);
  2456. Params.ImageName = L"Delete file";
  2457. unsigned int Answer = MessageDialog(MainInstructions(Query), qtConfirmation,
  2458. qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2459. if (Answer == qaNeverAskAgain)
  2460. {
  2461. Result = true;
  2462. if (Recycle)
  2463. {
  2464. WinConfiguration->ConfirmRecycling = false;
  2465. }
  2466. else
  2467. {
  2468. WinConfiguration->ConfirmDeleting = false;
  2469. }
  2470. }
  2471. else
  2472. {
  2473. Result = (Answer == qaOK);
  2474. }
  2475. }
  2476. if (Result)
  2477. {
  2478. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2479. }
  2480. }
  2481. else if (Operation == foSetProperties)
  2482. {
  2483. RemoteDirView->SaveSelectedNames();
  2484. Result = SetProperties(Side, FileList);
  2485. }
  2486. else if (Operation == foCustomCommand)
  2487. {
  2488. DebugAssert(Param);
  2489. DebugAssert(Side == osRemote);
  2490. RemoteDirView->SaveSelectedNames();
  2491. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2492. CustomCommand(FileList, *Command, NULL);
  2493. Result = true;
  2494. }
  2495. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2496. {
  2497. DebugAssert(Side == osRemote);
  2498. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2499. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2500. }
  2501. else if (Operation == foLock)
  2502. {
  2503. DebugAssert(Side == osRemote);
  2504. LockFiles(FileList, true);
  2505. Result = true;
  2506. }
  2507. else if (Operation == foUnlock)
  2508. {
  2509. DebugAssert(Side == osRemote);
  2510. LockFiles(FileList, false);
  2511. Result = true;
  2512. }
  2513. else
  2514. {
  2515. DebugFail();
  2516. }
  2517. }
  2518. __finally
  2519. {
  2520. BatchEnd(BatchStorage);
  2521. }
  2522. return Result;
  2523. }
  2524. //---------------------------------------------------------------------------
  2525. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2526. {
  2527. if (Side == osCurrent)
  2528. {
  2529. Side = FCurrentSide;
  2530. }
  2531. return Side;
  2532. }
  2533. //---------------------------------------------------------------------------
  2534. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2535. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2536. {
  2537. Side = GetSide(Side);
  2538. bool Result;
  2539. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2540. try
  2541. {
  2542. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2543. }
  2544. __finally
  2545. {
  2546. delete FileList;
  2547. }
  2548. return Result;
  2549. }
  2550. //---------------------------------------------------------------------------
  2551. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2552. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2553. bool NoConfirmation, void * Param)
  2554. {
  2555. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2556. {
  2557. if ((Operation == foCopy) || (Operation == foMove))
  2558. {
  2559. if (GetSide(Side) == osLocal)
  2560. {
  2561. Configuration->Usage->Inc(L"UploadsCommand");
  2562. }
  2563. else
  2564. {
  2565. Configuration->Usage->Inc(L"DownloadsCommand");
  2566. }
  2567. }
  2568. }
  2569. }
  2570. //---------------------------------------------------------------------------
  2571. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2572. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2573. {
  2574. TTransferOperationParam Param;
  2575. if ((WinConfiguration->Interface != ifCommander) ||
  2576. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2577. {
  2578. Flags &= ~cocShortCutHint;
  2579. }
  2580. TCustomDirView * DView = DirView(Side);
  2581. Param.Options =
  2582. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2583. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2584. if (FLAGSET(Flags, cocQueue))
  2585. {
  2586. Param.Queue = asOn;
  2587. }
  2588. else if (FLAGSET(Flags, cocNonQueue))
  2589. {
  2590. Param.Queue = asOff;
  2591. }
  2592. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2593. }
  2594. //---------------------------------------------------------------------------
  2595. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2596. {
  2597. try
  2598. {
  2599. if (ErrorList->Count)
  2600. {
  2601. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2602. if (MessageDialog(Message, qtError,
  2603. qaOK | qaCancel, HELP_NONE) == qaOK)
  2604. {
  2605. unsigned int Answer;
  2606. int Index = 0;
  2607. do
  2608. {
  2609. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2610. TQueryButtonAlias Aliases[2];
  2611. Aliases[0].Button = qaYes;
  2612. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2613. Aliases[1].Button = qaNo;
  2614. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2615. TMessageParams Params;
  2616. Params.Aliases = Aliases;
  2617. Params.AliasesCount = LENOF(Aliases);
  2618. Answer = MoreMessageDialog(
  2619. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2620. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2621. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2622. qaOK, HELP_NONE, &Params);
  2623. if (Answer == qaNo)
  2624. {
  2625. Index++;
  2626. }
  2627. if (Answer == qaYes)
  2628. {
  2629. Index--;
  2630. }
  2631. }
  2632. while (Answer != qaOK);
  2633. }
  2634. }
  2635. }
  2636. __finally
  2637. {
  2638. TStrings * List = ErrorList;
  2639. ErrorList = NULL;
  2640. for (int i = 0; i < List->Count; i++)
  2641. {
  2642. delete List->Objects[i];
  2643. }
  2644. delete List;
  2645. }
  2646. }
  2647. //---------------------------------------------------------------------------
  2648. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2649. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2650. {
  2651. // needed for checking filemasks, as there's no directory object
  2652. // associated with the file object
  2653. File->FullFileName = FullFileName;
  2654. TFileMasks::TParams MaskParams;
  2655. MaskParams.Size = File->Size;
  2656. MaskParams.Modification = File->Modification;
  2657. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2658. }
  2659. //---------------------------------------------------------------------------
  2660. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2661. {
  2662. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2663. Side = GetSide(Side);
  2664. TCustomDirView * DView = DirView(Side);
  2665. TListItem * FocusedItem = DView->ItemFocused;
  2666. UnicodeString Name;
  2667. if ((FocusedItem != NULL) && !DView->ItemIsParentDirectory(FocusedItem))
  2668. {
  2669. Name = DView->ItemFileName(FocusedItem);
  2670. }
  2671. else
  2672. {
  2673. Name = LoadStr(NEW_FILE);
  2674. }
  2675. UnicodeString Names = Name;
  2676. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2677. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2678. HELP_EDIT_NEW, History.get(), true))
  2679. {
  2680. while (!Names.IsEmpty())
  2681. {
  2682. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2683. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2684. UnicodeString TargetFileName;
  2685. UnicodeString LocalFileName;
  2686. UnicodeString RootTempDir;
  2687. UnicodeString TempDir;
  2688. UnicodeString RemoteDirectory;
  2689. bool ExistingFile = false;
  2690. if (Side == osRemote)
  2691. {
  2692. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2693. TRemoteFile * File = NULL;
  2694. if (FTerminal->FileExists(Name, &File))
  2695. {
  2696. try
  2697. {
  2698. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2699. ExistingFile = true;
  2700. }
  2701. __finally
  2702. {
  2703. delete File;
  2704. }
  2705. }
  2706. if (!ExistingFile)
  2707. {
  2708. RemoteDirectory = UnixExtractFilePath(Name);
  2709. TemporaryDirectoryForRemoteFiles(
  2710. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2711. TargetFileName = UnixExtractFileName(Name);
  2712. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2713. LocalFileName = TempDir +
  2714. // We probably do not want to trim the VMS version here
  2715. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2716. }
  2717. }
  2718. else
  2719. {
  2720. if (ExtractFilePath(Name).IsEmpty())
  2721. {
  2722. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2723. }
  2724. else
  2725. {
  2726. LocalFileName = ExpandFileName(Name);
  2727. }
  2728. TargetFileName = ExtractFileName(Name);
  2729. }
  2730. if (!ExistingFile)
  2731. {
  2732. if (!FileExists(ApiPath(LocalFileName)))
  2733. {
  2734. int File = FileCreate(ApiPath(LocalFileName));
  2735. if (File < 0)
  2736. {
  2737. if (!RootTempDir.IsEmpty())
  2738. {
  2739. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2740. }
  2741. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2742. }
  2743. else
  2744. {
  2745. FileClose(File);
  2746. }
  2747. }
  2748. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2749. const TEditorData * ExternalEditor = NULL;
  2750. TFileMasks::TParams MaskParams; // size not known
  2751. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2752. false, MaskParams);
  2753. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2754. ExternalEditor, RootTempDir, RemoteDirectory);
  2755. }
  2756. }
  2757. }
  2758. }
  2759. //---------------------------------------------------------------------------
  2760. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2761. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2762. {
  2763. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2764. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2765. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2766. return
  2767. ((ExecuteFileBy == efInternalEditor)) ||
  2768. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2769. }
  2770. //---------------------------------------------------------------------------
  2771. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2772. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2773. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2774. UnicodeString RemoteDirectory)
  2775. {
  2776. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2777. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2778. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2779. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2780. Side = GetSide(Side);
  2781. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2782. if (Side == osRemote)
  2783. {
  2784. Data->Terminal = Terminal;
  2785. Data->Queue = Queue;
  2786. Data->SessionData = CloneCurrentSessionData();
  2787. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2788. Data->RemoteDirectory = RemoteDirectory;
  2789. Data->SessionName = Terminal->SessionData->SessionName;
  2790. Data->LocalRootDirectory = LocalRootDirectory;
  2791. Data->OriginalFileName = OriginalFileName;
  2792. Data->Command = L""; // will be changed later for external editor
  2793. }
  2794. if (ExecuteFileBy == efInternalEditor)
  2795. {
  2796. if (Side == osRemote)
  2797. {
  2798. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2799. L" - " + Terminal->SessionData->SessionName;
  2800. TForm * Editor;
  2801. try
  2802. {
  2803. TNotifyEvent OnFileChanged = NULL;
  2804. TNotifyEvent OnSaveAll = NULL;
  2805. TAnyModifiedEvent OnAnyModified = NULL;
  2806. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2807. if (Terminal->IsCapable[fsBackgroundTransfers])
  2808. {
  2809. OnFileChanged = FEditorManager->FileChanged;
  2810. OnSaveAll = SaveAllInternalEditors;
  2811. OnAnyModified = AnyInternalEditorModified;
  2812. }
  2813. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2814. FEditorManager->FileReload, FEditorManager->FileClosed,
  2815. OnSaveAll, OnAnyModified,
  2816. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
  2817. }
  2818. catch(...)
  2819. {
  2820. if (!LocalRootDirectory.IsEmpty())
  2821. {
  2822. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2823. }
  2824. throw;
  2825. }
  2826. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2827. }
  2828. else
  2829. {
  2830. DebugAssert(!FStandaloneEditing);
  2831. TForm * Editor =
  2832. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2833. SaveAllInternalEditors, AnyInternalEditorModified,
  2834. L"", false, SessionColor, -1);
  2835. FLocalEditors->Add(Editor);
  2836. }
  2837. }
  2838. else
  2839. {
  2840. HANDLE Process;
  2841. if (ExecuteFileBy == efExternalEditor)
  2842. {
  2843. UnicodeString Program, Params, Dir;
  2844. Data->Command = ExternalEditor->ExternalEditor;
  2845. ReformatFileNameCommand(Data->Command);
  2846. SplitCommand(Data->Command, Program, Params, Dir);
  2847. Params = ExpandFileNameCommand(Params, FileName);
  2848. Program = ExpandEnvironmentVariables(Program);
  2849. if (!ExecuteShell(Program, Params, Process))
  2850. {
  2851. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2852. }
  2853. }
  2854. else
  2855. {
  2856. DebugAssert(Side == osRemote);
  2857. if (!ExecuteShell(FileName, L"", Process))
  2858. {
  2859. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2860. }
  2861. }
  2862. if ((Side == osLocal) ||
  2863. ((ExecuteFileBy == efShell) &&
  2864. !WinConfiguration->Editor.SDIShellEditor) ||
  2865. ((ExecuteFileBy == efExternalEditor) &&
  2866. !ExternalEditor->SDIExternalEditor))
  2867. {
  2868. // no need for handle
  2869. if (Process != NULL)
  2870. {
  2871. DebugCheck(CloseHandle(Process));
  2872. }
  2873. Process = INVALID_HANDLE_VALUE;
  2874. }
  2875. else
  2876. {
  2877. if (Process == NULL)
  2878. {
  2879. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2880. }
  2881. }
  2882. if (Side == osRemote)
  2883. {
  2884. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2885. }
  2886. }
  2887. }
  2888. //---------------------------------------------------------------------------
  2889. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2890. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2891. void * /*Arg*/)
  2892. {
  2893. if (Token != NULL)
  2894. {
  2895. EditorFormFileSave(static_cast<TForm *>(Token));
  2896. }
  2897. }
  2898. //---------------------------------------------------------------------------
  2899. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2900. {
  2901. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2902. {
  2903. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2904. }
  2905. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2906. }
  2907. //---------------------------------------------------------------------------
  2908. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2909. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2910. void * Arg)
  2911. {
  2912. if ((Token != NULL) &&
  2913. IsEditorFormModified(static_cast<TForm *>(Token)))
  2914. {
  2915. *static_cast<bool *>(Arg) = true;
  2916. }
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2920. TObject * /*Sender*/, bool & Modified)
  2921. {
  2922. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2923. {
  2924. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2925. {
  2926. Modified = true;
  2927. }
  2928. }
  2929. if (!Modified)
  2930. {
  2931. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  2932. }
  2933. }
  2934. //---------------------------------------------------------------------------
  2935. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  2936. {
  2937. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  2938. }
  2939. //---------------------------------------------------------------------------
  2940. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  2941. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  2942. UnicodeString & Result, UnicodeString & RootDirectory)
  2943. {
  2944. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  2945. {
  2946. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  2947. Result = RootDirectory;
  2948. }
  2949. else
  2950. {
  2951. RootDirectory = L"";
  2952. Result = WinConfiguration->ExpandedTemporaryDirectory();
  2953. Result = IncludeTrailingBackslash(Result);
  2954. }
  2955. if (WinConfiguration->TemporaryDirectoryAppendSession)
  2956. {
  2957. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  2958. }
  2959. if (WinConfiguration->TemporaryDirectoryAppendPath)
  2960. {
  2961. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  2962. {
  2963. RemoteDirectory.Delete(1, 1);
  2964. }
  2965. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  2966. }
  2967. if (!ForceDirectories(ApiPath(Result)))
  2968. {
  2969. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  2970. }
  2971. }
  2972. //---------------------------------------------------------------------------
  2973. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  2974. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  2975. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  2976. {
  2977. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2978. if (ForceText)
  2979. {
  2980. CopyParam.TransferMode = tmAscii;
  2981. }
  2982. TemporaryFileCopyParam(CopyParam);
  2983. if (AllFiles)
  2984. {
  2985. CopyParam.IncludeFileMask = TFileMasks();
  2986. }
  2987. if (TempDir.IsEmpty())
  2988. {
  2989. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  2990. }
  2991. DebugAssert(!FAutoOperation);
  2992. FAutoOperation = AutoOperation;
  2993. Terminal->ExceptionOnFail = true;
  2994. try
  2995. {
  2996. try
  2997. {
  2998. // turn off confirmations, as for MDI editors we may possibly download
  2999. // the same file over
  3000. Terminal->CopyToLocal(
  3001. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3002. if (GetTargetNames)
  3003. {
  3004. for (int i = 0; i < FileList->Count; i++)
  3005. {
  3006. FileList->Strings[i] =
  3007. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3008. }
  3009. }
  3010. }
  3011. catch(...)
  3012. {
  3013. if (!RootTempDir.IsEmpty())
  3014. {
  3015. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3016. }
  3017. throw;
  3018. }
  3019. }
  3020. __finally
  3021. {
  3022. FAutoOperation = false;
  3023. Terminal->ExceptionOnFail = false;
  3024. }
  3025. }
  3026. //---------------------------------------------------------------------------
  3027. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3028. {
  3029. // Do not waste time checking for default editor list the next time,
  3030. // or testing if default editor is not notepad.
  3031. bool TryNextTime = false;
  3032. UnicodeString UsageState;
  3033. if (!WinConfiguration->EditorList->IsDefaultList())
  3034. {
  3035. UsageState = "H";
  3036. }
  3037. else
  3038. {
  3039. UnicodeString Executable;
  3040. UnicodeString ExecutableDescription;
  3041. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3042. {
  3043. UnicodeString Message =
  3044. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3045. unsigned int Answer =
  3046. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3047. if (Answer != qaOK)
  3048. {
  3049. UsageState = "R";
  3050. }
  3051. else
  3052. {
  3053. UsageState = "A";
  3054. TEditorData EditorData;
  3055. EditorData.Editor = edExternal;
  3056. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3057. EditorData.DecideExternalEditorText();
  3058. TEditorList EditorList;
  3059. EditorList = *WinConfiguration->EditorList;
  3060. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3061. WinConfiguration->EditorList = &EditorList;
  3062. }
  3063. }
  3064. }
  3065. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3066. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3067. }
  3068. //---------------------------------------------------------------------------
  3069. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3070. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3071. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3072. {
  3073. if (ExecuteFileBy == efDefaultEditor)
  3074. {
  3075. if (!WinConfiguration->OfferedEditorAutoConfig)
  3076. {
  3077. EditorAutoConfig();
  3078. }
  3079. const TEditorPreferences * Editor =
  3080. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3081. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3082. {
  3083. ExecuteFileBy = efInternalEditor;
  3084. ExternalEditor = NULL;
  3085. }
  3086. else if (Editor->Data->Editor == edOpen)
  3087. {
  3088. ExecuteFileBy = efShell;
  3089. ExternalEditor = NULL;
  3090. }
  3091. else
  3092. {
  3093. ExecuteFileBy = efExternalEditor;
  3094. ExternalEditor = Editor->Data;
  3095. }
  3096. }
  3097. }
  3098. //---------------------------------------------------------------------------
  3099. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3100. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3101. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3102. {
  3103. UnicodeString OriginalFileName;
  3104. UnicodeString LocalRootDirectory;
  3105. UnicodeString RemoteDirectory;
  3106. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3107. (Side == osLocal), MaskParams);
  3108. UnicodeString Counter;
  3109. UnicodeString LocalFileName;
  3110. bool Handled = false;
  3111. if (Side == osRemote)
  3112. {
  3113. // We need to trim VMS version here, so that we use name without version
  3114. // when uploading back to create a new version of the file
  3115. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3116. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3117. TObject * Token = NULL;
  3118. UnicodeString LocalDirectory;
  3119. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3120. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3121. LocalDirectory))
  3122. {
  3123. if (Token != NULL)
  3124. {
  3125. TForm * Form = dynamic_cast<TForm *>(Token);
  3126. if (Form->WindowState == wsMinimized)
  3127. {
  3128. ShowWindow(Form->Handle, SW_RESTORE);
  3129. }
  3130. else
  3131. {
  3132. Form->SetFocus();
  3133. }
  3134. Handled = true;
  3135. }
  3136. else
  3137. {
  3138. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3139. }
  3140. }
  3141. if (!Handled)
  3142. {
  3143. TStringList * FileList1 = new TStringList();
  3144. try
  3145. {
  3146. FileList1->AddObject(FullFileName, Object);
  3147. TemporarilyDownloadFiles(FileList1,
  3148. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3149. LocalRootDirectory, LocalDirectory, true, true, true);
  3150. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3151. }
  3152. __finally
  3153. {
  3154. delete FileList1;
  3155. }
  3156. switch (ExecuteFileBy)
  3157. {
  3158. case efShell:
  3159. Counter = "RemoteFilesExecuted";
  3160. break;
  3161. case efInternalEditor:
  3162. Counter = "RemoteFilesOpenedInInternalEditor";
  3163. break;
  3164. case efExternalEditor:
  3165. Counter = "RemoteFilesOpenedInExternalEditor";
  3166. break;
  3167. default:
  3168. DebugFail();
  3169. }
  3170. }
  3171. }
  3172. else
  3173. {
  3174. LocalFileName = FullFileName;
  3175. OriginalFileName = ExtractFileName(FullFileName);
  3176. switch (ExecuteFileBy)
  3177. {
  3178. case efShell:
  3179. Counter = "LocalFilesExecuted";
  3180. break;
  3181. case efInternalEditor:
  3182. Counter = "LocalFilesOpenedInInternalEditor";
  3183. break;
  3184. case efExternalEditor:
  3185. Counter = "LocalFilesOpenedInExternalEditor";
  3186. break;
  3187. default:
  3188. DebugFail();
  3189. }
  3190. }
  3191. if (!Handled)
  3192. {
  3193. Configuration->Usage->Inc(Counter);
  3194. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3195. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3196. }
  3197. }
  3198. //---------------------------------------------------------------------------
  3199. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3200. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3201. bool AllSelected, bool OnFocused)
  3202. {
  3203. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3204. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3205. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3206. Side = GetSide(Side);
  3207. TCustomDirView * DView = DirView(Side);
  3208. TStrings * FileList = AllSelected ?
  3209. DView->CreateFileList(OnFocused, Side == osLocal) :
  3210. DView->CreateFocusedFileList(Side == osLocal);
  3211. try
  3212. {
  3213. DebugAssert(AllSelected || (FileList->Count == 1));
  3214. for (int i = 0; i < FileList->Count; i++)
  3215. {
  3216. UnicodeString ListFileName = FileList->Strings[i];
  3217. UnicodeString FileNameOnly = (Side == osRemote) ?
  3218. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3219. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3220. if (!DView->ItemIsDirectory(Item))
  3221. {
  3222. UnicodeString FullFileName;
  3223. if (Side == osRemote)
  3224. {
  3225. FullFileName = RemoteDirView->Path + ListFileName;
  3226. }
  3227. else
  3228. {
  3229. FullFileName = ListFileName;
  3230. }
  3231. TFileMasks::TParams MaskParams;
  3232. MaskParams.Size = DView->ItemFileSize(Item);
  3233. TDateTimePrecision Precision;
  3234. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3235. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3236. FileList->Objects[i], MaskParams);
  3237. }
  3238. }
  3239. }
  3240. __finally
  3241. {
  3242. delete FileList;
  3243. }
  3244. }
  3245. //---------------------------------------------------------------------------
  3246. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3247. {
  3248. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3249. CopyParam.FileNameCase = ncNoChange;
  3250. CopyParam.PreserveRights = false;
  3251. CopyParam.PreserveReadOnly = false;
  3252. CopyParam.ReplaceInvalidChars = true;
  3253. CopyParam.IncludeFileMask = TFileMasks();
  3254. CopyParam.NewerOnly = false;
  3255. CopyParam.FileMask = L"";
  3256. }
  3257. //---------------------------------------------------------------------------
  3258. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3259. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3260. {
  3261. TTerminalManager * Manager = TTerminalManager::Instance();
  3262. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3263. {
  3264. if (!NonVisualDataModule->Busy)
  3265. {
  3266. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3267. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3268. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3269. if (Data->Terminal == NULL)
  3270. {
  3271. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3272. if (SameSiteTerminal != NULL)
  3273. {
  3274. UnicodeString Message =
  3275. FMTLOAD(EDIT_SESSION_REATTACH,
  3276. (FileNameOnly, Data->SessionName, FileNameOnly));
  3277. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3278. {
  3279. Data->Terminal = Terminal;
  3280. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3281. Data->SessionName = Terminal->SessionData->SessionName;
  3282. // We might also overwrite session data
  3283. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3284. }
  3285. else
  3286. {
  3287. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3288. Abort();
  3289. }
  3290. }
  3291. }
  3292. // foreground session should reconnect itself
  3293. else if (Terminal != Data->Terminal)
  3294. {
  3295. UnicodeString Message =
  3296. MainInstructions(
  3297. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3298. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3299. {
  3300. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3301. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3302. }
  3303. else
  3304. {
  3305. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3306. Abort();
  3307. }
  3308. }
  3309. }
  3310. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3311. {
  3312. Configuration->Usage->Inc(L"EditInactiveSession");
  3313. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3314. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3315. (ExtractFileName(FileName), Data->SessionName)));
  3316. }
  3317. }
  3318. TStrings * FileList = new TStringList();
  3319. try
  3320. {
  3321. FileList->Add(FileName);
  3322. // consider using the same settings (preset) as when the file was downloaded
  3323. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3324. TemporaryFileCopyParam(CopyParam);
  3325. if (Data->ForceText)
  3326. {
  3327. CopyParam.TransferMode = tmAscii;
  3328. }
  3329. // so i do not need to worry if masking algorithm works in all cases
  3330. // ("" means "copy file name", no masking is actually done)
  3331. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3332. {
  3333. CopyParam.FileMask = L"";
  3334. }
  3335. else
  3336. {
  3337. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3338. }
  3339. DebugAssert(Data->Queue != NULL);
  3340. int Params = cpNoConfirmation | cpTemporary;
  3341. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3342. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3343. QueueItem->CompleteEvent = UploadCompleteEvent;
  3344. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3345. }
  3346. __finally
  3347. {
  3348. delete FileList;
  3349. }
  3350. }
  3351. //---------------------------------------------------------------------------
  3352. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3353. const UnicodeString FileName, const TEditedFileData * Data)
  3354. {
  3355. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3356. DebugAssert(!NonVisualDataModule->Busy);
  3357. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3358. {
  3359. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3360. (ExtractFileName(FileName), Data->SessionName)));
  3361. }
  3362. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3363. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3364. NonVisualDataModule->StartBusy();
  3365. try
  3366. {
  3367. std::unique_ptr<TRemoteFile> File;
  3368. UnicodeString RemoteFileName =
  3369. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3370. FTerminal->ExceptionOnFail = true;
  3371. try
  3372. {
  3373. TRemoteFile * AFile = NULL;
  3374. FTerminal->ReadFile(RemoteFileName, AFile);
  3375. File.reset(AFile);
  3376. if (!File->HaveFullFileName)
  3377. {
  3378. File->FullFileName = RemoteFileName;
  3379. }
  3380. }
  3381. __finally
  3382. {
  3383. FTerminal->ExceptionOnFail = false;
  3384. }
  3385. std::unique_ptr<TStrings> FileList(new TStringList());
  3386. FileList->AddObject(RemoteFileName, File.get());
  3387. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3388. UnicodeString TempDir = ExtractFilePath(FileName);
  3389. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3390. TempDir, true, true, true);
  3391. // sanity check, the target file name should be still the same
  3392. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3393. }
  3394. __finally
  3395. {
  3396. NonVisualDataModule->EndBusy();
  3397. // it actually may not exist anymore...
  3398. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3399. }
  3400. }
  3401. //---------------------------------------------------------------------------
  3402. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3403. const TEditedFileData * Data, bool & KeepOpen)
  3404. {
  3405. // Command is set for external editors only (not for "shell" open).
  3406. if (!Data->Command.IsEmpty())
  3407. {
  3408. bool AnyFound = false;
  3409. bool AnyMDI = false;
  3410. bool AnyNonMDI = false;
  3411. bool AnyDetect = false;
  3412. TEditorList * EditorList = new TEditorList();
  3413. try
  3414. {
  3415. *EditorList = *WinConfiguration->EditorList;
  3416. for (int i = 0; i < EditorList->Count; i++)
  3417. {
  3418. const TEditorPreferences * Editor = EditorList->Editors[i];
  3419. if ((Editor->Data->Editor == edExternal) &&
  3420. (Editor->Data->ExternalEditor == Data->Command))
  3421. {
  3422. AnyFound = true;
  3423. if (Editor->Data->SDIExternalEditor)
  3424. {
  3425. AnyNonMDI = true;
  3426. if (Editor->Data->DetectMDIExternalEditor)
  3427. {
  3428. AnyDetect = true;
  3429. }
  3430. }
  3431. else
  3432. {
  3433. AnyMDI = true;
  3434. }
  3435. }
  3436. }
  3437. bool EnableMDI = false;
  3438. bool DisableDetect = false;
  3439. if (AnyMDI)
  3440. {
  3441. KeepOpen = true;
  3442. if (AnyNonMDI)
  3443. {
  3444. // there is at least one instance of the editor with MDI support enabled,
  3445. // and one with disabled, enable it for all instances
  3446. EnableMDI = true;
  3447. }
  3448. }
  3449. else if (AnyFound && !AnyDetect)
  3450. {
  3451. // at least once instance found but all have MDI autodetection disabled
  3452. // => close the file (default action)
  3453. }
  3454. else
  3455. {
  3456. // no instance of the editor has MDI support enabled
  3457. TMessageParams Params;
  3458. if (AnyFound)
  3459. {
  3460. // there is at least one instance of the editor
  3461. Params.Params |= mpNeverAskAgainCheck;
  3462. }
  3463. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3464. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3465. switch (Answer)
  3466. {
  3467. case qaNeverAskAgain:
  3468. DisableDetect = true;
  3469. break;
  3470. case qaNo:
  3471. EnableMDI = true;
  3472. KeepOpen = true;
  3473. break;
  3474. }
  3475. }
  3476. if (AnyFound && (EnableMDI || DisableDetect))
  3477. {
  3478. bool Changed = false;
  3479. for (int i = 0; i < EditorList->Count; i++)
  3480. {
  3481. const TEditorPreferences * Editor = EditorList->Editors[i];
  3482. if ((Editor->Data->Editor == edExternal) &&
  3483. (Editor->Data->ExternalEditor == Data->Command) &&
  3484. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3485. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3486. {
  3487. Changed = true;
  3488. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3489. if (EnableMDI)
  3490. {
  3491. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3492. }
  3493. if (DisableDetect)
  3494. {
  3495. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3496. }
  3497. EditorList->Change(i, UpdatedEditor);
  3498. }
  3499. }
  3500. if (Changed)
  3501. {
  3502. WinConfiguration->EditorList = EditorList;
  3503. }
  3504. }
  3505. }
  3506. __finally
  3507. {
  3508. delete EditorList;
  3509. }
  3510. }
  3511. else
  3512. {
  3513. // "open" case
  3514. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3515. qaOK, HELP_APP_EARLY_CLOSED);
  3516. }
  3517. }
  3518. //---------------------------------------------------------------------------
  3519. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3520. {
  3521. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3522. }
  3523. //---------------------------------------------------------------------------
  3524. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3525. {
  3526. SideEnter(osRemote);
  3527. }
  3528. //---------------------------------------------------------------------------
  3529. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3530. {
  3531. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  3532. SideEnter(osRemote);
  3533. }
  3534. //---------------------------------------------------------------------------
  3535. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3536. {
  3537. FCurrentSide = Side;
  3538. if (Visible)
  3539. {
  3540. UpdateControls();
  3541. }
  3542. }
  3543. //---------------------------------------------------------------------------
  3544. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3545. TStrings * FileList, bool Alternative)
  3546. {
  3547. TCustomDirView * DView = DirView(Side);
  3548. DView->SaveSelection();
  3549. DView->SaveSelectedNames();
  3550. DebugAssert(!FAlternativeDelete);
  3551. FAlternativeDelete = Alternative;
  3552. try
  3553. {
  3554. if (Side == osRemote)
  3555. {
  3556. DebugAssert(Terminal != NULL);
  3557. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3558. }
  3559. else
  3560. {
  3561. try
  3562. {
  3563. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3564. }
  3565. __finally
  3566. {
  3567. ReloadLocalDirectory();
  3568. }
  3569. }
  3570. FAlternativeDelete = false;
  3571. }
  3572. catch(...)
  3573. {
  3574. FAlternativeDelete = false;
  3575. DView->DiscardSavedSelection();
  3576. throw;
  3577. }
  3578. DView->RestoreSelection();
  3579. }
  3580. //---------------------------------------------------------------------------
  3581. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3582. {
  3583. DebugAssert(Terminal);
  3584. RemoteDirView->SaveSelection();
  3585. RemoteDirView->SaveSelectedNames();
  3586. try
  3587. {
  3588. if (Lock)
  3589. {
  3590. Terminal->LockFiles(FileList);
  3591. }
  3592. else
  3593. {
  3594. Terminal->UnlockFiles(FileList);
  3595. }
  3596. }
  3597. catch(...)
  3598. {
  3599. RemoteDirView->DiscardSavedSelection();
  3600. throw;
  3601. }
  3602. RemoteDirView->RestoreSelection();
  3603. }
  3604. //---------------------------------------------------------------------------
  3605. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3606. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3607. bool NoConfirmation, bool Move)
  3608. {
  3609. DebugAssert(Terminal != NULL);
  3610. // update Terminal->StateData->RemoteDirectory
  3611. UpdateTerminal(Terminal);
  3612. if (Session == NULL)
  3613. {
  3614. Session = TTerminalManager::Instance()->ActiveTerminal;
  3615. }
  3616. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3617. {
  3618. if (RemoteDriveView->DropTarget != NULL)
  3619. {
  3620. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3621. }
  3622. else if (RemoteDirView->DropTarget != NULL)
  3623. {
  3624. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3625. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3626. }
  3627. else
  3628. {
  3629. Target = RemoteDirView->Path;
  3630. }
  3631. }
  3632. else
  3633. {
  3634. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Session));
  3635. Target = ManagedTerminal->StateData->RemoteDirectory;
  3636. }
  3637. Target = UnixIncludeTrailingBackslash(Target);
  3638. if (FileList->Count == 1)
  3639. {
  3640. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3641. }
  3642. else
  3643. {
  3644. FileMask = AnyMask;
  3645. }
  3646. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3647. bool Result = true;
  3648. if (!NoConfirmation)
  3649. {
  3650. bool Multi = (FileList->Count > 1);
  3651. if (Move)
  3652. {
  3653. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3654. }
  3655. else
  3656. {
  3657. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3658. TStrings * Directories = new TStringList;
  3659. try
  3660. {
  3661. for (int Index = 0; Index < Sessions->Count; Index++)
  3662. {
  3663. TManagedTerminal * Terminal =
  3664. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3665. Directories->Add(Terminal->StateData->RemoteDirectory);
  3666. }
  3667. TDirectRemoteCopy AllowDirectCopy;
  3668. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3669. {
  3670. DebugAssert(DirectCopy);
  3671. AllowDirectCopy = drcAllow;
  3672. }
  3673. else if (FTerminal->IsCapable[fcSecondaryShell])
  3674. {
  3675. DebugAssert(DirectCopy);
  3676. AllowDirectCopy = drcConfirmCommandSession;
  3677. }
  3678. else
  3679. {
  3680. DebugAssert(!DirectCopy);
  3681. AllowDirectCopy = drcDisallow;
  3682. }
  3683. void * ASession = Session;
  3684. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3685. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3686. Session = static_cast<TTerminal *>(ASession);
  3687. }
  3688. __finally
  3689. {
  3690. delete Directories;
  3691. }
  3692. }
  3693. }
  3694. return Result;
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3698. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3699. {
  3700. bool DirectCopy;
  3701. UnicodeString Target, FileMask;
  3702. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3703. if (Result)
  3704. {
  3705. if (!Move && !DirectCopy)
  3706. {
  3707. Configuration->Usage->Inc("RemoteCopyTemp");
  3708. UnicodeString RootTempDir;
  3709. UnicodeString TempDir;
  3710. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3711. TStrings * TemporaryFilesList = new TStringList();
  3712. try
  3713. {
  3714. TMakeLocalFileListParams MakeFileListParam;
  3715. MakeFileListParam.FileList = TemporaryFilesList;
  3716. MakeFileListParam.FileTimes = NULL;
  3717. MakeFileListParam.IncludeDirs = true;
  3718. MakeFileListParam.Recursive = false;
  3719. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3720. TTerminalManager::Instance()->ActiveTerminal = Session;
  3721. if (TemporaryFilesList->Count > 0)
  3722. {
  3723. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3724. CopyParam.FileMask = FileMask;
  3725. DebugAssert(!FAutoOperation);
  3726. FAutoOperation = true;
  3727. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3728. }
  3729. }
  3730. __finally
  3731. {
  3732. delete TemporaryFilesList;
  3733. FAutoOperation = false;
  3734. if (!RootTempDir.IsEmpty())
  3735. {
  3736. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3737. }
  3738. }
  3739. }
  3740. else
  3741. {
  3742. RemoteDirView->SaveSelection();
  3743. RemoteDirView->SaveSelectedNames();
  3744. try
  3745. {
  3746. if (Move)
  3747. {
  3748. Configuration->Usage->Inc("RemoteMove");
  3749. Terminal->MoveFiles(FileList, Target, FileMask);
  3750. }
  3751. else
  3752. {
  3753. Configuration->Usage->Inc("RemoteCopyDirect");
  3754. DebugAssert(DirectCopy);
  3755. DebugAssert(Session == FTerminal);
  3756. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3757. FTerminal->CommandSessionOpened ||
  3758. CommandSessionFallback())
  3759. {
  3760. Terminal->CopyFiles(FileList, Target, FileMask);
  3761. }
  3762. }
  3763. }
  3764. catch(...)
  3765. {
  3766. RemoteDirView->DiscardSavedSelection();
  3767. throw;
  3768. }
  3769. RemoteDirView->RestoreSelection();
  3770. }
  3771. }
  3772. return Result;
  3773. }
  3774. //---------------------------------------------------------------------------
  3775. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3776. const UnicodeString & Path, TRemoteProperties & Properties)
  3777. {
  3778. Properties.Valid = Properties.Valid << vpEncrypt;
  3779. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3780. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3781. }
  3782. //---------------------------------------------------------------------------
  3783. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3784. {
  3785. Side = GetSide(Side);
  3786. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3787. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3788. UnicodeString Name = LoadStr(NEW_FOLDER);
  3789. int AllowedChanges =
  3790. FLAGMASK((Side == osRemote) && Terminal->IsCapable[fcModeChanging], cpMode);
  3791. bool SaveSettings = false;
  3792. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3793. {
  3794. TWindowLock Lock(this);
  3795. if (Side == osRemote)
  3796. {
  3797. if (SaveSettings)
  3798. {
  3799. GUIConfiguration->NewDirectoryProperties = Properties;
  3800. }
  3801. CreateRemoteDirectory(Name, Properties);
  3802. }
  3803. else
  3804. {
  3805. DirView(Side)->CreateDirectory(Name);
  3806. }
  3807. }
  3808. }
  3809. //---------------------------------------------------------------------------
  3810. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3811. {
  3812. TWindowLock Lock(this);
  3813. DirView(Side)->ExecuteHomeDirectory();
  3814. }
  3815. //---------------------------------------------------------------------------
  3816. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3817. {
  3818. DoOpenDirectoryDialog(odBrowse, Side);
  3819. }
  3820. //---------------------------------------------------------------------------
  3821. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3822. {
  3823. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3824. bool Result = !Path.IsEmpty();
  3825. if (Result)
  3826. {
  3827. // While we might get here when the session is closed (from location profiles),
  3828. // it's not a problem as the Path setter is noop then
  3829. DirView(Side)->Path = Path;
  3830. }
  3831. return Result;
  3832. }
  3833. //---------------------------------------------------------------------------
  3834. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3835. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3836. bool & Close)
  3837. {
  3838. // terminal can be already closed (e.g. dropped connection)
  3839. if (Terminal != NULL)
  3840. {
  3841. try
  3842. {
  3843. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3844. }
  3845. catch(...)
  3846. {
  3847. if (!Terminal->Active)
  3848. {
  3849. Close = true;
  3850. }
  3851. throw;
  3852. }
  3853. }
  3854. }
  3855. //---------------------------------------------------------------------------
  3856. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3857. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3858. bool & Close)
  3859. {
  3860. // terminal can be already closed (e.g. dropped connection)
  3861. if (Terminal != NULL)
  3862. {
  3863. Configuration->Usage->Inc(L"ChecksumCalculated");
  3864. try
  3865. {
  3866. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3867. }
  3868. catch(...)
  3869. {
  3870. if (!Terminal->Active)
  3871. {
  3872. Close = true;
  3873. }
  3874. throw;
  3875. }
  3876. }
  3877. }
  3878. //---------------------------------------------------------------------------
  3879. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3880. {
  3881. bool Result;
  3882. if (Side == osRemote)
  3883. {
  3884. TRemoteTokenList * GroupList = NULL;
  3885. TRemoteTokenList * UserList = NULL;
  3886. try
  3887. {
  3888. TRemoteProperties CurrentProperties;
  3889. if (Terminal->LoadFilesProperties(FileList))
  3890. {
  3891. RemoteDirView->Invalidate();
  3892. }
  3893. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3894. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3895. if (CapableGroupChanging || CapableOwnerChanging)
  3896. {
  3897. if (CapableGroupChanging)
  3898. {
  3899. GroupList = Terminal->Groups->Duplicate();
  3900. }
  3901. if (CapableOwnerChanging)
  3902. {
  3903. UserList = Terminal->Users->Duplicate();
  3904. }
  3905. TRemoteDirectory * Files = Terminal->Files;
  3906. int Count = Files->Count;
  3907. if (Count > 100)
  3908. {
  3909. Count = 100;
  3910. }
  3911. for (int Index = 0; Index < Count; Index++)
  3912. {
  3913. TRemoteFile * File = Files->Files[Index];
  3914. if (CapableGroupChanging)
  3915. {
  3916. GroupList->AddUnique(File->Group);
  3917. }
  3918. if (CapableOwnerChanging)
  3919. {
  3920. UserList->AddUnique(File->Owner);
  3921. }
  3922. }
  3923. // if we haven't collected tokens for all files in current directory,
  3924. // make sure we collect them at least for all selected files.
  3925. // (note that so far the files in FileList has to be from current direcotry)
  3926. if (Count < Files->Count)
  3927. {
  3928. for (int Index = 0; Index < FileList->Count; Index++)
  3929. {
  3930. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  3931. if (CapableGroupChanging)
  3932. {
  3933. GroupList->AddUnique(File->Group);
  3934. }
  3935. if (CapableOwnerChanging)
  3936. {
  3937. UserList->AddUnique(File->Owner);
  3938. }
  3939. }
  3940. }
  3941. }
  3942. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  3943. int Flags = 0;
  3944. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  3945. if (CapableOwnerChanging) Flags |= cpOwner;
  3946. if (CapableGroupChanging) Flags |= cpGroup;
  3947. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  3948. if (Terminal->IsCapable[fcCalculatingChecksum])
  3949. {
  3950. CalculateChecksumEvent = CalculateChecksum;
  3951. }
  3952. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  3953. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  3954. TRemoteProperties NewProperties = CurrentProperties;
  3955. Result =
  3956. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  3957. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  3958. Terminal->IsCapable[fcGroupOwnerChangingByID],
  3959. CalculateSize, CalculateChecksumEvent);
  3960. if (Result)
  3961. {
  3962. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  3963. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  3964. }
  3965. }
  3966. __finally
  3967. {
  3968. delete GroupList;
  3969. delete UserList;
  3970. }
  3971. }
  3972. else
  3973. {
  3974. DirView(Side)->DisplayPropertiesMenu();
  3975. Result = true;
  3976. }
  3977. return Result;
  3978. }
  3979. //---------------------------------------------------------------------------
  3980. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  3981. {
  3982. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  3983. {
  3984. FIgnoreNextDialogChar = Key;
  3985. }
  3986. Key = 0;
  3987. }
  3988. //---------------------------------------------------------------------------
  3989. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  3990. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  3991. {
  3992. const TCustomCommandType * Command = List->Find(KeyShortCut);
  3993. if (Command != NULL)
  3994. {
  3995. KeyProcessed(Key, Shift);
  3996. if (CustomCommandState(*Command, false, ccltAll) > 0)
  3997. {
  3998. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  3999. false, false, const_cast<TCustomCommandType *>(Command));
  4000. }
  4001. }
  4002. }
  4003. //---------------------------------------------------------------------------
  4004. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4005. {
  4006. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4007. {
  4008. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4009. }
  4010. if (!DirView(osCurrent)->IsEditing())
  4011. {
  4012. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4013. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4014. {
  4015. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4016. if (((Action->ShortCut == KeyShortCut) ||
  4017. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4018. AllowedAction(Action, aaShortCut))
  4019. {
  4020. // Has to be called before the action as the dialog char is already in queue.
  4021. // So when the action consumes message queue, we already need to have the
  4022. // FIgnoreNextDialogChar set
  4023. KeyProcessed(Key, Shift);
  4024. // Reset reference to previous component (when menu/toolbar was clicked).
  4025. // Needed to detect that action was invoked by keyboard shortcut
  4026. // in TNonVisualDataModule::ExplorerActionsExecute
  4027. Action->ActionComponent = NULL;
  4028. Action->Execute();
  4029. return;
  4030. }
  4031. }
  4032. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4033. {
  4034. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4035. {
  4036. KeyProcessed(Key, Shift);
  4037. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4038. return;
  4039. }
  4040. }
  4041. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4042. {
  4043. KeyProcessed(Key, Shift);
  4044. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4045. }
  4046. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4047. if (IsCustomShortCut(CustomShortCut))
  4048. {
  4049. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4050. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4051. if (WinConfiguration->SharedBookmarks != NULL)
  4052. {
  4053. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4054. if ((Bookmark != NULL) &&
  4055. OpenBookmark(FCurrentSide, Bookmark))
  4056. {
  4057. KeyProcessed(Key, Shift);
  4058. }
  4059. }
  4060. }
  4061. }
  4062. TForm::KeyDown(Key, Shift);
  4063. }
  4064. //---------------------------------------------------------------------------
  4065. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4066. {
  4067. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4068. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4069. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4070. DebugAssert(Terminal);
  4071. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4072. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4073. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4074. // expanded from ?: to avoid memory leaks
  4075. if (SecurityEnabled)
  4076. {
  4077. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4078. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4079. }
  4080. else
  4081. {
  4082. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4083. }
  4084. if (FileSystemInfo.ProtocolName.IsEmpty())
  4085. {
  4086. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4087. }
  4088. else
  4089. {
  4090. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4091. }
  4092. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4093. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4094. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4095. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4096. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4097. UnicodeString CompressionStr = CSCompressionStr;
  4098. if (CSCompressionStr != SCCompressionStr)
  4099. {
  4100. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4101. }
  4102. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4103. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4104. UpdateStatusBar();
  4105. }
  4106. //---------------------------------------------------------------------------
  4107. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4108. {
  4109. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4110. DebugAssert(SessionStatusBar != NULL);
  4111. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4112. {
  4113. // note: (Terminal->Status < sshReady) currently never happens here,
  4114. // so STATUS_CONNECTING is never used
  4115. SessionStatusBar->SimplePanel = true;
  4116. SessionStatusBar->SimpleText = LoadStr(
  4117. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4118. }
  4119. else
  4120. {
  4121. DebugAssert(Terminal);
  4122. SessionStatusBar->SimplePanel = false;
  4123. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4124. if (!FNote.IsEmpty())
  4125. {
  4126. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4127. }
  4128. else
  4129. {
  4130. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4131. }
  4132. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4133. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4134. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4135. }
  4136. }
  4137. //---------------------------------------------------------------------------
  4138. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4139. {
  4140. Panel->Caption = L"";
  4141. }
  4142. //---------------------------------------------------------------------------
  4143. void __fastcall TCustomScpExplorerForm::Idle()
  4144. {
  4145. if (FShowing || FStandaloneEditing)
  4146. {
  4147. FEditorManager->Check();
  4148. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4149. // that needs to know if queue view is visible (and it may be closed after queue update)
  4150. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4151. }
  4152. if (FShowing)
  4153. {
  4154. if (!NonVisualDataModule->Busy &&
  4155. // Menu is opened or drag&drop is going on
  4156. (Mouse->Capture == NULL))
  4157. {
  4158. if (FRefreshRemoteDirectory)
  4159. {
  4160. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4161. {
  4162. Terminal->RefreshDirectory();
  4163. }
  4164. FRefreshRemoteDirectory = false;
  4165. }
  4166. if (FRefreshLocalDirectory)
  4167. {
  4168. ReloadLocalDirectory();
  4169. FRefreshLocalDirectory = false;
  4170. }
  4171. if (WinConfiguration->RefreshRemotePanel)
  4172. {
  4173. TManagedTerminal * ManagedTerminal =
  4174. dynamic_cast<TManagedTerminal *>(Terminal);
  4175. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  4176. (Now() - ManagedTerminal->DirectoryLoaded >
  4177. WinConfiguration->RefreshRemotePanelInterval))
  4178. {
  4179. RemoteDirView->ReloadDirectory();
  4180. }
  4181. }
  4182. }
  4183. }
  4184. if (FShowing || FStandaloneEditing)
  4185. {
  4186. if (FQueueStatusInvalidated)
  4187. {
  4188. UpdateQueueStatus(false);
  4189. }
  4190. RefreshQueueItems();
  4191. }
  4192. if (FShowing)
  4193. {
  4194. UpdateStatusBar();
  4195. }
  4196. FIgnoreNextDialogChar = 0;
  4197. }
  4198. //---------------------------------------------------------------------------
  4199. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4200. {
  4201. try
  4202. {
  4203. FUserActionTimer->Enabled = false;
  4204. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4205. {
  4206. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4207. {
  4208. FPendingQueueActionItem->ProcessUserAction();
  4209. }
  4210. }
  4211. }
  4212. __finally
  4213. {
  4214. FPendingQueueActionItem = NULL;
  4215. }
  4216. }
  4217. //---------------------------------------------------------------------------
  4218. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4219. {
  4220. if (WinConfiguration->MinimizeToTray)
  4221. {
  4222. UpdateTrayIcon();
  4223. FTrayIcon->Visible = true;
  4224. if (Visible)
  4225. {
  4226. ShowWindow(Handle, SW_HIDE);
  4227. }
  4228. }
  4229. }
  4230. //---------------------------------------------------------------------------
  4231. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4232. {
  4233. // WORKAROUND
  4234. // When restoring maximized window from minimization,
  4235. // rarely some controls do not align properly.
  4236. // Two instances seen (both for Commander):
  4237. // - When restoring, window is temporarily narrower (not maximized),
  4238. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4239. // Once maximized already, top dock shinks back, but the session PageControl,
  4240. // do not align up, leaving space between TopDock and PageControl.
  4241. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4242. for (int Index = 0; Index < ControlCount; Index++)
  4243. {
  4244. RealignControl(Controls[Index]);
  4245. }
  4246. if (FTrayIcon->Visible)
  4247. {
  4248. FTrayIcon->Visible = false;
  4249. if (Visible)
  4250. {
  4251. ShowWindow(Handle, SW_SHOW);
  4252. }
  4253. }
  4254. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4255. {
  4256. FNeedSession = false;
  4257. NonVisualDataModule->StartBusy();
  4258. try
  4259. {
  4260. NeedSession(false);
  4261. }
  4262. __finally
  4263. {
  4264. NonVisualDataModule->EndBusy();
  4265. }
  4266. }
  4267. }
  4268. //---------------------------------------------------------------------------
  4269. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4270. {
  4271. FTrayIcon->Hint = GetMainForm()->Caption;
  4272. }
  4273. //---------------------------------------------------------------------------
  4274. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4275. {
  4276. UpdateTrayIcon();
  4277. }
  4278. //---------------------------------------------------------------------------
  4279. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4280. {
  4281. // workaround
  4282. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4283. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4284. // But WM_ACTIVATEAPP message can be received even when
  4285. // the main window is minimized to the tray and internal editor window is focused
  4286. // (after another application was previously active)
  4287. if (::IsIconic(Handle))
  4288. {
  4289. if (!IsAppIconic())
  4290. {
  4291. SetAppIconic(true);
  4292. }
  4293. }
  4294. ::ApplicationRestore();
  4295. Application->BringToFront();
  4296. }
  4297. //---------------------------------------------------------------------------
  4298. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4299. {
  4300. RestoreApp();
  4301. }
  4302. //---------------------------------------------------------------------------
  4303. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4304. {
  4305. if (OpenInNewWindow())
  4306. {
  4307. // todo: Pass FromSite
  4308. ExecuteNewInstance(SessionUrl);
  4309. }
  4310. else
  4311. {
  4312. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4313. }
  4314. }
  4315. //---------------------------------------------------------------------------
  4316. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4317. {
  4318. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4319. // current working directories become defaults here, what is not right
  4320. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4321. StoredSessions->NewSession(SessionName, SessionData.get());
  4322. // modified only, explicit
  4323. StoredSessions->Save(false, true);
  4324. // encode session name because of slashes in hierarchical sessions
  4325. return EncodeUrlString(SessionName);
  4326. }
  4327. //---------------------------------------------------------------------------
  4328. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4329. {
  4330. if (OpenInNewWindow())
  4331. {
  4332. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4333. }
  4334. else
  4335. {
  4336. // current working directories become defaults here, what is not right
  4337. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4338. TTerminalManager * Manager = TTerminalManager::Instance();
  4339. TTerminal * Terminal = Manager->NewTerminal(SessionData.get());
  4340. Manager->ActiveTerminal = Terminal;
  4341. }
  4342. }
  4343. //---------------------------------------------------------------------------
  4344. void __fastcall TCustomScpExplorerForm::RenameSession()
  4345. {
  4346. UnicodeString Name = Terminal->SessionData->Name;
  4347. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4348. {
  4349. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4350. TSessionData::ValidateName(Name);
  4351. // This is inconsistent with how color (for example) is handled.
  4352. Terminal->SessionData->Name = Name;
  4353. UpdateControls();
  4354. // Add/Remove distinguishing paths from sessions of the same name.
  4355. DoTerminalListChanged();
  4356. }
  4357. }
  4358. //---------------------------------------------------------------------------
  4359. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4360. {
  4361. DebugAssert(Queue != NULL);
  4362. bool Result = Queue->IsEmpty;
  4363. if (!Result)
  4364. {
  4365. SetFocus();
  4366. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4367. }
  4368. return Result;
  4369. }
  4370. //---------------------------------------------------------------------------
  4371. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4372. {
  4373. return CanCloseQueue(FQueue);
  4374. }
  4375. //---------------------------------------------------------------------------
  4376. void __fastcall TCustomScpExplorerForm::CloseSession()
  4377. {
  4378. if (CanCloseQueue())
  4379. {
  4380. TTerminalManager::Instance()->FreeActiveTerminal();
  4381. }
  4382. }
  4383. //---------------------------------------------------------------------------
  4384. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4385. {
  4386. if (OpenInNewWindow())
  4387. {
  4388. // encode session name because of slashes in hierarchical sessions
  4389. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4390. }
  4391. else
  4392. {
  4393. TTerminalManager * Manager = TTerminalManager::Instance();
  4394. TTerminal * Terminal = Manager->NewTerminal(Data);
  4395. Manager->ActiveTerminal = Terminal;
  4396. }
  4397. }
  4398. //---------------------------------------------------------------------------
  4399. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4400. {
  4401. if (OpenInNewWindow())
  4402. {
  4403. ExecuteNewInstance(Name);
  4404. }
  4405. else
  4406. {
  4407. TTerminalManager * Manager = TTerminalManager::Instance();
  4408. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4409. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4410. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4411. }
  4412. }
  4413. //---------------------------------------------------------------------------
  4414. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4415. bool &CanClose)
  4416. {
  4417. if (Terminal != NULL)
  4418. {
  4419. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4420. {
  4421. unsigned int Result;
  4422. TMessageParams Params(mpNeverAskAgainCheck);
  4423. UnicodeString Message;
  4424. int Answers = qaOK | qaCancel;
  4425. if (TTerminalManager::Instance()->Count > 1)
  4426. {
  4427. if (!WinConfiguration->AutoSaveWorkspace)
  4428. {
  4429. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4430. Answers = qaYes | qaNo | qaCancel;
  4431. }
  4432. else
  4433. {
  4434. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4435. }
  4436. }
  4437. else
  4438. {
  4439. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4440. }
  4441. if (WinConfiguration->AutoSaveWorkspace)
  4442. {
  4443. Message =
  4444. FORMAT("%s\n\n%s", (Message,
  4445. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4446. }
  4447. SetFocus();
  4448. Result = MessageDialog(Message, qtConfirmation,
  4449. Answers, HELP_NONE, &Params);
  4450. if (Result == qaNeverAskAgain)
  4451. {
  4452. WinConfiguration->ConfirmClosingSession = false;
  4453. }
  4454. if (Result == qaNo)
  4455. {
  4456. CanClose = SaveWorkspace(true);
  4457. // note that the workspace will be saved redundatly again from FormClose
  4458. }
  4459. else
  4460. {
  4461. CanClose =
  4462. (Result == qaOK) ||
  4463. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4464. (Result == qaNeverAskAgain);
  4465. }
  4466. }
  4467. if (CanClose)
  4468. {
  4469. CanClose = CanCloseQueue();
  4470. }
  4471. }
  4472. if (CanClose)
  4473. {
  4474. CanClose =
  4475. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4476. FEditorManager->CloseExternalFilesWithoutProcess();
  4477. if (CanClose)
  4478. {
  4479. while (CanClose && (FLocalEditors->Count > 0))
  4480. {
  4481. int PrevCount = FLocalEditors->Count;
  4482. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4483. CanClose = (FLocalEditors->Count < PrevCount);
  4484. }
  4485. if (CanClose)
  4486. {
  4487. CanClose = FEditorManager->Empty(true);
  4488. if (!CanClose)
  4489. {
  4490. SetFocus();
  4491. CanClose =
  4492. (MessageDialog(
  4493. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4494. }
  4495. }
  4496. }
  4497. }
  4498. }
  4499. //---------------------------------------------------------------------------
  4500. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4501. {
  4502. TForm * Form = dynamic_cast<TForm *>(Sender);
  4503. DebugAssert(Form != NULL);
  4504. Form->Close();
  4505. }
  4506. //---------------------------------------------------------------------------
  4507. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4508. {
  4509. TForm * Form = dynamic_cast<TForm *>(Sender);
  4510. delete Form;
  4511. }
  4512. //---------------------------------------------------------------------------
  4513. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4514. {
  4515. while (FLocalEditors->Count > 0)
  4516. {
  4517. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4518. }
  4519. }
  4520. //---------------------------------------------------------------------------
  4521. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4522. TObject *Sender)
  4523. {
  4524. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4525. try
  4526. {
  4527. SetProperties(osRemote, FileList);
  4528. }
  4529. __finally
  4530. {
  4531. delete FileList;
  4532. }
  4533. }
  4534. //---------------------------------------------------------------------------
  4535. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4536. {
  4537. if (value)
  4538. {
  4539. if (Component == fcCustomCommandsBand)
  4540. {
  4541. UpdateCustomCommandsToolbar();
  4542. }
  4543. }
  4544. }
  4545. //---------------------------------------------------------------------------
  4546. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4547. {
  4548. TControl * Control = GetComponent(Component);
  4549. DebugAssert(Control);
  4550. bool Changed = (Control->Visible != value);
  4551. if (Changed)
  4552. {
  4553. ComponentShowing(Component, value);
  4554. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4555. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4556. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4557. if (value)
  4558. {
  4559. int RemainingHeight = Control->Parent->ClientHeight;
  4560. int RemainingWidth = Control->Parent->ClientWidth;
  4561. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4562. {
  4563. TControl * ChildControl = Control->Parent->Controls[i];
  4564. if (ChildControl->Visible)
  4565. {
  4566. switch (ChildControl->Align)
  4567. {
  4568. case alTop:
  4569. case alBottom:
  4570. RemainingHeight -= ChildControl->Height;
  4571. break;
  4572. case alLeft:
  4573. case alRight:
  4574. RemainingWidth -= ChildControl->Width;
  4575. break;
  4576. }
  4577. }
  4578. }
  4579. int Reserve = ScaleByTextHeight(this, 32);
  4580. // queue in explorer, trees in commander
  4581. if (Control->Height > RemainingHeight - Reserve)
  4582. {
  4583. Control->Height = RemainingHeight / 2;
  4584. }
  4585. if (Control->Width > RemainingWidth - Reserve)
  4586. {
  4587. Control->Width = RemainingWidth / 2;
  4588. }
  4589. }
  4590. Control->Visible = value;
  4591. if (WasFocused && Visible)
  4592. {
  4593. DirView(osCurrent)->SetFocus();
  4594. }
  4595. FixControlsPlacement();
  4596. }
  4597. }
  4598. //---------------------------------------------------------------------------
  4599. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4600. {
  4601. TControl * Control = GetComponent(Component);
  4602. if (Control == NULL)
  4603. {
  4604. return false;
  4605. }
  4606. else
  4607. {
  4608. return Control->Visible;
  4609. }
  4610. }
  4611. //---------------------------------------------------------------------------
  4612. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4613. {
  4614. bool Result;
  4615. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4616. {
  4617. Result = !IsUWP();
  4618. }
  4619. else
  4620. {
  4621. Result = true;
  4622. }
  4623. return Result;
  4624. }
  4625. //---------------------------------------------------------------------------
  4626. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4627. {
  4628. if (RemoteDirView->ItemFocused != NULL)
  4629. {
  4630. RemoteDirView->ItemFocused->MakeVisible(false);
  4631. }
  4632. QueueSplitter->Visible = QueuePanel->Visible;
  4633. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  4634. }
  4635. //---------------------------------------------------------------------------
  4636. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4637. {
  4638. switch (Component) {
  4639. case fcStatusBar: return RemoteStatusBar;
  4640. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4641. case fcQueueView: return QueuePanel;
  4642. case fcQueueToolbar: return QueueDock;
  4643. case fcRemoteTree: return RemoteDriveView;
  4644. case fcSessionsTabs: return SessionsPageControl;
  4645. default: return NULL;
  4646. }
  4647. }
  4648. //---------------------------------------------------------------------------
  4649. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4650. TObject *Sender, TListColumn *Column, TPoint &Point)
  4651. {
  4652. DebugAssert(NonVisualDataModule && Column && Sender);
  4653. NonVisualDataModule->ListColumn = Column;
  4654. TPopupMenu * DirViewColumnMenu;
  4655. if (Sender == RemoteDirView)
  4656. {
  4657. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4658. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4659. (Column->Index == uvName);
  4660. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4661. (Column->Index == uvSize);
  4662. }
  4663. else
  4664. {
  4665. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4666. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4667. (Column->Index == dvName);
  4668. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4669. (Column->Index == dvSize);
  4670. }
  4671. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4672. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4673. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4674. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4675. }
  4676. //---------------------------------------------------------------------------
  4677. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4678. TObject *Sender, TListItem *Item, bool &AllowExec)
  4679. {
  4680. DoDirViewExecFile(Sender, Item, AllowExec);
  4681. }
  4682. //---------------------------------------------------------------------------
  4683. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4684. TListItem * Item, bool & AllowExec)
  4685. {
  4686. DebugAssert(Sender && Item && Configuration);
  4687. DebugAssert(AllowExec);
  4688. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4689. bool Remote = (ADirView == DirView(osRemote));
  4690. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4691. TOperationSide Side = (Remote ? osRemote : osLocal);
  4692. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4693. // on files only (not directories)
  4694. // and only when symlinks are resolved (apply to remote panel only)
  4695. if (!ADirView->ItemIsDirectory(Item) &&
  4696. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4697. {
  4698. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4699. !FForceExecution &&
  4700. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4701. {
  4702. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4703. {
  4704. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4705. UnlockWindow();
  4706. try
  4707. {
  4708. ExecuteFileOperation(
  4709. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4710. }
  4711. __finally
  4712. {
  4713. LockWindow();
  4714. }
  4715. AllowExec = false;
  4716. }
  4717. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4718. {
  4719. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4720. {
  4721. ExecuteFile(Side, efDefaultEditor);
  4722. AllowExec = false;
  4723. }
  4724. }
  4725. else
  4726. {
  4727. DebugFail();
  4728. }
  4729. }
  4730. // if we have not done anything special, fall back to default behavior
  4731. if (AllowExec)
  4732. {
  4733. if (Remote && !WinConfiguration->DisableOpenEdit)
  4734. {
  4735. ExecuteFile(osRemote, efShell);
  4736. AllowExec = false;
  4737. }
  4738. }
  4739. }
  4740. }
  4741. //---------------------------------------------------------------------------
  4742. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4743. {
  4744. return ((Side == osRemote) || (Side == osCurrent));
  4745. }
  4746. //---------------------------------------------------------------------------
  4747. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4748. {
  4749. DebugFail();
  4750. }
  4751. //---------------------------------------------------------------------------
  4752. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4753. {
  4754. DebugFail();
  4755. }
  4756. //---------------------------------------------------------------------------
  4757. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4758. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4759. {
  4760. TSynchronizeParamType Params;
  4761. Params.LocalDirectory = LocalDirectory;
  4762. Params.RemoteDirectory = RemoteDirectory;
  4763. int UnusedParams =
  4764. (GUIConfiguration->SynchronizeParams &
  4765. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4766. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4767. Params.Options = GUIConfiguration->SynchronizeOptions;
  4768. bool SaveSettings = false;
  4769. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4770. &DoSynchronizeTooManyDirectories);
  4771. DebugAssert(FSynchronizeController == NULL);
  4772. FSynchronizeController = &Controller;
  4773. bool Result;
  4774. try
  4775. {
  4776. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4777. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4778. int Options =
  4779. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4780. DebugAssert(FOnFeedSynchronizeError == NULL);
  4781. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4782. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4783. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4784. if (Result)
  4785. {
  4786. if (SaveSettings)
  4787. {
  4788. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4789. GUIConfiguration->SynchronizeOptions = Params.Options;
  4790. }
  4791. else
  4792. {
  4793. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4794. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4795. FLAGSET(Params.Options, soSynchronize))
  4796. {
  4797. GUIConfiguration->SynchronizeOptions =
  4798. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4799. soSynchronize;
  4800. }
  4801. }
  4802. LocalDirectory = Params.LocalDirectory;
  4803. RemoteDirectory = Params.RemoteDirectory;
  4804. }
  4805. }
  4806. __finally
  4807. {
  4808. FSynchronizeController = NULL;
  4809. DebugAssert(FOnFeedSynchronizeError == NULL);
  4810. FOnFeedSynchronizeError = NULL;
  4811. }
  4812. return Result;
  4813. }
  4814. //---------------------------------------------------------------------------
  4815. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4816. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4817. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4818. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4819. TSynchronizeOptions * Options, bool Full)
  4820. {
  4821. // Keep-up-to-date mode
  4822. if (Terminal->Status == ssOpened)
  4823. {
  4824. try
  4825. {
  4826. int PParams = Params.Params;
  4827. if (!Full)
  4828. {
  4829. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  4830. if (FLAGSET(Params.Options, soRecurse))
  4831. {
  4832. PParams |= TTerminal::spSubDirs;
  4833. }
  4834. }
  4835. else
  4836. {
  4837. // if keepuptodate is non-recursive,
  4838. // full sync before has to be non-recursive as well
  4839. if (FLAGCLEAR(Params.Options, soRecurse))
  4840. {
  4841. PParams |= TTerminal::spNoRecurse;
  4842. }
  4843. }
  4844. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4845. PParams, Checklist, Options);
  4846. }
  4847. catch (Exception & E)
  4848. {
  4849. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4850. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4851. {
  4852. // noop, already logged in MoreMessageDialog
  4853. }
  4854. else
  4855. {
  4856. ShowExtendedExceptionEx(Terminal, &E);
  4857. throw;
  4858. }
  4859. }
  4860. }
  4861. }
  4862. //---------------------------------------------------------------------------
  4863. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4864. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4865. const UnicodeString ErrorStr)
  4866. {
  4867. if (!Directory.IsEmpty())
  4868. {
  4869. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4870. }
  4871. else
  4872. {
  4873. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4874. }
  4875. }
  4876. //---------------------------------------------------------------------------
  4877. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4878. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4879. {
  4880. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4881. {
  4882. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4883. }
  4884. else
  4885. {
  4886. TMessageParams Params(mpNeverAskAgainCheck);
  4887. unsigned int Result = MessageDialog(
  4888. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4889. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4890. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4891. {
  4892. MaxDirectories *= 2;
  4893. if (Result == qaNeverAskAgain)
  4894. {
  4895. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4896. }
  4897. }
  4898. else
  4899. {
  4900. Abort();
  4901. }
  4902. }
  4903. }
  4904. //---------------------------------------------------------------------------
  4905. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4906. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4907. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4908. TSynchronizeOptions * Options)
  4909. {
  4910. // Keep-up-to-date mode
  4911. DebugAssert(!FAutoOperation);
  4912. void * BatchStorage;
  4913. BatchStart(BatchStorage);
  4914. FAutoOperation = true;
  4915. bool AnyOperation = false;
  4916. TDateTime StartTime = Now();
  4917. TSynchronizeChecklist * AChecklist = NULL;
  4918. try
  4919. {
  4920. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4921. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4922. {
  4923. FSynchronizeProgressForm->Start();
  4924. }
  4925. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4926. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4927. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4928. Options);
  4929. SAFE_DESTROY(FSynchronizeProgressForm);
  4930. AnyOperation = (AChecklist->CheckedCount > 0);
  4931. if (AnyOperation)
  4932. {
  4933. TSynchronizeProgress SynchronizeProgress(AChecklist);
  4934. CreateProgressForm(&SynchronizeProgress);
  4935. try
  4936. {
  4937. Terminal->SynchronizeApply(
  4938. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4939. SynchronizeProcessedItem, NULL, NULL, NULL);
  4940. }
  4941. __finally
  4942. {
  4943. DestroyProgressForm();
  4944. }
  4945. }
  4946. }
  4947. __finally
  4948. {
  4949. if (Checklist == NULL)
  4950. {
  4951. delete AChecklist;
  4952. }
  4953. else
  4954. {
  4955. *Checklist = AChecklist;
  4956. }
  4957. FAutoOperation = false;
  4958. SAFE_DESTROY(FSynchronizeProgressForm);
  4959. BatchEnd(BatchStorage);
  4960. ReloadLocalDirectory();
  4961. if (AnyOperation)
  4962. {
  4963. OperationComplete(StartTime);
  4964. }
  4965. }
  4966. }
  4967. //---------------------------------------------------------------------------
  4968. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  4969. {
  4970. // can be called from command line
  4971. return Visible &&
  4972. ((DirView(osRemote)->SelCount > 0) ||
  4973. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  4974. }
  4975. //---------------------------------------------------------------------------
  4976. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  4977. {
  4978. LogSynchronizeEvent(Terminal, Message);
  4979. }
  4980. //---------------------------------------------------------------------------
  4981. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  4982. int Params, TSynchronizeOptions & Options)
  4983. {
  4984. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  4985. {
  4986. Options.Filter = new TStringList();
  4987. Options.Filter->CaseSensitive = false;
  4988. Options.Filter->Duplicates = Types::dupAccept;
  4989. if (DirView(osRemote)->SelCount > 0)
  4990. {
  4991. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  4992. }
  4993. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  4994. {
  4995. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  4996. }
  4997. Options.Filter->Sort();
  4998. }
  4999. }
  5000. //---------------------------------------------------------------------------
  5001. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5002. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5003. {
  5004. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5005. UnicodeString AdditionalParams =
  5006. FORMAT(L"%s \"%s\" \"%s\" %d %d %s", (
  5007. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5008. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options,
  5009. TProgramParams::FormatSwitch(DEFAULTS_SWITCH)));
  5010. TCopyParamType Defaults;
  5011. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5012. ConfigStorage->AccessMode = smRead;
  5013. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false, false))
  5014. {
  5015. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5016. }
  5017. ConfigStorage.reset(NULL);
  5018. std::unique_ptr<TStringList> Options(new TStringList());
  5019. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5020. GUIConfiguration->SaveCopyParam(OptionsStorage.get(), CopyParams, &Defaults);
  5021. if (Options->Count > 0)
  5022. {
  5023. AdditionalParams +=
  5024. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAW_CONFIG_SWITCH), StringsToParams(Options.get())));
  5025. }
  5026. ExecuteNewInstance(SessionName, AdditionalParams);
  5027. }
  5028. //---------------------------------------------------------------------------
  5029. struct TSynchronizeParams
  5030. {
  5031. UnicodeString LocalDirectory;
  5032. UnicodeString RemoteDirectory;
  5033. TSynchronizeMode Mode;
  5034. TSynchronizeChecklist * Checklist;
  5035. int Params;
  5036. TCopyParamType * CopyParam;
  5037. TDateTime CollectElapsed;
  5038. TDateTime * StartTime;
  5039. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5040. };
  5041. //---------------------------------------------------------------------------
  5042. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5043. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5044. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5045. {
  5046. DebugAssert(!FAutoOperation);
  5047. void * BatchStorage;
  5048. BatchStart(BatchStorage);
  5049. FAutoOperation = true;
  5050. TFileOperationStatistics Statistics;
  5051. TDateTime Start = Now();
  5052. try
  5053. {
  5054. Params.OnProcessedItem = OnProcessedItem;
  5055. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5056. CreateProgressForm(&SynchronizeProgress);
  5057. Terminal->SynchronizeApply(
  5058. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5059. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5060. &Statistics);
  5061. }
  5062. __finally
  5063. {
  5064. Params.OnProcessedItem = NULL;
  5065. FAutoOperation = false;
  5066. DestroyProgressForm();
  5067. BatchEnd(BatchStorage);
  5068. ReloadLocalDirectory();
  5069. }
  5070. if (WinConfiguration->SynchronizeSummary)
  5071. {
  5072. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5073. // The statistics should be 0 anyway in this case
  5074. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5075. {
  5076. Message += L"\n";
  5077. if (Statistics.FilesUploaded > 0)
  5078. {
  5079. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5080. }
  5081. if (Statistics.FilesDownloaded > 0)
  5082. {
  5083. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5084. }
  5085. if (Statistics.FilesDeletedLocal > 0)
  5086. {
  5087. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5088. }
  5089. if (Statistics.FilesDeletedRemote > 0)
  5090. {
  5091. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5092. }
  5093. }
  5094. TDateTime Elapsed = (Now() - Start);
  5095. Message +=
  5096. L"\n" +
  5097. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5098. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5099. TMessageParams Params(mpNeverAskAgainCheck);
  5100. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5101. if (Result == qaNeverAskAgain)
  5102. {
  5103. WinConfiguration->SynchronizeSummary = false;
  5104. }
  5105. }
  5106. }
  5107. //---------------------------------------------------------------------------
  5108. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5109. {
  5110. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5111. {
  5112. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5113. }
  5114. // Not set in keep-up-to-date mode - Synchronize() method
  5115. if (Token != NULL)
  5116. {
  5117. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5118. if (Params.OnProcessedItem != NULL)
  5119. {
  5120. Params.OnProcessedItem(NULL, ChecklistItem);
  5121. }
  5122. }
  5123. }
  5124. //---------------------------------------------------------------------------
  5125. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5126. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5127. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5128. {
  5129. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5130. *Params.StartTime = Now();
  5131. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5132. }
  5133. //---------------------------------------------------------------------------
  5134. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5135. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5136. {
  5137. // terminal can be already closed (e.g. dropped connection)
  5138. if (Terminal != NULL)
  5139. {
  5140. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5141. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5142. }
  5143. }
  5144. //---------------------------------------------------------------------------
  5145. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5146. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5147. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  5148. {
  5149. int Result;
  5150. int Params = GUIConfiguration->SynchronizeParams;
  5151. bool SaveSettings = false;
  5152. int Options =
  5153. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5154. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5155. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5156. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5157. bool Continue =
  5158. UseDefaults ||
  5159. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5160. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  5161. if (Continue)
  5162. {
  5163. Configuration->Usage->Inc(L"Synchronizations");
  5164. UpdateCopyParamCounters(CopyParam);
  5165. TSynchronizeOptions SynchronizeOptions;
  5166. GetSynchronizeOptions(Params, SynchronizeOptions);
  5167. if (SaveSettings)
  5168. {
  5169. GUIConfiguration->SynchronizeParams = Params;
  5170. }
  5171. else
  5172. {
  5173. SaveMode = false;
  5174. }
  5175. TDateTime StartTime = Now();
  5176. TSynchronizeChecklist * Checklist = NULL;
  5177. try
  5178. {
  5179. DebugAssert(!FAutoOperation);
  5180. FAutoOperation = true;
  5181. try
  5182. {
  5183. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  5184. FSynchronizeProgressForm->Start();
  5185. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5186. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5187. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5188. &SynchronizeOptions);
  5189. }
  5190. __finally
  5191. {
  5192. FAutoOperation = false;
  5193. SAFE_DESTROY(FSynchronizeProgressForm);
  5194. }
  5195. TSynchronizeParams SynchronizeParams;
  5196. SynchronizeParams.LocalDirectory = LocalDirectory;
  5197. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5198. SynchronizeParams.Mode = Mode;
  5199. SynchronizeParams.CopyParam = &CopyParam;
  5200. SynchronizeParams.Params = Params;
  5201. SynchronizeParams.Checklist = Checklist;
  5202. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5203. SynchronizeParams.StartTime = &StartTime;
  5204. SynchronizeParams.OnProcessedItem = NULL;
  5205. Result = Checklist->Count;
  5206. if (Checklist->Count > 0)
  5207. {
  5208. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5209. {
  5210. if (!DoSynchronizeChecklistDialog(
  5211. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5212. DoSynchronizeChecklistCalculateSize, &SynchronizeParams))
  5213. {
  5214. Result = -1;
  5215. }
  5216. }
  5217. else
  5218. {
  5219. FullSynchronize(SynchronizeParams, NULL, NULL);
  5220. }
  5221. }
  5222. else
  5223. {
  5224. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5225. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5226. }
  5227. }
  5228. __finally
  5229. {
  5230. delete Checklist;
  5231. }
  5232. OperationComplete(StartTime);
  5233. }
  5234. else
  5235. {
  5236. Result = -1;
  5237. }
  5238. return Result;
  5239. }
  5240. //---------------------------------------------------------------------------
  5241. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5242. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  5243. bool & Continue, bool Collect)
  5244. {
  5245. if (Collect)
  5246. {
  5247. DebugAssert(FSynchronizeProgressForm != NULL);
  5248. if (!FSynchronizeProgressForm->Started)
  5249. {
  5250. FSynchronizeProgressForm->Start();
  5251. }
  5252. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  5253. }
  5254. else
  5255. {
  5256. DebugAssert(FSynchronizeProgressForm == NULL);
  5257. DebugAssert(FProgressForm != NULL);
  5258. }
  5259. }
  5260. //---------------------------------------------------------------------------
  5261. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5262. {
  5263. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5264. TRemoteFile * File = NULL;
  5265. Terminal->ReadFile(FullFileName, File);
  5266. if (File != NULL)
  5267. {
  5268. std::unique_ptr<TRemoteFile> FileOwner(File);
  5269. TAutoFlag Flag(FStandaloneEditing);
  5270. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5271. Application->ShowMainForm = false;
  5272. Application->Run();
  5273. }
  5274. }
  5275. //---------------------------------------------------------------------------
  5276. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5277. {
  5278. DebugFail();
  5279. }
  5280. //---------------------------------------------------------------------------
  5281. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5282. {
  5283. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5284. SessionData->Assign(Terminal->SessionData);
  5285. UpdateSessionData(SessionData.get());
  5286. TTerminalManager::Instance()->UpdateSessionCredentials(SessionData.get());
  5287. if (!Terminal->SessionData->HasSessionName())
  5288. {
  5289. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5290. // once IsWorkspace is cleared
  5291. SessionData->Name = UnicodeString();
  5292. SessionData->IsWorkspace = false;
  5293. }
  5294. return SessionData.release();
  5295. }
  5296. //---------------------------------------------------------------------------
  5297. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5298. {
  5299. TSessionData * SessionData = CloneCurrentSessionData();
  5300. try
  5301. {
  5302. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5303. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5304. }
  5305. __finally
  5306. {
  5307. delete SessionData;
  5308. }
  5309. }
  5310. //---------------------------------------------------------------------------
  5311. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5312. {
  5313. TTerminalManager * Manager = TTerminalManager::Instance();
  5314. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5315. if (DebugAlwaysTrue(Terminal != NULL))
  5316. {
  5317. // Update (Managed)Terminal->StateData
  5318. UpdateTerminal(Terminal);
  5319. }
  5320. Manager->SaveWorkspace(DataList.get());
  5321. return DataList.release();
  5322. }
  5323. //---------------------------------------------------------------------------
  5324. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5325. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5326. {
  5327. WinConfiguration->LastWorkspace = Name;
  5328. if (!SavePasswords)
  5329. {
  5330. for (int Index = 0; Index < DataList->Count; Index++)
  5331. {
  5332. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5333. if (SessionData->Link.IsEmpty())
  5334. {
  5335. SessionData->ClearSessionPasswords();
  5336. }
  5337. }
  5338. }
  5339. StoredSessions->NewWorkspace(Name, DataList);
  5340. // modified only
  5341. StoredSessions->Save(false, Explicit);
  5342. }
  5343. //---------------------------------------------------------------------------
  5344. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5345. {
  5346. return
  5347. DefaultStr(WinConfiguration->LastWorkspace,
  5348. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5349. }
  5350. //---------------------------------------------------------------------------
  5351. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5352. {
  5353. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5354. bool AnyNonStoredSessionWithPassword = false;
  5355. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5356. bool AllNonStoredSessionsAnonymous = true;
  5357. TTerminalManager * Manager = TTerminalManager::Instance();
  5358. for (int Index = 0; Index < DataList->Count; Index++)
  5359. {
  5360. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5361. if (SessionData->Link.IsEmpty())
  5362. {
  5363. if (SessionData->HasAnySessionPassword())
  5364. {
  5365. AnyNonStoredSessionWithPassword = true;
  5366. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5367. {
  5368. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5369. }
  5370. }
  5371. if (!SameText(SessionData->UserName, AnonymousUserName))
  5372. {
  5373. AllNonStoredSessionsAnonymous = false;
  5374. }
  5375. }
  5376. }
  5377. bool SavePasswords;
  5378. bool * PSavePasswords;
  5379. bool NotRecommendedSavingPasswords =
  5380. !CustomWinConfiguration->UseMasterPassword &&
  5381. !AllNonStoredSessionsAnonymous;
  5382. if (Configuration->DisablePasswordStoring ||
  5383. !AnyNonStoredSessionWithPassword)
  5384. {
  5385. PSavePasswords = NULL;
  5386. SavePasswords = false;
  5387. }
  5388. else
  5389. {
  5390. PSavePasswords = &SavePasswords;
  5391. SavePasswords =
  5392. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5393. !NotRecommendedSavingPasswords;
  5394. }
  5395. UnicodeString Name = WorkspaceName();
  5396. bool CreateShortcut = false;
  5397. bool Result =
  5398. DoSaveWorkspaceDialog(
  5399. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5400. EnableAutoSave);
  5401. if (Result)
  5402. {
  5403. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5404. if (CreateShortcut)
  5405. {
  5406. TOperationVisualizer Visualizer;
  5407. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5408. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5409. }
  5410. if (EnableAutoSave)
  5411. {
  5412. WinConfiguration->AutoSaveWorkspace = true;
  5413. WinConfiguration->AutoWorkspace = Name;
  5414. if (PSavePasswords != NULL)
  5415. {
  5416. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5417. }
  5418. }
  5419. }
  5420. return Result;
  5421. }
  5422. //---------------------------------------------------------------------------
  5423. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5424. {
  5425. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5426. DebugAssert(ManagedTerminal != NULL);
  5427. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5428. if (WinConfiguration->PreservePanelState)
  5429. {
  5430. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5431. }
  5432. UpdateSessionData(ManagedTerminal->StateData);
  5433. }
  5434. //---------------------------------------------------------------------------
  5435. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5436. {
  5437. // Keep in sync with TSessionData::CopyStateData
  5438. DebugAssert(Data != NULL);
  5439. // This is inconsistent with how color (for example) is handled.
  5440. Data->Name = Terminal->SessionData->Name;
  5441. // cannot use RemoteDirView->Path, because it is empty if connection
  5442. // was already closed
  5443. // also only peek, we may not be connected at all atm
  5444. // so make sure we do not try retrieving current directory from the server
  5445. // (particularly with FTP)
  5446. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5447. if (!ACurrentDirectory.IsEmpty())
  5448. {
  5449. Data->RemoteDirectory = ACurrentDirectory;
  5450. }
  5451. Data->Color = SessionColor;
  5452. }
  5453. //---------------------------------------------------------------------------
  5454. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5455. {
  5456. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5457. DebugAssert(Toolbar != NULL);
  5458. for (int i = 0; i < Toolbar->Items->Count; i++)
  5459. {
  5460. TTBXCustomDropDownItem * DropDownItem;
  5461. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5462. if (DropDownItem != NULL)
  5463. {
  5464. ToolbarItemResize(DropDownItem,
  5465. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5466. Toolbar->NonClientWidth);
  5467. break;
  5468. }
  5469. }
  5470. }
  5471. //---------------------------------------------------------------------------
  5472. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5473. {
  5474. Item->EditWidth = Width;
  5475. }
  5476. //---------------------------------------------------------------------------
  5477. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5478. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5479. {
  5480. for (int i = 0; i < Toolbar->Items->Count; i++)
  5481. {
  5482. TTBXCustomDropDownItem * DropDownItem;
  5483. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5484. if (DropDownItem != NULL)
  5485. {
  5486. ASize.x -= DropDownItem->EditWidth;
  5487. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5488. }
  5489. }
  5490. }
  5491. //---------------------------------------------------------------------------
  5492. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5493. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5494. {
  5495. if (WinConfiguration->DDWarnLackOfTempSpace)
  5496. {
  5497. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5498. if (!ADrive.IsEmpty())
  5499. {
  5500. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5501. DebugAssert(RequiredSpace >= 0);
  5502. __int64 RequiredWithReserve;
  5503. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5504. if (FreeSpace < RequiredWithReserve)
  5505. {
  5506. unsigned int Result;
  5507. TMessageParams Params(mpNeverAskAgainCheck);
  5508. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5509. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5510. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5511. if (Result == qaNeverAskAgain)
  5512. {
  5513. WinConfiguration->DDWarnLackOfTempSpace = false;
  5514. }
  5515. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5516. }
  5517. }
  5518. }
  5519. }
  5520. //---------------------------------------------------------------------------
  5521. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5522. {
  5523. DoOpenDirectoryDialog(odAddBookmark, Side);
  5524. }
  5525. //---------------------------------------------------------------------------
  5526. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5527. {
  5528. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5529. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5530. try
  5531. {
  5532. TCustomDirView * DView = DirView(Side);
  5533. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5534. {
  5535. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5536. }
  5537. }
  5538. catch (...)
  5539. {
  5540. delete VisitedDirectories;
  5541. throw;
  5542. }
  5543. return VisitedDirectories;
  5544. }
  5545. //---------------------------------------------------------------------------
  5546. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5547. TOpenDirectoryMode Mode, TOperationSide Side)
  5548. {
  5549. bool Continue = true;
  5550. if (Mode == odAddBookmark)
  5551. {
  5552. TMessageParams Params(mpNeverAskAgainCheck);
  5553. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5554. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5555. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5556. unsigned int Answer =
  5557. MessageDialog(Message,
  5558. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5559. if (Answer == qaNeverAskAgain)
  5560. {
  5561. Continue = true;
  5562. WinConfiguration->UseSharedBookmarks = true;
  5563. }
  5564. else if (Answer == qaOK)
  5565. {
  5566. Continue = true;
  5567. WinConfiguration->UseSharedBookmarks = false;
  5568. }
  5569. else
  5570. {
  5571. Continue = false;
  5572. }
  5573. }
  5574. if (Continue)
  5575. {
  5576. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5577. try
  5578. {
  5579. UnicodeString Name = DirView(Side)->PathName;
  5580. bool Repeat;
  5581. do
  5582. {
  5583. Repeat = false;
  5584. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5585. // do not allow switching to location profiles,
  5586. // if we are not connected
  5587. HasDirView[osLocal] && (Terminal != NULL)))
  5588. {
  5589. TWindowLock Lock(this);
  5590. if (!TryOpenDirectory(Side, Name))
  5591. {
  5592. Repeat = true;
  5593. Mode = odBrowse;
  5594. }
  5595. }
  5596. }
  5597. while (Repeat);
  5598. }
  5599. __finally
  5600. {
  5601. delete VisitedDirectories;
  5602. }
  5603. }
  5604. }
  5605. //---------------------------------------------------------------------------
  5606. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5607. {
  5608. DebugAssert(!FTerminal->CommandSessionOpened);
  5609. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5610. }
  5611. //---------------------------------------------------------------------------
  5612. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5613. {
  5614. bool Result = FTerminal->IsCapable[Capability] ||
  5615. FTerminal->CommandSessionOpened;
  5616. if (!Result)
  5617. {
  5618. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5619. if (!GUIConfiguration->ConfirmCommandSession)
  5620. {
  5621. Result = true;
  5622. }
  5623. else
  5624. {
  5625. TMessageParams Params(mpNeverAskAgainCheck);
  5626. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5627. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5628. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5629. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5630. if (Answer == qaNeverAskAgain)
  5631. {
  5632. GUIConfiguration->ConfirmCommandSession = false;
  5633. Result = true;
  5634. }
  5635. else if (Answer == qaOK)
  5636. {
  5637. Result = true;
  5638. }
  5639. }
  5640. if (Result)
  5641. {
  5642. Result = CommandSessionFallback();
  5643. }
  5644. }
  5645. return Result;
  5646. }
  5647. //---------------------------------------------------------------------------
  5648. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5649. {
  5650. if (EnsureCommandSessionFallback(fcAnyCommand))
  5651. {
  5652. DoConsoleDialog(Terminal, Command);
  5653. }
  5654. }
  5655. //---------------------------------------------------------------------------
  5656. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5657. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5658. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5659. {
  5660. if (IsFileControl(DropSourceControl, osRemote) &&
  5661. (FDDExtMapFile != NULL))
  5662. {
  5663. Accept = true;
  5664. }
  5665. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5666. DebugAssert(FDDTargetControl != NULL);
  5667. }
  5668. //---------------------------------------------------------------------------
  5669. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5670. _di_IDataObject DataObj, int KeyState,
  5671. const TPoint & Point, int & Effect, bool & Accept)
  5672. {
  5673. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5674. }
  5675. //---------------------------------------------------------------------------
  5676. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5677. _di_IDataObject DataObj, int KeyState,
  5678. const TPoint & Point, int & Effect, bool & Accept)
  5679. {
  5680. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5681. }
  5682. //---------------------------------------------------------------------------
  5683. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5684. TObject * Sender)
  5685. {
  5686. DebugUsedParam(Sender);
  5687. DebugAssert(FDDTargetControl == Sender);
  5688. FDDTargetControl = NULL;
  5689. }
  5690. //---------------------------------------------------------------------------
  5691. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5692. {
  5693. FileControlDDDragLeave(SessionsPageControl);
  5694. }
  5695. //---------------------------------------------------------------------------
  5696. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5697. {
  5698. FileControlDDDragLeave(QueueView3);
  5699. }
  5700. //---------------------------------------------------------------------------
  5701. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5702. {
  5703. DebugAssert(GetSide(Side) == osRemote);
  5704. DebugUsedParam(Side);
  5705. bool Edit = false;
  5706. TRemoteFile * File = NULL;
  5707. UnicodeString FileName;
  5708. UnicodeString PointTo;
  5709. bool SymbolicLink = true;
  5710. if (RemoteDirView->ItemFocused)
  5711. {
  5712. DebugAssert(RemoteDirView->ItemFocused->Data);
  5713. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5714. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5715. if (Edit)
  5716. {
  5717. FileName = File->FileName;
  5718. PointTo = File->LinkTo;
  5719. }
  5720. else
  5721. {
  5722. PointTo = File->FileName;
  5723. }
  5724. }
  5725. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5726. Terminal->IsCapable[fcHardLink]))
  5727. {
  5728. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5729. if (Edit)
  5730. {
  5731. DebugAssert(File->FileName == FileName);
  5732. int Params = dfNoRecursive;
  5733. Terminal->ExceptionOnFail = true;
  5734. try
  5735. {
  5736. Terminal->DeleteFile(L"", File, &Params);
  5737. }
  5738. __finally
  5739. {
  5740. Terminal->ExceptionOnFail = false;
  5741. }
  5742. }
  5743. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5744. }
  5745. }
  5746. //---------------------------------------------------------------------------
  5747. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5748. {
  5749. return
  5750. (Terminal != NULL) &&
  5751. ((GetSide(Side) != osRemote) ||
  5752. (Terminal->ResolvingSymlinks &&
  5753. Terminal->IsCapable[fcSymbolicLink]));
  5754. }
  5755. //---------------------------------------------------------------------------
  5756. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5757. {
  5758. return
  5759. (FCurrentSide == osRemote) &&
  5760. (RemoteDirView->ItemFocused != NULL) &&
  5761. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5762. Terminal->SessionData->ResolveSymlinks;
  5763. }
  5764. //---------------------------------------------------------------------------
  5765. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5766. {
  5767. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5768. FForceExecution = true;
  5769. try
  5770. {
  5771. DirView(osCurrent)->ExecuteCurrentFile();
  5772. }
  5773. __finally
  5774. {
  5775. FForceExecution = false;
  5776. }
  5777. }
  5778. //---------------------------------------------------------------------------
  5779. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5780. {
  5781. TEditorData ExternalEditor;
  5782. ExternalEditor.Editor = edExternal;
  5783. bool Remember = false;
  5784. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5785. (GetSide(osCurrent) == osRemote)))
  5786. {
  5787. if (Remember)
  5788. {
  5789. TEditorList * EditorList = new TEditorList;
  5790. try
  5791. {
  5792. *EditorList = *WinConfiguration->EditorList;
  5793. bool Found = false;
  5794. int i = 0;
  5795. while (!Found && (i < EditorList->Count))
  5796. {
  5797. const TEditorPreferences * Editor = EditorList->Editors[i];
  5798. if ((Editor->Data->Editor == edExternal) &&
  5799. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5800. {
  5801. Found = true;
  5802. }
  5803. i++;
  5804. }
  5805. if (!Found)
  5806. {
  5807. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5808. WinConfiguration->EditorList = EditorList;
  5809. }
  5810. }
  5811. __finally
  5812. {
  5813. delete EditorList;
  5814. }
  5815. }
  5816. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5817. }
  5818. }
  5819. //---------------------------------------------------------------------------
  5820. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5821. {
  5822. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5823. if (FFileFindTerminal == Sender)
  5824. {
  5825. FFileFindTerminal = NULL;
  5826. HideFileFindDialog();
  5827. }
  5828. }
  5829. //---------------------------------------------------------------------------
  5830. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5831. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5832. {
  5833. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5834. DebugAssert(Terminal != NULL);
  5835. if (Data->Terminal == Terminal)
  5836. {
  5837. Data->Terminal = NULL;
  5838. }
  5839. }
  5840. //---------------------------------------------------------------------------
  5841. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5842. {
  5843. UpdateControls();
  5844. SessionColor = TColor(0);
  5845. UpdateRemotePathComboBox(false);
  5846. NeedSession(true);
  5847. }
  5848. //---------------------------------------------------------------------------
  5849. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5850. {
  5851. try
  5852. {
  5853. try
  5854. {
  5855. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5856. }
  5857. __finally
  5858. {
  5859. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5860. (!Terminal || !Terminal->Active))
  5861. {
  5862. TerminateApplication();
  5863. }
  5864. }
  5865. }
  5866. catch (EAbort &)
  5867. {
  5868. // swallow
  5869. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  5870. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  5871. }
  5872. }
  5873. //---------------------------------------------------------------------------
  5874. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  5875. {
  5876. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  5877. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5878. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  5879. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  5880. try
  5881. {
  5882. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  5883. // Clear the design time unthemed tab
  5884. ((SessionsPageControl->PageCount > 0) &&
  5885. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  5886. {
  5887. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5888. }
  5889. for (int Index = 0; Index <= TerminalList->Count; Index++)
  5890. {
  5891. TThemeTabSheet * TabSheet;
  5892. if (Index >= SessionsPageControl->PageCount)
  5893. {
  5894. TabSheet = new TThemeTabSheet(SessionsPageControl);
  5895. TabSheet->PageControl = SessionsPageControl;
  5896. }
  5897. else
  5898. {
  5899. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  5900. }
  5901. bool IsSessionTab = (Index < TerminalList->Count);
  5902. if (IsSessionTab)
  5903. {
  5904. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  5905. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  5906. UpdateSessionTab(TabSheet);
  5907. }
  5908. else
  5909. {
  5910. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  5911. TabSheet->Tag = 0; // not really needed
  5912. // We know that we are at the last page, sotherwise we could not call this (it assumes that new session tab is the last one)
  5913. UpdateNewSessionTab();
  5914. }
  5915. TabSheet->ShowCloseButton = IsSessionTab;
  5916. }
  5917. }
  5918. __finally
  5919. {
  5920. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  5921. }
  5922. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  5923. }
  5924. //---------------------------------------------------------------------------
  5925. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  5926. {
  5927. DoTerminalListChanged();
  5928. }
  5929. //---------------------------------------------------------------------------
  5930. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  5931. {
  5932. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5933. DebugAssert(TabSheet->ImageIndex == 0);
  5934. TabSheet->Caption =
  5935. WinConfiguration->SelectiveToolbarText ?
  5936. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  5937. UnicodeString();
  5938. }
  5939. //---------------------------------------------------------------------------
  5940. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  5941. {
  5942. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  5943. }
  5944. //---------------------------------------------------------------------------
  5945. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  5946. {
  5947. if (DebugAlwaysTrue(TabSheet != NULL))
  5948. {
  5949. TManagedTerminal * ManagedTerminal =
  5950. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  5951. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  5952. {
  5953. TColor Color = (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  5954. TabSheet->ImageIndex = AddSessionColor(Color);
  5955. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ManagedTerminal, true);
  5956. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  5957. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  5958. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  5959. {
  5960. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  5961. }
  5962. }
  5963. }
  5964. }
  5965. //---------------------------------------------------------------------------
  5966. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  5967. {
  5968. DebugAssert(SessionsPageControl->ActivePage != NULL);
  5969. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  5970. bool Result = (Terminal != NULL);
  5971. if (Result)
  5972. {
  5973. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5974. }
  5975. else
  5976. {
  5977. try
  5978. {
  5979. NewSession(false);
  5980. }
  5981. __finally
  5982. {
  5983. DoTerminalListChanged();
  5984. }
  5985. FSessionsPageControlNewSessionTime = Now();
  5986. }
  5987. return Result;
  5988. }
  5989. //---------------------------------------------------------------------------
  5990. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  5991. {
  5992. SessionTabSwitched();
  5993. }
  5994. //---------------------------------------------------------------------------
  5995. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  5996. {
  5997. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  5998. DebugAssert(TransferList != NULL);
  5999. UnicodeString Name;
  6000. if (TransferList->ItemIndex <= 0)
  6001. {
  6002. Name = L"";
  6003. }
  6004. else
  6005. {
  6006. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6007. }
  6008. if (FCopyParamAutoSelected.IsEmpty())
  6009. {
  6010. // if previous preset was not autoselected, make new preset the "default"
  6011. FCopyParamDefault = Name;
  6012. }
  6013. GUIConfiguration->CopyParamCurrent = Name;
  6014. }
  6015. //---------------------------------------------------------------------------
  6016. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6017. {
  6018. // sanity check
  6019. bool ExistingPreset =
  6020. (FTransferListHoverIndex >= 0) &&
  6021. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6022. DebugAssert(ExistingPreset);
  6023. if (ExistingPreset)
  6024. {
  6025. HDC DC = GetDC(0);
  6026. TCanvas * Canvas = new TCanvas();
  6027. try
  6028. {
  6029. Canvas->Handle = DC;
  6030. Canvas->Font = GetToolbarFont(this);
  6031. UnicodeString Name;
  6032. if (FTransferListHoverIndex == 0)
  6033. {
  6034. Name = L"";
  6035. }
  6036. else
  6037. {
  6038. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6039. }
  6040. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6041. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6042. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6043. static_cast<TObject*>(GetComponent(fcTransferList)));
  6044. UnicodeString InfoStr =
  6045. GUIConfiguration->CopyParamPreset[Name].
  6046. GetInfoStr(L"; ",
  6047. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  6048. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6049. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6050. {
  6051. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6052. {
  6053. InfoStr.SetLength(InfoStr.Length() - 1);
  6054. }
  6055. InfoStr += Ellipsis;
  6056. }
  6057. // UpdateCaption does not cause invalidation of whole submenu, while
  6058. // setting Caption property does.
  6059. // also it probably does not resize the label, even if necessary
  6060. // (we do not want that anyway)
  6061. TransferLabel->UpdateCaption(InfoStr);
  6062. }
  6063. __finally
  6064. {
  6065. Canvas->Handle = NULL;
  6066. ReleaseDC(0, DC);
  6067. delete Canvas;
  6068. }
  6069. }
  6070. }
  6071. //---------------------------------------------------------------------------
  6072. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6073. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6074. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6075. {
  6076. if (FTransferListHoverIndex != AHoverIndex)
  6077. {
  6078. FTransferListHoverIndex = AHoverIndex;
  6079. UpdateTransferLabel();
  6080. }
  6081. }
  6082. //---------------------------------------------------------------------------
  6083. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6084. {
  6085. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6086. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6087. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6088. {
  6089. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6090. {
  6091. OpenDirectory(GetSide(osCurrent));
  6092. Message.Result = 1;
  6093. }
  6094. else
  6095. {
  6096. TForm::Dispatch(&Message);
  6097. }
  6098. }
  6099. else
  6100. {
  6101. TForm::Dispatch(&Message);
  6102. }
  6103. }
  6104. //---------------------------------------------------------------------------
  6105. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6106. {
  6107. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6108. if ((FIgnoreNextDialogChar != 0) &&
  6109. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6110. {
  6111. Message.Result = 1;
  6112. }
  6113. else
  6114. {
  6115. TForm::Dispatch(&Message);
  6116. }
  6117. FIgnoreNextDialogChar = 0;
  6118. }
  6119. //---------------------------------------------------------------------------
  6120. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6121. {
  6122. // The four low-order bits are used internally by Windows
  6123. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6124. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6125. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6126. // 61730 - restore thru double click - undocumented
  6127. // 61490 - maximize thru double click - undocumented
  6128. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6129. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6130. {
  6131. SysResizing(Cmd);
  6132. }
  6133. TForm::Dispatch(&Message);
  6134. }
  6135. //---------------------------------------------------------------------------
  6136. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6137. {
  6138. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6139. // Also there no point returning TRUE as we are not able to
  6140. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6141. // Hence the process termination might be safer :)
  6142. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6143. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6144. {
  6145. Message.Result = FALSE;
  6146. }
  6147. else
  6148. {
  6149. Message.Result = TRUE;
  6150. }
  6151. // Do not call default handling as that triggers OnCloseQuery,
  6152. // where our implementation will popup confirmation dialogs, what we do not want,
  6153. // as per Vista guidelines:
  6154. // https://docs.microsoft.com/en-us/windows/desktop/shutdown/shutting-down
  6155. }
  6156. //---------------------------------------------------------------------------
  6157. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6158. {
  6159. if (Message.EndSession && IsApplicationMinimized())
  6160. {
  6161. // WORKAROUND
  6162. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6163. // when it receives WM_ENDSESSION,
  6164. // but that sometimes (particularly when application is minimized) cause crashes.
  6165. // Crash popups message that blocks log off.
  6166. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6167. // so we call ExitProcess() immediately, not even trying to cleanup.
  6168. // It still causes beep, so there's likely some popup, but it does not block
  6169. // log off.
  6170. ExitProcess(0);
  6171. }
  6172. TForm::Dispatch(&Message);
  6173. }
  6174. #ifdef _DEBUG
  6175. //---------------------------------------------------------------------------
  6176. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6177. {
  6178. TForm::Dispatch(&Message);
  6179. }
  6180. #endif
  6181. //---------------------------------------------------------------------------
  6182. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6183. {
  6184. }
  6185. //---------------------------------------------------------------------------
  6186. void __fastcall TCustomScpExplorerForm::DoShow()
  6187. {
  6188. // only now are the controls resized finally, so the size constraints
  6189. // will not conflict with possibly very small window size
  6190. RestoreFormParams();
  6191. FixControlsPlacement();
  6192. if (Position == poDefaultPosOnly)
  6193. {
  6194. CutFormToDesktop(this);
  6195. }
  6196. TForm::DoShow();
  6197. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6198. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6199. if (Terminal == NULL)
  6200. {
  6201. StartingDisconnected();
  6202. }
  6203. UpdatePixelsPerInchMainWindowCounter();
  6204. FShowing = true;
  6205. }
  6206. //---------------------------------------------------------------------------
  6207. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6208. {
  6209. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6210. }
  6211. //---------------------------------------------------------------------------
  6212. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6213. {
  6214. DoTerminalListChanged();
  6215. }
  6216. //---------------------------------------------------------------------------
  6217. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6218. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6219. TNotifyEvent OnBalloonClick, TObject * UserData)
  6220. {
  6221. bool Do;
  6222. UnicodeString Message;
  6223. if (E == NULL)
  6224. {
  6225. Message = Str;
  6226. Do = true;
  6227. }
  6228. else
  6229. {
  6230. Do = ExceptionMessage(E, Message);
  6231. }
  6232. if (Do && WinConfiguration->BalloonNotifications)
  6233. {
  6234. UnicodeString Title;
  6235. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6236. {
  6237. Message = TrimLeft(Message);
  6238. }
  6239. else
  6240. {
  6241. Message = UnformatMessage(Message);
  6242. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6243. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6244. Title = LoadResourceString(Captions[Type]);
  6245. if (Terminal != NULL)
  6246. {
  6247. Title = FORMAT(L"%s - %s",
  6248. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6249. }
  6250. }
  6251. if (Seconds == 0)
  6252. {
  6253. Seconds = WinConfiguration->NotificationsTimeout;
  6254. }
  6255. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6256. }
  6257. }
  6258. //---------------------------------------------------------------------------
  6259. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6260. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6261. UnicodeString HelpKeyword, const TMessageParams * Params,
  6262. TTerminal * Terminal)
  6263. {
  6264. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6265. (FOnFeedSynchronizeError != NULL)) &&
  6266. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6267. {
  6268. if (FOnFeedSynchronizeError != NULL)
  6269. {
  6270. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6271. }
  6272. else
  6273. {
  6274. DebugAssert(FErrorList != NULL);
  6275. TStringList * MoreMessagesCopy = NULL;
  6276. if (MoreMessages)
  6277. {
  6278. MoreMessagesCopy = new TStringList();
  6279. MoreMessagesCopy->Assign(MoreMessages);
  6280. }
  6281. FErrorList->AddObject(Message, MoreMessagesCopy);
  6282. }
  6283. PopupTrayBalloon(Terminal, Message, Type);
  6284. return ContinueAnswer(Answers);
  6285. }
  6286. else
  6287. {
  6288. bool UseBalloon = FTrayIcon->Visible;
  6289. if (UseBalloon)
  6290. {
  6291. PopupTrayBalloon(Terminal, Message, Type);
  6292. }
  6293. unsigned int Result;
  6294. try
  6295. {
  6296. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6297. }
  6298. __finally
  6299. {
  6300. // cancel only balloon we popped up, otherwise we may cancel notification
  6301. // balloon that was there before the message dialog
  6302. // (such as "dd confirmation opt in balloon)
  6303. if (UseBalloon)
  6304. {
  6305. FTrayIcon->CancelBalloon();
  6306. }
  6307. }
  6308. return Result;
  6309. }
  6310. }
  6311. //---------------------------------------------------------------------------
  6312. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6313. TTerminal * Terminal, Exception * E)
  6314. {
  6315. if (FTrayIcon->Visible)
  6316. {
  6317. PopupTrayBalloon(Terminal, L"", qtError, E);
  6318. }
  6319. // particularly prevent opening new session from jump list,
  6320. // while exception is shown
  6321. NonVisualDataModule->StartBusy();
  6322. try
  6323. {
  6324. ShowExtendedExceptionEx(Terminal, E);
  6325. }
  6326. __finally
  6327. {
  6328. NonVisualDataModule->EndBusy();
  6329. FTrayIcon->CancelBalloon();
  6330. }
  6331. }
  6332. //---------------------------------------------------------------------------
  6333. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6334. {
  6335. // cannot rely on active page being page for active terminal,
  6336. // as it can happen that active page is the "new session" page
  6337. // (e.g. when reconnecting active terminal, while login dialog
  6338. // invoked from "new session" page is modal)
  6339. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6340. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6341. }
  6342. //---------------------------------------------------------------------------
  6343. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6344. TTerminal * Terminal, Exception * E)
  6345. {
  6346. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6347. if (!Terminal->Active)
  6348. {
  6349. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6350. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6351. {
  6352. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6353. }
  6354. }
  6355. }
  6356. //---------------------------------------------------------------------------
  6357. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6358. UnicodeString Message, TQueryType Type,
  6359. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6360. {
  6361. if ((E == NULL) ||
  6362. ExceptionMessage(E, Message))
  6363. {
  6364. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6365. if (Important)
  6366. {
  6367. Seconds *= 5;
  6368. }
  6369. UnicodeString NoteMessage(UnformatMessage(Message));
  6370. if (Terminal != NULL)
  6371. {
  6372. NoteMessage = FORMAT(L"%s: %s",
  6373. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6374. }
  6375. if (WinConfiguration->BalloonNotifications)
  6376. {
  6377. AddNote(NoteMessage);
  6378. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6379. }
  6380. else
  6381. {
  6382. FlashOnBackground();
  6383. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6384. }
  6385. }
  6386. }
  6387. //---------------------------------------------------------------------------
  6388. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6389. {
  6390. RestoreApp();
  6391. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6392. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6393. !NonVisualDataModule->Busy)
  6394. {
  6395. TTerminal * Terminal = TerminalNoteData->Terminal;
  6396. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6397. if (!ComponentVisible[fcQueueView])
  6398. {
  6399. ToggleQueueVisibility();
  6400. GoToQueue();
  6401. }
  6402. }
  6403. }
  6404. //---------------------------------------------------------------------------
  6405. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  6406. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6407. {
  6408. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6409. UnicodeString Message;
  6410. TNotifyEvent OnClick = NULL;
  6411. TObject * UserData = NULL;
  6412. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6413. switch (Event)
  6414. {
  6415. case qeEmptyButMonitored:
  6416. if ((ATerminal != Terminal) || QueueInvisible)
  6417. {
  6418. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6419. OnClick = QueueEmptyNoteClicked;
  6420. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6421. TerminalNoteData->Terminal = ATerminal;
  6422. UserData = TerminalNoteData;
  6423. }
  6424. break;
  6425. case qeEmpty:
  6426. OperationComplete(ManagedTerminal->QueueOperationStart);
  6427. break;
  6428. case qePendingUserAction:
  6429. if ((ATerminal != Terminal) ||
  6430. (QueueInvisible && !IsQueueAutoPopup()))
  6431. {
  6432. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6433. }
  6434. break;
  6435. default:
  6436. DebugFail();
  6437. }
  6438. if (!Message.IsEmpty())
  6439. {
  6440. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6441. }
  6442. }
  6443. //---------------------------------------------------------------------------
  6444. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6445. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6446. {
  6447. if (FDDExtMapFile != NULL)
  6448. {
  6449. CloseHandle(FDDExtMapFile);
  6450. FDDExtMapFile = NULL;
  6451. }
  6452. if (WinConfiguration->DDFakeFile)
  6453. {
  6454. DDFakeFileInitDrag(FileList, Created);
  6455. }
  6456. }
  6457. //---------------------------------------------------------------------------
  6458. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6459. {
  6460. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6461. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6462. {
  6463. FFakeFileDropTarget = FileName;
  6464. }
  6465. }
  6466. //---------------------------------------------------------------------------
  6467. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6468. bool & Created)
  6469. {
  6470. FFakeFileDropTarget = UnicodeString();
  6471. FDragFakeDirectory =
  6472. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6473. if (!ForceDirectories(ApiPath(FDragFakeDirectory)))
  6474. {
  6475. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragFakeDirectory)));
  6476. }
  6477. FileSetAttr(ApiPath(FDragFakeDirectory), faHidden);
  6478. FileList->AddItem(NULL, FDragFakeDirectory);
  6479. Created = true;
  6480. if (!WinConfiguration->IsDDExtRunning() || (GetWindowsBuild() >= 17134))
  6481. {
  6482. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6483. }
  6484. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6485. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6486. {
  6487. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6488. TDragExtCommStruct* CommStruct;
  6489. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6490. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6491. DebugAssert(CommStruct != NULL);
  6492. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6493. CommStruct->Dragging = true;
  6494. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6495. LENOF(CommStruct->DropDest));
  6496. NULL_TERMINATE(CommStruct->DropDest);
  6497. UnmapViewOfFile(CommStruct);
  6498. }
  6499. FDDMoveSlipped = false;
  6500. }
  6501. //---------------------------------------------------------------------------
  6502. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6503. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6504. {
  6505. bool Result;
  6506. if (Sender == RemoteDirView)
  6507. {
  6508. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6509. }
  6510. else
  6511. {
  6512. DebugAssert(Sender == RemoteDriveView);
  6513. TStrings * FileList = RemoteDriveView->DragFileList();
  6514. try
  6515. {
  6516. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6517. }
  6518. __finally
  6519. {
  6520. delete FileList;
  6521. }
  6522. }
  6523. if (FDDTargetControl == RemoteDriveView)
  6524. {
  6525. RemoteDriveView->UpdateDropTarget();
  6526. }
  6527. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6528. // or from tree view to dir view.
  6529. // foMove happens when file/dir is dragged from remote tree view outside of
  6530. // application via dragex
  6531. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6532. (DropSourceControl == RemoteDriveView))
  6533. {
  6534. RemoteDriveView->UpdateDropSource();
  6535. }
  6536. return Result;
  6537. }
  6538. //---------------------------------------------------------------------------
  6539. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6540. {
  6541. // This also handles drops of remote files to queue.
  6542. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6543. SAFE_DESTROY(FDDFileList);
  6544. if (!FFakeFileDropTarget.IsEmpty())
  6545. {
  6546. RemoveDir(ApiPath(FFakeFileDropTarget));
  6547. }
  6548. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6549. {
  6550. try
  6551. {
  6552. TDragResult DDResult = (Sender == RemoteDirView) ?
  6553. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6554. // Focus is moved to the target application,
  6555. // but as we are going to present the UI, we need to steal the focus back.
  6556. // This most likely won't work though (windows does not allow application
  6557. // to steal focus most of the time)
  6558. Application->BringToFront();
  6559. // On older version of Windows we never got drMove here, see also comment below.
  6560. // On Windows 10, we get the "move".
  6561. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6562. {
  6563. UnicodeString TargetDirectory;
  6564. TFileOperation Operation;
  6565. // drInvalid may mean drMove, see comment below
  6566. switch (DDResult)
  6567. {
  6568. case drCopy:
  6569. Operation = foCopy;
  6570. break;
  6571. case drMove:
  6572. Operation = foMove;
  6573. break;
  6574. default:
  6575. DebugFail();
  6576. case drInvalid:
  6577. // prefer "copy" for safety
  6578. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6579. break;
  6580. }
  6581. if (FDDMoveSlipped)
  6582. {
  6583. Operation = foMove;
  6584. }
  6585. TTransferOperationParam Param;
  6586. UnicodeString CounterName;
  6587. bool ForceQueue;
  6588. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6589. {
  6590. // we get drInvalid both if d&d was intercepted by ddext,
  6591. // and when users drops on no-drop location.
  6592. // we tell the difference by existence of response from ddext,
  6593. // so we ignore absence of response in this case
  6594. if (DDResult != drInvalid)
  6595. {
  6596. // here we know that the extension is installed,
  6597. // as it is checked as soon as drag&drop starts from
  6598. // RemoteFileControlDDCreateDragFileList
  6599. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6600. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6601. }
  6602. }
  6603. else
  6604. {
  6605. // download using fake file
  6606. Param.Temp = false;
  6607. Param.DragDrop = true;
  6608. if (ForceQueue)
  6609. {
  6610. Param.Queue = asOn;
  6611. }
  6612. if (Sender == RemoteDirView)
  6613. {
  6614. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6615. }
  6616. if (RemoteFileControlFileOperation(Sender, Operation,
  6617. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6618. {
  6619. Configuration->Usage->Inc(CounterName);
  6620. }
  6621. }
  6622. }
  6623. }
  6624. __finally
  6625. {
  6626. CloseHandle(FDDExtMapFile);
  6627. FDDExtMapFile = NULL;
  6628. delete FDragFakeMonitors;
  6629. FDragFakeMonitors = NULL;
  6630. RemoveDir(ApiPath(FDragFakeDirectory));
  6631. FDragFakeDirectory = L"";
  6632. FFakeFileDropTarget = UnicodeString();
  6633. }
  6634. }
  6635. if (FDragDropSshTerminate.get() != NULL)
  6636. {
  6637. FDragDropSshTerminate->Rethrow();
  6638. }
  6639. }
  6640. //---------------------------------------------------------------------------
  6641. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6642. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  6643. {
  6644. HCURSOR SlippedCopyCursor;
  6645. FDDMoveSlipped =
  6646. (FDragMoveCursor != NULL) &&
  6647. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  6648. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  6649. FTerminal->IsCapable[fcRemoteMove]) ||
  6650. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  6651. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  6652. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  6653. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  6654. // Remember drop effect so we know (when user drops files), if we copy or move
  6655. FLastDropEffect = dwEffect;
  6656. }
  6657. //---------------------------------------------------------------------------
  6658. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6659. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  6660. {
  6661. bool Result;
  6662. if (FDDTargetControl == QueueView3)
  6663. {
  6664. Directory = DefaultDownloadTargetDirectory();
  6665. Result = true;
  6666. CounterName = L"DownloadsDragDropQueue";
  6667. ForceQueue = true;
  6668. }
  6669. else if (!FFakeFileDropTarget.IsEmpty())
  6670. {
  6671. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  6672. Result = true;
  6673. ForceQueue = false;
  6674. CounterName = L"DownloadsDragDropFakeFile";
  6675. }
  6676. else
  6677. {
  6678. ForceQueue = false;
  6679. Enabled = false;
  6680. try
  6681. {
  6682. int Timer = 0;
  6683. Result = false;
  6684. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6685. {
  6686. {
  6687. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6688. TDragExtCommStruct* CommStruct;
  6689. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6690. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6691. DebugAssert(CommStruct != NULL);
  6692. Result = !CommStruct->Dragging;
  6693. if (Result)
  6694. {
  6695. Directory = ExtractFilePath(CommStruct->DropDest);
  6696. CounterName = L"DownloadsDragDropExternalExt";
  6697. }
  6698. UnmapViewOfFile(CommStruct);
  6699. }
  6700. if (!Result)
  6701. {
  6702. Sleep(50);
  6703. Timer += 50;
  6704. Application->ProcessMessages();
  6705. }
  6706. }
  6707. }
  6708. __finally
  6709. {
  6710. Enabled = true;
  6711. }
  6712. }
  6713. return Result;
  6714. }
  6715. //---------------------------------------------------------------------------
  6716. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6717. const UnicodeString TempDir, int SecDelay)
  6718. {
  6719. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6720. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6721. if (FDelayedDeletionTimer == NULL)
  6722. {
  6723. DebugAssert(HandleAllocated());
  6724. FDelayedDeletionTimer = new TTimer(this);
  6725. FDelayedDeletionTimer->Interval = 10000;
  6726. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6727. }
  6728. else
  6729. {
  6730. FDelayedDeletionTimer->Enabled = true;
  6731. }
  6732. }
  6733. //---------------------------------------------------------------------------
  6734. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6735. {
  6736. DebugAssert(FDelayedDeletionList != NULL);
  6737. TDateTime N = Now();
  6738. TDateTime Alert;
  6739. UnicodeString Directory;
  6740. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6741. {
  6742. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6743. if ((N >= Alert) || (Sender == NULL))
  6744. {
  6745. Directory = FDelayedDeletionList->Strings[Index];
  6746. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6747. {
  6748. FDelayedDeletionList->Delete(Index);
  6749. }
  6750. }
  6751. }
  6752. if (FDelayedDeletionList->Count == 0)
  6753. {
  6754. FDelayedDeletionTimer->Enabled = false;
  6755. }
  6756. }
  6757. //---------------------------------------------------------------------------
  6758. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6759. {
  6760. if (IsFileControl(FDDTargetControl, osRemote) ||
  6761. (FDDTargetControl == SessionsPageControl))
  6762. {
  6763. TTerminal * TargetTerminal = NULL;
  6764. TFileOperation Operation = foNone;
  6765. if (FDDTargetControl == SessionsPageControl)
  6766. {
  6767. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6768. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6769. // do not allow dropping on the "+" tab
  6770. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6771. if (TargetTerminal != NULL)
  6772. {
  6773. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6774. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6775. {
  6776. Operation = foRemoteMove;
  6777. }
  6778. else
  6779. {
  6780. Operation = foRemoteCopy;
  6781. }
  6782. }
  6783. }
  6784. else
  6785. {
  6786. // when move from remote side is disabled, we allow copying inside the remote
  6787. // panel, but we interpret is as moving (we also slip in the move cursor)
  6788. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  6789. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  6790. FDDMoveSlipped))
  6791. {
  6792. Operation = foRemoteMove;
  6793. }
  6794. else if (FLastDropEffect == DROPEFFECT_COPY)
  6795. {
  6796. Operation = foRemoteCopy;
  6797. }
  6798. }
  6799. if (Operation != foNone)
  6800. {
  6801. RemoteFileControlFileOperation(DropSourceControl,
  6802. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6803. }
  6804. // abort drag&drop
  6805. Abort();
  6806. }
  6807. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6808. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6809. (FDDTargetControl != QueueView3))
  6810. {
  6811. DebugAssert(!FDragTempDir.IsEmpty());
  6812. TTransferType Type;
  6813. UnicodeString TempDir = FDragTempDir;
  6814. // We clear FDragTempDir before calling
  6815. // just in case it fail (raises exception)
  6816. FDragTempDir = L"";
  6817. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6818. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6819. // empty directory parameter means temp directory -> don't display it!
  6820. UnicodeString TargetDir = L"";
  6821. int Options = 0;
  6822. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6823. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6824. {
  6825. Abort();
  6826. }
  6827. // TargetDir is set when dropped on local file control
  6828. // (this was workaround for legacy dirview event handling, now it should be
  6829. // made prettier)
  6830. if (TargetDir.IsEmpty())
  6831. {
  6832. TargetDir = TempDir;
  6833. if (ForceDirectories(ApiPath(TargetDir)))
  6834. {
  6835. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6836. FPendingTempSpaceWarn = true;
  6837. try
  6838. {
  6839. FDragDropOperation = true;
  6840. int Params = cpTemporary |
  6841. (Type == ttMove ? cpDelete : 0);
  6842. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6843. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6844. }
  6845. __finally
  6846. {
  6847. FDragDropOperation = false;
  6848. FPendingTempSpaceWarn = false;
  6849. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6850. }
  6851. }
  6852. else
  6853. {
  6854. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6855. }
  6856. }
  6857. }
  6858. }
  6859. //---------------------------------------------------------------------------
  6860. void __fastcall TCustomScpExplorerForm::DDDownload(
  6861. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  6862. {
  6863. void * BatchStorage;
  6864. BatchStart(BatchStorage);
  6865. try
  6866. {
  6867. UpdateCopyParamCounters(*CopyParam);
  6868. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6869. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6870. {
  6871. RemoteDriveView->UpdateDropSource();
  6872. }
  6873. }
  6874. __finally
  6875. {
  6876. BatchEnd(BatchStorage);
  6877. }
  6878. }
  6879. //---------------------------------------------------------------------------
  6880. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6881. {
  6882. public:
  6883. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6884. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  6885. {
  6886. }
  6887. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  6888. {
  6889. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  6890. TDataObjectFilesEx::AllowData(FormatEtc);
  6891. }
  6892. };
  6893. //---------------------------------------------------------------------------
  6894. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  6895. TObject * Sender, TDataObject *& DataObject)
  6896. {
  6897. if (FDDExtMapFile != NULL)
  6898. {
  6899. TFileList * FileList = DragDropFiles(Sender)->FileList;
  6900. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  6901. {
  6902. Abort();
  6903. }
  6904. if (FileList->Count > 0)
  6905. {
  6906. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  6907. if (!FilesObject->IsValid(true, true))
  6908. {
  6909. FilesObject->_Release();
  6910. }
  6911. else
  6912. {
  6913. DataObject = FilesObject;
  6914. }
  6915. }
  6916. }
  6917. }
  6918. //---------------------------------------------------------------------------
  6919. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  6920. {
  6921. DebugFail();
  6922. }
  6923. //---------------------------------------------------------------------------
  6924. void __fastcall TCustomScpExplorerForm::GoToTree()
  6925. {
  6926. ComponentVisible[fcRemoteTree] = true;
  6927. RemoteDriveView->SetFocus();
  6928. }
  6929. //---------------------------------------------------------------------------
  6930. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6931. TPanelExport Export)
  6932. {
  6933. TCustomDirView * DirView = this->DirView(Side);
  6934. std::unique_ptr<TStrings> ExportData(new TStringList());
  6935. switch (Export)
  6936. {
  6937. case pePath:
  6938. ExportData->Add(DirView->PathName);
  6939. break;
  6940. case peFileList:
  6941. case peFullFileList:
  6942. {
  6943. bool FullPath = (Export == peFullFileList);
  6944. DirView->CreateFileList(false, FullPath, ExportData.get());
  6945. for (int Index = 0; Index < ExportData->Count; Index++)
  6946. {
  6947. if (ExportData->Strings[Index].Pos(L" ") > 0)
  6948. {
  6949. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  6950. }
  6951. }
  6952. }
  6953. break;
  6954. default:
  6955. DebugFail();
  6956. }
  6957. return ExportData.release();
  6958. }
  6959. //---------------------------------------------------------------------------
  6960. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6961. TPanelExport Export, TPanelExportDestination Destination)
  6962. {
  6963. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  6964. PanelExportStore(Side, Export, Destination, ExportData.get());
  6965. }
  6966. //---------------------------------------------------------------------------
  6967. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  6968. TPanelExport /*Export*/, TPanelExportDestination Destination,
  6969. TStrings * ExportData)
  6970. {
  6971. if (Destination == pedClipboard)
  6972. {
  6973. TInstantOperationVisualizer Visualizer;
  6974. CopyToClipboard(ExportData);
  6975. }
  6976. else
  6977. {
  6978. DebugFail();
  6979. }
  6980. }
  6981. //---------------------------------------------------------------------------
  6982. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  6983. {
  6984. TCustomDirView * DirView = this->DirView(Side);
  6985. TFileFilter Filter;
  6986. DefaultFileFilter(Filter);
  6987. Filter.Masks = DirView->Mask;
  6988. if (DoFilterMaskDialog(DirView, &Filter))
  6989. {
  6990. DirView->Mask = TFileMasks::NormalizeMask(Filter.Masks);
  6991. Configuration->Usage->Inc(L"Filters");
  6992. }
  6993. }
  6994. //---------------------------------------------------------------------------
  6995. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  6996. {
  6997. return FQueueController->DefaultOperation();
  6998. }
  6999. //---------------------------------------------------------------------------
  7000. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7001. TQueueOperation Operation, void ** Param)
  7002. {
  7003. switch (Operation)
  7004. {
  7005. case qoPreferences:
  7006. return true;
  7007. case qoGoTo:
  7008. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7009. case qoOnceEmpty:
  7010. return !FQueueController->Empty;
  7011. default:
  7012. return FQueueController->AllowOperation(Operation, Param);
  7013. }
  7014. }
  7015. //---------------------------------------------------------------------------
  7016. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7017. {
  7018. if (DebugAlwaysTrue(QueueView3->Visible))
  7019. {
  7020. QueueView3->SetFocus();
  7021. }
  7022. }
  7023. //---------------------------------------------------------------------------
  7024. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7025. TQueueOperation Operation, void * Param)
  7026. {
  7027. if (Operation == qoGoTo)
  7028. {
  7029. GoToQueue();
  7030. }
  7031. else if (Operation == qoPreferences)
  7032. {
  7033. PreferencesDialog(pmQueue);
  7034. }
  7035. else
  7036. {
  7037. FQueueController->ExecuteOperation(Operation, Param);
  7038. }
  7039. }
  7040. //---------------------------------------------------------------------------
  7041. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7042. {
  7043. return (Queue != NULL) && Queue->Enabled;
  7044. }
  7045. //---------------------------------------------------------------------------
  7046. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7047. {
  7048. DebugAssert(Queue != NULL);
  7049. if (Queue != NULL)
  7050. {
  7051. Queue->Enabled = !Queue->Enabled;
  7052. }
  7053. }
  7054. //---------------------------------------------------------------------------
  7055. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7056. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7057. {
  7058. FQueueActedItem = QueueView3->ItemFocused;
  7059. }
  7060. //---------------------------------------------------------------------------
  7061. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7062. {
  7063. return TopDock->Height + QueueSplitter->Height;
  7064. }
  7065. //---------------------------------------------------------------------------
  7066. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7067. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7068. {
  7069. // when queue is hidden by double-clicking splitter, stray attempt to
  7070. // resize the panel with strange value arrives, make sure it is ignored
  7071. if (ComponentVisible[fcQueueView])
  7072. {
  7073. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  7074. RemotePanel->Constraints->MinHeight;
  7075. if (NewSize > HeightLimit)
  7076. {
  7077. NewSize = HeightLimit;
  7078. }
  7079. }
  7080. else
  7081. {
  7082. Accept = false;
  7083. }
  7084. }
  7085. //---------------------------------------------------------------------------
  7086. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7087. TDragObject *& /*DragObject*/)
  7088. {
  7089. FQueueActedItem = QueueView3->ItemFocused;
  7090. }
  7091. //---------------------------------------------------------------------------
  7092. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7093. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7094. {
  7095. Accept = true;
  7096. if (Source == QueueView3)
  7097. {
  7098. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7099. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7100. if (Accept)
  7101. {
  7102. TQueueItemProxy * QueueItem;
  7103. TQueueItemProxy * DestQueueItem;
  7104. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7105. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7106. Accept = (QueueItem != DestQueueItem) &&
  7107. (QueueItem->Status == TQueueItem::qsPending) &&
  7108. (DestQueueItem->Status == TQueueItem::qsPending);
  7109. }
  7110. }
  7111. }
  7112. //---------------------------------------------------------------------------
  7113. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7114. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7115. {
  7116. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7117. {
  7118. TQueueItemProxy * QueueItem;
  7119. TQueueItemProxy * DestQueueItem;
  7120. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7121. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7122. QueueItem->Move(DestQueueItem);
  7123. }
  7124. }
  7125. //---------------------------------------------------------------------------
  7126. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7127. {
  7128. if ((QueueView3->ItemFocused == NULL) &&
  7129. (QueueView3->Items->Count > 0))
  7130. {
  7131. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7132. }
  7133. QueueLabelUpdateStatus();
  7134. }
  7135. //---------------------------------------------------------------------------
  7136. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7137. {
  7138. QueueLabelUpdateStatus();
  7139. }
  7140. //---------------------------------------------------------------------------
  7141. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7142. {
  7143. QueueLabel->UpdateStatus();
  7144. }
  7145. //---------------------------------------------------------------------------
  7146. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7147. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7148. {
  7149. if (Selected)
  7150. {
  7151. NonVisualDataModule->UpdateNonVisibleActions();
  7152. }
  7153. }
  7154. //---------------------------------------------------------------------------
  7155. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7156. {
  7157. TDragDropFilesEx * Result = NULL;
  7158. if (Sender == SessionsPageControl)
  7159. {
  7160. Result = FSessionsDragDropFilesEx;
  7161. }
  7162. else if (Sender == QueueView3)
  7163. {
  7164. Result = FQueueDragDropFilesEx;
  7165. }
  7166. else
  7167. {
  7168. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7169. if (DirView != NULL)
  7170. {
  7171. Result = DirView->DragDropFilesEx;
  7172. }
  7173. else
  7174. {
  7175. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7176. if (DriveView != NULL)
  7177. {
  7178. Result = DriveView->DragDropFilesEx;
  7179. }
  7180. }
  7181. }
  7182. DebugAssert(Result != NULL);
  7183. return Result;
  7184. }
  7185. //---------------------------------------------------------------------------
  7186. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7187. {
  7188. return (DView->SelCount == DView->FilesCount);
  7189. }
  7190. //---------------------------------------------------------------------------
  7191. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7192. {
  7193. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7194. }
  7195. //---------------------------------------------------------------------------
  7196. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7197. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue)
  7198. {
  7199. TFileOperation Operation;
  7200. switch (Effect)
  7201. {
  7202. case DROPEFFECT_MOVE:
  7203. Operation = foMove;
  7204. break;
  7205. case DROPEFFECT_COPY:
  7206. // occures on WinXP (reported by user)
  7207. default:
  7208. Operation = foCopy;
  7209. break;
  7210. };
  7211. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7212. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7213. if (DragDropFilesEx->FileList->Count > 0)
  7214. {
  7215. TStrings * FileList = new TStringList();
  7216. try
  7217. {
  7218. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7219. {
  7220. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7221. }
  7222. FDragDropOperation = true;
  7223. TTransferOperationParam Param;
  7224. Param.TargetDirectory = TargetPath;
  7225. // upload, no temp dirs
  7226. Param.Temp = false;
  7227. Param.DragDrop = true;
  7228. Param.Options =
  7229. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7230. if (ForceQueue)
  7231. {
  7232. Param.Queue = asOn;
  7233. }
  7234. if (ExecuteFileOperation(Operation, osLocal, FileList,
  7235. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7236. {
  7237. if (IsFileControl(DropSourceControl, osLocal))
  7238. {
  7239. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7240. }
  7241. else
  7242. {
  7243. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7244. }
  7245. }
  7246. }
  7247. __finally
  7248. {
  7249. FDragDropOperation = false;
  7250. delete FileList;
  7251. }
  7252. }
  7253. }
  7254. //---------------------------------------------------------------------------
  7255. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7256. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7257. UnicodeString TargetPath, bool & /*DoOperation*/)
  7258. {
  7259. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false);
  7260. }
  7261. //---------------------------------------------------------------------------
  7262. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7263. TObject * Sender, int grfKeyState, int & dwEffect)
  7264. {
  7265. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7266. if ((dwEffect != DROPEFFECT_None) &&
  7267. IsFileControl(DropSourceControl, osRemote))
  7268. {
  7269. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7270. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7271. (RemoteDirView->DropTarget == NULL))
  7272. {
  7273. dwEffect = DROPEFFECT_None;
  7274. }
  7275. else
  7276. {
  7277. if (dwEffect == DROPEFFECT_Copy)
  7278. {
  7279. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7280. // currently we support copying always (at least via temporary directory);
  7281. // remove associated checks once this all proves stable and working
  7282. bool CopyCapable = true;
  7283. // if we do not support neither of operations, there's no discussion
  7284. if (!MoveCapable && !CopyCapable)
  7285. {
  7286. dwEffect = DROPEFFECT_None;
  7287. }
  7288. // when moving is disabled, we need to keep effect to "copy",
  7289. // which will be later interpretted as move (with slipped-in cursor)
  7290. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  7291. {
  7292. // no-op, keep copy
  7293. }
  7294. else
  7295. {
  7296. // The default effect inside remote panel is move,
  7297. // unless we do not support it, but support copy
  7298. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7299. {
  7300. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  7301. }
  7302. else
  7303. {
  7304. // with ctrl-down, we want copy unless it is not supported
  7305. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  7306. }
  7307. }
  7308. }
  7309. }
  7310. }
  7311. }
  7312. //---------------------------------------------------------------------------
  7313. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7314. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7315. {
  7316. if (FDDTotalSize >= 0)
  7317. {
  7318. if (File->IsDirectory)
  7319. {
  7320. FDDTotalSize = -1;
  7321. }
  7322. else
  7323. {
  7324. FDDTotalSize += File->Size;
  7325. }
  7326. }
  7327. DebugAssert(!FDragTempDir.IsEmpty());
  7328. // TODO: this is quite ineffective
  7329. // TODO: what if invalid character replacement is disabled?
  7330. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7331. UnicodeString TransferFileName;
  7332. if (Sender == RemoteDriveView)
  7333. {
  7334. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7335. }
  7336. else
  7337. {
  7338. TransferFileName = File->FileName;
  7339. }
  7340. FDDFileList->AddObject(TransferFileName, File);
  7341. }
  7342. //---------------------------------------------------------------------------
  7343. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7344. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7345. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7346. {
  7347. // sometimes we do not get DDEnd so the list is not released
  7348. SAFE_DESTROY(FDDFileList);
  7349. FDDFileList = new TStringList();
  7350. FDragTempDir = WinConfiguration->TemporaryDir();
  7351. FDDTotalSize = 0;
  7352. FDragDropSshTerminate.reset(NULL);
  7353. }
  7354. //---------------------------------------------------------------------------
  7355. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7356. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7357. HRESULT & Result)
  7358. {
  7359. if (Result == DRAGDROP_S_DROP)
  7360. {
  7361. try
  7362. {
  7363. GlobalDragImageList->HideDragImage();
  7364. try
  7365. {
  7366. RemoteFileControlDDTargetDrop();
  7367. }
  7368. catch(ESshTerminate & E)
  7369. {
  7370. FDragDropSshTerminate.reset(E.Clone());
  7371. }
  7372. }
  7373. catch (Exception &E)
  7374. {
  7375. // If downloading fails we need to cancel drag&drop, otherwise
  7376. // Explorer shows error
  7377. // But by the way exception probably never reach this point as
  7378. // it's catched on way.
  7379. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7380. Result = DRAGDROP_S_CANCEL;
  7381. ShowExtendedException(Terminal, &E);
  7382. }
  7383. }
  7384. }
  7385. //---------------------------------------------------------------------------
  7386. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7387. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7388. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7389. {
  7390. TFileMasks::TParams MaskParams;
  7391. MaskParams.Size = Size;
  7392. MaskParams.Modification = Modification;
  7393. // this does not re-parse the mask if it is the same as the last time
  7394. FDirViewMatchMask = Masks;
  7395. bool ImplicitMatch;
  7396. Matches =
  7397. // RecurseInclude parameter has no effect as the Path is empty
  7398. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7399. (AllowImplicitMatches || !ImplicitMatch);
  7400. }
  7401. //---------------------------------------------------------------------------
  7402. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7403. TObject * Sender, TListItem * Item, WORD & Indexes)
  7404. {
  7405. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7406. UnicodeString Ext;
  7407. if (DirView == RemoteDirView)
  7408. {
  7409. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7410. }
  7411. else
  7412. {
  7413. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7414. }
  7415. if (SameText(Ext, Configuration->PartialExt))
  7416. {
  7417. Indexes |= oiPartial;
  7418. }
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7422. {
  7423. return
  7424. DirViewEnabled(osCurrent) &&
  7425. DirView(osCurrent)->CanPasteFromClipBoard();
  7426. }
  7427. //---------------------------------------------------------------------------
  7428. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7429. {
  7430. bool Result = false;
  7431. if (CanPasteToDirViewFromClipBoard())
  7432. {
  7433. Result = true;
  7434. }
  7435. else
  7436. {
  7437. UnicodeString ClipboardText;
  7438. if (NonEmptyTextFromClipboard(ClipboardText))
  7439. {
  7440. if (StoredSessions->IsUrl(ClipboardText))
  7441. {
  7442. Result = true;
  7443. }
  7444. else
  7445. {
  7446. Result = DirViewEnabled(osCurrent);
  7447. }
  7448. }
  7449. }
  7450. return Result;
  7451. }
  7452. //---------------------------------------------------------------------------
  7453. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7454. {
  7455. if (CanPasteToDirViewFromClipBoard())
  7456. {
  7457. DirView(osCurrent)->PasteFromClipBoard();
  7458. }
  7459. else
  7460. {
  7461. UnicodeString ClipboardText;
  7462. if (NonEmptyTextFromClipboard(ClipboardText))
  7463. {
  7464. if (StoredSessions->IsUrl(ClipboardText))
  7465. {
  7466. NewSession(false, ClipboardText);
  7467. }
  7468. else
  7469. {
  7470. DirView(osCurrent)->Path = ClipboardText;
  7471. }
  7472. }
  7473. }
  7474. }
  7475. //---------------------------------------------------------------------------
  7476. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7477. {
  7478. // TBD
  7479. }
  7480. //---------------------------------------------------------------------------
  7481. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7482. {
  7483. TCustomDirView * ADirView = DirView(Side);
  7484. ADirView->SelectAll(Mode);
  7485. ADirView->SetFocus();
  7486. }
  7487. //---------------------------------------------------------------------------
  7488. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7489. {
  7490. TCustomDirView * ADirView = DirView(Side);
  7491. TFileFilter Filter;
  7492. DefaultFileFilter(Filter);
  7493. if (DoSelectMaskDialog(ADirView, Select, &Filter, Configuration))
  7494. {
  7495. Configuration->Usage->Inc(L"MaskSelections");
  7496. ADirView->SelectFiles(Filter, Select);
  7497. ADirView->SetFocus();
  7498. }
  7499. }
  7500. //---------------------------------------------------------------------------
  7501. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7502. {
  7503. TCustomDirView * ADirView = DirView(Side);
  7504. ADirView->RestoreSelectedNames();
  7505. ADirView->SetFocus();
  7506. }
  7507. //---------------------------------------------------------------------------
  7508. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7509. {
  7510. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7511. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7512. {
  7513. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7514. UnicodeString Ext;
  7515. if (GetSide(osCurrent) == osRemote)
  7516. {
  7517. Ext = UnixExtractFileExt(FileName);
  7518. }
  7519. else
  7520. {
  7521. Ext = ExtractFileExt(FileName);
  7522. }
  7523. if (Ext.IsEmpty())
  7524. {
  7525. Ext = L".";
  7526. }
  7527. TFileFilter Filter;
  7528. Filter.Masks = FORMAT(L"*%s", (Ext));
  7529. Filter.Directories = false;
  7530. CurrentDirView->SelectFiles(Filter, Select);
  7531. }
  7532. }
  7533. //---------------------------------------------------------------------------
  7534. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7535. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7536. {
  7537. UnicodeString Result;
  7538. if ((Side == osRemote) && (Terminal == NULL))
  7539. {
  7540. // noop
  7541. }
  7542. else
  7543. {
  7544. Result =
  7545. FMTLOAD(FILE_INFO_FORMAT,
  7546. (FormatBytes(FileInfo.SelectedSize),
  7547. FormatBytes(FileInfo.FilesSize),
  7548. FormatNumber(FileInfo.SelectedCount),
  7549. FormatNumber(FileInfo.FilesCount)));
  7550. }
  7551. return Result;
  7552. }
  7553. //---------------------------------------------------------------------------
  7554. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7555. TTBXStatusPanel * Panel, TOperationSide Side)
  7556. {
  7557. if (Panel->Index == 1)
  7558. {
  7559. ToggleShowHiddenFiles();
  7560. }
  7561. else if (Panel->Index == 2)
  7562. {
  7563. Filter(Side);
  7564. }
  7565. }
  7566. //---------------------------------------------------------------------------
  7567. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7568. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7569. {
  7570. DebugAssert(!StatusBar->SimplePanel);
  7571. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7572. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7573. }
  7574. //---------------------------------------------------------------------------
  7575. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7576. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7577. {
  7578. DebugAssert(StatusBar->Panels->Count >= 3);
  7579. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7580. if (FileInfo.HiddenCount > 0)
  7581. {
  7582. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7583. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7584. }
  7585. else
  7586. {
  7587. HiddenFilesPanel->ViewPriority = 0;
  7588. // not really necessary, just to cleanup no-longer-valid data
  7589. HiddenFilesPanel->Caption = L"";
  7590. }
  7591. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7592. if (FileInfo.FilteredCount > 0)
  7593. {
  7594. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7595. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7596. }
  7597. else
  7598. {
  7599. FilteredFilesPanel->ViewPriority = 0;
  7600. // not really necessary, just to cleanup no-longer-valid data
  7601. FilteredFilesPanel->Caption = L"";
  7602. }
  7603. }
  7604. //---------------------------------------------------------------------------
  7605. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7606. TObject * /*Sender*/)
  7607. {
  7608. if (RemoteDirView->Enabled)
  7609. {
  7610. RemoteDirView->SetFocus();
  7611. }
  7612. }
  7613. //---------------------------------------------------------------------------
  7614. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7615. {
  7616. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7617. switch (Config.Show)
  7618. {
  7619. case qvShow:
  7620. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7621. {
  7622. Config.Show = qvHide;
  7623. }
  7624. else
  7625. {
  7626. Config.Show = Config.LastHideShow;
  7627. }
  7628. break;
  7629. case qvHideWhenEmpty:
  7630. if (ComponentVisible[fcQueueView])
  7631. {
  7632. Config.Show = qvHide;
  7633. }
  7634. else
  7635. {
  7636. Config.LastHideShow = Config.Show;
  7637. Config.Show = qvShow;
  7638. }
  7639. break;
  7640. case qvHide:
  7641. Config.LastHideShow = Config.Show;
  7642. Config.Show = qvShow;
  7643. break;
  7644. }
  7645. WinConfiguration->QueueView = Config;
  7646. }
  7647. //---------------------------------------------------------------------------
  7648. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7649. {
  7650. UnicodeString Result;
  7651. if (FTerminal != NULL)
  7652. {
  7653. switch (WinConfiguration->PathInCaption)
  7654. {
  7655. case picShort:
  7656. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  7657. break;
  7658. case picFull:
  7659. Result = FTerminal->CurrentDirectory;
  7660. break;
  7661. }
  7662. }
  7663. return Result;
  7664. }
  7665. //---------------------------------------------------------------------------
  7666. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7667. {
  7668. TTerminalManager::Instance()->UpdateAppTitle();
  7669. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7670. // background to gray on Windows 7 (works on Windows 10).
  7671. // See also EnableControl
  7672. if (Showing)
  7673. {
  7674. bool HasTerminal = (Terminal != NULL);
  7675. if (HasTerminal)
  7676. {
  7677. // Update path when it changes
  7678. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  7679. {
  7680. UpdateSessionTab(SessionsPageControl->ActivePage);
  7681. }
  7682. if (!RemoteDirView->Enabled)
  7683. {
  7684. RemoteDirView->Enabled = true;
  7685. if (FRemoteDirViewWasFocused)
  7686. {
  7687. ActiveControl = RemoteDirView;
  7688. }
  7689. }
  7690. RemoteDriveView->Enabled = true;
  7691. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  7692. RemoteDriveView->Color = RemoteDirView->Color;
  7693. }
  7694. else
  7695. {
  7696. if (RemoteDirView->Enabled)
  7697. {
  7698. // This is first called when the form is being constructed
  7699. // (not anymore due to Showing test above)
  7700. // but the false is overriden in the constructor later.
  7701. // An even later in TScpCommanderForm::DoShow()
  7702. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7703. EnableControl(RemoteDirView, false);
  7704. }
  7705. EnableControl(RemoteDriveView, false);
  7706. }
  7707. EnableControl(QueueView3, HasTerminal && Terminal->IsCapable[fsBackgroundTransfers]);
  7708. QueueLabelUpdateStatus();
  7709. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7710. }
  7711. }
  7712. //---------------------------------------------------------------------------
  7713. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7714. {
  7715. UpdateControls();
  7716. }
  7717. //---------------------------------------------------------------------------
  7718. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7719. TObject * Sender)
  7720. {
  7721. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7722. DebugAssert(DirView != NULL);
  7723. DoDirViewLoaded(DirView);
  7724. TransferPresetAutoSelect();
  7725. }
  7726. //---------------------------------------------------------------------------
  7727. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7728. {
  7729. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7730. // first run after installation
  7731. if (double(Updates.LastCheck) == 0)
  7732. {
  7733. // make sure next time there will be an update (if enabled)
  7734. Updates.LastCheck = TDateTime(1);
  7735. WinConfiguration->Updates = Updates;
  7736. }
  7737. else if ((double(Updates.Period) > 0) &&
  7738. (Now() - Updates.LastCheck >= Updates.Period))
  7739. {
  7740. TThreadMethod OnUpdatesChecked = NULL;
  7741. if (!IsUWP())
  7742. {
  7743. OnUpdatesChecked = UpdatesChecked;
  7744. }
  7745. StartUpdateThread(OnUpdatesChecked);
  7746. }
  7747. }
  7748. //---------------------------------------------------------------------------
  7749. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7750. {
  7751. UnicodeString Message;
  7752. bool New;
  7753. TQueryType Type;
  7754. GetUpdatesMessage(Message, New, Type, false);
  7755. if (!Message.IsEmpty())
  7756. {
  7757. if (New)
  7758. {
  7759. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7760. }
  7761. if (!New && (Type != qtWarning))
  7762. {
  7763. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7764. }
  7765. else
  7766. {
  7767. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7768. }
  7769. if (New)
  7770. {
  7771. Configuration->Usage->Inc(L"UpdateNotifications");
  7772. }
  7773. }
  7774. }
  7775. //---------------------------------------------------------------------------
  7776. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7777. {
  7778. RestoreApp();
  7779. bool CanDisplay = !NonVisualDataModule->Busy;
  7780. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7781. {
  7782. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7783. }
  7784. if (CanDisplay)
  7785. {
  7786. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7787. CheckForUpdates(true);
  7788. }
  7789. else
  7790. {
  7791. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7792. }
  7793. }
  7794. //---------------------------------------------------------------------------
  7795. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7796. TCopyParamRuleData & Data)
  7797. {
  7798. DebugAssert(Terminal != NULL);
  7799. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7800. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7801. Data.RemoteDirectory = RemoteDirView->PathName;
  7802. }
  7803. //---------------------------------------------------------------------------
  7804. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7805. {
  7806. // Terminal can be null when we are changing local directory implicitly,
  7807. // because it has been deleted, while no session is connected
  7808. // (Login dialog is open)
  7809. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7810. {
  7811. TCopyParamRuleData Data;
  7812. GetTransferPresetAutoSelectData(Data);
  7813. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7814. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7815. if (CopyParamIndex < 0)
  7816. {
  7817. // there is no preset that matches autoselection
  7818. // set preset that we consider "default"
  7819. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7820. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7821. }
  7822. else
  7823. {
  7824. // there is preset matching autoselection
  7825. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7826. if (CopyParamName == FCopyParamAutoSelected)
  7827. {
  7828. // autoselected the same preset as the last time
  7829. // make no change (i.e. preserve custom user preset, if any)
  7830. }
  7831. else
  7832. {
  7833. // autoselected the different preset then the last time (or there
  7834. // was default preset set)
  7835. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7836. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7837. }
  7838. }
  7839. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7840. {
  7841. if (CopyParamIndex >= 0)
  7842. {
  7843. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7844. }
  7845. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7846. try
  7847. {
  7848. int Fmt =
  7849. (CopyParamIndex < 0) ?
  7850. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7851. COPY_PARAM_AUTOSELECTED;
  7852. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7853. Data->Message = MainInstructions(Message);
  7854. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7855. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7856. CopyParamAttrs);
  7857. if (CopyParamIndex >= 0)
  7858. {
  7859. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7860. Info = FORMAT(L"%s\n \n%s", (Info,
  7861. FMTLOAD(COPY_PARAM_RULE,
  7862. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  7863. }
  7864. Data->Message += L"\n\n" + Info;
  7865. if (WinConfiguration->CopyParamAutoSelectNotice)
  7866. {
  7867. TransferPresetNoteMessage(Data, true);
  7868. }
  7869. else
  7870. {
  7871. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  7872. Data = NULL; // ownership passed
  7873. }
  7874. }
  7875. __finally
  7876. {
  7877. delete Data;
  7878. }
  7879. }
  7880. }
  7881. }
  7882. //---------------------------------------------------------------------------
  7883. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  7884. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  7885. {
  7886. DebugAssert(NoteData != NULL);
  7887. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  7888. TQueryButtonAlias Aliases[1];
  7889. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  7890. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  7891. Params.Aliases = Aliases;
  7892. Params.AliasesCount = LENOF(Aliases);
  7893. unsigned int Result =
  7894. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  7895. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  7896. switch (Result)
  7897. {
  7898. case qaNeverAskAgain:
  7899. DebugAssert(AllowNeverAskAgain);
  7900. WinConfiguration->CopyParamAutoSelectNotice = false;
  7901. break;
  7902. case qaIgnore:
  7903. PreferencesDialog(pmPresets);
  7904. break;
  7905. }
  7906. }
  7907. //---------------------------------------------------------------------------
  7908. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  7909. {
  7910. // as of now useless, as this is used for notes only, never for balloons, ...
  7911. RestoreApp();
  7912. // .. and we should never be busy here
  7913. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  7914. {
  7915. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  7916. }
  7917. }
  7918. //---------------------------------------------------------------------------
  7919. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  7920. TPreferencesMode APreferencesMode)
  7921. {
  7922. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  7923. TCopyParamRuleData Data;
  7924. if (Terminal != NULL)
  7925. {
  7926. PreferencesData.reset(new TPreferencesDialogData());
  7927. GetTransferPresetAutoSelectData(Data);
  7928. PreferencesData->CopyParamRuleData = &Data;
  7929. }
  7930. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  7931. }
  7932. //---------------------------------------------------------------------------
  7933. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  7934. const TCustomCommandType & Command)
  7935. {
  7936. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  7937. {
  7938. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  7939. }
  7940. }
  7941. //---------------------------------------------------------------------------
  7942. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  7943. {
  7944. bool RemoteAllowed = CustomCommandRemoteAllowed();
  7945. TCustomCommandType Command;
  7946. // make sure we use local custom command when remote are not supported
  7947. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  7948. {
  7949. Command = FLastCustomCommand;
  7950. }
  7951. else
  7952. {
  7953. Command.Params = Command.Params | ccLocal;
  7954. }
  7955. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  7956. FEditingFocusedAdHocCommand = OnFocused;
  7957. bool LocalSide = (FCurrentSide == osLocal);
  7958. int Options =
  7959. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  7960. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  7961. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  7962. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  7963. {
  7964. FLastCustomCommand = Command;
  7965. UpdateCustomCommandsToolbar();
  7966. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  7967. }
  7968. }
  7969. //---------------------------------------------------------------------------
  7970. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  7971. {
  7972. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  7973. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7974. DebugAssert(State > 0);
  7975. if (State <= 0)
  7976. {
  7977. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  7978. }
  7979. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  7980. }
  7981. //---------------------------------------------------------------------------
  7982. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  7983. TCustomCommandType & Command, int & State)
  7984. {
  7985. bool Result = !FLastCustomCommand.Command.IsEmpty();
  7986. if (Result)
  7987. {
  7988. Command = FLastCustomCommand;
  7989. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7990. }
  7991. return Result;
  7992. }
  7993. //---------------------------------------------------------------------------
  7994. void __fastcall TCustomScpExplorerForm::BeforeAction()
  7995. {
  7996. if (RemoteDirView->ItemFocused != NULL)
  7997. {
  7998. RemoteDirView->ItemFocused->CancelEdit();
  7999. }
  8000. }
  8001. //---------------------------------------------------------------------------
  8002. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8003. {
  8004. DebugAssert(ComponentVisible[Component]);
  8005. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8006. }
  8007. //---------------------------------------------------------------------------
  8008. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8009. {
  8010. // when queue panel is resized here directly, the status bar is stretched
  8011. // over whole space the panel occupied
  8012. PostComponentHide(fcQueueView);
  8013. }
  8014. //---------------------------------------------------------------------------
  8015. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8016. {
  8017. TMessage * M = static_cast<TMessage*>(Message);
  8018. switch (M->Msg)
  8019. {
  8020. case CM_DIALOGCHAR:
  8021. CMDialogChar(*M);
  8022. break;
  8023. case WM_APPCOMMAND:
  8024. WMAppCommand(*M);
  8025. break;
  8026. case WM_SYSCOMMAND:
  8027. WMSysCommand(*M);
  8028. break;
  8029. case WM_QUERYENDSESSION:
  8030. WMQueryEndSession(*M);
  8031. break;
  8032. case WM_ENDSESSION:
  8033. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8034. break;
  8035. #ifdef _DEBUG
  8036. case WM_WINDOWPOSCHANGED:
  8037. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8038. break;
  8039. case CM_CUSTOMSTYLECHANGED:
  8040. TForm::Dispatch(Message);
  8041. break;
  8042. #endif
  8043. case WM_COMPONENT_HIDE:
  8044. {
  8045. Byte Component = static_cast<Byte>(M->WParam);
  8046. // sanity check
  8047. if (ComponentVisible[Component])
  8048. {
  8049. // special treatment
  8050. if (Component == fcQueueView)
  8051. {
  8052. ToggleQueueVisibility();
  8053. DebugAssert(!ComponentVisible[fcQueueView]);
  8054. }
  8055. else
  8056. {
  8057. ComponentVisible[Component] = false;
  8058. }
  8059. }
  8060. }
  8061. break;
  8062. case WM_COPYDATA:
  8063. WMCopyData(*M);
  8064. break;
  8065. case WM_MANAGES_CAPTION:
  8066. // caption managed in TTerminalManager::UpdateAppTitle()
  8067. M->Result = 1;
  8068. break;
  8069. case WM_WANTS_MOUSEWHEEL:
  8070. M->Result = 1;
  8071. break;
  8072. case CM_SHOWINGCHANGED:
  8073. CMShowingChanged(*M);
  8074. break;
  8075. case WM_CLOSE:
  8076. WMClose(*M);
  8077. break;
  8078. case WM_DPICHANGED:
  8079. WMDpiChanged(*M);
  8080. break;
  8081. case CM_DPICHANGED:
  8082. CMDpiChanged(*M);
  8083. break;
  8084. default:
  8085. TForm::Dispatch(Message);
  8086. break;
  8087. }
  8088. }
  8089. //---------------------------------------------------------------------------
  8090. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8091. {
  8092. // noop
  8093. }
  8094. //---------------------------------------------------------------------------
  8095. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8096. {
  8097. TForm::Dispatch(&Message);
  8098. FSessionColors->Clear();
  8099. AddFixedSessionImages();
  8100. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8101. UpdateImages();
  8102. }
  8103. //---------------------------------------------------------------------------
  8104. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8105. {
  8106. TForm::Dispatch(&Message);
  8107. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8108. UpdatePixelsPerInchMainWindowCounter();
  8109. }
  8110. //---------------------------------------------------------------------------
  8111. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8112. {
  8113. // Cannot close window while we are busy.
  8114. // We cannot test this in FormCloseQuery as that is called also from
  8115. // Close(), which is called by CloseApplicationAction. So we can be busy
  8116. // there already even, when it is legitimate to close the application.
  8117. // Possibly a better place to handle this would be WMSysCommand.
  8118. if (NonVisualDataModule->Busy)
  8119. {
  8120. Message.Result = 1;
  8121. }
  8122. else
  8123. {
  8124. TForm::Dispatch(&Message);
  8125. }
  8126. }
  8127. //---------------------------------------------------------------------------
  8128. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8129. {
  8130. TForm::Dispatch(&Message);
  8131. if (Showing && (Terminal == NULL))
  8132. {
  8133. // When we are starting minimized (i.e. from an installer),
  8134. // postpone showing Login dialog until we get restored.
  8135. // Otherwise the Login dialog (and Authentication window) show restored
  8136. // over invidible (minimized) main window.
  8137. if (WindowState == wsMinimized)
  8138. {
  8139. FNeedSession = true;
  8140. }
  8141. else
  8142. {
  8143. // This happens before application ever goes idle, so the toolbars would
  8144. // stay enabled (initial state) until the Login dialog is dismissed.
  8145. UpdateActions();
  8146. NonVisualDataModule->StartBusy();
  8147. try
  8148. {
  8149. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8150. // otherwise the dialog does not receive focus.
  8151. // With Commander interface the ProcessMessages is called already
  8152. // by TDriveView, but with Explorer interface, we need to call it explicily
  8153. Application->ProcessMessages();
  8154. // do not reload sessions, they have been loaded just now (optimization)
  8155. NeedSession(false);
  8156. }
  8157. __finally
  8158. {
  8159. NonVisualDataModule->EndBusy();
  8160. }
  8161. }
  8162. }
  8163. }
  8164. //---------------------------------------------------------------------------
  8165. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8166. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8167. int & MaxHeight)
  8168. {
  8169. // workaround for bug in TWinControl.CalcConstraints
  8170. // Check for empty rect (restore from iconic state) is done there only after
  8171. // call to AdjustClientRect, which enlarges the rect (for forms).
  8172. TRect R = GetClientRect();
  8173. // when restoring from iconic state, place no restrictions
  8174. if (IsRectEmpty(R))
  8175. {
  8176. MinWidth = 0;
  8177. MinHeight = 0;
  8178. MaxWidth = 32000;
  8179. MaxHeight = 32000;
  8180. }
  8181. }
  8182. //---------------------------------------------------------------------------
  8183. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8184. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8185. {
  8186. // terminal can be already closed (e.g. dropped connection)
  8187. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8188. {
  8189. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8190. try
  8191. {
  8192. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8193. }
  8194. catch(...)
  8195. {
  8196. if (!Terminal->Active)
  8197. {
  8198. Close = true;
  8199. }
  8200. throw;
  8201. }
  8202. }
  8203. }
  8204. //---------------------------------------------------------------------------
  8205. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8206. {
  8207. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8208. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8209. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8210. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8211. {
  8212. OnGetSpaceAvailable = GetSpaceAvailable;
  8213. }
  8214. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8215. OnGetSpaceAvailable);
  8216. }
  8217. //---------------------------------------------------------------------------
  8218. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8219. {
  8220. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8221. Terminal->FillSessionDataForCode(Data.get());
  8222. return Data.release();
  8223. }
  8224. //---------------------------------------------------------------------------
  8225. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8226. {
  8227. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8228. DoGenerateUrlDialog(Data.get(), Paths);
  8229. }
  8230. //---------------------------------------------------------------------------
  8231. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8232. {
  8233. GenerateUrl(NULL);
  8234. }
  8235. //---------------------------------------------------------------------------
  8236. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8237. {
  8238. std::unique_ptr<TStrings> Paths(new TStringList());
  8239. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8240. GenerateUrl(Paths.get());
  8241. }
  8242. //---------------------------------------------------------------------------
  8243. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8244. {
  8245. if (value != FSessionColor)
  8246. {
  8247. FSessionColor = value;
  8248. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8249. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8250. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8251. DebugAssert(ColorItem != NULL);
  8252. ColorItem->Color = C;
  8253. NonVisualDataModule->ColorMenuItem->Color = C;
  8254. // Is null when called from LastTerminalClosed
  8255. if (Terminal != NULL)
  8256. {
  8257. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8258. }
  8259. UpdateControls();
  8260. }
  8261. }
  8262. //---------------------------------------------------------------------------
  8263. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8264. {
  8265. bool Result = FNoteTimer->Enabled;
  8266. if (Result)
  8267. {
  8268. // cannot cancel note too early
  8269. bool NotEarly =
  8270. (Now() - FNoteShown >
  8271. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8272. if (Force || NotEarly)
  8273. {
  8274. FNoteTimer->Enabled = false;
  8275. FNote = L"";
  8276. SAFE_DESTROY(FNoteData);
  8277. FOnNoteClick = NULL;
  8278. FNoteHints = FNotes->Text;
  8279. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8280. UpdateStatusBar();
  8281. }
  8282. }
  8283. return Result;
  8284. }
  8285. //---------------------------------------------------------------------------
  8286. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8287. {
  8288. DebugAssert(FNoteTimer->Enabled);
  8289. CancelNote(true);
  8290. }
  8291. //---------------------------------------------------------------------------
  8292. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8293. {
  8294. int P = Note.Pos(L"\n");
  8295. if (P > 0)
  8296. {
  8297. Note.SetLength(P - 1);
  8298. }
  8299. FNotes->Add(FORMAT(L"[%s] %s",
  8300. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8301. while (FNotes->Count > 10)
  8302. {
  8303. FNotes->Delete(0);
  8304. }
  8305. if (UpdateNow)
  8306. {
  8307. FNoteHints = FNotes->Text;
  8308. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8309. UpdateStatusBar();
  8310. }
  8311. }
  8312. //---------------------------------------------------------------------------
  8313. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8314. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8315. {
  8316. int P = Note.Pos(L"\n");
  8317. if (P > 0)
  8318. {
  8319. Note.SetLength(P - 1);
  8320. }
  8321. FNoteHints = FNotes->Text;
  8322. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8323. FNote = Note;
  8324. SAFE_DESTROY(FNoteData);
  8325. FNoteData = NoteData;
  8326. FOnNoteClick = OnNoteClick;
  8327. AddNote(Note, false);
  8328. UpdateStatusBar();
  8329. FNoteShown = Now();
  8330. FNoteTimer->Enabled = false;
  8331. if (Seconds == 0)
  8332. {
  8333. Seconds = WinConfiguration->NotificationsTimeout;
  8334. }
  8335. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8336. FNoteTimer->Enabled = true;
  8337. }
  8338. //---------------------------------------------------------------------------
  8339. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8340. {
  8341. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8342. }
  8343. //---------------------------------------------------------------------------
  8344. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8345. {
  8346. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8347. {
  8348. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8349. }
  8350. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8351. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8352. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8353. 0, NULL, NULL);
  8354. }
  8355. //---------------------------------------------------------------------------
  8356. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8357. {
  8358. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8359. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8360. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8361. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8365. {
  8366. WinConfiguration->FormatSizeBytes = Style;
  8367. }
  8368. //---------------------------------------------------------------------------
  8369. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8370. {
  8371. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8372. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8373. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8374. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8375. }
  8376. //---------------------------------------------------------------------------
  8377. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8378. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8379. {
  8380. if (Panel->Index == 0)
  8381. {
  8382. if (FOnNoteClick != NULL)
  8383. {
  8384. // prevent the user data from being freed by possible call
  8385. // to CancelNote or PostNote during call to OnNoteClick
  8386. std::unique_ptr<TObject> NoteData(FNoteData);
  8387. TNotifyEvent OnNoteClick = FOnNoteClick;
  8388. FNoteData = NULL;
  8389. // need to cancel the note as we are going to delete its user data
  8390. CancelNote(true);
  8391. OnNoteClick(NoteData.get());
  8392. }
  8393. }
  8394. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8395. {
  8396. FileSystemInfo();
  8397. }
  8398. }
  8399. //---------------------------------------------------------------------------
  8400. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8401. {
  8402. // workaround:
  8403. // 1) for unknown reason, disabling window, while minimized,
  8404. // prevents it from restoring, even if it was enabled again meanwhile
  8405. // 2) when disabling the main window, while another has focus
  8406. // minimize is no longer possible
  8407. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8408. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8409. // Shouldn't we use IsApplicationMinimized() here?
  8410. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8411. {
  8412. Enabled = false;
  8413. }
  8414. FLockLevel++;
  8415. }
  8416. //---------------------------------------------------------------------------
  8417. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8418. {
  8419. DebugAssert(FLockLevel > 0);
  8420. FLockLevel--;
  8421. if (FLockLevel == 0)
  8422. {
  8423. DebugAssert(FLockSuspendLevel == 0);
  8424. Enabled = true;
  8425. }
  8426. }
  8427. //---------------------------------------------------------------------------
  8428. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8429. {
  8430. // We need to make sure that window is enabled when the last modal window closes
  8431. // otherwise focus is not restored correctly.
  8432. // So we re-enable the window when modal window opens and
  8433. // disable it back after is closes
  8434. if (FLockLevel > 0)
  8435. {
  8436. // while we have nesting counter, we know that we never be called
  8437. // recursivelly as Application->OnModalBegin is called only
  8438. // for the top-level modal window
  8439. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8440. {
  8441. // won't be disabled when conditions in LockWindow() were not satisfied
  8442. FDisabledOnLockSuspend = !Enabled;
  8443. // When minimized to tray (or actually when set to SW_HIDE),
  8444. // setting Enabled makes the window focusable even when there's
  8445. // modal window over it
  8446. if (!FTrayIcon->Visible)
  8447. {
  8448. Enabled = true;
  8449. }
  8450. }
  8451. FLockSuspendLevel++;
  8452. }
  8453. }
  8454. //---------------------------------------------------------------------------
  8455. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8456. {
  8457. if (FLockSuspendLevel > 0)
  8458. {
  8459. DebugAssert(FLockLevel > 0);
  8460. FLockSuspendLevel--;
  8461. // see comment in SuspendWindowLock
  8462. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8463. {
  8464. // Note that window can be enabled here, when we were minized to tray when
  8465. // was SuspendWindowLock() called.
  8466. // We should possibly do the same check as in LockWindow(),
  8467. // if it is ever possible that the consitions change between
  8468. // SuspendWindowLock() and ResumeWindowLock()
  8469. Enabled = !FDisabledOnLockSuspend;
  8470. }
  8471. }
  8472. }
  8473. //---------------------------------------------------------------------------
  8474. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8475. {
  8476. if (!TextOnly)
  8477. {
  8478. TTBXComboBoxItem * RemotePathComboBox =
  8479. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8480. TStrings * Items = RemotePathComboBox->Strings;
  8481. Items->BeginUpdate();
  8482. try
  8483. {
  8484. Items->Clear();
  8485. if (Terminal != NULL)
  8486. {
  8487. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8488. while (!IsUnixRootPath(APath))
  8489. {
  8490. int P = APath.LastDelimiter(L'/');
  8491. DebugAssert(P >= 0);
  8492. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8493. APath.SetLength(P - 1);
  8494. }
  8495. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8496. }
  8497. }
  8498. __finally
  8499. {
  8500. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8501. // Setting ItemIndex to -1 does not reset its text
  8502. if (Items->Count == 0)
  8503. {
  8504. RemotePathComboBox->Text = L"";
  8505. }
  8506. Items->EndUpdate();
  8507. }
  8508. }
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8512. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8513. int & ImageIndex)
  8514. {
  8515. if (AIndex < 0)
  8516. {
  8517. AIndex = Sender->ItemIndex;
  8518. }
  8519. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8523. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8524. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8525. {
  8526. ARect.Left += (10 * AIndex);
  8527. }
  8528. //---------------------------------------------------------------------------
  8529. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8530. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8531. {
  8532. AWidth += (10 * AIndex);
  8533. }
  8534. //---------------------------------------------------------------------------
  8535. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8536. TObject * Sender)
  8537. {
  8538. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8539. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8540. int Index = RemotePathComboBox->ItemIndex;
  8541. while (Index < RemotePathComboBox->Strings->Count - 1)
  8542. {
  8543. APath = UnixExtractFileDir(APath);
  8544. Index++;
  8545. }
  8546. // VanDyke style paths
  8547. if (APath.IsEmpty())
  8548. {
  8549. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8550. APath = ROOTDIRECTORY;
  8551. }
  8552. if (RemoteDirView->Path != APath)
  8553. {
  8554. RemoteDirView->Path = APath;
  8555. }
  8556. }
  8557. //---------------------------------------------------------------------------
  8558. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8559. {
  8560. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8561. DebugUsedParam(Sender);
  8562. UpdateRemotePathComboBox(true);
  8563. }
  8564. //---------------------------------------------------------------------------
  8565. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8566. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8567. {
  8568. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8569. DebugAssert(DirView != NULL);
  8570. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8571. {
  8572. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8573. // OnEditing is called also from TCustomListView::CanEdit
  8574. if (Edit != NULL)
  8575. {
  8576. EditSelectBaseName(Edit);
  8577. }
  8578. }
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. //---------------------------------------------------------------------------
  8582. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8583. {
  8584. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8585. Result->AutoDetectDnD = false;
  8586. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8587. Result->RenderDataOn = rdoEnterAndDropSync;
  8588. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8589. return Result;
  8590. }
  8591. //---------------------------------------------------------------------------
  8592. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8593. {
  8594. TForm::CreateWnd();
  8595. if (FSessionsDragDropFilesEx == NULL)
  8596. {
  8597. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8598. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8599. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8600. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8601. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8602. }
  8603. if (FQueueDragDropFilesEx == NULL)
  8604. {
  8605. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8606. // No need to set OnDragOver as we do not have any restrictions
  8607. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8608. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8609. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8610. }
  8611. }
  8612. //---------------------------------------------------------------------------
  8613. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8614. {
  8615. TForm::DestroyWnd();
  8616. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8617. FQueueDragDropFilesEx->DragDropControl = NULL;
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8621. {
  8622. SideEnter(FCurrentSide);
  8623. FEverShown = true;
  8624. }
  8625. //---------------------------------------------------------------------------
  8626. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8627. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8628. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8629. {
  8630. if (!NonVisualDataModule->Busy)
  8631. {
  8632. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8633. Configuration->Usage->Inc(L"FileFinds");
  8634. LockWindow(true);
  8635. NonVisualDataModule->StartBusy();
  8636. WinConfiguration->LockedInterface = true;
  8637. try
  8638. {
  8639. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8640. }
  8641. __finally
  8642. {
  8643. WinConfiguration->LockedInterface = false;
  8644. NonVisualDataModule->EndBusy();
  8645. UnlockWindow();
  8646. }
  8647. }
  8648. }
  8649. //---------------------------------------------------------------------------
  8650. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8651. {
  8652. if (!NonVisualDataModule->Busy)
  8653. {
  8654. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8655. SetFocus();
  8656. RemoteDirView->Path = UnixExtractFilePath(Path);
  8657. TListItem * Item = RemoteDirView->FindFileItem(UnixExtractFileName(Path));
  8658. if (Item != NULL)
  8659. {
  8660. RemoteDirView->ItemFocused = Item;
  8661. RemoteDirView->ItemFocused->MakeVisible(false);
  8662. RemoteDirView->SetFocus();
  8663. }
  8664. }
  8665. }
  8666. //---------------------------------------------------------------------------
  8667. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  8668. {
  8669. bool Result = !NonVisualDataModule->Busy;
  8670. if (Result)
  8671. {
  8672. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8673. }
  8674. return Result;
  8675. }
  8676. //---------------------------------------------------------------------------
  8677. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8678. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8679. {
  8680. if (CanOperateOnFoundFiles(ATerminal))
  8681. {
  8682. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  8683. FOnFileOperationFinished = OnFileOperationFinished;
  8684. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8685. }
  8686. }
  8687. //---------------------------------------------------------------------------
  8688. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8689. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8690. {
  8691. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8692. }
  8693. //---------------------------------------------------------------------------
  8694. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8695. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8696. {
  8697. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8698. }
  8699. //---------------------------------------------------------------------------
  8700. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  8701. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8702. {
  8703. if (CanOperateOnFoundFiles(ATerminal))
  8704. {
  8705. for (int Index = 0; Index < FileList->Count; Index++)
  8706. {
  8707. UnicodeString FileName = FileList->Strings[Index];
  8708. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  8709. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  8710. OnFileOperationFinished(FileName, true);
  8711. }
  8712. }
  8713. }
  8714. //---------------------------------------------------------------------------
  8715. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8716. {
  8717. FFileFindTerminal = Terminal;
  8718. ShowFileFindDialog(
  8719. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  8720. DoDownloadFoundFiles, DoEditFoundFiles);
  8721. }
  8722. //---------------------------------------------------------------------------
  8723. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8724. {
  8725. FTaskbarList = TaskbarList;
  8726. }
  8727. //---------------------------------------------------------------------------
  8728. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8729. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8730. {
  8731. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8732. if (Index >= 0)
  8733. {
  8734. if (Button == mbLeft)
  8735. {
  8736. // "Mouse down" is raised only after tab is switched.
  8737. // If switching tab (switching session) takes long enough for user
  8738. // to actually release the button, "mouse down" is still raised,
  8739. // but we do not get "mouse up" event, so dragging is not cancelled,
  8740. // prevent that by not beginning dragging in the first place.
  8741. if (IsKeyPressed(VK_LBUTTON))
  8742. {
  8743. // when user clicks the "+", we get mouse down only after the session
  8744. // is closed, when new session tab is already on X:Y, so dragging
  8745. // starts, prevent that
  8746. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8747. {
  8748. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8749. if (Terminal != NULL)
  8750. {
  8751. SessionsPageControl->BeginDrag(false);
  8752. }
  8753. }
  8754. }
  8755. }
  8756. else if (Button == mbMiddle)
  8757. {
  8758. // ignore middle-click for "New session tab"
  8759. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8760. if (Terminal != NULL)
  8761. {
  8762. SessionsPageControl->ActivePageIndex = Index;
  8763. // Switch to session tab (has to be session tab, due to previous check)
  8764. if (DebugAlwaysTrue(SessionTabSwitched()))
  8765. {
  8766. CloseSession();
  8767. }
  8768. }
  8769. }
  8770. }
  8771. }
  8772. //---------------------------------------------------------------------------
  8773. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8774. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8775. {
  8776. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8777. // do not allow dropping on the "+" tab
  8778. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8779. if ((TargetTerminal != NULL) &&
  8780. (SessionsPageControl->ActivePage->PageIndex != Index))
  8781. {
  8782. Configuration->Usage->Inc(L"SessionTabMoves");
  8783. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8784. // but we want to actually prevent that to avoid flicker
  8785. SessionsPageControl->ActivePage->PageIndex = Index;
  8786. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8787. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8788. }
  8789. }
  8790. //---------------------------------------------------------------------------
  8791. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8792. TObject * Sender, TObject * Source, int X, int Y,
  8793. TDragState /*State*/, bool & Accept)
  8794. {
  8795. Accept = (Sender == Source);
  8796. if (Accept)
  8797. {
  8798. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8799. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8800. // do not allow dragging to the "+" tab
  8801. Accept = (Terminal != NULL);
  8802. }
  8803. }
  8804. //---------------------------------------------------------------------------
  8805. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8806. const TPoint & Point, int & Effect)
  8807. {
  8808. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8809. if (Index < 0)
  8810. {
  8811. Effect = DROPEFFECT_None;
  8812. }
  8813. else
  8814. {
  8815. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8816. // do not allow dropping on the "+" tab
  8817. if (TargetTerminal == NULL)
  8818. {
  8819. Effect = DROPEFFECT_None;
  8820. }
  8821. }
  8822. }
  8823. //---------------------------------------------------------------------------
  8824. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8825. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8826. {
  8827. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8828. // do not allow dropping on the "+" tab
  8829. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8830. if (TargetTerminal != NULL)
  8831. {
  8832. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8833. if (!IsFileControl(DropSourceControl, osRemote))
  8834. {
  8835. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8836. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  8837. // Why don't we use Terminal->CurrentDirectory directly?
  8838. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory, false);
  8839. }
  8840. }
  8841. }
  8842. //---------------------------------------------------------------------------
  8843. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  8844. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  8845. {
  8846. // Downloads are handled in RemoteFileControlDDEnd
  8847. if (!IsFileControl(DropSourceControl, osRemote))
  8848. {
  8849. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  8850. Terminal->CurrentDirectory,
  8851. // force queue
  8852. true);
  8853. }
  8854. }
  8855. //---------------------------------------------------------------------------
  8856. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  8857. {
  8858. FShowing = false;
  8859. // Do not save empty workspace
  8860. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  8861. {
  8862. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  8863. UnicodeString Name = WorkspaceName();
  8864. DoSaveWorkspace(
  8865. Name, DataList.get(),
  8866. !Configuration->DisablePasswordStoring &&
  8867. WinConfiguration->AutoSaveWorkspacePasswords, false);
  8868. WinConfiguration->LastStoredSession = Name;
  8869. }
  8870. }
  8871. //---------------------------------------------------------------------------
  8872. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  8873. {
  8874. TManagedTerminal * ManagedTerminal =
  8875. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  8876. if (ManagedTerminal != NULL)
  8877. {
  8878. ManagedTerminal->DirectoryLoaded = Now();
  8879. }
  8880. }
  8881. //---------------------------------------------------------------------------
  8882. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  8883. TListItem * /*Item*/, bool /*Selected*/)
  8884. {
  8885. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8886. switch (DirView->LastSelectMethod)
  8887. {
  8888. case smKeyboard:
  8889. Configuration->Usage->Inc(L"KeyboardSelections");
  8890. break;
  8891. case smMouse:
  8892. Configuration->Usage->Inc(L"MouseSelections");
  8893. break;
  8894. }
  8895. }
  8896. //---------------------------------------------------------------------------
  8897. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  8898. {
  8899. if (Color != 0)
  8900. {
  8901. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  8902. }
  8903. else
  8904. {
  8905. return FSessionTabImageIndex;
  8906. }
  8907. }
  8908. //---------------------------------------------------------------------------
  8909. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  8910. {
  8911. TPngImageCollectionItem * Item =
  8912. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  8913. FSessionColors->AddPng(Item->PngImage);
  8914. return FSessionColors->Count - 1;
  8915. }
  8916. //---------------------------------------------------------------------------
  8917. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  8918. {
  8919. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  8920. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  8921. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  8922. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  8923. }
  8924. //---------------------------------------------------------------------------
  8925. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  8926. {
  8927. for (int Index = 0; Index < Control->ControlCount; Index++)
  8928. {
  8929. TControl * AControl = Control->Controls[Index];
  8930. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  8931. if (WinControl != NULL)
  8932. {
  8933. CollectItemsWithTextDisplayMode(WinControl);
  8934. }
  8935. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  8936. if (Toolbar != NULL)
  8937. {
  8938. // we care for top-level items only
  8939. TTBCustomItem * Items = Toolbar->Items;
  8940. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  8941. {
  8942. TTBCustomItem * Item = Items->Items[ItemIndex];
  8943. if (((Item->DisplayMode == nbdmImageAndText) ||
  8944. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  8945. EligibleForImageDisplayMode(Item))
  8946. {
  8947. FItemsWithTextDisplayMode.insert(Item);
  8948. }
  8949. }
  8950. }
  8951. }
  8952. }
  8953. //---------------------------------------------------------------------------
  8954. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  8955. {
  8956. return true;
  8957. }
  8958. //---------------------------------------------------------------------------
  8959. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  8960. {
  8961. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  8962. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  8963. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  8964. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  8965. bool Result = true;
  8966. while (Result && (i != FItemsWithTextDisplayMode.end()))
  8967. {
  8968. TTBCustomItem * Item = *i;
  8969. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  8970. if (Label != NULL)
  8971. {
  8972. // optimization
  8973. if (Label->Visible == SelectiveToolbarText)
  8974. {
  8975. Result = false;
  8976. }
  8977. else
  8978. {
  8979. Label->Visible = SelectiveToolbarText;
  8980. }
  8981. }
  8982. else
  8983. {
  8984. // optimization
  8985. if (Item->DisplayMode == DisplayMode)
  8986. {
  8987. Result = false;
  8988. }
  8989. else
  8990. {
  8991. Item->DisplayMode = DisplayMode;
  8992. }
  8993. }
  8994. ++i;
  8995. }
  8996. if (Result)
  8997. {
  8998. UpdateNewSessionTab();
  8999. }
  9000. return Result;
  9001. }
  9002. //---------------------------------------------------------------------------
  9003. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9004. {
  9005. DebugFail();
  9006. }
  9007. //---------------------------------------------------------------------------
  9008. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9009. {
  9010. // Among other, a lock level is non zero, while directory is being loaded,
  9011. // even when it happens as a result of dirview navigation,
  9012. // i.e. when TNonVisualDataModule is NOT FBusy.
  9013. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9014. // Among other this prevents a panel auto update to occur while
  9015. // directory is changing.
  9016. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9017. }
  9018. //---------------------------------------------------------------------------
  9019. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9020. {
  9021. // While the window is disabled, we still seem to process menu shortcuts at least,
  9022. // so stop it at least here.
  9023. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9024. return
  9025. (Allowed == aaUpdate) ||
  9026. !NonVisualDataModule->Busy;
  9027. }
  9028. //---------------------------------------------------------------------------
  9029. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9030. {
  9031. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9032. }
  9033. //---------------------------------------------------------------------------
  9034. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9035. {
  9036. // This is somewhat redundant to LockWindow() call from
  9037. // TTerminalManager::TerminalReadDirectoryProgress.
  9038. // But disabling window is known not to block keyboard shorcuts
  9039. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9040. if (Busy > 0)
  9041. {
  9042. if (NonVisualDataModule->Busy)
  9043. {
  9044. State = false;
  9045. }
  9046. else
  9047. {
  9048. NonVisualDataModule->StartBusy();
  9049. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9050. LockWindow();
  9051. }
  9052. }
  9053. else if (Busy < 0)
  9054. {
  9055. UnlockWindow();
  9056. NonVisualDataModule->EndBusy();
  9057. }
  9058. else
  9059. {
  9060. State = NonVisualDataModule->Busy;
  9061. }
  9062. }
  9063. //---------------------------------------------------------------------------
  9064. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9065. {
  9066. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9067. // no context menu for "New session tab"
  9068. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9069. {
  9070. SessionsPageControl->ActivePageIndex = Index;
  9071. if (DebugAlwaysTrue(SessionTabSwitched()))
  9072. {
  9073. // copied from TControl.WMContextMenu
  9074. SendCancelMode(SessionsPageControl);
  9075. // explicit popup instead of using PopupMenu property
  9076. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9077. // while connecting yet not-connected session and hence
  9078. // allowing an access to commands over not-completelly connected session
  9079. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9080. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9081. PopupMenu->PopupComponent = SessionsPageControl;
  9082. PopupMenu->Popup(Point.x, Point.y);
  9083. }
  9084. }
  9085. Handled = true;
  9086. }
  9087. //---------------------------------------------------------------------------
  9088. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9089. {
  9090. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9091. }
  9092. //---------------------------------------------------------------------------
  9093. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9094. {
  9095. Configuration->Usage->Inc(L"PasswordChanges");
  9096. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9097. ChangePasswordData->DisableAuthentationsExceptPassword();
  9098. ChangePasswordData->ChangePassword = true;
  9099. std::unique_ptr<TTerminal> ChangePasswordSession(
  9100. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9101. ChangePasswordSession->AutoReadDirectory = false;
  9102. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9103. {
  9104. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9105. }
  9106. else
  9107. {
  9108. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9109. }
  9110. }
  9111. //---------------------------------------------------------------------------
  9112. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9113. {
  9114. // No nice way to assert SSH2
  9115. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9116. }
  9117. //---------------------------------------------------------------------------
  9118. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9119. {
  9120. TOperationVisualizer OperationVisualizer;
  9121. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9122. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9123. }
  9124. //---------------------------------------------------------------------------
  9125. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9126. {
  9127. TForm::ChangeScale(M, D);
  9128. int APixelsPerInch = GetControlPixelsPerInch(this);
  9129. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9130. try
  9131. {
  9132. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9133. }
  9134. __finally
  9135. {
  9136. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9137. }
  9138. }
  9139. //---------------------------------------------------------------------------
  9140. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9141. {
  9142. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9143. }
  9144. //---------------------------------------------------------------------
  9145. class TPublicControl : public TControl
  9146. {
  9147. friend class TCustomScpExplorerForm;
  9148. };
  9149. //---------------------------------------------------------------------------
  9150. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9151. {
  9152. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9153. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9154. }
  9155. //---------------------------------------------------------------------------
  9156. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9157. {
  9158. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9159. OpenBookmark(Side, Bookmark);
  9160. }
  9161. //---------------------------------------------------------------------------
  9162. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9163. {
  9164. DoBookmarkClick(osLocal, Sender);
  9165. }
  9166. //---------------------------------------------------------------------------
  9167. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9168. {
  9169. DoBookmarkClick(osRemote, Sender);
  9170. }
  9171. //---------------------------------------------------------------------------
  9172. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9173. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9174. {
  9175. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9176. if (!WinConfiguration->UseLocationProfiles)
  9177. {
  9178. std::unique_ptr<TStringList> Directories(new TStringList());
  9179. Directories->CaseSensitive = (Side == osRemote);
  9180. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9181. {
  9182. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9183. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9184. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9185. {
  9186. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9187. Item->Caption = EscapeHotkey(Directory);
  9188. Item->ShortCut = Bookmark->ShortCut;
  9189. Item->OnClick = OnBookmarkClick;
  9190. Item->Tag = reinterpret_cast<int>(Bookmark);
  9191. Directories->Add(Directory);
  9192. Menu->Add(Item.release());
  9193. }
  9194. }
  9195. }
  9196. else
  9197. {
  9198. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9199. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9200. {
  9201. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9202. if (!Bookmark->Node.IsEmpty())
  9203. {
  9204. Folders->Add(Bookmark->Node);
  9205. }
  9206. }
  9207. for (int Index = 0; Index < Folders->Count; Index++)
  9208. {
  9209. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9210. Item->Caption = Folders->Strings[Index];
  9211. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9212. Folders->Objects[Index] = Item.get();
  9213. Menu->Add(Item.release());
  9214. }
  9215. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9216. {
  9217. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9218. TTBCustomItem * Parent;
  9219. if (!Bookmark->Node.IsEmpty())
  9220. {
  9221. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9222. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9223. }
  9224. else
  9225. {
  9226. Parent = Menu;
  9227. }
  9228. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9229. Item->Caption = Bookmark->Name;
  9230. Item->ShortCut = Bookmark->ShortCut;
  9231. Item->OnClick = OnBookmarkClick;
  9232. Item->Tag = reinterpret_cast<int>(Bookmark);
  9233. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9234. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9235. {
  9236. // No hint for location profiles that are actually mere "bookmarks"
  9237. }
  9238. else
  9239. {
  9240. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9241. UnicodeString LongHint;
  9242. if (!Bookmark->Local.IsEmpty())
  9243. {
  9244. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9245. }
  9246. if (!Bookmark->Remote.IsEmpty())
  9247. {
  9248. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9249. }
  9250. AddToList(Hint, LongHint, L"|");
  9251. Item->Hint = Hint;
  9252. }
  9253. Parent->Add(Item.release());
  9254. }
  9255. }
  9256. }
  9257. //---------------------------------------------------------------------------
  9258. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9259. {
  9260. Menu->Clear();
  9261. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9262. AddMenuSeparator(Menu);
  9263. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9264. AddMenuSeparator(Menu);
  9265. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9266. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9267. Menu->Add(Item.release());
  9268. }
  9269. //---------------------------------------------------------------------------
  9270. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9271. {
  9272. bool Result = true;
  9273. try
  9274. {
  9275. if (Side == osRemote)
  9276. {
  9277. Terminal->ExceptionOnFail = true;
  9278. }
  9279. try
  9280. {
  9281. DirView(Side)->Path = Path;
  9282. }
  9283. __finally
  9284. {
  9285. if (Side == osRemote)
  9286. {
  9287. Terminal->ExceptionOnFail = false;
  9288. }
  9289. }
  9290. }
  9291. catch (Exception & E)
  9292. {
  9293. if ((Side != osRemote) || Terminal->Active)
  9294. {
  9295. ShowExtendedExceptionEx(Terminal, &E);
  9296. Result = false;
  9297. }
  9298. else
  9299. {
  9300. throw;
  9301. }
  9302. }
  9303. return Result;
  9304. }
  9305. //---------------------------------------------------------------------------
  9306. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9307. {
  9308. // Make sure there some feedback even when loading tine local folders
  9309. TInstantOperationVisualizer Visualizer;
  9310. DirView(Side)->ReloadDirectory();
  9311. }
  9312. //---------------------------------------------------------------------------
  9313. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9314. {
  9315. if (Index == SessionsPageControl->TabIndex)
  9316. {
  9317. CloseSession();
  9318. }
  9319. else
  9320. {
  9321. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9322. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9323. TTerminalManager * Manager = TTerminalManager::Instance();
  9324. if (!Terminal->Active)
  9325. {
  9326. Manager->FreeTerminal(Terminal);
  9327. }
  9328. else
  9329. {
  9330. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9331. if (CanCloseQueue(Queue))
  9332. {
  9333. Manager->FreeTerminal(Terminal);
  9334. }
  9335. }
  9336. }
  9337. }
  9338. //---------------------------------------------------------------------------