CustomScpExplorer.cpp 365 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079
  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 = 3;
  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. ManagedSession = 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 SessionListChanged => ... => 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->Sessions[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->ActiveSession = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  473. {
  474. TManagedTerminal * Result;
  475. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  476. {
  477. Result = FManagedSession;
  478. }
  479. else
  480. {
  481. Result = NULL;
  482. }
  483. return Result;
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  487. {
  488. if (FManagedSession != value)
  489. {
  490. TerminalChanging();
  491. DoSetManagedSession(value, false);
  492. }
  493. }
  494. //---------------------------------------------------------------------------
  495. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  496. {
  497. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  498. FManagedSession = value;
  499. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  500. FAllowTransferPresetAutoSelect = false;
  501. try
  502. {
  503. TerminalChanged(Replace);
  504. }
  505. __finally
  506. {
  507. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  508. }
  509. if (Terminal != NULL)
  510. {
  511. TransferPresetAutoSelect();
  512. }
  513. }
  514. //---------------------------------------------------------------------------
  515. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  516. {
  517. DoSetManagedSession(value, true);
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  521. {
  522. if (ManagedSession != NULL)
  523. {
  524. UpdateTerminal(ManagedSession);
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  529. {
  530. if (Terminal != NULL)
  531. {
  532. UpdateSessionColor((TColor)Terminal->StateData->Color);
  533. }
  534. SessionListChanged();
  535. if (Terminal != NULL)
  536. {
  537. if (Replaced)
  538. {
  539. RemoteDirView->ReplaceTerminal(Terminal);
  540. }
  541. else
  542. {
  543. RemoteDirView->Terminal = Terminal;
  544. }
  545. if (Terminal->Active)
  546. {
  547. Terminal->RefreshDirectory();
  548. }
  549. if (WinConfiguration->PreservePanelState)
  550. {
  551. if (Terminal->RemoteExplorerState != NULL)
  552. {
  553. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  554. }
  555. else
  556. {
  557. DirView(osRemote)->ClearState();
  558. }
  559. }
  560. }
  561. InitStatusBar();
  562. UpdateTransferList();
  563. // Update panels Enable state before refreshing the labels
  564. UpdateControls();
  565. }
  566. //---------------------------------------------------------------------------
  567. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  568. {
  569. if (Queue != value)
  570. {
  571. if (FQueue != NULL)
  572. {
  573. FQueue->OnListUpdate = NULL;
  574. FQueue->OnQueueItemUpdate = NULL;
  575. }
  576. FQueue = value;
  577. if (FQueue != NULL)
  578. {
  579. DebugAssert(FQueue->OnListUpdate == NULL);
  580. FQueue->OnListUpdate = QueueListUpdate;
  581. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  582. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  583. }
  584. QueueChanged();
  585. }
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  589. TListItem * Item)
  590. {
  591. if (FQueueActedItem == Item)
  592. {
  593. FQueueActedItem = NULL;
  594. if ((QueueView3->PopupMenu != NULL) &&
  595. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  596. {
  597. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  598. ReleaseCapture();
  599. }
  600. }
  601. if (Item->Data == FPendingQueueActionItem)
  602. {
  603. FPendingQueueActionItem = NULL;
  604. }
  605. }
  606. //---------------------------------------------------------------------------
  607. bool TCustomScpExplorerForm::IsAnythingQueued()
  608. {
  609. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  610. }
  611. //---------------------------------------------------------------------------
  612. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  613. {
  614. {
  615. TGuard Guard(FQueueStatusSection);
  616. FQueueStatusInvalidated = false;
  617. if (FQueue != NULL)
  618. {
  619. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  620. }
  621. }
  622. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  623. {
  624. FMaxQueueLength = FQueueStatus->Count;
  625. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  626. }
  627. {
  628. TAutoFlag Flag(FQueueStatusUpdating);
  629. FQueueController->UpdateQueueStatus(FQueueStatus);
  630. }
  631. UpdateQueueFileList();
  632. SetQueueProgress();
  633. UpdateQueueView();
  634. bool IsEmpty = !IsAnythingQueued();
  635. if (IsEmpty && (Terminal != NULL))
  636. {
  637. TOnceDoneOperation OnceDoneOperation =
  638. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  639. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  640. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  641. {
  642. FQueue->Enabled = false;
  643. }
  644. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  645. {
  646. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  647. }
  648. }
  649. }
  650. //---------------------------------------------------------------------------
  651. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  652. {
  653. UnicodeString Result;
  654. if (FQueueStatus != NULL)
  655. {
  656. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  657. {
  658. TFileOperationProgressType * ProgressData =
  659. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  660. if ((ProgressData != NULL) && ProgressData->InProgress)
  661. {
  662. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  663. }
  664. }
  665. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  666. {
  667. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  668. }
  669. }
  670. return Result;
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  674. {
  675. ComponentVisible[fcQueueView] =
  676. (WinConfiguration->QueueView.Show == qvShow) ||
  677. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  678. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  679. }
  680. //---------------------------------------------------------------------------
  681. void __fastcall TCustomScpExplorerForm::QueueChanged()
  682. {
  683. if (FQueueStatus != NULL)
  684. {
  685. // UpdateFileList implementation relies on the status being recreated when session changes
  686. delete FQueueStatus;
  687. FQueueStatus = NULL;
  688. }
  689. UpdateQueueStatus(true);
  690. }
  691. //---------------------------------------------------------------------------
  692. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  693. {
  694. if (FQueue == Queue)
  695. {
  696. FQueueStatusInvalidated = true;
  697. }
  698. }
  699. //---------------------------------------------------------------------------
  700. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  701. TQueueItem * Item)
  702. {
  703. if (FQueue == Queue)
  704. {
  705. TGuard Guard(FQueueStatusSection);
  706. // this may be running in parallel with QueueChanged
  707. if (FQueueStatus != NULL)
  708. {
  709. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  710. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  711. {
  712. FRefreshLocalDirectory = (QueueItem == NULL) ||
  713. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  714. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  715. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  716. }
  717. if (QueueItem != NULL)
  718. {
  719. QueueItem->UserData = (void*)true;
  720. FQueueItemInvalidated = true;
  721. }
  722. }
  723. }
  724. }
  725. //---------------------------------------------------------------------------
  726. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  727. {
  728. // during standalone editing, we have no way to see/control queue,
  729. // so we have to always popup prompts automatically
  730. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  734. {
  735. if (FQueueStatus != NULL)
  736. {
  737. bool QueueAutoPopup = IsQueueAutoPopup();
  738. bool NeedRefresh = FQueueController->NeedRefresh();
  739. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  740. FQueueItemInvalidated = false;
  741. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  742. bool Updated = false;
  743. TQueueItemProxy * QueueItem;
  744. bool WasUserAction;
  745. for (int Index = 0; Index < Limit; Index++)
  746. {
  747. bool Update = false;
  748. QueueItem = FQueueStatus->Items[Index];
  749. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  750. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  751. (FPendingQueueActionItem == NULL))
  752. {
  753. FPendingQueueActionItem = QueueItem;
  754. FUserActionTimer->Enabled = true;
  755. }
  756. if ((bool)QueueItem->UserData)
  757. {
  758. QueueItem->UserData = (void*)false;
  759. QueueItem->Update();
  760. Updated = true;
  761. Update = true;
  762. }
  763. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  764. {
  765. Update = true;
  766. }
  767. if (Update)
  768. {
  769. FQueueController->RefreshQueueItem(QueueItem);
  770. }
  771. }
  772. if (Updated)
  773. {
  774. NonVisualDataModule->UpdateNonVisibleActions();
  775. SetQueueProgress();
  776. UpdateQueueFileList();
  777. }
  778. }
  779. }
  780. //---------------------------------------------------------------------------
  781. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  782. {
  783. if (FTaskbarList != NULL)
  784. {
  785. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  786. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  787. }
  788. }
  789. //---------------------------------------------------------------------------
  790. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  791. {
  792. if (Progress >= 0)
  793. {
  794. if (FTaskbarList != NULL)
  795. {
  796. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  797. }
  798. }
  799. else
  800. {
  801. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  802. }
  803. }
  804. //---------------------------------------------------------------------------
  805. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  806. {
  807. int OverallProgress;
  808. // FProgressForm is null when this is called from SetQueueProgress
  809. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  810. {
  811. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  812. }
  813. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  814. {
  815. OverallProgress = ProgressData->OverallProgress();
  816. }
  817. else
  818. {
  819. OverallProgress = -1;
  820. }
  821. SetTaskbarListProgressValue(OverallProgress);
  822. }
  823. //---------------------------------------------------------------------------
  824. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  825. {
  826. TTerminalManager::Instance()->QueueStatusUpdated();
  827. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  828. {
  829. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  830. {
  831. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  832. {
  833. TFileOperationProgressType * ProgressData = NULL;
  834. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  835. {
  836. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  837. }
  838. if ((ProgressData != NULL) &&
  839. ProgressData->InProgress)
  840. {
  841. SetTaskbarListProgressValue(ProgressData);
  842. }
  843. else
  844. {
  845. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  846. }
  847. }
  848. else
  849. {
  850. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  851. }
  852. }
  853. else
  854. {
  855. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  856. }
  857. }
  858. UpdateQueueLabel();
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  862. {
  863. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  864. if (FQueueStatus != NULL)
  865. {
  866. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  867. if (ActiveAndPendingPrimaryCount > 0)
  868. {
  869. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  870. }
  871. }
  872. QueueLabel->Caption = Caption;
  873. }
  874. //---------------------------------------------------------------------------
  875. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  876. {
  877. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  878. static_cast<TComponent*>(GetComponent(fcTransferList)));
  879. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  880. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  881. TransferList->Strings->BeginUpdate();
  882. try
  883. {
  884. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  885. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  886. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  887. if (FTransferDropDownHint.IsEmpty())
  888. {
  889. FTransferDropDownHint = TransferDropDown->Hint;
  890. }
  891. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  892. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  893. TransferDropDown->Text = StripHotkey(Name);
  894. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  895. (FTransferDropDownHint, StripHotkey(Name),
  896. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  897. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  898. // update the label, otherwise when it is updated only on the first draw
  899. // of the list, it is drawn "bold" for some reason
  900. FTransferListHoverIndex = TransferList->ItemIndex;
  901. UpdateTransferLabel();
  902. }
  903. __finally
  904. {
  905. TransferList->Strings->EndUpdate();
  906. }
  907. }
  908. //---------------------------------------------------------------------------
  909. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  910. {
  911. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  912. DebugAssert(Toolbar != NULL);
  913. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  914. }
  915. //---------------------------------------------------------------------------
  916. void __fastcall TCustomScpExplorerForm::UpdateActions()
  917. {
  918. TForm::UpdateActions();
  919. if (ComponentVisible[fcCustomCommandsBand])
  920. {
  921. UpdateCustomCommandsToolbar();
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  926. {
  927. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  931. {
  932. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  933. {
  934. DirView->RowSelect = WinConfiguration->FullRowSelect;
  935. // selection is not redrawn automatically when RowSelect changes
  936. DirView->Invalidate();
  937. }
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  941. {
  942. Color = GetBtnFaceColor();
  943. DebugAssert(Configuration && RemoteDirView);
  944. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  945. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  946. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  947. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  948. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  949. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  950. UpdateRowSelect(RemoteDirView);
  951. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  952. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  953. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  954. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  955. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  956. UpdateSessionsPageControlHeight();
  957. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  958. UpdateToolbarDisplayMode();
  959. UpdateTransferList();
  960. if (Terminal != NULL)
  961. {
  962. TransferPresetAutoSelect();
  963. }
  964. UpdateQueueView();
  965. UpdateControls();
  966. // this can be called even before constuctor finishes.
  967. if (FEditorManager != NULL)
  968. {
  969. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  970. }
  971. // this can be called even before constuctor finishes.
  972. if (FLocalEditors != NULL)
  973. {
  974. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  975. {
  976. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  977. }
  978. }
  979. if (ComponentVisible[fcCustomCommandsBand])
  980. {
  981. UpdateCustomCommandsToolbar();
  982. }
  983. // show only when keeping queue items forever,
  984. // otherwise, its enough to have in in the context menu
  985. QueueDeleteAllDoneQueueToolbarItem->Visible =
  986. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  987. if (FFileColorsCurrent != WinConfiguration->FileColors)
  988. {
  989. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  990. FFileColorsCurrent = WinConfiguration->FileColors;
  991. FileColorsChanged();
  992. }
  993. }
  994. //---------------------------------------------------------------------------
  995. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  996. {
  997. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  998. DirView->Invalidate();
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1002. {
  1003. DoFileColorsChanged(RemoteDirView);
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1007. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1008. void * /*Arg*/)
  1009. {
  1010. if (Token != NULL)
  1011. {
  1012. TForm * Editor = dynamic_cast<TForm*>(Token);
  1013. DebugAssert(Editor != NULL);
  1014. ReconfigureEditorForm(Editor);
  1015. }
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1019. {
  1020. WinConfiguration->DDTransferConfirmation = asOn;
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1024. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1025. {
  1026. // noop
  1027. }
  1028. //---------------------------------------------------------------------------
  1029. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1030. {
  1031. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1035. {
  1036. if (DoNotShowAgain)
  1037. {
  1038. if (DragDrop)
  1039. {
  1040. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1041. {
  1042. PopupTrayBalloon(
  1043. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1044. }
  1045. WinConfiguration->DDTransferConfirmation = asOff;
  1046. }
  1047. else
  1048. {
  1049. WinConfiguration->ConfirmTransferring = false;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. // User explicitly unchecked "do not show again",
  1055. // so show him the dialog the next time
  1056. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1057. {
  1058. WinConfiguration->DDTransferConfirmation = asOn;
  1059. }
  1060. }
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1064. TTransferDirection Direction, TTransferType Type, bool Temp,
  1065. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1066. bool Confirm, bool DragDrop, int Options)
  1067. {
  1068. bool Result = true;
  1069. DebugAssert(HasActiveTerminal());
  1070. // these parameters are known in advance
  1071. int Params =
  1072. FLAGMASK(Type == ttMove, cpDelete);
  1073. bool ToTemp = (Temp && (Direction == tdToLocal));
  1074. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1075. {
  1076. bool DisableNewerOnly =
  1077. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1078. ToTemp;
  1079. Options |=
  1080. FLAGMASK(ToTemp, coTemp) |
  1081. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1082. coDoNotShowAgain;
  1083. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1084. int CopyParamAttrs = (Direction == tdToRemote ?
  1085. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1086. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1087. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1088. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1089. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1090. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1091. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1092. if (Result)
  1093. {
  1094. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1095. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1096. }
  1097. }
  1098. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1099. {
  1100. Configuration->Usage->Inc(L"TransfersOnBackground");
  1101. // these parameter are known only after transfer dialog
  1102. Params |=
  1103. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1104. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1105. Result = false;
  1106. ClearTransferSourceSelection(Direction);
  1107. }
  1108. return Result;
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1112. {
  1113. if (FOnFileOperationFinished != NULL)
  1114. {
  1115. FOnFileOperationFinished(UnicodeString(), true);
  1116. }
  1117. else
  1118. {
  1119. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1120. if (HasDirView[Side])
  1121. {
  1122. DirView(Side)->SelectAll(smNone);
  1123. }
  1124. }
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1128. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1129. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1130. int Params)
  1131. {
  1132. DebugAssert(Queue != NULL);
  1133. bool SingleFile = false;
  1134. if (FileList->Count == 1)
  1135. {
  1136. if (Direction == tdToRemote)
  1137. {
  1138. UnicodeString FileName = FileList->Strings[0];
  1139. SingleFile = FileExists(ApiPath(FileName));
  1140. }
  1141. else
  1142. {
  1143. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1144. SingleFile = !File->IsDirectory;
  1145. }
  1146. }
  1147. TQueueItem * QueueItem;
  1148. if (Direction == tdToRemote)
  1149. {
  1150. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1151. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1152. }
  1153. else
  1154. {
  1155. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1156. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1157. }
  1158. AddQueueItem(Queue, QueueItem, Terminal);
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1162. {
  1163. if (Queue->IsEmpty)
  1164. {
  1165. Terminal->QueueOperationStart = Now();
  1166. }
  1167. Queue->AddItem(QueueItem);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1171. {
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TCustomScpExplorerForm::InitControls()
  1175. {
  1176. DebugAssert(FDocks != NULL);
  1177. for (int Index = 0; Index < ComponentCount; Index++)
  1178. {
  1179. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1180. if ((Dock != NULL) && (Dock->Tag == 0))
  1181. {
  1182. FDocks->Add(Dock);
  1183. }
  1184. }
  1185. CollectItemsWithTextDisplayMode(this);
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1189. {
  1190. ConfigurationChanged();
  1191. QueuePanel->Height =
  1192. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1193. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1194. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1195. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1196. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1197. QueueFileList->Height =
  1198. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1199. if (QueueFileList->Visible)
  1200. {
  1201. AdjustQueueLayout();
  1202. }
  1203. UpdateCustomCommandsToolbar();
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TCustomScpExplorerForm::StoreParams()
  1207. {
  1208. int APixelsPerInch = GetControlPixelsPerInch(this);
  1209. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1210. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1211. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1212. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1213. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1214. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1215. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1216. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1217. }
  1218. //---------------------------------------------------------------------------
  1219. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1220. {
  1221. if (!FFormRestored)
  1222. {
  1223. FFormRestored = true;
  1224. RestoreFormParams();
  1225. }
  1226. TForm::CreateParams(Params);
  1227. }
  1228. //---------------------------------------------------------------------------
  1229. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1230. {
  1231. DebugAssert(FDocks != NULL);
  1232. for (int Index = 0; Index < FDocks->Count; Index++)
  1233. {
  1234. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1235. }
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1239. {
  1240. SetDockAllowDrag(true);
  1241. while (!ButtonsStr.IsEmpty())
  1242. {
  1243. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1244. UnicodeString Name = CutToChar(S, L'=', true);
  1245. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1246. {
  1247. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1248. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1249. {
  1250. while (!S.IsEmpty())
  1251. {
  1252. UnicodeString S2 = CutToChar(S, L',', true);
  1253. UnicodeString Name = CutToChar(S2, L':', true);
  1254. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1255. {
  1256. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1257. if (SameText(GetToolbarItemName(Item), Name))
  1258. {
  1259. // forward compatibility
  1260. UnicodeString S3 = CutToChar(S2, L':', true);
  1261. bool Visible = StrToIntDef(S3, 0);
  1262. Item->Visible = Visible;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1270. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1274. {
  1275. UnicodeString Result;
  1276. SetDockAllowDrag(true);
  1277. Result = ::GetToolbarsLayoutStr(this);
  1278. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1283. {
  1284. UnicodeString Result;
  1285. if (Item->Action != NULL)
  1286. {
  1287. Result = Item->Action->Name;
  1288. Result = RemoveSuffix(Result, L"Action", true);
  1289. }
  1290. else
  1291. {
  1292. Result = Item->Name;
  1293. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1294. Result = RemoveSuffix(Result, L"Item", true);
  1295. }
  1296. return Result;
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1300. {
  1301. UnicodeString Result;
  1302. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1303. {
  1304. UnicodeString ToolbarStr;
  1305. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1306. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1307. {
  1308. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1309. {
  1310. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1311. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1312. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1313. // and save the changes here only.
  1314. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1315. {
  1316. UnicodeString Name = GetToolbarItemName(Item);
  1317. DebugAssert(Name.Pos(L"TBX") == 0);
  1318. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1319. }
  1320. }
  1321. }
  1322. if (!ToolbarStr.IsEmpty())
  1323. {
  1324. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1325. }
  1326. }
  1327. return Result;
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1331. {
  1332. DebugAssert(FProgressForm == NULL);
  1333. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1334. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1335. FProgressForm->DeleteLocalToRecycleBin =
  1336. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1337. FProgressForm->DeleteRemoteToRecycleBin =
  1338. (Terminal != NULL) &&
  1339. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1340. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1341. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1342. LockWindow();
  1343. // Actually, do not know what hides the progress once the operation finishes
  1344. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1345. SetTaskbarListProgressState(TBPF_NORMAL);
  1346. }
  1347. //---------------------------------------------------------------------------
  1348. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1349. {
  1350. UnlockWindow();
  1351. SAFE_DESTROY(FProgressForm);
  1352. SetQueueProgress();
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1356. TFileOperationProgressType & ProgressData)
  1357. {
  1358. // Download to temporary local directory
  1359. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1360. {
  1361. bool Continue = true;
  1362. FPendingTempSpaceWarn = false;
  1363. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1364. if (!Continue)
  1365. {
  1366. Abort();
  1367. }
  1368. }
  1369. // operation is being executed and we still didn't show up progress form
  1370. if (ProgressData.InProgress && !FProgressForm)
  1371. {
  1372. CreateProgressForm(NULL);
  1373. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1374. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1375. }
  1376. // operation is finished (or terminated), so we hide progress form
  1377. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1378. {
  1379. DestroyProgressForm();
  1380. if (ProgressData.Operation == foCalculateSize)
  1381. {
  1382. // When calculating size before transfer, the abort caused by
  1383. // cancel flag set due to "MoveToQueue" below,
  1384. // is not propagated back to us in ExecuteFileOperation,
  1385. // as it is silently swallowed.
  1386. // So we explicitly (re)throw it here.
  1387. if (FMoveToQueue)
  1388. {
  1389. Abort();
  1390. }
  1391. }
  1392. else
  1393. {
  1394. if ((ProgressData.Cancel == csContinue) &&
  1395. !FAutoOperation)
  1396. {
  1397. OperationComplete(ProgressData.StartTime);
  1398. }
  1399. }
  1400. }
  1401. if (FProgressForm &&
  1402. // Can happen only during synchronization, when ending one of the operations
  1403. ProgressData.InProgress)
  1404. {
  1405. FProgressForm->SetProgressData(ProgressData);
  1406. DebugAssert(ProgressData.InProgress);
  1407. SetTaskbarListProgressValue(&ProgressData);
  1408. if (FProgressForm->Cancel > csContinue)
  1409. {
  1410. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1411. if (FProgressForm->Cancel == csCancelFile)
  1412. {
  1413. FProgressForm->ClearCancel();
  1414. }
  1415. // cancel cancels even the move
  1416. FMoveToQueue = false;
  1417. }
  1418. else if (FProgressForm->MoveToQueue)
  1419. {
  1420. FMoveToQueue = true;
  1421. ProgressData.SetCancelAtLeast(csCancel);
  1422. }
  1423. if ((FTransferResumeList != NULL) &&
  1424. ProgressData.InProgress &&
  1425. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1426. !ProgressData.FullFileName.IsEmpty())
  1427. {
  1428. if ((FTransferResumeList->Count == 0) ||
  1429. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1430. {
  1431. // note that we do not recognize directories from files here
  1432. FTransferResumeList->Add(ProgressData.FullFileName);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1439. const TDateTime & StartTime)
  1440. {
  1441. if (GUIConfiguration->BeepOnFinish &&
  1442. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1443. {
  1444. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1445. DWORD Sound;
  1446. if (!ExtractFileExt(BeepSound).IsEmpty())
  1447. {
  1448. Sound = SND_FILENAME;
  1449. }
  1450. else
  1451. {
  1452. Sound = SND_ALIAS;
  1453. }
  1454. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1455. }
  1456. }
  1457. //---------------------------------------------------------------------------
  1458. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1459. TFileOperationProgressType & ProgressData)
  1460. {
  1461. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1462. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1463. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1464. FileOperationProgress(ProgressData);
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1468. {
  1469. UnicodeString Result;
  1470. if (FProgressForm != NULL)
  1471. {
  1472. Result = FProgressForm->ProgressStr();
  1473. }
  1474. return Result;
  1475. }
  1476. //---------------------------------------------------------------------------
  1477. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1478. bool DragDrop)
  1479. {
  1480. return (!DragDrop && (DropSourceControl == NULL)) ||
  1481. (DropSourceControl == DirView(osOther));
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1485. TFileOperation Operation, TOperationSide Side,
  1486. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1487. TOnceDoneOperation & OnceDoneOperation)
  1488. {
  1489. if (!FAutoOperation)
  1490. {
  1491. // no selection on "/upload", form serves only as event handler
  1492. // (it is not displayed)
  1493. if (PanelOperation(Side, FDragDropOperation) &&
  1494. Visible && (Operation != foCalculateSize) &&
  1495. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1496. {
  1497. if (FOnFileOperationFinished != NULL)
  1498. {
  1499. FOnFileOperationFinished(FileName, Success);
  1500. }
  1501. else
  1502. {
  1503. TOperationSide DViewSide;
  1504. if ((FProgressSide != osCurrent) &&
  1505. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1506. {
  1507. // assume the operation is over the focused panel
  1508. DViewSide = FProgressSide;
  1509. }
  1510. else
  1511. {
  1512. DViewSide = Side;
  1513. }
  1514. TCustomDirView * DView = DirView(DViewSide);
  1515. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1516. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1517. // this can happen when local drive is unplugged in the middle of the operation
  1518. if (Item != NULL)
  1519. {
  1520. if (Success) Item->Selected = false;
  1521. DView->MakeProgressVisible(Item);
  1522. }
  1523. }
  1524. }
  1525. if ((Operation == foCopy) || (Operation == foMove))
  1526. {
  1527. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1528. {
  1529. if (Side == osLocal)
  1530. {
  1531. Configuration->Usage->Inc(L"UploadedFiles");
  1532. }
  1533. else
  1534. {
  1535. Configuration->Usage->Inc(L"DownloadedFiles");
  1536. }
  1537. }
  1538. }
  1539. }
  1540. if (Success && (FSynchronizeController != NULL))
  1541. {
  1542. DebugAssert(!IsSideLocalBrowser(osRemote));
  1543. if (Operation == foCopy)
  1544. {
  1545. DebugAssert(Side == osLocal);
  1546. FSynchronizeController->LogOperation(soUpload, FileName);
  1547. }
  1548. else if (Operation == foDelete)
  1549. {
  1550. DebugAssert(Side == osRemote);
  1551. FSynchronizeController->LogOperation(soDelete, FileName);
  1552. }
  1553. }
  1554. if (FProgressForm)
  1555. {
  1556. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1557. }
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1561. TFileOperation Operation, TOperationSide Side,
  1562. bool Temp, const UnicodeString & FileName, Boolean Success,
  1563. TOnceDoneOperation & OnceDoneOperation)
  1564. {
  1565. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1566. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1567. OnceDoneOperation);
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1571. {
  1572. return false;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1576. {
  1577. return false;
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1581. {
  1582. return NULL;
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1586. {
  1587. DebugAssert(GetSide(Side) == osRemote);
  1588. DebugUsedParam(Side);
  1589. return RemoteDirView;
  1590. }
  1591. //---------------------------------------------------------------------------
  1592. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1593. {
  1594. DebugAssert(GetSide(Side) == osRemote);
  1595. DebugUsedParam(Side);
  1596. return RemoteDriveView;
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1600. {
  1601. DebugAssert(GetSide(Side) == osRemote);
  1602. DebugUsedParam(Side);
  1603. return HasActiveTerminal();
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1607. TOperationSide Side, int FilesOnly)
  1608. {
  1609. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1610. }
  1611. //---------------------------------------------------------------------------
  1612. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1613. TOperationSide Side, int FilesOnly)
  1614. {
  1615. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. struct THistoryItemData
  1619. {
  1620. short int Side;
  1621. short int Index;
  1622. };
  1623. //---------------------------------------------------------------------------
  1624. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1625. {
  1626. DirView(Side)->HistoryGo(Index);
  1627. }
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1630. {
  1631. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1632. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1633. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1637. bool Back)
  1638. {
  1639. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1640. {
  1641. TCustomDirView * DView = DirView(Side);
  1642. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1643. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1644. if (ICount > 10)
  1645. {
  1646. ICount = 10;
  1647. }
  1648. Menu->Items->Clear();
  1649. THistoryItemData Data;
  1650. Data.Side = Side;
  1651. for (short int i = 1; i <= ICount; i++)
  1652. {
  1653. TTBCustomItem * Item = new TTBXItem(Menu);
  1654. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1655. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1656. Item->Hint = DView->HistoryPath[Data.Index];
  1657. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1658. Item->Tag = *reinterpret_cast<int*>(&Data);
  1659. Item->OnClick = HistoryItemClick;
  1660. Menu->Items->Add(Item);
  1661. }
  1662. }
  1663. }
  1664. //---------------------------------------------------------------------------
  1665. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1666. TOperationSide Side, bool Back)
  1667. {
  1668. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1669. {
  1670. // workaround
  1671. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1672. // operator new allocates memory in Pascal code, but calls inline
  1673. // contructor in C++, leading in problems, the function does
  1674. // both in Pascal code
  1675. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1676. UpdateHistoryMenu(Side, Back);
  1677. }
  1678. return FHistoryMenu[Side == osLocal][Back];
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1682. TCustomDirView *Sender)
  1683. {
  1684. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1685. UpdateHistoryMenu(Side, true);
  1686. UpdateHistoryMenu(Side, false);
  1687. }
  1688. //---------------------------------------------------------------------------
  1689. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1690. {
  1691. // remote custom commands can be executed only if the server supports shell commands
  1692. // or have secondary shell
  1693. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1694. }
  1695. //---------------------------------------------------------------------------
  1696. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1697. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1698. {
  1699. // -1 = hidden, 0 = disabled, 1 = enabled
  1700. int Result;
  1701. TFileCustomCommand RemoteCustomCommand;
  1702. TLocalCustomCommand LocalCustomCommand;
  1703. TFileCustomCommand * NonInteractiveCustomCommand =
  1704. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1705. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1706. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1707. if (FLAGCLEAR(Command.Params, ccLocal))
  1708. {
  1709. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1710. // custom command that does not operate with files can be executed anytime ...
  1711. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1712. {
  1713. // ... but do not show such command in remote file menu
  1714. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1715. {
  1716. Result = AllowedState;
  1717. }
  1718. else
  1719. {
  1720. Result = -1;
  1721. }
  1722. }
  1723. else
  1724. {
  1725. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1726. {
  1727. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1728. }
  1729. else
  1730. {
  1731. Result = -1;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. // custom command that does not operate with files can be executed anytime
  1738. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1739. {
  1740. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1741. }
  1742. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1743. {
  1744. if ((ListType == ccltAll) || (ListType == ccltFile))
  1745. {
  1746. // special case is "diff"-style command that can be executed over any side,
  1747. // if we have both sides
  1748. Result =
  1749. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1750. // directly (instead of EnableSelectedOperation) to pass
  1751. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1752. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1753. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1754. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1755. }
  1756. else if (ListType == ccltBoth)
  1757. {
  1758. DebugAssert(!IsLocalBrowserMode());
  1759. Result = 1;
  1760. }
  1761. else
  1762. {
  1763. Result = -1;
  1764. }
  1765. }
  1766. else
  1767. {
  1768. if ((ListType == ccltAll) ||
  1769. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1770. {
  1771. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1772. }
  1773. else
  1774. {
  1775. Result = -1;
  1776. }
  1777. }
  1778. if ((Result > 0) &&
  1779. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1780. !HasActiveTerminal())
  1781. {
  1782. Result = 0;
  1783. }
  1784. }
  1785. return Result;
  1786. }
  1787. //---------------------------------------------------------------------------
  1788. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1789. TStrings * FileList, const TCustomCommandType & ACommand,
  1790. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1791. {
  1792. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1793. {
  1794. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1795. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1796. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1797. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1798. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1799. bool Capture =
  1800. FLAGSET(ACommand.Params, ccShowResults) ||
  1801. FLAGSET(ACommand.Params, ccCopyResults) ||
  1802. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1803. TCaptureOutputEvent OutputEvent = NULL;
  1804. DebugAssert(FCapturedLog == NULL);
  1805. if (Capture)
  1806. {
  1807. FCapturedLog = new TStringList();
  1808. OutputEvent = TerminalCaptureLog;
  1809. }
  1810. try
  1811. {
  1812. if (!RemoteCustomCommand.IsFileCommand(Command))
  1813. {
  1814. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1815. OutputEvent);
  1816. }
  1817. else
  1818. {
  1819. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1820. }
  1821. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1822. {
  1823. if (FLAGSET(ACommand.Params, ccCopyResults))
  1824. {
  1825. CopyToClipboard(FCapturedLog);
  1826. }
  1827. if (FLAGSET(ACommand.Params, ccShowResults))
  1828. {
  1829. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1830. }
  1831. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1832. {
  1833. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1834. }
  1835. }
  1836. }
  1837. __finally
  1838. {
  1839. SAFE_DESTROY(FCapturedLog);
  1840. }
  1841. }
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1845. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1846. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1847. {
  1848. DebugAssert(!IsLocalBrowserMode());
  1849. TStrings * LocalFileList = NULL;
  1850. TStrings * RemoteFileList = NULL;
  1851. TStrings * RemoteFileListFull = NULL;
  1852. try
  1853. {
  1854. if (LocalFileCommand)
  1855. {
  1856. if (ALocalFileList == NULL)
  1857. {
  1858. DebugAssert(HasDirView[osLocal]);
  1859. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1860. // directly (instead of EnableSelectedOperation) to pass
  1861. // false to FocusedFileOnlyWhenFocused
  1862. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1863. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1864. }
  1865. else
  1866. {
  1867. LocalFileList = ALocalFileList;
  1868. }
  1869. if (FileListCommand)
  1870. {
  1871. if (LocalFileList->Count != 1)
  1872. {
  1873. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1874. }
  1875. }
  1876. else
  1877. {
  1878. if ((LocalFileList->Count != 1) &&
  1879. (FileList->Count != 1) &&
  1880. (LocalFileList->Count != FileList->Count))
  1881. {
  1882. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1883. }
  1884. }
  1885. }
  1886. UnicodeString RootTempDir;
  1887. UnicodeString TempDir;
  1888. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1889. if (!RemoteFiles)
  1890. {
  1891. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1892. }
  1893. try
  1894. {
  1895. TDateTimes RemoteFileTimes;
  1896. if (RemoteFiles)
  1897. {
  1898. RemoteFileList = FileList;
  1899. }
  1900. else
  1901. {
  1902. RemoteFileList = new TStringList();
  1903. TMakeLocalFileListParams MakeFileListParam;
  1904. MakeFileListParam.FileList = RemoteFileList;
  1905. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1906. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1907. MakeFileListParam.Recursive =
  1908. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1909. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1910. if (!MakeFileListParam.Recursive)
  1911. {
  1912. RemoteFileTimes.clear();
  1913. RemoteFileListFull = new TStringList();
  1914. MakeFileListParam.FileList = RemoteFileListFull;
  1915. MakeFileListParam.Recursive = true;
  1916. MakeFileListParam.IncludeDirs = false;
  1917. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1918. }
  1919. else
  1920. {
  1921. RemoteFileListFull = RemoteFileList;
  1922. }
  1923. }
  1924. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1925. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1926. if (!NonBlocking)
  1927. {
  1928. int Count;
  1929. if (FileListCommand)
  1930. {
  1931. Count = 1;
  1932. }
  1933. else if (LocalFileCommand)
  1934. {
  1935. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1936. }
  1937. else
  1938. {
  1939. Count = RemoteFileList->Count;
  1940. }
  1941. Progress.Start(foCustomCommand, osRemote, Count);
  1942. DebugAssert(FProgressForm != NULL);
  1943. FProgressForm->ReadOnly = true;
  1944. }
  1945. try
  1946. {
  1947. if (FileListCommand)
  1948. {
  1949. UnicodeString LocalFile;
  1950. // MakeFileList does not delimit filenames
  1951. UnicodeString FileList = MakeFileList(RemoteFileList);
  1952. if (LocalFileCommand)
  1953. {
  1954. DebugAssert(LocalFileList->Count == 1);
  1955. LocalFile = LocalFileList->Strings[0];
  1956. }
  1957. TLocalCustomCommand CustomCommand(Data,
  1958. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1959. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1960. if (NonBlocking)
  1961. {
  1962. DebugAssert(!POutput);
  1963. ExecuteShellChecked(ShellCommand);
  1964. }
  1965. else
  1966. {
  1967. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1968. }
  1969. }
  1970. else if (LocalFileCommand)
  1971. {
  1972. if (LocalFileList->Count == 1)
  1973. {
  1974. UnicodeString LocalFile = LocalFileList->Strings[0];
  1975. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1976. {
  1977. UnicodeString FileName = RemoteFileList->Strings[Index];
  1978. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1979. Progress.SetFile(FileNameForProgress);
  1980. TLocalCustomCommand CustomCommand(Data,
  1981. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1982. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1983. TOnceDoneOperation OnceDoneOperation;
  1984. // Do not unselect anything, as it won't work with two panels anyway
  1985. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1986. }
  1987. }
  1988. else if (RemoteFileList->Count == 1)
  1989. {
  1990. UnicodeString FileName = RemoteFileList->Strings[0];
  1991. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1992. {
  1993. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1994. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1995. Progress.SetFile(LocalFileNameOnly);
  1996. TLocalCustomCommand CustomCommand(
  1997. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1998. FileName, LocalFileName, L"");
  1999. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2000. TOnceDoneOperation OnceDoneOperation;
  2001. // Do not unselect anything, as it won't work with two panels anyway
  2002. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2003. }
  2004. }
  2005. else
  2006. {
  2007. if (LocalFileList->Count != RemoteFileList->Count)
  2008. {
  2009. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2010. }
  2011. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2012. {
  2013. UnicodeString FileName = RemoteFileList->Strings[Index];
  2014. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2015. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2016. Progress.SetFile(LocalFileNameOnly); // sic
  2017. TLocalCustomCommand CustomCommand(
  2018. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2019. FileName, LocalFileName, L"");
  2020. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2021. TOnceDoneOperation OnceDoneOperation;
  2022. // Do not unselect anything, as it won't work with two panels anyway
  2023. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2024. }
  2025. }
  2026. }
  2027. else
  2028. {
  2029. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2030. {
  2031. UnicodeString FileName = RemoteFileList->Strings[Index];
  2032. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2033. Progress.SetFile(FileNameForProgress);
  2034. TLocalCustomCommand CustomCommand(Data,
  2035. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2036. FileName, L"", L"");
  2037. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2038. TOnceDoneOperation OnceDoneOperation;
  2039. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2040. }
  2041. }
  2042. }
  2043. __finally
  2044. {
  2045. if (!NonBlocking)
  2046. {
  2047. Progress.Stop();
  2048. }
  2049. }
  2050. DebugAssert(!FAutoOperation);
  2051. if (!RemoteFiles)
  2052. {
  2053. TempDir = IncludeTrailingBackslash(TempDir);
  2054. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2055. {
  2056. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2057. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2058. // Skip directories, process only nested files.
  2059. // The check is redundant as FileAge fails for directories anyway.
  2060. !DirectoryExists(FileName))
  2061. {
  2062. UnicodeString RemoteDir =
  2063. UnixExtractFileDir(
  2064. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2065. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2066. TDateTime NewTime;
  2067. if (FileAge(FileName, NewTime) &&
  2068. (NewTime != RemoteFileTimes[Index]))
  2069. {
  2070. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2071. TemporaryFileCopyParam(CopyParam);
  2072. CopyParam.FileMask = L"";
  2073. FAutoOperation = true;
  2074. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2075. TemporaryFilesList->Add(FileName);
  2076. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. __finally
  2083. {
  2084. FAutoOperation = false;
  2085. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2086. {
  2087. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2088. }
  2089. }
  2090. }
  2091. __finally
  2092. {
  2093. if (RemoteFileList != FileList)
  2094. {
  2095. delete RemoteFileList;
  2096. }
  2097. if (LocalFileList != ALocalFileList)
  2098. {
  2099. delete LocalFileList;
  2100. }
  2101. if (RemoteFileListFull != RemoteFileList)
  2102. {
  2103. delete RemoteFileListFull;
  2104. }
  2105. }
  2106. }
  2107. //---------------------------------------------------------------------------
  2108. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2109. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2110. bool FileListCommand, UnicodeString * POutput)
  2111. {
  2112. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2113. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2114. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2115. {
  2116. UnicodeString FileName = SelectedFileList->Strings[Index];
  2117. if (DirectoryExists(FileName))
  2118. {
  2119. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2120. {
  2121. LocalFileList->Add(FileName);
  2122. }
  2123. if (FLAGSET(ACommand.Params, ccRecursive))
  2124. {
  2125. TMakeLocalFileListParams MakeFileListParam;
  2126. MakeFileListParam.FileList = LocalFileList.get();
  2127. MakeFileListParam.FileTimes = NULL;
  2128. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2129. MakeFileListParam.Recursive = true;
  2130. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2131. }
  2132. }
  2133. else
  2134. {
  2135. LocalFileList->Add(FileName);
  2136. }
  2137. }
  2138. UnicodeString RemotePath;
  2139. if (Terminal != NULL)
  2140. {
  2141. RemotePath = Terminal->CurrentDirectory;
  2142. }
  2143. if (FileListCommand)
  2144. {
  2145. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2146. TLocalCustomCommand CustomCommand(
  2147. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2148. L"", L"", FileList);
  2149. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2150. }
  2151. else
  2152. {
  2153. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2154. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2155. DebugAssert(FProgressForm != NULL);
  2156. FProgressForm->ReadOnly = true;
  2157. try
  2158. {
  2159. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2160. {
  2161. UnicodeString FileName = LocalFileList->Strings[Index];
  2162. Progress.SetFile(FileName);
  2163. TLocalCustomCommand CustomCommand(
  2164. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2165. FileName, L"", L"");
  2166. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2167. TOnceDoneOperation OnceDoneOperation;
  2168. Progress.Finish(FileName, true, OnceDoneOperation);
  2169. }
  2170. }
  2171. __finally
  2172. {
  2173. Progress.Stop();
  2174. }
  2175. }
  2176. }
  2177. //---------------------------------------------------------------------------
  2178. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2179. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2180. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2181. {
  2182. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2183. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2184. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2185. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2186. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2187. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2188. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2189. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2190. std::unique_ptr<UnicodeString> POutput;
  2191. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2192. FLAGSET(ACommand.Params, ccCopyResults))
  2193. {
  2194. POutput.reset(new UnicodeString());
  2195. }
  2196. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2197. FProgressSide = FCurrentSide;
  2198. if (!LocalCustomCommand.IsFileCommand(Command))
  2199. {
  2200. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2201. }
  2202. // remote files?
  2203. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2204. {
  2205. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2206. }
  2207. // local files
  2208. else
  2209. {
  2210. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2211. }
  2212. if (POutput.get() != NULL)
  2213. {
  2214. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2215. int P = POutput->Pos(sLineBreak);
  2216. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2217. {
  2218. POutput->SetLength(P - 1);
  2219. }
  2220. // Copy even empty output to clipboard
  2221. if (FLAGSET(ACommand.Params, ccCopyResults))
  2222. {
  2223. CopyToClipboard(*POutput);
  2224. }
  2225. // But do not show an empty message box.
  2226. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2227. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2228. !POutput->IsEmpty())
  2229. {
  2230. TClipboardHandler ClipboardHandler;
  2231. ClipboardHandler.Text = *POutput;
  2232. TMessageParams Params;
  2233. TQueryButtonAlias Aliases[1];
  2234. Aliases[0].Button = qaRetry;
  2235. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2236. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2237. Params.Aliases = Aliases;
  2238. Params.AliasesCount = LENOF(Aliases);
  2239. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2240. }
  2241. }
  2242. }
  2243. //---------------------------------------------------------------------------
  2244. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2245. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2246. {
  2247. TCustomCommandData Data;
  2248. UnicodeString Site;
  2249. UnicodeString RemotePath;
  2250. if (HasActiveTerminal())
  2251. {
  2252. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2253. Data = TCustomCommandData(SessionData.get());
  2254. Site = Terminal->SessionData->SessionKey;
  2255. RemotePath = Terminal->CurrentDirectory;
  2256. }
  2257. UnicodeString HelpKeyword = ACommand.HomePage;
  2258. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2259. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2260. {
  2261. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2262. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2263. {
  2264. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2265. }
  2266. else
  2267. {
  2268. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2269. }
  2270. if (!DoCustomCommandOptionsDialog(
  2271. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2272. {
  2273. Abort();
  2274. }
  2275. }
  2276. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2277. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2278. {
  2279. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2280. }
  2281. else
  2282. {
  2283. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2284. }
  2285. }
  2286. //---------------------------------------------------------------------------
  2287. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2288. const TCustomCommandType & Command)
  2289. {
  2290. DebugAssert(FCustomCommandLocalFileList != NULL);
  2291. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2292. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2293. TStrings * LocalFileList = new TStringList();
  2294. TStrings * RemoteFileList = new TStringList();
  2295. try
  2296. {
  2297. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2298. {
  2299. LocalFileList->Clear();
  2300. LocalFileList->AddObject(
  2301. FCustomCommandLocalFileList->Strings[Index],
  2302. FCustomCommandLocalFileList->Objects[Index]);
  2303. RemoteFileList->Clear();
  2304. RemoteFileList->AddObject(
  2305. FCustomCommandRemoteFileList->Strings[Index],
  2306. FCustomCommandRemoteFileList->Objects[Index]);
  2307. CustomCommand(RemoteFileList, Command, LocalFileList);
  2308. }
  2309. }
  2310. __finally
  2311. {
  2312. delete LocalFileList;
  2313. delete RemoteFileList;
  2314. }
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2318. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2319. {
  2320. delete FCustomCommandLocalFileList;
  2321. delete FCustomCommandRemoteFileList;
  2322. // takeover ownership,
  2323. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2324. FCustomCommandLocalFileList = LocalFileList;
  2325. FCustomCommandRemoteFileList = RemoteFileList;
  2326. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2327. if (Button != NULL)
  2328. {
  2329. FCustomCommandMenu->Items->Clear();
  2330. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2331. MenuPopup(FCustomCommandMenu, Button);
  2332. }
  2333. else
  2334. {
  2335. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2336. }
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2340. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2341. {
  2342. DebugAssert(FCapturedLog != NULL);
  2343. if ((OutputType == cotOutput) || (OutputType == cotError))
  2344. {
  2345. FCapturedLog->Add(AddedLine);
  2346. }
  2347. }
  2348. //---------------------------------------------------------------------------
  2349. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2350. TOperationSide Side)
  2351. {
  2352. return
  2353. (Side == osOther) &&
  2354. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2358. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2359. {
  2360. TTBItemOptions O;
  2361. O = Item->Options;
  2362. TCustomDirView * DView = DirView(Side);
  2363. if ((DView->ItemFocused != NULL) &&
  2364. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2365. // when resolving links is disabled, default action is to enter the directory,
  2366. // no matter what DoubleClickAction is configured to
  2367. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2368. // Can only Edit files, but can Open/Copy even directories
  2369. ((DoubleClickAction != dcaEdit) ||
  2370. !DView->ItemIsDirectory(DView->ItemFocused)))
  2371. {
  2372. Item->Options = O << tboDefault;
  2373. }
  2374. else
  2375. {
  2376. Item->Options = O >> tboDefault;
  2377. }
  2378. }
  2379. //---------------------------------------------------------------------------
  2380. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2381. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2382. {
  2383. TCustomDirView * DView = DirView(Side);
  2384. TListItem * Item = DView->ItemFocused;
  2385. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2386. EnableFocusedOperation[Side])
  2387. {
  2388. TPoint ClientPoint;
  2389. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2390. TPoint(0, 0) : MousePos;
  2391. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2392. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2393. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2394. }
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2398. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2399. {
  2400. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2401. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2402. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2403. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2404. Handled = true;
  2405. }
  2406. //---------------------------------------------------------------------------
  2407. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2408. {
  2409. }
  2410. //---------------------------------------------------------------------------
  2411. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2412. {
  2413. DebugAssert(FErrorList == NULL);
  2414. if (WinConfiguration->ContinueOnError)
  2415. {
  2416. FErrorList = new TStringList();
  2417. Configuration->Usage->Inc(L"ContinuationsOnError");
  2418. }
  2419. NonVisualDataModule->StartBusy();
  2420. }
  2421. //---------------------------------------------------------------------------
  2422. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2423. {
  2424. NonVisualDataModule->EndBusy();
  2425. if (FErrorList)
  2426. {
  2427. HandleErrorList(FErrorList);
  2428. }
  2429. }
  2430. //---------------------------------------------------------------------------
  2431. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2432. const TCopyParamType & CopyParam)
  2433. {
  2434. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2435. {
  2436. Configuration->Usage->Inc(L"FileMaskUses");
  2437. }
  2438. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2439. {
  2440. Configuration->Usage->Inc(L"OperationMaskUses");
  2441. }
  2442. }
  2443. //---------------------------------------------------------------------------
  2444. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2445. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2446. {
  2447. DebugAssert(!IsLocalBrowserMode());
  2448. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2449. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2450. TTransferOperationParam DefaultParam;
  2451. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2452. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2453. switch (Param.Queue)
  2454. {
  2455. case asOn:
  2456. CopyParam.Queue = true;
  2457. break;
  2458. case asOff:
  2459. CopyParam.Queue = false;
  2460. break;
  2461. case asAuto:
  2462. default:
  2463. // keep default
  2464. break;
  2465. }
  2466. bool Result =
  2467. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2468. if (Result)
  2469. {
  2470. DebugAssert(Terminal);
  2471. bool SelectionRestored = false;
  2472. TCustomDirView * DView = NULL;
  2473. if (HasDirView[Side])
  2474. {
  2475. DView = DirView(Side);
  2476. DView->SaveSelection();
  2477. DView->SaveSelectedNames();
  2478. }
  2479. UpdateCopyParamCounters(CopyParam);
  2480. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2481. DebugAssert(FTransferResumeList == NULL);
  2482. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2483. FMoveToQueue = false;
  2484. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2485. try
  2486. {
  2487. TStrings * PermanentFileList;
  2488. std::unique_ptr<TStrings> PermanentFileListOwner;
  2489. try
  2490. {
  2491. if (Side == osLocal)
  2492. {
  2493. PermanentFileList = FileList;
  2494. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2495. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2496. if (Operation == foMove)
  2497. {
  2498. ReloadLocalDirectory();
  2499. if (DView != NULL)
  2500. {
  2501. DView->RestoreSelection();
  2502. }
  2503. SelectionRestored = true;
  2504. }
  2505. }
  2506. else
  2507. {
  2508. // Clone the file list as it may refer to current directory files,
  2509. // which get destroyed, when the source directory is reloaded after foMove operation.
  2510. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2511. // But for a hotfix, we are not going to do such a big change.
  2512. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2513. PermanentFileList = PermanentFileListOwner.get();
  2514. try
  2515. {
  2516. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2517. }
  2518. __finally
  2519. {
  2520. if (Operation == foMove)
  2521. {
  2522. if (DView != NULL)
  2523. {
  2524. DView->RestoreSelection();
  2525. }
  2526. SelectionRestored = true;
  2527. }
  2528. ReloadLocalDirectory(Param.TargetDirectory);
  2529. }
  2530. }
  2531. }
  2532. catch (EAbort &)
  2533. {
  2534. if (FMoveToQueue)
  2535. {
  2536. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2537. DebugAssert(CopyParam.TransferSkipList == NULL);
  2538. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2539. if (TransferResumeList->Count > 0)
  2540. {
  2541. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2542. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2543. }
  2544. CopyParam.TransferSkipList = TransferResumeList.release();
  2545. // not really needed, just to keep it consistent with TransferResumeList
  2546. FTransferResumeList = NULL;
  2547. FMoveToQueue = false;
  2548. Configuration->Usage->Inc("MovesToBackground");
  2549. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2550. ClearTransferSourceSelection(Direction);
  2551. }
  2552. throw;
  2553. }
  2554. }
  2555. __finally
  2556. {
  2557. if (!SelectionRestored && (DView != NULL))
  2558. {
  2559. DView->DiscardSavedSelection();
  2560. }
  2561. FTransferResumeList = NULL;
  2562. }
  2563. }
  2564. return Result;
  2565. }
  2566. //---------------------------------------------------------------------------
  2567. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2568. TOperationSide Side, TStrings * FileList, void * Param)
  2569. {
  2570. DebugAssert(FileList->Count);
  2571. // We deliberately do not toggle alternative flag (Param), but use OR,
  2572. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2573. // shortcut of CurrentDeleteAlternativeAction
  2574. bool Alternative =
  2575. bool(Param) || UseAlternativeFunction();
  2576. bool Recycle;
  2577. if (IsSideLocalBrowser(Side))
  2578. {
  2579. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2580. }
  2581. else
  2582. {
  2583. Recycle =
  2584. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2585. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2586. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2587. }
  2588. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2589. if (!Result)
  2590. {
  2591. UnicodeString Query;
  2592. if (FileList->Count == 1)
  2593. {
  2594. if (IsSideLocalBrowser(Side))
  2595. {
  2596. Query = ExtractFileName(FileList->Strings[0]);
  2597. }
  2598. else
  2599. {
  2600. Query = UnixExtractFileName(FileList->Strings[0]);
  2601. }
  2602. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2603. }
  2604. else
  2605. {
  2606. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2607. }
  2608. TMessageParams Params(mpNeverAskAgainCheck);
  2609. Params.ImageName = L"Delete file";
  2610. unsigned int Answer =
  2611. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2612. if (Answer == qaNeverAskAgain)
  2613. {
  2614. Result = true;
  2615. if (Recycle)
  2616. {
  2617. WinConfiguration->ConfirmRecycling = false;
  2618. }
  2619. else
  2620. {
  2621. WinConfiguration->ConfirmDeleting = false;
  2622. }
  2623. }
  2624. else
  2625. {
  2626. Result = (Answer == qaOK);
  2627. }
  2628. }
  2629. if (Result)
  2630. {
  2631. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2632. }
  2633. return Result;
  2634. }
  2635. //---------------------------------------------------------------------------
  2636. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2637. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2638. {
  2639. TAutoBatch AutoBatch(this);
  2640. bool Result;
  2641. if ((Operation == foCopy) || (Operation == foMove))
  2642. {
  2643. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2644. }
  2645. else if (Operation == foRename)
  2646. {
  2647. DebugAssert(DirView(Side)->ItemFocused);
  2648. DirView(Side)->ItemFocused->EditCaption();
  2649. Result = true;
  2650. }
  2651. else if (Operation == foDelete)
  2652. {
  2653. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2654. }
  2655. else if (Operation == foSetProperties)
  2656. {
  2657. DirView(osRemote)->SaveSelectedNames();
  2658. Result = SetProperties(Side, FileList);
  2659. }
  2660. else if (Operation == foCustomCommand)
  2661. {
  2662. DebugAssert(Param);
  2663. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2664. DirView(osRemote)->SaveSelectedNames();
  2665. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2666. CustomCommand(FileList, *Command, NULL);
  2667. Result = true;
  2668. }
  2669. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2670. {
  2671. DebugAssert(!IsSideLocalBrowser(Side));
  2672. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2673. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2674. }
  2675. else if (Operation == foLock)
  2676. {
  2677. DebugAssert(!IsSideLocalBrowser(Side));
  2678. LockFiles(FileList, true);
  2679. Result = true;
  2680. }
  2681. else if (Operation == foUnlock)
  2682. {
  2683. DebugAssert(!IsSideLocalBrowser(Side));
  2684. LockFiles(FileList, false);
  2685. Result = true;
  2686. }
  2687. else
  2688. {
  2689. DebugFail();
  2690. }
  2691. return Result;
  2692. }
  2693. //---------------------------------------------------------------------------
  2694. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2695. {
  2696. if (Side == osCurrent)
  2697. {
  2698. Side = FCurrentSide;
  2699. }
  2700. return Side;
  2701. }
  2702. //---------------------------------------------------------------------------
  2703. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2704. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2705. {
  2706. Side = GetSide(Side);
  2707. bool Result;
  2708. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2709. try
  2710. {
  2711. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2712. }
  2713. __finally
  2714. {
  2715. delete FileList;
  2716. }
  2717. return Result;
  2718. }
  2719. //---------------------------------------------------------------------------
  2720. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2721. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2722. bool NoConfirmation, void * Param)
  2723. {
  2724. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2725. {
  2726. if ((Operation == foCopy) || (Operation == foMove))
  2727. {
  2728. DebugAssert(!IsLocalBrowserMode());
  2729. if (GetSide(Side) == osLocal)
  2730. {
  2731. Configuration->Usage->Inc(L"UploadsCommand");
  2732. }
  2733. else
  2734. {
  2735. Configuration->Usage->Inc(L"DownloadsCommand");
  2736. }
  2737. }
  2738. }
  2739. }
  2740. //---------------------------------------------------------------------------
  2741. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2742. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2743. {
  2744. TTransferOperationParam Param;
  2745. if ((WinConfiguration->Interface != ifCommander) ||
  2746. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2747. {
  2748. Flags &= ~cocShortCutHint;
  2749. }
  2750. TCustomDirView * DView = DirView(Side);
  2751. Param.Options =
  2752. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2753. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2754. if (FLAGSET(Flags, cocQueue))
  2755. {
  2756. Param.Queue = asOn;
  2757. }
  2758. else if (FLAGSET(Flags, cocNonQueue))
  2759. {
  2760. Param.Queue = asOff;
  2761. }
  2762. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2763. }
  2764. //---------------------------------------------------------------------------
  2765. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2766. {
  2767. try
  2768. {
  2769. if (ErrorList->Count)
  2770. {
  2771. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2772. if (MessageDialog(Message, qtError,
  2773. qaOK | qaCancel, HELP_NONE) == qaOK)
  2774. {
  2775. unsigned int Answer;
  2776. int Index = 0;
  2777. do
  2778. {
  2779. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2780. TQueryButtonAlias Aliases[2];
  2781. Aliases[0].Button = qaYes;
  2782. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2783. Aliases[1].Button = qaNo;
  2784. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2785. TMessageParams Params;
  2786. Params.Aliases = Aliases;
  2787. Params.AliasesCount = LENOF(Aliases);
  2788. Answer = MoreMessageDialog(
  2789. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2790. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2791. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2792. qaOK, HELP_NONE, &Params);
  2793. if (Answer == qaNo)
  2794. {
  2795. Index++;
  2796. }
  2797. if (Answer == qaYes)
  2798. {
  2799. Index--;
  2800. }
  2801. }
  2802. while (Answer != qaOK);
  2803. }
  2804. }
  2805. }
  2806. __finally
  2807. {
  2808. TStrings * List = ErrorList;
  2809. ErrorList = NULL;
  2810. for (int i = 0; i < List->Count; i++)
  2811. {
  2812. delete List->Objects[i];
  2813. }
  2814. delete List;
  2815. }
  2816. }
  2817. //---------------------------------------------------------------------------
  2818. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2819. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2820. {
  2821. // needed for checking filemasks, as there's no directory object
  2822. // associated with the file object
  2823. File->FullFileName = FullFileName;
  2824. TFileMasks::TParams MaskParams;
  2825. MaskParams.Size = File->Size;
  2826. MaskParams.Modification = File->Modification;
  2827. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2828. }
  2829. //---------------------------------------------------------------------------
  2830. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2831. {
  2832. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2833. Side = GetSide(Side);
  2834. TCustomDirView * DView = DirView(Side);
  2835. TListItem * FocusedItem = DView->ItemFocused;
  2836. UnicodeString Name;
  2837. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2838. {
  2839. Name = DView->ItemFileName(FocusedItem);
  2840. }
  2841. else
  2842. {
  2843. Name = LoadStr(NEW_FILE);
  2844. }
  2845. UnicodeString Names = Name;
  2846. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2847. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2848. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2849. {
  2850. while (!Names.IsEmpty())
  2851. {
  2852. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2853. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2854. UnicodeString TargetFileName;
  2855. UnicodeString LocalFileName;
  2856. UnicodeString RootTempDir;
  2857. UnicodeString TempDir;
  2858. UnicodeString RemoteDirectory;
  2859. bool ExistingFile = false;
  2860. if (!IsSideLocalBrowser(Side))
  2861. {
  2862. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2863. TRemoteFile * File = NULL;
  2864. if (Terminal->FileExists(Name, &File) &&
  2865. !File->IsDirectory)
  2866. {
  2867. try
  2868. {
  2869. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2870. ExistingFile = true;
  2871. }
  2872. __finally
  2873. {
  2874. delete File;
  2875. }
  2876. }
  2877. if (!ExistingFile)
  2878. {
  2879. RemoteDirectory = UnixExtractFilePath(Name);
  2880. TemporaryDirectoryForRemoteFiles(
  2881. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2882. TargetFileName = UnixExtractFileName(Name);
  2883. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2884. LocalFileName = TempDir +
  2885. // We probably do not want to trim the VMS version here
  2886. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if (ExtractFilePath(Name).IsEmpty())
  2892. {
  2893. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2894. }
  2895. else
  2896. {
  2897. LocalFileName = ExpandFileName(Name);
  2898. }
  2899. TargetFileName = ExtractFileName(Name);
  2900. }
  2901. if (!ExistingFile)
  2902. {
  2903. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2904. if (NewFile)
  2905. {
  2906. int File = FileCreate(ApiPath(LocalFileName));
  2907. if (File < 0)
  2908. {
  2909. if (!RootTempDir.IsEmpty())
  2910. {
  2911. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2912. }
  2913. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2914. }
  2915. else
  2916. {
  2917. FileClose(File);
  2918. }
  2919. }
  2920. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2921. const TEditorData * ExternalEditor = NULL;
  2922. TFileMasks::TParams MaskParams; // size not known
  2923. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2924. false, MaskParams);
  2925. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2926. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2927. }
  2928. }
  2929. }
  2930. }
  2931. //---------------------------------------------------------------------------
  2932. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2933. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2934. {
  2935. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2936. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2937. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2938. return
  2939. ((ExecuteFileBy == efInternalEditor)) ||
  2940. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2941. }
  2942. //---------------------------------------------------------------------------
  2943. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2944. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2945. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2946. UnicodeString RemoteDirectory, bool NewFile)
  2947. {
  2948. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2949. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2950. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2951. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2952. Side = GetSide(Side);
  2953. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2954. if (!IsSideLocalBrowser(Side))
  2955. {
  2956. Data->Terminal = Terminal;
  2957. Data->Queue = Queue;
  2958. Data->SessionData = CloneCurrentSessionData();
  2959. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2960. Data->RemoteDirectory = RemoteDirectory;
  2961. Data->SessionName = Terminal->SessionData->SessionName;
  2962. Data->LocalRootDirectory = LocalRootDirectory;
  2963. Data->OriginalFileName = OriginalFileName;
  2964. Data->Command = L""; // will be changed later for external editor
  2965. }
  2966. if (ExecuteFileBy == efInternalEditor)
  2967. {
  2968. if (!IsSideLocalBrowser(Side))
  2969. {
  2970. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2971. L" - " + Terminal->SessionData->SessionName;
  2972. TForm * Editor;
  2973. try
  2974. {
  2975. TNotifyEvent OnFileChanged = NULL;
  2976. TNotifyEvent OnSaveAll = NULL;
  2977. TAnyModifiedEvent OnAnyModified = NULL;
  2978. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2979. if (Terminal->IsCapable[fcBackgroundTransfers])
  2980. {
  2981. OnFileChanged = FEditorManager->FileChanged;
  2982. OnSaveAll = SaveAllInternalEditors;
  2983. OnAnyModified = AnyInternalEditorModified;
  2984. }
  2985. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2986. FEditorManager->FileReload, FEditorManager->FileClosed,
  2987. OnSaveAll, OnAnyModified,
  2988. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2989. }
  2990. catch(...)
  2991. {
  2992. if (!LocalRootDirectory.IsEmpty())
  2993. {
  2994. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2995. }
  2996. throw;
  2997. }
  2998. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2999. }
  3000. else
  3001. {
  3002. DebugAssert(!FStandaloneEditing);
  3003. TForm * Editor =
  3004. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3005. SaveAllInternalEditors, AnyInternalEditorModified,
  3006. L"", false, SessionColor, -1, NewFile);
  3007. FLocalEditors->Add(Editor);
  3008. }
  3009. }
  3010. else
  3011. {
  3012. HANDLE Process;
  3013. if (ExecuteFileBy == efExternalEditor)
  3014. {
  3015. UnicodeString Program, Params, Dir;
  3016. Data->Command = ExternalEditor->ExternalEditor;
  3017. ReformatFileNameCommand(Data->Command);
  3018. SplitCommand(Data->Command, Program, Params, Dir);
  3019. Params = ExpandFileNameCommand(Params, FileName);
  3020. Program = ExpandEnvironmentVariables(Program);
  3021. if (!ExecuteShell(Program, Params, Process))
  3022. {
  3023. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3024. }
  3025. }
  3026. else
  3027. {
  3028. DebugAssert(!IsSideLocalBrowser(Side));
  3029. if (!ExecuteShell(FileName, L"", Process))
  3030. {
  3031. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3032. }
  3033. }
  3034. if (IsSideLocalBrowser(Side) ||
  3035. ((ExecuteFileBy == efShell) &&
  3036. !WinConfiguration->Editor.SDIShellEditor) ||
  3037. ((ExecuteFileBy == efExternalEditor) &&
  3038. !ExternalEditor->SDIExternalEditor))
  3039. {
  3040. // no need for handle
  3041. if (Process != NULL)
  3042. {
  3043. DebugCheck(CloseHandle(Process));
  3044. }
  3045. Process = INVALID_HANDLE_VALUE;
  3046. }
  3047. else
  3048. {
  3049. if (Process == NULL)
  3050. {
  3051. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3052. }
  3053. }
  3054. if (!IsSideLocalBrowser(Side))
  3055. {
  3056. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3057. }
  3058. }
  3059. }
  3060. //---------------------------------------------------------------------------
  3061. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3062. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3063. void * /*Arg*/)
  3064. {
  3065. if (Token != NULL)
  3066. {
  3067. EditorFormFileSave(static_cast<TForm *>(Token));
  3068. }
  3069. }
  3070. //---------------------------------------------------------------------------
  3071. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3072. {
  3073. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3074. {
  3075. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3076. }
  3077. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3078. }
  3079. //---------------------------------------------------------------------------
  3080. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3081. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3082. void * Arg)
  3083. {
  3084. if ((Token != NULL) &&
  3085. IsEditorFormModified(static_cast<TForm *>(Token)))
  3086. {
  3087. *static_cast<bool *>(Arg) = true;
  3088. }
  3089. }
  3090. //---------------------------------------------------------------------------
  3091. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3092. TObject * /*Sender*/, bool & Modified)
  3093. {
  3094. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3095. {
  3096. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3097. {
  3098. Modified = true;
  3099. }
  3100. }
  3101. if (!Modified)
  3102. {
  3103. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3104. }
  3105. }
  3106. //---------------------------------------------------------------------------
  3107. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3108. {
  3109. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3110. }
  3111. //---------------------------------------------------------------------------
  3112. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3113. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3114. UnicodeString & Result, UnicodeString & RootDirectory)
  3115. {
  3116. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3117. {
  3118. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3119. Result = RootDirectory;
  3120. }
  3121. else
  3122. {
  3123. RootDirectory = L"";
  3124. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3125. Result = IncludeTrailingBackslash(Result);
  3126. }
  3127. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3128. {
  3129. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3130. }
  3131. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3132. {
  3133. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3134. {
  3135. RemoteDirectory.Delete(1, 1);
  3136. }
  3137. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3138. }
  3139. if (!ForceDirectories(ApiPath(Result)))
  3140. {
  3141. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3142. }
  3143. }
  3144. //---------------------------------------------------------------------------
  3145. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3146. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3147. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3148. {
  3149. DebugAssert(!IsLocalBrowserMode());
  3150. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3151. if (ForceText)
  3152. {
  3153. CopyParam.TransferMode = tmAscii;
  3154. }
  3155. TemporaryFileCopyParam(CopyParam);
  3156. if (AllFiles)
  3157. {
  3158. CopyParam.IncludeFileMask = TFileMasks();
  3159. }
  3160. if (TempDir.IsEmpty())
  3161. {
  3162. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3163. }
  3164. DebugAssert(!FAutoOperation);
  3165. FAutoOperation = AutoOperation;
  3166. Terminal->ExceptionOnFail = true;
  3167. try
  3168. {
  3169. try
  3170. {
  3171. // turn off confirmations, as for MDI editors we may possibly download
  3172. // the same file over
  3173. Terminal->CopyToLocal(
  3174. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3175. if (GetTargetNames)
  3176. {
  3177. for (int i = 0; i < FileList->Count; i++)
  3178. {
  3179. FileList->Strings[i] =
  3180. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3181. }
  3182. }
  3183. }
  3184. catch(...)
  3185. {
  3186. if (!RootTempDir.IsEmpty())
  3187. {
  3188. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3189. }
  3190. throw;
  3191. }
  3192. }
  3193. __finally
  3194. {
  3195. FAutoOperation = false;
  3196. Terminal->ExceptionOnFail = false;
  3197. }
  3198. }
  3199. //---------------------------------------------------------------------------
  3200. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3201. {
  3202. // Do not waste time checking for default editor list the next time,
  3203. // or testing if default editor is not notepad.
  3204. bool TryNextTime = false;
  3205. UnicodeString UsageState;
  3206. if (!WinConfiguration->EditorList->IsDefaultList())
  3207. {
  3208. UsageState = "H";
  3209. }
  3210. else
  3211. {
  3212. UnicodeString Executable;
  3213. UnicodeString ExecutableDescription;
  3214. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3215. {
  3216. UnicodeString Message =
  3217. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3218. unsigned int Answer =
  3219. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3220. if (Answer != qaOK)
  3221. {
  3222. UsageState = "R";
  3223. }
  3224. else
  3225. {
  3226. UsageState = "A";
  3227. TEditorData EditorData;
  3228. EditorData.Editor = edExternal;
  3229. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3230. EditorData.ExternalEditorOptionsAutodetect();
  3231. TEditorList EditorList;
  3232. EditorList = *WinConfiguration->EditorList;
  3233. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3234. WinConfiguration->EditorList = &EditorList;
  3235. }
  3236. }
  3237. }
  3238. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3239. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3240. }
  3241. //---------------------------------------------------------------------------
  3242. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3243. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3244. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3245. {
  3246. if (ExecuteFileBy == efDefaultEditor)
  3247. {
  3248. if (!WinConfiguration->OfferedEditorAutoConfig)
  3249. {
  3250. EditorAutoConfig();
  3251. }
  3252. const TEditorPreferences * Editor =
  3253. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3254. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3255. {
  3256. ExecuteFileBy = efInternalEditor;
  3257. ExternalEditor = NULL;
  3258. }
  3259. else if (Editor->Data->Editor == edOpen)
  3260. {
  3261. ExecuteFileBy = efShell;
  3262. ExternalEditor = NULL;
  3263. }
  3264. else
  3265. {
  3266. ExecuteFileBy = efExternalEditor;
  3267. ExternalEditor = Editor->Data;
  3268. }
  3269. }
  3270. }
  3271. //---------------------------------------------------------------------------
  3272. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3273. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3274. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3275. {
  3276. UnicodeString OriginalFileName;
  3277. UnicodeString LocalRootDirectory;
  3278. UnicodeString RemoteDirectory;
  3279. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3280. IsSideLocalBrowser(Side), MaskParams);
  3281. UnicodeString Counter;
  3282. UnicodeString LocalFileName;
  3283. bool Handled = false;
  3284. if (!IsSideLocalBrowser(Side))
  3285. {
  3286. // We need to trim VMS version here, so that we use name without version
  3287. // when uploading back to create a new version of the file
  3288. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3289. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3290. TObject * Token = NULL;
  3291. UnicodeString LocalDirectory;
  3292. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3293. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3294. LocalDirectory))
  3295. {
  3296. if (Token != NULL)
  3297. {
  3298. TForm * Form = dynamic_cast<TForm *>(Token);
  3299. if (Form->WindowState == wsMinimized)
  3300. {
  3301. ShowWindow(Form->Handle, SW_RESTORE);
  3302. }
  3303. else
  3304. {
  3305. Form->SetFocus();
  3306. }
  3307. Handled = true;
  3308. }
  3309. else
  3310. {
  3311. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3312. }
  3313. }
  3314. if (!Handled)
  3315. {
  3316. TStringList * FileList1 = new TStringList();
  3317. try
  3318. {
  3319. FileList1->AddObject(FullFileName, Object);
  3320. TemporarilyDownloadFiles(FileList1,
  3321. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3322. LocalRootDirectory, LocalDirectory, true, true, true);
  3323. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3324. }
  3325. __finally
  3326. {
  3327. delete FileList1;
  3328. }
  3329. switch (ExecuteFileBy)
  3330. {
  3331. case efShell:
  3332. Counter = "RemoteFilesExecuted";
  3333. break;
  3334. case efInternalEditor:
  3335. Counter = "RemoteFilesOpenedInInternalEditor";
  3336. break;
  3337. case efExternalEditor:
  3338. Counter = "RemoteFilesOpenedInExternalEditor";
  3339. break;
  3340. default:
  3341. DebugFail();
  3342. }
  3343. }
  3344. }
  3345. else
  3346. {
  3347. LocalFileName = FullFileName;
  3348. OriginalFileName = ExtractFileName(FullFileName);
  3349. switch (ExecuteFileBy)
  3350. {
  3351. case efShell:
  3352. Counter = "LocalFilesExecuted";
  3353. break;
  3354. case efInternalEditor:
  3355. Counter = "LocalFilesOpenedInInternalEditor";
  3356. break;
  3357. case efExternalEditor:
  3358. Counter = "LocalFilesOpenedInExternalEditor";
  3359. break;
  3360. default:
  3361. DebugFail();
  3362. }
  3363. }
  3364. if (!Handled)
  3365. {
  3366. Configuration->Usage->Inc(Counter);
  3367. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3368. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3369. }
  3370. }
  3371. //---------------------------------------------------------------------------
  3372. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3373. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3374. bool AllSelected, bool OnFocused)
  3375. {
  3376. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3377. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3378. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3379. Side = GetSide(Side);
  3380. TCustomDirView * DView = DirView(Side);
  3381. TStrings * FileList =
  3382. AllSelected ?
  3383. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3384. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3385. try
  3386. {
  3387. DebugAssert(AllSelected || (FileList->Count == 1));
  3388. for (int i = 0; i < FileList->Count; i++)
  3389. {
  3390. UnicodeString ListFileName = FileList->Strings[i];
  3391. UnicodeString FileNameOnly =
  3392. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3393. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3394. if (!DView->ItemIsDirectory(Item))
  3395. {
  3396. UnicodeString FullFileName;
  3397. if (!IsSideLocalBrowser(Side))
  3398. {
  3399. FullFileName = DirView(Side)->Path + ListFileName;
  3400. }
  3401. else
  3402. {
  3403. FullFileName = ListFileName;
  3404. }
  3405. TFileMasks::TParams MaskParams;
  3406. MaskParams.Size = DView->ItemFileSize(Item);
  3407. TDateTimePrecision Precision;
  3408. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3409. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3410. FileList->Objects[i], MaskParams);
  3411. }
  3412. }
  3413. }
  3414. __finally
  3415. {
  3416. delete FileList;
  3417. }
  3418. }
  3419. //---------------------------------------------------------------------------
  3420. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3421. {
  3422. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3423. CopyParam.FileNameCase = ncNoChange;
  3424. CopyParam.PreserveRights = false;
  3425. CopyParam.PreserveReadOnly = false;
  3426. CopyParam.ReplaceInvalidChars = true;
  3427. CopyParam.IncludeFileMask = TFileMasks();
  3428. CopyParam.NewerOnly = false;
  3429. CopyParam.FileMask = L"";
  3430. }
  3431. //---------------------------------------------------------------------------
  3432. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3433. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3434. {
  3435. TTerminalManager * Manager = TTerminalManager::Instance();
  3436. if (!IsActiveTerminal(Data->Terminal))
  3437. {
  3438. if (!NonVisualDataModule->Busy)
  3439. {
  3440. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3441. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3442. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3443. if (Data->Terminal == NULL)
  3444. {
  3445. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3446. if (SameSiteTerminal != NULL)
  3447. {
  3448. UnicodeString Message =
  3449. FMTLOAD(EDIT_SESSION_REATTACH,
  3450. (FileNameOnly, Data->SessionName, FileNameOnly));
  3451. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3452. {
  3453. Data->Terminal = Terminal;
  3454. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3455. Data->SessionName = Terminal->SessionData->SessionName;
  3456. // We might also overwrite session data
  3457. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3458. }
  3459. else
  3460. {
  3461. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3462. Abort();
  3463. }
  3464. }
  3465. }
  3466. // foreground session should reconnect itself
  3467. else if (Terminal != Data->Terminal)
  3468. {
  3469. UnicodeString Message =
  3470. MainInstructions(
  3471. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3472. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3473. {
  3474. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3475. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3476. }
  3477. else
  3478. {
  3479. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3480. Abort();
  3481. }
  3482. }
  3483. }
  3484. if (!IsActiveTerminal(Data->Terminal))
  3485. {
  3486. Configuration->Usage->Inc(L"EditInactiveSession");
  3487. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3488. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3489. (ExtractFileName(FileName), Data->SessionName)));
  3490. }
  3491. }
  3492. TStrings * FileList = new TStringList();
  3493. try
  3494. {
  3495. FileList->Add(FileName);
  3496. // consider using the same settings (preset) as when the file was downloaded
  3497. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3498. TemporaryFileCopyParam(CopyParam);
  3499. if (Data->ForceText)
  3500. {
  3501. CopyParam.TransferMode = tmAscii;
  3502. }
  3503. // so i do not need to worry if masking algorithm works in all cases
  3504. // ("" means "copy file name", no masking is actually done)
  3505. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3506. {
  3507. CopyParam.FileMask = L"";
  3508. }
  3509. else
  3510. {
  3511. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3512. }
  3513. DebugAssert(Data->Queue != NULL);
  3514. int Params = cpNoConfirmation | cpTemporary;
  3515. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3516. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3517. QueueItem->CompleteEvent = UploadCompleteEvent;
  3518. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3519. }
  3520. __finally
  3521. {
  3522. delete FileList;
  3523. }
  3524. }
  3525. //---------------------------------------------------------------------------
  3526. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3527. const UnicodeString FileName, const TEditedFileData * Data)
  3528. {
  3529. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3530. DebugAssert(!NonVisualDataModule->Busy);
  3531. if (!IsActiveTerminal(Data->Terminal))
  3532. {
  3533. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3534. (ExtractFileName(FileName), Data->SessionName)));
  3535. }
  3536. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3537. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3538. NonVisualDataModule->StartBusy();
  3539. try
  3540. {
  3541. std::unique_ptr<TRemoteFile> File;
  3542. UnicodeString RemoteFileName =
  3543. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3544. Terminal->ExceptionOnFail = true;
  3545. try
  3546. {
  3547. TRemoteFile * AFile = NULL;
  3548. Terminal->ReadFile(RemoteFileName, AFile);
  3549. File.reset(AFile);
  3550. if (!File->HaveFullFileName)
  3551. {
  3552. File->FullFileName = RemoteFileName;
  3553. }
  3554. }
  3555. __finally
  3556. {
  3557. Terminal->ExceptionOnFail = false;
  3558. }
  3559. std::unique_ptr<TStrings> FileList(new TStringList());
  3560. FileList->AddObject(RemoteFileName, File.get());
  3561. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3562. UnicodeString TempDir = ExtractFilePath(FileName);
  3563. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3564. TempDir, true, true, true);
  3565. // sanity check, the target file name should be still the same
  3566. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3567. }
  3568. __finally
  3569. {
  3570. NonVisualDataModule->EndBusy();
  3571. // it actually may not exist anymore...
  3572. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3573. }
  3574. }
  3575. //---------------------------------------------------------------------------
  3576. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3577. const TEditedFileData * Data, bool & KeepOpen)
  3578. {
  3579. // Command is set for external editors only (not for "shell" open).
  3580. if (!Data->Command.IsEmpty())
  3581. {
  3582. bool AnyFound = false;
  3583. bool AnyMDI = false;
  3584. bool AnyNonMDI = false;
  3585. bool AnyDetect = false;
  3586. TEditorList * EditorList = new TEditorList();
  3587. try
  3588. {
  3589. *EditorList = *WinConfiguration->EditorList;
  3590. for (int i = 0; i < EditorList->Count; i++)
  3591. {
  3592. const TEditorPreferences * Editor = EditorList->Editors[i];
  3593. if ((Editor->Data->Editor == edExternal) &&
  3594. (Editor->Data->ExternalEditor == Data->Command))
  3595. {
  3596. AnyFound = true;
  3597. if (Editor->Data->SDIExternalEditor)
  3598. {
  3599. AnyNonMDI = true;
  3600. if (Editor->Data->DetectMDIExternalEditor)
  3601. {
  3602. AnyDetect = true;
  3603. }
  3604. }
  3605. else
  3606. {
  3607. AnyMDI = true;
  3608. }
  3609. }
  3610. }
  3611. bool EnableMDI = false;
  3612. bool DisableDetect = false;
  3613. if (AnyMDI)
  3614. {
  3615. KeepOpen = true;
  3616. if (AnyNonMDI)
  3617. {
  3618. // there is at least one instance of the editor with MDI support enabled,
  3619. // and one with disabled, enable it for all instances
  3620. EnableMDI = true;
  3621. }
  3622. }
  3623. else if (AnyFound && !AnyDetect)
  3624. {
  3625. // at least once instance found but all have MDI autodetection disabled
  3626. // => close the file (default action)
  3627. }
  3628. else
  3629. {
  3630. // no instance of the editor has MDI support enabled
  3631. TMessageParams Params;
  3632. if (AnyFound)
  3633. {
  3634. // there is at least one instance of the editor
  3635. Params.Params |= mpNeverAskAgainCheck;
  3636. }
  3637. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3638. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3639. switch (Answer)
  3640. {
  3641. case qaNeverAskAgain:
  3642. DisableDetect = true;
  3643. break;
  3644. case qaNo:
  3645. EnableMDI = true;
  3646. KeepOpen = true;
  3647. break;
  3648. }
  3649. }
  3650. if (AnyFound && (EnableMDI || DisableDetect))
  3651. {
  3652. bool Changed = false;
  3653. for (int i = 0; i < EditorList->Count; i++)
  3654. {
  3655. const TEditorPreferences * Editor = EditorList->Editors[i];
  3656. if ((Editor->Data->Editor == edExternal) &&
  3657. (Editor->Data->ExternalEditor == Data->Command) &&
  3658. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3659. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3660. {
  3661. Changed = true;
  3662. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3663. if (EnableMDI)
  3664. {
  3665. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3666. }
  3667. if (DisableDetect)
  3668. {
  3669. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3670. }
  3671. EditorList->Change(i, UpdatedEditor);
  3672. }
  3673. }
  3674. if (Changed)
  3675. {
  3676. WinConfiguration->EditorList = EditorList;
  3677. }
  3678. }
  3679. }
  3680. __finally
  3681. {
  3682. delete EditorList;
  3683. }
  3684. }
  3685. else
  3686. {
  3687. // "open" case
  3688. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3689. qaOK, HELP_APP_EARLY_CLOSED);
  3690. }
  3691. }
  3692. //---------------------------------------------------------------------------
  3693. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3694. {
  3695. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3696. }
  3697. //---------------------------------------------------------------------------
  3698. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3699. {
  3700. SideEnter(osRemote);
  3701. }
  3702. //---------------------------------------------------------------------------
  3703. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3704. {
  3705. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3706. SideEnter(osRemote);
  3707. }
  3708. //---------------------------------------------------------------------------
  3709. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3710. {
  3711. FCurrentSide = Side;
  3712. if (Visible)
  3713. {
  3714. UpdateControls();
  3715. }
  3716. }
  3717. //---------------------------------------------------------------------------
  3718. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3719. TStrings * FileList, bool Alternative)
  3720. {
  3721. TCustomDirView * DView = DirView(Side);
  3722. DView->SaveSelection();
  3723. DView->SaveSelectedNames();
  3724. DebugAssert(!FAlternativeDelete);
  3725. FAlternativeDelete = Alternative;
  3726. try
  3727. {
  3728. if (!IsSideLocalBrowser(Side))
  3729. {
  3730. DebugAssert(Terminal != NULL);
  3731. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3732. }
  3733. else
  3734. {
  3735. if (IsLocalBrowserMode())
  3736. {
  3737. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3738. }
  3739. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3740. FProgressSide = FCurrentSide;
  3741. try
  3742. {
  3743. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3744. }
  3745. __finally
  3746. {
  3747. ReloadLocalDirectory();
  3748. }
  3749. }
  3750. FAlternativeDelete = false;
  3751. }
  3752. catch(...)
  3753. {
  3754. FAlternativeDelete = false;
  3755. DView->DiscardSavedSelection();
  3756. throw;
  3757. }
  3758. DView->RestoreSelection();
  3759. }
  3760. //---------------------------------------------------------------------------
  3761. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3762. {
  3763. DebugAssert(Terminal);
  3764. DebugAssert(!IsLocalBrowserMode());
  3765. RemoteDirView->SaveSelection();
  3766. RemoteDirView->SaveSelectedNames();
  3767. try
  3768. {
  3769. if (Lock)
  3770. {
  3771. Terminal->LockFiles(FileList);
  3772. }
  3773. else
  3774. {
  3775. Terminal->UnlockFiles(FileList);
  3776. }
  3777. }
  3778. catch(...)
  3779. {
  3780. RemoteDirView->DiscardSavedSelection();
  3781. throw;
  3782. }
  3783. RemoteDirView->RestoreSelection();
  3784. }
  3785. //---------------------------------------------------------------------------
  3786. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3787. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3788. bool NoConfirmation, bool Move)
  3789. {
  3790. DebugAssert(Terminal != NULL);
  3791. DebugAssert(!IsLocalBrowserMode());
  3792. // update Terminal->StateData->RemoteDirectory
  3793. UpdateTerminal(Terminal);
  3794. if (Session == NULL)
  3795. {
  3796. Session = TTerminalManager::Instance()->ActiveTerminal;
  3797. }
  3798. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3799. {
  3800. if (RemoteDriveView->DropTarget != NULL)
  3801. {
  3802. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3803. }
  3804. else if (RemoteDirView->DropTarget != NULL)
  3805. {
  3806. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3807. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3808. }
  3809. else
  3810. {
  3811. Target = RemoteDirView->Path;
  3812. }
  3813. }
  3814. else
  3815. {
  3816. Target = Session->StateData->RemoteDirectory;
  3817. }
  3818. Target = UnixIncludeTrailingBackslash(Target);
  3819. if (FileList->Count == 1)
  3820. {
  3821. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3822. }
  3823. else
  3824. {
  3825. FileMask = AnyMask;
  3826. }
  3827. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3828. bool Result = true;
  3829. if (!NoConfirmation)
  3830. {
  3831. bool Multi = (FileList->Count > 1);
  3832. if (Move)
  3833. {
  3834. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3835. }
  3836. else
  3837. {
  3838. TStrings * Sessions = TTerminalManager::Instance()->SessionList;
  3839. TStrings * Directories = new TStringList;
  3840. try
  3841. {
  3842. for (int Index = 0; Index < Sessions->Count; Index++)
  3843. {
  3844. TManagedTerminal * Terminal =
  3845. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3846. Directories->Add(Terminal->StateData->RemoteDirectory);
  3847. }
  3848. TDirectRemoteCopy AllowDirectCopy;
  3849. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3850. {
  3851. DebugAssert(DirectCopy);
  3852. AllowDirectCopy = drcAllow;
  3853. }
  3854. else if (Terminal->IsCapable[fcSecondaryShell])
  3855. {
  3856. DebugAssert(DirectCopy);
  3857. AllowDirectCopy = drcConfirmCommandSession;
  3858. }
  3859. else
  3860. {
  3861. DebugAssert(!DirectCopy);
  3862. AllowDirectCopy = drcDisallow;
  3863. }
  3864. void * ASession = Session;
  3865. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3866. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3867. Session = static_cast<TManagedTerminal *>(ASession);
  3868. }
  3869. __finally
  3870. {
  3871. delete Directories;
  3872. }
  3873. }
  3874. }
  3875. return Result;
  3876. }
  3877. //---------------------------------------------------------------------------
  3878. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3879. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3880. {
  3881. DebugAssert(!IsLocalBrowserMode());
  3882. bool DirectCopy;
  3883. UnicodeString Target, FileMask;
  3884. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3885. if (Result)
  3886. {
  3887. if (!Move && !DirectCopy)
  3888. {
  3889. Configuration->Usage->Inc("RemoteCopyTemp");
  3890. UnicodeString RootTempDir;
  3891. UnicodeString TempDir;
  3892. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3893. TStrings * TemporaryFilesList = new TStringList();
  3894. try
  3895. {
  3896. TMakeLocalFileListParams MakeFileListParam;
  3897. MakeFileListParam.FileList = TemporaryFilesList;
  3898. MakeFileListParam.FileTimes = NULL;
  3899. MakeFileListParam.IncludeDirs = true;
  3900. MakeFileListParam.Recursive = false;
  3901. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  3902. TTerminalManager::Instance()->ActiveSession = Session;
  3903. if (TemporaryFilesList->Count > 0)
  3904. {
  3905. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3906. CopyParam.FileMask = FileMask;
  3907. DebugAssert(!FAutoOperation);
  3908. FAutoOperation = true;
  3909. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3910. }
  3911. }
  3912. __finally
  3913. {
  3914. delete TemporaryFilesList;
  3915. FAutoOperation = false;
  3916. if (!RootTempDir.IsEmpty())
  3917. {
  3918. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3919. }
  3920. }
  3921. }
  3922. else
  3923. {
  3924. RemoteDirView->SaveSelection();
  3925. RemoteDirView->SaveSelectedNames();
  3926. try
  3927. {
  3928. if (Move)
  3929. {
  3930. Configuration->Usage->Inc("RemoteMove");
  3931. Terminal->MoveFiles(FileList, Target, FileMask);
  3932. }
  3933. else
  3934. {
  3935. Configuration->Usage->Inc("RemoteCopyDirect");
  3936. DebugAssert(DirectCopy);
  3937. DebugAssert(Session == Terminal);
  3938. if (Terminal->IsCapable[fcRemoteCopy] ||
  3939. Terminal->CommandSessionOpened ||
  3940. CommandSessionFallback())
  3941. {
  3942. Terminal->CopyFiles(FileList, Target, FileMask);
  3943. }
  3944. }
  3945. }
  3946. catch(...)
  3947. {
  3948. RemoteDirView->DiscardSavedSelection();
  3949. throw;
  3950. }
  3951. RemoteDirView->RestoreSelection();
  3952. }
  3953. }
  3954. return Result;
  3955. }
  3956. //---------------------------------------------------------------------------
  3957. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3958. const UnicodeString & Path, TRemoteProperties & Properties)
  3959. {
  3960. DebugAssert(!IsLocalBrowserMode());
  3961. Properties.Valid = Properties.Valid << vpEncrypt;
  3962. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3963. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3964. }
  3965. //---------------------------------------------------------------------------
  3966. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3967. {
  3968. Side = GetSide(Side);
  3969. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3970. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3971. UnicodeString Name = LoadStr(NEW_FOLDER);
  3972. int AllowedChanges =
  3973. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3974. bool SaveSettings = false;
  3975. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3976. {
  3977. TWindowLock Lock(this);
  3978. if (!IsSideLocalBrowser(Side))
  3979. {
  3980. if (SaveSettings)
  3981. {
  3982. GUIConfiguration->NewDirectoryProperties = Properties;
  3983. }
  3984. CreateRemoteDirectory(Name, Properties);
  3985. }
  3986. else
  3987. {
  3988. DirView(Side)->CreateDirectory(Name);
  3989. }
  3990. }
  3991. }
  3992. //---------------------------------------------------------------------------
  3993. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3994. {
  3995. TWindowLock Lock(this);
  3996. DirView(Side)->ExecuteHomeDirectory();
  3997. }
  3998. //---------------------------------------------------------------------------
  3999. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4000. {
  4001. DoOpenDirectoryDialog(odBrowse, Side);
  4002. }
  4003. //---------------------------------------------------------------------------
  4004. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4005. {
  4006. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4007. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4008. bool Result = !Path.IsEmpty();
  4009. if (Result)
  4010. {
  4011. // While we might get here when the session is closed (from location profiles),
  4012. // it's not a problem as the Path setter is noop then
  4013. DirView(Side)->Path = Path;
  4014. }
  4015. return Result;
  4016. }
  4017. //---------------------------------------------------------------------------
  4018. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4019. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4020. bool & Close)
  4021. {
  4022. // terminal can be already closed (e.g. dropped connection)
  4023. if (Terminal != NULL)
  4024. {
  4025. try
  4026. {
  4027. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4028. }
  4029. catch(...)
  4030. {
  4031. if (!Terminal->Active)
  4032. {
  4033. Close = true;
  4034. }
  4035. throw;
  4036. }
  4037. }
  4038. }
  4039. //---------------------------------------------------------------------------
  4040. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4041. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4042. bool & Close)
  4043. {
  4044. // terminal can be already closed (e.g. dropped connection)
  4045. if (Terminal != NULL)
  4046. {
  4047. Configuration->Usage->Inc(L"ChecksumCalculated");
  4048. try
  4049. {
  4050. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4051. }
  4052. catch(...)
  4053. {
  4054. if (!Terminal->Active)
  4055. {
  4056. Close = true;
  4057. }
  4058. throw;
  4059. }
  4060. }
  4061. }
  4062. //---------------------------------------------------------------------------
  4063. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4064. {
  4065. bool Result;
  4066. if (!IsSideLocalBrowser(Side))
  4067. {
  4068. TRemoteTokenList * GroupList = NULL;
  4069. TRemoteTokenList * UserList = NULL;
  4070. try
  4071. {
  4072. TRemoteProperties CurrentProperties;
  4073. if (Terminal->LoadFilesProperties(FileList))
  4074. {
  4075. RemoteDirView->Invalidate();
  4076. }
  4077. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4078. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4079. if (CapableGroupChanging || CapableOwnerChanging)
  4080. {
  4081. if (CapableGroupChanging)
  4082. {
  4083. GroupList = Terminal->Groups->Duplicate();
  4084. }
  4085. if (CapableOwnerChanging)
  4086. {
  4087. UserList = Terminal->Users->Duplicate();
  4088. }
  4089. TRemoteDirectory * Files = Terminal->Files;
  4090. int Count = Files->Count;
  4091. if (Count > 100)
  4092. {
  4093. Count = 100;
  4094. }
  4095. for (int Index = 0; Index < Count; Index++)
  4096. {
  4097. TRemoteFile * File = Files->Files[Index];
  4098. if (CapableGroupChanging)
  4099. {
  4100. GroupList->AddUnique(File->Group);
  4101. }
  4102. if (CapableOwnerChanging)
  4103. {
  4104. UserList->AddUnique(File->Owner);
  4105. }
  4106. }
  4107. // if we haven't collected tokens for all files in current directory,
  4108. // make sure we collect them at least for all selected files.
  4109. // (note that so far the files in FileList has to be from current direcotry)
  4110. if (Count < Files->Count)
  4111. {
  4112. for (int Index = 0; Index < FileList->Count; Index++)
  4113. {
  4114. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4115. if (CapableGroupChanging)
  4116. {
  4117. GroupList->AddUnique(File->Group);
  4118. }
  4119. if (CapableOwnerChanging)
  4120. {
  4121. UserList->AddUnique(File->Owner);
  4122. }
  4123. }
  4124. }
  4125. }
  4126. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4127. int Flags = 0;
  4128. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4129. if (CapableOwnerChanging) Flags |= cpOwner;
  4130. if (CapableGroupChanging) Flags |= cpGroup;
  4131. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4132. if (Terminal->IsCapable[fcCalculatingChecksum])
  4133. {
  4134. CalculateChecksumEvent = CalculateChecksum;
  4135. }
  4136. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4137. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4138. TRemoteProperties NewProperties = CurrentProperties;
  4139. Result =
  4140. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4141. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4142. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4143. CalculateSize, CalculateChecksumEvent);
  4144. if (Result)
  4145. {
  4146. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4147. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4148. }
  4149. }
  4150. __finally
  4151. {
  4152. delete GroupList;
  4153. delete UserList;
  4154. }
  4155. }
  4156. else
  4157. {
  4158. DirView(Side)->DisplayPropertiesMenu();
  4159. Result = true;
  4160. }
  4161. return Result;
  4162. }
  4163. //---------------------------------------------------------------------------
  4164. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4165. {
  4166. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4167. {
  4168. FIgnoreNextDialogChar = Key;
  4169. }
  4170. Key = 0;
  4171. }
  4172. //---------------------------------------------------------------------------
  4173. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4174. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4175. {
  4176. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4177. if (Command != NULL)
  4178. {
  4179. KeyProcessed(Key, Shift);
  4180. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4181. {
  4182. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4183. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4184. false, false, const_cast<TCustomCommandType *>(Command));
  4185. }
  4186. }
  4187. }
  4188. //---------------------------------------------------------------------------
  4189. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4190. {
  4191. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4192. {
  4193. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4194. }
  4195. if (!DirView(osCurrent)->IsEditing())
  4196. {
  4197. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4198. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4199. {
  4200. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4201. // But so far it's not a problem, as it does what we want.
  4202. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4203. if (((Action->ShortCut == KeyShortCut) ||
  4204. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4205. AllowedAction(Action, aaShortCut))
  4206. {
  4207. // Has to be called before the action as the dialog char is already in queue.
  4208. // So when the action consumes message queue, we already need to have the
  4209. // FIgnoreNextDialogChar set
  4210. KeyProcessed(Key, Shift);
  4211. // Reset reference to previous component (when menu/toolbar was clicked).
  4212. // Needed to detect that action was invoked by keyboard shortcut
  4213. // in TNonVisualDataModule::ExplorerActionsExecute
  4214. Action->ActionComponent = NULL;
  4215. Action->Execute();
  4216. return;
  4217. }
  4218. }
  4219. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4220. {
  4221. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4222. {
  4223. KeyProcessed(Key, Shift);
  4224. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4225. return;
  4226. }
  4227. }
  4228. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4229. {
  4230. KeyProcessed(Key, Shift);
  4231. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4232. }
  4233. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4234. if (IsCustomShortCut(CustomShortCut))
  4235. {
  4236. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4237. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4238. if (WinConfiguration->SharedBookmarks != NULL)
  4239. {
  4240. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4241. if ((Bookmark != NULL) &&
  4242. OpenBookmark(FCurrentSide, Bookmark))
  4243. {
  4244. KeyProcessed(Key, Shift);
  4245. }
  4246. }
  4247. }
  4248. }
  4249. TForm::KeyDown(Key, Shift);
  4250. }
  4251. //---------------------------------------------------------------------------
  4252. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4253. {
  4254. bool OpenedTerminal = false;
  4255. UnicodeString ProtocolName;
  4256. UnicodeString ProtocolNameHint;
  4257. UnicodeString SecurityProtocolName;
  4258. UnicodeString DurationHint;
  4259. // See the comment in TScpCommanderForm::UpdateControls()
  4260. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4261. if (ActiveTerminal != NULL)
  4262. {
  4263. // Active is not enough here
  4264. if (ActiveTerminal->Status == ssOpened)
  4265. {
  4266. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4267. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4268. if (FileSystemInfo.ProtocolName.IsEmpty())
  4269. {
  4270. ProtocolName = SessionInfo.ProtocolName;
  4271. }
  4272. else
  4273. {
  4274. ProtocolName = FileSystemInfo.ProtocolName;
  4275. }
  4276. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4277. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4278. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4279. OpenedTerminal = true;
  4280. }
  4281. else if (ActiveTerminal->Status > ssClosed)
  4282. {
  4283. ProtocolName = LoadStr(STATUS_CONNECTING);
  4284. }
  4285. else
  4286. {
  4287. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4288. }
  4289. }
  4290. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4291. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4292. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4293. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4294. if (ProtocolStatusPanel->Caption != ProtocolName)
  4295. {
  4296. ProtocolStatusPanel->Caption = ProtocolName;
  4297. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4298. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4299. }
  4300. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4301. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4302. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4303. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4304. SecurityStatusPanel->Enabled = SecurityEnabled;
  4305. UnicodeString SecurityProtocolHint;
  4306. if (SecurityEnabled)
  4307. {
  4308. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4309. }
  4310. else
  4311. {
  4312. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4313. }
  4314. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4315. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4316. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4317. DurationStatusPanel->Hint = DurationHint;
  4318. UpdateStatusBar();
  4319. }
  4320. //---------------------------------------------------------------------------
  4321. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4322. {
  4323. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4324. DebugAssert(SessionStatusBar != NULL);
  4325. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4326. if (!FNote.IsEmpty())
  4327. {
  4328. NoteStatusPanel->Caption = FNote;
  4329. }
  4330. else
  4331. {
  4332. UpdateStatusPanelText(NoteStatusPanel);
  4333. }
  4334. NoteStatusPanel->Hint = FNoteHints;
  4335. UnicodeString LoginTime;
  4336. // See the comment in TScpCommanderForm::UpdateControls()
  4337. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4338. // Active is not enough here
  4339. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4340. {
  4341. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4342. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4343. }
  4344. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4345. DurationStatusPanel->Caption = LoginTime;
  4346. }
  4347. //---------------------------------------------------------------------------
  4348. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4349. {
  4350. Panel->Caption = L"";
  4351. }
  4352. //---------------------------------------------------------------------------
  4353. void __fastcall TCustomScpExplorerForm::Idle()
  4354. {
  4355. if (FShowing || FStandaloneEditing)
  4356. {
  4357. FEditorManager->Check();
  4358. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4359. // that needs to know if queue view is visible (and it may be closed after queue update)
  4360. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4361. }
  4362. if (FShowing)
  4363. {
  4364. if (!NonVisualDataModule->Busy &&
  4365. // Menu is opened or drag&drop is going on
  4366. (Mouse->Capture == NULL))
  4367. {
  4368. if (FRefreshRemoteDirectory)
  4369. {
  4370. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4371. {
  4372. Terminal->RefreshDirectory();
  4373. }
  4374. FRefreshRemoteDirectory = false;
  4375. }
  4376. if (FRefreshLocalDirectory)
  4377. {
  4378. ReloadLocalDirectory();
  4379. FRefreshLocalDirectory = false;
  4380. }
  4381. if (WinConfiguration->RefreshRemotePanel)
  4382. {
  4383. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4384. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4385. {
  4386. RemoteDirView->ReloadDirectory();
  4387. }
  4388. }
  4389. }
  4390. }
  4391. if (FShowing || FStandaloneEditing)
  4392. {
  4393. if (FQueueStatusInvalidated)
  4394. {
  4395. UpdateQueueStatus(false);
  4396. }
  4397. RefreshQueueItems();
  4398. }
  4399. if (FShowing)
  4400. {
  4401. UpdateStatusBar();
  4402. }
  4403. FIgnoreNextDialogChar = 0;
  4404. }
  4405. //---------------------------------------------------------------------------
  4406. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4407. {
  4408. try
  4409. {
  4410. FUserActionTimer->Enabled = false;
  4411. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4412. {
  4413. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4414. {
  4415. FPendingQueueActionItem->ProcessUserAction();
  4416. }
  4417. }
  4418. }
  4419. __finally
  4420. {
  4421. FPendingQueueActionItem = NULL;
  4422. }
  4423. }
  4424. //---------------------------------------------------------------------------
  4425. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4426. {
  4427. if (WinConfiguration->MinimizeToTray)
  4428. {
  4429. UpdateTrayIcon();
  4430. FTrayIcon->Visible = true;
  4431. if (Visible)
  4432. {
  4433. ShowWindow(Handle, SW_HIDE);
  4434. }
  4435. }
  4436. }
  4437. //---------------------------------------------------------------------------
  4438. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4439. {
  4440. // WORKAROUND
  4441. // When restoring maximized window from minimization,
  4442. // rarely some controls do not align properly.
  4443. // Two instances seen (both for Commander):
  4444. // - When restoring, window is temporarily narrower (not maximized),
  4445. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4446. // Once maximized already, top dock shinks back, but the session PageControl,
  4447. // do not align up, leaving space between TopDock and PageControl.
  4448. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4449. for (int Index = 0; Index < ControlCount; Index++)
  4450. {
  4451. RealignControl(Controls[Index]);
  4452. }
  4453. if (FTrayIcon->Visible)
  4454. {
  4455. FTrayIcon->Visible = false;
  4456. if (Visible)
  4457. {
  4458. ShowWindow(Handle, SW_SHOW);
  4459. }
  4460. }
  4461. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4462. {
  4463. FNeedSession = false;
  4464. NonVisualDataModule->StartBusy();
  4465. try
  4466. {
  4467. NeedSession(true);
  4468. }
  4469. __finally
  4470. {
  4471. NonVisualDataModule->EndBusy();
  4472. }
  4473. }
  4474. }
  4475. //---------------------------------------------------------------------------
  4476. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4477. {
  4478. FTrayIcon->Hint = GetMainForm()->Caption;
  4479. }
  4480. //---------------------------------------------------------------------------
  4481. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4482. {
  4483. UpdateTrayIcon();
  4484. }
  4485. //---------------------------------------------------------------------------
  4486. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4487. {
  4488. // workaround
  4489. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4490. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4491. // But WM_ACTIVATEAPP message can be received even when
  4492. // the main window is minimized to the tray and internal editor window is focused
  4493. // (after another application was previously active)
  4494. if (::IsIconic(Handle))
  4495. {
  4496. if (!IsAppIconic())
  4497. {
  4498. SetAppIconic(true);
  4499. }
  4500. }
  4501. ::ApplicationRestore();
  4502. Application->BringToFront();
  4503. }
  4504. //---------------------------------------------------------------------------
  4505. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4506. {
  4507. RestoreApp();
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4511. {
  4512. if (OpenInNewWindow())
  4513. {
  4514. // todo: Pass FromSite
  4515. ExecuteNewInstance(SessionUrl);
  4516. }
  4517. else
  4518. {
  4519. TTerminalManager::Instance()->NewSession(SessionUrl);
  4520. }
  4521. }
  4522. //---------------------------------------------------------------------------
  4523. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4524. {
  4525. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4526. StoredSessions->NewSession(SessionName, SessionData);
  4527. // modified only, explicit
  4528. StoredSessions->Save(false, true);
  4529. // encode session name because of slashes in hierarchical sessions
  4530. return EncodeUrlString(SessionName);
  4531. }
  4532. //---------------------------------------------------------------------------
  4533. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4534. {
  4535. // current working directories become defaults here, what is not right
  4536. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4537. return SaveHiddenDuplicateSession(SessionData.get());
  4538. }
  4539. //---------------------------------------------------------------------------
  4540. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4541. {
  4542. if (OpenInNewWindow())
  4543. {
  4544. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4545. }
  4546. else
  4547. {
  4548. // current working directories become defaults here, what is not right
  4549. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4550. TTerminalManager * Manager = TTerminalManager::Instance();
  4551. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4552. Manager->ActiveSession = Terminal;
  4553. }
  4554. }
  4555. //---------------------------------------------------------------------------
  4556. void __fastcall TCustomScpExplorerForm::RenameSession()
  4557. {
  4558. UnicodeString Name = Terminal->SessionData->SessionName;
  4559. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4560. {
  4561. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4562. TSessionData::ValidateName(Name);
  4563. // This is inconsistent with how color (for example) is handled.
  4564. Terminal->SessionData->Name = Name;
  4565. UpdateControls();
  4566. // Add/Remove distinguishing paths from sessions of the same name.
  4567. SessionListChanged();
  4568. }
  4569. }
  4570. //---------------------------------------------------------------------------
  4571. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4572. {
  4573. DebugAssert(Queue != NULL);
  4574. bool Result = Queue->IsEmpty;
  4575. if (!Result)
  4576. {
  4577. SetFocus();
  4578. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4579. }
  4580. return Result;
  4581. }
  4582. //---------------------------------------------------------------------------
  4583. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4584. {
  4585. return CanCloseQueue(FQueue);
  4586. }
  4587. //---------------------------------------------------------------------------
  4588. void __fastcall TCustomScpExplorerForm::CloseSession()
  4589. {
  4590. if (CanCloseQueue())
  4591. {
  4592. TTerminalManager::Instance()->FreeActiveTerminal();
  4593. }
  4594. }
  4595. //---------------------------------------------------------------------------
  4596. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4597. {
  4598. if (CanCloseQueue())
  4599. {
  4600. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4601. }
  4602. }
  4603. //---------------------------------------------------------------------------
  4604. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4605. {
  4606. DetachTerminal(Terminal);
  4607. RemoteDirView->Terminal = Terminal;
  4608. UpdateRemotePathComboBox(false);
  4609. InitStatusBar();
  4610. UpdateControls();
  4611. }
  4612. //---------------------------------------------------------------------------
  4613. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4614. {
  4615. InitStatusBar();
  4616. }
  4617. //---------------------------------------------------------------------------
  4618. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4619. {
  4620. if (DebugAlwaysTrue(!Terminal->Active))
  4621. {
  4622. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4623. }
  4624. }
  4625. //---------------------------------------------------------------------------
  4626. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4627. {
  4628. if (OpenInNewWindow())
  4629. {
  4630. // encode session name because of slashes in hierarchical sessions
  4631. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4632. }
  4633. else
  4634. {
  4635. TTerminalManager * Manager = TTerminalManager::Instance();
  4636. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4637. Manager->ActiveSession = Terminal;
  4638. }
  4639. }
  4640. //---------------------------------------------------------------------------
  4641. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4642. {
  4643. TTerminalManager * Manager = TTerminalManager::Instance();
  4644. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4645. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4646. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4647. // FirstTerminal can be null, if some of the
  4648. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4649. {
  4650. FirstTerminal->Disconnected = true;
  4651. FirstTerminal->DisconnectedTemporarily = true;
  4652. }
  4653. Manager->ActiveSession = FirstTerminal;
  4654. }
  4655. //---------------------------------------------------------------------------
  4656. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4657. {
  4658. if (OpenInNewWindow())
  4659. {
  4660. ExecuteNewInstance(Name);
  4661. }
  4662. else
  4663. {
  4664. DoOpenFolderOrWorkspace(Name, true);
  4665. }
  4666. }
  4667. //---------------------------------------------------------------------------
  4668. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4669. bool &CanClose)
  4670. {
  4671. // See the comment in CloseApp()
  4672. if (NonVisualDataModule->Busy)
  4673. {
  4674. CanClose = false;
  4675. }
  4676. else if (Terminal != NULL)
  4677. {
  4678. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4679. {
  4680. unsigned int Result;
  4681. TMessageParams Params(mpNeverAskAgainCheck);
  4682. UnicodeString Message;
  4683. int Answers = qaOK | qaCancel;
  4684. if (TTerminalManager::Instance()->Count > 1)
  4685. {
  4686. if (!WinConfiguration->AutoSaveWorkspace)
  4687. {
  4688. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4689. }
  4690. else
  4691. {
  4692. Message = LoadStr(CLOSE_SESSIONS);
  4693. }
  4694. }
  4695. else
  4696. {
  4697. if (!WinConfiguration->AutoSaveWorkspace)
  4698. {
  4699. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4700. }
  4701. else
  4702. {
  4703. Message = LoadStr(CLOSE_SESSION);
  4704. }
  4705. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4706. }
  4707. UnicodeString Note;
  4708. if (WinConfiguration->AutoSaveWorkspace)
  4709. {
  4710. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4711. }
  4712. else
  4713. {
  4714. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4715. Answers = qaYes | qaNo | qaCancel;
  4716. }
  4717. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4718. SetFocus();
  4719. Result = MessageDialog(Message, qtConfirmation,
  4720. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4721. if (Result == qaNeverAskAgain)
  4722. {
  4723. WinConfiguration->ConfirmClosingSession = false;
  4724. }
  4725. if (Result == qaNo)
  4726. {
  4727. CanClose = SaveWorkspace(true);
  4728. // note that the workspace will be saved redundatly again from FormClose
  4729. }
  4730. else
  4731. {
  4732. CanClose =
  4733. (Result == qaOK) ||
  4734. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4735. (Result == qaNeverAskAgain);
  4736. }
  4737. }
  4738. if (CanClose)
  4739. {
  4740. CanClose = CanCloseQueue();
  4741. }
  4742. }
  4743. if (CanClose)
  4744. {
  4745. CanClose =
  4746. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4747. FEditorManager->CloseExternalFilesWithoutProcess();
  4748. if (CanClose)
  4749. {
  4750. while (CanClose && (FLocalEditors->Count > 0))
  4751. {
  4752. int PrevCount = FLocalEditors->Count;
  4753. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4754. CanClose = (FLocalEditors->Count < PrevCount);
  4755. }
  4756. if (CanClose)
  4757. {
  4758. CanClose = FEditorManager->Empty(true);
  4759. if (!CanClose)
  4760. {
  4761. SetFocus();
  4762. CanClose =
  4763. (MessageDialog(
  4764. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4765. }
  4766. }
  4767. }
  4768. }
  4769. }
  4770. //---------------------------------------------------------------------------
  4771. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4772. {
  4773. TForm * Form = dynamic_cast<TForm *>(Sender);
  4774. DebugAssert(Form != NULL);
  4775. Form->Close();
  4776. }
  4777. //---------------------------------------------------------------------------
  4778. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4779. {
  4780. TForm * Form = dynamic_cast<TForm *>(Sender);
  4781. delete Form;
  4782. }
  4783. //---------------------------------------------------------------------------
  4784. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4785. {
  4786. while (FLocalEditors->Count > 0)
  4787. {
  4788. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4789. }
  4790. }
  4791. //---------------------------------------------------------------------------
  4792. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4793. TObject *Sender)
  4794. {
  4795. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4796. try
  4797. {
  4798. SetProperties(osRemote, FileList);
  4799. }
  4800. __finally
  4801. {
  4802. delete FileList;
  4803. }
  4804. }
  4805. //---------------------------------------------------------------------------
  4806. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4807. {
  4808. if (value)
  4809. {
  4810. if (Component == fcCustomCommandsBand)
  4811. {
  4812. UpdateCustomCommandsToolbar();
  4813. }
  4814. if (Component == fcQueueFileList)
  4815. {
  4816. DebugAssert(!QueueFileListSplitter->Visible);
  4817. AdjustQueueLayout();
  4818. UpdateQueueFileList();
  4819. }
  4820. }
  4821. }
  4822. //---------------------------------------------------------------------------
  4823. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4824. {
  4825. int MinHeightLimit =
  4826. GetStaticQueuePanelComponentsHeight() +
  4827. QueueFileListSplitter->Height +
  4828. QueueFileList->Height +
  4829. GetMinQueueViewHeight();
  4830. if (QueuePanel->ClientHeight < MinHeightLimit)
  4831. {
  4832. QueuePanel->ClientHeight = MinHeightLimit;
  4833. }
  4834. }
  4835. //---------------------------------------------------------------------------
  4836. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4837. {
  4838. TControl * Control = GetComponent(Component);
  4839. DebugAssert(Control);
  4840. bool Changed = (Control->Visible != value);
  4841. if (Changed)
  4842. {
  4843. ComponentShowing(Component, value);
  4844. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4845. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4846. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4847. if (value)
  4848. {
  4849. int RemainingHeight = Control->Parent->ClientHeight;
  4850. int RemainingWidth = Control->Parent->ClientWidth;
  4851. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4852. {
  4853. TControl * ChildControl = Control->Parent->Controls[i];
  4854. if (ChildControl->Visible)
  4855. {
  4856. switch (ChildControl->Align)
  4857. {
  4858. case alTop:
  4859. case alBottom:
  4860. RemainingHeight -= ChildControl->Height;
  4861. break;
  4862. case alLeft:
  4863. case alRight:
  4864. RemainingWidth -= ChildControl->Width;
  4865. break;
  4866. }
  4867. }
  4868. }
  4869. int Reserve = ScaleByTextHeight(this, 32);
  4870. // queue in explorer, trees in commander
  4871. if (Control->Height > RemainingHeight - Reserve)
  4872. {
  4873. Control->Height = RemainingHeight / 2;
  4874. }
  4875. if (Control->Width > RemainingWidth - Reserve)
  4876. {
  4877. Control->Width = RemainingWidth / 2;
  4878. }
  4879. }
  4880. Control->Visible = value;
  4881. if (WasFocused && Visible)
  4882. {
  4883. DirView(osCurrent)->SetFocus();
  4884. }
  4885. FixControlsPlacement();
  4886. }
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4890. {
  4891. TControl * Control = GetComponent(Component);
  4892. if (Control == NULL)
  4893. {
  4894. return false;
  4895. }
  4896. else
  4897. {
  4898. return Control->Visible;
  4899. }
  4900. }
  4901. //---------------------------------------------------------------------------
  4902. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4903. {
  4904. bool Result;
  4905. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4906. {
  4907. Result = !IsUWP();
  4908. }
  4909. else
  4910. {
  4911. Result = true;
  4912. }
  4913. return Result;
  4914. }
  4915. //---------------------------------------------------------------------------
  4916. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4917. {
  4918. if (DirView->ItemFocused != NULL)
  4919. {
  4920. DirView->ItemFocused->MakeVisible(false);
  4921. }
  4922. }
  4923. //---------------------------------------------------------------------------
  4924. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4925. {
  4926. MakeFocusedItemVisible(RemoteDirView);
  4927. QueueSplitter->Visible = QueuePanel->Visible;
  4928. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4929. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4930. TControl * QueueControlsOrder[] =
  4931. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4932. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4933. }
  4934. //---------------------------------------------------------------------------
  4935. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4936. {
  4937. switch (Component) {
  4938. case fcStatusBar: return RemoteStatusBar;
  4939. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4940. case fcQueueView: return QueuePanel;
  4941. case fcQueueToolbar: return QueueDock;
  4942. case fcRemoteTree: return RemoteDrivePanel;
  4943. case fcSessionsTabs: return SessionsPageControl;
  4944. case fcQueueFileList: return QueueFileList;
  4945. default: return NULL;
  4946. }
  4947. }
  4948. //---------------------------------------------------------------------------
  4949. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4950. TObject *Sender, TListColumn *Column, TPoint &Point)
  4951. {
  4952. DebugAssert(NonVisualDataModule && Column && Sender);
  4953. NonVisualDataModule->ListColumn = Column;
  4954. TPopupMenu * DirViewColumnMenu;
  4955. if (Sender == DirView(osOther))
  4956. {
  4957. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4958. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4959. (Column->Index == uvName);
  4960. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4961. (Column->Index == uvSize);
  4962. }
  4963. else
  4964. {
  4965. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4966. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4967. (Column->Index == dvName);
  4968. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4969. (Column->Index == dvSize);
  4970. }
  4971. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4972. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4973. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4974. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4975. }
  4976. //---------------------------------------------------------------------------
  4977. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4978. TObject *Sender, TListItem *Item, bool &AllowExec)
  4979. {
  4980. DoDirViewExecFile(Sender, Item, AllowExec);
  4981. }
  4982. //---------------------------------------------------------------------------
  4983. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4984. TListItem * Item, bool & AllowExec)
  4985. {
  4986. DebugAssert(Sender && Item && Configuration);
  4987. DebugAssert(AllowExec);
  4988. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4989. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4990. bool Remote = !IsSideLocalBrowser(Side);
  4991. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4992. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4993. // on files only (not directories)
  4994. // and only when symlinks are resolved (apply to remote panel only)
  4995. if (!ADirView->ItemIsDirectory(Item) &&
  4996. (ResolvedSymlinks || FForceExecution))
  4997. {
  4998. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4999. !FForceExecution && ResolvedSymlinks)
  5000. {
  5001. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5002. {
  5003. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5004. UnlockWindow();
  5005. try
  5006. {
  5007. if (IsLocalBrowserMode())
  5008. {
  5009. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5010. }
  5011. else
  5012. {
  5013. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5014. }
  5015. }
  5016. __finally
  5017. {
  5018. LockWindow();
  5019. }
  5020. AllowExec = false;
  5021. }
  5022. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5023. {
  5024. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5025. {
  5026. ExecuteFile(Side, efDefaultEditor);
  5027. AllowExec = false;
  5028. }
  5029. }
  5030. else
  5031. {
  5032. DebugFail();
  5033. }
  5034. }
  5035. // if we have not done anything special, fall back to default behavior
  5036. if (AllowExec)
  5037. {
  5038. if (Remote && !WinConfiguration->DisableOpenEdit)
  5039. {
  5040. ExecuteFile(osRemote, efShell);
  5041. AllowExec = false;
  5042. }
  5043. }
  5044. }
  5045. }
  5046. //---------------------------------------------------------------------------
  5047. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5048. {
  5049. return ((Side == osRemote) || (Side == osCurrent));
  5050. }
  5051. //---------------------------------------------------------------------------
  5052. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5053. {
  5054. DebugFail();
  5055. }
  5056. //---------------------------------------------------------------------------
  5057. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5058. {
  5059. DebugFail();
  5060. }
  5061. //---------------------------------------------------------------------------
  5062. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5063. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5064. {
  5065. TSynchronizeParamType Params;
  5066. Params.LocalDirectory = LocalDirectory;
  5067. Params.RemoteDirectory = RemoteDirectory;
  5068. int UnusedParams =
  5069. (GUIConfiguration->SynchronizeParams &
  5070. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5071. TTerminal::spCaseSensitive));
  5072. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5073. Params.Options = GUIConfiguration->SynchronizeOptions;
  5074. bool SaveSettings = false;
  5075. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5076. &DoSynchronizeTooManyDirectories);
  5077. DebugAssert(FSynchronizeController == NULL);
  5078. FSynchronizeController = &Controller;
  5079. bool Result;
  5080. try
  5081. {
  5082. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5083. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5084. int Options =
  5085. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5086. DebugAssert(FOnFeedSynchronizeError == NULL);
  5087. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5088. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5089. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5090. if (Result)
  5091. {
  5092. if (SaveSettings)
  5093. {
  5094. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5095. GUIConfiguration->SynchronizeOptions = Params.Options;
  5096. }
  5097. else
  5098. {
  5099. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5100. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5101. FLAGSET(Params.Options, soSynchronize))
  5102. {
  5103. GUIConfiguration->SynchronizeOptions =
  5104. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5105. soSynchronize;
  5106. }
  5107. }
  5108. LocalDirectory = Params.LocalDirectory;
  5109. RemoteDirectory = Params.RemoteDirectory;
  5110. }
  5111. }
  5112. __finally
  5113. {
  5114. FSynchronizeController = NULL;
  5115. DebugAssert(FOnFeedSynchronizeError == NULL);
  5116. FOnFeedSynchronizeError = NULL;
  5117. }
  5118. return Result;
  5119. }
  5120. //---------------------------------------------------------------------------
  5121. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5122. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5123. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5124. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5125. TSynchronizeOptions * Options, bool Full)
  5126. {
  5127. // Keep-up-to-date mode
  5128. if (Terminal->Status == ssOpened)
  5129. {
  5130. try
  5131. {
  5132. int PParams = Params.Params;
  5133. if (!Full)
  5134. {
  5135. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5136. if (FLAGSET(Params.Options, soRecurse))
  5137. {
  5138. PParams |= TTerminal::spSubDirs;
  5139. }
  5140. }
  5141. else
  5142. {
  5143. // if keepuptodate is non-recursive,
  5144. // full sync before has to be non-recursive as well
  5145. if (FLAGCLEAR(Params.Options, soRecurse))
  5146. {
  5147. PParams |= TTerminal::spNoRecurse;
  5148. }
  5149. }
  5150. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5151. PParams, Checklist, Options);
  5152. }
  5153. catch (Exception & E)
  5154. {
  5155. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5156. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5157. {
  5158. // noop, already logged in MoreMessageDialog
  5159. }
  5160. else
  5161. {
  5162. ShowExtendedExceptionEx(Terminal, &E);
  5163. throw;
  5164. }
  5165. }
  5166. }
  5167. }
  5168. //---------------------------------------------------------------------------
  5169. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5170. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5171. const UnicodeString ErrorStr)
  5172. {
  5173. if (!Directory.IsEmpty())
  5174. {
  5175. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5176. }
  5177. else
  5178. {
  5179. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5180. }
  5181. }
  5182. //---------------------------------------------------------------------------
  5183. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5184. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5185. {
  5186. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5187. {
  5188. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5189. }
  5190. else
  5191. {
  5192. TMessageParams Params(mpNeverAskAgainCheck);
  5193. unsigned int Result = MessageDialog(
  5194. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5195. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5196. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5197. {
  5198. MaxDirectories *= 2;
  5199. if (Result == qaNeverAskAgain)
  5200. {
  5201. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5202. }
  5203. }
  5204. else
  5205. {
  5206. Abort();
  5207. }
  5208. }
  5209. }
  5210. //---------------------------------------------------------------------------
  5211. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5212. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5213. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5214. TSynchronizeOptions * Options)
  5215. {
  5216. // Keep-up-to-date mode
  5217. DebugAssert(!FAutoOperation);
  5218. void * BatchStorage;
  5219. BatchStart(BatchStorage);
  5220. FAutoOperation = true;
  5221. bool AnyOperation = false;
  5222. TDateTime StartTime = Now();
  5223. TSynchronizeChecklist * AChecklist = NULL;
  5224. try
  5225. {
  5226. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5227. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5228. {
  5229. FSynchronizeProgressForm->Start();
  5230. }
  5231. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5232. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5233. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5234. Options);
  5235. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5236. SAFE_DESTROY(FSynchronizeProgressForm);
  5237. AnyOperation = (AChecklist->CheckedCount > 0);
  5238. if (AnyOperation)
  5239. {
  5240. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5241. CreateProgressForm(&SynchronizeProgress);
  5242. try
  5243. {
  5244. Terminal->SynchronizeApply(
  5245. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5246. SynchronizeProcessedItem, NULL, NULL, NULL);
  5247. }
  5248. __finally
  5249. {
  5250. DestroyProgressForm();
  5251. }
  5252. }
  5253. }
  5254. __finally
  5255. {
  5256. if (Checklist == NULL)
  5257. {
  5258. delete AChecklist;
  5259. }
  5260. else
  5261. {
  5262. *Checklist = AChecklist;
  5263. }
  5264. FAutoOperation = false;
  5265. SAFE_DESTROY(FSynchronizeProgressForm);
  5266. BatchEnd(BatchStorage);
  5267. ReloadLocalDirectory();
  5268. if (AnyOperation)
  5269. {
  5270. OperationComplete(StartTime);
  5271. }
  5272. }
  5273. }
  5274. //---------------------------------------------------------------------------
  5275. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5276. {
  5277. // can be called from command line
  5278. return Visible &&
  5279. ((DirView(osRemote)->SelCount > 0) ||
  5280. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5281. }
  5282. //---------------------------------------------------------------------------
  5283. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5284. {
  5285. LogSynchronizeEvent(Terminal, Message);
  5286. }
  5287. //---------------------------------------------------------------------------
  5288. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5289. int Params, TSynchronizeOptions & Options)
  5290. {
  5291. DebugAssert(!IsLocalBrowserMode());
  5292. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5293. {
  5294. Options.Filter = new TStringList();
  5295. Options.Filter->CaseSensitive = false;
  5296. Options.Filter->Duplicates = Types::dupAccept;
  5297. if (DirView(osRemote)->SelCount > 0)
  5298. {
  5299. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5300. }
  5301. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5302. {
  5303. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5304. }
  5305. Options.Filter->Sort();
  5306. }
  5307. }
  5308. //---------------------------------------------------------------------------
  5309. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5310. {
  5311. TCopyParamType Defaults;
  5312. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5313. ConfigStorage->AccessMode = smRead;
  5314. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5315. {
  5316. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5317. }
  5318. ConfigStorage.reset(NULL);
  5319. std::unique_ptr<TStringList> Options(new TStringList());
  5320. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5321. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5322. UnicodeString Result;
  5323. if (Options->Count > 0)
  5324. {
  5325. Result =
  5326. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5327. }
  5328. return Result;
  5329. }
  5330. //---------------------------------------------------------------------------
  5331. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5332. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5333. {
  5334. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5335. UnicodeString AdditionalParams =
  5336. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5337. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5338. SerializeCopyParamForCommandLine(CopyParams),
  5339. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5340. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5341. ExecuteNewInstance(SessionName, AdditionalParams);
  5342. }
  5343. //---------------------------------------------------------------------------
  5344. struct TSynchronizeParams
  5345. {
  5346. UnicodeString LocalDirectory;
  5347. UnicodeString RemoteDirectory;
  5348. TSynchronizeMode Mode;
  5349. TSynchronizeChecklist * Checklist;
  5350. int Params;
  5351. TCopyParamType * CopyParam;
  5352. TDateTime CollectElapsed;
  5353. TDateTime * StartTime;
  5354. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5355. };
  5356. //---------------------------------------------------------------------------
  5357. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5358. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5359. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5360. {
  5361. DebugAssert(!FAutoOperation);
  5362. void * BatchStorage;
  5363. BatchStart(BatchStorage);
  5364. FAutoOperation = true;
  5365. TFileOperationStatistics Statistics;
  5366. TDateTime Start = Now();
  5367. try
  5368. {
  5369. Params.OnProcessedItem = OnProcessedItem;
  5370. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5371. CreateProgressForm(&SynchronizeProgress);
  5372. Terminal->SynchronizeApply(
  5373. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5374. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5375. &Statistics);
  5376. }
  5377. __finally
  5378. {
  5379. Params.OnProcessedItem = NULL;
  5380. FAutoOperation = false;
  5381. DestroyProgressForm();
  5382. BatchEnd(BatchStorage);
  5383. ReloadLocalDirectory();
  5384. }
  5385. if (WinConfiguration->SynchronizeSummary)
  5386. {
  5387. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5388. // The statistics should be 0 anyway in this case
  5389. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5390. {
  5391. Message += L"\n";
  5392. if (Statistics.FilesUploaded > 0)
  5393. {
  5394. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5395. }
  5396. if (Statistics.FilesDownloaded > 0)
  5397. {
  5398. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5399. }
  5400. if (Statistics.FilesDeletedLocal > 0)
  5401. {
  5402. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5403. }
  5404. if (Statistics.FilesDeletedRemote > 0)
  5405. {
  5406. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5407. }
  5408. }
  5409. TDateTime Elapsed = (Now() - Start);
  5410. Message +=
  5411. L"\n" +
  5412. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5413. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5414. TMessageParams Params(mpNeverAskAgainCheck);
  5415. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5416. if (Result == qaNeverAskAgain)
  5417. {
  5418. WinConfiguration->SynchronizeSummary = false;
  5419. }
  5420. }
  5421. }
  5422. //---------------------------------------------------------------------------
  5423. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5424. {
  5425. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5426. {
  5427. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5428. }
  5429. // Not set in keep-up-to-date mode - Synchronize() method
  5430. if (Token != NULL)
  5431. {
  5432. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5433. if (Params.OnProcessedItem != NULL)
  5434. {
  5435. Params.OnProcessedItem(NULL, ChecklistItem);
  5436. }
  5437. }
  5438. }
  5439. //---------------------------------------------------------------------------
  5440. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5441. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5442. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5443. {
  5444. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5445. *Params.StartTime = Now();
  5446. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5447. }
  5448. //---------------------------------------------------------------------------
  5449. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5450. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5451. {
  5452. // terminal can be already closed (e.g. dropped connection)
  5453. if (Terminal != NULL)
  5454. {
  5455. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5456. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5457. }
  5458. }
  5459. //---------------------------------------------------------------------------
  5460. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5461. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5462. {
  5463. DebugAssert(!IsLocalBrowserMode());
  5464. TAutoBatch AutoBatch(this);
  5465. TAutoFlag AutoOperationFlag(FAutoOperation);
  5466. if (Side == osRemote)
  5467. {
  5468. std::unique_ptr<TStrings> FileList(new TStringList());
  5469. FileList->AddObject(FileName, RemoteFile);
  5470. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5471. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5472. RemoteDirView->SaveSelection();
  5473. RemoteDirView->SaveSelectedNames();
  5474. try
  5475. {
  5476. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5477. }
  5478. catch(...)
  5479. {
  5480. RemoteDirView->DiscardSavedSelection();
  5481. throw;
  5482. }
  5483. RemoteDirView->RestoreSelection();
  5484. }
  5485. else if (DebugAlwaysTrue(Side == osLocal))
  5486. {
  5487. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5488. {
  5489. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5490. }
  5491. UnicodeString Directory = ExtractFileDir(FileName);
  5492. ReloadLocalDirectory(Directory);
  5493. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5494. if (!SamePaths(Directory, NewDirectory))
  5495. {
  5496. ReloadLocalDirectory(NewDirectory);
  5497. }
  5498. }
  5499. }
  5500. //---------------------------------------------------------------------------
  5501. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5502. {
  5503. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5504. if (Side == osLocal)
  5505. {
  5506. if (Action == TSynchronizeChecklist::saDownloadNew)
  5507. {
  5508. OpenFolderInExplorer(LocalPath);
  5509. }
  5510. else
  5511. {
  5512. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5513. }
  5514. }
  5515. else if (DebugAlwaysTrue(Side == osRemote))
  5516. {
  5517. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5518. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5519. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5520. if (!LocalPath.IsEmpty())
  5521. {
  5522. SessionData->LocalDirectory = LocalPath;
  5523. }
  5524. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5525. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5526. }
  5527. }
  5528. //---------------------------------------------------------------------------
  5529. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5530. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5531. const TCopyParamType * CopyParams)
  5532. {
  5533. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5534. UnicodeString AdditionalParams =
  5535. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5536. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5537. SerializeCopyParamForCommandLine(CopyParams),
  5538. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5539. LocalDirectory, RemoteDirectory, Mode, Params));
  5540. ExecuteNewInstance(SessionName, AdditionalParams);
  5541. }
  5542. //---------------------------------------------------------------------------
  5543. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5544. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5545. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5546. {
  5547. int Result;
  5548. bool SaveSettings = false;
  5549. int Options =
  5550. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5551. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5552. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5553. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5554. bool Continue =
  5555. (UseDefaults == 0) ||
  5556. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5557. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5558. if (Continue)
  5559. {
  5560. Configuration->Usage->Inc(L"Synchronizations");
  5561. UpdateCopyParamCounters(CopyParam);
  5562. TSynchronizeOptions SynchronizeOptions;
  5563. GetSynchronizeOptions(Params, SynchronizeOptions);
  5564. if (SaveSettings)
  5565. {
  5566. GUIConfiguration->SynchronizeParams = Params;
  5567. }
  5568. else
  5569. {
  5570. SaveMode = false;
  5571. }
  5572. TDateTime StartTime = Now();
  5573. TSynchronizeChecklist * Checklist = NULL;
  5574. try
  5575. {
  5576. DebugAssert(!FAutoOperation);
  5577. FAutoOperation = true;
  5578. try
  5579. {
  5580. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5581. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5582. int Files = -1;
  5583. if (DataList->Count >= 1)
  5584. {
  5585. Files = StrToIntDef(DataList->Strings[0], Files);
  5586. }
  5587. else
  5588. {
  5589. DataList->Add(UnicodeString());
  5590. }
  5591. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5592. FSynchronizeProgressForm->Start();
  5593. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5594. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5595. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5596. &SynchronizeOptions);
  5597. if (Terminal->SessionData->CacheDirectories)
  5598. {
  5599. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5600. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5601. }
  5602. }
  5603. __finally
  5604. {
  5605. FAutoOperation = false;
  5606. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5607. SAFE_DESTROY(FSynchronizeProgressForm);
  5608. }
  5609. TSynchronizeParams SynchronizeParams;
  5610. SynchronizeParams.LocalDirectory = LocalDirectory;
  5611. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5612. SynchronizeParams.Mode = Mode;
  5613. SynchronizeParams.CopyParam = &CopyParam;
  5614. SynchronizeParams.Params = Params;
  5615. SynchronizeParams.Checklist = Checklist;
  5616. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5617. SynchronizeParams.StartTime = &StartTime;
  5618. SynchronizeParams.OnProcessedItem = NULL;
  5619. Result = Checklist->Count;
  5620. if (Checklist->Count > 0)
  5621. {
  5622. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5623. {
  5624. if (!DoSynchronizeChecklistDialog(
  5625. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5626. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5627. {
  5628. Result = -1;
  5629. }
  5630. }
  5631. else
  5632. {
  5633. FullSynchronize(SynchronizeParams, NULL, NULL);
  5634. }
  5635. }
  5636. else
  5637. {
  5638. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5639. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5640. }
  5641. }
  5642. __finally
  5643. {
  5644. delete Checklist;
  5645. }
  5646. OperationComplete(StartTime);
  5647. }
  5648. else
  5649. {
  5650. Result = -1;
  5651. }
  5652. return Result;
  5653. }
  5654. //---------------------------------------------------------------------------
  5655. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5656. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5657. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5658. {
  5659. if (Collect)
  5660. {
  5661. DebugAssert(FSynchronizeProgressForm != NULL);
  5662. if (!FSynchronizeProgressForm->Started)
  5663. {
  5664. FSynchronizeProgressForm->Start();
  5665. }
  5666. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5667. SetTaskbarListProgressValue(CompareProgress);
  5668. }
  5669. else
  5670. {
  5671. DebugAssert(FSynchronizeProgressForm == NULL);
  5672. DebugAssert(FProgressForm != NULL);
  5673. }
  5674. }
  5675. //---------------------------------------------------------------------------
  5676. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5677. {
  5678. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5679. TRemoteFile * File = NULL;
  5680. Terminal->ReadFile(FullFileName, File);
  5681. if (File != NULL)
  5682. {
  5683. std::unique_ptr<TRemoteFile> FileOwner(File);
  5684. TAutoFlag Flag(FStandaloneEditing);
  5685. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5686. Application->ShowMainForm = false;
  5687. Application->Run();
  5688. }
  5689. }
  5690. //---------------------------------------------------------------------------
  5691. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5692. {
  5693. DebugFail();
  5694. }
  5695. //---------------------------------------------------------------------------
  5696. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5697. {
  5698. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5699. SessionData->Assign(Terminal->SessionData);
  5700. UpdateSessionData(SessionData.get());
  5701. Terminal->UpdateSessionCredentials(SessionData.get());
  5702. if (!Terminal->SessionData->HasSessionName())
  5703. {
  5704. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5705. // once IsWorkspace is cleared
  5706. SessionData->Name = UnicodeString();
  5707. SessionData->IsWorkspace = false;
  5708. }
  5709. return SessionData.release();
  5710. }
  5711. //---------------------------------------------------------------------------
  5712. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5713. {
  5714. TSessionData * SessionData = CloneCurrentSessionData();
  5715. try
  5716. {
  5717. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5718. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5719. }
  5720. __finally
  5721. {
  5722. delete SessionData;
  5723. }
  5724. }
  5725. //---------------------------------------------------------------------------
  5726. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5727. {
  5728. TTerminalManager * Manager = TTerminalManager::Instance();
  5729. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5730. if (DebugAlwaysTrue(Terminal != NULL))
  5731. {
  5732. // Update (Managed)Terminal->StateData
  5733. UpdateTerminal(Terminal);
  5734. }
  5735. Manager->SaveWorkspace(DataList.get());
  5736. return DataList.release();
  5737. }
  5738. //---------------------------------------------------------------------------
  5739. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5740. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5741. {
  5742. WinConfiguration->LastWorkspace = Name;
  5743. if (!SavePasswords)
  5744. {
  5745. for (int Index = 0; Index < DataList->Count; Index++)
  5746. {
  5747. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5748. if (SessionData->Link.IsEmpty())
  5749. {
  5750. SessionData->ClearSessionPasswords();
  5751. }
  5752. }
  5753. }
  5754. StoredSessions->NewWorkspace(Name, DataList);
  5755. // modified only
  5756. StoredSessions->Save(false, Explicit);
  5757. }
  5758. //---------------------------------------------------------------------------
  5759. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5760. {
  5761. return
  5762. DefaultStr(WinConfiguration->LastWorkspace,
  5763. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5764. }
  5765. //---------------------------------------------------------------------------
  5766. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5767. {
  5768. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5769. bool AnyNonStoredSessionWithPassword = false;
  5770. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5771. bool AllNonStoredSessionsAnonymous = true;
  5772. TTerminalManager * Manager = TTerminalManager::Instance();
  5773. for (int Index = 0; Index < DataList->Count; Index++)
  5774. {
  5775. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5776. if (SessionData->Link.IsEmpty())
  5777. {
  5778. if (SessionData->HasAnySessionPassword())
  5779. {
  5780. AnyNonStoredSessionWithPassword = true;
  5781. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5782. {
  5783. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5784. }
  5785. }
  5786. if (!SameText(SessionData->UserName, AnonymousUserName))
  5787. {
  5788. AllNonStoredSessionsAnonymous = false;
  5789. }
  5790. }
  5791. }
  5792. bool SavePasswords;
  5793. bool * PSavePasswords;
  5794. bool NotRecommendedSavingPasswords =
  5795. !CustomWinConfiguration->UseMasterPassword &&
  5796. !AllNonStoredSessionsAnonymous;
  5797. if (Configuration->DisablePasswordStoring ||
  5798. !AnyNonStoredSessionWithPassword)
  5799. {
  5800. PSavePasswords = NULL;
  5801. SavePasswords = false;
  5802. }
  5803. else
  5804. {
  5805. PSavePasswords = &SavePasswords;
  5806. SavePasswords =
  5807. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5808. !NotRecommendedSavingPasswords;
  5809. }
  5810. UnicodeString Name = WorkspaceName();
  5811. bool CreateShortcut = false;
  5812. bool Result =
  5813. DoSaveWorkspaceDialog(
  5814. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5815. EnableAutoSave);
  5816. if (Result)
  5817. {
  5818. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5819. if (CreateShortcut)
  5820. {
  5821. TOperationVisualizer Visualizer;
  5822. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5823. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5824. }
  5825. if (EnableAutoSave)
  5826. {
  5827. WinConfiguration->AutoSaveWorkspace = true;
  5828. WinConfiguration->AutoWorkspace = Name;
  5829. if (PSavePasswords != NULL)
  5830. {
  5831. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5832. }
  5833. }
  5834. }
  5835. return Result;
  5836. }
  5837. //---------------------------------------------------------------------------
  5838. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5839. {
  5840. DebugAssert(!IsLocalBrowserMode());
  5841. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5842. if (WinConfiguration->PreservePanelState)
  5843. {
  5844. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5845. }
  5846. UpdateSessionData(Terminal->StateData);
  5847. }
  5848. //---------------------------------------------------------------------------
  5849. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5850. {
  5851. // Keep in sync with TSessionData::CopyStateData
  5852. DebugAssert(!IsLocalBrowserMode());
  5853. DebugAssert(Data != NULL);
  5854. // This is inconsistent with how color (for example) is handled.
  5855. Data->Name = Terminal->SessionData->Name;
  5856. // cannot use RemoteDirView->Path, because it is empty if connection
  5857. // was already closed
  5858. // also only peek, we may not be connected at all atm
  5859. // so make sure we do not try retrieving current directory from the server
  5860. // (particularly with FTP)
  5861. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5862. if (!ACurrentDirectory.IsEmpty())
  5863. {
  5864. Data->RemoteDirectory = ACurrentDirectory;
  5865. }
  5866. Data->Color = SessionColor;
  5867. }
  5868. //---------------------------------------------------------------------------
  5869. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5870. {
  5871. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5872. DebugAssert(Toolbar != NULL);
  5873. for (int i = 0; i < Toolbar->Items->Count; i++)
  5874. {
  5875. TTBXCustomDropDownItem * DropDownItem;
  5876. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5877. if (DropDownItem != NULL)
  5878. {
  5879. ToolbarItemResize(DropDownItem,
  5880. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5881. Toolbar->NonClientWidth);
  5882. break;
  5883. }
  5884. }
  5885. }
  5886. //---------------------------------------------------------------------------
  5887. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5888. {
  5889. Item->EditWidth = Width;
  5890. }
  5891. //---------------------------------------------------------------------------
  5892. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5893. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5894. {
  5895. for (int i = 0; i < Toolbar->Items->Count; i++)
  5896. {
  5897. TTBXCustomDropDownItem * DropDownItem;
  5898. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5899. if (DropDownItem != NULL)
  5900. {
  5901. ASize.x -= DropDownItem->EditWidth;
  5902. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5903. }
  5904. }
  5905. }
  5906. //---------------------------------------------------------------------------
  5907. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5908. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5909. {
  5910. if (WinConfiguration->DDWarnLackOfTempSpace)
  5911. {
  5912. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5913. if (!ADrive.IsEmpty())
  5914. {
  5915. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5916. DebugAssert(RequiredSpace >= 0);
  5917. __int64 RequiredWithReserve;
  5918. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5919. if (FreeSpace < RequiredWithReserve)
  5920. {
  5921. unsigned int Result;
  5922. TMessageParams Params(mpNeverAskAgainCheck);
  5923. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5924. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5925. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5926. if (Result == qaNeverAskAgain)
  5927. {
  5928. WinConfiguration->DDWarnLackOfTempSpace = false;
  5929. }
  5930. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5931. }
  5932. }
  5933. }
  5934. }
  5935. //---------------------------------------------------------------------------
  5936. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5937. {
  5938. DoOpenDirectoryDialog(odAddBookmark, Side);
  5939. }
  5940. //---------------------------------------------------------------------------
  5941. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5942. {
  5943. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5944. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5945. try
  5946. {
  5947. TCustomDirView * DView = DirView(Side);
  5948. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5949. {
  5950. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5951. }
  5952. }
  5953. catch (...)
  5954. {
  5955. delete VisitedDirectories;
  5956. throw;
  5957. }
  5958. return VisitedDirectories;
  5959. }
  5960. //---------------------------------------------------------------------------
  5961. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5962. TOpenDirectoryMode Mode, TOperationSide Side)
  5963. {
  5964. bool Continue = true;
  5965. if (Mode == odAddBookmark)
  5966. {
  5967. TMessageParams Params(mpNeverAskAgainCheck);
  5968. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5969. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5970. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5971. unsigned int Answer =
  5972. MessageDialog(Message,
  5973. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5974. if (Answer == qaNeverAskAgain)
  5975. {
  5976. Continue = true;
  5977. WinConfiguration->UseSharedBookmarks = true;
  5978. }
  5979. else if (Answer == qaOK)
  5980. {
  5981. Continue = true;
  5982. WinConfiguration->UseSharedBookmarks = false;
  5983. }
  5984. else
  5985. {
  5986. Continue = false;
  5987. }
  5988. }
  5989. if (Continue)
  5990. {
  5991. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5992. try
  5993. {
  5994. UnicodeString Name = DirView(Side)->PathName;
  5995. bool Repeat;
  5996. do
  5997. {
  5998. Repeat = false;
  5999. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6000. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6001. // do not allow switching to location profiles,
  6002. // if we are not connected
  6003. HasDirView[osLocal] && (Terminal != NULL)))
  6004. {
  6005. TWindowLock Lock(this);
  6006. if (!TryOpenDirectory(Side, Name))
  6007. {
  6008. Repeat = true;
  6009. Mode = odBrowse;
  6010. }
  6011. }
  6012. }
  6013. while (Repeat);
  6014. }
  6015. __finally
  6016. {
  6017. delete VisitedDirectories;
  6018. }
  6019. }
  6020. }
  6021. //---------------------------------------------------------------------------
  6022. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6023. {
  6024. DebugAssert(!Terminal->CommandSessionOpened);
  6025. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6026. }
  6027. //---------------------------------------------------------------------------
  6028. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6029. {
  6030. bool Result = Terminal->IsCapable[Capability] ||
  6031. Terminal->CommandSessionOpened;
  6032. if (!Result)
  6033. {
  6034. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6035. if (!GUIConfiguration->ConfirmCommandSession)
  6036. {
  6037. Result = true;
  6038. }
  6039. else
  6040. {
  6041. TMessageParams Params(mpNeverAskAgainCheck);
  6042. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6043. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6044. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6045. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6046. if (Answer == qaNeverAskAgain)
  6047. {
  6048. GUIConfiguration->ConfirmCommandSession = false;
  6049. Result = true;
  6050. }
  6051. else if (Answer == qaOK)
  6052. {
  6053. Result = true;
  6054. }
  6055. }
  6056. if (Result)
  6057. {
  6058. Result = CommandSessionFallback();
  6059. }
  6060. }
  6061. return Result;
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6065. {
  6066. if (EnsureCommandSessionFallback(fcAnyCommand))
  6067. {
  6068. DoConsoleDialog(Terminal, Command);
  6069. }
  6070. }
  6071. //---------------------------------------------------------------------------
  6072. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6073. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6074. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6075. {
  6076. if (!IsSideLocalBrowser(osRemote) &&
  6077. IsFileControl(DropSourceControl, osRemote) &&
  6078. (FDDExtMapFile != NULL))
  6079. {
  6080. Accept = true;
  6081. }
  6082. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6083. DebugAssert(FDDTargetControl != NULL);
  6084. }
  6085. //---------------------------------------------------------------------------
  6086. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6087. _di_IDataObject DataObj, int KeyState,
  6088. const TPoint & Point, int & Effect, bool & Accept)
  6089. {
  6090. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6091. }
  6092. //---------------------------------------------------------------------------
  6093. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6094. _di_IDataObject DataObj, int KeyState,
  6095. const TPoint & Point, int & Effect, bool & Accept)
  6096. {
  6097. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6101. TObject * Sender)
  6102. {
  6103. DebugUsedParam(Sender);
  6104. DebugAssert(FDDTargetControl == Sender);
  6105. FDDTargetControl = NULL;
  6106. }
  6107. //---------------------------------------------------------------------------
  6108. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6109. {
  6110. FileControlDDDragLeave(SessionsPageControl);
  6111. }
  6112. //---------------------------------------------------------------------------
  6113. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6114. {
  6115. FileControlDDDragLeave(QueueView3);
  6116. }
  6117. //---------------------------------------------------------------------------
  6118. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6119. {
  6120. DebugAssert(!IsSideLocalBrowser(Side));
  6121. DebugUsedParam(Side);
  6122. bool Edit = false;
  6123. TRemoteFile * File = NULL;
  6124. UnicodeString FileName;
  6125. UnicodeString PointTo;
  6126. bool SymbolicLink = true;
  6127. if (RemoteDirView->ItemFocused)
  6128. {
  6129. DebugAssert(RemoteDirView->ItemFocused->Data);
  6130. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6131. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6132. if (Edit)
  6133. {
  6134. FileName = File->FileName;
  6135. PointTo = File->LinkTo;
  6136. }
  6137. else
  6138. {
  6139. PointTo = File->FileName;
  6140. }
  6141. }
  6142. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6143. Terminal->IsCapable[fcHardLink]))
  6144. {
  6145. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6146. if (Edit)
  6147. {
  6148. DebugAssert(File->FileName == FileName);
  6149. int Params = dfNoRecursive;
  6150. Terminal->ExceptionOnFail = true;
  6151. try
  6152. {
  6153. Terminal->DeleteFile(L"", File, &Params);
  6154. }
  6155. __finally
  6156. {
  6157. Terminal->ExceptionOnFail = false;
  6158. }
  6159. }
  6160. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6161. }
  6162. }
  6163. //---------------------------------------------------------------------------
  6164. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6165. {
  6166. return
  6167. (IsSideLocalBrowser(Side) ||
  6168. (HasActiveTerminal() &&
  6169. Terminal->ResolvingSymlinks &&
  6170. Terminal->IsCapable[fcSymbolicLink]));
  6171. }
  6172. //---------------------------------------------------------------------------
  6173. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6174. {
  6175. return
  6176. !IsSideLocalBrowser(FCurrentSide) &&
  6177. (RemoteDirView->ItemFocused != NULL) &&
  6178. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6179. Terminal->SessionData->ResolveSymlinks;
  6180. }
  6181. //---------------------------------------------------------------------------
  6182. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6183. {
  6184. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6185. FForceExecution = true;
  6186. try
  6187. {
  6188. DirView(osCurrent)->ExecuteCurrentFile();
  6189. }
  6190. __finally
  6191. {
  6192. FForceExecution = false;
  6193. }
  6194. }
  6195. //---------------------------------------------------------------------------
  6196. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6197. {
  6198. TEditorData ExternalEditor;
  6199. ExternalEditor.Editor = edExternal;
  6200. bool Remember = false;
  6201. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6202. {
  6203. if (Remember)
  6204. {
  6205. TEditorList * EditorList = new TEditorList;
  6206. try
  6207. {
  6208. *EditorList = *WinConfiguration->EditorList;
  6209. bool Found = false;
  6210. int i = 0;
  6211. while (!Found && (i < EditorList->Count))
  6212. {
  6213. const TEditorPreferences * Editor = EditorList->Editors[i];
  6214. if ((Editor->Data->Editor == edExternal) &&
  6215. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6216. {
  6217. Found = true;
  6218. }
  6219. i++;
  6220. }
  6221. if (!Found)
  6222. {
  6223. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6224. WinConfiguration->EditorList = EditorList;
  6225. }
  6226. }
  6227. __finally
  6228. {
  6229. delete EditorList;
  6230. }
  6231. }
  6232. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6233. }
  6234. }
  6235. //---------------------------------------------------------------------------
  6236. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6237. {
  6238. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6239. if (FFileFindTerminal == ATerminal)
  6240. {
  6241. FFileFindTerminal = NULL;
  6242. HideFileFindDialog();
  6243. }
  6244. if (FClipboardTerminal == ATerminal)
  6245. {
  6246. ClipboardClear(); // implies ClipboardStop
  6247. }
  6248. }
  6249. //---------------------------------------------------------------------------
  6250. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6251. {
  6252. DetachTerminal(Sender);
  6253. }
  6254. //---------------------------------------------------------------------------
  6255. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6256. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6257. {
  6258. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6259. DebugAssert(Terminal != NULL);
  6260. if (Data->Terminal == Terminal)
  6261. {
  6262. Data->Terminal = NULL;
  6263. }
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6267. {
  6268. UpdateControls();
  6269. SessionColor = TColor(0);
  6270. UpdateRemotePathComboBox(false);
  6271. NeedSession(false);
  6272. }
  6273. //---------------------------------------------------------------------------
  6274. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6275. {
  6276. try
  6277. {
  6278. // Cache, as the login dialog can change its value.
  6279. // See also DoShow. Also see TTerminalManager::NewSession.
  6280. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6281. try
  6282. {
  6283. if (ShowLogin)
  6284. {
  6285. bool ReloadSessions = !Startup;
  6286. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6287. }
  6288. }
  6289. __finally
  6290. {
  6291. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6292. // (so there was no chance for the user to open any session yet)
  6293. if ((ShowLogin || !Startup) &&
  6294. !WinConfiguration->KeepOpenWhenNoSession &&
  6295. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6296. {
  6297. TerminateApplication();
  6298. }
  6299. }
  6300. }
  6301. catch (EAbort &)
  6302. {
  6303. // swallow
  6304. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6305. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6306. }
  6307. }
  6308. //---------------------------------------------------------------------------
  6309. void __fastcall TCustomScpExplorerForm::SessionListChanged()
  6310. {
  6311. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  6312. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6313. Configuration->Usage->SetMax(L"MaxOpenedSessions", SessionList->Count);
  6314. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6315. try
  6316. {
  6317. while ((SessionsPageControl->PageCount > SessionList->Count + 1) ||
  6318. // Clear the design time unthemed tab
  6319. ((SessionsPageControl->PageCount > 0) &&
  6320. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6321. {
  6322. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6323. }
  6324. for (int Index = 0; Index <= SessionList->Count; Index++)
  6325. {
  6326. TThemeTabSheet * TabSheet;
  6327. if (Index >= SessionsPageControl->PageCount)
  6328. {
  6329. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6330. TabSheet->PageControl = SessionsPageControl;
  6331. }
  6332. else
  6333. {
  6334. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6335. }
  6336. bool IsSessionTab = (Index < SessionList->Count);
  6337. if (IsSessionTab)
  6338. {
  6339. TTerminal * Terminal = dynamic_cast<TTerminal *>(SessionList->Objects[Index]);
  6340. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6341. UpdateSessionTab(TabSheet);
  6342. }
  6343. else
  6344. {
  6345. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6346. TabSheet->Tag = 0; // not really needed
  6347. TabSheet->Shadowed = false;
  6348. // 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)
  6349. UpdateNewSessionTab();
  6350. }
  6351. TabSheet->ShowCloseButton = IsSessionTab;
  6352. }
  6353. }
  6354. __finally
  6355. {
  6356. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6357. }
  6358. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6359. }
  6360. //---------------------------------------------------------------------------
  6361. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6362. {
  6363. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6364. DebugAssert(TabSheet->ImageIndex == 0);
  6365. TabSheet->Caption =
  6366. WinConfiguration->SelectiveToolbarText ?
  6367. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6368. UnicodeString();
  6369. }
  6370. //---------------------------------------------------------------------------
  6371. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6372. {
  6373. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6374. }
  6375. //---------------------------------------------------------------------------
  6376. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6377. {
  6378. if (DebugAlwaysTrue(TabSheet != NULL))
  6379. {
  6380. TManagedTerminal * ATerminal = GetSessionTabSession(TabSheet);
  6381. if (DebugAlwaysTrue(ATerminal != NULL))
  6382. {
  6383. TColor Color = (ATerminal == Terminal) ? FSessionColor : ATerminal->StateData->Color;
  6384. TabSheet->ImageIndex = AddSessionColor(Color);
  6385. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6386. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6387. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6388. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6389. {
  6390. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6391. }
  6392. }
  6393. }
  6394. }
  6395. //---------------------------------------------------------------------------
  6396. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6397. {
  6398. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6399. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6400. bool Result = (Session != NULL);
  6401. if (Result)
  6402. {
  6403. TTerminalManager::Instance()->ActiveSession = Session;
  6404. }
  6405. else
  6406. {
  6407. try
  6408. {
  6409. NewSession();
  6410. }
  6411. __finally
  6412. {
  6413. SessionListChanged();
  6414. }
  6415. FSessionsPageControlNewSessionTime = Now();
  6416. }
  6417. return Result;
  6418. }
  6419. //---------------------------------------------------------------------------
  6420. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6421. {
  6422. SessionTabSwitched();
  6423. }
  6424. //---------------------------------------------------------------------------
  6425. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6426. {
  6427. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6428. DebugAssert(TransferList != NULL);
  6429. UnicodeString Name;
  6430. if (TransferList->ItemIndex <= 0)
  6431. {
  6432. Name = L"";
  6433. }
  6434. else
  6435. {
  6436. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6437. }
  6438. if (FCopyParamAutoSelected.IsEmpty())
  6439. {
  6440. // if previous preset was not autoselected, make new preset the "default"
  6441. FCopyParamDefault = Name;
  6442. }
  6443. GUIConfiguration->CopyParamCurrent = Name;
  6444. }
  6445. //---------------------------------------------------------------------------
  6446. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6447. {
  6448. // sanity check
  6449. bool ExistingPreset =
  6450. (FTransferListHoverIndex >= 0) &&
  6451. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6452. DebugAssert(ExistingPreset);
  6453. if (ExistingPreset)
  6454. {
  6455. HDC DC = GetDC(0);
  6456. TCanvas * Canvas = new TCanvas();
  6457. try
  6458. {
  6459. Canvas->Handle = DC;
  6460. Canvas->Font = GetToolbarFont(this);
  6461. UnicodeString Name;
  6462. if (FTransferListHoverIndex == 0)
  6463. {
  6464. Name = L"";
  6465. }
  6466. else
  6467. {
  6468. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6469. }
  6470. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6471. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6472. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6473. static_cast<TObject*>(GetComponent(fcTransferList)));
  6474. UnicodeString InfoStr =
  6475. GUIConfiguration->CopyParamPreset[Name].
  6476. GetInfoStr(L"; ",
  6477. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6478. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6479. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6480. {
  6481. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6482. {
  6483. InfoStr.SetLength(InfoStr.Length() - 1);
  6484. }
  6485. InfoStr += Ellipsis;
  6486. }
  6487. // UpdateCaption does not cause invalidation of whole submenu, while
  6488. // setting Caption property does.
  6489. // also it probably does not resize the label, even if necessary
  6490. // (we do not want that anyway)
  6491. TransferLabel->UpdateCaption(InfoStr);
  6492. }
  6493. __finally
  6494. {
  6495. Canvas->Handle = NULL;
  6496. ReleaseDC(0, DC);
  6497. delete Canvas;
  6498. }
  6499. }
  6500. }
  6501. //---------------------------------------------------------------------------
  6502. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6503. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6504. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6505. {
  6506. if (FTransferListHoverIndex != AHoverIndex)
  6507. {
  6508. FTransferListHoverIndex = AHoverIndex;
  6509. UpdateTransferLabel();
  6510. }
  6511. }
  6512. //---------------------------------------------------------------------------
  6513. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6514. {
  6515. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6516. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6517. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6518. {
  6519. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6520. {
  6521. if (!NonVisualDataModule->Busy)
  6522. {
  6523. OpenDirectory(GetSide(osCurrent));
  6524. }
  6525. Message.Result = 1;
  6526. }
  6527. else
  6528. {
  6529. TForm::Dispatch(&Message);
  6530. }
  6531. }
  6532. else
  6533. {
  6534. TForm::Dispatch(&Message);
  6535. }
  6536. }
  6537. //---------------------------------------------------------------------------
  6538. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6539. {
  6540. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6541. if ((FIgnoreNextDialogChar != 0) &&
  6542. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6543. {
  6544. Message.Result = 1;
  6545. }
  6546. else
  6547. {
  6548. TForm::Dispatch(&Message);
  6549. }
  6550. FIgnoreNextDialogChar = 0;
  6551. }
  6552. //---------------------------------------------------------------------------
  6553. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6554. {
  6555. // The four low-order bits are used internally by Windows
  6556. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6557. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6558. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6559. // 61730 - restore thru double click - undocumented
  6560. // 61490 - maximize thru double click - undocumented
  6561. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6562. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6563. {
  6564. SysResizing(Cmd);
  6565. }
  6566. TForm::Dispatch(&Message);
  6567. }
  6568. //---------------------------------------------------------------------------
  6569. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6570. {
  6571. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6572. // Also there no point returning TRUE as we are not able to
  6573. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6574. // Hence the process termination might be safer :)
  6575. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6576. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6577. {
  6578. Message.Result = FALSE;
  6579. }
  6580. else
  6581. {
  6582. Message.Result = TRUE;
  6583. }
  6584. // Do not call default handling as that triggers OnCloseQuery,
  6585. // where our implementation will popup confirmation dialogs, what we do not want,
  6586. // as per Vista guidelines:
  6587. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6588. }
  6589. //---------------------------------------------------------------------------
  6590. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6591. {
  6592. if (Message.EndSession && IsApplicationMinimized())
  6593. {
  6594. // WORKAROUND
  6595. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6596. // when it receives WM_ENDSESSION,
  6597. // but that sometimes (particularly when application is minimized) cause crashes.
  6598. // Crash popups message that blocks log off.
  6599. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6600. // so we call ExitProcess() immediately, not even trying to cleanup.
  6601. // It still causes beep, so there's likely some popup, but it does not block
  6602. // log off.
  6603. ExitProcess(0);
  6604. }
  6605. TForm::Dispatch(&Message);
  6606. }
  6607. #ifdef _DEBUG
  6608. //---------------------------------------------------------------------------
  6609. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6610. {
  6611. TForm::Dispatch(&Message);
  6612. }
  6613. #endif
  6614. //---------------------------------------------------------------------------
  6615. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6616. {
  6617. }
  6618. //---------------------------------------------------------------------------
  6619. void __fastcall TCustomScpExplorerForm::DoShow()
  6620. {
  6621. // only now are the controls resized finally, so the size constraints
  6622. // will not conflict with possibly very small window size
  6623. RestoreFormParams();
  6624. // This indicates that the form was rescaled after parameters were loaded and
  6625. // as most probably the parameters were actually saved with the current form scaling
  6626. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6627. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6628. // and no rounding problems will occur.
  6629. // See also RestoreForm.
  6630. // (we should be safe to call RestoreParams unconditionally)
  6631. if (PixelsPerInch != Screen->PixelsPerInch)
  6632. {
  6633. RestoreParams();
  6634. }
  6635. FixControlsPlacement();
  6636. if (Position == poDefaultPosOnly)
  6637. {
  6638. CutFormToDesktop(this);
  6639. }
  6640. TForm::DoShow();
  6641. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6642. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6643. // This was previously in NeedSession, where other related code is.
  6644. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6645. // unpleasanly shows briefly.
  6646. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6647. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6648. // This detects if workspace was saved the last time the main widow was closed
  6649. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6650. {
  6651. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6652. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6653. }
  6654. if (Terminal == NULL)
  6655. {
  6656. StartingDisconnected();
  6657. }
  6658. UpdatePixelsPerInchMainWindowCounter();
  6659. FShowing = true;
  6660. }
  6661. //---------------------------------------------------------------------------
  6662. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6663. {
  6664. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6665. }
  6666. //---------------------------------------------------------------------------
  6667. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6668. {
  6669. SessionListChanged();
  6670. InitStatusBar();
  6671. UpdateControls();
  6672. }
  6673. //---------------------------------------------------------------------------
  6674. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6675. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6676. TNotifyEvent OnBalloonClick, TObject * UserData)
  6677. {
  6678. bool Do;
  6679. UnicodeString Message;
  6680. if (E == NULL)
  6681. {
  6682. Message = Str;
  6683. Do = true;
  6684. }
  6685. else
  6686. {
  6687. Do = ExceptionMessage(E, Message);
  6688. }
  6689. if (Do && WinConfiguration->BalloonNotifications)
  6690. {
  6691. UnicodeString Title;
  6692. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6693. {
  6694. Message = TrimLeft(Message);
  6695. }
  6696. else
  6697. {
  6698. Message = UnformatMessage(Message);
  6699. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6700. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6701. Title = LoadResourceString(Captions[Type]);
  6702. if (Terminal != NULL)
  6703. {
  6704. Title = FORMAT(L"%s - %s",
  6705. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6706. }
  6707. }
  6708. if (Seconds == 0)
  6709. {
  6710. Seconds = WinConfiguration->NotificationsTimeout;
  6711. }
  6712. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6713. }
  6714. }
  6715. //---------------------------------------------------------------------------
  6716. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6717. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6718. UnicodeString HelpKeyword, const TMessageParams * Params,
  6719. TTerminal * Terminal)
  6720. {
  6721. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6722. (FOnFeedSynchronizeError != NULL)) &&
  6723. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6724. {
  6725. if (FOnFeedSynchronizeError != NULL)
  6726. {
  6727. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6728. }
  6729. else
  6730. {
  6731. DebugAssert(FErrorList != NULL);
  6732. TStringList * MoreMessagesCopy = NULL;
  6733. if (MoreMessages)
  6734. {
  6735. MoreMessagesCopy = new TStringList();
  6736. MoreMessagesCopy->Assign(MoreMessages);
  6737. }
  6738. FErrorList->AddObject(Message, MoreMessagesCopy);
  6739. }
  6740. PopupTrayBalloon(Terminal, Message, Type);
  6741. return ContinueAnswer(Answers);
  6742. }
  6743. else
  6744. {
  6745. bool UseBalloon = FTrayIcon->Visible;
  6746. if (UseBalloon)
  6747. {
  6748. PopupTrayBalloon(Terminal, Message, Type);
  6749. }
  6750. unsigned int Result;
  6751. try
  6752. {
  6753. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6754. }
  6755. __finally
  6756. {
  6757. // cancel only balloon we popped up, otherwise we may cancel notification
  6758. // balloon that was there before the message dialog
  6759. // (such as "dd confirmation opt in balloon)
  6760. if (UseBalloon)
  6761. {
  6762. FTrayIcon->CancelBalloon();
  6763. }
  6764. }
  6765. return Result;
  6766. }
  6767. }
  6768. //---------------------------------------------------------------------------
  6769. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6770. TTerminal * Terminal, Exception * E)
  6771. {
  6772. if (FTrayIcon->Visible)
  6773. {
  6774. PopupTrayBalloon(Terminal, L"", qtError, E);
  6775. }
  6776. // particularly prevent opening new session from jump list,
  6777. // while exception is shown
  6778. NonVisualDataModule->StartBusy();
  6779. try
  6780. {
  6781. ShowExtendedExceptionEx(Terminal, E);
  6782. }
  6783. __finally
  6784. {
  6785. NonVisualDataModule->EndBusy();
  6786. FTrayIcon->CancelBalloon();
  6787. }
  6788. }
  6789. //---------------------------------------------------------------------------
  6790. void __fastcall TCustomScpExplorerForm::SessionReady()
  6791. {
  6792. if (Terminal->Active)
  6793. {
  6794. InitStatusBar();
  6795. }
  6796. // cannot rely on active page being page for active terminal,
  6797. // as it can happen that active page is the "new session" page
  6798. // (e.g. when reconnecting active terminal, while login dialog
  6799. // invoked from "new session" page is modal)
  6800. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6801. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  6802. }
  6803. //---------------------------------------------------------------------------
  6804. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6805. TTerminal * Terminal, Exception * E)
  6806. {
  6807. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6808. if (!Terminal->Active)
  6809. {
  6810. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6811. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6812. {
  6813. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6814. }
  6815. }
  6816. }
  6817. //---------------------------------------------------------------------------
  6818. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6819. UnicodeString Message, TQueryType Type,
  6820. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6821. {
  6822. if ((E == NULL) ||
  6823. ExceptionMessage(E, Message))
  6824. {
  6825. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6826. if (Important)
  6827. {
  6828. Seconds *= 5;
  6829. }
  6830. UnicodeString NoteMessage(UnformatMessage(Message));
  6831. if (Terminal != NULL)
  6832. {
  6833. NoteMessage = FORMAT(L"%s: %s",
  6834. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6835. }
  6836. if (WinConfiguration->BalloonNotifications)
  6837. {
  6838. AddNote(NoteMessage);
  6839. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6840. }
  6841. else
  6842. {
  6843. FlashOnBackground();
  6844. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6845. }
  6846. }
  6847. }
  6848. //---------------------------------------------------------------------------
  6849. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6850. {
  6851. RestoreApp();
  6852. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6853. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6854. !NonVisualDataModule->Busy)
  6855. {
  6856. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6857. TTerminalManager::Instance()->ActiveSession = Terminal;
  6858. if (!ComponentVisible[fcQueueView])
  6859. {
  6860. ToggleQueueVisibility();
  6861. GoToQueue();
  6862. }
  6863. }
  6864. }
  6865. //---------------------------------------------------------------------------
  6866. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6867. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6868. {
  6869. UnicodeString Message;
  6870. TNotifyEvent OnClick = NULL;
  6871. TObject * UserData = NULL;
  6872. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6873. switch (Event)
  6874. {
  6875. case qeEmptyButMonitored:
  6876. if ((ATerminal != Terminal) || QueueInvisible)
  6877. {
  6878. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6879. OnClick = QueueEmptyNoteClicked;
  6880. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6881. TerminalNoteData->Terminal = ATerminal;
  6882. UserData = TerminalNoteData;
  6883. }
  6884. break;
  6885. case qeEmpty:
  6886. OperationComplete(ATerminal->QueueOperationStart);
  6887. break;
  6888. case qePendingUserAction:
  6889. if ((ATerminal != Terminal) ||
  6890. (QueueInvisible && !IsQueueAutoPopup()))
  6891. {
  6892. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6893. }
  6894. break;
  6895. default:
  6896. DebugFail();
  6897. }
  6898. if (!Message.IsEmpty())
  6899. {
  6900. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6901. }
  6902. }
  6903. //---------------------------------------------------------------------------
  6904. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6905. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6906. {
  6907. if (FDDExtMapFile != NULL)
  6908. {
  6909. CloseHandle(FDDExtMapFile);
  6910. FDDExtMapFile = NULL;
  6911. }
  6912. if (WinConfiguration->DDFakeFile)
  6913. {
  6914. DDFakeFileInitDrag(FileList, Created);
  6915. }
  6916. }
  6917. //---------------------------------------------------------------------------
  6918. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6919. {
  6920. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6921. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6922. {
  6923. FFakeFileDropTarget = FileName;
  6924. }
  6925. }
  6926. //---------------------------------------------------------------------------
  6927. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6928. {
  6929. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6930. if (!ForceDirectories(ApiPath(Result)))
  6931. {
  6932. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6933. }
  6934. FileSetAttr(ApiPath(Result), faHidden);
  6935. return Result;
  6936. }
  6937. //---------------------------------------------------------------------------
  6938. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6939. bool & Created)
  6940. {
  6941. FFakeFileDropTarget = UnicodeString();
  6942. FDragFakeDirectory = CreateFakeTransferDirectory();
  6943. FileList->AddItem(NULL, FDragFakeDirectory);
  6944. Created = true;
  6945. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6946. {
  6947. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6948. }
  6949. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6950. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6951. {
  6952. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6953. TDragExtCommStruct* CommStruct;
  6954. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6955. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6956. DebugAssert(CommStruct != NULL);
  6957. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6958. CommStruct->Dragging = true;
  6959. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6960. LENOF(CommStruct->DropDest));
  6961. NULL_TERMINATE(CommStruct->DropDest);
  6962. UnmapViewOfFile(CommStruct);
  6963. }
  6964. }
  6965. //---------------------------------------------------------------------------
  6966. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6967. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6968. {
  6969. bool Result;
  6970. DebugAssert(!IsLocalBrowserMode());
  6971. if (Sender == RemoteDirView)
  6972. {
  6973. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6974. }
  6975. else
  6976. {
  6977. DebugAssert(Sender == RemoteDriveView);
  6978. TStrings * FileList = RemoteDriveView->DragFileList();
  6979. try
  6980. {
  6981. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6982. }
  6983. __finally
  6984. {
  6985. delete FileList;
  6986. }
  6987. }
  6988. if (FDDTargetControl == RemoteDriveView)
  6989. {
  6990. RemoteDriveView->UpdateDropTarget();
  6991. }
  6992. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6993. // or from tree view to dir view.
  6994. // foMove happens when file/dir is dragged from remote tree view outside of
  6995. // application via dragex
  6996. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6997. (DropSourceControl == RemoteDriveView))
  6998. {
  6999. RemoteDriveView->UpdateDropSource();
  7000. }
  7001. return Result;
  7002. }
  7003. //---------------------------------------------------------------------------
  7004. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7005. {
  7006. DebugAssert(!IsLocalBrowserMode());
  7007. // This also handles drops of remote files to queue.
  7008. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7009. SAFE_DESTROY(FDDFileList);
  7010. if (!FFakeFileDropTarget.IsEmpty())
  7011. {
  7012. RemoveDir(ApiPath(FFakeFileDropTarget));
  7013. }
  7014. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7015. {
  7016. try
  7017. {
  7018. TDragResult DDResult = (Sender == RemoteDirView) ?
  7019. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7020. // Focus is moved to the target application,
  7021. // but as we are going to present the UI, we need to steal the focus back.
  7022. // This most likely won't work though (windows does not allow application
  7023. // to steal focus most of the time)
  7024. Application->BringToFront();
  7025. // On older version of Windows we never got drMove here, see also comment below.
  7026. // On Windows 10, we get the "move".
  7027. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7028. {
  7029. UnicodeString TargetDirectory;
  7030. TFileOperation Operation;
  7031. // drInvalid may mean drMove, see comment below
  7032. switch (DDResult)
  7033. {
  7034. case drCopy:
  7035. Operation = foCopy;
  7036. break;
  7037. case drMove:
  7038. Operation = foMove;
  7039. break;
  7040. default:
  7041. DebugFail();
  7042. case drInvalid:
  7043. // prefer "copy" for safety
  7044. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7045. break;
  7046. }
  7047. TTransferOperationParam Param;
  7048. UnicodeString CounterName;
  7049. bool ForceQueue;
  7050. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7051. {
  7052. // we get drInvalid both if d&d was intercepted by ddext,
  7053. // and when users drops on no-drop location.
  7054. // we tell the difference by existence of response from ddext,
  7055. // so we ignore absence of response in this case
  7056. if (DDResult != drInvalid)
  7057. {
  7058. // here we know that the extension is installed,
  7059. // as it is checked as soon as drag&drop starts from
  7060. // RemoteFileControlDDCreateDragFileList
  7061. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7062. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7063. {
  7064. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7065. }
  7066. else
  7067. {
  7068. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7069. }
  7070. }
  7071. }
  7072. else
  7073. {
  7074. // download using fake file
  7075. Param.Temp = false;
  7076. Param.DragDrop = true;
  7077. if (ForceQueue)
  7078. {
  7079. Param.Queue = asOn;
  7080. }
  7081. if (Sender == RemoteDirView)
  7082. {
  7083. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7084. }
  7085. if (RemoteFileControlFileOperation(Sender, Operation,
  7086. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7087. {
  7088. Configuration->Usage->Inc(CounterName);
  7089. }
  7090. }
  7091. }
  7092. }
  7093. __finally
  7094. {
  7095. CloseHandle(FDDExtMapFile);
  7096. FDDExtMapFile = NULL;
  7097. delete FDragFakeMonitors;
  7098. FDragFakeMonitors = NULL;
  7099. RemoveDir(ApiPath(FDragFakeDirectory));
  7100. FDragFakeDirectory = L"";
  7101. FFakeFileDropTarget = UnicodeString();
  7102. }
  7103. }
  7104. if (FDragDropSshTerminate.get() != NULL)
  7105. {
  7106. FDragDropSshTerminate->Rethrow();
  7107. }
  7108. }
  7109. //---------------------------------------------------------------------------
  7110. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7111. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7112. {
  7113. // Remember drop effect so we know (when user drops files), if we copy or move
  7114. FLastDropEffect = dwEffect;
  7115. }
  7116. //---------------------------------------------------------------------------
  7117. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7118. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7119. {
  7120. bool Result;
  7121. if (FDDTargetControl == QueueView3)
  7122. {
  7123. Directory = DefaultDownloadTargetDirectory();
  7124. Result = true;
  7125. CounterName = L"DownloadsDragDropQueue";
  7126. ForceQueue = true;
  7127. }
  7128. else if (!FFakeFileDropTarget.IsEmpty())
  7129. {
  7130. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7131. Result = true;
  7132. ForceQueue = false;
  7133. CounterName = L"DownloadsDragDropFakeFile";
  7134. }
  7135. else
  7136. {
  7137. ForceQueue = false;
  7138. Enabled = false;
  7139. try
  7140. {
  7141. int Timer = 0;
  7142. Result = false;
  7143. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7144. {
  7145. {
  7146. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7147. TDragExtCommStruct* CommStruct;
  7148. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7149. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7150. DebugAssert(CommStruct != NULL);
  7151. Result = !CommStruct->Dragging;
  7152. if (Result)
  7153. {
  7154. Directory = ExtractFilePath(CommStruct->DropDest);
  7155. CounterName = L"DownloadsDragDropExternalExt";
  7156. }
  7157. UnmapViewOfFile(CommStruct);
  7158. }
  7159. if (!Result)
  7160. {
  7161. Sleep(50);
  7162. Timer += 50;
  7163. Application->ProcessMessages();
  7164. }
  7165. }
  7166. }
  7167. __finally
  7168. {
  7169. Enabled = true;
  7170. }
  7171. }
  7172. return Result;
  7173. }
  7174. //---------------------------------------------------------------------------
  7175. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7176. const UnicodeString TempDir, int SecDelay)
  7177. {
  7178. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7179. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7180. if (FDelayedDeletionTimer == NULL)
  7181. {
  7182. DebugAssert(HandleAllocated());
  7183. FDelayedDeletionTimer = new TTimer(this);
  7184. FDelayedDeletionTimer->Interval = 10000;
  7185. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7186. }
  7187. else
  7188. {
  7189. FDelayedDeletionTimer->Enabled = true;
  7190. }
  7191. }
  7192. //---------------------------------------------------------------------------
  7193. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7194. {
  7195. DebugAssert(FDelayedDeletionList != NULL);
  7196. TDateTime N = Now();
  7197. TDateTime Alert;
  7198. UnicodeString Directory;
  7199. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7200. {
  7201. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7202. if ((N >= Alert) || (Sender == NULL))
  7203. {
  7204. Directory = FDelayedDeletionList->Strings[Index];
  7205. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7206. {
  7207. FDelayedDeletionList->Delete(Index);
  7208. }
  7209. }
  7210. }
  7211. if (FDelayedDeletionList->Count == 0)
  7212. {
  7213. FDelayedDeletionTimer->Enabled = false;
  7214. }
  7215. }
  7216. //---------------------------------------------------------------------------
  7217. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7218. {
  7219. DebugAssert(!IsLocalBrowserMode());
  7220. if (IsFileControl(FDDTargetControl, osRemote) ||
  7221. (FDDTargetControl == SessionsPageControl))
  7222. {
  7223. TTerminal * TargetTerminal = NULL;
  7224. TFileOperation Operation = foNone;
  7225. if (FDDTargetControl == SessionsPageControl)
  7226. {
  7227. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7228. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7229. // do not allow dropping on the "+" tab
  7230. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7231. if (TargetTerminal != NULL)
  7232. {
  7233. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7234. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7235. {
  7236. Operation = foRemoteMove;
  7237. }
  7238. else
  7239. {
  7240. Operation = foRemoteCopy;
  7241. }
  7242. }
  7243. }
  7244. else
  7245. {
  7246. if (FLastDropEffect == DROPEFFECT_MOVE)
  7247. {
  7248. Operation = foRemoteMove;
  7249. }
  7250. else if (FLastDropEffect == DROPEFFECT_COPY)
  7251. {
  7252. Operation = foRemoteCopy;
  7253. }
  7254. }
  7255. if (Operation != foNone)
  7256. {
  7257. RemoteFileControlFileOperation(DropSourceControl,
  7258. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7259. }
  7260. // abort drag&drop
  7261. Abort();
  7262. }
  7263. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7264. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7265. (FDDTargetControl != QueueView3))
  7266. {
  7267. DebugAssert(!FDragTempDir.IsEmpty());
  7268. TTransferType Type;
  7269. UnicodeString TempDir = FDragTempDir;
  7270. // We clear FDragTempDir before calling
  7271. // just in case it fail (raises exception)
  7272. FDragTempDir = L"";
  7273. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7274. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7275. // empty directory parameter means temp directory -> don't display it!
  7276. UnicodeString TargetDir = L"";
  7277. int Options = 0;
  7278. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7279. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7280. {
  7281. Abort();
  7282. }
  7283. // TargetDir is set when dropped on local file control
  7284. // (this was workaround for legacy dirview event handling, now it should be
  7285. // made prettier)
  7286. if (TargetDir.IsEmpty())
  7287. {
  7288. TargetDir = TempDir;
  7289. if (ForceDirectories(ApiPath(TargetDir)))
  7290. {
  7291. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7292. FPendingTempSpaceWarn = true;
  7293. try
  7294. {
  7295. FDragDropOperation = true;
  7296. int Params = cpTemporary |
  7297. (Type == ttMove ? cpDelete : 0);
  7298. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7299. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7300. }
  7301. __finally
  7302. {
  7303. FDragDropOperation = false;
  7304. FPendingTempSpaceWarn = false;
  7305. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7306. }
  7307. }
  7308. else
  7309. {
  7310. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7311. }
  7312. }
  7313. }
  7314. }
  7315. //---------------------------------------------------------------------------
  7316. void __fastcall TCustomScpExplorerForm::DDDownload(
  7317. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7318. {
  7319. DebugAssert(!IsLocalBrowserMode());
  7320. TAutoBatch AutoBatch(this);
  7321. UpdateCopyParamCounters(*CopyParam);
  7322. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7323. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7324. {
  7325. RemoteDriveView->UpdateDropSource();
  7326. }
  7327. }
  7328. //---------------------------------------------------------------------------
  7329. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7330. {
  7331. public:
  7332. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7333. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7334. {
  7335. }
  7336. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7337. {
  7338. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7339. TDataObjectFilesEx::AllowData(FormatEtc);
  7340. }
  7341. };
  7342. //---------------------------------------------------------------------------
  7343. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7344. TObject * Sender, TDataObject *& DataObject)
  7345. {
  7346. if (FDDExtMapFile != NULL)
  7347. {
  7348. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7349. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7350. {
  7351. Abort();
  7352. }
  7353. if (FileList->Count > 0)
  7354. {
  7355. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7356. if (!FilesObject->IsValid(true, true))
  7357. {
  7358. FilesObject->_Release();
  7359. }
  7360. else
  7361. {
  7362. DataObject = FilesObject;
  7363. }
  7364. }
  7365. }
  7366. }
  7367. //---------------------------------------------------------------------------
  7368. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7369. {
  7370. DebugFail();
  7371. }
  7372. //---------------------------------------------------------------------------
  7373. void __fastcall TCustomScpExplorerForm::GoToTree()
  7374. {
  7375. ComponentVisible[fcRemoteTree] = true;
  7376. DriveView(osRemote)->SetFocus();
  7377. }
  7378. //---------------------------------------------------------------------------
  7379. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7380. TPanelExport Export)
  7381. {
  7382. TCustomDirView * DirView = this->DirView(Side);
  7383. std::unique_ptr<TStrings> ExportData(new TStringList());
  7384. switch (Export)
  7385. {
  7386. case pePath:
  7387. ExportData->Add(DirView->PathName);
  7388. break;
  7389. case peFileList:
  7390. case peFullFileList:
  7391. {
  7392. bool FullPath = (Export == peFullFileList);
  7393. DirView->CreateFileList(false, FullPath, ExportData.get());
  7394. for (int Index = 0; Index < ExportData->Count; Index++)
  7395. {
  7396. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7397. {
  7398. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7399. }
  7400. }
  7401. }
  7402. break;
  7403. default:
  7404. DebugFail();
  7405. }
  7406. return ExportData.release();
  7407. }
  7408. //---------------------------------------------------------------------------
  7409. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7410. TPanelExport Export, TPanelExportDestination Destination)
  7411. {
  7412. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7413. PanelExportStore(Side, Export, Destination, ExportData.get());
  7414. }
  7415. //---------------------------------------------------------------------------
  7416. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7417. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7418. TStrings * ExportData)
  7419. {
  7420. if (Destination == pedClipboard)
  7421. {
  7422. TInstantOperationVisualizer Visualizer;
  7423. CopyToClipboard(ExportData);
  7424. }
  7425. else
  7426. {
  7427. DebugFail();
  7428. }
  7429. }
  7430. //---------------------------------------------------------------------------
  7431. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7432. {
  7433. TCustomDirView * DirView = this->DirView(Side);
  7434. UnicodeString Mask = DirView->Mask;
  7435. if (DoFilterMaskDialog(DirView, Mask))
  7436. {
  7437. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7438. Configuration->Usage->Inc(L"Filters");
  7439. }
  7440. }
  7441. //---------------------------------------------------------------------------
  7442. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7443. {
  7444. return FQueueController->DefaultOperation();
  7445. }
  7446. //---------------------------------------------------------------------------
  7447. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7448. TQueueOperation Operation, void ** Param)
  7449. {
  7450. switch (Operation)
  7451. {
  7452. case qoPreferences:
  7453. return true;
  7454. case qoGoTo:
  7455. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7456. case qoOnceEmpty:
  7457. return IsAnythingQueued();
  7458. default:
  7459. return FQueueController->AllowOperation(Operation, Param);
  7460. }
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7464. {
  7465. if (DebugAlwaysTrue(QueueView3->Visible))
  7466. {
  7467. QueueView3->SetFocus();
  7468. }
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7472. TQueueOperation Operation, void * Param)
  7473. {
  7474. if (Operation == qoGoTo)
  7475. {
  7476. GoToQueue();
  7477. }
  7478. else if (Operation == qoPreferences)
  7479. {
  7480. PreferencesDialog(pmQueue);
  7481. }
  7482. else
  7483. {
  7484. FQueueController->ExecuteOperation(Operation, Param);
  7485. }
  7486. }
  7487. //---------------------------------------------------------------------------
  7488. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7489. {
  7490. return (Queue != NULL) && Queue->Enabled;
  7491. }
  7492. //---------------------------------------------------------------------------
  7493. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7494. {
  7495. DebugAssert(Queue != NULL);
  7496. if (Queue != NULL)
  7497. {
  7498. Queue->Enabled = !Queue->Enabled;
  7499. }
  7500. }
  7501. //---------------------------------------------------------------------------
  7502. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7503. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7504. {
  7505. FQueueActedItem = QueueView3->ItemFocused;
  7506. }
  7507. //---------------------------------------------------------------------------
  7508. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7509. {
  7510. return TopDock->Height + QueueSplitter->Height;
  7511. }
  7512. //---------------------------------------------------------------------------
  7513. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7514. {
  7515. return
  7516. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7517. (QueueDock->Visible ? QueueDock->Height : 0) +
  7518. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7519. }
  7520. //---------------------------------------------------------------------------
  7521. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7522. {
  7523. return ScaleByTextHeight(this, 48);
  7524. }
  7525. //---------------------------------------------------------------------------
  7526. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7527. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7528. {
  7529. // when queue is hidden by double-clicking splitter, stray attempt to
  7530. // resize the panel with strange value arrives, make sure it is ignored
  7531. if (ComponentVisible[fcQueueView])
  7532. {
  7533. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7534. if (NewSize > MaxHeightLimit)
  7535. {
  7536. NewSize = MaxHeightLimit;
  7537. }
  7538. int MinHeightLimit =
  7539. GetStaticQueuePanelComponentsHeight() +
  7540. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7541. GetMinQueueViewHeight();
  7542. if (NewSize < MinHeightLimit)
  7543. {
  7544. NewSize = MinHeightLimit;
  7545. }
  7546. }
  7547. else
  7548. {
  7549. Accept = false;
  7550. }
  7551. }
  7552. //---------------------------------------------------------------------------
  7553. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7554. {
  7555. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7556. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7557. if (QueueViewHeight < GetMinQueueViewHeight())
  7558. {
  7559. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7560. }
  7561. }
  7562. //---------------------------------------------------------------------------
  7563. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7564. TDragObject *& /*DragObject*/)
  7565. {
  7566. FQueueActedItem = QueueView3->ItemFocused;
  7567. }
  7568. //---------------------------------------------------------------------------
  7569. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7570. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7571. {
  7572. Accept = true;
  7573. if (Source == QueueView3)
  7574. {
  7575. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7576. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7577. if (Accept)
  7578. {
  7579. TQueueItemProxy * QueueItem;
  7580. TQueueItemProxy * DestQueueItem;
  7581. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7582. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7583. Accept = (QueueItem != DestQueueItem) &&
  7584. (QueueItem->Status == TQueueItem::qsPending) &&
  7585. (DestQueueItem->Status == TQueueItem::qsPending);
  7586. }
  7587. }
  7588. }
  7589. //---------------------------------------------------------------------------
  7590. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7591. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7592. {
  7593. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7594. {
  7595. TQueueItemProxy * QueueItem;
  7596. TQueueItemProxy * DestQueueItem;
  7597. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7598. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7599. QueueItem->Move(DestQueueItem);
  7600. }
  7601. }
  7602. //---------------------------------------------------------------------------
  7603. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7604. {
  7605. if ((QueueView3->ItemFocused == NULL) &&
  7606. (QueueView3->Items->Count > 0))
  7607. {
  7608. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7609. }
  7610. QueueLabelUpdateStatus();
  7611. }
  7612. //---------------------------------------------------------------------------
  7613. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7614. {
  7615. QueueLabelUpdateStatus();
  7616. }
  7617. //---------------------------------------------------------------------------
  7618. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7619. {
  7620. QueueLabel->UpdateStatus();
  7621. }
  7622. //---------------------------------------------------------------------------
  7623. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7624. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7625. {
  7626. if (Selected)
  7627. {
  7628. NonVisualDataModule->UpdateNonVisibleActions();
  7629. }
  7630. }
  7631. //---------------------------------------------------------------------------
  7632. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7633. {
  7634. TDragDropFilesEx * Result = NULL;
  7635. if (Sender == SessionsPageControl)
  7636. {
  7637. Result = FSessionsDragDropFilesEx;
  7638. }
  7639. else if (Sender == QueueView3)
  7640. {
  7641. Result = FQueueDragDropFilesEx;
  7642. }
  7643. else
  7644. {
  7645. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7646. if (DirView != NULL)
  7647. {
  7648. Result = DirView->DragDropFilesEx;
  7649. }
  7650. else
  7651. {
  7652. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7653. if (DriveView != NULL)
  7654. {
  7655. Result = DriveView->DragDropFilesEx;
  7656. }
  7657. }
  7658. }
  7659. DebugAssert(Result != NULL);
  7660. return Result;
  7661. }
  7662. //---------------------------------------------------------------------------
  7663. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7664. {
  7665. return (DView->SelCount == DView->FilesCount);
  7666. }
  7667. //---------------------------------------------------------------------------
  7668. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7669. {
  7670. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7671. }
  7672. //---------------------------------------------------------------------------
  7673. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7674. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7675. {
  7676. DebugAssert(!IsLocalBrowserMode());
  7677. TFileOperation Operation;
  7678. switch (Effect)
  7679. {
  7680. case DROPEFFECT_MOVE:
  7681. Operation = foMove;
  7682. break;
  7683. case DROPEFFECT_COPY:
  7684. // occures on WinXP (reported by user)
  7685. default:
  7686. Operation = foCopy;
  7687. break;
  7688. };
  7689. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7690. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7691. if (DragDropFilesEx->FileList->Count > 0)
  7692. {
  7693. TStrings * FileList = new TStringList();
  7694. try
  7695. {
  7696. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7697. {
  7698. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7699. }
  7700. FDragDropOperation = true;
  7701. TTransferOperationParam Param;
  7702. Param.TargetDirectory = TargetPath;
  7703. // upload, no temp dirs
  7704. Param.Temp = false;
  7705. Param.DragDrop = DragDrop;
  7706. Param.Options =
  7707. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7708. if (ForceQueue)
  7709. {
  7710. Param.Queue = asOn;
  7711. }
  7712. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7713. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7714. {
  7715. if (IsFileControl(DropSourceControl, osLocal))
  7716. {
  7717. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7718. }
  7719. else
  7720. {
  7721. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7722. }
  7723. }
  7724. }
  7725. __finally
  7726. {
  7727. FDragDropOperation = false;
  7728. delete FileList;
  7729. }
  7730. }
  7731. }
  7732. //---------------------------------------------------------------------------
  7733. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7734. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7735. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7736. {
  7737. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7738. }
  7739. //---------------------------------------------------------------------------
  7740. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7741. TObject * Sender, int grfKeyState, int & dwEffect)
  7742. {
  7743. DebugAssert(!IsLocalBrowserMode());
  7744. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7745. if ((dwEffect != DROPEFFECT_NONE) &&
  7746. IsFileControl(DropSourceControl, osRemote))
  7747. {
  7748. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7749. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7750. (RemoteDirView->DropTarget == NULL))
  7751. {
  7752. dwEffect = DROPEFFECT_NONE;
  7753. }
  7754. else
  7755. {
  7756. if (dwEffect == DROPEFFECT_COPY)
  7757. {
  7758. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7759. // currently we support copying always (at least via temporary directory);
  7760. // remove associated checks once this all proves stable and working
  7761. bool CopyCapable = true;
  7762. // if we do not support neither of operations, there's no discussion
  7763. if (!MoveCapable && !CopyCapable)
  7764. {
  7765. dwEffect = DROPEFFECT_NONE;
  7766. }
  7767. else
  7768. {
  7769. // The default effect inside remote panel is move,
  7770. // unless we do not support it, but support copy
  7771. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7772. {
  7773. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7774. }
  7775. else
  7776. {
  7777. // with ctrl-down, we want copy unless it is not supported
  7778. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7779. }
  7780. }
  7781. }
  7782. }
  7783. }
  7784. }
  7785. //---------------------------------------------------------------------------
  7786. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7787. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7788. {
  7789. DebugAssert(!IsLocalBrowserMode());
  7790. if (FDDTotalSize >= 0)
  7791. {
  7792. if (File->IsDirectory)
  7793. {
  7794. FDDTotalSize = -1;
  7795. }
  7796. else
  7797. {
  7798. FDDTotalSize += File->Size;
  7799. }
  7800. }
  7801. DebugAssert(!FDragTempDir.IsEmpty());
  7802. // TODO: this is quite ineffective
  7803. // TODO: what if invalid character replacement is disabled?
  7804. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7805. UnicodeString TransferFileName;
  7806. if (Sender == RemoteDriveView)
  7807. {
  7808. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7809. }
  7810. else
  7811. {
  7812. TransferFileName = File->FileName;
  7813. }
  7814. FDDFileList->AddObject(TransferFileName, File);
  7815. }
  7816. //---------------------------------------------------------------------------
  7817. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7818. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7819. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7820. {
  7821. // sometimes we do not get DDEnd so the list is not released
  7822. SAFE_DESTROY(FDDFileList);
  7823. FDDFileList = new TStringList();
  7824. FDragTempDir = WinConfiguration->TemporaryDir();
  7825. FDDTotalSize = 0;
  7826. FDragDropSshTerminate.reset(NULL);
  7827. }
  7828. //---------------------------------------------------------------------------
  7829. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7830. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7831. HRESULT & Result)
  7832. {
  7833. if (Result == DRAGDROP_S_DROP)
  7834. {
  7835. try
  7836. {
  7837. GlobalDragImageList->HideDragImage();
  7838. try
  7839. {
  7840. RemoteFileControlDDTargetDrop();
  7841. }
  7842. catch(ESshTerminate & E)
  7843. {
  7844. FDragDropSshTerminate.reset(E.Clone());
  7845. }
  7846. }
  7847. catch (Exception &E)
  7848. {
  7849. // If downloading fails we need to cancel drag&drop, otherwise
  7850. // Explorer shows error
  7851. // But by the way exception probably never reach this point as
  7852. // it's catched on way.
  7853. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7854. Result = DRAGDROP_S_CANCEL;
  7855. ShowExtendedException(Terminal, &E);
  7856. }
  7857. }
  7858. }
  7859. //---------------------------------------------------------------------------
  7860. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7861. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7862. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7863. {
  7864. TFileMasks::TParams MaskParams;
  7865. MaskParams.Size = Size;
  7866. MaskParams.Modification = Modification;
  7867. // this does not re-parse the mask if it is the same as the last time
  7868. FDirViewMatchMask = Masks;
  7869. bool ImplicitMatch;
  7870. Matches =
  7871. // RecurseInclude parameter has no effect as the Path is empty
  7872. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7873. (AllowImplicitMatches || !ImplicitMatch);
  7874. }
  7875. //---------------------------------------------------------------------------
  7876. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7877. TObject * Sender, TListItem * Item, WORD & Indexes)
  7878. {
  7879. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7880. UnicodeString Ext;
  7881. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7882. {
  7883. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7884. }
  7885. else
  7886. {
  7887. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7888. }
  7889. if (SameText(Ext, Configuration->PartialExt))
  7890. {
  7891. Indexes |= oiPartial;
  7892. }
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7896. {
  7897. return
  7898. DirViewEnabled(osCurrent) &&
  7899. DirView(osCurrent)->CanPasteFromClipBoard();
  7900. }
  7901. //---------------------------------------------------------------------------
  7902. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7903. {
  7904. bool Result = false;
  7905. if (CanPasteToDirViewFromClipBoard())
  7906. {
  7907. Result = true;
  7908. }
  7909. else
  7910. {
  7911. UnicodeString ClipboardText;
  7912. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7913. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7914. {
  7915. if (StoredSessions->IsUrl(ClipboardText))
  7916. {
  7917. Result = true;
  7918. }
  7919. else
  7920. {
  7921. Result = DirViewEnabled(osCurrent);
  7922. }
  7923. }
  7924. }
  7925. return Result;
  7926. }
  7927. //---------------------------------------------------------------------------
  7928. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7929. {
  7930. if (DoesClipboardContainOurFiles())
  7931. {
  7932. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7933. {
  7934. DebugAssert(!IsLocalBrowserMode());
  7935. TTerminalManager * Manager = TTerminalManager::Instance();
  7936. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7937. Manager->ActiveSession = FClipboardTerminal;
  7938. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7939. }
  7940. }
  7941. else if (CanPasteToDirViewFromClipBoard())
  7942. {
  7943. DirView(osCurrent)->PasteFromClipBoard();
  7944. }
  7945. else
  7946. {
  7947. UnicodeString ClipboardText;
  7948. if (NonEmptyTextFromClipboard(ClipboardText))
  7949. {
  7950. if (StoredSessions->IsUrl(ClipboardText))
  7951. {
  7952. NewSession(ClipboardText);
  7953. }
  7954. else
  7955. {
  7956. DirView(osCurrent)->Path = ClipboardText;
  7957. }
  7958. }
  7959. }
  7960. }
  7961. //---------------------------------------------------------------------------
  7962. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7963. {
  7964. // TBD
  7965. }
  7966. //---------------------------------------------------------------------------
  7967. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7968. {
  7969. TCustomDirView * ADirView = DirView(Side);
  7970. ADirView->SelectAll(Mode);
  7971. ADirView->SetFocus();
  7972. }
  7973. //---------------------------------------------------------------------------
  7974. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7975. {
  7976. TCustomDirView * ADirView = DirView(Side);
  7977. TFileFilter Filter;
  7978. DefaultFileFilter(Filter);
  7979. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7980. {
  7981. Configuration->Usage->Inc(L"MaskSelections");
  7982. ADirView->SelectFiles(Filter, Select);
  7983. ADirView->SetFocus();
  7984. }
  7985. }
  7986. //---------------------------------------------------------------------------
  7987. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7988. {
  7989. TCustomDirView * ADirView = DirView(Side);
  7990. ADirView->RestoreSelectedNames();
  7991. ADirView->SetFocus();
  7992. }
  7993. //---------------------------------------------------------------------------
  7994. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7995. {
  7996. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7997. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7998. {
  7999. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8000. UnicodeString Ext;
  8001. if (!IsSideLocalBrowser(osCurrent))
  8002. {
  8003. Ext = UnixExtractFileExt(FileName);
  8004. }
  8005. else
  8006. {
  8007. Ext = ExtractFileExt(FileName);
  8008. }
  8009. if (Ext.IsEmpty())
  8010. {
  8011. Ext = L".";
  8012. }
  8013. TFileFilter Filter;
  8014. Filter.Masks = FORMAT(L"*%s", (Ext));
  8015. Filter.Directories = false;
  8016. CurrentDirView->SelectFiles(Filter, Select);
  8017. }
  8018. }
  8019. //---------------------------------------------------------------------------
  8020. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8021. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8022. {
  8023. UnicodeString Result;
  8024. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8025. {
  8026. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8027. }
  8028. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8029. {
  8030. // noop
  8031. }
  8032. else
  8033. {
  8034. Result =
  8035. FMTLOAD(FILE_INFO_FORMAT,
  8036. (FormatBytes(FileInfo.SelectedSize),
  8037. FormatBytes(FileInfo.FilesSize),
  8038. FormatNumber(FileInfo.SelectedCount),
  8039. FormatNumber(FileInfo.FilesCount)));
  8040. }
  8041. return Result;
  8042. }
  8043. //---------------------------------------------------------------------------
  8044. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8045. TTBXStatusPanel * Panel, TOperationSide Side)
  8046. {
  8047. if (Panel->Index == 1)
  8048. {
  8049. ToggleShowHiddenFiles();
  8050. }
  8051. else if (Panel->Index == 2)
  8052. {
  8053. Filter(Side);
  8054. }
  8055. }
  8056. //---------------------------------------------------------------------------
  8057. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8058. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8059. {
  8060. DebugAssert(!StatusBar->SimplePanel);
  8061. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8062. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8063. }
  8064. //---------------------------------------------------------------------------
  8065. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8066. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8067. {
  8068. DebugAssert(StatusBar->Panels->Count >= 3);
  8069. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8070. if (FileInfo.HiddenCount > 0)
  8071. {
  8072. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8073. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8074. }
  8075. else
  8076. {
  8077. HiddenFilesPanel->ViewPriority = 0;
  8078. // not really necessary, just to cleanup no-longer-valid data
  8079. HiddenFilesPanel->Caption = L"";
  8080. }
  8081. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8082. if (FileInfo.FilteredCount > 0)
  8083. {
  8084. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8085. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8086. }
  8087. else
  8088. {
  8089. FilteredFilesPanel->ViewPriority = 0;
  8090. // not really necessary, just to cleanup no-longer-valid data
  8091. FilteredFilesPanel->Caption = L"";
  8092. }
  8093. }
  8094. //---------------------------------------------------------------------------
  8095. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8096. TObject * /*Sender*/)
  8097. {
  8098. if (DirView(osOther)->Enabled)
  8099. {
  8100. DirView(osOther)->SetFocus();
  8101. }
  8102. }
  8103. //---------------------------------------------------------------------------
  8104. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8105. {
  8106. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8107. switch (Config.Show)
  8108. {
  8109. case qvShow:
  8110. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8111. {
  8112. Config.Show = qvHide;
  8113. }
  8114. else
  8115. {
  8116. Config.Show = Config.LastHideShow;
  8117. }
  8118. break;
  8119. case qvHideWhenEmpty:
  8120. if (ComponentVisible[fcQueueView])
  8121. {
  8122. Config.Show = qvHide;
  8123. }
  8124. else
  8125. {
  8126. Config.LastHideShow = Config.Show;
  8127. Config.Show = qvShow;
  8128. }
  8129. break;
  8130. case qvHide:
  8131. Config.LastHideShow = Config.Show;
  8132. Config.Show = qvShow;
  8133. break;
  8134. }
  8135. WinConfiguration->QueueView = Config;
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8139. {
  8140. UnicodeString Result;
  8141. if (Terminal != NULL)
  8142. {
  8143. switch (WinConfiguration->PathInCaption)
  8144. {
  8145. case picShort:
  8146. Result = TTerminalManager::Instance()->GetTerminalShortPath(Terminal);
  8147. break;
  8148. case picFull:
  8149. Result = Terminal->CurrentDirectory;
  8150. break;
  8151. }
  8152. }
  8153. return Result;
  8154. }
  8155. //---------------------------------------------------------------------------
  8156. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8157. {
  8158. TColor Result = GetWindowColor(FSessionColor);
  8159. return Result;
  8160. }
  8161. //---------------------------------------------------------------------------
  8162. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8163. {
  8164. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8165. return Result;
  8166. }
  8167. //---------------------------------------------------------------------------
  8168. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8169. {
  8170. TTerminalManager::Instance()->UpdateAppTitle();
  8171. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8172. // background to gray on Windows 7 (works on Windows 10).
  8173. // See also EnableControl
  8174. if (Showing)
  8175. {
  8176. if (Terminal != NULL)
  8177. {
  8178. // Update path when it changes
  8179. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabSession(SessionsPageControl->ActivePage) == Terminal))
  8180. {
  8181. UpdateSessionTab(SessionsPageControl->ActivePage);
  8182. }
  8183. }
  8184. NonVisualDataModule->ReconnectSessionAction->Update();
  8185. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8186. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8187. CenterReconnectToolbar();
  8188. bool HasTerminal = HasActiveTerminal();
  8189. RemoteDirView->Enabled = HasTerminal;
  8190. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8191. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8192. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8193. RemoteDriveView->Color = RemoteDirView->Color;
  8194. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8195. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8196. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8197. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8198. QueueFileList->Enabled = QueueView3->Enabled;
  8199. QueueFileList->Color = QueueView3->Color;
  8200. QueueFileList->Font->Color = QueueView3->Font->Color;
  8201. QueueLabelUpdateStatus();
  8202. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8203. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8204. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8205. }
  8206. }
  8207. //---------------------------------------------------------------------------
  8208. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8209. {
  8210. UpdateControls();
  8211. }
  8212. //---------------------------------------------------------------------------
  8213. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8214. TObject * Sender)
  8215. {
  8216. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8217. DebugAssert(DirView != NULL);
  8218. DoDirViewLoaded(DirView);
  8219. TransferPresetAutoSelect();
  8220. }
  8221. //---------------------------------------------------------------------------
  8222. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8223. {
  8224. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8225. // first run after installation
  8226. if (double(Updates.LastCheck) == 0)
  8227. {
  8228. // make sure next time there will be an update (if enabled)
  8229. Updates.LastCheck = TDateTime(1);
  8230. WinConfiguration->Updates = Updates;
  8231. }
  8232. else if ((double(Updates.Period) > 0) &&
  8233. (Now() - Updates.LastCheck >= Updates.Period))
  8234. {
  8235. TThreadMethod OnUpdatesChecked = NULL;
  8236. if (!IsUWP())
  8237. {
  8238. OnUpdatesChecked = UpdatesChecked;
  8239. }
  8240. StartUpdateThread(OnUpdatesChecked);
  8241. }
  8242. }
  8243. //---------------------------------------------------------------------------
  8244. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8245. {
  8246. UnicodeString Message;
  8247. bool New;
  8248. TQueryType Type;
  8249. GetUpdatesMessage(Message, New, Type, false);
  8250. if (!Message.IsEmpty())
  8251. {
  8252. if (New)
  8253. {
  8254. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8255. }
  8256. if (!New && (Type != qtWarning))
  8257. {
  8258. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8259. }
  8260. else
  8261. {
  8262. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8263. }
  8264. if (New)
  8265. {
  8266. Configuration->Usage->Inc(L"UpdateNotifications");
  8267. }
  8268. }
  8269. }
  8270. //---------------------------------------------------------------------------
  8271. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8272. {
  8273. RestoreApp();
  8274. bool CanDisplay = !NonVisualDataModule->Busy;
  8275. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8276. {
  8277. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8278. }
  8279. if (CanDisplay)
  8280. {
  8281. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8282. CheckForUpdates(true);
  8283. }
  8284. else
  8285. {
  8286. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8287. }
  8288. }
  8289. //---------------------------------------------------------------------------
  8290. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8291. TCopyParamRuleData & Data)
  8292. {
  8293. DebugAssert(Terminal != NULL);
  8294. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8295. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8296. Data.RemoteDirectory = RemoteDirView->PathName;
  8297. }
  8298. //---------------------------------------------------------------------------
  8299. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8300. {
  8301. // Terminal can be null when we are changing local directory implicitly,
  8302. // because it has been deleted, while no session is connected
  8303. // (Login dialog is open)
  8304. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8305. {
  8306. DebugAssert(!IsLocalBrowserMode());
  8307. TCopyParamRuleData Data;
  8308. GetTransferPresetAutoSelectData(Data);
  8309. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8310. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8311. if (CopyParamIndex < 0)
  8312. {
  8313. // there is no preset that matches autoselection
  8314. // set preset that we consider "default"
  8315. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8316. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8317. }
  8318. else
  8319. {
  8320. // there is preset matching autoselection
  8321. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8322. if (CopyParamName == FCopyParamAutoSelected)
  8323. {
  8324. // autoselected the same preset as the last time
  8325. // make no change (i.e. preserve custom user preset, if any)
  8326. }
  8327. else
  8328. {
  8329. // autoselected the different preset then the last time (or there
  8330. // was default preset set)
  8331. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8332. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8333. }
  8334. }
  8335. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8336. {
  8337. if (CopyParamIndex >= 0)
  8338. {
  8339. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8340. }
  8341. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8342. try
  8343. {
  8344. int Fmt =
  8345. (CopyParamIndex < 0) ?
  8346. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8347. COPY_PARAM_AUTOSELECTED;
  8348. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8349. Data->Message = MainInstructions(Message);
  8350. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8351. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8352. CopyParamAttrs);
  8353. if (CopyParamIndex >= 0)
  8354. {
  8355. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8356. Info = FORMAT(L"%s\n \n%s", (Info,
  8357. FMTLOAD(COPY_PARAM_RULE,
  8358. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8359. }
  8360. Data->Message += L"\n\n" + Info;
  8361. if (WinConfiguration->CopyParamAutoSelectNotice)
  8362. {
  8363. TransferPresetNoteMessage(Data, true);
  8364. }
  8365. else
  8366. {
  8367. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8368. Data = NULL; // ownership passed
  8369. }
  8370. }
  8371. __finally
  8372. {
  8373. delete Data;
  8374. }
  8375. }
  8376. }
  8377. }
  8378. //---------------------------------------------------------------------------
  8379. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8380. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8381. {
  8382. DebugAssert(NoteData != NULL);
  8383. DebugAssert(!IsLocalBrowserMode());
  8384. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8385. TQueryButtonAlias Aliases[1];
  8386. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8387. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8388. Params.Aliases = Aliases;
  8389. Params.AliasesCount = LENOF(Aliases);
  8390. unsigned int Result =
  8391. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8392. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8393. switch (Result)
  8394. {
  8395. case qaNeverAskAgain:
  8396. DebugAssert(AllowNeverAskAgain);
  8397. WinConfiguration->CopyParamAutoSelectNotice = false;
  8398. break;
  8399. case qaIgnore:
  8400. PreferencesDialog(pmPresets);
  8401. break;
  8402. }
  8403. }
  8404. //---------------------------------------------------------------------------
  8405. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8406. {
  8407. // as of now useless, as this is used for notes only, never for balloons, ...
  8408. RestoreApp();
  8409. // .. and we should never be busy here
  8410. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8411. {
  8412. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8413. }
  8414. }
  8415. //---------------------------------------------------------------------------
  8416. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8417. TPreferencesMode APreferencesMode)
  8418. {
  8419. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8420. TCopyParamRuleData Data;
  8421. if (Terminal != NULL)
  8422. {
  8423. PreferencesData.reset(new TPreferencesDialogData());
  8424. GetTransferPresetAutoSelectData(Data);
  8425. PreferencesData->CopyParamRuleData = &Data;
  8426. }
  8427. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8428. }
  8429. //---------------------------------------------------------------------------
  8430. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8431. const TCustomCommandType & Command)
  8432. {
  8433. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8434. {
  8435. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8436. }
  8437. }
  8438. //---------------------------------------------------------------------------
  8439. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8440. {
  8441. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8442. TCustomCommandType Command;
  8443. // make sure we use local custom command when remote are not supported
  8444. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8445. {
  8446. Command = FLastCustomCommand;
  8447. }
  8448. else
  8449. {
  8450. Command.Params = Command.Params | ccLocal;
  8451. }
  8452. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8453. FEditingFocusedAdHocCommand = OnFocused;
  8454. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8455. int Options =
  8456. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8457. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8458. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8459. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8460. {
  8461. FLastCustomCommand = Command;
  8462. UpdateCustomCommandsToolbar();
  8463. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8464. }
  8465. }
  8466. //---------------------------------------------------------------------------
  8467. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8468. {
  8469. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8470. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8471. DebugAssert(State > 0);
  8472. if (State <= 0)
  8473. {
  8474. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8475. }
  8476. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8477. }
  8478. //---------------------------------------------------------------------------
  8479. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8480. TCustomCommandType & Command, int & State)
  8481. {
  8482. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8483. if (Result)
  8484. {
  8485. Command = FLastCustomCommand;
  8486. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8487. }
  8488. return Result;
  8489. }
  8490. //---------------------------------------------------------------------------
  8491. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8492. {
  8493. ResetIncrementalSearch();
  8494. }
  8495. //---------------------------------------------------------------------------
  8496. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8497. {
  8498. DebugAssert(ComponentVisible[Component]);
  8499. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8500. }
  8501. //---------------------------------------------------------------------------
  8502. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8503. {
  8504. // when queue panel is resized here directly, the status bar is stretched
  8505. // over whole space the panel occupied
  8506. PostComponentHide(fcQueueView);
  8507. }
  8508. //---------------------------------------------------------------------------
  8509. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8510. {
  8511. ComponentVisible[fcQueueFileList] = false;
  8512. }
  8513. //---------------------------------------------------------------------------
  8514. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8515. {
  8516. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8517. RefreshColorMode();
  8518. ResetSysDarkTheme();
  8519. ConfigurationChanged();
  8520. ConfigureInterface();
  8521. // Should be called for all controls
  8522. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8523. }
  8524. //---------------------------------------------------------------------------
  8525. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8526. {
  8527. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8528. if (!FInvalid &&
  8529. (Message.LParam != 0) &&
  8530. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8531. {
  8532. ThemeChanged();
  8533. }
  8534. TForm::Dispatch(&Message);
  8535. }
  8536. //---------------------------------------------------------------------------
  8537. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8538. {
  8539. TMessage * M = static_cast<TMessage*>(Message);
  8540. switch (M->Msg)
  8541. {
  8542. case CM_DIALOGCHAR:
  8543. CMDialogChar(*M);
  8544. break;
  8545. case WM_APPCOMMAND:
  8546. WMAppCommand(*M);
  8547. break;
  8548. case WM_SYSCOMMAND:
  8549. WMSysCommand(*M);
  8550. break;
  8551. case WM_QUERYENDSESSION:
  8552. WMQueryEndSession(*M);
  8553. break;
  8554. case WM_ENDSESSION:
  8555. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8556. break;
  8557. #ifdef _DEBUG
  8558. case WM_WINDOWPOSCHANGED:
  8559. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8560. break;
  8561. case CM_CUSTOMSTYLECHANGED:
  8562. TForm::Dispatch(Message);
  8563. break;
  8564. #endif
  8565. case WM_COMPONENT_HIDE:
  8566. {
  8567. Byte Component = static_cast<Byte>(M->WParam);
  8568. // sanity check
  8569. if (ComponentVisible[Component])
  8570. {
  8571. // special treatment
  8572. if (Component == fcQueueView)
  8573. {
  8574. ToggleQueueVisibility();
  8575. DebugAssert(!ComponentVisible[fcQueueView]);
  8576. }
  8577. else
  8578. {
  8579. ComponentVisible[Component] = false;
  8580. }
  8581. }
  8582. }
  8583. break;
  8584. case WM_COPYDATA:
  8585. WMCopyData(*M);
  8586. break;
  8587. case WM_MANAGES_CAPTION:
  8588. // caption managed in TTerminalManager::UpdateAppTitle()
  8589. M->Result = 1;
  8590. break;
  8591. case WM_WANTS_MOUSEWHEEL:
  8592. M->Result = 1;
  8593. break;
  8594. case CM_SHOWINGCHANGED:
  8595. CMShowingChanged(*M);
  8596. break;
  8597. case WM_CLOSE:
  8598. WMClose(*M);
  8599. break;
  8600. case WM_DPICHANGED:
  8601. WMDpiChanged(*M);
  8602. break;
  8603. case CM_DPICHANGED:
  8604. CMDpiChanged(*M);
  8605. break;
  8606. case WM_SETTINGCHANGE:
  8607. WMSettingChange(*M);
  8608. break;
  8609. case CM_DIALOGKEY:
  8610. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8611. break;
  8612. default:
  8613. TForm::Dispatch(Message);
  8614. break;
  8615. }
  8616. }
  8617. //---------------------------------------------------------------------------
  8618. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8619. {
  8620. // noop
  8621. }
  8622. //---------------------------------------------------------------------------
  8623. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8624. {
  8625. TForm::Dispatch(&Message);
  8626. FSessionColors->Clear();
  8627. AddFixedSessionImages();
  8628. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8629. UpdateImages();
  8630. }
  8631. //---------------------------------------------------------------------------
  8632. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8633. {
  8634. TForm::Dispatch(&Message);
  8635. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8636. UpdatePixelsPerInchMainWindowCounter();
  8637. }
  8638. //---------------------------------------------------------------------------
  8639. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8640. {
  8641. // Cannot close window while we are busy.
  8642. // We cannot test this in FormCloseQuery as that is called also from
  8643. // Close(), which is called by CloseApplicationAction. So we can be busy
  8644. // there already even, when it is legitimate to close the application.
  8645. // Possibly a better place to handle this would be WMSysCommand.
  8646. if (NonVisualDataModule->Busy)
  8647. {
  8648. Message.Result = 1;
  8649. }
  8650. else
  8651. {
  8652. TForm::Dispatch(&Message);
  8653. }
  8654. }
  8655. //---------------------------------------------------------------------------
  8656. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8657. {
  8658. TForm::Dispatch(&Message);
  8659. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8660. if (Showing && !FStarted)
  8661. {
  8662. FStarted = true;
  8663. InterfaceStarted();
  8664. }
  8665. if (Showing && (Terminal == NULL))
  8666. {
  8667. // When we are starting minimized (i.e. from an installer),
  8668. // postpone showing Login dialog until we get restored.
  8669. // Otherwise the Login dialog (and Authentication window) show restored
  8670. // over invisible (minimized) main window.
  8671. if (WindowState == wsMinimized)
  8672. {
  8673. FNeedSession = true;
  8674. }
  8675. else
  8676. {
  8677. // This happens before application ever goes idle, so the toolbars would
  8678. // stay enabled (initial state) until the Login dialog is dismissed.
  8679. UpdateActions();
  8680. NonVisualDataModule->StartBusy();
  8681. try
  8682. {
  8683. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8684. // otherwise the dialog does not receive focus.
  8685. // With Commander interface the ProcessMessages is called already
  8686. // by TDriveView, but with Explorer interface, we need to call it explicily
  8687. Application->ProcessMessages();
  8688. // do not reload sessions, they have been loaded just now (optimization)
  8689. NeedSession(true);
  8690. }
  8691. __finally
  8692. {
  8693. NonVisualDataModule->EndBusy();
  8694. }
  8695. }
  8696. }
  8697. }
  8698. //---------------------------------------------------------------------------
  8699. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8700. {
  8701. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8702. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8703. }
  8704. //---------------------------------------------------------------------------
  8705. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8706. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8707. int & MaxHeight)
  8708. {
  8709. // workaround for bug in TWinControl.CalcConstraints
  8710. // Check for empty rect (restore from iconic state) is done there only after
  8711. // call to AdjustClientRect, which enlarges the rect (for forms).
  8712. TRect R = GetClientRect();
  8713. // when restoring from iconic state, place no restrictions
  8714. if (IsRectEmpty(R))
  8715. {
  8716. MinWidth = 0;
  8717. MinHeight = 0;
  8718. MaxWidth = 32000;
  8719. MaxHeight = 32000;
  8720. }
  8721. }
  8722. //---------------------------------------------------------------------------
  8723. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8724. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8725. {
  8726. // terminal can be already closed (e.g. dropped connection)
  8727. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8728. {
  8729. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8730. try
  8731. {
  8732. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8733. }
  8734. catch(...)
  8735. {
  8736. if (!Terminal->Active)
  8737. {
  8738. Close = true;
  8739. }
  8740. throw;
  8741. }
  8742. }
  8743. }
  8744. //---------------------------------------------------------------------------
  8745. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8746. {
  8747. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8748. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8749. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8750. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8751. {
  8752. OnGetSpaceAvailable = GetSpaceAvailable;
  8753. }
  8754. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8755. OnGetSpaceAvailable);
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8759. {
  8760. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8761. Terminal->FillSessionDataForCode(Data.get());
  8762. return Data.release();
  8763. }
  8764. //---------------------------------------------------------------------------
  8765. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8766. {
  8767. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8768. DoGenerateUrlDialog(Data.get(), Paths);
  8769. }
  8770. //---------------------------------------------------------------------------
  8771. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8772. {
  8773. GenerateUrl(NULL);
  8774. }
  8775. //---------------------------------------------------------------------------
  8776. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8777. {
  8778. std::unique_ptr<TStrings> Paths(new TStringList());
  8779. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8780. GenerateUrl(Paths.get());
  8781. }
  8782. //---------------------------------------------------------------------------
  8783. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8784. {
  8785. FSessionColor = value;
  8786. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8787. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8788. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8789. DebugAssert(ColorItem != NULL);
  8790. ColorItem->Color = C;
  8791. NonVisualDataModule->ColorMenuItem->Color = C;
  8792. UpdateControls();
  8793. }
  8794. //---------------------------------------------------------------------------
  8795. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8796. {
  8797. if (value != FSessionColor)
  8798. {
  8799. UpdateSessionColor(value);
  8800. // Is null when called from LastTerminalClosed
  8801. if (Terminal != NULL)
  8802. {
  8803. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8804. }
  8805. }
  8806. }
  8807. //---------------------------------------------------------------------------
  8808. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8809. {
  8810. bool Result = FNoteTimer->Enabled;
  8811. if (Result)
  8812. {
  8813. // cannot cancel note too early
  8814. bool NotEarly =
  8815. (Now() - FNoteShown >
  8816. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8817. if (Force || NotEarly)
  8818. {
  8819. FNoteTimer->Enabled = false;
  8820. FNote = L"";
  8821. SAFE_DESTROY(FNoteData);
  8822. FOnNoteClick = NULL;
  8823. FNoteHints = FNotes->Text;
  8824. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8825. UpdateStatusBar();
  8826. }
  8827. }
  8828. return Result;
  8829. }
  8830. //---------------------------------------------------------------------------
  8831. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8832. {
  8833. DebugAssert(FNoteTimer->Enabled);
  8834. CancelNote(true);
  8835. }
  8836. //---------------------------------------------------------------------------
  8837. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8838. {
  8839. FNoteHints = FNotes->Text.TrimRight();
  8840. }
  8841. //---------------------------------------------------------------------------
  8842. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8843. {
  8844. int P = Note.Pos(L"\n");
  8845. if (P > 0)
  8846. {
  8847. Note.SetLength(P - 1);
  8848. }
  8849. FNotes->Add(FORMAT(L"[%s] %s",
  8850. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8851. while (FNotes->Count > 10)
  8852. {
  8853. FNotes->Delete(0);
  8854. }
  8855. if (UpdateNow)
  8856. {
  8857. UpdateNoteHints();
  8858. UpdateStatusBar();
  8859. }
  8860. }
  8861. //---------------------------------------------------------------------------
  8862. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8863. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8864. {
  8865. int P = Note.Pos(L"\n");
  8866. if (P > 0)
  8867. {
  8868. Note.SetLength(P - 1);
  8869. }
  8870. UpdateNoteHints();
  8871. FNote = Note;
  8872. SAFE_DESTROY(FNoteData);
  8873. FNoteData = NoteData;
  8874. FOnNoteClick = OnNoteClick;
  8875. AddNote(Note, false);
  8876. UpdateStatusBar();
  8877. FNoteShown = Now();
  8878. FNoteTimer->Enabled = false;
  8879. if (Seconds == 0)
  8880. {
  8881. Seconds = WinConfiguration->NotificationsTimeout;
  8882. }
  8883. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8884. FNoteTimer->Enabled = true;
  8885. }
  8886. //---------------------------------------------------------------------------
  8887. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8888. {
  8889. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8893. {
  8894. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8895. {
  8896. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8897. }
  8898. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8899. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8900. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8901. 0, NULL, NULL);
  8902. }
  8903. //---------------------------------------------------------------------------
  8904. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8905. {
  8906. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8907. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8908. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8909. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8910. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8911. }
  8912. //---------------------------------------------------------------------------
  8913. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8914. {
  8915. WinConfiguration->FormatSizeBytes = Style;
  8916. }
  8917. //---------------------------------------------------------------------------
  8918. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8919. {
  8920. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8921. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8922. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8923. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8924. }
  8925. //---------------------------------------------------------------------------
  8926. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8927. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8928. {
  8929. if (Panel->Index == 0)
  8930. {
  8931. if (FOnNoteClick != NULL)
  8932. {
  8933. // prevent the user data from being freed by possible call
  8934. // to CancelNote or PostNote during call to OnNoteClick
  8935. std::unique_ptr<TObject> NoteData(FNoteData);
  8936. TNotifyEvent OnNoteClick = FOnNoteClick;
  8937. FNoteData = NULL;
  8938. // need to cancel the note as we are going to delete its user data
  8939. CancelNote(true);
  8940. OnNoteClick(NoteData.get());
  8941. }
  8942. }
  8943. if (HasActiveTerminal() &&
  8944. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8945. {
  8946. FileSystemInfo();
  8947. }
  8948. }
  8949. //---------------------------------------------------------------------------
  8950. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8951. {
  8952. // workaround:
  8953. // 1) for unknown reason, disabling window, while minimized,
  8954. // prevents it from restoring, even if it was enabled again meanwhile
  8955. // 2) when disabling the main window, while another has focus
  8956. // minimize is no longer possible
  8957. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8958. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8959. // Shouldn't we use IsApplicationMinimized() here?
  8960. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8961. {
  8962. Enabled = false;
  8963. }
  8964. FLockLevel++;
  8965. }
  8966. //---------------------------------------------------------------------------
  8967. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8968. {
  8969. DebugAssert(FLockLevel > 0);
  8970. FLockLevel--;
  8971. if (FLockLevel == 0)
  8972. {
  8973. DebugAssert(FLockSuspendLevel == 0);
  8974. Enabled = true;
  8975. }
  8976. }
  8977. //---------------------------------------------------------------------------
  8978. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8979. {
  8980. // We need to make sure that window is enabled when the last modal window closes
  8981. // otherwise focus is not restored correctly.
  8982. // So we re-enable the window when modal window opens and
  8983. // disable it back after is closes
  8984. if (FLockLevel > 0)
  8985. {
  8986. // while we have nesting counter, we know that we never be called
  8987. // recursivelly as Application->OnModalBegin is called only
  8988. // for the top-level modal window
  8989. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8990. {
  8991. // won't be disabled when conditions in LockWindow() were not satisfied
  8992. FDisabledOnLockSuspend = !Enabled;
  8993. // When minimized to tray (or actually when set to SW_HIDE),
  8994. // setting Enabled makes the window focusable even when there's
  8995. // modal window over it
  8996. if (!FTrayIcon->Visible)
  8997. {
  8998. Enabled = true;
  8999. }
  9000. }
  9001. FLockSuspendLevel++;
  9002. }
  9003. }
  9004. //---------------------------------------------------------------------------
  9005. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9006. {
  9007. if (FLockSuspendLevel > 0)
  9008. {
  9009. DebugAssert(FLockLevel > 0);
  9010. FLockSuspendLevel--;
  9011. // see comment in SuspendWindowLock
  9012. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9013. {
  9014. // Note that window can be enabled here, when we were minized to tray when
  9015. // was SuspendWindowLock() called.
  9016. // We should possibly do the same check as in LockWindow(),
  9017. // if it is ever possible that the consitions change between
  9018. // SuspendWindowLock() and ResumeWindowLock()
  9019. Enabled = !FDisabledOnLockSuspend;
  9020. }
  9021. }
  9022. }
  9023. //---------------------------------------------------------------------------
  9024. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9025. {
  9026. TTBXComboBoxItem * RemotePathComboBox =
  9027. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9028. if (!TextOnly)
  9029. {
  9030. TStrings * Items = RemotePathComboBox->Strings;
  9031. Items->BeginUpdate();
  9032. try
  9033. {
  9034. Items->Clear();
  9035. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9036. {
  9037. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9038. while (!IsUnixRootPath(APath))
  9039. {
  9040. int P = APath.LastDelimiter(L'/');
  9041. DebugAssert(P >= 0);
  9042. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9043. APath.SetLength(P - 1);
  9044. }
  9045. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9046. }
  9047. }
  9048. __finally
  9049. {
  9050. Items->EndUpdate();
  9051. }
  9052. }
  9053. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9054. // Setting ItemIndex to -1 does not reset its text
  9055. if (RemotePathComboBox->Strings->Count == 0)
  9056. {
  9057. RemotePathComboBox->Text = L"";
  9058. }
  9059. }
  9060. //---------------------------------------------------------------------------
  9061. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9062. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9063. {
  9064. if (AIndex < 0)
  9065. {
  9066. AIndex = Sender->ItemIndex;
  9067. }
  9068. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9069. }
  9070. //---------------------------------------------------------------------------
  9071. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9072. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9073. int & ImageIndex)
  9074. {
  9075. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9076. }
  9077. //---------------------------------------------------------------------------
  9078. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9079. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9080. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9081. {
  9082. if (!IsLocalBrowserMode())
  9083. {
  9084. ARect.Left += (10 * AIndex);
  9085. }
  9086. }
  9087. //---------------------------------------------------------------------------
  9088. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9089. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9090. {
  9091. AWidth += (10 * AIndex);
  9092. }
  9093. //---------------------------------------------------------------------------
  9094. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9095. {
  9096. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9097. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9098. int Index = RemotePathComboBox->ItemIndex;
  9099. while (Index < RemotePathComboBox->Strings->Count - 1)
  9100. {
  9101. APath = UnixExtractFileDir(APath);
  9102. Index++;
  9103. }
  9104. // VanDyke style paths
  9105. if (APath.IsEmpty())
  9106. {
  9107. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9108. APath = ROOTDIRECTORY;
  9109. }
  9110. if (RemoteDirView->Path != APath)
  9111. {
  9112. RemoteDirView->Path = APath;
  9113. }
  9114. }
  9115. //---------------------------------------------------------------------------
  9116. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9117. {
  9118. DoRemotePathComboBoxItemClick(Sender);
  9119. }
  9120. //---------------------------------------------------------------------------
  9121. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9122. {
  9123. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9124. DebugUsedParam(Sender);
  9125. UpdateRemotePathComboBox(true);
  9126. }
  9127. //---------------------------------------------------------------------------
  9128. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9129. {
  9130. DoRemotePathComboBoxCancel(Sender);
  9131. }
  9132. //---------------------------------------------------------------------------
  9133. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9134. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9135. {
  9136. ResetIncrementalSearch();
  9137. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9138. DebugAssert(DirView != NULL);
  9139. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9140. {
  9141. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9142. // OnEditing is called also from TCustomListView::CanEdit
  9143. if (Edit != NULL)
  9144. {
  9145. EditSelectBaseName(Edit);
  9146. }
  9147. }
  9148. }
  9149. //---------------------------------------------------------------------------
  9150. //---------------------------------------------------------------------------
  9151. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9152. {
  9153. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9154. Result->AutoDetectDnD = false;
  9155. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9156. Result->RenderDataOn = rdoEnterAndDropSync;
  9157. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9158. return Result;
  9159. }
  9160. //---------------------------------------------------------------------------
  9161. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9162. {
  9163. TForm::CreateWnd();
  9164. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9165. if (IsWin10Build(2004))
  9166. {
  9167. BOOL DarkMode = TRUE;
  9168. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9169. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9170. }
  9171. if (FSessionsDragDropFilesEx == NULL)
  9172. {
  9173. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9174. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9175. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9176. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9177. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9178. }
  9179. if (FQueueDragDropFilesEx == NULL)
  9180. {
  9181. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9182. // No need to set OnDragOver as we do not have any restrictions
  9183. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9184. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9185. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9186. }
  9187. }
  9188. //---------------------------------------------------------------------------
  9189. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9190. {
  9191. TForm::DestroyWnd();
  9192. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9193. FQueueDragDropFilesEx->DragDropControl = NULL;
  9194. }
  9195. //---------------------------------------------------------------------------
  9196. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9197. {
  9198. SideEnter(FCurrentSide);
  9199. FEverShown = true;
  9200. }
  9201. //---------------------------------------------------------------------------
  9202. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9203. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9204. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9205. {
  9206. if (!NonVisualDataModule->Busy)
  9207. {
  9208. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9209. Configuration->Usage->Inc(L"FileFinds");
  9210. LockWindow(true);
  9211. NonVisualDataModule->StartBusy();
  9212. WinConfiguration->LockedInterface = true;
  9213. try
  9214. {
  9215. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9216. }
  9217. __finally
  9218. {
  9219. WinConfiguration->LockedInterface = false;
  9220. NonVisualDataModule->EndBusy();
  9221. UnlockWindow();
  9222. }
  9223. }
  9224. }
  9225. //---------------------------------------------------------------------------
  9226. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9227. {
  9228. if (!NonVisualDataModule->Busy)
  9229. {
  9230. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9231. SetFocus();
  9232. RemoteDirView->Path = UnixExtractFilePath(Path);
  9233. UnicodeString FileName = UnixExtractFileName(Path);
  9234. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9235. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9236. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9237. if (Item == NULL)
  9238. {
  9239. ReloadDirectory(osRemote);
  9240. Item = RemoteDirView->FindFileItem(FileName);
  9241. }
  9242. if (Item != NULL)
  9243. {
  9244. RemoteDirView->ItemFocused = Item;
  9245. RemoteDirView->ItemFocused->MakeVisible(false);
  9246. RemoteDirView->SetFocus();
  9247. }
  9248. }
  9249. }
  9250. //---------------------------------------------------------------------------
  9251. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9252. {
  9253. bool Result = !NonVisualDataModule->Busy;
  9254. if (Result)
  9255. {
  9256. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9257. }
  9258. return Result;
  9259. }
  9260. //---------------------------------------------------------------------------
  9261. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9262. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9263. {
  9264. if (CanOperateOnFoundFiles(ATerminal))
  9265. {
  9266. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9267. FOnFileOperationFinished = OnFileOperationFinished;
  9268. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9269. }
  9270. }
  9271. //---------------------------------------------------------------------------
  9272. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9273. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9274. {
  9275. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9276. }
  9277. //---------------------------------------------------------------------------
  9278. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9279. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9280. {
  9281. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9282. }
  9283. //---------------------------------------------------------------------------
  9284. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9285. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9286. {
  9287. if (CanOperateOnFoundFiles(ATerminal))
  9288. {
  9289. for (int Index = 0; Index < FileList->Count; Index++)
  9290. {
  9291. UnicodeString FileName = FileList->Strings[Index];
  9292. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9293. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9294. OnFileOperationFinished(FileName, true);
  9295. }
  9296. }
  9297. }
  9298. //---------------------------------------------------------------------------
  9299. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9300. {
  9301. FFileFindTerminal = Terminal;
  9302. ShowFileFindDialog(
  9303. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9304. DoDownloadFoundFiles, DoEditFoundFiles);
  9305. }
  9306. //---------------------------------------------------------------------------
  9307. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9308. {
  9309. FTaskbarList = TaskbarList;
  9310. }
  9311. //---------------------------------------------------------------------------
  9312. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9313. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9314. {
  9315. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9316. if (Index >= 0)
  9317. {
  9318. if (Button == mbLeft)
  9319. {
  9320. // "Mouse down" is raised only after tab is switched.
  9321. // If switching tab (switching session) takes long enough for user
  9322. // to actually release the button, "mouse down" is still raised,
  9323. // but we do not get "mouse up" event, so dragging is not cancelled,
  9324. // prevent that by not beginning dragging in the first place.
  9325. if (IsKeyPressed(VK_LBUTTON))
  9326. {
  9327. // when user clicks the "+", we get mouse down only after the session
  9328. // is closed, when new session tab is already on X:Y, so dragging
  9329. // starts, prevent that
  9330. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9331. {
  9332. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9333. if (Terminal != NULL)
  9334. {
  9335. SessionsPageControl->BeginDrag(false);
  9336. }
  9337. }
  9338. }
  9339. }
  9340. else if (Button == mbMiddle)
  9341. {
  9342. // ignore middle-click for "New session tab"
  9343. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9344. if (Terminal != NULL)
  9345. {
  9346. CloseSessionTab(Index);
  9347. }
  9348. }
  9349. }
  9350. }
  9351. //---------------------------------------------------------------------------
  9352. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9353. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9354. {
  9355. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9356. // do not allow dropping on the "+" tab
  9357. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9358. if ((TargetTerminal != NULL) &&
  9359. (SessionsPageControl->ActivePage->PageIndex != Index))
  9360. {
  9361. Configuration->Usage->Inc(L"SessionTabMoves");
  9362. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9363. // but we want to actually prevent that to avoid flicker
  9364. SessionsPageControl->ActivePage->PageIndex = Index;
  9365. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9366. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9367. }
  9368. }
  9369. //---------------------------------------------------------------------------
  9370. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9371. TObject * Sender, TObject * Source, int X, int Y,
  9372. TDragState /*State*/, bool & Accept)
  9373. {
  9374. Accept = (Sender == Source);
  9375. if (Accept)
  9376. {
  9377. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9378. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9379. // do not allow dragging to the "+" tab
  9380. Accept = (Terminal != NULL);
  9381. }
  9382. }
  9383. //---------------------------------------------------------------------------
  9384. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9385. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9386. {
  9387. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9388. if (Index < 0)
  9389. {
  9390. Effect = DROPEFFECT_NONE;
  9391. }
  9392. else
  9393. {
  9394. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9395. // do not allow dropping on the "+" tab
  9396. if (TargetTerminal == NULL)
  9397. {
  9398. Effect = DROPEFFECT_NONE;
  9399. }
  9400. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9401. {
  9402. Effect = DROPEFFECT_COPY;
  9403. }
  9404. }
  9405. }
  9406. //---------------------------------------------------------------------------
  9407. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9408. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9409. {
  9410. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9411. // do not allow dropping on the "+" tab
  9412. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9413. if (TargetTerminal != NULL)
  9414. {
  9415. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9416. if (!IsFileControl(DropSourceControl, osRemote))
  9417. {
  9418. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9419. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9420. // Why don't we use Terminal->CurrentDirectory directly?
  9421. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9422. // do not force queue, drag drop
  9423. false, true);
  9424. }
  9425. }
  9426. }
  9427. //---------------------------------------------------------------------------
  9428. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9429. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9430. {
  9431. // Downloads are handled in RemoteFileControlDDEnd
  9432. if (!IsFileControl(DropSourceControl, osRemote))
  9433. {
  9434. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9435. Terminal->CurrentDirectory,
  9436. // force queue, drag drop
  9437. true, true);
  9438. }
  9439. }
  9440. //---------------------------------------------------------------------------
  9441. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9442. {
  9443. FShowing = false;
  9444. // Do not save empty workspace
  9445. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9446. {
  9447. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9448. UnicodeString Name = WorkspaceName();
  9449. DoSaveWorkspace(
  9450. Name, DataList.get(),
  9451. !Configuration->DisablePasswordStoring &&
  9452. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9453. WinConfiguration->LastStoredSession = Name;
  9454. }
  9455. }
  9456. //---------------------------------------------------------------------------
  9457. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9458. {
  9459. TManagedTerminal * ManagedTerminal =
  9460. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9461. if (ManagedTerminal != NULL)
  9462. {
  9463. ManagedTerminal->DirectoryLoaded = Now();
  9464. }
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9468. TListItem * /*Item*/, bool /*Selected*/)
  9469. {
  9470. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9471. switch (DirView->LastSelectMethod)
  9472. {
  9473. case smKeyboard:
  9474. Configuration->Usage->Inc(L"KeyboardSelections");
  9475. break;
  9476. case smMouse:
  9477. Configuration->Usage->Inc(L"MouseSelections");
  9478. break;
  9479. }
  9480. }
  9481. //---------------------------------------------------------------------------
  9482. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9483. {
  9484. if (Color != 0)
  9485. {
  9486. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9487. }
  9488. else
  9489. {
  9490. return FSessionTabImageIndex;
  9491. }
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9495. {
  9496. TPngImageCollectionItem * Item =
  9497. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9498. FSessionColors->AddPng(Item->PngImage);
  9499. return FSessionColors->Count - 1;
  9500. }
  9501. //---------------------------------------------------------------------------
  9502. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9503. {
  9504. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9505. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9506. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9507. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9508. }
  9509. //---------------------------------------------------------------------------
  9510. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9511. {
  9512. for (int Index = 0; Index < Control->ControlCount; Index++)
  9513. {
  9514. TControl * AControl = Control->Controls[Index];
  9515. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9516. if (WinControl != NULL)
  9517. {
  9518. CollectItemsWithTextDisplayMode(WinControl);
  9519. }
  9520. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9521. if (Toolbar != NULL)
  9522. {
  9523. // we care for top-level items only
  9524. TTBCustomItem * Items = Toolbar->Items;
  9525. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9526. {
  9527. TTBCustomItem * Item = Items->Items[ItemIndex];
  9528. if (((Item->DisplayMode == nbdmImageAndText) ||
  9529. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9530. EligibleForImageDisplayMode(Item))
  9531. {
  9532. FItemsWithTextDisplayMode.insert(Item);
  9533. }
  9534. }
  9535. }
  9536. }
  9537. }
  9538. //---------------------------------------------------------------------------
  9539. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9540. {
  9541. return true;
  9542. }
  9543. //---------------------------------------------------------------------------
  9544. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9545. {
  9546. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9547. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9548. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9549. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9550. bool Result = true;
  9551. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9552. {
  9553. TTBCustomItem * Item = *i;
  9554. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9555. if (Label != NULL)
  9556. {
  9557. // optimization
  9558. if (Label->Visible == SelectiveToolbarText)
  9559. {
  9560. Result = false;
  9561. }
  9562. else
  9563. {
  9564. Label->Visible = SelectiveToolbarText;
  9565. }
  9566. }
  9567. else
  9568. {
  9569. // optimization
  9570. if (Item->DisplayMode == DisplayMode)
  9571. {
  9572. Result = false;
  9573. }
  9574. else
  9575. {
  9576. Item->DisplayMode = DisplayMode;
  9577. }
  9578. }
  9579. ++i;
  9580. }
  9581. if (Result)
  9582. {
  9583. UpdateNewSessionTab();
  9584. }
  9585. return Result;
  9586. }
  9587. //---------------------------------------------------------------------------
  9588. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9589. {
  9590. DebugFail();
  9591. }
  9592. //---------------------------------------------------------------------------
  9593. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9594. {
  9595. // Among other, a lock level is non zero, while directory is being loaded,
  9596. // even when it happens as a result of dirview navigation,
  9597. // i.e. when TNonVisualDataModule is NOT FBusy.
  9598. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9599. // Among other this prevents a panel auto update to occur while
  9600. // directory is changing.
  9601. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9602. }
  9603. //---------------------------------------------------------------------------
  9604. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9605. {
  9606. // While the window is disabled, we still seem to process menu shortcuts at least,
  9607. // so stop it at least here.
  9608. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9609. bool Result;
  9610. if (Allowed == aaUpdate)
  9611. {
  9612. Result = true;
  9613. }
  9614. else
  9615. {
  9616. Result = !NonVisualDataModule->Busy;
  9617. if (Result && (Allowed == aaShortCut))
  9618. {
  9619. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9620. Action->Update();
  9621. Result = Action->Enabled;
  9622. }
  9623. }
  9624. return Result;
  9625. }
  9626. //---------------------------------------------------------------------------
  9627. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9628. {
  9629. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9630. }
  9631. //---------------------------------------------------------------------------
  9632. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9633. {
  9634. // This is somewhat redundant to LockWindow() call from
  9635. // TTerminalManager::TerminalReadDirectoryProgress.
  9636. // But disabling window is known not to block keyboard shorcuts
  9637. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9638. if (Busy > 0)
  9639. {
  9640. if (NonVisualDataModule->Busy)
  9641. {
  9642. State = false;
  9643. }
  9644. else
  9645. {
  9646. NonVisualDataModule->StartBusy();
  9647. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9648. LockWindow();
  9649. }
  9650. }
  9651. else if (Busy < 0)
  9652. {
  9653. UnlockWindow();
  9654. NonVisualDataModule->EndBusy();
  9655. }
  9656. else
  9657. {
  9658. State = NonVisualDataModule->Busy;
  9659. }
  9660. }
  9661. //---------------------------------------------------------------------------
  9662. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9663. {
  9664. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9665. // no context menu for "New session tab"
  9666. if ((Index >= 0) && (GetSessionTabSession(SessionsPageControl->Pages[Index]) != NULL))
  9667. {
  9668. SessionsPageControl->ActivePageIndex = Index;
  9669. if (DebugAlwaysTrue(SessionTabSwitched()))
  9670. {
  9671. // copied from TControl.WMContextMenu
  9672. SendCancelMode(SessionsPageControl);
  9673. // explicit popup instead of using PopupMenu property
  9674. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9675. // while connecting yet not-connected session and hence
  9676. // allowing an access to commands over not-completelly connected session
  9677. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9678. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9679. PopupMenu->PopupComponent = SessionsPageControl;
  9680. PopupMenu->Popup(Point.x, Point.y);
  9681. }
  9682. }
  9683. Handled = true;
  9684. }
  9685. //---------------------------------------------------------------------------
  9686. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9687. {
  9688. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9689. }
  9690. //---------------------------------------------------------------------------
  9691. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9692. {
  9693. Configuration->Usage->Inc(L"PasswordChanges");
  9694. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9695. ChangePasswordData->DisableAuthentationsExceptPassword();
  9696. ChangePasswordData->ChangePassword = true;
  9697. std::unique_ptr<TTerminal> ChangePasswordSession(
  9698. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9699. ChangePasswordSession->AutoReadDirectory = false;
  9700. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9701. {
  9702. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9703. }
  9704. else
  9705. {
  9706. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9707. }
  9708. }
  9709. //---------------------------------------------------------------------------
  9710. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9711. {
  9712. // No nice way to assert SSH2
  9713. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9714. }
  9715. //---------------------------------------------------------------------------
  9716. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9717. {
  9718. TOperationVisualizer OperationVisualizer;
  9719. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9720. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9721. }
  9722. //---------------------------------------------------------------------------
  9723. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9724. {
  9725. TForm::ChangeScale(M, D);
  9726. int APixelsPerInch = GetControlPixelsPerInch(this);
  9727. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9728. try
  9729. {
  9730. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9731. }
  9732. __finally
  9733. {
  9734. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9735. }
  9736. }
  9737. //---------------------------------------------------------------------------
  9738. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9739. {
  9740. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9741. }
  9742. //---------------------------------------------------------------------
  9743. class TPublicControl : public TControl
  9744. {
  9745. friend class TCustomScpExplorerForm;
  9746. };
  9747. //---------------------------------------------------------------------------
  9748. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9749. {
  9750. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9751. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9752. }
  9753. //---------------------------------------------------------------------------
  9754. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9755. {
  9756. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9757. OpenBookmark(Side, Bookmark);
  9758. }
  9759. //---------------------------------------------------------------------------
  9760. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9761. {
  9762. DoBookmarkClick(osLocal, Sender);
  9763. }
  9764. //---------------------------------------------------------------------------
  9765. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9766. {
  9767. DoBookmarkClick(osRemote, Sender);
  9768. }
  9769. //---------------------------------------------------------------------------
  9770. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9771. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9772. {
  9773. if (BookmarkList != NULL)
  9774. {
  9775. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9776. if (IsLocalBrowserMode())
  9777. {
  9778. Side = osLocal;
  9779. }
  9780. if (!WinConfiguration->UseLocationProfiles)
  9781. {
  9782. std::unique_ptr<TStringList> Directories(new TStringList());
  9783. Directories->CaseSensitive = (Side == osRemote);
  9784. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9785. {
  9786. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9787. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9788. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9789. {
  9790. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9791. Item->Caption = EscapeHotkey(Directory);
  9792. Item->ShortCut = Bookmark->ShortCut;
  9793. Item->OnClick = OnBookmarkClick;
  9794. Item->Tag = reinterpret_cast<int>(Bookmark);
  9795. Directories->Add(Directory);
  9796. Menu->Add(Item.release());
  9797. }
  9798. }
  9799. }
  9800. else
  9801. {
  9802. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9803. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9804. {
  9805. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9806. if (!Bookmark->Node.IsEmpty())
  9807. {
  9808. Folders->Add(Bookmark->Node);
  9809. }
  9810. }
  9811. for (int Index = 0; Index < Folders->Count; Index++)
  9812. {
  9813. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9814. Item->Caption = Folders->Strings[Index];
  9815. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9816. Folders->Objects[Index] = Item.get();
  9817. Menu->Add(Item.release());
  9818. }
  9819. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9820. {
  9821. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9822. TTBCustomItem * Parent;
  9823. if (!Bookmark->Node.IsEmpty())
  9824. {
  9825. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9826. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9827. }
  9828. else
  9829. {
  9830. Parent = Menu;
  9831. }
  9832. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9833. Item->Caption = Bookmark->Name;
  9834. Item->ShortCut = Bookmark->ShortCut;
  9835. Item->OnClick = OnBookmarkClick;
  9836. Item->Tag = reinterpret_cast<int>(Bookmark);
  9837. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9838. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9839. {
  9840. // No hint for location profiles that are actually mere "bookmarks"
  9841. }
  9842. else
  9843. {
  9844. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9845. UnicodeString LongHint;
  9846. if (!Bookmark->Local.IsEmpty())
  9847. {
  9848. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9849. }
  9850. if (!Bookmark->Remote.IsEmpty())
  9851. {
  9852. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9853. }
  9854. AddToList(Hint, LongHint, L"|");
  9855. Item->Hint = Hint;
  9856. }
  9857. Parent->Add(Item.release());
  9858. }
  9859. }
  9860. AddMenuSeparator(Menu);
  9861. }
  9862. }
  9863. //---------------------------------------------------------------------------
  9864. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9865. {
  9866. Menu->Clear();
  9867. std::unique_ptr<TTBCustomItem> Item;
  9868. Item.reset(new TTBXItem(Owner));
  9869. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9870. Item->Options = Item->Options << tboDefault;
  9871. Menu->Add(Item.release());
  9872. AddMenuSeparator(Menu);
  9873. if (Terminal != NULL)
  9874. {
  9875. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9876. }
  9877. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9878. Item.reset(new TTBXItem(Owner));
  9879. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9880. Menu->Add(Item.release());
  9881. }
  9882. //---------------------------------------------------------------------------
  9883. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9884. {
  9885. bool Result = true;
  9886. bool Remote = !IsSideLocalBrowser(Side);
  9887. try
  9888. {
  9889. if (Remote)
  9890. {
  9891. Terminal->ExceptionOnFail = true;
  9892. }
  9893. try
  9894. {
  9895. DirView(Side)->Path = Path;
  9896. }
  9897. __finally
  9898. {
  9899. if (Remote)
  9900. {
  9901. Terminal->ExceptionOnFail = false;
  9902. }
  9903. }
  9904. }
  9905. catch (Exception & E)
  9906. {
  9907. if (!Remote || Terminal->Active)
  9908. {
  9909. ShowExtendedExceptionEx(Terminal, &E);
  9910. Result = false;
  9911. }
  9912. else
  9913. {
  9914. throw;
  9915. }
  9916. }
  9917. return Result;
  9918. }
  9919. //---------------------------------------------------------------------------
  9920. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9921. {
  9922. // Make sure there some feedback even when loading tiny local folders
  9923. TInstantOperationVisualizer Visualizer;
  9924. DirView(Side)->ReloadDirectory();
  9925. }
  9926. //---------------------------------------------------------------------------
  9927. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9928. {
  9929. if (Index == SessionsPageControl->TabIndex)
  9930. {
  9931. CloseSession();
  9932. }
  9933. else
  9934. {
  9935. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9936. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  9937. TTerminalManager * Manager = TTerminalManager::Instance();
  9938. if (!Terminal->Active)
  9939. {
  9940. Manager->FreeTerminal(Terminal);
  9941. }
  9942. else
  9943. {
  9944. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9945. if (CanCloseQueue(Queue))
  9946. {
  9947. Manager->FreeTerminal(Terminal);
  9948. }
  9949. }
  9950. }
  9951. }
  9952. //---------------------------------------------------------------------------
  9953. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9954. {
  9955. CloseSessionTab(Index);
  9956. }
  9957. //---------------------------------------------------------------------------
  9958. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9959. {
  9960. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9961. {
  9962. TInstantOperationVisualizer Visualizer;
  9963. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9964. // before we create a new data object
  9965. ClipboardClear();
  9966. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9967. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9968. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9969. // Intermediate variable to WORKAROUND a crash in compiler
  9970. TObjectList * ClipboardFakeMonitors =
  9971. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9972. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9973. if (FClipboardDragDropFilesEx.get() == NULL)
  9974. {
  9975. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9976. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9977. }
  9978. FClipboardDragDropFilesEx->FileList->Clear();
  9979. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9980. FClipboardDragDropFilesEx->CopyToClipboard();
  9981. FClipboardTerminal = Terminal;
  9982. // Need full paths, as cwd can be different once files are pasted
  9983. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9984. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9985. {
  9986. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9987. }
  9988. }
  9989. }
  9990. //---------------------------------------------------------------------------
  9991. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9992. {
  9993. if (OpenClipboard(0))
  9994. {
  9995. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9996. CloseClipboard();
  9997. }
  9998. }
  9999. //---------------------------------------------------------------------------
  10000. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10001. {
  10002. return !FClipboardFakeDirectory.IsEmpty();
  10003. }
  10004. //---------------------------------------------------------------------------
  10005. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10006. {
  10007. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10008. FClipboardFakeDirectory = UnicodeString();
  10009. FClipboardTerminal = NULL;
  10010. // Also called in Idle()
  10011. FClipboardFakeMonitors.reset(NULL);
  10012. }
  10013. //---------------------------------------------------------------------------
  10014. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10015. {
  10016. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10017. {
  10018. ClipboardStop();
  10019. }
  10020. }
  10021. //---------------------------------------------------------------------------
  10022. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10023. {
  10024. TTerminalManager * Manager = TTerminalManager::Instance();
  10025. Manager->ActiveSession = FClipboardTerminal;
  10026. TTransferOperationParam Params;
  10027. Params.TargetDirectory = TargetDirectory;
  10028. Params.DragDrop = DragDrop;
  10029. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10030. }
  10031. //---------------------------------------------------------------------------
  10032. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10033. {
  10034. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10035. // (as it pumps a Windows message queue while being shutted down)
  10036. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10037. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10038. {
  10039. // Can fail as it can be e.g. locked by AV, so we retry that later
  10040. bool Removed = RemoveDir(ApiPath(FileName));
  10041. try
  10042. {
  10043. if (!NonVisualDataModule->Busy)
  10044. {
  10045. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10046. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10047. }
  10048. }
  10049. __finally
  10050. {
  10051. if (!Removed)
  10052. {
  10053. RemoveDir(ApiPath(FileName));
  10054. }
  10055. }
  10056. }
  10057. }
  10058. //---------------------------------------------------------------------------
  10059. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10060. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10061. {
  10062. TFileMasks::TParams MaskParams;
  10063. MaskParams.Size = Size;
  10064. MaskParams.Modification = Modification;
  10065. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10066. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10067. {
  10068. bool ImplicitMatch;
  10069. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10070. !ImplicitMatch)
  10071. {
  10072. Color = Iter->Color;
  10073. break;
  10074. }
  10075. }
  10076. }
  10077. //---------------------------------------------------------------------------
  10078. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10079. {
  10080. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10081. if (!DirView->IsEditing())
  10082. {
  10083. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10084. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10085. // while searching
  10086. if (Key == VK_BACK)
  10087. {
  10088. if (!FIncrementalSearch.IsEmpty())
  10089. {
  10090. if (FIncrementalSearch.Length() == 1)
  10091. {
  10092. ResetIncrementalSearch();
  10093. }
  10094. else
  10095. {
  10096. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10097. IncrementalSearch(NewText, false, false);
  10098. }
  10099. Key = 0;
  10100. }
  10101. }
  10102. }
  10103. }
  10104. //---------------------------------------------------------------------------
  10105. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10106. {
  10107. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10108. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10109. {
  10110. // Filter control sequences.
  10111. // When not searching yet, prefer use of the space for toggling file selection
  10112. // (so we cannot incrementally search for a string starting with a space).
  10113. if ((Key > VK_SPACE) ||
  10114. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10115. {
  10116. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10117. Key = 0;
  10118. }
  10119. }
  10120. }
  10121. //---------------------------------------------------------------------------
  10122. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10123. {
  10124. if (!FIncrementalSearch.IsEmpty())
  10125. {
  10126. FIncrementalSearch = L"";
  10127. DirView(osCurrent)->UpdateStatusBar();
  10128. }
  10129. }
  10130. //---------------------------------------------------------------------------
  10131. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10132. {
  10133. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10134. if (Item == NULL)
  10135. {
  10136. MessageBeep(MB_ICONHAND);
  10137. }
  10138. else
  10139. {
  10140. TCustomDirView * ADirView = DirView(osCurrent);
  10141. {
  10142. TAutoNestingCounter Guard(FIncrementalSearching);
  10143. ADirView->FocusItem(Item);
  10144. if (ADirView->NortonLike == nlOff)
  10145. {
  10146. if ((ADirView->Selected != Item) ||
  10147. (ADirView->SelCount > 1))
  10148. {
  10149. ADirView->ClearSelection();
  10150. ADirView->Selected = Item;
  10151. }
  10152. }
  10153. }
  10154. FIncrementalSearch = Text;
  10155. Item->MakeVisible(false);
  10156. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10157. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10158. ADirView->UpdateStatusBar();
  10159. }
  10160. }
  10161. //---------------------------------------------------------------------------
  10162. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10163. {
  10164. int Index = Item->Index;
  10165. if (!Reverse)
  10166. {
  10167. Index++;
  10168. if (Index >= Item->Owner->Count)
  10169. {
  10170. Index = 0;
  10171. }
  10172. }
  10173. else
  10174. {
  10175. Index--;
  10176. if (Index < 0)
  10177. {
  10178. Index = Item->Owner->Count - 1;
  10179. }
  10180. }
  10181. return Item->Owner->Item[Index];
  10182. }
  10183. //---------------------------------------------------------------------------
  10184. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10185. {
  10186. TCustomDirView * ADirView = DirView(osCurrent);
  10187. if (ADirView->Items->Count == 0)
  10188. {
  10189. return NULL;
  10190. }
  10191. else
  10192. {
  10193. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10194. TListItem * Item = CurrentItem;
  10195. if (SkipCurrent)
  10196. {
  10197. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10198. }
  10199. while (true)
  10200. {
  10201. bool Matches = false;
  10202. switch (WinConfiguration->PanelSearch)
  10203. {
  10204. case isNameStartOnly:
  10205. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10206. break;
  10207. case isName:
  10208. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10209. break;
  10210. case isAll:
  10211. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10212. int Index = 0;
  10213. while ((Index < ColCount) && !Matches)
  10214. {
  10215. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10216. if (Visible)
  10217. {
  10218. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10219. }
  10220. Index++;
  10221. }
  10222. break;
  10223. }
  10224. if (Matches)
  10225. {
  10226. return Item;
  10227. }
  10228. Item = GetNextFile(Item, Reverse);
  10229. if (Item == CurrentItem)
  10230. {
  10231. return NULL;
  10232. }
  10233. }
  10234. }
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10238. {
  10239. ResetIncrementalSearch();
  10240. }
  10241. //---------------------------------------------------------------------------
  10242. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10243. {
  10244. if (Message.CharCode == VK_TAB)
  10245. {
  10246. if (!FIncrementalSearch.IsEmpty())
  10247. {
  10248. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10249. bool Reverse = Shift.Contains(ssShift);
  10250. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10251. Message.Result = 1;
  10252. return;
  10253. }
  10254. }
  10255. else if (Message.CharCode == VK_ESCAPE)
  10256. {
  10257. if (!FIncrementalSearch.IsEmpty())
  10258. {
  10259. ResetIncrementalSearch();
  10260. Message.Result = 1;
  10261. return;
  10262. }
  10263. }
  10264. TForm::Dispatch(&Message);
  10265. }
  10266. //---------------------------------------------------------------------------
  10267. void __fastcall TCustomScpExplorerForm::Deactivate()
  10268. {
  10269. TForm::Deactivate();
  10270. // E.g. when switching to an internal editor window
  10271. ResetIncrementalSearch();
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10275. {
  10276. // When switching to another application
  10277. ResetIncrementalSearch();
  10278. }
  10279. //---------------------------------------------------------------------------
  10280. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10281. {
  10282. ResetIncrementalSearch();
  10283. }
  10284. //---------------------------------------------------------------------------
  10285. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10286. {
  10287. if (FIncrementalSearching <= 0)
  10288. {
  10289. ResetIncrementalSearch();
  10290. }
  10291. }
  10292. //---------------------------------------------------------------------------
  10293. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10294. {
  10295. CountClicksForWindowPrint(this);
  10296. }
  10297. //---------------------------------------------------------------------------
  10298. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10299. {
  10300. CenterReconnectToolbar();
  10301. }
  10302. //---------------------------------------------------------------------------
  10303. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10304. {
  10305. if (RemoteDirView->ItemFocused != NULL)
  10306. {
  10307. RemoteDirView->ItemFocused->Selected = true;
  10308. }
  10309. }
  10310. //---------------------------------------------------------------------------
  10311. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10312. {
  10313. if (!FQueueStatusUpdating)
  10314. {
  10315. bool Refresh;
  10316. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10317. {
  10318. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10319. }
  10320. else
  10321. {
  10322. if (FQueueFileList->GetCount() > 0)
  10323. {
  10324. FQueueFileList->Clear();
  10325. Refresh = true;
  10326. }
  10327. }
  10328. int Count = FQueueFileList->GetCount();
  10329. if (QueueFileList->Items->Count != Count)
  10330. {
  10331. DebugAssert(Refresh);
  10332. QueueFileList->Items->Count = Count;
  10333. }
  10334. if (Refresh)
  10335. {
  10336. QueueFileList->Invalidate();
  10337. }
  10338. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10339. }
  10340. }
  10341. //---------------------------------------------------------------------------
  10342. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10343. {
  10344. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10345. }
  10346. //---------------------------------------------------------------------------
  10347. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10348. {
  10349. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10350. // See TSynchronizeChecklistDialog::UpdateTimer
  10351. if (QueueFileList->Items->Count > 0)
  10352. {
  10353. QueueFileList->Items->Item[0]->MakeVisible(false);
  10354. }
  10355. UpdateQueueFileList();
  10356. }
  10357. //---------------------------------------------------------------------------
  10358. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10359. {
  10360. Active = QueueView3->Focused() || QueueFileList->Focused();
  10361. }
  10362. //---------------------------------------------------------------------------
  10363. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10364. {
  10365. QueueLabelUpdateStatus();
  10366. }
  10367. //---------------------------------------------------------------------------
  10368. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10369. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10370. {
  10371. int State = FQueueFileList->GetState(Item->Index);
  10372. if (State == qfsProcessed)
  10373. {
  10374. Sender->Canvas->Font->Color = clGrayText;
  10375. }
  10376. }
  10377. //---------------------------------------------------------------------------
  10378. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10379. {
  10380. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10381. QueueFileList->Column[0]->Width =
  10382. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10383. }
  10384. //---------------------------------------------------------------------------
  10385. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10386. {
  10387. QueueFileListColumnAutoSize();
  10388. }
  10389. //---------------------------------------------------------------------------
  10390. void __fastcall TCustomScpExplorerForm::CloseApp()
  10391. {
  10392. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10393. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10394. // So we clear the flag here.
  10395. DebugAssert(NonVisualDataModule->Busy);
  10396. NonVisualDataModule->EndBusy();
  10397. try
  10398. {
  10399. Close();
  10400. }
  10401. __finally
  10402. {
  10403. NonVisualDataModule->StartBusy();
  10404. }
  10405. }
  10406. //---------------------------------------------------------------------------
  10407. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10408. {
  10409. return (Terminal != NULL) && Terminal->Active;
  10410. }
  10411. //---------------------------------------------------------------------------
  10412. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10413. {
  10414. return IsActiveTerminal(Terminal);
  10415. }
  10416. //---------------------------------------------------------------------------
  10417. void TCustomScpExplorerForm::LocalLocalCopy(
  10418. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10419. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10420. {
  10421. DebugFail();
  10422. }
  10423. //---------------------------------------------------------------------------
  10424. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10425. {
  10426. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10427. }