CustomScpExplorer.cpp 342 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485
  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 WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. static const int SessionPanelCount = 4;
  55. //---------------------------------------------------------------------------
  56. class TMutexGuard
  57. {
  58. public:
  59. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  60. int Timeout = 5000)
  61. {
  62. FMutex = NULL;
  63. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  64. if (WaitResult == WAIT_TIMEOUT)
  65. {
  66. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  67. }
  68. else
  69. {
  70. FMutex = AMutex;
  71. }
  72. }
  73. ~TMutexGuard()
  74. {
  75. if (FMutex != NULL)
  76. {
  77. ReleaseMutex(FMutex);
  78. }
  79. }
  80. private:
  81. HANDLE FMutex;
  82. };
  83. //---------------------------------------------------------------------------
  84. class TWindowLock
  85. {
  86. public:
  87. TWindowLock(TCustomScpExplorerForm * Form) :
  88. FForm(Form)
  89. {
  90. FForm->LockWindow();
  91. }
  92. ~TWindowLock()
  93. {
  94. FForm->UnlockWindow();
  95. }
  96. private:
  97. TCustomScpExplorerForm * FForm;
  98. };
  99. //---------------------------------------------------------------------------
  100. class TAutoBatch
  101. {
  102. public:
  103. TAutoBatch(TCustomScpExplorerForm * Form) :
  104. FForm(Form)
  105. {
  106. FForm->BatchStart(FBatchStorage);
  107. }
  108. ~TAutoBatch()
  109. {
  110. FForm->BatchEnd(FBatchStorage);
  111. }
  112. private:
  113. TCustomScpExplorerForm * FForm;
  114. void * FBatchStorage;
  115. };
  116. //---------------------------------------------------------------------------
  117. struct TTransferOperationParam
  118. {
  119. TTransferOperationParam();
  120. UnicodeString TargetDirectory;
  121. bool Temp;
  122. bool DragDrop;
  123. int Options;
  124. TAutoSwitch Queue;
  125. };
  126. //---------------------------------------------------------------------------
  127. TTransferOperationParam::TTransferOperationParam()
  128. {
  129. Temp = false;
  130. DragDrop = false;
  131. Options = 0;
  132. Queue = asAuto;
  133. }
  134. //---------------------------------------------------------------------------
  135. class TTransferPresetNoteData : public TObject
  136. {
  137. public:
  138. UnicodeString Message;
  139. };
  140. //---------------------------------------------------------------------------
  141. class TTerminalNoteData : public TObject
  142. {
  143. public:
  144. TTerminal * Terminal;
  145. };
  146. //---------------------------------------------------------------------------
  147. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  148. FFormRestored(false),
  149. TForm(Owner)
  150. {
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. RestoreParams();
  155. ConfigurationChanged();
  156. RemoteDirView->Invalidate();
  157. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  158. NonVisualDataModule->ScpExplorer = this;
  159. FAutoOperation = false;
  160. FOnFileOperationFinished = NULL;
  161. FForceExecution = false;
  162. FIgnoreNextDialogChar = 0;
  163. FErrorList = NULL;
  164. FSynchronizeProgressForm = NULL;
  165. FProgressForm = NULL;
  166. FRefreshLocalDirectory = false;
  167. FRefreshRemoteDirectory = false;
  168. FDDExtMapFile = NULL;
  169. // CreateMutexW keeps failing with ERROR_NOACCESS
  170. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  171. DebugAssert(FDDExtMutex != NULL);
  172. FDDTargetControl = NULL;
  173. FDelayedDeletionTimer = NULL;
  174. FDelayedDeletionList = new TStringList();
  175. FDDFileList = NULL;
  176. FPendingTempSpaceWarn = false;
  177. FCapturedLog = NULL;
  178. FDragDropOperation = false;
  179. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  180. FAllowTransferPresetAutoSelect = true;
  181. FCopyParamDefault = L"";
  182. FSynchronizeController = NULL;
  183. FPendingQueueActionItem = NULL;
  184. FLockLevel = 0;
  185. FLockSuspendLevel = 0;
  186. FDisabledOnLockSuspend = false;
  187. FAlternativeDelete = false;
  188. FTrayIcon = new ::TTrayIcon(0);
  189. FTrayIcon->OnClick = TrayIconClick;
  190. FMaxQueueLength = 0;
  191. FLastContextPopupScreenPoint = TPoint(-1, -1);
  192. FTransferResumeList = NULL;
  193. FMoveToQueue = false;
  194. FStandaloneEditing = false;
  195. FOnFeedSynchronizeError = NULL;
  196. FNeedSession = false;
  197. FDoNotIdleCurrentTerminal = 0;
  198. FIncrementalSearching = 0;
  199. FIncrementalSearchHaveNext = false;
  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. delete FCustomCommandLocalFileList;
  263. delete FCustomCommandRemoteFileList;
  264. delete FCustomCommandMenu;
  265. delete FTrayIcon;
  266. FTrayIcon = NULL;
  267. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  268. delete FEditorManager;
  269. ForceCloseLocalEditors();
  270. delete FLocalEditors;
  271. HideFileFindDialog();
  272. if (FDelayedDeletionTimer)
  273. {
  274. DoDelayedDeletion(NULL);
  275. SAFE_DESTROY(FDelayedDeletionTimer);
  276. }
  277. SAFE_DESTROY(FDelayedDeletionList);
  278. // sometimes we do not get DDEnd so the list is not released
  279. SAFE_DESTROY(FDDFileList);
  280. DebugAssert(FSynchronizeController == NULL);
  281. CloseHandle(FDDExtMutex);
  282. FDDExtMutex = NULL;
  283. FreeLibrary(FOle32Library);
  284. FOle32Library = NULL;
  285. FDragMoveCursor = NULL;
  286. DebugAssert(!FErrorList);
  287. if (FEverShown)
  288. {
  289. // when window is never shown (like when running command-line operation),
  290. // particularly window site is not restored correctly (BoundsRect value set
  291. // in RestoreForm gets lost during handle allocation), so we do not want
  292. // it to be stored
  293. StoreParams();
  294. }
  295. Terminal = NULL;
  296. Queue = NULL;
  297. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  298. NonVisualDataModule->ScpExplorer = NULL;
  299. delete FQueueController;
  300. FQueueController = NULL;
  301. delete FQueueStatusSection;
  302. FQueueStatusSection = NULL;
  303. delete FQueueStatus;
  304. FQueueStatus = NULL;
  305. delete FUserActionTimer;
  306. FUserActionTimer = NULL;
  307. delete FNoteTimer;
  308. delete FNotes;
  309. delete FNoteData;
  310. SAFE_DESTROY(FDocks);
  311. SessionsPageControl->Images = NULL;
  312. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  313. SAFE_DESTROY(FSessionColors);
  314. SAFE_DESTROY(FSessionsDragDropFilesEx);
  315. SAFE_DESTROY(FHistoryMenu[0][0]);
  316. SAFE_DESTROY(FHistoryMenu[0][1]);
  317. SAFE_DESTROY(FHistoryMenu[1][0]);
  318. SAFE_DESTROY(FHistoryMenu[1][1]);
  319. if (FHiddenWindow != NULL)
  320. {
  321. DestroyWindow(FHiddenWindow);
  322. FHiddenWindow = NULL;
  323. }
  324. }
  325. //---------------------------------------------------------------------------
  326. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  327. {
  328. std::unique_ptr<TSessionData> Data;
  329. if (!Session.IsEmpty())
  330. {
  331. bool DefaultsOnly;
  332. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  333. }
  334. TTerminalManager * Manager = TTerminalManager::Instance();
  335. for (int Index = 0; Index < Manager->Count; Index++)
  336. {
  337. TTerminal * Terminal = Manager->Terminals[Index];
  338. if (Session.IsEmpty() ||
  339. Terminal->SessionData->IsSameSite(Data.get()))
  340. {
  341. if (Path.IsEmpty())
  342. {
  343. Terminal->ClearCaches();
  344. }
  345. else
  346. {
  347. Terminal->DirectoryModified(Path, true);
  348. }
  349. }
  350. }
  351. // We should flag a pending refresh for the background terminals or busy foreground terminals
  352. if ((Terminal != NULL) && Terminal->Active &&
  353. CanCommandLineFromAnotherInstance() &&
  354. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  355. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  356. {
  357. Terminal->ReloadDirectory();
  358. }
  359. }
  360. //---------------------------------------------------------------------------
  361. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  362. {
  363. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  364. size_t MessageSize = sizeof(TCopyDataMessage);
  365. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  366. if (Result)
  367. {
  368. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  369. Result = (Message.Version == TCopyDataMessage::Version1);
  370. if (Result)
  371. {
  372. switch (Message.Command)
  373. {
  374. case TCopyDataMessage::CommandCanCommandLine:
  375. Result = CanCommandLineFromAnotherInstance();
  376. break;
  377. case TCopyDataMessage::CommandCommandLine:
  378. {
  379. UnicodeString CommandLine(Message.CommandLine);
  380. Result = CommandLineFromAnotherInstance(CommandLine);
  381. }
  382. break;
  383. case TCopyDataMessage::RefreshPanel:
  384. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  385. break;
  386. case TCopyDataMessage::MainWindowCheck:
  387. Result = true;
  388. break;
  389. default:
  390. Result = false;
  391. break;
  392. }
  393. }
  394. }
  395. Message.Result = Result ? 1 : 0;
  396. }
  397. //---------------------------------------------------------------------------
  398. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  399. {
  400. WNDCLASS WindowClass = {0};
  401. WindowClass.lpfnWndProc = DefWindowProc;
  402. WindowClass.hInstance = HInstance;
  403. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  404. FHiddenWindow = NULL;
  405. if (RegisterClass(&WindowClass))
  406. {
  407. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  408. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  409. }
  410. }
  411. //---------------------------------------------------------------------------
  412. bool __fastcall TCustomScpExplorerForm::CanConsole()
  413. {
  414. return
  415. (Terminal != NULL) &&
  416. Terminal->Active &&
  417. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  418. }
  419. //---------------------------------------------------------------------------
  420. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  421. {
  422. bool Result = Visible && !NonVisualDataModule->Busy;
  423. return Result;
  424. }
  425. //---------------------------------------------------------------------------
  426. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  427. const UnicodeString & CommandLine)
  428. {
  429. TProgramParams Params(CommandLine);
  430. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  431. if (Result)
  432. {
  433. NonVisualDataModule->StartBusy();
  434. try
  435. {
  436. // this action is initiated from another process,
  437. // so it's likely that our window is not visible,
  438. // and user won't see what is going on
  439. Application->BringToFront();
  440. // reload sessions as we may be asked to open a session
  441. // just stored by another instance
  442. StoredSessions->Reload();
  443. UnicodeString SessionName = Params.Param[1];
  444. std::unique_ptr<TObjectList> DataList(new TObjectList());
  445. UnicodeString DownloadFile; // unused
  446. try
  447. {
  448. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  449. }
  450. catch (EAbort &)
  451. {
  452. // Happens when opening session in PuTTY and in other situations,
  453. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  454. // to process the command-line on its own (or to pass it to yet another instance)
  455. }
  456. if (DataList->Count > 0)
  457. {
  458. TTerminalManager * Manager = TTerminalManager::Instance();
  459. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  460. }
  461. }
  462. __finally
  463. {
  464. NonVisualDataModule->EndBusy();
  465. }
  466. }
  467. return Result;
  468. }
  469. //---------------------------------------------------------------------------
  470. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  471. {
  472. if (FTerminal != value)
  473. {
  474. TerminalChanging();
  475. DoSetTerminal(value, false);
  476. }
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TTerminal * value, bool Replace)
  480. {
  481. FTerminal = value;
  482. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  483. FAllowTransferPresetAutoSelect = false;
  484. try
  485. {
  486. TerminalChanged(Replace);
  487. }
  488. __finally
  489. {
  490. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  491. }
  492. if (Terminal != NULL)
  493. {
  494. TransferPresetAutoSelect();
  495. }
  496. }
  497. //---------------------------------------------------------------------------
  498. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TTerminal * value)
  499. {
  500. DoSetTerminal(value, true);
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  504. {
  505. if (FTerminal != NULL)
  506. {
  507. UpdateTerminal(Terminal);
  508. }
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  512. {
  513. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  514. if (ManagedTerminal != NULL)
  515. {
  516. UpdateSessionColor((TColor)ManagedTerminal->StateData->Color);
  517. }
  518. DoTerminalListChanged();
  519. if (Replaced)
  520. {
  521. RemoteDirView->ReplaceTerminal(Terminal);
  522. }
  523. else
  524. {
  525. RemoteDirView->Terminal = Terminal;
  526. }
  527. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  528. if (Terminal != NULL)
  529. {
  530. if (Terminal->Active)
  531. {
  532. Terminal->RefreshDirectory();
  533. }
  534. DebugAssert(ManagedTerminal == Terminal);
  535. if (WinConfiguration->PreservePanelState)
  536. {
  537. if (ManagedTerminal->RemoteExplorerState != NULL)
  538. {
  539. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  540. }
  541. else
  542. {
  543. RemoteDirView->ClearState();
  544. }
  545. }
  546. if (!Replaced)
  547. {
  548. InitStatusBar();
  549. }
  550. }
  551. UpdateTransferList();
  552. // Update panels Enable state before refreshing the labels
  553. UpdateControls();
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  557. {
  558. if (Queue != value)
  559. {
  560. if (FQueue != NULL)
  561. {
  562. FQueue->OnListUpdate = NULL;
  563. FQueue->OnQueueItemUpdate = NULL;
  564. }
  565. FQueue = value;
  566. if (FQueue != NULL)
  567. {
  568. DebugAssert(FQueue->OnListUpdate == NULL);
  569. FQueue->OnListUpdate = QueueListUpdate;
  570. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  571. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  572. }
  573. QueueChanged();
  574. }
  575. }
  576. //---------------------------------------------------------------------------
  577. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  578. TListItem * Item)
  579. {
  580. if (FQueueActedItem == Item)
  581. {
  582. FQueueActedItem = NULL;
  583. if ((QueueView3->PopupMenu != NULL) &&
  584. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  585. {
  586. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  587. ReleaseCapture();
  588. }
  589. }
  590. if (Item->Data == FPendingQueueActionItem)
  591. {
  592. FPendingQueueActionItem = NULL;
  593. }
  594. }
  595. //---------------------------------------------------------------------------
  596. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  597. {
  598. {
  599. TGuard Guard(FQueueStatusSection);
  600. FQueueStatusInvalidated = false;
  601. if (FQueue != NULL)
  602. {
  603. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  604. }
  605. }
  606. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  607. {
  608. FMaxQueueLength = FQueueStatus->Count;
  609. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  610. }
  611. FQueueController->UpdateQueueStatus(FQueueStatus);
  612. SetQueueProgress();
  613. UpdateQueueView();
  614. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  615. if (IsEmpty && (Terminal != NULL))
  616. {
  617. TOnceDoneOperation OnceDoneOperation =
  618. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  619. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  620. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  621. {
  622. FQueue->Enabled = false;
  623. }
  624. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  625. {
  626. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  627. }
  628. }
  629. }
  630. //---------------------------------------------------------------------------
  631. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  632. {
  633. UnicodeString Result;
  634. if (FQueueStatus != NULL)
  635. {
  636. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  637. {
  638. TFileOperationProgressType * ProgressData =
  639. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  640. if ((ProgressData != NULL) && ProgressData->InProgress)
  641. {
  642. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  643. }
  644. }
  645. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  646. {
  647. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  648. }
  649. }
  650. return Result;
  651. }
  652. //---------------------------------------------------------------------------
  653. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  654. {
  655. ComponentVisible[fcQueueView] =
  656. (WinConfiguration->QueueView.Show == qvShow) ||
  657. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  658. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TCustomScpExplorerForm::QueueChanged()
  662. {
  663. if (FQueueStatus != NULL)
  664. {
  665. delete FQueueStatus;
  666. FQueueStatus = NULL;
  667. }
  668. UpdateQueueStatus(true);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  672. {
  673. if (FQueue == Queue)
  674. {
  675. FQueueStatusInvalidated = true;
  676. }
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  680. TQueueItem * Item)
  681. {
  682. if (FQueue == Queue)
  683. {
  684. TGuard Guard(FQueueStatusSection);
  685. // this may be running in parallel with QueueChanged
  686. if (FQueueStatus != NULL)
  687. {
  688. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  689. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  690. {
  691. FRefreshLocalDirectory = (QueueItem == NULL) ||
  692. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  693. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  694. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  695. }
  696. if (QueueItem != NULL)
  697. {
  698. QueueItem->UserData = (void*)true;
  699. FQueueItemInvalidated = true;
  700. }
  701. }
  702. }
  703. }
  704. //---------------------------------------------------------------------------
  705. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  706. {
  707. // during standalone editing, we have no way to see/control queue,
  708. // so we have to always popup prompts automatically
  709. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  713. {
  714. if (FQueueStatus != NULL)
  715. {
  716. bool QueueAutoPopup = IsQueueAutoPopup();
  717. bool NeedRefresh = FQueueController->NeedRefresh();
  718. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  719. FQueueItemInvalidated = false;
  720. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  721. bool Updated = false;
  722. TQueueItemProxy * QueueItem;
  723. bool WasUserAction;
  724. for (int Index = 0; Index < Limit; Index++)
  725. {
  726. bool Update = false;
  727. QueueItem = FQueueStatus->Items[Index];
  728. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  729. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  730. (FPendingQueueActionItem == NULL))
  731. {
  732. FPendingQueueActionItem = QueueItem;
  733. FUserActionTimer->Enabled = true;
  734. }
  735. if ((bool)QueueItem->UserData)
  736. {
  737. QueueItem->UserData = (void*)false;
  738. QueueItem->Update();
  739. Updated = true;
  740. Update = true;
  741. }
  742. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  743. {
  744. Update = true;
  745. }
  746. if (Update)
  747. {
  748. FQueueController->RefreshQueueItem(QueueItem);
  749. }
  750. }
  751. if (Updated)
  752. {
  753. NonVisualDataModule->UpdateNonVisibleActions();
  754. SetQueueProgress();
  755. }
  756. }
  757. }
  758. //---------------------------------------------------------------------------
  759. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  760. {
  761. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  762. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  763. }
  764. //---------------------------------------------------------------------------
  765. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  766. {
  767. if (ProgressData->Operation != foCalculateSize)
  768. {
  769. int OverallProgress;
  770. // FProgressForm is null when this is called from SetQueueProgress
  771. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  772. {
  773. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  774. }
  775. else
  776. {
  777. OverallProgress = ProgressData->OverallProgress();
  778. }
  779. // implies TBPF_NORMAL
  780. FTaskbarList->SetProgressValue(GetMainForm()->Handle, OverallProgress, 100);
  781. }
  782. else
  783. {
  784. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  785. }
  786. }
  787. //---------------------------------------------------------------------------
  788. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  789. {
  790. TTerminalManager::Instance()->QueueStatusUpdated();
  791. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  792. {
  793. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  794. {
  795. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  796. {
  797. TFileOperationProgressType * ProgressData = NULL;
  798. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  799. {
  800. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  801. }
  802. if ((ProgressData != NULL) &&
  803. ProgressData->InProgress)
  804. {
  805. SetTaskbarListProgressValue(ProgressData);
  806. }
  807. else
  808. {
  809. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  810. }
  811. }
  812. else
  813. {
  814. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  815. }
  816. }
  817. else
  818. {
  819. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  820. }
  821. }
  822. UpdateQueueLabel();
  823. }
  824. //---------------------------------------------------------------------------
  825. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  826. {
  827. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  828. if (FQueueStatus != NULL)
  829. {
  830. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  831. if (ActiveAndPendingPrimaryCount > 0)
  832. {
  833. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  834. }
  835. }
  836. QueueLabel->Caption = Caption;
  837. }
  838. //---------------------------------------------------------------------------
  839. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  840. {
  841. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  842. static_cast<TComponent*>(GetComponent(fcTransferList)));
  843. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  844. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  845. TransferList->Strings->BeginUpdate();
  846. try
  847. {
  848. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  849. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  850. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  851. if (FTransferDropDownHint.IsEmpty())
  852. {
  853. FTransferDropDownHint = TransferDropDown->Hint;
  854. }
  855. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  856. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  857. TransferDropDown->Text = StripHotkey(Name);
  858. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  859. (FTransferDropDownHint, StripHotkey(Name),
  860. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  861. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General))));
  862. // update the label, otherwise when it is updated only on the first draw
  863. // of the list, it is drawn "bold" for some reason
  864. FTransferListHoverIndex = TransferList->ItemIndex;
  865. UpdateTransferLabel();
  866. }
  867. __finally
  868. {
  869. TransferList->Strings->EndUpdate();
  870. }
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  874. {
  875. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  876. DebugAssert(Toolbar != NULL);
  877. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  878. }
  879. //---------------------------------------------------------------------------
  880. void __fastcall TCustomScpExplorerForm::UpdateActions()
  881. {
  882. TForm::UpdateActions();
  883. if (ComponentVisible[fcCustomCommandsBand])
  884. {
  885. UpdateCustomCommandsToolbar();
  886. }
  887. }
  888. //---------------------------------------------------------------------------
  889. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  890. {
  891. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  892. }
  893. //---------------------------------------------------------------------------
  894. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  895. {
  896. Color = GetBtnFaceColor();
  897. DebugAssert(Configuration && RemoteDirView);
  898. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  899. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  900. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  901. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  902. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  903. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  904. {
  905. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  906. // selection is not redrawn automatically when RowSelect changes
  907. RemoteDirView->Invalidate();
  908. }
  909. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  910. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  911. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  912. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  913. UpdateSessionsPageControlHeight();
  914. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  915. UpdateToolbarDisplayMode();
  916. UpdateTransferList();
  917. if (Terminal != NULL)
  918. {
  919. TransferPresetAutoSelect();
  920. }
  921. UpdateQueueView();
  922. UpdateControls();
  923. // this can be called even before constuctor finishes.
  924. if (FEditorManager != NULL)
  925. {
  926. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  927. }
  928. // this can be called even before constuctor finishes.
  929. if (FLocalEditors != NULL)
  930. {
  931. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  932. {
  933. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  934. }
  935. }
  936. if (ComponentVisible[fcCustomCommandsBand])
  937. {
  938. UpdateCustomCommandsToolbar();
  939. }
  940. // show only when keeping queue items forever,
  941. // otherwise, its enough to have in in the context menu
  942. QueueDeleteAllDoneQueueToolbarItem->Visible =
  943. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  944. if (FFileColorsCurrent != WinConfiguration->FileColors)
  945. {
  946. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  947. FFileColorsCurrent = WinConfiguration->FileColors;
  948. FileColorsChanged();
  949. }
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  953. {
  954. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  955. DirView->Invalidate();
  956. }
  957. //---------------------------------------------------------------------------
  958. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  959. {
  960. DoFileColorsChanged(RemoteDirView);
  961. }
  962. //---------------------------------------------------------------------------
  963. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  964. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  965. void * /*Arg*/)
  966. {
  967. if (Token != NULL)
  968. {
  969. TForm * Editor = dynamic_cast<TForm*>(Token);
  970. DebugAssert(Editor != NULL);
  971. ReconfigureEditorForm(Editor);
  972. }
  973. }
  974. //---------------------------------------------------------------------------
  975. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  976. {
  977. WinConfiguration->DDTransferConfirmation = asOn;
  978. }
  979. //---------------------------------------------------------------------------
  980. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  981. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  982. {
  983. // noop
  984. }
  985. //---------------------------------------------------------------------------
  986. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  987. TTransferDirection Direction, TTransferType Type, bool Temp,
  988. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  989. bool Confirm, bool DragDrop, int Options)
  990. {
  991. bool Result = true;
  992. DebugAssert(Terminal && Terminal->Active);
  993. // these parameters are known in advance
  994. int Params =
  995. FLAGMASK(Type == ttMove, cpDelete);
  996. bool ToTemp = (Temp && (Direction == tdToLocal));
  997. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  998. {
  999. bool DisableNewerOnly =
  1000. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1001. ToTemp;
  1002. Options |=
  1003. FLAGMASK(ToTemp, coTemp) |
  1004. FLAGMASK(!Terminal->IsCapable[fsBackgroundTransfers], coDisableQueue) |
  1005. coDoNotShowAgain;
  1006. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1007. int CopyParamAttrs = (Direction == tdToRemote ?
  1008. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1009. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1010. int OutputOptions =
  1011. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1012. cooDoNotShowAgain);
  1013. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1014. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1015. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1016. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  1017. if (Result)
  1018. {
  1019. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1020. {
  1021. if (DragDrop)
  1022. {
  1023. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1024. {
  1025. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1026. NULL, 0, EnableDDTransferConfirmation, NULL);
  1027. }
  1028. WinConfiguration->DDTransferConfirmation = asOff;
  1029. }
  1030. else
  1031. {
  1032. WinConfiguration->ConfirmTransferring = false;
  1033. }
  1034. }
  1035. else
  1036. {
  1037. // User explicitly unchecked "do not show again",
  1038. // so show him the dialog the next time
  1039. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1040. {
  1041. WinConfiguration->DDTransferConfirmation = asOn;
  1042. }
  1043. }
  1044. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1045. }
  1046. }
  1047. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fsBackgroundTransfers])
  1048. {
  1049. Configuration->Usage->Inc(L"TransfersOnBackground");
  1050. // these parameter are known only after transfer dialog
  1051. Params |=
  1052. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1053. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1054. Result = false;
  1055. ClearTransferSourceSelection(Direction);
  1056. }
  1057. return Result;
  1058. }
  1059. //---------------------------------------------------------------------------
  1060. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1061. {
  1062. if (FOnFileOperationFinished != NULL)
  1063. {
  1064. FOnFileOperationFinished(UnicodeString(), true);
  1065. }
  1066. else
  1067. {
  1068. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1069. if (HasDirView[Side])
  1070. {
  1071. DirView(Side)->SelectAll(smNone);
  1072. }
  1073. }
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1077. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1078. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1079. int Params)
  1080. {
  1081. DebugAssert(Queue != NULL);
  1082. bool SingleFile = false;
  1083. if (FileList->Count == 1)
  1084. {
  1085. if (Direction == tdToRemote)
  1086. {
  1087. UnicodeString FileName = FileList->Strings[0];
  1088. SingleFile = FileExists(ApiPath(FileName));
  1089. }
  1090. else
  1091. {
  1092. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1093. SingleFile = !File->IsDirectory;
  1094. }
  1095. }
  1096. TQueueItem * QueueItem;
  1097. if (Direction == tdToRemote)
  1098. {
  1099. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1100. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1101. }
  1102. else
  1103. {
  1104. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1105. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1106. }
  1107. AddQueueItem(Queue, QueueItem, Terminal);
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1111. {
  1112. if (Queue->IsEmpty)
  1113. {
  1114. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1115. ManagedTerminal->QueueOperationStart = Now();
  1116. }
  1117. Queue->AddItem(QueueItem);
  1118. }
  1119. //---------------------------------------------------------------------------
  1120. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1121. {
  1122. }
  1123. //---------------------------------------------------------------------------
  1124. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1125. {
  1126. DebugAssert(FDocks != NULL);
  1127. for (int Index = 0; Index < ComponentCount; Index++)
  1128. {
  1129. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1130. if ((Dock != NULL) && (Dock->Tag == 0))
  1131. {
  1132. FDocks->Add(Dock);
  1133. }
  1134. }
  1135. CollectItemsWithTextDisplayMode(this);
  1136. ConfigurationChanged();
  1137. QueuePanel->Height =
  1138. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1139. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1140. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1141. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TCustomScpExplorerForm::StoreParams()
  1145. {
  1146. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1147. WinConfiguration->QueueView.HeightPixelsPerInch = GetControlPixelsPerInch(this);
  1148. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1149. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1150. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1154. {
  1155. if (!FFormRestored)
  1156. {
  1157. FFormRestored = true;
  1158. RestoreFormParams();
  1159. }
  1160. TForm::CreateParams(Params);
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1164. {
  1165. DebugAssert(FDocks != NULL);
  1166. for (int Index = 0; Index < FDocks->Count; Index++)
  1167. {
  1168. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1169. }
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1173. {
  1174. SetDockAllowDrag(true);
  1175. while (!ButtonsStr.IsEmpty())
  1176. {
  1177. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1178. UnicodeString Name = CutToChar(S, L'=', true);
  1179. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1180. {
  1181. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1182. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1183. {
  1184. while (!S.IsEmpty())
  1185. {
  1186. UnicodeString S2 = CutToChar(S, L',', true);
  1187. UnicodeString Name = CutToChar(S2, L':', true);
  1188. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1189. {
  1190. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1191. if (SameText(GetToolbarItemName(Item), Name))
  1192. {
  1193. // forward compatibility
  1194. UnicodeString S3 = CutToChar(S2, L':', true);
  1195. bool Visible = StrToIntDef(S3, 0);
  1196. Item->Visible = Visible;
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1204. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1205. }
  1206. //---------------------------------------------------------------------------
  1207. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1208. {
  1209. UnicodeString Result;
  1210. SetDockAllowDrag(true);
  1211. Result = ::GetToolbarsLayoutStr(this);
  1212. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1213. return Result;
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1217. {
  1218. UnicodeString Result;
  1219. if (Item->Action != NULL)
  1220. {
  1221. Result = Item->Action->Name;
  1222. Result = RemoveSuffix(Result, L"Action");
  1223. }
  1224. else
  1225. {
  1226. Result = Item->Name;
  1227. Result = RemoveSuffix(Result, L"SubmenuItem");
  1228. Result = RemoveSuffix(Result, L"Item");
  1229. }
  1230. return Result;
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1234. {
  1235. UnicodeString Result;
  1236. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1237. {
  1238. UnicodeString ToolbarStr;
  1239. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1240. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1241. {
  1242. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1243. {
  1244. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1245. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1246. // Once we introduce any buttons that aer hidden by default, we would have to remember their initial state
  1247. // and save the changes here only.
  1248. if (!Item->Visible)
  1249. {
  1250. UnicodeString Name = GetToolbarItemName(Item);
  1251. DebugAssert(Name.Pos(L"TBX") == 0);
  1252. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1253. }
  1254. }
  1255. }
  1256. if (!ToolbarStr.IsEmpty())
  1257. {
  1258. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1259. }
  1260. }
  1261. return Result;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1265. {
  1266. DebugAssert(FProgressForm == NULL);
  1267. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fsSkipTransfer] : false;
  1268. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1269. FProgressForm->DeleteLocalToRecycleBin =
  1270. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1271. FProgressForm->DeleteRemoteToRecycleBin =
  1272. (Terminal != NULL) &&
  1273. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1274. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1275. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1276. LockWindow();
  1277. if (FTaskbarList != NULL)
  1278. {
  1279. // Actually, do not know what hides the progress once the operation finishes
  1280. SetTaskbarListProgressState(TBPF_NORMAL);
  1281. }
  1282. }
  1283. //---------------------------------------------------------------------------
  1284. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1285. {
  1286. UnlockWindow();
  1287. SAFE_DESTROY(FProgressForm);
  1288. SetQueueProgress();
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1292. TFileOperationProgressType & ProgressData)
  1293. {
  1294. // Download to temporary local directory
  1295. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1296. {
  1297. bool Continue = true;
  1298. FPendingTempSpaceWarn = false;
  1299. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1300. if (!Continue)
  1301. {
  1302. Abort();
  1303. }
  1304. }
  1305. // operation is being executed and we still didn't show up progress form
  1306. if (ProgressData.InProgress && !FProgressForm)
  1307. {
  1308. CreateProgressForm(NULL);
  1309. // When main window is hidden, synchronisation form does not exist (we do not get here during synchronization - only comparing),
  1310. // we suppose "/upload" or URL download mode
  1311. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1312. (ProgressData.Operation != foCalculateChecksum) &&
  1313. // Hack to prevent renames from DoSynchronizeMove (synchronize checklist) closing the connection
  1314. (ProgressData.Operation != foRemoteMove) &&
  1315. (FSynchronizeProgressForm == NULL) &&
  1316. !FStandaloneEditing)
  1317. {
  1318. FProgressForm->OnceDoneOperation = odoDisconnect;
  1319. }
  1320. }
  1321. // operation is finished (or terminated), so we hide progress form
  1322. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1323. {
  1324. DestroyProgressForm();
  1325. if (ProgressData.Operation == foCalculateSize)
  1326. {
  1327. // When calculating size before transfer, the abort caused by
  1328. // cancel flag set due to "MoveToQueue" below,
  1329. // is not propagated back to us in ExecuteFileOperation,
  1330. // as it is silently swallowed.
  1331. // So we explicitly (re)throw it here.
  1332. if (FMoveToQueue)
  1333. {
  1334. Abort();
  1335. }
  1336. }
  1337. else
  1338. {
  1339. if ((ProgressData.Cancel == csContinue) &&
  1340. !FAutoOperation)
  1341. {
  1342. OperationComplete(ProgressData.StartTime);
  1343. }
  1344. }
  1345. }
  1346. if (FProgressForm &&
  1347. // Can happen only during synchronization, when ending one of the operations
  1348. ProgressData.InProgress)
  1349. {
  1350. FProgressForm->SetProgressData(ProgressData);
  1351. if (FTaskbarList != NULL)
  1352. {
  1353. DebugAssert(ProgressData.InProgress);
  1354. SetTaskbarListProgressValue(&ProgressData);
  1355. }
  1356. if (FProgressForm->Cancel > csContinue)
  1357. {
  1358. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1359. if (FProgressForm->Cancel == csCancelFile)
  1360. {
  1361. FProgressForm->ClearCancel();
  1362. }
  1363. // cancel cancels even the move
  1364. FMoveToQueue = false;
  1365. }
  1366. else if (FProgressForm->MoveToQueue)
  1367. {
  1368. FMoveToQueue = true;
  1369. ProgressData.SetCancelAtLeast(csCancel);
  1370. }
  1371. if ((FTransferResumeList != NULL) &&
  1372. ProgressData.InProgress &&
  1373. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1374. !ProgressData.FullFileName.IsEmpty())
  1375. {
  1376. if ((FTransferResumeList->Count == 0) ||
  1377. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1378. {
  1379. // note that we do not recognize directories from files here
  1380. FTransferResumeList->Add(ProgressData.FullFileName);
  1381. }
  1382. }
  1383. }
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1387. const TDateTime & StartTime)
  1388. {
  1389. if (GUIConfiguration->BeepOnFinish &&
  1390. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1391. {
  1392. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1393. DWORD Sound;
  1394. if (!ExtractFileExt(BeepSound).IsEmpty())
  1395. {
  1396. Sound = SND_FILENAME;
  1397. }
  1398. else
  1399. {
  1400. Sound = SND_ALIAS;
  1401. }
  1402. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1403. }
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1407. TFileOperationProgressType & ProgressData)
  1408. {
  1409. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1410. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1411. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1412. FileOperationProgress(ProgressData);
  1413. }
  1414. //---------------------------------------------------------------------------
  1415. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1416. {
  1417. UnicodeString Result;
  1418. if (FProgressForm != NULL)
  1419. {
  1420. Result = FProgressForm->ProgressStr();
  1421. }
  1422. return Result;
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1426. bool DragDrop)
  1427. {
  1428. return (!DragDrop && (DropSourceControl == NULL)) ||
  1429. (DropSourceControl == RemoteDirView);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1433. TFileOperation Operation, TOperationSide Side,
  1434. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1435. TOnceDoneOperation & OnceDoneOperation)
  1436. {
  1437. if (!FAutoOperation)
  1438. {
  1439. // no selection on "/upload", form servers only as event handler
  1440. // (it is not displayed)
  1441. if (PanelOperation(Side, FDragDropOperation) &&
  1442. Visible && (Operation != foCalculateSize) &&
  1443. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1444. {
  1445. if (FOnFileOperationFinished != NULL)
  1446. {
  1447. FOnFileOperationFinished(FileName, Success);
  1448. }
  1449. else
  1450. {
  1451. TCustomDirView * DView = DirView(Side);
  1452. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1453. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1454. // this can happen when local drive is unplugged in the middle of the operation
  1455. if (Item != NULL)
  1456. {
  1457. if (Success) Item->Selected = false;
  1458. DView->MakeProgressVisible(Item);
  1459. }
  1460. }
  1461. }
  1462. if ((Operation == foCopy) || (Operation == foMove))
  1463. {
  1464. if (Side == osLocal)
  1465. {
  1466. Configuration->Usage->Inc(L"UploadedFiles");
  1467. }
  1468. else
  1469. {
  1470. Configuration->Usage->Inc(L"DownloadedFiles");
  1471. }
  1472. }
  1473. }
  1474. if (Success && (FSynchronizeController != NULL))
  1475. {
  1476. if (Operation == foCopy)
  1477. {
  1478. DebugAssert(Side == osLocal);
  1479. FSynchronizeController->LogOperation(soUpload, FileName);
  1480. }
  1481. else if (Operation == foDelete)
  1482. {
  1483. DebugAssert(Side == osRemote);
  1484. FSynchronizeController->LogOperation(soDelete, FileName);
  1485. }
  1486. }
  1487. if (FProgressForm)
  1488. {
  1489. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1490. }
  1491. }
  1492. //---------------------------------------------------------------------------
  1493. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1494. TFileOperation Operation, TOperationSide Side,
  1495. bool Temp, const UnicodeString & FileName, Boolean Success,
  1496. TOnceDoneOperation & OnceDoneOperation)
  1497. {
  1498. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1499. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1500. OnceDoneOperation);
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1504. {
  1505. DebugAssert(GetSide(Side) == osRemote);
  1506. DebugUsedParam(Side);
  1507. return RemoteDirView;
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1511. {
  1512. DebugAssert(GetSide(Side) == osRemote);
  1513. DebugUsedParam(Side);
  1514. return (Terminal != NULL);
  1515. }
  1516. //---------------------------------------------------------------------------
  1517. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1518. TOperationSide Side, int FilesOnly)
  1519. {
  1520. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1521. }
  1522. //---------------------------------------------------------------------------
  1523. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1524. TOperationSide Side, int FilesOnly)
  1525. {
  1526. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. struct THistoryItemData
  1530. {
  1531. short int Side;
  1532. short int Index;
  1533. };
  1534. //---------------------------------------------------------------------------
  1535. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1536. {
  1537. DirView(Side)->HistoryGo(Index);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1541. {
  1542. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1543. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1544. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1548. bool Back)
  1549. {
  1550. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1551. {
  1552. TCustomDirView * DView = DirView(Side);
  1553. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1554. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1555. if (ICount > 10)
  1556. {
  1557. ICount = 10;
  1558. }
  1559. Menu->Items->Clear();
  1560. THistoryItemData Data;
  1561. Data.Side = Side;
  1562. for (short int i = 1; i <= ICount; i++)
  1563. {
  1564. TTBCustomItem * Item = new TTBXItem(Menu);
  1565. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1566. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1567. Item->Hint = DView->HistoryPath[Data.Index];
  1568. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1569. Item->Tag = *reinterpret_cast<int*>(&Data);
  1570. Item->OnClick = HistoryItemClick;
  1571. Menu->Items->Add(Item);
  1572. }
  1573. }
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1577. TOperationSide Side, bool Back)
  1578. {
  1579. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1580. {
  1581. // workaround
  1582. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1583. // operator new allocates memory in Pascal code, but calls inline
  1584. // contructor in C++, leading in problems, the function does
  1585. // both in Pascal code
  1586. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1587. UpdateHistoryMenu(Side, Back);
  1588. }
  1589. return FHistoryMenu[Side == osLocal][Back];
  1590. }
  1591. //---------------------------------------------------------------------------
  1592. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1593. TCustomDirView *Sender)
  1594. {
  1595. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1596. UpdateHistoryMenu(Side, true);
  1597. UpdateHistoryMenu(Side, false);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1601. {
  1602. // remote custom commands can be executed only if the server supports shell commands
  1603. // or have secondary shell
  1604. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1608. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1609. {
  1610. int Result;
  1611. TFileCustomCommand RemoteCustomCommand;
  1612. TLocalCustomCommand LocalCustomCommand;
  1613. TFileCustomCommand * NonInteractiveCustomCommand =
  1614. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1615. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1616. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1617. if (FLAGCLEAR(Command.Params, ccLocal))
  1618. {
  1619. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1620. // custom command that does not operate with files can be executed anytime ...
  1621. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1622. {
  1623. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1624. {
  1625. // ... but do not show such command in remote file menu (TODO)
  1626. Result = AllowedState;
  1627. }
  1628. else
  1629. {
  1630. Result = -1;
  1631. }
  1632. }
  1633. else
  1634. {
  1635. if ((ListType == ccltAll) || (ListType == ccltFile))
  1636. {
  1637. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1638. }
  1639. else
  1640. {
  1641. Result = -1;
  1642. }
  1643. }
  1644. }
  1645. else
  1646. {
  1647. // custom command that does not operate with files can be executed anytime
  1648. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1649. {
  1650. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1651. }
  1652. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1653. {
  1654. if ((ListType == ccltAll) || (ListType == ccltFile))
  1655. {
  1656. // special case is "diff"-style command that can be executed over any side,
  1657. // if we have both sides
  1658. Result =
  1659. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1660. // directly (instead of EnableSelectedOperation) to pass
  1661. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1662. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1663. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1664. }
  1665. else if (ListType == ccltBoth)
  1666. {
  1667. Result = 1;
  1668. }
  1669. else
  1670. {
  1671. Result = -1;
  1672. }
  1673. }
  1674. else
  1675. {
  1676. if ((ListType == ccltAll) || (ListType == ccltFile))
  1677. {
  1678. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1679. }
  1680. else
  1681. {
  1682. Result = -1;
  1683. }
  1684. }
  1685. }
  1686. return Result;
  1687. }
  1688. //---------------------------------------------------------------------------
  1689. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1690. TStrings * FileList, const TCustomCommandType & ACommand,
  1691. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1692. {
  1693. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1694. {
  1695. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1696. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1697. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1698. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1699. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1700. bool Capture =
  1701. FLAGSET(ACommand.Params, ccShowResults) ||
  1702. FLAGSET(ACommand.Params, ccCopyResults) ||
  1703. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1704. TCaptureOutputEvent OutputEvent = NULL;
  1705. DebugAssert(FCapturedLog == NULL);
  1706. if (Capture)
  1707. {
  1708. FCapturedLog = new TStringList();
  1709. OutputEvent = TerminalCaptureLog;
  1710. }
  1711. try
  1712. {
  1713. if (!RemoteCustomCommand.IsFileCommand(Command))
  1714. {
  1715. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1716. OutputEvent);
  1717. }
  1718. else
  1719. {
  1720. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1721. }
  1722. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1723. {
  1724. if (FLAGSET(ACommand.Params, ccCopyResults))
  1725. {
  1726. CopyToClipboard(FCapturedLog);
  1727. }
  1728. if (FLAGSET(ACommand.Params, ccShowResults))
  1729. {
  1730. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1731. }
  1732. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1733. {
  1734. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1735. }
  1736. }
  1737. }
  1738. __finally
  1739. {
  1740. SAFE_DESTROY(FCapturedLog);
  1741. }
  1742. }
  1743. }
  1744. //---------------------------------------------------------------------------
  1745. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1746. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1747. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1748. {
  1749. TStrings * LocalFileList = NULL;
  1750. TStrings * RemoteFileList = NULL;
  1751. TStrings * RemoteFileListFull = NULL;
  1752. try
  1753. {
  1754. if (LocalFileCommand)
  1755. {
  1756. if (ALocalFileList == NULL)
  1757. {
  1758. DebugAssert(HasDirView[osLocal]);
  1759. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1760. // directly (instead of EnableSelectedOperation) to pass
  1761. // false to FocusedFileOnlyWhenFocused
  1762. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1763. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1764. }
  1765. else
  1766. {
  1767. LocalFileList = ALocalFileList;
  1768. }
  1769. if (FileListCommand)
  1770. {
  1771. if (LocalFileList->Count != 1)
  1772. {
  1773. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1774. }
  1775. }
  1776. else
  1777. {
  1778. if ((LocalFileList->Count != 1) &&
  1779. (FileList->Count != 1) &&
  1780. (LocalFileList->Count != FileList->Count))
  1781. {
  1782. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1783. }
  1784. }
  1785. }
  1786. UnicodeString RootTempDir;
  1787. UnicodeString TempDir;
  1788. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1789. if (!RemoteFiles)
  1790. {
  1791. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1792. }
  1793. try
  1794. {
  1795. TDateTimes RemoteFileTimes;
  1796. if (RemoteFiles)
  1797. {
  1798. RemoteFileList = FileList;
  1799. }
  1800. else
  1801. {
  1802. RemoteFileList = new TStringList();
  1803. TMakeLocalFileListParams MakeFileListParam;
  1804. MakeFileListParam.FileList = RemoteFileList;
  1805. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1806. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1807. MakeFileListParam.Recursive =
  1808. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1809. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1810. if (!MakeFileListParam.Recursive)
  1811. {
  1812. RemoteFileTimes.clear();
  1813. RemoteFileListFull = new TStringList();
  1814. MakeFileListParam.FileList = RemoteFileListFull;
  1815. MakeFileListParam.Recursive = true;
  1816. MakeFileListParam.IncludeDirs = false;
  1817. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1818. }
  1819. else
  1820. {
  1821. RemoteFileListFull = RemoteFileList;
  1822. }
  1823. }
  1824. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1825. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1826. if (!NonBlocking)
  1827. {
  1828. int Count;
  1829. if (FileListCommand)
  1830. {
  1831. Count = 1;
  1832. }
  1833. else if (LocalFileCommand)
  1834. {
  1835. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1836. }
  1837. else
  1838. {
  1839. Count = RemoteFileList->Count;
  1840. }
  1841. Progress.Start(foCustomCommand, osRemote, Count);
  1842. DebugAssert(FProgressForm != NULL);
  1843. FProgressForm->ReadOnly = true;
  1844. }
  1845. try
  1846. {
  1847. if (FileListCommand)
  1848. {
  1849. UnicodeString LocalFile;
  1850. // MakeFileList does not delimit filenames
  1851. UnicodeString FileList = MakeFileList(RemoteFileList);
  1852. if (LocalFileCommand)
  1853. {
  1854. DebugAssert(LocalFileList->Count == 1);
  1855. LocalFile = LocalFileList->Strings[0];
  1856. }
  1857. TLocalCustomCommand CustomCommand(Data,
  1858. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1859. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1860. if (NonBlocking)
  1861. {
  1862. DebugAssert(!POutput);
  1863. ExecuteShellChecked(ShellCommand);
  1864. }
  1865. else
  1866. {
  1867. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1868. }
  1869. }
  1870. else if (LocalFileCommand)
  1871. {
  1872. if (LocalFileList->Count == 1)
  1873. {
  1874. UnicodeString LocalFile = LocalFileList->Strings[0];
  1875. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1876. {
  1877. UnicodeString FileName = RemoteFileList->Strings[Index];
  1878. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1879. Progress.SetFile(FileNameForProgress);
  1880. TLocalCustomCommand CustomCommand(Data,
  1881. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1882. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1883. TOnceDoneOperation OnceDoneOperation;
  1884. // Do not unselect anything, as it won't work with two panels anyway
  1885. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1886. }
  1887. }
  1888. else if (RemoteFileList->Count == 1)
  1889. {
  1890. UnicodeString FileName = RemoteFileList->Strings[0];
  1891. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1892. {
  1893. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1894. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1895. Progress.SetFile(LocalFileNameOnly);
  1896. TLocalCustomCommand CustomCommand(
  1897. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1898. FileName, LocalFileName, L"");
  1899. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1900. TOnceDoneOperation OnceDoneOperation;
  1901. // Do not unselect anything, as it won't work with two panels anyway
  1902. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1903. }
  1904. }
  1905. else
  1906. {
  1907. if (LocalFileList->Count != RemoteFileList->Count)
  1908. {
  1909. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1910. }
  1911. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1912. {
  1913. UnicodeString FileName = RemoteFileList->Strings[Index];
  1914. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1915. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1916. Progress.SetFile(LocalFileNameOnly); // sic
  1917. TLocalCustomCommand CustomCommand(
  1918. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1919. FileName, LocalFileName, L"");
  1920. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1921. TOnceDoneOperation OnceDoneOperation;
  1922. // Do not unselect anything, as it won't work with two panels anyway
  1923. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1924. }
  1925. }
  1926. }
  1927. else
  1928. {
  1929. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1930. {
  1931. UnicodeString FileName = RemoteFileList->Strings[Index];
  1932. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1933. Progress.SetFile(FileNameForProgress);
  1934. TLocalCustomCommand CustomCommand(Data,
  1935. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1936. FileName, L"", L"");
  1937. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1938. TOnceDoneOperation OnceDoneOperation;
  1939. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  1940. }
  1941. }
  1942. }
  1943. __finally
  1944. {
  1945. if (!NonBlocking)
  1946. {
  1947. Progress.Stop();
  1948. }
  1949. }
  1950. DebugAssert(!FAutoOperation);
  1951. if (!RemoteFiles)
  1952. {
  1953. TempDir = IncludeTrailingBackslash(TempDir);
  1954. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  1955. {
  1956. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  1957. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1958. // Skip directories, process only nested files.
  1959. // The check is redundant as FileAge fails for directories anyway.
  1960. !DirectoryExists(FileName))
  1961. {
  1962. UnicodeString RemoteDir =
  1963. UnixExtractFileDir(
  1964. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1965. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1966. TDateTime NewTime;
  1967. if (FileAge(FileName, NewTime) &&
  1968. (NewTime != RemoteFileTimes[Index]))
  1969. {
  1970. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1971. TemporaryFileCopyParam(CopyParam);
  1972. CopyParam.FileMask = L"";
  1973. FAutoOperation = true;
  1974. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1975. TemporaryFilesList->Add(FileName);
  1976. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. __finally
  1983. {
  1984. FAutoOperation = false;
  1985. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  1986. {
  1987. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  1988. }
  1989. }
  1990. }
  1991. __finally
  1992. {
  1993. if (RemoteFileList != FileList)
  1994. {
  1995. delete RemoteFileList;
  1996. }
  1997. if (LocalFileList != ALocalFileList)
  1998. {
  1999. delete LocalFileList;
  2000. }
  2001. if (RemoteFileListFull != RemoteFileList)
  2002. {
  2003. delete RemoteFileListFull;
  2004. }
  2005. }
  2006. }
  2007. //---------------------------------------------------------------------------
  2008. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2009. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2010. bool FileListCommand, UnicodeString * POutput)
  2011. {
  2012. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2013. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2014. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2015. {
  2016. UnicodeString FileName = SelectedFileList->Strings[Index];
  2017. if (DirectoryExists(FileName))
  2018. {
  2019. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2020. {
  2021. LocalFileList->Add(FileName);
  2022. }
  2023. if (FLAGSET(ACommand.Params, ccRecursive))
  2024. {
  2025. TMakeLocalFileListParams MakeFileListParam;
  2026. MakeFileListParam.FileList = LocalFileList.get();
  2027. MakeFileListParam.FileTimes = NULL;
  2028. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2029. MakeFileListParam.Recursive = true;
  2030. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2031. }
  2032. }
  2033. else
  2034. {
  2035. LocalFileList->Add(FileName);
  2036. }
  2037. }
  2038. UnicodeString RemotePath;
  2039. if (Terminal != NULL)
  2040. {
  2041. RemotePath = Terminal->CurrentDirectory;
  2042. }
  2043. if (FileListCommand)
  2044. {
  2045. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2046. TLocalCustomCommand CustomCommand(
  2047. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2048. L"", L"", FileList);
  2049. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2050. }
  2051. else
  2052. {
  2053. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2054. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2055. DebugAssert(FProgressForm != NULL);
  2056. FProgressForm->ReadOnly = true;
  2057. try
  2058. {
  2059. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2060. {
  2061. UnicodeString FileName = LocalFileList->Strings[Index];
  2062. Progress.SetFile(FileName);
  2063. TLocalCustomCommand CustomCommand(
  2064. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2065. FileName, L"", L"");
  2066. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2067. TOnceDoneOperation OnceDoneOperation;
  2068. Progress.Finish(FileName, true, OnceDoneOperation);
  2069. }
  2070. }
  2071. __finally
  2072. {
  2073. Progress.Stop();
  2074. }
  2075. }
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2079. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2080. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2081. {
  2082. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2083. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2084. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2085. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2086. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2087. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2088. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2089. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2090. std::unique_ptr<UnicodeString> POutput;
  2091. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2092. FLAGSET(ACommand.Params, ccCopyResults))
  2093. {
  2094. POutput.reset(new UnicodeString());
  2095. }
  2096. if (!LocalCustomCommand.IsFileCommand(Command))
  2097. {
  2098. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2099. }
  2100. // remote files?
  2101. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2102. {
  2103. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2104. }
  2105. // local files
  2106. else
  2107. {
  2108. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2109. }
  2110. if (POutput.get() != NULL)
  2111. {
  2112. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2113. int P = POutput->Pos(sLineBreak);
  2114. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2115. {
  2116. POutput->SetLength(P - 1);
  2117. }
  2118. // Copy even empty output to clipboard
  2119. if (FLAGSET(ACommand.Params, ccCopyResults))
  2120. {
  2121. CopyToClipboard(*POutput);
  2122. }
  2123. // But do not show an empty message box.
  2124. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2125. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2126. !POutput->IsEmpty())
  2127. {
  2128. TClipboardHandler ClipboardHandler;
  2129. ClipboardHandler.Text = *POutput;
  2130. TMessageParams Params;
  2131. TQueryButtonAlias Aliases[1];
  2132. Aliases[0].Button = qaRetry;
  2133. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2134. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2135. Params.Aliases = Aliases;
  2136. Params.AliasesCount = LENOF(Aliases);
  2137. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2138. }
  2139. }
  2140. }
  2141. //---------------------------------------------------------------------------
  2142. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2143. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2144. {
  2145. TCustomCommandData Data;
  2146. UnicodeString Site;
  2147. UnicodeString RemotePath;
  2148. if (Terminal != NULL)
  2149. {
  2150. Data = TCustomCommandData(Terminal);
  2151. Site = Terminal->SessionData->SessionKey;
  2152. RemotePath = Terminal->CurrentDirectory;
  2153. }
  2154. UnicodeString HelpKeyword = ACommand.HomePage;
  2155. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2156. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2157. {
  2158. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2159. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2160. {
  2161. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2162. }
  2163. else
  2164. {
  2165. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2166. }
  2167. if (!DoCustomCommandOptionsDialog(
  2168. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2169. {
  2170. Abort();
  2171. }
  2172. }
  2173. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2174. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2175. {
  2176. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2177. }
  2178. else
  2179. {
  2180. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2181. }
  2182. }
  2183. //---------------------------------------------------------------------------
  2184. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2185. const TCustomCommandType & Command)
  2186. {
  2187. DebugAssert(FCustomCommandLocalFileList != NULL);
  2188. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2189. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2190. TStrings * LocalFileList = new TStringList();
  2191. TStrings * RemoteFileList = new TStringList();
  2192. try
  2193. {
  2194. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2195. {
  2196. LocalFileList->Clear();
  2197. LocalFileList->AddObject(
  2198. FCustomCommandLocalFileList->Strings[Index],
  2199. FCustomCommandLocalFileList->Objects[Index]);
  2200. RemoteFileList->Clear();
  2201. RemoteFileList->AddObject(
  2202. FCustomCommandRemoteFileList->Strings[Index],
  2203. FCustomCommandRemoteFileList->Objects[Index]);
  2204. CustomCommand(RemoteFileList, Command, LocalFileList);
  2205. }
  2206. }
  2207. __finally
  2208. {
  2209. delete LocalFileList;
  2210. delete RemoteFileList;
  2211. }
  2212. }
  2213. //---------------------------------------------------------------------------
  2214. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2215. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2216. {
  2217. delete FCustomCommandLocalFileList;
  2218. delete FCustomCommandRemoteFileList;
  2219. // takeover ownership,
  2220. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2221. FCustomCommandLocalFileList = LocalFileList;
  2222. FCustomCommandRemoteFileList = RemoteFileList;
  2223. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2224. if (Button != NULL)
  2225. {
  2226. FCustomCommandMenu->Items->Clear();
  2227. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  2228. MenuPopup(FCustomCommandMenu, Button);
  2229. }
  2230. else
  2231. {
  2232. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2233. }
  2234. }
  2235. //---------------------------------------------------------------------------
  2236. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2237. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2238. {
  2239. DebugAssert(FCapturedLog != NULL);
  2240. if ((OutputType == cotOutput) || (OutputType == cotError))
  2241. {
  2242. FCapturedLog->Add(AddedLine);
  2243. }
  2244. }
  2245. //---------------------------------------------------------------------------
  2246. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2247. TOperationSide Side)
  2248. {
  2249. return (Side == osRemote) &&
  2250. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2251. }
  2252. //---------------------------------------------------------------------------
  2253. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2254. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2255. {
  2256. TTBItemOptions O;
  2257. O = Item->Options;
  2258. TCustomDirView * DView = DirView(Side);
  2259. if ((DView->ItemFocused != NULL) &&
  2260. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2261. // when resolving links is disabled, default action is to enter the directory,
  2262. // no matter what DoubleClickAction is configured to
  2263. ((Side != osRemote) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2264. // Can only Edit files, but can Open/Copy even directories
  2265. ((DoubleClickAction != dcaEdit) ||
  2266. !DView->ItemIsDirectory(DView->ItemFocused)))
  2267. {
  2268. Item->Options = O << tboDefault;
  2269. }
  2270. else
  2271. {
  2272. Item->Options = O >> tboDefault;
  2273. }
  2274. }
  2275. //---------------------------------------------------------------------------
  2276. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2277. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2278. {
  2279. TCustomDirView * DView = DirView(Side);
  2280. TListItem * Item = DView->ItemFocused;
  2281. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2282. EnableFocusedOperation[Side])
  2283. {
  2284. TPoint ClientPoint;
  2285. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2286. TPoint(0, 0) : MousePos;
  2287. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2288. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2289. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2290. }
  2291. }
  2292. //---------------------------------------------------------------------------
  2293. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2294. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2295. {
  2296. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2297. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2298. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2299. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2300. Handled = true;
  2301. }
  2302. //---------------------------------------------------------------------------
  2303. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2304. {
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2308. {
  2309. DebugAssert(FErrorList == NULL);
  2310. if (WinConfiguration->ContinueOnError)
  2311. {
  2312. FErrorList = new TStringList();
  2313. Configuration->Usage->Inc(L"ContinuationsOnError");
  2314. }
  2315. NonVisualDataModule->StartBusy();
  2316. }
  2317. //---------------------------------------------------------------------------
  2318. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2319. {
  2320. NonVisualDataModule->EndBusy();
  2321. if (FErrorList)
  2322. {
  2323. HandleErrorList(FErrorList);
  2324. }
  2325. }
  2326. //---------------------------------------------------------------------------
  2327. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2328. const TCopyParamType & CopyParam)
  2329. {
  2330. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2331. {
  2332. Configuration->Usage->Inc(L"FileMaskUses");
  2333. }
  2334. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2335. {
  2336. Configuration->Usage->Inc(L"OperationMaskUses");
  2337. }
  2338. }
  2339. //---------------------------------------------------------------------------
  2340. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2341. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2342. {
  2343. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2344. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2345. TTransferOperationParam DefaultParam;
  2346. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2347. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2348. switch (Param.Queue)
  2349. {
  2350. case asOn:
  2351. CopyParam.Queue = true;
  2352. break;
  2353. case asOff:
  2354. CopyParam.Queue = false;
  2355. break;
  2356. case asAuto:
  2357. default:
  2358. // keep default
  2359. break;
  2360. }
  2361. bool Result =
  2362. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2363. if (Result)
  2364. {
  2365. DebugAssert(Terminal);
  2366. bool SelectionRestored = false;
  2367. TCustomDirView * DView = NULL;
  2368. if (HasDirView[Side])
  2369. {
  2370. DView = DirView(Side);
  2371. DView->SaveSelection();
  2372. DView->SaveSelectedNames();
  2373. }
  2374. UpdateCopyParamCounters(CopyParam);
  2375. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2376. DebugAssert(FTransferResumeList == NULL);
  2377. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2378. FMoveToQueue = false;
  2379. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2380. try
  2381. {
  2382. TStrings * PermanentFileList;
  2383. std::unique_ptr<TStrings> PermanentFileListOwner;
  2384. try
  2385. {
  2386. if (Side == osLocal)
  2387. {
  2388. PermanentFileList = FileList;
  2389. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2390. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2391. if (Operation == foMove)
  2392. {
  2393. ReloadLocalDirectory();
  2394. if (DView != NULL)
  2395. {
  2396. DView->RestoreSelection();
  2397. }
  2398. SelectionRestored = true;
  2399. }
  2400. }
  2401. else
  2402. {
  2403. // Clone the file list as it may refer to current directory files,
  2404. // which get destroyed, when the source directory is reloaded after foMove operation.
  2405. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2406. // But for a hotfix, we are not going to do such a big change.
  2407. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2408. PermanentFileList = PermanentFileListOwner.get();
  2409. try
  2410. {
  2411. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2412. }
  2413. __finally
  2414. {
  2415. if (Operation == foMove)
  2416. {
  2417. if (DView != NULL)
  2418. {
  2419. DView->RestoreSelection();
  2420. }
  2421. SelectionRestored = true;
  2422. }
  2423. ReloadLocalDirectory(Param.TargetDirectory);
  2424. }
  2425. }
  2426. }
  2427. catch (EAbort &)
  2428. {
  2429. if (FMoveToQueue)
  2430. {
  2431. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2432. DebugAssert(CopyParam.TransferSkipList == NULL);
  2433. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2434. if (TransferResumeList->Count > 0)
  2435. {
  2436. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2437. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2438. }
  2439. CopyParam.TransferSkipList = TransferResumeList.release();
  2440. // not really needed, just to keep it consistent with TransferResumeList
  2441. FTransferResumeList = NULL;
  2442. FMoveToQueue = false;
  2443. Configuration->Usage->Inc("MovesToBackground");
  2444. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2445. ClearTransferSourceSelection(Direction);
  2446. }
  2447. throw;
  2448. }
  2449. }
  2450. __finally
  2451. {
  2452. if (!SelectionRestored && (DView != NULL))
  2453. {
  2454. DView->DiscardSavedSelection();
  2455. }
  2456. FTransferResumeList = NULL;
  2457. }
  2458. }
  2459. return Result;
  2460. }
  2461. //---------------------------------------------------------------------------
  2462. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2463. TOperationSide Side, TStrings * FileList, void * Param)
  2464. {
  2465. DebugAssert(FileList->Count);
  2466. // We deliberately do not toggle alternative flag (Param), but use OR,
  2467. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2468. // shortcut of CurrentDeleteAlternativeAction
  2469. bool Alternative =
  2470. bool(Param) || UseAlternativeFunction();
  2471. bool Recycle;
  2472. if (Side == osLocal)
  2473. {
  2474. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2475. }
  2476. else
  2477. {
  2478. Recycle =
  2479. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2480. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2481. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2482. }
  2483. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2484. if (!Result)
  2485. {
  2486. UnicodeString Query;
  2487. if (FileList->Count == 1)
  2488. {
  2489. if (Side == osLocal)
  2490. {
  2491. Query = ExtractFileName(FileList->Strings[0]);
  2492. }
  2493. else
  2494. {
  2495. Query = UnixExtractFileName(FileList->Strings[0]);
  2496. }
  2497. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2498. }
  2499. else
  2500. {
  2501. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2502. }
  2503. TMessageParams Params(mpNeverAskAgainCheck);
  2504. Params.ImageName = L"Delete file";
  2505. unsigned int Answer =
  2506. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2507. if (Answer == qaNeverAskAgain)
  2508. {
  2509. Result = true;
  2510. if (Recycle)
  2511. {
  2512. WinConfiguration->ConfirmRecycling = false;
  2513. }
  2514. else
  2515. {
  2516. WinConfiguration->ConfirmDeleting = false;
  2517. }
  2518. }
  2519. else
  2520. {
  2521. Result = (Answer == qaOK);
  2522. }
  2523. }
  2524. if (Result)
  2525. {
  2526. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2527. }
  2528. return Result;
  2529. }
  2530. //---------------------------------------------------------------------------
  2531. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2532. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2533. {
  2534. TAutoBatch AutoBatch(this);
  2535. bool Result;
  2536. if ((Operation == foCopy) || (Operation == foMove))
  2537. {
  2538. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2539. }
  2540. else if (Operation == foRename)
  2541. {
  2542. DebugAssert(DirView(Side)->ItemFocused);
  2543. DirView(Side)->ItemFocused->EditCaption();
  2544. Result = true;
  2545. }
  2546. else if (Operation == foDelete)
  2547. {
  2548. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2549. }
  2550. else if (Operation == foSetProperties)
  2551. {
  2552. RemoteDirView->SaveSelectedNames();
  2553. Result = SetProperties(Side, FileList);
  2554. }
  2555. else if (Operation == foCustomCommand)
  2556. {
  2557. DebugAssert(Param);
  2558. DebugAssert(Side == osRemote);
  2559. RemoteDirView->SaveSelectedNames();
  2560. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2561. CustomCommand(FileList, *Command, NULL);
  2562. Result = true;
  2563. }
  2564. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2565. {
  2566. DebugAssert(Side == osRemote);
  2567. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2568. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2569. }
  2570. else if (Operation == foLock)
  2571. {
  2572. DebugAssert(Side == osRemote);
  2573. LockFiles(FileList, true);
  2574. Result = true;
  2575. }
  2576. else if (Operation == foUnlock)
  2577. {
  2578. DebugAssert(Side == osRemote);
  2579. LockFiles(FileList, false);
  2580. Result = true;
  2581. }
  2582. else
  2583. {
  2584. DebugFail();
  2585. }
  2586. return Result;
  2587. }
  2588. //---------------------------------------------------------------------------
  2589. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2590. {
  2591. if (Side == osCurrent)
  2592. {
  2593. Side = FCurrentSide;
  2594. }
  2595. return Side;
  2596. }
  2597. //---------------------------------------------------------------------------
  2598. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2599. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2600. {
  2601. Side = GetSide(Side);
  2602. bool Result;
  2603. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2604. try
  2605. {
  2606. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2607. }
  2608. __finally
  2609. {
  2610. delete FileList;
  2611. }
  2612. return Result;
  2613. }
  2614. //---------------------------------------------------------------------------
  2615. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2616. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2617. bool NoConfirmation, void * Param)
  2618. {
  2619. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2620. {
  2621. if ((Operation == foCopy) || (Operation == foMove))
  2622. {
  2623. if (GetSide(Side) == osLocal)
  2624. {
  2625. Configuration->Usage->Inc(L"UploadsCommand");
  2626. }
  2627. else
  2628. {
  2629. Configuration->Usage->Inc(L"DownloadsCommand");
  2630. }
  2631. }
  2632. }
  2633. }
  2634. //---------------------------------------------------------------------------
  2635. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2636. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2637. {
  2638. TTransferOperationParam Param;
  2639. if ((WinConfiguration->Interface != ifCommander) ||
  2640. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2641. {
  2642. Flags &= ~cocShortCutHint;
  2643. }
  2644. TCustomDirView * DView = DirView(Side);
  2645. Param.Options =
  2646. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2647. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2648. if (FLAGSET(Flags, cocQueue))
  2649. {
  2650. Param.Queue = asOn;
  2651. }
  2652. else if (FLAGSET(Flags, cocNonQueue))
  2653. {
  2654. Param.Queue = asOff;
  2655. }
  2656. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2657. }
  2658. //---------------------------------------------------------------------------
  2659. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2660. {
  2661. try
  2662. {
  2663. if (ErrorList->Count)
  2664. {
  2665. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2666. if (MessageDialog(Message, qtError,
  2667. qaOK | qaCancel, HELP_NONE) == qaOK)
  2668. {
  2669. unsigned int Answer;
  2670. int Index = 0;
  2671. do
  2672. {
  2673. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2674. TQueryButtonAlias Aliases[2];
  2675. Aliases[0].Button = qaYes;
  2676. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2677. Aliases[1].Button = qaNo;
  2678. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2679. TMessageParams Params;
  2680. Params.Aliases = Aliases;
  2681. Params.AliasesCount = LENOF(Aliases);
  2682. Answer = MoreMessageDialog(
  2683. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2684. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2685. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2686. qaOK, HELP_NONE, &Params);
  2687. if (Answer == qaNo)
  2688. {
  2689. Index++;
  2690. }
  2691. if (Answer == qaYes)
  2692. {
  2693. Index--;
  2694. }
  2695. }
  2696. while (Answer != qaOK);
  2697. }
  2698. }
  2699. }
  2700. __finally
  2701. {
  2702. TStrings * List = ErrorList;
  2703. ErrorList = NULL;
  2704. for (int i = 0; i < List->Count; i++)
  2705. {
  2706. delete List->Objects[i];
  2707. }
  2708. delete List;
  2709. }
  2710. }
  2711. //---------------------------------------------------------------------------
  2712. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2713. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2714. {
  2715. // needed for checking filemasks, as there's no directory object
  2716. // associated with the file object
  2717. File->FullFileName = FullFileName;
  2718. TFileMasks::TParams MaskParams;
  2719. MaskParams.Size = File->Size;
  2720. MaskParams.Modification = File->Modification;
  2721. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2722. }
  2723. //---------------------------------------------------------------------------
  2724. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2725. {
  2726. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2727. Side = GetSide(Side);
  2728. TCustomDirView * DView = DirView(Side);
  2729. TListItem * FocusedItem = DView->ItemFocused;
  2730. UnicodeString Name;
  2731. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2732. {
  2733. Name = DView->ItemFileName(FocusedItem);
  2734. }
  2735. else
  2736. {
  2737. Name = LoadStr(NEW_FILE);
  2738. }
  2739. UnicodeString Names = Name;
  2740. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2741. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2742. HELP_EDIT_NEW, History.get(), true))
  2743. {
  2744. while (!Names.IsEmpty())
  2745. {
  2746. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2747. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2748. UnicodeString TargetFileName;
  2749. UnicodeString LocalFileName;
  2750. UnicodeString RootTempDir;
  2751. UnicodeString TempDir;
  2752. UnicodeString RemoteDirectory;
  2753. bool ExistingFile = false;
  2754. if (Side == osRemote)
  2755. {
  2756. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2757. TRemoteFile * File = NULL;
  2758. if (FTerminal->FileExists(Name, &File) &&
  2759. !File->IsDirectory)
  2760. {
  2761. try
  2762. {
  2763. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2764. ExistingFile = true;
  2765. }
  2766. __finally
  2767. {
  2768. delete File;
  2769. }
  2770. }
  2771. if (!ExistingFile)
  2772. {
  2773. RemoteDirectory = UnixExtractFilePath(Name);
  2774. TemporaryDirectoryForRemoteFiles(
  2775. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2776. TargetFileName = UnixExtractFileName(Name);
  2777. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2778. LocalFileName = TempDir +
  2779. // We probably do not want to trim the VMS version here
  2780. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2781. }
  2782. }
  2783. else
  2784. {
  2785. if (ExtractFilePath(Name).IsEmpty())
  2786. {
  2787. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2788. }
  2789. else
  2790. {
  2791. LocalFileName = ExpandFileName(Name);
  2792. }
  2793. TargetFileName = ExtractFileName(Name);
  2794. }
  2795. if (!ExistingFile)
  2796. {
  2797. if (!FileExists(ApiPath(LocalFileName)))
  2798. {
  2799. int File = FileCreate(ApiPath(LocalFileName));
  2800. if (File < 0)
  2801. {
  2802. if (!RootTempDir.IsEmpty())
  2803. {
  2804. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2805. }
  2806. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2807. }
  2808. else
  2809. {
  2810. FileClose(File);
  2811. }
  2812. }
  2813. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2814. const TEditorData * ExternalEditor = NULL;
  2815. TFileMasks::TParams MaskParams; // size not known
  2816. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2817. false, MaskParams);
  2818. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2819. ExternalEditor, RootTempDir, RemoteDirectory);
  2820. }
  2821. }
  2822. }
  2823. }
  2824. //---------------------------------------------------------------------------
  2825. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2826. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2827. {
  2828. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2829. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2830. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2831. return
  2832. ((ExecuteFileBy == efInternalEditor)) ||
  2833. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2834. }
  2835. //---------------------------------------------------------------------------
  2836. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2837. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2838. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2839. UnicodeString RemoteDirectory)
  2840. {
  2841. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2842. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2843. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2844. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2845. Side = GetSide(Side);
  2846. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2847. if (Side == osRemote)
  2848. {
  2849. Data->Terminal = Terminal;
  2850. Data->Queue = Queue;
  2851. Data->SessionData = CloneCurrentSessionData();
  2852. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2853. Data->RemoteDirectory = RemoteDirectory;
  2854. Data->SessionName = Terminal->SessionData->SessionName;
  2855. Data->LocalRootDirectory = LocalRootDirectory;
  2856. Data->OriginalFileName = OriginalFileName;
  2857. Data->Command = L""; // will be changed later for external editor
  2858. }
  2859. if (ExecuteFileBy == efInternalEditor)
  2860. {
  2861. if (Side == osRemote)
  2862. {
  2863. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2864. L" - " + Terminal->SessionData->SessionName;
  2865. TForm * Editor;
  2866. try
  2867. {
  2868. TNotifyEvent OnFileChanged = NULL;
  2869. TNotifyEvent OnSaveAll = NULL;
  2870. TAnyModifiedEvent OnAnyModified = NULL;
  2871. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2872. if (Terminal->IsCapable[fsBackgroundTransfers])
  2873. {
  2874. OnFileChanged = FEditorManager->FileChanged;
  2875. OnSaveAll = SaveAllInternalEditors;
  2876. OnAnyModified = AnyInternalEditorModified;
  2877. }
  2878. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2879. FEditorManager->FileReload, FEditorManager->FileClosed,
  2880. OnSaveAll, OnAnyModified,
  2881. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
  2882. }
  2883. catch(...)
  2884. {
  2885. if (!LocalRootDirectory.IsEmpty())
  2886. {
  2887. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2888. }
  2889. throw;
  2890. }
  2891. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2892. }
  2893. else
  2894. {
  2895. DebugAssert(!FStandaloneEditing);
  2896. TForm * Editor =
  2897. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2898. SaveAllInternalEditors, AnyInternalEditorModified,
  2899. L"", false, SessionColor, -1);
  2900. FLocalEditors->Add(Editor);
  2901. }
  2902. }
  2903. else
  2904. {
  2905. HANDLE Process;
  2906. if (ExecuteFileBy == efExternalEditor)
  2907. {
  2908. UnicodeString Program, Params, Dir;
  2909. Data->Command = ExternalEditor->ExternalEditor;
  2910. ReformatFileNameCommand(Data->Command);
  2911. SplitCommand(Data->Command, Program, Params, Dir);
  2912. Params = ExpandFileNameCommand(Params, FileName);
  2913. Program = ExpandEnvironmentVariables(Program);
  2914. if (!ExecuteShell(Program, Params, Process))
  2915. {
  2916. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2917. }
  2918. }
  2919. else
  2920. {
  2921. DebugAssert(Side == osRemote);
  2922. if (!ExecuteShell(FileName, L"", Process))
  2923. {
  2924. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2925. }
  2926. }
  2927. if ((Side == osLocal) ||
  2928. ((ExecuteFileBy == efShell) &&
  2929. !WinConfiguration->Editor.SDIShellEditor) ||
  2930. ((ExecuteFileBy == efExternalEditor) &&
  2931. !ExternalEditor->SDIExternalEditor))
  2932. {
  2933. // no need for handle
  2934. if (Process != NULL)
  2935. {
  2936. DebugCheck(CloseHandle(Process));
  2937. }
  2938. Process = INVALID_HANDLE_VALUE;
  2939. }
  2940. else
  2941. {
  2942. if (Process == NULL)
  2943. {
  2944. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2945. }
  2946. }
  2947. if (Side == osRemote)
  2948. {
  2949. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2950. }
  2951. }
  2952. }
  2953. //---------------------------------------------------------------------------
  2954. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2955. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2956. void * /*Arg*/)
  2957. {
  2958. if (Token != NULL)
  2959. {
  2960. EditorFormFileSave(static_cast<TForm *>(Token));
  2961. }
  2962. }
  2963. //---------------------------------------------------------------------------
  2964. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2965. {
  2966. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2967. {
  2968. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2969. }
  2970. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2971. }
  2972. //---------------------------------------------------------------------------
  2973. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2974. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2975. void * Arg)
  2976. {
  2977. if ((Token != NULL) &&
  2978. IsEditorFormModified(static_cast<TForm *>(Token)))
  2979. {
  2980. *static_cast<bool *>(Arg) = true;
  2981. }
  2982. }
  2983. //---------------------------------------------------------------------------
  2984. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2985. TObject * /*Sender*/, bool & Modified)
  2986. {
  2987. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2988. {
  2989. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2990. {
  2991. Modified = true;
  2992. }
  2993. }
  2994. if (!Modified)
  2995. {
  2996. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  2997. }
  2998. }
  2999. //---------------------------------------------------------------------------
  3000. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3001. {
  3002. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3003. }
  3004. //---------------------------------------------------------------------------
  3005. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3006. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3007. UnicodeString & Result, UnicodeString & RootDirectory)
  3008. {
  3009. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3010. {
  3011. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3012. Result = RootDirectory;
  3013. }
  3014. else
  3015. {
  3016. RootDirectory = L"";
  3017. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3018. Result = IncludeTrailingBackslash(Result);
  3019. }
  3020. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3021. {
  3022. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3023. }
  3024. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3025. {
  3026. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3027. {
  3028. RemoteDirectory.Delete(1, 1);
  3029. }
  3030. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3031. }
  3032. if (!ForceDirectories(ApiPath(Result)))
  3033. {
  3034. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3035. }
  3036. }
  3037. //---------------------------------------------------------------------------
  3038. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3039. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3040. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3041. {
  3042. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3043. if (ForceText)
  3044. {
  3045. CopyParam.TransferMode = tmAscii;
  3046. }
  3047. TemporaryFileCopyParam(CopyParam);
  3048. if (AllFiles)
  3049. {
  3050. CopyParam.IncludeFileMask = TFileMasks();
  3051. }
  3052. if (TempDir.IsEmpty())
  3053. {
  3054. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3055. }
  3056. DebugAssert(!FAutoOperation);
  3057. FAutoOperation = AutoOperation;
  3058. Terminal->ExceptionOnFail = true;
  3059. try
  3060. {
  3061. try
  3062. {
  3063. // turn off confirmations, as for MDI editors we may possibly download
  3064. // the same file over
  3065. Terminal->CopyToLocal(
  3066. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3067. if (GetTargetNames)
  3068. {
  3069. for (int i = 0; i < FileList->Count; i++)
  3070. {
  3071. FileList->Strings[i] =
  3072. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3073. }
  3074. }
  3075. }
  3076. catch(...)
  3077. {
  3078. if (!RootTempDir.IsEmpty())
  3079. {
  3080. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3081. }
  3082. throw;
  3083. }
  3084. }
  3085. __finally
  3086. {
  3087. FAutoOperation = false;
  3088. Terminal->ExceptionOnFail = false;
  3089. }
  3090. }
  3091. //---------------------------------------------------------------------------
  3092. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3093. {
  3094. // Do not waste time checking for default editor list the next time,
  3095. // or testing if default editor is not notepad.
  3096. bool TryNextTime = false;
  3097. UnicodeString UsageState;
  3098. if (!WinConfiguration->EditorList->IsDefaultList())
  3099. {
  3100. UsageState = "H";
  3101. }
  3102. else
  3103. {
  3104. UnicodeString Executable;
  3105. UnicodeString ExecutableDescription;
  3106. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3107. {
  3108. UnicodeString Message =
  3109. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3110. unsigned int Answer =
  3111. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3112. if (Answer != qaOK)
  3113. {
  3114. UsageState = "R";
  3115. }
  3116. else
  3117. {
  3118. UsageState = "A";
  3119. TEditorData EditorData;
  3120. EditorData.Editor = edExternal;
  3121. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3122. EditorData.DecideExternalEditorText();
  3123. TEditorList EditorList;
  3124. EditorList = *WinConfiguration->EditorList;
  3125. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3126. WinConfiguration->EditorList = &EditorList;
  3127. }
  3128. }
  3129. }
  3130. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3131. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3132. }
  3133. //---------------------------------------------------------------------------
  3134. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3135. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3136. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3137. {
  3138. if (ExecuteFileBy == efDefaultEditor)
  3139. {
  3140. if (!WinConfiguration->OfferedEditorAutoConfig)
  3141. {
  3142. EditorAutoConfig();
  3143. }
  3144. const TEditorPreferences * Editor =
  3145. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3146. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3147. {
  3148. ExecuteFileBy = efInternalEditor;
  3149. ExternalEditor = NULL;
  3150. }
  3151. else if (Editor->Data->Editor == edOpen)
  3152. {
  3153. ExecuteFileBy = efShell;
  3154. ExternalEditor = NULL;
  3155. }
  3156. else
  3157. {
  3158. ExecuteFileBy = efExternalEditor;
  3159. ExternalEditor = Editor->Data;
  3160. }
  3161. }
  3162. }
  3163. //---------------------------------------------------------------------------
  3164. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3165. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3166. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3167. {
  3168. UnicodeString OriginalFileName;
  3169. UnicodeString LocalRootDirectory;
  3170. UnicodeString RemoteDirectory;
  3171. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3172. (Side == osLocal), MaskParams);
  3173. UnicodeString Counter;
  3174. UnicodeString LocalFileName;
  3175. bool Handled = false;
  3176. if (Side == osRemote)
  3177. {
  3178. // We need to trim VMS version here, so that we use name without version
  3179. // when uploading back to create a new version of the file
  3180. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3181. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3182. TObject * Token = NULL;
  3183. UnicodeString LocalDirectory;
  3184. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3185. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3186. LocalDirectory))
  3187. {
  3188. if (Token != NULL)
  3189. {
  3190. TForm * Form = dynamic_cast<TForm *>(Token);
  3191. if (Form->WindowState == wsMinimized)
  3192. {
  3193. ShowWindow(Form->Handle, SW_RESTORE);
  3194. }
  3195. else
  3196. {
  3197. Form->SetFocus();
  3198. }
  3199. Handled = true;
  3200. }
  3201. else
  3202. {
  3203. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3204. }
  3205. }
  3206. if (!Handled)
  3207. {
  3208. TStringList * FileList1 = new TStringList();
  3209. try
  3210. {
  3211. FileList1->AddObject(FullFileName, Object);
  3212. TemporarilyDownloadFiles(FileList1,
  3213. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3214. LocalRootDirectory, LocalDirectory, true, true, true);
  3215. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3216. }
  3217. __finally
  3218. {
  3219. delete FileList1;
  3220. }
  3221. switch (ExecuteFileBy)
  3222. {
  3223. case efShell:
  3224. Counter = "RemoteFilesExecuted";
  3225. break;
  3226. case efInternalEditor:
  3227. Counter = "RemoteFilesOpenedInInternalEditor";
  3228. break;
  3229. case efExternalEditor:
  3230. Counter = "RemoteFilesOpenedInExternalEditor";
  3231. break;
  3232. default:
  3233. DebugFail();
  3234. }
  3235. }
  3236. }
  3237. else
  3238. {
  3239. LocalFileName = FullFileName;
  3240. OriginalFileName = ExtractFileName(FullFileName);
  3241. switch (ExecuteFileBy)
  3242. {
  3243. case efShell:
  3244. Counter = "LocalFilesExecuted";
  3245. break;
  3246. case efInternalEditor:
  3247. Counter = "LocalFilesOpenedInInternalEditor";
  3248. break;
  3249. case efExternalEditor:
  3250. Counter = "LocalFilesOpenedInExternalEditor";
  3251. break;
  3252. default:
  3253. DebugFail();
  3254. }
  3255. }
  3256. if (!Handled)
  3257. {
  3258. Configuration->Usage->Inc(Counter);
  3259. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3260. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3261. }
  3262. }
  3263. //---------------------------------------------------------------------------
  3264. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3265. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3266. bool AllSelected, bool OnFocused)
  3267. {
  3268. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3269. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3270. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3271. Side = GetSide(Side);
  3272. TCustomDirView * DView = DirView(Side);
  3273. TStrings * FileList = AllSelected ?
  3274. DView->CreateFileList(OnFocused, Side == osLocal) :
  3275. DView->CreateFocusedFileList(Side == osLocal);
  3276. try
  3277. {
  3278. DebugAssert(AllSelected || (FileList->Count == 1));
  3279. for (int i = 0; i < FileList->Count; i++)
  3280. {
  3281. UnicodeString ListFileName = FileList->Strings[i];
  3282. UnicodeString FileNameOnly = (Side == osRemote) ?
  3283. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3284. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3285. if (!DView->ItemIsDirectory(Item))
  3286. {
  3287. UnicodeString FullFileName;
  3288. if (Side == osRemote)
  3289. {
  3290. FullFileName = RemoteDirView->Path + ListFileName;
  3291. }
  3292. else
  3293. {
  3294. FullFileName = ListFileName;
  3295. }
  3296. TFileMasks::TParams MaskParams;
  3297. MaskParams.Size = DView->ItemFileSize(Item);
  3298. TDateTimePrecision Precision;
  3299. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3300. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3301. FileList->Objects[i], MaskParams);
  3302. }
  3303. }
  3304. }
  3305. __finally
  3306. {
  3307. delete FileList;
  3308. }
  3309. }
  3310. //---------------------------------------------------------------------------
  3311. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3312. {
  3313. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3314. CopyParam.FileNameCase = ncNoChange;
  3315. CopyParam.PreserveRights = false;
  3316. CopyParam.PreserveReadOnly = false;
  3317. CopyParam.ReplaceInvalidChars = true;
  3318. CopyParam.IncludeFileMask = TFileMasks();
  3319. CopyParam.NewerOnly = false;
  3320. CopyParam.FileMask = L"";
  3321. }
  3322. //---------------------------------------------------------------------------
  3323. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3324. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3325. {
  3326. TTerminalManager * Manager = TTerminalManager::Instance();
  3327. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3328. {
  3329. if (!NonVisualDataModule->Busy)
  3330. {
  3331. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3332. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3333. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3334. if (Data->Terminal == NULL)
  3335. {
  3336. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3337. if (SameSiteTerminal != NULL)
  3338. {
  3339. UnicodeString Message =
  3340. FMTLOAD(EDIT_SESSION_REATTACH,
  3341. (FileNameOnly, Data->SessionName, FileNameOnly));
  3342. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3343. {
  3344. Data->Terminal = Terminal;
  3345. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3346. Data->SessionName = Terminal->SessionData->SessionName;
  3347. // We might also overwrite session data
  3348. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3349. }
  3350. else
  3351. {
  3352. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3353. Abort();
  3354. }
  3355. }
  3356. }
  3357. // foreground session should reconnect itself
  3358. else if (Terminal != Data->Terminal)
  3359. {
  3360. UnicodeString Message =
  3361. MainInstructions(
  3362. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3363. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3364. {
  3365. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3366. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3367. }
  3368. else
  3369. {
  3370. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3371. Abort();
  3372. }
  3373. }
  3374. }
  3375. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3376. {
  3377. Configuration->Usage->Inc(L"EditInactiveSession");
  3378. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3379. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3380. (ExtractFileName(FileName), Data->SessionName)));
  3381. }
  3382. }
  3383. TStrings * FileList = new TStringList();
  3384. try
  3385. {
  3386. FileList->Add(FileName);
  3387. // consider using the same settings (preset) as when the file was downloaded
  3388. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3389. TemporaryFileCopyParam(CopyParam);
  3390. if (Data->ForceText)
  3391. {
  3392. CopyParam.TransferMode = tmAscii;
  3393. }
  3394. // so i do not need to worry if masking algorithm works in all cases
  3395. // ("" means "copy file name", no masking is actually done)
  3396. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3397. {
  3398. CopyParam.FileMask = L"";
  3399. }
  3400. else
  3401. {
  3402. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3403. }
  3404. DebugAssert(Data->Queue != NULL);
  3405. int Params = cpNoConfirmation | cpTemporary;
  3406. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3407. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3408. QueueItem->CompleteEvent = UploadCompleteEvent;
  3409. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3410. }
  3411. __finally
  3412. {
  3413. delete FileList;
  3414. }
  3415. }
  3416. //---------------------------------------------------------------------------
  3417. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3418. const UnicodeString FileName, const TEditedFileData * Data)
  3419. {
  3420. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3421. DebugAssert(!NonVisualDataModule->Busy);
  3422. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3423. {
  3424. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3425. (ExtractFileName(FileName), Data->SessionName)));
  3426. }
  3427. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3428. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3429. NonVisualDataModule->StartBusy();
  3430. try
  3431. {
  3432. std::unique_ptr<TRemoteFile> File;
  3433. UnicodeString RemoteFileName =
  3434. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3435. FTerminal->ExceptionOnFail = true;
  3436. try
  3437. {
  3438. TRemoteFile * AFile = NULL;
  3439. FTerminal->ReadFile(RemoteFileName, AFile);
  3440. File.reset(AFile);
  3441. if (!File->HaveFullFileName)
  3442. {
  3443. File->FullFileName = RemoteFileName;
  3444. }
  3445. }
  3446. __finally
  3447. {
  3448. FTerminal->ExceptionOnFail = false;
  3449. }
  3450. std::unique_ptr<TStrings> FileList(new TStringList());
  3451. FileList->AddObject(RemoteFileName, File.get());
  3452. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3453. UnicodeString TempDir = ExtractFilePath(FileName);
  3454. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3455. TempDir, true, true, true);
  3456. // sanity check, the target file name should be still the same
  3457. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3458. }
  3459. __finally
  3460. {
  3461. NonVisualDataModule->EndBusy();
  3462. // it actually may not exist anymore...
  3463. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3464. }
  3465. }
  3466. //---------------------------------------------------------------------------
  3467. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3468. const TEditedFileData * Data, bool & KeepOpen)
  3469. {
  3470. // Command is set for external editors only (not for "shell" open).
  3471. if (!Data->Command.IsEmpty())
  3472. {
  3473. bool AnyFound = false;
  3474. bool AnyMDI = false;
  3475. bool AnyNonMDI = false;
  3476. bool AnyDetect = false;
  3477. TEditorList * EditorList = new TEditorList();
  3478. try
  3479. {
  3480. *EditorList = *WinConfiguration->EditorList;
  3481. for (int i = 0; i < EditorList->Count; i++)
  3482. {
  3483. const TEditorPreferences * Editor = EditorList->Editors[i];
  3484. if ((Editor->Data->Editor == edExternal) &&
  3485. (Editor->Data->ExternalEditor == Data->Command))
  3486. {
  3487. AnyFound = true;
  3488. if (Editor->Data->SDIExternalEditor)
  3489. {
  3490. AnyNonMDI = true;
  3491. if (Editor->Data->DetectMDIExternalEditor)
  3492. {
  3493. AnyDetect = true;
  3494. }
  3495. }
  3496. else
  3497. {
  3498. AnyMDI = true;
  3499. }
  3500. }
  3501. }
  3502. bool EnableMDI = false;
  3503. bool DisableDetect = false;
  3504. if (AnyMDI)
  3505. {
  3506. KeepOpen = true;
  3507. if (AnyNonMDI)
  3508. {
  3509. // there is at least one instance of the editor with MDI support enabled,
  3510. // and one with disabled, enable it for all instances
  3511. EnableMDI = true;
  3512. }
  3513. }
  3514. else if (AnyFound && !AnyDetect)
  3515. {
  3516. // at least once instance found but all have MDI autodetection disabled
  3517. // => close the file (default action)
  3518. }
  3519. else
  3520. {
  3521. // no instance of the editor has MDI support enabled
  3522. TMessageParams Params;
  3523. if (AnyFound)
  3524. {
  3525. // there is at least one instance of the editor
  3526. Params.Params |= mpNeverAskAgainCheck;
  3527. }
  3528. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3529. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3530. switch (Answer)
  3531. {
  3532. case qaNeverAskAgain:
  3533. DisableDetect = true;
  3534. break;
  3535. case qaNo:
  3536. EnableMDI = true;
  3537. KeepOpen = true;
  3538. break;
  3539. }
  3540. }
  3541. if (AnyFound && (EnableMDI || DisableDetect))
  3542. {
  3543. bool Changed = false;
  3544. for (int i = 0; i < EditorList->Count; i++)
  3545. {
  3546. const TEditorPreferences * Editor = EditorList->Editors[i];
  3547. if ((Editor->Data->Editor == edExternal) &&
  3548. (Editor->Data->ExternalEditor == Data->Command) &&
  3549. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3550. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3551. {
  3552. Changed = true;
  3553. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3554. if (EnableMDI)
  3555. {
  3556. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3557. }
  3558. if (DisableDetect)
  3559. {
  3560. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3561. }
  3562. EditorList->Change(i, UpdatedEditor);
  3563. }
  3564. }
  3565. if (Changed)
  3566. {
  3567. WinConfiguration->EditorList = EditorList;
  3568. }
  3569. }
  3570. }
  3571. __finally
  3572. {
  3573. delete EditorList;
  3574. }
  3575. }
  3576. else
  3577. {
  3578. // "open" case
  3579. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3580. qaOK, HELP_APP_EARLY_CLOSED);
  3581. }
  3582. }
  3583. //---------------------------------------------------------------------------
  3584. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3585. {
  3586. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3587. }
  3588. //---------------------------------------------------------------------------
  3589. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3590. {
  3591. SideEnter(osRemote);
  3592. }
  3593. //---------------------------------------------------------------------------
  3594. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3595. {
  3596. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3597. SideEnter(osRemote);
  3598. }
  3599. //---------------------------------------------------------------------------
  3600. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3601. {
  3602. FCurrentSide = Side;
  3603. if (Visible)
  3604. {
  3605. UpdateControls();
  3606. }
  3607. }
  3608. //---------------------------------------------------------------------------
  3609. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3610. TStrings * FileList, bool Alternative)
  3611. {
  3612. TCustomDirView * DView = DirView(Side);
  3613. DView->SaveSelection();
  3614. DView->SaveSelectedNames();
  3615. DebugAssert(!FAlternativeDelete);
  3616. FAlternativeDelete = Alternative;
  3617. try
  3618. {
  3619. if (Side == osRemote)
  3620. {
  3621. DebugAssert(Terminal != NULL);
  3622. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3623. }
  3624. else
  3625. {
  3626. try
  3627. {
  3628. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3629. }
  3630. __finally
  3631. {
  3632. ReloadLocalDirectory();
  3633. }
  3634. }
  3635. FAlternativeDelete = false;
  3636. }
  3637. catch(...)
  3638. {
  3639. FAlternativeDelete = false;
  3640. DView->DiscardSavedSelection();
  3641. throw;
  3642. }
  3643. DView->RestoreSelection();
  3644. }
  3645. //---------------------------------------------------------------------------
  3646. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3647. {
  3648. DebugAssert(Terminal);
  3649. RemoteDirView->SaveSelection();
  3650. RemoteDirView->SaveSelectedNames();
  3651. try
  3652. {
  3653. if (Lock)
  3654. {
  3655. Terminal->LockFiles(FileList);
  3656. }
  3657. else
  3658. {
  3659. Terminal->UnlockFiles(FileList);
  3660. }
  3661. }
  3662. catch(...)
  3663. {
  3664. RemoteDirView->DiscardSavedSelection();
  3665. throw;
  3666. }
  3667. RemoteDirView->RestoreSelection();
  3668. }
  3669. //---------------------------------------------------------------------------
  3670. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3671. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3672. bool NoConfirmation, bool Move)
  3673. {
  3674. DebugAssert(Terminal != NULL);
  3675. // update Terminal->StateData->RemoteDirectory
  3676. UpdateTerminal(Terminal);
  3677. if (Session == NULL)
  3678. {
  3679. Session = TTerminalManager::Instance()->ActiveTerminal;
  3680. }
  3681. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3682. {
  3683. if (RemoteDriveView->DropTarget != NULL)
  3684. {
  3685. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3686. }
  3687. else if (RemoteDirView->DropTarget != NULL)
  3688. {
  3689. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3690. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3691. }
  3692. else
  3693. {
  3694. Target = RemoteDirView->Path;
  3695. }
  3696. }
  3697. else
  3698. {
  3699. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Session));
  3700. Target = ManagedTerminal->StateData->RemoteDirectory;
  3701. }
  3702. Target = UnixIncludeTrailingBackslash(Target);
  3703. if (FileList->Count == 1)
  3704. {
  3705. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3706. }
  3707. else
  3708. {
  3709. FileMask = AnyMask;
  3710. }
  3711. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3712. bool Result = true;
  3713. if (!NoConfirmation)
  3714. {
  3715. bool Multi = (FileList->Count > 1);
  3716. if (Move)
  3717. {
  3718. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3719. }
  3720. else
  3721. {
  3722. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3723. TStrings * Directories = new TStringList;
  3724. try
  3725. {
  3726. for (int Index = 0; Index < Sessions->Count; Index++)
  3727. {
  3728. TManagedTerminal * Terminal =
  3729. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3730. Directories->Add(Terminal->StateData->RemoteDirectory);
  3731. }
  3732. TDirectRemoteCopy AllowDirectCopy;
  3733. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3734. {
  3735. DebugAssert(DirectCopy);
  3736. AllowDirectCopy = drcAllow;
  3737. }
  3738. else if (FTerminal->IsCapable[fcSecondaryShell])
  3739. {
  3740. DebugAssert(DirectCopy);
  3741. AllowDirectCopy = drcConfirmCommandSession;
  3742. }
  3743. else
  3744. {
  3745. DebugAssert(!DirectCopy);
  3746. AllowDirectCopy = drcDisallow;
  3747. }
  3748. void * ASession = Session;
  3749. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3750. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3751. Session = static_cast<TTerminal *>(ASession);
  3752. }
  3753. __finally
  3754. {
  3755. delete Directories;
  3756. }
  3757. }
  3758. }
  3759. return Result;
  3760. }
  3761. //---------------------------------------------------------------------------
  3762. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3763. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3764. {
  3765. bool DirectCopy;
  3766. UnicodeString Target, FileMask;
  3767. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3768. if (Result)
  3769. {
  3770. if (!Move && !DirectCopy)
  3771. {
  3772. Configuration->Usage->Inc("RemoteCopyTemp");
  3773. UnicodeString RootTempDir;
  3774. UnicodeString TempDir;
  3775. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3776. TStrings * TemporaryFilesList = new TStringList();
  3777. try
  3778. {
  3779. TMakeLocalFileListParams MakeFileListParam;
  3780. MakeFileListParam.FileList = TemporaryFilesList;
  3781. MakeFileListParam.FileTimes = NULL;
  3782. MakeFileListParam.IncludeDirs = true;
  3783. MakeFileListParam.Recursive = false;
  3784. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3785. TTerminalManager::Instance()->ActiveTerminal = Session;
  3786. if (TemporaryFilesList->Count > 0)
  3787. {
  3788. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3789. CopyParam.FileMask = FileMask;
  3790. DebugAssert(!FAutoOperation);
  3791. FAutoOperation = true;
  3792. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3793. }
  3794. }
  3795. __finally
  3796. {
  3797. delete TemporaryFilesList;
  3798. FAutoOperation = false;
  3799. if (!RootTempDir.IsEmpty())
  3800. {
  3801. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3802. }
  3803. }
  3804. }
  3805. else
  3806. {
  3807. RemoteDirView->SaveSelection();
  3808. RemoteDirView->SaveSelectedNames();
  3809. try
  3810. {
  3811. if (Move)
  3812. {
  3813. Configuration->Usage->Inc("RemoteMove");
  3814. Terminal->MoveFiles(FileList, Target, FileMask);
  3815. }
  3816. else
  3817. {
  3818. Configuration->Usage->Inc("RemoteCopyDirect");
  3819. DebugAssert(DirectCopy);
  3820. DebugAssert(Session == FTerminal);
  3821. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3822. FTerminal->CommandSessionOpened ||
  3823. CommandSessionFallback())
  3824. {
  3825. Terminal->CopyFiles(FileList, Target, FileMask);
  3826. }
  3827. }
  3828. }
  3829. catch(...)
  3830. {
  3831. RemoteDirView->DiscardSavedSelection();
  3832. throw;
  3833. }
  3834. RemoteDirView->RestoreSelection();
  3835. }
  3836. }
  3837. return Result;
  3838. }
  3839. //---------------------------------------------------------------------------
  3840. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3841. const UnicodeString & Path, TRemoteProperties & Properties)
  3842. {
  3843. Properties.Valid = Properties.Valid << vpEncrypt;
  3844. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3845. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3846. }
  3847. //---------------------------------------------------------------------------
  3848. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3849. {
  3850. Side = GetSide(Side);
  3851. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3852. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3853. UnicodeString Name = LoadStr(NEW_FOLDER);
  3854. int AllowedChanges =
  3855. FLAGMASK((Side == osRemote) && Terminal->IsCapable[fcModeChanging], cpMode);
  3856. bool SaveSettings = false;
  3857. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3858. {
  3859. TWindowLock Lock(this);
  3860. if (Side == osRemote)
  3861. {
  3862. if (SaveSettings)
  3863. {
  3864. GUIConfiguration->NewDirectoryProperties = Properties;
  3865. }
  3866. CreateRemoteDirectory(Name, Properties);
  3867. }
  3868. else
  3869. {
  3870. DirView(Side)->CreateDirectory(Name);
  3871. }
  3872. }
  3873. }
  3874. //---------------------------------------------------------------------------
  3875. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3876. {
  3877. TWindowLock Lock(this);
  3878. DirView(Side)->ExecuteHomeDirectory();
  3879. }
  3880. //---------------------------------------------------------------------------
  3881. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3882. {
  3883. DoOpenDirectoryDialog(odBrowse, Side);
  3884. }
  3885. //---------------------------------------------------------------------------
  3886. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3887. {
  3888. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3889. bool Result = !Path.IsEmpty();
  3890. if (Result)
  3891. {
  3892. // While we might get here when the session is closed (from location profiles),
  3893. // it's not a problem as the Path setter is noop then
  3894. DirView(Side)->Path = Path;
  3895. }
  3896. return Result;
  3897. }
  3898. //---------------------------------------------------------------------------
  3899. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3900. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3901. bool & Close)
  3902. {
  3903. // terminal can be already closed (e.g. dropped connection)
  3904. if (Terminal != NULL)
  3905. {
  3906. try
  3907. {
  3908. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3909. }
  3910. catch(...)
  3911. {
  3912. if (!Terminal->Active)
  3913. {
  3914. Close = true;
  3915. }
  3916. throw;
  3917. }
  3918. }
  3919. }
  3920. //---------------------------------------------------------------------------
  3921. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3922. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3923. bool & Close)
  3924. {
  3925. // terminal can be already closed (e.g. dropped connection)
  3926. if (Terminal != NULL)
  3927. {
  3928. Configuration->Usage->Inc(L"ChecksumCalculated");
  3929. try
  3930. {
  3931. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3932. }
  3933. catch(...)
  3934. {
  3935. if (!Terminal->Active)
  3936. {
  3937. Close = true;
  3938. }
  3939. throw;
  3940. }
  3941. }
  3942. }
  3943. //---------------------------------------------------------------------------
  3944. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3945. {
  3946. bool Result;
  3947. if (Side == osRemote)
  3948. {
  3949. TRemoteTokenList * GroupList = NULL;
  3950. TRemoteTokenList * UserList = NULL;
  3951. try
  3952. {
  3953. TRemoteProperties CurrentProperties;
  3954. if (Terminal->LoadFilesProperties(FileList))
  3955. {
  3956. RemoteDirView->Invalidate();
  3957. }
  3958. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3959. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3960. if (CapableGroupChanging || CapableOwnerChanging)
  3961. {
  3962. if (CapableGroupChanging)
  3963. {
  3964. GroupList = Terminal->Groups->Duplicate();
  3965. }
  3966. if (CapableOwnerChanging)
  3967. {
  3968. UserList = Terminal->Users->Duplicate();
  3969. }
  3970. TRemoteDirectory * Files = Terminal->Files;
  3971. int Count = Files->Count;
  3972. if (Count > 100)
  3973. {
  3974. Count = 100;
  3975. }
  3976. for (int Index = 0; Index < Count; Index++)
  3977. {
  3978. TRemoteFile * File = Files->Files[Index];
  3979. if (CapableGroupChanging)
  3980. {
  3981. GroupList->AddUnique(File->Group);
  3982. }
  3983. if (CapableOwnerChanging)
  3984. {
  3985. UserList->AddUnique(File->Owner);
  3986. }
  3987. }
  3988. // if we haven't collected tokens for all files in current directory,
  3989. // make sure we collect them at least for all selected files.
  3990. // (note that so far the files in FileList has to be from current direcotry)
  3991. if (Count < Files->Count)
  3992. {
  3993. for (int Index = 0; Index < FileList->Count; Index++)
  3994. {
  3995. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  3996. if (CapableGroupChanging)
  3997. {
  3998. GroupList->AddUnique(File->Group);
  3999. }
  4000. if (CapableOwnerChanging)
  4001. {
  4002. UserList->AddUnique(File->Owner);
  4003. }
  4004. }
  4005. }
  4006. }
  4007. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4008. int Flags = 0;
  4009. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4010. if (CapableOwnerChanging) Flags |= cpOwner;
  4011. if (CapableGroupChanging) Flags |= cpGroup;
  4012. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4013. if (Terminal->IsCapable[fcCalculatingChecksum])
  4014. {
  4015. CalculateChecksumEvent = CalculateChecksum;
  4016. }
  4017. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4018. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4019. TRemoteProperties NewProperties = CurrentProperties;
  4020. Result =
  4021. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4022. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4023. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4024. CalculateSize, CalculateChecksumEvent);
  4025. if (Result)
  4026. {
  4027. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4028. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4029. }
  4030. }
  4031. __finally
  4032. {
  4033. delete GroupList;
  4034. delete UserList;
  4035. }
  4036. }
  4037. else
  4038. {
  4039. DirView(Side)->DisplayPropertiesMenu();
  4040. Result = true;
  4041. }
  4042. return Result;
  4043. }
  4044. //---------------------------------------------------------------------------
  4045. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4046. {
  4047. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4048. {
  4049. FIgnoreNextDialogChar = Key;
  4050. }
  4051. Key = 0;
  4052. }
  4053. //---------------------------------------------------------------------------
  4054. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4055. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4056. {
  4057. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4058. if (Command != NULL)
  4059. {
  4060. KeyProcessed(Key, Shift);
  4061. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4062. {
  4063. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4064. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4065. false, false, const_cast<TCustomCommandType *>(Command));
  4066. }
  4067. }
  4068. }
  4069. //---------------------------------------------------------------------------
  4070. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4071. {
  4072. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4073. {
  4074. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4075. }
  4076. if (!DirView(osCurrent)->IsEditing())
  4077. {
  4078. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4079. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4080. {
  4081. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4082. if (((Action->ShortCut == KeyShortCut) ||
  4083. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4084. AllowedAction(Action, aaShortCut))
  4085. {
  4086. // Has to be called before the action as the dialog char is already in queue.
  4087. // So when the action consumes message queue, we already need to have the
  4088. // FIgnoreNextDialogChar set
  4089. KeyProcessed(Key, Shift);
  4090. // Reset reference to previous component (when menu/toolbar was clicked).
  4091. // Needed to detect that action was invoked by keyboard shortcut
  4092. // in TNonVisualDataModule::ExplorerActionsExecute
  4093. Action->ActionComponent = NULL;
  4094. Action->Execute();
  4095. return;
  4096. }
  4097. }
  4098. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4099. {
  4100. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4101. {
  4102. KeyProcessed(Key, Shift);
  4103. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4104. return;
  4105. }
  4106. }
  4107. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4108. {
  4109. KeyProcessed(Key, Shift);
  4110. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4111. }
  4112. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4113. if (IsCustomShortCut(CustomShortCut))
  4114. {
  4115. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4116. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4117. if (WinConfiguration->SharedBookmarks != NULL)
  4118. {
  4119. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4120. if ((Bookmark != NULL) &&
  4121. OpenBookmark(FCurrentSide, Bookmark))
  4122. {
  4123. KeyProcessed(Key, Shift);
  4124. }
  4125. }
  4126. }
  4127. }
  4128. TForm::KeyDown(Key, Shift);
  4129. }
  4130. //---------------------------------------------------------------------------
  4131. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4132. {
  4133. DebugAssert(Terminal != NULL);
  4134. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4135. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4136. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4137. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4138. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4139. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4140. // expanded from ?: to avoid memory leaks
  4141. if (SecurityEnabled)
  4142. {
  4143. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4144. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4145. }
  4146. else
  4147. {
  4148. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4149. }
  4150. if (FileSystemInfo.ProtocolName.IsEmpty())
  4151. {
  4152. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4153. }
  4154. else
  4155. {
  4156. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4157. }
  4158. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4159. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4160. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4161. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4162. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4163. UnicodeString CompressionStr = CSCompressionStr;
  4164. if (CSCompressionStr != SCCompressionStr)
  4165. {
  4166. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4167. }
  4168. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4169. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4170. UpdateStatusBar();
  4171. }
  4172. //---------------------------------------------------------------------------
  4173. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4174. {
  4175. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4176. DebugAssert(SessionStatusBar != NULL);
  4177. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4178. {
  4179. // note: (Terminal->Status < sshReady) currently never happens here,
  4180. // so STATUS_CONNECTING is never used
  4181. SessionStatusBar->SimplePanel = true;
  4182. SessionStatusBar->SimpleText = LoadStr(
  4183. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4184. }
  4185. else
  4186. {
  4187. DebugAssert(Terminal);
  4188. SessionStatusBar->SimplePanel = false;
  4189. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4190. if (!FNote.IsEmpty())
  4191. {
  4192. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4193. }
  4194. else
  4195. {
  4196. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4197. }
  4198. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4199. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4200. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4201. }
  4202. }
  4203. //---------------------------------------------------------------------------
  4204. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4205. {
  4206. Panel->Caption = L"";
  4207. }
  4208. //---------------------------------------------------------------------------
  4209. void __fastcall TCustomScpExplorerForm::Idle()
  4210. {
  4211. if (FShowing || FStandaloneEditing)
  4212. {
  4213. FEditorManager->Check();
  4214. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4215. // that needs to know if queue view is visible (and it may be closed after queue update)
  4216. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4217. }
  4218. if (FShowing)
  4219. {
  4220. if (!NonVisualDataModule->Busy &&
  4221. // Menu is opened or drag&drop is going on
  4222. (Mouse->Capture == NULL))
  4223. {
  4224. if (FRefreshRemoteDirectory)
  4225. {
  4226. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4227. {
  4228. Terminal->RefreshDirectory();
  4229. }
  4230. FRefreshRemoteDirectory = false;
  4231. }
  4232. if (FRefreshLocalDirectory)
  4233. {
  4234. ReloadLocalDirectory();
  4235. FRefreshLocalDirectory = false;
  4236. }
  4237. if (WinConfiguration->RefreshRemotePanel)
  4238. {
  4239. TManagedTerminal * ManagedTerminal =
  4240. dynamic_cast<TManagedTerminal *>(Terminal);
  4241. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  4242. (Now() - ManagedTerminal->DirectoryLoaded >
  4243. WinConfiguration->RefreshRemotePanelInterval))
  4244. {
  4245. RemoteDirView->ReloadDirectory();
  4246. }
  4247. }
  4248. }
  4249. }
  4250. if (FShowing || FStandaloneEditing)
  4251. {
  4252. if (FQueueStatusInvalidated)
  4253. {
  4254. UpdateQueueStatus(false);
  4255. }
  4256. RefreshQueueItems();
  4257. }
  4258. if (FShowing)
  4259. {
  4260. UpdateStatusBar();
  4261. }
  4262. FIgnoreNextDialogChar = 0;
  4263. }
  4264. //---------------------------------------------------------------------------
  4265. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4266. {
  4267. try
  4268. {
  4269. FUserActionTimer->Enabled = false;
  4270. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4271. {
  4272. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4273. {
  4274. FPendingQueueActionItem->ProcessUserAction();
  4275. }
  4276. }
  4277. }
  4278. __finally
  4279. {
  4280. FPendingQueueActionItem = NULL;
  4281. }
  4282. }
  4283. //---------------------------------------------------------------------------
  4284. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4285. {
  4286. if (WinConfiguration->MinimizeToTray)
  4287. {
  4288. UpdateTrayIcon();
  4289. FTrayIcon->Visible = true;
  4290. if (Visible)
  4291. {
  4292. ShowWindow(Handle, SW_HIDE);
  4293. }
  4294. }
  4295. }
  4296. //---------------------------------------------------------------------------
  4297. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4298. {
  4299. // WORKAROUND
  4300. // When restoring maximized window from minimization,
  4301. // rarely some controls do not align properly.
  4302. // Two instances seen (both for Commander):
  4303. // - When restoring, window is temporarily narrower (not maximized),
  4304. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4305. // Once maximized already, top dock shinks back, but the session PageControl,
  4306. // do not align up, leaving space between TopDock and PageControl.
  4307. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4308. for (int Index = 0; Index < ControlCount; Index++)
  4309. {
  4310. RealignControl(Controls[Index]);
  4311. }
  4312. if (FTrayIcon->Visible)
  4313. {
  4314. FTrayIcon->Visible = false;
  4315. if (Visible)
  4316. {
  4317. ShowWindow(Handle, SW_SHOW);
  4318. }
  4319. }
  4320. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4321. {
  4322. FNeedSession = false;
  4323. NonVisualDataModule->StartBusy();
  4324. try
  4325. {
  4326. NeedSession(false);
  4327. }
  4328. __finally
  4329. {
  4330. NonVisualDataModule->EndBusy();
  4331. }
  4332. }
  4333. }
  4334. //---------------------------------------------------------------------------
  4335. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4336. {
  4337. FTrayIcon->Hint = GetMainForm()->Caption;
  4338. }
  4339. //---------------------------------------------------------------------------
  4340. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4341. {
  4342. UpdateTrayIcon();
  4343. }
  4344. //---------------------------------------------------------------------------
  4345. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4346. {
  4347. // workaround
  4348. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4349. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4350. // But WM_ACTIVATEAPP message can be received even when
  4351. // the main window is minimized to the tray and internal editor window is focused
  4352. // (after another application was previously active)
  4353. if (::IsIconic(Handle))
  4354. {
  4355. if (!IsAppIconic())
  4356. {
  4357. SetAppIconic(true);
  4358. }
  4359. }
  4360. ::ApplicationRestore();
  4361. Application->BringToFront();
  4362. }
  4363. //---------------------------------------------------------------------------
  4364. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4365. {
  4366. RestoreApp();
  4367. }
  4368. //---------------------------------------------------------------------------
  4369. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4370. {
  4371. if (OpenInNewWindow())
  4372. {
  4373. // todo: Pass FromSite
  4374. ExecuteNewInstance(SessionUrl);
  4375. }
  4376. else
  4377. {
  4378. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4379. }
  4380. }
  4381. //---------------------------------------------------------------------------
  4382. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4383. {
  4384. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4385. // current working directories become defaults here, what is not right
  4386. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4387. StoredSessions->NewSession(SessionName, SessionData.get());
  4388. // modified only, explicit
  4389. StoredSessions->Save(false, true);
  4390. // encode session name because of slashes in hierarchical sessions
  4391. return EncodeUrlString(SessionName);
  4392. }
  4393. //---------------------------------------------------------------------------
  4394. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4395. {
  4396. if (OpenInNewWindow())
  4397. {
  4398. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4399. }
  4400. else
  4401. {
  4402. // current working directories become defaults here, what is not right
  4403. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4404. TTerminalManager * Manager = TTerminalManager::Instance();
  4405. TTerminal * Terminal = Manager->NewTerminal(SessionData.get());
  4406. Manager->ActiveTerminal = Terminal;
  4407. }
  4408. }
  4409. //---------------------------------------------------------------------------
  4410. void __fastcall TCustomScpExplorerForm::RenameSession()
  4411. {
  4412. UnicodeString Name = Terminal->SessionData->Name;
  4413. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4414. {
  4415. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4416. TSessionData::ValidateName(Name);
  4417. // This is inconsistent with how color (for example) is handled.
  4418. Terminal->SessionData->Name = Name;
  4419. UpdateControls();
  4420. // Add/Remove distinguishing paths from sessions of the same name.
  4421. DoTerminalListChanged();
  4422. }
  4423. }
  4424. //---------------------------------------------------------------------------
  4425. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4426. {
  4427. DebugAssert(Queue != NULL);
  4428. bool Result = Queue->IsEmpty;
  4429. if (!Result)
  4430. {
  4431. SetFocus();
  4432. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4433. }
  4434. return Result;
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4438. {
  4439. return CanCloseQueue(FQueue);
  4440. }
  4441. //---------------------------------------------------------------------------
  4442. void __fastcall TCustomScpExplorerForm::CloseSession()
  4443. {
  4444. if (CanCloseQueue())
  4445. {
  4446. TTerminalManager::Instance()->FreeActiveTerminal();
  4447. }
  4448. }
  4449. //---------------------------------------------------------------------------
  4450. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4451. {
  4452. if (OpenInNewWindow())
  4453. {
  4454. // encode session name because of slashes in hierarchical sessions
  4455. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4456. }
  4457. else
  4458. {
  4459. TTerminalManager * Manager = TTerminalManager::Instance();
  4460. TTerminal * Terminal = Manager->NewTerminal(Data);
  4461. Manager->ActiveTerminal = Terminal;
  4462. }
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4466. {
  4467. if (OpenInNewWindow())
  4468. {
  4469. ExecuteNewInstance(Name);
  4470. }
  4471. else
  4472. {
  4473. TTerminalManager * Manager = TTerminalManager::Instance();
  4474. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4475. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4476. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4477. }
  4478. }
  4479. //---------------------------------------------------------------------------
  4480. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4481. bool &CanClose)
  4482. {
  4483. if (Terminal != NULL)
  4484. {
  4485. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4486. {
  4487. unsigned int Result;
  4488. TMessageParams Params(mpNeverAskAgainCheck);
  4489. UnicodeString Message;
  4490. int Answers = qaOK | qaCancel;
  4491. if (TTerminalManager::Instance()->Count > 1)
  4492. {
  4493. if (!WinConfiguration->AutoSaveWorkspace)
  4494. {
  4495. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4496. Answers = qaYes | qaNo | qaCancel;
  4497. }
  4498. else
  4499. {
  4500. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4501. }
  4502. }
  4503. else
  4504. {
  4505. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4506. }
  4507. if (WinConfiguration->AutoSaveWorkspace)
  4508. {
  4509. Message =
  4510. FORMAT("%s\n\n%s", (Message,
  4511. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4512. }
  4513. SetFocus();
  4514. Result = MessageDialog(Message, qtConfirmation,
  4515. Answers, HELP_NONE, &Params);
  4516. if (Result == qaNeverAskAgain)
  4517. {
  4518. WinConfiguration->ConfirmClosingSession = false;
  4519. }
  4520. if (Result == qaNo)
  4521. {
  4522. CanClose = SaveWorkspace(true);
  4523. // note that the workspace will be saved redundatly again from FormClose
  4524. }
  4525. else
  4526. {
  4527. CanClose =
  4528. (Result == qaOK) ||
  4529. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4530. (Result == qaNeverAskAgain);
  4531. }
  4532. }
  4533. if (CanClose)
  4534. {
  4535. CanClose = CanCloseQueue();
  4536. }
  4537. }
  4538. if (CanClose)
  4539. {
  4540. CanClose =
  4541. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4542. FEditorManager->CloseExternalFilesWithoutProcess();
  4543. if (CanClose)
  4544. {
  4545. while (CanClose && (FLocalEditors->Count > 0))
  4546. {
  4547. int PrevCount = FLocalEditors->Count;
  4548. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4549. CanClose = (FLocalEditors->Count < PrevCount);
  4550. }
  4551. if (CanClose)
  4552. {
  4553. CanClose = FEditorManager->Empty(true);
  4554. if (!CanClose)
  4555. {
  4556. SetFocus();
  4557. CanClose =
  4558. (MessageDialog(
  4559. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4560. }
  4561. }
  4562. }
  4563. }
  4564. }
  4565. //---------------------------------------------------------------------------
  4566. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4567. {
  4568. TForm * Form = dynamic_cast<TForm *>(Sender);
  4569. DebugAssert(Form != NULL);
  4570. Form->Close();
  4571. }
  4572. //---------------------------------------------------------------------------
  4573. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4574. {
  4575. TForm * Form = dynamic_cast<TForm *>(Sender);
  4576. delete Form;
  4577. }
  4578. //---------------------------------------------------------------------------
  4579. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4580. {
  4581. while (FLocalEditors->Count > 0)
  4582. {
  4583. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4584. }
  4585. }
  4586. //---------------------------------------------------------------------------
  4587. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4588. TObject *Sender)
  4589. {
  4590. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4591. try
  4592. {
  4593. SetProperties(osRemote, FileList);
  4594. }
  4595. __finally
  4596. {
  4597. delete FileList;
  4598. }
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4602. {
  4603. if (value)
  4604. {
  4605. if (Component == fcCustomCommandsBand)
  4606. {
  4607. UpdateCustomCommandsToolbar();
  4608. }
  4609. }
  4610. }
  4611. //---------------------------------------------------------------------------
  4612. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4613. {
  4614. TControl * Control = GetComponent(Component);
  4615. DebugAssert(Control);
  4616. bool Changed = (Control->Visible != value);
  4617. if (Changed)
  4618. {
  4619. ComponentShowing(Component, value);
  4620. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4621. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4622. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4623. if (value)
  4624. {
  4625. int RemainingHeight = Control->Parent->ClientHeight;
  4626. int RemainingWidth = Control->Parent->ClientWidth;
  4627. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4628. {
  4629. TControl * ChildControl = Control->Parent->Controls[i];
  4630. if (ChildControl->Visible)
  4631. {
  4632. switch (ChildControl->Align)
  4633. {
  4634. case alTop:
  4635. case alBottom:
  4636. RemainingHeight -= ChildControl->Height;
  4637. break;
  4638. case alLeft:
  4639. case alRight:
  4640. RemainingWidth -= ChildControl->Width;
  4641. break;
  4642. }
  4643. }
  4644. }
  4645. int Reserve = ScaleByTextHeight(this, 32);
  4646. // queue in explorer, trees in commander
  4647. if (Control->Height > RemainingHeight - Reserve)
  4648. {
  4649. Control->Height = RemainingHeight / 2;
  4650. }
  4651. if (Control->Width > RemainingWidth - Reserve)
  4652. {
  4653. Control->Width = RemainingWidth / 2;
  4654. }
  4655. }
  4656. Control->Visible = value;
  4657. if (WasFocused && Visible)
  4658. {
  4659. DirView(osCurrent)->SetFocus();
  4660. }
  4661. FixControlsPlacement();
  4662. }
  4663. }
  4664. //---------------------------------------------------------------------------
  4665. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4666. {
  4667. TControl * Control = GetComponent(Component);
  4668. if (Control == NULL)
  4669. {
  4670. return false;
  4671. }
  4672. else
  4673. {
  4674. return Control->Visible;
  4675. }
  4676. }
  4677. //---------------------------------------------------------------------------
  4678. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4679. {
  4680. bool Result;
  4681. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4682. {
  4683. Result = !IsUWP();
  4684. }
  4685. else
  4686. {
  4687. Result = true;
  4688. }
  4689. return Result;
  4690. }
  4691. //---------------------------------------------------------------------------
  4692. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4693. {
  4694. if (RemoteDirView->ItemFocused != NULL)
  4695. {
  4696. RemoteDirView->ItemFocused->MakeVisible(false);
  4697. }
  4698. QueueSplitter->Visible = QueuePanel->Visible;
  4699. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4700. }
  4701. //---------------------------------------------------------------------------
  4702. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4703. {
  4704. switch (Component) {
  4705. case fcStatusBar: return RemoteStatusBar;
  4706. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4707. case fcQueueView: return QueuePanel;
  4708. case fcQueueToolbar: return QueueDock;
  4709. case fcRemoteTree: return RemoteDrivePanel;
  4710. case fcSessionsTabs: return SessionsPageControl;
  4711. default: return NULL;
  4712. }
  4713. }
  4714. //---------------------------------------------------------------------------
  4715. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4716. TObject *Sender, TListColumn *Column, TPoint &Point)
  4717. {
  4718. DebugAssert(NonVisualDataModule && Column && Sender);
  4719. NonVisualDataModule->ListColumn = Column;
  4720. TPopupMenu * DirViewColumnMenu;
  4721. if (Sender == RemoteDirView)
  4722. {
  4723. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4724. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4725. (Column->Index == uvName);
  4726. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4727. (Column->Index == uvSize);
  4728. }
  4729. else
  4730. {
  4731. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4732. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4733. (Column->Index == dvName);
  4734. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4735. (Column->Index == dvSize);
  4736. }
  4737. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4738. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4739. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4740. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4741. }
  4742. //---------------------------------------------------------------------------
  4743. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4744. TObject *Sender, TListItem *Item, bool &AllowExec)
  4745. {
  4746. DoDirViewExecFile(Sender, Item, AllowExec);
  4747. }
  4748. //---------------------------------------------------------------------------
  4749. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4750. TListItem * Item, bool & AllowExec)
  4751. {
  4752. DebugAssert(Sender && Item && Configuration);
  4753. DebugAssert(AllowExec);
  4754. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4755. bool Remote = (ADirView == DirView(osRemote));
  4756. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4757. TOperationSide Side = (Remote ? osRemote : osLocal);
  4758. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4759. // on files only (not directories)
  4760. // and only when symlinks are resolved (apply to remote panel only)
  4761. if (!ADirView->ItemIsDirectory(Item) &&
  4762. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4763. {
  4764. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4765. !FForceExecution &&
  4766. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4767. {
  4768. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4769. {
  4770. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4771. UnlockWindow();
  4772. try
  4773. {
  4774. ExecuteFileOperation(
  4775. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4776. }
  4777. __finally
  4778. {
  4779. LockWindow();
  4780. }
  4781. AllowExec = false;
  4782. }
  4783. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4784. {
  4785. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4786. {
  4787. ExecuteFile(Side, efDefaultEditor);
  4788. AllowExec = false;
  4789. }
  4790. }
  4791. else
  4792. {
  4793. DebugFail();
  4794. }
  4795. }
  4796. // if we have not done anything special, fall back to default behavior
  4797. if (AllowExec)
  4798. {
  4799. if (Remote && !WinConfiguration->DisableOpenEdit)
  4800. {
  4801. ExecuteFile(osRemote, efShell);
  4802. AllowExec = false;
  4803. }
  4804. }
  4805. }
  4806. }
  4807. //---------------------------------------------------------------------------
  4808. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4809. {
  4810. return ((Side == osRemote) || (Side == osCurrent));
  4811. }
  4812. //---------------------------------------------------------------------------
  4813. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4814. {
  4815. DebugFail();
  4816. }
  4817. //---------------------------------------------------------------------------
  4818. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4819. {
  4820. DebugFail();
  4821. }
  4822. //---------------------------------------------------------------------------
  4823. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4824. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4825. {
  4826. TSynchronizeParamType Params;
  4827. Params.LocalDirectory = LocalDirectory;
  4828. Params.RemoteDirectory = RemoteDirectory;
  4829. int UnusedParams =
  4830. (GUIConfiguration->SynchronizeParams &
  4831. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4832. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4833. Params.Options = GUIConfiguration->SynchronizeOptions;
  4834. bool SaveSettings = false;
  4835. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4836. &DoSynchronizeTooManyDirectories);
  4837. DebugAssert(FSynchronizeController == NULL);
  4838. FSynchronizeController = &Controller;
  4839. bool Result;
  4840. try
  4841. {
  4842. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4843. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4844. int Options =
  4845. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4846. DebugAssert(FOnFeedSynchronizeError == NULL);
  4847. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4848. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4849. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4850. if (Result)
  4851. {
  4852. if (SaveSettings)
  4853. {
  4854. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4855. GUIConfiguration->SynchronizeOptions = Params.Options;
  4856. }
  4857. else
  4858. {
  4859. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4860. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4861. FLAGSET(Params.Options, soSynchronize))
  4862. {
  4863. GUIConfiguration->SynchronizeOptions =
  4864. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4865. soSynchronize;
  4866. }
  4867. }
  4868. LocalDirectory = Params.LocalDirectory;
  4869. RemoteDirectory = Params.RemoteDirectory;
  4870. }
  4871. }
  4872. __finally
  4873. {
  4874. FSynchronizeController = NULL;
  4875. DebugAssert(FOnFeedSynchronizeError == NULL);
  4876. FOnFeedSynchronizeError = NULL;
  4877. }
  4878. return Result;
  4879. }
  4880. //---------------------------------------------------------------------------
  4881. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4882. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4883. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4884. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4885. TSynchronizeOptions * Options, bool Full)
  4886. {
  4887. // Keep-up-to-date mode
  4888. if (Terminal->Status == ssOpened)
  4889. {
  4890. try
  4891. {
  4892. int PParams = Params.Params;
  4893. if (!Full)
  4894. {
  4895. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  4896. if (FLAGSET(Params.Options, soRecurse))
  4897. {
  4898. PParams |= TTerminal::spSubDirs;
  4899. }
  4900. }
  4901. else
  4902. {
  4903. // if keepuptodate is non-recursive,
  4904. // full sync before has to be non-recursive as well
  4905. if (FLAGCLEAR(Params.Options, soRecurse))
  4906. {
  4907. PParams |= TTerminal::spNoRecurse;
  4908. }
  4909. }
  4910. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4911. PParams, Checklist, Options);
  4912. }
  4913. catch (Exception & E)
  4914. {
  4915. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4916. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4917. {
  4918. // noop, already logged in MoreMessageDialog
  4919. }
  4920. else
  4921. {
  4922. ShowExtendedExceptionEx(Terminal, &E);
  4923. throw;
  4924. }
  4925. }
  4926. }
  4927. }
  4928. //---------------------------------------------------------------------------
  4929. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4930. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4931. const UnicodeString ErrorStr)
  4932. {
  4933. if (!Directory.IsEmpty())
  4934. {
  4935. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4936. }
  4937. else
  4938. {
  4939. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4940. }
  4941. }
  4942. //---------------------------------------------------------------------------
  4943. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4944. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4945. {
  4946. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4947. {
  4948. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4949. }
  4950. else
  4951. {
  4952. TMessageParams Params(mpNeverAskAgainCheck);
  4953. unsigned int Result = MessageDialog(
  4954. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4955. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4956. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4957. {
  4958. MaxDirectories *= 2;
  4959. if (Result == qaNeverAskAgain)
  4960. {
  4961. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4962. }
  4963. }
  4964. else
  4965. {
  4966. Abort();
  4967. }
  4968. }
  4969. }
  4970. //---------------------------------------------------------------------------
  4971. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4972. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4973. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4974. TSynchronizeOptions * Options)
  4975. {
  4976. // Keep-up-to-date mode
  4977. DebugAssert(!FAutoOperation);
  4978. void * BatchStorage;
  4979. BatchStart(BatchStorage);
  4980. FAutoOperation = true;
  4981. bool AnyOperation = false;
  4982. TDateTime StartTime = Now();
  4983. TSynchronizeChecklist * AChecklist = NULL;
  4984. try
  4985. {
  4986. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4987. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4988. {
  4989. FSynchronizeProgressForm->Start();
  4990. }
  4991. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4992. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4993. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4994. Options);
  4995. SAFE_DESTROY(FSynchronizeProgressForm);
  4996. AnyOperation = (AChecklist->CheckedCount > 0);
  4997. if (AnyOperation)
  4998. {
  4999. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5000. CreateProgressForm(&SynchronizeProgress);
  5001. try
  5002. {
  5003. Terminal->SynchronizeApply(
  5004. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5005. SynchronizeProcessedItem, NULL, NULL, NULL);
  5006. }
  5007. __finally
  5008. {
  5009. DestroyProgressForm();
  5010. }
  5011. }
  5012. }
  5013. __finally
  5014. {
  5015. if (Checklist == NULL)
  5016. {
  5017. delete AChecklist;
  5018. }
  5019. else
  5020. {
  5021. *Checklist = AChecklist;
  5022. }
  5023. FAutoOperation = false;
  5024. SAFE_DESTROY(FSynchronizeProgressForm);
  5025. BatchEnd(BatchStorage);
  5026. ReloadLocalDirectory();
  5027. if (AnyOperation)
  5028. {
  5029. OperationComplete(StartTime);
  5030. }
  5031. }
  5032. }
  5033. //---------------------------------------------------------------------------
  5034. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5035. {
  5036. // can be called from command line
  5037. return Visible &&
  5038. ((DirView(osRemote)->SelCount > 0) ||
  5039. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5040. }
  5041. //---------------------------------------------------------------------------
  5042. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5043. {
  5044. LogSynchronizeEvent(Terminal, Message);
  5045. }
  5046. //---------------------------------------------------------------------------
  5047. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5048. int Params, TSynchronizeOptions & Options)
  5049. {
  5050. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5051. {
  5052. Options.Filter = new TStringList();
  5053. Options.Filter->CaseSensitive = false;
  5054. Options.Filter->Duplicates = Types::dupAccept;
  5055. if (DirView(osRemote)->SelCount > 0)
  5056. {
  5057. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5058. }
  5059. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5060. {
  5061. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5062. }
  5063. Options.Filter->Sort();
  5064. }
  5065. }
  5066. //---------------------------------------------------------------------------
  5067. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5068. {
  5069. TCopyParamType Defaults;
  5070. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5071. ConfigStorage->AccessMode = smRead;
  5072. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false, false))
  5073. {
  5074. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5075. }
  5076. ConfigStorage.reset(NULL);
  5077. std::unique_ptr<TStringList> Options(new TStringList());
  5078. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5079. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5080. UnicodeString Result;
  5081. if (Options->Count > 0)
  5082. {
  5083. Result =
  5084. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5085. }
  5086. return Result;
  5087. }
  5088. //---------------------------------------------------------------------------
  5089. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5090. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5091. {
  5092. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5093. UnicodeString AdditionalParams =
  5094. FORMAT(L"%s \"%s\" \"%s\" %d %d %s%s", (
  5095. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5096. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options,
  5097. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5098. SerializeCopyParamForCommandLine(CopyParams)));
  5099. ExecuteNewInstance(SessionName, AdditionalParams);
  5100. }
  5101. //---------------------------------------------------------------------------
  5102. struct TSynchronizeParams
  5103. {
  5104. UnicodeString LocalDirectory;
  5105. UnicodeString RemoteDirectory;
  5106. TSynchronizeMode Mode;
  5107. TSynchronizeChecklist * Checklist;
  5108. int Params;
  5109. TCopyParamType * CopyParam;
  5110. TDateTime CollectElapsed;
  5111. TDateTime * StartTime;
  5112. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5113. };
  5114. //---------------------------------------------------------------------------
  5115. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5116. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5117. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5118. {
  5119. DebugAssert(!FAutoOperation);
  5120. void * BatchStorage;
  5121. BatchStart(BatchStorage);
  5122. FAutoOperation = true;
  5123. TFileOperationStatistics Statistics;
  5124. TDateTime Start = Now();
  5125. try
  5126. {
  5127. Params.OnProcessedItem = OnProcessedItem;
  5128. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5129. CreateProgressForm(&SynchronizeProgress);
  5130. Terminal->SynchronizeApply(
  5131. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5132. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5133. &Statistics);
  5134. }
  5135. __finally
  5136. {
  5137. Params.OnProcessedItem = NULL;
  5138. FAutoOperation = false;
  5139. DestroyProgressForm();
  5140. BatchEnd(BatchStorage);
  5141. ReloadLocalDirectory();
  5142. }
  5143. if (WinConfiguration->SynchronizeSummary)
  5144. {
  5145. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5146. // The statistics should be 0 anyway in this case
  5147. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5148. {
  5149. Message += L"\n";
  5150. if (Statistics.FilesUploaded > 0)
  5151. {
  5152. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5153. }
  5154. if (Statistics.FilesDownloaded > 0)
  5155. {
  5156. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5157. }
  5158. if (Statistics.FilesDeletedLocal > 0)
  5159. {
  5160. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5161. }
  5162. if (Statistics.FilesDeletedRemote > 0)
  5163. {
  5164. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5165. }
  5166. }
  5167. TDateTime Elapsed = (Now() - Start);
  5168. Message +=
  5169. L"\n" +
  5170. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5171. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5172. TMessageParams Params(mpNeverAskAgainCheck);
  5173. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5174. if (Result == qaNeverAskAgain)
  5175. {
  5176. WinConfiguration->SynchronizeSummary = false;
  5177. }
  5178. }
  5179. }
  5180. //---------------------------------------------------------------------------
  5181. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5182. {
  5183. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5184. {
  5185. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5186. }
  5187. // Not set in keep-up-to-date mode - Synchronize() method
  5188. if (Token != NULL)
  5189. {
  5190. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5191. if (Params.OnProcessedItem != NULL)
  5192. {
  5193. Params.OnProcessedItem(NULL, ChecklistItem);
  5194. }
  5195. }
  5196. }
  5197. //---------------------------------------------------------------------------
  5198. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5199. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5200. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5201. {
  5202. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5203. *Params.StartTime = Now();
  5204. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5205. }
  5206. //---------------------------------------------------------------------------
  5207. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5208. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5209. {
  5210. // terminal can be already closed (e.g. dropped connection)
  5211. if (Terminal != NULL)
  5212. {
  5213. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5214. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5215. }
  5216. }
  5217. //---------------------------------------------------------------------------
  5218. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5219. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5220. {
  5221. TAutoBatch AutoBatch(this);
  5222. TAutoFlag AutoOperationFlag(FAutoOperation);
  5223. if (Side == osRemote)
  5224. {
  5225. std::unique_ptr<TStrings> FileList(new TStringList());
  5226. FileList->AddObject(FileName, RemoteFile);
  5227. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5228. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5229. RemoteDirView->SaveSelection();
  5230. RemoteDirView->SaveSelectedNames();
  5231. try
  5232. {
  5233. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5234. }
  5235. catch(...)
  5236. {
  5237. RemoteDirView->DiscardSavedSelection();
  5238. throw;
  5239. }
  5240. RemoteDirView->RestoreSelection();
  5241. }
  5242. else if (DebugAlwaysTrue(Side == osLocal))
  5243. {
  5244. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5245. {
  5246. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5247. }
  5248. UnicodeString Directory = ExtractFileDir(FileName);
  5249. ReloadLocalDirectory(Directory);
  5250. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5251. if (!SamePaths(Directory, NewDirectory))
  5252. {
  5253. ReloadLocalDirectory(NewDirectory);
  5254. }
  5255. }
  5256. }
  5257. //---------------------------------------------------------------------------
  5258. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5259. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5260. const TCopyParamType * CopyParams)
  5261. {
  5262. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5263. UnicodeString AdditionalParams =
  5264. FORMAT(L"%s \"%s\" \"%s\" %d %d %s%s", (
  5265. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5266. LocalDirectory, RemoteDirectory, Mode, Params,
  5267. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5268. SerializeCopyParamForCommandLine(CopyParams)));
  5269. ExecuteNewInstance(SessionName, AdditionalParams);
  5270. }
  5271. //---------------------------------------------------------------------------
  5272. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5273. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5274. TSynchronizeMode & Mode, int Params, bool & SaveMode, bool UseDefaults)
  5275. {
  5276. int Result;
  5277. bool SaveSettings = false;
  5278. int Options =
  5279. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5280. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5281. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5282. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5283. bool Continue =
  5284. UseDefaults ||
  5285. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5286. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow);
  5287. if (Continue)
  5288. {
  5289. Configuration->Usage->Inc(L"Synchronizations");
  5290. UpdateCopyParamCounters(CopyParam);
  5291. TSynchronizeOptions SynchronizeOptions;
  5292. GetSynchronizeOptions(Params, SynchronizeOptions);
  5293. if (SaveSettings)
  5294. {
  5295. GUIConfiguration->SynchronizeParams = Params;
  5296. }
  5297. else
  5298. {
  5299. SaveMode = false;
  5300. }
  5301. TDateTime StartTime = Now();
  5302. TSynchronizeChecklist * Checklist = NULL;
  5303. try
  5304. {
  5305. DebugAssert(!FAutoOperation);
  5306. FAutoOperation = true;
  5307. try
  5308. {
  5309. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  5310. FSynchronizeProgressForm->Start();
  5311. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5312. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5313. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5314. &SynchronizeOptions);
  5315. }
  5316. __finally
  5317. {
  5318. FAutoOperation = false;
  5319. SAFE_DESTROY(FSynchronizeProgressForm);
  5320. }
  5321. TSynchronizeParams SynchronizeParams;
  5322. SynchronizeParams.LocalDirectory = LocalDirectory;
  5323. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5324. SynchronizeParams.Mode = Mode;
  5325. SynchronizeParams.CopyParam = &CopyParam;
  5326. SynchronizeParams.Params = Params;
  5327. SynchronizeParams.Checklist = Checklist;
  5328. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5329. SynchronizeParams.StartTime = &StartTime;
  5330. SynchronizeParams.OnProcessedItem = NULL;
  5331. Result = Checklist->Count;
  5332. if (Checklist->Count > 0)
  5333. {
  5334. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5335. {
  5336. if (!DoSynchronizeChecklistDialog(
  5337. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5338. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, &SynchronizeParams))
  5339. {
  5340. Result = -1;
  5341. }
  5342. }
  5343. else
  5344. {
  5345. FullSynchronize(SynchronizeParams, NULL, NULL);
  5346. }
  5347. }
  5348. else
  5349. {
  5350. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5351. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5352. }
  5353. }
  5354. __finally
  5355. {
  5356. delete Checklist;
  5357. }
  5358. OperationComplete(StartTime);
  5359. }
  5360. else
  5361. {
  5362. Result = -1;
  5363. }
  5364. return Result;
  5365. }
  5366. //---------------------------------------------------------------------------
  5367. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5368. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  5369. bool & Continue, bool Collect)
  5370. {
  5371. if (Collect)
  5372. {
  5373. DebugAssert(FSynchronizeProgressForm != NULL);
  5374. if (!FSynchronizeProgressForm->Started)
  5375. {
  5376. FSynchronizeProgressForm->Start();
  5377. }
  5378. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  5379. }
  5380. else
  5381. {
  5382. DebugAssert(FSynchronizeProgressForm == NULL);
  5383. DebugAssert(FProgressForm != NULL);
  5384. }
  5385. }
  5386. //---------------------------------------------------------------------------
  5387. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5388. {
  5389. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5390. TRemoteFile * File = NULL;
  5391. Terminal->ReadFile(FullFileName, File);
  5392. if (File != NULL)
  5393. {
  5394. std::unique_ptr<TRemoteFile> FileOwner(File);
  5395. TAutoFlag Flag(FStandaloneEditing);
  5396. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5397. Application->ShowMainForm = false;
  5398. Application->Run();
  5399. }
  5400. }
  5401. //---------------------------------------------------------------------------
  5402. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5403. {
  5404. DebugFail();
  5405. }
  5406. //---------------------------------------------------------------------------
  5407. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5408. {
  5409. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5410. SessionData->Assign(Terminal->SessionData);
  5411. UpdateSessionData(SessionData.get());
  5412. Terminal->UpdateSessionCredentials(SessionData.get());
  5413. if (!Terminal->SessionData->HasSessionName())
  5414. {
  5415. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5416. // once IsWorkspace is cleared
  5417. SessionData->Name = UnicodeString();
  5418. SessionData->IsWorkspace = false;
  5419. }
  5420. return SessionData.release();
  5421. }
  5422. //---------------------------------------------------------------------------
  5423. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5424. {
  5425. TSessionData * SessionData = CloneCurrentSessionData();
  5426. try
  5427. {
  5428. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5429. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5430. }
  5431. __finally
  5432. {
  5433. delete SessionData;
  5434. }
  5435. }
  5436. //---------------------------------------------------------------------------
  5437. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5438. {
  5439. TTerminalManager * Manager = TTerminalManager::Instance();
  5440. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5441. if (DebugAlwaysTrue(Terminal != NULL))
  5442. {
  5443. // Update (Managed)Terminal->StateData
  5444. UpdateTerminal(Terminal);
  5445. }
  5446. Manager->SaveWorkspace(DataList.get());
  5447. return DataList.release();
  5448. }
  5449. //---------------------------------------------------------------------------
  5450. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5451. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5452. {
  5453. WinConfiguration->LastWorkspace = Name;
  5454. if (!SavePasswords)
  5455. {
  5456. for (int Index = 0; Index < DataList->Count; Index++)
  5457. {
  5458. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5459. if (SessionData->Link.IsEmpty())
  5460. {
  5461. SessionData->ClearSessionPasswords();
  5462. }
  5463. }
  5464. }
  5465. StoredSessions->NewWorkspace(Name, DataList);
  5466. // modified only
  5467. StoredSessions->Save(false, Explicit);
  5468. }
  5469. //---------------------------------------------------------------------------
  5470. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5471. {
  5472. return
  5473. DefaultStr(WinConfiguration->LastWorkspace,
  5474. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5475. }
  5476. //---------------------------------------------------------------------------
  5477. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5478. {
  5479. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5480. bool AnyNonStoredSessionWithPassword = false;
  5481. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5482. bool AllNonStoredSessionsAnonymous = true;
  5483. TTerminalManager * Manager = TTerminalManager::Instance();
  5484. for (int Index = 0; Index < DataList->Count; Index++)
  5485. {
  5486. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5487. if (SessionData->Link.IsEmpty())
  5488. {
  5489. if (SessionData->HasAnySessionPassword())
  5490. {
  5491. AnyNonStoredSessionWithPassword = true;
  5492. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5493. {
  5494. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5495. }
  5496. }
  5497. if (!SameText(SessionData->UserName, AnonymousUserName))
  5498. {
  5499. AllNonStoredSessionsAnonymous = false;
  5500. }
  5501. }
  5502. }
  5503. bool SavePasswords;
  5504. bool * PSavePasswords;
  5505. bool NotRecommendedSavingPasswords =
  5506. !CustomWinConfiguration->UseMasterPassword &&
  5507. !AllNonStoredSessionsAnonymous;
  5508. if (Configuration->DisablePasswordStoring ||
  5509. !AnyNonStoredSessionWithPassword)
  5510. {
  5511. PSavePasswords = NULL;
  5512. SavePasswords = false;
  5513. }
  5514. else
  5515. {
  5516. PSavePasswords = &SavePasswords;
  5517. SavePasswords =
  5518. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5519. !NotRecommendedSavingPasswords;
  5520. }
  5521. UnicodeString Name = WorkspaceName();
  5522. bool CreateShortcut = false;
  5523. bool Result =
  5524. DoSaveWorkspaceDialog(
  5525. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5526. EnableAutoSave);
  5527. if (Result)
  5528. {
  5529. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5530. if (CreateShortcut)
  5531. {
  5532. TOperationVisualizer Visualizer;
  5533. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5534. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5535. }
  5536. if (EnableAutoSave)
  5537. {
  5538. WinConfiguration->AutoSaveWorkspace = true;
  5539. WinConfiguration->AutoWorkspace = Name;
  5540. if (PSavePasswords != NULL)
  5541. {
  5542. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5543. }
  5544. }
  5545. }
  5546. return Result;
  5547. }
  5548. //---------------------------------------------------------------------------
  5549. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5550. {
  5551. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5552. DebugAssert(ManagedTerminal != NULL);
  5553. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5554. if (WinConfiguration->PreservePanelState)
  5555. {
  5556. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5557. }
  5558. UpdateSessionData(ManagedTerminal->StateData);
  5559. }
  5560. //---------------------------------------------------------------------------
  5561. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5562. {
  5563. // Keep in sync with TSessionData::CopyStateData
  5564. DebugAssert(Data != NULL);
  5565. // This is inconsistent with how color (for example) is handled.
  5566. Data->Name = Terminal->SessionData->Name;
  5567. // cannot use RemoteDirView->Path, because it is empty if connection
  5568. // was already closed
  5569. // also only peek, we may not be connected at all atm
  5570. // so make sure we do not try retrieving current directory from the server
  5571. // (particularly with FTP)
  5572. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5573. if (!ACurrentDirectory.IsEmpty())
  5574. {
  5575. Data->RemoteDirectory = ACurrentDirectory;
  5576. }
  5577. Data->Color = SessionColor;
  5578. }
  5579. //---------------------------------------------------------------------------
  5580. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5581. {
  5582. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5583. DebugAssert(Toolbar != NULL);
  5584. for (int i = 0; i < Toolbar->Items->Count; i++)
  5585. {
  5586. TTBXCustomDropDownItem * DropDownItem;
  5587. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5588. if (DropDownItem != NULL)
  5589. {
  5590. ToolbarItemResize(DropDownItem,
  5591. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5592. Toolbar->NonClientWidth);
  5593. break;
  5594. }
  5595. }
  5596. }
  5597. //---------------------------------------------------------------------------
  5598. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5599. {
  5600. Item->EditWidth = Width;
  5601. }
  5602. //---------------------------------------------------------------------------
  5603. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5604. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5605. {
  5606. for (int i = 0; i < Toolbar->Items->Count; i++)
  5607. {
  5608. TTBXCustomDropDownItem * DropDownItem;
  5609. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5610. if (DropDownItem != NULL)
  5611. {
  5612. ASize.x -= DropDownItem->EditWidth;
  5613. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5614. }
  5615. }
  5616. }
  5617. //---------------------------------------------------------------------------
  5618. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5619. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5620. {
  5621. if (WinConfiguration->DDWarnLackOfTempSpace)
  5622. {
  5623. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5624. if (!ADrive.IsEmpty())
  5625. {
  5626. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5627. DebugAssert(RequiredSpace >= 0);
  5628. __int64 RequiredWithReserve;
  5629. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5630. if (FreeSpace < RequiredWithReserve)
  5631. {
  5632. unsigned int Result;
  5633. TMessageParams Params(mpNeverAskAgainCheck);
  5634. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5635. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5636. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5637. if (Result == qaNeverAskAgain)
  5638. {
  5639. WinConfiguration->DDWarnLackOfTempSpace = false;
  5640. }
  5641. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5642. }
  5643. }
  5644. }
  5645. }
  5646. //---------------------------------------------------------------------------
  5647. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5648. {
  5649. DoOpenDirectoryDialog(odAddBookmark, Side);
  5650. }
  5651. //---------------------------------------------------------------------------
  5652. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5653. {
  5654. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5655. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5656. try
  5657. {
  5658. TCustomDirView * DView = DirView(Side);
  5659. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5660. {
  5661. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5662. }
  5663. }
  5664. catch (...)
  5665. {
  5666. delete VisitedDirectories;
  5667. throw;
  5668. }
  5669. return VisitedDirectories;
  5670. }
  5671. //---------------------------------------------------------------------------
  5672. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5673. TOpenDirectoryMode Mode, TOperationSide Side)
  5674. {
  5675. bool Continue = true;
  5676. if (Mode == odAddBookmark)
  5677. {
  5678. TMessageParams Params(mpNeverAskAgainCheck);
  5679. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5680. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5681. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5682. unsigned int Answer =
  5683. MessageDialog(Message,
  5684. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5685. if (Answer == qaNeverAskAgain)
  5686. {
  5687. Continue = true;
  5688. WinConfiguration->UseSharedBookmarks = true;
  5689. }
  5690. else if (Answer == qaOK)
  5691. {
  5692. Continue = true;
  5693. WinConfiguration->UseSharedBookmarks = false;
  5694. }
  5695. else
  5696. {
  5697. Continue = false;
  5698. }
  5699. }
  5700. if (Continue)
  5701. {
  5702. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5703. try
  5704. {
  5705. UnicodeString Name = DirView(Side)->PathName;
  5706. bool Repeat;
  5707. do
  5708. {
  5709. Repeat = false;
  5710. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5711. // do not allow switching to location profiles,
  5712. // if we are not connected
  5713. HasDirView[osLocal] && (Terminal != NULL)))
  5714. {
  5715. TWindowLock Lock(this);
  5716. if (!TryOpenDirectory(Side, Name))
  5717. {
  5718. Repeat = true;
  5719. Mode = odBrowse;
  5720. }
  5721. }
  5722. }
  5723. while (Repeat);
  5724. }
  5725. __finally
  5726. {
  5727. delete VisitedDirectories;
  5728. }
  5729. }
  5730. }
  5731. //---------------------------------------------------------------------------
  5732. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5733. {
  5734. DebugAssert(!FTerminal->CommandSessionOpened);
  5735. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5736. }
  5737. //---------------------------------------------------------------------------
  5738. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5739. {
  5740. bool Result = FTerminal->IsCapable[Capability] ||
  5741. FTerminal->CommandSessionOpened;
  5742. if (!Result)
  5743. {
  5744. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5745. if (!GUIConfiguration->ConfirmCommandSession)
  5746. {
  5747. Result = true;
  5748. }
  5749. else
  5750. {
  5751. TMessageParams Params(mpNeverAskAgainCheck);
  5752. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5753. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5754. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5755. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5756. if (Answer == qaNeverAskAgain)
  5757. {
  5758. GUIConfiguration->ConfirmCommandSession = false;
  5759. Result = true;
  5760. }
  5761. else if (Answer == qaOK)
  5762. {
  5763. Result = true;
  5764. }
  5765. }
  5766. if (Result)
  5767. {
  5768. Result = CommandSessionFallback();
  5769. }
  5770. }
  5771. return Result;
  5772. }
  5773. //---------------------------------------------------------------------------
  5774. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5775. {
  5776. if (EnsureCommandSessionFallback(fcAnyCommand))
  5777. {
  5778. DoConsoleDialog(Terminal, Command);
  5779. }
  5780. }
  5781. //---------------------------------------------------------------------------
  5782. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5783. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5784. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5785. {
  5786. if (IsFileControl(DropSourceControl, osRemote) &&
  5787. (FDDExtMapFile != NULL))
  5788. {
  5789. Accept = true;
  5790. }
  5791. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5792. DebugAssert(FDDTargetControl != NULL);
  5793. }
  5794. //---------------------------------------------------------------------------
  5795. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5796. _di_IDataObject DataObj, int KeyState,
  5797. const TPoint & Point, int & Effect, bool & Accept)
  5798. {
  5799. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5800. }
  5801. //---------------------------------------------------------------------------
  5802. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5803. _di_IDataObject DataObj, int KeyState,
  5804. const TPoint & Point, int & Effect, bool & Accept)
  5805. {
  5806. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5807. }
  5808. //---------------------------------------------------------------------------
  5809. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5810. TObject * Sender)
  5811. {
  5812. DebugUsedParam(Sender);
  5813. DebugAssert(FDDTargetControl == Sender);
  5814. FDDTargetControl = NULL;
  5815. }
  5816. //---------------------------------------------------------------------------
  5817. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5818. {
  5819. FileControlDDDragLeave(SessionsPageControl);
  5820. }
  5821. //---------------------------------------------------------------------------
  5822. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5823. {
  5824. FileControlDDDragLeave(QueueView3);
  5825. }
  5826. //---------------------------------------------------------------------------
  5827. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5828. {
  5829. DebugAssert(GetSide(Side) == osRemote);
  5830. DebugUsedParam(Side);
  5831. bool Edit = false;
  5832. TRemoteFile * File = NULL;
  5833. UnicodeString FileName;
  5834. UnicodeString PointTo;
  5835. bool SymbolicLink = true;
  5836. if (RemoteDirView->ItemFocused)
  5837. {
  5838. DebugAssert(RemoteDirView->ItemFocused->Data);
  5839. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5840. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5841. if (Edit)
  5842. {
  5843. FileName = File->FileName;
  5844. PointTo = File->LinkTo;
  5845. }
  5846. else
  5847. {
  5848. PointTo = File->FileName;
  5849. }
  5850. }
  5851. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5852. Terminal->IsCapable[fcHardLink]))
  5853. {
  5854. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5855. if (Edit)
  5856. {
  5857. DebugAssert(File->FileName == FileName);
  5858. int Params = dfNoRecursive;
  5859. Terminal->ExceptionOnFail = true;
  5860. try
  5861. {
  5862. Terminal->DeleteFile(L"", File, &Params);
  5863. }
  5864. __finally
  5865. {
  5866. Terminal->ExceptionOnFail = false;
  5867. }
  5868. }
  5869. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5870. }
  5871. }
  5872. //---------------------------------------------------------------------------
  5873. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5874. {
  5875. return
  5876. ((GetSide(Side) != osRemote) ||
  5877. ((Terminal != NULL) &&
  5878. Terminal->ResolvingSymlinks &&
  5879. Terminal->IsCapable[fcSymbolicLink]));
  5880. }
  5881. //---------------------------------------------------------------------------
  5882. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5883. {
  5884. return
  5885. (FCurrentSide == osRemote) &&
  5886. (RemoteDirView->ItemFocused != NULL) &&
  5887. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5888. Terminal->SessionData->ResolveSymlinks;
  5889. }
  5890. //---------------------------------------------------------------------------
  5891. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5892. {
  5893. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5894. FForceExecution = true;
  5895. try
  5896. {
  5897. DirView(osCurrent)->ExecuteCurrentFile();
  5898. }
  5899. __finally
  5900. {
  5901. FForceExecution = false;
  5902. }
  5903. }
  5904. //---------------------------------------------------------------------------
  5905. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5906. {
  5907. TEditorData ExternalEditor;
  5908. ExternalEditor.Editor = edExternal;
  5909. bool Remember = false;
  5910. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5911. (GetSide(osCurrent) == osRemote)))
  5912. {
  5913. if (Remember)
  5914. {
  5915. TEditorList * EditorList = new TEditorList;
  5916. try
  5917. {
  5918. *EditorList = *WinConfiguration->EditorList;
  5919. bool Found = false;
  5920. int i = 0;
  5921. while (!Found && (i < EditorList->Count))
  5922. {
  5923. const TEditorPreferences * Editor = EditorList->Editors[i];
  5924. if ((Editor->Data->Editor == edExternal) &&
  5925. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5926. {
  5927. Found = true;
  5928. }
  5929. i++;
  5930. }
  5931. if (!Found)
  5932. {
  5933. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5934. WinConfiguration->EditorList = EditorList;
  5935. }
  5936. }
  5937. __finally
  5938. {
  5939. delete EditorList;
  5940. }
  5941. }
  5942. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5943. }
  5944. }
  5945. //---------------------------------------------------------------------------
  5946. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5947. {
  5948. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5949. if (FFileFindTerminal == Sender)
  5950. {
  5951. FFileFindTerminal = NULL;
  5952. HideFileFindDialog();
  5953. }
  5954. if (FClipboardTerminal == Sender)
  5955. {
  5956. ClipboardClear(); // implies ClipboardStop
  5957. }
  5958. }
  5959. //---------------------------------------------------------------------------
  5960. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5961. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5962. {
  5963. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5964. DebugAssert(Terminal != NULL);
  5965. if (Data->Terminal == Terminal)
  5966. {
  5967. Data->Terminal = NULL;
  5968. }
  5969. }
  5970. //---------------------------------------------------------------------------
  5971. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5972. {
  5973. UpdateControls();
  5974. SessionColor = TColor(0);
  5975. UpdateRemotePathComboBox(false);
  5976. NeedSession(true);
  5977. }
  5978. //---------------------------------------------------------------------------
  5979. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5980. {
  5981. try
  5982. {
  5983. try
  5984. {
  5985. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5986. }
  5987. __finally
  5988. {
  5989. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5990. (!Terminal || !Terminal->Active))
  5991. {
  5992. TerminateApplication();
  5993. }
  5994. }
  5995. }
  5996. catch (EAbort &)
  5997. {
  5998. // swallow
  5999. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6000. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6001. }
  6002. }
  6003. //---------------------------------------------------------------------------
  6004. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6005. {
  6006. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6007. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6008. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6009. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6010. try
  6011. {
  6012. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6013. // Clear the design time unthemed tab
  6014. ((SessionsPageControl->PageCount > 0) &&
  6015. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6016. {
  6017. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6018. }
  6019. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6020. {
  6021. TThemeTabSheet * TabSheet;
  6022. if (Index >= SessionsPageControl->PageCount)
  6023. {
  6024. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6025. TabSheet->PageControl = SessionsPageControl;
  6026. }
  6027. else
  6028. {
  6029. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6030. }
  6031. bool IsSessionTab = (Index < TerminalList->Count);
  6032. if (IsSessionTab)
  6033. {
  6034. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6035. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6036. UpdateSessionTab(TabSheet);
  6037. }
  6038. else
  6039. {
  6040. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6041. TabSheet->Tag = 0; // not really needed
  6042. // 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)
  6043. UpdateNewSessionTab();
  6044. }
  6045. TabSheet->ShowCloseButton = IsSessionTab;
  6046. }
  6047. }
  6048. __finally
  6049. {
  6050. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6051. }
  6052. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6053. }
  6054. //---------------------------------------------------------------------------
  6055. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6056. {
  6057. DoTerminalListChanged();
  6058. }
  6059. //---------------------------------------------------------------------------
  6060. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6061. {
  6062. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6063. DebugAssert(TabSheet->ImageIndex == 0);
  6064. TabSheet->Caption =
  6065. WinConfiguration->SelectiveToolbarText ?
  6066. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6067. UnicodeString();
  6068. }
  6069. //---------------------------------------------------------------------------
  6070. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6071. {
  6072. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  6073. }
  6074. //---------------------------------------------------------------------------
  6075. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6076. {
  6077. if (DebugAlwaysTrue(TabSheet != NULL))
  6078. {
  6079. TManagedTerminal * ManagedTerminal =
  6080. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  6081. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  6082. {
  6083. TColor Color = (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  6084. TabSheet->ImageIndex = AddSessionColor(Color);
  6085. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ManagedTerminal, true);
  6086. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6087. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6088. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6089. {
  6090. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  6091. }
  6092. }
  6093. }
  6094. }
  6095. //---------------------------------------------------------------------------
  6096. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6097. {
  6098. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6099. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6100. bool Result = (Terminal != NULL);
  6101. if (Result)
  6102. {
  6103. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6104. }
  6105. else
  6106. {
  6107. try
  6108. {
  6109. NewSession(false);
  6110. }
  6111. __finally
  6112. {
  6113. DoTerminalListChanged();
  6114. }
  6115. FSessionsPageControlNewSessionTime = Now();
  6116. }
  6117. return Result;
  6118. }
  6119. //---------------------------------------------------------------------------
  6120. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6121. {
  6122. SessionTabSwitched();
  6123. }
  6124. //---------------------------------------------------------------------------
  6125. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6126. {
  6127. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6128. DebugAssert(TransferList != NULL);
  6129. UnicodeString Name;
  6130. if (TransferList->ItemIndex <= 0)
  6131. {
  6132. Name = L"";
  6133. }
  6134. else
  6135. {
  6136. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6137. }
  6138. if (FCopyParamAutoSelected.IsEmpty())
  6139. {
  6140. // if previous preset was not autoselected, make new preset the "default"
  6141. FCopyParamDefault = Name;
  6142. }
  6143. GUIConfiguration->CopyParamCurrent = Name;
  6144. }
  6145. //---------------------------------------------------------------------------
  6146. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6147. {
  6148. // sanity check
  6149. bool ExistingPreset =
  6150. (FTransferListHoverIndex >= 0) &&
  6151. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6152. DebugAssert(ExistingPreset);
  6153. if (ExistingPreset)
  6154. {
  6155. HDC DC = GetDC(0);
  6156. TCanvas * Canvas = new TCanvas();
  6157. try
  6158. {
  6159. Canvas->Handle = DC;
  6160. Canvas->Font = GetToolbarFont(this);
  6161. UnicodeString Name;
  6162. if (FTransferListHoverIndex == 0)
  6163. {
  6164. Name = L"";
  6165. }
  6166. else
  6167. {
  6168. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6169. }
  6170. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6171. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6172. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6173. static_cast<TObject*>(GetComponent(fcTransferList)));
  6174. UnicodeString InfoStr =
  6175. GUIConfiguration->CopyParamPreset[Name].
  6176. GetInfoStr(L"; ",
  6177. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6178. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6179. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6180. {
  6181. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6182. {
  6183. InfoStr.SetLength(InfoStr.Length() - 1);
  6184. }
  6185. InfoStr += Ellipsis;
  6186. }
  6187. // UpdateCaption does not cause invalidation of whole submenu, while
  6188. // setting Caption property does.
  6189. // also it probably does not resize the label, even if necessary
  6190. // (we do not want that anyway)
  6191. TransferLabel->UpdateCaption(InfoStr);
  6192. }
  6193. __finally
  6194. {
  6195. Canvas->Handle = NULL;
  6196. ReleaseDC(0, DC);
  6197. delete Canvas;
  6198. }
  6199. }
  6200. }
  6201. //---------------------------------------------------------------------------
  6202. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6203. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6204. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6205. {
  6206. if (FTransferListHoverIndex != AHoverIndex)
  6207. {
  6208. FTransferListHoverIndex = AHoverIndex;
  6209. UpdateTransferLabel();
  6210. }
  6211. }
  6212. //---------------------------------------------------------------------------
  6213. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6214. {
  6215. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6216. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6217. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6218. {
  6219. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6220. {
  6221. OpenDirectory(GetSide(osCurrent));
  6222. Message.Result = 1;
  6223. }
  6224. else
  6225. {
  6226. TForm::Dispatch(&Message);
  6227. }
  6228. }
  6229. else
  6230. {
  6231. TForm::Dispatch(&Message);
  6232. }
  6233. }
  6234. //---------------------------------------------------------------------------
  6235. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6236. {
  6237. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6238. if ((FIgnoreNextDialogChar != 0) &&
  6239. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6240. {
  6241. Message.Result = 1;
  6242. }
  6243. else
  6244. {
  6245. TForm::Dispatch(&Message);
  6246. }
  6247. FIgnoreNextDialogChar = 0;
  6248. }
  6249. //---------------------------------------------------------------------------
  6250. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6251. {
  6252. // The four low-order bits are used internally by Windows
  6253. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6254. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6255. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6256. // 61730 - restore thru double click - undocumented
  6257. // 61490 - maximize thru double click - undocumented
  6258. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6259. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6260. {
  6261. SysResizing(Cmd);
  6262. }
  6263. TForm::Dispatch(&Message);
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6267. {
  6268. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6269. // Also there no point returning TRUE as we are not able to
  6270. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6271. // Hence the process termination might be safer :)
  6272. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6273. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6274. {
  6275. Message.Result = FALSE;
  6276. }
  6277. else
  6278. {
  6279. Message.Result = TRUE;
  6280. }
  6281. // Do not call default handling as that triggers OnCloseQuery,
  6282. // where our implementation will popup confirmation dialogs, what we do not want,
  6283. // as per Vista guidelines:
  6284. // https://docs.microsoft.com/en-us/windows/desktop/shutdown/shutting-down
  6285. }
  6286. //---------------------------------------------------------------------------
  6287. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6288. {
  6289. if (Message.EndSession && IsApplicationMinimized())
  6290. {
  6291. // WORKAROUND
  6292. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6293. // when it receives WM_ENDSESSION,
  6294. // but that sometimes (particularly when application is minimized) cause crashes.
  6295. // Crash popups message that blocks log off.
  6296. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6297. // so we call ExitProcess() immediately, not even trying to cleanup.
  6298. // It still causes beep, so there's likely some popup, but it does not block
  6299. // log off.
  6300. ExitProcess(0);
  6301. }
  6302. TForm::Dispatch(&Message);
  6303. }
  6304. #ifdef _DEBUG
  6305. //---------------------------------------------------------------------------
  6306. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6307. {
  6308. TForm::Dispatch(&Message);
  6309. }
  6310. #endif
  6311. //---------------------------------------------------------------------------
  6312. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6313. {
  6314. }
  6315. //---------------------------------------------------------------------------
  6316. void __fastcall TCustomScpExplorerForm::DoShow()
  6317. {
  6318. // only now are the controls resized finally, so the size constraints
  6319. // will not conflict with possibly very small window size
  6320. RestoreFormParams();
  6321. FixControlsPlacement();
  6322. if (Position == poDefaultPosOnly)
  6323. {
  6324. CutFormToDesktop(this);
  6325. }
  6326. TForm::DoShow();
  6327. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6328. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6329. if (Terminal == NULL)
  6330. {
  6331. StartingDisconnected();
  6332. }
  6333. UpdatePixelsPerInchMainWindowCounter();
  6334. FShowing = true;
  6335. }
  6336. //---------------------------------------------------------------------------
  6337. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6338. {
  6339. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6340. }
  6341. //---------------------------------------------------------------------------
  6342. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6343. {
  6344. DoTerminalListChanged();
  6345. }
  6346. //---------------------------------------------------------------------------
  6347. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6348. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6349. TNotifyEvent OnBalloonClick, TObject * UserData)
  6350. {
  6351. bool Do;
  6352. UnicodeString Message;
  6353. if (E == NULL)
  6354. {
  6355. Message = Str;
  6356. Do = true;
  6357. }
  6358. else
  6359. {
  6360. Do = ExceptionMessage(E, Message);
  6361. }
  6362. if (Do && WinConfiguration->BalloonNotifications)
  6363. {
  6364. UnicodeString Title;
  6365. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6366. {
  6367. Message = TrimLeft(Message);
  6368. }
  6369. else
  6370. {
  6371. Message = UnformatMessage(Message);
  6372. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6373. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6374. Title = LoadResourceString(Captions[Type]);
  6375. if (Terminal != NULL)
  6376. {
  6377. Title = FORMAT(L"%s - %s",
  6378. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6379. }
  6380. }
  6381. if (Seconds == 0)
  6382. {
  6383. Seconds = WinConfiguration->NotificationsTimeout;
  6384. }
  6385. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6386. }
  6387. }
  6388. //---------------------------------------------------------------------------
  6389. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6390. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6391. UnicodeString HelpKeyword, const TMessageParams * Params,
  6392. TTerminal * Terminal)
  6393. {
  6394. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6395. (FOnFeedSynchronizeError != NULL)) &&
  6396. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6397. {
  6398. if (FOnFeedSynchronizeError != NULL)
  6399. {
  6400. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6401. }
  6402. else
  6403. {
  6404. DebugAssert(FErrorList != NULL);
  6405. TStringList * MoreMessagesCopy = NULL;
  6406. if (MoreMessages)
  6407. {
  6408. MoreMessagesCopy = new TStringList();
  6409. MoreMessagesCopy->Assign(MoreMessages);
  6410. }
  6411. FErrorList->AddObject(Message, MoreMessagesCopy);
  6412. }
  6413. PopupTrayBalloon(Terminal, Message, Type);
  6414. return ContinueAnswer(Answers);
  6415. }
  6416. else
  6417. {
  6418. bool UseBalloon = FTrayIcon->Visible;
  6419. if (UseBalloon)
  6420. {
  6421. PopupTrayBalloon(Terminal, Message, Type);
  6422. }
  6423. unsigned int Result;
  6424. try
  6425. {
  6426. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6427. }
  6428. __finally
  6429. {
  6430. // cancel only balloon we popped up, otherwise we may cancel notification
  6431. // balloon that was there before the message dialog
  6432. // (such as "dd confirmation opt in balloon)
  6433. if (UseBalloon)
  6434. {
  6435. FTrayIcon->CancelBalloon();
  6436. }
  6437. }
  6438. return Result;
  6439. }
  6440. }
  6441. //---------------------------------------------------------------------------
  6442. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6443. TTerminal * Terminal, Exception * E)
  6444. {
  6445. if (FTrayIcon->Visible)
  6446. {
  6447. PopupTrayBalloon(Terminal, L"", qtError, E);
  6448. }
  6449. // particularly prevent opening new session from jump list,
  6450. // while exception is shown
  6451. NonVisualDataModule->StartBusy();
  6452. try
  6453. {
  6454. ShowExtendedExceptionEx(Terminal, E);
  6455. }
  6456. __finally
  6457. {
  6458. NonVisualDataModule->EndBusy();
  6459. FTrayIcon->CancelBalloon();
  6460. }
  6461. }
  6462. //---------------------------------------------------------------------------
  6463. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6464. {
  6465. // cannot rely on active page being page for active terminal,
  6466. // as it can happen that active page is the "new session" page
  6467. // (e.g. when reconnecting active terminal, while login dialog
  6468. // invoked from "new session" page is modal)
  6469. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6470. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6471. }
  6472. //---------------------------------------------------------------------------
  6473. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6474. TTerminal * Terminal, Exception * E)
  6475. {
  6476. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6477. if (!Terminal->Active)
  6478. {
  6479. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6480. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6481. {
  6482. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6483. }
  6484. }
  6485. }
  6486. //---------------------------------------------------------------------------
  6487. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6488. UnicodeString Message, TQueryType Type,
  6489. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6490. {
  6491. if ((E == NULL) ||
  6492. ExceptionMessage(E, Message))
  6493. {
  6494. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6495. if (Important)
  6496. {
  6497. Seconds *= 5;
  6498. }
  6499. UnicodeString NoteMessage(UnformatMessage(Message));
  6500. if (Terminal != NULL)
  6501. {
  6502. NoteMessage = FORMAT(L"%s: %s",
  6503. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6504. }
  6505. if (WinConfiguration->BalloonNotifications)
  6506. {
  6507. AddNote(NoteMessage);
  6508. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6509. }
  6510. else
  6511. {
  6512. FlashOnBackground();
  6513. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6514. }
  6515. }
  6516. }
  6517. //---------------------------------------------------------------------------
  6518. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6519. {
  6520. RestoreApp();
  6521. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6522. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6523. !NonVisualDataModule->Busy)
  6524. {
  6525. TTerminal * Terminal = TerminalNoteData->Terminal;
  6526. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6527. if (!ComponentVisible[fcQueueView])
  6528. {
  6529. ToggleQueueVisibility();
  6530. GoToQueue();
  6531. }
  6532. }
  6533. }
  6534. //---------------------------------------------------------------------------
  6535. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  6536. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6537. {
  6538. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6539. UnicodeString Message;
  6540. TNotifyEvent OnClick = NULL;
  6541. TObject * UserData = NULL;
  6542. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6543. switch (Event)
  6544. {
  6545. case qeEmptyButMonitored:
  6546. if ((ATerminal != Terminal) || QueueInvisible)
  6547. {
  6548. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6549. OnClick = QueueEmptyNoteClicked;
  6550. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6551. TerminalNoteData->Terminal = ATerminal;
  6552. UserData = TerminalNoteData;
  6553. }
  6554. break;
  6555. case qeEmpty:
  6556. OperationComplete(ManagedTerminal->QueueOperationStart);
  6557. break;
  6558. case qePendingUserAction:
  6559. if ((ATerminal != Terminal) ||
  6560. (QueueInvisible && !IsQueueAutoPopup()))
  6561. {
  6562. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6563. }
  6564. break;
  6565. default:
  6566. DebugFail();
  6567. }
  6568. if (!Message.IsEmpty())
  6569. {
  6570. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6571. }
  6572. }
  6573. //---------------------------------------------------------------------------
  6574. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6575. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6576. {
  6577. if (FDDExtMapFile != NULL)
  6578. {
  6579. CloseHandle(FDDExtMapFile);
  6580. FDDExtMapFile = NULL;
  6581. }
  6582. if (WinConfiguration->DDFakeFile)
  6583. {
  6584. DDFakeFileInitDrag(FileList, Created);
  6585. }
  6586. }
  6587. //---------------------------------------------------------------------------
  6588. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6589. {
  6590. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6591. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6592. {
  6593. FFakeFileDropTarget = FileName;
  6594. }
  6595. }
  6596. //---------------------------------------------------------------------------
  6597. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6598. {
  6599. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6600. if (!ForceDirectories(ApiPath(Result)))
  6601. {
  6602. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6603. }
  6604. FileSetAttr(ApiPath(Result), faHidden);
  6605. return Result;
  6606. }
  6607. //---------------------------------------------------------------------------
  6608. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6609. bool & Created)
  6610. {
  6611. FFakeFileDropTarget = UnicodeString();
  6612. FDragFakeDirectory = CreateFakeTransferDirectory();
  6613. FileList->AddItem(NULL, FDragFakeDirectory);
  6614. Created = true;
  6615. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6616. {
  6617. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6618. }
  6619. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6620. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6621. {
  6622. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6623. TDragExtCommStruct* CommStruct;
  6624. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6625. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6626. DebugAssert(CommStruct != NULL);
  6627. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6628. CommStruct->Dragging = true;
  6629. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6630. LENOF(CommStruct->DropDest));
  6631. NULL_TERMINATE(CommStruct->DropDest);
  6632. UnmapViewOfFile(CommStruct);
  6633. }
  6634. }
  6635. //---------------------------------------------------------------------------
  6636. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6637. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6638. {
  6639. bool Result;
  6640. if (Sender == RemoteDirView)
  6641. {
  6642. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6643. }
  6644. else
  6645. {
  6646. DebugAssert(Sender == RemoteDriveView);
  6647. TStrings * FileList = RemoteDriveView->DragFileList();
  6648. try
  6649. {
  6650. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6651. }
  6652. __finally
  6653. {
  6654. delete FileList;
  6655. }
  6656. }
  6657. if (FDDTargetControl == RemoteDriveView)
  6658. {
  6659. RemoteDriveView->UpdateDropTarget();
  6660. }
  6661. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6662. // or from tree view to dir view.
  6663. // foMove happens when file/dir is dragged from remote tree view outside of
  6664. // application via dragex
  6665. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6666. (DropSourceControl == RemoteDriveView))
  6667. {
  6668. RemoteDriveView->UpdateDropSource();
  6669. }
  6670. return Result;
  6671. }
  6672. //---------------------------------------------------------------------------
  6673. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6674. {
  6675. // This also handles drops of remote files to queue.
  6676. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6677. SAFE_DESTROY(FDDFileList);
  6678. if (!FFakeFileDropTarget.IsEmpty())
  6679. {
  6680. RemoveDir(ApiPath(FFakeFileDropTarget));
  6681. }
  6682. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6683. {
  6684. try
  6685. {
  6686. TDragResult DDResult = (Sender == RemoteDirView) ?
  6687. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6688. // Focus is moved to the target application,
  6689. // but as we are going to present the UI, we need to steal the focus back.
  6690. // This most likely won't work though (windows does not allow application
  6691. // to steal focus most of the time)
  6692. Application->BringToFront();
  6693. // On older version of Windows we never got drMove here, see also comment below.
  6694. // On Windows 10, we get the "move".
  6695. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6696. {
  6697. UnicodeString TargetDirectory;
  6698. TFileOperation Operation;
  6699. // drInvalid may mean drMove, see comment below
  6700. switch (DDResult)
  6701. {
  6702. case drCopy:
  6703. Operation = foCopy;
  6704. break;
  6705. case drMove:
  6706. Operation = foMove;
  6707. break;
  6708. default:
  6709. DebugFail();
  6710. case drInvalid:
  6711. // prefer "copy" for safety
  6712. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6713. break;
  6714. }
  6715. TTransferOperationParam Param;
  6716. UnicodeString CounterName;
  6717. bool ForceQueue;
  6718. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6719. {
  6720. // we get drInvalid both if d&d was intercepted by ddext,
  6721. // and when users drops on no-drop location.
  6722. // we tell the difference by existence of response from ddext,
  6723. // so we ignore absence of response in this case
  6724. if (DDResult != drInvalid)
  6725. {
  6726. // here we know that the extension is installed,
  6727. // as it is checked as soon as drag&drop starts from
  6728. // RemoteFileControlDDCreateDragFileList
  6729. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6730. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6731. {
  6732. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6733. }
  6734. else
  6735. {
  6736. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6737. }
  6738. }
  6739. }
  6740. else
  6741. {
  6742. // download using fake file
  6743. Param.Temp = false;
  6744. Param.DragDrop = true;
  6745. if (ForceQueue)
  6746. {
  6747. Param.Queue = asOn;
  6748. }
  6749. if (Sender == RemoteDirView)
  6750. {
  6751. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6752. }
  6753. if (RemoteFileControlFileOperation(Sender, Operation,
  6754. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6755. {
  6756. Configuration->Usage->Inc(CounterName);
  6757. }
  6758. }
  6759. }
  6760. }
  6761. __finally
  6762. {
  6763. CloseHandle(FDDExtMapFile);
  6764. FDDExtMapFile = NULL;
  6765. delete FDragFakeMonitors;
  6766. FDragFakeMonitors = NULL;
  6767. RemoveDir(ApiPath(FDragFakeDirectory));
  6768. FDragFakeDirectory = L"";
  6769. FFakeFileDropTarget = UnicodeString();
  6770. }
  6771. }
  6772. if (FDragDropSshTerminate.get() != NULL)
  6773. {
  6774. FDragDropSshTerminate->Rethrow();
  6775. }
  6776. }
  6777. //---------------------------------------------------------------------------
  6778. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6779. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  6780. {
  6781. // Remember drop effect so we know (when user drops files), if we copy or move
  6782. FLastDropEffect = dwEffect;
  6783. }
  6784. //---------------------------------------------------------------------------
  6785. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6786. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  6787. {
  6788. bool Result;
  6789. if (FDDTargetControl == QueueView3)
  6790. {
  6791. Directory = DefaultDownloadTargetDirectory();
  6792. Result = true;
  6793. CounterName = L"DownloadsDragDropQueue";
  6794. ForceQueue = true;
  6795. }
  6796. else if (!FFakeFileDropTarget.IsEmpty())
  6797. {
  6798. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  6799. Result = true;
  6800. ForceQueue = false;
  6801. CounterName = L"DownloadsDragDropFakeFile";
  6802. }
  6803. else
  6804. {
  6805. ForceQueue = false;
  6806. Enabled = false;
  6807. try
  6808. {
  6809. int Timer = 0;
  6810. Result = false;
  6811. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6812. {
  6813. {
  6814. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6815. TDragExtCommStruct* CommStruct;
  6816. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6817. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6818. DebugAssert(CommStruct != NULL);
  6819. Result = !CommStruct->Dragging;
  6820. if (Result)
  6821. {
  6822. Directory = ExtractFilePath(CommStruct->DropDest);
  6823. CounterName = L"DownloadsDragDropExternalExt";
  6824. }
  6825. UnmapViewOfFile(CommStruct);
  6826. }
  6827. if (!Result)
  6828. {
  6829. Sleep(50);
  6830. Timer += 50;
  6831. Application->ProcessMessages();
  6832. }
  6833. }
  6834. }
  6835. __finally
  6836. {
  6837. Enabled = true;
  6838. }
  6839. }
  6840. return Result;
  6841. }
  6842. //---------------------------------------------------------------------------
  6843. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6844. const UnicodeString TempDir, int SecDelay)
  6845. {
  6846. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6847. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6848. if (FDelayedDeletionTimer == NULL)
  6849. {
  6850. DebugAssert(HandleAllocated());
  6851. FDelayedDeletionTimer = new TTimer(this);
  6852. FDelayedDeletionTimer->Interval = 10000;
  6853. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6854. }
  6855. else
  6856. {
  6857. FDelayedDeletionTimer->Enabled = true;
  6858. }
  6859. }
  6860. //---------------------------------------------------------------------------
  6861. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6862. {
  6863. DebugAssert(FDelayedDeletionList != NULL);
  6864. TDateTime N = Now();
  6865. TDateTime Alert;
  6866. UnicodeString Directory;
  6867. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6868. {
  6869. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6870. if ((N >= Alert) || (Sender == NULL))
  6871. {
  6872. Directory = FDelayedDeletionList->Strings[Index];
  6873. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6874. {
  6875. FDelayedDeletionList->Delete(Index);
  6876. }
  6877. }
  6878. }
  6879. if (FDelayedDeletionList->Count == 0)
  6880. {
  6881. FDelayedDeletionTimer->Enabled = false;
  6882. }
  6883. }
  6884. //---------------------------------------------------------------------------
  6885. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6886. {
  6887. if (IsFileControl(FDDTargetControl, osRemote) ||
  6888. (FDDTargetControl == SessionsPageControl))
  6889. {
  6890. TTerminal * TargetTerminal = NULL;
  6891. TFileOperation Operation = foNone;
  6892. if (FDDTargetControl == SessionsPageControl)
  6893. {
  6894. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6895. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6896. // do not allow dropping on the "+" tab
  6897. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6898. if (TargetTerminal != NULL)
  6899. {
  6900. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6901. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6902. {
  6903. Operation = foRemoteMove;
  6904. }
  6905. else
  6906. {
  6907. Operation = foRemoteCopy;
  6908. }
  6909. }
  6910. }
  6911. else
  6912. {
  6913. if (FLastDropEffect == DROPEFFECT_MOVE)
  6914. {
  6915. Operation = foRemoteMove;
  6916. }
  6917. else if (FLastDropEffect == DROPEFFECT_COPY)
  6918. {
  6919. Operation = foRemoteCopy;
  6920. }
  6921. }
  6922. if (Operation != foNone)
  6923. {
  6924. RemoteFileControlFileOperation(DropSourceControl,
  6925. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6926. }
  6927. // abort drag&drop
  6928. Abort();
  6929. }
  6930. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6931. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6932. (FDDTargetControl != QueueView3))
  6933. {
  6934. DebugAssert(!FDragTempDir.IsEmpty());
  6935. TTransferType Type;
  6936. UnicodeString TempDir = FDragTempDir;
  6937. // We clear FDragTempDir before calling
  6938. // just in case it fail (raises exception)
  6939. FDragTempDir = L"";
  6940. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6941. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6942. // empty directory parameter means temp directory -> don't display it!
  6943. UnicodeString TargetDir = L"";
  6944. int Options = 0;
  6945. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6946. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6947. {
  6948. Abort();
  6949. }
  6950. // TargetDir is set when dropped on local file control
  6951. // (this was workaround for legacy dirview event handling, now it should be
  6952. // made prettier)
  6953. if (TargetDir.IsEmpty())
  6954. {
  6955. TargetDir = TempDir;
  6956. if (ForceDirectories(ApiPath(TargetDir)))
  6957. {
  6958. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6959. FPendingTempSpaceWarn = true;
  6960. try
  6961. {
  6962. FDragDropOperation = true;
  6963. int Params = cpTemporary |
  6964. (Type == ttMove ? cpDelete : 0);
  6965. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6966. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6967. }
  6968. __finally
  6969. {
  6970. FDragDropOperation = false;
  6971. FPendingTempSpaceWarn = false;
  6972. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6973. }
  6974. }
  6975. else
  6976. {
  6977. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6978. }
  6979. }
  6980. }
  6981. }
  6982. //---------------------------------------------------------------------------
  6983. void __fastcall TCustomScpExplorerForm::DDDownload(
  6984. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  6985. {
  6986. TAutoBatch AutoBatch(this);
  6987. UpdateCopyParamCounters(*CopyParam);
  6988. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6989. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6990. {
  6991. RemoteDriveView->UpdateDropSource();
  6992. }
  6993. }
  6994. //---------------------------------------------------------------------------
  6995. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6996. {
  6997. public:
  6998. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6999. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7000. {
  7001. }
  7002. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7003. {
  7004. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7005. TDataObjectFilesEx::AllowData(FormatEtc);
  7006. }
  7007. };
  7008. //---------------------------------------------------------------------------
  7009. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7010. TObject * Sender, TDataObject *& DataObject)
  7011. {
  7012. if (FDDExtMapFile != NULL)
  7013. {
  7014. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7015. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7016. {
  7017. Abort();
  7018. }
  7019. if (FileList->Count > 0)
  7020. {
  7021. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7022. if (!FilesObject->IsValid(true, true))
  7023. {
  7024. FilesObject->_Release();
  7025. }
  7026. else
  7027. {
  7028. DataObject = FilesObject;
  7029. }
  7030. }
  7031. }
  7032. }
  7033. //---------------------------------------------------------------------------
  7034. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7035. {
  7036. DebugFail();
  7037. }
  7038. //---------------------------------------------------------------------------
  7039. void __fastcall TCustomScpExplorerForm::GoToTree()
  7040. {
  7041. ComponentVisible[fcRemoteTree] = true;
  7042. RemoteDriveView->SetFocus();
  7043. }
  7044. //---------------------------------------------------------------------------
  7045. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7046. TPanelExport Export)
  7047. {
  7048. TCustomDirView * DirView = this->DirView(Side);
  7049. std::unique_ptr<TStrings> ExportData(new TStringList());
  7050. switch (Export)
  7051. {
  7052. case pePath:
  7053. ExportData->Add(DirView->PathName);
  7054. break;
  7055. case peFileList:
  7056. case peFullFileList:
  7057. {
  7058. bool FullPath = (Export == peFullFileList);
  7059. DirView->CreateFileList(false, FullPath, ExportData.get());
  7060. for (int Index = 0; Index < ExportData->Count; Index++)
  7061. {
  7062. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7063. {
  7064. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7065. }
  7066. }
  7067. }
  7068. break;
  7069. default:
  7070. DebugFail();
  7071. }
  7072. return ExportData.release();
  7073. }
  7074. //---------------------------------------------------------------------------
  7075. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7076. TPanelExport Export, TPanelExportDestination Destination)
  7077. {
  7078. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7079. PanelExportStore(Side, Export, Destination, ExportData.get());
  7080. }
  7081. //---------------------------------------------------------------------------
  7082. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7083. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7084. TStrings * ExportData)
  7085. {
  7086. if (Destination == pedClipboard)
  7087. {
  7088. TInstantOperationVisualizer Visualizer;
  7089. CopyToClipboard(ExportData);
  7090. }
  7091. else
  7092. {
  7093. DebugFail();
  7094. }
  7095. }
  7096. //---------------------------------------------------------------------------
  7097. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7098. {
  7099. TCustomDirView * DirView = this->DirView(Side);
  7100. UnicodeString Mask = DirView->Mask;
  7101. if (DoFilterMaskDialog(DirView, Mask))
  7102. {
  7103. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7104. Configuration->Usage->Inc(L"Filters");
  7105. }
  7106. }
  7107. //---------------------------------------------------------------------------
  7108. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7109. {
  7110. return FQueueController->DefaultOperation();
  7111. }
  7112. //---------------------------------------------------------------------------
  7113. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7114. TQueueOperation Operation, void ** Param)
  7115. {
  7116. switch (Operation)
  7117. {
  7118. case qoPreferences:
  7119. return true;
  7120. case qoGoTo:
  7121. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7122. case qoOnceEmpty:
  7123. return !FQueueController->Empty;
  7124. default:
  7125. return FQueueController->AllowOperation(Operation, Param);
  7126. }
  7127. }
  7128. //---------------------------------------------------------------------------
  7129. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7130. {
  7131. if (DebugAlwaysTrue(QueueView3->Visible))
  7132. {
  7133. QueueView3->SetFocus();
  7134. }
  7135. }
  7136. //---------------------------------------------------------------------------
  7137. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7138. TQueueOperation Operation, void * Param)
  7139. {
  7140. if (Operation == qoGoTo)
  7141. {
  7142. GoToQueue();
  7143. }
  7144. else if (Operation == qoPreferences)
  7145. {
  7146. PreferencesDialog(pmQueue);
  7147. }
  7148. else
  7149. {
  7150. FQueueController->ExecuteOperation(Operation, Param);
  7151. }
  7152. }
  7153. //---------------------------------------------------------------------------
  7154. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7155. {
  7156. return (Queue != NULL) && Queue->Enabled;
  7157. }
  7158. //---------------------------------------------------------------------------
  7159. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7160. {
  7161. DebugAssert(Queue != NULL);
  7162. if (Queue != NULL)
  7163. {
  7164. Queue->Enabled = !Queue->Enabled;
  7165. }
  7166. }
  7167. //---------------------------------------------------------------------------
  7168. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7169. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7170. {
  7171. FQueueActedItem = QueueView3->ItemFocused;
  7172. }
  7173. //---------------------------------------------------------------------------
  7174. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7175. {
  7176. return TopDock->Height + QueueSplitter->Height;
  7177. }
  7178. //---------------------------------------------------------------------------
  7179. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7180. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7181. {
  7182. // when queue is hidden by double-clicking splitter, stray attempt to
  7183. // resize the panel with strange value arrives, make sure it is ignored
  7184. if (ComponentVisible[fcQueueView])
  7185. {
  7186. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  7187. RemotePanel->Constraints->MinHeight;
  7188. if (NewSize > HeightLimit)
  7189. {
  7190. NewSize = HeightLimit;
  7191. }
  7192. }
  7193. else
  7194. {
  7195. Accept = false;
  7196. }
  7197. }
  7198. //---------------------------------------------------------------------------
  7199. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7200. TDragObject *& /*DragObject*/)
  7201. {
  7202. FQueueActedItem = QueueView3->ItemFocused;
  7203. }
  7204. //---------------------------------------------------------------------------
  7205. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7206. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7207. {
  7208. Accept = true;
  7209. if (Source == QueueView3)
  7210. {
  7211. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7212. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7213. if (Accept)
  7214. {
  7215. TQueueItemProxy * QueueItem;
  7216. TQueueItemProxy * DestQueueItem;
  7217. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7218. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7219. Accept = (QueueItem != DestQueueItem) &&
  7220. (QueueItem->Status == TQueueItem::qsPending) &&
  7221. (DestQueueItem->Status == TQueueItem::qsPending);
  7222. }
  7223. }
  7224. }
  7225. //---------------------------------------------------------------------------
  7226. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7227. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7228. {
  7229. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7230. {
  7231. TQueueItemProxy * QueueItem;
  7232. TQueueItemProxy * DestQueueItem;
  7233. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7234. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7235. QueueItem->Move(DestQueueItem);
  7236. }
  7237. }
  7238. //---------------------------------------------------------------------------
  7239. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7240. {
  7241. if ((QueueView3->ItemFocused == NULL) &&
  7242. (QueueView3->Items->Count > 0))
  7243. {
  7244. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7245. }
  7246. QueueLabelUpdateStatus();
  7247. }
  7248. //---------------------------------------------------------------------------
  7249. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7250. {
  7251. QueueLabelUpdateStatus();
  7252. }
  7253. //---------------------------------------------------------------------------
  7254. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7255. {
  7256. QueueLabel->UpdateStatus();
  7257. }
  7258. //---------------------------------------------------------------------------
  7259. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7260. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7261. {
  7262. if (Selected)
  7263. {
  7264. NonVisualDataModule->UpdateNonVisibleActions();
  7265. }
  7266. }
  7267. //---------------------------------------------------------------------------
  7268. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7269. {
  7270. TDragDropFilesEx * Result = NULL;
  7271. if (Sender == SessionsPageControl)
  7272. {
  7273. Result = FSessionsDragDropFilesEx;
  7274. }
  7275. else if (Sender == QueueView3)
  7276. {
  7277. Result = FQueueDragDropFilesEx;
  7278. }
  7279. else
  7280. {
  7281. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7282. if (DirView != NULL)
  7283. {
  7284. Result = DirView->DragDropFilesEx;
  7285. }
  7286. else
  7287. {
  7288. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7289. if (DriveView != NULL)
  7290. {
  7291. Result = DriveView->DragDropFilesEx;
  7292. }
  7293. }
  7294. }
  7295. DebugAssert(Result != NULL);
  7296. return Result;
  7297. }
  7298. //---------------------------------------------------------------------------
  7299. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7300. {
  7301. return (DView->SelCount == DView->FilesCount);
  7302. }
  7303. //---------------------------------------------------------------------------
  7304. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7305. {
  7306. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7307. }
  7308. //---------------------------------------------------------------------------
  7309. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7310. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7311. {
  7312. TFileOperation Operation;
  7313. switch (Effect)
  7314. {
  7315. case DROPEFFECT_MOVE:
  7316. Operation = foMove;
  7317. break;
  7318. case DROPEFFECT_COPY:
  7319. // occures on WinXP (reported by user)
  7320. default:
  7321. Operation = foCopy;
  7322. break;
  7323. };
  7324. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7325. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7326. if (DragDropFilesEx->FileList->Count > 0)
  7327. {
  7328. TStrings * FileList = new TStringList();
  7329. try
  7330. {
  7331. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7332. {
  7333. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7334. }
  7335. FDragDropOperation = true;
  7336. TTransferOperationParam Param;
  7337. Param.TargetDirectory = TargetPath;
  7338. // upload, no temp dirs
  7339. Param.Temp = false;
  7340. Param.DragDrop = DragDrop;
  7341. Param.Options =
  7342. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7343. if (ForceQueue)
  7344. {
  7345. Param.Queue = asOn;
  7346. }
  7347. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7348. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7349. {
  7350. if (IsFileControl(DropSourceControl, osLocal))
  7351. {
  7352. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7353. }
  7354. else
  7355. {
  7356. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7357. }
  7358. }
  7359. }
  7360. __finally
  7361. {
  7362. FDragDropOperation = false;
  7363. delete FileList;
  7364. }
  7365. }
  7366. }
  7367. //---------------------------------------------------------------------------
  7368. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7369. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7370. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7371. {
  7372. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7373. }
  7374. //---------------------------------------------------------------------------
  7375. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7376. TObject * Sender, int grfKeyState, int & dwEffect)
  7377. {
  7378. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7379. if ((dwEffect != DROPEFFECT_NONE) &&
  7380. IsFileControl(DropSourceControl, osRemote))
  7381. {
  7382. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7383. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7384. (RemoteDirView->DropTarget == NULL))
  7385. {
  7386. dwEffect = DROPEFFECT_NONE;
  7387. }
  7388. else
  7389. {
  7390. if (dwEffect == DROPEFFECT_COPY)
  7391. {
  7392. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7393. // currently we support copying always (at least via temporary directory);
  7394. // remove associated checks once this all proves stable and working
  7395. bool CopyCapable = true;
  7396. // if we do not support neither of operations, there's no discussion
  7397. if (!MoveCapable && !CopyCapable)
  7398. {
  7399. dwEffect = DROPEFFECT_NONE;
  7400. }
  7401. else
  7402. {
  7403. // The default effect inside remote panel is move,
  7404. // unless we do not support it, but support copy
  7405. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7406. {
  7407. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7408. }
  7409. else
  7410. {
  7411. // with ctrl-down, we want copy unless it is not supported
  7412. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7413. }
  7414. }
  7415. }
  7416. }
  7417. }
  7418. }
  7419. //---------------------------------------------------------------------------
  7420. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7421. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7422. {
  7423. if (FDDTotalSize >= 0)
  7424. {
  7425. if (File->IsDirectory)
  7426. {
  7427. FDDTotalSize = -1;
  7428. }
  7429. else
  7430. {
  7431. FDDTotalSize += File->Size;
  7432. }
  7433. }
  7434. DebugAssert(!FDragTempDir.IsEmpty());
  7435. // TODO: this is quite ineffective
  7436. // TODO: what if invalid character replacement is disabled?
  7437. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7438. UnicodeString TransferFileName;
  7439. if (Sender == RemoteDriveView)
  7440. {
  7441. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7442. }
  7443. else
  7444. {
  7445. TransferFileName = File->FileName;
  7446. }
  7447. FDDFileList->AddObject(TransferFileName, File);
  7448. }
  7449. //---------------------------------------------------------------------------
  7450. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7451. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7452. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7453. {
  7454. // sometimes we do not get DDEnd so the list is not released
  7455. SAFE_DESTROY(FDDFileList);
  7456. FDDFileList = new TStringList();
  7457. FDragTempDir = WinConfiguration->TemporaryDir();
  7458. FDDTotalSize = 0;
  7459. FDragDropSshTerminate.reset(NULL);
  7460. }
  7461. //---------------------------------------------------------------------------
  7462. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7463. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7464. HRESULT & Result)
  7465. {
  7466. if (Result == DRAGDROP_S_DROP)
  7467. {
  7468. try
  7469. {
  7470. GlobalDragImageList->HideDragImage();
  7471. try
  7472. {
  7473. RemoteFileControlDDTargetDrop();
  7474. }
  7475. catch(ESshTerminate & E)
  7476. {
  7477. FDragDropSshTerminate.reset(E.Clone());
  7478. }
  7479. }
  7480. catch (Exception &E)
  7481. {
  7482. // If downloading fails we need to cancel drag&drop, otherwise
  7483. // Explorer shows error
  7484. // But by the way exception probably never reach this point as
  7485. // it's catched on way.
  7486. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7487. Result = DRAGDROP_S_CANCEL;
  7488. ShowExtendedException(Terminal, &E);
  7489. }
  7490. }
  7491. }
  7492. //---------------------------------------------------------------------------
  7493. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7494. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7495. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7496. {
  7497. TFileMasks::TParams MaskParams;
  7498. MaskParams.Size = Size;
  7499. MaskParams.Modification = Modification;
  7500. // this does not re-parse the mask if it is the same as the last time
  7501. FDirViewMatchMask = Masks;
  7502. bool ImplicitMatch;
  7503. Matches =
  7504. // RecurseInclude parameter has no effect as the Path is empty
  7505. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7506. (AllowImplicitMatches || !ImplicitMatch);
  7507. }
  7508. //---------------------------------------------------------------------------
  7509. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7510. TObject * Sender, TListItem * Item, WORD & Indexes)
  7511. {
  7512. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7513. UnicodeString Ext;
  7514. if (DirView == RemoteDirView)
  7515. {
  7516. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7517. }
  7518. else
  7519. {
  7520. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7521. }
  7522. if (SameText(Ext, Configuration->PartialExt))
  7523. {
  7524. Indexes |= oiPartial;
  7525. }
  7526. }
  7527. //---------------------------------------------------------------------------
  7528. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7529. {
  7530. return
  7531. DirViewEnabled(osCurrent) &&
  7532. DirView(osCurrent)->CanPasteFromClipBoard();
  7533. }
  7534. //---------------------------------------------------------------------------
  7535. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7536. {
  7537. bool Result = false;
  7538. if (CanPasteToDirViewFromClipBoard())
  7539. {
  7540. Result = true;
  7541. }
  7542. else
  7543. {
  7544. UnicodeString ClipboardText;
  7545. if (NonEmptyTextFromClipboard(ClipboardText))
  7546. {
  7547. if (StoredSessions->IsUrl(ClipboardText))
  7548. {
  7549. Result = true;
  7550. }
  7551. else
  7552. {
  7553. Result = DirViewEnabled(osCurrent);
  7554. }
  7555. }
  7556. }
  7557. return Result;
  7558. }
  7559. //---------------------------------------------------------------------------
  7560. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7561. {
  7562. if (DoesClipboardContainOurFiles())
  7563. {
  7564. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7565. {
  7566. TTerminalManager * Manager = TTerminalManager::Instance();
  7567. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7568. Manager->ActiveTerminal = FClipboardTerminal;
  7569. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7570. }
  7571. }
  7572. else if (CanPasteToDirViewFromClipBoard())
  7573. {
  7574. DirView(osCurrent)->PasteFromClipBoard();
  7575. }
  7576. else
  7577. {
  7578. UnicodeString ClipboardText;
  7579. if (NonEmptyTextFromClipboard(ClipboardText))
  7580. {
  7581. if (StoredSessions->IsUrl(ClipboardText))
  7582. {
  7583. NewSession(false, ClipboardText);
  7584. }
  7585. else
  7586. {
  7587. DirView(osCurrent)->Path = ClipboardText;
  7588. }
  7589. }
  7590. }
  7591. }
  7592. //---------------------------------------------------------------------------
  7593. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7594. {
  7595. // TBD
  7596. }
  7597. //---------------------------------------------------------------------------
  7598. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7599. {
  7600. TCustomDirView * ADirView = DirView(Side);
  7601. ADirView->SelectAll(Mode);
  7602. ADirView->SetFocus();
  7603. }
  7604. //---------------------------------------------------------------------------
  7605. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7606. {
  7607. TCustomDirView * ADirView = DirView(Side);
  7608. TFileFilter Filter;
  7609. DefaultFileFilter(Filter);
  7610. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7611. {
  7612. Configuration->Usage->Inc(L"MaskSelections");
  7613. ADirView->SelectFiles(Filter, Select);
  7614. ADirView->SetFocus();
  7615. }
  7616. }
  7617. //---------------------------------------------------------------------------
  7618. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7619. {
  7620. TCustomDirView * ADirView = DirView(Side);
  7621. ADirView->RestoreSelectedNames();
  7622. ADirView->SetFocus();
  7623. }
  7624. //---------------------------------------------------------------------------
  7625. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7626. {
  7627. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7628. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7629. {
  7630. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7631. UnicodeString Ext;
  7632. if (GetSide(osCurrent) == osRemote)
  7633. {
  7634. Ext = UnixExtractFileExt(FileName);
  7635. }
  7636. else
  7637. {
  7638. Ext = ExtractFileExt(FileName);
  7639. }
  7640. if (Ext.IsEmpty())
  7641. {
  7642. Ext = L".";
  7643. }
  7644. TFileFilter Filter;
  7645. Filter.Masks = FORMAT(L"*%s", (Ext));
  7646. Filter.Directories = false;
  7647. CurrentDirView->SelectFiles(Filter, Select);
  7648. }
  7649. }
  7650. //---------------------------------------------------------------------------
  7651. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7652. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7653. {
  7654. UnicodeString Result;
  7655. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7656. {
  7657. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7658. }
  7659. else if ((Side == osRemote) && (Terminal == NULL))
  7660. {
  7661. // noop
  7662. }
  7663. else
  7664. {
  7665. Result =
  7666. FMTLOAD(FILE_INFO_FORMAT,
  7667. (FormatBytes(FileInfo.SelectedSize),
  7668. FormatBytes(FileInfo.FilesSize),
  7669. FormatNumber(FileInfo.SelectedCount),
  7670. FormatNumber(FileInfo.FilesCount)));
  7671. }
  7672. return Result;
  7673. }
  7674. //---------------------------------------------------------------------------
  7675. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7676. TTBXStatusPanel * Panel, TOperationSide Side)
  7677. {
  7678. if (Panel->Index == 1)
  7679. {
  7680. ToggleShowHiddenFiles();
  7681. }
  7682. else if (Panel->Index == 2)
  7683. {
  7684. Filter(Side);
  7685. }
  7686. }
  7687. //---------------------------------------------------------------------------
  7688. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7689. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7690. {
  7691. DebugAssert(!StatusBar->SimplePanel);
  7692. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7693. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7694. }
  7695. //---------------------------------------------------------------------------
  7696. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7697. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7698. {
  7699. DebugAssert(StatusBar->Panels->Count >= 3);
  7700. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7701. if (FileInfo.HiddenCount > 0)
  7702. {
  7703. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7704. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7705. }
  7706. else
  7707. {
  7708. HiddenFilesPanel->ViewPriority = 0;
  7709. // not really necessary, just to cleanup no-longer-valid data
  7710. HiddenFilesPanel->Caption = L"";
  7711. }
  7712. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7713. if (FileInfo.FilteredCount > 0)
  7714. {
  7715. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7716. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7717. }
  7718. else
  7719. {
  7720. FilteredFilesPanel->ViewPriority = 0;
  7721. // not really necessary, just to cleanup no-longer-valid data
  7722. FilteredFilesPanel->Caption = L"";
  7723. }
  7724. }
  7725. //---------------------------------------------------------------------------
  7726. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7727. TObject * /*Sender*/)
  7728. {
  7729. if (RemoteDirView->Enabled)
  7730. {
  7731. RemoteDirView->SetFocus();
  7732. }
  7733. }
  7734. //---------------------------------------------------------------------------
  7735. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7736. {
  7737. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7738. switch (Config.Show)
  7739. {
  7740. case qvShow:
  7741. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7742. {
  7743. Config.Show = qvHide;
  7744. }
  7745. else
  7746. {
  7747. Config.Show = Config.LastHideShow;
  7748. }
  7749. break;
  7750. case qvHideWhenEmpty:
  7751. if (ComponentVisible[fcQueueView])
  7752. {
  7753. Config.Show = qvHide;
  7754. }
  7755. else
  7756. {
  7757. Config.LastHideShow = Config.Show;
  7758. Config.Show = qvShow;
  7759. }
  7760. break;
  7761. case qvHide:
  7762. Config.LastHideShow = Config.Show;
  7763. Config.Show = qvShow;
  7764. break;
  7765. }
  7766. WinConfiguration->QueueView = Config;
  7767. }
  7768. //---------------------------------------------------------------------------
  7769. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7770. {
  7771. UnicodeString Result;
  7772. if (FTerminal != NULL)
  7773. {
  7774. switch (WinConfiguration->PathInCaption)
  7775. {
  7776. case picShort:
  7777. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  7778. break;
  7779. case picFull:
  7780. Result = FTerminal->CurrentDirectory;
  7781. break;
  7782. }
  7783. }
  7784. return Result;
  7785. }
  7786. //---------------------------------------------------------------------------
  7787. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  7788. {
  7789. TColor Result = GetWindowColor(FSessionColor);
  7790. return Result;
  7791. }
  7792. //---------------------------------------------------------------------------
  7793. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  7794. {
  7795. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  7796. return Result;
  7797. }
  7798. //---------------------------------------------------------------------------
  7799. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7800. {
  7801. TTerminalManager::Instance()->UpdateAppTitle();
  7802. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7803. // background to gray on Windows 7 (works on Windows 10).
  7804. // See also EnableControl
  7805. if (Showing)
  7806. {
  7807. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  7808. if (HasTerminal)
  7809. {
  7810. // Update path when it changes
  7811. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  7812. {
  7813. UpdateSessionTab(SessionsPageControl->ActivePage);
  7814. }
  7815. if (!RemoteDirView->Enabled)
  7816. {
  7817. RemoteDirView->Enabled = true;
  7818. if (FRemoteDirViewWasFocused)
  7819. {
  7820. ActiveControl = RemoteDirView;
  7821. }
  7822. }
  7823. RemoteDirView->Color = PanelColor();
  7824. }
  7825. else
  7826. {
  7827. if (RemoteDirView->Enabled)
  7828. {
  7829. // This is first called when the form is being constructed
  7830. // (not anymore due to Showing test above)
  7831. // but the false is overriden in the constructor later.
  7832. // An even later in TScpCommanderForm::DoShow()
  7833. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7834. RemoteDirView->Enabled = false;
  7835. RemoteDirView->Color = DisabledPanelColor();
  7836. }
  7837. }
  7838. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  7839. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  7840. RemoteDriveView->Color = RemoteDirView->Color;
  7841. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  7842. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fsBackgroundTransfers];
  7843. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  7844. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  7845. QueueLabelUpdateStatus();
  7846. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  7847. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  7848. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7849. }
  7850. }
  7851. //---------------------------------------------------------------------------
  7852. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7853. {
  7854. UpdateControls();
  7855. }
  7856. //---------------------------------------------------------------------------
  7857. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7858. TObject * Sender)
  7859. {
  7860. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7861. DebugAssert(DirView != NULL);
  7862. DoDirViewLoaded(DirView);
  7863. TransferPresetAutoSelect();
  7864. }
  7865. //---------------------------------------------------------------------------
  7866. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7867. {
  7868. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7869. // first run after installation
  7870. if (double(Updates.LastCheck) == 0)
  7871. {
  7872. // make sure next time there will be an update (if enabled)
  7873. Updates.LastCheck = TDateTime(1);
  7874. WinConfiguration->Updates = Updates;
  7875. }
  7876. else if ((double(Updates.Period) > 0) &&
  7877. (Now() - Updates.LastCheck >= Updates.Period))
  7878. {
  7879. TThreadMethod OnUpdatesChecked = NULL;
  7880. if (!IsUWP())
  7881. {
  7882. OnUpdatesChecked = UpdatesChecked;
  7883. }
  7884. StartUpdateThread(OnUpdatesChecked);
  7885. }
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7889. {
  7890. UnicodeString Message;
  7891. bool New;
  7892. TQueryType Type;
  7893. GetUpdatesMessage(Message, New, Type, false);
  7894. if (!Message.IsEmpty())
  7895. {
  7896. if (New)
  7897. {
  7898. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7899. }
  7900. if (!New && (Type != qtWarning))
  7901. {
  7902. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7903. }
  7904. else
  7905. {
  7906. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7907. }
  7908. if (New)
  7909. {
  7910. Configuration->Usage->Inc(L"UpdateNotifications");
  7911. }
  7912. }
  7913. }
  7914. //---------------------------------------------------------------------------
  7915. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7916. {
  7917. RestoreApp();
  7918. bool CanDisplay = !NonVisualDataModule->Busy;
  7919. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7920. {
  7921. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7922. }
  7923. if (CanDisplay)
  7924. {
  7925. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7926. CheckForUpdates(true);
  7927. }
  7928. else
  7929. {
  7930. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7931. }
  7932. }
  7933. //---------------------------------------------------------------------------
  7934. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7935. TCopyParamRuleData & Data)
  7936. {
  7937. DebugAssert(Terminal != NULL);
  7938. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7939. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7940. Data.RemoteDirectory = RemoteDirView->PathName;
  7941. }
  7942. //---------------------------------------------------------------------------
  7943. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7944. {
  7945. // Terminal can be null when we are changing local directory implicitly,
  7946. // because it has been deleted, while no session is connected
  7947. // (Login dialog is open)
  7948. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7949. {
  7950. TCopyParamRuleData Data;
  7951. GetTransferPresetAutoSelectData(Data);
  7952. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7953. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7954. if (CopyParamIndex < 0)
  7955. {
  7956. // there is no preset that matches autoselection
  7957. // set preset that we consider "default"
  7958. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7959. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7960. }
  7961. else
  7962. {
  7963. // there is preset matching autoselection
  7964. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7965. if (CopyParamName == FCopyParamAutoSelected)
  7966. {
  7967. // autoselected the same preset as the last time
  7968. // make no change (i.e. preserve custom user preset, if any)
  7969. }
  7970. else
  7971. {
  7972. // autoselected the different preset then the last time (or there
  7973. // was default preset set)
  7974. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7975. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7976. }
  7977. }
  7978. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7979. {
  7980. if (CopyParamIndex >= 0)
  7981. {
  7982. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7983. }
  7984. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7985. try
  7986. {
  7987. int Fmt =
  7988. (CopyParamIndex < 0) ?
  7989. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7990. COPY_PARAM_AUTOSELECTED;
  7991. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7992. Data->Message = MainInstructions(Message);
  7993. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7994. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7995. CopyParamAttrs);
  7996. if (CopyParamIndex >= 0)
  7997. {
  7998. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7999. Info = FORMAT(L"%s\n \n%s", (Info,
  8000. FMTLOAD(COPY_PARAM_RULE,
  8001. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8002. }
  8003. Data->Message += L"\n\n" + Info;
  8004. if (WinConfiguration->CopyParamAutoSelectNotice)
  8005. {
  8006. TransferPresetNoteMessage(Data, true);
  8007. }
  8008. else
  8009. {
  8010. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8011. Data = NULL; // ownership passed
  8012. }
  8013. }
  8014. __finally
  8015. {
  8016. delete Data;
  8017. }
  8018. }
  8019. }
  8020. }
  8021. //---------------------------------------------------------------------------
  8022. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8023. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8024. {
  8025. DebugAssert(NoteData != NULL);
  8026. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8027. TQueryButtonAlias Aliases[1];
  8028. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8029. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8030. Params.Aliases = Aliases;
  8031. Params.AliasesCount = LENOF(Aliases);
  8032. unsigned int Result =
  8033. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8034. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8035. switch (Result)
  8036. {
  8037. case qaNeverAskAgain:
  8038. DebugAssert(AllowNeverAskAgain);
  8039. WinConfiguration->CopyParamAutoSelectNotice = false;
  8040. break;
  8041. case qaIgnore:
  8042. PreferencesDialog(pmPresets);
  8043. break;
  8044. }
  8045. }
  8046. //---------------------------------------------------------------------------
  8047. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8048. {
  8049. // as of now useless, as this is used for notes only, never for balloons, ...
  8050. RestoreApp();
  8051. // .. and we should never be busy here
  8052. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8053. {
  8054. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8055. }
  8056. }
  8057. //---------------------------------------------------------------------------
  8058. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8059. TPreferencesMode APreferencesMode)
  8060. {
  8061. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8062. TCopyParamRuleData Data;
  8063. if (Terminal != NULL)
  8064. {
  8065. PreferencesData.reset(new TPreferencesDialogData());
  8066. GetTransferPresetAutoSelectData(Data);
  8067. PreferencesData->CopyParamRuleData = &Data;
  8068. }
  8069. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8070. }
  8071. //---------------------------------------------------------------------------
  8072. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8073. const TCustomCommandType & Command)
  8074. {
  8075. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8076. {
  8077. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8078. }
  8079. }
  8080. //---------------------------------------------------------------------------
  8081. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8082. {
  8083. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8084. TCustomCommandType Command;
  8085. // make sure we use local custom command when remote are not supported
  8086. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8087. {
  8088. Command = FLastCustomCommand;
  8089. }
  8090. else
  8091. {
  8092. Command.Params = Command.Params | ccLocal;
  8093. }
  8094. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8095. FEditingFocusedAdHocCommand = OnFocused;
  8096. bool LocalSide = (FCurrentSide == osLocal);
  8097. int Options =
  8098. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8099. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8100. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8101. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8102. {
  8103. FLastCustomCommand = Command;
  8104. UpdateCustomCommandsToolbar();
  8105. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8106. }
  8107. }
  8108. //---------------------------------------------------------------------------
  8109. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8110. {
  8111. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8112. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8113. DebugAssert(State > 0);
  8114. if (State <= 0)
  8115. {
  8116. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8117. }
  8118. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8119. }
  8120. //---------------------------------------------------------------------------
  8121. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8122. TCustomCommandType & Command, int & State)
  8123. {
  8124. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8125. if (Result)
  8126. {
  8127. Command = FLastCustomCommand;
  8128. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8129. }
  8130. return Result;
  8131. }
  8132. //---------------------------------------------------------------------------
  8133. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8134. {
  8135. ResetIncrementalSearch();
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8139. {
  8140. DebugAssert(ComponentVisible[Component]);
  8141. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8142. }
  8143. //---------------------------------------------------------------------------
  8144. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8145. {
  8146. // when queue panel is resized here directly, the status bar is stretched
  8147. // over whole space the panel occupied
  8148. PostComponentHide(fcQueueView);
  8149. }
  8150. //---------------------------------------------------------------------------
  8151. void __fastcall TCustomScpExplorerForm::WMWinIniChange(TMessage & Message)
  8152. {
  8153. WinConfiguration->ResetSysDarkTheme();
  8154. ConfigurationChanged();
  8155. ConfigureInterface();
  8156. TForm::Dispatch(&Message);
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8160. {
  8161. TMessage * M = static_cast<TMessage*>(Message);
  8162. switch (M->Msg)
  8163. {
  8164. case CM_DIALOGCHAR:
  8165. CMDialogChar(*M);
  8166. break;
  8167. case WM_APPCOMMAND:
  8168. WMAppCommand(*M);
  8169. break;
  8170. case WM_SYSCOMMAND:
  8171. WMSysCommand(*M);
  8172. break;
  8173. case WM_QUERYENDSESSION:
  8174. WMQueryEndSession(*M);
  8175. break;
  8176. case WM_ENDSESSION:
  8177. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8178. break;
  8179. #ifdef _DEBUG
  8180. case WM_WINDOWPOSCHANGED:
  8181. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8182. break;
  8183. case CM_CUSTOMSTYLECHANGED:
  8184. TForm::Dispatch(Message);
  8185. break;
  8186. #endif
  8187. case WM_COMPONENT_HIDE:
  8188. {
  8189. Byte Component = static_cast<Byte>(M->WParam);
  8190. // sanity check
  8191. if (ComponentVisible[Component])
  8192. {
  8193. // special treatment
  8194. if (Component == fcQueueView)
  8195. {
  8196. ToggleQueueVisibility();
  8197. DebugAssert(!ComponentVisible[fcQueueView]);
  8198. }
  8199. else
  8200. {
  8201. ComponentVisible[Component] = false;
  8202. }
  8203. }
  8204. }
  8205. break;
  8206. case WM_COPYDATA:
  8207. WMCopyData(*M);
  8208. break;
  8209. case WM_MANAGES_CAPTION:
  8210. // caption managed in TTerminalManager::UpdateAppTitle()
  8211. M->Result = 1;
  8212. break;
  8213. case WM_WANTS_MOUSEWHEEL:
  8214. M->Result = 1;
  8215. break;
  8216. case CM_SHOWINGCHANGED:
  8217. CMShowingChanged(*M);
  8218. break;
  8219. case WM_CLOSE:
  8220. WMClose(*M);
  8221. break;
  8222. case WM_DPICHANGED:
  8223. WMDpiChanged(*M);
  8224. break;
  8225. case CM_DPICHANGED:
  8226. CMDpiChanged(*M);
  8227. break;
  8228. case WM_WININICHANGE:
  8229. WMWinIniChange(*M);
  8230. break;
  8231. case CM_DIALOGKEY:
  8232. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8233. break;
  8234. default:
  8235. TForm::Dispatch(Message);
  8236. break;
  8237. }
  8238. }
  8239. //---------------------------------------------------------------------------
  8240. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8241. {
  8242. // noop
  8243. }
  8244. //---------------------------------------------------------------------------
  8245. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8246. {
  8247. TForm::Dispatch(&Message);
  8248. FSessionColors->Clear();
  8249. AddFixedSessionImages();
  8250. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8251. UpdateImages();
  8252. }
  8253. //---------------------------------------------------------------------------
  8254. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8255. {
  8256. TForm::Dispatch(&Message);
  8257. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8258. UpdatePixelsPerInchMainWindowCounter();
  8259. }
  8260. //---------------------------------------------------------------------------
  8261. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8262. {
  8263. // Cannot close window while we are busy.
  8264. // We cannot test this in FormCloseQuery as that is called also from
  8265. // Close(), which is called by CloseApplicationAction. So we can be busy
  8266. // there already even, when it is legitimate to close the application.
  8267. // Possibly a better place to handle this would be WMSysCommand.
  8268. if (NonVisualDataModule->Busy)
  8269. {
  8270. Message.Result = 1;
  8271. }
  8272. else
  8273. {
  8274. TForm::Dispatch(&Message);
  8275. }
  8276. }
  8277. //---------------------------------------------------------------------------
  8278. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8279. {
  8280. TForm::Dispatch(&Message);
  8281. if (Showing && (Terminal == NULL))
  8282. {
  8283. // When we are starting minimized (i.e. from an installer),
  8284. // postpone showing Login dialog until we get restored.
  8285. // Otherwise the Login dialog (and Authentication window) show restored
  8286. // over invidible (minimized) main window.
  8287. if (WindowState == wsMinimized)
  8288. {
  8289. FNeedSession = true;
  8290. }
  8291. else
  8292. {
  8293. // This happens before application ever goes idle, so the toolbars would
  8294. // stay enabled (initial state) until the Login dialog is dismissed.
  8295. UpdateActions();
  8296. NonVisualDataModule->StartBusy();
  8297. try
  8298. {
  8299. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8300. // otherwise the dialog does not receive focus.
  8301. // With Commander interface the ProcessMessages is called already
  8302. // by TDriveView, but with Explorer interface, we need to call it explicily
  8303. Application->ProcessMessages();
  8304. // do not reload sessions, they have been loaded just now (optimization)
  8305. NeedSession(false);
  8306. }
  8307. __finally
  8308. {
  8309. NonVisualDataModule->EndBusy();
  8310. }
  8311. }
  8312. }
  8313. }
  8314. //---------------------------------------------------------------------------
  8315. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8316. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8317. int & MaxHeight)
  8318. {
  8319. // workaround for bug in TWinControl.CalcConstraints
  8320. // Check for empty rect (restore from iconic state) is done there only after
  8321. // call to AdjustClientRect, which enlarges the rect (for forms).
  8322. TRect R = GetClientRect();
  8323. // when restoring from iconic state, place no restrictions
  8324. if (IsRectEmpty(R))
  8325. {
  8326. MinWidth = 0;
  8327. MinHeight = 0;
  8328. MaxWidth = 32000;
  8329. MaxHeight = 32000;
  8330. }
  8331. }
  8332. //---------------------------------------------------------------------------
  8333. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8334. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8335. {
  8336. // terminal can be already closed (e.g. dropped connection)
  8337. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8338. {
  8339. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8340. try
  8341. {
  8342. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8343. }
  8344. catch(...)
  8345. {
  8346. if (!Terminal->Active)
  8347. {
  8348. Close = true;
  8349. }
  8350. throw;
  8351. }
  8352. }
  8353. }
  8354. //---------------------------------------------------------------------------
  8355. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8356. {
  8357. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8358. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8359. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8360. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8361. {
  8362. OnGetSpaceAvailable = GetSpaceAvailable;
  8363. }
  8364. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8365. OnGetSpaceAvailable);
  8366. }
  8367. //---------------------------------------------------------------------------
  8368. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8369. {
  8370. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8371. Terminal->FillSessionDataForCode(Data.get());
  8372. return Data.release();
  8373. }
  8374. //---------------------------------------------------------------------------
  8375. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8376. {
  8377. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8378. DoGenerateUrlDialog(Data.get(), Paths);
  8379. }
  8380. //---------------------------------------------------------------------------
  8381. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8382. {
  8383. GenerateUrl(NULL);
  8384. }
  8385. //---------------------------------------------------------------------------
  8386. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8387. {
  8388. std::unique_ptr<TStrings> Paths(new TStringList());
  8389. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8390. GenerateUrl(Paths.get());
  8391. }
  8392. //---------------------------------------------------------------------------
  8393. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8394. {
  8395. FSessionColor = value;
  8396. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8397. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8398. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8399. DebugAssert(ColorItem != NULL);
  8400. ColorItem->Color = C;
  8401. NonVisualDataModule->ColorMenuItem->Color = C;
  8402. UpdateControls();
  8403. }
  8404. //---------------------------------------------------------------------------
  8405. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8406. {
  8407. if (value != FSessionColor)
  8408. {
  8409. UpdateSessionColor(value);
  8410. // Is null when called from LastTerminalClosed
  8411. if (Terminal != NULL)
  8412. {
  8413. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8414. }
  8415. }
  8416. }
  8417. //---------------------------------------------------------------------------
  8418. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8419. {
  8420. bool Result = FNoteTimer->Enabled;
  8421. if (Result)
  8422. {
  8423. // cannot cancel note too early
  8424. bool NotEarly =
  8425. (Now() - FNoteShown >
  8426. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8427. if (Force || NotEarly)
  8428. {
  8429. FNoteTimer->Enabled = false;
  8430. FNote = L"";
  8431. SAFE_DESTROY(FNoteData);
  8432. FOnNoteClick = NULL;
  8433. FNoteHints = FNotes->Text;
  8434. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8435. UpdateStatusBar();
  8436. }
  8437. }
  8438. return Result;
  8439. }
  8440. //---------------------------------------------------------------------------
  8441. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8442. {
  8443. DebugAssert(FNoteTimer->Enabled);
  8444. CancelNote(true);
  8445. }
  8446. //---------------------------------------------------------------------------
  8447. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8448. {
  8449. int P = Note.Pos(L"\n");
  8450. if (P > 0)
  8451. {
  8452. Note.SetLength(P - 1);
  8453. }
  8454. FNotes->Add(FORMAT(L"[%s] %s",
  8455. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8456. while (FNotes->Count > 10)
  8457. {
  8458. FNotes->Delete(0);
  8459. }
  8460. if (UpdateNow)
  8461. {
  8462. FNoteHints = FNotes->Text;
  8463. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8464. UpdateStatusBar();
  8465. }
  8466. }
  8467. //---------------------------------------------------------------------------
  8468. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8469. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8470. {
  8471. int P = Note.Pos(L"\n");
  8472. if (P > 0)
  8473. {
  8474. Note.SetLength(P - 1);
  8475. }
  8476. FNoteHints = FNotes->Text;
  8477. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8478. FNote = Note;
  8479. SAFE_DESTROY(FNoteData);
  8480. FNoteData = NoteData;
  8481. FOnNoteClick = OnNoteClick;
  8482. AddNote(Note, false);
  8483. UpdateStatusBar();
  8484. FNoteShown = Now();
  8485. FNoteTimer->Enabled = false;
  8486. if (Seconds == 0)
  8487. {
  8488. Seconds = WinConfiguration->NotificationsTimeout;
  8489. }
  8490. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8491. FNoteTimer->Enabled = true;
  8492. }
  8493. //---------------------------------------------------------------------------
  8494. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8495. {
  8496. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8497. }
  8498. //---------------------------------------------------------------------------
  8499. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8500. {
  8501. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8502. {
  8503. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8504. }
  8505. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8506. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8507. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8508. 0, NULL, NULL);
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8512. {
  8513. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8514. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8515. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8516. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8517. }
  8518. //---------------------------------------------------------------------------
  8519. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8520. {
  8521. WinConfiguration->FormatSizeBytes = Style;
  8522. }
  8523. //---------------------------------------------------------------------------
  8524. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8525. {
  8526. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8527. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8528. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8529. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8530. }
  8531. //---------------------------------------------------------------------------
  8532. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8533. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8534. {
  8535. if (Panel->Index == 0)
  8536. {
  8537. if (FOnNoteClick != NULL)
  8538. {
  8539. // prevent the user data from being freed by possible call
  8540. // to CancelNote or PostNote during call to OnNoteClick
  8541. std::unique_ptr<TObject> NoteData(FNoteData);
  8542. TNotifyEvent OnNoteClick = FOnNoteClick;
  8543. FNoteData = NULL;
  8544. // need to cancel the note as we are going to delete its user data
  8545. CancelNote(true);
  8546. OnNoteClick(NoteData.get());
  8547. }
  8548. }
  8549. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8550. {
  8551. FileSystemInfo();
  8552. }
  8553. }
  8554. //---------------------------------------------------------------------------
  8555. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8556. {
  8557. // workaround:
  8558. // 1) for unknown reason, disabling window, while minimized,
  8559. // prevents it from restoring, even if it was enabled again meanwhile
  8560. // 2) when disabling the main window, while another has focus
  8561. // minimize is no longer possible
  8562. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8563. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8564. // Shouldn't we use IsApplicationMinimized() here?
  8565. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8566. {
  8567. Enabled = false;
  8568. }
  8569. FLockLevel++;
  8570. }
  8571. //---------------------------------------------------------------------------
  8572. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8573. {
  8574. DebugAssert(FLockLevel > 0);
  8575. FLockLevel--;
  8576. if (FLockLevel == 0)
  8577. {
  8578. DebugAssert(FLockSuspendLevel == 0);
  8579. Enabled = true;
  8580. }
  8581. }
  8582. //---------------------------------------------------------------------------
  8583. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8584. {
  8585. // We need to make sure that window is enabled when the last modal window closes
  8586. // otherwise focus is not restored correctly.
  8587. // So we re-enable the window when modal window opens and
  8588. // disable it back after is closes
  8589. if (FLockLevel > 0)
  8590. {
  8591. // while we have nesting counter, we know that we never be called
  8592. // recursivelly as Application->OnModalBegin is called only
  8593. // for the top-level modal window
  8594. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8595. {
  8596. // won't be disabled when conditions in LockWindow() were not satisfied
  8597. FDisabledOnLockSuspend = !Enabled;
  8598. // When minimized to tray (or actually when set to SW_HIDE),
  8599. // setting Enabled makes the window focusable even when there's
  8600. // modal window over it
  8601. if (!FTrayIcon->Visible)
  8602. {
  8603. Enabled = true;
  8604. }
  8605. }
  8606. FLockSuspendLevel++;
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8611. {
  8612. if (FLockSuspendLevel > 0)
  8613. {
  8614. DebugAssert(FLockLevel > 0);
  8615. FLockSuspendLevel--;
  8616. // see comment in SuspendWindowLock
  8617. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8618. {
  8619. // Note that window can be enabled here, when we were minized to tray when
  8620. // was SuspendWindowLock() called.
  8621. // We should possibly do the same check as in LockWindow(),
  8622. // if it is ever possible that the consitions change between
  8623. // SuspendWindowLock() and ResumeWindowLock()
  8624. Enabled = !FDisabledOnLockSuspend;
  8625. }
  8626. }
  8627. }
  8628. //---------------------------------------------------------------------------
  8629. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8630. {
  8631. if (!TextOnly)
  8632. {
  8633. TTBXComboBoxItem * RemotePathComboBox =
  8634. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8635. TStrings * Items = RemotePathComboBox->Strings;
  8636. Items->BeginUpdate();
  8637. try
  8638. {
  8639. Items->Clear();
  8640. if (Terminal != NULL)
  8641. {
  8642. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8643. while (!IsUnixRootPath(APath))
  8644. {
  8645. int P = APath.LastDelimiter(L'/');
  8646. DebugAssert(P >= 0);
  8647. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8648. APath.SetLength(P - 1);
  8649. }
  8650. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8651. }
  8652. }
  8653. __finally
  8654. {
  8655. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8656. // Setting ItemIndex to -1 does not reset its text
  8657. if (Items->Count == 0)
  8658. {
  8659. RemotePathComboBox->Text = L"";
  8660. }
  8661. Items->EndUpdate();
  8662. }
  8663. }
  8664. }
  8665. //---------------------------------------------------------------------------
  8666. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8667. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8668. int & ImageIndex)
  8669. {
  8670. if (AIndex < 0)
  8671. {
  8672. AIndex = Sender->ItemIndex;
  8673. }
  8674. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8675. }
  8676. //---------------------------------------------------------------------------
  8677. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8678. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8679. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8680. {
  8681. ARect.Left += (10 * AIndex);
  8682. }
  8683. //---------------------------------------------------------------------------
  8684. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8685. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8686. {
  8687. AWidth += (10 * AIndex);
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8691. TObject * Sender)
  8692. {
  8693. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8694. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8695. int Index = RemotePathComboBox->ItemIndex;
  8696. while (Index < RemotePathComboBox->Strings->Count - 1)
  8697. {
  8698. APath = UnixExtractFileDir(APath);
  8699. Index++;
  8700. }
  8701. // VanDyke style paths
  8702. if (APath.IsEmpty())
  8703. {
  8704. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8705. APath = ROOTDIRECTORY;
  8706. }
  8707. if (RemoteDirView->Path != APath)
  8708. {
  8709. RemoteDirView->Path = APath;
  8710. }
  8711. }
  8712. //---------------------------------------------------------------------------
  8713. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8714. {
  8715. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8716. DebugUsedParam(Sender);
  8717. UpdateRemotePathComboBox(true);
  8718. }
  8719. //---------------------------------------------------------------------------
  8720. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8721. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8722. {
  8723. ResetIncrementalSearch();
  8724. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8725. DebugAssert(DirView != NULL);
  8726. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8727. {
  8728. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8729. // OnEditing is called also from TCustomListView::CanEdit
  8730. if (Edit != NULL)
  8731. {
  8732. EditSelectBaseName(Edit);
  8733. }
  8734. }
  8735. }
  8736. //---------------------------------------------------------------------------
  8737. //---------------------------------------------------------------------------
  8738. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8739. {
  8740. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8741. Result->AutoDetectDnD = false;
  8742. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8743. Result->RenderDataOn = rdoEnterAndDropSync;
  8744. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8745. return Result;
  8746. }
  8747. //---------------------------------------------------------------------------
  8748. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8749. {
  8750. TForm::CreateWnd();
  8751. if (FSessionsDragDropFilesEx == NULL)
  8752. {
  8753. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8754. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8755. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8756. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8757. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8758. }
  8759. if (FQueueDragDropFilesEx == NULL)
  8760. {
  8761. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8762. // No need to set OnDragOver as we do not have any restrictions
  8763. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8764. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8765. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8766. }
  8767. }
  8768. //---------------------------------------------------------------------------
  8769. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8770. {
  8771. TForm::DestroyWnd();
  8772. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8773. FQueueDragDropFilesEx->DragDropControl = NULL;
  8774. }
  8775. //---------------------------------------------------------------------------
  8776. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8777. {
  8778. SideEnter(FCurrentSide);
  8779. FEverShown = true;
  8780. }
  8781. //---------------------------------------------------------------------------
  8782. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8783. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8784. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8785. {
  8786. if (!NonVisualDataModule->Busy)
  8787. {
  8788. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8789. Configuration->Usage->Inc(L"FileFinds");
  8790. LockWindow(true);
  8791. NonVisualDataModule->StartBusy();
  8792. WinConfiguration->LockedInterface = true;
  8793. try
  8794. {
  8795. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8796. }
  8797. __finally
  8798. {
  8799. WinConfiguration->LockedInterface = false;
  8800. NonVisualDataModule->EndBusy();
  8801. UnlockWindow();
  8802. }
  8803. }
  8804. }
  8805. //---------------------------------------------------------------------------
  8806. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8807. {
  8808. if (!NonVisualDataModule->Busy)
  8809. {
  8810. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8811. SetFocus();
  8812. RemoteDirView->Path = UnixExtractFilePath(Path);
  8813. UnicodeString FileName = UnixExtractFileName(Path);
  8814. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  8815. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  8816. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  8817. if (Item == NULL)
  8818. {
  8819. ReloadDirectory(osRemote);
  8820. Item = RemoteDirView->FindFileItem(FileName);
  8821. }
  8822. if (Item != NULL)
  8823. {
  8824. RemoteDirView->ItemFocused = Item;
  8825. RemoteDirView->ItemFocused->MakeVisible(false);
  8826. RemoteDirView->SetFocus();
  8827. }
  8828. }
  8829. }
  8830. //---------------------------------------------------------------------------
  8831. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  8832. {
  8833. bool Result = !NonVisualDataModule->Busy;
  8834. if (Result)
  8835. {
  8836. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8837. }
  8838. return Result;
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8842. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8843. {
  8844. if (CanOperateOnFoundFiles(ATerminal))
  8845. {
  8846. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  8847. FOnFileOperationFinished = OnFileOperationFinished;
  8848. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8849. }
  8850. }
  8851. //---------------------------------------------------------------------------
  8852. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8853. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8854. {
  8855. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8856. }
  8857. //---------------------------------------------------------------------------
  8858. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8859. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8860. {
  8861. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8862. }
  8863. //---------------------------------------------------------------------------
  8864. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  8865. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8866. {
  8867. if (CanOperateOnFoundFiles(ATerminal))
  8868. {
  8869. for (int Index = 0; Index < FileList->Count; Index++)
  8870. {
  8871. UnicodeString FileName = FileList->Strings[Index];
  8872. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  8873. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  8874. OnFileOperationFinished(FileName, true);
  8875. }
  8876. }
  8877. }
  8878. //---------------------------------------------------------------------------
  8879. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8880. {
  8881. FFileFindTerminal = Terminal;
  8882. ShowFileFindDialog(
  8883. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  8884. DoDownloadFoundFiles, DoEditFoundFiles);
  8885. }
  8886. //---------------------------------------------------------------------------
  8887. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8888. {
  8889. FTaskbarList = TaskbarList;
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8893. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8894. {
  8895. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8896. if (Index >= 0)
  8897. {
  8898. if (Button == mbLeft)
  8899. {
  8900. // "Mouse down" is raised only after tab is switched.
  8901. // If switching tab (switching session) takes long enough for user
  8902. // to actually release the button, "mouse down" is still raised,
  8903. // but we do not get "mouse up" event, so dragging is not cancelled,
  8904. // prevent that by not beginning dragging in the first place.
  8905. if (IsKeyPressed(VK_LBUTTON))
  8906. {
  8907. // when user clicks the "+", we get mouse down only after the session
  8908. // is closed, when new session tab is already on X:Y, so dragging
  8909. // starts, prevent that
  8910. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8911. {
  8912. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8913. if (Terminal != NULL)
  8914. {
  8915. SessionsPageControl->BeginDrag(false);
  8916. }
  8917. }
  8918. }
  8919. }
  8920. else if (Button == mbMiddle)
  8921. {
  8922. // ignore middle-click for "New session tab"
  8923. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8924. if (Terminal != NULL)
  8925. {
  8926. CloseSessionTab(Index);
  8927. }
  8928. }
  8929. }
  8930. }
  8931. //---------------------------------------------------------------------------
  8932. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8933. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8934. {
  8935. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8936. // do not allow dropping on the "+" tab
  8937. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8938. if ((TargetTerminal != NULL) &&
  8939. (SessionsPageControl->ActivePage->PageIndex != Index))
  8940. {
  8941. Configuration->Usage->Inc(L"SessionTabMoves");
  8942. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8943. // but we want to actually prevent that to avoid flicker
  8944. SessionsPageControl->ActivePage->PageIndex = Index;
  8945. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8946. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8947. }
  8948. }
  8949. //---------------------------------------------------------------------------
  8950. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8951. TObject * Sender, TObject * Source, int X, int Y,
  8952. TDragState /*State*/, bool & Accept)
  8953. {
  8954. Accept = (Sender == Source);
  8955. if (Accept)
  8956. {
  8957. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8958. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8959. // do not allow dragging to the "+" tab
  8960. Accept = (Terminal != NULL);
  8961. }
  8962. }
  8963. //---------------------------------------------------------------------------
  8964. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8965. const TPoint & Point, int & Effect)
  8966. {
  8967. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8968. if (Index < 0)
  8969. {
  8970. Effect = DROPEFFECT_NONE;
  8971. }
  8972. else
  8973. {
  8974. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8975. // do not allow dropping on the "+" tab
  8976. if (TargetTerminal == NULL)
  8977. {
  8978. Effect = DROPEFFECT_NONE;
  8979. }
  8980. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  8981. {
  8982. Effect = DROPEFFECT_COPY;
  8983. }
  8984. }
  8985. }
  8986. //---------------------------------------------------------------------------
  8987. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8988. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8989. {
  8990. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8991. // do not allow dropping on the "+" tab
  8992. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8993. if (TargetTerminal != NULL)
  8994. {
  8995. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8996. if (!IsFileControl(DropSourceControl, osRemote))
  8997. {
  8998. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8999. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9000. // Why don't we use Terminal->CurrentDirectory directly?
  9001. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9002. // do not force queue, drag drop
  9003. false, true);
  9004. }
  9005. }
  9006. }
  9007. //---------------------------------------------------------------------------
  9008. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9009. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9010. {
  9011. // Downloads are handled in RemoteFileControlDDEnd
  9012. if (!IsFileControl(DropSourceControl, osRemote))
  9013. {
  9014. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9015. Terminal->CurrentDirectory,
  9016. // force queue, drag drop
  9017. true, true);
  9018. }
  9019. }
  9020. //---------------------------------------------------------------------------
  9021. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9022. {
  9023. FShowing = false;
  9024. // Do not save empty workspace
  9025. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9026. {
  9027. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9028. UnicodeString Name = WorkspaceName();
  9029. DoSaveWorkspace(
  9030. Name, DataList.get(),
  9031. !Configuration->DisablePasswordStoring &&
  9032. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9033. WinConfiguration->LastStoredSession = Name;
  9034. }
  9035. }
  9036. //---------------------------------------------------------------------------
  9037. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9038. {
  9039. TManagedTerminal * ManagedTerminal =
  9040. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9041. if (ManagedTerminal != NULL)
  9042. {
  9043. ManagedTerminal->DirectoryLoaded = Now();
  9044. }
  9045. }
  9046. //---------------------------------------------------------------------------
  9047. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9048. TListItem * /*Item*/, bool /*Selected*/)
  9049. {
  9050. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9051. switch (DirView->LastSelectMethod)
  9052. {
  9053. case smKeyboard:
  9054. Configuration->Usage->Inc(L"KeyboardSelections");
  9055. break;
  9056. case smMouse:
  9057. Configuration->Usage->Inc(L"MouseSelections");
  9058. break;
  9059. }
  9060. }
  9061. //---------------------------------------------------------------------------
  9062. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9063. {
  9064. if (Color != 0)
  9065. {
  9066. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9067. }
  9068. else
  9069. {
  9070. return FSessionTabImageIndex;
  9071. }
  9072. }
  9073. //---------------------------------------------------------------------------
  9074. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9075. {
  9076. TPngImageCollectionItem * Item =
  9077. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9078. FSessionColors->AddPng(Item->PngImage);
  9079. return FSessionColors->Count - 1;
  9080. }
  9081. //---------------------------------------------------------------------------
  9082. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9083. {
  9084. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9085. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9086. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9087. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9088. }
  9089. //---------------------------------------------------------------------------
  9090. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9091. {
  9092. for (int Index = 0; Index < Control->ControlCount; Index++)
  9093. {
  9094. TControl * AControl = Control->Controls[Index];
  9095. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9096. if (WinControl != NULL)
  9097. {
  9098. CollectItemsWithTextDisplayMode(WinControl);
  9099. }
  9100. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9101. if (Toolbar != NULL)
  9102. {
  9103. // we care for top-level items only
  9104. TTBCustomItem * Items = Toolbar->Items;
  9105. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9106. {
  9107. TTBCustomItem * Item = Items->Items[ItemIndex];
  9108. if (((Item->DisplayMode == nbdmImageAndText) ||
  9109. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9110. EligibleForImageDisplayMode(Item))
  9111. {
  9112. FItemsWithTextDisplayMode.insert(Item);
  9113. }
  9114. }
  9115. }
  9116. }
  9117. }
  9118. //---------------------------------------------------------------------------
  9119. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9120. {
  9121. return true;
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9125. {
  9126. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9127. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9128. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9129. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9130. bool Result = true;
  9131. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9132. {
  9133. TTBCustomItem * Item = *i;
  9134. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9135. if (Label != NULL)
  9136. {
  9137. // optimization
  9138. if (Label->Visible == SelectiveToolbarText)
  9139. {
  9140. Result = false;
  9141. }
  9142. else
  9143. {
  9144. Label->Visible = SelectiveToolbarText;
  9145. }
  9146. }
  9147. else
  9148. {
  9149. // optimization
  9150. if (Item->DisplayMode == DisplayMode)
  9151. {
  9152. Result = false;
  9153. }
  9154. else
  9155. {
  9156. Item->DisplayMode = DisplayMode;
  9157. }
  9158. }
  9159. ++i;
  9160. }
  9161. if (Result)
  9162. {
  9163. UpdateNewSessionTab();
  9164. }
  9165. return Result;
  9166. }
  9167. //---------------------------------------------------------------------------
  9168. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9169. {
  9170. DebugFail();
  9171. }
  9172. //---------------------------------------------------------------------------
  9173. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9174. {
  9175. // Among other, a lock level is non zero, while directory is being loaded,
  9176. // even when it happens as a result of dirview navigation,
  9177. // i.e. when TNonVisualDataModule is NOT FBusy.
  9178. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9179. // Among other this prevents a panel auto update to occur while
  9180. // directory is changing.
  9181. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9182. }
  9183. //---------------------------------------------------------------------------
  9184. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9185. {
  9186. // While the window is disabled, we still seem to process menu shortcuts at least,
  9187. // so stop it at least here.
  9188. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9189. return
  9190. (Allowed == aaUpdate) ||
  9191. !NonVisualDataModule->Busy;
  9192. }
  9193. //---------------------------------------------------------------------------
  9194. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9195. {
  9196. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9197. }
  9198. //---------------------------------------------------------------------------
  9199. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9200. {
  9201. // This is somewhat redundant to LockWindow() call from
  9202. // TTerminalManager::TerminalReadDirectoryProgress.
  9203. // But disabling window is known not to block keyboard shorcuts
  9204. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9205. if (Busy > 0)
  9206. {
  9207. if (NonVisualDataModule->Busy)
  9208. {
  9209. State = false;
  9210. }
  9211. else
  9212. {
  9213. NonVisualDataModule->StartBusy();
  9214. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9215. LockWindow();
  9216. }
  9217. }
  9218. else if (Busy < 0)
  9219. {
  9220. UnlockWindow();
  9221. NonVisualDataModule->EndBusy();
  9222. }
  9223. else
  9224. {
  9225. State = NonVisualDataModule->Busy;
  9226. }
  9227. }
  9228. //---------------------------------------------------------------------------
  9229. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9230. {
  9231. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9232. // no context menu for "New session tab"
  9233. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9234. {
  9235. SessionsPageControl->ActivePageIndex = Index;
  9236. if (DebugAlwaysTrue(SessionTabSwitched()))
  9237. {
  9238. // copied from TControl.WMContextMenu
  9239. SendCancelMode(SessionsPageControl);
  9240. // explicit popup instead of using PopupMenu property
  9241. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9242. // while connecting yet not-connected session and hence
  9243. // allowing an access to commands over not-completelly connected session
  9244. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9245. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9246. PopupMenu->PopupComponent = SessionsPageControl;
  9247. PopupMenu->Popup(Point.x, Point.y);
  9248. }
  9249. }
  9250. Handled = true;
  9251. }
  9252. //---------------------------------------------------------------------------
  9253. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9254. {
  9255. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9256. }
  9257. //---------------------------------------------------------------------------
  9258. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9259. {
  9260. Configuration->Usage->Inc(L"PasswordChanges");
  9261. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9262. ChangePasswordData->DisableAuthentationsExceptPassword();
  9263. ChangePasswordData->ChangePassword = true;
  9264. std::unique_ptr<TTerminal> ChangePasswordSession(
  9265. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9266. ChangePasswordSession->AutoReadDirectory = false;
  9267. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9268. {
  9269. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9270. }
  9271. else
  9272. {
  9273. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9274. }
  9275. }
  9276. //---------------------------------------------------------------------------
  9277. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9278. {
  9279. // No nice way to assert SSH2
  9280. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9281. }
  9282. //---------------------------------------------------------------------------
  9283. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9284. {
  9285. TOperationVisualizer OperationVisualizer;
  9286. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9287. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9288. }
  9289. //---------------------------------------------------------------------------
  9290. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9291. {
  9292. TForm::ChangeScale(M, D);
  9293. int APixelsPerInch = GetControlPixelsPerInch(this);
  9294. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9295. try
  9296. {
  9297. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9298. }
  9299. __finally
  9300. {
  9301. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9302. }
  9303. }
  9304. //---------------------------------------------------------------------------
  9305. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9306. {
  9307. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9308. }
  9309. //---------------------------------------------------------------------
  9310. class TPublicControl : public TControl
  9311. {
  9312. friend class TCustomScpExplorerForm;
  9313. };
  9314. //---------------------------------------------------------------------------
  9315. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9316. {
  9317. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9318. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9319. }
  9320. //---------------------------------------------------------------------------
  9321. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9322. {
  9323. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9324. OpenBookmark(Side, Bookmark);
  9325. }
  9326. //---------------------------------------------------------------------------
  9327. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9328. {
  9329. DoBookmarkClick(osLocal, Sender);
  9330. }
  9331. //---------------------------------------------------------------------------
  9332. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9333. {
  9334. DoBookmarkClick(osRemote, Sender);
  9335. }
  9336. //---------------------------------------------------------------------------
  9337. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9338. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9339. {
  9340. if (BookmarkList != NULL)
  9341. {
  9342. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9343. if (!WinConfiguration->UseLocationProfiles)
  9344. {
  9345. std::unique_ptr<TStringList> Directories(new TStringList());
  9346. Directories->CaseSensitive = (Side == osRemote);
  9347. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9348. {
  9349. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9350. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9351. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9352. {
  9353. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9354. Item->Caption = EscapeHotkey(Directory);
  9355. Item->ShortCut = Bookmark->ShortCut;
  9356. Item->OnClick = OnBookmarkClick;
  9357. Item->Tag = reinterpret_cast<int>(Bookmark);
  9358. Directories->Add(Directory);
  9359. Menu->Add(Item.release());
  9360. }
  9361. }
  9362. }
  9363. else
  9364. {
  9365. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9366. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9367. {
  9368. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9369. if (!Bookmark->Node.IsEmpty())
  9370. {
  9371. Folders->Add(Bookmark->Node);
  9372. }
  9373. }
  9374. for (int Index = 0; Index < Folders->Count; Index++)
  9375. {
  9376. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9377. Item->Caption = Folders->Strings[Index];
  9378. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9379. Folders->Objects[Index] = Item.get();
  9380. Menu->Add(Item.release());
  9381. }
  9382. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9383. {
  9384. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9385. TTBCustomItem * Parent;
  9386. if (!Bookmark->Node.IsEmpty())
  9387. {
  9388. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9389. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9390. }
  9391. else
  9392. {
  9393. Parent = Menu;
  9394. }
  9395. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9396. Item->Caption = Bookmark->Name;
  9397. Item->ShortCut = Bookmark->ShortCut;
  9398. Item->OnClick = OnBookmarkClick;
  9399. Item->Tag = reinterpret_cast<int>(Bookmark);
  9400. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9401. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9402. {
  9403. // No hint for location profiles that are actually mere "bookmarks"
  9404. }
  9405. else
  9406. {
  9407. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9408. UnicodeString LongHint;
  9409. if (!Bookmark->Local.IsEmpty())
  9410. {
  9411. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9412. }
  9413. if (!Bookmark->Remote.IsEmpty())
  9414. {
  9415. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9416. }
  9417. AddToList(Hint, LongHint, L"|");
  9418. Item->Hint = Hint;
  9419. }
  9420. Parent->Add(Item.release());
  9421. }
  9422. }
  9423. AddMenuSeparator(Menu);
  9424. }
  9425. }
  9426. //---------------------------------------------------------------------------
  9427. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9428. {
  9429. Menu->Clear();
  9430. std::unique_ptr<TTBCustomItem> Item;
  9431. Item.reset(new TTBXItem(Owner));
  9432. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9433. Item->Options = Item->Options << tboDefault;
  9434. Menu->Add(Item.release());
  9435. AddMenuSeparator(Menu);
  9436. if (Terminal != NULL)
  9437. {
  9438. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9439. }
  9440. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9441. Item.reset(new TTBXItem(Owner));
  9442. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9443. Menu->Add(Item.release());
  9444. }
  9445. //---------------------------------------------------------------------------
  9446. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9447. {
  9448. bool Result = true;
  9449. try
  9450. {
  9451. if (Side == osRemote)
  9452. {
  9453. Terminal->ExceptionOnFail = true;
  9454. }
  9455. try
  9456. {
  9457. DirView(Side)->Path = Path;
  9458. }
  9459. __finally
  9460. {
  9461. if (Side == osRemote)
  9462. {
  9463. Terminal->ExceptionOnFail = false;
  9464. }
  9465. }
  9466. }
  9467. catch (Exception & E)
  9468. {
  9469. if ((Side != osRemote) || Terminal->Active)
  9470. {
  9471. ShowExtendedExceptionEx(Terminal, &E);
  9472. Result = false;
  9473. }
  9474. else
  9475. {
  9476. throw;
  9477. }
  9478. }
  9479. return Result;
  9480. }
  9481. //---------------------------------------------------------------------------
  9482. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9483. {
  9484. // Make sure there some feedback even when loading tine local folders
  9485. TInstantOperationVisualizer Visualizer;
  9486. DirView(Side)->ReloadDirectory();
  9487. }
  9488. //---------------------------------------------------------------------------
  9489. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9490. {
  9491. if (Index == SessionsPageControl->TabIndex)
  9492. {
  9493. CloseSession();
  9494. }
  9495. else
  9496. {
  9497. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9498. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9499. TTerminalManager * Manager = TTerminalManager::Instance();
  9500. if (!Terminal->Active)
  9501. {
  9502. Manager->FreeTerminal(Terminal);
  9503. }
  9504. else
  9505. {
  9506. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9507. if (CanCloseQueue(Queue))
  9508. {
  9509. Manager->FreeTerminal(Terminal);
  9510. }
  9511. }
  9512. }
  9513. }
  9514. //---------------------------------------------------------------------------
  9515. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9516. {
  9517. CloseSessionTab(Index);
  9518. }
  9519. //---------------------------------------------------------------------------
  9520. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side)
  9521. {
  9522. if (DebugAlwaysTrue(GetSide(Side) == osRemote))
  9523. {
  9524. TInstantOperationVisualizer Visualizer;
  9525. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9526. // before we create a new data object
  9527. ClipboardClear();
  9528. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9529. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9530. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9531. FClipboardFakeMonitors.reset(StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated));
  9532. if (FClipboardDragDropFilesEx.get() == NULL)
  9533. {
  9534. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9535. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9536. }
  9537. FClipboardDragDropFilesEx->FileList->Clear();
  9538. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9539. FClipboardDragDropFilesEx->CopyToClipboard();
  9540. FClipboardTerminal = FTerminal;
  9541. // Need full paths, as cwd can be different once files are pasted
  9542. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(false, true)));
  9543. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9544. {
  9545. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9546. }
  9547. }
  9548. }
  9549. //---------------------------------------------------------------------------
  9550. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9551. {
  9552. if (OpenClipboard(0))
  9553. {
  9554. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9555. CloseClipboard();
  9556. }
  9557. }
  9558. //---------------------------------------------------------------------------
  9559. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9560. {
  9561. return !FClipboardFakeDirectory.IsEmpty();
  9562. }
  9563. //---------------------------------------------------------------------------
  9564. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9565. {
  9566. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9567. FClipboardFakeDirectory = UnicodeString();
  9568. FClipboardTerminal = NULL;
  9569. // Also called in Idle()
  9570. FClipboardFakeMonitors.reset(NULL);
  9571. }
  9572. //---------------------------------------------------------------------------
  9573. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9574. {
  9575. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9576. {
  9577. ClipboardStop();
  9578. }
  9579. }
  9580. //---------------------------------------------------------------------------
  9581. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9582. {
  9583. TTerminalManager * Manager = TTerminalManager::Instance();
  9584. Manager->ActiveTerminal = FClipboardTerminal;
  9585. TTransferOperationParam Params;
  9586. Params.TargetDirectory = TargetDirectory;
  9587. Params.DragDrop = DragDrop;
  9588. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9589. }
  9590. //---------------------------------------------------------------------------
  9591. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9592. {
  9593. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9594. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9595. {
  9596. RemoveDir(ApiPath(FileName));
  9597. if (!NonVisualDataModule->Busy)
  9598. {
  9599. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9600. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9601. }
  9602. }
  9603. }
  9604. //---------------------------------------------------------------------------
  9605. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9606. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9607. {
  9608. TFileMasks::TParams MaskParams;
  9609. MaskParams.Size = Size;
  9610. MaskParams.Modification = Modification;
  9611. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9612. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9613. {
  9614. bool ImplicitMatch;
  9615. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9616. !ImplicitMatch)
  9617. {
  9618. Color = Iter->Color;
  9619. break;
  9620. }
  9621. }
  9622. }
  9623. //---------------------------------------------------------------------------
  9624. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9625. {
  9626. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9627. if (!DirView->IsEditing())
  9628. {
  9629. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9630. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9631. // while searching
  9632. if (Key == VK_BACK)
  9633. {
  9634. if (!FIncrementalSearch.IsEmpty())
  9635. {
  9636. if (FIncrementalSearch.Length() == 1)
  9637. {
  9638. ResetIncrementalSearch();
  9639. }
  9640. else
  9641. {
  9642. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9643. IncrementalSearch(NewText, false, false);
  9644. }
  9645. Key = 0;
  9646. }
  9647. }
  9648. }
  9649. }
  9650. //---------------------------------------------------------------------------
  9651. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9652. {
  9653. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9654. if (!DirView->IsEditing())
  9655. {
  9656. // Filter control sequences.
  9657. // When not searching yet, prefer use of the space for toggling file selection
  9658. // (so we cannot incrementally search for a string starting with a space).
  9659. if ((Key > VK_SPACE) ||
  9660. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9661. {
  9662. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9663. Key = 0;
  9664. }
  9665. }
  9666. }
  9667. //---------------------------------------------------------------------------
  9668. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  9669. {
  9670. if (!FIncrementalSearch.IsEmpty())
  9671. {
  9672. FIncrementalSearch = L"";
  9673. DirView(osCurrent)->UpdateStatusBar();
  9674. }
  9675. }
  9676. //---------------------------------------------------------------------------
  9677. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  9678. {
  9679. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  9680. if (Item == NULL)
  9681. {
  9682. MessageBeep(MB_ICONHAND);
  9683. }
  9684. else
  9685. {
  9686. TCustomDirView * ADirView = DirView(osCurrent);
  9687. {
  9688. TAutoNestingCounter Guard(FIncrementalSearching);
  9689. ADirView->FocusItem(Item);
  9690. if (ADirView->NortonLike == nlOff)
  9691. {
  9692. if ((ADirView->Selected != Item) ||
  9693. (ADirView->SelCount > 1))
  9694. {
  9695. ADirView->ClearSelection();
  9696. ADirView->Selected = Item;
  9697. }
  9698. }
  9699. }
  9700. FIncrementalSearch = Text;
  9701. Item->MakeVisible(false);
  9702. TListItem * NextItem = SearchFile(Text, true, Reverse);
  9703. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  9704. ADirView->UpdateStatusBar();
  9705. }
  9706. }
  9707. //---------------------------------------------------------------------------
  9708. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  9709. {
  9710. int Index = Item->Index;
  9711. if (!Reverse)
  9712. {
  9713. Index++;
  9714. if (Index >= Item->Owner->Count)
  9715. {
  9716. Index = 0;
  9717. }
  9718. }
  9719. else
  9720. {
  9721. Index--;
  9722. if (Index < 0)
  9723. {
  9724. Index = Item->Owner->Count - 1;
  9725. }
  9726. }
  9727. return Item->Owner->Item[Index];
  9728. }
  9729. //---------------------------------------------------------------------------
  9730. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  9731. {
  9732. TCustomDirView * ADirView = DirView(osCurrent);
  9733. if (ADirView->Items->Count == 0)
  9734. {
  9735. return NULL;
  9736. }
  9737. else
  9738. {
  9739. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  9740. TListItem * Item = CurrentItem;
  9741. if (SkipCurrent)
  9742. {
  9743. Item = DebugNotNull(GetNextFile(Item, Reverse));
  9744. }
  9745. while (true)
  9746. {
  9747. bool Matches = false;
  9748. switch (WinConfiguration->PanelSearch)
  9749. {
  9750. case isNameStartOnly:
  9751. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  9752. break;
  9753. case isName:
  9754. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  9755. break;
  9756. case isAll:
  9757. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  9758. int Index = 0;
  9759. while ((Index < ColCount) && !Matches)
  9760. {
  9761. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  9762. if (Visible)
  9763. {
  9764. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  9765. }
  9766. Index++;
  9767. }
  9768. break;
  9769. }
  9770. if (Matches)
  9771. {
  9772. return Item;
  9773. }
  9774. Item = GetNextFile(Item, Reverse);
  9775. if (Item == CurrentItem)
  9776. {
  9777. return NULL;
  9778. }
  9779. }
  9780. }
  9781. }
  9782. //---------------------------------------------------------------------------
  9783. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  9784. {
  9785. ResetIncrementalSearch();
  9786. }
  9787. //---------------------------------------------------------------------------
  9788. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  9789. {
  9790. if (Message.CharCode == VK_TAB)
  9791. {
  9792. if (!FIncrementalSearch.IsEmpty())
  9793. {
  9794. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  9795. bool Reverse = Shift.Contains(ssShift);
  9796. IncrementalSearch(FIncrementalSearch, true, Reverse);
  9797. Message.Result = 1;
  9798. return;
  9799. }
  9800. }
  9801. else if (Message.CharCode == VK_ESCAPE)
  9802. {
  9803. if (!FIncrementalSearch.IsEmpty())
  9804. {
  9805. ResetIncrementalSearch();
  9806. Message.Result = 1;
  9807. return;
  9808. }
  9809. }
  9810. TForm::Dispatch(&Message);
  9811. }
  9812. //---------------------------------------------------------------------------
  9813. void __fastcall TCustomScpExplorerForm::Deactivate()
  9814. {
  9815. TForm::Deactivate();
  9816. // E.g. when switching to an internal editor window
  9817. ResetIncrementalSearch();
  9818. }
  9819. //---------------------------------------------------------------------------
  9820. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  9821. {
  9822. // When switching to another application
  9823. ResetIncrementalSearch();
  9824. }
  9825. //---------------------------------------------------------------------------
  9826. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  9827. {
  9828. ResetIncrementalSearch();
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  9832. {
  9833. if (FIncrementalSearching <= 0)
  9834. {
  9835. ResetIncrementalSearch();
  9836. }
  9837. }
  9838. //---------------------------------------------------------------------------
  9839. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  9840. {
  9841. CountClicksForWindowPrint(this);
  9842. }
  9843. //---------------------------------------------------------------------------