CustomScpExplorer.cpp 415 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387
  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 <algorithm>
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.h>
  17. #include <Progress.h>
  18. #include <SynchronizeProgress.h>
  19. #include <DragExt.h>
  20. #include <WinApi.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. #include <System.StrUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. #define WM_PASTE_FILES (WM_WINSCP_USER + 14)
  55. static const int SessionPanelCount = 3;
  56. //---------------------------------------------------------------------------
  57. class TMutexGuard
  58. {
  59. public:
  60. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  61. int Timeout = 5000)
  62. {
  63. FMutex = NULL;
  64. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  65. if (WaitResult == WAIT_TIMEOUT)
  66. {
  67. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  68. }
  69. else
  70. {
  71. FMutex = AMutex;
  72. }
  73. }
  74. ~TMutexGuard()
  75. {
  76. if (FMutex != NULL)
  77. {
  78. ReleaseMutex(FMutex);
  79. }
  80. }
  81. private:
  82. HANDLE FMutex;
  83. };
  84. //---------------------------------------------------------------------------
  85. class TWindowLock
  86. {
  87. public:
  88. TWindowLock(TCustomScpExplorerForm * Form) :
  89. FForm(Form)
  90. {
  91. FForm->LockWindow();
  92. }
  93. ~TWindowLock()
  94. {
  95. FForm->UnlockWindow();
  96. }
  97. private:
  98. TCustomScpExplorerForm * FForm;
  99. };
  100. //---------------------------------------------------------------------------
  101. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  102. FForm(Form)
  103. {
  104. FForm->BatchStart(FBatchStorage);
  105. }
  106. //---------------------------------------------------------------------------
  107. TAutoBatch::~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. //---------------------------------------------------------------------------
  112. struct TTransferOperationParam
  113. {
  114. TTransferOperationParam();
  115. UnicodeString TargetDirectory;
  116. bool Temp;
  117. bool DragDrop;
  118. int Options;
  119. TAutoSwitch Queue;
  120. };
  121. //---------------------------------------------------------------------------
  122. TTransferOperationParam::TTransferOperationParam()
  123. {
  124. Temp = false;
  125. DragDrop = false;
  126. Options = 0;
  127. Queue = asAuto;
  128. }
  129. //---------------------------------------------------------------------------
  130. class TTransferPresetNoteData : public TObject
  131. {
  132. public:
  133. UnicodeString Message;
  134. };
  135. //---------------------------------------------------------------------------
  136. class TTerminalNoteData : public TObject
  137. {
  138. public:
  139. TManagedTerminal * Terminal;
  140. };
  141. //---------------------------------------------------------------------------
  142. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  143. FFormRestored(false),
  144. TForm(Owner)
  145. {
  146. AddStartupSequence(L"F");
  147. FInvalid = false;
  148. FCurrentSide = osRemote;
  149. FEverShown = false;
  150. FDocks = new TList();
  151. InitControls();
  152. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  153. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  154. NonVisualDataModule->ScpExplorer = this;
  155. RestoreParams();
  156. ConfigurationChanged();
  157. RemoteDirView->Invalidate();
  158. FAutoOperation = false;
  159. FOnFileOperationFinished = NULL;
  160. FPrimaryOperation = foNone;
  161. FForceExecution = false;
  162. FIgnoreNextDialogChar = 0;
  163. FErrorList = NULL;
  164. FSynchronizeProgressForm = NULL;
  165. FProgressForm = NULL;
  166. FRefreshLocalDirectory = false;
  167. FRefreshRemoteDirectory = false;
  168. FDDExtMapFile = NULL;
  169. // CreateMutexW keeps failing with ERROR_NOACCESS
  170. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  171. DebugAssert(FDDExtMutex != NULL);
  172. FDDTargetControl = NULL;
  173. FDelayedDeletionTimer = NULL;
  174. FDelayedDeletionList = new TStringList();
  175. FDDFileList = NULL;
  176. FPendingTempSpaceWarn = false;
  177. FCapturedLog = NULL;
  178. FDragDropOperation = false;
  179. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  180. FAllowTransferPresetAutoSelect = true;
  181. FSessionChanging = false;
  182. FCopyParamDefault = L"";
  183. FSynchronizeController = NULL;
  184. FPendingQueueActionItem = NULL;
  185. FLockLevel = 0;
  186. FLockSuspendLevel = 0;
  187. FDisabledOnLockSuspend = false;
  188. FAlternativeDelete = false;
  189. FTrayIcon = new ::TTrayIcon(0);
  190. FTrayIcon->OnClick = TrayIconClick;
  191. FMaxQueueLength = 0;
  192. FLastContextPopupScreenPoint = TPoint(-1, -1);
  193. FTransferResumeList = NULL;
  194. FDeletedFiles = NULL;
  195. FMoveToQueue = false;
  196. StandaloneOperation = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FOnSynchronizeAbort = NULL;
  199. FSynchronizeTerminal = NULL;
  200. FNeedSession = false;
  201. FDoNotIdleCurrentTerminal = 0;
  202. FIncrementalSearching = 0;
  203. FQueueFileList.reset(new TQueueFileList());
  204. FProgressSide = osCurrent;
  205. FCalculateSizeOperation = NULL;
  206. FDownloadingFromClipboard = false;
  207. FClipboardFakeMonitorsPendingReset = false;
  208. FHiContrastTheme = NULL;
  209. InitializeRemoteThumbnailMask();
  210. FEditorManager = new TEditorManager();
  211. FEditorManager->OnFileChange = ExecutedFileChanged;
  212. FEditorManager->OnFileReload = ExecutedFileReload;
  213. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  214. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  215. FLocalEditors = new TList();
  216. FQueueStatus = NULL;
  217. FQueueStatusSection = new TCriticalSection();
  218. FQueueStatusInvalidated = false;
  219. FQueueItemInvalidated = false;
  220. FQueueStatusUpdating = false;
  221. FQueueActedItem = NULL;
  222. FQueueController = new TQueueController(QueueView3);
  223. FQueueScrollOnDragOver = new TListViewScrollOnDragOver(QueueView3, true);
  224. FUserActionTimer = new TTimer(this);
  225. FUserActionTimer->Enabled = false;
  226. FUserActionTimer->Interval = 10;
  227. FUserActionTimer->OnTimer = UserActionTimer;
  228. FNotes = new TStringList();
  229. FNoteTimer = new TTimer(this);
  230. FNoteTimer->Enabled = false;
  231. FNoteTimer->OnTimer = NoteTimer;
  232. FOnNoteClick = NULL;
  233. FOle32Library = LoadLibrary(L"Ole32.dll");
  234. FDragMoveCursor = FOle32Library != NULL ?
  235. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  236. UseSystemSettings(this);
  237. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  238. static_cast<TObject*>(GetComponent(fcTransferList)));
  239. DebugAssert(TransferList != NULL);
  240. FTransferListHoverIndex = -1;
  241. TransferList->OnChange = TransferListChange;
  242. TransferList->OnDrawItem = TransferListDrawItem;
  243. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))), true);
  244. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  245. UseDesktopFont(SessionsPageControl);
  246. UseDesktopFont(RemoteDirView);
  247. UseDesktopFont(RemoteDriveView);
  248. UseDesktopFont(QueueView3);
  249. UseDesktopFont(QueueFileList);
  250. UseDesktopFont(QueueLabel);
  251. UseDesktopFont(RemoteStatusBar);
  252. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  253. QueueSplitter->ShowHint = true;
  254. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  255. QueueFileListSplitter->ShowHint = true;
  256. RemotePanelSplitter->ShowHint = true;
  257. UpdateImages();
  258. FCustomCommandMenu = CreateTBXPopupMenu(this);
  259. FCustomCommandLocalFileList = NULL;
  260. FCustomCommandRemoteFileList = NULL;
  261. FSessionColors = new TPngImageList(this);
  262. FSessionColors->ColorDepth = cd32Bit;
  263. AddFixedSessionImages();
  264. SessionsPageControl->Images = FSessionColors;
  265. // Needed for Explorer (Commander calls it implicitly on its own)
  266. UpdateSessionsPageControlHeight();
  267. UpdateQueueLabel();
  268. CheckStoreTransition();
  269. CreateHiddenWindow();
  270. StartUpdates();
  271. // Start loading drive data, so that they are ready once we need them for StartCreationDirectoryMonitorsOnEachDrive
  272. // (necessary for "explorer" only, as "commander" loads it for its drive menu)
  273. DriveInfo->NeedData();
  274. }
  275. //---------------------------------------------------------------------------
  276. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  277. {
  278. AppLog(L"Destroying main window");
  279. FInvalid = true;
  280. ReleaseHiContrastTheme();
  281. if (FClipboardTerminal != NULL)
  282. {
  283. ClipboardClear(); // implies ClipboardStop
  284. }
  285. // this has to be one of the very first things to do
  286. StopUpdateThread();
  287. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  288. TTerminalManager::Instance()->ScpExplorer = NULL;
  289. delete FCustomCommandLocalFileList;
  290. delete FCustomCommandRemoteFileList;
  291. delete FCustomCommandMenu;
  292. delete FTrayIcon;
  293. FTrayIcon = NULL;
  294. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  295. delete FEditorManager;
  296. ForceCloseLocalEditors();
  297. delete FLocalEditors;
  298. HideFileFindDialog();
  299. if (FDelayedDeletionTimer)
  300. {
  301. DoDelayedDeletion(NULL);
  302. SAFE_DESTROY(FDelayedDeletionTimer);
  303. }
  304. SAFE_DESTROY(FDelayedDeletionList);
  305. // sometimes we do not get DDEnd so the list is not released
  306. SAFE_DESTROY(FDDFileList);
  307. DebugAssert(FSynchronizeController == NULL);
  308. CloseHandle(FDDExtMutex);
  309. FDDExtMutex = NULL;
  310. FreeLibrary(FOle32Library);
  311. FOle32Library = NULL;
  312. FDragMoveCursor = NULL;
  313. DebugAssert(!FErrorList);
  314. if (FEverShown)
  315. {
  316. // when window is never shown (like when running command-line operation),
  317. // particularly window site is not restored correctly (BoundsRect value set
  318. // in RestoreForm gets lost during handle allocation), so we do not want
  319. // it to be stored
  320. AppLog(L"Storing main window configuration");
  321. StoreParams();
  322. }
  323. ManagedSession = NULL;
  324. Queue = NULL;
  325. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  326. NonVisualDataModule->ScpExplorer = NULL;
  327. delete FQueueScrollOnDragOver;
  328. FQueueScrollOnDragOver = NULL;
  329. delete FQueueController;
  330. FQueueController = NULL;
  331. delete FQueueStatusSection;
  332. FQueueStatusSection = NULL;
  333. delete FQueueStatus;
  334. FQueueStatus = NULL;
  335. delete FUserActionTimer;
  336. FUserActionTimer = NULL;
  337. delete FNoteTimer;
  338. delete FNotes;
  339. delete FNoteData;
  340. SAFE_DESTROY(FDocks);
  341. SessionsPageControl->Images = NULL;
  342. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  343. SAFE_DESTROY(FSessionColors);
  344. SAFE_DESTROY(FSessionsDragDropFilesEx);
  345. SAFE_DESTROY(FHistoryMenu[0][0]);
  346. SAFE_DESTROY(FHistoryMenu[0][1]);
  347. SAFE_DESTROY(FHistoryMenu[1][0]);
  348. SAFE_DESTROY(FHistoryMenu[1][1]);
  349. if (FHiddenWindow != NULL)
  350. {
  351. DestroyWindow(FHiddenWindow);
  352. FHiddenWindow = NULL;
  353. }
  354. AppLog(L"Main window destroyed");
  355. }
  356. //---------------------------------------------------------------------------
  357. void TCustomScpExplorerForm::ReleaseHiContrastTheme()
  358. {
  359. if (FHiContrastTheme != NULL)
  360. {
  361. ReleaseTBXTheme(FHiContrastTheme);
  362. FHiContrastTheme = NULL;
  363. }
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  367. {
  368. std::unique_ptr<TSessionData> Data;
  369. if (!Session.IsEmpty())
  370. {
  371. bool DefaultsOnly;
  372. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  373. }
  374. TTerminalManager * Manager = TTerminalManager::Instance();
  375. for (int Index = 0; Index < Manager->Count; Index++)
  376. {
  377. TTerminal * Terminal = Manager->Sessions[Index];
  378. if (Session.IsEmpty() ||
  379. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  380. {
  381. if (Path.IsEmpty())
  382. {
  383. Terminal->ClearCaches();
  384. }
  385. else
  386. {
  387. Terminal->DirectoryModified(Path, true);
  388. }
  389. }
  390. }
  391. // We should flag a pending refresh for the background terminals or busy foreground terminals
  392. if (HasActiveTerminal() &&
  393. CanCommandLineFromAnotherInstance() &&
  394. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  395. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  396. {
  397. Terminal->ReloadDirectory();
  398. }
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  402. {
  403. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  404. AppLogFmt(L"Received copy data message with size %d", (int(CopyData->cbData)));
  405. size_t MessageSize = sizeof(TCopyDataMessage);
  406. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  407. if (Result)
  408. {
  409. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  410. Result = (Message.Version == TCopyDataMessage::Version1);
  411. if (Result)
  412. {
  413. switch (Message.Command)
  414. {
  415. case TCopyDataMessage::CommandCanCommandLine:
  416. Result = CanCommandLineFromAnotherInstance();
  417. if (Result)
  418. {
  419. AppLog(L"Can process command-line from other instance");
  420. }
  421. else
  422. {
  423. AppLog(L"Cannot process command-line from other instance");
  424. }
  425. break;
  426. case TCopyDataMessage::CommandCommandLine:
  427. {
  428. UnicodeString CommandLine(Message.CommandLine);
  429. Result = CommandLineFromAnotherInstance(CommandLine);
  430. }
  431. break;
  432. case TCopyDataMessage::RefreshPanel:
  433. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  434. break;
  435. case TCopyDataMessage::MainWindowCheck:
  436. Result = true;
  437. break;
  438. default:
  439. Result = false;
  440. break;
  441. }
  442. }
  443. }
  444. Message.Result = Result ? 1 : 0;
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  448. {
  449. WNDCLASS WindowClass = {0};
  450. WindowClass.lpfnWndProc = DefWindowProc;
  451. WindowClass.hInstance = HInstance;
  452. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  453. FHiddenWindow = NULL;
  454. if (RegisterClass(&WindowClass))
  455. {
  456. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  457. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  458. }
  459. }
  460. //---------------------------------------------------------------------------
  461. bool __fastcall TCustomScpExplorerForm::CanConsole()
  462. {
  463. return
  464. HasActiveTerminal() &&
  465. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  466. }
  467. //---------------------------------------------------------------------------
  468. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  469. {
  470. bool Result = Visible && !NonVisualDataModule->Busy;
  471. return Result;
  472. }
  473. //---------------------------------------------------------------------------
  474. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  475. const UnicodeString & CommandLine)
  476. {
  477. TProgramParams Params(CommandLine);
  478. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  479. if (Result)
  480. {
  481. NonVisualDataModule->StartBusy();
  482. try
  483. {
  484. // this action is initiated from another process,
  485. // so it's likely that our window is not visible,
  486. // and user won't see what is going on
  487. Application->BringToFront();
  488. // reload sessions as we may be asked to open a session
  489. // just stored by another instance
  490. StoredSessions->Reload();
  491. UnicodeString SessionName = Params.Param[1];
  492. std::unique_ptr<TObjectList> DataList(new TObjectList());
  493. try
  494. {
  495. UnicodeString DownloadFile; // unused
  496. int Flags = GetCommandLineParseUrlFlags(&Params);
  497. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  498. }
  499. catch (EAbort &)
  500. {
  501. // Happens when opening session in PuTTY and in other situations,
  502. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  503. // to process the command-line on its own (or to pass it to yet another instance)
  504. }
  505. if (DataList->Count > 0)
  506. {
  507. TTerminalManager * Manager = TTerminalManager::Instance();
  508. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  509. }
  510. }
  511. __finally
  512. {
  513. NonVisualDataModule->EndBusy();
  514. }
  515. }
  516. return Result;
  517. }
  518. //---------------------------------------------------------------------------
  519. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  520. {
  521. TManagedTerminal * Result;
  522. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  523. {
  524. Result = FManagedSession;
  525. }
  526. else
  527. {
  528. Result = NULL;
  529. }
  530. return Result;
  531. }
  532. //---------------------------------------------------------------------------
  533. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  534. {
  535. if (FManagedSession != value)
  536. {
  537. TWindowLock Lock(this);
  538. SessionChanging();
  539. DoSetManagedSession(value, false);
  540. }
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  544. {
  545. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  546. FManagedSession = value;
  547. {
  548. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect, false);
  549. TAutoFlag SessionChangingFlag(FSessionChanging);
  550. SessionChanged(Replace);
  551. }
  552. if (Terminal != NULL)
  553. {
  554. TransferPresetAutoSelect();
  555. }
  556. // Update app and tab titles, prevented above by FSessionChanging.
  557. UpdateControls();
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  561. {
  562. FEditorManager->ProcessFiles(FileTerminalReplaced, value);
  563. DoSetManagedSession(value, true);
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SessionChanging()
  567. {
  568. if (ManagedSession != NULL)
  569. {
  570. UpdateSession(ManagedSession);
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  575. {
  576. if (ManagedSession != NULL)
  577. {
  578. UpdateSessionColor(static_cast<TColor>(ManagedSession->StateData->Color));
  579. }
  580. if (!TTerminalManager::Instance()->Updating)
  581. {
  582. SessionListChanged();
  583. }
  584. if (Terminal != NULL)
  585. {
  586. TObject * State = NULL;
  587. if (WinConfiguration->PreservePanelState)
  588. {
  589. State = Terminal->RemoteExplorerState;
  590. DirView(osRemote)->AnnounceState(State);
  591. }
  592. try
  593. {
  594. if (Replaced)
  595. {
  596. RemoteDirView->ReplaceTerminal(Terminal);
  597. }
  598. else
  599. {
  600. RemoteDirView->Terminal = Terminal;
  601. }
  602. if (Terminal->Active)
  603. {
  604. Terminal->RefreshDirectory();
  605. }
  606. if (State != NULL)
  607. {
  608. DirView(osRemote)->RestoreState(State);
  609. }
  610. }
  611. __finally
  612. {
  613. DirView(osRemote)->AnnounceState(NULL);
  614. }
  615. }
  616. else
  617. {
  618. RemoteDirView->Terminal = NULL;
  619. }
  620. InitStatusBar();
  621. UpdateTransferList();
  622. // Update panels Enable state before refreshing the labels
  623. UpdateControls();
  624. }
  625. //---------------------------------------------------------------------------
  626. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  627. {
  628. if (Queue != value)
  629. {
  630. if (FQueue != NULL)
  631. {
  632. FQueue->OnListUpdate = NULL;
  633. FQueue->OnQueueItemUpdate = NULL;
  634. }
  635. FQueue = value;
  636. if (FQueue != NULL)
  637. {
  638. DebugAssert(FQueue->OnListUpdate == NULL);
  639. FQueue->OnListUpdate = QueueListUpdate;
  640. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  641. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  642. }
  643. QueueChanged();
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  648. TListItem * Item)
  649. {
  650. if (FQueueActedItem == Item)
  651. {
  652. FQueueActedItem = NULL;
  653. if ((QueueView3->PopupMenu != NULL) &&
  654. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  655. {
  656. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  657. ReleaseCapture();
  658. }
  659. }
  660. if (Item->Data == FPendingQueueActionItem)
  661. {
  662. FPendingQueueActionItem = NULL;
  663. }
  664. }
  665. //---------------------------------------------------------------------------
  666. bool TCustomScpExplorerForm::IsAnythingQueued()
  667. {
  668. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  672. {
  673. {
  674. TGuard Guard(FQueueStatusSection);
  675. FQueueStatusInvalidated = false;
  676. if (FQueue != NULL)
  677. {
  678. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  679. }
  680. }
  681. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  682. {
  683. FMaxQueueLength = FQueueStatus->Count;
  684. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  685. }
  686. {
  687. TAutoFlag Flag(FQueueStatusUpdating);
  688. FQueueController->UpdateQueueStatus(FQueueStatus);
  689. }
  690. UpdateQueueFileList();
  691. SetQueueProgress();
  692. UpdateQueueView();
  693. bool IsEmpty = !IsAnythingQueued();
  694. if (IsEmpty && (Terminal != NULL))
  695. {
  696. TOnceDoneOperation OnceDoneOperation =
  697. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  698. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  699. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  700. {
  701. FQueue->Enabled = false;
  702. }
  703. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  704. {
  705. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  706. }
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  711. {
  712. UnicodeString Result;
  713. if (FQueueStatus != NULL)
  714. {
  715. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  716. {
  717. TFileOperationProgressType * ProgressData =
  718. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  719. if ((ProgressData != NULL) && ProgressData->InProgress)
  720. {
  721. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  722. }
  723. }
  724. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  725. {
  726. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  727. }
  728. }
  729. return Result;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  733. {
  734. ComponentVisible[fcQueueView] =
  735. !IsLocalBrowserMode() &&
  736. ((WinConfiguration->QueueView.Show == qvShow) ||
  737. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  738. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  739. }
  740. //---------------------------------------------------------------------------
  741. void __fastcall TCustomScpExplorerForm::QueueChanged()
  742. {
  743. if (FQueueStatus != NULL)
  744. {
  745. // UpdateFileList implementation relies on the status being recreated when session changes
  746. delete FQueueStatus;
  747. FQueueStatus = NULL;
  748. }
  749. UpdateQueueStatus(true);
  750. }
  751. //---------------------------------------------------------------------------
  752. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  753. {
  754. if (FQueue == Queue)
  755. {
  756. FQueueStatusInvalidated = true;
  757. }
  758. }
  759. //---------------------------------------------------------------------------
  760. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  761. TQueueItem * Item)
  762. {
  763. if (FQueue == Queue)
  764. {
  765. TGuard Guard(FQueueStatusSection);
  766. // this may be running in parallel with QueueChanged
  767. if (FQueueStatus != NULL)
  768. {
  769. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  770. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  771. {
  772. FRefreshLocalDirectory = (QueueItem == NULL) ||
  773. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  774. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  775. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  776. }
  777. if (QueueItem != NULL)
  778. {
  779. QueueItem->UserData = (void*)true;
  780. FQueueItemInvalidated = true;
  781. }
  782. }
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  787. {
  788. // during standalone editing, we have no way to see/control queue,
  789. // so we have to always popup prompts automatically
  790. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  791. }
  792. //---------------------------------------------------------------------------
  793. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  794. {
  795. if (FQueueStatus != NULL)
  796. {
  797. bool QueueAutoPopup = IsQueueAutoPopup();
  798. bool NeedRefresh = FQueueController->NeedRefresh();
  799. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  800. FQueueItemInvalidated = false;
  801. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  802. bool Updated = false;
  803. TQueueItemProxy * QueueItem;
  804. bool WasUserAction;
  805. for (int Index = 0; Index < Limit; Index++)
  806. {
  807. bool Update = false;
  808. QueueItem = FQueueStatus->Items[Index];
  809. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  810. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  811. (FPendingQueueActionItem == NULL))
  812. {
  813. FPendingQueueActionItem = QueueItem;
  814. FUserActionTimer->Enabled = true;
  815. }
  816. if ((bool)QueueItem->UserData)
  817. {
  818. QueueItem->UserData = (void*)false;
  819. QueueItem->Update();
  820. Updated = true;
  821. Update = true;
  822. }
  823. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  824. {
  825. Update = true;
  826. }
  827. if (Update)
  828. {
  829. FQueueController->RefreshQueueItem(QueueItem);
  830. }
  831. }
  832. if (Updated)
  833. {
  834. NonVisualDataModule->UpdateNonVisibleActions();
  835. SetQueueProgress();
  836. UpdateQueueFileList();
  837. }
  838. }
  839. }
  840. //---------------------------------------------------------------------------
  841. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  842. {
  843. if (FTaskbarList != NULL)
  844. {
  845. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  846. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  847. }
  848. }
  849. //---------------------------------------------------------------------------
  850. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  851. {
  852. if (Progress >= 0)
  853. {
  854. if (FTaskbarList != NULL)
  855. {
  856. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  857. }
  858. }
  859. else
  860. {
  861. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  862. }
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  866. {
  867. int OverallProgress;
  868. // FProgressForm is null when this is called from SetQueueProgress
  869. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  870. {
  871. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  872. }
  873. else if (!ProgressData->IsIndeterminate())
  874. {
  875. OverallProgress = ProgressData->OverallProgress();
  876. }
  877. else
  878. {
  879. OverallProgress = -1;
  880. }
  881. SetTaskbarListProgressValue(OverallProgress);
  882. }
  883. //---------------------------------------------------------------------------
  884. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  885. {
  886. TTerminalManager::Instance()->QueueStatusUpdated();
  887. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  888. {
  889. // Do not animate task bar button, when items are queued, but processing is disabled
  890. if ((FQueueStatus != NULL) && (FQueueStatus->ActivePrimaryCount > 0))
  891. {
  892. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  893. {
  894. TFileOperationProgressType * ProgressData = NULL;
  895. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  896. {
  897. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  898. }
  899. if ((ProgressData != NULL) &&
  900. ProgressData->InProgress)
  901. {
  902. SetTaskbarListProgressValue(ProgressData);
  903. }
  904. else
  905. {
  906. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  907. }
  908. }
  909. else
  910. {
  911. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  912. }
  913. }
  914. else
  915. {
  916. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  917. }
  918. }
  919. UpdateQueueLabel();
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  923. {
  924. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  925. if (FQueueStatus != NULL)
  926. {
  927. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  928. if (ActiveAndPendingPrimaryCount > 0)
  929. {
  930. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  931. }
  932. }
  933. QueueLabel->Caption = Caption;
  934. }
  935. //---------------------------------------------------------------------------
  936. void TCustomScpExplorerForm::CheckStoreTransition()
  937. {
  938. if (WinConfiguration->StoreTransition == stInit)
  939. {
  940. if (IsUWP())
  941. {
  942. WinConfiguration->StoreTransition = stStoreFresh;
  943. AppLog(L"Fresh UWP/store installation");
  944. }
  945. else
  946. {
  947. WinConfiguration->StoreTransition = stStandard;
  948. AppLog(L"Fresh standard installation");
  949. }
  950. }
  951. else if ((WinConfiguration->StoreTransition == stStandard) && IsUWP())
  952. {
  953. WinConfiguration->StoreTransition = stStoreMigrated;
  954. WinConfiguration->FirstRun = WinConfiguration->FirstRun + L"=>" + StandardDatestamp();
  955. AppLog(L"Standard installation migrated to store installation");
  956. }
  957. if (WinConfiguration->StoreTransition == stStoreMigrated)
  958. {
  959. TTBXToolbar * Toolbar = new TTBXToolbar(MessageDock);
  960. Toolbar->Parent = MessageDock;
  961. Toolbar->FullSize = true;
  962. Toolbar->Color = Application->HintColor;
  963. TTBXLabelItem * LabelItem;
  964. LabelItem = new TTBXLabelItem(Toolbar);
  965. // Convert to explicit RGB "black" color, to make sure it is contrasting even in Dark theme
  966. // (TTBXOfficeXPTheme.GetStandardColor would convert clWindow to "white" in dark theme)
  967. LabelItem->FontSettings->Color = static_cast<TColor>(GetSysColor(clWindow));
  968. LabelItem->Margin = ScaleByTextHeight(MessageDock, 2); // Is this automatically rescaled?
  969. LabelItem->Caption = LoadStr(STORE_MIGRATION_THANKS);
  970. Toolbar->Items->Add(LabelItem);
  971. TTBXCustomItem * LinkItem = new TTBXItem(Toolbar);
  972. LinkItem->FontSettings->Color = LinkColor;
  973. LinkItem->Caption = LoadStr(STORE_MIGRATION_LEARN);
  974. LinkItem->OnClick = StoreTransitionLinkClick;
  975. Toolbar->Items->Add(LinkItem);
  976. AddMenuSeparator(Toolbar->Items);
  977. TTBXCustomItem * CloseItem = new TTBXItem(Toolbar);
  978. CloseItem->FontSettings->Color = static_cast<TColor>(GetSysColor(clWindow));
  979. CloseItem->Caption = LoadStr(MESSAGE_DISMISS);
  980. CloseItem->OnClick = StoreTransitionCloseClick;
  981. Toolbar->Items->Add(CloseItem);
  982. GiveTBItemPriority(CloseItem);
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::StoreTransitionLinkClick(TObject *)
  987. {
  988. ShowHelp(HELP_STORE_TRANSITION);
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::StoreTransitionCloseClick(TObject * Sender)
  992. {
  993. TTBCustomItem * Item = DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender));
  994. TTBXToolbar * Toolbar = DebugNotNull(dynamic_cast<TTBXToolbar *>(DebugNotNull(DebugNotNull(Item->Parent)->ParentComponent)));
  995. delete Toolbar;
  996. WinConfiguration->StoreTransition = stStoreAcknowledged;
  997. UpdateControls();
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  1001. {
  1002. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  1003. static_cast<TComponent*>(GetComponent(fcTransferList)));
  1004. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  1005. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  1006. TransferList->Strings->BeginUpdate();
  1007. try
  1008. {
  1009. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  1010. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  1011. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  1012. if (FTransferDropDownHint.IsEmpty())
  1013. {
  1014. FTransferDropDownHint = TransferDropDown->Hint;
  1015. }
  1016. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  1017. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  1018. TransferDropDown->Text = StripHotkey(Name);
  1019. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  1020. (FTransferDropDownHint, StripHotkey(Name),
  1021. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  1022. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  1023. // update the label, otherwise when it is updated only on the first draw
  1024. // of the list, it is drawn "bold" for some reason
  1025. FTransferListHoverIndex = TransferList->ItemIndex;
  1026. UpdateTransferLabel();
  1027. }
  1028. __finally
  1029. {
  1030. TransferList->Strings->EndUpdate();
  1031. }
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  1035. {
  1036. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  1037. DebugAssert(Toolbar != NULL);
  1038. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  1039. }
  1040. //---------------------------------------------------------------------------
  1041. void __fastcall TCustomScpExplorerForm::UpdateActions()
  1042. {
  1043. TForm::UpdateActions();
  1044. if (ComponentVisible[fcCustomCommandsBand])
  1045. {
  1046. UpdateCustomCommandsToolbar();
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  1051. {
  1052. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  1053. }
  1054. //---------------------------------------------------------------------------
  1055. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  1056. {
  1057. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  1058. {
  1059. DirView->RowSelect = WinConfiguration->FullRowSelect;
  1060. // Without this, the panel turns gray and unused part of header turns black
  1061. DirView->Perform(CM_COLORCHANGED, 0, 0);
  1062. }
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  1066. {
  1067. Color = GetBtnFaceColor();
  1068. DebugAssert(Configuration && RemoteDirView);
  1069. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1070. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  1071. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  1072. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  1073. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1074. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1075. RemoteDirView->AlwaysSortDirectoriesByName = WinConfiguration->AlwaysSortDirectoriesByName;
  1076. UpdateRowSelect(RemoteDirView);
  1077. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1078. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  1079. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  1080. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1081. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1082. UpdateSessionsPageControlHeight();
  1083. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1084. UpdateToolbarDisplayMode();
  1085. UpdateTransferList();
  1086. if (Terminal != NULL)
  1087. {
  1088. TransferPresetAutoSelect();
  1089. }
  1090. UpdateQueueView();
  1091. UpdateControls();
  1092. // this can be called even before constuctor finishes.
  1093. if (FEditorManager != NULL)
  1094. {
  1095. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  1096. }
  1097. // this can be called even before constuctor finishes.
  1098. if (FLocalEditors != NULL)
  1099. {
  1100. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  1101. {
  1102. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  1103. }
  1104. }
  1105. if (ComponentVisible[fcCustomCommandsBand])
  1106. {
  1107. UpdateCustomCommandsToolbar();
  1108. }
  1109. // show only when keeping queue items forever,
  1110. // otherwise, it's enough to have it in the context menu
  1111. QueueDeleteAllDoneQueueToolbarItem->Visible =
  1112. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  1113. if (FFileColorsCurrent != WinConfiguration->FileColors)
  1114. {
  1115. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  1116. FFileColorsCurrent = WinConfiguration->FileColors;
  1117. FileColorsChanged();
  1118. }
  1119. if ((GetNewTabTab()->CaptionTruncation != GetNewTabTabCaptionTruncation()) &&
  1120. (FSessionColors != NULL))
  1121. {
  1122. SessionListChanged();
  1123. }
  1124. if (GlyphsModule->LargerToolbar != WinConfiguration->LargerToolbar)
  1125. {
  1126. GlyphsModule->LargerToolbar = WinConfiguration->LargerToolbar;
  1127. if (FSessionColors != NULL)
  1128. {
  1129. RegenerateSessionColorsImageList();
  1130. UpdateSessionsPageControlHeight();
  1131. }
  1132. }
  1133. }
  1134. //---------------------------------------------------------------------------
  1135. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1136. {
  1137. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1138. DirView->Invalidate();
  1139. }
  1140. //---------------------------------------------------------------------------
  1141. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1142. {
  1143. DoFileColorsChanged(RemoteDirView);
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1147. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1148. void * /*Arg*/)
  1149. {
  1150. if (Token != NULL)
  1151. {
  1152. TForm * Editor = dynamic_cast<TForm*>(Token);
  1153. DebugAssert(Editor != NULL);
  1154. ReconfigureEditorForm(Editor);
  1155. }
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1159. {
  1160. WinConfiguration->DDTransferConfirmation = asOn;
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1164. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1165. {
  1166. // noop
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1170. {
  1171. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1175. {
  1176. if (DoNotShowAgain)
  1177. {
  1178. if (DragDrop)
  1179. {
  1180. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1181. {
  1182. PopupTrayBalloon(
  1183. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1184. }
  1185. WinConfiguration->DDTransferConfirmation = asOff;
  1186. }
  1187. else
  1188. {
  1189. WinConfiguration->ConfirmTransferring = false;
  1190. }
  1191. }
  1192. else
  1193. {
  1194. // User explicitly unchecked "do not show again",
  1195. // so show him the dialog the next time
  1196. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1197. {
  1198. WinConfiguration->DDTransferConfirmation = asOn;
  1199. }
  1200. }
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1204. TTransferDirection Direction, TTransferType Type, bool Temp,
  1205. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1206. bool Confirm, bool DragDrop, int Options)
  1207. {
  1208. bool Result = true;
  1209. DebugAssert(HasActiveTerminal());
  1210. // these parameters are known in advance
  1211. int Params =
  1212. FLAGMASK(Type == ttMove, cpDelete);
  1213. bool ToTemp = (Temp && (Direction == tdToLocal));
  1214. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1215. {
  1216. bool DisableNewerOnly =
  1217. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1218. ToTemp;
  1219. Options |=
  1220. FLAGMASK(ToTemp, coTemp) |
  1221. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1222. coDoNotShowAgain;
  1223. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1224. int CopyParamAttrs = (Direction == tdToRemote ?
  1225. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1226. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1227. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1228. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1229. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1230. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1231. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1232. if (Result)
  1233. {
  1234. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1235. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1236. }
  1237. }
  1238. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1239. {
  1240. Configuration->Usage->Inc(L"TransfersOnBackground");
  1241. // these parameter are known only after transfer dialog
  1242. Params |=
  1243. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1244. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1245. Result = false;
  1246. ClearTransferSourceSelection(Direction);
  1247. }
  1248. return Result;
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. void TCustomScpExplorerForm::ClearOperationSelection(TOperationSide Side)
  1252. {
  1253. if (FOnFileOperationFinished != NULL)
  1254. {
  1255. FOnFileOperationFinished(Side, UnicodeString(), true, true);
  1256. }
  1257. else
  1258. {
  1259. if (HasDirView[Side])
  1260. {
  1261. DirView(Side)->SelectAll(smNone);
  1262. }
  1263. }
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1267. {
  1268. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1269. ClearOperationSelection(Side);
  1270. }
  1271. //---------------------------------------------------------------------------
  1272. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1273. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1274. const UnicodeString TargetDirectory, TGUICopyParamType & CopyParam,
  1275. int Params)
  1276. {
  1277. DebugAssert(Queue != NULL);
  1278. TQueueItem * QueueItem;
  1279. if (Direction == tdToRemote)
  1280. {
  1281. CopyParam.IncludeFileMask.SetRoots(FileList, TargetDirectory);
  1282. QueueItem =
  1283. new TUploadQueueItem(
  1284. Terminal, FileList, TargetDirectory, &CopyParam, Params, CopyParam.QueueParallel);
  1285. }
  1286. else
  1287. {
  1288. CopyParam.IncludeFileMask.SetRoots(TargetDirectory, FileList);
  1289. QueueItem =
  1290. new TDownloadQueueItem(
  1291. Terminal, FileList, TargetDirectory, &CopyParam, Params, CopyParam.QueueParallel);
  1292. }
  1293. AddQueueItem(Queue, QueueItem, Terminal);
  1294. }
  1295. //---------------------------------------------------------------------------
  1296. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1297. {
  1298. if (Queue->IsEmpty)
  1299. {
  1300. Terminal->QueueOperationStart = Now();
  1301. }
  1302. Queue->AddItem(QueueItem);
  1303. }
  1304. //---------------------------------------------------------------------------
  1305. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1306. {
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. void __fastcall TCustomScpExplorerForm::InitControls()
  1310. {
  1311. DebugAssert(FDocks != NULL);
  1312. for (int Index = 0; Index < ComponentCount; Index++)
  1313. {
  1314. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1315. if ((Dock != NULL) && (Dock->Tag == 0))
  1316. {
  1317. FDocks->Add(Dock);
  1318. }
  1319. }
  1320. CollectItemsWithTextDisplayMode(this);
  1321. }
  1322. //---------------------------------------------------------------------------
  1323. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1324. {
  1325. ConfigurationChanged();
  1326. QueuePanel->Height =
  1327. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1328. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1329. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1330. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1331. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1332. QueueFileList->Height =
  1333. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1334. if (QueueFileList->Visible)
  1335. {
  1336. AdjustQueueLayout();
  1337. }
  1338. UpdateCustomCommandsToolbar();
  1339. }
  1340. //---------------------------------------------------------------------------
  1341. void __fastcall TCustomScpExplorerForm::StoreParams()
  1342. {
  1343. int APixelsPerInch = GetControlPixelsPerInch(this);
  1344. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1345. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1346. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1347. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1348. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1349. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1350. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1351. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1355. {
  1356. if (!FFormRestored)
  1357. {
  1358. FFormRestored = true;
  1359. RestoreFormParams();
  1360. }
  1361. TForm::CreateParams(Params);
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1365. {
  1366. DebugAssert(FDocks != NULL);
  1367. for (int Index = 0; Index < FDocks->Count; Index++)
  1368. {
  1369. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1370. }
  1371. }
  1372. //---------------------------------------------------------------------------
  1373. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1374. {
  1375. SetDockAllowDrag(true);
  1376. while (!ButtonsStr.IsEmpty())
  1377. {
  1378. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1379. UnicodeString Name = CutToChar(S, L'=', true);
  1380. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1381. {
  1382. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1383. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1384. {
  1385. while (!S.IsEmpty())
  1386. {
  1387. UnicodeString S2 = CutToChar(S, L',', true);
  1388. UnicodeString Name = CutToChar(S2, L':', true);
  1389. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1390. {
  1391. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1392. if (SameText(GetToolbarItemName(Item), Name))
  1393. {
  1394. // forward compatibility
  1395. UnicodeString S3 = CutToChar(S2, L':', true);
  1396. bool Visible = StrToIntDef(S3, 0);
  1397. Item->Visible = Visible;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1405. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1406. }
  1407. //---------------------------------------------------------------------------
  1408. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1409. {
  1410. UnicodeString Result;
  1411. SetDockAllowDrag(true);
  1412. Result = ::GetToolbarsLayoutStr(this);
  1413. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1414. return Result;
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1418. {
  1419. UnicodeString Result;
  1420. if (Item->Action != NULL)
  1421. {
  1422. Result = Item->Action->Name;
  1423. Result = RemoveSuffix(Result, L"Action", true);
  1424. }
  1425. else
  1426. {
  1427. Result = Item->Name;
  1428. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1429. Result = RemoveSuffix(Result, L"Item", true);
  1430. }
  1431. return Result;
  1432. }
  1433. //---------------------------------------------------------------------------
  1434. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1435. {
  1436. UnicodeString Result;
  1437. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1438. {
  1439. UnicodeString ToolbarStr;
  1440. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1441. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1442. {
  1443. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1444. {
  1445. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1446. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1447. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1448. // and save the changes here only.
  1449. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1450. {
  1451. UnicodeString Name = GetToolbarItemName(Item);
  1452. DebugAssert(Name.Pos(L"TBX") == 0);
  1453. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1454. }
  1455. }
  1456. }
  1457. if (!ToolbarStr.IsEmpty())
  1458. {
  1459. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1460. }
  1461. }
  1462. return Result;
  1463. }
  1464. //---------------------------------------------------------------------------
  1465. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1466. {
  1467. DebugAssert(FProgressForm == NULL);
  1468. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1469. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1470. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1471. FProgressForm->DeleteLocalToRecycleBin =
  1472. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1473. FProgressForm->DeleteRemoteToRecycleBin =
  1474. HasActiveTerminal() &&
  1475. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1476. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1477. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1478. LockWindow();
  1479. // Actually, do not know what hides the progress once the operation finishes
  1480. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1481. SetTaskbarListProgressState(TBPF_NORMAL);
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1485. {
  1486. UnlockWindow();
  1487. SAFE_DESTROY(FProgressForm);
  1488. SetQueueProgress();
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1492. TFileOperationProgressType & ProgressData)
  1493. {
  1494. // Download to temporary local directory
  1495. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1496. {
  1497. bool Continue = true;
  1498. FPendingTempSpaceWarn = false;
  1499. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1500. if (!Continue)
  1501. {
  1502. Abort();
  1503. }
  1504. }
  1505. // operation is being executed and we still didn't show up progress form
  1506. if (ProgressData.InProgress && !FProgressForm)
  1507. {
  1508. CreateProgressForm(NULL);
  1509. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1510. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1511. }
  1512. // operation is finished (or terminated), so we hide progress form
  1513. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1514. {
  1515. DestroyProgressForm();
  1516. if (ProgressData.Operation == foCalculateSize)
  1517. {
  1518. // When calculating size before transfer, the abort caused by
  1519. // cancel flag set due to "MoveToQueue" below,
  1520. // is not propagated back to us in ExecuteFileOperation,
  1521. // as it is silently swallowed.
  1522. // So we explicitly (re)throw it here.
  1523. if (FMoveToQueue)
  1524. {
  1525. Abort();
  1526. }
  1527. }
  1528. else
  1529. {
  1530. if ((ProgressData.Cancel == csContinue) &&
  1531. !FAutoOperation)
  1532. {
  1533. OperationComplete(ProgressData.StartTime);
  1534. }
  1535. }
  1536. }
  1537. if (FProgressForm &&
  1538. // Can happen only during synchronization, when ending one of the operations
  1539. ProgressData.InProgress)
  1540. {
  1541. FProgressForm->SetProgressData(ProgressData);
  1542. DebugAssert(ProgressData.InProgress);
  1543. SetTaskbarListProgressValue(&ProgressData);
  1544. if (FProgressForm->Cancel > csContinue)
  1545. {
  1546. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1547. if (FProgressForm->Cancel == csCancelFile)
  1548. {
  1549. FProgressForm->ClearCancel();
  1550. }
  1551. // cancel cancels even the move
  1552. FMoveToQueue = false;
  1553. }
  1554. else if (FProgressForm->MoveToQueue)
  1555. {
  1556. FMoveToQueue = true;
  1557. ProgressData.SetCancelAtLeast(csCancel);
  1558. }
  1559. if ((FTransferResumeList != NULL) &&
  1560. ProgressData.InProgress &&
  1561. ProgressData.IsTransfer() &&
  1562. !ProgressData.FullFileName.IsEmpty())
  1563. {
  1564. if ((FTransferResumeList->Count == 0) ||
  1565. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1566. {
  1567. // note that we do not recognize directories from files here
  1568. FTransferResumeList->Add(ProgressData.FullFileName);
  1569. }
  1570. }
  1571. }
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1575. const TDateTime & StartTime)
  1576. {
  1577. if (GUIConfiguration->BeepOnFinish &&
  1578. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1579. {
  1580. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1581. DWORD Sound;
  1582. if (!ExtractFileExt(BeepSound).IsEmpty())
  1583. {
  1584. Sound = SND_FILENAME;
  1585. }
  1586. else
  1587. {
  1588. Sound = SND_ALIAS;
  1589. }
  1590. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1591. }
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1595. TFileOperationProgressType & ProgressData)
  1596. {
  1597. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1598. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1599. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1600. FileOperationProgress(ProgressData);
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1604. {
  1605. UnicodeString Result;
  1606. if (FProgressForm != NULL)
  1607. {
  1608. Result = FProgressForm->ProgressStr();
  1609. }
  1610. return Result;
  1611. }
  1612. //---------------------------------------------------------------------------
  1613. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1614. bool DragDrop)
  1615. {
  1616. return (!DragDrop && (DropSourceControl == NULL)) ||
  1617. (DropSourceControl == DirView(osOther));
  1618. }
  1619. //---------------------------------------------------------------------------
  1620. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1621. {
  1622. TCustomDirView * ADirView = DirView(Side);
  1623. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1624. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1625. // this can happen when local drive is unplugged in the middle of the operation
  1626. if (Item != NULL)
  1627. {
  1628. if (Unselect)
  1629. {
  1630. Item->Selected = false;
  1631. }
  1632. ADirView->MakeProgressVisible(Item);
  1633. }
  1634. return Item;
  1635. }
  1636. //---------------------------------------------------------------------------
  1637. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1638. TFileOperation Operation, TOperationSide Side,
  1639. bool /*Temp*/, const UnicodeString & FileName, bool Success, bool NotCancelled,
  1640. TOnceDoneOperation & OnceDoneOperation)
  1641. {
  1642. if (!FAutoOperation)
  1643. {
  1644. // no selection on "/upload", form serves only as event handler
  1645. // (it is not displayed)
  1646. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1647. ((Operation == FPrimaryOperation) ||
  1648. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1649. {
  1650. TOperationSide DViewSide;
  1651. if ((FProgressSide != osCurrent) &&
  1652. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1653. {
  1654. // assume the operation is over the focused panel
  1655. DViewSide = FProgressSide;
  1656. }
  1657. else
  1658. {
  1659. DViewSide = Side;
  1660. }
  1661. if (FOnFileOperationFinished != NULL)
  1662. {
  1663. FOnFileOperationFinished(DViewSide, FileName, Success, NotCancelled);
  1664. }
  1665. else
  1666. {
  1667. VisualiseOperationFinished(DViewSide, FileName, Success && NotCancelled);
  1668. }
  1669. }
  1670. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1671. {
  1672. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1673. {
  1674. if (Side == osLocal)
  1675. {
  1676. Configuration->Usage->Inc(L"UploadedFiles");
  1677. }
  1678. else
  1679. {
  1680. Configuration->Usage->Inc(L"DownloadedFiles");
  1681. }
  1682. }
  1683. }
  1684. }
  1685. if (Success && (FSynchronizeController != NULL))
  1686. {
  1687. DebugAssert(!IsSideLocalBrowser(osRemote));
  1688. if (Operation == foCopy)
  1689. {
  1690. DebugAssert(Side == osLocal);
  1691. FSynchronizeController->LogOperation(soUpload, FileName);
  1692. }
  1693. else if (Operation == foDelete)
  1694. {
  1695. DebugAssert(Side == osRemote);
  1696. FSynchronizeController->LogOperation(soDelete, FileName);
  1697. }
  1698. }
  1699. if (FProgressForm)
  1700. {
  1701. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1702. }
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1706. TFileOperation Operation, TOperationSide Side,
  1707. bool Temp, const UnicodeString & FileName, bool Success, bool NotCancelled,
  1708. TOnceDoneOperation & OnceDoneOperation)
  1709. {
  1710. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1711. DoOperationFinished(Operation, Side, Temp, FileName, Success, NotCancelled, OnceDoneOperation);
  1712. }
  1713. //---------------------------------------------------------------------------
  1714. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1715. {
  1716. return false;
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1720. {
  1721. return false;
  1722. }
  1723. //---------------------------------------------------------------------------
  1724. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1725. {
  1726. return false;
  1727. }
  1728. //---------------------------------------------------------------------------
  1729. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1730. {
  1731. return NULL;
  1732. }
  1733. //---------------------------------------------------------------------------
  1734. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1735. {
  1736. DebugAssert(GetSide(Side) == osRemote);
  1737. DebugUsedParam(Side);
  1738. return RemoteDirView;
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1742. {
  1743. DebugAssert(GetSide(Side) == osRemote);
  1744. DebugUsedParam(Side);
  1745. return RemoteDriveView;
  1746. }
  1747. //---------------------------------------------------------------------------
  1748. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1749. {
  1750. DebugAssert(GetSide(Side) == osRemote);
  1751. DebugUsedParam(Side);
  1752. return HasActiveTerminal();
  1753. }
  1754. //---------------------------------------------------------------------------
  1755. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1756. TOperationSide Side, int FilesOnly)
  1757. {
  1758. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1759. }
  1760. //---------------------------------------------------------------------------
  1761. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1762. TOperationSide Side, int FilesOnly)
  1763. {
  1764. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. struct THistoryItemData
  1768. {
  1769. short int Side;
  1770. short int Index;
  1771. };
  1772. //---------------------------------------------------------------------------
  1773. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1774. {
  1775. DirView(Side)->HistoryGo(Index);
  1776. }
  1777. //---------------------------------------------------------------------------
  1778. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1779. {
  1780. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1781. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1782. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1783. }
  1784. //---------------------------------------------------------------------------
  1785. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1786. bool Back)
  1787. {
  1788. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1789. {
  1790. TCustomDirView * DView = DirView(Side);
  1791. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1792. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1793. if (ICount > 10)
  1794. {
  1795. ICount = 10;
  1796. }
  1797. Menu->Items->Clear();
  1798. THistoryItemData Data;
  1799. Data.Side = Side;
  1800. for (short int i = 1; i <= ICount; i++)
  1801. {
  1802. TTBCustomItem * Item = new TTBXItem(Menu);
  1803. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1804. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1805. Item->Hint = DView->HistoryPath[Data.Index];
  1806. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1807. Item->Tag = *reinterpret_cast<int*>(&Data);
  1808. Item->OnClick = HistoryItemClick;
  1809. Menu->Items->Add(Item);
  1810. }
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1815. TOperationSide Side, bool Back)
  1816. {
  1817. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1818. {
  1819. // workaround
  1820. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1821. // operator new allocates memory in Pascal code, but calls inline
  1822. // constructor in C++, leading in problems, the function does
  1823. // both in Pascal code
  1824. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1825. UpdateHistoryMenu(Side, Back);
  1826. }
  1827. return FHistoryMenu[Side == osLocal][Back];
  1828. }
  1829. //---------------------------------------------------------------------------
  1830. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1831. TCustomDirView *Sender)
  1832. {
  1833. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1834. UpdateHistoryMenu(Side, true);
  1835. UpdateHistoryMenu(Side, false);
  1836. }
  1837. //---------------------------------------------------------------------------
  1838. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1839. {
  1840. // remote custom commands can be executed only if the server supports shell commands
  1841. // or have secondary shell
  1842. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1843. }
  1844. //---------------------------------------------------------------------------
  1845. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1846. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1847. {
  1848. // -1 = hidden, 0 = disabled, 1 = enabled
  1849. int Result;
  1850. TFileCustomCommand RemoteCustomCommand;
  1851. TLocalCustomCommand LocalCustomCommand;
  1852. TFileCustomCommand * NonInteractiveCustomCommand =
  1853. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1854. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1855. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1856. if (FLAGCLEAR(Command.Params, ccLocal))
  1857. {
  1858. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1859. // custom command that does not operate with files can be executed anytime ...
  1860. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1861. {
  1862. // ... but do not show such command in remote file menu
  1863. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1864. {
  1865. Result = AllowedState;
  1866. }
  1867. else
  1868. {
  1869. Result = -1;
  1870. }
  1871. }
  1872. else
  1873. {
  1874. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1875. {
  1876. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1877. }
  1878. else
  1879. {
  1880. Result = -1;
  1881. }
  1882. }
  1883. }
  1884. else
  1885. {
  1886. // custom command that does not operate with files can be executed anytime
  1887. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1888. {
  1889. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1890. }
  1891. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1892. {
  1893. if ((ListType == ccltAll) || (ListType == ccltFile))
  1894. {
  1895. // special case is "diff"-style command that can be executed over any side,
  1896. // if we have both sides
  1897. Result =
  1898. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1899. // directly (instead of EnableSelectedOperation) to pass
  1900. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1901. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1902. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1903. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1904. }
  1905. else if (ListType == ccltBoth)
  1906. {
  1907. DebugAssert(!IsLocalBrowserMode());
  1908. Result = 1;
  1909. }
  1910. else
  1911. {
  1912. Result = -1;
  1913. }
  1914. }
  1915. else
  1916. {
  1917. if ((ListType == ccltAll) ||
  1918. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1919. {
  1920. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1921. }
  1922. else
  1923. {
  1924. Result = -1;
  1925. }
  1926. }
  1927. if ((Result > 0) &&
  1928. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1929. !HasActiveTerminal())
  1930. {
  1931. Result = 0;
  1932. }
  1933. }
  1934. return Result;
  1935. }
  1936. //---------------------------------------------------------------------------
  1937. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1938. TStrings * FileList, const TCustomCommandType & ACommand,
  1939. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1940. {
  1941. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1942. {
  1943. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1944. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1945. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1946. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1947. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1948. bool Capture =
  1949. FLAGSET(ACommand.Params, ccShowResults) ||
  1950. FLAGSET(ACommand.Params, ccCopyResults) ||
  1951. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1952. TCaptureOutputEvent OutputEvent = NULL;
  1953. DebugAssert(FCapturedLog == NULL);
  1954. if (Capture)
  1955. {
  1956. FCapturedLog = new TStringList();
  1957. OutputEvent = TerminalCaptureLog;
  1958. }
  1959. try
  1960. {
  1961. if (!RemoteCustomCommand.IsFileCommand(Command))
  1962. {
  1963. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1964. OutputEvent);
  1965. }
  1966. else
  1967. {
  1968. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1969. }
  1970. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1971. {
  1972. if (FLAGSET(ACommand.Params, ccCopyResults))
  1973. {
  1974. CopyToClipboard(FCapturedLog);
  1975. }
  1976. if (FLAGSET(ACommand.Params, ccShowResults))
  1977. {
  1978. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1979. }
  1980. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1981. {
  1982. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1983. }
  1984. }
  1985. }
  1986. __finally
  1987. {
  1988. SAFE_DESTROY(FCapturedLog);
  1989. }
  1990. }
  1991. }
  1992. //---------------------------------------------------------------------------
  1993. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1994. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1995. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1996. {
  1997. DebugAssert(!IsLocalBrowserMode());
  1998. TStrings * LocalFileList = NULL;
  1999. TStrings * RemoteFileList = NULL;
  2000. TStrings * RemoteFileListFull = NULL;
  2001. try
  2002. {
  2003. if (LocalFileCommand)
  2004. {
  2005. if (ALocalFileList == NULL)
  2006. {
  2007. DebugAssert(HasDirView[osLocal]);
  2008. // Cannot have focus on both panels, so we have to call AnyFileSelected
  2009. // directly (instead of EnableSelectedOperation) to pass
  2010. // false to FocusedFileOnlyWhenFocused
  2011. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  2012. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  2013. }
  2014. else
  2015. {
  2016. LocalFileList = ALocalFileList;
  2017. }
  2018. if (FileListCommand)
  2019. {
  2020. if (LocalFileList->Count != 1)
  2021. {
  2022. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  2023. }
  2024. }
  2025. else
  2026. {
  2027. if ((LocalFileList->Count != 1) &&
  2028. (FileList->Count != 1) &&
  2029. (LocalFileList->Count != FileList->Count))
  2030. {
  2031. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  2032. }
  2033. }
  2034. }
  2035. UnicodeString RootTempDir;
  2036. UnicodeString TempDir;
  2037. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  2038. if (!RemoteFiles)
  2039. {
  2040. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, true, true);
  2041. }
  2042. try
  2043. {
  2044. TDateTimes RemoteFileTimes;
  2045. if (RemoteFiles)
  2046. {
  2047. RemoteFileList = FileList;
  2048. }
  2049. else
  2050. {
  2051. RemoteFileList = new TStringList();
  2052. TMakeLocalFileListParams MakeFileListParam;
  2053. MakeFileListParam.FileList = RemoteFileList;
  2054. MakeFileListParam.FileTimes = &RemoteFileTimes;
  2055. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2056. MakeFileListParam.Recursive =
  2057. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  2058. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2059. if (!MakeFileListParam.Recursive)
  2060. {
  2061. RemoteFileTimes.clear();
  2062. RemoteFileListFull = new TStringList();
  2063. MakeFileListParam.FileList = RemoteFileListFull;
  2064. MakeFileListParam.Recursive = true;
  2065. MakeFileListParam.IncludeDirs = false;
  2066. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2067. }
  2068. else
  2069. {
  2070. RemoteFileListFull = RemoteFileList;
  2071. }
  2072. }
  2073. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  2074. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2075. if (!NonBlocking)
  2076. {
  2077. int Count;
  2078. if (FileListCommand)
  2079. {
  2080. Count = 1;
  2081. }
  2082. else if (LocalFileCommand)
  2083. {
  2084. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  2085. }
  2086. else
  2087. {
  2088. Count = RemoteFileList->Count;
  2089. }
  2090. Progress.Start(foCustomCommand, osRemote, Count);
  2091. DebugAssert(FProgressForm != NULL);
  2092. FProgressForm->ReadOnly = true;
  2093. }
  2094. try
  2095. {
  2096. if (FileListCommand)
  2097. {
  2098. UnicodeString LocalFile;
  2099. // MakeFileList does not delimit filenames
  2100. UnicodeString FileList = MakeFileList(RemoteFileList);
  2101. if (LocalFileCommand)
  2102. {
  2103. DebugAssert(LocalFileList->Count == 1);
  2104. LocalFile = LocalFileList->Strings[0];
  2105. }
  2106. TLocalCustomCommand CustomCommand(Data,
  2107. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  2108. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2109. if (NonBlocking)
  2110. {
  2111. DebugAssert(!POutput);
  2112. ExecuteShellChecked(ShellCommand);
  2113. }
  2114. else
  2115. {
  2116. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2117. }
  2118. }
  2119. else if (LocalFileCommand)
  2120. {
  2121. if (LocalFileList->Count == 1)
  2122. {
  2123. UnicodeString LocalFile = LocalFileList->Strings[0];
  2124. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2125. {
  2126. UnicodeString FileName = RemoteFileList->Strings[Index];
  2127. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2128. Progress.SetFile(FileNameForProgress);
  2129. TLocalCustomCommand CustomCommand(Data,
  2130. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2131. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2132. TOnceDoneOperation OnceDoneOperation;
  2133. // Do not unselect anything, as it won't work with two panels anyway
  2134. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2135. }
  2136. }
  2137. else if (RemoteFileList->Count == 1)
  2138. {
  2139. UnicodeString FileName = RemoteFileList->Strings[0];
  2140. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2141. {
  2142. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2143. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2144. Progress.SetFile(LocalFileNameOnly);
  2145. TLocalCustomCommand CustomCommand(
  2146. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2147. FileName, LocalFileName, L"");
  2148. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2149. TOnceDoneOperation OnceDoneOperation;
  2150. // Do not unselect anything, as it won't work with two panels anyway
  2151. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2152. }
  2153. }
  2154. else
  2155. {
  2156. if (LocalFileList->Count != RemoteFileList->Count)
  2157. {
  2158. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2159. }
  2160. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2161. {
  2162. UnicodeString FileName = RemoteFileList->Strings[Index];
  2163. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2164. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2165. Progress.SetFile(LocalFileNameOnly); // sic
  2166. TLocalCustomCommand CustomCommand(
  2167. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2168. FileName, LocalFileName, L"");
  2169. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2170. TOnceDoneOperation OnceDoneOperation;
  2171. // Do not unselect anything, as it won't work with two panels anyway
  2172. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2173. }
  2174. }
  2175. }
  2176. else
  2177. {
  2178. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2179. {
  2180. UnicodeString FileName = RemoteFileList->Strings[Index];
  2181. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2182. Progress.SetFile(FileNameForProgress);
  2183. TLocalCustomCommand CustomCommand(Data,
  2184. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2185. FileName, L"", L"");
  2186. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2187. TOnceDoneOperation OnceDoneOperation;
  2188. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2189. }
  2190. }
  2191. }
  2192. __finally
  2193. {
  2194. if (!NonBlocking)
  2195. {
  2196. Progress.Stop();
  2197. }
  2198. }
  2199. DebugAssert(!FAutoOperation);
  2200. if (!RemoteFiles)
  2201. {
  2202. TempDir = IncludeTrailingBackslash(TempDir);
  2203. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2204. {
  2205. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2206. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2207. // Skip directories, process only nested files.
  2208. // The check is redundant as FileAge fails for directories anyway.
  2209. !DirectoryExists(FileName))
  2210. {
  2211. UnicodeString RemoteDir =
  2212. UnixExtractFileDir(
  2213. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2214. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2215. TSearchRecSmart SearchRec;
  2216. if (FileSearchRec(FileName, SearchRec) &&
  2217. (SearchRec.GetLastWriteTime() != RemoteFileTimes[Index]))
  2218. {
  2219. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2220. TemporaryFileCopyParam(CopyParam);
  2221. CopyParam.FileMask = L"";
  2222. FAutoOperation = true;
  2223. FMoveToQueue = false;
  2224. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2225. TemporaryFilesList->Add(FileName);
  2226. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. __finally
  2233. {
  2234. FAutoOperation = false;
  2235. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2236. {
  2237. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  2238. }
  2239. }
  2240. }
  2241. __finally
  2242. {
  2243. if (RemoteFileList != FileList)
  2244. {
  2245. delete RemoteFileList;
  2246. }
  2247. if (LocalFileList != ALocalFileList)
  2248. {
  2249. delete LocalFileList;
  2250. }
  2251. if (RemoteFileListFull != RemoteFileList)
  2252. {
  2253. delete RemoteFileListFull;
  2254. }
  2255. }
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2259. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2260. bool FileListCommand, UnicodeString * POutput)
  2261. {
  2262. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2263. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2264. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2265. {
  2266. UnicodeString FileName = SelectedFileList->Strings[Index];
  2267. if (DirectoryExists(FileName))
  2268. {
  2269. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2270. {
  2271. LocalFileList->Add(FileName);
  2272. }
  2273. if (FLAGSET(ACommand.Params, ccRecursive))
  2274. {
  2275. TMakeLocalFileListParams MakeFileListParam;
  2276. MakeFileListParam.FileList = LocalFileList.get();
  2277. MakeFileListParam.FileTimes = NULL;
  2278. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2279. MakeFileListParam.Recursive = true;
  2280. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2281. }
  2282. }
  2283. else
  2284. {
  2285. LocalFileList->Add(FileName);
  2286. }
  2287. }
  2288. UnicodeString RemotePath;
  2289. if (Terminal != NULL)
  2290. {
  2291. RemotePath = Terminal->CurrentDirectory;
  2292. }
  2293. if (FileListCommand)
  2294. {
  2295. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2296. TLocalCustomCommand CustomCommand(
  2297. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2298. L"", L"", FileList);
  2299. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2300. }
  2301. else
  2302. {
  2303. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2304. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2305. DebugAssert(FProgressForm != NULL);
  2306. FProgressForm->ReadOnly = true;
  2307. try
  2308. {
  2309. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2310. {
  2311. UnicodeString FileName = LocalFileList->Strings[Index];
  2312. Progress.SetFile(FileName);
  2313. TLocalCustomCommand CustomCommand(
  2314. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2315. FileName, L"", L"");
  2316. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2317. TOnceDoneOperation OnceDoneOperation;
  2318. Progress.Finish(FileName, true, OnceDoneOperation);
  2319. }
  2320. }
  2321. __finally
  2322. {
  2323. Progress.Stop();
  2324. }
  2325. }
  2326. }
  2327. //---------------------------------------------------------------------------
  2328. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2329. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2330. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2331. {
  2332. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2333. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2334. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2335. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2336. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2337. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2338. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2339. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2340. std::unique_ptr<UnicodeString> POutput;
  2341. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2342. FLAGSET(ACommand.Params, ccCopyResults))
  2343. {
  2344. POutput.reset(new UnicodeString());
  2345. }
  2346. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  2347. if (!LocalCustomCommand.IsFileCommand(Command))
  2348. {
  2349. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2350. }
  2351. // remote files?
  2352. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2353. {
  2354. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2355. }
  2356. // local files
  2357. else
  2358. {
  2359. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2360. }
  2361. if (POutput.get() != NULL)
  2362. {
  2363. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2364. int P = POutput->Pos(sLineBreak);
  2365. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2366. {
  2367. POutput->SetLength(P - 1);
  2368. }
  2369. // Copy even empty output to clipboard
  2370. if (FLAGSET(ACommand.Params, ccCopyResults))
  2371. {
  2372. CopyToClipboard(*POutput);
  2373. }
  2374. // But do not show an empty message box.
  2375. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2376. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2377. !POutput->IsEmpty())
  2378. {
  2379. TClipboardHandler ClipboardHandler;
  2380. ClipboardHandler.Text = *POutput;
  2381. TMessageParams Params;
  2382. TQueryButtonAlias Aliases[1];
  2383. Aliases[0].Button = qaRetry;
  2384. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2385. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2386. Params.Aliases = Aliases;
  2387. Params.AliasesCount = LENOF(Aliases);
  2388. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2389. }
  2390. }
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2394. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2395. {
  2396. TCustomCommandData Data;
  2397. UnicodeString Site;
  2398. UnicodeString RemotePath;
  2399. if (HasActiveTerminal())
  2400. {
  2401. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2402. Data = TCustomCommandData(SessionData.get());
  2403. Site = Terminal->SessionData->SessionKey;
  2404. RemotePath = Terminal->CurrentDirectory;
  2405. }
  2406. UnicodeString HelpKeyword = ACommand.HomePage;
  2407. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2408. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2409. {
  2410. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2411. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2412. {
  2413. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2414. }
  2415. else
  2416. {
  2417. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2418. }
  2419. if (!DoCustomCommandOptionsDialog(
  2420. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2421. {
  2422. Abort();
  2423. }
  2424. }
  2425. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2426. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2427. {
  2428. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2429. }
  2430. else
  2431. {
  2432. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2433. }
  2434. }
  2435. //---------------------------------------------------------------------------
  2436. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2437. const TCustomCommandType & Command)
  2438. {
  2439. DebugAssert(FCustomCommandLocalFileList != NULL);
  2440. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2441. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2442. TStrings * LocalFileList = new TStringList();
  2443. TStrings * RemoteFileList = new TStringList();
  2444. try
  2445. {
  2446. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2447. {
  2448. LocalFileList->Clear();
  2449. LocalFileList->AddObject(
  2450. FCustomCommandLocalFileList->Strings[Index],
  2451. FCustomCommandLocalFileList->Objects[Index]);
  2452. RemoteFileList->Clear();
  2453. RemoteFileList->AddObject(
  2454. FCustomCommandRemoteFileList->Strings[Index],
  2455. FCustomCommandRemoteFileList->Objects[Index]);
  2456. CustomCommand(RemoteFileList, Command, LocalFileList);
  2457. }
  2458. }
  2459. __finally
  2460. {
  2461. delete LocalFileList;
  2462. delete RemoteFileList;
  2463. }
  2464. }
  2465. //---------------------------------------------------------------------------
  2466. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2467. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2468. {
  2469. delete FCustomCommandLocalFileList;
  2470. delete FCustomCommandRemoteFileList;
  2471. // takeover ownership,
  2472. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2473. FCustomCommandLocalFileList = LocalFileList;
  2474. FCustomCommandRemoteFileList = RemoteFileList;
  2475. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2476. if (Button != NULL)
  2477. {
  2478. FCustomCommandMenu->Items->Clear();
  2479. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2480. MenuPopup(FCustomCommandMenu, Button);
  2481. }
  2482. else
  2483. {
  2484. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2485. }
  2486. }
  2487. //---------------------------------------------------------------------------
  2488. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2489. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2490. {
  2491. DebugAssert(FCapturedLog != NULL);
  2492. if ((OutputType == cotOutput) || (OutputType == cotError))
  2493. {
  2494. FCapturedLog->Add(AddedLine);
  2495. }
  2496. }
  2497. //---------------------------------------------------------------------------
  2498. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2499. TOperationSide Side)
  2500. {
  2501. return
  2502. (Side == osOther) &&
  2503. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2504. }
  2505. //---------------------------------------------------------------------------
  2506. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2507. TOperationSide Side, TTBXCustomItem * Item,
  2508. TResolvedDoubleClickAction DoubleClickAction1, TResolvedDoubleClickAction DoubleClickAction2)
  2509. {
  2510. TCustomDirView * DView = DirView(Side);
  2511. bool IsDefault = false;
  2512. if (DView->ItemFocused != NULL)
  2513. {
  2514. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  2515. TResolvedDoubleClickAction DefaultAction =
  2516. WinConfiguration->ResolveDoubleClickAction(DView->ItemIsDirectory(DView->ItemFocused), ATerminal);
  2517. IsDefault = (DefaultAction == DoubleClickAction1) || (DefaultAction == DoubleClickAction2);
  2518. }
  2519. TTBItemOptions O = Item->Options;
  2520. if (IsDefault)
  2521. {
  2522. Item->Options = O << tboDefault;
  2523. }
  2524. else
  2525. {
  2526. Item->Options = O >> tboDefault;
  2527. }
  2528. }
  2529. //---------------------------------------------------------------------------
  2530. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2531. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2532. {
  2533. TCustomDirView * DView = DirView(Side);
  2534. TListItem * Item = DView->ItemFocused;
  2535. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2536. EnableFocusedOperation[Side])
  2537. {
  2538. TPoint ClientPoint;
  2539. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2540. TPoint(0, 0) : MousePos;
  2541. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2542. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2543. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2544. }
  2545. }
  2546. //---------------------------------------------------------------------------
  2547. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2548. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2549. {
  2550. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, rdcaChangeDir, rdcaOpen);
  2551. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, rdcaEdit, rdcaNone);
  2552. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, rdcaCopy, rdcaNone);
  2553. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2554. Handled = true;
  2555. }
  2556. //---------------------------------------------------------------------------
  2557. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2558. {
  2559. }
  2560. //---------------------------------------------------------------------------
  2561. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2562. {
  2563. DebugAssert(FErrorList == NULL);
  2564. if (WinConfiguration->ContinueOnError)
  2565. {
  2566. FErrorList = new TStringList();
  2567. Configuration->Usage->Inc(L"ContinuationsOnError");
  2568. }
  2569. NonVisualDataModule->StartBusy();
  2570. }
  2571. //---------------------------------------------------------------------------
  2572. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2573. {
  2574. NonVisualDataModule->EndBusy();
  2575. if (FErrorList)
  2576. {
  2577. HandleErrorList(FErrorList);
  2578. }
  2579. }
  2580. //---------------------------------------------------------------------------
  2581. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2582. const TCopyParamType & CopyParam)
  2583. {
  2584. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2585. {
  2586. Configuration->Usage->Inc(L"FileMaskUses");
  2587. }
  2588. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2589. {
  2590. Configuration->Usage->Inc(L"OperationMaskUses");
  2591. }
  2592. }
  2593. //---------------------------------------------------------------------------
  2594. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2595. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2596. {
  2597. DebugAssert(!IsLocalBrowserMode());
  2598. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2599. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2600. TTransferOperationParam DefaultParam;
  2601. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2602. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2603. switch (Param.Queue)
  2604. {
  2605. case asOn:
  2606. CopyParam.Queue = true;
  2607. break;
  2608. case asOff:
  2609. CopyParam.Queue = false;
  2610. break;
  2611. case asAuto:
  2612. default:
  2613. // keep default
  2614. break;
  2615. }
  2616. bool Result =
  2617. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2618. if (Result)
  2619. {
  2620. DebugAssert(Terminal);
  2621. bool SelectionRestored = false;
  2622. TCustomDirView * DView = NULL;
  2623. if (HasDirView[Side])
  2624. {
  2625. DView = DirView(Side);
  2626. DView->SaveSelection();
  2627. DView->SaveSelectedNames();
  2628. }
  2629. UpdateCopyParamCounters(CopyParam);
  2630. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2631. DebugAssert(FTransferResumeList == NULL);
  2632. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2633. FMoveToQueue = false;
  2634. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2635. try
  2636. {
  2637. TStrings * PermanentFileList;
  2638. std::unique_ptr<TStrings> PermanentFileListOwner;
  2639. try
  2640. {
  2641. if (Side == osLocal)
  2642. {
  2643. PermanentFileList = FileList;
  2644. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2645. CopyParam.IncludeFileMask.SetRoots(FileList, Param.TargetDirectory);
  2646. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2647. if (Operation == foMove)
  2648. {
  2649. ReloadLocalDirectory();
  2650. if (DView != NULL)
  2651. {
  2652. DView->RestoreSelection();
  2653. }
  2654. SelectionRestored = true;
  2655. }
  2656. }
  2657. else
  2658. {
  2659. // Clone the file list as it may refer to current directory files,
  2660. // which get destroyed, when the source directory is reloaded after foMove operation.
  2661. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2662. // But for a hotfix, we are not going to do such a big change.
  2663. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2664. PermanentFileList = PermanentFileListOwner.get();
  2665. try
  2666. {
  2667. CopyParam.IncludeFileMask.SetRoots(Param.TargetDirectory, FileList);
  2668. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2669. }
  2670. __finally
  2671. {
  2672. if (Operation == foMove)
  2673. {
  2674. if (DView != NULL)
  2675. {
  2676. DView->RestoreSelection();
  2677. }
  2678. SelectionRestored = true;
  2679. }
  2680. ReloadLocalDirectory(Param.TargetDirectory);
  2681. }
  2682. }
  2683. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2684. if (FMoveToQueue)
  2685. {
  2686. Abort();
  2687. }
  2688. }
  2689. catch (EAbort &)
  2690. {
  2691. if (FMoveToQueue)
  2692. {
  2693. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2694. DebugAssert(CopyParam.TransferSkipList == NULL);
  2695. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2696. if (TransferResumeList->Count > 0)
  2697. {
  2698. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2699. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2700. }
  2701. CopyParam.TransferSkipList = TransferResumeList.release();
  2702. // not really needed, just to keep it consistent with TransferResumeList
  2703. FTransferResumeList = NULL;
  2704. FMoveToQueue = false;
  2705. Configuration->Usage->Inc("MovesToBackground");
  2706. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2707. ClearTransferSourceSelection(Direction);
  2708. }
  2709. throw;
  2710. }
  2711. }
  2712. __finally
  2713. {
  2714. if (!SelectionRestored && (DView != NULL))
  2715. {
  2716. DView->DiscardSavedSelection();
  2717. }
  2718. FTransferResumeList = NULL;
  2719. }
  2720. }
  2721. return Result;
  2722. }
  2723. //---------------------------------------------------------------------------
  2724. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2725. TOperationSide Side, TStrings * FileList, void * Param)
  2726. {
  2727. DebugAssert(FileList->Count);
  2728. // We deliberately do not toggle alternative flag (Param), but use OR,
  2729. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2730. // shortcut of CurrentDeleteAlternativeAction
  2731. bool Alternative =
  2732. bool(Param) || UseAlternativeFunction();
  2733. bool Recycle;
  2734. if (IsSideLocalBrowser(Side))
  2735. {
  2736. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2737. }
  2738. else
  2739. {
  2740. Recycle =
  2741. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2742. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2743. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2744. }
  2745. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2746. if (!Result)
  2747. {
  2748. UnicodeString Query;
  2749. if (FileList->Count == 1)
  2750. {
  2751. if (IsSideLocalBrowser(Side))
  2752. {
  2753. Query = ExtractFileName(FileList->Strings[0]);
  2754. }
  2755. else
  2756. {
  2757. Query = UnixExtractFileName(FileList->Strings[0]);
  2758. }
  2759. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2760. }
  2761. else
  2762. {
  2763. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2764. }
  2765. TMessageParams Params(mpNeverAskAgainCheck);
  2766. Params.ImageName = L"Delete file";
  2767. unsigned int Answer =
  2768. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2769. if (Answer == qaNeverAskAgain)
  2770. {
  2771. Result = true;
  2772. if (Recycle)
  2773. {
  2774. WinConfiguration->ConfirmRecycling = false;
  2775. }
  2776. else
  2777. {
  2778. WinConfiguration->ConfirmDeleting = false;
  2779. }
  2780. }
  2781. else
  2782. {
  2783. Result = (Answer == qaOK);
  2784. }
  2785. }
  2786. if (Result)
  2787. {
  2788. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2789. }
  2790. return Result;
  2791. }
  2792. //---------------------------------------------------------------------------
  2793. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2794. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2795. {
  2796. TAutoBatch AutoBatch(this);
  2797. bool Result;
  2798. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2799. {
  2800. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2801. }
  2802. else if (Operation == foRename)
  2803. {
  2804. DebugAssert(DirView(Side)->ItemFocused);
  2805. DirView(Side)->ItemFocused->EditCaption();
  2806. Result = true;
  2807. }
  2808. else if (Operation == foDelete)
  2809. {
  2810. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2811. }
  2812. else if (Operation == foSetProperties)
  2813. {
  2814. DirView(osRemote)->SaveSelectedNames();
  2815. Result = SetProperties(Side, FileList);
  2816. }
  2817. else if (Operation == foCustomCommand)
  2818. {
  2819. DebugAssert(Param);
  2820. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2821. DirView(osRemote)->SaveSelectedNames();
  2822. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2823. CustomCommand(FileList, *Command, NULL);
  2824. Result = true;
  2825. }
  2826. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2827. {
  2828. DebugAssert(!IsSideLocalBrowser(Side));
  2829. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2830. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2831. }
  2832. else if (Operation == foLock)
  2833. {
  2834. DebugAssert(!IsSideLocalBrowser(Side));
  2835. LockFiles(FileList, true);
  2836. Result = true;
  2837. }
  2838. else if (Operation == foUnlock)
  2839. {
  2840. DebugAssert(!IsSideLocalBrowser(Side));
  2841. LockFiles(FileList, false);
  2842. Result = true;
  2843. }
  2844. else
  2845. {
  2846. DebugFail();
  2847. }
  2848. return Result;
  2849. }
  2850. //---------------------------------------------------------------------------
  2851. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2852. {
  2853. if (Side == osCurrent)
  2854. {
  2855. Side = FCurrentSide;
  2856. }
  2857. return Side;
  2858. }
  2859. //---------------------------------------------------------------------------
  2860. TOperationSide TCustomScpExplorerForm::GetOtherSide(TOperationSide Side)
  2861. {
  2862. TOperationSide Result;
  2863. switch (GetSide(Side))
  2864. {
  2865. case osLocal:
  2866. Result = osOther;
  2867. break;
  2868. case osOther:
  2869. Result = osLocal;
  2870. break;
  2871. default:
  2872. DebugFail();
  2873. Abort();
  2874. }
  2875. return Result;
  2876. }
  2877. //---------------------------------------------------------------------------
  2878. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2879. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2880. {
  2881. Side = GetSide(Side);
  2882. bool FullPath = IsSideLocalBrowser(Side);
  2883. TCustomDirView * ADirView = DirView(Side);
  2884. std::unique_ptr<TStringList> FileList(new TStringList());
  2885. ADirView->CreateFileList(OnFocused, FullPath, FileList.get());
  2886. bool ReloadProperties =
  2887. !IsSideLocalBrowser(Side) && (Operation == foSetProperties) &&
  2888. DebugAlwaysTrue(HasActiveTerminal()) && Terminal->IsCapable[fcLoadingAdditionalProperties];
  2889. bool Result = ExecuteFileOperation(Operation, Side, FileList.get(), NoConfirmation, Param);
  2890. if (Result && ReloadProperties)
  2891. {
  2892. std::unique_ptr<TStringList> FileList2(new TStringList());
  2893. FileList->CaseSensitive = true;
  2894. FileList->Sort();
  2895. for (int Index = 0; Index < ADirView->Items->Count; Index++)
  2896. {
  2897. TListItem * Item = ADirView->Items->Item[Index];
  2898. UnicodeString FileName = ADirView->ItemFileName(Item);
  2899. int Index2;
  2900. if (FileList->Find(FileName, Index2))
  2901. {
  2902. FileList2->AddObject(FileName, ADirView->ItemData(Item));
  2903. }
  2904. }
  2905. LoadFilesProperties(FileList2.get());
  2906. }
  2907. return Result;
  2908. }
  2909. //---------------------------------------------------------------------------
  2910. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2911. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2912. bool NoConfirmation, void * Param)
  2913. {
  2914. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2915. {
  2916. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2917. {
  2918. DebugAssert(!IsLocalBrowserMode());
  2919. if (GetSide(Side) == osLocal)
  2920. {
  2921. Configuration->Usage->Inc(L"UploadsCommand");
  2922. }
  2923. else
  2924. {
  2925. Configuration->Usage->Inc(L"DownloadsCommand");
  2926. }
  2927. }
  2928. }
  2929. }
  2930. //---------------------------------------------------------------------------
  2931. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2932. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2933. {
  2934. TTransferOperationParam Param;
  2935. if ((WinConfiguration->Interface != ifCommander) ||
  2936. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2937. {
  2938. Flags &= ~cocShortCutHint;
  2939. }
  2940. TCustomDirView * DView = DirView(Side);
  2941. Param.Options =
  2942. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2943. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2944. if (FLAGSET(Flags, cocQueue))
  2945. {
  2946. Param.Queue = asOn;
  2947. }
  2948. else if (FLAGSET(Flags, cocNonQueue))
  2949. {
  2950. Param.Queue = asOff;
  2951. }
  2952. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2953. }
  2954. //---------------------------------------------------------------------------
  2955. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2956. {
  2957. int Count = ErrorList->Count;
  2958. try
  2959. {
  2960. if (ErrorList->Count)
  2961. {
  2962. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2963. if (MessageDialog(Message, qtError,
  2964. qaOK | qaCancel, HELP_NONE) == qaOK)
  2965. {
  2966. unsigned int Answer;
  2967. int Index = 0;
  2968. do
  2969. {
  2970. DebugAssert(Index >= 0 && Index < Count);
  2971. TQueryButtonAlias Aliases[2];
  2972. Aliases[0].Button = qaYes;
  2973. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2974. Aliases[1].Button = qaNo;
  2975. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2976. TMessageParams Params;
  2977. Params.Aliases = Aliases;
  2978. Params.AliasesCount = LENOF(Aliases);
  2979. int No = Index + 1;
  2980. UnicodeString Message = ErrorList->Strings[Index];
  2981. UnicodeString AMainInstructions;
  2982. UnicodeString Details;
  2983. if (ExtractMainInstructions(Message, AMainInstructions))
  2984. {
  2985. Details = Message;
  2986. Message = AMainInstructions;
  2987. }
  2988. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  2989. Answer = MoreMessageDialog(
  2990. Message,
  2991. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2992. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  2993. qaOK, HELP_NONE, &Params);
  2994. if (Answer == qaNo)
  2995. {
  2996. Index++;
  2997. }
  2998. if (Answer == qaYes)
  2999. {
  3000. Index--;
  3001. }
  3002. }
  3003. while (Answer != qaOK);
  3004. }
  3005. }
  3006. }
  3007. __finally
  3008. {
  3009. TStrings * List = ErrorList;
  3010. ErrorList = NULL;
  3011. for (int i = 0; i < Count; i++)
  3012. {
  3013. delete List->Objects[i];
  3014. }
  3015. delete List;
  3016. }
  3017. }
  3018. //---------------------------------------------------------------------------
  3019. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  3020. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  3021. {
  3022. // needed for checking filemasks, as there's no directory object
  3023. // associated with the file object
  3024. File->FullFileName = FullFileName;
  3025. TFileMasks::TParams MaskParams;
  3026. MaskParams.Size = File->Size;
  3027. MaskParams.Modification = File->Modification;
  3028. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  3029. }
  3030. //---------------------------------------------------------------------------
  3031. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  3032. {
  3033. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3034. Side = GetSide(Side);
  3035. TCustomDirView * DView = DirView(Side);
  3036. TListItem * FocusedItem = DView->ItemFocused;
  3037. UnicodeString Name;
  3038. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  3039. {
  3040. Name = DView->ItemFileName(FocusedItem);
  3041. }
  3042. else
  3043. {
  3044. Name = LoadStr(NEW_FILE);
  3045. }
  3046. UnicodeString Names = Name;
  3047. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  3048. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  3049. HELP_EDIT_NEW, History.get(), true, NULL, true, 444))
  3050. {
  3051. while (!Names.IsEmpty())
  3052. {
  3053. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  3054. CustomWinConfiguration->History[L"EditFile"] = History.get();
  3055. UnicodeString TargetFileName;
  3056. UnicodeString LocalFileName;
  3057. UnicodeString RootTempDir;
  3058. UnicodeString TempDir;
  3059. UnicodeString RemoteDirectory;
  3060. bool ExistingFile = false;
  3061. if (!IsSideLocalBrowser(Side))
  3062. {
  3063. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  3064. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(Name));
  3065. if ((File.get() != NULL) &&
  3066. !File->IsDirectory)
  3067. {
  3068. ExecuteRemoteFile(Name, File.get(), efDefaultEditor);
  3069. ExistingFile = true;
  3070. }
  3071. File.reset(NULL);
  3072. if (!ExistingFile)
  3073. {
  3074. RemoteDirectory = UnixExtractFilePath(Name);
  3075. TemporaryDirectoryForRemoteFiles(
  3076. RemoteDirectory, GUIConfiguration->CurrentCopyParam, false, TempDir, RootTempDir);
  3077. TargetFileName = UnixExtractFileName(Name);
  3078. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3079. LocalFileName = TempDir +
  3080. // We probably do not want to trim the VMS version here
  3081. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  3082. }
  3083. }
  3084. else
  3085. {
  3086. if (ExtractFilePath(Name).IsEmpty())
  3087. {
  3088. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  3089. }
  3090. else
  3091. {
  3092. LocalFileName = ExpandFileName(Name);
  3093. }
  3094. TargetFileName = ExtractFileName(Name);
  3095. }
  3096. if (!ExistingFile)
  3097. {
  3098. bool NewFile = !FileExists(ApiPath(LocalFileName));
  3099. if (NewFile)
  3100. {
  3101. int File = FileCreate(ApiPath(LocalFileName));
  3102. if (File < 0)
  3103. {
  3104. if (!RootTempDir.IsEmpty())
  3105. {
  3106. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3107. }
  3108. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  3109. }
  3110. else
  3111. {
  3112. FileClose(File);
  3113. }
  3114. }
  3115. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  3116. const TEditorData * ExternalEditor = NULL;
  3117. TFileMasks::TParams MaskParams; // size not known
  3118. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  3119. false, MaskParams);
  3120. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  3121. ExternalEditor, RootTempDir, RemoteDirectory, NewFile, TDateTime());
  3122. }
  3123. }
  3124. }
  3125. }
  3126. //---------------------------------------------------------------------------
  3127. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  3128. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  3129. {
  3130. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3131. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3132. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3133. return
  3134. ((ExecuteFileBy == efInternalEditor)) ||
  3135. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  3136. }
  3137. //---------------------------------------------------------------------------
  3138. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3139. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3140. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3141. UnicodeString RemoteDirectory, bool NewFile, const TDateTime & SourceTimestamp)
  3142. {
  3143. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3144. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3145. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3146. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3147. Side = GetSide(Side);
  3148. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3149. if (!IsSideLocalBrowser(Side))
  3150. {
  3151. Data->Terminal = Terminal;
  3152. Data->SessionData = CloneCurrentSessionData();
  3153. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3154. Data->RemoteDirectory = RemoteDirectory;
  3155. Data->SessionName = Terminal->SessionData->SessionName;
  3156. Data->LocalRootDirectory = LocalRootDirectory;
  3157. Data->OriginalFileName = OriginalFileName;
  3158. Data->Command = L""; // will be changed later for external editor
  3159. // Empty SourceTimestamp indicates that checking was disabled when the file was opened
  3160. if (WinConfiguration->EditorCheckNotModified)
  3161. {
  3162. Data->SourceTimestamp = SourceTimestamp;
  3163. }
  3164. }
  3165. if (ExecuteFileBy == efInternalEditor)
  3166. {
  3167. if (!IsSideLocalBrowser(Side))
  3168. {
  3169. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3170. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3171. TForm * Editor;
  3172. try
  3173. {
  3174. Editor =
  3175. ShowEditorForm(
  3176. FileName, this,
  3177. FEditorManager->FileChanged, FEditorManager->FileReload, FEditorManager->FileClosed,
  3178. SaveAllInternalEditors, AnyInternalEditorModified,
  3179. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3180. }
  3181. catch(...)
  3182. {
  3183. if (!LocalRootDirectory.IsEmpty())
  3184. {
  3185. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory));
  3186. }
  3187. throw;
  3188. }
  3189. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3190. AppLogFmt(L"Opened internal editor with \"%s\"", (FileName));
  3191. }
  3192. else
  3193. {
  3194. DebugAssert(!StandaloneOperation);
  3195. TForm * Editor =
  3196. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3197. SaveAllInternalEditors, AnyInternalEditorModified,
  3198. L"", false, SessionColor, -1, NewFile);
  3199. FLocalEditors->Add(Editor);
  3200. }
  3201. }
  3202. else
  3203. {
  3204. HANDLE Process;
  3205. if (ExecuteFileBy == efExternalEditor)
  3206. {
  3207. UnicodeString Program, Params, Dir;
  3208. Data->Command = ExternalEditor->ExternalEditor;
  3209. ReformatFileNameCommand(Data->Command);
  3210. SplitCommand(Data->Command, Program, Params, Dir);
  3211. Params = ExpandFileNameCommand(Params, FileName);
  3212. Program = ExpandEnvironmentVariables(Program);
  3213. if (!ExecuteShell(Program, Params, Process))
  3214. {
  3215. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3216. }
  3217. }
  3218. else
  3219. {
  3220. DebugAssert(!IsSideLocalBrowser(Side));
  3221. if (!ExecuteShell(FileName, L"", Process))
  3222. {
  3223. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3224. }
  3225. }
  3226. if (IsSideLocalBrowser(Side) ||
  3227. ((ExecuteFileBy == efShell) &&
  3228. !WinConfiguration->Editor.SDIShellEditor) ||
  3229. ((ExecuteFileBy == efExternalEditor) &&
  3230. !ExternalEditor->SDIExternalEditor))
  3231. {
  3232. // no need for handle
  3233. if (Process != NULL)
  3234. {
  3235. DebugCheck(CloseHandle(Process));
  3236. }
  3237. Process = INVALID_HANDLE_VALUE;
  3238. }
  3239. else
  3240. {
  3241. if (Process == NULL)
  3242. {
  3243. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3244. }
  3245. }
  3246. if (!IsSideLocalBrowser(Side))
  3247. {
  3248. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3249. AppLogFmt(L"Opened external editor with remote file \"%s\".", (FileName));
  3250. }
  3251. }
  3252. }
  3253. //---------------------------------------------------------------------------
  3254. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3255. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3256. void * /*Arg*/)
  3257. {
  3258. if (Token != NULL)
  3259. {
  3260. EditorFormFileSave(static_cast<TForm *>(Token));
  3261. }
  3262. }
  3263. //---------------------------------------------------------------------------
  3264. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3265. {
  3266. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3267. {
  3268. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3269. }
  3270. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3271. }
  3272. //---------------------------------------------------------------------------
  3273. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3274. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3275. void * Arg)
  3276. {
  3277. if ((Token != NULL) &&
  3278. IsEditorFormModified(static_cast<TForm *>(Token)))
  3279. {
  3280. *static_cast<bool *>(Arg) = true;
  3281. }
  3282. }
  3283. //---------------------------------------------------------------------------
  3284. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3285. TObject * /*Sender*/, bool & Modified)
  3286. {
  3287. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3288. {
  3289. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3290. {
  3291. Modified = true;
  3292. }
  3293. }
  3294. if (!Modified)
  3295. {
  3296. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3297. }
  3298. }
  3299. //---------------------------------------------------------------------------
  3300. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3301. {
  3302. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3303. }
  3304. //---------------------------------------------------------------------------
  3305. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3306. const UnicodeString & RemoteDirectory, const TCopyParamType & CopyParam, bool Simple,
  3307. UnicodeString & Result, UnicodeString & RootDirectory)
  3308. {
  3309. if (!WinConfiguration->TemporaryDirectoryDeterministic || Simple)
  3310. {
  3311. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3312. Result = RootDirectory;
  3313. }
  3314. else
  3315. {
  3316. RootDirectory = L"";
  3317. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3318. Result = IncludeTrailingBackslash(Result);
  3319. }
  3320. if (WinConfiguration->TemporaryDirectoryAppendSession && !Simple)
  3321. {
  3322. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3323. }
  3324. if (WinConfiguration->TemporaryDirectoryAppendPath && !Simple)
  3325. {
  3326. UnicodeString ARemoteDirectory = RemoteDirectory;
  3327. if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory[1] == L'/'))
  3328. {
  3329. ARemoteDirectory.Delete(1, 1);
  3330. }
  3331. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(ARemoteDirectory)));
  3332. }
  3333. if (!ForceDirectories(ApiPath(Result)))
  3334. {
  3335. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3336. }
  3337. }
  3338. //---------------------------------------------------------------------------
  3339. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3340. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3341. bool GetTargetNames, bool AutoOperation, bool SimpleTempDir)
  3342. {
  3343. DebugAssert(!IsLocalBrowserMode());
  3344. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3345. if (ForceText)
  3346. {
  3347. CopyParam.TransferMode = tmAscii;
  3348. }
  3349. TemporaryFileCopyParam(CopyParam);
  3350. if (TempDir.IsEmpty())
  3351. {
  3352. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, SimpleTempDir, TempDir, RootTempDir);
  3353. }
  3354. DebugAssert(!FAutoOperation);
  3355. FAutoOperation = AutoOperation;
  3356. FMoveToQueue = false;
  3357. Terminal->ExceptionOnFail = true;
  3358. try
  3359. {
  3360. try
  3361. {
  3362. // turn off confirmations, as for MDI editors we may possibly download
  3363. // the same file over
  3364. Terminal->CopyToLocal(
  3365. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3366. if (GetTargetNames)
  3367. {
  3368. for (int i = 0; i < FileList->Count; i++)
  3369. {
  3370. FileList->Strings[i] =
  3371. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3372. }
  3373. }
  3374. }
  3375. catch(...)
  3376. {
  3377. if (!RootTempDir.IsEmpty())
  3378. {
  3379. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3380. }
  3381. throw;
  3382. }
  3383. }
  3384. __finally
  3385. {
  3386. FAutoOperation = false;
  3387. Terminal->ExceptionOnFail = false;
  3388. }
  3389. }
  3390. //---------------------------------------------------------------------------
  3391. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3392. {
  3393. // Do not waste time checking for default editor list the next time,
  3394. // or testing if default editor is not notepad.
  3395. bool TryNextTime = false;
  3396. UnicodeString UsageState;
  3397. if (!WinConfiguration->EditorList->IsDefaultList())
  3398. {
  3399. UsageState = "H";
  3400. }
  3401. else
  3402. {
  3403. UnicodeString Executable;
  3404. UnicodeString ExecutableDescription;
  3405. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3406. {
  3407. UnicodeString Message =
  3408. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3409. unsigned int Answer =
  3410. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3411. if (Answer != qaOK)
  3412. {
  3413. UsageState = "R";
  3414. }
  3415. else
  3416. {
  3417. UsageState = "A";
  3418. TEditorData EditorData;
  3419. EditorData.Editor = edExternal;
  3420. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3421. EditorData.ExternalEditorOptionsAutodetect();
  3422. TEditorList EditorList;
  3423. EditorList = *WinConfiguration->EditorList;
  3424. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3425. WinConfiguration->EditorList = &EditorList;
  3426. }
  3427. }
  3428. }
  3429. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3430. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3431. }
  3432. //---------------------------------------------------------------------------
  3433. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3434. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3435. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3436. {
  3437. if (ExecuteFileBy == efDefaultEditor)
  3438. {
  3439. if (!WinConfiguration->OfferedEditorAutoConfig)
  3440. {
  3441. EditorAutoConfig();
  3442. }
  3443. const TEditorPreferences * Editor =
  3444. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3445. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3446. {
  3447. ExecuteFileBy = efInternalEditor;
  3448. ExternalEditor = NULL;
  3449. }
  3450. else if (Editor->Data->Editor == edOpen)
  3451. {
  3452. ExecuteFileBy = efShell;
  3453. ExternalEditor = NULL;
  3454. }
  3455. else
  3456. {
  3457. ExecuteFileBy = efExternalEditor;
  3458. ExternalEditor = Editor->Data;
  3459. }
  3460. }
  3461. }
  3462. //---------------------------------------------------------------------------
  3463. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3464. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3465. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3466. {
  3467. UnicodeString OriginalFileName;
  3468. UnicodeString LocalRootDirectory;
  3469. UnicodeString RemoteDirectory;
  3470. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3471. IsSideLocalBrowser(Side), MaskParams);
  3472. UnicodeString Counter;
  3473. UnicodeString LocalFileName;
  3474. bool Handled = false;
  3475. if (!IsSideLocalBrowser(Side))
  3476. {
  3477. // We need to trim VMS version here, so that we use name without version
  3478. // when uploading back to create a new version of the file
  3479. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3480. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3481. TObject * Token = NULL;
  3482. UnicodeString LocalDirectory;
  3483. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3484. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3485. LocalDirectory))
  3486. {
  3487. if (Token != NULL)
  3488. {
  3489. TForm * Form = dynamic_cast<TForm *>(Token);
  3490. if (Form->WindowState == wsMinimized)
  3491. {
  3492. ShowWindow(Form->Handle, SW_RESTORE);
  3493. }
  3494. else
  3495. {
  3496. Form->SetFocus();
  3497. }
  3498. Handled = true;
  3499. }
  3500. else
  3501. {
  3502. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3503. }
  3504. }
  3505. if (!Handled)
  3506. {
  3507. TStringList * FileList1 = new TStringList();
  3508. try
  3509. {
  3510. FileList1->AddObject(FullFileName, Object);
  3511. TemporarilyDownloadFiles(FileList1,
  3512. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3513. LocalRootDirectory, LocalDirectory, true, true, false);
  3514. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3515. }
  3516. __finally
  3517. {
  3518. delete FileList1;
  3519. }
  3520. switch (ExecuteFileBy)
  3521. {
  3522. case efShell:
  3523. Counter = "RemoteFilesExecuted";
  3524. break;
  3525. case efInternalEditor:
  3526. Counter = "RemoteFilesOpenedInInternalEditor";
  3527. break;
  3528. case efExternalEditor:
  3529. Counter = "RemoteFilesOpenedInExternalEditor";
  3530. break;
  3531. default:
  3532. DebugFail();
  3533. }
  3534. }
  3535. }
  3536. else
  3537. {
  3538. LocalFileName = FullFileName;
  3539. OriginalFileName = ExtractFileName(FullFileName);
  3540. switch (ExecuteFileBy)
  3541. {
  3542. case efShell:
  3543. Counter = "LocalFilesExecuted";
  3544. break;
  3545. case efInternalEditor:
  3546. Counter = "LocalFilesOpenedInInternalEditor";
  3547. break;
  3548. case efExternalEditor:
  3549. Counter = "LocalFilesOpenedInExternalEditor";
  3550. break;
  3551. default:
  3552. DebugFail();
  3553. }
  3554. }
  3555. if (!Handled)
  3556. {
  3557. Configuration->Usage->Inc(Counter);
  3558. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3559. ExternalEditor, LocalRootDirectory, RemoteDirectory, false, MaskParams.Modification);
  3560. }
  3561. }
  3562. //---------------------------------------------------------------------------
  3563. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3564. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3565. bool AllSelected, bool OnFocused)
  3566. {
  3567. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3568. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3569. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3570. Side = GetSide(Side);
  3571. TCustomDirView * DView = DirView(Side);
  3572. TStrings * FileList =
  3573. AllSelected ?
  3574. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3575. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3576. try
  3577. {
  3578. DebugAssert(AllSelected || (FileList->Count == 1));
  3579. for (int i = 0; i < FileList->Count; i++)
  3580. {
  3581. UnicodeString ListFileName = FileList->Strings[i];
  3582. UnicodeString FileNameOnly =
  3583. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3584. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3585. if (!DView->ItemIsDirectory(Item))
  3586. {
  3587. UnicodeString FullFileName;
  3588. if (!IsSideLocalBrowser(Side))
  3589. {
  3590. FullFileName = DirView(Side)->Path + ListFileName;
  3591. }
  3592. else
  3593. {
  3594. FullFileName = ListFileName;
  3595. }
  3596. TObject * Object = FileList->Objects[i];
  3597. TFileMasks::TParams MaskParams;
  3598. MaskParams.Size = DView->ItemFileSize(Item);
  3599. TDateTimePrecision Precision;
  3600. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3601. std::unique_ptr<TRemoteFile> File;
  3602. if (!IsSideLocalBrowser(Side))
  3603. {
  3604. File.reset(Terminal->TryReadFile(FullFileName));
  3605. if (File.get() != NULL)
  3606. {
  3607. File->FullFileName = FullFileName;
  3608. Object = File.get();
  3609. MaskParams.Size = File->Size;
  3610. MaskParams.Modification = File->Modification;
  3611. }
  3612. }
  3613. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName, Object, MaskParams);
  3614. }
  3615. }
  3616. }
  3617. __finally
  3618. {
  3619. delete FileList;
  3620. }
  3621. }
  3622. //---------------------------------------------------------------------------
  3623. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3624. {
  3625. CopyParam.FileNameCase = ncNoChange;
  3626. CopyParam.PreserveRights = false;
  3627. CopyParam.PreserveReadOnly = false;
  3628. CopyParam.ReplaceInvalidChars = true;
  3629. CopyParam.IncludeFileMask = TFileMasks();
  3630. CopyParam.NewerOnly = false;
  3631. CopyParam.FileMask = L"";
  3632. }
  3633. //---------------------------------------------------------------------------
  3634. bool TCustomScpExplorerForm::EditorCheckNotModified(const TEditedFileData * Data)
  3635. {
  3636. return WinConfiguration->EditorCheckNotModified && (Data->SourceTimestamp != TDateTime());
  3637. }
  3638. //---------------------------------------------------------------------------
  3639. class TEditorUploadQueueItem : public TUploadQueueItem
  3640. {
  3641. public:
  3642. __fastcall TEditorUploadQueueItem(
  3643. TTerminal * Terminal, TStrings * FilesToCopy, const UnicodeString & TargetDir,
  3644. const TCopyParamType * CopyParam, int Params) :
  3645. TUploadQueueItem(Terminal, FilesToCopy, TargetDir, CopyParam, Params, false)
  3646. {
  3647. }
  3648. protected:
  3649. virtual void __fastcall DoTransferExecute(TTerminal * Terminal, TParallelOperation * ParallelOperation)
  3650. {
  3651. TUploadQueueItem::DoTransferExecute(Terminal, ParallelOperation);
  3652. TTerminalManager::Instance()->ScpExplorer->EditedFileUploaded(Terminal, CompleteEvent);
  3653. }
  3654. };
  3655. //---------------------------------------------------------------------------
  3656. void TCustomScpExplorerForm::EditedFileUploaded(TTerminal * ATerminal, HANDLE UploadCompleteEvent)
  3657. {
  3658. if (WinConfiguration->EditorCheckNotModified) // optimization
  3659. {
  3660. UnicodeString RemoteFilePath;
  3661. {
  3662. TGuard Guard(FEditorManager->Section);
  3663. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3664. if (DebugAlwaysTrue(Data != NULL) &&
  3665. EditorCheckNotModified(Data))
  3666. {
  3667. RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3668. }
  3669. }
  3670. if (!RemoteFilePath.IsEmpty())
  3671. {
  3672. std::unique_ptr<TRemoteFile> File(ATerminal->TryReadFile(RemoteFilePath));
  3673. if (File.get() != NULL)
  3674. {
  3675. TGuard Guard(FEditorManager->Section);
  3676. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3677. if (DebugAlwaysTrue(Data != NULL))
  3678. {
  3679. Data->SourceTimestamp = File->Modification;
  3680. AppLogFmt(L"Uploaded edited remote file timestamp: %s", (StandardTimestamp(Data->SourceTimestamp)));
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. //---------------------------------------------------------------------------
  3687. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(
  3688. const UnicodeString & FileName, TEditedFileData * Data, HANDLE UploadCompleteEvent, bool & Retry)
  3689. {
  3690. TTerminalManager * Manager = TTerminalManager::Instance();
  3691. if ((Manager->ActiveTerminal == Data->Terminal) &&
  3692. Manager->ScheduleTerminalReconnnect(Data->Terminal))
  3693. {
  3694. AppLog(L"Scheduled session reconnect, will retry the upload later");
  3695. Retry = true;
  3696. }
  3697. else if (!IsActiveTerminal(Data->Terminal))
  3698. {
  3699. if (!NonVisualDataModule->Busy)
  3700. {
  3701. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3702. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3703. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3704. if (Data->Terminal == NULL)
  3705. {
  3706. TManagedTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3707. if (SameSiteTerminal != NULL)
  3708. {
  3709. UnicodeString Message =
  3710. FMTLOAD(EDIT_SESSION_REATTACH,
  3711. (FileNameOnly, Data->SessionName, FileNameOnly));
  3712. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3713. {
  3714. Data->Terminal = SameSiteTerminal;
  3715. Data->SessionName = SameSiteTerminal->SessionData->SessionName;
  3716. // We might also overwrite session data
  3717. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3718. }
  3719. else
  3720. {
  3721. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3722. Abort();
  3723. }
  3724. }
  3725. }
  3726. // Foreground session should reconnect itself (except for those disconnected explicitly by the user)
  3727. else if (DebugAlwaysTrue(Terminal->Disconnected || (Terminal != Data->Terminal)))
  3728. {
  3729. UnicodeString Message =
  3730. MainInstructions(
  3731. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3732. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3733. {
  3734. if (Terminal->Disconnected)
  3735. {
  3736. Manager->ActiveSession = Terminal;
  3737. ReconnectSession();
  3738. // Was it reconnected? (if not, Data->Terminal should be nulled now)
  3739. if (!IsActiveTerminal(Data->Terminal) || (Terminal != Data->Terminal))
  3740. {
  3741. Abort();
  3742. }
  3743. }
  3744. else
  3745. {
  3746. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3747. }
  3748. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3749. }
  3750. else
  3751. {
  3752. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3753. Abort();
  3754. }
  3755. }
  3756. }
  3757. if (!IsActiveTerminal(Data->Terminal))
  3758. {
  3759. Configuration->Usage->Inc(L"EditInactiveSession");
  3760. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3761. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3762. (ExtractFileName(FileName), Data->SessionName)));
  3763. }
  3764. }
  3765. if (!Retry && EditorCheckNotModified(Data))
  3766. {
  3767. if (NonVisualDataModule->Busy)
  3768. {
  3769. Retry = true;
  3770. }
  3771. else
  3772. {
  3773. UnicodeString RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3774. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(RemoteFilePath));
  3775. if (File.get() != NULL)
  3776. {
  3777. AppLogFmt(L"Edited remote file timestamp: %s, Original timestamp: %s", (StandardTimestamp(File->Modification), StandardTimestamp(Data->SourceTimestamp)));
  3778. if (File->Modification != Data->SourceTimestamp)
  3779. {
  3780. UnicodeString Message = MainInstructions(LoadStr(EDIT_CHANGED_EXTERNALLY));
  3781. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) != qaOK)
  3782. {
  3783. Abort();
  3784. }
  3785. }
  3786. }
  3787. }
  3788. }
  3789. if (!Retry)
  3790. {
  3791. TStrings * FileList = new TStringList();
  3792. try
  3793. {
  3794. FileList->Add(FileName);
  3795. // Consider using the same settings (preset) as when the file was downloaded.
  3796. // More over this does not reflect the actual session that will do the upload.
  3797. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3798. TemporaryFileCopyParam(CopyParam);
  3799. if (Data->ForceText)
  3800. {
  3801. CopyParam.TransferMode = tmAscii;
  3802. }
  3803. // so i do not need to worry if masking algorithm works in all cases
  3804. // ("" means "copy file name", no masking is actually done)
  3805. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3806. {
  3807. CopyParam.FileMask = L"";
  3808. }
  3809. else
  3810. {
  3811. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3812. }
  3813. int Params = cpNoConfirmation | cpTemporary;
  3814. if (Data->Terminal->IsCapable[fcBackgroundTransfers])
  3815. {
  3816. TTerminalQueue * AQueue = Manager->FindQueueForTerminal(Data->Terminal);
  3817. TQueueItem * QueueItem =
  3818. new TEditorUploadQueueItem(Data->Terminal, FileList, Data->RemoteDirectory, &CopyParam, Params);
  3819. QueueItem->CompleteEvent = UploadCompleteEvent;
  3820. AddQueueItem(AQueue, QueueItem, Data->Terminal);
  3821. }
  3822. else
  3823. {
  3824. if (NonVisualDataModule->Busy)
  3825. {
  3826. Retry = true;
  3827. }
  3828. else
  3829. {
  3830. FMoveToQueue = false;
  3831. Data->Terminal->CopyToRemote(FileList, Data->RemoteDirectory, &CopyParam, Params, NULL);
  3832. SetEvent(UploadCompleteEvent);
  3833. }
  3834. }
  3835. }
  3836. __finally
  3837. {
  3838. delete FileList;
  3839. }
  3840. }
  3841. }
  3842. //---------------------------------------------------------------------------
  3843. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3844. const UnicodeString & FileName, TEditedFileData * Data)
  3845. {
  3846. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3847. DebugAssert(!NonVisualDataModule->Busy);
  3848. if (!IsActiveTerminal(Data->Terminal))
  3849. {
  3850. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3851. (ExtractFileName(FileName), Data->SessionName)));
  3852. }
  3853. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3854. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3855. NonVisualDataModule->StartBusy();
  3856. try
  3857. {
  3858. std::unique_ptr<TRemoteFile> File;
  3859. UnicodeString RemoteFileName =
  3860. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3861. Terminal->ExceptionOnFail = true;
  3862. try
  3863. {
  3864. File.reset(Terminal->ReadFile(RemoteFileName));
  3865. if (!File->HaveFullFileName)
  3866. {
  3867. File->FullFileName = RemoteFileName;
  3868. }
  3869. }
  3870. __finally
  3871. {
  3872. Terminal->ExceptionOnFail = false;
  3873. }
  3874. std::unique_ptr<TStrings> FileList(new TStringList());
  3875. FileList->AddObject(RemoteFileName, File.get());
  3876. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3877. UnicodeString TempDir = ExtractFilePath(FileName);
  3878. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir, TempDir, true, true, false);
  3879. if (EditorCheckNotModified(Data))
  3880. {
  3881. Data->SourceTimestamp = File->Modification;
  3882. }
  3883. // sanity check, the target file name should be still the same
  3884. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3885. }
  3886. __finally
  3887. {
  3888. NonVisualDataModule->EndBusy();
  3889. // it actually may not exist anymore...
  3890. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3891. }
  3892. }
  3893. //---------------------------------------------------------------------------
  3894. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3895. const TEditedFileData * Data, bool & KeepOpen)
  3896. {
  3897. // Command is set for external editors only (not for "shell" open).
  3898. if (!Data->Command.IsEmpty())
  3899. {
  3900. bool AnyFound = false;
  3901. bool AnyMDI = false;
  3902. bool AnyNonMDI = false;
  3903. bool AnyDetect = false;
  3904. TEditorList * EditorList = new TEditorList();
  3905. try
  3906. {
  3907. *EditorList = *WinConfiguration->EditorList;
  3908. for (int i = 0; i < EditorList->Count; i++)
  3909. {
  3910. const TEditorPreferences * Editor = EditorList->Editors[i];
  3911. if ((Editor->Data->Editor == edExternal) &&
  3912. (Editor->Data->ExternalEditor == Data->Command))
  3913. {
  3914. AnyFound = true;
  3915. if (Editor->Data->SDIExternalEditor)
  3916. {
  3917. AnyNonMDI = true;
  3918. if (Editor->Data->DetectMDIExternalEditor)
  3919. {
  3920. AnyDetect = true;
  3921. }
  3922. }
  3923. else
  3924. {
  3925. AnyMDI = true;
  3926. }
  3927. }
  3928. }
  3929. bool EnableMDI = false;
  3930. bool DisableDetect = false;
  3931. if (AnyMDI)
  3932. {
  3933. KeepOpen = true;
  3934. if (AnyNonMDI)
  3935. {
  3936. // there is at least one instance of the editor with MDI support enabled,
  3937. // and one with disabled, enable it for all instances
  3938. EnableMDI = true;
  3939. }
  3940. }
  3941. else if (AnyFound && !AnyDetect)
  3942. {
  3943. // at least once instance found but all have MDI autodetection disabled
  3944. // => close the file (default action)
  3945. }
  3946. else
  3947. {
  3948. // no instance of the editor has MDI support enabled
  3949. TMessageParams Params;
  3950. if (AnyFound)
  3951. {
  3952. // there is at least one instance of the editor
  3953. Params.Params |= mpNeverAskAgainCheck;
  3954. }
  3955. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3956. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3957. switch (Answer)
  3958. {
  3959. case qaNeverAskAgain:
  3960. DisableDetect = true;
  3961. break;
  3962. case qaNo:
  3963. EnableMDI = true;
  3964. KeepOpen = true;
  3965. break;
  3966. }
  3967. }
  3968. if (AnyFound && (EnableMDI || DisableDetect))
  3969. {
  3970. bool Changed = false;
  3971. for (int i = 0; i < EditorList->Count; i++)
  3972. {
  3973. const TEditorPreferences * Editor = EditorList->Editors[i];
  3974. if ((Editor->Data->Editor == edExternal) &&
  3975. (Editor->Data->ExternalEditor == Data->Command) &&
  3976. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3977. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3978. {
  3979. Changed = true;
  3980. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3981. if (EnableMDI)
  3982. {
  3983. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3984. }
  3985. if (DisableDetect)
  3986. {
  3987. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3988. }
  3989. EditorList->Change(i, UpdatedEditor);
  3990. }
  3991. }
  3992. if (Changed)
  3993. {
  3994. WinConfiguration->EditorList = EditorList;
  3995. }
  3996. }
  3997. }
  3998. __finally
  3999. {
  4000. delete EditorList;
  4001. }
  4002. }
  4003. else
  4004. {
  4005. // "open" case
  4006. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  4007. qaOK, HELP_APP_EARLY_CLOSED);
  4008. }
  4009. }
  4010. //---------------------------------------------------------------------------
  4011. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  4012. {
  4013. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  4014. }
  4015. //---------------------------------------------------------------------------
  4016. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  4017. {
  4018. SideEnter(osRemote);
  4019. }
  4020. //---------------------------------------------------------------------------
  4021. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  4022. {
  4023. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  4024. SideEnter(osRemote);
  4025. }
  4026. //---------------------------------------------------------------------------
  4027. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  4028. {
  4029. FCurrentSide = Side;
  4030. if (Visible)
  4031. {
  4032. UpdateControls();
  4033. }
  4034. }
  4035. //---------------------------------------------------------------------------
  4036. void __fastcall TCustomScpExplorerForm::FileDeleted(
  4037. TOperationSide Side, const UnicodeString & FileName, bool Success, bool NotCancelled)
  4038. {
  4039. VisualiseOperationFinished(Side, FileName, Success && NotCancelled);
  4040. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  4041. {
  4042. FDeletedFiles->Add(FileName);
  4043. }
  4044. }
  4045. //---------------------------------------------------------------------------
  4046. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  4047. TStrings * FileList, bool Alternative)
  4048. {
  4049. TCustomDirView * DView = DirView(Side);
  4050. DView->SaveSelection();
  4051. DView->SaveSelectedNames();
  4052. DebugAssert(!FAlternativeDelete);
  4053. FAlternativeDelete = Alternative;
  4054. try
  4055. {
  4056. int Params = FLAGMASK(Alternative, dfAlternative);
  4057. bool Remote = !IsSideLocalBrowser(Side);
  4058. std::unique_ptr<TStringList> DeletedFiles;
  4059. std::unique_ptr<TStrings> PermanentFileList;
  4060. bool AllowMoveToQueue = (Terminal != NULL);
  4061. if (AllowMoveToQueue)
  4062. {
  4063. DeletedFiles.reset(new TStringList());
  4064. DeletedFiles->CaseSensitive = Remote;
  4065. }
  4066. try
  4067. {
  4068. DebugAssert(FDeletedFiles == NULL);
  4069. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles, DeletedFiles.get());
  4070. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  4071. if (AllowMoveToQueue)
  4072. {
  4073. FOnFileOperationFinished = FileDeleted;
  4074. }
  4075. FMoveToQueue = false;
  4076. if (Remote)
  4077. {
  4078. DebugAssert(AllowMoveToQueue);
  4079. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  4080. PermanentFileList.reset(TRemoteFileList::CloneStrings(FileList));
  4081. DebugAssert(Terminal != NULL);
  4082. Terminal->DeleteFiles(FileList, Params);
  4083. }
  4084. else
  4085. {
  4086. if (AllowMoveToQueue) // optimization)
  4087. {
  4088. PermanentFileList.reset(CloneStrings(FileList));
  4089. }
  4090. if (IsLocalBrowserMode())
  4091. {
  4092. Configuration->Usage->Inc(L"LocalLocalDeletes");
  4093. }
  4094. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  4095. try
  4096. {
  4097. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, Params);
  4098. }
  4099. __finally
  4100. {
  4101. ReloadLocalDirectory();
  4102. }
  4103. }
  4104. // Probably not needed for deleting, just for consistency with transfer code
  4105. if (FMoveToQueue)
  4106. {
  4107. Abort();
  4108. }
  4109. }
  4110. catch (EAbort &)
  4111. {
  4112. if (FMoveToQueue && DebugAlwaysTrue(AllowMoveToQueue) && DebugAlwaysTrue(Terminal != NULL))
  4113. {
  4114. FMoveToQueue = false;
  4115. DeletedFiles->Sorted = true;
  4116. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  4117. {
  4118. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  4119. {
  4120. // We should always be deleting the first item => what can be used to optimize this code, if needed
  4121. DebugAssert(Index == 0);
  4122. PermanentFileList->Delete(Index);
  4123. Index--;
  4124. }
  4125. }
  4126. if (Remote)
  4127. {
  4128. Configuration->Usage->Inc("MovesToBackgroundDelete");
  4129. TQueueItem * QueueItem = new TRemoteDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  4130. AddQueueItem(Queue, QueueItem, Terminal);
  4131. }
  4132. else
  4133. {
  4134. Configuration->Usage->Inc("MovesToBackgroundDeleteLocal");
  4135. TQueueItem * QueueItem = new TLocalDeleteQueueItem(PermanentFileList.get(), Params);
  4136. AddQueueItem(Queue, QueueItem, Terminal);
  4137. }
  4138. ClearOperationSelection(Side);
  4139. }
  4140. }
  4141. FAlternativeDelete = false;
  4142. }
  4143. catch(...)
  4144. {
  4145. FAlternativeDelete = false;
  4146. DView->DiscardSavedSelection();
  4147. throw;
  4148. }
  4149. DView->RestoreSelection();
  4150. }
  4151. //---------------------------------------------------------------------------
  4152. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  4153. {
  4154. DebugAssert(Terminal);
  4155. DebugAssert(!IsLocalBrowserMode());
  4156. RemoteDirView->SaveSelection();
  4157. RemoteDirView->SaveSelectedNames();
  4158. try
  4159. {
  4160. if (Lock)
  4161. {
  4162. Terminal->LockFiles(FileList);
  4163. }
  4164. else
  4165. {
  4166. Terminal->UnlockFiles(FileList);
  4167. }
  4168. }
  4169. catch(...)
  4170. {
  4171. RemoteDirView->DiscardSavedSelection();
  4172. throw;
  4173. }
  4174. RemoteDirView->RestoreSelection();
  4175. }
  4176. //---------------------------------------------------------------------------
  4177. bool TCustomScpExplorerForm::DoDirectoryExists(void * Session, const UnicodeString & Directory)
  4178. {
  4179. TTerminal * ATerminal = (Session == NULL) ? Terminal : reinterpret_cast<TTerminal *>(Session);
  4180. bool Result =
  4181. IsActiveTerminal(ATerminal) &&
  4182. ATerminal->DirectoryExists(Directory);
  4183. return Result;
  4184. }
  4185. //---------------------------------------------------------------------------
  4186. bool TCustomScpExplorerForm::NeedSecondarySessionForRemoteCopy(TStrings * FileList)
  4187. {
  4188. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4189. return
  4190. !Terminal->IsCapable[fcRemoteCopy] ||
  4191. (CopyDirsOnSecondarySession && TRemoteFileList::AnyDirectory(FileList));
  4192. }
  4193. //---------------------------------------------------------------------------
  4194. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  4195. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  4196. bool NoConfirmation, bool Move)
  4197. {
  4198. DebugAssert(Terminal != NULL);
  4199. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  4200. DebugAssert(!IsLocalBrowserMode());
  4201. if (Session == NULL)
  4202. {
  4203. Session = Terminal;
  4204. }
  4205. bool TargetConfirmed = false;
  4206. if (Session == Terminal)
  4207. {
  4208. if (RemoteDriveView->DropTarget != NULL)
  4209. {
  4210. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  4211. TargetConfirmed = true;
  4212. }
  4213. else if (RemoteDirView->DropTarget != NULL)
  4214. {
  4215. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  4216. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  4217. TargetConfirmed = true;
  4218. }
  4219. else
  4220. {
  4221. Target = RemoteDirView->Path;
  4222. }
  4223. }
  4224. else
  4225. {
  4226. Target = GetSessionPath(Session, osRemote);
  4227. }
  4228. Target = UnixIncludeTrailingBackslash(Target);
  4229. if (FileList->Count == 1)
  4230. {
  4231. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  4232. }
  4233. else
  4234. {
  4235. FileMask = AnyMask;
  4236. }
  4237. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  4238. bool Result = true;
  4239. if (!NoConfirmation)
  4240. {
  4241. bool Multi = (FileList->Count > 1);
  4242. if (Move)
  4243. {
  4244. Result = DoRemoteMoveDialog(Multi, Target, FileMask, DoDirectoryExists);
  4245. }
  4246. else
  4247. {
  4248. std::unique_ptr<TStrings> Sessions(new TStringList);
  4249. std::unique_ptr<TStrings> Directories(new TStringList);
  4250. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  4251. for (int Index = 0; Index < SessionList->Count; Index++)
  4252. {
  4253. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  4254. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  4255. {
  4256. Sessions->AddObject(SessionList->Strings[Index], ASession);
  4257. Directories->Add(GetSessionPath(ASession, osRemote));
  4258. }
  4259. }
  4260. bool AnyDirectory = false;
  4261. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4262. if (CopyDirsOnSecondarySession && !Terminal->CommandSessionOpened) // optimization
  4263. {
  4264. for (int Index = 0; !AnyDirectory && (Index < FileList->Count); Index++)
  4265. {
  4266. AnyDirectory = DebugNotNull(dynamic_cast<TRemoteFile *>(FileList->Objects[Index]))->IsDirectory;
  4267. }
  4268. }
  4269. TDirectRemoteCopy AllowDirectCopy;
  4270. if (Terminal->CommandSessionOpened || !NeedSecondarySessionForRemoteCopy(FileList))
  4271. {
  4272. DebugAssert(DirectCopy);
  4273. AllowDirectCopy = drcAllow;
  4274. }
  4275. else if (Terminal->IsCapable[fcSecondaryShell])
  4276. {
  4277. DebugAssert(DirectCopy);
  4278. AllowDirectCopy = Terminal->IsCapable[fcRemoteCopy] ? drcConfirmCommandSessionDirs : drcConfirmCommandSession;
  4279. }
  4280. else
  4281. {
  4282. DebugAssert(!DirectCopy);
  4283. AllowDirectCopy = drcDisallow;
  4284. }
  4285. void * ASession = Session;
  4286. Result = DoRemoteCopyDialog(
  4287. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal,
  4288. DoDirectoryExists, TargetConfirmed);
  4289. Session = static_cast<TManagedTerminal *>(ASession);
  4290. }
  4291. }
  4292. return Result;
  4293. }
  4294. //---------------------------------------------------------------------------
  4295. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  4296. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  4297. {
  4298. DebugAssert(!IsLocalBrowserMode());
  4299. bool DirectCopy;
  4300. UnicodeString Target, FileMask;
  4301. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  4302. if (Result)
  4303. {
  4304. if (!Move && !DirectCopy)
  4305. {
  4306. Configuration->Usage->Inc("RemoteCopyTemp");
  4307. UnicodeString RootTempDir;
  4308. UnicodeString TempDir;
  4309. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  4310. TStrings * TemporaryFilesList = new TStringList();
  4311. try
  4312. {
  4313. TMakeLocalFileListParams MakeFileListParam;
  4314. MakeFileListParam.FileList = TemporaryFilesList;
  4315. MakeFileListParam.FileTimes = NULL;
  4316. MakeFileListParam.IncludeDirs = true;
  4317. MakeFileListParam.Recursive = false;
  4318. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4319. TTerminalManager::Instance()->ActiveSession = Session;
  4320. if (TemporaryFilesList->Count > 0)
  4321. {
  4322. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4323. CopyParam.FileMask = FileMask;
  4324. DebugAssert(!FAutoOperation);
  4325. FAutoOperation = true;
  4326. FMoveToQueue = false;
  4327. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4328. }
  4329. }
  4330. __finally
  4331. {
  4332. delete TemporaryFilesList;
  4333. FAutoOperation = false;
  4334. if (!RootTempDir.IsEmpty())
  4335. {
  4336. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  4337. }
  4338. }
  4339. }
  4340. else
  4341. {
  4342. RemoteDirView->SaveSelection();
  4343. RemoteDirView->SaveSelectedNames();
  4344. try
  4345. {
  4346. if (Move)
  4347. {
  4348. Configuration->Usage->Inc("RemoteMove");
  4349. Terminal->MoveFiles(FileList, Target, FileMask, false);
  4350. }
  4351. else
  4352. {
  4353. Configuration->Usage->Inc("RemoteCopyDirect");
  4354. DebugAssert(DirectCopy);
  4355. DebugAssert(Session == Terminal);
  4356. if (!NeedSecondarySessionForRemoteCopy(FileList) ||
  4357. Terminal->CommandSessionOpened ||
  4358. CommandSessionFallback())
  4359. {
  4360. Terminal->CopyFiles(FileList, Target, FileMask, false);
  4361. }
  4362. }
  4363. }
  4364. catch(...)
  4365. {
  4366. RemoteDirView->DiscardSavedSelection();
  4367. throw;
  4368. }
  4369. RemoteDirView->RestoreSelection();
  4370. }
  4371. }
  4372. return Result;
  4373. }
  4374. //---------------------------------------------------------------------------
  4375. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4376. const UnicodeString & Path, TRemoteProperties & Properties)
  4377. {
  4378. DebugAssert(!IsLocalBrowserMode());
  4379. Properties.Valid = Properties.Valid << vpEncrypt;
  4380. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4381. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4382. }
  4383. //---------------------------------------------------------------------------
  4384. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4385. {
  4386. Side = GetSide(Side);
  4387. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4388. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4389. UnicodeString Name = LoadStr(NEW_FOLDER);
  4390. int AllowedChanges =
  4391. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4392. bool SaveSettings = false;
  4393. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4394. {
  4395. TWindowLock Lock(this);
  4396. if (!IsSideLocalBrowser(Side))
  4397. {
  4398. if (SaveSettings)
  4399. {
  4400. GUIConfiguration->NewDirectoryProperties = Properties;
  4401. }
  4402. CreateRemoteDirectory(Name, Properties);
  4403. }
  4404. else
  4405. {
  4406. DirView(Side)->CreateDirectory(Name);
  4407. }
  4408. }
  4409. }
  4410. //---------------------------------------------------------------------------
  4411. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4412. {
  4413. TWindowLock Lock(this);
  4414. DirView(Side)->ExecuteHomeDirectory();
  4415. }
  4416. //---------------------------------------------------------------------------
  4417. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4418. {
  4419. DoOpenDirectoryDialog(odBrowse, Side);
  4420. }
  4421. //---------------------------------------------------------------------------
  4422. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4423. {
  4424. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4425. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4426. bool Result = !Path.IsEmpty();
  4427. if (Result)
  4428. {
  4429. TryOpenDirectory(Side, Path);
  4430. }
  4431. return Result;
  4432. }
  4433. //---------------------------------------------------------------------------
  4434. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4435. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4436. bool & Close)
  4437. {
  4438. // terminal can be already closed (e.g. dropped connection)
  4439. if (Terminal != NULL)
  4440. {
  4441. try
  4442. {
  4443. TCalculateSizeParams Params;
  4444. Params.Stats = &Stats;
  4445. Terminal->CalculateFilesSize(FileList, Size, Params);
  4446. }
  4447. catch(...)
  4448. {
  4449. if (!Terminal->Active)
  4450. {
  4451. Close = true;
  4452. }
  4453. throw;
  4454. }
  4455. }
  4456. }
  4457. //---------------------------------------------------------------------------
  4458. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4459. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4460. bool & Close)
  4461. {
  4462. if ((Terminal != NULL) && // terminal can be already closed (e.g. dropped connection)
  4463. EnsureCommandSessionFallback(fcCalculatingChecksum))
  4464. {
  4465. Configuration->Usage->Inc(L"ChecksumCalculated");
  4466. try
  4467. {
  4468. Terminal->CalculateFilesChecksum(Alg, FileList, OnCalculatedChecksum);
  4469. }
  4470. catch(...)
  4471. {
  4472. if (!Terminal->Active)
  4473. {
  4474. Close = true;
  4475. }
  4476. throw;
  4477. }
  4478. }
  4479. }
  4480. //---------------------------------------------------------------------------
  4481. void TCustomScpExplorerForm::LoadFilesProperties(TStrings * FileList)
  4482. {
  4483. if (Terminal->LoadFilesProperties(FileList))
  4484. {
  4485. RemoteDirView->Invalidate();
  4486. }
  4487. }
  4488. //---------------------------------------------------------------------------
  4489. bool TCustomScpExplorerForm::CanCalculateChecksum()
  4490. {
  4491. return
  4492. Terminal->IsCapable[fcCalculatingChecksum] ||
  4493. (Terminal->IsCapable[fcSecondaryShell] && !Terminal->IsEncryptingFiles());
  4494. }
  4495. //---------------------------------------------------------------------------
  4496. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4497. {
  4498. bool Result;
  4499. if (!IsSideLocalBrowser(Side))
  4500. {
  4501. TRemoteTokenList * GroupList = NULL;
  4502. TRemoteTokenList * UserList = NULL;
  4503. try
  4504. {
  4505. TRemoteProperties CurrentProperties;
  4506. LoadFilesProperties(FileList);
  4507. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4508. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4509. if (CapableGroupChanging || CapableOwnerChanging)
  4510. {
  4511. if (CapableGroupChanging)
  4512. {
  4513. GroupList = Terminal->Groups->Duplicate();
  4514. }
  4515. if (CapableOwnerChanging)
  4516. {
  4517. UserList = Terminal->Users->Duplicate();
  4518. }
  4519. TRemoteDirectory * Files = Terminal->Files;
  4520. int Count = Files->Count;
  4521. if (Count > 100)
  4522. {
  4523. Count = 100;
  4524. }
  4525. for (int Index = 0; Index < Count; Index++)
  4526. {
  4527. TRemoteFile * File = Files->Files[Index];
  4528. if (CapableGroupChanging)
  4529. {
  4530. GroupList->AddUnique(File->Group);
  4531. }
  4532. if (CapableOwnerChanging)
  4533. {
  4534. UserList->AddUnique(File->Owner);
  4535. }
  4536. }
  4537. // if we haven't collected tokens for all files in current directory,
  4538. // make sure we collect them at least for all selected files.
  4539. // (note that so far the files in FileList has to be from current direcotry)
  4540. if (Count < Files->Count)
  4541. {
  4542. for (int Index = 0; Index < FileList->Count; Index++)
  4543. {
  4544. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4545. if (CapableGroupChanging)
  4546. {
  4547. GroupList->AddUnique(File->Group);
  4548. }
  4549. if (CapableOwnerChanging)
  4550. {
  4551. UserList->AddUnique(File->Owner);
  4552. }
  4553. }
  4554. }
  4555. }
  4556. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4557. bool CapableAclChanging = Terminal->IsCapable[fcAclChangingFiles];
  4558. if (CapableAclChanging && TRemoteFileList::AnyDirectory(FileList))
  4559. {
  4560. CapableAclChanging = false;
  4561. CurrentProperties.Valid = CurrentProperties.Valid >> vpRights;
  4562. }
  4563. int Flags = 0;
  4564. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4565. if (CapableAclChanging) Flags |= cpAcl;
  4566. if (CapableOwnerChanging) Flags |= cpOwner;
  4567. if (CapableGroupChanging) Flags |= cpGroup;
  4568. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4569. if (CanCalculateChecksum())
  4570. {
  4571. CalculateChecksumEvent = CalculateChecksum;
  4572. }
  4573. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4574. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4575. int Options =
  4576. FLAGMASK(Terminal->IsCapable[fcGroupOwnerChangingByID], poUserGroupByID) |
  4577. FLAGMASK(Terminal->IsCapable[fcTags], poTags);
  4578. TRemoteProperties NewProperties = CurrentProperties;
  4579. Result =
  4580. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4581. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags, Options,
  4582. CalculateSize, CalculateChecksumEvent);
  4583. if (Result)
  4584. {
  4585. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4586. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4587. }
  4588. }
  4589. __finally
  4590. {
  4591. delete GroupList;
  4592. delete UserList;
  4593. }
  4594. }
  4595. else
  4596. {
  4597. DirView(Side)->DisplayPropertiesMenu();
  4598. Result = true;
  4599. }
  4600. return Result;
  4601. }
  4602. //---------------------------------------------------------------------------
  4603. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4604. {
  4605. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4606. {
  4607. FIgnoreNextDialogChar = Key;
  4608. }
  4609. Key = 0;
  4610. }
  4611. //---------------------------------------------------------------------------
  4612. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4613. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4614. {
  4615. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4616. if (Command != NULL)
  4617. {
  4618. KeyProcessed(Key, Shift);
  4619. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4620. {
  4621. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4622. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4623. false, false, const_cast<TCustomCommandType *>(Command));
  4624. }
  4625. }
  4626. }
  4627. //---------------------------------------------------------------------------
  4628. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4629. {
  4630. if (!NonVisualDataModule->Busy)
  4631. {
  4632. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4633. {
  4634. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4635. }
  4636. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4637. {
  4638. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4639. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4640. {
  4641. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4642. // But so far it's not a problem, as it does what we want.
  4643. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4644. if (((Action->ShortCut == KeyShortCut) ||
  4645. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4646. AllowedAction(Action, aaShortCut))
  4647. {
  4648. // Has to be called before the action as the dialog char is already in queue.
  4649. // So when the action consumes message queue, we already need to have the
  4650. // FIgnoreNextDialogChar set
  4651. KeyProcessed(Key, Shift);
  4652. // Reset reference to previous component (when menu/toolbar was clicked).
  4653. // Needed to detect that action was invoked by keyboard shortcut
  4654. // in TNonVisualDataModule::ExplorerActionsExecute
  4655. Action->ActionComponent = NULL;
  4656. Action->Execute();
  4657. return;
  4658. }
  4659. }
  4660. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4661. {
  4662. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4663. {
  4664. KeyProcessed(Key, Shift);
  4665. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4666. return;
  4667. }
  4668. }
  4669. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4670. {
  4671. KeyProcessed(Key, Shift);
  4672. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4673. }
  4674. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4675. if (IsCustomShortCut(CustomShortCut))
  4676. {
  4677. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4678. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4679. if (WinConfiguration->SharedBookmarks != NULL)
  4680. {
  4681. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4682. if ((Bookmark != NULL) &&
  4683. OpenBookmark(FCurrentSide, Bookmark))
  4684. {
  4685. KeyProcessed(Key, Shift);
  4686. }
  4687. }
  4688. }
  4689. }
  4690. }
  4691. TForm::KeyDown(Key, Shift);
  4692. }
  4693. //---------------------------------------------------------------------------
  4694. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4695. {
  4696. bool OpenedTerminal = false;
  4697. UnicodeString ProtocolName;
  4698. UnicodeString ProtocolNameHint;
  4699. UnicodeString SecurityProtocolName;
  4700. UnicodeString DurationHint;
  4701. // See the comment in TScpCommanderForm::UpdateControls()
  4702. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4703. if (ActiveTerminal != NULL)
  4704. {
  4705. // Active is not enough here
  4706. if (ActiveTerminal->Status == ssOpened)
  4707. {
  4708. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4709. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4710. if (FileSystemInfo.ProtocolName.IsEmpty())
  4711. {
  4712. ProtocolName = SessionInfo.ProtocolName;
  4713. }
  4714. else
  4715. {
  4716. ProtocolName = FileSystemInfo.ProtocolName;
  4717. }
  4718. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4719. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4720. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4721. OpenedTerminal = true;
  4722. }
  4723. else if (ActiveTerminal->Status > ssClosed)
  4724. {
  4725. ProtocolName = LoadStr(STATUS_CONNECTING);
  4726. }
  4727. else
  4728. {
  4729. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4730. }
  4731. }
  4732. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4733. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4734. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4735. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4736. if (ProtocolStatusPanel->Caption != ProtocolName)
  4737. {
  4738. ProtocolStatusPanel->Caption = ProtocolName;
  4739. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4740. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4741. }
  4742. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4743. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4744. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4745. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4746. SecurityStatusPanel->Enabled = SecurityEnabled;
  4747. UnicodeString SecurityProtocolHint;
  4748. if (SecurityEnabled)
  4749. {
  4750. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4751. }
  4752. else
  4753. {
  4754. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4755. }
  4756. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4757. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4758. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4759. DurationStatusPanel->Hint = DurationHint;
  4760. UpdateStatusBar();
  4761. }
  4762. //---------------------------------------------------------------------------
  4763. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4764. {
  4765. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4766. DebugAssert(SessionStatusBar != NULL);
  4767. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4768. if (!FNote.IsEmpty())
  4769. {
  4770. NoteStatusPanel->Caption = FNote;
  4771. }
  4772. else
  4773. {
  4774. UpdateStatusPanelText(NoteStatusPanel);
  4775. }
  4776. NoteStatusPanel->Hint = FNoteHints;
  4777. UnicodeString LoginTime;
  4778. // See the comment in TScpCommanderForm::UpdateControls()
  4779. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4780. // Active is not enough here
  4781. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4782. {
  4783. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4784. LoginTime = FormatDateTimeSpan(Now() - SessionInfo.LoginTime);
  4785. }
  4786. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4787. DurationStatusPanel->Caption = LoginTime;
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4791. {
  4792. Panel->Caption = L"";
  4793. }
  4794. //---------------------------------------------------------------------------
  4795. void __fastcall TCustomScpExplorerForm::Idle()
  4796. {
  4797. if (FShowing ||
  4798. // Particularly for
  4799. // - Standalone editing
  4800. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4801. // while "keeping remote directory up to date".
  4802. StandaloneOperation)
  4803. {
  4804. FEditorManager->Check();
  4805. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4806. // that needs to know if queue view is visible (and it may be closed after queue update)
  4807. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4808. }
  4809. if (FShowing)
  4810. {
  4811. if (!NonVisualDataModule->Busy &&
  4812. // Menu is opened or drag&drop is going on
  4813. (Mouse->Capture == NULL))
  4814. {
  4815. if (FRefreshRemoteDirectory)
  4816. {
  4817. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4818. {
  4819. Terminal->RefreshDirectory();
  4820. }
  4821. FRefreshRemoteDirectory = false;
  4822. }
  4823. if (FRefreshLocalDirectory)
  4824. {
  4825. ReloadLocalDirectory();
  4826. FRefreshLocalDirectory = false;
  4827. }
  4828. if (WinConfiguration->RefreshRemotePanel)
  4829. {
  4830. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4831. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4832. {
  4833. RemoteDirView->ReloadDirectory();
  4834. }
  4835. }
  4836. }
  4837. // TB2 shows accels on Alt key down, but hides it only after menu modal loop finishes.
  4838. // But if Alt is used to switch apps or for keyboard shortcut, the menu modal loop does not happen and accelerators stay displayed.
  4839. // It's difficult to fix this in TB2, as there's no "up" equivalent to CM_DIALOGKEY, which shows the accels.
  4840. // And the Alt key can be released even when other window or application is active, so handling the key up in explorer window won't do either.
  4841. TTBCustomToolbar * MenuToolbar = DebugNotNull(dynamic_cast<TTBCustomToolbar *>(GetComponent(fcMenu)));
  4842. MenuToolbar->Idle();
  4843. }
  4844. if (FShowing || StandaloneOperation)
  4845. {
  4846. if (FQueueStatusInvalidated)
  4847. {
  4848. UpdateQueueStatus(false);
  4849. }
  4850. RefreshQueueItems();
  4851. }
  4852. if (FShowing)
  4853. {
  4854. UpdateStatusBar();
  4855. }
  4856. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4857. {
  4858. FClipboardFakeMonitorsPendingReset = false;
  4859. FClipboardFakeMonitors.reset(NULL);
  4860. }
  4861. FIgnoreNextDialogChar = 0;
  4862. }
  4863. //---------------------------------------------------------------------------
  4864. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4865. {
  4866. try
  4867. {
  4868. FUserActionTimer->Enabled = false;
  4869. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4870. {
  4871. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4872. {
  4873. FPendingQueueActionItem->ProcessUserAction();
  4874. }
  4875. }
  4876. }
  4877. __finally
  4878. {
  4879. FPendingQueueActionItem = NULL;
  4880. }
  4881. }
  4882. //---------------------------------------------------------------------------
  4883. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4884. {
  4885. if (WinConfiguration->MinimizeToTray)
  4886. {
  4887. UpdateTrayIcon();
  4888. FTrayIcon->Visible = true;
  4889. if (Visible)
  4890. {
  4891. ShowWindow(Handle, SW_HIDE);
  4892. }
  4893. }
  4894. }
  4895. //---------------------------------------------------------------------------
  4896. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4897. {
  4898. // WORKAROUND
  4899. // When restoring maximized window from minimization,
  4900. // rarely some controls do not align properly.
  4901. // Two instances seen (both for Commander):
  4902. // - When restoring, window is temporarily narrower (not maximized),
  4903. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4904. // Once maximized already, top dock shinks back, but the session PageControl,
  4905. // do not align up, leaving space between TopDock and PageControl.
  4906. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4907. for (int Index = 0; Index < ControlCount; Index++)
  4908. {
  4909. RealignControl(Controls[Index]);
  4910. }
  4911. if (FTrayIcon->Visible)
  4912. {
  4913. FTrayIcon->Visible = false;
  4914. if (Visible)
  4915. {
  4916. ShowWindow(Handle, SW_SHOW);
  4917. }
  4918. }
  4919. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4920. {
  4921. FNeedSession = false;
  4922. NonVisualDataModule->StartBusy();
  4923. try
  4924. {
  4925. NeedSession(true);
  4926. }
  4927. __finally
  4928. {
  4929. NonVisualDataModule->EndBusy();
  4930. }
  4931. }
  4932. }
  4933. //---------------------------------------------------------------------------
  4934. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4935. {
  4936. FTrayIcon->Hint = GetMainForm()->Caption;
  4937. }
  4938. //---------------------------------------------------------------------------
  4939. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4940. {
  4941. UpdateTrayIcon();
  4942. }
  4943. //---------------------------------------------------------------------------
  4944. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4945. {
  4946. // workaround
  4947. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4948. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4949. // But WM_ACTIVATEAPP message can be received even when
  4950. // the main window is minimized to the tray and internal editor window is focused
  4951. // (after another application was previously active)
  4952. if (::IsIconic(Handle))
  4953. {
  4954. if (!IsAppIconic())
  4955. {
  4956. SetAppIconic(true);
  4957. }
  4958. }
  4959. ::ApplicationRestore();
  4960. Application->BringToFront();
  4961. }
  4962. //---------------------------------------------------------------------------
  4963. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4964. {
  4965. RestoreApp();
  4966. }
  4967. //---------------------------------------------------------------------------
  4968. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4969. {
  4970. if (OpenInNewWindow())
  4971. {
  4972. ExecuteNewInstance(SessionUrl);
  4973. }
  4974. else
  4975. {
  4976. TTerminalManager::Instance()->NewSession(SessionUrl);
  4977. }
  4978. }
  4979. //---------------------------------------------------------------------------
  4980. void TCustomScpExplorerForm::NewTab(TOperationSide, bool)
  4981. {
  4982. NewSession();
  4983. }
  4984. //---------------------------------------------------------------------------
  4985. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4986. {
  4987. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4988. StoredSessions->NewSession(SessionName, SessionData);
  4989. // modified only, explicit
  4990. StoredSessions->Save(false, true);
  4991. // encode session name because of slashes in hierarchical sessions
  4992. return EncodeUrlString(SessionName);
  4993. }
  4994. //---------------------------------------------------------------------------
  4995. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4996. {
  4997. // current working directories become defaults here, what is not right
  4998. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4999. return SaveHiddenDuplicateSession(SessionData.get());
  5000. }
  5001. //---------------------------------------------------------------------------
  5002. void __fastcall TCustomScpExplorerForm::DuplicateTab()
  5003. {
  5004. if (OpenInNewWindow())
  5005. {
  5006. ExecuteNewInstance(CreateHiddenDuplicateSession());
  5007. }
  5008. else
  5009. {
  5010. // current working directories become defaults here, what is not right
  5011. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5012. TTerminalManager * Manager = TTerminalManager::Instance();
  5013. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  5014. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  5015. // We definitely want these
  5016. ASession->Disconnected = ManagedSession->Disconnected;
  5017. // Not sure about these two
  5018. ASession->Permanent = ManagedSession->Permanent;
  5019. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  5020. Manager->ActiveSession = ASession;
  5021. }
  5022. }
  5023. //---------------------------------------------------------------------------
  5024. void __fastcall TCustomScpExplorerForm::RenameTab()
  5025. {
  5026. UnicodeString Name = ManagedSession->SessionData->SessionName;
  5027. if (InputDialog(LoadStr(RENAME_TAB_TITLE), LoadStr(RENAME_TAB_PROMPT), Name, HELP_TAB_RENAME) &&
  5028. // When submitting the default name, do not fix it
  5029. (Name != ManagedSession->SessionData->SessionName))
  5030. {
  5031. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  5032. TSessionData::ValidateName(Name);
  5033. // This is inconsistent with how color (for example) is handled.
  5034. ManagedSession->SessionData->Name = Name;
  5035. UpdateControls();
  5036. // Add/Remove distinguishing paths from sessions of the same name.
  5037. SessionListChanged();
  5038. }
  5039. }
  5040. //---------------------------------------------------------------------------
  5041. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  5042. {
  5043. DebugAssert(Queue != NULL);
  5044. bool Result = Queue->IsEmpty;
  5045. if (!Result)
  5046. {
  5047. SetFocus();
  5048. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  5049. }
  5050. return Result;
  5051. }
  5052. //---------------------------------------------------------------------------
  5053. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  5054. {
  5055. return CanCloseQueue(FQueue);
  5056. }
  5057. //---------------------------------------------------------------------------
  5058. void __fastcall TCustomScpExplorerForm::CloseTab()
  5059. {
  5060. if (CanCloseQueue())
  5061. {
  5062. TTerminalManager::Instance()->FreeActiveTerminal();
  5063. }
  5064. }
  5065. //---------------------------------------------------------------------------
  5066. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  5067. {
  5068. if (CanCloseQueue())
  5069. {
  5070. TTerminalManager::Instance()->DisconnectActiveTerminal();
  5071. }
  5072. }
  5073. //---------------------------------------------------------------------------
  5074. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  5075. {
  5076. DetachTerminal(Terminal);
  5077. RemoteDirView->Terminal = Terminal;
  5078. UpdateRemotePathComboBox(false);
  5079. InitStatusBar();
  5080. UpdateControls();
  5081. }
  5082. //---------------------------------------------------------------------------
  5083. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  5084. {
  5085. InitStatusBar();
  5086. }
  5087. //---------------------------------------------------------------------------
  5088. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  5089. {
  5090. if (DebugAlwaysTrue(!Terminal->Active))
  5091. {
  5092. TTerminalManager::Instance()->ReconnectActiveTerminal();
  5093. }
  5094. }
  5095. //---------------------------------------------------------------------------
  5096. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  5097. {
  5098. if (OpenInNewWindow())
  5099. {
  5100. // encode session name because of slashes in hierarchical sessions
  5101. ExecuteNewInstance(EncodeUrlString(Data->Name));
  5102. }
  5103. else
  5104. {
  5105. TTerminalManager * Manager = TTerminalManager::Instance();
  5106. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  5107. Manager->ActiveSession = Terminal;
  5108. }
  5109. }
  5110. //---------------------------------------------------------------------------
  5111. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  5112. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  5113. {
  5114. TTerminalManager * Manager = TTerminalManager::Instance();
  5115. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5116. // This asks for a master password. Maybe we should postpone asking until a connection is actually opened.
  5117. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  5118. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  5119. {
  5120. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  5121. // FirstSession can be null, if none of the workspace sites exist anymore
  5122. // or if all workspace sessions are not suported by the interface
  5123. // (when trying to open all local-local workspace in "explorer" interface)
  5124. if (FirstSession != NULL)
  5125. {
  5126. if (!ConnectFirstTerminal)
  5127. {
  5128. FirstSession->Disconnected = true;
  5129. FirstSession->DisconnectedTemporarily = true;
  5130. }
  5131. Manager->ActiveSession = FirstSession;
  5132. }
  5133. }
  5134. }
  5135. //---------------------------------------------------------------------------
  5136. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  5137. {
  5138. if (OpenInNewWindow())
  5139. {
  5140. ExecuteNewInstance(Name);
  5141. }
  5142. else
  5143. {
  5144. DoOpenFolderOrWorkspace(Name, true, false);
  5145. }
  5146. }
  5147. //---------------------------------------------------------------------------
  5148. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  5149. bool &CanClose)
  5150. {
  5151. AppLog(L"Windows close query");
  5152. // See the comment in CloseApp()
  5153. if (NonVisualDataModule->Busy)
  5154. {
  5155. CanClose = false;
  5156. }
  5157. else
  5158. {
  5159. TTerminalManager * Manager = TTerminalManager::Instance();
  5160. int ActiveSessions = 0;
  5161. for (int Index = 0; Index < Manager->Count; Index++)
  5162. {
  5163. if (Manager->Sessions[Index]->Active)
  5164. {
  5165. ActiveSessions++;
  5166. }
  5167. }
  5168. // Confirm, when there's at least one active remote session or
  5169. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  5170. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  5171. WinConfiguration->ConfirmClosingSession)
  5172. {
  5173. unsigned int Result;
  5174. TMessageParams Params(mpNeverAskAgainCheck);
  5175. UnicodeString Message;
  5176. int Answers = qaOK | qaCancel;
  5177. // The current session is the only active session
  5178. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  5179. {
  5180. if (!WinConfiguration->AutoSaveWorkspace)
  5181. {
  5182. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  5183. }
  5184. else
  5185. {
  5186. Message = LoadStr(CLOSE_SESSION);
  5187. }
  5188. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  5189. }
  5190. // Multiple active sessions or one active session, but it's not the current one
  5191. else if (ActiveSessions > 0)
  5192. {
  5193. if (!WinConfiguration->AutoSaveWorkspace)
  5194. {
  5195. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  5196. }
  5197. else
  5198. {
  5199. Message = LoadStr(CLOSE_SESSIONS);
  5200. }
  5201. }
  5202. // Multiple tabs, but all are inactive or local, and saving of worspace is not enabled
  5203. else
  5204. {
  5205. DebugAlwaysTrue(Manager->Count > 1);
  5206. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  5207. Message = LoadStr(CLOSE_WORKSPACE);
  5208. }
  5209. UnicodeString Note;
  5210. if (WinConfiguration->AutoSaveWorkspace)
  5211. {
  5212. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  5213. }
  5214. else
  5215. {
  5216. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  5217. Answers = qaYes | qaNo | qaCancel;
  5218. }
  5219. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  5220. SetFocus();
  5221. Result = MessageDialog(Message, qtConfirmation,
  5222. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  5223. if (Result == qaNeverAskAgain)
  5224. {
  5225. WinConfiguration->ConfirmClosingSession = false;
  5226. }
  5227. if (Result == qaNo)
  5228. {
  5229. CanClose = SaveWorkspace(true);
  5230. // note that the workspace will be saved redundatly again from FormClose
  5231. }
  5232. else
  5233. {
  5234. CanClose =
  5235. (Result == qaOK) ||
  5236. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  5237. (Result == qaNeverAskAgain);
  5238. }
  5239. }
  5240. if (CanClose && HasActiveTerminal())
  5241. {
  5242. CanClose = CanCloseQueue();
  5243. }
  5244. }
  5245. if (CanClose)
  5246. {
  5247. CanClose =
  5248. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  5249. FEditorManager->CloseExternalFilesWithoutProcess();
  5250. if (CanClose)
  5251. {
  5252. while (CanClose && (FLocalEditors->Count > 0))
  5253. {
  5254. int PrevCount = FLocalEditors->Count;
  5255. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  5256. CanClose = (FLocalEditors->Count < PrevCount);
  5257. }
  5258. if (CanClose)
  5259. {
  5260. CanClose = FEditorManager->Empty(true);
  5261. if (!CanClose)
  5262. {
  5263. SetFocus();
  5264. CanClose =
  5265. (MessageDialog(
  5266. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  5267. }
  5268. }
  5269. }
  5270. }
  5271. }
  5272. //---------------------------------------------------------------------------
  5273. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  5274. {
  5275. TForm * Form = dynamic_cast<TForm *>(Sender);
  5276. DebugAssert(Form != NULL);
  5277. Form->Close();
  5278. }
  5279. //---------------------------------------------------------------------------
  5280. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  5281. {
  5282. TForm * Form = dynamic_cast<TForm *>(Sender);
  5283. delete Form;
  5284. }
  5285. //---------------------------------------------------------------------------
  5286. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  5287. {
  5288. while (FLocalEditors->Count > 0)
  5289. {
  5290. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  5291. }
  5292. }
  5293. //---------------------------------------------------------------------------
  5294. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  5295. TObject *Sender)
  5296. {
  5297. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  5298. try
  5299. {
  5300. SetProperties(osRemote, FileList);
  5301. }
  5302. __finally
  5303. {
  5304. delete FileList;
  5305. }
  5306. }
  5307. //---------------------------------------------------------------------------
  5308. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  5309. {
  5310. if (value)
  5311. {
  5312. if (Component == fcCustomCommandsBand)
  5313. {
  5314. UpdateCustomCommandsToolbar();
  5315. }
  5316. if (Component == fcQueueFileList)
  5317. {
  5318. DebugAssert(!QueueFileListSplitter->Visible);
  5319. AdjustQueueLayout();
  5320. UpdateQueueFileList();
  5321. }
  5322. }
  5323. }
  5324. //---------------------------------------------------------------------------
  5325. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5326. {
  5327. int MinHeightLimit =
  5328. GetStaticQueuePanelComponentsHeight() +
  5329. QueueFileListSplitter->Height +
  5330. QueueFileList->Height +
  5331. GetMinQueueViewHeight();
  5332. if (QueuePanel->ClientHeight < MinHeightLimit)
  5333. {
  5334. QueuePanel->ClientHeight = MinHeightLimit;
  5335. }
  5336. }
  5337. //---------------------------------------------------------------------------
  5338. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5339. {
  5340. TControl * Control = GetComponent(Component);
  5341. DebugAssert(Control);
  5342. bool Changed = (Control->Visible != value);
  5343. if (Changed)
  5344. {
  5345. ComponentShowing(Component, value);
  5346. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5347. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5348. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5349. if (value)
  5350. {
  5351. int RemainingHeight = Control->Parent->ClientHeight;
  5352. int RemainingWidth = Control->Parent->ClientWidth;
  5353. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5354. {
  5355. TControl * ChildControl = Control->Parent->Controls[i];
  5356. if (ChildControl->Visible)
  5357. {
  5358. switch (ChildControl->Align)
  5359. {
  5360. case alTop:
  5361. case alBottom:
  5362. RemainingHeight -= ChildControl->Height;
  5363. break;
  5364. case alLeft:
  5365. case alRight:
  5366. RemainingWidth -= ChildControl->Width;
  5367. break;
  5368. }
  5369. }
  5370. }
  5371. int Reserve = ScaleByTextHeight(this, 32);
  5372. // queue in explorer, trees in commander
  5373. if (Control->Height > RemainingHeight - Reserve)
  5374. {
  5375. Control->Height = RemainingHeight / 2;
  5376. }
  5377. if (Control->Width > RemainingWidth - Reserve)
  5378. {
  5379. Control->Width = RemainingWidth / 2;
  5380. }
  5381. }
  5382. Control->Visible = value;
  5383. if (WasFocused && Visible)
  5384. {
  5385. DirView(osCurrent)->SetFocus();
  5386. }
  5387. FixControlsPlacement();
  5388. }
  5389. }
  5390. //---------------------------------------------------------------------------
  5391. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5392. {
  5393. TControl * Control = GetComponent(Component);
  5394. if (Control == NULL)
  5395. {
  5396. return false;
  5397. }
  5398. else
  5399. {
  5400. return Control->Visible;
  5401. }
  5402. }
  5403. //---------------------------------------------------------------------------
  5404. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5405. {
  5406. bool Result;
  5407. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5408. {
  5409. Result = !IsUWP();
  5410. }
  5411. else
  5412. {
  5413. Result = true;
  5414. }
  5415. return Result;
  5416. }
  5417. //---------------------------------------------------------------------------
  5418. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5419. {
  5420. if (DirView->ItemFocused != NULL)
  5421. {
  5422. DirView->ItemFocused->MakeVisible(false);
  5423. }
  5424. }
  5425. //---------------------------------------------------------------------------
  5426. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5427. {
  5428. MakeFocusedItemVisible(RemoteDirView);
  5429. QueueSplitter->Visible = QueuePanel->Visible;
  5430. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5431. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5432. TControl * TopControlsOrder[] =
  5433. { TopDock, MessageDock, SessionsPageControl };
  5434. SetVerticalControlsOrder(TopControlsOrder, LENOF(TopControlsOrder));
  5435. TControl * QueueControlsOrder[] =
  5436. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5437. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5438. }
  5439. //---------------------------------------------------------------------------
  5440. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5441. {
  5442. switch (Component) {
  5443. case fcStatusBar: return RemoteStatusBar;
  5444. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5445. case fcQueueView: return QueuePanel;
  5446. case fcQueueToolbar: return QueueDock;
  5447. case fcRemoteTree: return RemoteDrivePanel;
  5448. case fcSessionsTabs: return SessionsPageControl;
  5449. case fcQueueFileList: return QueueFileList;
  5450. default: return NULL;
  5451. }
  5452. }
  5453. //---------------------------------------------------------------------------
  5454. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5455. TObject *Sender, TListColumn *Column, TPoint &Point)
  5456. {
  5457. DebugAssert(NonVisualDataModule && Column && Sender);
  5458. NonVisualDataModule->ListColumn = Column;
  5459. TPopupMenu * DirViewColumnMenu;
  5460. if (Sender == DirView(osOther))
  5461. {
  5462. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5463. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible = (Column->Index == uvName);
  5464. bool SizeColumn = (Column->Index == uvSize);
  5465. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible = SizeColumn;
  5466. NonVisualDataModule->RemoteCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5467. }
  5468. else
  5469. {
  5470. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5471. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible = (Column->Index == dvName);
  5472. bool SizeColumn = (Column->Index == dvSize);
  5473. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible = SizeColumn;
  5474. NonVisualDataModule->LocalCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5475. }
  5476. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5477. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5478. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5479. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5480. }
  5481. //---------------------------------------------------------------------------
  5482. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5483. TObject *Sender, TListItem *Item, bool &AllowExec)
  5484. {
  5485. DoDirViewExecFile(Sender, Item, AllowExec);
  5486. }
  5487. //---------------------------------------------------------------------------
  5488. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5489. TListItem * Item, bool & AllowExec)
  5490. {
  5491. DebugAssert(Sender && Item && Configuration);
  5492. DebugAssert(AllowExec);
  5493. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5494. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5495. bool Remote = !IsSideLocalBrowser(Side);
  5496. DebugAssert(Item == ADirView->ItemFocused);
  5497. bool IsDirectory = ADirView->ItemIsDirectory(Item);
  5498. TResolvedDoubleClickAction Action;
  5499. if (FForceExecution)
  5500. {
  5501. Action = IsDirectory ? rdcaChangeDir : rdcaOpen;
  5502. }
  5503. else
  5504. {
  5505. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  5506. Action = WinConfiguration->ResolveDoubleClickAction(IsDirectory, ATerminal);
  5507. }
  5508. if (Action == rdcaCopy)
  5509. {
  5510. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5511. UnlockWindow();
  5512. try
  5513. {
  5514. if (IsLocalBrowserMode())
  5515. {
  5516. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5517. }
  5518. else
  5519. {
  5520. if (HasActiveTerminal())
  5521. {
  5522. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5523. }
  5524. }
  5525. }
  5526. __finally
  5527. {
  5528. LockWindow();
  5529. }
  5530. AllowExec = false;
  5531. }
  5532. else if (Action == rdcaEdit)
  5533. {
  5534. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5535. {
  5536. ExecuteFile(Side, efDefaultEditor);
  5537. AllowExec = false;
  5538. }
  5539. }
  5540. else if (Action == rdcaOpen)
  5541. {
  5542. if (DebugAlwaysTrue(!IsDirectory) && Remote && !WinConfiguration->DisableOpenEdit)
  5543. {
  5544. ExecuteFile(osRemote, efShell);
  5545. AllowExec = false;
  5546. }
  5547. }
  5548. }
  5549. //---------------------------------------------------------------------------
  5550. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5551. {
  5552. return ((Side == osRemote) || (Side == osCurrent));
  5553. }
  5554. //---------------------------------------------------------------------------
  5555. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5556. {
  5557. DebugFail();
  5558. }
  5559. //---------------------------------------------------------------------------
  5560. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5561. {
  5562. DebugFail();
  5563. }
  5564. //---------------------------------------------------------------------------
  5565. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5566. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5567. {
  5568. TSynchronizeParamType Params;
  5569. Params.LocalDirectory = LocalDirectory;
  5570. Params.RemoteDirectory = RemoteDirectory;
  5571. int UnusedParams =
  5572. (GUIConfiguration->SynchronizeParams &
  5573. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5574. TTerminal::spCaseSensitive | TTerminal::spMirror | TTerminal::spByChecksum));
  5575. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5576. Params.Options = GUIConfiguration->SynchronizeOptions;
  5577. bool SaveSettings = false;
  5578. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5579. &DoSynchronizeTooManyDirectories);
  5580. DebugAssert(FSynchronizeController == NULL);
  5581. FSynchronizeController = &Controller;
  5582. bool Result;
  5583. try
  5584. {
  5585. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5586. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5587. int Options =
  5588. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5589. DebugAssert(FOnFeedSynchronizeError == NULL);
  5590. DebugAssert(FOnSynchronizeAbort == NULL);
  5591. DebugAssert(FSynchronizeTerminal == NULL);
  5592. FSynchronizeTerminal = Terminal;
  5593. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5594. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5595. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5596. if (Result)
  5597. {
  5598. if (SaveSettings)
  5599. {
  5600. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5601. GUIConfiguration->SynchronizeOptions = Params.Options;
  5602. }
  5603. else
  5604. {
  5605. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5606. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5607. FLAGSET(Params.Options, soSynchronize))
  5608. {
  5609. GUIConfiguration->SynchronizeOptions =
  5610. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5611. soSynchronize;
  5612. }
  5613. }
  5614. LocalDirectory = Params.LocalDirectory;
  5615. RemoteDirectory = Params.RemoteDirectory;
  5616. }
  5617. }
  5618. __finally
  5619. {
  5620. FSynchronizeController = NULL;
  5621. DebugAssert(FOnFeedSynchronizeError == NULL);
  5622. FOnFeedSynchronizeError = NULL;
  5623. DebugAssert(FOnSynchronizeAbort == NULL);
  5624. FOnSynchronizeAbort = NULL;
  5625. FSynchronizeTerminal = NULL;
  5626. }
  5627. return Result;
  5628. }
  5629. //---------------------------------------------------------------------------
  5630. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5631. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5632. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5633. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5634. TSynchronizeOptions * Options, bool Full)
  5635. {
  5636. // Keep-up-to-date mode
  5637. if (Terminal->Status == ssOpened)
  5638. {
  5639. try
  5640. {
  5641. int PParams = Params.Params;
  5642. if (!Full)
  5643. {
  5644. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5645. if (FLAGSET(Params.Options, soRecurse))
  5646. {
  5647. PParams |= TTerminal::spSubDirs;
  5648. }
  5649. }
  5650. else
  5651. {
  5652. // if keepuptodate is non-recursive,
  5653. // full sync before has to be non-recursive as well
  5654. if (FLAGCLEAR(Params.Options, soRecurse))
  5655. {
  5656. PParams |= TTerminal::spNoRecurse;
  5657. }
  5658. }
  5659. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5660. PParams, Checklist, Options);
  5661. }
  5662. catch (Exception & E)
  5663. {
  5664. if (!Terminal->Active)
  5665. {
  5666. ShowExtendedExceptionEx(Terminal, &E);
  5667. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5668. if (!Terminal->Active)
  5669. {
  5670. throw;
  5671. }
  5672. }
  5673. else
  5674. {
  5675. if (FLAGSET(Params.Options, soContinueOnError) &&
  5676. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5677. {
  5678. // noop, already logged in MoreMessageDialog
  5679. }
  5680. else
  5681. {
  5682. // We get mostly EAbort here, so this is noop.
  5683. // Exception is an error when listing directories while looking for differences.
  5684. ShowExtendedExceptionEx(Terminal, &E);
  5685. throw;
  5686. }
  5687. }
  5688. }
  5689. }
  5690. }
  5691. //---------------------------------------------------------------------------
  5692. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5693. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5694. const UnicodeString ErrorStr)
  5695. {
  5696. if (!Directory.IsEmpty())
  5697. {
  5698. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5699. }
  5700. else
  5701. {
  5702. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5703. }
  5704. }
  5705. //---------------------------------------------------------------------------
  5706. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5707. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5708. {
  5709. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5710. {
  5711. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5712. }
  5713. else
  5714. {
  5715. TMessageParams Params(mpNeverAskAgainCheck);
  5716. unsigned int Result = MessageDialog(
  5717. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5718. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5719. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5720. {
  5721. MaxDirectories *= 2;
  5722. if (Result == qaNeverAskAgain)
  5723. {
  5724. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5725. }
  5726. }
  5727. else
  5728. {
  5729. Abort();
  5730. }
  5731. }
  5732. }
  5733. //---------------------------------------------------------------------------
  5734. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5735. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5736. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5737. TSynchronizeOptions * Options)
  5738. {
  5739. // Keep-up-to-date mode
  5740. DebugAssert(!FAutoOperation);
  5741. void * BatchStorage;
  5742. BatchStart(BatchStorage);
  5743. FAutoOperation = true;
  5744. bool AnyOperation = false;
  5745. TDateTime StartTime = Now();
  5746. TSynchronizeChecklist * AChecklist = NULL;
  5747. try
  5748. {
  5749. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5750. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5751. {
  5752. FSynchronizeProgressForm->Start();
  5753. }
  5754. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5755. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5756. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5757. Options);
  5758. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5759. SAFE_DESTROY(FSynchronizeProgressForm);
  5760. AnyOperation = (AChecklist->CheckedCount > 0);
  5761. if (AnyOperation)
  5762. {
  5763. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5764. CreateProgressForm(&SynchronizeProgress);
  5765. try
  5766. {
  5767. Terminal->SynchronizeApply(
  5768. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5769. SynchronizeProcessedItem, NULL, NULL, NULL);
  5770. }
  5771. __finally
  5772. {
  5773. DestroyProgressForm();
  5774. }
  5775. }
  5776. }
  5777. __finally
  5778. {
  5779. if (Checklist == NULL)
  5780. {
  5781. delete AChecklist;
  5782. }
  5783. else
  5784. {
  5785. *Checklist = AChecklist;
  5786. }
  5787. FAutoOperation = false;
  5788. SAFE_DESTROY(FSynchronizeProgressForm);
  5789. BatchEnd(BatchStorage);
  5790. ReloadLocalDirectory();
  5791. if (AnyOperation)
  5792. {
  5793. OperationComplete(StartTime);
  5794. }
  5795. }
  5796. }
  5797. //---------------------------------------------------------------------------
  5798. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5799. {
  5800. // can be called from command line
  5801. return Visible &&
  5802. ((DirView(osRemote)->SelCount > 0) ||
  5803. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5804. }
  5805. //---------------------------------------------------------------------------
  5806. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5807. {
  5808. LogSynchronizeEvent(Terminal, Message);
  5809. }
  5810. //---------------------------------------------------------------------------
  5811. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5812. int Params, TSynchronizeOptions & Options)
  5813. {
  5814. DebugAssert(!IsLocalBrowserMode());
  5815. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5816. {
  5817. Options.Filter = new TStringList();
  5818. Options.Filter->CaseSensitive = false;
  5819. Options.Filter->Duplicates = Types::dupAccept;
  5820. if (DirView(osRemote)->SelCount > 0)
  5821. {
  5822. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5823. }
  5824. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5825. {
  5826. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5827. }
  5828. Options.Filter->Sort();
  5829. }
  5830. }
  5831. //---------------------------------------------------------------------------
  5832. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5833. {
  5834. TCopyParamType Defaults;
  5835. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5836. ConfigStorage->AccessMode = smRead;
  5837. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5838. {
  5839. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5840. }
  5841. ConfigStorage.reset(NULL);
  5842. std::unique_ptr<TStringList> Options(new TStringList());
  5843. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5844. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5845. UnicodeString Result;
  5846. if (Options->Count > 0)
  5847. {
  5848. Result =
  5849. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5850. }
  5851. return Result;
  5852. }
  5853. //---------------------------------------------------------------------------
  5854. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5855. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5856. {
  5857. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5858. UnicodeString AdditionalParams =
  5859. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5860. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5861. SerializeCopyParamForCommandLine(CopyParams),
  5862. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5863. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5864. ExecuteNewInstance(SessionName, AdditionalParams);
  5865. }
  5866. //---------------------------------------------------------------------------
  5867. struct TSynchronizeParams
  5868. {
  5869. UnicodeString LocalDirectory;
  5870. UnicodeString RemoteDirectory;
  5871. TSynchronizeMode Mode;
  5872. TSynchronizeChecklist * Checklist;
  5873. int Params;
  5874. TCopyParamType * CopyParam;
  5875. TDateTime CollectElapsed;
  5876. TDateTime * StartTime;
  5877. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5878. };
  5879. //---------------------------------------------------------------------------
  5880. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5881. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5882. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5883. {
  5884. DebugAssert(!FAutoOperation);
  5885. void * BatchStorage;
  5886. BatchStart(BatchStorage);
  5887. FAutoOperation = true;
  5888. TFileOperationStatistics Statistics;
  5889. TDateTime Start = Now();
  5890. try
  5891. {
  5892. Params.OnProcessedItem = OnProcessedItem;
  5893. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5894. CreateProgressForm(&SynchronizeProgress);
  5895. Terminal->SynchronizeApply(
  5896. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5897. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5898. &Statistics);
  5899. }
  5900. __finally
  5901. {
  5902. Params.OnProcessedItem = NULL;
  5903. FAutoOperation = false;
  5904. DestroyProgressForm();
  5905. BatchEnd(BatchStorage);
  5906. ReloadLocalDirectory();
  5907. }
  5908. if (WinConfiguration->SynchronizeSummary)
  5909. {
  5910. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5911. // The statistics should be 0 anyway in this case
  5912. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5913. {
  5914. Message += L"\n";
  5915. if (Statistics.FilesUploaded > 0)
  5916. {
  5917. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5918. }
  5919. if (Statistics.FilesDownloaded > 0)
  5920. {
  5921. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5922. }
  5923. if (Statistics.FilesDeletedLocal > 0)
  5924. {
  5925. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5926. }
  5927. if (Statistics.FilesDeletedRemote > 0)
  5928. {
  5929. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5930. }
  5931. }
  5932. TDateTime Elapsed = (Now() - Start);
  5933. Message +=
  5934. L"\n" +
  5935. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Params.CollectElapsed))) + L"\n" +
  5936. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Elapsed)));
  5937. TMessageParams Params(mpNeverAskAgainCheck);
  5938. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5939. if (Result == qaNeverAskAgain)
  5940. {
  5941. WinConfiguration->SynchronizeSummary = false;
  5942. }
  5943. }
  5944. }
  5945. //---------------------------------------------------------------------------
  5946. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5947. {
  5948. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5949. {
  5950. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5951. }
  5952. // Not set in keep-up-to-date mode - Synchronize() method
  5953. if (Token != NULL)
  5954. {
  5955. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5956. if (Params.OnProcessedItem != NULL)
  5957. {
  5958. Params.OnProcessedItem(NULL, ChecklistItem);
  5959. }
  5960. }
  5961. }
  5962. //---------------------------------------------------------------------------
  5963. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5964. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5965. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5966. {
  5967. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5968. *Params.StartTime = Now();
  5969. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5970. }
  5971. //---------------------------------------------------------------------------
  5972. void TCustomScpExplorerForm::DoQueueSynchronize(void * Token)
  5973. {
  5974. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5975. int CopyParams = TTerminal::GetSynchronizeCopyParams(Params.Params);
  5976. TCopyParamType SyncCopyParam = TTerminal::GetSynchronizeCopyParam(Params.CopyParam, Params.Params);
  5977. bool Parallel = GUIConfiguration->CurrentCopyParam.QueueParallel;
  5978. int Index = 0;
  5979. const TSynchronizeChecklist::TItem * ChecklistItem;
  5980. while (Params.Checklist->GetNextChecked(Index, ChecklistItem))
  5981. {
  5982. TQueueItem * QueueItem = Terminal->SynchronizeToQueue(ChecklistItem, &SyncCopyParam, CopyParams, Parallel);
  5983. AddQueueItem(Queue, QueueItem, Terminal);
  5984. }
  5985. }
  5986. //---------------------------------------------------------------------------
  5987. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5988. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5989. {
  5990. // terminal can be already closed (e.g. dropped connection)
  5991. if (Terminal != NULL)
  5992. {
  5993. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5994. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5995. }
  5996. }
  5997. //---------------------------------------------------------------------------
  5998. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5999. TOperationSide Side, TStrings * FileList, const UnicodeString & NewFileName, bool TargetIsDirectory, void * Token)
  6000. {
  6001. DebugAssert(!IsLocalBrowserMode());
  6002. TAutoBatch AutoBatch(this);
  6003. TAutoFlag AutoOperationFlag(FAutoOperation);
  6004. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  6005. if (Side == osRemote)
  6006. {
  6007. UnicodeString Target;
  6008. UnicodeString FileMask;
  6009. if (TargetIsDirectory)
  6010. {
  6011. Target = NewFileName;
  6012. Terminal->CreateTargetDirectory(Target, faDirectory, Params.CopyParam);
  6013. }
  6014. else
  6015. {
  6016. Target = UnixExtractFileDir(NewFileName);
  6017. FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  6018. }
  6019. RemoteDirView->SaveSelection();
  6020. RemoteDirView->SaveSelectedNames();
  6021. try
  6022. {
  6023. Terminal->MoveFiles(FileList, Target, FileMask, false);
  6024. }
  6025. catch(...)
  6026. {
  6027. RemoteDirView->DiscardSavedSelection();
  6028. throw;
  6029. }
  6030. RemoteDirView->RestoreSelection();
  6031. }
  6032. else if (DebugAlwaysTrue(Side == osLocal))
  6033. {
  6034. std::unique_ptr<TStrings> Directories(CreateSortedStringList());
  6035. if (TargetIsDirectory)
  6036. {
  6037. if (!ForceDirectories(ApiPath(NewFileName)))
  6038. {
  6039. throw EOSExtException(FMTLOAD(CREATE_DIR_ERROR, (NewFileName)));
  6040. }
  6041. Directories->Add(NewFileName);
  6042. }
  6043. else
  6044. {
  6045. Directories->Add(ExtractFileDir(NewFileName));
  6046. }
  6047. for (int Index = 0; Index < FileList->Count; Index++)
  6048. {
  6049. UnicodeString FileName = FileList->Strings[Index];
  6050. UnicodeString Directory = ExtractFileDir(FileName);
  6051. Directories->Add(Directory);
  6052. UnicodeString NewFilePath = NewFileName;
  6053. if (TargetIsDirectory)
  6054. {
  6055. NewFilePath = TPath::Combine(NewFilePath, ExtractFileName(FileName));
  6056. }
  6057. if (!MoveFile(ApiPath(FileName).c_str(), ApiPath(NewFilePath).c_str()))
  6058. {
  6059. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFilePath)));
  6060. }
  6061. }
  6062. for (int Index = 0; Index < Directories->Count; Index++)
  6063. {
  6064. ReloadLocalDirectory(Directories->Strings[Index]);
  6065. }
  6066. }
  6067. }
  6068. //---------------------------------------------------------------------------
  6069. void __fastcall TCustomScpExplorerForm::DoSynchronizeExplore(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  6070. {
  6071. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  6072. if (Side == osLocal)
  6073. {
  6074. if (Action == TSynchronizeChecklist::saDownloadNew)
  6075. {
  6076. OpenFolderInExplorer(LocalPath);
  6077. }
  6078. else
  6079. {
  6080. OpenFileInExplorer(CombinePaths(LocalPath, Item->GetFileName()));
  6081. }
  6082. }
  6083. else if (DebugAlwaysTrue(Side == osRemote))
  6084. {
  6085. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  6086. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  6087. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  6088. if (!LocalPath.IsEmpty())
  6089. {
  6090. SessionData->LocalDirectory = LocalPath;
  6091. }
  6092. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  6093. ExecuteNewInstance(SessionName, FORMAT(L"%s=\"%s\"", (TProgramParams::FormatSwitch(EXPLORE_SWITCH), Item->GetFileName())));
  6094. }
  6095. }
  6096. //---------------------------------------------------------------------------
  6097. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  6098. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6099. const TCopyParamType * CopyParams)
  6100. {
  6101. UnicodeString SessionName = CreateHiddenDuplicateSession();
  6102. UnicodeString AdditionalParams =
  6103. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  6104. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  6105. SerializeCopyParamForCommandLine(CopyParams),
  6106. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  6107. LocalDirectory, RemoteDirectory, Mode, Params));
  6108. ExecuteNewInstance(SessionName, AdditionalParams);
  6109. }
  6110. //---------------------------------------------------------------------------
  6111. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  6112. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  6113. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  6114. {
  6115. int Result;
  6116. bool SaveSettings = false;
  6117. int Options =
  6118. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  6119. FLAGMASK(!CanCalculateChecksum(), fsoDisableByChecksum) |
  6120. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  6121. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  6122. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  6123. bool Continue =
  6124. ((UseDefaults == 0) ||
  6125. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  6126. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults)) &&
  6127. (FLAGCLEAR(Params, TTerminal::spByChecksum) || EnsureCommandSessionFallback(fcCalculatingChecksum));
  6128. if (Continue)
  6129. {
  6130. Configuration->Usage->Inc(L"Synchronizations");
  6131. CopyParam.IncludeFileMask.SetRoots(LocalDirectory, RemoteDirectory);
  6132. UpdateCopyParamCounters(CopyParam);
  6133. TSynchronizeOptions SynchronizeOptions;
  6134. GetSynchronizeOptions(Params, SynchronizeOptions);
  6135. if (SaveSettings)
  6136. {
  6137. GUIConfiguration->SynchronizeParams = Params;
  6138. }
  6139. else
  6140. {
  6141. SaveMode = false;
  6142. }
  6143. TDateTime StartTime = Now();
  6144. TSynchronizeChecklist * Checklist = NULL;
  6145. try
  6146. {
  6147. DebugAssert(!FAutoOperation);
  6148. FAutoOperation = true;
  6149. try
  6150. {
  6151. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  6152. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  6153. int Files = -1;
  6154. if (DataList->Count >= 1)
  6155. {
  6156. Files = StrToIntDef(DataList->Strings[0], Files);
  6157. }
  6158. else
  6159. {
  6160. DataList->Add(UnicodeString());
  6161. }
  6162. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  6163. FSynchronizeProgressForm->Start();
  6164. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  6165. static_cast<TTerminal::TSynchronizeMode>(Mode),
  6166. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  6167. &SynchronizeOptions);
  6168. if (Terminal->SessionData->CacheDirectories)
  6169. {
  6170. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  6171. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  6172. }
  6173. }
  6174. __finally
  6175. {
  6176. FAutoOperation = false;
  6177. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  6178. SAFE_DESTROY(FSynchronizeProgressForm);
  6179. }
  6180. TSynchronizeParams SynchronizeParams;
  6181. SynchronizeParams.LocalDirectory = LocalDirectory;
  6182. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  6183. SynchronizeParams.Mode = Mode;
  6184. SynchronizeParams.CopyParam = &CopyParam;
  6185. SynchronizeParams.Params = Params;
  6186. SynchronizeParams.Checklist = Checklist;
  6187. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  6188. SynchronizeParams.StartTime = &StartTime;
  6189. SynchronizeParams.OnProcessedItem = NULL;
  6190. Result = Checklist->Count;
  6191. if (Checklist->Count > 0)
  6192. {
  6193. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  6194. {
  6195. TQueueSynchronizeEvent OnQueueSynchronize = NULL;
  6196. if (Visible && FLAGCLEAR(Params, TTerminal::spTimestamp))
  6197. {
  6198. OnQueueSynchronize = DoQueueSynchronize;
  6199. }
  6200. if (!DoSynchronizeChecklistDialog(
  6201. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  6202. OnQueueSynchronize, DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeExplore,
  6203. &SynchronizeParams))
  6204. {
  6205. Result = -1;
  6206. }
  6207. }
  6208. else
  6209. {
  6210. FullSynchronize(SynchronizeParams, NULL, NULL);
  6211. }
  6212. }
  6213. else
  6214. {
  6215. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  6216. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  6217. }
  6218. }
  6219. __finally
  6220. {
  6221. delete Checklist;
  6222. }
  6223. OperationComplete(StartTime);
  6224. }
  6225. else
  6226. {
  6227. Result = -1;
  6228. }
  6229. return Result;
  6230. }
  6231. //---------------------------------------------------------------------------
  6232. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  6233. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6234. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  6235. {
  6236. if (Collect)
  6237. {
  6238. DebugAssert(FSynchronizeProgressForm != NULL);
  6239. if (!FSynchronizeProgressForm->Started)
  6240. {
  6241. FSynchronizeProgressForm->Start();
  6242. }
  6243. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  6244. SetTaskbarListProgressValue(CompareProgress);
  6245. }
  6246. else
  6247. {
  6248. DebugAssert(FSynchronizeProgressForm == NULL);
  6249. DebugAssert(FProgressForm != NULL);
  6250. }
  6251. }
  6252. //---------------------------------------------------------------------------
  6253. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  6254. {
  6255. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  6256. std::unique_ptr<TRemoteFile> File(Terminal->ReadFile(FullFileName));
  6257. if (File.get() != NULL)
  6258. {
  6259. ExecuteRemoteFile(FullFileName, File.get(), efInternalEditor);
  6260. Application->ShowMainForm = false;
  6261. Application->Run();
  6262. }
  6263. }
  6264. //---------------------------------------------------------------------------
  6265. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  6266. {
  6267. DebugFail();
  6268. }
  6269. //---------------------------------------------------------------------------
  6270. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  6271. {
  6272. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  6273. SessionData->Assign(ManagedSession->SessionData);
  6274. UpdateSessionData(SessionData.get());
  6275. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  6276. if (IsActiveTerminal(ManagedSession))
  6277. {
  6278. ManagedSession->UpdateSessionCredentials(SessionData.get());
  6279. }
  6280. if (!ManagedSession->SessionData->HasSessionName())
  6281. {
  6282. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  6283. // once IsWorkspace is cleared
  6284. SessionData->Name = UnicodeString();
  6285. }
  6286. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  6287. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  6288. SessionData->IsWorkspace = false;
  6289. return SessionData.release();
  6290. }
  6291. //---------------------------------------------------------------------------
  6292. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  6293. {
  6294. TSessionData * SessionData = CloneCurrentSessionData();
  6295. try
  6296. {
  6297. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  6298. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  6299. }
  6300. __finally
  6301. {
  6302. delete SessionData;
  6303. }
  6304. }
  6305. //---------------------------------------------------------------------------
  6306. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  6307. {
  6308. TTerminalManager * Manager = TTerminalManager::Instance();
  6309. std::unique_ptr<TObjectList> DataList(new TObjectList());
  6310. if (DebugAlwaysTrue(ManagedSession != NULL))
  6311. {
  6312. // Update ManagedSession->StateData
  6313. UpdateSession(ManagedSession);
  6314. }
  6315. Manager->SaveWorkspace(DataList.get());
  6316. return DataList.release();
  6317. }
  6318. //---------------------------------------------------------------------------
  6319. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  6320. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  6321. {
  6322. WinConfiguration->LastWorkspace = Name;
  6323. if (!SavePasswords)
  6324. {
  6325. for (int Index = 0; Index < DataList->Count; Index++)
  6326. {
  6327. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6328. if (SessionData->Link.IsEmpty())
  6329. {
  6330. SessionData->ClearSessionPasswords();
  6331. }
  6332. }
  6333. }
  6334. StoredSessions->NewWorkspace(Name, DataList);
  6335. // modified only
  6336. StoredSessions->Save(false, Explicit);
  6337. }
  6338. //---------------------------------------------------------------------------
  6339. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  6340. {
  6341. return
  6342. DefaultStr(WinConfiguration->LastWorkspace,
  6343. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  6344. }
  6345. //---------------------------------------------------------------------------
  6346. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  6347. {
  6348. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  6349. bool AnyNonStoredSessionWithPassword = false;
  6350. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  6351. bool AllNonStoredSessionsAnonymous = true;
  6352. TTerminalManager * Manager = TTerminalManager::Instance();
  6353. for (int Index = 0; Index < DataList->Count; Index++)
  6354. {
  6355. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6356. if (SessionData->Link.IsEmpty())
  6357. {
  6358. if (SessionData->HasAnySessionPassword())
  6359. {
  6360. AnyNonStoredSessionWithPassword = true;
  6361. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  6362. {
  6363. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  6364. }
  6365. }
  6366. if (!SameText(SessionData->UserName, AnonymousUserName))
  6367. {
  6368. AllNonStoredSessionsAnonymous = false;
  6369. }
  6370. }
  6371. }
  6372. bool SavePasswords;
  6373. bool * PSavePasswords;
  6374. bool NotRecommendedSavingPasswords =
  6375. !CustomWinConfiguration->UseMasterPassword &&
  6376. !AllNonStoredSessionsAnonymous;
  6377. if (Configuration->DisablePasswordStoring ||
  6378. !AnyNonStoredSessionWithPassword)
  6379. {
  6380. PSavePasswords = NULL;
  6381. SavePasswords = false;
  6382. }
  6383. else
  6384. {
  6385. PSavePasswords = &SavePasswords;
  6386. SavePasswords =
  6387. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6388. !NotRecommendedSavingPasswords;
  6389. }
  6390. UnicodeString Name = WorkspaceName();
  6391. bool CreateShortcut = false;
  6392. bool Result =
  6393. DoSaveWorkspaceDialog(
  6394. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6395. EnableAutoSave);
  6396. if (Result)
  6397. {
  6398. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6399. if (CreateShortcut)
  6400. {
  6401. TOperationVisualizer Visualizer;
  6402. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6403. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6404. }
  6405. if (EnableAutoSave)
  6406. {
  6407. WinConfiguration->AutoSaveWorkspace = true;
  6408. WinConfiguration->AutoWorkspace = Name;
  6409. if (PSavePasswords != NULL)
  6410. {
  6411. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6412. }
  6413. }
  6414. }
  6415. return Result;
  6416. }
  6417. //---------------------------------------------------------------------------
  6418. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6419. {
  6420. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6421. DebugAssert(Session == ManagedSession);
  6422. if (!IsLocalBrowserMode())
  6423. {
  6424. SAFE_DESTROY(Session->RemoteExplorerState);
  6425. if (WinConfiguration->PreservePanelState)
  6426. {
  6427. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6428. }
  6429. }
  6430. UpdateSessionData(Session->StateData);
  6431. }
  6432. //---------------------------------------------------------------------------
  6433. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6434. {
  6435. // Keep in sync with TSessionData::CopyStateData
  6436. DebugAssert(Data != NULL);
  6437. // This is inconsistent with how color (for example) is handled.
  6438. Data->Name = ManagedSession->SessionData->Name;
  6439. if (!IsLocalBrowserMode())
  6440. {
  6441. // cannot use RemoteDirView->Path, because it is empty if connection
  6442. // was already closed
  6443. // also only peek, we may not be connected at all atm
  6444. // so make sure we do not try retrieving current directory from the server
  6445. // (particularly with FTP)
  6446. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6447. if (!ACurrentDirectory.IsEmpty())
  6448. {
  6449. Data->RemoteDirectory = ACurrentDirectory;
  6450. }
  6451. }
  6452. Data->Color = SessionColor;
  6453. }
  6454. //---------------------------------------------------------------------------
  6455. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6456. {
  6457. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6458. DebugAssert(Toolbar != NULL);
  6459. for (int i = 0; i < Toolbar->Items->Count; i++)
  6460. {
  6461. TTBXCustomDropDownItem * DropDownItem;
  6462. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6463. if (DropDownItem != NULL)
  6464. {
  6465. ToolbarItemResize(DropDownItem,
  6466. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6467. Toolbar->NonClientWidth);
  6468. break;
  6469. }
  6470. }
  6471. }
  6472. //---------------------------------------------------------------------------
  6473. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6474. {
  6475. Item->EditWidth = Width;
  6476. }
  6477. //---------------------------------------------------------------------------
  6478. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6479. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6480. {
  6481. for (int i = 0; i < Toolbar->Items->Count; i++)
  6482. {
  6483. TTBXCustomDropDownItem * DropDownItem;
  6484. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6485. if (DropDownItem != NULL)
  6486. {
  6487. ASize.x -= DropDownItem->EditWidth;
  6488. TControl * Control = this;
  6489. ASize.x += ScaleByTextHeight(Control, 50) /* minimal combo width */;
  6490. }
  6491. }
  6492. }
  6493. //---------------------------------------------------------------------------
  6494. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6495. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6496. {
  6497. if (WinConfiguration->DDWarnLackOfTempSpace)
  6498. {
  6499. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6500. if (!ADrive.IsEmpty())
  6501. {
  6502. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6503. DebugAssert(RequiredSpace >= 0);
  6504. __int64 RequiredWithReserve;
  6505. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6506. if (FreeSpace < RequiredWithReserve)
  6507. {
  6508. unsigned int Result;
  6509. TMessageParams Params(mpNeverAskAgainCheck);
  6510. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6511. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6512. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6513. if (Result == qaNeverAskAgain)
  6514. {
  6515. WinConfiguration->DDWarnLackOfTempSpace = false;
  6516. }
  6517. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6518. }
  6519. }
  6520. }
  6521. }
  6522. //---------------------------------------------------------------------------
  6523. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6524. {
  6525. DoOpenDirectoryDialog(odAddBookmark, Side);
  6526. }
  6527. //---------------------------------------------------------------------------
  6528. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6529. {
  6530. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6531. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6532. try
  6533. {
  6534. TCustomDirView * DView = DirView(Side);
  6535. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6536. {
  6537. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6538. }
  6539. }
  6540. catch (...)
  6541. {
  6542. delete VisitedDirectories;
  6543. throw;
  6544. }
  6545. return VisitedDirectories;
  6546. }
  6547. //---------------------------------------------------------------------------
  6548. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6549. TOpenDirectoryMode Mode, TOperationSide Side)
  6550. {
  6551. bool Continue = true;
  6552. if (Mode == odAddBookmark)
  6553. {
  6554. TMessageParams Params(mpNeverAskAgainCheck);
  6555. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6556. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6557. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6558. unsigned int Answer =
  6559. MessageDialog(Message,
  6560. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6561. if (Answer == qaNeverAskAgain)
  6562. {
  6563. Continue = true;
  6564. WinConfiguration->UseSharedBookmarks = true;
  6565. }
  6566. else if (Answer == qaOK)
  6567. {
  6568. Continue = true;
  6569. WinConfiguration->UseSharedBookmarks = false;
  6570. }
  6571. else
  6572. {
  6573. Continue = false;
  6574. }
  6575. }
  6576. if (Continue)
  6577. {
  6578. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6579. try
  6580. {
  6581. UnicodeString Name = DirView(Side)->PathName;
  6582. bool Repeat;
  6583. do
  6584. {
  6585. Repeat = false;
  6586. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6587. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6588. // do not allow switching to location profiles,
  6589. // if we are not connected
  6590. HasDirView[osLocal] && IsActiveTerminal(Terminal)))
  6591. {
  6592. TWindowLock Lock(this);
  6593. if (!TryOpenDirectory(Side, Name))
  6594. {
  6595. Repeat = true;
  6596. Mode = odBrowse;
  6597. }
  6598. }
  6599. }
  6600. while (Repeat);
  6601. }
  6602. __finally
  6603. {
  6604. delete VisitedDirectories;
  6605. }
  6606. }
  6607. }
  6608. //---------------------------------------------------------------------------
  6609. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6610. {
  6611. DebugAssert(!Terminal->CommandSessionOpened);
  6612. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6613. }
  6614. //---------------------------------------------------------------------------
  6615. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6616. {
  6617. bool Result = Terminal->IsCapable[Capability] ||
  6618. Terminal->CommandSessionOpened;
  6619. if (!Result)
  6620. {
  6621. // We might get here for example when "checksum" synchronization is requested from command-line
  6622. // on server that supports neither checksum nor shell
  6623. if (!Terminal->IsCapable[fcSecondaryShell])
  6624. {
  6625. NotSupported();
  6626. }
  6627. else if (!GUIConfiguration->ConfirmCommandSession)
  6628. {
  6629. Result = true;
  6630. }
  6631. else
  6632. {
  6633. TMessageParams Params(mpNeverAskAgainCheck);
  6634. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6635. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6636. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6637. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6638. if (Answer == qaNeverAskAgain)
  6639. {
  6640. GUIConfiguration->ConfirmCommandSession = false;
  6641. Result = true;
  6642. }
  6643. else if (Answer == qaOK)
  6644. {
  6645. Result = true;
  6646. }
  6647. }
  6648. if (Result)
  6649. {
  6650. Result = CommandSessionFallback();
  6651. }
  6652. }
  6653. return Result;
  6654. }
  6655. //---------------------------------------------------------------------------
  6656. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6657. {
  6658. if (EnsureCommandSessionFallback(fcAnyCommand))
  6659. {
  6660. DoConsoleDialog(Terminal, Command);
  6661. }
  6662. }
  6663. //---------------------------------------------------------------------------
  6664. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6665. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6666. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6667. {
  6668. if (!IsSideLocalBrowser(osRemote) &&
  6669. IsFileControl(DropSourceControl, osRemote) &&
  6670. (FDDExtMapFile != NULL))
  6671. {
  6672. Accept = true;
  6673. }
  6674. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6675. DebugAssert(FDDTargetControl != NULL);
  6676. }
  6677. //---------------------------------------------------------------------------
  6678. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6679. _di_IDataObject DataObj, int KeyState,
  6680. const TPoint & Point, int & Effect, bool & Accept)
  6681. {
  6682. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6683. }
  6684. //---------------------------------------------------------------------------
  6685. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6686. _di_IDataObject DataObj, int KeyState,
  6687. const TPoint & Point, int & Effect, bool & Accept)
  6688. {
  6689. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6690. }
  6691. //---------------------------------------------------------------------------
  6692. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6693. TObject * Sender)
  6694. {
  6695. DebugUsedParam(Sender);
  6696. DebugAssert(FDDTargetControl == Sender);
  6697. FDDTargetControl = NULL;
  6698. }
  6699. //---------------------------------------------------------------------------
  6700. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave(int)
  6701. {
  6702. FileControlDDDragLeave(SessionsPageControl);
  6703. }
  6704. //---------------------------------------------------------------------------
  6705. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave(int)
  6706. {
  6707. FileControlDDDragLeave(QueueView3);
  6708. }
  6709. //---------------------------------------------------------------------------
  6710. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6711. {
  6712. DebugAssert(!IsSideLocalBrowser(Side));
  6713. DebugUsedParam(Side);
  6714. bool Edit = false;
  6715. TRemoteFile * File = NULL;
  6716. UnicodeString FileName;
  6717. UnicodeString PointTo;
  6718. bool SymbolicLink = true;
  6719. if (RemoteDirView->ItemFocused)
  6720. {
  6721. DebugAssert(RemoteDirView->ItemFocused->Data);
  6722. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6723. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6724. if (Edit)
  6725. {
  6726. FileName = File->FileName;
  6727. PointTo = File->LinkTo;
  6728. }
  6729. else if (!File->IsParentDirectory)
  6730. {
  6731. PointTo = File->FileName;
  6732. }
  6733. }
  6734. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6735. Terminal->IsCapable[fcHardLink]))
  6736. {
  6737. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6738. if (Edit)
  6739. {
  6740. DebugAssert(File->FileName == FileName);
  6741. int Params = dfNoRecursive;
  6742. Terminal->ExceptionOnFail = true;
  6743. try
  6744. {
  6745. Terminal->DeleteFile(L"", File, &Params);
  6746. }
  6747. __finally
  6748. {
  6749. Terminal->ExceptionOnFail = false;
  6750. }
  6751. }
  6752. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6753. }
  6754. }
  6755. //---------------------------------------------------------------------------
  6756. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6757. {
  6758. return
  6759. (IsSideLocalBrowser(Side) ||
  6760. (HasActiveTerminal() &&
  6761. Terminal->ResolvingSymlinks &&
  6762. Terminal->IsCapable[fcSymbolicLink]));
  6763. }
  6764. //---------------------------------------------------------------------------
  6765. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6766. {
  6767. return
  6768. !IsSideLocalBrowser(FCurrentSide) &&
  6769. (RemoteDirView->ItemFocused != NULL) &&
  6770. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6771. Terminal->SessionData->ResolveSymlinks;
  6772. }
  6773. //---------------------------------------------------------------------------
  6774. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6775. {
  6776. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6777. FForceExecution = true;
  6778. try
  6779. {
  6780. DirView(osCurrent)->ExecuteCurrentFile();
  6781. }
  6782. __finally
  6783. {
  6784. FForceExecution = false;
  6785. }
  6786. }
  6787. //---------------------------------------------------------------------------
  6788. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6789. {
  6790. TEditorData ExternalEditor;
  6791. ExternalEditor.Editor = edExternal;
  6792. bool Remember = false;
  6793. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6794. {
  6795. if (Remember)
  6796. {
  6797. TEditorList * EditorList = new TEditorList;
  6798. try
  6799. {
  6800. *EditorList = *WinConfiguration->EditorList;
  6801. bool Found = false;
  6802. int i = 0;
  6803. while (!Found && (i < EditorList->Count))
  6804. {
  6805. const TEditorPreferences * Editor = EditorList->Editors[i];
  6806. if ((Editor->Data->Editor == edExternal) &&
  6807. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6808. {
  6809. Found = true;
  6810. }
  6811. i++;
  6812. }
  6813. if (!Found)
  6814. {
  6815. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6816. WinConfiguration->EditorList = EditorList;
  6817. }
  6818. }
  6819. __finally
  6820. {
  6821. delete EditorList;
  6822. }
  6823. }
  6824. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6825. }
  6826. }
  6827. //---------------------------------------------------------------------------
  6828. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6829. {
  6830. if (FFileFindTerminal == ATerminal)
  6831. {
  6832. FFileFindTerminal = NULL;
  6833. HideFileFindDialog();
  6834. }
  6835. if (FClipboardTerminal == ATerminal)
  6836. {
  6837. ClipboardClear(); // implies ClipboardStop
  6838. }
  6839. if ((FOnSynchronizeAbort != NULL) &&
  6840. (ATerminal == FManagedSession))
  6841. {
  6842. FOnSynchronizeAbort(NULL);
  6843. }
  6844. }
  6845. //---------------------------------------------------------------------------
  6846. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6847. {
  6848. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6849. DetachTerminal(Sender);
  6850. }
  6851. //---------------------------------------------------------------------------
  6852. void __fastcall TCustomScpExplorerForm::FileTerminalReplaced(
  6853. const UnicodeString FileName, TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6854. {
  6855. TManagedTerminal * ATerminal = static_cast<TManagedTerminal *>(Arg);
  6856. if (Data->Terminal == Terminal)
  6857. {
  6858. Data->Terminal = ATerminal;
  6859. }
  6860. }
  6861. //---------------------------------------------------------------------------
  6862. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6863. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6864. {
  6865. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6866. DebugAssert(Terminal != NULL);
  6867. if (Data->Terminal == Terminal)
  6868. {
  6869. Data->Terminal = NULL;
  6870. }
  6871. }
  6872. //---------------------------------------------------------------------------
  6873. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6874. {
  6875. return NULL;
  6876. }
  6877. //---------------------------------------------------------------------------
  6878. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6879. {
  6880. UpdateControls();
  6881. SessionColor = TColor(0);
  6882. UpdateRemotePathComboBox(false);
  6883. NeedSession(false);
  6884. }
  6885. //---------------------------------------------------------------------------
  6886. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6887. {
  6888. try
  6889. {
  6890. // Cache, as the login dialog can change its value.
  6891. // See also DoShow. Also see TTerminalManager::NewSession.
  6892. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6893. try
  6894. {
  6895. if (ShowLogin)
  6896. {
  6897. bool ReloadSessions = !Startup;
  6898. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6899. }
  6900. }
  6901. __finally
  6902. {
  6903. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6904. // (so there was no chance for the user to open any session yet)
  6905. if ((ShowLogin || !Startup) &&
  6906. !WinConfiguration->KeepOpenWhenNoSession &&
  6907. // this rules out the implicit Commander's local-local browser
  6908. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6909. {
  6910. TerminateApplication();
  6911. }
  6912. }
  6913. }
  6914. catch (EAbort &)
  6915. {
  6916. // swallow
  6917. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6918. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6919. }
  6920. }
  6921. //---------------------------------------------------------------------------
  6922. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6923. {
  6924. TTerminalManager * Manager = TTerminalManager::Instance();
  6925. DebugAssert(!Manager->Updating);
  6926. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6927. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6928. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6929. SessionsPageControl->LockDrawing();
  6930. try
  6931. {
  6932. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6933. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6934. {
  6935. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6936. }
  6937. for (int Index = 0; Index <= Manager->Count; Index++)
  6938. {
  6939. TThemeTabSheet * TabSheet;
  6940. if (Index >= SessionsPageControl->PageCount)
  6941. {
  6942. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6943. TabSheet->PageControl = SessionsPageControl;
  6944. }
  6945. else
  6946. {
  6947. TabSheet = SessionsPageControl->Pages[Index];
  6948. }
  6949. bool IsSessionTab = (Index < Manager->Count);
  6950. if (IsSessionTab)
  6951. {
  6952. TTerminal * Terminal = Manager->Sessions[Index];
  6953. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6954. TabSheet->CaptionTruncation = WinConfiguration->SessionTabCaptionTruncation ? tttEllipsis : tttNone;
  6955. UpdateSessionTab(TabSheet);
  6956. }
  6957. else
  6958. {
  6959. TabSheet->Tag = 0; // not really needed
  6960. TabSheet->Shadowed = false;
  6961. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6962. TabSheet->CaptionTruncation = GetNewTabTabCaptionTruncation();
  6963. // 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)
  6964. UpdateNewTabTab();
  6965. }
  6966. }
  6967. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6968. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6969. {
  6970. SessionsPageControl->UpdateTabsCaptionTruncation();
  6971. }
  6972. }
  6973. __finally
  6974. {
  6975. SessionsPageControl->UnlockDrawing();
  6976. }
  6977. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6978. }
  6979. //---------------------------------------------------------------------------
  6980. TThemeTabCaptionTruncation TCustomScpExplorerForm::GetNewTabTabCaptionTruncation()
  6981. {
  6982. return WinConfiguration->SessionTabCaptionTruncation ? tttNoText : tttNone;
  6983. }
  6984. //---------------------------------------------------------------------------
  6985. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6986. {
  6987. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6988. }
  6989. //---------------------------------------------------------------------------
  6990. TThemeTabSheet * TCustomScpExplorerForm::GetNewTabTab()
  6991. {
  6992. return SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6993. }
  6994. //---------------------------------------------------------------------------
  6995. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6996. {
  6997. TThemeTabSheet * TabSheet = GetNewTabTab();
  6998. UnicodeString TabCaption;
  6999. if (WinConfiguration->SelectiveToolbarText)
  7000. {
  7001. TabCaption = GetNewTabTabCaption();
  7002. }
  7003. TabSheet->BaseCaption = TabCaption;
  7004. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  7005. }
  7006. //---------------------------------------------------------------------------
  7007. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  7008. {
  7009. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  7010. }
  7011. //---------------------------------------------------------------------------
  7012. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  7013. {
  7014. DebugFail();
  7015. return UnicodeString();
  7016. }
  7017. //---------------------------------------------------------------------------
  7018. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  7019. {
  7020. if (DebugAlwaysTrue(TabSheet != NULL))
  7021. {
  7022. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  7023. if (DebugAlwaysTrue(ASession != NULL))
  7024. {
  7025. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  7026. if (ASession->LocalBrowser)
  7027. {
  7028. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  7029. }
  7030. else
  7031. {
  7032. TabSheet->ImageIndex = AddSessionColor(Color);
  7033. }
  7034. TTerminalManager * Manager = TTerminalManager::Instance();
  7035. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  7036. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  7037. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  7038. }
  7039. }
  7040. }
  7041. //---------------------------------------------------------------------------
  7042. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  7043. {
  7044. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  7045. }
  7046. //---------------------------------------------------------------------------
  7047. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  7048. {
  7049. DebugAssert(SessionsPageControl->ActivePage != NULL);
  7050. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  7051. bool Result = (Session != NULL);
  7052. if (Result)
  7053. {
  7054. TTerminalManager::Instance()->ActiveSession = Session;
  7055. }
  7056. else
  7057. {
  7058. try
  7059. {
  7060. NewTab();
  7061. }
  7062. __finally
  7063. {
  7064. SessionListChanged();
  7065. }
  7066. FSessionsPageControlNewTabTime = Now();
  7067. }
  7068. return Result;
  7069. }
  7070. //---------------------------------------------------------------------------
  7071. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  7072. {
  7073. TWindowLock Lock(this);
  7074. SessionTabSwitched();
  7075. }
  7076. //---------------------------------------------------------------------------
  7077. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  7078. {
  7079. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  7080. DebugAssert(TransferList != NULL);
  7081. UnicodeString Name;
  7082. if (TransferList->ItemIndex <= 0)
  7083. {
  7084. Name = L"";
  7085. }
  7086. else
  7087. {
  7088. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  7089. }
  7090. if (FCopyParamAutoSelected.IsEmpty())
  7091. {
  7092. // if previous preset was not autoselected, make new preset the "default"
  7093. FCopyParamDefault = Name;
  7094. }
  7095. GUIConfiguration->CopyParamCurrent = Name;
  7096. }
  7097. //---------------------------------------------------------------------------
  7098. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  7099. {
  7100. // sanity check
  7101. bool ExistingPreset =
  7102. (FTransferListHoverIndex >= 0) &&
  7103. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  7104. DebugAssert(ExistingPreset);
  7105. if (ExistingPreset)
  7106. {
  7107. HDC DC = GetDC(0);
  7108. TCanvas * Canvas = new TCanvas();
  7109. try
  7110. {
  7111. Canvas->Handle = DC;
  7112. Canvas->Font = GetToolbarFont(this);
  7113. UnicodeString Name;
  7114. if (FTransferListHoverIndex == 0)
  7115. {
  7116. Name = L"";
  7117. }
  7118. else
  7119. {
  7120. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  7121. }
  7122. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  7123. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  7124. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  7125. static_cast<TObject*>(GetComponent(fcTransferList)));
  7126. UnicodeString InfoStr =
  7127. GUIConfiguration->CopyParamPreset[Name].
  7128. GetInfoStr(L"; ",
  7129. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  7130. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  7131. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  7132. {
  7133. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  7134. {
  7135. InfoStr.SetLength(InfoStr.Length() - 1);
  7136. }
  7137. InfoStr += Ellipsis;
  7138. }
  7139. // UpdateCaption does not cause invalidation of whole submenu, while
  7140. // setting Caption property does.
  7141. // also it probably does not resize the label, even if necessary
  7142. // (we do not want that anyway)
  7143. TransferLabel->UpdateCaption(InfoStr);
  7144. }
  7145. __finally
  7146. {
  7147. Canvas->Handle = NULL;
  7148. ReleaseDC(0, DC);
  7149. delete Canvas;
  7150. }
  7151. }
  7152. }
  7153. //---------------------------------------------------------------------------
  7154. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  7155. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  7156. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  7157. {
  7158. if (FTransferListHoverIndex != AHoverIndex)
  7159. {
  7160. FTransferListHoverIndex = AHoverIndex;
  7161. UpdateTransferLabel();
  7162. }
  7163. }
  7164. //---------------------------------------------------------------------------
  7165. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  7166. {
  7167. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  7168. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  7169. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  7170. {
  7171. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  7172. {
  7173. if (!NonVisualDataModule->Busy)
  7174. {
  7175. OpenDirectory(GetSide(osCurrent));
  7176. }
  7177. Message.Result = 1;
  7178. }
  7179. else
  7180. {
  7181. TForm::Dispatch(&Message);
  7182. }
  7183. }
  7184. else
  7185. {
  7186. TForm::Dispatch(&Message);
  7187. }
  7188. }
  7189. //---------------------------------------------------------------------------
  7190. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  7191. {
  7192. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  7193. if ((FIgnoreNextDialogChar != 0) &&
  7194. (towupper(Message.CharCode) == towupper(FIgnoreNextDialogChar)))
  7195. {
  7196. Message.Result = 1;
  7197. }
  7198. else
  7199. {
  7200. TForm::Dispatch(&Message);
  7201. }
  7202. FIgnoreNextDialogChar = 0;
  7203. }
  7204. //---------------------------------------------------------------------------
  7205. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  7206. {
  7207. // The four low-order bits are used internally by Windows
  7208. unsigned int Cmd = (Message.WParam & 0xFFF0);
  7209. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  7210. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  7211. // 61730 - restore thru double click - undocumented
  7212. // 61490 - maximize thru double click - undocumented
  7213. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  7214. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  7215. {
  7216. SysResizing(Cmd);
  7217. }
  7218. TForm::Dispatch(&Message);
  7219. }
  7220. //---------------------------------------------------------------------------
  7221. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  7222. {
  7223. AppLog(L"Windows session end query");
  7224. // We were actually never able to make ENDSESSION_CRITICAL happen.
  7225. // Also there no point returning TRUE as we are not able to
  7226. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  7227. // Hence the process termination might be safer :)
  7228. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  7229. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  7230. {
  7231. Message.Result = FALSE;
  7232. }
  7233. else
  7234. {
  7235. Message.Result = TRUE;
  7236. }
  7237. // Do not call default handling as that triggers OnCloseQuery,
  7238. // where our implementation will popup confirmation dialogs, what we do not want,
  7239. // as per Vista guidelines:
  7240. // https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  7241. }
  7242. //---------------------------------------------------------------------------
  7243. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  7244. {
  7245. AppLog(L"Windows session end");
  7246. if (Message.EndSession && IsApplicationMinimized())
  7247. {
  7248. // WORKAROUND
  7249. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  7250. // when it receives WM_ENDSESSION,
  7251. // but that sometimes (particularly when application is minimized) cause crashes.
  7252. // Crash popups message that blocks log off.
  7253. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  7254. // so we call ExitProcess() immediately, not even trying to cleanup.
  7255. // It still causes beep, so there's likely some popup, but it does not block
  7256. // log off.
  7257. ExitProcess(0);
  7258. }
  7259. TForm::Dispatch(&Message);
  7260. }
  7261. #ifdef _DEBUG
  7262. //---------------------------------------------------------------------------
  7263. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  7264. {
  7265. TForm::Dispatch(&Message);
  7266. }
  7267. #endif
  7268. //---------------------------------------------------------------------------
  7269. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  7270. {
  7271. }
  7272. //---------------------------------------------------------------------------
  7273. void __fastcall TCustomScpExplorerForm::DoShow()
  7274. {
  7275. // Called from TCustomScpExplorerForm::CMShowingChanged
  7276. // only now are the controls resized finally, so the size constraints
  7277. // will not conflict with possibly very small window size
  7278. RestoreFormParams();
  7279. // This indicates that the form was rescaled after parameters were loaded and
  7280. // as most probably the parameters were actually saved with the current form scaling
  7281. // (windows was the last time likely closed on the same monitor, where it is starting now),
  7282. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  7283. // and no rounding problems will occur.
  7284. // See also RestoreForm.
  7285. // (we should be safe to call RestoreParams unconditionally)
  7286. if (PixelsPerInch != Screen->PixelsPerInch)
  7287. {
  7288. RestoreParams();
  7289. }
  7290. FixControlsPlacement();
  7291. if (Position == poDefaultPosOnly)
  7292. {
  7293. CutFormToDesktop(this);
  7294. }
  7295. TForm::DoShow();
  7296. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  7297. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  7298. // This was previously in NeedSession, where other related code is.
  7299. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  7300. // unpleasantly shows briefly.
  7301. if ((ManagedSession == NULL) &&
  7302. !WinConfiguration->ShowLoginWhenNoSession &&
  7303. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  7304. // This detects if workspace was saved the last time the main widow was closed
  7305. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  7306. {
  7307. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  7308. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  7309. }
  7310. // Before main window displays
  7311. if (ManagedSession == NULL)
  7312. {
  7313. StartingWithoutSession();
  7314. }
  7315. UpdatePixelsPerInchMainWindowCounter();
  7316. FShowing = true;
  7317. }
  7318. //---------------------------------------------------------------------------
  7319. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  7320. {
  7321. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  7322. }
  7323. //---------------------------------------------------------------------------
  7324. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  7325. {
  7326. SessionListChanged();
  7327. InitStatusBar();
  7328. UpdateControls();
  7329. }
  7330. //---------------------------------------------------------------------------
  7331. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  7332. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  7333. TNotifyEvent OnBalloonClick, TObject * UserData)
  7334. {
  7335. bool Do;
  7336. UnicodeString Message;
  7337. if (E == NULL)
  7338. {
  7339. Message = Str;
  7340. Do = true;
  7341. }
  7342. else
  7343. {
  7344. Do = ExceptionMessage(E, Message);
  7345. }
  7346. if (Do && WinConfiguration->BalloonNotifications)
  7347. {
  7348. UnicodeString Title;
  7349. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  7350. {
  7351. Message = TrimLeft(Message);
  7352. }
  7353. else
  7354. {
  7355. Message = UnformatMessage(Message);
  7356. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  7357. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  7358. Title = LoadResourceString(Captions[Type]);
  7359. if (Terminal != NULL)
  7360. {
  7361. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal->PrimaryTerminal));
  7362. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  7363. }
  7364. }
  7365. if (Seconds == 0)
  7366. {
  7367. Seconds = WinConfiguration->NotificationsTimeout;
  7368. }
  7369. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  7370. }
  7371. }
  7372. //---------------------------------------------------------------------------
  7373. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  7374. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  7375. UnicodeString HelpKeyword, const TMessageParams * Params,
  7376. TTerminal * Terminal)
  7377. {
  7378. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  7379. (FOnFeedSynchronizeError != NULL)) &&
  7380. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  7381. {
  7382. if (FOnFeedSynchronizeError != NULL)
  7383. {
  7384. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  7385. }
  7386. else
  7387. {
  7388. DebugAssert(FErrorList != NULL);
  7389. TStringList * MoreMessagesCopy = NULL;
  7390. if (MoreMessages)
  7391. {
  7392. MoreMessagesCopy = new TStringList();
  7393. MoreMessagesCopy->Assign(MoreMessages);
  7394. }
  7395. FErrorList->AddObject(Message, MoreMessagesCopy);
  7396. }
  7397. PopupTrayBalloon(Terminal, Message, Type);
  7398. return ContinueAnswer(Answers);
  7399. }
  7400. else
  7401. {
  7402. bool UseBalloon = FTrayIcon->Visible;
  7403. if (UseBalloon)
  7404. {
  7405. PopupTrayBalloon(Terminal, Message, Type);
  7406. }
  7407. unsigned int Result;
  7408. try
  7409. {
  7410. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7411. }
  7412. __finally
  7413. {
  7414. // cancel only balloon we popped up, otherwise we may cancel notification
  7415. // balloon that was there before the message dialog
  7416. // (such as "dd confirmation opt in balloon)
  7417. if (UseBalloon)
  7418. {
  7419. FTrayIcon->CancelBalloon();
  7420. }
  7421. }
  7422. return Result;
  7423. }
  7424. }
  7425. //---------------------------------------------------------------------------
  7426. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7427. TTerminal * Terminal, Exception * E)
  7428. {
  7429. if (FTrayIcon->Visible)
  7430. {
  7431. PopupTrayBalloon(Terminal, L"", qtError, E);
  7432. }
  7433. // particularly prevent opening new session from jump list,
  7434. // while exception is shown
  7435. NonVisualDataModule->StartBusy();
  7436. try
  7437. {
  7438. ShowExtendedExceptionEx(Terminal, E);
  7439. }
  7440. __finally
  7441. {
  7442. NonVisualDataModule->EndBusy();
  7443. FTrayIcon->CancelBalloon();
  7444. }
  7445. }
  7446. //---------------------------------------------------------------------------
  7447. void __fastcall TCustomScpExplorerForm::SessionReady()
  7448. {
  7449. InitStatusBar();
  7450. // cannot rely on active page being page for active terminal,
  7451. // as it can happen that active page is the "new session" page
  7452. // (e.g. when reconnecting active terminal, while login dialog
  7453. // invoked from "new session" page is modal)
  7454. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7455. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7456. }
  7457. //---------------------------------------------------------------------------
  7458. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7459. TTerminal * Terminal, Exception * E)
  7460. {
  7461. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7462. if (!Terminal->Active)
  7463. {
  7464. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7465. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7466. {
  7467. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7468. }
  7469. }
  7470. }
  7471. //---------------------------------------------------------------------------
  7472. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7473. UnicodeString Message, TQueryType Type,
  7474. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7475. {
  7476. if ((E == NULL) ||
  7477. ExceptionMessage(E, Message))
  7478. {
  7479. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7480. if (Important)
  7481. {
  7482. Seconds *= 5;
  7483. }
  7484. UnicodeString NoteMessage(UnformatMessage(Message));
  7485. if (Terminal != NULL)
  7486. {
  7487. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7488. NoteMessage = FORMAT(L"%s: %s",
  7489. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7490. }
  7491. if (WinConfiguration->BalloonNotifications)
  7492. {
  7493. AddNote(NoteMessage);
  7494. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7495. }
  7496. else
  7497. {
  7498. FlashOnBackground();
  7499. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7500. }
  7501. }
  7502. }
  7503. //---------------------------------------------------------------------------
  7504. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7505. {
  7506. RestoreApp();
  7507. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7508. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7509. !NonVisualDataModule->Busy)
  7510. {
  7511. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7512. TTerminalManager::Instance()->ActiveSession = Terminal;
  7513. if (!ComponentVisible[fcQueueView])
  7514. {
  7515. ToggleQueueVisibility();
  7516. GoToQueue();
  7517. }
  7518. }
  7519. }
  7520. //---------------------------------------------------------------------------
  7521. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7522. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7523. {
  7524. UnicodeString Message;
  7525. TNotifyEvent OnClick = NULL;
  7526. TObject * UserData = NULL;
  7527. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7528. switch (Event)
  7529. {
  7530. case qeEmptyButMonitored:
  7531. if ((ATerminal != Terminal) || QueueInvisible)
  7532. {
  7533. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7534. OnClick = QueueEmptyNoteClicked;
  7535. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7536. TerminalNoteData->Terminal = ATerminal;
  7537. UserData = TerminalNoteData;
  7538. }
  7539. break;
  7540. case qeEmpty:
  7541. OperationComplete(ATerminal->QueueOperationStart);
  7542. break;
  7543. case qePendingUserAction:
  7544. if ((ATerminal != Terminal) ||
  7545. (QueueInvisible && !IsQueueAutoPopup()))
  7546. {
  7547. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7548. }
  7549. break;
  7550. default:
  7551. DebugFail();
  7552. }
  7553. if (!Message.IsEmpty())
  7554. {
  7555. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7556. }
  7557. }
  7558. //---------------------------------------------------------------------------
  7559. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7560. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7561. {
  7562. if (FDDExtMapFile != NULL)
  7563. {
  7564. CloseHandle(FDDExtMapFile);
  7565. FDDExtMapFile = NULL;
  7566. }
  7567. if (WinConfiguration->DDFakeFile)
  7568. {
  7569. DDFakeFileInitDrag(FileList, Created);
  7570. }
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7574. {
  7575. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7576. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7577. {
  7578. FFakeFileDropTarget = FileName;
  7579. }
  7580. }
  7581. //---------------------------------------------------------------------------
  7582. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7583. {
  7584. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7585. if (!ForceDirectories(ApiPath(Result)))
  7586. {
  7587. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7588. }
  7589. FileSetAttr(ApiPath(Result), faHidden);
  7590. return Result;
  7591. }
  7592. //---------------------------------------------------------------------------
  7593. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7594. bool & Created)
  7595. {
  7596. FFakeFileDropTarget = UnicodeString();
  7597. FDragFakeDirectory = CreateFakeTransferDirectory();
  7598. FileList->AddItem(NULL, FDragFakeDirectory);
  7599. Created = true;
  7600. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7601. {
  7602. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7603. }
  7604. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7605. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7606. {
  7607. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7608. TDragExtCommStruct* CommStruct;
  7609. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7610. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7611. DebugAssert(CommStruct != NULL);
  7612. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7613. CommStruct->Dragging = true;
  7614. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7615. LENOF(CommStruct->DropDest));
  7616. NULL_TERMINATE(CommStruct->DropDest);
  7617. UnmapViewOfFile(CommStruct);
  7618. }
  7619. }
  7620. //---------------------------------------------------------------------------
  7621. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7622. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7623. {
  7624. bool Result;
  7625. DebugAssert(!IsLocalBrowserMode());
  7626. if (Sender == RemoteDirView)
  7627. {
  7628. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7629. }
  7630. else
  7631. {
  7632. DebugAssert(Sender == RemoteDriveView);
  7633. TStrings * FileList = RemoteDriveView->DragFileList();
  7634. try
  7635. {
  7636. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7637. }
  7638. __finally
  7639. {
  7640. delete FileList;
  7641. }
  7642. }
  7643. if (FDDTargetControl == RemoteDriveView)
  7644. {
  7645. RemoteDriveView->UpdateDropTarget();
  7646. }
  7647. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7648. // or from tree view to dir view.
  7649. // foMove happens when file/dir is dragged from remote tree view outside of
  7650. // application via dragex
  7651. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7652. (DropSourceControl == RemoteDriveView))
  7653. {
  7654. RemoteDriveView->UpdateDropSource();
  7655. }
  7656. return Result;
  7657. }
  7658. //---------------------------------------------------------------------------
  7659. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7660. {
  7661. DebugAssert(!IsLocalBrowserMode());
  7662. // This also handles drops of remote files to queue.
  7663. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7664. SAFE_DESTROY(FDDFileList);
  7665. if (!FFakeFileDropTarget.IsEmpty())
  7666. {
  7667. RemoveDir(ApiPath(FFakeFileDropTarget));
  7668. }
  7669. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7670. {
  7671. try
  7672. {
  7673. TDragResult DDResult = (Sender == RemoteDirView) ?
  7674. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7675. // Focus is moved to the target application,
  7676. // but as we are going to present the UI, we need to steal the focus back.
  7677. // This most likely won't work though (windows does not allow application
  7678. // to steal focus most of the time)
  7679. Application->BringToFront();
  7680. // On older version of Windows we never got drMove here, see also comment below.
  7681. // On Windows 10, we get the "move".
  7682. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7683. {
  7684. UnicodeString TargetDirectory;
  7685. TFileOperation Operation;
  7686. // drInvalid may mean drMove, see comment below
  7687. switch (DDResult)
  7688. {
  7689. case drCopy:
  7690. Operation = foCopy;
  7691. break;
  7692. case drMove:
  7693. Operation = foMove;
  7694. break;
  7695. default:
  7696. DebugFail();
  7697. case drInvalid:
  7698. // prefer "copy" for safety
  7699. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7700. break;
  7701. }
  7702. TTransferOperationParam Param;
  7703. UnicodeString CounterName;
  7704. bool ForceQueue;
  7705. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7706. {
  7707. // we get drInvalid both if d&d was intercepted by ddext,
  7708. // and when users drops on no-drop location.
  7709. // we tell the difference by existence of response from ddext,
  7710. // so we ignore absence of response in this case
  7711. if (DDResult != drInvalid)
  7712. {
  7713. // here we know that the extension is installed,
  7714. // as it is checked as soon as drag&drop starts from
  7715. // RemoteFileControlDDCreateDragFileList
  7716. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7717. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7718. {
  7719. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7720. }
  7721. else
  7722. {
  7723. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7724. }
  7725. }
  7726. }
  7727. else
  7728. {
  7729. // download using fake file
  7730. Param.Temp = false;
  7731. Param.DragDrop = true;
  7732. if (ForceQueue)
  7733. {
  7734. Param.Queue = asOn;
  7735. }
  7736. if (Sender == RemoteDirView)
  7737. {
  7738. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7739. }
  7740. if (RemoteFileControlFileOperation(Sender, Operation,
  7741. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7742. {
  7743. Configuration->Usage->Inc(CounterName);
  7744. }
  7745. }
  7746. }
  7747. }
  7748. __finally
  7749. {
  7750. CloseHandle(FDDExtMapFile);
  7751. FDDExtMapFile = NULL;
  7752. delete FDragFakeMonitors;
  7753. FDragFakeMonitors = NULL;
  7754. RemoveDir(ApiPath(FDragFakeDirectory));
  7755. FDragFakeDirectory = L"";
  7756. FFakeFileDropTarget = UnicodeString();
  7757. }
  7758. }
  7759. if (FDragDropSshTerminate.get() != NULL)
  7760. {
  7761. FDragDropSshTerminate->Rethrow();
  7762. }
  7763. }
  7764. //---------------------------------------------------------------------------
  7765. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7766. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7767. {
  7768. // Remember drop effect so we know (when user drops files), if we copy or move
  7769. FLastDropEffect = dwEffect;
  7770. }
  7771. //---------------------------------------------------------------------------
  7772. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7773. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7774. {
  7775. bool Result;
  7776. if (FDDTargetControl == QueueView3)
  7777. {
  7778. Directory = DefaultDownloadTargetDirectory();
  7779. Result = true;
  7780. CounterName = L"DownloadsDragDropQueue";
  7781. ForceQueue = true;
  7782. }
  7783. else if (!FFakeFileDropTarget.IsEmpty())
  7784. {
  7785. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7786. Result = true;
  7787. ForceQueue = false;
  7788. CounterName = L"DownloadsDragDropFakeFile";
  7789. }
  7790. else
  7791. {
  7792. ForceQueue = false;
  7793. Enabled = false;
  7794. try
  7795. {
  7796. int Timer = 0;
  7797. Result = false;
  7798. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7799. {
  7800. {
  7801. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7802. TDragExtCommStruct* CommStruct;
  7803. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7804. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7805. DebugAssert(CommStruct != NULL);
  7806. Result = !CommStruct->Dragging;
  7807. if (Result)
  7808. {
  7809. Directory = ExtractFilePath(CommStruct->DropDest);
  7810. CounterName = L"DownloadsDragDropExternalExt";
  7811. }
  7812. UnmapViewOfFile(CommStruct);
  7813. }
  7814. if (!Result)
  7815. {
  7816. Sleep(50);
  7817. Timer += 50;
  7818. Application->ProcessMessages();
  7819. }
  7820. }
  7821. }
  7822. __finally
  7823. {
  7824. Enabled = true;
  7825. }
  7826. }
  7827. return Result;
  7828. }
  7829. //---------------------------------------------------------------------------
  7830. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7831. const UnicodeString TempDir, int SecDelay)
  7832. {
  7833. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7834. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7835. if (FDelayedDeletionTimer == NULL)
  7836. {
  7837. DebugAssert(HandleAllocated());
  7838. FDelayedDeletionTimer = new TTimer(this);
  7839. FDelayedDeletionTimer->Interval = 10000;
  7840. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7841. }
  7842. else
  7843. {
  7844. FDelayedDeletionTimer->Enabled = true;
  7845. }
  7846. }
  7847. //---------------------------------------------------------------------------
  7848. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7849. {
  7850. DebugAssert(FDelayedDeletionList != NULL);
  7851. TDateTime N = Now();
  7852. TDateTime Alert;
  7853. UnicodeString Directory;
  7854. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7855. {
  7856. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7857. if ((N >= Alert) || (Sender == NULL))
  7858. {
  7859. Directory = FDelayedDeletionList->Strings[Index];
  7860. if (RecursiveDeleteFile(ExcludeTrailingBackslash(Directory)))
  7861. {
  7862. FDelayedDeletionList->Delete(Index);
  7863. }
  7864. }
  7865. }
  7866. if (FDelayedDeletionList->Count == 0)
  7867. {
  7868. FDelayedDeletionTimer->Enabled = false;
  7869. }
  7870. }
  7871. //---------------------------------------------------------------------------
  7872. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7873. {
  7874. DebugAssert(!IsLocalBrowserMode());
  7875. if (IsFileControl(FDDTargetControl, osRemote) ||
  7876. (FDDTargetControl == SessionsPageControl))
  7877. {
  7878. TManagedTerminal * TargetTerminal = NULL;
  7879. TFileOperation Operation = foNone;
  7880. if (FDDTargetControl == SessionsPageControl)
  7881. {
  7882. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7883. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7884. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7885. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7886. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7887. {
  7888. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7889. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7890. {
  7891. Operation = foRemoteMove;
  7892. }
  7893. else
  7894. {
  7895. Operation = foRemoteCopy;
  7896. }
  7897. }
  7898. }
  7899. else
  7900. {
  7901. if (FLastDropEffect == DROPEFFECT_MOVE)
  7902. {
  7903. Operation = foRemoteMove;
  7904. }
  7905. else if (FLastDropEffect == DROPEFFECT_COPY)
  7906. {
  7907. Operation = foRemoteCopy;
  7908. }
  7909. }
  7910. if (Operation != foNone)
  7911. {
  7912. RemoteFileControlFileOperation(DropSourceControl,
  7913. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7914. }
  7915. // abort drag&drop
  7916. Abort();
  7917. }
  7918. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7919. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7920. (FDDTargetControl != QueueView3))
  7921. {
  7922. DebugAssert(!FDragTempDir.IsEmpty());
  7923. TTransferType Type;
  7924. UnicodeString TempDir = FDragTempDir;
  7925. // We clear FDragTempDir before calling
  7926. // just in case it fail (raises exception)
  7927. FDragTempDir = L"";
  7928. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7929. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7930. // empty directory parameter means temp directory -> don't display it!
  7931. UnicodeString TargetDir = L"";
  7932. int Options = 0;
  7933. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7934. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7935. {
  7936. Abort();
  7937. }
  7938. // TargetDir is set when dropped on local file control
  7939. // (this was workaround for legacy dirview event handling, now it should be
  7940. // made prettier)
  7941. if (TargetDir.IsEmpty())
  7942. {
  7943. TargetDir = TempDir;
  7944. if (ForceDirectories(ApiPath(TargetDir)))
  7945. {
  7946. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7947. FPendingTempSpaceWarn = true;
  7948. try
  7949. {
  7950. FDragDropOperation = true;
  7951. int Params = cpTemporary |
  7952. (Type == ttMove ? cpDelete : 0);
  7953. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7954. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7955. }
  7956. __finally
  7957. {
  7958. FDragDropOperation = false;
  7959. FPendingTempSpaceWarn = false;
  7960. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7961. }
  7962. }
  7963. else
  7964. {
  7965. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7966. }
  7967. }
  7968. }
  7969. }
  7970. //---------------------------------------------------------------------------
  7971. void __fastcall TCustomScpExplorerForm::DDDownload(
  7972. TStrings * FilesToCopy, const UnicodeString & TargetDir, TCopyParamType * CopyParam, int Params)
  7973. {
  7974. DebugAssert(!IsLocalBrowserMode());
  7975. TAutoBatch AutoBatch(this);
  7976. CopyParam->IncludeFileMask.SetRoots(TargetDir, FilesToCopy);
  7977. UpdateCopyParamCounters(*CopyParam);
  7978. FMoveToQueue = false;
  7979. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7980. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7981. {
  7982. RemoteDriveView->UpdateDropSource();
  7983. }
  7984. }
  7985. //---------------------------------------------------------------------------
  7986. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7987. {
  7988. public:
  7989. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7990. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7991. {
  7992. }
  7993. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7994. {
  7995. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7996. TDataObjectFilesEx::AllowData(FormatEtc);
  7997. }
  7998. };
  7999. //---------------------------------------------------------------------------
  8000. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  8001. TObject * Sender, TDataObject *& DataObject)
  8002. {
  8003. if (FDDExtMapFile != NULL)
  8004. {
  8005. TFileList * FileList = DragDropFiles(Sender)->FileList;
  8006. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  8007. {
  8008. Abort();
  8009. }
  8010. if (FileList->Count > 0)
  8011. {
  8012. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  8013. if (!FilesObject->IsValid(true, true))
  8014. {
  8015. FilesObject->_Release();
  8016. }
  8017. else
  8018. {
  8019. DataObject = FilesObject;
  8020. }
  8021. }
  8022. }
  8023. }
  8024. //---------------------------------------------------------------------------
  8025. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  8026. {
  8027. DebugFail();
  8028. }
  8029. //---------------------------------------------------------------------------
  8030. void __fastcall TCustomScpExplorerForm::GoToTree()
  8031. {
  8032. ComponentVisible[fcRemoteTree] = true;
  8033. DriveView(osRemote)->SetFocus();
  8034. }
  8035. //---------------------------------------------------------------------------
  8036. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8037. TPanelExport Export)
  8038. {
  8039. TCustomDirView * DirView = this->DirView(Side);
  8040. std::unique_ptr<TStrings> ExportData(new TStringList());
  8041. switch (Export)
  8042. {
  8043. case pePath:
  8044. ExportData->Add(DirView->PathName);
  8045. break;
  8046. case peFileList:
  8047. case peFullFileList:
  8048. {
  8049. bool FullPath = (Export == peFullFileList);
  8050. DirView->CreateFileList(false, FullPath, ExportData.get());
  8051. for (int Index = 0; Index < ExportData->Count; Index++)
  8052. {
  8053. if (ExportData->Strings[Index].Pos(L" ") > 0)
  8054. {
  8055. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  8056. }
  8057. }
  8058. }
  8059. break;
  8060. default:
  8061. DebugFail();
  8062. }
  8063. return ExportData.release();
  8064. }
  8065. //---------------------------------------------------------------------------
  8066. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8067. TPanelExport Export, TPanelExportDestination Destination)
  8068. {
  8069. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  8070. PanelExportStore(Side, Export, Destination, ExportData.get());
  8071. }
  8072. //---------------------------------------------------------------------------
  8073. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  8074. TPanelExport /*Export*/, TPanelExportDestination Destination,
  8075. TStrings * ExportData)
  8076. {
  8077. if (Destination == pedClipboard)
  8078. {
  8079. TInstantOperationVisualizer Visualizer;
  8080. CopyToClipboard(ExportData);
  8081. }
  8082. else
  8083. {
  8084. DebugFail();
  8085. }
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  8089. {
  8090. TCustomDirView * DirView = this->DirView(Side);
  8091. UnicodeString Mask = DirView->Mask;
  8092. if (DoFilterMaskDialog(DirView, Mask))
  8093. {
  8094. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  8095. Configuration->Usage->Inc(L"Filters");
  8096. }
  8097. }
  8098. //---------------------------------------------------------------------------
  8099. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  8100. {
  8101. return FQueueController->DefaultOperation();
  8102. }
  8103. //---------------------------------------------------------------------------
  8104. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  8105. TQueueOperation Operation, void ** Param)
  8106. {
  8107. switch (Operation)
  8108. {
  8109. case qoPreferences:
  8110. return true;
  8111. case qoGoTo:
  8112. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  8113. case qoOnceEmpty:
  8114. return IsAnythingQueued();
  8115. default:
  8116. return FQueueController->AllowOperation(Operation, Param);
  8117. }
  8118. }
  8119. //---------------------------------------------------------------------------
  8120. void __fastcall TCustomScpExplorerForm::GoToQueue()
  8121. {
  8122. if (DebugAlwaysTrue(QueueView3->Visible))
  8123. {
  8124. QueueView3->SetFocus();
  8125. }
  8126. }
  8127. //---------------------------------------------------------------------------
  8128. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  8129. TQueueOperation Operation, void * Param)
  8130. {
  8131. if (Operation == qoGoTo)
  8132. {
  8133. GoToQueue();
  8134. }
  8135. else if (Operation == qoPreferences)
  8136. {
  8137. PreferencesDialog(pmQueue);
  8138. }
  8139. else
  8140. {
  8141. FQueueController->ExecuteOperation(Operation, Param);
  8142. }
  8143. }
  8144. //---------------------------------------------------------------------------
  8145. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  8146. {
  8147. return (Queue != NULL) && Queue->Enabled;
  8148. }
  8149. //---------------------------------------------------------------------------
  8150. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  8151. {
  8152. DebugAssert(Queue != NULL);
  8153. if (Queue != NULL)
  8154. {
  8155. Queue->Enabled = !Queue->Enabled;
  8156. }
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  8160. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  8161. {
  8162. FQueueActedItem = QueueView3->ItemFocused;
  8163. }
  8164. //---------------------------------------------------------------------------
  8165. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  8166. {
  8167. return TopDock->Height + (MessageDock->Visible ? MessageDock->Height : 0) + QueueSplitter->Height;
  8168. }
  8169. //---------------------------------------------------------------------------
  8170. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  8171. {
  8172. return
  8173. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  8174. (QueueDock->Visible ? QueueDock->Height : 0) +
  8175. (QueueLabel->Visible ? QueueLabel->Height : 0);
  8176. }
  8177. //---------------------------------------------------------------------------
  8178. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  8179. {
  8180. return ScaleByTextHeight(this, 48);
  8181. }
  8182. //---------------------------------------------------------------------------
  8183. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  8184. TObject * /*Sender*/, int & NewSize, bool & Accept)
  8185. {
  8186. // when queue is hidden by double-clicking splitter, stray attempt to
  8187. // resize the panel with strange value arrives, make sure it is ignored
  8188. if (ComponentVisible[fcQueueView])
  8189. {
  8190. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  8191. if (NewSize > MaxHeightLimit)
  8192. {
  8193. NewSize = MaxHeightLimit;
  8194. }
  8195. int MinHeightLimit =
  8196. GetStaticQueuePanelComponentsHeight() +
  8197. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  8198. GetMinQueueViewHeight();
  8199. if (NewSize < MinHeightLimit)
  8200. {
  8201. NewSize = MinHeightLimit;
  8202. }
  8203. }
  8204. else
  8205. {
  8206. Accept = false;
  8207. }
  8208. }
  8209. //---------------------------------------------------------------------------
  8210. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  8211. {
  8212. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  8213. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  8214. if (QueueViewHeight < GetMinQueueViewHeight())
  8215. {
  8216. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  8217. }
  8218. }
  8219. //---------------------------------------------------------------------------
  8220. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  8221. TDragObject *& /*DragObject*/)
  8222. {
  8223. FQueueActedItem = QueueView3->ItemFocused;
  8224. FQueueScrollOnDragOver->StartDrag();
  8225. }
  8226. //---------------------------------------------------------------------------
  8227. void __fastcall TCustomScpExplorerForm::QueueView3EndDrag(
  8228. TObject *, TObject * DebugUsedArg(Target), int DebugUsedArg(X), int DebugUsedArg(Y))
  8229. {
  8230. FQueueScrollOnDragOver->EndDrag();
  8231. }
  8232. //---------------------------------------------------------------------------
  8233. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  8234. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  8235. {
  8236. Accept = true;
  8237. if (Source == QueueView3)
  8238. {
  8239. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  8240. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  8241. if (Accept)
  8242. {
  8243. TQueueItemProxy * QueueItem;
  8244. TQueueItemProxy * DestQueueItem;
  8245. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8246. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  8247. Accept = (QueueItem != DestQueueItem) &&
  8248. (QueueItem->Status == TQueueItem::qsPending) &&
  8249. (DestQueueItem->Status == TQueueItem::qsPending);
  8250. }
  8251. FQueueScrollOnDragOver->DragOver(TPoint(X, Y));
  8252. }
  8253. }
  8254. //---------------------------------------------------------------------------
  8255. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  8256. TObject * /*Source*/, int /*X*/, int /*Y*/)
  8257. {
  8258. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  8259. {
  8260. TQueueItemProxy * QueueItem;
  8261. TQueueItemProxy * DestQueueItem;
  8262. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8263. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  8264. QueueItem->Move(DestQueueItem);
  8265. }
  8266. }
  8267. //---------------------------------------------------------------------------
  8268. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  8269. {
  8270. if ((QueueView3->ItemFocused == NULL) &&
  8271. (QueueView3->Items->Count > 0))
  8272. {
  8273. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  8274. }
  8275. QueueLabelUpdateStatus();
  8276. }
  8277. //---------------------------------------------------------------------------
  8278. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  8279. {
  8280. QueueLabelUpdateStatus();
  8281. }
  8282. //---------------------------------------------------------------------------
  8283. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  8284. {
  8285. QueueLabel->UpdateStatus();
  8286. }
  8287. //---------------------------------------------------------------------------
  8288. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  8289. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  8290. {
  8291. if (Selected)
  8292. {
  8293. NonVisualDataModule->UpdateNonVisibleActions();
  8294. }
  8295. }
  8296. //---------------------------------------------------------------------------
  8297. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  8298. {
  8299. TDragDropFilesEx * Result = NULL;
  8300. if (Sender == SessionsPageControl)
  8301. {
  8302. Result = FSessionsDragDropFilesEx;
  8303. }
  8304. else if (Sender == QueueView3)
  8305. {
  8306. Result = FQueueDragDropFilesEx;
  8307. }
  8308. else
  8309. {
  8310. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8311. if (DirView != NULL)
  8312. {
  8313. Result = DirView->DragDropFilesEx;
  8314. }
  8315. else
  8316. {
  8317. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  8318. if (DriveView != NULL)
  8319. {
  8320. Result = DriveView->DragDropFilesEx;
  8321. }
  8322. }
  8323. }
  8324. DebugAssert(Result != NULL);
  8325. return Result;
  8326. }
  8327. //---------------------------------------------------------------------------
  8328. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  8329. {
  8330. return (DView->SelCount == DView->FilesCount);
  8331. }
  8332. //---------------------------------------------------------------------------
  8333. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  8334. {
  8335. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  8336. }
  8337. //---------------------------------------------------------------------------
  8338. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  8339. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  8340. {
  8341. DebugAssert(!IsLocalBrowserMode());
  8342. TFileOperation Operation;
  8343. switch (Effect)
  8344. {
  8345. case DROPEFFECT_MOVE:
  8346. Operation = foMove;
  8347. break;
  8348. case DROPEFFECT_COPY:
  8349. // occures on WinXP (reported by user)
  8350. default:
  8351. Operation = foCopy;
  8352. break;
  8353. };
  8354. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  8355. // see a comment in TUnixDirView::PerformItemDragDropOperation
  8356. if (DragDropFilesEx->FileList->Count > 0)
  8357. {
  8358. TStrings * FileList = new TStringList();
  8359. try
  8360. {
  8361. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  8362. {
  8363. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  8364. }
  8365. FDragDropOperation = true;
  8366. TTransferOperationParam Param;
  8367. Param.TargetDirectory = TargetPath;
  8368. // upload, no temp dirs
  8369. Param.Temp = false;
  8370. Param.DragDrop = DragDrop;
  8371. Param.Options =
  8372. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  8373. if (ForceQueue)
  8374. {
  8375. Param.Queue = asOn;
  8376. }
  8377. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  8378. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  8379. {
  8380. if (IsFileControl(DropSourceControl, osLocal))
  8381. {
  8382. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  8383. }
  8384. else
  8385. {
  8386. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  8387. }
  8388. }
  8389. }
  8390. __finally
  8391. {
  8392. FDragDropOperation = false;
  8393. delete FileList;
  8394. }
  8395. }
  8396. }
  8397. //---------------------------------------------------------------------------
  8398. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  8399. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  8400. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  8401. {
  8402. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  8403. }
  8404. //---------------------------------------------------------------------------
  8405. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  8406. TObject * Sender, int grfKeyState, int & dwEffect)
  8407. {
  8408. DebugAssert(!IsLocalBrowserMode());
  8409. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  8410. if ((dwEffect != DROPEFFECT_NONE) &&
  8411. IsFileControl(DropSourceControl, osRemote))
  8412. {
  8413. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8414. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8415. (RemoteDirView->DropTarget == NULL))
  8416. {
  8417. dwEffect = DROPEFFECT_NONE;
  8418. }
  8419. else
  8420. {
  8421. if (dwEffect == DROPEFFECT_COPY)
  8422. {
  8423. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8424. // currently we support copying always (at least via temporary directory);
  8425. // remove associated checks once this all proves stable and working
  8426. bool CopyCapable = true;
  8427. // if we do not support neither of operations, there's no discussion
  8428. if (!MoveCapable && !CopyCapable)
  8429. {
  8430. dwEffect = DROPEFFECT_NONE;
  8431. }
  8432. else
  8433. {
  8434. // The default effect inside remote panel is move,
  8435. // unless we do not support it, but support copy
  8436. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8437. {
  8438. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8439. }
  8440. else
  8441. {
  8442. // with ctrl-down, we want copy unless it is not supported
  8443. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8444. }
  8445. }
  8446. }
  8447. }
  8448. }
  8449. }
  8450. //---------------------------------------------------------------------------
  8451. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8452. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8453. {
  8454. DebugAssert(!IsLocalBrowserMode());
  8455. if (FDDTotalSize >= 0)
  8456. {
  8457. if (File->IsDirectory)
  8458. {
  8459. FDDTotalSize = -1;
  8460. }
  8461. else
  8462. {
  8463. FDDTotalSize += File->Size;
  8464. }
  8465. }
  8466. DebugAssert(!FDragTempDir.IsEmpty());
  8467. // TODO: this is quite ineffective
  8468. // TODO: what if invalid character replacement is disabled?
  8469. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8470. UnicodeString TransferFileName;
  8471. if (Sender == RemoteDriveView)
  8472. {
  8473. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8474. }
  8475. else
  8476. {
  8477. TransferFileName = File->FileName;
  8478. }
  8479. FDDFileList->AddObject(TransferFileName, File);
  8480. }
  8481. //---------------------------------------------------------------------------
  8482. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8483. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8484. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8485. {
  8486. // sometimes we do not get DDEnd so the list is not released
  8487. SAFE_DESTROY(FDDFileList);
  8488. FDDFileList = new TStringList();
  8489. FDragTempDir = WinConfiguration->TemporaryDir();
  8490. FDDTotalSize = 0;
  8491. FDragDropSshTerminate.reset(NULL);
  8492. }
  8493. //---------------------------------------------------------------------------
  8494. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8495. TObject * /*Sender*/, LongBool /*FEscapePressed*/, int /*grfKeyState*/,
  8496. HRESULT & Result)
  8497. {
  8498. if (Result == DRAGDROP_S_DROP)
  8499. {
  8500. try
  8501. {
  8502. GlobalDragImageList->HideDragImage();
  8503. try
  8504. {
  8505. RemoteFileControlDDTargetDrop();
  8506. }
  8507. catch(ESshTerminate & E)
  8508. {
  8509. FDragDropSshTerminate.reset(E.Clone());
  8510. }
  8511. }
  8512. catch (Exception &E)
  8513. {
  8514. // If downloading fails we need to cancel drag&drop, otherwise
  8515. // Explorer shows error
  8516. // But by the way exception probably never reach this point as
  8517. // it's catched on way.
  8518. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8519. Result = DRAGDROP_S_CANCEL;
  8520. ShowExtendedException(Terminal, &E);
  8521. }
  8522. }
  8523. }
  8524. //---------------------------------------------------------------------------
  8525. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8526. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8527. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8528. {
  8529. TFileMasks::TParams MaskParams;
  8530. MaskParams.Size = Size;
  8531. MaskParams.Modification = Modification;
  8532. // this does not re-parse the mask if it is the same as the last time
  8533. FDirViewMatchMask = Masks;
  8534. bool ImplicitMatch;
  8535. Matches =
  8536. // Local and RecurseInclude parameters have no effect as there's no path.
  8537. // This should use potential MatchesFileName overload with ImplicitMatch argument.
  8538. FDirViewMatchMask.Matches(FileName, false, Directory, &MaskParams, true, ImplicitMatch) &&
  8539. (AllowImplicitMatches || !ImplicitMatch);
  8540. }
  8541. //---------------------------------------------------------------------------
  8542. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8543. TObject * Sender, TListItem * Item, WORD & Indexes)
  8544. {
  8545. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8546. if (GetPartialFileExtLen(DirView->ItemFileName(Item)) > 0)
  8547. {
  8548. Indexes |= oiPartial;
  8549. }
  8550. }
  8551. //---------------------------------------------------------------------------
  8552. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8553. {
  8554. return
  8555. DirViewEnabled(osCurrent) &&
  8556. DirView(osCurrent)->CanPasteFromClipBoard();
  8557. }
  8558. //---------------------------------------------------------------------------
  8559. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8560. {
  8561. bool Result = false;
  8562. if (CanPasteToDirViewFromClipBoard())
  8563. {
  8564. Result = true;
  8565. }
  8566. else
  8567. {
  8568. UnicodeString ClipboardText;
  8569. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8570. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8571. {
  8572. if (StoredSessions->IsUrl(ClipboardText))
  8573. {
  8574. Result = true;
  8575. }
  8576. else
  8577. {
  8578. Result = DirViewEnabled(osCurrent);
  8579. }
  8580. }
  8581. }
  8582. return Result;
  8583. }
  8584. //---------------------------------------------------------------------------
  8585. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8586. {
  8587. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8588. if (DoesClipboardContainOurFiles())
  8589. {
  8590. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8591. {
  8592. DebugAssert(!IsLocalBrowserMode());
  8593. TTerminalManager * Manager = TTerminalManager::Instance();
  8594. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8595. Manager->ActiveSession = FClipboardTerminal;
  8596. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8597. }
  8598. }
  8599. else if (CanPasteToDirViewFromClipBoard())
  8600. {
  8601. DirView(osCurrent)->PasteFromClipBoard();
  8602. }
  8603. else
  8604. {
  8605. UnicodeString ClipboardText;
  8606. if (NonEmptyTextFromClipboard(ClipboardText))
  8607. {
  8608. if (StoredSessions->IsUrl(ClipboardText))
  8609. {
  8610. NewSession(ClipboardText);
  8611. }
  8612. else
  8613. {
  8614. DirView(osCurrent)->Path = ClipboardText;
  8615. }
  8616. }
  8617. }
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8621. {
  8622. // TBD
  8623. }
  8624. //---------------------------------------------------------------------------
  8625. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8626. {
  8627. TCustomDirView * ADirView = DirView(Side);
  8628. ADirView->SelectAll(Mode);
  8629. ADirView->SetFocus();
  8630. }
  8631. //---------------------------------------------------------------------------
  8632. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8633. {
  8634. TCustomDirView * ADirView = DirView(Side);
  8635. TFileFilter Filter;
  8636. DefaultFileFilter(Filter);
  8637. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8638. {
  8639. Configuration->Usage->Inc(L"MaskSelections");
  8640. ADirView->SelectFiles(Filter, Select);
  8641. ADirView->SetFocus();
  8642. }
  8643. }
  8644. //---------------------------------------------------------------------------
  8645. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8646. {
  8647. TCustomDirView * ADirView = DirView(Side);
  8648. ADirView->RestoreSelectedNames();
  8649. ADirView->SetFocus();
  8650. }
  8651. //---------------------------------------------------------------------------
  8652. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8653. {
  8654. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8655. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8656. {
  8657. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8658. UnicodeString Ext;
  8659. if (!IsSideLocalBrowser(osCurrent))
  8660. {
  8661. Ext = UnixExtractFileExt(FileName);
  8662. }
  8663. else
  8664. {
  8665. Ext = ExtractFileExt(FileName);
  8666. }
  8667. if (Ext.IsEmpty())
  8668. {
  8669. Ext = L".";
  8670. }
  8671. TFileFilter Filter;
  8672. Filter.Masks = FORMAT(L"*%s", (Ext));
  8673. Filter.Directories = false;
  8674. CurrentDirView->SelectFiles(Filter, Select);
  8675. }
  8676. }
  8677. //---------------------------------------------------------------------------
  8678. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8679. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8680. {
  8681. UnicodeString Result;
  8682. if (FIncrementalSearchState.Searching && (Side == GetSide(osCurrent)))
  8683. {
  8684. Result = FormatIncrementalSearchStatus(FIncrementalSearchState);
  8685. }
  8686. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8687. {
  8688. // noop
  8689. }
  8690. else
  8691. {
  8692. Result =
  8693. FMTLOAD(FILE_INFO_FORMAT,
  8694. (FormatBytes(FileInfo.SelectedSize),
  8695. FormatBytes(FileInfo.FilesSize),
  8696. FormatNumber(FileInfo.SelectedCount),
  8697. FormatNumber(FileInfo.FilesCount)));
  8698. }
  8699. return Result;
  8700. }
  8701. //---------------------------------------------------------------------------
  8702. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8703. TTBXStatusPanel * Panel, TOperationSide Side)
  8704. {
  8705. if (Panel->Index == 1)
  8706. {
  8707. ToggleShowHiddenFiles();
  8708. }
  8709. else if (Panel->Index == 2)
  8710. {
  8711. Filter(Side);
  8712. }
  8713. }
  8714. //---------------------------------------------------------------------------
  8715. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8716. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8717. {
  8718. DebugAssert(!StatusBar->SimplePanel);
  8719. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8720. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8721. }
  8722. //---------------------------------------------------------------------------
  8723. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8724. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8725. {
  8726. DebugAssert(StatusBar->Panels->Count >= 3);
  8727. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8728. if (FileInfo.HiddenCount > 0)
  8729. {
  8730. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8731. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8732. }
  8733. else
  8734. {
  8735. HiddenFilesPanel->ViewPriority = 0;
  8736. // not really necessary, just to cleanup no-longer-valid data
  8737. HiddenFilesPanel->Caption = L"";
  8738. }
  8739. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8740. if (FileInfo.FilteredCount > 0)
  8741. {
  8742. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8743. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8744. }
  8745. else
  8746. {
  8747. FilteredFilesPanel->ViewPriority = 0;
  8748. // not really necessary, just to cleanup no-longer-valid data
  8749. FilteredFilesPanel->Caption = L"";
  8750. }
  8751. }
  8752. //---------------------------------------------------------------------------
  8753. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8754. TObject * /*Sender*/)
  8755. {
  8756. if (DirView(osOther)->Enabled)
  8757. {
  8758. DirView(osOther)->SetFocus();
  8759. }
  8760. }
  8761. //---------------------------------------------------------------------------
  8762. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8763. {
  8764. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8765. switch (Config.Show)
  8766. {
  8767. case qvShow:
  8768. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8769. {
  8770. Config.Show = qvHide;
  8771. }
  8772. else
  8773. {
  8774. Config.Show = Config.LastHideShow;
  8775. }
  8776. break;
  8777. case qvHideWhenEmpty:
  8778. if (ComponentVisible[fcQueueView])
  8779. {
  8780. Config.Show = qvHide;
  8781. }
  8782. else
  8783. {
  8784. Config.LastHideShow = Config.Show;
  8785. Config.Show = qvShow;
  8786. }
  8787. break;
  8788. case qvHide:
  8789. Config.LastHideShow = Config.Show;
  8790. Config.Show = qvShow;
  8791. break;
  8792. }
  8793. WinConfiguration->QueueView = Config;
  8794. }
  8795. //---------------------------------------------------------------------------
  8796. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8797. {
  8798. UnicodeString Result;
  8799. if (Terminal != NULL)
  8800. {
  8801. switch (WinConfiguration->PathInCaption)
  8802. {
  8803. case picShort:
  8804. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8805. break;
  8806. case picFull:
  8807. Result = Terminal->CurrentDirectory;
  8808. break;
  8809. }
  8810. }
  8811. return Result;
  8812. }
  8813. //---------------------------------------------------------------------------
  8814. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8815. {
  8816. TColor Result = GetWindowColor(FSessionColor);
  8817. return Result;
  8818. }
  8819. //---------------------------------------------------------------------------
  8820. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8821. {
  8822. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8823. return Result;
  8824. }
  8825. //---------------------------------------------------------------------------
  8826. void TCustomScpExplorerForm::UpdatePanelControls(TCustomDirView * ADirView, TCustomDriveView * ADriveView)
  8827. {
  8828. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8829. ADirView->DarkMode = UseDarkTheme;
  8830. ADriveView->DarkMode = UseDarkTheme;
  8831. }
  8832. //---------------------------------------------------------------------------
  8833. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8834. {
  8835. if (!FSessionChanging)
  8836. {
  8837. TTerminalManager::Instance()->UpdateAppTitle();
  8838. }
  8839. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8840. // background to gray on Windows 7 (works on Windows 10).
  8841. // See also EnableControl
  8842. if (Showing)
  8843. {
  8844. if (ManagedSession != NULL)
  8845. {
  8846. // Update path when it changes
  8847. if ((SessionsPageControl->ActivePage != NULL) &&
  8848. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8849. {
  8850. UpdateSessionTab(SessionsPageControl->ActivePage);
  8851. }
  8852. }
  8853. NonVisualDataModule->ReconnectSessionAction->Update();
  8854. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8855. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8856. CenterReconnectToolbar();
  8857. bool HasTerminal = HasActiveTerminal();
  8858. RemoteDirView->Enabled = HasTerminal;
  8859. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8860. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8861. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8862. RemoteDriveView->Color = RemoteDirView->Color;
  8863. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8864. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8865. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8866. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8867. QueueFileList->Enabled = QueueView3->Enabled;
  8868. QueueFileList->Color = QueueView3->Color;
  8869. QueueFileList->Font->Color = QueueView3->Font->Color;
  8870. QueueLabelUpdateStatus();
  8871. UpdatePanelControls(RemoteDirView, RemoteDriveView);
  8872. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8873. if (FImmersiveDarkMode != UseDarkTheme)
  8874. {
  8875. UpdateDarkMode();
  8876. }
  8877. SessionsPageControl->TabTheme = UseDarkTheme ? CurrentTheme : NULL;
  8878. UnicodeString CurrentHiContrastThemeName = (FHiContrastTheme != NULL) ? FHiContrastTheme->Name : EmptyStr;
  8879. bool HiContrast = WinConfiguration->HiContrast;
  8880. UnicodeString NewHiContrastThemeName = HiContrast ? GetThemeName(!UseDarkTheme) : EmptyStr;
  8881. if (CurrentHiContrastThemeName != NewHiContrastThemeName)
  8882. {
  8883. ReleaseHiContrastTheme();
  8884. if (!NewHiContrastThemeName.IsEmpty())
  8885. {
  8886. FHiContrastTheme = GetTBXTheme(NewHiContrastThemeName);
  8887. }
  8888. }
  8889. SessionsPageControl->ActiveTabTheme = HiContrast ? DebugNotNull(FHiContrastTheme) : NULL;
  8890. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8891. MessageDock->Visible = (MessageDock->ToolbarCount > 0);
  8892. }
  8893. }
  8894. //---------------------------------------------------------------------------
  8895. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8896. {
  8897. UpdateControls();
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8901. TObject * Sender)
  8902. {
  8903. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8904. DebugAssert(DirView != NULL);
  8905. DoDirViewLoaded(DirView);
  8906. TransferPresetAutoSelect();
  8907. TUnixDirView * UnixDirView = dynamic_cast<TUnixDirView *>(DirView);
  8908. if (UnixDirView != NULL)
  8909. {
  8910. TManagedTerminal * ATerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(UnixDirView->Terminal));
  8911. TTerminalManager::Instance()->TerminalLoadedDirectory(ATerminal);
  8912. }
  8913. }
  8914. //---------------------------------------------------------------------------
  8915. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8916. {
  8917. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8918. // first run after installation
  8919. if (double(Updates.LastCheck) == 0)
  8920. {
  8921. AppLog(L"First run, scheduling updates check for the next run");
  8922. // make sure next time there will be an update (if enabled)
  8923. Updates.LastCheck = TDateTime(1);
  8924. WinConfiguration->Updates = Updates;
  8925. }
  8926. else
  8927. {
  8928. TDateTime Period;
  8929. if (IsUWP() && !IsOfficialPackage())
  8930. {
  8931. Period = DefaultUpdatesPeriod;
  8932. AppLog(L"Thirdparty UWP package, using default updates check period");
  8933. }
  8934. else
  8935. {
  8936. Period = Updates.Period;
  8937. }
  8938. AppLogFmt(L"Updates check period: %.2f", (double(Period)));
  8939. if (double(Period) > 0)
  8940. {
  8941. TDateTime Interval = Now() - Updates.LastCheck;
  8942. AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
  8943. if (Interval >= Period)
  8944. {
  8945. StartUpdateThread(UpdatesChecked);
  8946. }
  8947. }
  8948. }
  8949. }
  8950. //---------------------------------------------------------------------------
  8951. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8952. {
  8953. AppLog(L"Updates check done");
  8954. UnicodeString Message;
  8955. bool New;
  8956. TQueryType Type;
  8957. GetUpdatesMessage(Message, New, Type, false);
  8958. if (!Message.IsEmpty())
  8959. {
  8960. AppLogFmt(L"Updates check message: %s", (Message));
  8961. if (New)
  8962. {
  8963. AppLog(L"New version detected");
  8964. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8965. }
  8966. if (!New && (Type != qtWarning))
  8967. {
  8968. AppLog(L"Posting non-critical updates note");
  8969. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8970. }
  8971. else
  8972. {
  8973. AppLog(L"Posting new version or critical message notification");
  8974. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8975. }
  8976. if (New)
  8977. {
  8978. Configuration->Usage->Inc(L"UpdateNotifications");
  8979. }
  8980. }
  8981. }
  8982. //---------------------------------------------------------------------------
  8983. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8984. {
  8985. RestoreApp();
  8986. bool CanDisplay = !NonVisualDataModule->Busy;
  8987. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8988. {
  8989. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8990. }
  8991. if (CanDisplay)
  8992. {
  8993. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8994. // Probably not needed as CheckForUpdates is blocking since we started using neon for HTTP implementation.
  8995. NonVisualDataModule->StartBusy();
  8996. try
  8997. {
  8998. CheckForUpdates(true);
  8999. }
  9000. __finally
  9001. {
  9002. NonVisualDataModule->EndBusy();
  9003. }
  9004. }
  9005. else
  9006. {
  9007. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  9008. }
  9009. }
  9010. //---------------------------------------------------------------------------
  9011. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  9012. TCopyParamRuleData & Data)
  9013. {
  9014. DebugAssert(Terminal != NULL);
  9015. Data.HostName = Terminal->SessionData->HostNameExpanded;
  9016. Data.UserName = Terminal->SessionData->UserNameExpanded;
  9017. Data.RemoteDirectory = RemoteDirView->PathName;
  9018. }
  9019. //---------------------------------------------------------------------------
  9020. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  9021. {
  9022. // Terminal can be null when we are changing local directory implicitly,
  9023. // because it has been deleted, while no session is connected
  9024. // (Login dialog is open)
  9025. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  9026. {
  9027. DebugAssert(!IsLocalBrowserMode());
  9028. TCopyParamRuleData Data;
  9029. GetTransferPresetAutoSelectData(Data);
  9030. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  9031. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  9032. if (CopyParamIndex < 0)
  9033. {
  9034. // there is no preset that matches autoselection
  9035. // set preset that we consider "default"
  9036. FCopyParamAutoSelected = L""; // forget last autoselected preset
  9037. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  9038. }
  9039. else
  9040. {
  9041. // there is preset matching autoselection
  9042. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  9043. if (CopyParamName == FCopyParamAutoSelected)
  9044. {
  9045. // autoselected the same preset as the last time
  9046. // make no change (i.e. preserve custom user preset, if any)
  9047. }
  9048. else
  9049. {
  9050. // autoselected the different preset then the last time (or there
  9051. // was default preset set)
  9052. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  9053. GUIConfiguration->CopyParamCurrent = CopyParamName;
  9054. }
  9055. }
  9056. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  9057. {
  9058. if (CopyParamIndex >= 0)
  9059. {
  9060. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  9061. }
  9062. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  9063. try
  9064. {
  9065. int Fmt =
  9066. (CopyParamIndex < 0) ?
  9067. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  9068. COPY_PARAM_AUTOSELECTED;
  9069. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  9070. Data->Message = MainInstructions(Message);
  9071. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  9072. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  9073. CopyParamAttrs);
  9074. if (CopyParamIndex >= 0)
  9075. {
  9076. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  9077. Info = FORMAT(L"%s\n \n%s", (Info,
  9078. FMTLOAD(COPY_PARAM_RULE,
  9079. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  9080. }
  9081. Data->Message += L"\n\n" + Info;
  9082. if (WinConfiguration->CopyParamAutoSelectNotice)
  9083. {
  9084. TransferPresetNoteMessage(Data, true);
  9085. }
  9086. else
  9087. {
  9088. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  9089. Data = NULL; // ownership passed
  9090. }
  9091. }
  9092. __finally
  9093. {
  9094. delete Data;
  9095. }
  9096. }
  9097. }
  9098. }
  9099. //---------------------------------------------------------------------------
  9100. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  9101. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  9102. {
  9103. DebugAssert(NoteData != NULL);
  9104. DebugAssert(!IsLocalBrowserMode());
  9105. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  9106. TQueryButtonAlias Aliases[1];
  9107. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  9108. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  9109. Params.Aliases = Aliases;
  9110. Params.AliasesCount = LENOF(Aliases);
  9111. unsigned int Result =
  9112. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  9113. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  9114. switch (Result)
  9115. {
  9116. case qaNeverAskAgain:
  9117. DebugAssert(AllowNeverAskAgain);
  9118. WinConfiguration->CopyParamAutoSelectNotice = false;
  9119. break;
  9120. case qaIgnore:
  9121. PreferencesDialog(pmPresets);
  9122. break;
  9123. }
  9124. }
  9125. //---------------------------------------------------------------------------
  9126. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  9127. {
  9128. // as of now useless, as this is used for notes only, never for balloons, ...
  9129. RestoreApp();
  9130. // .. and we should never be busy here
  9131. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  9132. {
  9133. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  9134. }
  9135. }
  9136. //---------------------------------------------------------------------------
  9137. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  9138. TPreferencesMode APreferencesMode)
  9139. {
  9140. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  9141. TCopyParamRuleData Data;
  9142. if (Terminal != NULL)
  9143. {
  9144. PreferencesData.reset(new TPreferencesDialogData());
  9145. GetTransferPresetAutoSelectData(Data);
  9146. PreferencesData->CopyParamRuleData = &Data;
  9147. }
  9148. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  9149. }
  9150. //---------------------------------------------------------------------------
  9151. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  9152. const TCustomCommandType & Command)
  9153. {
  9154. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  9155. {
  9156. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  9157. }
  9158. }
  9159. //---------------------------------------------------------------------------
  9160. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  9161. {
  9162. bool RemoteAllowed = CustomCommandRemoteAllowed();
  9163. TCustomCommandType Command;
  9164. // make sure we use local custom command when remote are not supported
  9165. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  9166. {
  9167. Command = FLastCustomCommand;
  9168. }
  9169. else
  9170. {
  9171. Command.Params = Command.Params | ccLocal;
  9172. }
  9173. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  9174. FEditingFocusedAdHocCommand = OnFocused;
  9175. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  9176. int Options =
  9177. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  9178. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  9179. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  9180. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  9181. {
  9182. FLastCustomCommand = Command;
  9183. UpdateCustomCommandsToolbar();
  9184. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  9185. }
  9186. }
  9187. //---------------------------------------------------------------------------
  9188. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  9189. {
  9190. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  9191. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9192. DebugAssert(State > 0);
  9193. if (State <= 0)
  9194. {
  9195. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  9196. }
  9197. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  9198. }
  9199. //---------------------------------------------------------------------------
  9200. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  9201. TCustomCommandType & Command, int & State)
  9202. {
  9203. bool Result = !FLastCustomCommand.Command.IsEmpty();
  9204. if (Result)
  9205. {
  9206. Command = FLastCustomCommand;
  9207. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9208. }
  9209. return Result;
  9210. }
  9211. //---------------------------------------------------------------------------
  9212. void __fastcall TCustomScpExplorerForm::BeforeAction()
  9213. {
  9214. ResetIncrementalSearch();
  9215. }
  9216. //---------------------------------------------------------------------------
  9217. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  9218. {
  9219. DebugAssert(ComponentVisible[Component]);
  9220. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  9221. }
  9222. //---------------------------------------------------------------------------
  9223. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  9224. {
  9225. // when queue panel is resized here directly, the status bar is stretched
  9226. // over whole space the panel occupied
  9227. PostComponentHide(fcQueueView);
  9228. }
  9229. //---------------------------------------------------------------------------
  9230. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  9231. {
  9232. ComponentVisible[fcQueueFileList] = false;
  9233. }
  9234. //---------------------------------------------------------------------------
  9235. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  9236. {
  9237. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  9238. RefreshColorMode();
  9239. ResetSysDarkTheme();
  9240. ConfigurationChanged();
  9241. ConfigureInterface();
  9242. // Should be called for all controls
  9243. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  9244. }
  9245. //---------------------------------------------------------------------------
  9246. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  9247. {
  9248. // Do not handle, when shutting down anyway (maybe also when not setup completely yet?)
  9249. if (!FInvalid &&
  9250. (Message.LParam != 0) &&
  9251. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  9252. {
  9253. ThemeChanged();
  9254. }
  9255. TForm::Dispatch(&Message);
  9256. }
  9257. //---------------------------------------------------------------------------
  9258. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  9259. {
  9260. TMessage * M = static_cast<TMessage*>(Message);
  9261. switch (M->Msg)
  9262. {
  9263. case CM_DIALOGCHAR:
  9264. CMDialogChar(*M);
  9265. break;
  9266. case WM_APPCOMMAND:
  9267. WMAppCommand(*M);
  9268. break;
  9269. case WM_SYSCOMMAND:
  9270. WMSysCommand(*M);
  9271. break;
  9272. case WM_QUERYENDSESSION:
  9273. WMQueryEndSession(*M);
  9274. break;
  9275. case WM_ENDSESSION:
  9276. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  9277. break;
  9278. #ifdef _DEBUG
  9279. case WM_WINDOWPOSCHANGED:
  9280. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  9281. break;
  9282. case CM_CUSTOMSTYLECHANGED:
  9283. TForm::Dispatch(Message);
  9284. break;
  9285. #endif
  9286. case WM_COMPONENT_HIDE:
  9287. {
  9288. Byte Component = static_cast<Byte>(M->WParam);
  9289. // sanity check
  9290. if (ComponentVisible[Component])
  9291. {
  9292. // special treatment
  9293. if (Component == fcQueueView)
  9294. {
  9295. ToggleQueueVisibility();
  9296. DebugAssert(!ComponentVisible[fcQueueView]);
  9297. }
  9298. else
  9299. {
  9300. ComponentVisible[Component] = false;
  9301. }
  9302. }
  9303. }
  9304. break;
  9305. case WM_COPYDATA:
  9306. WMCopyData(*M);
  9307. break;
  9308. case WM_MANAGES_CAPTION:
  9309. // caption managed in TTerminalManager::UpdateAppTitle()
  9310. M->Result = 1;
  9311. break;
  9312. case WM_WANTS_MOUSEWHEEL:
  9313. M->Result = 1;
  9314. break;
  9315. case CM_SHOWINGCHANGED:
  9316. CMShowingChanged(*M);
  9317. break;
  9318. case WM_CLOSE:
  9319. WMClose(*M);
  9320. break;
  9321. case WM_DPICHANGED:
  9322. WMDpiChanged(*M);
  9323. break;
  9324. case WM_SETTINGCHANGE:
  9325. WMSettingChange(*M);
  9326. break;
  9327. case CM_DIALOGKEY:
  9328. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  9329. break;
  9330. case WM_PASTE_FILES:
  9331. PasteFiles();
  9332. break;
  9333. case WM_IS_HIDDEN:
  9334. // To treat master password prompt as a main window while showing it when workspace is loading while
  9335. // the exporer is showing up (Visible is true already)
  9336. M->Result = !FShowing;
  9337. break;
  9338. case WM_SHOWWINDOW:
  9339. if (M->WParam)
  9340. {
  9341. AddStartupSequence(L"J");
  9342. }
  9343. TForm::Dispatch(Message);
  9344. break;
  9345. case WM_QUEUE_CALLBACK:
  9346. WMQueueCallback(*M);
  9347. break;
  9348. default:
  9349. TForm::Dispatch(Message);
  9350. break;
  9351. }
  9352. }
  9353. //---------------------------------------------------------------------------
  9354. void __fastcall TCustomScpExplorerForm::UpdateImages()
  9355. {
  9356. // noop
  9357. }
  9358. //---------------------------------------------------------------------------
  9359. void TCustomScpExplorerForm::RegenerateSessionColorsImageList()
  9360. {
  9361. FSessionColors->Clear();
  9362. AddFixedSessionImages();
  9363. ::RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  9364. UpdateImages();
  9365. }
  9366. //---------------------------------------------------------------------------
  9367. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  9368. {
  9369. TForm::Dispatch(&Message);
  9370. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  9371. UpdatePixelsPerInchMainWindowCounter();
  9372. }
  9373. //---------------------------------------------------------------------------
  9374. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  9375. {
  9376. AppLog(L"Main window WM_CLOSE");
  9377. // Cannot close window while we are busy.
  9378. // We cannot test this in FormCloseQuery as that is called also from
  9379. // Close(), which is called by CloseApplicationAction. So we can be busy
  9380. // there already even, when it is legitimate to close the application.
  9381. // Possibly a better place to handle this would be WMSysCommand.
  9382. if (NonVisualDataModule->Busy)
  9383. {
  9384. Message.Result = 1;
  9385. }
  9386. else
  9387. {
  9388. TForm::Dispatch(&Message);
  9389. }
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  9393. {
  9394. if (!FShowingChanged)
  9395. {
  9396. AddStartupSequence(L"D");
  9397. FShowingChanged = true;
  9398. }
  9399. // Ignoring implicit local-local browser of Commander, opened from DoShow
  9400. bool NoSession = (ManagedSession == NULL);
  9401. // This calls TCustomScpExplorerForm::DoShow
  9402. TForm::Dispatch(&Message);
  9403. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  9404. if (Showing && !FStarted)
  9405. {
  9406. FStarted = true;
  9407. InterfaceStarted();
  9408. }
  9409. if (Showing && NoSession)
  9410. {
  9411. // When we are starting minimized (i.e. from an installer),
  9412. // postpone showing Login dialog until we get restored.
  9413. // Otherwise the Login dialog (and Authentication window) show restored
  9414. // over invisible (minimized) main window.
  9415. if (WindowState == wsMinimized)
  9416. {
  9417. FNeedSession = true;
  9418. }
  9419. else
  9420. {
  9421. // This happens before application ever goes idle, so the toolbars would
  9422. // stay enabled (initial state) until the Login dialog is dismissed.
  9423. UpdateActions();
  9424. NonVisualDataModule->StartBusy();
  9425. try
  9426. {
  9427. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  9428. // otherwise the dialog does not receive focus.
  9429. // With Commander interface the ProcessMessages is called already
  9430. // by TDriveView, but with Explorer interface, we need to call it explicily
  9431. Application->ProcessMessages();
  9432. // do not reload sessions, they have been loaded just now (optimization)
  9433. NeedSession(true);
  9434. }
  9435. __finally
  9436. {
  9437. NonVisualDataModule->EndBusy();
  9438. }
  9439. }
  9440. }
  9441. }
  9442. //---------------------------------------------------------------------------
  9443. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  9444. {
  9445. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  9446. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  9447. }
  9448. //---------------------------------------------------------------------------
  9449. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  9450. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  9451. int & MaxHeight)
  9452. {
  9453. // workaround for bug in TWinControl.CalcConstraints
  9454. // Check for empty rect (restore from iconic state) is done there only after
  9455. // call to AdjustClientRect, which enlarges the rect (for forms).
  9456. TRect R = GetClientRect();
  9457. // when restoring from iconic state, place no restrictions
  9458. if (IsRectEmpty(R))
  9459. {
  9460. MinWidth = 0;
  9461. MinHeight = 0;
  9462. MaxWidth = 32000;
  9463. MaxHeight = 32000;
  9464. }
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  9468. TSpaceAvailable & ASpaceAvailable, bool & Close)
  9469. {
  9470. // terminal can be already closed (e.g. dropped connection)
  9471. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  9472. {
  9473. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  9474. try
  9475. {
  9476. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  9477. }
  9478. catch(...)
  9479. {
  9480. if (!Terminal->Active)
  9481. {
  9482. Close = true;
  9483. }
  9484. throw;
  9485. }
  9486. }
  9487. }
  9488. //---------------------------------------------------------------------------
  9489. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9490. {
  9491. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9492. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9493. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9494. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9495. {
  9496. OnGetSpaceAvailable = GetSpaceAvailable;
  9497. }
  9498. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9499. OnGetSpaceAvailable);
  9500. }
  9501. //---------------------------------------------------------------------------
  9502. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9503. {
  9504. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9505. Terminal->FillSessionDataForCode(Data.get());
  9506. return Data.release();
  9507. }
  9508. //---------------------------------------------------------------------------
  9509. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9510. {
  9511. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9512. DoGenerateUrlDialog(Data.get(), Paths);
  9513. }
  9514. //---------------------------------------------------------------------------
  9515. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9516. {
  9517. GenerateUrl(NULL);
  9518. }
  9519. //---------------------------------------------------------------------------
  9520. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9521. {
  9522. std::unique_ptr<TStrings> Paths(new TStringList());
  9523. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9524. GenerateUrl(Paths.get());
  9525. }
  9526. //---------------------------------------------------------------------------
  9527. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9528. {
  9529. FSessionColor = value;
  9530. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9531. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9532. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9533. DebugAssert(ColorItem != NULL);
  9534. ColorItem->Color = C;
  9535. NonVisualDataModule->ColorMenuItem->Color = C;
  9536. UpdateControls();
  9537. }
  9538. //---------------------------------------------------------------------------
  9539. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9540. {
  9541. if (value != FSessionColor)
  9542. {
  9543. UpdateSessionColor(value);
  9544. // Is null when called from LastTerminalClosed
  9545. if (Terminal != NULL)
  9546. {
  9547. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9548. }
  9549. }
  9550. }
  9551. //---------------------------------------------------------------------------
  9552. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9553. {
  9554. bool Result = FNoteTimer->Enabled;
  9555. if (Result)
  9556. {
  9557. // cannot cancel note too early
  9558. bool NotEarly =
  9559. (Now() - FNoteShown >
  9560. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9561. if (Force || NotEarly)
  9562. {
  9563. FNoteTimer->Enabled = false;
  9564. FNote = L"";
  9565. SAFE_DESTROY(FNoteData);
  9566. FOnNoteClick = NULL;
  9567. FNoteHints = FNotes->Text;
  9568. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9569. UpdateStatusBar();
  9570. }
  9571. }
  9572. return Result;
  9573. }
  9574. //---------------------------------------------------------------------------
  9575. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9576. {
  9577. DebugAssert(FNoteTimer->Enabled);
  9578. CancelNote(true);
  9579. }
  9580. //---------------------------------------------------------------------------
  9581. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9582. {
  9583. FNoteHints = FNotes->Text.TrimRight();
  9584. }
  9585. //---------------------------------------------------------------------------
  9586. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9587. {
  9588. int P = Note.Pos(L"\n");
  9589. if (P > 0)
  9590. {
  9591. Note.SetLength(P - 1);
  9592. }
  9593. FNotes->Add(FORMAT(L"[%s] %s",
  9594. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9595. while (FNotes->Count > 10)
  9596. {
  9597. FNotes->Delete(0);
  9598. }
  9599. if (UpdateNow)
  9600. {
  9601. UpdateNoteHints();
  9602. UpdateStatusBar();
  9603. }
  9604. }
  9605. //---------------------------------------------------------------------------
  9606. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9607. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9608. {
  9609. int P = Note.Pos(L"\n");
  9610. if (P > 0)
  9611. {
  9612. Note.SetLength(P - 1);
  9613. }
  9614. UpdateNoteHints();
  9615. FNote = Note;
  9616. SAFE_DESTROY(FNoteData);
  9617. FNoteData = NoteData;
  9618. FOnNoteClick = OnNoteClick;
  9619. AddNote(Note, false);
  9620. UpdateStatusBar();
  9621. FNoteShown = Now();
  9622. FNoteTimer->Enabled = false;
  9623. if (Seconds == 0)
  9624. {
  9625. Seconds = WinConfiguration->NotificationsTimeout;
  9626. }
  9627. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9628. FNoteTimer->Enabled = true;
  9629. }
  9630. //---------------------------------------------------------------------------
  9631. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9632. {
  9633. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9634. }
  9635. //---------------------------------------------------------------------------
  9636. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9637. {
  9638. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9639. {
  9640. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9641. }
  9642. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9643. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9644. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9645. 0, NULL, NULL);
  9646. }
  9647. //---------------------------------------------------------------------------
  9648. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9649. {
  9650. bool NewShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9651. UnicodeString Note =
  9652. FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1), (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, (NewShowHiddenFiles ? 2 : 3))));
  9653. PostNote(Note, 0, NULL, NULL);
  9654. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9655. WinConfiguration->ShowHiddenFiles = NewShowHiddenFiles;
  9656. }
  9657. //---------------------------------------------------------------------------
  9658. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9659. {
  9660. WinConfiguration->FormatSizeBytes = Style;
  9661. }
  9662. //---------------------------------------------------------------------------
  9663. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9664. {
  9665. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9666. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9667. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9668. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9669. }
  9670. //---------------------------------------------------------------------------
  9671. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9672. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9673. {
  9674. if (Panel->Index == 0)
  9675. {
  9676. if (FOnNoteClick != NULL)
  9677. {
  9678. // prevent the user data from being freed by possible call
  9679. // to CancelNote or PostNote during call to OnNoteClick
  9680. std::unique_ptr<TObject> NoteData(FNoteData);
  9681. TNotifyEvent OnNoteClick = FOnNoteClick;
  9682. FNoteData = NULL;
  9683. // need to cancel the note as we are going to delete its user data
  9684. CancelNote(true);
  9685. OnNoteClick(NoteData.get());
  9686. }
  9687. }
  9688. if (HasActiveTerminal() &&
  9689. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9690. {
  9691. FileSystemInfo();
  9692. }
  9693. }
  9694. //---------------------------------------------------------------------------
  9695. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9696. {
  9697. // workaround:
  9698. // 1) for unknown reason, disabling window, while minimized,
  9699. // prevents it from restoring, even if it was enabled again meanwhile
  9700. // 2) when disabling the main window, while another has focus
  9701. // minimize is no longer possible
  9702. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9703. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9704. // Shouldn't we use IsApplicationMinimized() here?
  9705. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9706. {
  9707. Enabled = false;
  9708. }
  9709. FLockLevel++;
  9710. }
  9711. //---------------------------------------------------------------------------
  9712. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9713. {
  9714. DebugAssert(FLockLevel > 0);
  9715. FLockLevel--;
  9716. if (FLockLevel == 0)
  9717. {
  9718. DebugAssert(FLockSuspendLevel == 0);
  9719. Enabled = true;
  9720. // VCL_COPY (TCustomForm.SetWindowFocus)
  9721. if (Active && (ActiveControl != NULL))
  9722. {
  9723. ::SetFocus(ActiveControl->Handle);
  9724. if (GetFocus() == ActiveControl->Handle)
  9725. {
  9726. ActiveControl->Perform(CM_UIACTIVATE, 0, 0);
  9727. }
  9728. }
  9729. }
  9730. }
  9731. //---------------------------------------------------------------------------
  9732. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9733. {
  9734. // We need to make sure that window is enabled when the last modal window closes
  9735. // otherwise focus is not restored correctly.
  9736. // So we re-enable the window when modal window opens and
  9737. // disable it back after is closes
  9738. if (FLockLevel > 0)
  9739. {
  9740. // while we have nesting counter, we know that we never be called
  9741. // recursivelly as Application->OnModalBegin is called only
  9742. // for the top-level modal window
  9743. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9744. {
  9745. // won't be disabled when conditions in LockWindow() were not satisfied
  9746. FDisabledOnLockSuspend = !Enabled;
  9747. // When minimized to tray (or actually when set to SW_HIDE),
  9748. // setting Enabled makes the window focusable even when there's
  9749. // modal window over it
  9750. if (!FTrayIcon->Visible)
  9751. {
  9752. Enabled = true;
  9753. }
  9754. }
  9755. FLockSuspendLevel++;
  9756. }
  9757. }
  9758. //---------------------------------------------------------------------------
  9759. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9760. {
  9761. if (FLockSuspendLevel > 0)
  9762. {
  9763. DebugAssert(FLockLevel > 0);
  9764. FLockSuspendLevel--;
  9765. // see comment in SuspendWindowLock
  9766. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9767. {
  9768. // Note that window can be enabled here, when we were minized to tray when
  9769. // was SuspendWindowLock() called.
  9770. // We should possibly do the same check as in LockWindow(),
  9771. // if it is ever possible that the consitions change between
  9772. // SuspendWindowLock() and ResumeWindowLock()
  9773. Enabled = !FDisabledOnLockSuspend;
  9774. }
  9775. }
  9776. }
  9777. //---------------------------------------------------------------------------
  9778. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9779. {
  9780. TTBXComboBoxItem * RemotePathComboBox =
  9781. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9782. if (!TextOnly)
  9783. {
  9784. TStrings * Items = RemotePathComboBox->Strings;
  9785. Items->BeginUpdate();
  9786. try
  9787. {
  9788. Items->Clear();
  9789. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9790. {
  9791. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9792. while (!IsUnixRootPath(APath))
  9793. {
  9794. int P = APath.LastDelimiter(L'/');
  9795. DebugAssert(P >= 0);
  9796. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9797. APath.SetLength(P - 1);
  9798. }
  9799. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9800. }
  9801. }
  9802. __finally
  9803. {
  9804. Items->EndUpdate();
  9805. }
  9806. }
  9807. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9808. // Setting ItemIndex to -1 does not reset its text
  9809. if (RemotePathComboBox->Strings->Count == 0)
  9810. {
  9811. RemotePathComboBox->Text = L"";
  9812. }
  9813. }
  9814. //---------------------------------------------------------------------------
  9815. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9816. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9817. {
  9818. if (AIndex < 0)
  9819. {
  9820. AIndex = Sender->ItemIndex;
  9821. }
  9822. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9823. }
  9824. //---------------------------------------------------------------------------
  9825. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9826. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9827. int & ImageIndex)
  9828. {
  9829. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9830. }
  9831. //---------------------------------------------------------------------------
  9832. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9833. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9834. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9835. {
  9836. if (!IsLocalBrowserMode())
  9837. {
  9838. ARect.Left += (10 * AIndex);
  9839. }
  9840. }
  9841. //---------------------------------------------------------------------------
  9842. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9843. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9844. {
  9845. AWidth += (10 * AIndex);
  9846. }
  9847. //---------------------------------------------------------------------------
  9848. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9849. {
  9850. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9851. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9852. int Index = RemotePathComboBox->ItemIndex;
  9853. while (Index < RemotePathComboBox->Strings->Count - 1)
  9854. {
  9855. APath = UnixExtractFileDir(APath);
  9856. Index++;
  9857. }
  9858. // VanDyke style paths
  9859. if (APath.IsEmpty())
  9860. {
  9861. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9862. APath = ROOTDIRECTORY;
  9863. }
  9864. if (RemoteDirView->Path != APath)
  9865. {
  9866. RemoteDirView->Path = APath;
  9867. }
  9868. }
  9869. //---------------------------------------------------------------------------
  9870. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9871. {
  9872. DoRemotePathComboBoxItemClick(Sender);
  9873. }
  9874. //---------------------------------------------------------------------------
  9875. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9876. {
  9877. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9878. DebugUsedParam(Sender);
  9879. UpdateRemotePathComboBox(true);
  9880. }
  9881. //---------------------------------------------------------------------------
  9882. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9883. {
  9884. DoRemotePathComboBoxCancel(Sender);
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9888. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9889. {
  9890. ResetIncrementalSearch();
  9891. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9892. DebugAssert(DirView != NULL);
  9893. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9894. {
  9895. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9896. // OnEditing is called also from TCustomListView::CanEdit
  9897. if (Edit != NULL)
  9898. {
  9899. EditSelectBaseName(Edit);
  9900. }
  9901. }
  9902. }
  9903. //---------------------------------------------------------------------------
  9904. //---------------------------------------------------------------------------
  9905. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9906. {
  9907. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9908. Result->AutoDetectDnD = false;
  9909. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9910. Result->RenderDataOn = rdoEnterAndDropSync;
  9911. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9912. return Result;
  9913. }
  9914. //---------------------------------------------------------------------------
  9915. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9916. {
  9917. if (IsWin10Build(19041))
  9918. {
  9919. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9920. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9921. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9922. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9923. }
  9924. }
  9925. //---------------------------------------------------------------------------
  9926. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9927. {
  9928. TForm::CreateWnd();
  9929. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9930. UpdateDarkMode();
  9931. if (FSessionsDragDropFilesEx == NULL)
  9932. {
  9933. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9934. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9935. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9936. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9937. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9938. }
  9939. if (FQueueDragDropFilesEx == NULL)
  9940. {
  9941. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9942. // No need to set OnDragOver as we do not have any restrictions
  9943. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9944. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9945. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9946. }
  9947. }
  9948. //---------------------------------------------------------------------------
  9949. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9950. {
  9951. TForm::DestroyWnd();
  9952. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9953. FQueueDragDropFilesEx->DragDropControl = NULL;
  9954. }
  9955. //---------------------------------------------------------------------------
  9956. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9957. {
  9958. SideEnter(FCurrentSide);
  9959. FEverShown = true;
  9960. }
  9961. //---------------------------------------------------------------------------
  9962. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9963. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9964. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9965. {
  9966. if (!NonVisualDataModule->Busy)
  9967. {
  9968. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9969. Configuration->Usage->Inc(L"FileFinds");
  9970. LockWindow(true);
  9971. NonVisualDataModule->StartBusy();
  9972. WinConfiguration->LockedInterface = true;
  9973. try
  9974. {
  9975. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9976. }
  9977. __finally
  9978. {
  9979. WinConfiguration->LockedInterface = false;
  9980. NonVisualDataModule->EndBusy();
  9981. UnlockWindow();
  9982. }
  9983. }
  9984. }
  9985. //---------------------------------------------------------------------------
  9986. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9987. {
  9988. if (!NonVisualDataModule->Busy)
  9989. {
  9990. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9991. SetFocus();
  9992. RemoteDirView->Path = UnixExtractFilePath(Path);
  9993. UnicodeString FileName = UnixExtractFileName(Path);
  9994. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9995. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9996. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9997. if (Item == NULL)
  9998. {
  9999. ReloadDirectory(osRemote);
  10000. Item = RemoteDirView->FindFileItem(FileName);
  10001. }
  10002. if (Item != NULL)
  10003. {
  10004. RemoteDirView->ItemFocused = Item;
  10005. RemoteDirView->ItemFocused->MakeVisible(false);
  10006. RemoteDirView->SetFocus();
  10007. }
  10008. }
  10009. }
  10010. //---------------------------------------------------------------------------
  10011. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  10012. {
  10013. bool Result = !NonVisualDataModule->Busy;
  10014. if (Result)
  10015. {
  10016. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  10017. }
  10018. return Result;
  10019. }
  10020. //---------------------------------------------------------------------------
  10021. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  10022. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10023. {
  10024. if (CanOperateOnFoundFiles(ATerminal))
  10025. {
  10026. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished, OnFileOperationFinished);
  10027. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  10028. }
  10029. }
  10030. //---------------------------------------------------------------------------
  10031. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  10032. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10033. {
  10034. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  10035. }
  10036. //---------------------------------------------------------------------------
  10037. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  10038. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10039. {
  10040. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  10041. }
  10042. //---------------------------------------------------------------------------
  10043. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  10044. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10045. {
  10046. if (CanOperateOnFoundFiles(ATerminal))
  10047. {
  10048. for (int Index = 0; Index < FileList->Count; Index++)
  10049. {
  10050. UnicodeString FileName = FileList->Strings[Index];
  10051. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  10052. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  10053. OnFileOperationFinished(osRemote, FileName, true, true);
  10054. }
  10055. }
  10056. }
  10057. //---------------------------------------------------------------------------
  10058. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  10059. {
  10060. FFileFindTerminal = Terminal;
  10061. ShowFileFindDialog(
  10062. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  10063. DoDownloadFoundFiles, DoEditFoundFiles);
  10064. }
  10065. //---------------------------------------------------------------------------
  10066. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  10067. {
  10068. FTaskbarList = TaskbarList;
  10069. }
  10070. //---------------------------------------------------------------------------
  10071. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  10072. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  10073. {
  10074. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10075. if (Index >= 0)
  10076. {
  10077. if (Button == mbLeft)
  10078. {
  10079. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  10080. // If switching tab (switching session) takes long enough for user
  10081. // to actually release the button, "mouse down" is still raised,
  10082. // but we do not get "mouse up" event, so dragging is not cancelled,
  10083. // prevent that by not beginning dragging in the first place.
  10084. int Key = ((GetSystemMetrics(SM_SWAPBUTTON) == 0) ? VK_LBUTTON : VK_RBUTTON);
  10085. if (IsKeyPressed(Key))
  10086. {
  10087. // when user clicks the "+", we get mouse down only after the session
  10088. // is closed, when new session tab is already on X:Y, so dragging
  10089. // starts, prevent that
  10090. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  10091. {
  10092. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10093. if (Terminal != NULL)
  10094. {
  10095. SessionsPageControl->BeginDrag(false);
  10096. }
  10097. }
  10098. }
  10099. }
  10100. else if (Button == mbMiddle)
  10101. {
  10102. // ignore middle-click for "New session tab" and the last local-local tab
  10103. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10104. if ((Session != NULL) && CanCloseSession(Session))
  10105. {
  10106. CloseSessionTab(Index);
  10107. }
  10108. }
  10109. }
  10110. }
  10111. //---------------------------------------------------------------------------
  10112. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  10113. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  10114. {
  10115. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10116. // do not allow dropping on the "+" tab
  10117. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10118. if ((TargetTerminal != NULL) &&
  10119. (SessionsPageControl->ActivePage->PageIndex != Index))
  10120. {
  10121. Configuration->Usage->Inc(L"SessionTabMoves");
  10122. // this is almost redundant as we would recreate tabs in SessionListChanged,
  10123. // but we want to actually prevent that to avoid flicker
  10124. SessionsPageControl->ActivePage->PageIndex = Index;
  10125. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  10126. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  10127. }
  10128. }
  10129. //---------------------------------------------------------------------------
  10130. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  10131. TObject * Sender, TObject * Source, int X, int Y,
  10132. TDragState /*State*/, bool & Accept)
  10133. {
  10134. Accept = (Sender == Source);
  10135. if (Accept)
  10136. {
  10137. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10138. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10139. // do not allow dragging to the "+" tab
  10140. Accept = (Terminal != NULL);
  10141. }
  10142. }
  10143. //---------------------------------------------------------------------------
  10144. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  10145. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  10146. {
  10147. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10148. if (Index < 0)
  10149. {
  10150. Effect = DROPEFFECT_NONE;
  10151. }
  10152. else
  10153. {
  10154. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10155. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  10156. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  10157. {
  10158. Effect = DROPEFFECT_NONE;
  10159. }
  10160. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  10161. {
  10162. Effect = DROPEFFECT_COPY;
  10163. }
  10164. }
  10165. }
  10166. //---------------------------------------------------------------------------
  10167. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  10168. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  10169. {
  10170. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10171. // do not allow dropping on local-local, disconnected and the "+" tab
  10172. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  10173. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10174. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  10175. {
  10176. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  10177. if (!IsFileControl(DropSourceControl, osRemote))
  10178. {
  10179. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  10180. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  10181. // Why don't we use Terminal->CurrentDirectory directly?
  10182. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  10183. // do not force queue, drag drop
  10184. false, true);
  10185. }
  10186. }
  10187. }
  10188. //---------------------------------------------------------------------------
  10189. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  10190. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  10191. {
  10192. // Downloads are handled in RemoteFileControlDDEnd
  10193. if (!IsFileControl(DropSourceControl, osRemote))
  10194. {
  10195. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  10196. Terminal->CurrentDirectory,
  10197. // force queue, drag drop
  10198. true, true);
  10199. }
  10200. }
  10201. //---------------------------------------------------------------------------
  10202. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  10203. {
  10204. FShowing = false;
  10205. // Do not save empty workspace
  10206. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  10207. {
  10208. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  10209. UnicodeString Name = WorkspaceName();
  10210. DoSaveWorkspace(
  10211. Name, DataList.get(),
  10212. !Configuration->DisablePasswordStoring &&
  10213. WinConfiguration->AutoSaveWorkspacePasswords, false);
  10214. WinConfiguration->LastStoredSession = Name;
  10215. }
  10216. AppLog(L"Closing main window");
  10217. }
  10218. //---------------------------------------------------------------------------
  10219. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  10220. {
  10221. TManagedTerminal * ManagedTerminal =
  10222. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  10223. if (ManagedTerminal != NULL)
  10224. {
  10225. ManagedTerminal->DirectoryLoaded = Now();
  10226. }
  10227. }
  10228. //---------------------------------------------------------------------------
  10229. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  10230. TListItem * /*Item*/, bool /*Selected*/)
  10231. {
  10232. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  10233. switch (DirView->LastSelectMethod)
  10234. {
  10235. case smKeyboard:
  10236. Configuration->Usage->Inc(L"KeyboardSelections");
  10237. break;
  10238. case smMouse:
  10239. Configuration->Usage->Inc(L"MouseSelections");
  10240. break;
  10241. }
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  10245. {
  10246. if (Color != 0)
  10247. {
  10248. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  10249. }
  10250. else
  10251. {
  10252. return FSessionTabImageIndex;
  10253. }
  10254. }
  10255. //---------------------------------------------------------------------------
  10256. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  10257. {
  10258. TPngImageCollectionItem * Item =
  10259. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  10260. FSessionColors->AddPng(Item->PngImage);
  10261. return FSessionColors->Count - 1;
  10262. }
  10263. //---------------------------------------------------------------------------
  10264. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  10265. {
  10266. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  10267. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  10268. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  10269. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  10270. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  10271. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  10275. {
  10276. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  10277. }
  10278. //---------------------------------------------------------------------------
  10279. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  10280. {
  10281. switch (Side)
  10282. {
  10283. case osLocal:
  10284. return FNewLocalTabTabImageIndex;
  10285. case osRemote:
  10286. case osCurrent:
  10287. return FNewRemoteTabTabImageIndex;
  10288. default:
  10289. DebugFail();
  10290. return -1;
  10291. }
  10292. }
  10293. //---------------------------------------------------------------------------
  10294. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  10295. {
  10296. for (int Index = 0; Index < Control->ControlCount; Index++)
  10297. {
  10298. TControl * AControl = Control->Controls[Index];
  10299. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  10300. if (WinControl != NULL)
  10301. {
  10302. CollectItemsWithTextDisplayMode(WinControl);
  10303. }
  10304. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  10305. if (Toolbar != NULL)
  10306. {
  10307. // we care for top-level items only
  10308. TTBCustomItem * Items = Toolbar->Items;
  10309. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  10310. {
  10311. TTBCustomItem * Item = Items->Items[ItemIndex];
  10312. if (((Item->DisplayMode == nbdmImageAndText) ||
  10313. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  10314. EligibleForImageDisplayMode(Item))
  10315. {
  10316. FItemsWithTextDisplayMode.insert(Item);
  10317. }
  10318. }
  10319. }
  10320. }
  10321. }
  10322. //---------------------------------------------------------------------------
  10323. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  10324. {
  10325. return true;
  10326. }
  10327. //---------------------------------------------------------------------------
  10328. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  10329. {
  10330. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  10331. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  10332. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  10333. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  10334. bool Result = true;
  10335. while (Result && (i != FItemsWithTextDisplayMode.end()))
  10336. {
  10337. TTBCustomItem * Item = *i;
  10338. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  10339. if (Label != NULL)
  10340. {
  10341. // optimization
  10342. if (Label->Visible == SelectiveToolbarText)
  10343. {
  10344. Result = false;
  10345. }
  10346. else
  10347. {
  10348. Label->Visible = SelectiveToolbarText;
  10349. }
  10350. }
  10351. else
  10352. {
  10353. // optimization
  10354. if (Item->DisplayMode == DisplayMode)
  10355. {
  10356. Result = false;
  10357. }
  10358. else
  10359. {
  10360. Item->DisplayMode = DisplayMode;
  10361. }
  10362. }
  10363. ++i;
  10364. }
  10365. UpdateNewTabTab();
  10366. return Result;
  10367. }
  10368. //---------------------------------------------------------------------------
  10369. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  10370. {
  10371. DebugFail();
  10372. }
  10373. //---------------------------------------------------------------------------
  10374. bool __fastcall TCustomScpExplorerForm::IsBusy()
  10375. {
  10376. // Among other, a lock level is non zero, while directory is being loaded,
  10377. // even when it happens as a result of dirview navigation,
  10378. // i.e. when TNonVisualDataModule is NOT FBusy.
  10379. // That's why the TNonVisualDataModule::GetBusy calls this method.
  10380. // Among other this prevents a panel auto update to occur while
  10381. // directory is changing.
  10382. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  10383. }
  10384. //---------------------------------------------------------------------------
  10385. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  10386. {
  10387. // While the window is disabled, we still seem to process menu shortcuts at least,
  10388. // so stop it at least here.
  10389. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  10390. bool Result;
  10391. if (Allowed == aaUpdate)
  10392. {
  10393. Result = true;
  10394. }
  10395. else
  10396. {
  10397. Result = !NonVisualDataModule->Busy;
  10398. if (Result && (Allowed == aaShortCut))
  10399. {
  10400. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  10401. Action->Update();
  10402. Result = Action->Enabled;
  10403. }
  10404. }
  10405. return Result;
  10406. }
  10407. //---------------------------------------------------------------------------
  10408. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  10409. {
  10410. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  10411. }
  10412. //---------------------------------------------------------------------------
  10413. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  10414. {
  10415. // This is somewhat redundant to LockWindow() call from
  10416. // TTerminalManager::TerminalReadDirectoryProgress.
  10417. // But disabling window is known not to block keyboard shorcuts
  10418. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  10419. if (Busy > 0)
  10420. {
  10421. if (NonVisualDataModule->Busy)
  10422. {
  10423. State = false;
  10424. }
  10425. else
  10426. {
  10427. NonVisualDataModule->StartBusy();
  10428. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  10429. LockWindow();
  10430. }
  10431. }
  10432. else if (Busy < 0)
  10433. {
  10434. UnlockWindow();
  10435. NonVisualDataModule->EndBusy();
  10436. }
  10437. else
  10438. {
  10439. State = NonVisualDataModule->Busy;
  10440. }
  10441. }
  10442. //---------------------------------------------------------------------------
  10443. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  10444. {
  10445. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  10446. if (Index >= 0)
  10447. {
  10448. TPopupMenu * PopupMenu = NULL;
  10449. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10450. if (Session != NULL)
  10451. {
  10452. SessionsPageControl->ActivePageIndex = Index;
  10453. if (DebugAlwaysTrue(SessionTabSwitched()))
  10454. {
  10455. // copied from TControl.WMContextMenu
  10456. SendCancelMode(SessionsPageControl);
  10457. // explicit popup instead of using PopupMenu property
  10458. // to avoid menu to popup somewhere within SessionTabSwitched above,
  10459. // while connecting yet not-connected session and hence
  10460. // allowing an access to commands over not-completely connected session
  10461. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  10462. }
  10463. }
  10464. else
  10465. {
  10466. if (SupportsLocalBrowser())
  10467. {
  10468. PopupMenu = NonVisualDataModule->NewTabPopup;
  10469. }
  10470. }
  10471. if (PopupMenu != NULL)
  10472. {
  10473. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  10474. PopupMenu->PopupComponent = SessionsPageControl;
  10475. PopupMenu->Popup(Point.x, Point.y);
  10476. }
  10477. }
  10478. Handled = true;
  10479. }
  10480. //---------------------------------------------------------------------------
  10481. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  10482. {
  10483. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  10484. }
  10485. //---------------------------------------------------------------------------
  10486. void __fastcall TCustomScpExplorerForm::ChangePassword()
  10487. {
  10488. Configuration->Usage->Inc(L"PasswordChanges");
  10489. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  10490. ChangePasswordData->DisableAuthentationsExceptPassword();
  10491. ChangePasswordData->ChangePassword = true;
  10492. std::unique_ptr<TTerminal> ChangePasswordSession(
  10493. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10494. ChangePasswordSession->AutoReadDirectory = false;
  10495. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10496. {
  10497. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10498. }
  10499. else
  10500. {
  10501. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10502. }
  10503. }
  10504. //---------------------------------------------------------------------------
  10505. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10506. {
  10507. // No nice way to assert SSH2
  10508. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10509. }
  10510. //---------------------------------------------------------------------------
  10511. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10512. {
  10513. TOperationVisualizer OperationVisualizer;
  10514. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10515. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10516. }
  10517. //---------------------------------------------------------------------------
  10518. void __fastcall TCustomScpExplorerForm::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  10519. {
  10520. DebugUsedParam(OldDPI);
  10521. DebugAssert(NewDPI == GetControlPixelsPerInch(this));
  10522. GlyphsModule->PixelsPerInch = NewDPI;
  10523. // Can be called too early when primary monitor has non-system dpi
  10524. if (FSessionColors != NULL)
  10525. {
  10526. RegenerateSessionColorsImageList();
  10527. }
  10528. UpdateTabsSize();
  10529. UpdateSessionsPageControlHeight();
  10530. QueueFileListColumnAutoSize();
  10531. }
  10532. //---------------------------------------------------------------------------
  10533. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10534. {
  10535. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10536. }
  10537. //---------------------------------------------------------------------
  10538. class TPublicControl : public TControl
  10539. {
  10540. friend class TCustomScpExplorerForm;
  10541. };
  10542. //---------------------------------------------------------------------------
  10543. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10544. {
  10545. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10546. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10547. }
  10548. //---------------------------------------------------------------------------
  10549. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10550. {
  10551. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10552. OpenBookmark(Side, Bookmark);
  10553. }
  10554. //---------------------------------------------------------------------------
  10555. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10556. {
  10557. DoBookmarkClick(osLocal, Sender);
  10558. }
  10559. //---------------------------------------------------------------------------
  10560. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10561. {
  10562. DoBookmarkClick(osRemote, Sender);
  10563. }
  10564. //---------------------------------------------------------------------------
  10565. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10566. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10567. {
  10568. if (BookmarkList != NULL)
  10569. {
  10570. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10571. if (IsLocalBrowserMode())
  10572. {
  10573. Side = osLocal;
  10574. }
  10575. if (!WinConfiguration->UseLocationProfiles)
  10576. {
  10577. std::unique_ptr<TStringList> Directories(new TStringList());
  10578. Directories->CaseSensitive = (Side == osRemote);
  10579. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10580. {
  10581. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10582. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10583. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10584. {
  10585. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10586. Item->Caption = EscapeHotkey(Directory);
  10587. Item->ShortCut = Bookmark->ShortCut;
  10588. Item->OnClick = OnBookmarkClick;
  10589. Item->Tag = reinterpret_cast<int>(Bookmark);
  10590. Directories->Add(Directory);
  10591. Menu->Add(Item.release());
  10592. }
  10593. }
  10594. }
  10595. else
  10596. {
  10597. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10598. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10599. {
  10600. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10601. if (!Bookmark->Node.IsEmpty())
  10602. {
  10603. Folders->Add(Bookmark->Node);
  10604. }
  10605. }
  10606. for (int Index = 0; Index < Folders->Count; Index++)
  10607. {
  10608. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10609. Item->Caption = Folders->Strings[Index];
  10610. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10611. Folders->Objects[Index] = Item.get();
  10612. Menu->Add(Item.release());
  10613. }
  10614. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10615. {
  10616. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10617. TTBCustomItem * Parent;
  10618. if (!Bookmark->Node.IsEmpty())
  10619. {
  10620. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10621. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10622. }
  10623. else
  10624. {
  10625. Parent = Menu;
  10626. }
  10627. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10628. Item->Caption = Bookmark->Name;
  10629. Item->ShortCut = Bookmark->ShortCut;
  10630. Item->OnClick = OnBookmarkClick;
  10631. Item->Tag = reinterpret_cast<int>(Bookmark);
  10632. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10633. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10634. {
  10635. // No hint for location profiles that are actually mere "bookmarks"
  10636. }
  10637. else
  10638. {
  10639. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10640. UnicodeString LongHint;
  10641. if (!Bookmark->Local.IsEmpty())
  10642. {
  10643. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10644. }
  10645. if (!Bookmark->Remote.IsEmpty())
  10646. {
  10647. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10648. }
  10649. AddToList(Hint, LongHint, L"|");
  10650. Item->Hint = Hint;
  10651. }
  10652. Parent->Add(Item.release());
  10653. }
  10654. }
  10655. AddMenuSeparator(Menu);
  10656. }
  10657. }
  10658. //---------------------------------------------------------------------------
  10659. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10660. {
  10661. Menu->Clear();
  10662. std::unique_ptr<TTBCustomItem> Item;
  10663. Item.reset(new TTBXItem(Owner));
  10664. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10665. Item->Options = Item->Options << tboDefault;
  10666. Menu->Add(Item.release());
  10667. AddMenuSeparator(Menu);
  10668. if (Terminal != NULL)
  10669. {
  10670. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10671. }
  10672. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10673. Item.reset(new TTBXItem(Owner));
  10674. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10675. Menu->Add(Item.release());
  10676. }
  10677. //---------------------------------------------------------------------------
  10678. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10679. {
  10680. bool Result = true;
  10681. bool Remote = !IsSideLocalBrowser(Side);
  10682. try
  10683. {
  10684. UnicodeString APath = Path;
  10685. if (Remote)
  10686. {
  10687. Terminal->ExceptionOnFail = true;
  10688. }
  10689. else
  10690. {
  10691. APath = ExpandEnvironmentVariables(Path);
  10692. }
  10693. try
  10694. {
  10695. DirView(Side)->Path = APath;
  10696. }
  10697. __finally
  10698. {
  10699. if (Remote)
  10700. {
  10701. Terminal->ExceptionOnFail = false;
  10702. }
  10703. }
  10704. }
  10705. catch (Exception & E)
  10706. {
  10707. if (!Remote || Terminal->Active)
  10708. {
  10709. ShowExtendedExceptionEx(Terminal, &E);
  10710. Result = false;
  10711. }
  10712. else
  10713. {
  10714. throw;
  10715. }
  10716. }
  10717. return Result;
  10718. }
  10719. //---------------------------------------------------------------------------
  10720. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10721. {
  10722. // Make sure there some feedback even when loading tiny local folders
  10723. TInstantOperationVisualizer Visualizer;
  10724. DirView(Side)->ReloadDirectory();
  10725. }
  10726. //---------------------------------------------------------------------------
  10727. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10728. {
  10729. if (Index == SessionsPageControl->TabIndex)
  10730. {
  10731. CloseTab();
  10732. }
  10733. else
  10734. {
  10735. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10736. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10737. TTerminalManager * Manager = TTerminalManager::Instance();
  10738. if (!Terminal->Active)
  10739. {
  10740. Manager->FreeTerminal(Terminal);
  10741. }
  10742. else
  10743. {
  10744. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10745. if (CanCloseQueue(Queue))
  10746. {
  10747. Manager->FreeTerminal(Terminal);
  10748. }
  10749. }
  10750. }
  10751. }
  10752. //---------------------------------------------------------------------------
  10753. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10754. {
  10755. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10756. if (Session == NULL)
  10757. {
  10758. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10759. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10760. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10761. //P = SessionsPageControl->ClientToScreen(P);
  10762. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10763. }
  10764. else
  10765. {
  10766. CloseSessionTab(Index);
  10767. }
  10768. }
  10769. //---------------------------------------------------------------------------
  10770. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10771. {
  10772. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10773. {
  10774. TInstantOperationVisualizer Visualizer;
  10775. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10776. // before we create a new data object
  10777. ClipboardClear();
  10778. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10779. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10780. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10781. // Intermediate variable to WORKAROUND a crash in compiler
  10782. TObjectList * ClipboardFakeMonitors =
  10783. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10784. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10785. if (FClipboardDragDropFilesEx.get() == NULL)
  10786. {
  10787. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10788. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10789. }
  10790. FClipboardDragDropFilesEx->FileList->Clear();
  10791. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10792. FClipboardDragDropFilesEx->CopyToClipboard();
  10793. FClipboardTerminal = Terminal;
  10794. // Need full paths, as cwd can be different once files are pasted
  10795. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10796. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10797. {
  10798. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10799. }
  10800. AppLogFmt(L"Created fake clipboard directory \"%s\" and started drive monitors", (FClipboardFakeDirectory));
  10801. }
  10802. }
  10803. //---------------------------------------------------------------------------
  10804. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10805. {
  10806. if (OpenClipboard(0))
  10807. {
  10808. AppLog(L"Clearing clipboard");
  10809. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10810. CloseClipboard();
  10811. }
  10812. }
  10813. //---------------------------------------------------------------------------
  10814. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10815. {
  10816. return !FClipboardFakeDirectory.IsEmpty();
  10817. }
  10818. //---------------------------------------------------------------------------
  10819. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10820. {
  10821. bool Deleted = RemoveDir(ApiPath(FClipboardFakeDirectory));
  10822. AppLogFmt(L"Clearing clipboard, deleted clipboard temporary folder \"%s\" - %d", (FClipboardFakeDirectory, int(Deleted)));
  10823. FClipboardFakeDirectory = UnicodeString();
  10824. FClipboardTerminal = NULL;
  10825. if (FDownloadingFromClipboard)
  10826. {
  10827. // We are called by the monitor, so attempt to release it would deadlock
  10828. FClipboardFakeMonitorsPendingReset = true;
  10829. }
  10830. else
  10831. {
  10832. FClipboardFakeMonitors.reset(NULL);
  10833. }
  10834. }
  10835. //---------------------------------------------------------------------------
  10836. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10837. {
  10838. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10839. {
  10840. ClipboardStop();
  10841. }
  10842. }
  10843. //---------------------------------------------------------------------------
  10844. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10845. {
  10846. TTerminalManager * Manager = TTerminalManager::Instance();
  10847. Manager->ActiveSession = FClipboardTerminal;
  10848. TTransferOperationParam Params;
  10849. Params.TargetDirectory = TargetDirectory;
  10850. Params.DragDrop = DragDrop;
  10851. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10852. }
  10853. //---------------------------------------------------------------------------
  10854. void TCustomScpExplorerForm::PasteFiles()
  10855. {
  10856. // Guard against possible race conditions
  10857. if (!FClipboardPasteTarget.IsEmpty())
  10858. {
  10859. // ClipboardFakeCreated might be called while we are here, so make sure we finish operating on the same path we started with
  10860. UnicodeString Target = FClipboardPasteTarget;
  10861. FClipboardPasteTarget = EmptyStr;
  10862. // Can fail as it can be e.g. locked by AV, so we retry that later
  10863. bool Removed = RemoveDir(ApiPath(Target));
  10864. AppLogFmt(L"First attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10865. try
  10866. {
  10867. if (NonVisualDataModule->Busy)
  10868. {
  10869. AppLog(L"Is busy, cannot paste");
  10870. }
  10871. else
  10872. {
  10873. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10874. FClipboardFakeMonitorsPendingReset = false;
  10875. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10876. TAutoFlag Flag(FDownloadingFromClipboard);
  10877. AppLog(L"Downloading to paste target...");
  10878. ClipboardDownload(ExtractFilePath(Target), NoConfirmation, true);
  10879. AppLog(L"Downloaded to paste target...");
  10880. }
  10881. }
  10882. __finally
  10883. {
  10884. if (!Removed)
  10885. {
  10886. Removed = RemoveDir(ApiPath(Target));
  10887. AppLogFmt(L"Second attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10888. }
  10889. }
  10890. }
  10891. }
  10892. //---------------------------------------------------------------------------
  10893. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10894. {
  10895. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10896. // (as it pumps a Windows message queue while being shutted down)
  10897. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10898. // Is can happen that creation of our temporary directory is detected (even though we are creating it before starting the monitors).
  10899. // It tent do happen with later copy-pastes, probably because everything is cached already and monitors start quickly.
  10900. !IsPathToSameFile(FClipboardFakeDirectory, FileName) &&
  10901. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10902. {
  10903. AppLogFmt(L"Fake clipboard directory pasted to \"%s\"", (FileName));
  10904. FClipboardPasteTarget = FileName;
  10905. // Particularly when pasting to external HDD, the fake directory is strangely recreated if removed here in the monitor callback.
  10906. // Postponing removing (or actually whole pasting operation) seems to help.
  10907. PostMessage(Handle, WM_PASTE_FILES, 0, 0);
  10908. }
  10909. }
  10910. //---------------------------------------------------------------------------
  10911. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10912. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10913. {
  10914. TFileMasks::TParams MaskParams;
  10915. MaskParams.Size = Size;
  10916. MaskParams.Modification = Modification;
  10917. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10918. bool Local = (dynamic_cast<TUnixDirView *>(DirView) == NULL);
  10919. // TUnixDirView::ItemFullFileName returns trailing backslash for directories, what filemask cannot deal with
  10920. if (!Local && Directory)
  10921. {
  10922. FileName = UnixExcludeTrailingBackslash(FileName);
  10923. }
  10924. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10925. {
  10926. bool ImplicitMatch;
  10927. if (Iter->FileMask.Matches(FileName, Local, Directory, &MaskParams, false, ImplicitMatch) &&
  10928. !ImplicitMatch)
  10929. {
  10930. Color = Iter->Color;
  10931. break;
  10932. }
  10933. }
  10934. }
  10935. //---------------------------------------------------------------------------
  10936. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10937. {
  10938. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10939. if (!DirView->IsEditing())
  10940. {
  10941. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10942. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10943. // while searching
  10944. if (Key == VK_BACK)
  10945. {
  10946. if (FIncrementalSearchState.Searching)
  10947. {
  10948. if (FIncrementalSearchState.Text.Length() <= 1)
  10949. {
  10950. ResetIncrementalSearch();
  10951. }
  10952. else
  10953. {
  10954. UnicodeString NewText = LeftStr(FIncrementalSearchState.Text, FIncrementalSearchState.Text.Length() - 1);
  10955. IncrementalSearch(NewText, false, false);
  10956. }
  10957. Key = 0;
  10958. }
  10959. }
  10960. }
  10961. }
  10962. //---------------------------------------------------------------------------
  10963. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10964. {
  10965. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10966. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10967. {
  10968. // Filter control sequences.
  10969. // When not searching yet, prefer use of the space for toggling file selection
  10970. // (so we cannot incrementally search for a string starting with a space).
  10971. if ((Key > VK_SPACE) ||
  10972. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearchState.Searching))
  10973. {
  10974. IncrementalSearch(FIncrementalSearchState.Text + Key, false, false);
  10975. Key = 0;
  10976. }
  10977. }
  10978. }
  10979. //---------------------------------------------------------------------------
  10980. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10981. {
  10982. if (FIncrementalSearchState.Searching)
  10983. {
  10984. FIncrementalSearchState.Reset();
  10985. DirView(osCurrent)->UpdateStatusBar();
  10986. }
  10987. }
  10988. //---------------------------------------------------------------------------
  10989. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10990. {
  10991. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10992. if (Item == NULL)
  10993. {
  10994. MessageBeep(MB_ICONHAND);
  10995. }
  10996. else
  10997. {
  10998. TCustomDirView * ADirView = DirView(osCurrent);
  10999. {
  11000. TAutoNestingCounter Guard(FIncrementalSearching);
  11001. ADirView->FocusItem(Item);
  11002. if (ADirView->NortonLike == nlOff)
  11003. {
  11004. if ((ADirView->Selected != Item) ||
  11005. (ADirView->SelCount > 1))
  11006. {
  11007. ADirView->ClearSelection();
  11008. ADirView->Selected = Item;
  11009. }
  11010. }
  11011. }
  11012. FIncrementalSearchState.Searching = true;
  11013. FIncrementalSearchState.Text = Text;
  11014. Item->MakeVisible(false);
  11015. TListItem * NextItem = SearchFile(Text, true, Reverse);
  11016. FIncrementalSearchState.HaveNext = (NextItem != NULL) && (NextItem != Item);
  11017. ADirView->UpdateStatusBar();
  11018. }
  11019. }
  11020. //---------------------------------------------------------------------------
  11021. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  11022. {
  11023. int Index = Item->Index;
  11024. if (!Reverse)
  11025. {
  11026. Index++;
  11027. if (Index >= Item->Owner->Count)
  11028. {
  11029. Index = 0;
  11030. }
  11031. }
  11032. else
  11033. {
  11034. Index--;
  11035. if (Index < 0)
  11036. {
  11037. Index = Item->Owner->Count - 1;
  11038. }
  11039. }
  11040. return Item->Owner->Item[Index];
  11041. }
  11042. //---------------------------------------------------------------------------
  11043. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  11044. {
  11045. TCustomDirView * ADirView = DirView(osCurrent);
  11046. if (ADirView->Items->Count == 0)
  11047. {
  11048. return NULL;
  11049. }
  11050. else
  11051. {
  11052. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  11053. TListItem * Item = CurrentItem;
  11054. if (SkipCurrent)
  11055. {
  11056. Item = DebugNotNull(GetNextFile(Item, Reverse));
  11057. }
  11058. while (true)
  11059. {
  11060. bool Matches = false;
  11061. switch (WinConfiguration->PanelSearch)
  11062. {
  11063. case isNameStartOnly:
  11064. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item).SubString(1, Text.Length()), Text);
  11065. break;
  11066. case isName:
  11067. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item), Text);
  11068. break;
  11069. case isAll:
  11070. int ColCount = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Count : 1;
  11071. int Index = 0;
  11072. while ((Index < ColCount) && !Matches)
  11073. {
  11074. bool Visible = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Visible[Index] : true;
  11075. if (Visible)
  11076. {
  11077. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  11078. }
  11079. Index++;
  11080. }
  11081. break;
  11082. }
  11083. if (Matches)
  11084. {
  11085. return Item;
  11086. }
  11087. Item = GetNextFile(Item, Reverse);
  11088. if (Item == CurrentItem)
  11089. {
  11090. return NULL;
  11091. }
  11092. }
  11093. }
  11094. }
  11095. //---------------------------------------------------------------------------
  11096. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  11097. {
  11098. ResetIncrementalSearch();
  11099. }
  11100. //---------------------------------------------------------------------------
  11101. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  11102. {
  11103. if (Message.CharCode == VK_TAB)
  11104. {
  11105. if (!FIncrementalSearchState.Text.IsEmpty())
  11106. {
  11107. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  11108. bool Reverse = Shift.Contains(ssShift);
  11109. IncrementalSearch(FIncrementalSearchState.Text, true, Reverse);
  11110. Message.Result = 1;
  11111. return;
  11112. }
  11113. }
  11114. else if (Message.CharCode == VK_ESCAPE)
  11115. {
  11116. if (FIncrementalSearchState.Searching)
  11117. {
  11118. ResetIncrementalSearch();
  11119. Message.Result = 1;
  11120. return;
  11121. }
  11122. }
  11123. TForm::Dispatch(&Message);
  11124. }
  11125. //---------------------------------------------------------------------------
  11126. void __fastcall TCustomScpExplorerForm::Deactivate()
  11127. {
  11128. TForm::Deactivate();
  11129. // E.g. when switching to an internal editor window
  11130. ResetIncrementalSearch();
  11131. }
  11132. //---------------------------------------------------------------------------
  11133. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  11134. {
  11135. // When switching to another application
  11136. ResetIncrementalSearch();
  11137. }
  11138. //---------------------------------------------------------------------------
  11139. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  11140. {
  11141. ResetIncrementalSearch();
  11142. }
  11143. //---------------------------------------------------------------------------
  11144. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  11145. {
  11146. if (FIncrementalSearching <= 0)
  11147. {
  11148. ResetIncrementalSearch();
  11149. }
  11150. }
  11151. //---------------------------------------------------------------------------
  11152. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  11153. {
  11154. CountClicksForWindowPrint(this);
  11155. }
  11156. //---------------------------------------------------------------------------
  11157. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  11158. {
  11159. CenterReconnectToolbar();
  11160. }
  11161. //---------------------------------------------------------------------------
  11162. void TCustomScpExplorerForm::DoExploreFile(TCustomDirView * DirView, const UnicodeString & FileName)
  11163. {
  11164. if (!FileName.IsEmpty())
  11165. {
  11166. DirView->FocusByName(FileName);
  11167. if (DirView->ItemFocused != NULL)
  11168. {
  11169. DirView->ItemFocused->Selected = true;
  11170. }
  11171. }
  11172. }
  11173. //---------------------------------------------------------------------------
  11174. void __fastcall TCustomScpExplorerForm::ExploreFile(const UnicodeString & FileName)
  11175. {
  11176. DoExploreFile(RemoteDirView, FileName);
  11177. }
  11178. //---------------------------------------------------------------------------
  11179. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  11180. {
  11181. if (!FQueueStatusUpdating)
  11182. {
  11183. bool Refresh;
  11184. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  11185. {
  11186. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  11187. }
  11188. else
  11189. {
  11190. if (FQueueFileList->GetCount() > 0)
  11191. {
  11192. FQueueFileList->Clear();
  11193. Refresh = true;
  11194. }
  11195. }
  11196. int Count = FQueueFileList->GetCount();
  11197. if (QueueFileList->Items->Count != Count)
  11198. {
  11199. DebugAssert(Refresh);
  11200. QueueFileList->Items->Count = Count;
  11201. }
  11202. if (Refresh)
  11203. {
  11204. QueueFileList->Invalidate();
  11205. }
  11206. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  11207. }
  11208. }
  11209. //---------------------------------------------------------------------------
  11210. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  11211. {
  11212. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  11213. }
  11214. //---------------------------------------------------------------------------
  11215. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  11216. {
  11217. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  11218. // See TSynchronizeChecklistDialog::UpdateTimer
  11219. if (QueueFileList->Items->Count > 0)
  11220. {
  11221. QueueFileList->Items->Item[0]->MakeVisible(false);
  11222. }
  11223. UpdateQueueFileList();
  11224. }
  11225. //---------------------------------------------------------------------------
  11226. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  11227. {
  11228. Active = QueueView3->Focused() || QueueFileList->Focused();
  11229. }
  11230. //---------------------------------------------------------------------------
  11231. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  11232. {
  11233. QueueLabelUpdateStatus();
  11234. }
  11235. //---------------------------------------------------------------------------
  11236. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  11237. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  11238. {
  11239. int State = FQueueFileList->GetState(Item->Index);
  11240. if (State == qfsProcessed)
  11241. {
  11242. Sender->Canvas->Font->Color = clGrayText;
  11243. }
  11244. }
  11245. //---------------------------------------------------------------------------
  11246. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  11247. {
  11248. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  11249. QueueFileList->Column[0]->Width =
  11250. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  11251. }
  11252. //---------------------------------------------------------------------------
  11253. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  11254. {
  11255. QueueFileListColumnAutoSize();
  11256. }
  11257. //---------------------------------------------------------------------------
  11258. void __fastcall TCustomScpExplorerForm::CloseApp()
  11259. {
  11260. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  11261. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  11262. // So we clear the flag here.
  11263. DebugAssert(NonVisualDataModule->Busy);
  11264. NonVisualDataModule->EndBusy();
  11265. try
  11266. {
  11267. Close();
  11268. }
  11269. __finally
  11270. {
  11271. NonVisualDataModule->StartBusy();
  11272. }
  11273. }
  11274. //---------------------------------------------------------------------------
  11275. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  11276. {
  11277. return (Terminal != NULL) && Terminal->Active;
  11278. }
  11279. //---------------------------------------------------------------------------
  11280. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  11281. {
  11282. return (ManagedSession != NULL);
  11283. }
  11284. //---------------------------------------------------------------------------
  11285. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  11286. {
  11287. return IsActiveTerminal(Terminal);
  11288. }
  11289. //---------------------------------------------------------------------------
  11290. void TCustomScpExplorerForm::LocalLocalCopy(
  11291. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  11292. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  11293. {
  11294. DebugFail();
  11295. }
  11296. //---------------------------------------------------------------------------
  11297. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  11298. {
  11299. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  11300. }
  11301. //---------------------------------------------------------------------------
  11302. void TCustomScpExplorerForm::UpdateTabsSize()
  11303. {
  11304. // 1) Changing tab list triggers the OnResize.
  11305. // 2) Is called in TForm constructor, when we are not ready to call SessionListChanged (particularly when starting with colored session)
  11306. if (!FUpdatingSessionTabs && (FSessionColors != NULL))
  11307. {
  11308. // UpdateTabsCaptionTruncation should be enough
  11309. SessionListChanged(true);
  11310. }
  11311. }
  11312. //---------------------------------------------------------------------------
  11313. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  11314. {
  11315. UpdateTabsSize();
  11316. }
  11317. //---------------------------------------------------------------------------
  11318. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  11319. {
  11320. if (ASession == ManagedSession)
  11321. {
  11322. UpdateSession(ASession);
  11323. }
  11324. TSessionData * Data = ASession->StateData;
  11325. UnicodeString Result;
  11326. if (Side == osLocal)
  11327. {
  11328. Result = Data->LocalDirectory;
  11329. }
  11330. else if (DebugAlwaysTrue(Side == osOther))
  11331. {
  11332. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  11333. }
  11334. return Result;
  11335. }
  11336. //---------------------------------------------------------------------------
  11337. UnicodeString TCustomScpExplorerForm::GetTabHintSessionDetails(TManagedTerminal * ASession)
  11338. {
  11339. UnicodeString Title = TTerminalManager::Instance()->GetSessionTitle(ASession, false);
  11340. UnicodeString Result = ASession->SessionData->DefaultSessionName;
  11341. if (Title == Result)
  11342. {
  11343. Result = EmptyStr;
  11344. }
  11345. else
  11346. {
  11347. Result += L"\n";
  11348. }
  11349. return Result;
  11350. }
  11351. //---------------------------------------------------------------------------
  11352. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  11353. {
  11354. UnicodeString Result = GetTabHintSessionDetails(ASession);
  11355. if (!ASession->Active)
  11356. {
  11357. Result += LoadStr(STATUS_NOT_CONNECTED2);
  11358. }
  11359. else
  11360. {
  11361. Result += GetSessionPath(ASession, osRemote);
  11362. }
  11363. return Result;
  11364. }
  11365. //---------------------------------------------------------------------------
  11366. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  11367. {
  11368. return LoadStr(NEW_REMOTE_TAB_HINT);
  11369. }
  11370. //---------------------------------------------------------------------------
  11371. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  11372. {
  11373. if (Index >= 0)
  11374. {
  11375. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  11376. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  11377. if (TabSession == NULL)
  11378. {
  11379. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  11380. if (NewTabTabCaption != TabSheet->Caption)
  11381. {
  11382. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  11383. }
  11384. }
  11385. else
  11386. {
  11387. TTerminalManager * Manager = TTerminalManager::Instance();
  11388. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  11389. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  11390. }
  11391. }
  11392. }
  11393. //---------------------------------------------------------------------------
  11394. typedef std::vector<TListItem *> TListItemsVector;
  11395. struct TCalculateSizeOperation
  11396. {
  11397. TCalculateSizeStats Stats;
  11398. TListItemsVector ListItems;
  11399. size_t Index;
  11400. };
  11401. //---------------------------------------------------------------------------
  11402. void TCustomScpExplorerForm::CalculateDirectorySizes(TOperationSide Side)
  11403. {
  11404. TCalculateSizeOperation CalculateSizeOperation;
  11405. Side = GetSide(Side);
  11406. TCustomDirView * ADirView = DirView(Side);
  11407. bool LocalSide = IsSideLocalBrowser(Side);
  11408. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, LocalSide, NULL, true));
  11409. std::unique_ptr<TStrings> FileList(new TStringList());
  11410. for (int Index = 0; Index < AllFileList->Count; Index++)
  11411. {
  11412. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  11413. if (ADirView->ItemIsDirectory(Item))
  11414. {
  11415. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  11416. CalculateSizeOperation.ListItems.push_back(Item);
  11417. }
  11418. }
  11419. CalculateSizeOperation.Index = 0;
  11420. __int64 Size = 0;
  11421. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation, &CalculateSizeOperation);
  11422. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  11423. FOnFileOperationFinished = DirectorySizeCalculated;
  11424. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation, foCalculateSize);
  11425. TCalculatedSizes CalculatedSizes;
  11426. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  11427. if (LocalSide)
  11428. {
  11429. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, Side);
  11430. ManagedSession->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  11431. }
  11432. else
  11433. {
  11434. TCalculateSizeParams Params;
  11435. Params.Stats = &CalculateSizeOperation.Stats;
  11436. Params.UseCache = true;
  11437. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  11438. }
  11439. }
  11440. //---------------------------------------------------------------------------
  11441. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(
  11442. TOperationSide Side, const UnicodeString & FileName, bool Success, bool NotCancelled)
  11443. {
  11444. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  11445. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  11446. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  11447. // optimization
  11448. bool GotExpectedItem =
  11449. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  11450. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  11451. int Index = -1;
  11452. if (DebugAlwaysTrue(GotExpectedItem))
  11453. {
  11454. Index = FCalculateSizeOperation->Index;
  11455. FCalculateSizeOperation->Index++;
  11456. }
  11457. else
  11458. {
  11459. TListItemsVector::iterator I =
  11460. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  11461. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  11462. {
  11463. Index = I - FCalculateSizeOperation->ListItems.begin();
  11464. }
  11465. }
  11466. if (DebugAlwaysTrue(Index >= 0) && Success && NotCancelled)
  11467. {
  11468. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  11469. ADirView->SetItemCalculatedSize(Item, Size);
  11470. }
  11471. }
  11472. //---------------------------------------------------------------------------
  11473. void __fastcall TCustomScpExplorerForm::MessageDockRequestDock(TObject *, TTBCustomDockableWindow *, bool & Accept)
  11474. {
  11475. Accept = false;
  11476. }
  11477. //---------------------------------------------------------------------------
  11478. void TCustomScpExplorerForm::AutoSizeColumns(TOperationSide Side)
  11479. {
  11480. // Send Ctrl+Gray+ to the list view
  11481. TKeyboardState KeyState;
  11482. GetKeyboardState(KeyState);
  11483. TKeyboardState NewKeyState;
  11484. memset(NewKeyState, 0, sizeof(NewKeyState));
  11485. NewKeyState[VK_CONTROL] = 0x81;
  11486. SetKeyboardState(NewKeyState);
  11487. SendMessage(DirView(Side)->Handle, WM_KEYDOWN, VK_ADD, 0);
  11488. SetKeyboardState(KeyState);
  11489. }
  11490. //---------------------------------------------------------------------------
  11491. void TCustomScpExplorerForm::QueueResetLayoutColumns()
  11492. {
  11493. LoadListViewStr(QueueView3, QueueViewLayoutDefault);
  11494. }
  11495. //---------------------------------------------------------------------------
  11496. void * TCustomScpExplorerForm::SaveFocus()
  11497. {
  11498. return NULL;
  11499. }
  11500. //---------------------------------------------------------------------------
  11501. void TCustomScpExplorerForm::RestoreFocus(void * Focus)
  11502. {
  11503. DebugUsedParam(Focus);
  11504. DebugAssert(Focus == NULL);
  11505. }
  11506. //---------------------------------------------------------------------------
  11507. void TCustomScpExplorerForm::IncrementalSearchStart()
  11508. {
  11509. TCustomDirView * ADirView = DirView(osCurrent);
  11510. ADirView->SetFocus();
  11511. if (!FIncrementalSearchState.Searching)
  11512. {
  11513. FIncrementalSearchState.Searching = true;
  11514. FIncrementalSearchState.HaveNext = false;
  11515. DebugAssert(FIncrementalSearchState.Text.IsEmpty());
  11516. ADirView->UpdateStatusBar();
  11517. }
  11518. }
  11519. //---------------------------------------------------------------------------
  11520. void __fastcall TCustomScpExplorerForm::RemoteDirViewThumbnailNeeded(
  11521. TUnixDirView *, TListItem * Item, TRemoteFile * File, const TSize & Size, TBitmap *& Bitmap)
  11522. {
  11523. // though when downloading to temporary folder, encryption should not be a problem
  11524. if (Terminal->IsCapable[fcBackgroundTransfers] &&
  11525. !File->IsDirectory)
  11526. {
  11527. UnicodeString FileName = File->FullFileName;
  11528. TFileMasks::TParams MaskParams;
  11529. MaskParams.Size = File->Size;
  11530. MaskParams.Modification = File->Modification;
  11531. if ((File->Size <= static_cast<__int64>(WinConfiguration->RemoteThumbnailSizeLimit) * 1024) &&
  11532. FRemoteThumbnailMask.Matches(FileName, false, File->IsDirectory, &MaskParams))
  11533. {
  11534. Bitmap = TTerminalManager::Instance()->ThumbnailNeeded(Terminal, Item->Index, File, Size);
  11535. }
  11536. }
  11537. }
  11538. //---------------------------------------------------------------------------
  11539. TThumbnailDownloadQueueItem * TCustomScpExplorerForm::AddThumbnailDownloadQueueItem(TManagedTerminal * ATerminal)
  11540. {
  11541. DebugAssert(ATerminal == Terminal);
  11542. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  11543. TemporaryFileCopyParam(CopyParam);
  11544. CopyParam.TransferMode = tmBinary;
  11545. UnicodeString SourceDir = ATerminal->CurrentDirectory;
  11546. UnicodeString TempDir, RootTempDir;
  11547. TemporaryDirectoryForRemoteFiles(SourceDir, CopyParam, true, TempDir, RootTempDir);
  11548. TTerminalQueue * AQueue = TTerminalManager::Instance()->FindQueueForTerminal(ATerminal);
  11549. DebugAssert((Queue == NULL) || (AQueue == Queue)); // we might get here before queue is set
  11550. TThumbnailDownloadQueueItem * QueueItem =
  11551. new TThumbnailDownloadQueueItem(this, Terminal, SourceDir, TempDir, &CopyParam);
  11552. AddQueueItem(AQueue, QueueItem, ATerminal);
  11553. return QueueItem;
  11554. }
  11555. //---------------------------------------------------------------------------
  11556. enum { qccRemoteItemVisible, qccRemoteItemRedraw };
  11557. typedef std::pair<int, UnicodeString> TRemoteItemVisibleData;
  11558. //---------------------------------------------------------------------------
  11559. void TCustomScpExplorerForm::PostThumbnailVisibleQueueQuery(int Index, const UnicodeString & FileName)
  11560. {
  11561. // The queue might be destroyed before the WM_QUEUE_CALLBACK is processed
  11562. TRemoteItemVisibleData * Data = new TRemoteItemVisibleData();
  11563. Data->first = Index;
  11564. Data->second = FileName;
  11565. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemVisible, reinterpret_cast<WPARAM>(Data));
  11566. }
  11567. //---------------------------------------------------------------------------
  11568. void TCustomScpExplorerForm::PostThumbnailDrawRequest(int Index)
  11569. {
  11570. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemRedraw, Index);
  11571. }
  11572. //---------------------------------------------------------------------------
  11573. void TCustomScpExplorerForm::WMQueueCallback(TMessage & Message)
  11574. {
  11575. int Command = Message.WParam;
  11576. if (Command == qccRemoteItemVisible)
  11577. {
  11578. TRemoteItemVisibleData * Data = reinterpret_cast<TRemoteItemVisibleData *>(Message.LParam);
  11579. int Index = Data->first;
  11580. UnicodeString FileName = Data->second;
  11581. delete Data;
  11582. TGuard Guard(Terminal->ThumbnailsSection.get());
  11583. bool Visible = False;
  11584. if (Terminal->ThumbnailsEnabled &&
  11585. // though we should better also disable thumbnails once we switch to different view style
  11586. (RemoteDirView->DirViewStyle == dvsThumbnail))
  11587. {
  11588. // The message might be processed, while we are already loading a different directory
  11589. if ((Index >= 0) &&
  11590. (Index < RemoteDirView->Items->Count))
  11591. {
  11592. TListItem * Item = RemoteDirView->Items->Item[Index];
  11593. Visible =
  11594. (RemoteDirView->ItemFullFileName(Item) == FileName) &&
  11595. ListView_IsItemVisible(RemoteDirView->Handle, Index);
  11596. }
  11597. }
  11598. Terminal->ThumbnailVisible(Index, FileName, Visible);
  11599. }
  11600. else if (Command == qccRemoteItemRedraw)
  11601. {
  11602. int Index = Message.LParam;
  11603. if ((Index >= 0) &&
  11604. (Index < RemoteDirView->Items->Count))
  11605. {
  11606. RemoteDirView->InvalidateItem(RemoteDirView->Items->Item[Index]);
  11607. }
  11608. }
  11609. }
  11610. //---------------------------------------------------------------------------
  11611. void TCustomScpExplorerForm::InitializeRemoteThumbnailMask()
  11612. {
  11613. UnicodeString DefaultRemoteThumbnailMask = L"*.jpg;*.jpeg;*.gif;*.png;*.svg;*.bmp;*.raw;*.ico;*.heic;*.webp";
  11614. UnicodeString RemoteThumbnailMask = WinConfiguration->RemoteThumbnailMask;
  11615. if (RemoteThumbnailMask.IsEmpty() ||
  11616. StartsStr(L"+", RemoteThumbnailMask) || StartsStr(L"-", RemoteThumbnailMask) || StartsStr(L"*", RemoteThumbnailMask))
  11617. {
  11618. std::unique_ptr<TStrings> RemoteThumbnailMasks(new TStringList());
  11619. while (!DefaultRemoteThumbnailMask.IsEmpty())
  11620. {
  11621. RemoteThumbnailMasks->Add(CutToChar(DefaultRemoteThumbnailMask, L';', true));
  11622. }
  11623. RemoteThumbnailMasks.reset(ProcessFeatures(RemoteThumbnailMasks.get(), RemoteThumbnailMask));
  11624. RemoteThumbnailMask = EmptyStr;
  11625. for (int Index = 0; Index < RemoteThumbnailMasks->Count; Index++)
  11626. {
  11627. AddToList(RemoteThumbnailMask, RemoteThumbnailMasks->Strings[Index], L";");
  11628. }
  11629. }
  11630. FRemoteThumbnailMask.Masks = RemoteThumbnailMask;
  11631. }
  11632. //---------------------------------------------------------------------------
  11633. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartLoading(TObject *)
  11634. {
  11635. Terminal->StartLoadingDirectory();
  11636. }
  11637. //---------------------------------------------------------------------------
  11638. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartReading(TObject *)
  11639. {
  11640. Terminal->DisableThumbnails();
  11641. }
  11642. //---------------------------------------------------------------------------
  11643. void TCustomScpExplorerForm::ChangeDirViewStyle(TOperationSide Side, TDirViewStyle DirViewStyle)
  11644. {
  11645. TCustomDirView * ADirView = DirView(Side);
  11646. if (ADirView->DirViewStyle != DirViewStyle)
  11647. {
  11648. if (DirViewStyle == dvsThumbnail)
  11649. {
  11650. if (dynamic_cast<TUnixDirView *>(ADirView) != NULL)
  11651. {
  11652. Configuration->Usage->Inc(L"ThumbnailsRemote");
  11653. }
  11654. else
  11655. {
  11656. Configuration->Usage->Inc(L"ThumbnailsLocal");
  11657. }
  11658. }
  11659. ADirView->DirViewStyle = DirViewStyle;
  11660. UpdateControls();
  11661. }
  11662. }