CustomScpExplorer.cpp 362 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004
  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. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  198. FEditorManager = new TEditorManager();
  199. FEditorManager->OnFileChange = ExecutedFileChanged;
  200. FEditorManager->OnFileReload = ExecutedFileReload;
  201. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  202. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  203. FLocalEditors = new TList();
  204. FQueueStatus = NULL;
  205. FQueueStatusSection = new TCriticalSection();
  206. FQueueStatusInvalidated = false;
  207. FQueueItemInvalidated = false;
  208. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. if (!Replaced && Terminal->Active)
  548. {
  549. InitStatusBar();
  550. }
  551. }
  552. UpdateTransferList();
  553. // Update panels Enable state before refreshing the labels
  554. UpdateControls();
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  558. {
  559. if (Queue != value)
  560. {
  561. if (FQueue != NULL)
  562. {
  563. FQueue->OnListUpdate = NULL;
  564. FQueue->OnQueueItemUpdate = NULL;
  565. }
  566. FQueue = value;
  567. if (FQueue != NULL)
  568. {
  569. DebugAssert(FQueue->OnListUpdate == NULL);
  570. FQueue->OnListUpdate = QueueListUpdate;
  571. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  572. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  573. }
  574. QueueChanged();
  575. }
  576. }
  577. //---------------------------------------------------------------------------
  578. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  579. TListItem * Item)
  580. {
  581. if (FQueueActedItem == Item)
  582. {
  583. FQueueActedItem = NULL;
  584. if ((QueueView3->PopupMenu != NULL) &&
  585. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  586. {
  587. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  588. ReleaseCapture();
  589. }
  590. }
  591. if (Item->Data == FPendingQueueActionItem)
  592. {
  593. FPendingQueueActionItem = NULL;
  594. }
  595. }
  596. //---------------------------------------------------------------------------
  597. bool TCustomScpExplorerForm::IsAnythingQueued()
  598. {
  599. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  603. {
  604. {
  605. TGuard Guard(FQueueStatusSection);
  606. FQueueStatusInvalidated = false;
  607. if (FQueue != NULL)
  608. {
  609. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  610. }
  611. }
  612. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  613. {
  614. FMaxQueueLength = FQueueStatus->Count;
  615. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  616. }
  617. {
  618. TAutoFlag Flag(FQueueStatusUpdating);
  619. FQueueController->UpdateQueueStatus(FQueueStatus);
  620. }
  621. UpdateQueueFileList();
  622. SetQueueProgress();
  623. UpdateQueueView();
  624. bool IsEmpty = !IsAnythingQueued();
  625. if (IsEmpty && (Terminal != NULL))
  626. {
  627. TOnceDoneOperation OnceDoneOperation =
  628. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  629. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  630. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  631. {
  632. FQueue->Enabled = false;
  633. }
  634. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  635. {
  636. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  637. }
  638. }
  639. }
  640. //---------------------------------------------------------------------------
  641. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  642. {
  643. UnicodeString Result;
  644. if (FQueueStatus != NULL)
  645. {
  646. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  647. {
  648. TFileOperationProgressType * ProgressData =
  649. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  650. if ((ProgressData != NULL) && ProgressData->InProgress)
  651. {
  652. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  653. }
  654. }
  655. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  656. {
  657. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  658. }
  659. }
  660. return Result;
  661. }
  662. //---------------------------------------------------------------------------
  663. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  664. {
  665. ComponentVisible[fcQueueView] =
  666. (WinConfiguration->QueueView.Show == qvShow) ||
  667. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  668. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::QueueChanged()
  672. {
  673. if (FQueueStatus != NULL)
  674. {
  675. // UpdateFileList implementation relies on the status being recreated when session changes
  676. delete FQueueStatus;
  677. FQueueStatus = NULL;
  678. }
  679. UpdateQueueStatus(true);
  680. }
  681. //---------------------------------------------------------------------------
  682. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  683. {
  684. if (FQueue == Queue)
  685. {
  686. FQueueStatusInvalidated = true;
  687. }
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  691. TQueueItem * Item)
  692. {
  693. if (FQueue == Queue)
  694. {
  695. TGuard Guard(FQueueStatusSection);
  696. // this may be running in parallel with QueueChanged
  697. if (FQueueStatus != NULL)
  698. {
  699. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  700. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  701. {
  702. FRefreshLocalDirectory = (QueueItem == NULL) ||
  703. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  704. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  705. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  706. }
  707. if (QueueItem != NULL)
  708. {
  709. QueueItem->UserData = (void*)true;
  710. FQueueItemInvalidated = true;
  711. }
  712. }
  713. }
  714. }
  715. //---------------------------------------------------------------------------
  716. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  717. {
  718. // during standalone editing, we have no way to see/control queue,
  719. // so we have to always popup prompts automatically
  720. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  721. }
  722. //---------------------------------------------------------------------------
  723. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  724. {
  725. if (FQueueStatus != NULL)
  726. {
  727. bool QueueAutoPopup = IsQueueAutoPopup();
  728. bool NeedRefresh = FQueueController->NeedRefresh();
  729. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  730. FQueueItemInvalidated = false;
  731. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  732. bool Updated = false;
  733. TQueueItemProxy * QueueItem;
  734. bool WasUserAction;
  735. for (int Index = 0; Index < Limit; Index++)
  736. {
  737. bool Update = false;
  738. QueueItem = FQueueStatus->Items[Index];
  739. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  740. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  741. (FPendingQueueActionItem == NULL))
  742. {
  743. FPendingQueueActionItem = QueueItem;
  744. FUserActionTimer->Enabled = true;
  745. }
  746. if ((bool)QueueItem->UserData)
  747. {
  748. QueueItem->UserData = (void*)false;
  749. QueueItem->Update();
  750. Updated = true;
  751. Update = true;
  752. }
  753. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  754. {
  755. Update = true;
  756. }
  757. if (Update)
  758. {
  759. FQueueController->RefreshQueueItem(QueueItem);
  760. }
  761. }
  762. if (Updated)
  763. {
  764. NonVisualDataModule->UpdateNonVisibleActions();
  765. SetQueueProgress();
  766. UpdateQueueFileList();
  767. }
  768. }
  769. }
  770. //---------------------------------------------------------------------------
  771. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  772. {
  773. if (FTaskbarList != NULL)
  774. {
  775. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  776. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  781. {
  782. if (Progress >= 0)
  783. {
  784. if (FTaskbarList != NULL)
  785. {
  786. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  787. }
  788. }
  789. else
  790. {
  791. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  792. }
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  796. {
  797. int OverallProgress;
  798. // FProgressForm is null when this is called from SetQueueProgress
  799. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  800. {
  801. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  802. }
  803. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  804. {
  805. OverallProgress = ProgressData->OverallProgress();
  806. }
  807. else
  808. {
  809. OverallProgress = -1;
  810. }
  811. SetTaskbarListProgressValue(OverallProgress);
  812. }
  813. //---------------------------------------------------------------------------
  814. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  815. {
  816. TTerminalManager::Instance()->QueueStatusUpdated();
  817. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  818. {
  819. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  820. {
  821. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  822. {
  823. TFileOperationProgressType * ProgressData = NULL;
  824. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  825. {
  826. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  827. }
  828. if ((ProgressData != NULL) &&
  829. ProgressData->InProgress)
  830. {
  831. SetTaskbarListProgressValue(ProgressData);
  832. }
  833. else
  834. {
  835. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  836. }
  837. }
  838. else
  839. {
  840. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  841. }
  842. }
  843. else
  844. {
  845. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  846. }
  847. }
  848. UpdateQueueLabel();
  849. }
  850. //---------------------------------------------------------------------------
  851. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  852. {
  853. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  854. if (FQueueStatus != NULL)
  855. {
  856. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  857. if (ActiveAndPendingPrimaryCount > 0)
  858. {
  859. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  860. }
  861. }
  862. QueueLabel->Caption = Caption;
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  866. {
  867. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  868. static_cast<TComponent*>(GetComponent(fcTransferList)));
  869. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  870. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  871. TransferList->Strings->BeginUpdate();
  872. try
  873. {
  874. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  875. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  876. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  877. if (FTransferDropDownHint.IsEmpty())
  878. {
  879. FTransferDropDownHint = TransferDropDown->Hint;
  880. }
  881. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  882. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  883. TransferDropDown->Text = StripHotkey(Name);
  884. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  885. (FTransferDropDownHint, StripHotkey(Name),
  886. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  887. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  888. // update the label, otherwise when it is updated only on the first draw
  889. // of the list, it is drawn "bold" for some reason
  890. FTransferListHoverIndex = TransferList->ItemIndex;
  891. UpdateTransferLabel();
  892. }
  893. __finally
  894. {
  895. TransferList->Strings->EndUpdate();
  896. }
  897. }
  898. //---------------------------------------------------------------------------
  899. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  900. {
  901. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  902. DebugAssert(Toolbar != NULL);
  903. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateActions()
  907. {
  908. TForm::UpdateActions();
  909. if (ComponentVisible[fcCustomCommandsBand])
  910. {
  911. UpdateCustomCommandsToolbar();
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  916. {
  917. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  918. }
  919. //---------------------------------------------------------------------------
  920. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  921. {
  922. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  923. {
  924. DirView->RowSelect = WinConfiguration->FullRowSelect;
  925. // selection is not redrawn automatically when RowSelect changes
  926. DirView->Invalidate();
  927. }
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  931. {
  932. Color = GetBtnFaceColor();
  933. DebugAssert(Configuration && RemoteDirView);
  934. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  935. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  936. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  937. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  938. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  939. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  940. UpdateRowSelect(RemoteDirView);
  941. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  942. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  943. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  944. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  945. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  946. UpdateSessionsPageControlHeight();
  947. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  948. UpdateToolbarDisplayMode();
  949. UpdateTransferList();
  950. if (Terminal != NULL)
  951. {
  952. TransferPresetAutoSelect();
  953. }
  954. UpdateQueueView();
  955. UpdateControls();
  956. // this can be called even before constuctor finishes.
  957. if (FEditorManager != NULL)
  958. {
  959. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  960. }
  961. // this can be called even before constuctor finishes.
  962. if (FLocalEditors != NULL)
  963. {
  964. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  965. {
  966. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  967. }
  968. }
  969. if (ComponentVisible[fcCustomCommandsBand])
  970. {
  971. UpdateCustomCommandsToolbar();
  972. }
  973. // show only when keeping queue items forever,
  974. // otherwise, its enough to have in in the context menu
  975. QueueDeleteAllDoneQueueToolbarItem->Visible =
  976. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  977. if (FFileColorsCurrent != WinConfiguration->FileColors)
  978. {
  979. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  980. FFileColorsCurrent = WinConfiguration->FileColors;
  981. FileColorsChanged();
  982. }
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  986. {
  987. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  988. DirView->Invalidate();
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  992. {
  993. DoFileColorsChanged(RemoteDirView);
  994. }
  995. //---------------------------------------------------------------------------
  996. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  997. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  998. void * /*Arg*/)
  999. {
  1000. if (Token != NULL)
  1001. {
  1002. TForm * Editor = dynamic_cast<TForm*>(Token);
  1003. DebugAssert(Editor != NULL);
  1004. ReconfigureEditorForm(Editor);
  1005. }
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1009. {
  1010. WinConfiguration->DDTransferConfirmation = asOn;
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1014. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1015. {
  1016. // noop
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1020. TTransferDirection Direction, TTransferType Type, bool Temp,
  1021. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1022. bool Confirm, bool DragDrop, int Options)
  1023. {
  1024. bool Result = true;
  1025. DebugAssert(HasActiveTerminal());
  1026. // these parameters are known in advance
  1027. int Params =
  1028. FLAGMASK(Type == ttMove, cpDelete);
  1029. bool ToTemp = (Temp && (Direction == tdToLocal));
  1030. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1031. {
  1032. bool DisableNewerOnly =
  1033. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1034. ToTemp;
  1035. Options |=
  1036. FLAGMASK(ToTemp, coTemp) |
  1037. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1038. coDoNotShowAgain;
  1039. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1040. int CopyParamAttrs = (Direction == tdToRemote ?
  1041. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1042. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1043. int OutputOptions =
  1044. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1045. cooDoNotShowAgain);
  1046. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1047. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1048. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1049. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1050. if (Result)
  1051. {
  1052. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1053. {
  1054. if (DragDrop)
  1055. {
  1056. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1057. {
  1058. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1059. NULL, 0, EnableDDTransferConfirmation, NULL);
  1060. }
  1061. WinConfiguration->DDTransferConfirmation = asOff;
  1062. }
  1063. else
  1064. {
  1065. WinConfiguration->ConfirmTransferring = false;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. // User explicitly unchecked "do not show again",
  1071. // so show him the dialog the next time
  1072. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1073. {
  1074. WinConfiguration->DDTransferConfirmation = asOn;
  1075. }
  1076. }
  1077. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1078. }
  1079. }
  1080. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1081. {
  1082. Configuration->Usage->Inc(L"TransfersOnBackground");
  1083. // these parameter are known only after transfer dialog
  1084. Params |=
  1085. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1086. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1087. Result = false;
  1088. ClearTransferSourceSelection(Direction);
  1089. }
  1090. return Result;
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1094. {
  1095. if (FOnFileOperationFinished != NULL)
  1096. {
  1097. FOnFileOperationFinished(UnicodeString(), true);
  1098. }
  1099. else
  1100. {
  1101. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1102. if (HasDirView[Side])
  1103. {
  1104. DirView(Side)->SelectAll(smNone);
  1105. }
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1110. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1111. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1112. int Params)
  1113. {
  1114. DebugAssert(Queue != NULL);
  1115. bool SingleFile = false;
  1116. if (FileList->Count == 1)
  1117. {
  1118. if (Direction == tdToRemote)
  1119. {
  1120. UnicodeString FileName = FileList->Strings[0];
  1121. SingleFile = FileExists(ApiPath(FileName));
  1122. }
  1123. else
  1124. {
  1125. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1126. SingleFile = !File->IsDirectory;
  1127. }
  1128. }
  1129. TQueueItem * QueueItem;
  1130. if (Direction == tdToRemote)
  1131. {
  1132. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1133. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1134. }
  1135. else
  1136. {
  1137. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. AddQueueItem(Queue, QueueItem, Terminal);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1144. {
  1145. if (Queue->IsEmpty)
  1146. {
  1147. Terminal->QueueOperationStart = Now();
  1148. }
  1149. Queue->AddItem(QueueItem);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1153. {
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::InitControls()
  1157. {
  1158. DebugAssert(FDocks != NULL);
  1159. for (int Index = 0; Index < ComponentCount; Index++)
  1160. {
  1161. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1162. if ((Dock != NULL) && (Dock->Tag == 0))
  1163. {
  1164. FDocks->Add(Dock);
  1165. }
  1166. }
  1167. CollectItemsWithTextDisplayMode(this);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1171. {
  1172. ConfigurationChanged();
  1173. QueuePanel->Height =
  1174. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1175. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1176. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1177. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1178. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1179. QueueFileList->Height =
  1180. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1181. if (QueueFileList->Visible)
  1182. {
  1183. AdjustQueueLayout();
  1184. }
  1185. UpdateCustomCommandsToolbar();
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::StoreParams()
  1189. {
  1190. int APixelsPerInch = GetControlPixelsPerInch(this);
  1191. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1192. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1193. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1194. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1195. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1196. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1197. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1198. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1202. {
  1203. if (!FFormRestored)
  1204. {
  1205. FFormRestored = true;
  1206. RestoreFormParams();
  1207. }
  1208. TForm::CreateParams(Params);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1212. {
  1213. DebugAssert(FDocks != NULL);
  1214. for (int Index = 0; Index < FDocks->Count; Index++)
  1215. {
  1216. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1221. {
  1222. SetDockAllowDrag(true);
  1223. while (!ButtonsStr.IsEmpty())
  1224. {
  1225. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1226. UnicodeString Name = CutToChar(S, L'=', true);
  1227. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1228. {
  1229. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1230. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1231. {
  1232. while (!S.IsEmpty())
  1233. {
  1234. UnicodeString S2 = CutToChar(S, L',', true);
  1235. UnicodeString Name = CutToChar(S2, L':', true);
  1236. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1237. {
  1238. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1239. if (SameText(GetToolbarItemName(Item), Name))
  1240. {
  1241. // forward compatibility
  1242. UnicodeString S3 = CutToChar(S2, L':', true);
  1243. bool Visible = StrToIntDef(S3, 0);
  1244. Item->Visible = Visible;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1252. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1256. {
  1257. UnicodeString Result;
  1258. SetDockAllowDrag(true);
  1259. Result = ::GetToolbarsLayoutStr(this);
  1260. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1261. return Result;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1265. {
  1266. UnicodeString Result;
  1267. if (Item->Action != NULL)
  1268. {
  1269. Result = Item->Action->Name;
  1270. Result = RemoveSuffix(Result, L"Action", true);
  1271. }
  1272. else
  1273. {
  1274. Result = Item->Name;
  1275. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1276. Result = RemoveSuffix(Result, L"Item", true);
  1277. }
  1278. return Result;
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1282. {
  1283. UnicodeString Result;
  1284. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1285. {
  1286. UnicodeString ToolbarStr;
  1287. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1288. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1289. {
  1290. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1291. {
  1292. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1293. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1294. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1295. // and save the changes here only.
  1296. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1297. {
  1298. UnicodeString Name = GetToolbarItemName(Item);
  1299. DebugAssert(Name.Pos(L"TBX") == 0);
  1300. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1301. }
  1302. }
  1303. }
  1304. if (!ToolbarStr.IsEmpty())
  1305. {
  1306. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1307. }
  1308. }
  1309. return Result;
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1313. {
  1314. DebugAssert(FProgressForm == NULL);
  1315. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1316. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1317. FProgressForm->DeleteLocalToRecycleBin =
  1318. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1319. FProgressForm->DeleteRemoteToRecycleBin =
  1320. (Terminal != NULL) &&
  1321. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1322. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1323. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1324. LockWindow();
  1325. // Actually, do not know what hides the progress once the operation finishes
  1326. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1327. SetTaskbarListProgressState(TBPF_NORMAL);
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1331. {
  1332. UnlockWindow();
  1333. SAFE_DESTROY(FProgressForm);
  1334. SetQueueProgress();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1338. TFileOperationProgressType & ProgressData)
  1339. {
  1340. // Download to temporary local directory
  1341. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1342. {
  1343. bool Continue = true;
  1344. FPendingTempSpaceWarn = false;
  1345. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1346. if (!Continue)
  1347. {
  1348. Abort();
  1349. }
  1350. }
  1351. // operation is being executed and we still didn't show up progress form
  1352. if (ProgressData.InProgress && !FProgressForm)
  1353. {
  1354. CreateProgressForm(NULL);
  1355. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1356. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1357. }
  1358. // operation is finished (or terminated), so we hide progress form
  1359. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1360. {
  1361. DestroyProgressForm();
  1362. if (ProgressData.Operation == foCalculateSize)
  1363. {
  1364. // When calculating size before transfer, the abort caused by
  1365. // cancel flag set due to "MoveToQueue" below,
  1366. // is not propagated back to us in ExecuteFileOperation,
  1367. // as it is silently swallowed.
  1368. // So we explicitly (re)throw it here.
  1369. if (FMoveToQueue)
  1370. {
  1371. Abort();
  1372. }
  1373. }
  1374. else
  1375. {
  1376. if ((ProgressData.Cancel == csContinue) &&
  1377. !FAutoOperation)
  1378. {
  1379. OperationComplete(ProgressData.StartTime);
  1380. }
  1381. }
  1382. }
  1383. if (FProgressForm &&
  1384. // Can happen only during synchronization, when ending one of the operations
  1385. ProgressData.InProgress)
  1386. {
  1387. FProgressForm->SetProgressData(ProgressData);
  1388. DebugAssert(ProgressData.InProgress);
  1389. SetTaskbarListProgressValue(&ProgressData);
  1390. if (FProgressForm->Cancel > csContinue)
  1391. {
  1392. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1393. if (FProgressForm->Cancel == csCancelFile)
  1394. {
  1395. FProgressForm->ClearCancel();
  1396. }
  1397. // cancel cancels even the move
  1398. FMoveToQueue = false;
  1399. }
  1400. else if (FProgressForm->MoveToQueue)
  1401. {
  1402. FMoveToQueue = true;
  1403. ProgressData.SetCancelAtLeast(csCancel);
  1404. }
  1405. if ((FTransferResumeList != NULL) &&
  1406. ProgressData.InProgress &&
  1407. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1408. !ProgressData.FullFileName.IsEmpty())
  1409. {
  1410. if ((FTransferResumeList->Count == 0) ||
  1411. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1412. {
  1413. // note that we do not recognize directories from files here
  1414. FTransferResumeList->Add(ProgressData.FullFileName);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1421. const TDateTime & StartTime)
  1422. {
  1423. if (GUIConfiguration->BeepOnFinish &&
  1424. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1425. {
  1426. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1427. DWORD Sound;
  1428. if (!ExtractFileExt(BeepSound).IsEmpty())
  1429. {
  1430. Sound = SND_FILENAME;
  1431. }
  1432. else
  1433. {
  1434. Sound = SND_ALIAS;
  1435. }
  1436. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1437. }
  1438. }
  1439. //---------------------------------------------------------------------------
  1440. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1441. TFileOperationProgressType & ProgressData)
  1442. {
  1443. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1444. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1445. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1446. FileOperationProgress(ProgressData);
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1450. {
  1451. UnicodeString Result;
  1452. if (FProgressForm != NULL)
  1453. {
  1454. Result = FProgressForm->ProgressStr();
  1455. }
  1456. return Result;
  1457. }
  1458. //---------------------------------------------------------------------------
  1459. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1460. bool DragDrop)
  1461. {
  1462. return (!DragDrop && (DropSourceControl == NULL)) ||
  1463. (DropSourceControl == DirView(osOther));
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1467. TFileOperation Operation, TOperationSide Side,
  1468. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1469. TOnceDoneOperation & OnceDoneOperation)
  1470. {
  1471. if (!FAutoOperation)
  1472. {
  1473. // no selection on "/upload", form serves only as event handler
  1474. // (it is not displayed)
  1475. if (PanelOperation(Side, FDragDropOperation) &&
  1476. Visible && (Operation != foCalculateSize) &&
  1477. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1478. {
  1479. if (FOnFileOperationFinished != NULL)
  1480. {
  1481. FOnFileOperationFinished(FileName, Success);
  1482. }
  1483. else
  1484. {
  1485. TOperationSide DViewSide;
  1486. if ((FProgressSide != osCurrent) &&
  1487. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1488. {
  1489. // assume the operation is over the focused panel
  1490. DViewSide = FProgressSide;
  1491. }
  1492. else
  1493. {
  1494. DViewSide = Side;
  1495. }
  1496. TCustomDirView * DView = DirView(DViewSide);
  1497. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1498. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1499. // this can happen when local drive is unplugged in the middle of the operation
  1500. if (Item != NULL)
  1501. {
  1502. if (Success) Item->Selected = false;
  1503. DView->MakeProgressVisible(Item);
  1504. }
  1505. }
  1506. }
  1507. if ((Operation == foCopy) || (Operation == foMove))
  1508. {
  1509. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1510. {
  1511. if (Side == osLocal)
  1512. {
  1513. Configuration->Usage->Inc(L"UploadedFiles");
  1514. }
  1515. else
  1516. {
  1517. Configuration->Usage->Inc(L"DownloadedFiles");
  1518. }
  1519. }
  1520. }
  1521. }
  1522. if (Success && (FSynchronizeController != NULL))
  1523. {
  1524. DebugAssert(!IsSideLocalBrowser(osRemote));
  1525. if (Operation == foCopy)
  1526. {
  1527. DebugAssert(Side == osLocal);
  1528. FSynchronizeController->LogOperation(soUpload, FileName);
  1529. }
  1530. else if (Operation == foDelete)
  1531. {
  1532. DebugAssert(Side == osRemote);
  1533. FSynchronizeController->LogOperation(soDelete, FileName);
  1534. }
  1535. }
  1536. if (FProgressForm)
  1537. {
  1538. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1539. }
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1543. TFileOperation Operation, TOperationSide Side,
  1544. bool Temp, const UnicodeString & FileName, Boolean Success,
  1545. TOnceDoneOperation & OnceDoneOperation)
  1546. {
  1547. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1548. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1549. OnceDoneOperation);
  1550. }
  1551. //---------------------------------------------------------------------------
  1552. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1553. {
  1554. return false;
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1558. {
  1559. return false;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1563. {
  1564. return NULL;
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1568. {
  1569. DebugAssert(GetSide(Side) == osRemote);
  1570. DebugUsedParam(Side);
  1571. return RemoteDirView;
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1575. {
  1576. DebugAssert(GetSide(Side) == osRemote);
  1577. DebugUsedParam(Side);
  1578. return RemoteDriveView;
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1582. {
  1583. DebugAssert(GetSide(Side) == osRemote);
  1584. DebugUsedParam(Side);
  1585. return HasActiveTerminal();
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1589. TOperationSide Side, int FilesOnly)
  1590. {
  1591. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1595. TOperationSide Side, int FilesOnly)
  1596. {
  1597. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. struct THistoryItemData
  1601. {
  1602. short int Side;
  1603. short int Index;
  1604. };
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1607. {
  1608. DirView(Side)->HistoryGo(Index);
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1612. {
  1613. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1614. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1615. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1619. bool Back)
  1620. {
  1621. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1622. {
  1623. TCustomDirView * DView = DirView(Side);
  1624. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1625. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1626. if (ICount > 10)
  1627. {
  1628. ICount = 10;
  1629. }
  1630. Menu->Items->Clear();
  1631. THistoryItemData Data;
  1632. Data.Side = Side;
  1633. for (short int i = 1; i <= ICount; i++)
  1634. {
  1635. TTBCustomItem * Item = new TTBXItem(Menu);
  1636. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1637. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1638. Item->Hint = DView->HistoryPath[Data.Index];
  1639. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1640. Item->Tag = *reinterpret_cast<int*>(&Data);
  1641. Item->OnClick = HistoryItemClick;
  1642. Menu->Items->Add(Item);
  1643. }
  1644. }
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1648. TOperationSide Side, bool Back)
  1649. {
  1650. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1651. {
  1652. // workaround
  1653. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1654. // operator new allocates memory in Pascal code, but calls inline
  1655. // contructor in C++, leading in problems, the function does
  1656. // both in Pascal code
  1657. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1658. UpdateHistoryMenu(Side, Back);
  1659. }
  1660. return FHistoryMenu[Side == osLocal][Back];
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1664. TCustomDirView *Sender)
  1665. {
  1666. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1667. UpdateHistoryMenu(Side, true);
  1668. UpdateHistoryMenu(Side, false);
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1672. {
  1673. // remote custom commands can be executed only if the server supports shell commands
  1674. // or have secondary shell
  1675. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1679. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1680. {
  1681. // -1 = hidden, 0 = disabled, 1 = enabled
  1682. int Result;
  1683. TFileCustomCommand RemoteCustomCommand;
  1684. TLocalCustomCommand LocalCustomCommand;
  1685. TFileCustomCommand * NonInteractiveCustomCommand =
  1686. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1687. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1688. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1689. if (FLAGCLEAR(Command.Params, ccLocal))
  1690. {
  1691. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1692. // custom command that does not operate with files can be executed anytime ...
  1693. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1694. {
  1695. // ... but do not show such command in remote file menu
  1696. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1697. {
  1698. Result = AllowedState;
  1699. }
  1700. else
  1701. {
  1702. Result = -1;
  1703. }
  1704. }
  1705. else
  1706. {
  1707. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1708. {
  1709. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1710. }
  1711. else
  1712. {
  1713. Result = -1;
  1714. }
  1715. }
  1716. }
  1717. else
  1718. {
  1719. // custom command that does not operate with files can be executed anytime
  1720. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1721. {
  1722. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1723. }
  1724. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1725. {
  1726. if ((ListType == ccltAll) || (ListType == ccltFile))
  1727. {
  1728. // special case is "diff"-style command that can be executed over any side,
  1729. // if we have both sides
  1730. Result =
  1731. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1732. // directly (instead of EnableSelectedOperation) to pass
  1733. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1734. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1735. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1736. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1737. }
  1738. else if (ListType == ccltBoth)
  1739. {
  1740. DebugAssert(!IsLocalBrowserMode());
  1741. Result = 1;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. else
  1749. {
  1750. if ((ListType == ccltAll) ||
  1751. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1752. {
  1753. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1754. }
  1755. else
  1756. {
  1757. Result = -1;
  1758. }
  1759. }
  1760. if ((Result > 0) &&
  1761. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1762. !HasActiveTerminal())
  1763. {
  1764. Result = 0;
  1765. }
  1766. }
  1767. return Result;
  1768. }
  1769. //---------------------------------------------------------------------------
  1770. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1771. TStrings * FileList, const TCustomCommandType & ACommand,
  1772. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1773. {
  1774. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1775. {
  1776. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1777. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1778. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1779. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1780. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1781. bool Capture =
  1782. FLAGSET(ACommand.Params, ccShowResults) ||
  1783. FLAGSET(ACommand.Params, ccCopyResults) ||
  1784. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1785. TCaptureOutputEvent OutputEvent = NULL;
  1786. DebugAssert(FCapturedLog == NULL);
  1787. if (Capture)
  1788. {
  1789. FCapturedLog = new TStringList();
  1790. OutputEvent = TerminalCaptureLog;
  1791. }
  1792. try
  1793. {
  1794. if (!RemoteCustomCommand.IsFileCommand(Command))
  1795. {
  1796. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1797. OutputEvent);
  1798. }
  1799. else
  1800. {
  1801. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1802. }
  1803. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1804. {
  1805. if (FLAGSET(ACommand.Params, ccCopyResults))
  1806. {
  1807. CopyToClipboard(FCapturedLog);
  1808. }
  1809. if (FLAGSET(ACommand.Params, ccShowResults))
  1810. {
  1811. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1812. }
  1813. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1814. {
  1815. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1816. }
  1817. }
  1818. }
  1819. __finally
  1820. {
  1821. SAFE_DESTROY(FCapturedLog);
  1822. }
  1823. }
  1824. }
  1825. //---------------------------------------------------------------------------
  1826. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1827. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1828. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1829. {
  1830. DebugAssert(!IsLocalBrowserMode());
  1831. TStrings * LocalFileList = NULL;
  1832. TStrings * RemoteFileList = NULL;
  1833. TStrings * RemoteFileListFull = NULL;
  1834. try
  1835. {
  1836. if (LocalFileCommand)
  1837. {
  1838. if (ALocalFileList == NULL)
  1839. {
  1840. DebugAssert(HasDirView[osLocal]);
  1841. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1842. // directly (instead of EnableSelectedOperation) to pass
  1843. // false to FocusedFileOnlyWhenFocused
  1844. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1845. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1846. }
  1847. else
  1848. {
  1849. LocalFileList = ALocalFileList;
  1850. }
  1851. if (FileListCommand)
  1852. {
  1853. if (LocalFileList->Count != 1)
  1854. {
  1855. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1856. }
  1857. }
  1858. else
  1859. {
  1860. if ((LocalFileList->Count != 1) &&
  1861. (FileList->Count != 1) &&
  1862. (LocalFileList->Count != FileList->Count))
  1863. {
  1864. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1865. }
  1866. }
  1867. }
  1868. UnicodeString RootTempDir;
  1869. UnicodeString TempDir;
  1870. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1871. if (!RemoteFiles)
  1872. {
  1873. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1874. }
  1875. try
  1876. {
  1877. TDateTimes RemoteFileTimes;
  1878. if (RemoteFiles)
  1879. {
  1880. RemoteFileList = FileList;
  1881. }
  1882. else
  1883. {
  1884. RemoteFileList = new TStringList();
  1885. TMakeLocalFileListParams MakeFileListParam;
  1886. MakeFileListParam.FileList = RemoteFileList;
  1887. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1888. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1889. MakeFileListParam.Recursive =
  1890. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1891. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1892. if (!MakeFileListParam.Recursive)
  1893. {
  1894. RemoteFileTimes.clear();
  1895. RemoteFileListFull = new TStringList();
  1896. MakeFileListParam.FileList = RemoteFileListFull;
  1897. MakeFileListParam.Recursive = true;
  1898. MakeFileListParam.IncludeDirs = false;
  1899. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1900. }
  1901. else
  1902. {
  1903. RemoteFileListFull = RemoteFileList;
  1904. }
  1905. }
  1906. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1907. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1908. if (!NonBlocking)
  1909. {
  1910. int Count;
  1911. if (FileListCommand)
  1912. {
  1913. Count = 1;
  1914. }
  1915. else if (LocalFileCommand)
  1916. {
  1917. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1918. }
  1919. else
  1920. {
  1921. Count = RemoteFileList->Count;
  1922. }
  1923. Progress.Start(foCustomCommand, osRemote, Count);
  1924. DebugAssert(FProgressForm != NULL);
  1925. FProgressForm->ReadOnly = true;
  1926. }
  1927. try
  1928. {
  1929. if (FileListCommand)
  1930. {
  1931. UnicodeString LocalFile;
  1932. // MakeFileList does not delimit filenames
  1933. UnicodeString FileList = MakeFileList(RemoteFileList);
  1934. if (LocalFileCommand)
  1935. {
  1936. DebugAssert(LocalFileList->Count == 1);
  1937. LocalFile = LocalFileList->Strings[0];
  1938. }
  1939. TLocalCustomCommand CustomCommand(Data,
  1940. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1941. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1942. if (NonBlocking)
  1943. {
  1944. DebugAssert(!POutput);
  1945. ExecuteShellChecked(ShellCommand);
  1946. }
  1947. else
  1948. {
  1949. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1950. }
  1951. }
  1952. else if (LocalFileCommand)
  1953. {
  1954. if (LocalFileList->Count == 1)
  1955. {
  1956. UnicodeString LocalFile = LocalFileList->Strings[0];
  1957. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1958. {
  1959. UnicodeString FileName = RemoteFileList->Strings[Index];
  1960. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1961. Progress.SetFile(FileNameForProgress);
  1962. TLocalCustomCommand CustomCommand(Data,
  1963. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1964. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1965. TOnceDoneOperation OnceDoneOperation;
  1966. // Do not unselect anything, as it won't work with two panels anyway
  1967. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1968. }
  1969. }
  1970. else if (RemoteFileList->Count == 1)
  1971. {
  1972. UnicodeString FileName = RemoteFileList->Strings[0];
  1973. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1974. {
  1975. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1976. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1977. Progress.SetFile(LocalFileNameOnly);
  1978. TLocalCustomCommand CustomCommand(
  1979. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1980. FileName, LocalFileName, L"");
  1981. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1982. TOnceDoneOperation OnceDoneOperation;
  1983. // Do not unselect anything, as it won't work with two panels anyway
  1984. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1985. }
  1986. }
  1987. else
  1988. {
  1989. if (LocalFileList->Count != RemoteFileList->Count)
  1990. {
  1991. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1992. }
  1993. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1994. {
  1995. UnicodeString FileName = RemoteFileList->Strings[Index];
  1996. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1997. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1998. Progress.SetFile(LocalFileNameOnly); // sic
  1999. TLocalCustomCommand CustomCommand(
  2000. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2001. FileName, LocalFileName, L"");
  2002. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2003. TOnceDoneOperation OnceDoneOperation;
  2004. // Do not unselect anything, as it won't work with two panels anyway
  2005. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2012. {
  2013. UnicodeString FileName = RemoteFileList->Strings[Index];
  2014. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2015. Progress.SetFile(FileNameForProgress);
  2016. TLocalCustomCommand CustomCommand(Data,
  2017. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2018. FileName, L"", L"");
  2019. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2020. TOnceDoneOperation OnceDoneOperation;
  2021. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2022. }
  2023. }
  2024. }
  2025. __finally
  2026. {
  2027. if (!NonBlocking)
  2028. {
  2029. Progress.Stop();
  2030. }
  2031. }
  2032. DebugAssert(!FAutoOperation);
  2033. if (!RemoteFiles)
  2034. {
  2035. TempDir = IncludeTrailingBackslash(TempDir);
  2036. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2037. {
  2038. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2039. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2040. // Skip directories, process only nested files.
  2041. // The check is redundant as FileAge fails for directories anyway.
  2042. !DirectoryExists(FileName))
  2043. {
  2044. UnicodeString RemoteDir =
  2045. UnixExtractFileDir(
  2046. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2047. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2048. TDateTime NewTime;
  2049. if (FileAge(FileName, NewTime) &&
  2050. (NewTime != RemoteFileTimes[Index]))
  2051. {
  2052. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2053. TemporaryFileCopyParam(CopyParam);
  2054. CopyParam.FileMask = L"";
  2055. FAutoOperation = true;
  2056. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2057. TemporaryFilesList->Add(FileName);
  2058. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. __finally
  2065. {
  2066. FAutoOperation = false;
  2067. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2068. {
  2069. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2070. }
  2071. }
  2072. }
  2073. __finally
  2074. {
  2075. if (RemoteFileList != FileList)
  2076. {
  2077. delete RemoteFileList;
  2078. }
  2079. if (LocalFileList != ALocalFileList)
  2080. {
  2081. delete LocalFileList;
  2082. }
  2083. if (RemoteFileListFull != RemoteFileList)
  2084. {
  2085. delete RemoteFileListFull;
  2086. }
  2087. }
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2091. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2092. bool FileListCommand, UnicodeString * POutput)
  2093. {
  2094. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2095. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2096. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2097. {
  2098. UnicodeString FileName = SelectedFileList->Strings[Index];
  2099. if (DirectoryExists(FileName))
  2100. {
  2101. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2102. {
  2103. LocalFileList->Add(FileName);
  2104. }
  2105. if (FLAGSET(ACommand.Params, ccRecursive))
  2106. {
  2107. TMakeLocalFileListParams MakeFileListParam;
  2108. MakeFileListParam.FileList = LocalFileList.get();
  2109. MakeFileListParam.FileTimes = NULL;
  2110. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2111. MakeFileListParam.Recursive = true;
  2112. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2113. }
  2114. }
  2115. else
  2116. {
  2117. LocalFileList->Add(FileName);
  2118. }
  2119. }
  2120. UnicodeString RemotePath;
  2121. if (Terminal != NULL)
  2122. {
  2123. RemotePath = Terminal->CurrentDirectory;
  2124. }
  2125. if (FileListCommand)
  2126. {
  2127. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2128. TLocalCustomCommand CustomCommand(
  2129. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2130. L"", L"", FileList);
  2131. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2132. }
  2133. else
  2134. {
  2135. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2136. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2137. DebugAssert(FProgressForm != NULL);
  2138. FProgressForm->ReadOnly = true;
  2139. try
  2140. {
  2141. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2142. {
  2143. UnicodeString FileName = LocalFileList->Strings[Index];
  2144. Progress.SetFile(FileName);
  2145. TLocalCustomCommand CustomCommand(
  2146. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2147. FileName, L"", L"");
  2148. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2149. TOnceDoneOperation OnceDoneOperation;
  2150. Progress.Finish(FileName, true, OnceDoneOperation);
  2151. }
  2152. }
  2153. __finally
  2154. {
  2155. Progress.Stop();
  2156. }
  2157. }
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2161. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2162. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2163. {
  2164. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2165. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2166. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2167. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2168. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2169. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2170. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2171. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2172. std::unique_ptr<UnicodeString> POutput;
  2173. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2174. FLAGSET(ACommand.Params, ccCopyResults))
  2175. {
  2176. POutput.reset(new UnicodeString());
  2177. }
  2178. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2179. FProgressSide = FCurrentSide;
  2180. if (!LocalCustomCommand.IsFileCommand(Command))
  2181. {
  2182. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2183. }
  2184. // remote files?
  2185. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2186. {
  2187. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2188. }
  2189. // local files
  2190. else
  2191. {
  2192. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2193. }
  2194. if (POutput.get() != NULL)
  2195. {
  2196. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2197. int P = POutput->Pos(sLineBreak);
  2198. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2199. {
  2200. POutput->SetLength(P - 1);
  2201. }
  2202. // Copy even empty output to clipboard
  2203. if (FLAGSET(ACommand.Params, ccCopyResults))
  2204. {
  2205. CopyToClipboard(*POutput);
  2206. }
  2207. // But do not show an empty message box.
  2208. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2209. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2210. !POutput->IsEmpty())
  2211. {
  2212. TClipboardHandler ClipboardHandler;
  2213. ClipboardHandler.Text = *POutput;
  2214. TMessageParams Params;
  2215. TQueryButtonAlias Aliases[1];
  2216. Aliases[0].Button = qaRetry;
  2217. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2218. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2219. Params.Aliases = Aliases;
  2220. Params.AliasesCount = LENOF(Aliases);
  2221. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2222. }
  2223. }
  2224. }
  2225. //---------------------------------------------------------------------------
  2226. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2227. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2228. {
  2229. TCustomCommandData Data;
  2230. UnicodeString Site;
  2231. UnicodeString RemotePath;
  2232. if (HasActiveTerminal())
  2233. {
  2234. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2235. Data = TCustomCommandData(SessionData.get());
  2236. Site = Terminal->SessionData->SessionKey;
  2237. RemotePath = Terminal->CurrentDirectory;
  2238. }
  2239. UnicodeString HelpKeyword = ACommand.HomePage;
  2240. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2241. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2242. {
  2243. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2244. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2245. {
  2246. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2247. }
  2248. else
  2249. {
  2250. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2251. }
  2252. if (!DoCustomCommandOptionsDialog(
  2253. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2254. {
  2255. Abort();
  2256. }
  2257. }
  2258. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2259. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2260. {
  2261. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2262. }
  2263. else
  2264. {
  2265. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2266. }
  2267. }
  2268. //---------------------------------------------------------------------------
  2269. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2270. const TCustomCommandType & Command)
  2271. {
  2272. DebugAssert(FCustomCommandLocalFileList != NULL);
  2273. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2274. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2275. TStrings * LocalFileList = new TStringList();
  2276. TStrings * RemoteFileList = new TStringList();
  2277. try
  2278. {
  2279. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2280. {
  2281. LocalFileList->Clear();
  2282. LocalFileList->AddObject(
  2283. FCustomCommandLocalFileList->Strings[Index],
  2284. FCustomCommandLocalFileList->Objects[Index]);
  2285. RemoteFileList->Clear();
  2286. RemoteFileList->AddObject(
  2287. FCustomCommandRemoteFileList->Strings[Index],
  2288. FCustomCommandRemoteFileList->Objects[Index]);
  2289. CustomCommand(RemoteFileList, Command, LocalFileList);
  2290. }
  2291. }
  2292. __finally
  2293. {
  2294. delete LocalFileList;
  2295. delete RemoteFileList;
  2296. }
  2297. }
  2298. //---------------------------------------------------------------------------
  2299. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2300. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2301. {
  2302. delete FCustomCommandLocalFileList;
  2303. delete FCustomCommandRemoteFileList;
  2304. // takeover ownership,
  2305. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2306. FCustomCommandLocalFileList = LocalFileList;
  2307. FCustomCommandRemoteFileList = RemoteFileList;
  2308. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2309. if (Button != NULL)
  2310. {
  2311. FCustomCommandMenu->Items->Clear();
  2312. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2313. MenuPopup(FCustomCommandMenu, Button);
  2314. }
  2315. else
  2316. {
  2317. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2318. }
  2319. }
  2320. //---------------------------------------------------------------------------
  2321. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2322. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2323. {
  2324. DebugAssert(FCapturedLog != NULL);
  2325. if ((OutputType == cotOutput) || (OutputType == cotError))
  2326. {
  2327. FCapturedLog->Add(AddedLine);
  2328. }
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2332. TOperationSide Side)
  2333. {
  2334. return
  2335. (Side == osOther) &&
  2336. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2340. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2341. {
  2342. TTBItemOptions O;
  2343. O = Item->Options;
  2344. TCustomDirView * DView = DirView(Side);
  2345. if ((DView->ItemFocused != NULL) &&
  2346. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2347. // when resolving links is disabled, default action is to enter the directory,
  2348. // no matter what DoubleClickAction is configured to
  2349. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2350. // Can only Edit files, but can Open/Copy even directories
  2351. ((DoubleClickAction != dcaEdit) ||
  2352. !DView->ItemIsDirectory(DView->ItemFocused)))
  2353. {
  2354. Item->Options = O << tboDefault;
  2355. }
  2356. else
  2357. {
  2358. Item->Options = O >> tboDefault;
  2359. }
  2360. }
  2361. //---------------------------------------------------------------------------
  2362. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2363. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2364. {
  2365. TCustomDirView * DView = DirView(Side);
  2366. TListItem * Item = DView->ItemFocused;
  2367. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2368. EnableFocusedOperation[Side])
  2369. {
  2370. TPoint ClientPoint;
  2371. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2372. TPoint(0, 0) : MousePos;
  2373. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2374. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2375. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2376. }
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2380. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2381. {
  2382. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2383. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2384. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2385. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2386. Handled = true;
  2387. }
  2388. //---------------------------------------------------------------------------
  2389. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2390. {
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2394. {
  2395. DebugAssert(FErrorList == NULL);
  2396. if (WinConfiguration->ContinueOnError)
  2397. {
  2398. FErrorList = new TStringList();
  2399. Configuration->Usage->Inc(L"ContinuationsOnError");
  2400. }
  2401. NonVisualDataModule->StartBusy();
  2402. }
  2403. //---------------------------------------------------------------------------
  2404. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2405. {
  2406. NonVisualDataModule->EndBusy();
  2407. if (FErrorList)
  2408. {
  2409. HandleErrorList(FErrorList);
  2410. }
  2411. }
  2412. //---------------------------------------------------------------------------
  2413. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2414. const TCopyParamType & CopyParam)
  2415. {
  2416. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2417. {
  2418. Configuration->Usage->Inc(L"FileMaskUses");
  2419. }
  2420. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2421. {
  2422. Configuration->Usage->Inc(L"OperationMaskUses");
  2423. }
  2424. }
  2425. //---------------------------------------------------------------------------
  2426. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2427. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2428. {
  2429. DebugAssert(!IsLocalBrowserMode());
  2430. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2431. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2432. TTransferOperationParam DefaultParam;
  2433. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2434. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2435. switch (Param.Queue)
  2436. {
  2437. case asOn:
  2438. CopyParam.Queue = true;
  2439. break;
  2440. case asOff:
  2441. CopyParam.Queue = false;
  2442. break;
  2443. case asAuto:
  2444. default:
  2445. // keep default
  2446. break;
  2447. }
  2448. bool Result =
  2449. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2450. if (Result)
  2451. {
  2452. DebugAssert(Terminal);
  2453. bool SelectionRestored = false;
  2454. TCustomDirView * DView = NULL;
  2455. if (HasDirView[Side])
  2456. {
  2457. DView = DirView(Side);
  2458. DView->SaveSelection();
  2459. DView->SaveSelectedNames();
  2460. }
  2461. UpdateCopyParamCounters(CopyParam);
  2462. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2463. DebugAssert(FTransferResumeList == NULL);
  2464. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2465. FMoveToQueue = false;
  2466. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2467. try
  2468. {
  2469. TStrings * PermanentFileList;
  2470. std::unique_ptr<TStrings> PermanentFileListOwner;
  2471. try
  2472. {
  2473. if (Side == osLocal)
  2474. {
  2475. PermanentFileList = FileList;
  2476. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2477. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2478. if (Operation == foMove)
  2479. {
  2480. ReloadLocalDirectory();
  2481. if (DView != NULL)
  2482. {
  2483. DView->RestoreSelection();
  2484. }
  2485. SelectionRestored = true;
  2486. }
  2487. }
  2488. else
  2489. {
  2490. // Clone the file list as it may refer to current directory files,
  2491. // which get destroyed, when the source directory is reloaded after foMove operation.
  2492. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2493. // But for a hotfix, we are not going to do such a big change.
  2494. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2495. PermanentFileList = PermanentFileListOwner.get();
  2496. try
  2497. {
  2498. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2499. }
  2500. __finally
  2501. {
  2502. if (Operation == foMove)
  2503. {
  2504. if (DView != NULL)
  2505. {
  2506. DView->RestoreSelection();
  2507. }
  2508. SelectionRestored = true;
  2509. }
  2510. ReloadLocalDirectory(Param.TargetDirectory);
  2511. }
  2512. }
  2513. }
  2514. catch (EAbort &)
  2515. {
  2516. if (FMoveToQueue)
  2517. {
  2518. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2519. DebugAssert(CopyParam.TransferSkipList == NULL);
  2520. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2521. if (TransferResumeList->Count > 0)
  2522. {
  2523. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2524. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2525. }
  2526. CopyParam.TransferSkipList = TransferResumeList.release();
  2527. // not really needed, just to keep it consistent with TransferResumeList
  2528. FTransferResumeList = NULL;
  2529. FMoveToQueue = false;
  2530. Configuration->Usage->Inc("MovesToBackground");
  2531. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2532. ClearTransferSourceSelection(Direction);
  2533. }
  2534. throw;
  2535. }
  2536. }
  2537. __finally
  2538. {
  2539. if (!SelectionRestored && (DView != NULL))
  2540. {
  2541. DView->DiscardSavedSelection();
  2542. }
  2543. FTransferResumeList = NULL;
  2544. }
  2545. }
  2546. return Result;
  2547. }
  2548. //---------------------------------------------------------------------------
  2549. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2550. TOperationSide Side, TStrings * FileList, void * Param)
  2551. {
  2552. DebugAssert(FileList->Count);
  2553. // We deliberately do not toggle alternative flag (Param), but use OR,
  2554. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2555. // shortcut of CurrentDeleteAlternativeAction
  2556. bool Alternative =
  2557. bool(Param) || UseAlternativeFunction();
  2558. bool Recycle;
  2559. if (IsSideLocalBrowser(Side))
  2560. {
  2561. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2562. }
  2563. else
  2564. {
  2565. Recycle =
  2566. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2567. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2568. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2569. }
  2570. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2571. if (!Result)
  2572. {
  2573. UnicodeString Query;
  2574. if (FileList->Count == 1)
  2575. {
  2576. if (IsSideLocalBrowser(Side))
  2577. {
  2578. Query = ExtractFileName(FileList->Strings[0]);
  2579. }
  2580. else
  2581. {
  2582. Query = UnixExtractFileName(FileList->Strings[0]);
  2583. }
  2584. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2585. }
  2586. else
  2587. {
  2588. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2589. }
  2590. TMessageParams Params(mpNeverAskAgainCheck);
  2591. Params.ImageName = L"Delete file";
  2592. unsigned int Answer =
  2593. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2594. if (Answer == qaNeverAskAgain)
  2595. {
  2596. Result = true;
  2597. if (Recycle)
  2598. {
  2599. WinConfiguration->ConfirmRecycling = false;
  2600. }
  2601. else
  2602. {
  2603. WinConfiguration->ConfirmDeleting = false;
  2604. }
  2605. }
  2606. else
  2607. {
  2608. Result = (Answer == qaOK);
  2609. }
  2610. }
  2611. if (Result)
  2612. {
  2613. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2614. }
  2615. return Result;
  2616. }
  2617. //---------------------------------------------------------------------------
  2618. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2619. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2620. {
  2621. TAutoBatch AutoBatch(this);
  2622. bool Result;
  2623. if ((Operation == foCopy) || (Operation == foMove))
  2624. {
  2625. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2626. }
  2627. else if (Operation == foRename)
  2628. {
  2629. DebugAssert(DirView(Side)->ItemFocused);
  2630. DirView(Side)->ItemFocused->EditCaption();
  2631. Result = true;
  2632. }
  2633. else if (Operation == foDelete)
  2634. {
  2635. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2636. }
  2637. else if (Operation == foSetProperties)
  2638. {
  2639. DirView(osRemote)->SaveSelectedNames();
  2640. Result = SetProperties(Side, FileList);
  2641. }
  2642. else if (Operation == foCustomCommand)
  2643. {
  2644. DebugAssert(Param);
  2645. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2646. DirView(osRemote)->SaveSelectedNames();
  2647. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2648. CustomCommand(FileList, *Command, NULL);
  2649. Result = true;
  2650. }
  2651. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2652. {
  2653. DebugAssert(!IsSideLocalBrowser(Side));
  2654. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2655. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2656. }
  2657. else if (Operation == foLock)
  2658. {
  2659. DebugAssert(!IsSideLocalBrowser(Side));
  2660. LockFiles(FileList, true);
  2661. Result = true;
  2662. }
  2663. else if (Operation == foUnlock)
  2664. {
  2665. DebugAssert(!IsSideLocalBrowser(Side));
  2666. LockFiles(FileList, false);
  2667. Result = true;
  2668. }
  2669. else
  2670. {
  2671. DebugFail();
  2672. }
  2673. return Result;
  2674. }
  2675. //---------------------------------------------------------------------------
  2676. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2677. {
  2678. if (Side == osCurrent)
  2679. {
  2680. Side = FCurrentSide;
  2681. }
  2682. return Side;
  2683. }
  2684. //---------------------------------------------------------------------------
  2685. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2686. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2687. {
  2688. Side = GetSide(Side);
  2689. bool Result;
  2690. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2691. try
  2692. {
  2693. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2694. }
  2695. __finally
  2696. {
  2697. delete FileList;
  2698. }
  2699. return Result;
  2700. }
  2701. //---------------------------------------------------------------------------
  2702. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2703. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2704. bool NoConfirmation, void * Param)
  2705. {
  2706. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2707. {
  2708. if ((Operation == foCopy) || (Operation == foMove))
  2709. {
  2710. DebugAssert(!IsLocalBrowserMode());
  2711. if (GetSide(Side) == osLocal)
  2712. {
  2713. Configuration->Usage->Inc(L"UploadsCommand");
  2714. }
  2715. else
  2716. {
  2717. Configuration->Usage->Inc(L"DownloadsCommand");
  2718. }
  2719. }
  2720. }
  2721. }
  2722. //---------------------------------------------------------------------------
  2723. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2724. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2725. {
  2726. TTransferOperationParam Param;
  2727. if ((WinConfiguration->Interface != ifCommander) ||
  2728. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2729. {
  2730. Flags &= ~cocShortCutHint;
  2731. }
  2732. TCustomDirView * DView = DirView(Side);
  2733. Param.Options =
  2734. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2735. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2736. if (FLAGSET(Flags, cocQueue))
  2737. {
  2738. Param.Queue = asOn;
  2739. }
  2740. else if (FLAGSET(Flags, cocNonQueue))
  2741. {
  2742. Param.Queue = asOff;
  2743. }
  2744. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2745. }
  2746. //---------------------------------------------------------------------------
  2747. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2748. {
  2749. try
  2750. {
  2751. if (ErrorList->Count)
  2752. {
  2753. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2754. if (MessageDialog(Message, qtError,
  2755. qaOK | qaCancel, HELP_NONE) == qaOK)
  2756. {
  2757. unsigned int Answer;
  2758. int Index = 0;
  2759. do
  2760. {
  2761. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2762. TQueryButtonAlias Aliases[2];
  2763. Aliases[0].Button = qaYes;
  2764. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2765. Aliases[1].Button = qaNo;
  2766. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2767. TMessageParams Params;
  2768. Params.Aliases = Aliases;
  2769. Params.AliasesCount = LENOF(Aliases);
  2770. Answer = MoreMessageDialog(
  2771. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2772. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2773. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2774. qaOK, HELP_NONE, &Params);
  2775. if (Answer == qaNo)
  2776. {
  2777. Index++;
  2778. }
  2779. if (Answer == qaYes)
  2780. {
  2781. Index--;
  2782. }
  2783. }
  2784. while (Answer != qaOK);
  2785. }
  2786. }
  2787. }
  2788. __finally
  2789. {
  2790. TStrings * List = ErrorList;
  2791. ErrorList = NULL;
  2792. for (int i = 0; i < List->Count; i++)
  2793. {
  2794. delete List->Objects[i];
  2795. }
  2796. delete List;
  2797. }
  2798. }
  2799. //---------------------------------------------------------------------------
  2800. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2801. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2802. {
  2803. // needed for checking filemasks, as there's no directory object
  2804. // associated with the file object
  2805. File->FullFileName = FullFileName;
  2806. TFileMasks::TParams MaskParams;
  2807. MaskParams.Size = File->Size;
  2808. MaskParams.Modification = File->Modification;
  2809. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2810. }
  2811. //---------------------------------------------------------------------------
  2812. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2813. {
  2814. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2815. Side = GetSide(Side);
  2816. TCustomDirView * DView = DirView(Side);
  2817. TListItem * FocusedItem = DView->ItemFocused;
  2818. UnicodeString Name;
  2819. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2820. {
  2821. Name = DView->ItemFileName(FocusedItem);
  2822. }
  2823. else
  2824. {
  2825. Name = LoadStr(NEW_FILE);
  2826. }
  2827. UnicodeString Names = Name;
  2828. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2829. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2830. HELP_EDIT_NEW, History.get(), true))
  2831. {
  2832. while (!Names.IsEmpty())
  2833. {
  2834. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2835. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2836. UnicodeString TargetFileName;
  2837. UnicodeString LocalFileName;
  2838. UnicodeString RootTempDir;
  2839. UnicodeString TempDir;
  2840. UnicodeString RemoteDirectory;
  2841. bool ExistingFile = false;
  2842. if (!IsSideLocalBrowser(Side))
  2843. {
  2844. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2845. TRemoteFile * File = NULL;
  2846. if (FTerminal->FileExists(Name, &File) &&
  2847. !File->IsDirectory)
  2848. {
  2849. try
  2850. {
  2851. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2852. ExistingFile = true;
  2853. }
  2854. __finally
  2855. {
  2856. delete File;
  2857. }
  2858. }
  2859. if (!ExistingFile)
  2860. {
  2861. RemoteDirectory = UnixExtractFilePath(Name);
  2862. TemporaryDirectoryForRemoteFiles(
  2863. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2864. TargetFileName = UnixExtractFileName(Name);
  2865. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2866. LocalFileName = TempDir +
  2867. // We probably do not want to trim the VMS version here
  2868. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2869. }
  2870. }
  2871. else
  2872. {
  2873. if (ExtractFilePath(Name).IsEmpty())
  2874. {
  2875. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2876. }
  2877. else
  2878. {
  2879. LocalFileName = ExpandFileName(Name);
  2880. }
  2881. TargetFileName = ExtractFileName(Name);
  2882. }
  2883. if (!ExistingFile)
  2884. {
  2885. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2886. if (NewFile)
  2887. {
  2888. int File = FileCreate(ApiPath(LocalFileName));
  2889. if (File < 0)
  2890. {
  2891. if (!RootTempDir.IsEmpty())
  2892. {
  2893. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2894. }
  2895. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2896. }
  2897. else
  2898. {
  2899. FileClose(File);
  2900. }
  2901. }
  2902. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2903. const TEditorData * ExternalEditor = NULL;
  2904. TFileMasks::TParams MaskParams; // size not known
  2905. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2906. false, MaskParams);
  2907. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2908. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2909. }
  2910. }
  2911. }
  2912. }
  2913. //---------------------------------------------------------------------------
  2914. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2915. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2916. {
  2917. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2918. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2919. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2920. return
  2921. ((ExecuteFileBy == efInternalEditor)) ||
  2922. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2923. }
  2924. //---------------------------------------------------------------------------
  2925. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2926. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2927. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2928. UnicodeString RemoteDirectory, bool NewFile)
  2929. {
  2930. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2931. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2932. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2933. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2934. Side = GetSide(Side);
  2935. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2936. if (!IsSideLocalBrowser(Side))
  2937. {
  2938. Data->Terminal = Terminal;
  2939. Data->Queue = Queue;
  2940. Data->SessionData = CloneCurrentSessionData();
  2941. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2942. Data->RemoteDirectory = RemoteDirectory;
  2943. Data->SessionName = Terminal->SessionData->SessionName;
  2944. Data->LocalRootDirectory = LocalRootDirectory;
  2945. Data->OriginalFileName = OriginalFileName;
  2946. Data->Command = L""; // will be changed later for external editor
  2947. }
  2948. if (ExecuteFileBy == efInternalEditor)
  2949. {
  2950. if (!IsSideLocalBrowser(Side))
  2951. {
  2952. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2953. L" - " + Terminal->SessionData->SessionName;
  2954. TForm * Editor;
  2955. try
  2956. {
  2957. TNotifyEvent OnFileChanged = NULL;
  2958. TNotifyEvent OnSaveAll = NULL;
  2959. TAnyModifiedEvent OnAnyModified = NULL;
  2960. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2961. if (Terminal->IsCapable[fcBackgroundTransfers])
  2962. {
  2963. OnFileChanged = FEditorManager->FileChanged;
  2964. OnSaveAll = SaveAllInternalEditors;
  2965. OnAnyModified = AnyInternalEditorModified;
  2966. }
  2967. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2968. FEditorManager->FileReload, FEditorManager->FileClosed,
  2969. OnSaveAll, OnAnyModified,
  2970. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2971. }
  2972. catch(...)
  2973. {
  2974. if (!LocalRootDirectory.IsEmpty())
  2975. {
  2976. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2977. }
  2978. throw;
  2979. }
  2980. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2981. }
  2982. else
  2983. {
  2984. DebugAssert(!FStandaloneEditing);
  2985. TForm * Editor =
  2986. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2987. SaveAllInternalEditors, AnyInternalEditorModified,
  2988. L"", false, SessionColor, -1, NewFile);
  2989. FLocalEditors->Add(Editor);
  2990. }
  2991. }
  2992. else
  2993. {
  2994. HANDLE Process;
  2995. if (ExecuteFileBy == efExternalEditor)
  2996. {
  2997. UnicodeString Program, Params, Dir;
  2998. Data->Command = ExternalEditor->ExternalEditor;
  2999. ReformatFileNameCommand(Data->Command);
  3000. SplitCommand(Data->Command, Program, Params, Dir);
  3001. Params = ExpandFileNameCommand(Params, FileName);
  3002. Program = ExpandEnvironmentVariables(Program);
  3003. if (!ExecuteShell(Program, Params, Process))
  3004. {
  3005. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3006. }
  3007. }
  3008. else
  3009. {
  3010. DebugAssert(!IsSideLocalBrowser(Side));
  3011. if (!ExecuteShell(FileName, L"", Process))
  3012. {
  3013. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3014. }
  3015. }
  3016. if (IsSideLocalBrowser(Side) ||
  3017. ((ExecuteFileBy == efShell) &&
  3018. !WinConfiguration->Editor.SDIShellEditor) ||
  3019. ((ExecuteFileBy == efExternalEditor) &&
  3020. !ExternalEditor->SDIExternalEditor))
  3021. {
  3022. // no need for handle
  3023. if (Process != NULL)
  3024. {
  3025. DebugCheck(CloseHandle(Process));
  3026. }
  3027. Process = INVALID_HANDLE_VALUE;
  3028. }
  3029. else
  3030. {
  3031. if (Process == NULL)
  3032. {
  3033. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3034. }
  3035. }
  3036. if (!IsSideLocalBrowser(Side))
  3037. {
  3038. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3039. }
  3040. }
  3041. }
  3042. //---------------------------------------------------------------------------
  3043. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3044. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3045. void * /*Arg*/)
  3046. {
  3047. if (Token != NULL)
  3048. {
  3049. EditorFormFileSave(static_cast<TForm *>(Token));
  3050. }
  3051. }
  3052. //---------------------------------------------------------------------------
  3053. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3054. {
  3055. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3056. {
  3057. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3058. }
  3059. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3060. }
  3061. //---------------------------------------------------------------------------
  3062. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3063. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3064. void * Arg)
  3065. {
  3066. if ((Token != NULL) &&
  3067. IsEditorFormModified(static_cast<TForm *>(Token)))
  3068. {
  3069. *static_cast<bool *>(Arg) = true;
  3070. }
  3071. }
  3072. //---------------------------------------------------------------------------
  3073. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3074. TObject * /*Sender*/, bool & Modified)
  3075. {
  3076. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3077. {
  3078. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3079. {
  3080. Modified = true;
  3081. }
  3082. }
  3083. if (!Modified)
  3084. {
  3085. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3086. }
  3087. }
  3088. //---------------------------------------------------------------------------
  3089. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3090. {
  3091. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3092. }
  3093. //---------------------------------------------------------------------------
  3094. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3095. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3096. UnicodeString & Result, UnicodeString & RootDirectory)
  3097. {
  3098. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3099. {
  3100. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3101. Result = RootDirectory;
  3102. }
  3103. else
  3104. {
  3105. RootDirectory = L"";
  3106. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3107. Result = IncludeTrailingBackslash(Result);
  3108. }
  3109. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3110. {
  3111. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3112. }
  3113. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3114. {
  3115. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3116. {
  3117. RemoteDirectory.Delete(1, 1);
  3118. }
  3119. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3120. }
  3121. if (!ForceDirectories(ApiPath(Result)))
  3122. {
  3123. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3124. }
  3125. }
  3126. //---------------------------------------------------------------------------
  3127. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3128. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3129. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3130. {
  3131. DebugAssert(!IsLocalBrowserMode());
  3132. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3133. if (ForceText)
  3134. {
  3135. CopyParam.TransferMode = tmAscii;
  3136. }
  3137. TemporaryFileCopyParam(CopyParam);
  3138. if (AllFiles)
  3139. {
  3140. CopyParam.IncludeFileMask = TFileMasks();
  3141. }
  3142. if (TempDir.IsEmpty())
  3143. {
  3144. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3145. }
  3146. DebugAssert(!FAutoOperation);
  3147. FAutoOperation = AutoOperation;
  3148. Terminal->ExceptionOnFail = true;
  3149. try
  3150. {
  3151. try
  3152. {
  3153. // turn off confirmations, as for MDI editors we may possibly download
  3154. // the same file over
  3155. Terminal->CopyToLocal(
  3156. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3157. if (GetTargetNames)
  3158. {
  3159. for (int i = 0; i < FileList->Count; i++)
  3160. {
  3161. FileList->Strings[i] =
  3162. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3163. }
  3164. }
  3165. }
  3166. catch(...)
  3167. {
  3168. if (!RootTempDir.IsEmpty())
  3169. {
  3170. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3171. }
  3172. throw;
  3173. }
  3174. }
  3175. __finally
  3176. {
  3177. FAutoOperation = false;
  3178. Terminal->ExceptionOnFail = false;
  3179. }
  3180. }
  3181. //---------------------------------------------------------------------------
  3182. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3183. {
  3184. // Do not waste time checking for default editor list the next time,
  3185. // or testing if default editor is not notepad.
  3186. bool TryNextTime = false;
  3187. UnicodeString UsageState;
  3188. if (!WinConfiguration->EditorList->IsDefaultList())
  3189. {
  3190. UsageState = "H";
  3191. }
  3192. else
  3193. {
  3194. UnicodeString Executable;
  3195. UnicodeString ExecutableDescription;
  3196. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3197. {
  3198. UnicodeString Message =
  3199. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3200. unsigned int Answer =
  3201. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3202. if (Answer != qaOK)
  3203. {
  3204. UsageState = "R";
  3205. }
  3206. else
  3207. {
  3208. UsageState = "A";
  3209. TEditorData EditorData;
  3210. EditorData.Editor = edExternal;
  3211. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3212. EditorData.ExternalEditorOptionsAutodetect();
  3213. TEditorList EditorList;
  3214. EditorList = *WinConfiguration->EditorList;
  3215. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3216. WinConfiguration->EditorList = &EditorList;
  3217. }
  3218. }
  3219. }
  3220. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3221. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3222. }
  3223. //---------------------------------------------------------------------------
  3224. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3225. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3226. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3227. {
  3228. if (ExecuteFileBy == efDefaultEditor)
  3229. {
  3230. if (!WinConfiguration->OfferedEditorAutoConfig)
  3231. {
  3232. EditorAutoConfig();
  3233. }
  3234. const TEditorPreferences * Editor =
  3235. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3236. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3237. {
  3238. ExecuteFileBy = efInternalEditor;
  3239. ExternalEditor = NULL;
  3240. }
  3241. else if (Editor->Data->Editor == edOpen)
  3242. {
  3243. ExecuteFileBy = efShell;
  3244. ExternalEditor = NULL;
  3245. }
  3246. else
  3247. {
  3248. ExecuteFileBy = efExternalEditor;
  3249. ExternalEditor = Editor->Data;
  3250. }
  3251. }
  3252. }
  3253. //---------------------------------------------------------------------------
  3254. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3255. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3256. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3257. {
  3258. UnicodeString OriginalFileName;
  3259. UnicodeString LocalRootDirectory;
  3260. UnicodeString RemoteDirectory;
  3261. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3262. IsSideLocalBrowser(Side), MaskParams);
  3263. UnicodeString Counter;
  3264. UnicodeString LocalFileName;
  3265. bool Handled = false;
  3266. if (!IsSideLocalBrowser(Side))
  3267. {
  3268. // We need to trim VMS version here, so that we use name without version
  3269. // when uploading back to create a new version of the file
  3270. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3271. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3272. TObject * Token = NULL;
  3273. UnicodeString LocalDirectory;
  3274. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3275. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3276. LocalDirectory))
  3277. {
  3278. if (Token != NULL)
  3279. {
  3280. TForm * Form = dynamic_cast<TForm *>(Token);
  3281. if (Form->WindowState == wsMinimized)
  3282. {
  3283. ShowWindow(Form->Handle, SW_RESTORE);
  3284. }
  3285. else
  3286. {
  3287. Form->SetFocus();
  3288. }
  3289. Handled = true;
  3290. }
  3291. else
  3292. {
  3293. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3294. }
  3295. }
  3296. if (!Handled)
  3297. {
  3298. TStringList * FileList1 = new TStringList();
  3299. try
  3300. {
  3301. FileList1->AddObject(FullFileName, Object);
  3302. TemporarilyDownloadFiles(FileList1,
  3303. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3304. LocalRootDirectory, LocalDirectory, true, true, true);
  3305. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3306. }
  3307. __finally
  3308. {
  3309. delete FileList1;
  3310. }
  3311. switch (ExecuteFileBy)
  3312. {
  3313. case efShell:
  3314. Counter = "RemoteFilesExecuted";
  3315. break;
  3316. case efInternalEditor:
  3317. Counter = "RemoteFilesOpenedInInternalEditor";
  3318. break;
  3319. case efExternalEditor:
  3320. Counter = "RemoteFilesOpenedInExternalEditor";
  3321. break;
  3322. default:
  3323. DebugFail();
  3324. }
  3325. }
  3326. }
  3327. else
  3328. {
  3329. LocalFileName = FullFileName;
  3330. OriginalFileName = ExtractFileName(FullFileName);
  3331. switch (ExecuteFileBy)
  3332. {
  3333. case efShell:
  3334. Counter = "LocalFilesExecuted";
  3335. break;
  3336. case efInternalEditor:
  3337. Counter = "LocalFilesOpenedInInternalEditor";
  3338. break;
  3339. case efExternalEditor:
  3340. Counter = "LocalFilesOpenedInExternalEditor";
  3341. break;
  3342. default:
  3343. DebugFail();
  3344. }
  3345. }
  3346. if (!Handled)
  3347. {
  3348. Configuration->Usage->Inc(Counter);
  3349. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3350. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3351. }
  3352. }
  3353. //---------------------------------------------------------------------------
  3354. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3355. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3356. bool AllSelected, bool OnFocused)
  3357. {
  3358. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3359. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3360. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3361. Side = GetSide(Side);
  3362. TCustomDirView * DView = DirView(Side);
  3363. TStrings * FileList =
  3364. AllSelected ?
  3365. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3366. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3367. try
  3368. {
  3369. DebugAssert(AllSelected || (FileList->Count == 1));
  3370. for (int i = 0; i < FileList->Count; i++)
  3371. {
  3372. UnicodeString ListFileName = FileList->Strings[i];
  3373. UnicodeString FileNameOnly =
  3374. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3375. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3376. if (!DView->ItemIsDirectory(Item))
  3377. {
  3378. UnicodeString FullFileName;
  3379. if (!IsSideLocalBrowser(Side))
  3380. {
  3381. FullFileName = DirView(Side)->Path + ListFileName;
  3382. }
  3383. else
  3384. {
  3385. FullFileName = ListFileName;
  3386. }
  3387. TFileMasks::TParams MaskParams;
  3388. MaskParams.Size = DView->ItemFileSize(Item);
  3389. TDateTimePrecision Precision;
  3390. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3391. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3392. FileList->Objects[i], MaskParams);
  3393. }
  3394. }
  3395. }
  3396. __finally
  3397. {
  3398. delete FileList;
  3399. }
  3400. }
  3401. //---------------------------------------------------------------------------
  3402. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3403. {
  3404. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3405. CopyParam.FileNameCase = ncNoChange;
  3406. CopyParam.PreserveRights = false;
  3407. CopyParam.PreserveReadOnly = false;
  3408. CopyParam.ReplaceInvalidChars = true;
  3409. CopyParam.IncludeFileMask = TFileMasks();
  3410. CopyParam.NewerOnly = false;
  3411. CopyParam.FileMask = L"";
  3412. }
  3413. //---------------------------------------------------------------------------
  3414. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3415. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3416. {
  3417. TTerminalManager * Manager = TTerminalManager::Instance();
  3418. if (!IsActiveTerminal(Data->Terminal))
  3419. {
  3420. if (!NonVisualDataModule->Busy)
  3421. {
  3422. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3423. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3424. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3425. if (Data->Terminal == NULL)
  3426. {
  3427. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3428. if (SameSiteTerminal != NULL)
  3429. {
  3430. UnicodeString Message =
  3431. FMTLOAD(EDIT_SESSION_REATTACH,
  3432. (FileNameOnly, Data->SessionName, FileNameOnly));
  3433. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3434. {
  3435. Data->Terminal = Terminal;
  3436. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3437. Data->SessionName = Terminal->SessionData->SessionName;
  3438. // We might also overwrite session data
  3439. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3440. }
  3441. else
  3442. {
  3443. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3444. Abort();
  3445. }
  3446. }
  3447. }
  3448. // foreground session should reconnect itself
  3449. else if (Terminal != Data->Terminal)
  3450. {
  3451. UnicodeString Message =
  3452. MainInstructions(
  3453. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3454. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3455. {
  3456. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3457. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3458. }
  3459. else
  3460. {
  3461. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3462. Abort();
  3463. }
  3464. }
  3465. }
  3466. if (!IsActiveTerminal(Data->Terminal))
  3467. {
  3468. Configuration->Usage->Inc(L"EditInactiveSession");
  3469. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3470. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3471. (ExtractFileName(FileName), Data->SessionName)));
  3472. }
  3473. }
  3474. TStrings * FileList = new TStringList();
  3475. try
  3476. {
  3477. FileList->Add(FileName);
  3478. // consider using the same settings (preset) as when the file was downloaded
  3479. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3480. TemporaryFileCopyParam(CopyParam);
  3481. if (Data->ForceText)
  3482. {
  3483. CopyParam.TransferMode = tmAscii;
  3484. }
  3485. // so i do not need to worry if masking algorithm works in all cases
  3486. // ("" means "copy file name", no masking is actually done)
  3487. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3488. {
  3489. CopyParam.FileMask = L"";
  3490. }
  3491. else
  3492. {
  3493. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3494. }
  3495. DebugAssert(Data->Queue != NULL);
  3496. int Params = cpNoConfirmation | cpTemporary;
  3497. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3498. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3499. QueueItem->CompleteEvent = UploadCompleteEvent;
  3500. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3501. }
  3502. __finally
  3503. {
  3504. delete FileList;
  3505. }
  3506. }
  3507. //---------------------------------------------------------------------------
  3508. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3509. const UnicodeString FileName, const TEditedFileData * Data)
  3510. {
  3511. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3512. DebugAssert(!NonVisualDataModule->Busy);
  3513. if (!IsActiveTerminal(Data->Terminal))
  3514. {
  3515. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3516. (ExtractFileName(FileName), Data->SessionName)));
  3517. }
  3518. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3519. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3520. NonVisualDataModule->StartBusy();
  3521. try
  3522. {
  3523. std::unique_ptr<TRemoteFile> File;
  3524. UnicodeString RemoteFileName =
  3525. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3526. FTerminal->ExceptionOnFail = true;
  3527. try
  3528. {
  3529. TRemoteFile * AFile = NULL;
  3530. FTerminal->ReadFile(RemoteFileName, AFile);
  3531. File.reset(AFile);
  3532. if (!File->HaveFullFileName)
  3533. {
  3534. File->FullFileName = RemoteFileName;
  3535. }
  3536. }
  3537. __finally
  3538. {
  3539. FTerminal->ExceptionOnFail = false;
  3540. }
  3541. std::unique_ptr<TStrings> FileList(new TStringList());
  3542. FileList->AddObject(RemoteFileName, File.get());
  3543. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3544. UnicodeString TempDir = ExtractFilePath(FileName);
  3545. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3546. TempDir, true, true, true);
  3547. // sanity check, the target file name should be still the same
  3548. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3549. }
  3550. __finally
  3551. {
  3552. NonVisualDataModule->EndBusy();
  3553. // it actually may not exist anymore...
  3554. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3555. }
  3556. }
  3557. //---------------------------------------------------------------------------
  3558. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3559. const TEditedFileData * Data, bool & KeepOpen)
  3560. {
  3561. // Command is set for external editors only (not for "shell" open).
  3562. if (!Data->Command.IsEmpty())
  3563. {
  3564. bool AnyFound = false;
  3565. bool AnyMDI = false;
  3566. bool AnyNonMDI = false;
  3567. bool AnyDetect = false;
  3568. TEditorList * EditorList = new TEditorList();
  3569. try
  3570. {
  3571. *EditorList = *WinConfiguration->EditorList;
  3572. for (int i = 0; i < EditorList->Count; i++)
  3573. {
  3574. const TEditorPreferences * Editor = EditorList->Editors[i];
  3575. if ((Editor->Data->Editor == edExternal) &&
  3576. (Editor->Data->ExternalEditor == Data->Command))
  3577. {
  3578. AnyFound = true;
  3579. if (Editor->Data->SDIExternalEditor)
  3580. {
  3581. AnyNonMDI = true;
  3582. if (Editor->Data->DetectMDIExternalEditor)
  3583. {
  3584. AnyDetect = true;
  3585. }
  3586. }
  3587. else
  3588. {
  3589. AnyMDI = true;
  3590. }
  3591. }
  3592. }
  3593. bool EnableMDI = false;
  3594. bool DisableDetect = false;
  3595. if (AnyMDI)
  3596. {
  3597. KeepOpen = true;
  3598. if (AnyNonMDI)
  3599. {
  3600. // there is at least one instance of the editor with MDI support enabled,
  3601. // and one with disabled, enable it for all instances
  3602. EnableMDI = true;
  3603. }
  3604. }
  3605. else if (AnyFound && !AnyDetect)
  3606. {
  3607. // at least once instance found but all have MDI autodetection disabled
  3608. // => close the file (default action)
  3609. }
  3610. else
  3611. {
  3612. // no instance of the editor has MDI support enabled
  3613. TMessageParams Params;
  3614. if (AnyFound)
  3615. {
  3616. // there is at least one instance of the editor
  3617. Params.Params |= mpNeverAskAgainCheck;
  3618. }
  3619. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3620. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3621. switch (Answer)
  3622. {
  3623. case qaNeverAskAgain:
  3624. DisableDetect = true;
  3625. break;
  3626. case qaNo:
  3627. EnableMDI = true;
  3628. KeepOpen = true;
  3629. break;
  3630. }
  3631. }
  3632. if (AnyFound && (EnableMDI || DisableDetect))
  3633. {
  3634. bool Changed = false;
  3635. for (int i = 0; i < EditorList->Count; i++)
  3636. {
  3637. const TEditorPreferences * Editor = EditorList->Editors[i];
  3638. if ((Editor->Data->Editor == edExternal) &&
  3639. (Editor->Data->ExternalEditor == Data->Command) &&
  3640. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3641. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3642. {
  3643. Changed = true;
  3644. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3645. if (EnableMDI)
  3646. {
  3647. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3648. }
  3649. if (DisableDetect)
  3650. {
  3651. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3652. }
  3653. EditorList->Change(i, UpdatedEditor);
  3654. }
  3655. }
  3656. if (Changed)
  3657. {
  3658. WinConfiguration->EditorList = EditorList;
  3659. }
  3660. }
  3661. }
  3662. __finally
  3663. {
  3664. delete EditorList;
  3665. }
  3666. }
  3667. else
  3668. {
  3669. // "open" case
  3670. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3671. qaOK, HELP_APP_EARLY_CLOSED);
  3672. }
  3673. }
  3674. //---------------------------------------------------------------------------
  3675. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3676. {
  3677. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3678. }
  3679. //---------------------------------------------------------------------------
  3680. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3681. {
  3682. SideEnter(osRemote);
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3686. {
  3687. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3688. SideEnter(osRemote);
  3689. }
  3690. //---------------------------------------------------------------------------
  3691. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3692. {
  3693. FCurrentSide = Side;
  3694. if (Visible)
  3695. {
  3696. UpdateControls();
  3697. }
  3698. }
  3699. //---------------------------------------------------------------------------
  3700. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3701. TStrings * FileList, bool Alternative)
  3702. {
  3703. TCustomDirView * DView = DirView(Side);
  3704. DView->SaveSelection();
  3705. DView->SaveSelectedNames();
  3706. DebugAssert(!FAlternativeDelete);
  3707. FAlternativeDelete = Alternative;
  3708. try
  3709. {
  3710. if (!IsSideLocalBrowser(Side))
  3711. {
  3712. DebugAssert(Terminal != NULL);
  3713. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3714. }
  3715. else
  3716. {
  3717. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3718. FProgressSide = FCurrentSide;
  3719. try
  3720. {
  3721. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3722. }
  3723. __finally
  3724. {
  3725. ReloadLocalDirectory();
  3726. }
  3727. }
  3728. FAlternativeDelete = false;
  3729. }
  3730. catch(...)
  3731. {
  3732. FAlternativeDelete = false;
  3733. DView->DiscardSavedSelection();
  3734. throw;
  3735. }
  3736. DView->RestoreSelection();
  3737. }
  3738. //---------------------------------------------------------------------------
  3739. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3740. {
  3741. DebugAssert(Terminal);
  3742. DebugAssert(!IsLocalBrowserMode());
  3743. RemoteDirView->SaveSelection();
  3744. RemoteDirView->SaveSelectedNames();
  3745. try
  3746. {
  3747. if (Lock)
  3748. {
  3749. Terminal->LockFiles(FileList);
  3750. }
  3751. else
  3752. {
  3753. Terminal->UnlockFiles(FileList);
  3754. }
  3755. }
  3756. catch(...)
  3757. {
  3758. RemoteDirView->DiscardSavedSelection();
  3759. throw;
  3760. }
  3761. RemoteDirView->RestoreSelection();
  3762. }
  3763. //---------------------------------------------------------------------------
  3764. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3765. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3766. bool NoConfirmation, bool Move)
  3767. {
  3768. DebugAssert(Terminal != NULL);
  3769. DebugAssert(!IsLocalBrowserMode());
  3770. // update Terminal->StateData->RemoteDirectory
  3771. UpdateTerminal(Terminal);
  3772. if (Session == NULL)
  3773. {
  3774. Session = TTerminalManager::Instance()->ActiveTerminal;
  3775. }
  3776. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3777. {
  3778. if (RemoteDriveView->DropTarget != NULL)
  3779. {
  3780. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3781. }
  3782. else if (RemoteDirView->DropTarget != NULL)
  3783. {
  3784. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3785. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3786. }
  3787. else
  3788. {
  3789. Target = RemoteDirView->Path;
  3790. }
  3791. }
  3792. else
  3793. {
  3794. Target = Session->StateData->RemoteDirectory;
  3795. }
  3796. Target = UnixIncludeTrailingBackslash(Target);
  3797. if (FileList->Count == 1)
  3798. {
  3799. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3800. }
  3801. else
  3802. {
  3803. FileMask = AnyMask;
  3804. }
  3805. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3806. bool Result = true;
  3807. if (!NoConfirmation)
  3808. {
  3809. bool Multi = (FileList->Count > 1);
  3810. if (Move)
  3811. {
  3812. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3813. }
  3814. else
  3815. {
  3816. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3817. TStrings * Directories = new TStringList;
  3818. try
  3819. {
  3820. for (int Index = 0; Index < Sessions->Count; Index++)
  3821. {
  3822. TManagedTerminal * Terminal =
  3823. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3824. Directories->Add(Terminal->StateData->RemoteDirectory);
  3825. }
  3826. TDirectRemoteCopy AllowDirectCopy;
  3827. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3828. {
  3829. DebugAssert(DirectCopy);
  3830. AllowDirectCopy = drcAllow;
  3831. }
  3832. else if (FTerminal->IsCapable[fcSecondaryShell])
  3833. {
  3834. DebugAssert(DirectCopy);
  3835. AllowDirectCopy = drcConfirmCommandSession;
  3836. }
  3837. else
  3838. {
  3839. DebugAssert(!DirectCopy);
  3840. AllowDirectCopy = drcDisallow;
  3841. }
  3842. void * ASession = Session;
  3843. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3844. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3845. Session = static_cast<TManagedTerminal *>(ASession);
  3846. }
  3847. __finally
  3848. {
  3849. delete Directories;
  3850. }
  3851. }
  3852. }
  3853. return Result;
  3854. }
  3855. //---------------------------------------------------------------------------
  3856. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3857. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3858. {
  3859. DebugAssert(!IsLocalBrowserMode());
  3860. bool DirectCopy;
  3861. UnicodeString Target, FileMask;
  3862. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3863. if (Result)
  3864. {
  3865. if (!Move && !DirectCopy)
  3866. {
  3867. Configuration->Usage->Inc("RemoteCopyTemp");
  3868. UnicodeString RootTempDir;
  3869. UnicodeString TempDir;
  3870. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3871. TStrings * TemporaryFilesList = new TStringList();
  3872. try
  3873. {
  3874. TMakeLocalFileListParams MakeFileListParam;
  3875. MakeFileListParam.FileList = TemporaryFilesList;
  3876. MakeFileListParam.FileTimes = NULL;
  3877. MakeFileListParam.IncludeDirs = true;
  3878. MakeFileListParam.Recursive = false;
  3879. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3880. TTerminalManager::Instance()->ActiveTerminal = Session;
  3881. if (TemporaryFilesList->Count > 0)
  3882. {
  3883. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3884. CopyParam.FileMask = FileMask;
  3885. DebugAssert(!FAutoOperation);
  3886. FAutoOperation = true;
  3887. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3888. }
  3889. }
  3890. __finally
  3891. {
  3892. delete TemporaryFilesList;
  3893. FAutoOperation = false;
  3894. if (!RootTempDir.IsEmpty())
  3895. {
  3896. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3897. }
  3898. }
  3899. }
  3900. else
  3901. {
  3902. RemoteDirView->SaveSelection();
  3903. RemoteDirView->SaveSelectedNames();
  3904. try
  3905. {
  3906. if (Move)
  3907. {
  3908. Configuration->Usage->Inc("RemoteMove");
  3909. Terminal->MoveFiles(FileList, Target, FileMask);
  3910. }
  3911. else
  3912. {
  3913. Configuration->Usage->Inc("RemoteCopyDirect");
  3914. DebugAssert(DirectCopy);
  3915. DebugAssert(Session == FTerminal);
  3916. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3917. FTerminal->CommandSessionOpened ||
  3918. CommandSessionFallback())
  3919. {
  3920. Terminal->CopyFiles(FileList, Target, FileMask);
  3921. }
  3922. }
  3923. }
  3924. catch(...)
  3925. {
  3926. RemoteDirView->DiscardSavedSelection();
  3927. throw;
  3928. }
  3929. RemoteDirView->RestoreSelection();
  3930. }
  3931. }
  3932. return Result;
  3933. }
  3934. //---------------------------------------------------------------------------
  3935. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3936. const UnicodeString & Path, TRemoteProperties & Properties)
  3937. {
  3938. DebugAssert(!IsLocalBrowserMode());
  3939. Properties.Valid = Properties.Valid << vpEncrypt;
  3940. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3941. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3942. }
  3943. //---------------------------------------------------------------------------
  3944. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3945. {
  3946. Side = GetSide(Side);
  3947. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3948. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3949. UnicodeString Name = LoadStr(NEW_FOLDER);
  3950. int AllowedChanges =
  3951. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3952. bool SaveSettings = false;
  3953. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3954. {
  3955. TWindowLock Lock(this);
  3956. if (!IsSideLocalBrowser(Side))
  3957. {
  3958. if (SaveSettings)
  3959. {
  3960. GUIConfiguration->NewDirectoryProperties = Properties;
  3961. }
  3962. CreateRemoteDirectory(Name, Properties);
  3963. }
  3964. else
  3965. {
  3966. DirView(Side)->CreateDirectory(Name);
  3967. }
  3968. }
  3969. }
  3970. //---------------------------------------------------------------------------
  3971. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3972. {
  3973. TWindowLock Lock(this);
  3974. DirView(Side)->ExecuteHomeDirectory();
  3975. }
  3976. //---------------------------------------------------------------------------
  3977. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3978. {
  3979. DoOpenDirectoryDialog(odBrowse, Side);
  3980. }
  3981. //---------------------------------------------------------------------------
  3982. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3983. {
  3984. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3985. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3986. bool Result = !Path.IsEmpty();
  3987. if (Result)
  3988. {
  3989. // While we might get here when the session is closed (from location profiles),
  3990. // it's not a problem as the Path setter is noop then
  3991. DirView(Side)->Path = Path;
  3992. }
  3993. return Result;
  3994. }
  3995. //---------------------------------------------------------------------------
  3996. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3997. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3998. bool & Close)
  3999. {
  4000. // terminal can be already closed (e.g. dropped connection)
  4001. if (Terminal != NULL)
  4002. {
  4003. try
  4004. {
  4005. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4006. }
  4007. catch(...)
  4008. {
  4009. if (!Terminal->Active)
  4010. {
  4011. Close = true;
  4012. }
  4013. throw;
  4014. }
  4015. }
  4016. }
  4017. //---------------------------------------------------------------------------
  4018. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4019. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4020. bool & Close)
  4021. {
  4022. // terminal can be already closed (e.g. dropped connection)
  4023. if (Terminal != NULL)
  4024. {
  4025. Configuration->Usage->Inc(L"ChecksumCalculated");
  4026. try
  4027. {
  4028. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4029. }
  4030. catch(...)
  4031. {
  4032. if (!Terminal->Active)
  4033. {
  4034. Close = true;
  4035. }
  4036. throw;
  4037. }
  4038. }
  4039. }
  4040. //---------------------------------------------------------------------------
  4041. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4042. {
  4043. bool Result;
  4044. if (!IsSideLocalBrowser(Side))
  4045. {
  4046. TRemoteTokenList * GroupList = NULL;
  4047. TRemoteTokenList * UserList = NULL;
  4048. try
  4049. {
  4050. TRemoteProperties CurrentProperties;
  4051. if (Terminal->LoadFilesProperties(FileList))
  4052. {
  4053. RemoteDirView->Invalidate();
  4054. }
  4055. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4056. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4057. if (CapableGroupChanging || CapableOwnerChanging)
  4058. {
  4059. if (CapableGroupChanging)
  4060. {
  4061. GroupList = Terminal->Groups->Duplicate();
  4062. }
  4063. if (CapableOwnerChanging)
  4064. {
  4065. UserList = Terminal->Users->Duplicate();
  4066. }
  4067. TRemoteDirectory * Files = Terminal->Files;
  4068. int Count = Files->Count;
  4069. if (Count > 100)
  4070. {
  4071. Count = 100;
  4072. }
  4073. for (int Index = 0; Index < Count; Index++)
  4074. {
  4075. TRemoteFile * File = Files->Files[Index];
  4076. if (CapableGroupChanging)
  4077. {
  4078. GroupList->AddUnique(File->Group);
  4079. }
  4080. if (CapableOwnerChanging)
  4081. {
  4082. UserList->AddUnique(File->Owner);
  4083. }
  4084. }
  4085. // if we haven't collected tokens for all files in current directory,
  4086. // make sure we collect them at least for all selected files.
  4087. // (note that so far the files in FileList has to be from current direcotry)
  4088. if (Count < Files->Count)
  4089. {
  4090. for (int Index = 0; Index < FileList->Count; Index++)
  4091. {
  4092. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4093. if (CapableGroupChanging)
  4094. {
  4095. GroupList->AddUnique(File->Group);
  4096. }
  4097. if (CapableOwnerChanging)
  4098. {
  4099. UserList->AddUnique(File->Owner);
  4100. }
  4101. }
  4102. }
  4103. }
  4104. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4105. int Flags = 0;
  4106. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4107. if (CapableOwnerChanging) Flags |= cpOwner;
  4108. if (CapableGroupChanging) Flags |= cpGroup;
  4109. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4110. if (Terminal->IsCapable[fcCalculatingChecksum])
  4111. {
  4112. CalculateChecksumEvent = CalculateChecksum;
  4113. }
  4114. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4115. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4116. TRemoteProperties NewProperties = CurrentProperties;
  4117. Result =
  4118. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4119. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4120. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4121. CalculateSize, CalculateChecksumEvent);
  4122. if (Result)
  4123. {
  4124. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4125. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4126. }
  4127. }
  4128. __finally
  4129. {
  4130. delete GroupList;
  4131. delete UserList;
  4132. }
  4133. }
  4134. else
  4135. {
  4136. DirView(Side)->DisplayPropertiesMenu();
  4137. Result = true;
  4138. }
  4139. return Result;
  4140. }
  4141. //---------------------------------------------------------------------------
  4142. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4143. {
  4144. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4145. {
  4146. FIgnoreNextDialogChar = Key;
  4147. }
  4148. Key = 0;
  4149. }
  4150. //---------------------------------------------------------------------------
  4151. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4152. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4153. {
  4154. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4155. if (Command != NULL)
  4156. {
  4157. KeyProcessed(Key, Shift);
  4158. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4159. {
  4160. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4161. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4162. false, false, const_cast<TCustomCommandType *>(Command));
  4163. }
  4164. }
  4165. }
  4166. //---------------------------------------------------------------------------
  4167. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4168. {
  4169. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4170. {
  4171. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4172. }
  4173. if (!DirView(osCurrent)->IsEditing())
  4174. {
  4175. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4176. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4177. {
  4178. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4179. // But so far it's not a problem, as it does what we want.
  4180. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4181. if (((Action->ShortCut == KeyShortCut) ||
  4182. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4183. AllowedAction(Action, aaShortCut))
  4184. {
  4185. // Has to be called before the action as the dialog char is already in queue.
  4186. // So when the action consumes message queue, we already need to have the
  4187. // FIgnoreNextDialogChar set
  4188. KeyProcessed(Key, Shift);
  4189. // Reset reference to previous component (when menu/toolbar was clicked).
  4190. // Needed to detect that action was invoked by keyboard shortcut
  4191. // in TNonVisualDataModule::ExplorerActionsExecute
  4192. Action->ActionComponent = NULL;
  4193. Action->Execute();
  4194. return;
  4195. }
  4196. }
  4197. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4198. {
  4199. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4200. {
  4201. KeyProcessed(Key, Shift);
  4202. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4203. return;
  4204. }
  4205. }
  4206. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4207. {
  4208. KeyProcessed(Key, Shift);
  4209. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4210. }
  4211. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4212. if (IsCustomShortCut(CustomShortCut))
  4213. {
  4214. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4215. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4216. if (WinConfiguration->SharedBookmarks != NULL)
  4217. {
  4218. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4219. if ((Bookmark != NULL) &&
  4220. OpenBookmark(FCurrentSide, Bookmark))
  4221. {
  4222. KeyProcessed(Key, Shift);
  4223. }
  4224. }
  4225. }
  4226. }
  4227. TForm::KeyDown(Key, Shift);
  4228. }
  4229. //---------------------------------------------------------------------------
  4230. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4231. {
  4232. DebugAssert(Terminal != NULL);
  4233. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4234. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4235. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4236. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4237. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4238. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4239. // expanded from ?: to avoid memory leaks
  4240. if (SecurityEnabled)
  4241. {
  4242. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4243. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4244. }
  4245. else
  4246. {
  4247. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4248. }
  4249. if (FileSystemInfo.ProtocolName.IsEmpty())
  4250. {
  4251. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4252. }
  4253. else
  4254. {
  4255. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4256. }
  4257. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4258. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4259. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4260. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4261. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4262. UnicodeString CompressionStr = CSCompressionStr;
  4263. if (CSCompressionStr != SCCompressionStr)
  4264. {
  4265. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4266. }
  4267. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4268. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4269. UpdateStatusBar();
  4270. }
  4271. //---------------------------------------------------------------------------
  4272. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4273. {
  4274. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4275. DebugAssert(SessionStatusBar != NULL);
  4276. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4277. {
  4278. // note: (Terminal->Status < sshReady) currently never happens here,
  4279. // so STATUS_CONNECTING is never used
  4280. SessionStatusBar->SimplePanel = true;
  4281. SessionStatusBar->SimpleText = LoadStr(
  4282. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4283. }
  4284. else
  4285. {
  4286. DebugAssert(Terminal);
  4287. SessionStatusBar->SimplePanel = false;
  4288. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4289. if (!FNote.IsEmpty())
  4290. {
  4291. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4292. }
  4293. else
  4294. {
  4295. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4296. }
  4297. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4298. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4299. }
  4300. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4301. }
  4302. //---------------------------------------------------------------------------
  4303. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4304. {
  4305. Panel->Caption = L"";
  4306. }
  4307. //---------------------------------------------------------------------------
  4308. void __fastcall TCustomScpExplorerForm::Idle()
  4309. {
  4310. if (FShowing || FStandaloneEditing)
  4311. {
  4312. FEditorManager->Check();
  4313. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4314. // that needs to know if queue view is visible (and it may be closed after queue update)
  4315. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4316. }
  4317. if (FShowing)
  4318. {
  4319. if (!NonVisualDataModule->Busy &&
  4320. // Menu is opened or drag&drop is going on
  4321. (Mouse->Capture == NULL))
  4322. {
  4323. if (FRefreshRemoteDirectory)
  4324. {
  4325. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4326. {
  4327. Terminal->RefreshDirectory();
  4328. }
  4329. FRefreshRemoteDirectory = false;
  4330. }
  4331. if (FRefreshLocalDirectory)
  4332. {
  4333. ReloadLocalDirectory();
  4334. FRefreshLocalDirectory = false;
  4335. }
  4336. if (WinConfiguration->RefreshRemotePanel)
  4337. {
  4338. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4339. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4340. {
  4341. RemoteDirView->ReloadDirectory();
  4342. }
  4343. }
  4344. if (!FStarted)
  4345. {
  4346. FStarted = true;
  4347. InterfaceStarted();
  4348. }
  4349. }
  4350. }
  4351. if (FShowing || FStandaloneEditing)
  4352. {
  4353. if (FQueueStatusInvalidated)
  4354. {
  4355. UpdateQueueStatus(false);
  4356. }
  4357. RefreshQueueItems();
  4358. }
  4359. if (FShowing)
  4360. {
  4361. UpdateStatusBar();
  4362. }
  4363. FIgnoreNextDialogChar = 0;
  4364. }
  4365. //---------------------------------------------------------------------------
  4366. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4367. {
  4368. try
  4369. {
  4370. FUserActionTimer->Enabled = false;
  4371. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4372. {
  4373. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4374. {
  4375. FPendingQueueActionItem->ProcessUserAction();
  4376. }
  4377. }
  4378. }
  4379. __finally
  4380. {
  4381. FPendingQueueActionItem = NULL;
  4382. }
  4383. }
  4384. //---------------------------------------------------------------------------
  4385. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4386. {
  4387. if (WinConfiguration->MinimizeToTray)
  4388. {
  4389. UpdateTrayIcon();
  4390. FTrayIcon->Visible = true;
  4391. if (Visible)
  4392. {
  4393. ShowWindow(Handle, SW_HIDE);
  4394. }
  4395. }
  4396. }
  4397. //---------------------------------------------------------------------------
  4398. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4399. {
  4400. // WORKAROUND
  4401. // When restoring maximized window from minimization,
  4402. // rarely some controls do not align properly.
  4403. // Two instances seen (both for Commander):
  4404. // - When restoring, window is temporarily narrower (not maximized),
  4405. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4406. // Once maximized already, top dock shinks back, but the session PageControl,
  4407. // do not align up, leaving space between TopDock and PageControl.
  4408. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4409. for (int Index = 0; Index < ControlCount; Index++)
  4410. {
  4411. RealignControl(Controls[Index]);
  4412. }
  4413. if (FTrayIcon->Visible)
  4414. {
  4415. FTrayIcon->Visible = false;
  4416. if (Visible)
  4417. {
  4418. ShowWindow(Handle, SW_SHOW);
  4419. }
  4420. }
  4421. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4422. {
  4423. FNeedSession = false;
  4424. NonVisualDataModule->StartBusy();
  4425. try
  4426. {
  4427. NeedSession(true);
  4428. }
  4429. __finally
  4430. {
  4431. NonVisualDataModule->EndBusy();
  4432. }
  4433. }
  4434. }
  4435. //---------------------------------------------------------------------------
  4436. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4437. {
  4438. FTrayIcon->Hint = GetMainForm()->Caption;
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4442. {
  4443. UpdateTrayIcon();
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4447. {
  4448. // workaround
  4449. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4450. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4451. // But WM_ACTIVATEAPP message can be received even when
  4452. // the main window is minimized to the tray and internal editor window is focused
  4453. // (after another application was previously active)
  4454. if (::IsIconic(Handle))
  4455. {
  4456. if (!IsAppIconic())
  4457. {
  4458. SetAppIconic(true);
  4459. }
  4460. }
  4461. ::ApplicationRestore();
  4462. Application->BringToFront();
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4466. {
  4467. RestoreApp();
  4468. }
  4469. //---------------------------------------------------------------------------
  4470. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4471. {
  4472. if (OpenInNewWindow())
  4473. {
  4474. // todo: Pass FromSite
  4475. ExecuteNewInstance(SessionUrl);
  4476. }
  4477. else
  4478. {
  4479. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4480. }
  4481. }
  4482. //---------------------------------------------------------------------------
  4483. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4484. {
  4485. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4486. StoredSessions->NewSession(SessionName, SessionData);
  4487. // modified only, explicit
  4488. StoredSessions->Save(false, true);
  4489. // encode session name because of slashes in hierarchical sessions
  4490. return EncodeUrlString(SessionName);
  4491. }
  4492. //---------------------------------------------------------------------------
  4493. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4494. {
  4495. // current working directories become defaults here, what is not right
  4496. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4497. return SaveHiddenDuplicateSession(SessionData.get());
  4498. }
  4499. //---------------------------------------------------------------------------
  4500. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4501. {
  4502. if (OpenInNewWindow())
  4503. {
  4504. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4505. }
  4506. else
  4507. {
  4508. // current working directories become defaults here, what is not right
  4509. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4510. TTerminalManager * Manager = TTerminalManager::Instance();
  4511. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4512. Manager->ActiveTerminal = Terminal;
  4513. }
  4514. }
  4515. //---------------------------------------------------------------------------
  4516. void __fastcall TCustomScpExplorerForm::RenameSession()
  4517. {
  4518. UnicodeString Name = Terminal->SessionData->SessionName;
  4519. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4520. {
  4521. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4522. TSessionData::ValidateName(Name);
  4523. // This is inconsistent with how color (for example) is handled.
  4524. Terminal->SessionData->Name = Name;
  4525. UpdateControls();
  4526. // Add/Remove distinguishing paths from sessions of the same name.
  4527. DoTerminalListChanged();
  4528. }
  4529. }
  4530. //---------------------------------------------------------------------------
  4531. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4532. {
  4533. DebugAssert(Queue != NULL);
  4534. bool Result = Queue->IsEmpty;
  4535. if (!Result)
  4536. {
  4537. SetFocus();
  4538. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4539. }
  4540. return Result;
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4544. {
  4545. return CanCloseQueue(FQueue);
  4546. }
  4547. //---------------------------------------------------------------------------
  4548. void __fastcall TCustomScpExplorerForm::CloseSession()
  4549. {
  4550. if (CanCloseQueue())
  4551. {
  4552. TTerminalManager::Instance()->FreeActiveTerminal();
  4553. }
  4554. }
  4555. //---------------------------------------------------------------------------
  4556. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4557. {
  4558. if (CanCloseQueue())
  4559. {
  4560. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4561. }
  4562. }
  4563. //---------------------------------------------------------------------------
  4564. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4565. {
  4566. DetachTerminal(Terminal);
  4567. RemoteDirView->Terminal = Terminal;
  4568. UpdateRemotePathComboBox(false);
  4569. UpdateControls();
  4570. }
  4571. //---------------------------------------------------------------------------
  4572. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4573. {
  4574. if (DebugAlwaysTrue(!Terminal->Active))
  4575. {
  4576. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4577. }
  4578. }
  4579. //---------------------------------------------------------------------------
  4580. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4581. {
  4582. if (OpenInNewWindow())
  4583. {
  4584. // encode session name because of slashes in hierarchical sessions
  4585. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4586. }
  4587. else
  4588. {
  4589. TTerminalManager * Manager = TTerminalManager::Instance();
  4590. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4591. Manager->ActiveTerminal = Terminal;
  4592. }
  4593. }
  4594. //---------------------------------------------------------------------------
  4595. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4596. {
  4597. TTerminalManager * Manager = TTerminalManager::Instance();
  4598. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4599. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4600. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4601. // FirstTerminal can be null, if some of the
  4602. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4603. {
  4604. FirstTerminal->Disconnected = true;
  4605. FirstTerminal->DisconnectedTemporarily = true;
  4606. }
  4607. Manager->ActiveTerminal = FirstTerminal;
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4611. {
  4612. if (OpenInNewWindow())
  4613. {
  4614. ExecuteNewInstance(Name);
  4615. }
  4616. else
  4617. {
  4618. DoOpenFolderOrWorkspace(Name, true);
  4619. }
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4623. bool &CanClose)
  4624. {
  4625. // See the comment in CloseApp()
  4626. if (NonVisualDataModule->Busy)
  4627. {
  4628. CanClose = false;
  4629. }
  4630. else if (Terminal != NULL)
  4631. {
  4632. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4633. {
  4634. unsigned int Result;
  4635. TMessageParams Params(mpNeverAskAgainCheck);
  4636. UnicodeString Message;
  4637. int Answers = qaOK | qaCancel;
  4638. if (TTerminalManager::Instance()->Count > 1)
  4639. {
  4640. if (!WinConfiguration->AutoSaveWorkspace)
  4641. {
  4642. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4643. }
  4644. else
  4645. {
  4646. Message = LoadStr(CLOSE_SESSIONS);
  4647. }
  4648. }
  4649. else
  4650. {
  4651. if (!WinConfiguration->AutoSaveWorkspace)
  4652. {
  4653. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4654. }
  4655. else
  4656. {
  4657. Message = LoadStr(CLOSE_SESSION);
  4658. }
  4659. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4660. }
  4661. UnicodeString Note;
  4662. if (WinConfiguration->AutoSaveWorkspace)
  4663. {
  4664. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4665. }
  4666. else
  4667. {
  4668. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4669. Answers = qaYes | qaNo | qaCancel;
  4670. }
  4671. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4672. SetFocus();
  4673. Result = MessageDialog(Message, qtConfirmation,
  4674. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4675. if (Result == qaNeverAskAgain)
  4676. {
  4677. WinConfiguration->ConfirmClosingSession = false;
  4678. }
  4679. if (Result == qaNo)
  4680. {
  4681. CanClose = SaveWorkspace(true);
  4682. // note that the workspace will be saved redundatly again from FormClose
  4683. }
  4684. else
  4685. {
  4686. CanClose =
  4687. (Result == qaOK) ||
  4688. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4689. (Result == qaNeverAskAgain);
  4690. }
  4691. }
  4692. if (CanClose)
  4693. {
  4694. CanClose = CanCloseQueue();
  4695. }
  4696. }
  4697. if (CanClose)
  4698. {
  4699. CanClose =
  4700. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4701. FEditorManager->CloseExternalFilesWithoutProcess();
  4702. if (CanClose)
  4703. {
  4704. while (CanClose && (FLocalEditors->Count > 0))
  4705. {
  4706. int PrevCount = FLocalEditors->Count;
  4707. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4708. CanClose = (FLocalEditors->Count < PrevCount);
  4709. }
  4710. if (CanClose)
  4711. {
  4712. CanClose = FEditorManager->Empty(true);
  4713. if (!CanClose)
  4714. {
  4715. SetFocus();
  4716. CanClose =
  4717. (MessageDialog(
  4718. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. //---------------------------------------------------------------------------
  4725. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4726. {
  4727. TForm * Form = dynamic_cast<TForm *>(Sender);
  4728. DebugAssert(Form != NULL);
  4729. Form->Close();
  4730. }
  4731. //---------------------------------------------------------------------------
  4732. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4733. {
  4734. TForm * Form = dynamic_cast<TForm *>(Sender);
  4735. delete Form;
  4736. }
  4737. //---------------------------------------------------------------------------
  4738. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4739. {
  4740. while (FLocalEditors->Count > 0)
  4741. {
  4742. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4743. }
  4744. }
  4745. //---------------------------------------------------------------------------
  4746. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4747. TObject *Sender)
  4748. {
  4749. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4750. try
  4751. {
  4752. SetProperties(osRemote, FileList);
  4753. }
  4754. __finally
  4755. {
  4756. delete FileList;
  4757. }
  4758. }
  4759. //---------------------------------------------------------------------------
  4760. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4761. {
  4762. if (value)
  4763. {
  4764. if (Component == fcCustomCommandsBand)
  4765. {
  4766. UpdateCustomCommandsToolbar();
  4767. }
  4768. if (Component == fcQueueFileList)
  4769. {
  4770. DebugAssert(!QueueFileListSplitter->Visible);
  4771. AdjustQueueLayout();
  4772. UpdateQueueFileList();
  4773. }
  4774. }
  4775. }
  4776. //---------------------------------------------------------------------------
  4777. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4778. {
  4779. int MinHeightLimit =
  4780. GetStaticQueuePanelComponentsHeight() +
  4781. QueueFileListSplitter->Height +
  4782. QueueFileList->Height +
  4783. GetMinQueueViewHeight();
  4784. if (QueuePanel->ClientHeight < MinHeightLimit)
  4785. {
  4786. QueuePanel->ClientHeight = MinHeightLimit;
  4787. }
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4791. {
  4792. TControl * Control = GetComponent(Component);
  4793. DebugAssert(Control);
  4794. bool Changed = (Control->Visible != value);
  4795. if (Changed)
  4796. {
  4797. ComponentShowing(Component, value);
  4798. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4799. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4800. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4801. if (value)
  4802. {
  4803. int RemainingHeight = Control->Parent->ClientHeight;
  4804. int RemainingWidth = Control->Parent->ClientWidth;
  4805. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4806. {
  4807. TControl * ChildControl = Control->Parent->Controls[i];
  4808. if (ChildControl->Visible)
  4809. {
  4810. switch (ChildControl->Align)
  4811. {
  4812. case alTop:
  4813. case alBottom:
  4814. RemainingHeight -= ChildControl->Height;
  4815. break;
  4816. case alLeft:
  4817. case alRight:
  4818. RemainingWidth -= ChildControl->Width;
  4819. break;
  4820. }
  4821. }
  4822. }
  4823. int Reserve = ScaleByTextHeight(this, 32);
  4824. // queue in explorer, trees in commander
  4825. if (Control->Height > RemainingHeight - Reserve)
  4826. {
  4827. Control->Height = RemainingHeight / 2;
  4828. }
  4829. if (Control->Width > RemainingWidth - Reserve)
  4830. {
  4831. Control->Width = RemainingWidth / 2;
  4832. }
  4833. }
  4834. Control->Visible = value;
  4835. if (WasFocused && Visible)
  4836. {
  4837. DirView(osCurrent)->SetFocus();
  4838. }
  4839. FixControlsPlacement();
  4840. }
  4841. }
  4842. //---------------------------------------------------------------------------
  4843. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4844. {
  4845. TControl * Control = GetComponent(Component);
  4846. if (Control == NULL)
  4847. {
  4848. return false;
  4849. }
  4850. else
  4851. {
  4852. return Control->Visible;
  4853. }
  4854. }
  4855. //---------------------------------------------------------------------------
  4856. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4857. {
  4858. bool Result;
  4859. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4860. {
  4861. Result = !IsUWP();
  4862. }
  4863. else
  4864. {
  4865. Result = true;
  4866. }
  4867. return Result;
  4868. }
  4869. //---------------------------------------------------------------------------
  4870. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4871. {
  4872. if (DirView->ItemFocused != NULL)
  4873. {
  4874. DirView->ItemFocused->MakeVisible(false);
  4875. }
  4876. }
  4877. //---------------------------------------------------------------------------
  4878. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4879. {
  4880. MakeFocusedItemVisible(RemoteDirView);
  4881. QueueSplitter->Visible = QueuePanel->Visible;
  4882. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4883. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4884. TControl * QueueControlsOrder[] =
  4885. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4886. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4890. {
  4891. switch (Component) {
  4892. case fcStatusBar: return RemoteStatusBar;
  4893. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4894. case fcQueueView: return QueuePanel;
  4895. case fcQueueToolbar: return QueueDock;
  4896. case fcRemoteTree: return RemoteDrivePanel;
  4897. case fcSessionsTabs: return SessionsPageControl;
  4898. case fcQueueFileList: return QueueFileList;
  4899. default: return NULL;
  4900. }
  4901. }
  4902. //---------------------------------------------------------------------------
  4903. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4904. TObject *Sender, TListColumn *Column, TPoint &Point)
  4905. {
  4906. DebugAssert(NonVisualDataModule && Column && Sender);
  4907. NonVisualDataModule->ListColumn = Column;
  4908. TPopupMenu * DirViewColumnMenu;
  4909. if (Sender == DirView(osOther))
  4910. {
  4911. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4912. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4913. (Column->Index == uvName);
  4914. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4915. (Column->Index == uvSize);
  4916. }
  4917. else
  4918. {
  4919. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4920. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4921. (Column->Index == dvName);
  4922. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4923. (Column->Index == dvSize);
  4924. }
  4925. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4926. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4927. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4928. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4929. }
  4930. //---------------------------------------------------------------------------
  4931. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4932. TObject *Sender, TListItem *Item, bool &AllowExec)
  4933. {
  4934. DoDirViewExecFile(Sender, Item, AllowExec);
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4938. TListItem * Item, bool & AllowExec)
  4939. {
  4940. DebugAssert(Sender && Item && Configuration);
  4941. DebugAssert(AllowExec);
  4942. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4943. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4944. bool Remote = !IsSideLocalBrowser(Side);
  4945. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4946. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4947. // on files only (not directories)
  4948. // and only when symlinks are resolved (apply to remote panel only)
  4949. if (!ADirView->ItemIsDirectory(Item) &&
  4950. (ResolvedSymlinks || FForceExecution))
  4951. {
  4952. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4953. !FForceExecution && ResolvedSymlinks)
  4954. {
  4955. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4956. {
  4957. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4958. UnlockWindow();
  4959. try
  4960. {
  4961. ExecuteFileOperation(
  4962. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4963. }
  4964. __finally
  4965. {
  4966. LockWindow();
  4967. }
  4968. AllowExec = false;
  4969. }
  4970. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4971. {
  4972. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4973. {
  4974. ExecuteFile(Side, efDefaultEditor);
  4975. AllowExec = false;
  4976. }
  4977. }
  4978. else
  4979. {
  4980. DebugFail();
  4981. }
  4982. }
  4983. // if we have not done anything special, fall back to default behavior
  4984. if (AllowExec)
  4985. {
  4986. if (Remote && !WinConfiguration->DisableOpenEdit)
  4987. {
  4988. ExecuteFile(osRemote, efShell);
  4989. AllowExec = false;
  4990. }
  4991. }
  4992. }
  4993. }
  4994. //---------------------------------------------------------------------------
  4995. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4996. {
  4997. return ((Side == osRemote) || (Side == osCurrent));
  4998. }
  4999. //---------------------------------------------------------------------------
  5000. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5001. {
  5002. DebugFail();
  5003. }
  5004. //---------------------------------------------------------------------------
  5005. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5006. {
  5007. DebugFail();
  5008. }
  5009. //---------------------------------------------------------------------------
  5010. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5011. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5012. {
  5013. TSynchronizeParamType Params;
  5014. Params.LocalDirectory = LocalDirectory;
  5015. Params.RemoteDirectory = RemoteDirectory;
  5016. int UnusedParams =
  5017. (GUIConfiguration->SynchronizeParams &
  5018. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5019. TTerminal::spCaseSensitive));
  5020. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5021. Params.Options = GUIConfiguration->SynchronizeOptions;
  5022. bool SaveSettings = false;
  5023. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5024. &DoSynchronizeTooManyDirectories);
  5025. DebugAssert(FSynchronizeController == NULL);
  5026. FSynchronizeController = &Controller;
  5027. bool Result;
  5028. try
  5029. {
  5030. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5031. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5032. int Options =
  5033. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5034. DebugAssert(FOnFeedSynchronizeError == NULL);
  5035. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5036. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5037. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5038. if (Result)
  5039. {
  5040. if (SaveSettings)
  5041. {
  5042. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5043. GUIConfiguration->SynchronizeOptions = Params.Options;
  5044. }
  5045. else
  5046. {
  5047. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5048. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5049. FLAGSET(Params.Options, soSynchronize))
  5050. {
  5051. GUIConfiguration->SynchronizeOptions =
  5052. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5053. soSynchronize;
  5054. }
  5055. }
  5056. LocalDirectory = Params.LocalDirectory;
  5057. RemoteDirectory = Params.RemoteDirectory;
  5058. }
  5059. }
  5060. __finally
  5061. {
  5062. FSynchronizeController = NULL;
  5063. DebugAssert(FOnFeedSynchronizeError == NULL);
  5064. FOnFeedSynchronizeError = NULL;
  5065. }
  5066. return Result;
  5067. }
  5068. //---------------------------------------------------------------------------
  5069. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5070. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5071. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5072. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5073. TSynchronizeOptions * Options, bool Full)
  5074. {
  5075. // Keep-up-to-date mode
  5076. if (Terminal->Status == ssOpened)
  5077. {
  5078. try
  5079. {
  5080. int PParams = Params.Params;
  5081. if (!Full)
  5082. {
  5083. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5084. if (FLAGSET(Params.Options, soRecurse))
  5085. {
  5086. PParams |= TTerminal::spSubDirs;
  5087. }
  5088. }
  5089. else
  5090. {
  5091. // if keepuptodate is non-recursive,
  5092. // full sync before has to be non-recursive as well
  5093. if (FLAGCLEAR(Params.Options, soRecurse))
  5094. {
  5095. PParams |= TTerminal::spNoRecurse;
  5096. }
  5097. }
  5098. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5099. PParams, Checklist, Options);
  5100. }
  5101. catch (Exception & E)
  5102. {
  5103. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5104. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5105. {
  5106. // noop, already logged in MoreMessageDialog
  5107. }
  5108. else
  5109. {
  5110. ShowExtendedExceptionEx(Terminal, &E);
  5111. throw;
  5112. }
  5113. }
  5114. }
  5115. }
  5116. //---------------------------------------------------------------------------
  5117. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5118. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5119. const UnicodeString ErrorStr)
  5120. {
  5121. if (!Directory.IsEmpty())
  5122. {
  5123. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5124. }
  5125. else
  5126. {
  5127. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5128. }
  5129. }
  5130. //---------------------------------------------------------------------------
  5131. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5132. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5133. {
  5134. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5135. {
  5136. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5137. }
  5138. else
  5139. {
  5140. TMessageParams Params(mpNeverAskAgainCheck);
  5141. unsigned int Result = MessageDialog(
  5142. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5143. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5144. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5145. {
  5146. MaxDirectories *= 2;
  5147. if (Result == qaNeverAskAgain)
  5148. {
  5149. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5150. }
  5151. }
  5152. else
  5153. {
  5154. Abort();
  5155. }
  5156. }
  5157. }
  5158. //---------------------------------------------------------------------------
  5159. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5160. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5161. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5162. TSynchronizeOptions * Options)
  5163. {
  5164. // Keep-up-to-date mode
  5165. DebugAssert(!FAutoOperation);
  5166. void * BatchStorage;
  5167. BatchStart(BatchStorage);
  5168. FAutoOperation = true;
  5169. bool AnyOperation = false;
  5170. TDateTime StartTime = Now();
  5171. TSynchronizeChecklist * AChecklist = NULL;
  5172. try
  5173. {
  5174. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5175. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5176. {
  5177. FSynchronizeProgressForm->Start();
  5178. }
  5179. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5180. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5181. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5182. Options);
  5183. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5184. SAFE_DESTROY(FSynchronizeProgressForm);
  5185. AnyOperation = (AChecklist->CheckedCount > 0);
  5186. if (AnyOperation)
  5187. {
  5188. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5189. CreateProgressForm(&SynchronizeProgress);
  5190. try
  5191. {
  5192. Terminal->SynchronizeApply(
  5193. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5194. SynchronizeProcessedItem, NULL, NULL, NULL);
  5195. }
  5196. __finally
  5197. {
  5198. DestroyProgressForm();
  5199. }
  5200. }
  5201. }
  5202. __finally
  5203. {
  5204. if (Checklist == NULL)
  5205. {
  5206. delete AChecklist;
  5207. }
  5208. else
  5209. {
  5210. *Checklist = AChecklist;
  5211. }
  5212. FAutoOperation = false;
  5213. SAFE_DESTROY(FSynchronizeProgressForm);
  5214. BatchEnd(BatchStorage);
  5215. ReloadLocalDirectory();
  5216. if (AnyOperation)
  5217. {
  5218. OperationComplete(StartTime);
  5219. }
  5220. }
  5221. }
  5222. //---------------------------------------------------------------------------
  5223. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5224. {
  5225. // can be called from command line
  5226. return Visible &&
  5227. ((DirView(osRemote)->SelCount > 0) ||
  5228. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5229. }
  5230. //---------------------------------------------------------------------------
  5231. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5232. {
  5233. LogSynchronizeEvent(Terminal, Message);
  5234. }
  5235. //---------------------------------------------------------------------------
  5236. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5237. int Params, TSynchronizeOptions & Options)
  5238. {
  5239. DebugAssert(!IsLocalBrowserMode());
  5240. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5241. {
  5242. Options.Filter = new TStringList();
  5243. Options.Filter->CaseSensitive = false;
  5244. Options.Filter->Duplicates = Types::dupAccept;
  5245. if (DirView(osRemote)->SelCount > 0)
  5246. {
  5247. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5248. }
  5249. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5250. {
  5251. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5252. }
  5253. Options.Filter->Sort();
  5254. }
  5255. }
  5256. //---------------------------------------------------------------------------
  5257. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5258. {
  5259. TCopyParamType Defaults;
  5260. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5261. ConfigStorage->AccessMode = smRead;
  5262. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5263. {
  5264. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5265. }
  5266. ConfigStorage.reset(NULL);
  5267. std::unique_ptr<TStringList> Options(new TStringList());
  5268. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5269. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5270. UnicodeString Result;
  5271. if (Options->Count > 0)
  5272. {
  5273. Result =
  5274. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5275. }
  5276. return Result;
  5277. }
  5278. //---------------------------------------------------------------------------
  5279. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5280. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5281. {
  5282. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5283. UnicodeString AdditionalParams =
  5284. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5285. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5286. SerializeCopyParamForCommandLine(CopyParams),
  5287. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5288. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5289. ExecuteNewInstance(SessionName, AdditionalParams);
  5290. }
  5291. //---------------------------------------------------------------------------
  5292. struct TSynchronizeParams
  5293. {
  5294. UnicodeString LocalDirectory;
  5295. UnicodeString RemoteDirectory;
  5296. TSynchronizeMode Mode;
  5297. TSynchronizeChecklist * Checklist;
  5298. int Params;
  5299. TCopyParamType * CopyParam;
  5300. TDateTime CollectElapsed;
  5301. TDateTime * StartTime;
  5302. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5303. };
  5304. //---------------------------------------------------------------------------
  5305. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5306. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5307. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5308. {
  5309. DebugAssert(!FAutoOperation);
  5310. void * BatchStorage;
  5311. BatchStart(BatchStorage);
  5312. FAutoOperation = true;
  5313. TFileOperationStatistics Statistics;
  5314. TDateTime Start = Now();
  5315. try
  5316. {
  5317. Params.OnProcessedItem = OnProcessedItem;
  5318. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5319. CreateProgressForm(&SynchronizeProgress);
  5320. Terminal->SynchronizeApply(
  5321. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5322. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5323. &Statistics);
  5324. }
  5325. __finally
  5326. {
  5327. Params.OnProcessedItem = NULL;
  5328. FAutoOperation = false;
  5329. DestroyProgressForm();
  5330. BatchEnd(BatchStorage);
  5331. ReloadLocalDirectory();
  5332. }
  5333. if (WinConfiguration->SynchronizeSummary)
  5334. {
  5335. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5336. // The statistics should be 0 anyway in this case
  5337. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5338. {
  5339. Message += L"\n";
  5340. if (Statistics.FilesUploaded > 0)
  5341. {
  5342. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5343. }
  5344. if (Statistics.FilesDownloaded > 0)
  5345. {
  5346. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5347. }
  5348. if (Statistics.FilesDeletedLocal > 0)
  5349. {
  5350. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5351. }
  5352. if (Statistics.FilesDeletedRemote > 0)
  5353. {
  5354. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5355. }
  5356. }
  5357. TDateTime Elapsed = (Now() - Start);
  5358. Message +=
  5359. L"\n" +
  5360. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5361. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5362. TMessageParams Params(mpNeverAskAgainCheck);
  5363. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5364. if (Result == qaNeverAskAgain)
  5365. {
  5366. WinConfiguration->SynchronizeSummary = false;
  5367. }
  5368. }
  5369. }
  5370. //---------------------------------------------------------------------------
  5371. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5372. {
  5373. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5374. {
  5375. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5376. }
  5377. // Not set in keep-up-to-date mode - Synchronize() method
  5378. if (Token != NULL)
  5379. {
  5380. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5381. if (Params.OnProcessedItem != NULL)
  5382. {
  5383. Params.OnProcessedItem(NULL, ChecklistItem);
  5384. }
  5385. }
  5386. }
  5387. //---------------------------------------------------------------------------
  5388. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5389. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5390. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5391. {
  5392. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5393. *Params.StartTime = Now();
  5394. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5395. }
  5396. //---------------------------------------------------------------------------
  5397. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5398. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5399. {
  5400. // terminal can be already closed (e.g. dropped connection)
  5401. if (Terminal != NULL)
  5402. {
  5403. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5404. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5405. }
  5406. }
  5407. //---------------------------------------------------------------------------
  5408. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5409. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5410. {
  5411. DebugAssert(!IsLocalBrowserMode());
  5412. TAutoBatch AutoBatch(this);
  5413. TAutoFlag AutoOperationFlag(FAutoOperation);
  5414. if (Side == osRemote)
  5415. {
  5416. std::unique_ptr<TStrings> FileList(new TStringList());
  5417. FileList->AddObject(FileName, RemoteFile);
  5418. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5419. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5420. RemoteDirView->SaveSelection();
  5421. RemoteDirView->SaveSelectedNames();
  5422. try
  5423. {
  5424. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5425. }
  5426. catch(...)
  5427. {
  5428. RemoteDirView->DiscardSavedSelection();
  5429. throw;
  5430. }
  5431. RemoteDirView->RestoreSelection();
  5432. }
  5433. else if (DebugAlwaysTrue(Side == osLocal))
  5434. {
  5435. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5436. {
  5437. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5438. }
  5439. UnicodeString Directory = ExtractFileDir(FileName);
  5440. ReloadLocalDirectory(Directory);
  5441. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5442. if (!SamePaths(Directory, NewDirectory))
  5443. {
  5444. ReloadLocalDirectory(NewDirectory);
  5445. }
  5446. }
  5447. }
  5448. //---------------------------------------------------------------------------
  5449. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5450. {
  5451. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5452. if (Side == osLocal)
  5453. {
  5454. if (Action == TSynchronizeChecklist::saDownloadNew)
  5455. {
  5456. OpenFolderInExplorer(LocalPath);
  5457. }
  5458. else
  5459. {
  5460. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5461. }
  5462. }
  5463. else if (DebugAlwaysTrue(Side == osRemote))
  5464. {
  5465. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5466. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5467. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5468. if (!LocalPath.IsEmpty())
  5469. {
  5470. SessionData->LocalDirectory = LocalPath;
  5471. }
  5472. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5473. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5474. }
  5475. }
  5476. //---------------------------------------------------------------------------
  5477. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5478. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5479. const TCopyParamType * CopyParams)
  5480. {
  5481. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5482. UnicodeString AdditionalParams =
  5483. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5484. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5485. SerializeCopyParamForCommandLine(CopyParams),
  5486. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5487. LocalDirectory, RemoteDirectory, Mode, Params));
  5488. ExecuteNewInstance(SessionName, AdditionalParams);
  5489. }
  5490. //---------------------------------------------------------------------------
  5491. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5492. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5493. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5494. {
  5495. int Result;
  5496. bool SaveSettings = false;
  5497. int Options =
  5498. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5499. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5500. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5501. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5502. bool Continue =
  5503. (UseDefaults == 0) ||
  5504. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5505. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5506. if (Continue)
  5507. {
  5508. Configuration->Usage->Inc(L"Synchronizations");
  5509. UpdateCopyParamCounters(CopyParam);
  5510. TSynchronizeOptions SynchronizeOptions;
  5511. GetSynchronizeOptions(Params, SynchronizeOptions);
  5512. if (SaveSettings)
  5513. {
  5514. GUIConfiguration->SynchronizeParams = Params;
  5515. }
  5516. else
  5517. {
  5518. SaveMode = false;
  5519. }
  5520. TDateTime StartTime = Now();
  5521. TSynchronizeChecklist * Checklist = NULL;
  5522. try
  5523. {
  5524. DebugAssert(!FAutoOperation);
  5525. FAutoOperation = true;
  5526. try
  5527. {
  5528. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5529. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5530. int Files = -1;
  5531. if (DataList->Count >= 1)
  5532. {
  5533. Files = StrToIntDef(DataList->Strings[0], Files);
  5534. }
  5535. else
  5536. {
  5537. DataList->Add(UnicodeString());
  5538. }
  5539. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5540. FSynchronizeProgressForm->Start();
  5541. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5542. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5543. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5544. &SynchronizeOptions);
  5545. if (Terminal->SessionData->CacheDirectories)
  5546. {
  5547. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5548. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5549. }
  5550. }
  5551. __finally
  5552. {
  5553. FAutoOperation = false;
  5554. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5555. SAFE_DESTROY(FSynchronizeProgressForm);
  5556. }
  5557. TSynchronizeParams SynchronizeParams;
  5558. SynchronizeParams.LocalDirectory = LocalDirectory;
  5559. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5560. SynchronizeParams.Mode = Mode;
  5561. SynchronizeParams.CopyParam = &CopyParam;
  5562. SynchronizeParams.Params = Params;
  5563. SynchronizeParams.Checklist = Checklist;
  5564. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5565. SynchronizeParams.StartTime = &StartTime;
  5566. SynchronizeParams.OnProcessedItem = NULL;
  5567. Result = Checklist->Count;
  5568. if (Checklist->Count > 0)
  5569. {
  5570. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5571. {
  5572. if (!DoSynchronizeChecklistDialog(
  5573. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5574. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5575. {
  5576. Result = -1;
  5577. }
  5578. }
  5579. else
  5580. {
  5581. FullSynchronize(SynchronizeParams, NULL, NULL);
  5582. }
  5583. }
  5584. else
  5585. {
  5586. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5587. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5588. }
  5589. }
  5590. __finally
  5591. {
  5592. delete Checklist;
  5593. }
  5594. OperationComplete(StartTime);
  5595. }
  5596. else
  5597. {
  5598. Result = -1;
  5599. }
  5600. return Result;
  5601. }
  5602. //---------------------------------------------------------------------------
  5603. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5604. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5605. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5606. {
  5607. if (Collect)
  5608. {
  5609. DebugAssert(FSynchronizeProgressForm != NULL);
  5610. if (!FSynchronizeProgressForm->Started)
  5611. {
  5612. FSynchronizeProgressForm->Start();
  5613. }
  5614. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5615. SetTaskbarListProgressValue(CompareProgress);
  5616. }
  5617. else
  5618. {
  5619. DebugAssert(FSynchronizeProgressForm == NULL);
  5620. DebugAssert(FProgressForm != NULL);
  5621. }
  5622. }
  5623. //---------------------------------------------------------------------------
  5624. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5625. {
  5626. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5627. TRemoteFile * File = NULL;
  5628. Terminal->ReadFile(FullFileName, File);
  5629. if (File != NULL)
  5630. {
  5631. std::unique_ptr<TRemoteFile> FileOwner(File);
  5632. TAutoFlag Flag(FStandaloneEditing);
  5633. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5634. Application->ShowMainForm = false;
  5635. Application->Run();
  5636. }
  5637. }
  5638. //---------------------------------------------------------------------------
  5639. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5640. {
  5641. DebugFail();
  5642. }
  5643. //---------------------------------------------------------------------------
  5644. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5645. {
  5646. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5647. SessionData->Assign(Terminal->SessionData);
  5648. UpdateSessionData(SessionData.get());
  5649. Terminal->UpdateSessionCredentials(SessionData.get());
  5650. if (!Terminal->SessionData->HasSessionName())
  5651. {
  5652. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5653. // once IsWorkspace is cleared
  5654. SessionData->Name = UnicodeString();
  5655. SessionData->IsWorkspace = false;
  5656. }
  5657. return SessionData.release();
  5658. }
  5659. //---------------------------------------------------------------------------
  5660. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5661. {
  5662. TSessionData * SessionData = CloneCurrentSessionData();
  5663. try
  5664. {
  5665. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5666. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5667. }
  5668. __finally
  5669. {
  5670. delete SessionData;
  5671. }
  5672. }
  5673. //---------------------------------------------------------------------------
  5674. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5675. {
  5676. TTerminalManager * Manager = TTerminalManager::Instance();
  5677. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5678. if (DebugAlwaysTrue(Terminal != NULL))
  5679. {
  5680. // Update (Managed)Terminal->StateData
  5681. UpdateTerminal(Terminal);
  5682. }
  5683. Manager->SaveWorkspace(DataList.get());
  5684. return DataList.release();
  5685. }
  5686. //---------------------------------------------------------------------------
  5687. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5688. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5689. {
  5690. WinConfiguration->LastWorkspace = Name;
  5691. if (!SavePasswords)
  5692. {
  5693. for (int Index = 0; Index < DataList->Count; Index++)
  5694. {
  5695. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5696. if (SessionData->Link.IsEmpty())
  5697. {
  5698. SessionData->ClearSessionPasswords();
  5699. }
  5700. }
  5701. }
  5702. StoredSessions->NewWorkspace(Name, DataList);
  5703. // modified only
  5704. StoredSessions->Save(false, Explicit);
  5705. }
  5706. //---------------------------------------------------------------------------
  5707. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5708. {
  5709. return
  5710. DefaultStr(WinConfiguration->LastWorkspace,
  5711. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5712. }
  5713. //---------------------------------------------------------------------------
  5714. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5715. {
  5716. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5717. bool AnyNonStoredSessionWithPassword = false;
  5718. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5719. bool AllNonStoredSessionsAnonymous = true;
  5720. TTerminalManager * Manager = TTerminalManager::Instance();
  5721. for (int Index = 0; Index < DataList->Count; Index++)
  5722. {
  5723. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5724. if (SessionData->Link.IsEmpty())
  5725. {
  5726. if (SessionData->HasAnySessionPassword())
  5727. {
  5728. AnyNonStoredSessionWithPassword = true;
  5729. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5730. {
  5731. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5732. }
  5733. }
  5734. if (!SameText(SessionData->UserName, AnonymousUserName))
  5735. {
  5736. AllNonStoredSessionsAnonymous = false;
  5737. }
  5738. }
  5739. }
  5740. bool SavePasswords;
  5741. bool * PSavePasswords;
  5742. bool NotRecommendedSavingPasswords =
  5743. !CustomWinConfiguration->UseMasterPassword &&
  5744. !AllNonStoredSessionsAnonymous;
  5745. if (Configuration->DisablePasswordStoring ||
  5746. !AnyNonStoredSessionWithPassword)
  5747. {
  5748. PSavePasswords = NULL;
  5749. SavePasswords = false;
  5750. }
  5751. else
  5752. {
  5753. PSavePasswords = &SavePasswords;
  5754. SavePasswords =
  5755. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5756. !NotRecommendedSavingPasswords;
  5757. }
  5758. UnicodeString Name = WorkspaceName();
  5759. bool CreateShortcut = false;
  5760. bool Result =
  5761. DoSaveWorkspaceDialog(
  5762. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5763. EnableAutoSave);
  5764. if (Result)
  5765. {
  5766. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5767. if (CreateShortcut)
  5768. {
  5769. TOperationVisualizer Visualizer;
  5770. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5771. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5772. }
  5773. if (EnableAutoSave)
  5774. {
  5775. WinConfiguration->AutoSaveWorkspace = true;
  5776. WinConfiguration->AutoWorkspace = Name;
  5777. if (PSavePasswords != NULL)
  5778. {
  5779. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5780. }
  5781. }
  5782. }
  5783. return Result;
  5784. }
  5785. //---------------------------------------------------------------------------
  5786. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5787. {
  5788. DebugAssert(!IsLocalBrowserMode());
  5789. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5790. if (WinConfiguration->PreservePanelState)
  5791. {
  5792. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5793. }
  5794. UpdateSessionData(Terminal->StateData);
  5795. }
  5796. //---------------------------------------------------------------------------
  5797. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5798. {
  5799. // Keep in sync with TSessionData::CopyStateData
  5800. DebugAssert(!IsLocalBrowserMode());
  5801. DebugAssert(Data != NULL);
  5802. // This is inconsistent with how color (for example) is handled.
  5803. Data->Name = Terminal->SessionData->Name;
  5804. // cannot use RemoteDirView->Path, because it is empty if connection
  5805. // was already closed
  5806. // also only peek, we may not be connected at all atm
  5807. // so make sure we do not try retrieving current directory from the server
  5808. // (particularly with FTP)
  5809. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5810. if (!ACurrentDirectory.IsEmpty())
  5811. {
  5812. Data->RemoteDirectory = ACurrentDirectory;
  5813. }
  5814. Data->Color = SessionColor;
  5815. }
  5816. //---------------------------------------------------------------------------
  5817. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5818. {
  5819. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5820. DebugAssert(Toolbar != NULL);
  5821. for (int i = 0; i < Toolbar->Items->Count; i++)
  5822. {
  5823. TTBXCustomDropDownItem * DropDownItem;
  5824. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5825. if (DropDownItem != NULL)
  5826. {
  5827. ToolbarItemResize(DropDownItem,
  5828. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5829. Toolbar->NonClientWidth);
  5830. break;
  5831. }
  5832. }
  5833. }
  5834. //---------------------------------------------------------------------------
  5835. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5836. {
  5837. Item->EditWidth = Width;
  5838. }
  5839. //---------------------------------------------------------------------------
  5840. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5841. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5842. {
  5843. for (int i = 0; i < Toolbar->Items->Count; i++)
  5844. {
  5845. TTBXCustomDropDownItem * DropDownItem;
  5846. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5847. if (DropDownItem != NULL)
  5848. {
  5849. ASize.x -= DropDownItem->EditWidth;
  5850. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5851. }
  5852. }
  5853. }
  5854. //---------------------------------------------------------------------------
  5855. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5856. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5857. {
  5858. if (WinConfiguration->DDWarnLackOfTempSpace)
  5859. {
  5860. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5861. if (!ADrive.IsEmpty())
  5862. {
  5863. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5864. DebugAssert(RequiredSpace >= 0);
  5865. __int64 RequiredWithReserve;
  5866. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5867. if (FreeSpace < RequiredWithReserve)
  5868. {
  5869. unsigned int Result;
  5870. TMessageParams Params(mpNeverAskAgainCheck);
  5871. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5872. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5873. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5874. if (Result == qaNeverAskAgain)
  5875. {
  5876. WinConfiguration->DDWarnLackOfTempSpace = false;
  5877. }
  5878. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5879. }
  5880. }
  5881. }
  5882. }
  5883. //---------------------------------------------------------------------------
  5884. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5885. {
  5886. DoOpenDirectoryDialog(odAddBookmark, Side);
  5887. }
  5888. //---------------------------------------------------------------------------
  5889. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5890. {
  5891. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5892. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5893. try
  5894. {
  5895. TCustomDirView * DView = DirView(Side);
  5896. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5897. {
  5898. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5899. }
  5900. }
  5901. catch (...)
  5902. {
  5903. delete VisitedDirectories;
  5904. throw;
  5905. }
  5906. return VisitedDirectories;
  5907. }
  5908. //---------------------------------------------------------------------------
  5909. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5910. TOpenDirectoryMode Mode, TOperationSide Side)
  5911. {
  5912. bool Continue = true;
  5913. if (Mode == odAddBookmark)
  5914. {
  5915. TMessageParams Params(mpNeverAskAgainCheck);
  5916. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5917. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5918. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5919. unsigned int Answer =
  5920. MessageDialog(Message,
  5921. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5922. if (Answer == qaNeverAskAgain)
  5923. {
  5924. Continue = true;
  5925. WinConfiguration->UseSharedBookmarks = true;
  5926. }
  5927. else if (Answer == qaOK)
  5928. {
  5929. Continue = true;
  5930. WinConfiguration->UseSharedBookmarks = false;
  5931. }
  5932. else
  5933. {
  5934. Continue = false;
  5935. }
  5936. }
  5937. if (Continue)
  5938. {
  5939. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5940. try
  5941. {
  5942. UnicodeString Name = DirView(Side)->PathName;
  5943. bool Repeat;
  5944. do
  5945. {
  5946. Repeat = false;
  5947. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5948. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5949. // do not allow switching to location profiles,
  5950. // if we are not connected
  5951. HasDirView[osLocal] && (Terminal != NULL)))
  5952. {
  5953. TWindowLock Lock(this);
  5954. if (!TryOpenDirectory(Side, Name))
  5955. {
  5956. Repeat = true;
  5957. Mode = odBrowse;
  5958. }
  5959. }
  5960. }
  5961. while (Repeat);
  5962. }
  5963. __finally
  5964. {
  5965. delete VisitedDirectories;
  5966. }
  5967. }
  5968. }
  5969. //---------------------------------------------------------------------------
  5970. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5971. {
  5972. DebugAssert(!FTerminal->CommandSessionOpened);
  5973. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5974. }
  5975. //---------------------------------------------------------------------------
  5976. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5977. {
  5978. bool Result = FTerminal->IsCapable[Capability] ||
  5979. FTerminal->CommandSessionOpened;
  5980. if (!Result)
  5981. {
  5982. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5983. if (!GUIConfiguration->ConfirmCommandSession)
  5984. {
  5985. Result = true;
  5986. }
  5987. else
  5988. {
  5989. TMessageParams Params(mpNeverAskAgainCheck);
  5990. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5991. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5992. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5993. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5994. if (Answer == qaNeverAskAgain)
  5995. {
  5996. GUIConfiguration->ConfirmCommandSession = false;
  5997. Result = true;
  5998. }
  5999. else if (Answer == qaOK)
  6000. {
  6001. Result = true;
  6002. }
  6003. }
  6004. if (Result)
  6005. {
  6006. Result = CommandSessionFallback();
  6007. }
  6008. }
  6009. return Result;
  6010. }
  6011. //---------------------------------------------------------------------------
  6012. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6013. {
  6014. if (EnsureCommandSessionFallback(fcAnyCommand))
  6015. {
  6016. DoConsoleDialog(Terminal, Command);
  6017. }
  6018. }
  6019. //---------------------------------------------------------------------------
  6020. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6021. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6022. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6023. {
  6024. if (!IsSideLocalBrowser(osRemote) &&
  6025. IsFileControl(DropSourceControl, osRemote) &&
  6026. (FDDExtMapFile != NULL))
  6027. {
  6028. Accept = true;
  6029. }
  6030. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6031. DebugAssert(FDDTargetControl != NULL);
  6032. }
  6033. //---------------------------------------------------------------------------
  6034. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6035. _di_IDataObject DataObj, int KeyState,
  6036. const TPoint & Point, int & Effect, bool & Accept)
  6037. {
  6038. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6039. }
  6040. //---------------------------------------------------------------------------
  6041. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6042. _di_IDataObject DataObj, int KeyState,
  6043. const TPoint & Point, int & Effect, bool & Accept)
  6044. {
  6045. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6046. }
  6047. //---------------------------------------------------------------------------
  6048. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6049. TObject * Sender)
  6050. {
  6051. DebugUsedParam(Sender);
  6052. DebugAssert(FDDTargetControl == Sender);
  6053. FDDTargetControl = NULL;
  6054. }
  6055. //---------------------------------------------------------------------------
  6056. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6057. {
  6058. FileControlDDDragLeave(SessionsPageControl);
  6059. }
  6060. //---------------------------------------------------------------------------
  6061. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6062. {
  6063. FileControlDDDragLeave(QueueView3);
  6064. }
  6065. //---------------------------------------------------------------------------
  6066. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6067. {
  6068. DebugAssert(!IsSideLocalBrowser(Side));
  6069. DebugUsedParam(Side);
  6070. bool Edit = false;
  6071. TRemoteFile * File = NULL;
  6072. UnicodeString FileName;
  6073. UnicodeString PointTo;
  6074. bool SymbolicLink = true;
  6075. if (RemoteDirView->ItemFocused)
  6076. {
  6077. DebugAssert(RemoteDirView->ItemFocused->Data);
  6078. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6079. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6080. if (Edit)
  6081. {
  6082. FileName = File->FileName;
  6083. PointTo = File->LinkTo;
  6084. }
  6085. else
  6086. {
  6087. PointTo = File->FileName;
  6088. }
  6089. }
  6090. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6091. Terminal->IsCapable[fcHardLink]))
  6092. {
  6093. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6094. if (Edit)
  6095. {
  6096. DebugAssert(File->FileName == FileName);
  6097. int Params = dfNoRecursive;
  6098. Terminal->ExceptionOnFail = true;
  6099. try
  6100. {
  6101. Terminal->DeleteFile(L"", File, &Params);
  6102. }
  6103. __finally
  6104. {
  6105. Terminal->ExceptionOnFail = false;
  6106. }
  6107. }
  6108. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6109. }
  6110. }
  6111. //---------------------------------------------------------------------------
  6112. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6113. {
  6114. return
  6115. (IsSideLocalBrowser(Side) ||
  6116. (HasActiveTerminal() &&
  6117. Terminal->ResolvingSymlinks &&
  6118. Terminal->IsCapable[fcSymbolicLink]));
  6119. }
  6120. //---------------------------------------------------------------------------
  6121. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6122. {
  6123. return
  6124. !IsSideLocalBrowser(FCurrentSide) &&
  6125. (RemoteDirView->ItemFocused != NULL) &&
  6126. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6127. Terminal->SessionData->ResolveSymlinks;
  6128. }
  6129. //---------------------------------------------------------------------------
  6130. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6131. {
  6132. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6133. FForceExecution = true;
  6134. try
  6135. {
  6136. DirView(osCurrent)->ExecuteCurrentFile();
  6137. }
  6138. __finally
  6139. {
  6140. FForceExecution = false;
  6141. }
  6142. }
  6143. //---------------------------------------------------------------------------
  6144. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6145. {
  6146. TEditorData ExternalEditor;
  6147. ExternalEditor.Editor = edExternal;
  6148. bool Remember = false;
  6149. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6150. {
  6151. if (Remember)
  6152. {
  6153. TEditorList * EditorList = new TEditorList;
  6154. try
  6155. {
  6156. *EditorList = *WinConfiguration->EditorList;
  6157. bool Found = false;
  6158. int i = 0;
  6159. while (!Found && (i < EditorList->Count))
  6160. {
  6161. const TEditorPreferences * Editor = EditorList->Editors[i];
  6162. if ((Editor->Data->Editor == edExternal) &&
  6163. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6164. {
  6165. Found = true;
  6166. }
  6167. i++;
  6168. }
  6169. if (!Found)
  6170. {
  6171. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6172. WinConfiguration->EditorList = EditorList;
  6173. }
  6174. }
  6175. __finally
  6176. {
  6177. delete EditorList;
  6178. }
  6179. }
  6180. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6181. }
  6182. }
  6183. //---------------------------------------------------------------------------
  6184. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6185. {
  6186. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6187. if (FFileFindTerminal == ATerminal)
  6188. {
  6189. FFileFindTerminal = NULL;
  6190. HideFileFindDialog();
  6191. }
  6192. if (FClipboardTerminal == ATerminal)
  6193. {
  6194. ClipboardClear(); // implies ClipboardStop
  6195. }
  6196. }
  6197. //---------------------------------------------------------------------------
  6198. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6199. {
  6200. DetachTerminal(Sender);
  6201. }
  6202. //---------------------------------------------------------------------------
  6203. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6204. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6205. {
  6206. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6207. DebugAssert(Terminal != NULL);
  6208. if (Data->Terminal == Terminal)
  6209. {
  6210. Data->Terminal = NULL;
  6211. }
  6212. }
  6213. //---------------------------------------------------------------------------
  6214. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6215. {
  6216. UpdateControls();
  6217. SessionColor = TColor(0);
  6218. UpdateRemotePathComboBox(false);
  6219. NeedSession(false);
  6220. }
  6221. //---------------------------------------------------------------------------
  6222. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6223. {
  6224. try
  6225. {
  6226. // Cache, as the login dialog can change its value.
  6227. // See also DoShow.
  6228. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6229. try
  6230. {
  6231. if (ShowLogin)
  6232. {
  6233. bool ReloadSessions = !Startup;
  6234. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6235. }
  6236. }
  6237. __finally
  6238. {
  6239. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6240. // (so there was no chance for the user to open any session yet)
  6241. if ((ShowLogin || !Startup) &&
  6242. !WinConfiguration->KeepOpenWhenNoSession &&
  6243. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6244. {
  6245. TerminateApplication();
  6246. }
  6247. }
  6248. }
  6249. catch (EAbort &)
  6250. {
  6251. // swallow
  6252. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6253. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6254. }
  6255. }
  6256. //---------------------------------------------------------------------------
  6257. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6258. {
  6259. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6260. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6261. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6262. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6263. try
  6264. {
  6265. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6266. // Clear the design time unthemed tab
  6267. ((SessionsPageControl->PageCount > 0) &&
  6268. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6269. {
  6270. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6271. }
  6272. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6273. {
  6274. TThemeTabSheet * TabSheet;
  6275. if (Index >= SessionsPageControl->PageCount)
  6276. {
  6277. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6278. TabSheet->PageControl = SessionsPageControl;
  6279. }
  6280. else
  6281. {
  6282. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6283. }
  6284. bool IsSessionTab = (Index < TerminalList->Count);
  6285. if (IsSessionTab)
  6286. {
  6287. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6288. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6289. UpdateSessionTab(TabSheet);
  6290. }
  6291. else
  6292. {
  6293. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6294. TabSheet->Tag = 0; // not really needed
  6295. TabSheet->Shadowed = false;
  6296. // We know that we are at the last page, otherwise we could not call this (it assumes that new session tab is the last one)
  6297. UpdateNewSessionTab();
  6298. }
  6299. TabSheet->ShowCloseButton = IsSessionTab;
  6300. }
  6301. }
  6302. __finally
  6303. {
  6304. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6305. }
  6306. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6307. }
  6308. //---------------------------------------------------------------------------
  6309. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6310. {
  6311. DoTerminalListChanged();
  6312. }
  6313. //---------------------------------------------------------------------------
  6314. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6315. {
  6316. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6317. DebugAssert(TabSheet->ImageIndex == 0);
  6318. TabSheet->Caption =
  6319. WinConfiguration->SelectiveToolbarText ?
  6320. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6321. UnicodeString();
  6322. }
  6323. //---------------------------------------------------------------------------
  6324. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6325. {
  6326. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6327. }
  6328. //---------------------------------------------------------------------------
  6329. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6330. {
  6331. if (DebugAlwaysTrue(TabSheet != NULL))
  6332. {
  6333. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6334. if (DebugAlwaysTrue(ATerminal != NULL))
  6335. {
  6336. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6337. TabSheet->ImageIndex = AddSessionColor(Color);
  6338. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6339. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6340. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6341. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6342. {
  6343. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6344. }
  6345. }
  6346. }
  6347. }
  6348. //---------------------------------------------------------------------------
  6349. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6350. {
  6351. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6352. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6353. bool Result = (Terminal != NULL);
  6354. if (Result)
  6355. {
  6356. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6357. }
  6358. else
  6359. {
  6360. try
  6361. {
  6362. NewSession(false);
  6363. }
  6364. __finally
  6365. {
  6366. DoTerminalListChanged();
  6367. }
  6368. FSessionsPageControlNewSessionTime = Now();
  6369. }
  6370. return Result;
  6371. }
  6372. //---------------------------------------------------------------------------
  6373. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6374. {
  6375. SessionTabSwitched();
  6376. }
  6377. //---------------------------------------------------------------------------
  6378. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6379. {
  6380. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6381. DebugAssert(TransferList != NULL);
  6382. UnicodeString Name;
  6383. if (TransferList->ItemIndex <= 0)
  6384. {
  6385. Name = L"";
  6386. }
  6387. else
  6388. {
  6389. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6390. }
  6391. if (FCopyParamAutoSelected.IsEmpty())
  6392. {
  6393. // if previous preset was not autoselected, make new preset the "default"
  6394. FCopyParamDefault = Name;
  6395. }
  6396. GUIConfiguration->CopyParamCurrent = Name;
  6397. }
  6398. //---------------------------------------------------------------------------
  6399. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6400. {
  6401. // sanity check
  6402. bool ExistingPreset =
  6403. (FTransferListHoverIndex >= 0) &&
  6404. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6405. DebugAssert(ExistingPreset);
  6406. if (ExistingPreset)
  6407. {
  6408. HDC DC = GetDC(0);
  6409. TCanvas * Canvas = new TCanvas();
  6410. try
  6411. {
  6412. Canvas->Handle = DC;
  6413. Canvas->Font = GetToolbarFont(this);
  6414. UnicodeString Name;
  6415. if (FTransferListHoverIndex == 0)
  6416. {
  6417. Name = L"";
  6418. }
  6419. else
  6420. {
  6421. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6422. }
  6423. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6424. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6425. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6426. static_cast<TObject*>(GetComponent(fcTransferList)));
  6427. UnicodeString InfoStr =
  6428. GUIConfiguration->CopyParamPreset[Name].
  6429. GetInfoStr(L"; ",
  6430. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6431. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6432. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6433. {
  6434. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6435. {
  6436. InfoStr.SetLength(InfoStr.Length() - 1);
  6437. }
  6438. InfoStr += Ellipsis;
  6439. }
  6440. // UpdateCaption does not cause invalidation of whole submenu, while
  6441. // setting Caption property does.
  6442. // also it probably does not resize the label, even if necessary
  6443. // (we do not want that anyway)
  6444. TransferLabel->UpdateCaption(InfoStr);
  6445. }
  6446. __finally
  6447. {
  6448. Canvas->Handle = NULL;
  6449. ReleaseDC(0, DC);
  6450. delete Canvas;
  6451. }
  6452. }
  6453. }
  6454. //---------------------------------------------------------------------------
  6455. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6456. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6457. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6458. {
  6459. if (FTransferListHoverIndex != AHoverIndex)
  6460. {
  6461. FTransferListHoverIndex = AHoverIndex;
  6462. UpdateTransferLabel();
  6463. }
  6464. }
  6465. //---------------------------------------------------------------------------
  6466. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6467. {
  6468. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6469. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6470. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6471. {
  6472. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6473. {
  6474. if (!NonVisualDataModule->Busy)
  6475. {
  6476. OpenDirectory(GetSide(osCurrent));
  6477. }
  6478. Message.Result = 1;
  6479. }
  6480. else
  6481. {
  6482. TForm::Dispatch(&Message);
  6483. }
  6484. }
  6485. else
  6486. {
  6487. TForm::Dispatch(&Message);
  6488. }
  6489. }
  6490. //---------------------------------------------------------------------------
  6491. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6492. {
  6493. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6494. if ((FIgnoreNextDialogChar != 0) &&
  6495. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6496. {
  6497. Message.Result = 1;
  6498. }
  6499. else
  6500. {
  6501. TForm::Dispatch(&Message);
  6502. }
  6503. FIgnoreNextDialogChar = 0;
  6504. }
  6505. //---------------------------------------------------------------------------
  6506. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6507. {
  6508. // The four low-order bits are used internally by Windows
  6509. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6510. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6511. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6512. // 61730 - restore thru double click - undocumented
  6513. // 61490 - maximize thru double click - undocumented
  6514. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6515. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6516. {
  6517. SysResizing(Cmd);
  6518. }
  6519. TForm::Dispatch(&Message);
  6520. }
  6521. //---------------------------------------------------------------------------
  6522. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6523. {
  6524. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6525. // Also there no point returning TRUE as we are not able to
  6526. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6527. // Hence the process termination might be safer :)
  6528. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6529. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6530. {
  6531. Message.Result = FALSE;
  6532. }
  6533. else
  6534. {
  6535. Message.Result = TRUE;
  6536. }
  6537. // Do not call default handling as that triggers OnCloseQuery,
  6538. // where our implementation will popup confirmation dialogs, what we do not want,
  6539. // as per Vista guidelines:
  6540. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6541. }
  6542. //---------------------------------------------------------------------------
  6543. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6544. {
  6545. if (Message.EndSession && IsApplicationMinimized())
  6546. {
  6547. // WORKAROUND
  6548. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6549. // when it receives WM_ENDSESSION,
  6550. // but that sometimes (particularly when application is minimized) cause crashes.
  6551. // Crash popups message that blocks log off.
  6552. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6553. // so we call ExitProcess() immediately, not even trying to cleanup.
  6554. // It still causes beep, so there's likely some popup, but it does not block
  6555. // log off.
  6556. ExitProcess(0);
  6557. }
  6558. TForm::Dispatch(&Message);
  6559. }
  6560. #ifdef _DEBUG
  6561. //---------------------------------------------------------------------------
  6562. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6563. {
  6564. TForm::Dispatch(&Message);
  6565. }
  6566. #endif
  6567. //---------------------------------------------------------------------------
  6568. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6569. {
  6570. }
  6571. //---------------------------------------------------------------------------
  6572. void __fastcall TCustomScpExplorerForm::DoShow()
  6573. {
  6574. // only now are the controls resized finally, so the size constraints
  6575. // will not conflict with possibly very small window size
  6576. RestoreFormParams();
  6577. // This indicates that the form was rescaled after parameters were loaded and
  6578. // as most probably the parameters were actually saved with the current form scaling
  6579. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6580. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6581. // and no rounding problems will occur.
  6582. // See also RestoreForm.
  6583. // (we should be safe to call RestoreParams unconditionally)
  6584. if (PixelsPerInch != Screen->PixelsPerInch)
  6585. {
  6586. RestoreParams();
  6587. }
  6588. FixControlsPlacement();
  6589. if (Position == poDefaultPosOnly)
  6590. {
  6591. CutFormToDesktop(this);
  6592. }
  6593. TForm::DoShow();
  6594. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6595. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6596. // This was previously in NeedSession, where other related code is.
  6597. // But that is called form CMShowingChanged, when the window is already visible and the local-local window state
  6598. // unpleasanly shows briefly.
  6599. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6600. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6601. // This detects if workspace was saved the last time the main widow was closed
  6602. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6603. {
  6604. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6605. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6606. }
  6607. if (Terminal == NULL)
  6608. {
  6609. StartingDisconnected();
  6610. }
  6611. UpdatePixelsPerInchMainWindowCounter();
  6612. FShowing = true;
  6613. }
  6614. //---------------------------------------------------------------------------
  6615. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6616. {
  6617. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6618. }
  6619. //---------------------------------------------------------------------------
  6620. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6621. {
  6622. DoTerminalListChanged();
  6623. UpdateControls();
  6624. }
  6625. //---------------------------------------------------------------------------
  6626. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6627. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6628. TNotifyEvent OnBalloonClick, TObject * UserData)
  6629. {
  6630. bool Do;
  6631. UnicodeString Message;
  6632. if (E == NULL)
  6633. {
  6634. Message = Str;
  6635. Do = true;
  6636. }
  6637. else
  6638. {
  6639. Do = ExceptionMessage(E, Message);
  6640. }
  6641. if (Do && WinConfiguration->BalloonNotifications)
  6642. {
  6643. UnicodeString Title;
  6644. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6645. {
  6646. Message = TrimLeft(Message);
  6647. }
  6648. else
  6649. {
  6650. Message = UnformatMessage(Message);
  6651. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6652. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6653. Title = LoadResourceString(Captions[Type]);
  6654. if (Terminal != NULL)
  6655. {
  6656. Title = FORMAT(L"%s - %s",
  6657. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6658. }
  6659. }
  6660. if (Seconds == 0)
  6661. {
  6662. Seconds = WinConfiguration->NotificationsTimeout;
  6663. }
  6664. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6665. }
  6666. }
  6667. //---------------------------------------------------------------------------
  6668. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6669. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6670. UnicodeString HelpKeyword, const TMessageParams * Params,
  6671. TTerminal * Terminal)
  6672. {
  6673. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6674. (FOnFeedSynchronizeError != NULL)) &&
  6675. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6676. {
  6677. if (FOnFeedSynchronizeError != NULL)
  6678. {
  6679. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6680. }
  6681. else
  6682. {
  6683. DebugAssert(FErrorList != NULL);
  6684. TStringList * MoreMessagesCopy = NULL;
  6685. if (MoreMessages)
  6686. {
  6687. MoreMessagesCopy = new TStringList();
  6688. MoreMessagesCopy->Assign(MoreMessages);
  6689. }
  6690. FErrorList->AddObject(Message, MoreMessagesCopy);
  6691. }
  6692. PopupTrayBalloon(Terminal, Message, Type);
  6693. return ContinueAnswer(Answers);
  6694. }
  6695. else
  6696. {
  6697. bool UseBalloon = FTrayIcon->Visible;
  6698. if (UseBalloon)
  6699. {
  6700. PopupTrayBalloon(Terminal, Message, Type);
  6701. }
  6702. unsigned int Result;
  6703. try
  6704. {
  6705. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6706. }
  6707. __finally
  6708. {
  6709. // cancel only balloon we popped up, otherwise we may cancel notification
  6710. // balloon that was there before the message dialog
  6711. // (such as "dd confirmation opt in balloon)
  6712. if (UseBalloon)
  6713. {
  6714. FTrayIcon->CancelBalloon();
  6715. }
  6716. }
  6717. return Result;
  6718. }
  6719. }
  6720. //---------------------------------------------------------------------------
  6721. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6722. TTerminal * Terminal, Exception * E)
  6723. {
  6724. if (FTrayIcon->Visible)
  6725. {
  6726. PopupTrayBalloon(Terminal, L"", qtError, E);
  6727. }
  6728. // particularly prevent opening new session from jump list,
  6729. // while exception is shown
  6730. NonVisualDataModule->StartBusy();
  6731. try
  6732. {
  6733. ShowExtendedExceptionEx(Terminal, E);
  6734. }
  6735. __finally
  6736. {
  6737. NonVisualDataModule->EndBusy();
  6738. FTrayIcon->CancelBalloon();
  6739. }
  6740. }
  6741. //---------------------------------------------------------------------------
  6742. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6743. {
  6744. if (Terminal->Active)
  6745. {
  6746. InitStatusBar();
  6747. }
  6748. // cannot rely on active page being page for active terminal,
  6749. // as it can happen that active page is the "new session" page
  6750. // (e.g. when reconnecting active terminal, while login dialog
  6751. // invoked from "new session" page is modal)
  6752. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6753. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6754. }
  6755. //---------------------------------------------------------------------------
  6756. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6757. TTerminal * Terminal, Exception * E)
  6758. {
  6759. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6760. if (!Terminal->Active)
  6761. {
  6762. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6763. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6764. {
  6765. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6766. }
  6767. }
  6768. }
  6769. //---------------------------------------------------------------------------
  6770. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6771. UnicodeString Message, TQueryType Type,
  6772. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6773. {
  6774. if ((E == NULL) ||
  6775. ExceptionMessage(E, Message))
  6776. {
  6777. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6778. if (Important)
  6779. {
  6780. Seconds *= 5;
  6781. }
  6782. UnicodeString NoteMessage(UnformatMessage(Message));
  6783. if (Terminal != NULL)
  6784. {
  6785. NoteMessage = FORMAT(L"%s: %s",
  6786. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6787. }
  6788. if (WinConfiguration->BalloonNotifications)
  6789. {
  6790. AddNote(NoteMessage);
  6791. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6792. }
  6793. else
  6794. {
  6795. FlashOnBackground();
  6796. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6797. }
  6798. }
  6799. }
  6800. //---------------------------------------------------------------------------
  6801. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6802. {
  6803. RestoreApp();
  6804. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6805. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6806. !NonVisualDataModule->Busy)
  6807. {
  6808. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6809. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6810. if (!ComponentVisible[fcQueueView])
  6811. {
  6812. ToggleQueueVisibility();
  6813. GoToQueue();
  6814. }
  6815. }
  6816. }
  6817. //---------------------------------------------------------------------------
  6818. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6819. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6820. {
  6821. UnicodeString Message;
  6822. TNotifyEvent OnClick = NULL;
  6823. TObject * UserData = NULL;
  6824. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6825. switch (Event)
  6826. {
  6827. case qeEmptyButMonitored:
  6828. if ((ATerminal != Terminal) || QueueInvisible)
  6829. {
  6830. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6831. OnClick = QueueEmptyNoteClicked;
  6832. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6833. TerminalNoteData->Terminal = ATerminal;
  6834. UserData = TerminalNoteData;
  6835. }
  6836. break;
  6837. case qeEmpty:
  6838. OperationComplete(ATerminal->QueueOperationStart);
  6839. break;
  6840. case qePendingUserAction:
  6841. if ((ATerminal != Terminal) ||
  6842. (QueueInvisible && !IsQueueAutoPopup()))
  6843. {
  6844. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6845. }
  6846. break;
  6847. default:
  6848. DebugFail();
  6849. }
  6850. if (!Message.IsEmpty())
  6851. {
  6852. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6853. }
  6854. }
  6855. //---------------------------------------------------------------------------
  6856. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6857. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6858. {
  6859. if (FDDExtMapFile != NULL)
  6860. {
  6861. CloseHandle(FDDExtMapFile);
  6862. FDDExtMapFile = NULL;
  6863. }
  6864. if (WinConfiguration->DDFakeFile)
  6865. {
  6866. DDFakeFileInitDrag(FileList, Created);
  6867. }
  6868. }
  6869. //---------------------------------------------------------------------------
  6870. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6871. {
  6872. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6873. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6874. {
  6875. FFakeFileDropTarget = FileName;
  6876. }
  6877. }
  6878. //---------------------------------------------------------------------------
  6879. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6880. {
  6881. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6882. if (!ForceDirectories(ApiPath(Result)))
  6883. {
  6884. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6885. }
  6886. FileSetAttr(ApiPath(Result), faHidden);
  6887. return Result;
  6888. }
  6889. //---------------------------------------------------------------------------
  6890. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6891. bool & Created)
  6892. {
  6893. FFakeFileDropTarget = UnicodeString();
  6894. FDragFakeDirectory = CreateFakeTransferDirectory();
  6895. FileList->AddItem(NULL, FDragFakeDirectory);
  6896. Created = true;
  6897. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6898. {
  6899. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6900. }
  6901. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6902. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6903. {
  6904. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6905. TDragExtCommStruct* CommStruct;
  6906. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6907. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6908. DebugAssert(CommStruct != NULL);
  6909. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6910. CommStruct->Dragging = true;
  6911. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6912. LENOF(CommStruct->DropDest));
  6913. NULL_TERMINATE(CommStruct->DropDest);
  6914. UnmapViewOfFile(CommStruct);
  6915. }
  6916. }
  6917. //---------------------------------------------------------------------------
  6918. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6919. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6920. {
  6921. bool Result;
  6922. DebugAssert(!IsLocalBrowserMode());
  6923. if (Sender == RemoteDirView)
  6924. {
  6925. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6926. }
  6927. else
  6928. {
  6929. DebugAssert(Sender == RemoteDriveView);
  6930. TStrings * FileList = RemoteDriveView->DragFileList();
  6931. try
  6932. {
  6933. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6934. }
  6935. __finally
  6936. {
  6937. delete FileList;
  6938. }
  6939. }
  6940. if (FDDTargetControl == RemoteDriveView)
  6941. {
  6942. RemoteDriveView->UpdateDropTarget();
  6943. }
  6944. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6945. // or from tree view to dir view.
  6946. // foMove happens when file/dir is dragged from remote tree view outside of
  6947. // application via dragex
  6948. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6949. (DropSourceControl == RemoteDriveView))
  6950. {
  6951. RemoteDriveView->UpdateDropSource();
  6952. }
  6953. return Result;
  6954. }
  6955. //---------------------------------------------------------------------------
  6956. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6957. {
  6958. DebugAssert(!IsLocalBrowserMode());
  6959. // This also handles drops of remote files to queue.
  6960. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6961. SAFE_DESTROY(FDDFileList);
  6962. if (!FFakeFileDropTarget.IsEmpty())
  6963. {
  6964. RemoveDir(ApiPath(FFakeFileDropTarget));
  6965. }
  6966. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6967. {
  6968. try
  6969. {
  6970. TDragResult DDResult = (Sender == RemoteDirView) ?
  6971. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6972. // Focus is moved to the target application,
  6973. // but as we are going to present the UI, we need to steal the focus back.
  6974. // This most likely won't work though (windows does not allow application
  6975. // to steal focus most of the time)
  6976. Application->BringToFront();
  6977. // On older version of Windows we never got drMove here, see also comment below.
  6978. // On Windows 10, we get the "move".
  6979. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6980. {
  6981. UnicodeString TargetDirectory;
  6982. TFileOperation Operation;
  6983. // drInvalid may mean drMove, see comment below
  6984. switch (DDResult)
  6985. {
  6986. case drCopy:
  6987. Operation = foCopy;
  6988. break;
  6989. case drMove:
  6990. Operation = foMove;
  6991. break;
  6992. default:
  6993. DebugFail();
  6994. case drInvalid:
  6995. // prefer "copy" for safety
  6996. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6997. break;
  6998. }
  6999. TTransferOperationParam Param;
  7000. UnicodeString CounterName;
  7001. bool ForceQueue;
  7002. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7003. {
  7004. // we get drInvalid both if d&d was intercepted by ddext,
  7005. // and when users drops on no-drop location.
  7006. // we tell the difference by existence of response from ddext,
  7007. // so we ignore absence of response in this case
  7008. if (DDResult != drInvalid)
  7009. {
  7010. // here we know that the extension is installed,
  7011. // as it is checked as soon as drag&drop starts from
  7012. // RemoteFileControlDDCreateDragFileList
  7013. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7014. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7015. {
  7016. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7017. }
  7018. else
  7019. {
  7020. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7021. }
  7022. }
  7023. }
  7024. else
  7025. {
  7026. // download using fake file
  7027. Param.Temp = false;
  7028. Param.DragDrop = true;
  7029. if (ForceQueue)
  7030. {
  7031. Param.Queue = asOn;
  7032. }
  7033. if (Sender == RemoteDirView)
  7034. {
  7035. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7036. }
  7037. if (RemoteFileControlFileOperation(Sender, Operation,
  7038. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7039. {
  7040. Configuration->Usage->Inc(CounterName);
  7041. }
  7042. }
  7043. }
  7044. }
  7045. __finally
  7046. {
  7047. CloseHandle(FDDExtMapFile);
  7048. FDDExtMapFile = NULL;
  7049. delete FDragFakeMonitors;
  7050. FDragFakeMonitors = NULL;
  7051. RemoveDir(ApiPath(FDragFakeDirectory));
  7052. FDragFakeDirectory = L"";
  7053. FFakeFileDropTarget = UnicodeString();
  7054. }
  7055. }
  7056. if (FDragDropSshTerminate.get() != NULL)
  7057. {
  7058. FDragDropSshTerminate->Rethrow();
  7059. }
  7060. }
  7061. //---------------------------------------------------------------------------
  7062. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7063. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7064. {
  7065. // Remember drop effect so we know (when user drops files), if we copy or move
  7066. FLastDropEffect = dwEffect;
  7067. }
  7068. //---------------------------------------------------------------------------
  7069. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7070. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7071. {
  7072. bool Result;
  7073. if (FDDTargetControl == QueueView3)
  7074. {
  7075. Directory = DefaultDownloadTargetDirectory();
  7076. Result = true;
  7077. CounterName = L"DownloadsDragDropQueue";
  7078. ForceQueue = true;
  7079. }
  7080. else if (!FFakeFileDropTarget.IsEmpty())
  7081. {
  7082. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7083. Result = true;
  7084. ForceQueue = false;
  7085. CounterName = L"DownloadsDragDropFakeFile";
  7086. }
  7087. else
  7088. {
  7089. ForceQueue = false;
  7090. Enabled = false;
  7091. try
  7092. {
  7093. int Timer = 0;
  7094. Result = false;
  7095. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7096. {
  7097. {
  7098. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7099. TDragExtCommStruct* CommStruct;
  7100. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7101. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7102. DebugAssert(CommStruct != NULL);
  7103. Result = !CommStruct->Dragging;
  7104. if (Result)
  7105. {
  7106. Directory = ExtractFilePath(CommStruct->DropDest);
  7107. CounterName = L"DownloadsDragDropExternalExt";
  7108. }
  7109. UnmapViewOfFile(CommStruct);
  7110. }
  7111. if (!Result)
  7112. {
  7113. Sleep(50);
  7114. Timer += 50;
  7115. Application->ProcessMessages();
  7116. }
  7117. }
  7118. }
  7119. __finally
  7120. {
  7121. Enabled = true;
  7122. }
  7123. }
  7124. return Result;
  7125. }
  7126. //---------------------------------------------------------------------------
  7127. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7128. const UnicodeString TempDir, int SecDelay)
  7129. {
  7130. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7131. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7132. if (FDelayedDeletionTimer == NULL)
  7133. {
  7134. DebugAssert(HandleAllocated());
  7135. FDelayedDeletionTimer = new TTimer(this);
  7136. FDelayedDeletionTimer->Interval = 10000;
  7137. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7138. }
  7139. else
  7140. {
  7141. FDelayedDeletionTimer->Enabled = true;
  7142. }
  7143. }
  7144. //---------------------------------------------------------------------------
  7145. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7146. {
  7147. DebugAssert(FDelayedDeletionList != NULL);
  7148. TDateTime N = Now();
  7149. TDateTime Alert;
  7150. UnicodeString Directory;
  7151. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7152. {
  7153. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7154. if ((N >= Alert) || (Sender == NULL))
  7155. {
  7156. Directory = FDelayedDeletionList->Strings[Index];
  7157. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7158. {
  7159. FDelayedDeletionList->Delete(Index);
  7160. }
  7161. }
  7162. }
  7163. if (FDelayedDeletionList->Count == 0)
  7164. {
  7165. FDelayedDeletionTimer->Enabled = false;
  7166. }
  7167. }
  7168. //---------------------------------------------------------------------------
  7169. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7170. {
  7171. DebugAssert(!IsLocalBrowserMode());
  7172. if (IsFileControl(FDDTargetControl, osRemote) ||
  7173. (FDDTargetControl == SessionsPageControl))
  7174. {
  7175. TTerminal * TargetTerminal = NULL;
  7176. TFileOperation Operation = foNone;
  7177. if (FDDTargetControl == SessionsPageControl)
  7178. {
  7179. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7180. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7181. // do not allow dropping on the "+" tab
  7182. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7183. if (TargetTerminal != NULL)
  7184. {
  7185. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7186. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7187. {
  7188. Operation = foRemoteMove;
  7189. }
  7190. else
  7191. {
  7192. Operation = foRemoteCopy;
  7193. }
  7194. }
  7195. }
  7196. else
  7197. {
  7198. if (FLastDropEffect == DROPEFFECT_MOVE)
  7199. {
  7200. Operation = foRemoteMove;
  7201. }
  7202. else if (FLastDropEffect == DROPEFFECT_COPY)
  7203. {
  7204. Operation = foRemoteCopy;
  7205. }
  7206. }
  7207. if (Operation != foNone)
  7208. {
  7209. RemoteFileControlFileOperation(DropSourceControl,
  7210. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7211. }
  7212. // abort drag&drop
  7213. Abort();
  7214. }
  7215. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7216. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7217. (FDDTargetControl != QueueView3))
  7218. {
  7219. DebugAssert(!FDragTempDir.IsEmpty());
  7220. TTransferType Type;
  7221. UnicodeString TempDir = FDragTempDir;
  7222. // We clear FDragTempDir before calling
  7223. // just in case it fail (raises exception)
  7224. FDragTempDir = L"";
  7225. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7226. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7227. // empty directory parameter means temp directory -> don't display it!
  7228. UnicodeString TargetDir = L"";
  7229. int Options = 0;
  7230. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7231. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7232. {
  7233. Abort();
  7234. }
  7235. // TargetDir is set when dropped on local file control
  7236. // (this was workaround for legacy dirview event handling, now it should be
  7237. // made prettier)
  7238. if (TargetDir.IsEmpty())
  7239. {
  7240. TargetDir = TempDir;
  7241. if (ForceDirectories(ApiPath(TargetDir)))
  7242. {
  7243. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7244. FPendingTempSpaceWarn = true;
  7245. try
  7246. {
  7247. FDragDropOperation = true;
  7248. int Params = cpTemporary |
  7249. (Type == ttMove ? cpDelete : 0);
  7250. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7251. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7252. }
  7253. __finally
  7254. {
  7255. FDragDropOperation = false;
  7256. FPendingTempSpaceWarn = false;
  7257. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7258. }
  7259. }
  7260. else
  7261. {
  7262. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7263. }
  7264. }
  7265. }
  7266. }
  7267. //---------------------------------------------------------------------------
  7268. void __fastcall TCustomScpExplorerForm::DDDownload(
  7269. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7270. {
  7271. DebugAssert(!IsLocalBrowserMode());
  7272. TAutoBatch AutoBatch(this);
  7273. UpdateCopyParamCounters(*CopyParam);
  7274. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7275. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7276. {
  7277. RemoteDriveView->UpdateDropSource();
  7278. }
  7279. }
  7280. //---------------------------------------------------------------------------
  7281. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7282. {
  7283. public:
  7284. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7285. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7286. {
  7287. }
  7288. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7289. {
  7290. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7291. TDataObjectFilesEx::AllowData(FormatEtc);
  7292. }
  7293. };
  7294. //---------------------------------------------------------------------------
  7295. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7296. TObject * Sender, TDataObject *& DataObject)
  7297. {
  7298. if (FDDExtMapFile != NULL)
  7299. {
  7300. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7301. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7302. {
  7303. Abort();
  7304. }
  7305. if (FileList->Count > 0)
  7306. {
  7307. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7308. if (!FilesObject->IsValid(true, true))
  7309. {
  7310. FilesObject->_Release();
  7311. }
  7312. else
  7313. {
  7314. DataObject = FilesObject;
  7315. }
  7316. }
  7317. }
  7318. }
  7319. //---------------------------------------------------------------------------
  7320. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7321. {
  7322. DebugFail();
  7323. }
  7324. //---------------------------------------------------------------------------
  7325. void __fastcall TCustomScpExplorerForm::GoToTree()
  7326. {
  7327. ComponentVisible[fcRemoteTree] = true;
  7328. DriveView(osRemote)->SetFocus();
  7329. }
  7330. //---------------------------------------------------------------------------
  7331. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7332. TPanelExport Export)
  7333. {
  7334. TCustomDirView * DirView = this->DirView(Side);
  7335. std::unique_ptr<TStrings> ExportData(new TStringList());
  7336. switch (Export)
  7337. {
  7338. case pePath:
  7339. ExportData->Add(DirView->PathName);
  7340. break;
  7341. case peFileList:
  7342. case peFullFileList:
  7343. {
  7344. bool FullPath = (Export == peFullFileList);
  7345. DirView->CreateFileList(false, FullPath, ExportData.get());
  7346. for (int Index = 0; Index < ExportData->Count; Index++)
  7347. {
  7348. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7349. {
  7350. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7351. }
  7352. }
  7353. }
  7354. break;
  7355. default:
  7356. DebugFail();
  7357. }
  7358. return ExportData.release();
  7359. }
  7360. //---------------------------------------------------------------------------
  7361. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7362. TPanelExport Export, TPanelExportDestination Destination)
  7363. {
  7364. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7365. PanelExportStore(Side, Export, Destination, ExportData.get());
  7366. }
  7367. //---------------------------------------------------------------------------
  7368. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7369. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7370. TStrings * ExportData)
  7371. {
  7372. if (Destination == pedClipboard)
  7373. {
  7374. TInstantOperationVisualizer Visualizer;
  7375. CopyToClipboard(ExportData);
  7376. }
  7377. else
  7378. {
  7379. DebugFail();
  7380. }
  7381. }
  7382. //---------------------------------------------------------------------------
  7383. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7384. {
  7385. TCustomDirView * DirView = this->DirView(Side);
  7386. UnicodeString Mask = DirView->Mask;
  7387. if (DoFilterMaskDialog(DirView, Mask))
  7388. {
  7389. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7390. Configuration->Usage->Inc(L"Filters");
  7391. }
  7392. }
  7393. //---------------------------------------------------------------------------
  7394. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7395. {
  7396. return FQueueController->DefaultOperation();
  7397. }
  7398. //---------------------------------------------------------------------------
  7399. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7400. TQueueOperation Operation, void ** Param)
  7401. {
  7402. switch (Operation)
  7403. {
  7404. case qoPreferences:
  7405. return true;
  7406. case qoGoTo:
  7407. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7408. case qoOnceEmpty:
  7409. return IsAnythingQueued();
  7410. default:
  7411. return FQueueController->AllowOperation(Operation, Param);
  7412. }
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7416. {
  7417. if (DebugAlwaysTrue(QueueView3->Visible))
  7418. {
  7419. QueueView3->SetFocus();
  7420. }
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7424. TQueueOperation Operation, void * Param)
  7425. {
  7426. if (Operation == qoGoTo)
  7427. {
  7428. GoToQueue();
  7429. }
  7430. else if (Operation == qoPreferences)
  7431. {
  7432. PreferencesDialog(pmQueue);
  7433. }
  7434. else
  7435. {
  7436. FQueueController->ExecuteOperation(Operation, Param);
  7437. }
  7438. }
  7439. //---------------------------------------------------------------------------
  7440. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7441. {
  7442. return (Queue != NULL) && Queue->Enabled;
  7443. }
  7444. //---------------------------------------------------------------------------
  7445. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7446. {
  7447. DebugAssert(Queue != NULL);
  7448. if (Queue != NULL)
  7449. {
  7450. Queue->Enabled = !Queue->Enabled;
  7451. }
  7452. }
  7453. //---------------------------------------------------------------------------
  7454. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7455. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7456. {
  7457. FQueueActedItem = QueueView3->ItemFocused;
  7458. }
  7459. //---------------------------------------------------------------------------
  7460. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7461. {
  7462. return TopDock->Height + QueueSplitter->Height;
  7463. }
  7464. //---------------------------------------------------------------------------
  7465. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7466. {
  7467. return
  7468. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7469. (QueueDock->Visible ? QueueDock->Height : 0) +
  7470. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7471. }
  7472. //---------------------------------------------------------------------------
  7473. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7474. {
  7475. return ScaleByTextHeight(this, 48);
  7476. }
  7477. //---------------------------------------------------------------------------
  7478. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7479. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7480. {
  7481. // when queue is hidden by double-clicking splitter, stray attempt to
  7482. // resize the panel with strange value arrives, make sure it is ignored
  7483. if (ComponentVisible[fcQueueView])
  7484. {
  7485. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7486. if (NewSize > MaxHeightLimit)
  7487. {
  7488. NewSize = MaxHeightLimit;
  7489. }
  7490. int MinHeightLimit =
  7491. GetStaticQueuePanelComponentsHeight() +
  7492. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7493. GetMinQueueViewHeight();
  7494. if (NewSize < MinHeightLimit)
  7495. {
  7496. NewSize = MinHeightLimit;
  7497. }
  7498. }
  7499. else
  7500. {
  7501. Accept = false;
  7502. }
  7503. }
  7504. //---------------------------------------------------------------------------
  7505. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7506. {
  7507. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7508. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7509. if (QueueViewHeight < GetMinQueueViewHeight())
  7510. {
  7511. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7512. }
  7513. }
  7514. //---------------------------------------------------------------------------
  7515. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7516. TDragObject *& /*DragObject*/)
  7517. {
  7518. FQueueActedItem = QueueView3->ItemFocused;
  7519. }
  7520. //---------------------------------------------------------------------------
  7521. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7522. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7523. {
  7524. Accept = true;
  7525. if (Source == QueueView3)
  7526. {
  7527. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7528. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7529. if (Accept)
  7530. {
  7531. TQueueItemProxy * QueueItem;
  7532. TQueueItemProxy * DestQueueItem;
  7533. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7534. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7535. Accept = (QueueItem != DestQueueItem) &&
  7536. (QueueItem->Status == TQueueItem::qsPending) &&
  7537. (DestQueueItem->Status == TQueueItem::qsPending);
  7538. }
  7539. }
  7540. }
  7541. //---------------------------------------------------------------------------
  7542. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7543. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7544. {
  7545. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7546. {
  7547. TQueueItemProxy * QueueItem;
  7548. TQueueItemProxy * DestQueueItem;
  7549. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7550. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7551. QueueItem->Move(DestQueueItem);
  7552. }
  7553. }
  7554. //---------------------------------------------------------------------------
  7555. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7556. {
  7557. if ((QueueView3->ItemFocused == NULL) &&
  7558. (QueueView3->Items->Count > 0))
  7559. {
  7560. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7561. }
  7562. QueueLabelUpdateStatus();
  7563. }
  7564. //---------------------------------------------------------------------------
  7565. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7566. {
  7567. QueueLabelUpdateStatus();
  7568. }
  7569. //---------------------------------------------------------------------------
  7570. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7571. {
  7572. QueueLabel->UpdateStatus();
  7573. }
  7574. //---------------------------------------------------------------------------
  7575. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7576. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7577. {
  7578. if (Selected)
  7579. {
  7580. NonVisualDataModule->UpdateNonVisibleActions();
  7581. }
  7582. }
  7583. //---------------------------------------------------------------------------
  7584. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7585. {
  7586. TDragDropFilesEx * Result = NULL;
  7587. if (Sender == SessionsPageControl)
  7588. {
  7589. Result = FSessionsDragDropFilesEx;
  7590. }
  7591. else if (Sender == QueueView3)
  7592. {
  7593. Result = FQueueDragDropFilesEx;
  7594. }
  7595. else
  7596. {
  7597. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7598. if (DirView != NULL)
  7599. {
  7600. Result = DirView->DragDropFilesEx;
  7601. }
  7602. else
  7603. {
  7604. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7605. if (DriveView != NULL)
  7606. {
  7607. Result = DriveView->DragDropFilesEx;
  7608. }
  7609. }
  7610. }
  7611. DebugAssert(Result != NULL);
  7612. return Result;
  7613. }
  7614. //---------------------------------------------------------------------------
  7615. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7616. {
  7617. return (DView->SelCount == DView->FilesCount);
  7618. }
  7619. //---------------------------------------------------------------------------
  7620. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7621. {
  7622. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7623. }
  7624. //---------------------------------------------------------------------------
  7625. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7626. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7627. {
  7628. DebugAssert(!IsLocalBrowserMode());
  7629. TFileOperation Operation;
  7630. switch (Effect)
  7631. {
  7632. case DROPEFFECT_MOVE:
  7633. Operation = foMove;
  7634. break;
  7635. case DROPEFFECT_COPY:
  7636. // occures on WinXP (reported by user)
  7637. default:
  7638. Operation = foCopy;
  7639. break;
  7640. };
  7641. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7642. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7643. if (DragDropFilesEx->FileList->Count > 0)
  7644. {
  7645. TStrings * FileList = new TStringList();
  7646. try
  7647. {
  7648. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7649. {
  7650. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7651. }
  7652. FDragDropOperation = true;
  7653. TTransferOperationParam Param;
  7654. Param.TargetDirectory = TargetPath;
  7655. // upload, no temp dirs
  7656. Param.Temp = false;
  7657. Param.DragDrop = DragDrop;
  7658. Param.Options =
  7659. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7660. if (ForceQueue)
  7661. {
  7662. Param.Queue = asOn;
  7663. }
  7664. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7665. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7666. {
  7667. if (IsFileControl(DropSourceControl, osLocal))
  7668. {
  7669. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7670. }
  7671. else
  7672. {
  7673. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7674. }
  7675. }
  7676. }
  7677. __finally
  7678. {
  7679. FDragDropOperation = false;
  7680. delete FileList;
  7681. }
  7682. }
  7683. }
  7684. //---------------------------------------------------------------------------
  7685. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7686. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7687. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7688. {
  7689. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7690. }
  7691. //---------------------------------------------------------------------------
  7692. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7693. TObject * Sender, int grfKeyState, int & dwEffect)
  7694. {
  7695. DebugAssert(!IsLocalBrowserMode());
  7696. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7697. if ((dwEffect != DROPEFFECT_NONE) &&
  7698. IsFileControl(DropSourceControl, osRemote))
  7699. {
  7700. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7701. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7702. (RemoteDirView->DropTarget == NULL))
  7703. {
  7704. dwEffect = DROPEFFECT_NONE;
  7705. }
  7706. else
  7707. {
  7708. if (dwEffect == DROPEFFECT_COPY)
  7709. {
  7710. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7711. // currently we support copying always (at least via temporary directory);
  7712. // remove associated checks once this all proves stable and working
  7713. bool CopyCapable = true;
  7714. // if we do not support neither of operations, there's no discussion
  7715. if (!MoveCapable && !CopyCapable)
  7716. {
  7717. dwEffect = DROPEFFECT_NONE;
  7718. }
  7719. else
  7720. {
  7721. // The default effect inside remote panel is move,
  7722. // unless we do not support it, but support copy
  7723. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7724. {
  7725. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7726. }
  7727. else
  7728. {
  7729. // with ctrl-down, we want copy unless it is not supported
  7730. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7731. }
  7732. }
  7733. }
  7734. }
  7735. }
  7736. }
  7737. //---------------------------------------------------------------------------
  7738. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7739. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7740. {
  7741. DebugAssert(!IsLocalBrowserMode());
  7742. if (FDDTotalSize >= 0)
  7743. {
  7744. if (File->IsDirectory)
  7745. {
  7746. FDDTotalSize = -1;
  7747. }
  7748. else
  7749. {
  7750. FDDTotalSize += File->Size;
  7751. }
  7752. }
  7753. DebugAssert(!FDragTempDir.IsEmpty());
  7754. // TODO: this is quite ineffective
  7755. // TODO: what if invalid character replacement is disabled?
  7756. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7757. UnicodeString TransferFileName;
  7758. if (Sender == RemoteDriveView)
  7759. {
  7760. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7761. }
  7762. else
  7763. {
  7764. TransferFileName = File->FileName;
  7765. }
  7766. FDDFileList->AddObject(TransferFileName, File);
  7767. }
  7768. //---------------------------------------------------------------------------
  7769. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7770. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7771. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7772. {
  7773. // sometimes we do not get DDEnd so the list is not released
  7774. SAFE_DESTROY(FDDFileList);
  7775. FDDFileList = new TStringList();
  7776. FDragTempDir = WinConfiguration->TemporaryDir();
  7777. FDDTotalSize = 0;
  7778. FDragDropSshTerminate.reset(NULL);
  7779. }
  7780. //---------------------------------------------------------------------------
  7781. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7782. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7783. HRESULT & Result)
  7784. {
  7785. if (Result == DRAGDROP_S_DROP)
  7786. {
  7787. try
  7788. {
  7789. GlobalDragImageList->HideDragImage();
  7790. try
  7791. {
  7792. RemoteFileControlDDTargetDrop();
  7793. }
  7794. catch(ESshTerminate & E)
  7795. {
  7796. FDragDropSshTerminate.reset(E.Clone());
  7797. }
  7798. }
  7799. catch (Exception &E)
  7800. {
  7801. // If downloading fails we need to cancel drag&drop, otherwise
  7802. // Explorer shows error
  7803. // But by the way exception probably never reach this point as
  7804. // it's catched on way.
  7805. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7806. Result = DRAGDROP_S_CANCEL;
  7807. ShowExtendedException(Terminal, &E);
  7808. }
  7809. }
  7810. }
  7811. //---------------------------------------------------------------------------
  7812. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7813. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7814. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7815. {
  7816. TFileMasks::TParams MaskParams;
  7817. MaskParams.Size = Size;
  7818. MaskParams.Modification = Modification;
  7819. // this does not re-parse the mask if it is the same as the last time
  7820. FDirViewMatchMask = Masks;
  7821. bool ImplicitMatch;
  7822. Matches =
  7823. // RecurseInclude parameter has no effect as the Path is empty
  7824. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7825. (AllowImplicitMatches || !ImplicitMatch);
  7826. }
  7827. //---------------------------------------------------------------------------
  7828. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7829. TObject * Sender, TListItem * Item, WORD & Indexes)
  7830. {
  7831. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7832. UnicodeString Ext;
  7833. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7834. {
  7835. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7836. }
  7837. else
  7838. {
  7839. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7840. }
  7841. if (SameText(Ext, Configuration->PartialExt))
  7842. {
  7843. Indexes |= oiPartial;
  7844. }
  7845. }
  7846. //---------------------------------------------------------------------------
  7847. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7848. {
  7849. return
  7850. DirViewEnabled(osCurrent) &&
  7851. DirView(osCurrent)->CanPasteFromClipBoard();
  7852. }
  7853. //---------------------------------------------------------------------------
  7854. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7855. {
  7856. bool Result = false;
  7857. if (CanPasteToDirViewFromClipBoard())
  7858. {
  7859. Result = true;
  7860. }
  7861. else
  7862. {
  7863. UnicodeString ClipboardText;
  7864. if (NonEmptyTextFromClipboard(ClipboardText))
  7865. {
  7866. if (StoredSessions->IsUrl(ClipboardText))
  7867. {
  7868. Result = true;
  7869. }
  7870. else
  7871. {
  7872. Result = DirViewEnabled(osCurrent);
  7873. }
  7874. }
  7875. }
  7876. return Result;
  7877. }
  7878. //---------------------------------------------------------------------------
  7879. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7880. {
  7881. if (DoesClipboardContainOurFiles())
  7882. {
  7883. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7884. {
  7885. DebugAssert(!IsLocalBrowserMode());
  7886. TTerminalManager * Manager = TTerminalManager::Instance();
  7887. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7888. Manager->ActiveTerminal = FClipboardTerminal;
  7889. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7890. }
  7891. }
  7892. else if (CanPasteToDirViewFromClipBoard())
  7893. {
  7894. DirView(osCurrent)->PasteFromClipBoard();
  7895. }
  7896. else
  7897. {
  7898. UnicodeString ClipboardText;
  7899. if (NonEmptyTextFromClipboard(ClipboardText))
  7900. {
  7901. if (StoredSessions->IsUrl(ClipboardText))
  7902. {
  7903. NewSession(false, ClipboardText);
  7904. }
  7905. else
  7906. {
  7907. DirView(osCurrent)->Path = ClipboardText;
  7908. }
  7909. }
  7910. }
  7911. }
  7912. //---------------------------------------------------------------------------
  7913. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7914. {
  7915. // TBD
  7916. }
  7917. //---------------------------------------------------------------------------
  7918. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7919. {
  7920. TCustomDirView * ADirView = DirView(Side);
  7921. ADirView->SelectAll(Mode);
  7922. ADirView->SetFocus();
  7923. }
  7924. //---------------------------------------------------------------------------
  7925. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7926. {
  7927. TCustomDirView * ADirView = DirView(Side);
  7928. TFileFilter Filter;
  7929. DefaultFileFilter(Filter);
  7930. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7931. {
  7932. Configuration->Usage->Inc(L"MaskSelections");
  7933. ADirView->SelectFiles(Filter, Select);
  7934. ADirView->SetFocus();
  7935. }
  7936. }
  7937. //---------------------------------------------------------------------------
  7938. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7939. {
  7940. TCustomDirView * ADirView = DirView(Side);
  7941. ADirView->RestoreSelectedNames();
  7942. ADirView->SetFocus();
  7943. }
  7944. //---------------------------------------------------------------------------
  7945. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7946. {
  7947. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7948. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7949. {
  7950. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7951. UnicodeString Ext;
  7952. if (!IsSideLocalBrowser(osCurrent))
  7953. {
  7954. Ext = UnixExtractFileExt(FileName);
  7955. }
  7956. else
  7957. {
  7958. Ext = ExtractFileExt(FileName);
  7959. }
  7960. if (Ext.IsEmpty())
  7961. {
  7962. Ext = L".";
  7963. }
  7964. TFileFilter Filter;
  7965. Filter.Masks = FORMAT(L"*%s", (Ext));
  7966. Filter.Directories = false;
  7967. CurrentDirView->SelectFiles(Filter, Select);
  7968. }
  7969. }
  7970. //---------------------------------------------------------------------------
  7971. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7972. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7973. {
  7974. UnicodeString Result;
  7975. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7976. {
  7977. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7978. }
  7979. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7980. {
  7981. // noop
  7982. }
  7983. else
  7984. {
  7985. Result =
  7986. FMTLOAD(FILE_INFO_FORMAT,
  7987. (FormatBytes(FileInfo.SelectedSize),
  7988. FormatBytes(FileInfo.FilesSize),
  7989. FormatNumber(FileInfo.SelectedCount),
  7990. FormatNumber(FileInfo.FilesCount)));
  7991. }
  7992. return Result;
  7993. }
  7994. //---------------------------------------------------------------------------
  7995. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7996. TTBXStatusPanel * Panel, TOperationSide Side)
  7997. {
  7998. if (Panel->Index == 1)
  7999. {
  8000. ToggleShowHiddenFiles();
  8001. }
  8002. else if (Panel->Index == 2)
  8003. {
  8004. Filter(Side);
  8005. }
  8006. }
  8007. //---------------------------------------------------------------------------
  8008. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8009. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8010. {
  8011. DebugAssert(!StatusBar->SimplePanel);
  8012. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8013. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8014. }
  8015. //---------------------------------------------------------------------------
  8016. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8017. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8018. {
  8019. DebugAssert(StatusBar->Panels->Count >= 3);
  8020. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8021. if (FileInfo.HiddenCount > 0)
  8022. {
  8023. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8024. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8025. }
  8026. else
  8027. {
  8028. HiddenFilesPanel->ViewPriority = 0;
  8029. // not really necessary, just to cleanup no-longer-valid data
  8030. HiddenFilesPanel->Caption = L"";
  8031. }
  8032. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8033. if (FileInfo.FilteredCount > 0)
  8034. {
  8035. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8036. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8037. }
  8038. else
  8039. {
  8040. FilteredFilesPanel->ViewPriority = 0;
  8041. // not really necessary, just to cleanup no-longer-valid data
  8042. FilteredFilesPanel->Caption = L"";
  8043. }
  8044. }
  8045. //---------------------------------------------------------------------------
  8046. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8047. TObject * /*Sender*/)
  8048. {
  8049. if (DirView(osOther)->Enabled)
  8050. {
  8051. DirView(osOther)->SetFocus();
  8052. }
  8053. }
  8054. //---------------------------------------------------------------------------
  8055. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8056. {
  8057. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8058. switch (Config.Show)
  8059. {
  8060. case qvShow:
  8061. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8062. {
  8063. Config.Show = qvHide;
  8064. }
  8065. else
  8066. {
  8067. Config.Show = Config.LastHideShow;
  8068. }
  8069. break;
  8070. case qvHideWhenEmpty:
  8071. if (ComponentVisible[fcQueueView])
  8072. {
  8073. Config.Show = qvHide;
  8074. }
  8075. else
  8076. {
  8077. Config.LastHideShow = Config.Show;
  8078. Config.Show = qvShow;
  8079. }
  8080. break;
  8081. case qvHide:
  8082. Config.LastHideShow = Config.Show;
  8083. Config.Show = qvShow;
  8084. break;
  8085. }
  8086. WinConfiguration->QueueView = Config;
  8087. }
  8088. //---------------------------------------------------------------------------
  8089. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8090. {
  8091. UnicodeString Result;
  8092. if (FTerminal != NULL)
  8093. {
  8094. switch (WinConfiguration->PathInCaption)
  8095. {
  8096. case picShort:
  8097. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8098. break;
  8099. case picFull:
  8100. Result = FTerminal->CurrentDirectory;
  8101. break;
  8102. }
  8103. }
  8104. return Result;
  8105. }
  8106. //---------------------------------------------------------------------------
  8107. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8108. {
  8109. TColor Result = GetWindowColor(FSessionColor);
  8110. return Result;
  8111. }
  8112. //---------------------------------------------------------------------------
  8113. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8114. {
  8115. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8116. return Result;
  8117. }
  8118. //---------------------------------------------------------------------------
  8119. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8120. {
  8121. TTerminalManager::Instance()->UpdateAppTitle();
  8122. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8123. // background to gray on Windows 7 (works on Windows 10).
  8124. // See also EnableControl
  8125. if (Showing)
  8126. {
  8127. if (Terminal != NULL)
  8128. {
  8129. // Update path when it changes
  8130. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8131. {
  8132. UpdateSessionTab(SessionsPageControl->ActivePage);
  8133. }
  8134. }
  8135. NonVisualDataModule->ReconnectSessionAction->Update();
  8136. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8137. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8138. CenterReconnectToolbar();
  8139. bool HasTerminal = HasActiveTerminal();
  8140. RemoteDirView->Enabled = HasTerminal;
  8141. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8142. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8143. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8144. RemoteDriveView->Color = RemoteDirView->Color;
  8145. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8146. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8147. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8148. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8149. QueueFileList->Enabled = QueueView3->Enabled;
  8150. QueueFileList->Color = QueueView3->Color;
  8151. QueueFileList->Font->Color = QueueView3->Font->Color;
  8152. QueueLabelUpdateStatus();
  8153. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8154. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8155. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8156. }
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8160. {
  8161. UpdateControls();
  8162. }
  8163. //---------------------------------------------------------------------------
  8164. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8165. TObject * Sender)
  8166. {
  8167. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8168. DebugAssert(DirView != NULL);
  8169. DoDirViewLoaded(DirView);
  8170. TransferPresetAutoSelect();
  8171. }
  8172. //---------------------------------------------------------------------------
  8173. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8174. {
  8175. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8176. // first run after installation
  8177. if (double(Updates.LastCheck) == 0)
  8178. {
  8179. // make sure next time there will be an update (if enabled)
  8180. Updates.LastCheck = TDateTime(1);
  8181. WinConfiguration->Updates = Updates;
  8182. }
  8183. else if ((double(Updates.Period) > 0) &&
  8184. (Now() - Updates.LastCheck >= Updates.Period))
  8185. {
  8186. TThreadMethod OnUpdatesChecked = NULL;
  8187. if (!IsUWP())
  8188. {
  8189. OnUpdatesChecked = UpdatesChecked;
  8190. }
  8191. StartUpdateThread(OnUpdatesChecked);
  8192. }
  8193. }
  8194. //---------------------------------------------------------------------------
  8195. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8196. {
  8197. UnicodeString Message;
  8198. bool New;
  8199. TQueryType Type;
  8200. GetUpdatesMessage(Message, New, Type, false);
  8201. if (!Message.IsEmpty())
  8202. {
  8203. if (New)
  8204. {
  8205. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8206. }
  8207. if (!New && (Type != qtWarning))
  8208. {
  8209. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8210. }
  8211. else
  8212. {
  8213. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8214. }
  8215. if (New)
  8216. {
  8217. Configuration->Usage->Inc(L"UpdateNotifications");
  8218. }
  8219. }
  8220. }
  8221. //---------------------------------------------------------------------------
  8222. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8223. {
  8224. RestoreApp();
  8225. bool CanDisplay = !NonVisualDataModule->Busy;
  8226. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8227. {
  8228. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8229. }
  8230. if (CanDisplay)
  8231. {
  8232. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8233. CheckForUpdates(true);
  8234. }
  8235. else
  8236. {
  8237. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8238. }
  8239. }
  8240. //---------------------------------------------------------------------------
  8241. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8242. TCopyParamRuleData & Data)
  8243. {
  8244. DebugAssert(Terminal != NULL);
  8245. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8246. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8247. Data.RemoteDirectory = RemoteDirView->PathName;
  8248. }
  8249. //---------------------------------------------------------------------------
  8250. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8251. {
  8252. // Terminal can be null when we are changing local directory implicitly,
  8253. // because it has been deleted, while no session is connected
  8254. // (Login dialog is open)
  8255. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8256. {
  8257. DebugAssert(!IsLocalBrowserMode());
  8258. TCopyParamRuleData Data;
  8259. GetTransferPresetAutoSelectData(Data);
  8260. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8261. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8262. if (CopyParamIndex < 0)
  8263. {
  8264. // there is no preset that matches autoselection
  8265. // set preset that we consider "default"
  8266. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8267. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8268. }
  8269. else
  8270. {
  8271. // there is preset matching autoselection
  8272. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8273. if (CopyParamName == FCopyParamAutoSelected)
  8274. {
  8275. // autoselected the same preset as the last time
  8276. // make no change (i.e. preserve custom user preset, if any)
  8277. }
  8278. else
  8279. {
  8280. // autoselected the different preset then the last time (or there
  8281. // was default preset set)
  8282. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8283. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8284. }
  8285. }
  8286. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8287. {
  8288. if (CopyParamIndex >= 0)
  8289. {
  8290. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8291. }
  8292. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8293. try
  8294. {
  8295. int Fmt =
  8296. (CopyParamIndex < 0) ?
  8297. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8298. COPY_PARAM_AUTOSELECTED;
  8299. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8300. Data->Message = MainInstructions(Message);
  8301. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8302. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8303. CopyParamAttrs);
  8304. if (CopyParamIndex >= 0)
  8305. {
  8306. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8307. Info = FORMAT(L"%s\n \n%s", (Info,
  8308. FMTLOAD(COPY_PARAM_RULE,
  8309. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8310. }
  8311. Data->Message += L"\n\n" + Info;
  8312. if (WinConfiguration->CopyParamAutoSelectNotice)
  8313. {
  8314. TransferPresetNoteMessage(Data, true);
  8315. }
  8316. else
  8317. {
  8318. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8319. Data = NULL; // ownership passed
  8320. }
  8321. }
  8322. __finally
  8323. {
  8324. delete Data;
  8325. }
  8326. }
  8327. }
  8328. }
  8329. //---------------------------------------------------------------------------
  8330. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8331. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8332. {
  8333. DebugAssert(NoteData != NULL);
  8334. DebugAssert(!IsLocalBrowserMode());
  8335. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8336. TQueryButtonAlias Aliases[1];
  8337. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8338. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8339. Params.Aliases = Aliases;
  8340. Params.AliasesCount = LENOF(Aliases);
  8341. unsigned int Result =
  8342. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8343. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8344. switch (Result)
  8345. {
  8346. case qaNeverAskAgain:
  8347. DebugAssert(AllowNeverAskAgain);
  8348. WinConfiguration->CopyParamAutoSelectNotice = false;
  8349. break;
  8350. case qaIgnore:
  8351. PreferencesDialog(pmPresets);
  8352. break;
  8353. }
  8354. }
  8355. //---------------------------------------------------------------------------
  8356. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8357. {
  8358. // as of now useless, as this is used for notes only, never for balloons, ...
  8359. RestoreApp();
  8360. // .. and we should never be busy here
  8361. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8362. {
  8363. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8364. }
  8365. }
  8366. //---------------------------------------------------------------------------
  8367. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8368. TPreferencesMode APreferencesMode)
  8369. {
  8370. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8371. TCopyParamRuleData Data;
  8372. if (Terminal != NULL)
  8373. {
  8374. PreferencesData.reset(new TPreferencesDialogData());
  8375. GetTransferPresetAutoSelectData(Data);
  8376. PreferencesData->CopyParamRuleData = &Data;
  8377. }
  8378. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8379. }
  8380. //---------------------------------------------------------------------------
  8381. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8382. const TCustomCommandType & Command)
  8383. {
  8384. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8385. {
  8386. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8387. }
  8388. }
  8389. //---------------------------------------------------------------------------
  8390. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8391. {
  8392. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8393. TCustomCommandType Command;
  8394. // make sure we use local custom command when remote are not supported
  8395. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8396. {
  8397. Command = FLastCustomCommand;
  8398. }
  8399. else
  8400. {
  8401. Command.Params = Command.Params | ccLocal;
  8402. }
  8403. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8404. FEditingFocusedAdHocCommand = OnFocused;
  8405. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8406. int Options =
  8407. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8408. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8409. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8410. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8411. {
  8412. FLastCustomCommand = Command;
  8413. UpdateCustomCommandsToolbar();
  8414. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8415. }
  8416. }
  8417. //---------------------------------------------------------------------------
  8418. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8419. {
  8420. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8421. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8422. DebugAssert(State > 0);
  8423. if (State <= 0)
  8424. {
  8425. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8426. }
  8427. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8428. }
  8429. //---------------------------------------------------------------------------
  8430. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8431. TCustomCommandType & Command, int & State)
  8432. {
  8433. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8434. if (Result)
  8435. {
  8436. Command = FLastCustomCommand;
  8437. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8438. }
  8439. return Result;
  8440. }
  8441. //---------------------------------------------------------------------------
  8442. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8443. {
  8444. ResetIncrementalSearch();
  8445. }
  8446. //---------------------------------------------------------------------------
  8447. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8448. {
  8449. DebugAssert(ComponentVisible[Component]);
  8450. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8451. }
  8452. //---------------------------------------------------------------------------
  8453. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8454. {
  8455. // when queue panel is resized here directly, the status bar is stretched
  8456. // over whole space the panel occupied
  8457. PostComponentHide(fcQueueView);
  8458. }
  8459. //---------------------------------------------------------------------------
  8460. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8461. {
  8462. ComponentVisible[fcQueueFileList] = false;
  8463. }
  8464. //---------------------------------------------------------------------------
  8465. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8466. {
  8467. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8468. RefreshColorMode();
  8469. ResetSysDarkTheme();
  8470. ConfigurationChanged();
  8471. ConfigureInterface();
  8472. // Should be called for all controls
  8473. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8474. }
  8475. //---------------------------------------------------------------------------
  8476. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8477. {
  8478. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8479. if (!FInvalid &&
  8480. (Message.LParam != 0) &&
  8481. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8482. {
  8483. ThemeChanged();
  8484. }
  8485. TForm::Dispatch(&Message);
  8486. }
  8487. //---------------------------------------------------------------------------
  8488. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8489. {
  8490. TMessage * M = static_cast<TMessage*>(Message);
  8491. switch (M->Msg)
  8492. {
  8493. case CM_DIALOGCHAR:
  8494. CMDialogChar(*M);
  8495. break;
  8496. case WM_APPCOMMAND:
  8497. WMAppCommand(*M);
  8498. break;
  8499. case WM_SYSCOMMAND:
  8500. WMSysCommand(*M);
  8501. break;
  8502. case WM_QUERYENDSESSION:
  8503. WMQueryEndSession(*M);
  8504. break;
  8505. case WM_ENDSESSION:
  8506. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8507. break;
  8508. #ifdef _DEBUG
  8509. case WM_WINDOWPOSCHANGED:
  8510. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8511. break;
  8512. case CM_CUSTOMSTYLECHANGED:
  8513. TForm::Dispatch(Message);
  8514. break;
  8515. #endif
  8516. case WM_COMPONENT_HIDE:
  8517. {
  8518. Byte Component = static_cast<Byte>(M->WParam);
  8519. // sanity check
  8520. if (ComponentVisible[Component])
  8521. {
  8522. // special treatment
  8523. if (Component == fcQueueView)
  8524. {
  8525. ToggleQueueVisibility();
  8526. DebugAssert(!ComponentVisible[fcQueueView]);
  8527. }
  8528. else
  8529. {
  8530. ComponentVisible[Component] = false;
  8531. }
  8532. }
  8533. }
  8534. break;
  8535. case WM_COPYDATA:
  8536. WMCopyData(*M);
  8537. break;
  8538. case WM_MANAGES_CAPTION:
  8539. // caption managed in TTerminalManager::UpdateAppTitle()
  8540. M->Result = 1;
  8541. break;
  8542. case WM_WANTS_MOUSEWHEEL:
  8543. M->Result = 1;
  8544. break;
  8545. case CM_SHOWINGCHANGED:
  8546. CMShowingChanged(*M);
  8547. break;
  8548. case WM_CLOSE:
  8549. WMClose(*M);
  8550. break;
  8551. case WM_DPICHANGED:
  8552. WMDpiChanged(*M);
  8553. break;
  8554. case CM_DPICHANGED:
  8555. CMDpiChanged(*M);
  8556. break;
  8557. case WM_SETTINGCHANGE:
  8558. WMSettingChange(*M);
  8559. break;
  8560. case CM_DIALOGKEY:
  8561. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8562. break;
  8563. default:
  8564. TForm::Dispatch(Message);
  8565. break;
  8566. }
  8567. }
  8568. //---------------------------------------------------------------------------
  8569. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8570. {
  8571. // noop
  8572. }
  8573. //---------------------------------------------------------------------------
  8574. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8575. {
  8576. TForm::Dispatch(&Message);
  8577. FSessionColors->Clear();
  8578. AddFixedSessionImages();
  8579. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8580. UpdateImages();
  8581. }
  8582. //---------------------------------------------------------------------------
  8583. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8584. {
  8585. TForm::Dispatch(&Message);
  8586. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8587. UpdatePixelsPerInchMainWindowCounter();
  8588. }
  8589. //---------------------------------------------------------------------------
  8590. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8591. {
  8592. // Cannot close window while we are busy.
  8593. // We cannot test this in FormCloseQuery as that is called also from
  8594. // Close(), which is called by CloseApplicationAction. So we can be busy
  8595. // there already even, when it is legitimate to close the application.
  8596. // Possibly a better place to handle this would be WMSysCommand.
  8597. if (NonVisualDataModule->Busy)
  8598. {
  8599. Message.Result = 1;
  8600. }
  8601. else
  8602. {
  8603. TForm::Dispatch(&Message);
  8604. }
  8605. }
  8606. //---------------------------------------------------------------------------
  8607. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8608. {
  8609. TForm::Dispatch(&Message);
  8610. if (Showing && (Terminal == NULL))
  8611. {
  8612. // When we are starting minimized (i.e. from an installer),
  8613. // postpone showing Login dialog until we get restored.
  8614. // Otherwise the Login dialog (and Authentication window) show restored
  8615. // over invisible (minimized) main window.
  8616. if (WindowState == wsMinimized)
  8617. {
  8618. FNeedSession = true;
  8619. }
  8620. else
  8621. {
  8622. // This happens before application ever goes idle, so the toolbars would
  8623. // stay enabled (initial state) until the Login dialog is dismissed.
  8624. UpdateActions();
  8625. NonVisualDataModule->StartBusy();
  8626. try
  8627. {
  8628. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8629. // otherwise the dialog does not receive focus.
  8630. // With Commander interface the ProcessMessages is called already
  8631. // by TDriveView, but with Explorer interface, we need to call it explicily
  8632. Application->ProcessMessages();
  8633. // do not reload sessions, they have been loaded just now (optimization)
  8634. NeedSession(true);
  8635. }
  8636. __finally
  8637. {
  8638. NonVisualDataModule->EndBusy();
  8639. }
  8640. }
  8641. }
  8642. }
  8643. //---------------------------------------------------------------------------
  8644. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8645. {
  8646. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8647. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8648. }
  8649. //---------------------------------------------------------------------------
  8650. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8651. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8652. int & MaxHeight)
  8653. {
  8654. // workaround for bug in TWinControl.CalcConstraints
  8655. // Check for empty rect (restore from iconic state) is done there only after
  8656. // call to AdjustClientRect, which enlarges the rect (for forms).
  8657. TRect R = GetClientRect();
  8658. // when restoring from iconic state, place no restrictions
  8659. if (IsRectEmpty(R))
  8660. {
  8661. MinWidth = 0;
  8662. MinHeight = 0;
  8663. MaxWidth = 32000;
  8664. MaxHeight = 32000;
  8665. }
  8666. }
  8667. //---------------------------------------------------------------------------
  8668. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8669. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8670. {
  8671. // terminal can be already closed (e.g. dropped connection)
  8672. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8673. {
  8674. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8675. try
  8676. {
  8677. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8678. }
  8679. catch(...)
  8680. {
  8681. if (!Terminal->Active)
  8682. {
  8683. Close = true;
  8684. }
  8685. throw;
  8686. }
  8687. }
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8691. {
  8692. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8693. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8694. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8695. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8696. {
  8697. OnGetSpaceAvailable = GetSpaceAvailable;
  8698. }
  8699. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8700. OnGetSpaceAvailable);
  8701. }
  8702. //---------------------------------------------------------------------------
  8703. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8704. {
  8705. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8706. Terminal->FillSessionDataForCode(Data.get());
  8707. return Data.release();
  8708. }
  8709. //---------------------------------------------------------------------------
  8710. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8711. {
  8712. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8713. DoGenerateUrlDialog(Data.get(), Paths);
  8714. }
  8715. //---------------------------------------------------------------------------
  8716. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8717. {
  8718. GenerateUrl(NULL);
  8719. }
  8720. //---------------------------------------------------------------------------
  8721. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8722. {
  8723. std::unique_ptr<TStrings> Paths(new TStringList());
  8724. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8725. GenerateUrl(Paths.get());
  8726. }
  8727. //---------------------------------------------------------------------------
  8728. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8729. {
  8730. FSessionColor = value;
  8731. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8732. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8733. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8734. DebugAssert(ColorItem != NULL);
  8735. ColorItem->Color = C;
  8736. NonVisualDataModule->ColorMenuItem->Color = C;
  8737. UpdateControls();
  8738. }
  8739. //---------------------------------------------------------------------------
  8740. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8741. {
  8742. if (value != FSessionColor)
  8743. {
  8744. UpdateSessionColor(value);
  8745. // Is null when called from LastTerminalClosed
  8746. if (Terminal != NULL)
  8747. {
  8748. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8749. }
  8750. }
  8751. }
  8752. //---------------------------------------------------------------------------
  8753. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8754. {
  8755. bool Result = FNoteTimer->Enabled;
  8756. if (Result)
  8757. {
  8758. // cannot cancel note too early
  8759. bool NotEarly =
  8760. (Now() - FNoteShown >
  8761. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8762. if (Force || NotEarly)
  8763. {
  8764. FNoteTimer->Enabled = false;
  8765. FNote = L"";
  8766. SAFE_DESTROY(FNoteData);
  8767. FOnNoteClick = NULL;
  8768. FNoteHints = FNotes->Text;
  8769. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8770. UpdateStatusBar();
  8771. }
  8772. }
  8773. return Result;
  8774. }
  8775. //---------------------------------------------------------------------------
  8776. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8777. {
  8778. DebugAssert(FNoteTimer->Enabled);
  8779. CancelNote(true);
  8780. }
  8781. //---------------------------------------------------------------------------
  8782. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8783. {
  8784. int P = Note.Pos(L"\n");
  8785. if (P > 0)
  8786. {
  8787. Note.SetLength(P - 1);
  8788. }
  8789. FNotes->Add(FORMAT(L"[%s] %s",
  8790. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8791. while (FNotes->Count > 10)
  8792. {
  8793. FNotes->Delete(0);
  8794. }
  8795. if (UpdateNow)
  8796. {
  8797. FNoteHints = FNotes->Text;
  8798. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8799. UpdateStatusBar();
  8800. }
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8804. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8805. {
  8806. int P = Note.Pos(L"\n");
  8807. if (P > 0)
  8808. {
  8809. Note.SetLength(P - 1);
  8810. }
  8811. FNoteHints = FNotes->Text;
  8812. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8813. FNote = Note;
  8814. SAFE_DESTROY(FNoteData);
  8815. FNoteData = NoteData;
  8816. FOnNoteClick = OnNoteClick;
  8817. AddNote(Note, false);
  8818. UpdateStatusBar();
  8819. FNoteShown = Now();
  8820. FNoteTimer->Enabled = false;
  8821. if (Seconds == 0)
  8822. {
  8823. Seconds = WinConfiguration->NotificationsTimeout;
  8824. }
  8825. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8826. FNoteTimer->Enabled = true;
  8827. }
  8828. //---------------------------------------------------------------------------
  8829. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8830. {
  8831. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8832. }
  8833. //---------------------------------------------------------------------------
  8834. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8835. {
  8836. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8837. {
  8838. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8839. }
  8840. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8841. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8842. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8843. 0, NULL, NULL);
  8844. }
  8845. //---------------------------------------------------------------------------
  8846. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8847. {
  8848. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8849. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8850. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8851. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8852. }
  8853. //---------------------------------------------------------------------------
  8854. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8855. {
  8856. WinConfiguration->FormatSizeBytes = Style;
  8857. }
  8858. //---------------------------------------------------------------------------
  8859. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8860. {
  8861. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8862. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8863. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8864. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8865. }
  8866. //---------------------------------------------------------------------------
  8867. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8868. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8869. {
  8870. if (Panel->Index == 0)
  8871. {
  8872. if (FOnNoteClick != NULL)
  8873. {
  8874. // prevent the user data from being freed by possible call
  8875. // to CancelNote or PostNote during call to OnNoteClick
  8876. std::unique_ptr<TObject> NoteData(FNoteData);
  8877. TNotifyEvent OnNoteClick = FOnNoteClick;
  8878. FNoteData = NULL;
  8879. // need to cancel the note as we are going to delete its user data
  8880. CancelNote(true);
  8881. OnNoteClick(NoteData.get());
  8882. }
  8883. }
  8884. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8885. {
  8886. FileSystemInfo();
  8887. }
  8888. }
  8889. //---------------------------------------------------------------------------
  8890. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8891. {
  8892. // workaround:
  8893. // 1) for unknown reason, disabling window, while minimized,
  8894. // prevents it from restoring, even if it was enabled again meanwhile
  8895. // 2) when disabling the main window, while another has focus
  8896. // minimize is no longer possible
  8897. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8898. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8899. // Shouldn't we use IsApplicationMinimized() here?
  8900. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8901. {
  8902. Enabled = false;
  8903. }
  8904. FLockLevel++;
  8905. }
  8906. //---------------------------------------------------------------------------
  8907. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8908. {
  8909. DebugAssert(FLockLevel > 0);
  8910. FLockLevel--;
  8911. if (FLockLevel == 0)
  8912. {
  8913. DebugAssert(FLockSuspendLevel == 0);
  8914. Enabled = true;
  8915. }
  8916. }
  8917. //---------------------------------------------------------------------------
  8918. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8919. {
  8920. // We need to make sure that window is enabled when the last modal window closes
  8921. // otherwise focus is not restored correctly.
  8922. // So we re-enable the window when modal window opens and
  8923. // disable it back after is closes
  8924. if (FLockLevel > 0)
  8925. {
  8926. // while we have nesting counter, we know that we never be called
  8927. // recursivelly as Application->OnModalBegin is called only
  8928. // for the top-level modal window
  8929. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8930. {
  8931. // won't be disabled when conditions in LockWindow() were not satisfied
  8932. FDisabledOnLockSuspend = !Enabled;
  8933. // When minimized to tray (or actually when set to SW_HIDE),
  8934. // setting Enabled makes the window focusable even when there's
  8935. // modal window over it
  8936. if (!FTrayIcon->Visible)
  8937. {
  8938. Enabled = true;
  8939. }
  8940. }
  8941. FLockSuspendLevel++;
  8942. }
  8943. }
  8944. //---------------------------------------------------------------------------
  8945. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8946. {
  8947. if (FLockSuspendLevel > 0)
  8948. {
  8949. DebugAssert(FLockLevel > 0);
  8950. FLockSuspendLevel--;
  8951. // see comment in SuspendWindowLock
  8952. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8953. {
  8954. // Note that window can be enabled here, when we were minized to tray when
  8955. // was SuspendWindowLock() called.
  8956. // We should possibly do the same check as in LockWindow(),
  8957. // if it is ever possible that the consitions change between
  8958. // SuspendWindowLock() and ResumeWindowLock()
  8959. Enabled = !FDisabledOnLockSuspend;
  8960. }
  8961. }
  8962. }
  8963. //---------------------------------------------------------------------------
  8964. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8965. {
  8966. TTBXComboBoxItem * RemotePathComboBox =
  8967. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8968. if (!TextOnly)
  8969. {
  8970. TStrings * Items = RemotePathComboBox->Strings;
  8971. Items->BeginUpdate();
  8972. try
  8973. {
  8974. Items->Clear();
  8975. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8976. {
  8977. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8978. while (!IsUnixRootPath(APath))
  8979. {
  8980. int P = APath.LastDelimiter(L'/');
  8981. DebugAssert(P >= 0);
  8982. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8983. APath.SetLength(P - 1);
  8984. }
  8985. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8986. }
  8987. }
  8988. __finally
  8989. {
  8990. Items->EndUpdate();
  8991. }
  8992. }
  8993. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  8994. // Setting ItemIndex to -1 does not reset its text
  8995. if (RemotePathComboBox->Strings->Count == 0)
  8996. {
  8997. RemotePathComboBox->Text = L"";
  8998. }
  8999. }
  9000. //---------------------------------------------------------------------------
  9001. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9002. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9003. {
  9004. if (AIndex < 0)
  9005. {
  9006. AIndex = Sender->ItemIndex;
  9007. }
  9008. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9009. }
  9010. //---------------------------------------------------------------------------
  9011. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9012. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9013. int & ImageIndex)
  9014. {
  9015. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9016. }
  9017. //---------------------------------------------------------------------------
  9018. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9019. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9020. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9021. {
  9022. if (!IsLocalBrowserMode())
  9023. {
  9024. ARect.Left += (10 * AIndex);
  9025. }
  9026. }
  9027. //---------------------------------------------------------------------------
  9028. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9029. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9030. {
  9031. AWidth += (10 * AIndex);
  9032. }
  9033. //---------------------------------------------------------------------------
  9034. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9035. {
  9036. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9037. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9038. int Index = RemotePathComboBox->ItemIndex;
  9039. while (Index < RemotePathComboBox->Strings->Count - 1)
  9040. {
  9041. APath = UnixExtractFileDir(APath);
  9042. Index++;
  9043. }
  9044. // VanDyke style paths
  9045. if (APath.IsEmpty())
  9046. {
  9047. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9048. APath = ROOTDIRECTORY;
  9049. }
  9050. if (RemoteDirView->Path != APath)
  9051. {
  9052. RemoteDirView->Path = APath;
  9053. }
  9054. }
  9055. //---------------------------------------------------------------------------
  9056. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9057. {
  9058. DoRemotePathComboBoxItemClick(Sender);
  9059. }
  9060. //---------------------------------------------------------------------------
  9061. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9062. {
  9063. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9064. DebugUsedParam(Sender);
  9065. UpdateRemotePathComboBox(true);
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9069. {
  9070. DoRemotePathComboBoxCancel(Sender);
  9071. }
  9072. //---------------------------------------------------------------------------
  9073. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9074. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9075. {
  9076. ResetIncrementalSearch();
  9077. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9078. DebugAssert(DirView != NULL);
  9079. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9080. {
  9081. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9082. // OnEditing is called also from TCustomListView::CanEdit
  9083. if (Edit != NULL)
  9084. {
  9085. EditSelectBaseName(Edit);
  9086. }
  9087. }
  9088. }
  9089. //---------------------------------------------------------------------------
  9090. //---------------------------------------------------------------------------
  9091. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9092. {
  9093. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9094. Result->AutoDetectDnD = false;
  9095. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9096. Result->RenderDataOn = rdoEnterAndDropSync;
  9097. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9098. return Result;
  9099. }
  9100. //---------------------------------------------------------------------------
  9101. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9102. {
  9103. TForm::CreateWnd();
  9104. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9105. if (FSessionsDragDropFilesEx == NULL)
  9106. {
  9107. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9108. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9109. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9110. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9111. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9112. }
  9113. if (FQueueDragDropFilesEx == NULL)
  9114. {
  9115. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9116. // No need to set OnDragOver as we do not have any restrictions
  9117. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9118. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9119. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9120. }
  9121. }
  9122. //---------------------------------------------------------------------------
  9123. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9124. {
  9125. TForm::DestroyWnd();
  9126. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9127. FQueueDragDropFilesEx->DragDropControl = NULL;
  9128. }
  9129. //---------------------------------------------------------------------------
  9130. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9131. {
  9132. SideEnter(FCurrentSide);
  9133. FEverShown = true;
  9134. }
  9135. //---------------------------------------------------------------------------
  9136. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9137. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9138. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9139. {
  9140. if (!NonVisualDataModule->Busy)
  9141. {
  9142. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9143. Configuration->Usage->Inc(L"FileFinds");
  9144. LockWindow(true);
  9145. NonVisualDataModule->StartBusy();
  9146. WinConfiguration->LockedInterface = true;
  9147. try
  9148. {
  9149. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9150. }
  9151. __finally
  9152. {
  9153. WinConfiguration->LockedInterface = false;
  9154. NonVisualDataModule->EndBusy();
  9155. UnlockWindow();
  9156. }
  9157. }
  9158. }
  9159. //---------------------------------------------------------------------------
  9160. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9161. {
  9162. if (!NonVisualDataModule->Busy)
  9163. {
  9164. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9165. SetFocus();
  9166. RemoteDirView->Path = UnixExtractFilePath(Path);
  9167. UnicodeString FileName = UnixExtractFileName(Path);
  9168. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9169. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9170. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9171. if (Item == NULL)
  9172. {
  9173. ReloadDirectory(osRemote);
  9174. Item = RemoteDirView->FindFileItem(FileName);
  9175. }
  9176. if (Item != NULL)
  9177. {
  9178. RemoteDirView->ItemFocused = Item;
  9179. RemoteDirView->ItemFocused->MakeVisible(false);
  9180. RemoteDirView->SetFocus();
  9181. }
  9182. }
  9183. }
  9184. //---------------------------------------------------------------------------
  9185. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9186. {
  9187. bool Result = !NonVisualDataModule->Busy;
  9188. if (Result)
  9189. {
  9190. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9191. }
  9192. return Result;
  9193. }
  9194. //---------------------------------------------------------------------------
  9195. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9196. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9197. {
  9198. if (CanOperateOnFoundFiles(ATerminal))
  9199. {
  9200. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9201. FOnFileOperationFinished = OnFileOperationFinished;
  9202. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9203. }
  9204. }
  9205. //---------------------------------------------------------------------------
  9206. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9207. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9208. {
  9209. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9210. }
  9211. //---------------------------------------------------------------------------
  9212. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9213. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9214. {
  9215. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9216. }
  9217. //---------------------------------------------------------------------------
  9218. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9219. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9220. {
  9221. if (CanOperateOnFoundFiles(ATerminal))
  9222. {
  9223. for (int Index = 0; Index < FileList->Count; Index++)
  9224. {
  9225. UnicodeString FileName = FileList->Strings[Index];
  9226. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9227. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9228. OnFileOperationFinished(FileName, true);
  9229. }
  9230. }
  9231. }
  9232. //---------------------------------------------------------------------------
  9233. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9234. {
  9235. FFileFindTerminal = Terminal;
  9236. ShowFileFindDialog(
  9237. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9238. DoDownloadFoundFiles, DoEditFoundFiles);
  9239. }
  9240. //---------------------------------------------------------------------------
  9241. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9242. {
  9243. FTaskbarList = TaskbarList;
  9244. }
  9245. //---------------------------------------------------------------------------
  9246. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9247. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9248. {
  9249. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9250. if (Index >= 0)
  9251. {
  9252. if (Button == mbLeft)
  9253. {
  9254. // "Mouse down" is raised only after tab is switched.
  9255. // If switching tab (switching session) takes long enough for user
  9256. // to actually release the button, "mouse down" is still raised,
  9257. // but we do not get "mouse up" event, so dragging is not cancelled,
  9258. // prevent that by not beginning dragging in the first place.
  9259. if (IsKeyPressed(VK_LBUTTON))
  9260. {
  9261. // when user clicks the "+", we get mouse down only after the session
  9262. // is closed, when new session tab is already on X:Y, so dragging
  9263. // starts, prevent that
  9264. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9265. {
  9266. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9267. if (Terminal != NULL)
  9268. {
  9269. SessionsPageControl->BeginDrag(false);
  9270. }
  9271. }
  9272. }
  9273. }
  9274. else if (Button == mbMiddle)
  9275. {
  9276. // ignore middle-click for "New session tab"
  9277. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9278. if (Terminal != NULL)
  9279. {
  9280. CloseSessionTab(Index);
  9281. }
  9282. }
  9283. }
  9284. }
  9285. //---------------------------------------------------------------------------
  9286. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9287. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9288. {
  9289. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9290. // do not allow dropping on the "+" tab
  9291. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9292. if ((TargetTerminal != NULL) &&
  9293. (SessionsPageControl->ActivePage->PageIndex != Index))
  9294. {
  9295. Configuration->Usage->Inc(L"SessionTabMoves");
  9296. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9297. // but we want to actually prevent that to avoid flicker
  9298. SessionsPageControl->ActivePage->PageIndex = Index;
  9299. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9300. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9301. }
  9302. }
  9303. //---------------------------------------------------------------------------
  9304. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9305. TObject * Sender, TObject * Source, int X, int Y,
  9306. TDragState /*State*/, bool & Accept)
  9307. {
  9308. Accept = (Sender == Source);
  9309. if (Accept)
  9310. {
  9311. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9312. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9313. // do not allow dragging to the "+" tab
  9314. Accept = (Terminal != NULL);
  9315. }
  9316. }
  9317. //---------------------------------------------------------------------------
  9318. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9319. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9320. {
  9321. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9322. if (Index < 0)
  9323. {
  9324. Effect = DROPEFFECT_NONE;
  9325. }
  9326. else
  9327. {
  9328. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9329. // do not allow dropping on the "+" tab
  9330. if (TargetTerminal == NULL)
  9331. {
  9332. Effect = DROPEFFECT_NONE;
  9333. }
  9334. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9335. {
  9336. Effect = DROPEFFECT_COPY;
  9337. }
  9338. }
  9339. }
  9340. //---------------------------------------------------------------------------
  9341. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9342. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9343. {
  9344. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9345. // do not allow dropping on the "+" tab
  9346. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9347. if (TargetTerminal != NULL)
  9348. {
  9349. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9350. if (!IsFileControl(DropSourceControl, osRemote))
  9351. {
  9352. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9353. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9354. // Why don't we use Terminal->CurrentDirectory directly?
  9355. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9356. // do not force queue, drag drop
  9357. false, true);
  9358. }
  9359. }
  9360. }
  9361. //---------------------------------------------------------------------------
  9362. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9363. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9364. {
  9365. // Downloads are handled in RemoteFileControlDDEnd
  9366. if (!IsFileControl(DropSourceControl, osRemote))
  9367. {
  9368. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9369. Terminal->CurrentDirectory,
  9370. // force queue, drag drop
  9371. true, true);
  9372. }
  9373. }
  9374. //---------------------------------------------------------------------------
  9375. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9376. {
  9377. FShowing = false;
  9378. // Do not save empty workspace
  9379. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9380. {
  9381. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9382. UnicodeString Name = WorkspaceName();
  9383. DoSaveWorkspace(
  9384. Name, DataList.get(),
  9385. !Configuration->DisablePasswordStoring &&
  9386. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9387. WinConfiguration->LastStoredSession = Name;
  9388. }
  9389. }
  9390. //---------------------------------------------------------------------------
  9391. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9392. {
  9393. TManagedTerminal * ManagedTerminal =
  9394. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9395. if (ManagedTerminal != NULL)
  9396. {
  9397. ManagedTerminal->DirectoryLoaded = Now();
  9398. }
  9399. }
  9400. //---------------------------------------------------------------------------
  9401. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9402. TListItem * /*Item*/, bool /*Selected*/)
  9403. {
  9404. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9405. switch (DirView->LastSelectMethod)
  9406. {
  9407. case smKeyboard:
  9408. Configuration->Usage->Inc(L"KeyboardSelections");
  9409. break;
  9410. case smMouse:
  9411. Configuration->Usage->Inc(L"MouseSelections");
  9412. break;
  9413. }
  9414. }
  9415. //---------------------------------------------------------------------------
  9416. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9417. {
  9418. if (Color != 0)
  9419. {
  9420. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9421. }
  9422. else
  9423. {
  9424. return FSessionTabImageIndex;
  9425. }
  9426. }
  9427. //---------------------------------------------------------------------------
  9428. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9429. {
  9430. TPngImageCollectionItem * Item =
  9431. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9432. FSessionColors->AddPng(Item->PngImage);
  9433. return FSessionColors->Count - 1;
  9434. }
  9435. //---------------------------------------------------------------------------
  9436. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9437. {
  9438. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9439. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9440. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9441. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9442. }
  9443. //---------------------------------------------------------------------------
  9444. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9445. {
  9446. for (int Index = 0; Index < Control->ControlCount; Index++)
  9447. {
  9448. TControl * AControl = Control->Controls[Index];
  9449. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9450. if (WinControl != NULL)
  9451. {
  9452. CollectItemsWithTextDisplayMode(WinControl);
  9453. }
  9454. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9455. if (Toolbar != NULL)
  9456. {
  9457. // we care for top-level items only
  9458. TTBCustomItem * Items = Toolbar->Items;
  9459. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9460. {
  9461. TTBCustomItem * Item = Items->Items[ItemIndex];
  9462. if (((Item->DisplayMode == nbdmImageAndText) ||
  9463. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9464. EligibleForImageDisplayMode(Item))
  9465. {
  9466. FItemsWithTextDisplayMode.insert(Item);
  9467. }
  9468. }
  9469. }
  9470. }
  9471. }
  9472. //---------------------------------------------------------------------------
  9473. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9474. {
  9475. return true;
  9476. }
  9477. //---------------------------------------------------------------------------
  9478. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9479. {
  9480. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9481. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9482. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9483. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9484. bool Result = true;
  9485. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9486. {
  9487. TTBCustomItem * Item = *i;
  9488. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9489. if (Label != NULL)
  9490. {
  9491. // optimization
  9492. if (Label->Visible == SelectiveToolbarText)
  9493. {
  9494. Result = false;
  9495. }
  9496. else
  9497. {
  9498. Label->Visible = SelectiveToolbarText;
  9499. }
  9500. }
  9501. else
  9502. {
  9503. // optimization
  9504. if (Item->DisplayMode == DisplayMode)
  9505. {
  9506. Result = false;
  9507. }
  9508. else
  9509. {
  9510. Item->DisplayMode = DisplayMode;
  9511. }
  9512. }
  9513. ++i;
  9514. }
  9515. if (Result)
  9516. {
  9517. UpdateNewSessionTab();
  9518. }
  9519. return Result;
  9520. }
  9521. //---------------------------------------------------------------------------
  9522. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9523. {
  9524. DebugFail();
  9525. }
  9526. //---------------------------------------------------------------------------
  9527. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9528. {
  9529. // Among other, a lock level is non zero, while directory is being loaded,
  9530. // even when it happens as a result of dirview navigation,
  9531. // i.e. when TNonVisualDataModule is NOT FBusy.
  9532. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9533. // Among other this prevents a panel auto update to occur while
  9534. // directory is changing.
  9535. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9536. }
  9537. //---------------------------------------------------------------------------
  9538. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9539. {
  9540. // While the window is disabled, we still seem to process menu shortcuts at least,
  9541. // so stop it at least here.
  9542. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9543. bool Result;
  9544. if (Allowed == aaUpdate)
  9545. {
  9546. Result = true;
  9547. }
  9548. else
  9549. {
  9550. Result = !NonVisualDataModule->Busy;
  9551. if (Result && (Allowed == aaShortCut))
  9552. {
  9553. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9554. Action->Update();
  9555. Result = Action->Enabled;
  9556. }
  9557. }
  9558. return Result;
  9559. }
  9560. //---------------------------------------------------------------------------
  9561. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9562. {
  9563. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9564. }
  9565. //---------------------------------------------------------------------------
  9566. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9567. {
  9568. // This is somewhat redundant to LockWindow() call from
  9569. // TTerminalManager::TerminalReadDirectoryProgress.
  9570. // But disabling window is known not to block keyboard shorcuts
  9571. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9572. if (Busy > 0)
  9573. {
  9574. if (NonVisualDataModule->Busy)
  9575. {
  9576. State = false;
  9577. }
  9578. else
  9579. {
  9580. NonVisualDataModule->StartBusy();
  9581. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9582. LockWindow();
  9583. }
  9584. }
  9585. else if (Busy < 0)
  9586. {
  9587. UnlockWindow();
  9588. NonVisualDataModule->EndBusy();
  9589. }
  9590. else
  9591. {
  9592. State = NonVisualDataModule->Busy;
  9593. }
  9594. }
  9595. //---------------------------------------------------------------------------
  9596. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9597. {
  9598. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9599. // no context menu for "New session tab"
  9600. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9601. {
  9602. SessionsPageControl->ActivePageIndex = Index;
  9603. if (DebugAlwaysTrue(SessionTabSwitched()))
  9604. {
  9605. // copied from TControl.WMContextMenu
  9606. SendCancelMode(SessionsPageControl);
  9607. // explicit popup instead of using PopupMenu property
  9608. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9609. // while connecting yet not-connected session and hence
  9610. // allowing an access to commands over not-completelly connected session
  9611. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9612. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9613. PopupMenu->PopupComponent = SessionsPageControl;
  9614. PopupMenu->Popup(Point.x, Point.y);
  9615. }
  9616. }
  9617. Handled = true;
  9618. }
  9619. //---------------------------------------------------------------------------
  9620. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9621. {
  9622. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9623. }
  9624. //---------------------------------------------------------------------------
  9625. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9626. {
  9627. Configuration->Usage->Inc(L"PasswordChanges");
  9628. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9629. ChangePasswordData->DisableAuthentationsExceptPassword();
  9630. ChangePasswordData->ChangePassword = true;
  9631. std::unique_ptr<TTerminal> ChangePasswordSession(
  9632. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9633. ChangePasswordSession->AutoReadDirectory = false;
  9634. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9635. {
  9636. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9637. }
  9638. else
  9639. {
  9640. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9641. }
  9642. }
  9643. //---------------------------------------------------------------------------
  9644. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9645. {
  9646. // No nice way to assert SSH2
  9647. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9648. }
  9649. //---------------------------------------------------------------------------
  9650. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9651. {
  9652. TOperationVisualizer OperationVisualizer;
  9653. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9654. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9655. }
  9656. //---------------------------------------------------------------------------
  9657. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9658. {
  9659. TForm::ChangeScale(M, D);
  9660. int APixelsPerInch = GetControlPixelsPerInch(this);
  9661. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9662. try
  9663. {
  9664. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9665. }
  9666. __finally
  9667. {
  9668. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9669. }
  9670. }
  9671. //---------------------------------------------------------------------------
  9672. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9673. {
  9674. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9675. }
  9676. //---------------------------------------------------------------------
  9677. class TPublicControl : public TControl
  9678. {
  9679. friend class TCustomScpExplorerForm;
  9680. };
  9681. //---------------------------------------------------------------------------
  9682. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9683. {
  9684. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9685. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9686. }
  9687. //---------------------------------------------------------------------------
  9688. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9689. {
  9690. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9691. OpenBookmark(Side, Bookmark);
  9692. }
  9693. //---------------------------------------------------------------------------
  9694. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9695. {
  9696. DoBookmarkClick(osLocal, Sender);
  9697. }
  9698. //---------------------------------------------------------------------------
  9699. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9700. {
  9701. DoBookmarkClick(osRemote, Sender);
  9702. }
  9703. //---------------------------------------------------------------------------
  9704. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9705. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9706. {
  9707. if (BookmarkList != NULL)
  9708. {
  9709. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9710. if (IsLocalBrowserMode())
  9711. {
  9712. Side = osLocal;
  9713. }
  9714. if (!WinConfiguration->UseLocationProfiles)
  9715. {
  9716. std::unique_ptr<TStringList> Directories(new TStringList());
  9717. Directories->CaseSensitive = (Side == osRemote);
  9718. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9719. {
  9720. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9721. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9722. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9723. {
  9724. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9725. Item->Caption = EscapeHotkey(Directory);
  9726. Item->ShortCut = Bookmark->ShortCut;
  9727. Item->OnClick = OnBookmarkClick;
  9728. Item->Tag = reinterpret_cast<int>(Bookmark);
  9729. Directories->Add(Directory);
  9730. Menu->Add(Item.release());
  9731. }
  9732. }
  9733. }
  9734. else
  9735. {
  9736. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9737. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9738. {
  9739. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9740. if (!Bookmark->Node.IsEmpty())
  9741. {
  9742. Folders->Add(Bookmark->Node);
  9743. }
  9744. }
  9745. for (int Index = 0; Index < Folders->Count; Index++)
  9746. {
  9747. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9748. Item->Caption = Folders->Strings[Index];
  9749. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9750. Folders->Objects[Index] = Item.get();
  9751. Menu->Add(Item.release());
  9752. }
  9753. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9754. {
  9755. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9756. TTBCustomItem * Parent;
  9757. if (!Bookmark->Node.IsEmpty())
  9758. {
  9759. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9760. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9761. }
  9762. else
  9763. {
  9764. Parent = Menu;
  9765. }
  9766. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9767. Item->Caption = Bookmark->Name;
  9768. Item->ShortCut = Bookmark->ShortCut;
  9769. Item->OnClick = OnBookmarkClick;
  9770. Item->Tag = reinterpret_cast<int>(Bookmark);
  9771. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9772. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9773. {
  9774. // No hint for location profiles that are actually mere "bookmarks"
  9775. }
  9776. else
  9777. {
  9778. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9779. UnicodeString LongHint;
  9780. if (!Bookmark->Local.IsEmpty())
  9781. {
  9782. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9783. }
  9784. if (!Bookmark->Remote.IsEmpty())
  9785. {
  9786. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9787. }
  9788. AddToList(Hint, LongHint, L"|");
  9789. Item->Hint = Hint;
  9790. }
  9791. Parent->Add(Item.release());
  9792. }
  9793. }
  9794. AddMenuSeparator(Menu);
  9795. }
  9796. }
  9797. //---------------------------------------------------------------------------
  9798. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9799. {
  9800. Menu->Clear();
  9801. std::unique_ptr<TTBCustomItem> Item;
  9802. Item.reset(new TTBXItem(Owner));
  9803. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9804. Item->Options = Item->Options << tboDefault;
  9805. Menu->Add(Item.release());
  9806. AddMenuSeparator(Menu);
  9807. if (Terminal != NULL)
  9808. {
  9809. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9810. }
  9811. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9812. Item.reset(new TTBXItem(Owner));
  9813. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9814. Menu->Add(Item.release());
  9815. }
  9816. //---------------------------------------------------------------------------
  9817. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9818. {
  9819. bool Result = true;
  9820. bool Remote = !IsSideLocalBrowser(Side);
  9821. try
  9822. {
  9823. if (Remote)
  9824. {
  9825. Terminal->ExceptionOnFail = true;
  9826. }
  9827. try
  9828. {
  9829. DirView(Side)->Path = Path;
  9830. }
  9831. __finally
  9832. {
  9833. if (Remote)
  9834. {
  9835. Terminal->ExceptionOnFail = false;
  9836. }
  9837. }
  9838. }
  9839. catch (Exception & E)
  9840. {
  9841. if (!Remote || Terminal->Active)
  9842. {
  9843. ShowExtendedExceptionEx(Terminal, &E);
  9844. Result = false;
  9845. }
  9846. else
  9847. {
  9848. throw;
  9849. }
  9850. }
  9851. return Result;
  9852. }
  9853. //---------------------------------------------------------------------------
  9854. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9855. {
  9856. // Make sure there some feedback even when loading tiny local folders
  9857. TInstantOperationVisualizer Visualizer;
  9858. DirView(Side)->ReloadDirectory();
  9859. }
  9860. //---------------------------------------------------------------------------
  9861. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9862. {
  9863. if (Index == SessionsPageControl->TabIndex)
  9864. {
  9865. CloseSession();
  9866. }
  9867. else
  9868. {
  9869. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9870. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9871. TTerminalManager * Manager = TTerminalManager::Instance();
  9872. if (!Terminal->Active)
  9873. {
  9874. Manager->FreeTerminal(Terminal);
  9875. }
  9876. else
  9877. {
  9878. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9879. if (CanCloseQueue(Queue))
  9880. {
  9881. Manager->FreeTerminal(Terminal);
  9882. }
  9883. }
  9884. }
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9888. {
  9889. CloseSessionTab(Index);
  9890. }
  9891. //---------------------------------------------------------------------------
  9892. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9893. {
  9894. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9895. {
  9896. TInstantOperationVisualizer Visualizer;
  9897. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9898. // before we create a new data object
  9899. ClipboardClear();
  9900. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9901. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9902. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9903. // Intermediate variable to WORKAROUND a crash in compiler
  9904. TObjectList * ClipboardFakeMonitors =
  9905. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9906. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9907. if (FClipboardDragDropFilesEx.get() == NULL)
  9908. {
  9909. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9910. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9911. }
  9912. FClipboardDragDropFilesEx->FileList->Clear();
  9913. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9914. FClipboardDragDropFilesEx->CopyToClipboard();
  9915. FClipboardTerminal = FTerminal;
  9916. // Need full paths, as cwd can be different once files are pasted
  9917. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9918. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9919. {
  9920. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9921. }
  9922. }
  9923. }
  9924. //---------------------------------------------------------------------------
  9925. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9926. {
  9927. if (OpenClipboard(0))
  9928. {
  9929. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9930. CloseClipboard();
  9931. }
  9932. }
  9933. //---------------------------------------------------------------------------
  9934. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9935. {
  9936. return !FClipboardFakeDirectory.IsEmpty();
  9937. }
  9938. //---------------------------------------------------------------------------
  9939. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9940. {
  9941. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9942. FClipboardFakeDirectory = UnicodeString();
  9943. FClipboardTerminal = NULL;
  9944. // Also called in Idle()
  9945. FClipboardFakeMonitors.reset(NULL);
  9946. }
  9947. //---------------------------------------------------------------------------
  9948. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9949. {
  9950. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9951. {
  9952. ClipboardStop();
  9953. }
  9954. }
  9955. //---------------------------------------------------------------------------
  9956. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9957. {
  9958. TTerminalManager * Manager = TTerminalManager::Instance();
  9959. Manager->ActiveTerminal = FClipboardTerminal;
  9960. TTransferOperationParam Params;
  9961. Params.TargetDirectory = TargetDirectory;
  9962. Params.DragDrop = DragDrop;
  9963. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9964. }
  9965. //---------------------------------------------------------------------------
  9966. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9967. {
  9968. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9969. // (as it pumps a Windows message queue while being shutted down)
  9970. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9971. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9972. {
  9973. // Can fail as it can be e.g. locked by AV, so we retry that later
  9974. bool Removed = RemoveDir(ApiPath(FileName));
  9975. try
  9976. {
  9977. if (!NonVisualDataModule->Busy)
  9978. {
  9979. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9980. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9981. }
  9982. }
  9983. __finally
  9984. {
  9985. if (!Removed)
  9986. {
  9987. RemoveDir(ApiPath(FileName));
  9988. }
  9989. }
  9990. }
  9991. }
  9992. //---------------------------------------------------------------------------
  9993. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9994. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9995. {
  9996. TFileMasks::TParams MaskParams;
  9997. MaskParams.Size = Size;
  9998. MaskParams.Modification = Modification;
  9999. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10000. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10001. {
  10002. bool ImplicitMatch;
  10003. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10004. !ImplicitMatch)
  10005. {
  10006. Color = Iter->Color;
  10007. break;
  10008. }
  10009. }
  10010. }
  10011. //---------------------------------------------------------------------------
  10012. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10013. {
  10014. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10015. if (!DirView->IsEditing())
  10016. {
  10017. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10018. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10019. // while searching
  10020. if (Key == VK_BACK)
  10021. {
  10022. if (!FIncrementalSearch.IsEmpty())
  10023. {
  10024. if (FIncrementalSearch.Length() == 1)
  10025. {
  10026. ResetIncrementalSearch();
  10027. }
  10028. else
  10029. {
  10030. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10031. IncrementalSearch(NewText, false, false);
  10032. }
  10033. Key = 0;
  10034. }
  10035. }
  10036. }
  10037. }
  10038. //---------------------------------------------------------------------------
  10039. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10040. {
  10041. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10042. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10043. {
  10044. // Filter control sequences.
  10045. // When not searching yet, prefer use of the space for toggling file selection
  10046. // (so we cannot incrementally search for a string starting with a space).
  10047. if ((Key > VK_SPACE) ||
  10048. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10049. {
  10050. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10051. Key = 0;
  10052. }
  10053. }
  10054. }
  10055. //---------------------------------------------------------------------------
  10056. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10057. {
  10058. if (!FIncrementalSearch.IsEmpty())
  10059. {
  10060. FIncrementalSearch = L"";
  10061. DirView(osCurrent)->UpdateStatusBar();
  10062. }
  10063. }
  10064. //---------------------------------------------------------------------------
  10065. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10066. {
  10067. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10068. if (Item == NULL)
  10069. {
  10070. MessageBeep(MB_ICONHAND);
  10071. }
  10072. else
  10073. {
  10074. TCustomDirView * ADirView = DirView(osCurrent);
  10075. {
  10076. TAutoNestingCounter Guard(FIncrementalSearching);
  10077. ADirView->FocusItem(Item);
  10078. if (ADirView->NortonLike == nlOff)
  10079. {
  10080. if ((ADirView->Selected != Item) ||
  10081. (ADirView->SelCount > 1))
  10082. {
  10083. ADirView->ClearSelection();
  10084. ADirView->Selected = Item;
  10085. }
  10086. }
  10087. }
  10088. FIncrementalSearch = Text;
  10089. Item->MakeVisible(false);
  10090. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10091. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10092. ADirView->UpdateStatusBar();
  10093. }
  10094. }
  10095. //---------------------------------------------------------------------------
  10096. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10097. {
  10098. int Index = Item->Index;
  10099. if (!Reverse)
  10100. {
  10101. Index++;
  10102. if (Index >= Item->Owner->Count)
  10103. {
  10104. Index = 0;
  10105. }
  10106. }
  10107. else
  10108. {
  10109. Index--;
  10110. if (Index < 0)
  10111. {
  10112. Index = Item->Owner->Count - 1;
  10113. }
  10114. }
  10115. return Item->Owner->Item[Index];
  10116. }
  10117. //---------------------------------------------------------------------------
  10118. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10119. {
  10120. TCustomDirView * ADirView = DirView(osCurrent);
  10121. if (ADirView->Items->Count == 0)
  10122. {
  10123. return NULL;
  10124. }
  10125. else
  10126. {
  10127. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10128. TListItem * Item = CurrentItem;
  10129. if (SkipCurrent)
  10130. {
  10131. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10132. }
  10133. while (true)
  10134. {
  10135. bool Matches = false;
  10136. switch (WinConfiguration->PanelSearch)
  10137. {
  10138. case isNameStartOnly:
  10139. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10140. break;
  10141. case isName:
  10142. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10143. break;
  10144. case isAll:
  10145. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10146. int Index = 0;
  10147. while ((Index < ColCount) && !Matches)
  10148. {
  10149. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10150. if (Visible)
  10151. {
  10152. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10153. }
  10154. Index++;
  10155. }
  10156. break;
  10157. }
  10158. if (Matches)
  10159. {
  10160. return Item;
  10161. }
  10162. Item = GetNextFile(Item, Reverse);
  10163. if (Item == CurrentItem)
  10164. {
  10165. return NULL;
  10166. }
  10167. }
  10168. }
  10169. }
  10170. //---------------------------------------------------------------------------
  10171. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10172. {
  10173. ResetIncrementalSearch();
  10174. }
  10175. //---------------------------------------------------------------------------
  10176. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10177. {
  10178. if (Message.CharCode == VK_TAB)
  10179. {
  10180. if (!FIncrementalSearch.IsEmpty())
  10181. {
  10182. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10183. bool Reverse = Shift.Contains(ssShift);
  10184. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10185. Message.Result = 1;
  10186. return;
  10187. }
  10188. }
  10189. else if (Message.CharCode == VK_ESCAPE)
  10190. {
  10191. if (!FIncrementalSearch.IsEmpty())
  10192. {
  10193. ResetIncrementalSearch();
  10194. Message.Result = 1;
  10195. return;
  10196. }
  10197. }
  10198. TForm::Dispatch(&Message);
  10199. }
  10200. //---------------------------------------------------------------------------
  10201. void __fastcall TCustomScpExplorerForm::Deactivate()
  10202. {
  10203. TForm::Deactivate();
  10204. // E.g. when switching to an internal editor window
  10205. ResetIncrementalSearch();
  10206. }
  10207. //---------------------------------------------------------------------------
  10208. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10209. {
  10210. // When switching to another application
  10211. ResetIncrementalSearch();
  10212. }
  10213. //---------------------------------------------------------------------------
  10214. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10215. {
  10216. ResetIncrementalSearch();
  10217. }
  10218. //---------------------------------------------------------------------------
  10219. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10220. {
  10221. if (FIncrementalSearching <= 0)
  10222. {
  10223. ResetIncrementalSearch();
  10224. }
  10225. }
  10226. //---------------------------------------------------------------------------
  10227. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10228. {
  10229. CountClicksForWindowPrint(this);
  10230. }
  10231. //---------------------------------------------------------------------------
  10232. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10233. {
  10234. CenterReconnectToolbar();
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10238. {
  10239. if (RemoteDirView->ItemFocused != NULL)
  10240. {
  10241. RemoteDirView->ItemFocused->Selected = true;
  10242. }
  10243. }
  10244. //---------------------------------------------------------------------------
  10245. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10246. {
  10247. if (!FQueueStatusUpdating)
  10248. {
  10249. bool Refresh;
  10250. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10251. {
  10252. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10253. }
  10254. else
  10255. {
  10256. if (FQueueFileList->GetCount() > 0)
  10257. {
  10258. FQueueFileList->Clear();
  10259. Refresh = true;
  10260. }
  10261. }
  10262. int Count = FQueueFileList->GetCount();
  10263. if (QueueFileList->Items->Count != Count)
  10264. {
  10265. DebugAssert(Refresh);
  10266. QueueFileList->Items->Count = Count;
  10267. }
  10268. if (Refresh)
  10269. {
  10270. QueueFileList->Invalidate();
  10271. }
  10272. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10273. }
  10274. }
  10275. //---------------------------------------------------------------------------
  10276. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10277. {
  10278. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10279. }
  10280. //---------------------------------------------------------------------------
  10281. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10282. {
  10283. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10284. // See TSynchronizeChecklistDialog::UpdateTimer
  10285. if (QueueFileList->Items->Count > 0)
  10286. {
  10287. QueueFileList->Items->Item[0]->MakeVisible(false);
  10288. }
  10289. UpdateQueueFileList();
  10290. }
  10291. //---------------------------------------------------------------------------
  10292. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10293. {
  10294. Active = QueueView3->Focused() || QueueFileList->Focused();
  10295. }
  10296. //---------------------------------------------------------------------------
  10297. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10298. {
  10299. QueueLabelUpdateStatus();
  10300. }
  10301. //---------------------------------------------------------------------------
  10302. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10303. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10304. {
  10305. int State = FQueueFileList->GetState(Item->Index);
  10306. if (State == qfsProcessed)
  10307. {
  10308. Sender->Canvas->Font->Color = clGrayText;
  10309. }
  10310. }
  10311. //---------------------------------------------------------------------------
  10312. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10313. {
  10314. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10315. QueueFileList->Column[0]->Width =
  10316. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10317. }
  10318. //---------------------------------------------------------------------------
  10319. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10320. {
  10321. QueueFileListColumnAutoSize();
  10322. }
  10323. //---------------------------------------------------------------------------
  10324. void __fastcall TCustomScpExplorerForm::CloseApp()
  10325. {
  10326. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10327. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10328. // So we clear the flag here.
  10329. DebugAssert(NonVisualDataModule->Busy);
  10330. NonVisualDataModule->EndBusy();
  10331. try
  10332. {
  10333. Close();
  10334. }
  10335. __finally
  10336. {
  10337. NonVisualDataModule->StartBusy();
  10338. }
  10339. }
  10340. //---------------------------------------------------------------------------
  10341. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10342. {
  10343. return (Terminal != NULL) && Terminal->Active;
  10344. }
  10345. //---------------------------------------------------------------------------
  10346. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10347. {
  10348. return IsActiveTerminal(Terminal);
  10349. }
  10350. //---------------------------------------------------------------------------
  10351. void TCustomScpExplorerForm::LocalLocalCopy(TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused))
  10352. {
  10353. DebugFail();
  10354. }