CustomScpExplorer.cpp 415 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384
  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. TRemoteProperties NewProperties = CurrentProperties;
  4576. Result =
  4577. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4578. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4579. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4580. CalculateSize, CalculateChecksumEvent);
  4581. if (Result)
  4582. {
  4583. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4584. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4585. }
  4586. }
  4587. __finally
  4588. {
  4589. delete GroupList;
  4590. delete UserList;
  4591. }
  4592. }
  4593. else
  4594. {
  4595. DirView(Side)->DisplayPropertiesMenu();
  4596. Result = true;
  4597. }
  4598. return Result;
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4602. {
  4603. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4604. {
  4605. FIgnoreNextDialogChar = Key;
  4606. }
  4607. Key = 0;
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4611. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4612. {
  4613. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4614. if (Command != NULL)
  4615. {
  4616. KeyProcessed(Key, Shift);
  4617. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4618. {
  4619. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4620. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4621. false, false, const_cast<TCustomCommandType *>(Command));
  4622. }
  4623. }
  4624. }
  4625. //---------------------------------------------------------------------------
  4626. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4627. {
  4628. if (!NonVisualDataModule->Busy)
  4629. {
  4630. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4631. {
  4632. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4633. }
  4634. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4635. {
  4636. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4637. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4638. {
  4639. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4640. // But so far it's not a problem, as it does what we want.
  4641. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4642. if (((Action->ShortCut == KeyShortCut) ||
  4643. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4644. AllowedAction(Action, aaShortCut))
  4645. {
  4646. // Has to be called before the action as the dialog char is already in queue.
  4647. // So when the action consumes message queue, we already need to have the
  4648. // FIgnoreNextDialogChar set
  4649. KeyProcessed(Key, Shift);
  4650. // Reset reference to previous component (when menu/toolbar was clicked).
  4651. // Needed to detect that action was invoked by keyboard shortcut
  4652. // in TNonVisualDataModule::ExplorerActionsExecute
  4653. Action->ActionComponent = NULL;
  4654. Action->Execute();
  4655. return;
  4656. }
  4657. }
  4658. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4659. {
  4660. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4661. {
  4662. KeyProcessed(Key, Shift);
  4663. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4664. return;
  4665. }
  4666. }
  4667. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4668. {
  4669. KeyProcessed(Key, Shift);
  4670. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4671. }
  4672. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4673. if (IsCustomShortCut(CustomShortCut))
  4674. {
  4675. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4676. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4677. if (WinConfiguration->SharedBookmarks != NULL)
  4678. {
  4679. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4680. if ((Bookmark != NULL) &&
  4681. OpenBookmark(FCurrentSide, Bookmark))
  4682. {
  4683. KeyProcessed(Key, Shift);
  4684. }
  4685. }
  4686. }
  4687. }
  4688. }
  4689. TForm::KeyDown(Key, Shift);
  4690. }
  4691. //---------------------------------------------------------------------------
  4692. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4693. {
  4694. bool OpenedTerminal = false;
  4695. UnicodeString ProtocolName;
  4696. UnicodeString ProtocolNameHint;
  4697. UnicodeString SecurityProtocolName;
  4698. UnicodeString DurationHint;
  4699. // See the comment in TScpCommanderForm::UpdateControls()
  4700. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4701. if (ActiveTerminal != NULL)
  4702. {
  4703. // Active is not enough here
  4704. if (ActiveTerminal->Status == ssOpened)
  4705. {
  4706. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4707. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4708. if (FileSystemInfo.ProtocolName.IsEmpty())
  4709. {
  4710. ProtocolName = SessionInfo.ProtocolName;
  4711. }
  4712. else
  4713. {
  4714. ProtocolName = FileSystemInfo.ProtocolName;
  4715. }
  4716. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4717. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4718. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4719. OpenedTerminal = true;
  4720. }
  4721. else if (ActiveTerminal->Status > ssClosed)
  4722. {
  4723. ProtocolName = LoadStr(STATUS_CONNECTING);
  4724. }
  4725. else
  4726. {
  4727. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4728. }
  4729. }
  4730. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4731. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4732. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4733. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4734. if (ProtocolStatusPanel->Caption != ProtocolName)
  4735. {
  4736. ProtocolStatusPanel->Caption = ProtocolName;
  4737. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4738. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4739. }
  4740. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4741. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4742. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4743. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4744. SecurityStatusPanel->Enabled = SecurityEnabled;
  4745. UnicodeString SecurityProtocolHint;
  4746. if (SecurityEnabled)
  4747. {
  4748. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4749. }
  4750. else
  4751. {
  4752. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4753. }
  4754. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4755. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4756. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4757. DurationStatusPanel->Hint = DurationHint;
  4758. UpdateStatusBar();
  4759. }
  4760. //---------------------------------------------------------------------------
  4761. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4762. {
  4763. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4764. DebugAssert(SessionStatusBar != NULL);
  4765. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4766. if (!FNote.IsEmpty())
  4767. {
  4768. NoteStatusPanel->Caption = FNote;
  4769. }
  4770. else
  4771. {
  4772. UpdateStatusPanelText(NoteStatusPanel);
  4773. }
  4774. NoteStatusPanel->Hint = FNoteHints;
  4775. UnicodeString LoginTime;
  4776. // See the comment in TScpCommanderForm::UpdateControls()
  4777. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4778. // Active is not enough here
  4779. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4780. {
  4781. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4782. LoginTime = FormatDateTimeSpan(Now() - SessionInfo.LoginTime);
  4783. }
  4784. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4785. DurationStatusPanel->Caption = LoginTime;
  4786. }
  4787. //---------------------------------------------------------------------------
  4788. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4789. {
  4790. Panel->Caption = L"";
  4791. }
  4792. //---------------------------------------------------------------------------
  4793. void __fastcall TCustomScpExplorerForm::Idle()
  4794. {
  4795. if (FShowing ||
  4796. // Particularly for
  4797. // - Standalone editing
  4798. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4799. // while "keeping remote directory up to date".
  4800. StandaloneOperation)
  4801. {
  4802. FEditorManager->Check();
  4803. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4804. // that needs to know if queue view is visible (and it may be closed after queue update)
  4805. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4806. }
  4807. if (FShowing)
  4808. {
  4809. if (!NonVisualDataModule->Busy &&
  4810. // Menu is opened or drag&drop is going on
  4811. (Mouse->Capture == NULL))
  4812. {
  4813. if (FRefreshRemoteDirectory)
  4814. {
  4815. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4816. {
  4817. Terminal->RefreshDirectory();
  4818. }
  4819. FRefreshRemoteDirectory = false;
  4820. }
  4821. if (FRefreshLocalDirectory)
  4822. {
  4823. ReloadLocalDirectory();
  4824. FRefreshLocalDirectory = false;
  4825. }
  4826. if (WinConfiguration->RefreshRemotePanel)
  4827. {
  4828. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4829. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4830. {
  4831. RemoteDirView->ReloadDirectory();
  4832. }
  4833. }
  4834. }
  4835. // TB2 shows accels on Alt key down, but hides it only after menu modal loop finishes.
  4836. // But if Alt is used to switch apps or for keyboard shortcut, the menu modal loop does not happen and accelerators stay displayed.
  4837. // It's difficult to fix this in TB2, as there's no "up" equivalent to CM_DIALOGKEY, which shows the accels.
  4838. // 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.
  4839. TTBCustomToolbar * MenuToolbar = DebugNotNull(dynamic_cast<TTBCustomToolbar *>(GetComponent(fcMenu)));
  4840. MenuToolbar->Idle();
  4841. }
  4842. if (FShowing || StandaloneOperation)
  4843. {
  4844. if (FQueueStatusInvalidated)
  4845. {
  4846. UpdateQueueStatus(false);
  4847. }
  4848. RefreshQueueItems();
  4849. }
  4850. if (FShowing)
  4851. {
  4852. UpdateStatusBar();
  4853. }
  4854. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4855. {
  4856. FClipboardFakeMonitorsPendingReset = false;
  4857. FClipboardFakeMonitors.reset(NULL);
  4858. }
  4859. FIgnoreNextDialogChar = 0;
  4860. }
  4861. //---------------------------------------------------------------------------
  4862. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4863. {
  4864. try
  4865. {
  4866. FUserActionTimer->Enabled = false;
  4867. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4868. {
  4869. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4870. {
  4871. FPendingQueueActionItem->ProcessUserAction();
  4872. }
  4873. }
  4874. }
  4875. __finally
  4876. {
  4877. FPendingQueueActionItem = NULL;
  4878. }
  4879. }
  4880. //---------------------------------------------------------------------------
  4881. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4882. {
  4883. if (WinConfiguration->MinimizeToTray)
  4884. {
  4885. UpdateTrayIcon();
  4886. FTrayIcon->Visible = true;
  4887. if (Visible)
  4888. {
  4889. ShowWindow(Handle, SW_HIDE);
  4890. }
  4891. }
  4892. }
  4893. //---------------------------------------------------------------------------
  4894. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4895. {
  4896. // WORKAROUND
  4897. // When restoring maximized window from minimization,
  4898. // rarely some controls do not align properly.
  4899. // Two instances seen (both for Commander):
  4900. // - When restoring, window is temporarily narrower (not maximized),
  4901. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4902. // Once maximized already, top dock shinks back, but the session PageControl,
  4903. // do not align up, leaving space between TopDock and PageControl.
  4904. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4905. for (int Index = 0; Index < ControlCount; Index++)
  4906. {
  4907. RealignControl(Controls[Index]);
  4908. }
  4909. if (FTrayIcon->Visible)
  4910. {
  4911. FTrayIcon->Visible = false;
  4912. if (Visible)
  4913. {
  4914. ShowWindow(Handle, SW_SHOW);
  4915. }
  4916. }
  4917. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4918. {
  4919. FNeedSession = false;
  4920. NonVisualDataModule->StartBusy();
  4921. try
  4922. {
  4923. NeedSession(true);
  4924. }
  4925. __finally
  4926. {
  4927. NonVisualDataModule->EndBusy();
  4928. }
  4929. }
  4930. }
  4931. //---------------------------------------------------------------------------
  4932. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4933. {
  4934. FTrayIcon->Hint = GetMainForm()->Caption;
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4938. {
  4939. UpdateTrayIcon();
  4940. }
  4941. //---------------------------------------------------------------------------
  4942. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4943. {
  4944. // workaround
  4945. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4946. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4947. // But WM_ACTIVATEAPP message can be received even when
  4948. // the main window is minimized to the tray and internal editor window is focused
  4949. // (after another application was previously active)
  4950. if (::IsIconic(Handle))
  4951. {
  4952. if (!IsAppIconic())
  4953. {
  4954. SetAppIconic(true);
  4955. }
  4956. }
  4957. ::ApplicationRestore();
  4958. Application->BringToFront();
  4959. }
  4960. //---------------------------------------------------------------------------
  4961. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4962. {
  4963. RestoreApp();
  4964. }
  4965. //---------------------------------------------------------------------------
  4966. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4967. {
  4968. if (OpenInNewWindow())
  4969. {
  4970. ExecuteNewInstance(SessionUrl);
  4971. }
  4972. else
  4973. {
  4974. TTerminalManager::Instance()->NewSession(SessionUrl);
  4975. }
  4976. }
  4977. //---------------------------------------------------------------------------
  4978. void TCustomScpExplorerForm::NewTab(TOperationSide, bool)
  4979. {
  4980. NewSession();
  4981. }
  4982. //---------------------------------------------------------------------------
  4983. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4984. {
  4985. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4986. StoredSessions->NewSession(SessionName, SessionData);
  4987. // modified only, explicit
  4988. StoredSessions->Save(false, true);
  4989. // encode session name because of slashes in hierarchical sessions
  4990. return EncodeUrlString(SessionName);
  4991. }
  4992. //---------------------------------------------------------------------------
  4993. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4994. {
  4995. // current working directories become defaults here, what is not right
  4996. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4997. return SaveHiddenDuplicateSession(SessionData.get());
  4998. }
  4999. //---------------------------------------------------------------------------
  5000. void __fastcall TCustomScpExplorerForm::DuplicateTab()
  5001. {
  5002. if (OpenInNewWindow())
  5003. {
  5004. ExecuteNewInstance(CreateHiddenDuplicateSession());
  5005. }
  5006. else
  5007. {
  5008. // current working directories become defaults here, what is not right
  5009. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5010. TTerminalManager * Manager = TTerminalManager::Instance();
  5011. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  5012. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  5013. // We definitely want these
  5014. ASession->Disconnected = ManagedSession->Disconnected;
  5015. // Not sure about these two
  5016. ASession->Permanent = ManagedSession->Permanent;
  5017. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  5018. Manager->ActiveSession = ASession;
  5019. }
  5020. }
  5021. //---------------------------------------------------------------------------
  5022. void __fastcall TCustomScpExplorerForm::RenameTab()
  5023. {
  5024. UnicodeString Name = ManagedSession->SessionData->SessionName;
  5025. if (InputDialog(LoadStr(RENAME_TAB_TITLE), LoadStr(RENAME_TAB_PROMPT), Name, HELP_TAB_RENAME) &&
  5026. // When submitting the default name, do not fix it
  5027. (Name != ManagedSession->SessionData->SessionName))
  5028. {
  5029. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  5030. TSessionData::ValidateName(Name);
  5031. // This is inconsistent with how color (for example) is handled.
  5032. ManagedSession->SessionData->Name = Name;
  5033. UpdateControls();
  5034. // Add/Remove distinguishing paths from sessions of the same name.
  5035. SessionListChanged();
  5036. }
  5037. }
  5038. //---------------------------------------------------------------------------
  5039. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  5040. {
  5041. DebugAssert(Queue != NULL);
  5042. bool Result = Queue->IsEmpty;
  5043. if (!Result)
  5044. {
  5045. SetFocus();
  5046. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  5047. }
  5048. return Result;
  5049. }
  5050. //---------------------------------------------------------------------------
  5051. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  5052. {
  5053. return CanCloseQueue(FQueue);
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. void __fastcall TCustomScpExplorerForm::CloseTab()
  5057. {
  5058. if (CanCloseQueue())
  5059. {
  5060. TTerminalManager::Instance()->FreeActiveTerminal();
  5061. }
  5062. }
  5063. //---------------------------------------------------------------------------
  5064. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  5065. {
  5066. if (CanCloseQueue())
  5067. {
  5068. TTerminalManager::Instance()->DisconnectActiveTerminal();
  5069. }
  5070. }
  5071. //---------------------------------------------------------------------------
  5072. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  5073. {
  5074. DetachTerminal(Terminal);
  5075. RemoteDirView->Terminal = Terminal;
  5076. UpdateRemotePathComboBox(false);
  5077. InitStatusBar();
  5078. UpdateControls();
  5079. }
  5080. //---------------------------------------------------------------------------
  5081. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  5082. {
  5083. InitStatusBar();
  5084. }
  5085. //---------------------------------------------------------------------------
  5086. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  5087. {
  5088. if (DebugAlwaysTrue(!Terminal->Active))
  5089. {
  5090. TTerminalManager::Instance()->ReconnectActiveTerminal();
  5091. }
  5092. }
  5093. //---------------------------------------------------------------------------
  5094. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  5095. {
  5096. if (OpenInNewWindow())
  5097. {
  5098. // encode session name because of slashes in hierarchical sessions
  5099. ExecuteNewInstance(EncodeUrlString(Data->Name));
  5100. }
  5101. else
  5102. {
  5103. TTerminalManager * Manager = TTerminalManager::Instance();
  5104. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  5105. Manager->ActiveSession = Terminal;
  5106. }
  5107. }
  5108. //---------------------------------------------------------------------------
  5109. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  5110. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  5111. {
  5112. TTerminalManager * Manager = TTerminalManager::Instance();
  5113. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5114. // This asks for a master password. Maybe we should postpone asking until a connection is actually opened.
  5115. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  5116. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  5117. {
  5118. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  5119. // FirstSession can be null, if none of the workspace sites exist anymore
  5120. // or if all workspace sessions are not suported by the interface
  5121. // (when trying to open all local-local workspace in "explorer" interface)
  5122. if (FirstSession != NULL)
  5123. {
  5124. if (!ConnectFirstTerminal)
  5125. {
  5126. FirstSession->Disconnected = true;
  5127. FirstSession->DisconnectedTemporarily = true;
  5128. }
  5129. Manager->ActiveSession = FirstSession;
  5130. }
  5131. }
  5132. }
  5133. //---------------------------------------------------------------------------
  5134. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  5135. {
  5136. if (OpenInNewWindow())
  5137. {
  5138. ExecuteNewInstance(Name);
  5139. }
  5140. else
  5141. {
  5142. DoOpenFolderOrWorkspace(Name, true, false);
  5143. }
  5144. }
  5145. //---------------------------------------------------------------------------
  5146. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  5147. bool &CanClose)
  5148. {
  5149. AppLog(L"Windows close query");
  5150. // See the comment in CloseApp()
  5151. if (NonVisualDataModule->Busy)
  5152. {
  5153. CanClose = false;
  5154. }
  5155. else
  5156. {
  5157. TTerminalManager * Manager = TTerminalManager::Instance();
  5158. int ActiveSessions = 0;
  5159. for (int Index = 0; Index < Manager->Count; Index++)
  5160. {
  5161. if (Manager->Sessions[Index]->Active)
  5162. {
  5163. ActiveSessions++;
  5164. }
  5165. }
  5166. // Confirm, when there's at least one active remote session or
  5167. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  5168. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  5169. WinConfiguration->ConfirmClosingSession)
  5170. {
  5171. unsigned int Result;
  5172. TMessageParams Params(mpNeverAskAgainCheck);
  5173. UnicodeString Message;
  5174. int Answers = qaOK | qaCancel;
  5175. // The current session is the only active session
  5176. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  5177. {
  5178. if (!WinConfiguration->AutoSaveWorkspace)
  5179. {
  5180. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  5181. }
  5182. else
  5183. {
  5184. Message = LoadStr(CLOSE_SESSION);
  5185. }
  5186. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  5187. }
  5188. // Multiple active sessions or one active session, but it's not the current one
  5189. else if (ActiveSessions > 0)
  5190. {
  5191. if (!WinConfiguration->AutoSaveWorkspace)
  5192. {
  5193. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  5194. }
  5195. else
  5196. {
  5197. Message = LoadStr(CLOSE_SESSIONS);
  5198. }
  5199. }
  5200. // Multiple tabs, but all are inactive or local, and saving of worspace is not enabled
  5201. else
  5202. {
  5203. DebugAlwaysTrue(Manager->Count > 1);
  5204. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  5205. Message = LoadStr(CLOSE_WORKSPACE);
  5206. }
  5207. UnicodeString Note;
  5208. if (WinConfiguration->AutoSaveWorkspace)
  5209. {
  5210. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  5211. }
  5212. else
  5213. {
  5214. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  5215. Answers = qaYes | qaNo | qaCancel;
  5216. }
  5217. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  5218. SetFocus();
  5219. Result = MessageDialog(Message, qtConfirmation,
  5220. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  5221. if (Result == qaNeverAskAgain)
  5222. {
  5223. WinConfiguration->ConfirmClosingSession = false;
  5224. }
  5225. if (Result == qaNo)
  5226. {
  5227. CanClose = SaveWorkspace(true);
  5228. // note that the workspace will be saved redundatly again from FormClose
  5229. }
  5230. else
  5231. {
  5232. CanClose =
  5233. (Result == qaOK) ||
  5234. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  5235. (Result == qaNeverAskAgain);
  5236. }
  5237. }
  5238. if (CanClose && HasActiveTerminal())
  5239. {
  5240. CanClose = CanCloseQueue();
  5241. }
  5242. }
  5243. if (CanClose)
  5244. {
  5245. CanClose =
  5246. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  5247. FEditorManager->CloseExternalFilesWithoutProcess();
  5248. if (CanClose)
  5249. {
  5250. while (CanClose && (FLocalEditors->Count > 0))
  5251. {
  5252. int PrevCount = FLocalEditors->Count;
  5253. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  5254. CanClose = (FLocalEditors->Count < PrevCount);
  5255. }
  5256. if (CanClose)
  5257. {
  5258. CanClose = FEditorManager->Empty(true);
  5259. if (!CanClose)
  5260. {
  5261. SetFocus();
  5262. CanClose =
  5263. (MessageDialog(
  5264. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  5265. }
  5266. }
  5267. }
  5268. }
  5269. }
  5270. //---------------------------------------------------------------------------
  5271. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  5272. {
  5273. TForm * Form = dynamic_cast<TForm *>(Sender);
  5274. DebugAssert(Form != NULL);
  5275. Form->Close();
  5276. }
  5277. //---------------------------------------------------------------------------
  5278. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  5279. {
  5280. TForm * Form = dynamic_cast<TForm *>(Sender);
  5281. delete Form;
  5282. }
  5283. //---------------------------------------------------------------------------
  5284. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  5285. {
  5286. while (FLocalEditors->Count > 0)
  5287. {
  5288. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  5289. }
  5290. }
  5291. //---------------------------------------------------------------------------
  5292. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  5293. TObject *Sender)
  5294. {
  5295. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  5296. try
  5297. {
  5298. SetProperties(osRemote, FileList);
  5299. }
  5300. __finally
  5301. {
  5302. delete FileList;
  5303. }
  5304. }
  5305. //---------------------------------------------------------------------------
  5306. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  5307. {
  5308. if (value)
  5309. {
  5310. if (Component == fcCustomCommandsBand)
  5311. {
  5312. UpdateCustomCommandsToolbar();
  5313. }
  5314. if (Component == fcQueueFileList)
  5315. {
  5316. DebugAssert(!QueueFileListSplitter->Visible);
  5317. AdjustQueueLayout();
  5318. UpdateQueueFileList();
  5319. }
  5320. }
  5321. }
  5322. //---------------------------------------------------------------------------
  5323. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5324. {
  5325. int MinHeightLimit =
  5326. GetStaticQueuePanelComponentsHeight() +
  5327. QueueFileListSplitter->Height +
  5328. QueueFileList->Height +
  5329. GetMinQueueViewHeight();
  5330. if (QueuePanel->ClientHeight < MinHeightLimit)
  5331. {
  5332. QueuePanel->ClientHeight = MinHeightLimit;
  5333. }
  5334. }
  5335. //---------------------------------------------------------------------------
  5336. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5337. {
  5338. TControl * Control = GetComponent(Component);
  5339. DebugAssert(Control);
  5340. bool Changed = (Control->Visible != value);
  5341. if (Changed)
  5342. {
  5343. ComponentShowing(Component, value);
  5344. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5345. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5346. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5347. if (value)
  5348. {
  5349. int RemainingHeight = Control->Parent->ClientHeight;
  5350. int RemainingWidth = Control->Parent->ClientWidth;
  5351. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5352. {
  5353. TControl * ChildControl = Control->Parent->Controls[i];
  5354. if (ChildControl->Visible)
  5355. {
  5356. switch (ChildControl->Align)
  5357. {
  5358. case alTop:
  5359. case alBottom:
  5360. RemainingHeight -= ChildControl->Height;
  5361. break;
  5362. case alLeft:
  5363. case alRight:
  5364. RemainingWidth -= ChildControl->Width;
  5365. break;
  5366. }
  5367. }
  5368. }
  5369. int Reserve = ScaleByTextHeight(this, 32);
  5370. // queue in explorer, trees in commander
  5371. if (Control->Height > RemainingHeight - Reserve)
  5372. {
  5373. Control->Height = RemainingHeight / 2;
  5374. }
  5375. if (Control->Width > RemainingWidth - Reserve)
  5376. {
  5377. Control->Width = RemainingWidth / 2;
  5378. }
  5379. }
  5380. Control->Visible = value;
  5381. if (WasFocused && Visible)
  5382. {
  5383. DirView(osCurrent)->SetFocus();
  5384. }
  5385. FixControlsPlacement();
  5386. }
  5387. }
  5388. //---------------------------------------------------------------------------
  5389. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5390. {
  5391. TControl * Control = GetComponent(Component);
  5392. if (Control == NULL)
  5393. {
  5394. return false;
  5395. }
  5396. else
  5397. {
  5398. return Control->Visible;
  5399. }
  5400. }
  5401. //---------------------------------------------------------------------------
  5402. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5403. {
  5404. bool Result;
  5405. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5406. {
  5407. Result = !IsUWP();
  5408. }
  5409. else
  5410. {
  5411. Result = true;
  5412. }
  5413. return Result;
  5414. }
  5415. //---------------------------------------------------------------------------
  5416. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5417. {
  5418. if (DirView->ItemFocused != NULL)
  5419. {
  5420. DirView->ItemFocused->MakeVisible(false);
  5421. }
  5422. }
  5423. //---------------------------------------------------------------------------
  5424. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5425. {
  5426. MakeFocusedItemVisible(RemoteDirView);
  5427. QueueSplitter->Visible = QueuePanel->Visible;
  5428. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5429. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5430. TControl * TopControlsOrder[] =
  5431. { TopDock, MessageDock, SessionsPageControl };
  5432. SetVerticalControlsOrder(TopControlsOrder, LENOF(TopControlsOrder));
  5433. TControl * QueueControlsOrder[] =
  5434. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5435. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5436. }
  5437. //---------------------------------------------------------------------------
  5438. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5439. {
  5440. switch (Component) {
  5441. case fcStatusBar: return RemoteStatusBar;
  5442. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5443. case fcQueueView: return QueuePanel;
  5444. case fcQueueToolbar: return QueueDock;
  5445. case fcRemoteTree: return RemoteDrivePanel;
  5446. case fcSessionsTabs: return SessionsPageControl;
  5447. case fcQueueFileList: return QueueFileList;
  5448. default: return NULL;
  5449. }
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5453. TObject *Sender, TListColumn *Column, TPoint &Point)
  5454. {
  5455. DebugAssert(NonVisualDataModule && Column && Sender);
  5456. NonVisualDataModule->ListColumn = Column;
  5457. TPopupMenu * DirViewColumnMenu;
  5458. if (Sender == DirView(osOther))
  5459. {
  5460. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5461. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible = (Column->Index == uvName);
  5462. bool SizeColumn = (Column->Index == uvSize);
  5463. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible = SizeColumn;
  5464. NonVisualDataModule->RemoteCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5465. }
  5466. else
  5467. {
  5468. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5469. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible = (Column->Index == dvName);
  5470. bool SizeColumn = (Column->Index == dvSize);
  5471. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible = SizeColumn;
  5472. NonVisualDataModule->LocalCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5473. }
  5474. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5475. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5476. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5477. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5478. }
  5479. //---------------------------------------------------------------------------
  5480. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5481. TObject *Sender, TListItem *Item, bool &AllowExec)
  5482. {
  5483. DoDirViewExecFile(Sender, Item, AllowExec);
  5484. }
  5485. //---------------------------------------------------------------------------
  5486. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5487. TListItem * Item, bool & AllowExec)
  5488. {
  5489. DebugAssert(Sender && Item && Configuration);
  5490. DebugAssert(AllowExec);
  5491. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5492. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5493. bool Remote = !IsSideLocalBrowser(Side);
  5494. DebugAssert(Item == ADirView->ItemFocused);
  5495. bool IsDirectory = ADirView->ItemIsDirectory(Item);
  5496. TResolvedDoubleClickAction Action;
  5497. if (FForceExecution)
  5498. {
  5499. Action = IsDirectory ? rdcaChangeDir : rdcaOpen;
  5500. }
  5501. else
  5502. {
  5503. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  5504. Action = WinConfiguration->ResolveDoubleClickAction(IsDirectory, ATerminal);
  5505. }
  5506. if (Action == rdcaCopy)
  5507. {
  5508. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5509. UnlockWindow();
  5510. try
  5511. {
  5512. if (IsLocalBrowserMode())
  5513. {
  5514. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5515. }
  5516. else
  5517. {
  5518. if (HasActiveTerminal())
  5519. {
  5520. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5521. }
  5522. }
  5523. }
  5524. __finally
  5525. {
  5526. LockWindow();
  5527. }
  5528. AllowExec = false;
  5529. }
  5530. else if (Action == rdcaEdit)
  5531. {
  5532. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5533. {
  5534. ExecuteFile(Side, efDefaultEditor);
  5535. AllowExec = false;
  5536. }
  5537. }
  5538. else if (Action == rdcaOpen)
  5539. {
  5540. if (DebugAlwaysTrue(!IsDirectory) && Remote && !WinConfiguration->DisableOpenEdit)
  5541. {
  5542. ExecuteFile(osRemote, efShell);
  5543. AllowExec = false;
  5544. }
  5545. }
  5546. }
  5547. //---------------------------------------------------------------------------
  5548. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5549. {
  5550. return ((Side == osRemote) || (Side == osCurrent));
  5551. }
  5552. //---------------------------------------------------------------------------
  5553. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5554. {
  5555. DebugFail();
  5556. }
  5557. //---------------------------------------------------------------------------
  5558. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5559. {
  5560. DebugFail();
  5561. }
  5562. //---------------------------------------------------------------------------
  5563. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5564. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5565. {
  5566. TSynchronizeParamType Params;
  5567. Params.LocalDirectory = LocalDirectory;
  5568. Params.RemoteDirectory = RemoteDirectory;
  5569. int UnusedParams =
  5570. (GUIConfiguration->SynchronizeParams &
  5571. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5572. TTerminal::spCaseSensitive | TTerminal::spMirror | TTerminal::spByChecksum));
  5573. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5574. Params.Options = GUIConfiguration->SynchronizeOptions;
  5575. bool SaveSettings = false;
  5576. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5577. &DoSynchronizeTooManyDirectories);
  5578. DebugAssert(FSynchronizeController == NULL);
  5579. FSynchronizeController = &Controller;
  5580. bool Result;
  5581. try
  5582. {
  5583. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5584. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5585. int Options =
  5586. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5587. DebugAssert(FOnFeedSynchronizeError == NULL);
  5588. DebugAssert(FOnSynchronizeAbort == NULL);
  5589. DebugAssert(FSynchronizeTerminal == NULL);
  5590. FSynchronizeTerminal = Terminal;
  5591. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5592. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5593. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5594. if (Result)
  5595. {
  5596. if (SaveSettings)
  5597. {
  5598. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5599. GUIConfiguration->SynchronizeOptions = Params.Options;
  5600. }
  5601. else
  5602. {
  5603. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5604. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5605. FLAGSET(Params.Options, soSynchronize))
  5606. {
  5607. GUIConfiguration->SynchronizeOptions =
  5608. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5609. soSynchronize;
  5610. }
  5611. }
  5612. LocalDirectory = Params.LocalDirectory;
  5613. RemoteDirectory = Params.RemoteDirectory;
  5614. }
  5615. }
  5616. __finally
  5617. {
  5618. FSynchronizeController = NULL;
  5619. DebugAssert(FOnFeedSynchronizeError == NULL);
  5620. FOnFeedSynchronizeError = NULL;
  5621. DebugAssert(FOnSynchronizeAbort == NULL);
  5622. FOnSynchronizeAbort = NULL;
  5623. FSynchronizeTerminal = NULL;
  5624. }
  5625. return Result;
  5626. }
  5627. //---------------------------------------------------------------------------
  5628. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5629. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5630. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5631. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5632. TSynchronizeOptions * Options, bool Full)
  5633. {
  5634. // Keep-up-to-date mode
  5635. if (Terminal->Status == ssOpened)
  5636. {
  5637. try
  5638. {
  5639. int PParams = Params.Params;
  5640. if (!Full)
  5641. {
  5642. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5643. if (FLAGSET(Params.Options, soRecurse))
  5644. {
  5645. PParams |= TTerminal::spSubDirs;
  5646. }
  5647. }
  5648. else
  5649. {
  5650. // if keepuptodate is non-recursive,
  5651. // full sync before has to be non-recursive as well
  5652. if (FLAGCLEAR(Params.Options, soRecurse))
  5653. {
  5654. PParams |= TTerminal::spNoRecurse;
  5655. }
  5656. }
  5657. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5658. PParams, Checklist, Options);
  5659. }
  5660. catch (Exception & E)
  5661. {
  5662. if (!Terminal->Active)
  5663. {
  5664. ShowExtendedExceptionEx(Terminal, &E);
  5665. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5666. if (!Terminal->Active)
  5667. {
  5668. throw;
  5669. }
  5670. }
  5671. else
  5672. {
  5673. if (FLAGSET(Params.Options, soContinueOnError) &&
  5674. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5675. {
  5676. // noop, already logged in MoreMessageDialog
  5677. }
  5678. else
  5679. {
  5680. // We get mostly EAbort here, so this is noop.
  5681. // Exception is an error when listing directories while looking for differences.
  5682. ShowExtendedExceptionEx(Terminal, &E);
  5683. throw;
  5684. }
  5685. }
  5686. }
  5687. }
  5688. }
  5689. //---------------------------------------------------------------------------
  5690. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5691. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5692. const UnicodeString ErrorStr)
  5693. {
  5694. if (!Directory.IsEmpty())
  5695. {
  5696. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5697. }
  5698. else
  5699. {
  5700. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5701. }
  5702. }
  5703. //---------------------------------------------------------------------------
  5704. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5705. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5706. {
  5707. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5708. {
  5709. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5710. }
  5711. else
  5712. {
  5713. TMessageParams Params(mpNeverAskAgainCheck);
  5714. unsigned int Result = MessageDialog(
  5715. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5716. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5717. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5718. {
  5719. MaxDirectories *= 2;
  5720. if (Result == qaNeverAskAgain)
  5721. {
  5722. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5723. }
  5724. }
  5725. else
  5726. {
  5727. Abort();
  5728. }
  5729. }
  5730. }
  5731. //---------------------------------------------------------------------------
  5732. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5733. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5734. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5735. TSynchronizeOptions * Options)
  5736. {
  5737. // Keep-up-to-date mode
  5738. DebugAssert(!FAutoOperation);
  5739. void * BatchStorage;
  5740. BatchStart(BatchStorage);
  5741. FAutoOperation = true;
  5742. bool AnyOperation = false;
  5743. TDateTime StartTime = Now();
  5744. TSynchronizeChecklist * AChecklist = NULL;
  5745. try
  5746. {
  5747. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5748. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5749. {
  5750. FSynchronizeProgressForm->Start();
  5751. }
  5752. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5753. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5754. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5755. Options);
  5756. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5757. SAFE_DESTROY(FSynchronizeProgressForm);
  5758. AnyOperation = (AChecklist->CheckedCount > 0);
  5759. if (AnyOperation)
  5760. {
  5761. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5762. CreateProgressForm(&SynchronizeProgress);
  5763. try
  5764. {
  5765. Terminal->SynchronizeApply(
  5766. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5767. SynchronizeProcessedItem, NULL, NULL, NULL);
  5768. }
  5769. __finally
  5770. {
  5771. DestroyProgressForm();
  5772. }
  5773. }
  5774. }
  5775. __finally
  5776. {
  5777. if (Checklist == NULL)
  5778. {
  5779. delete AChecklist;
  5780. }
  5781. else
  5782. {
  5783. *Checklist = AChecklist;
  5784. }
  5785. FAutoOperation = false;
  5786. SAFE_DESTROY(FSynchronizeProgressForm);
  5787. BatchEnd(BatchStorage);
  5788. ReloadLocalDirectory();
  5789. if (AnyOperation)
  5790. {
  5791. OperationComplete(StartTime);
  5792. }
  5793. }
  5794. }
  5795. //---------------------------------------------------------------------------
  5796. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5797. {
  5798. // can be called from command line
  5799. return Visible &&
  5800. ((DirView(osRemote)->SelCount > 0) ||
  5801. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5802. }
  5803. //---------------------------------------------------------------------------
  5804. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5805. {
  5806. LogSynchronizeEvent(Terminal, Message);
  5807. }
  5808. //---------------------------------------------------------------------------
  5809. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5810. int Params, TSynchronizeOptions & Options)
  5811. {
  5812. DebugAssert(!IsLocalBrowserMode());
  5813. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5814. {
  5815. Options.Filter = new TStringList();
  5816. Options.Filter->CaseSensitive = false;
  5817. Options.Filter->Duplicates = Types::dupAccept;
  5818. if (DirView(osRemote)->SelCount > 0)
  5819. {
  5820. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5821. }
  5822. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5823. {
  5824. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5825. }
  5826. Options.Filter->Sort();
  5827. }
  5828. }
  5829. //---------------------------------------------------------------------------
  5830. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5831. {
  5832. TCopyParamType Defaults;
  5833. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5834. ConfigStorage->AccessMode = smRead;
  5835. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5836. {
  5837. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5838. }
  5839. ConfigStorage.reset(NULL);
  5840. std::unique_ptr<TStringList> Options(new TStringList());
  5841. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5842. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5843. UnicodeString Result;
  5844. if (Options->Count > 0)
  5845. {
  5846. Result =
  5847. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5848. }
  5849. return Result;
  5850. }
  5851. //---------------------------------------------------------------------------
  5852. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5853. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5854. {
  5855. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5856. UnicodeString AdditionalParams =
  5857. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5858. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5859. SerializeCopyParamForCommandLine(CopyParams),
  5860. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5861. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5862. ExecuteNewInstance(SessionName, AdditionalParams);
  5863. }
  5864. //---------------------------------------------------------------------------
  5865. struct TSynchronizeParams
  5866. {
  5867. UnicodeString LocalDirectory;
  5868. UnicodeString RemoteDirectory;
  5869. TSynchronizeMode Mode;
  5870. TSynchronizeChecklist * Checklist;
  5871. int Params;
  5872. TCopyParamType * CopyParam;
  5873. TDateTime CollectElapsed;
  5874. TDateTime * StartTime;
  5875. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5876. };
  5877. //---------------------------------------------------------------------------
  5878. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5879. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5880. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5881. {
  5882. DebugAssert(!FAutoOperation);
  5883. void * BatchStorage;
  5884. BatchStart(BatchStorage);
  5885. FAutoOperation = true;
  5886. TFileOperationStatistics Statistics;
  5887. TDateTime Start = Now();
  5888. try
  5889. {
  5890. Params.OnProcessedItem = OnProcessedItem;
  5891. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5892. CreateProgressForm(&SynchronizeProgress);
  5893. Terminal->SynchronizeApply(
  5894. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5895. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5896. &Statistics);
  5897. }
  5898. __finally
  5899. {
  5900. Params.OnProcessedItem = NULL;
  5901. FAutoOperation = false;
  5902. DestroyProgressForm();
  5903. BatchEnd(BatchStorage);
  5904. ReloadLocalDirectory();
  5905. }
  5906. if (WinConfiguration->SynchronizeSummary)
  5907. {
  5908. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5909. // The statistics should be 0 anyway in this case
  5910. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5911. {
  5912. Message += L"\n";
  5913. if (Statistics.FilesUploaded > 0)
  5914. {
  5915. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5916. }
  5917. if (Statistics.FilesDownloaded > 0)
  5918. {
  5919. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5920. }
  5921. if (Statistics.FilesDeletedLocal > 0)
  5922. {
  5923. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5924. }
  5925. if (Statistics.FilesDeletedRemote > 0)
  5926. {
  5927. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5928. }
  5929. }
  5930. TDateTime Elapsed = (Now() - Start);
  5931. Message +=
  5932. L"\n" +
  5933. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Params.CollectElapsed))) + L"\n" +
  5934. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Elapsed)));
  5935. TMessageParams Params(mpNeverAskAgainCheck);
  5936. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5937. if (Result == qaNeverAskAgain)
  5938. {
  5939. WinConfiguration->SynchronizeSummary = false;
  5940. }
  5941. }
  5942. }
  5943. //---------------------------------------------------------------------------
  5944. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5945. {
  5946. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5947. {
  5948. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5949. }
  5950. // Not set in keep-up-to-date mode - Synchronize() method
  5951. if (Token != NULL)
  5952. {
  5953. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5954. if (Params.OnProcessedItem != NULL)
  5955. {
  5956. Params.OnProcessedItem(NULL, ChecklistItem);
  5957. }
  5958. }
  5959. }
  5960. //---------------------------------------------------------------------------
  5961. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5962. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5963. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5964. {
  5965. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5966. *Params.StartTime = Now();
  5967. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5968. }
  5969. //---------------------------------------------------------------------------
  5970. void TCustomScpExplorerForm::DoQueueSynchronize(void * Token)
  5971. {
  5972. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5973. int CopyParams = TTerminal::GetSynchronizeCopyParams(Params.Params);
  5974. TCopyParamType SyncCopyParam = TTerminal::GetSynchronizeCopyParam(Params.CopyParam, Params.Params);
  5975. bool Parallel = GUIConfiguration->CurrentCopyParam.QueueParallel;
  5976. int Index = 0;
  5977. const TSynchronizeChecklist::TItem * ChecklistItem;
  5978. while (Params.Checklist->GetNextChecked(Index, ChecklistItem))
  5979. {
  5980. TQueueItem * QueueItem = Terminal->SynchronizeToQueue(ChecklistItem, &SyncCopyParam, CopyParams, Parallel);
  5981. AddQueueItem(Queue, QueueItem, Terminal);
  5982. }
  5983. }
  5984. //---------------------------------------------------------------------------
  5985. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5986. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5987. {
  5988. // terminal can be already closed (e.g. dropped connection)
  5989. if (Terminal != NULL)
  5990. {
  5991. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5992. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5993. }
  5994. }
  5995. //---------------------------------------------------------------------------
  5996. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5997. TOperationSide Side, TStrings * FileList, const UnicodeString & NewFileName, bool TargetIsDirectory, void * Token)
  5998. {
  5999. DebugAssert(!IsLocalBrowserMode());
  6000. TAutoBatch AutoBatch(this);
  6001. TAutoFlag AutoOperationFlag(FAutoOperation);
  6002. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  6003. if (Side == osRemote)
  6004. {
  6005. UnicodeString Target;
  6006. UnicodeString FileMask;
  6007. if (TargetIsDirectory)
  6008. {
  6009. Target = NewFileName;
  6010. Terminal->CreateTargetDirectory(Target, faDirectory, Params.CopyParam);
  6011. }
  6012. else
  6013. {
  6014. Target = UnixExtractFileDir(NewFileName);
  6015. FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  6016. }
  6017. RemoteDirView->SaveSelection();
  6018. RemoteDirView->SaveSelectedNames();
  6019. try
  6020. {
  6021. Terminal->MoveFiles(FileList, Target, FileMask, false);
  6022. }
  6023. catch(...)
  6024. {
  6025. RemoteDirView->DiscardSavedSelection();
  6026. throw;
  6027. }
  6028. RemoteDirView->RestoreSelection();
  6029. }
  6030. else if (DebugAlwaysTrue(Side == osLocal))
  6031. {
  6032. std::unique_ptr<TStrings> Directories(CreateSortedStringList());
  6033. if (TargetIsDirectory)
  6034. {
  6035. if (!ForceDirectories(ApiPath(NewFileName)))
  6036. {
  6037. throw EOSExtException(FMTLOAD(CREATE_DIR_ERROR, (NewFileName)));
  6038. }
  6039. Directories->Add(NewFileName);
  6040. }
  6041. else
  6042. {
  6043. Directories->Add(ExtractFileDir(NewFileName));
  6044. }
  6045. for (int Index = 0; Index < FileList->Count; Index++)
  6046. {
  6047. UnicodeString FileName = FileList->Strings[Index];
  6048. UnicodeString Directory = ExtractFileDir(FileName);
  6049. Directories->Add(Directory);
  6050. UnicodeString NewFilePath = NewFileName;
  6051. if (TargetIsDirectory)
  6052. {
  6053. NewFilePath = TPath::Combine(NewFilePath, ExtractFileName(FileName));
  6054. }
  6055. if (!MoveFile(ApiPath(FileName).c_str(), ApiPath(NewFilePath).c_str()))
  6056. {
  6057. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFilePath)));
  6058. }
  6059. }
  6060. for (int Index = 0; Index < Directories->Count; Index++)
  6061. {
  6062. ReloadLocalDirectory(Directories->Strings[Index]);
  6063. }
  6064. }
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  6068. {
  6069. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  6070. if (Side == osLocal)
  6071. {
  6072. if (Action == TSynchronizeChecklist::saDownloadNew)
  6073. {
  6074. OpenFolderInExplorer(LocalPath);
  6075. }
  6076. else
  6077. {
  6078. OpenFileInExplorer(CombinePaths(LocalPath, Item->GetFileName()));
  6079. }
  6080. }
  6081. else if (DebugAlwaysTrue(Side == osRemote))
  6082. {
  6083. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  6084. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  6085. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  6086. if (!LocalPath.IsEmpty())
  6087. {
  6088. SessionData->LocalDirectory = LocalPath;
  6089. }
  6090. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  6091. ExecuteNewInstance(SessionName, FORMAT(L"%s=\"%s\"", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  6092. }
  6093. }
  6094. //---------------------------------------------------------------------------
  6095. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  6096. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6097. const TCopyParamType * CopyParams)
  6098. {
  6099. UnicodeString SessionName = CreateHiddenDuplicateSession();
  6100. UnicodeString AdditionalParams =
  6101. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  6102. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  6103. SerializeCopyParamForCommandLine(CopyParams),
  6104. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  6105. LocalDirectory, RemoteDirectory, Mode, Params));
  6106. ExecuteNewInstance(SessionName, AdditionalParams);
  6107. }
  6108. //---------------------------------------------------------------------------
  6109. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  6110. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  6111. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  6112. {
  6113. int Result;
  6114. bool SaveSettings = false;
  6115. int Options =
  6116. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  6117. FLAGMASK(!CanCalculateChecksum(), fsoDisableByChecksum) |
  6118. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  6119. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  6120. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  6121. bool Continue =
  6122. ((UseDefaults == 0) ||
  6123. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  6124. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults)) &&
  6125. (FLAGCLEAR(Params, TTerminal::spByChecksum) || EnsureCommandSessionFallback(fcCalculatingChecksum));
  6126. if (Continue)
  6127. {
  6128. Configuration->Usage->Inc(L"Synchronizations");
  6129. CopyParam.IncludeFileMask.SetRoots(LocalDirectory, RemoteDirectory);
  6130. UpdateCopyParamCounters(CopyParam);
  6131. TSynchronizeOptions SynchronizeOptions;
  6132. GetSynchronizeOptions(Params, SynchronizeOptions);
  6133. if (SaveSettings)
  6134. {
  6135. GUIConfiguration->SynchronizeParams = Params;
  6136. }
  6137. else
  6138. {
  6139. SaveMode = false;
  6140. }
  6141. TDateTime StartTime = Now();
  6142. TSynchronizeChecklist * Checklist = NULL;
  6143. try
  6144. {
  6145. DebugAssert(!FAutoOperation);
  6146. FAutoOperation = true;
  6147. try
  6148. {
  6149. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  6150. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  6151. int Files = -1;
  6152. if (DataList->Count >= 1)
  6153. {
  6154. Files = StrToIntDef(DataList->Strings[0], Files);
  6155. }
  6156. else
  6157. {
  6158. DataList->Add(UnicodeString());
  6159. }
  6160. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  6161. FSynchronizeProgressForm->Start();
  6162. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  6163. static_cast<TTerminal::TSynchronizeMode>(Mode),
  6164. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  6165. &SynchronizeOptions);
  6166. if (Terminal->SessionData->CacheDirectories)
  6167. {
  6168. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  6169. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  6170. }
  6171. }
  6172. __finally
  6173. {
  6174. FAutoOperation = false;
  6175. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  6176. SAFE_DESTROY(FSynchronizeProgressForm);
  6177. }
  6178. TSynchronizeParams SynchronizeParams;
  6179. SynchronizeParams.LocalDirectory = LocalDirectory;
  6180. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  6181. SynchronizeParams.Mode = Mode;
  6182. SynchronizeParams.CopyParam = &CopyParam;
  6183. SynchronizeParams.Params = Params;
  6184. SynchronizeParams.Checklist = Checklist;
  6185. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  6186. SynchronizeParams.StartTime = &StartTime;
  6187. SynchronizeParams.OnProcessedItem = NULL;
  6188. Result = Checklist->Count;
  6189. if (Checklist->Count > 0)
  6190. {
  6191. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  6192. {
  6193. TQueueSynchronizeEvent OnQueueSynchronize = NULL;
  6194. if (Visible && FLAGCLEAR(Params, TTerminal::spTimestamp))
  6195. {
  6196. OnQueueSynchronize = DoQueueSynchronize;
  6197. }
  6198. if (!DoSynchronizeChecklistDialog(
  6199. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  6200. OnQueueSynchronize, DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse,
  6201. &SynchronizeParams))
  6202. {
  6203. Result = -1;
  6204. }
  6205. }
  6206. else
  6207. {
  6208. FullSynchronize(SynchronizeParams, NULL, NULL);
  6209. }
  6210. }
  6211. else
  6212. {
  6213. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  6214. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  6215. }
  6216. }
  6217. __finally
  6218. {
  6219. delete Checklist;
  6220. }
  6221. OperationComplete(StartTime);
  6222. }
  6223. else
  6224. {
  6225. Result = -1;
  6226. }
  6227. return Result;
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  6231. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6232. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  6233. {
  6234. if (Collect)
  6235. {
  6236. DebugAssert(FSynchronizeProgressForm != NULL);
  6237. if (!FSynchronizeProgressForm->Started)
  6238. {
  6239. FSynchronizeProgressForm->Start();
  6240. }
  6241. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  6242. SetTaskbarListProgressValue(CompareProgress);
  6243. }
  6244. else
  6245. {
  6246. DebugAssert(FSynchronizeProgressForm == NULL);
  6247. DebugAssert(FProgressForm != NULL);
  6248. }
  6249. }
  6250. //---------------------------------------------------------------------------
  6251. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  6252. {
  6253. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  6254. std::unique_ptr<TRemoteFile> File(Terminal->ReadFile(FullFileName));
  6255. if (File.get() != NULL)
  6256. {
  6257. ExecuteRemoteFile(FullFileName, File.get(), efInternalEditor);
  6258. Application->ShowMainForm = false;
  6259. Application->Run();
  6260. }
  6261. }
  6262. //---------------------------------------------------------------------------
  6263. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  6264. {
  6265. DebugFail();
  6266. }
  6267. //---------------------------------------------------------------------------
  6268. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  6269. {
  6270. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  6271. SessionData->Assign(ManagedSession->SessionData);
  6272. UpdateSessionData(SessionData.get());
  6273. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  6274. if (IsActiveTerminal(ManagedSession))
  6275. {
  6276. ManagedSession->UpdateSessionCredentials(SessionData.get());
  6277. }
  6278. if (!ManagedSession->SessionData->HasSessionName())
  6279. {
  6280. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  6281. // once IsWorkspace is cleared
  6282. SessionData->Name = UnicodeString();
  6283. }
  6284. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  6285. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  6286. SessionData->IsWorkspace = false;
  6287. return SessionData.release();
  6288. }
  6289. //---------------------------------------------------------------------------
  6290. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  6291. {
  6292. TSessionData * SessionData = CloneCurrentSessionData();
  6293. try
  6294. {
  6295. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  6296. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  6297. }
  6298. __finally
  6299. {
  6300. delete SessionData;
  6301. }
  6302. }
  6303. //---------------------------------------------------------------------------
  6304. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  6305. {
  6306. TTerminalManager * Manager = TTerminalManager::Instance();
  6307. std::unique_ptr<TObjectList> DataList(new TObjectList());
  6308. if (DebugAlwaysTrue(ManagedSession != NULL))
  6309. {
  6310. // Update ManagedSession->StateData
  6311. UpdateSession(ManagedSession);
  6312. }
  6313. Manager->SaveWorkspace(DataList.get());
  6314. return DataList.release();
  6315. }
  6316. //---------------------------------------------------------------------------
  6317. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  6318. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  6319. {
  6320. WinConfiguration->LastWorkspace = Name;
  6321. if (!SavePasswords)
  6322. {
  6323. for (int Index = 0; Index < DataList->Count; Index++)
  6324. {
  6325. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6326. if (SessionData->Link.IsEmpty())
  6327. {
  6328. SessionData->ClearSessionPasswords();
  6329. }
  6330. }
  6331. }
  6332. StoredSessions->NewWorkspace(Name, DataList);
  6333. // modified only
  6334. StoredSessions->Save(false, Explicit);
  6335. }
  6336. //---------------------------------------------------------------------------
  6337. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  6338. {
  6339. return
  6340. DefaultStr(WinConfiguration->LastWorkspace,
  6341. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  6342. }
  6343. //---------------------------------------------------------------------------
  6344. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  6345. {
  6346. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  6347. bool AnyNonStoredSessionWithPassword = false;
  6348. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  6349. bool AllNonStoredSessionsAnonymous = true;
  6350. TTerminalManager * Manager = TTerminalManager::Instance();
  6351. for (int Index = 0; Index < DataList->Count; Index++)
  6352. {
  6353. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6354. if (SessionData->Link.IsEmpty())
  6355. {
  6356. if (SessionData->HasAnySessionPassword())
  6357. {
  6358. AnyNonStoredSessionWithPassword = true;
  6359. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  6360. {
  6361. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  6362. }
  6363. }
  6364. if (!SameText(SessionData->UserName, AnonymousUserName))
  6365. {
  6366. AllNonStoredSessionsAnonymous = false;
  6367. }
  6368. }
  6369. }
  6370. bool SavePasswords;
  6371. bool * PSavePasswords;
  6372. bool NotRecommendedSavingPasswords =
  6373. !CustomWinConfiguration->UseMasterPassword &&
  6374. !AllNonStoredSessionsAnonymous;
  6375. if (Configuration->DisablePasswordStoring ||
  6376. !AnyNonStoredSessionWithPassword)
  6377. {
  6378. PSavePasswords = NULL;
  6379. SavePasswords = false;
  6380. }
  6381. else
  6382. {
  6383. PSavePasswords = &SavePasswords;
  6384. SavePasswords =
  6385. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6386. !NotRecommendedSavingPasswords;
  6387. }
  6388. UnicodeString Name = WorkspaceName();
  6389. bool CreateShortcut = false;
  6390. bool Result =
  6391. DoSaveWorkspaceDialog(
  6392. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6393. EnableAutoSave);
  6394. if (Result)
  6395. {
  6396. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6397. if (CreateShortcut)
  6398. {
  6399. TOperationVisualizer Visualizer;
  6400. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6401. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6402. }
  6403. if (EnableAutoSave)
  6404. {
  6405. WinConfiguration->AutoSaveWorkspace = true;
  6406. WinConfiguration->AutoWorkspace = Name;
  6407. if (PSavePasswords != NULL)
  6408. {
  6409. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6410. }
  6411. }
  6412. }
  6413. return Result;
  6414. }
  6415. //---------------------------------------------------------------------------
  6416. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6417. {
  6418. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6419. DebugAssert(Session == ManagedSession);
  6420. if (!IsLocalBrowserMode())
  6421. {
  6422. SAFE_DESTROY(Session->RemoteExplorerState);
  6423. if (WinConfiguration->PreservePanelState)
  6424. {
  6425. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6426. }
  6427. }
  6428. UpdateSessionData(Session->StateData);
  6429. }
  6430. //---------------------------------------------------------------------------
  6431. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6432. {
  6433. // Keep in sync with TSessionData::CopyStateData
  6434. DebugAssert(Data != NULL);
  6435. // This is inconsistent with how color (for example) is handled.
  6436. Data->Name = ManagedSession->SessionData->Name;
  6437. if (!IsLocalBrowserMode())
  6438. {
  6439. // cannot use RemoteDirView->Path, because it is empty if connection
  6440. // was already closed
  6441. // also only peek, we may not be connected at all atm
  6442. // so make sure we do not try retrieving current directory from the server
  6443. // (particularly with FTP)
  6444. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6445. if (!ACurrentDirectory.IsEmpty())
  6446. {
  6447. Data->RemoteDirectory = ACurrentDirectory;
  6448. }
  6449. }
  6450. Data->Color = SessionColor;
  6451. }
  6452. //---------------------------------------------------------------------------
  6453. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6454. {
  6455. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6456. DebugAssert(Toolbar != NULL);
  6457. for (int i = 0; i < Toolbar->Items->Count; i++)
  6458. {
  6459. TTBXCustomDropDownItem * DropDownItem;
  6460. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6461. if (DropDownItem != NULL)
  6462. {
  6463. ToolbarItemResize(DropDownItem,
  6464. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6465. Toolbar->NonClientWidth);
  6466. break;
  6467. }
  6468. }
  6469. }
  6470. //---------------------------------------------------------------------------
  6471. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6472. {
  6473. Item->EditWidth = Width;
  6474. }
  6475. //---------------------------------------------------------------------------
  6476. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6477. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6478. {
  6479. for (int i = 0; i < Toolbar->Items->Count; i++)
  6480. {
  6481. TTBXCustomDropDownItem * DropDownItem;
  6482. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6483. if (DropDownItem != NULL)
  6484. {
  6485. ASize.x -= DropDownItem->EditWidth;
  6486. TControl * Control = this;
  6487. ASize.x += ScaleByTextHeight(Control, 50) /* minimal combo width */;
  6488. }
  6489. }
  6490. }
  6491. //---------------------------------------------------------------------------
  6492. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6493. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6494. {
  6495. if (WinConfiguration->DDWarnLackOfTempSpace)
  6496. {
  6497. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6498. if (!ADrive.IsEmpty())
  6499. {
  6500. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6501. DebugAssert(RequiredSpace >= 0);
  6502. __int64 RequiredWithReserve;
  6503. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6504. if (FreeSpace < RequiredWithReserve)
  6505. {
  6506. unsigned int Result;
  6507. TMessageParams Params(mpNeverAskAgainCheck);
  6508. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6509. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6510. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6511. if (Result == qaNeverAskAgain)
  6512. {
  6513. WinConfiguration->DDWarnLackOfTempSpace = false;
  6514. }
  6515. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6516. }
  6517. }
  6518. }
  6519. }
  6520. //---------------------------------------------------------------------------
  6521. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6522. {
  6523. DoOpenDirectoryDialog(odAddBookmark, Side);
  6524. }
  6525. //---------------------------------------------------------------------------
  6526. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6527. {
  6528. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6529. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6530. try
  6531. {
  6532. TCustomDirView * DView = DirView(Side);
  6533. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6534. {
  6535. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6536. }
  6537. }
  6538. catch (...)
  6539. {
  6540. delete VisitedDirectories;
  6541. throw;
  6542. }
  6543. return VisitedDirectories;
  6544. }
  6545. //---------------------------------------------------------------------------
  6546. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6547. TOpenDirectoryMode Mode, TOperationSide Side)
  6548. {
  6549. bool Continue = true;
  6550. if (Mode == odAddBookmark)
  6551. {
  6552. TMessageParams Params(mpNeverAskAgainCheck);
  6553. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6554. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6555. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6556. unsigned int Answer =
  6557. MessageDialog(Message,
  6558. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6559. if (Answer == qaNeverAskAgain)
  6560. {
  6561. Continue = true;
  6562. WinConfiguration->UseSharedBookmarks = true;
  6563. }
  6564. else if (Answer == qaOK)
  6565. {
  6566. Continue = true;
  6567. WinConfiguration->UseSharedBookmarks = false;
  6568. }
  6569. else
  6570. {
  6571. Continue = false;
  6572. }
  6573. }
  6574. if (Continue)
  6575. {
  6576. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6577. try
  6578. {
  6579. UnicodeString Name = DirView(Side)->PathName;
  6580. bool Repeat;
  6581. do
  6582. {
  6583. Repeat = false;
  6584. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6585. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6586. // do not allow switching to location profiles,
  6587. // if we are not connected
  6588. HasDirView[osLocal] && IsActiveTerminal(Terminal)))
  6589. {
  6590. TWindowLock Lock(this);
  6591. if (!TryOpenDirectory(Side, Name))
  6592. {
  6593. Repeat = true;
  6594. Mode = odBrowse;
  6595. }
  6596. }
  6597. }
  6598. while (Repeat);
  6599. }
  6600. __finally
  6601. {
  6602. delete VisitedDirectories;
  6603. }
  6604. }
  6605. }
  6606. //---------------------------------------------------------------------------
  6607. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6608. {
  6609. DebugAssert(!Terminal->CommandSessionOpened);
  6610. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6611. }
  6612. //---------------------------------------------------------------------------
  6613. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6614. {
  6615. bool Result = Terminal->IsCapable[Capability] ||
  6616. Terminal->CommandSessionOpened;
  6617. if (!Result)
  6618. {
  6619. // We might get here for example when "checksum" synchronization is requested from command-line
  6620. // on server that supports neither checksum nor shell
  6621. if (!Terminal->IsCapable[fcSecondaryShell])
  6622. {
  6623. NotSupported();
  6624. }
  6625. else if (!GUIConfiguration->ConfirmCommandSession)
  6626. {
  6627. Result = true;
  6628. }
  6629. else
  6630. {
  6631. TMessageParams Params(mpNeverAskAgainCheck);
  6632. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6633. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6634. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6635. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6636. if (Answer == qaNeverAskAgain)
  6637. {
  6638. GUIConfiguration->ConfirmCommandSession = false;
  6639. Result = true;
  6640. }
  6641. else if (Answer == qaOK)
  6642. {
  6643. Result = true;
  6644. }
  6645. }
  6646. if (Result)
  6647. {
  6648. Result = CommandSessionFallback();
  6649. }
  6650. }
  6651. return Result;
  6652. }
  6653. //---------------------------------------------------------------------------
  6654. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6655. {
  6656. if (EnsureCommandSessionFallback(fcAnyCommand))
  6657. {
  6658. DoConsoleDialog(Terminal, Command);
  6659. }
  6660. }
  6661. //---------------------------------------------------------------------------
  6662. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6663. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6664. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6665. {
  6666. if (!IsSideLocalBrowser(osRemote) &&
  6667. IsFileControl(DropSourceControl, osRemote) &&
  6668. (FDDExtMapFile != NULL))
  6669. {
  6670. Accept = true;
  6671. }
  6672. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6673. DebugAssert(FDDTargetControl != NULL);
  6674. }
  6675. //---------------------------------------------------------------------------
  6676. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6677. _di_IDataObject DataObj, int KeyState,
  6678. const TPoint & Point, int & Effect, bool & Accept)
  6679. {
  6680. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6681. }
  6682. //---------------------------------------------------------------------------
  6683. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6684. _di_IDataObject DataObj, int KeyState,
  6685. const TPoint & Point, int & Effect, bool & Accept)
  6686. {
  6687. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6688. }
  6689. //---------------------------------------------------------------------------
  6690. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6691. TObject * Sender)
  6692. {
  6693. DebugUsedParam(Sender);
  6694. DebugAssert(FDDTargetControl == Sender);
  6695. FDDTargetControl = NULL;
  6696. }
  6697. //---------------------------------------------------------------------------
  6698. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave(int)
  6699. {
  6700. FileControlDDDragLeave(SessionsPageControl);
  6701. }
  6702. //---------------------------------------------------------------------------
  6703. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave(int)
  6704. {
  6705. FileControlDDDragLeave(QueueView3);
  6706. }
  6707. //---------------------------------------------------------------------------
  6708. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6709. {
  6710. DebugAssert(!IsSideLocalBrowser(Side));
  6711. DebugUsedParam(Side);
  6712. bool Edit = false;
  6713. TRemoteFile * File = NULL;
  6714. UnicodeString FileName;
  6715. UnicodeString PointTo;
  6716. bool SymbolicLink = true;
  6717. if (RemoteDirView->ItemFocused)
  6718. {
  6719. DebugAssert(RemoteDirView->ItemFocused->Data);
  6720. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6721. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6722. if (Edit)
  6723. {
  6724. FileName = File->FileName;
  6725. PointTo = File->LinkTo;
  6726. }
  6727. else if (!File->IsParentDirectory)
  6728. {
  6729. PointTo = File->FileName;
  6730. }
  6731. }
  6732. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6733. Terminal->IsCapable[fcHardLink]))
  6734. {
  6735. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6736. if (Edit)
  6737. {
  6738. DebugAssert(File->FileName == FileName);
  6739. int Params = dfNoRecursive;
  6740. Terminal->ExceptionOnFail = true;
  6741. try
  6742. {
  6743. Terminal->DeleteFile(L"", File, &Params);
  6744. }
  6745. __finally
  6746. {
  6747. Terminal->ExceptionOnFail = false;
  6748. }
  6749. }
  6750. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6751. }
  6752. }
  6753. //---------------------------------------------------------------------------
  6754. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6755. {
  6756. return
  6757. (IsSideLocalBrowser(Side) ||
  6758. (HasActiveTerminal() &&
  6759. Terminal->ResolvingSymlinks &&
  6760. Terminal->IsCapable[fcSymbolicLink]));
  6761. }
  6762. //---------------------------------------------------------------------------
  6763. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6764. {
  6765. return
  6766. !IsSideLocalBrowser(FCurrentSide) &&
  6767. (RemoteDirView->ItemFocused != NULL) &&
  6768. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6769. Terminal->SessionData->ResolveSymlinks;
  6770. }
  6771. //---------------------------------------------------------------------------
  6772. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6773. {
  6774. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6775. FForceExecution = true;
  6776. try
  6777. {
  6778. DirView(osCurrent)->ExecuteCurrentFile();
  6779. }
  6780. __finally
  6781. {
  6782. FForceExecution = false;
  6783. }
  6784. }
  6785. //---------------------------------------------------------------------------
  6786. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6787. {
  6788. TEditorData ExternalEditor;
  6789. ExternalEditor.Editor = edExternal;
  6790. bool Remember = false;
  6791. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6792. {
  6793. if (Remember)
  6794. {
  6795. TEditorList * EditorList = new TEditorList;
  6796. try
  6797. {
  6798. *EditorList = *WinConfiguration->EditorList;
  6799. bool Found = false;
  6800. int i = 0;
  6801. while (!Found && (i < EditorList->Count))
  6802. {
  6803. const TEditorPreferences * Editor = EditorList->Editors[i];
  6804. if ((Editor->Data->Editor == edExternal) &&
  6805. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6806. {
  6807. Found = true;
  6808. }
  6809. i++;
  6810. }
  6811. if (!Found)
  6812. {
  6813. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6814. WinConfiguration->EditorList = EditorList;
  6815. }
  6816. }
  6817. __finally
  6818. {
  6819. delete EditorList;
  6820. }
  6821. }
  6822. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6823. }
  6824. }
  6825. //---------------------------------------------------------------------------
  6826. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6827. {
  6828. if (FFileFindTerminal == ATerminal)
  6829. {
  6830. FFileFindTerminal = NULL;
  6831. HideFileFindDialog();
  6832. }
  6833. if (FClipboardTerminal == ATerminal)
  6834. {
  6835. ClipboardClear(); // implies ClipboardStop
  6836. }
  6837. if ((FOnSynchronizeAbort != NULL) &&
  6838. (ATerminal == FManagedSession))
  6839. {
  6840. FOnSynchronizeAbort(NULL);
  6841. }
  6842. }
  6843. //---------------------------------------------------------------------------
  6844. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6845. {
  6846. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6847. DetachTerminal(Sender);
  6848. }
  6849. //---------------------------------------------------------------------------
  6850. void __fastcall TCustomScpExplorerForm::FileTerminalReplaced(
  6851. const UnicodeString FileName, TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6852. {
  6853. TManagedTerminal * ATerminal = static_cast<TManagedTerminal *>(Arg);
  6854. if (Data->Terminal == Terminal)
  6855. {
  6856. Data->Terminal = ATerminal;
  6857. }
  6858. }
  6859. //---------------------------------------------------------------------------
  6860. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6861. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6862. {
  6863. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6864. DebugAssert(Terminal != NULL);
  6865. if (Data->Terminal == Terminal)
  6866. {
  6867. Data->Terminal = NULL;
  6868. }
  6869. }
  6870. //---------------------------------------------------------------------------
  6871. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6872. {
  6873. return NULL;
  6874. }
  6875. //---------------------------------------------------------------------------
  6876. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6877. {
  6878. UpdateControls();
  6879. SessionColor = TColor(0);
  6880. UpdateRemotePathComboBox(false);
  6881. NeedSession(false);
  6882. }
  6883. //---------------------------------------------------------------------------
  6884. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6885. {
  6886. try
  6887. {
  6888. // Cache, as the login dialog can change its value.
  6889. // See also DoShow. Also see TTerminalManager::NewSession.
  6890. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6891. try
  6892. {
  6893. if (ShowLogin)
  6894. {
  6895. bool ReloadSessions = !Startup;
  6896. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6897. }
  6898. }
  6899. __finally
  6900. {
  6901. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6902. // (so there was no chance for the user to open any session yet)
  6903. if ((ShowLogin || !Startup) &&
  6904. !WinConfiguration->KeepOpenWhenNoSession &&
  6905. // this rules out the implicit Commander's local-local browser
  6906. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6907. {
  6908. TerminateApplication();
  6909. }
  6910. }
  6911. }
  6912. catch (EAbort &)
  6913. {
  6914. // swallow
  6915. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6916. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6917. }
  6918. }
  6919. //---------------------------------------------------------------------------
  6920. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6921. {
  6922. TTerminalManager * Manager = TTerminalManager::Instance();
  6923. DebugAssert(!Manager->Updating);
  6924. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6925. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6926. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6927. SessionsPageControl->LockDrawing();
  6928. try
  6929. {
  6930. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6931. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6932. {
  6933. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6934. }
  6935. for (int Index = 0; Index <= Manager->Count; Index++)
  6936. {
  6937. TThemeTabSheet * TabSheet;
  6938. if (Index >= SessionsPageControl->PageCount)
  6939. {
  6940. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6941. TabSheet->PageControl = SessionsPageControl;
  6942. }
  6943. else
  6944. {
  6945. TabSheet = SessionsPageControl->Pages[Index];
  6946. }
  6947. bool IsSessionTab = (Index < Manager->Count);
  6948. if (IsSessionTab)
  6949. {
  6950. TTerminal * Terminal = Manager->Sessions[Index];
  6951. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6952. TabSheet->CaptionTruncation = WinConfiguration->SessionTabCaptionTruncation ? tttEllipsis : tttNone;
  6953. UpdateSessionTab(TabSheet);
  6954. }
  6955. else
  6956. {
  6957. TabSheet->Tag = 0; // not really needed
  6958. TabSheet->Shadowed = false;
  6959. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6960. TabSheet->CaptionTruncation = GetNewTabTabCaptionTruncation();
  6961. // 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)
  6962. UpdateNewTabTab();
  6963. }
  6964. }
  6965. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6966. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6967. {
  6968. SessionsPageControl->UpdateTabsCaptionTruncation();
  6969. }
  6970. }
  6971. __finally
  6972. {
  6973. SessionsPageControl->UnlockDrawing();
  6974. }
  6975. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6976. }
  6977. //---------------------------------------------------------------------------
  6978. TThemeTabCaptionTruncation TCustomScpExplorerForm::GetNewTabTabCaptionTruncation()
  6979. {
  6980. return WinConfiguration->SessionTabCaptionTruncation ? tttNoText : tttNone;
  6981. }
  6982. //---------------------------------------------------------------------------
  6983. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6984. {
  6985. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6986. }
  6987. //---------------------------------------------------------------------------
  6988. TThemeTabSheet * TCustomScpExplorerForm::GetNewTabTab()
  6989. {
  6990. return SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6991. }
  6992. //---------------------------------------------------------------------------
  6993. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6994. {
  6995. TThemeTabSheet * TabSheet = GetNewTabTab();
  6996. UnicodeString TabCaption;
  6997. if (WinConfiguration->SelectiveToolbarText)
  6998. {
  6999. TabCaption = GetNewTabTabCaption();
  7000. }
  7001. TabSheet->BaseCaption = TabCaption;
  7002. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  7003. }
  7004. //---------------------------------------------------------------------------
  7005. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  7006. {
  7007. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  7008. }
  7009. //---------------------------------------------------------------------------
  7010. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  7011. {
  7012. DebugFail();
  7013. return UnicodeString();
  7014. }
  7015. //---------------------------------------------------------------------------
  7016. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  7017. {
  7018. if (DebugAlwaysTrue(TabSheet != NULL))
  7019. {
  7020. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  7021. if (DebugAlwaysTrue(ASession != NULL))
  7022. {
  7023. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  7024. if (ASession->LocalBrowser)
  7025. {
  7026. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  7027. }
  7028. else
  7029. {
  7030. TabSheet->ImageIndex = AddSessionColor(Color);
  7031. }
  7032. TTerminalManager * Manager = TTerminalManager::Instance();
  7033. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  7034. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  7035. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  7036. }
  7037. }
  7038. }
  7039. //---------------------------------------------------------------------------
  7040. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  7041. {
  7042. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  7043. }
  7044. //---------------------------------------------------------------------------
  7045. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  7046. {
  7047. DebugAssert(SessionsPageControl->ActivePage != NULL);
  7048. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  7049. bool Result = (Session != NULL);
  7050. if (Result)
  7051. {
  7052. TTerminalManager::Instance()->ActiveSession = Session;
  7053. }
  7054. else
  7055. {
  7056. try
  7057. {
  7058. NewTab();
  7059. }
  7060. __finally
  7061. {
  7062. SessionListChanged();
  7063. }
  7064. FSessionsPageControlNewTabTime = Now();
  7065. }
  7066. return Result;
  7067. }
  7068. //---------------------------------------------------------------------------
  7069. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  7070. {
  7071. TWindowLock Lock(this);
  7072. SessionTabSwitched();
  7073. }
  7074. //---------------------------------------------------------------------------
  7075. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  7076. {
  7077. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  7078. DebugAssert(TransferList != NULL);
  7079. UnicodeString Name;
  7080. if (TransferList->ItemIndex <= 0)
  7081. {
  7082. Name = L"";
  7083. }
  7084. else
  7085. {
  7086. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  7087. }
  7088. if (FCopyParamAutoSelected.IsEmpty())
  7089. {
  7090. // if previous preset was not autoselected, make new preset the "default"
  7091. FCopyParamDefault = Name;
  7092. }
  7093. GUIConfiguration->CopyParamCurrent = Name;
  7094. }
  7095. //---------------------------------------------------------------------------
  7096. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  7097. {
  7098. // sanity check
  7099. bool ExistingPreset =
  7100. (FTransferListHoverIndex >= 0) &&
  7101. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  7102. DebugAssert(ExistingPreset);
  7103. if (ExistingPreset)
  7104. {
  7105. HDC DC = GetDC(0);
  7106. TCanvas * Canvas = new TCanvas();
  7107. try
  7108. {
  7109. Canvas->Handle = DC;
  7110. Canvas->Font = GetToolbarFont(this);
  7111. UnicodeString Name;
  7112. if (FTransferListHoverIndex == 0)
  7113. {
  7114. Name = L"";
  7115. }
  7116. else
  7117. {
  7118. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  7119. }
  7120. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  7121. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  7122. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  7123. static_cast<TObject*>(GetComponent(fcTransferList)));
  7124. UnicodeString InfoStr =
  7125. GUIConfiguration->CopyParamPreset[Name].
  7126. GetInfoStr(L"; ",
  7127. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  7128. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  7129. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  7130. {
  7131. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  7132. {
  7133. InfoStr.SetLength(InfoStr.Length() - 1);
  7134. }
  7135. InfoStr += Ellipsis;
  7136. }
  7137. // UpdateCaption does not cause invalidation of whole submenu, while
  7138. // setting Caption property does.
  7139. // also it probably does not resize the label, even if necessary
  7140. // (we do not want that anyway)
  7141. TransferLabel->UpdateCaption(InfoStr);
  7142. }
  7143. __finally
  7144. {
  7145. Canvas->Handle = NULL;
  7146. ReleaseDC(0, DC);
  7147. delete Canvas;
  7148. }
  7149. }
  7150. }
  7151. //---------------------------------------------------------------------------
  7152. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  7153. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  7154. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  7155. {
  7156. if (FTransferListHoverIndex != AHoverIndex)
  7157. {
  7158. FTransferListHoverIndex = AHoverIndex;
  7159. UpdateTransferLabel();
  7160. }
  7161. }
  7162. //---------------------------------------------------------------------------
  7163. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  7164. {
  7165. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  7166. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  7167. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  7168. {
  7169. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  7170. {
  7171. if (!NonVisualDataModule->Busy)
  7172. {
  7173. OpenDirectory(GetSide(osCurrent));
  7174. }
  7175. Message.Result = 1;
  7176. }
  7177. else
  7178. {
  7179. TForm::Dispatch(&Message);
  7180. }
  7181. }
  7182. else
  7183. {
  7184. TForm::Dispatch(&Message);
  7185. }
  7186. }
  7187. //---------------------------------------------------------------------------
  7188. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  7189. {
  7190. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  7191. if ((FIgnoreNextDialogChar != 0) &&
  7192. (towupper(Message.CharCode) == towupper(FIgnoreNextDialogChar)))
  7193. {
  7194. Message.Result = 1;
  7195. }
  7196. else
  7197. {
  7198. TForm::Dispatch(&Message);
  7199. }
  7200. FIgnoreNextDialogChar = 0;
  7201. }
  7202. //---------------------------------------------------------------------------
  7203. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  7204. {
  7205. // The four low-order bits are used internally by Windows
  7206. unsigned int Cmd = (Message.WParam & 0xFFF0);
  7207. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  7208. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  7209. // 61730 - restore thru double click - undocumented
  7210. // 61490 - maximize thru double click - undocumented
  7211. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  7212. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  7213. {
  7214. SysResizing(Cmd);
  7215. }
  7216. TForm::Dispatch(&Message);
  7217. }
  7218. //---------------------------------------------------------------------------
  7219. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  7220. {
  7221. AppLog(L"Windows session end query");
  7222. // We were actually never able to make ENDSESSION_CRITICAL happen.
  7223. // Also there no point returning TRUE as we are not able to
  7224. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  7225. // Hence the process termination might be safer :)
  7226. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  7227. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  7228. {
  7229. Message.Result = FALSE;
  7230. }
  7231. else
  7232. {
  7233. Message.Result = TRUE;
  7234. }
  7235. // Do not call default handling as that triggers OnCloseQuery,
  7236. // where our implementation will popup confirmation dialogs, what we do not want,
  7237. // as per Vista guidelines:
  7238. // https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  7239. }
  7240. //---------------------------------------------------------------------------
  7241. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  7242. {
  7243. AppLog(L"Windows session end");
  7244. if (Message.EndSession && IsApplicationMinimized())
  7245. {
  7246. // WORKAROUND
  7247. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  7248. // when it receives WM_ENDSESSION,
  7249. // but that sometimes (particularly when application is minimized) cause crashes.
  7250. // Crash popups message that blocks log off.
  7251. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  7252. // so we call ExitProcess() immediately, not even trying to cleanup.
  7253. // It still causes beep, so there's likely some popup, but it does not block
  7254. // log off.
  7255. ExitProcess(0);
  7256. }
  7257. TForm::Dispatch(&Message);
  7258. }
  7259. #ifdef _DEBUG
  7260. //---------------------------------------------------------------------------
  7261. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  7262. {
  7263. TForm::Dispatch(&Message);
  7264. }
  7265. #endif
  7266. //---------------------------------------------------------------------------
  7267. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  7268. {
  7269. }
  7270. //---------------------------------------------------------------------------
  7271. void __fastcall TCustomScpExplorerForm::DoShow()
  7272. {
  7273. // Called from TCustomScpExplorerForm::CMShowingChanged
  7274. // only now are the controls resized finally, so the size constraints
  7275. // will not conflict with possibly very small window size
  7276. RestoreFormParams();
  7277. // This indicates that the form was rescaled after parameters were loaded and
  7278. // as most probably the parameters were actually saved with the current form scaling
  7279. // (windows was the last time likely closed on the same monitor, where it is starting now),
  7280. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  7281. // and no rounding problems will occur.
  7282. // See also RestoreForm.
  7283. // (we should be safe to call RestoreParams unconditionally)
  7284. if (PixelsPerInch != Screen->PixelsPerInch)
  7285. {
  7286. RestoreParams();
  7287. }
  7288. FixControlsPlacement();
  7289. if (Position == poDefaultPosOnly)
  7290. {
  7291. CutFormToDesktop(this);
  7292. }
  7293. TForm::DoShow();
  7294. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  7295. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  7296. // This was previously in NeedSession, where other related code is.
  7297. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  7298. // unpleasantly shows briefly.
  7299. if ((ManagedSession == NULL) &&
  7300. !WinConfiguration->ShowLoginWhenNoSession &&
  7301. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  7302. // This detects if workspace was saved the last time the main widow was closed
  7303. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  7304. {
  7305. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  7306. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  7307. }
  7308. // Before main window displays
  7309. if (ManagedSession == NULL)
  7310. {
  7311. StartingWithoutSession();
  7312. }
  7313. UpdatePixelsPerInchMainWindowCounter();
  7314. FShowing = true;
  7315. }
  7316. //---------------------------------------------------------------------------
  7317. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  7318. {
  7319. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  7320. }
  7321. //---------------------------------------------------------------------------
  7322. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  7323. {
  7324. SessionListChanged();
  7325. InitStatusBar();
  7326. UpdateControls();
  7327. }
  7328. //---------------------------------------------------------------------------
  7329. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  7330. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  7331. TNotifyEvent OnBalloonClick, TObject * UserData)
  7332. {
  7333. bool Do;
  7334. UnicodeString Message;
  7335. if (E == NULL)
  7336. {
  7337. Message = Str;
  7338. Do = true;
  7339. }
  7340. else
  7341. {
  7342. Do = ExceptionMessage(E, Message);
  7343. }
  7344. if (Do && WinConfiguration->BalloonNotifications)
  7345. {
  7346. UnicodeString Title;
  7347. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  7348. {
  7349. Message = TrimLeft(Message);
  7350. }
  7351. else
  7352. {
  7353. Message = UnformatMessage(Message);
  7354. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  7355. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  7356. Title = LoadResourceString(Captions[Type]);
  7357. if (Terminal != NULL)
  7358. {
  7359. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal->PrimaryTerminal));
  7360. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  7361. }
  7362. }
  7363. if (Seconds == 0)
  7364. {
  7365. Seconds = WinConfiguration->NotificationsTimeout;
  7366. }
  7367. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  7368. }
  7369. }
  7370. //---------------------------------------------------------------------------
  7371. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  7372. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  7373. UnicodeString HelpKeyword, const TMessageParams * Params,
  7374. TTerminal * Terminal)
  7375. {
  7376. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  7377. (FOnFeedSynchronizeError != NULL)) &&
  7378. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  7379. {
  7380. if (FOnFeedSynchronizeError != NULL)
  7381. {
  7382. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  7383. }
  7384. else
  7385. {
  7386. DebugAssert(FErrorList != NULL);
  7387. TStringList * MoreMessagesCopy = NULL;
  7388. if (MoreMessages)
  7389. {
  7390. MoreMessagesCopy = new TStringList();
  7391. MoreMessagesCopy->Assign(MoreMessages);
  7392. }
  7393. FErrorList->AddObject(Message, MoreMessagesCopy);
  7394. }
  7395. PopupTrayBalloon(Terminal, Message, Type);
  7396. return ContinueAnswer(Answers);
  7397. }
  7398. else
  7399. {
  7400. bool UseBalloon = FTrayIcon->Visible;
  7401. if (UseBalloon)
  7402. {
  7403. PopupTrayBalloon(Terminal, Message, Type);
  7404. }
  7405. unsigned int Result;
  7406. try
  7407. {
  7408. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7409. }
  7410. __finally
  7411. {
  7412. // cancel only balloon we popped up, otherwise we may cancel notification
  7413. // balloon that was there before the message dialog
  7414. // (such as "dd confirmation opt in balloon)
  7415. if (UseBalloon)
  7416. {
  7417. FTrayIcon->CancelBalloon();
  7418. }
  7419. }
  7420. return Result;
  7421. }
  7422. }
  7423. //---------------------------------------------------------------------------
  7424. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7425. TTerminal * Terminal, Exception * E)
  7426. {
  7427. if (FTrayIcon->Visible)
  7428. {
  7429. PopupTrayBalloon(Terminal, L"", qtError, E);
  7430. }
  7431. // particularly prevent opening new session from jump list,
  7432. // while exception is shown
  7433. NonVisualDataModule->StartBusy();
  7434. try
  7435. {
  7436. ShowExtendedExceptionEx(Terminal, E);
  7437. }
  7438. __finally
  7439. {
  7440. NonVisualDataModule->EndBusy();
  7441. FTrayIcon->CancelBalloon();
  7442. }
  7443. }
  7444. //---------------------------------------------------------------------------
  7445. void __fastcall TCustomScpExplorerForm::SessionReady()
  7446. {
  7447. InitStatusBar();
  7448. // cannot rely on active page being page for active terminal,
  7449. // as it can happen that active page is the "new session" page
  7450. // (e.g. when reconnecting active terminal, while login dialog
  7451. // invoked from "new session" page is modal)
  7452. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7453. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7457. TTerminal * Terminal, Exception * E)
  7458. {
  7459. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7460. if (!Terminal->Active)
  7461. {
  7462. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7463. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7464. {
  7465. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7466. }
  7467. }
  7468. }
  7469. //---------------------------------------------------------------------------
  7470. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7471. UnicodeString Message, TQueryType Type,
  7472. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7473. {
  7474. if ((E == NULL) ||
  7475. ExceptionMessage(E, Message))
  7476. {
  7477. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7478. if (Important)
  7479. {
  7480. Seconds *= 5;
  7481. }
  7482. UnicodeString NoteMessage(UnformatMessage(Message));
  7483. if (Terminal != NULL)
  7484. {
  7485. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7486. NoteMessage = FORMAT(L"%s: %s",
  7487. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7488. }
  7489. if (WinConfiguration->BalloonNotifications)
  7490. {
  7491. AddNote(NoteMessage);
  7492. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7493. }
  7494. else
  7495. {
  7496. FlashOnBackground();
  7497. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7498. }
  7499. }
  7500. }
  7501. //---------------------------------------------------------------------------
  7502. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7503. {
  7504. RestoreApp();
  7505. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7506. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7507. !NonVisualDataModule->Busy)
  7508. {
  7509. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7510. TTerminalManager::Instance()->ActiveSession = Terminal;
  7511. if (!ComponentVisible[fcQueueView])
  7512. {
  7513. ToggleQueueVisibility();
  7514. GoToQueue();
  7515. }
  7516. }
  7517. }
  7518. //---------------------------------------------------------------------------
  7519. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7520. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7521. {
  7522. UnicodeString Message;
  7523. TNotifyEvent OnClick = NULL;
  7524. TObject * UserData = NULL;
  7525. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7526. switch (Event)
  7527. {
  7528. case qeEmptyButMonitored:
  7529. if ((ATerminal != Terminal) || QueueInvisible)
  7530. {
  7531. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7532. OnClick = QueueEmptyNoteClicked;
  7533. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7534. TerminalNoteData->Terminal = ATerminal;
  7535. UserData = TerminalNoteData;
  7536. }
  7537. break;
  7538. case qeEmpty:
  7539. OperationComplete(ATerminal->QueueOperationStart);
  7540. break;
  7541. case qePendingUserAction:
  7542. if ((ATerminal != Terminal) ||
  7543. (QueueInvisible && !IsQueueAutoPopup()))
  7544. {
  7545. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7546. }
  7547. break;
  7548. default:
  7549. DebugFail();
  7550. }
  7551. if (!Message.IsEmpty())
  7552. {
  7553. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7554. }
  7555. }
  7556. //---------------------------------------------------------------------------
  7557. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7558. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7559. {
  7560. if (FDDExtMapFile != NULL)
  7561. {
  7562. CloseHandle(FDDExtMapFile);
  7563. FDDExtMapFile = NULL;
  7564. }
  7565. if (WinConfiguration->DDFakeFile)
  7566. {
  7567. DDFakeFileInitDrag(FileList, Created);
  7568. }
  7569. }
  7570. //---------------------------------------------------------------------------
  7571. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7572. {
  7573. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7574. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7575. {
  7576. FFakeFileDropTarget = FileName;
  7577. }
  7578. }
  7579. //---------------------------------------------------------------------------
  7580. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7581. {
  7582. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7583. if (!ForceDirectories(ApiPath(Result)))
  7584. {
  7585. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7586. }
  7587. FileSetAttr(ApiPath(Result), faHidden);
  7588. return Result;
  7589. }
  7590. //---------------------------------------------------------------------------
  7591. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7592. bool & Created)
  7593. {
  7594. FFakeFileDropTarget = UnicodeString();
  7595. FDragFakeDirectory = CreateFakeTransferDirectory();
  7596. FileList->AddItem(NULL, FDragFakeDirectory);
  7597. Created = true;
  7598. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7599. {
  7600. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7601. }
  7602. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7603. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7604. {
  7605. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7606. TDragExtCommStruct* CommStruct;
  7607. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7608. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7609. DebugAssert(CommStruct != NULL);
  7610. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7611. CommStruct->Dragging = true;
  7612. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7613. LENOF(CommStruct->DropDest));
  7614. NULL_TERMINATE(CommStruct->DropDest);
  7615. UnmapViewOfFile(CommStruct);
  7616. }
  7617. }
  7618. //---------------------------------------------------------------------------
  7619. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7620. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7621. {
  7622. bool Result;
  7623. DebugAssert(!IsLocalBrowserMode());
  7624. if (Sender == RemoteDirView)
  7625. {
  7626. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7627. }
  7628. else
  7629. {
  7630. DebugAssert(Sender == RemoteDriveView);
  7631. TStrings * FileList = RemoteDriveView->DragFileList();
  7632. try
  7633. {
  7634. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7635. }
  7636. __finally
  7637. {
  7638. delete FileList;
  7639. }
  7640. }
  7641. if (FDDTargetControl == RemoteDriveView)
  7642. {
  7643. RemoteDriveView->UpdateDropTarget();
  7644. }
  7645. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7646. // or from tree view to dir view.
  7647. // foMove happens when file/dir is dragged from remote tree view outside of
  7648. // application via dragex
  7649. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7650. (DropSourceControl == RemoteDriveView))
  7651. {
  7652. RemoteDriveView->UpdateDropSource();
  7653. }
  7654. return Result;
  7655. }
  7656. //---------------------------------------------------------------------------
  7657. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7658. {
  7659. DebugAssert(!IsLocalBrowserMode());
  7660. // This also handles drops of remote files to queue.
  7661. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7662. SAFE_DESTROY(FDDFileList);
  7663. if (!FFakeFileDropTarget.IsEmpty())
  7664. {
  7665. RemoveDir(ApiPath(FFakeFileDropTarget));
  7666. }
  7667. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7668. {
  7669. try
  7670. {
  7671. TDragResult DDResult = (Sender == RemoteDirView) ?
  7672. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7673. // Focus is moved to the target application,
  7674. // but as we are going to present the UI, we need to steal the focus back.
  7675. // This most likely won't work though (windows does not allow application
  7676. // to steal focus most of the time)
  7677. Application->BringToFront();
  7678. // On older version of Windows we never got drMove here, see also comment below.
  7679. // On Windows 10, we get the "move".
  7680. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7681. {
  7682. UnicodeString TargetDirectory;
  7683. TFileOperation Operation;
  7684. // drInvalid may mean drMove, see comment below
  7685. switch (DDResult)
  7686. {
  7687. case drCopy:
  7688. Operation = foCopy;
  7689. break;
  7690. case drMove:
  7691. Operation = foMove;
  7692. break;
  7693. default:
  7694. DebugFail();
  7695. case drInvalid:
  7696. // prefer "copy" for safety
  7697. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7698. break;
  7699. }
  7700. TTransferOperationParam Param;
  7701. UnicodeString CounterName;
  7702. bool ForceQueue;
  7703. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7704. {
  7705. // we get drInvalid both if d&d was intercepted by ddext,
  7706. // and when users drops on no-drop location.
  7707. // we tell the difference by existence of response from ddext,
  7708. // so we ignore absence of response in this case
  7709. if (DDResult != drInvalid)
  7710. {
  7711. // here we know that the extension is installed,
  7712. // as it is checked as soon as drag&drop starts from
  7713. // RemoteFileControlDDCreateDragFileList
  7714. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7715. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7716. {
  7717. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7718. }
  7719. else
  7720. {
  7721. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7722. }
  7723. }
  7724. }
  7725. else
  7726. {
  7727. // download using fake file
  7728. Param.Temp = false;
  7729. Param.DragDrop = true;
  7730. if (ForceQueue)
  7731. {
  7732. Param.Queue = asOn;
  7733. }
  7734. if (Sender == RemoteDirView)
  7735. {
  7736. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7737. }
  7738. if (RemoteFileControlFileOperation(Sender, Operation,
  7739. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7740. {
  7741. Configuration->Usage->Inc(CounterName);
  7742. }
  7743. }
  7744. }
  7745. }
  7746. __finally
  7747. {
  7748. CloseHandle(FDDExtMapFile);
  7749. FDDExtMapFile = NULL;
  7750. delete FDragFakeMonitors;
  7751. FDragFakeMonitors = NULL;
  7752. RemoveDir(ApiPath(FDragFakeDirectory));
  7753. FDragFakeDirectory = L"";
  7754. FFakeFileDropTarget = UnicodeString();
  7755. }
  7756. }
  7757. if (FDragDropSshTerminate.get() != NULL)
  7758. {
  7759. FDragDropSshTerminate->Rethrow();
  7760. }
  7761. }
  7762. //---------------------------------------------------------------------------
  7763. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7764. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7765. {
  7766. // Remember drop effect so we know (when user drops files), if we copy or move
  7767. FLastDropEffect = dwEffect;
  7768. }
  7769. //---------------------------------------------------------------------------
  7770. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7771. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7772. {
  7773. bool Result;
  7774. if (FDDTargetControl == QueueView3)
  7775. {
  7776. Directory = DefaultDownloadTargetDirectory();
  7777. Result = true;
  7778. CounterName = L"DownloadsDragDropQueue";
  7779. ForceQueue = true;
  7780. }
  7781. else if (!FFakeFileDropTarget.IsEmpty())
  7782. {
  7783. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7784. Result = true;
  7785. ForceQueue = false;
  7786. CounterName = L"DownloadsDragDropFakeFile";
  7787. }
  7788. else
  7789. {
  7790. ForceQueue = false;
  7791. Enabled = false;
  7792. try
  7793. {
  7794. int Timer = 0;
  7795. Result = false;
  7796. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7797. {
  7798. {
  7799. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7800. TDragExtCommStruct* CommStruct;
  7801. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7802. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7803. DebugAssert(CommStruct != NULL);
  7804. Result = !CommStruct->Dragging;
  7805. if (Result)
  7806. {
  7807. Directory = ExtractFilePath(CommStruct->DropDest);
  7808. CounterName = L"DownloadsDragDropExternalExt";
  7809. }
  7810. UnmapViewOfFile(CommStruct);
  7811. }
  7812. if (!Result)
  7813. {
  7814. Sleep(50);
  7815. Timer += 50;
  7816. Application->ProcessMessages();
  7817. }
  7818. }
  7819. }
  7820. __finally
  7821. {
  7822. Enabled = true;
  7823. }
  7824. }
  7825. return Result;
  7826. }
  7827. //---------------------------------------------------------------------------
  7828. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7829. const UnicodeString TempDir, int SecDelay)
  7830. {
  7831. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7832. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7833. if (FDelayedDeletionTimer == NULL)
  7834. {
  7835. DebugAssert(HandleAllocated());
  7836. FDelayedDeletionTimer = new TTimer(this);
  7837. FDelayedDeletionTimer->Interval = 10000;
  7838. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7839. }
  7840. else
  7841. {
  7842. FDelayedDeletionTimer->Enabled = true;
  7843. }
  7844. }
  7845. //---------------------------------------------------------------------------
  7846. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7847. {
  7848. DebugAssert(FDelayedDeletionList != NULL);
  7849. TDateTime N = Now();
  7850. TDateTime Alert;
  7851. UnicodeString Directory;
  7852. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7853. {
  7854. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7855. if ((N >= Alert) || (Sender == NULL))
  7856. {
  7857. Directory = FDelayedDeletionList->Strings[Index];
  7858. if (RecursiveDeleteFile(ExcludeTrailingBackslash(Directory)))
  7859. {
  7860. FDelayedDeletionList->Delete(Index);
  7861. }
  7862. }
  7863. }
  7864. if (FDelayedDeletionList->Count == 0)
  7865. {
  7866. FDelayedDeletionTimer->Enabled = false;
  7867. }
  7868. }
  7869. //---------------------------------------------------------------------------
  7870. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7871. {
  7872. DebugAssert(!IsLocalBrowserMode());
  7873. if (IsFileControl(FDDTargetControl, osRemote) ||
  7874. (FDDTargetControl == SessionsPageControl))
  7875. {
  7876. TManagedTerminal * TargetTerminal = NULL;
  7877. TFileOperation Operation = foNone;
  7878. if (FDDTargetControl == SessionsPageControl)
  7879. {
  7880. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7881. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7882. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7883. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7884. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7885. {
  7886. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7887. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7888. {
  7889. Operation = foRemoteMove;
  7890. }
  7891. else
  7892. {
  7893. Operation = foRemoteCopy;
  7894. }
  7895. }
  7896. }
  7897. else
  7898. {
  7899. if (FLastDropEffect == DROPEFFECT_MOVE)
  7900. {
  7901. Operation = foRemoteMove;
  7902. }
  7903. else if (FLastDropEffect == DROPEFFECT_COPY)
  7904. {
  7905. Operation = foRemoteCopy;
  7906. }
  7907. }
  7908. if (Operation != foNone)
  7909. {
  7910. RemoteFileControlFileOperation(DropSourceControl,
  7911. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7912. }
  7913. // abort drag&drop
  7914. Abort();
  7915. }
  7916. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7917. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7918. (FDDTargetControl != QueueView3))
  7919. {
  7920. DebugAssert(!FDragTempDir.IsEmpty());
  7921. TTransferType Type;
  7922. UnicodeString TempDir = FDragTempDir;
  7923. // We clear FDragTempDir before calling
  7924. // just in case it fail (raises exception)
  7925. FDragTempDir = L"";
  7926. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7927. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7928. // empty directory parameter means temp directory -> don't display it!
  7929. UnicodeString TargetDir = L"";
  7930. int Options = 0;
  7931. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7932. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7933. {
  7934. Abort();
  7935. }
  7936. // TargetDir is set when dropped on local file control
  7937. // (this was workaround for legacy dirview event handling, now it should be
  7938. // made prettier)
  7939. if (TargetDir.IsEmpty())
  7940. {
  7941. TargetDir = TempDir;
  7942. if (ForceDirectories(ApiPath(TargetDir)))
  7943. {
  7944. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7945. FPendingTempSpaceWarn = true;
  7946. try
  7947. {
  7948. FDragDropOperation = true;
  7949. int Params = cpTemporary |
  7950. (Type == ttMove ? cpDelete : 0);
  7951. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7952. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7953. }
  7954. __finally
  7955. {
  7956. FDragDropOperation = false;
  7957. FPendingTempSpaceWarn = false;
  7958. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7959. }
  7960. }
  7961. else
  7962. {
  7963. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7964. }
  7965. }
  7966. }
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. void __fastcall TCustomScpExplorerForm::DDDownload(
  7970. TStrings * FilesToCopy, const UnicodeString & TargetDir, TCopyParamType * CopyParam, int Params)
  7971. {
  7972. DebugAssert(!IsLocalBrowserMode());
  7973. TAutoBatch AutoBatch(this);
  7974. CopyParam->IncludeFileMask.SetRoots(TargetDir, FilesToCopy);
  7975. UpdateCopyParamCounters(*CopyParam);
  7976. FMoveToQueue = false;
  7977. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7978. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7979. {
  7980. RemoteDriveView->UpdateDropSource();
  7981. }
  7982. }
  7983. //---------------------------------------------------------------------------
  7984. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7985. {
  7986. public:
  7987. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7988. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7989. {
  7990. }
  7991. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7992. {
  7993. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7994. TDataObjectFilesEx::AllowData(FormatEtc);
  7995. }
  7996. };
  7997. //---------------------------------------------------------------------------
  7998. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7999. TObject * Sender, TDataObject *& DataObject)
  8000. {
  8001. if (FDDExtMapFile != NULL)
  8002. {
  8003. TFileList * FileList = DragDropFiles(Sender)->FileList;
  8004. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  8005. {
  8006. Abort();
  8007. }
  8008. if (FileList->Count > 0)
  8009. {
  8010. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  8011. if (!FilesObject->IsValid(true, true))
  8012. {
  8013. FilesObject->_Release();
  8014. }
  8015. else
  8016. {
  8017. DataObject = FilesObject;
  8018. }
  8019. }
  8020. }
  8021. }
  8022. //---------------------------------------------------------------------------
  8023. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  8024. {
  8025. DebugFail();
  8026. }
  8027. //---------------------------------------------------------------------------
  8028. void __fastcall TCustomScpExplorerForm::GoToTree()
  8029. {
  8030. ComponentVisible[fcRemoteTree] = true;
  8031. DriveView(osRemote)->SetFocus();
  8032. }
  8033. //---------------------------------------------------------------------------
  8034. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8035. TPanelExport Export)
  8036. {
  8037. TCustomDirView * DirView = this->DirView(Side);
  8038. std::unique_ptr<TStrings> ExportData(new TStringList());
  8039. switch (Export)
  8040. {
  8041. case pePath:
  8042. ExportData->Add(DirView->PathName);
  8043. break;
  8044. case peFileList:
  8045. case peFullFileList:
  8046. {
  8047. bool FullPath = (Export == peFullFileList);
  8048. DirView->CreateFileList(false, FullPath, ExportData.get());
  8049. for (int Index = 0; Index < ExportData->Count; Index++)
  8050. {
  8051. if (ExportData->Strings[Index].Pos(L" ") > 0)
  8052. {
  8053. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  8054. }
  8055. }
  8056. }
  8057. break;
  8058. default:
  8059. DebugFail();
  8060. }
  8061. return ExportData.release();
  8062. }
  8063. //---------------------------------------------------------------------------
  8064. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8065. TPanelExport Export, TPanelExportDestination Destination)
  8066. {
  8067. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  8068. PanelExportStore(Side, Export, Destination, ExportData.get());
  8069. }
  8070. //---------------------------------------------------------------------------
  8071. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  8072. TPanelExport /*Export*/, TPanelExportDestination Destination,
  8073. TStrings * ExportData)
  8074. {
  8075. if (Destination == pedClipboard)
  8076. {
  8077. TInstantOperationVisualizer Visualizer;
  8078. CopyToClipboard(ExportData);
  8079. }
  8080. else
  8081. {
  8082. DebugFail();
  8083. }
  8084. }
  8085. //---------------------------------------------------------------------------
  8086. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  8087. {
  8088. TCustomDirView * DirView = this->DirView(Side);
  8089. UnicodeString Mask = DirView->Mask;
  8090. if (DoFilterMaskDialog(DirView, Mask))
  8091. {
  8092. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  8093. Configuration->Usage->Inc(L"Filters");
  8094. }
  8095. }
  8096. //---------------------------------------------------------------------------
  8097. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  8098. {
  8099. return FQueueController->DefaultOperation();
  8100. }
  8101. //---------------------------------------------------------------------------
  8102. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  8103. TQueueOperation Operation, void ** Param)
  8104. {
  8105. switch (Operation)
  8106. {
  8107. case qoPreferences:
  8108. return true;
  8109. case qoGoTo:
  8110. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  8111. case qoOnceEmpty:
  8112. return IsAnythingQueued();
  8113. default:
  8114. return FQueueController->AllowOperation(Operation, Param);
  8115. }
  8116. }
  8117. //---------------------------------------------------------------------------
  8118. void __fastcall TCustomScpExplorerForm::GoToQueue()
  8119. {
  8120. if (DebugAlwaysTrue(QueueView3->Visible))
  8121. {
  8122. QueueView3->SetFocus();
  8123. }
  8124. }
  8125. //---------------------------------------------------------------------------
  8126. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  8127. TQueueOperation Operation, void * Param)
  8128. {
  8129. if (Operation == qoGoTo)
  8130. {
  8131. GoToQueue();
  8132. }
  8133. else if (Operation == qoPreferences)
  8134. {
  8135. PreferencesDialog(pmQueue);
  8136. }
  8137. else
  8138. {
  8139. FQueueController->ExecuteOperation(Operation, Param);
  8140. }
  8141. }
  8142. //---------------------------------------------------------------------------
  8143. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  8144. {
  8145. return (Queue != NULL) && Queue->Enabled;
  8146. }
  8147. //---------------------------------------------------------------------------
  8148. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  8149. {
  8150. DebugAssert(Queue != NULL);
  8151. if (Queue != NULL)
  8152. {
  8153. Queue->Enabled = !Queue->Enabled;
  8154. }
  8155. }
  8156. //---------------------------------------------------------------------------
  8157. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  8158. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  8159. {
  8160. FQueueActedItem = QueueView3->ItemFocused;
  8161. }
  8162. //---------------------------------------------------------------------------
  8163. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  8164. {
  8165. return TopDock->Height + (MessageDock->Visible ? MessageDock->Height : 0) + QueueSplitter->Height;
  8166. }
  8167. //---------------------------------------------------------------------------
  8168. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  8169. {
  8170. return
  8171. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  8172. (QueueDock->Visible ? QueueDock->Height : 0) +
  8173. (QueueLabel->Visible ? QueueLabel->Height : 0);
  8174. }
  8175. //---------------------------------------------------------------------------
  8176. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  8177. {
  8178. return ScaleByTextHeight(this, 48);
  8179. }
  8180. //---------------------------------------------------------------------------
  8181. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  8182. TObject * /*Sender*/, int & NewSize, bool & Accept)
  8183. {
  8184. // when queue is hidden by double-clicking splitter, stray attempt to
  8185. // resize the panel with strange value arrives, make sure it is ignored
  8186. if (ComponentVisible[fcQueueView])
  8187. {
  8188. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  8189. if (NewSize > MaxHeightLimit)
  8190. {
  8191. NewSize = MaxHeightLimit;
  8192. }
  8193. int MinHeightLimit =
  8194. GetStaticQueuePanelComponentsHeight() +
  8195. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  8196. GetMinQueueViewHeight();
  8197. if (NewSize < MinHeightLimit)
  8198. {
  8199. NewSize = MinHeightLimit;
  8200. }
  8201. }
  8202. else
  8203. {
  8204. Accept = false;
  8205. }
  8206. }
  8207. //---------------------------------------------------------------------------
  8208. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  8209. {
  8210. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  8211. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  8212. if (QueueViewHeight < GetMinQueueViewHeight())
  8213. {
  8214. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  8215. }
  8216. }
  8217. //---------------------------------------------------------------------------
  8218. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  8219. TDragObject *& /*DragObject*/)
  8220. {
  8221. FQueueActedItem = QueueView3->ItemFocused;
  8222. FQueueScrollOnDragOver->StartDrag();
  8223. }
  8224. //---------------------------------------------------------------------------
  8225. void __fastcall TCustomScpExplorerForm::QueueView3EndDrag(
  8226. TObject *, TObject * DebugUsedArg(Target), int DebugUsedArg(X), int DebugUsedArg(Y))
  8227. {
  8228. FQueueScrollOnDragOver->EndDrag();
  8229. }
  8230. //---------------------------------------------------------------------------
  8231. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  8232. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  8233. {
  8234. Accept = true;
  8235. if (Source == QueueView3)
  8236. {
  8237. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  8238. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  8239. if (Accept)
  8240. {
  8241. TQueueItemProxy * QueueItem;
  8242. TQueueItemProxy * DestQueueItem;
  8243. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8244. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  8245. Accept = (QueueItem != DestQueueItem) &&
  8246. (QueueItem->Status == TQueueItem::qsPending) &&
  8247. (DestQueueItem->Status == TQueueItem::qsPending);
  8248. }
  8249. FQueueScrollOnDragOver->DragOver(TPoint(X, Y));
  8250. }
  8251. }
  8252. //---------------------------------------------------------------------------
  8253. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  8254. TObject * /*Source*/, int /*X*/, int /*Y*/)
  8255. {
  8256. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  8257. {
  8258. TQueueItemProxy * QueueItem;
  8259. TQueueItemProxy * DestQueueItem;
  8260. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8261. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  8262. QueueItem->Move(DestQueueItem);
  8263. }
  8264. }
  8265. //---------------------------------------------------------------------------
  8266. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  8267. {
  8268. if ((QueueView3->ItemFocused == NULL) &&
  8269. (QueueView3->Items->Count > 0))
  8270. {
  8271. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  8272. }
  8273. QueueLabelUpdateStatus();
  8274. }
  8275. //---------------------------------------------------------------------------
  8276. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  8277. {
  8278. QueueLabelUpdateStatus();
  8279. }
  8280. //---------------------------------------------------------------------------
  8281. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  8282. {
  8283. QueueLabel->UpdateStatus();
  8284. }
  8285. //---------------------------------------------------------------------------
  8286. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  8287. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  8288. {
  8289. if (Selected)
  8290. {
  8291. NonVisualDataModule->UpdateNonVisibleActions();
  8292. }
  8293. }
  8294. //---------------------------------------------------------------------------
  8295. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  8296. {
  8297. TDragDropFilesEx * Result = NULL;
  8298. if (Sender == SessionsPageControl)
  8299. {
  8300. Result = FSessionsDragDropFilesEx;
  8301. }
  8302. else if (Sender == QueueView3)
  8303. {
  8304. Result = FQueueDragDropFilesEx;
  8305. }
  8306. else
  8307. {
  8308. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8309. if (DirView != NULL)
  8310. {
  8311. Result = DirView->DragDropFilesEx;
  8312. }
  8313. else
  8314. {
  8315. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  8316. if (DriveView != NULL)
  8317. {
  8318. Result = DriveView->DragDropFilesEx;
  8319. }
  8320. }
  8321. }
  8322. DebugAssert(Result != NULL);
  8323. return Result;
  8324. }
  8325. //---------------------------------------------------------------------------
  8326. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  8327. {
  8328. return (DView->SelCount == DView->FilesCount);
  8329. }
  8330. //---------------------------------------------------------------------------
  8331. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  8332. {
  8333. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  8334. }
  8335. //---------------------------------------------------------------------------
  8336. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  8337. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  8338. {
  8339. DebugAssert(!IsLocalBrowserMode());
  8340. TFileOperation Operation;
  8341. switch (Effect)
  8342. {
  8343. case DROPEFFECT_MOVE:
  8344. Operation = foMove;
  8345. break;
  8346. case DROPEFFECT_COPY:
  8347. // occures on WinXP (reported by user)
  8348. default:
  8349. Operation = foCopy;
  8350. break;
  8351. };
  8352. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  8353. // see a comment in TUnixDirView::PerformItemDragDropOperation
  8354. if (DragDropFilesEx->FileList->Count > 0)
  8355. {
  8356. TStrings * FileList = new TStringList();
  8357. try
  8358. {
  8359. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  8360. {
  8361. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  8362. }
  8363. FDragDropOperation = true;
  8364. TTransferOperationParam Param;
  8365. Param.TargetDirectory = TargetPath;
  8366. // upload, no temp dirs
  8367. Param.Temp = false;
  8368. Param.DragDrop = DragDrop;
  8369. Param.Options =
  8370. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  8371. if (ForceQueue)
  8372. {
  8373. Param.Queue = asOn;
  8374. }
  8375. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  8376. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  8377. {
  8378. if (IsFileControl(DropSourceControl, osLocal))
  8379. {
  8380. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  8381. }
  8382. else
  8383. {
  8384. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  8385. }
  8386. }
  8387. }
  8388. __finally
  8389. {
  8390. FDragDropOperation = false;
  8391. delete FileList;
  8392. }
  8393. }
  8394. }
  8395. //---------------------------------------------------------------------------
  8396. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  8397. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  8398. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  8399. {
  8400. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  8401. }
  8402. //---------------------------------------------------------------------------
  8403. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  8404. TObject * Sender, int grfKeyState, int & dwEffect)
  8405. {
  8406. DebugAssert(!IsLocalBrowserMode());
  8407. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  8408. if ((dwEffect != DROPEFFECT_NONE) &&
  8409. IsFileControl(DropSourceControl, osRemote))
  8410. {
  8411. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8412. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8413. (RemoteDirView->DropTarget == NULL))
  8414. {
  8415. dwEffect = DROPEFFECT_NONE;
  8416. }
  8417. else
  8418. {
  8419. if (dwEffect == DROPEFFECT_COPY)
  8420. {
  8421. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8422. // currently we support copying always (at least via temporary directory);
  8423. // remove associated checks once this all proves stable and working
  8424. bool CopyCapable = true;
  8425. // if we do not support neither of operations, there's no discussion
  8426. if (!MoveCapable && !CopyCapable)
  8427. {
  8428. dwEffect = DROPEFFECT_NONE;
  8429. }
  8430. else
  8431. {
  8432. // The default effect inside remote panel is move,
  8433. // unless we do not support it, but support copy
  8434. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8435. {
  8436. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8437. }
  8438. else
  8439. {
  8440. // with ctrl-down, we want copy unless it is not supported
  8441. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8442. }
  8443. }
  8444. }
  8445. }
  8446. }
  8447. }
  8448. //---------------------------------------------------------------------------
  8449. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8450. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8451. {
  8452. DebugAssert(!IsLocalBrowserMode());
  8453. if (FDDTotalSize >= 0)
  8454. {
  8455. if (File->IsDirectory)
  8456. {
  8457. FDDTotalSize = -1;
  8458. }
  8459. else
  8460. {
  8461. FDDTotalSize += File->Size;
  8462. }
  8463. }
  8464. DebugAssert(!FDragTempDir.IsEmpty());
  8465. // TODO: this is quite ineffective
  8466. // TODO: what if invalid character replacement is disabled?
  8467. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8468. UnicodeString TransferFileName;
  8469. if (Sender == RemoteDriveView)
  8470. {
  8471. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8472. }
  8473. else
  8474. {
  8475. TransferFileName = File->FileName;
  8476. }
  8477. FDDFileList->AddObject(TransferFileName, File);
  8478. }
  8479. //---------------------------------------------------------------------------
  8480. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8481. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8482. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8483. {
  8484. // sometimes we do not get DDEnd so the list is not released
  8485. SAFE_DESTROY(FDDFileList);
  8486. FDDFileList = new TStringList();
  8487. FDragTempDir = WinConfiguration->TemporaryDir();
  8488. FDDTotalSize = 0;
  8489. FDragDropSshTerminate.reset(NULL);
  8490. }
  8491. //---------------------------------------------------------------------------
  8492. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8493. TObject * /*Sender*/, LongBool /*FEscapePressed*/, int /*grfKeyState*/,
  8494. HRESULT & Result)
  8495. {
  8496. if (Result == DRAGDROP_S_DROP)
  8497. {
  8498. try
  8499. {
  8500. GlobalDragImageList->HideDragImage();
  8501. try
  8502. {
  8503. RemoteFileControlDDTargetDrop();
  8504. }
  8505. catch(ESshTerminate & E)
  8506. {
  8507. FDragDropSshTerminate.reset(E.Clone());
  8508. }
  8509. }
  8510. catch (Exception &E)
  8511. {
  8512. // If downloading fails we need to cancel drag&drop, otherwise
  8513. // Explorer shows error
  8514. // But by the way exception probably never reach this point as
  8515. // it's catched on way.
  8516. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8517. Result = DRAGDROP_S_CANCEL;
  8518. ShowExtendedException(Terminal, &E);
  8519. }
  8520. }
  8521. }
  8522. //---------------------------------------------------------------------------
  8523. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8524. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8525. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8526. {
  8527. TFileMasks::TParams MaskParams;
  8528. MaskParams.Size = Size;
  8529. MaskParams.Modification = Modification;
  8530. // this does not re-parse the mask if it is the same as the last time
  8531. FDirViewMatchMask = Masks;
  8532. bool ImplicitMatch;
  8533. Matches =
  8534. // Local and RecurseInclude parameters have no effect as there's no path.
  8535. // This should use potential MatchesFileName overload with ImplicitMatch argument.
  8536. FDirViewMatchMask.Matches(FileName, false, Directory, &MaskParams, true, ImplicitMatch) &&
  8537. (AllowImplicitMatches || !ImplicitMatch);
  8538. }
  8539. //---------------------------------------------------------------------------
  8540. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8541. TObject * Sender, TListItem * Item, WORD & Indexes)
  8542. {
  8543. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8544. if (GetPartialFileExtLen(DirView->ItemFileName(Item)) > 0)
  8545. {
  8546. Indexes |= oiPartial;
  8547. }
  8548. }
  8549. //---------------------------------------------------------------------------
  8550. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8551. {
  8552. return
  8553. DirViewEnabled(osCurrent) &&
  8554. DirView(osCurrent)->CanPasteFromClipBoard();
  8555. }
  8556. //---------------------------------------------------------------------------
  8557. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8558. {
  8559. bool Result = false;
  8560. if (CanPasteToDirViewFromClipBoard())
  8561. {
  8562. Result = true;
  8563. }
  8564. else
  8565. {
  8566. UnicodeString ClipboardText;
  8567. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8568. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8569. {
  8570. if (StoredSessions->IsUrl(ClipboardText))
  8571. {
  8572. Result = true;
  8573. }
  8574. else
  8575. {
  8576. Result = DirViewEnabled(osCurrent);
  8577. }
  8578. }
  8579. }
  8580. return Result;
  8581. }
  8582. //---------------------------------------------------------------------------
  8583. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8584. {
  8585. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8586. if (DoesClipboardContainOurFiles())
  8587. {
  8588. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8589. {
  8590. DebugAssert(!IsLocalBrowserMode());
  8591. TTerminalManager * Manager = TTerminalManager::Instance();
  8592. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8593. Manager->ActiveSession = FClipboardTerminal;
  8594. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8595. }
  8596. }
  8597. else if (CanPasteToDirViewFromClipBoard())
  8598. {
  8599. DirView(osCurrent)->PasteFromClipBoard();
  8600. }
  8601. else
  8602. {
  8603. UnicodeString ClipboardText;
  8604. if (NonEmptyTextFromClipboard(ClipboardText))
  8605. {
  8606. if (StoredSessions->IsUrl(ClipboardText))
  8607. {
  8608. NewSession(ClipboardText);
  8609. }
  8610. else
  8611. {
  8612. DirView(osCurrent)->Path = ClipboardText;
  8613. }
  8614. }
  8615. }
  8616. }
  8617. //---------------------------------------------------------------------------
  8618. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8619. {
  8620. // TBD
  8621. }
  8622. //---------------------------------------------------------------------------
  8623. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8624. {
  8625. TCustomDirView * ADirView = DirView(Side);
  8626. ADirView->SelectAll(Mode);
  8627. ADirView->SetFocus();
  8628. }
  8629. //---------------------------------------------------------------------------
  8630. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8631. {
  8632. TCustomDirView * ADirView = DirView(Side);
  8633. TFileFilter Filter;
  8634. DefaultFileFilter(Filter);
  8635. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8636. {
  8637. Configuration->Usage->Inc(L"MaskSelections");
  8638. ADirView->SelectFiles(Filter, Select);
  8639. ADirView->SetFocus();
  8640. }
  8641. }
  8642. //---------------------------------------------------------------------------
  8643. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8644. {
  8645. TCustomDirView * ADirView = DirView(Side);
  8646. ADirView->RestoreSelectedNames();
  8647. ADirView->SetFocus();
  8648. }
  8649. //---------------------------------------------------------------------------
  8650. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8651. {
  8652. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8653. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8654. {
  8655. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8656. UnicodeString Ext;
  8657. if (!IsSideLocalBrowser(osCurrent))
  8658. {
  8659. Ext = UnixExtractFileExt(FileName);
  8660. }
  8661. else
  8662. {
  8663. Ext = ExtractFileExt(FileName);
  8664. }
  8665. if (Ext.IsEmpty())
  8666. {
  8667. Ext = L".";
  8668. }
  8669. TFileFilter Filter;
  8670. Filter.Masks = FORMAT(L"*%s", (Ext));
  8671. Filter.Directories = false;
  8672. CurrentDirView->SelectFiles(Filter, Select);
  8673. }
  8674. }
  8675. //---------------------------------------------------------------------------
  8676. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8677. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8678. {
  8679. UnicodeString Result;
  8680. if (FIncrementalSearchState.Searching && (Side == GetSide(osCurrent)))
  8681. {
  8682. Result = FormatIncrementalSearchStatus(FIncrementalSearchState);
  8683. }
  8684. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8685. {
  8686. // noop
  8687. }
  8688. else
  8689. {
  8690. Result =
  8691. FMTLOAD(FILE_INFO_FORMAT,
  8692. (FormatBytes(FileInfo.SelectedSize),
  8693. FormatBytes(FileInfo.FilesSize),
  8694. FormatNumber(FileInfo.SelectedCount),
  8695. FormatNumber(FileInfo.FilesCount)));
  8696. }
  8697. return Result;
  8698. }
  8699. //---------------------------------------------------------------------------
  8700. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8701. TTBXStatusPanel * Panel, TOperationSide Side)
  8702. {
  8703. if (Panel->Index == 1)
  8704. {
  8705. ToggleShowHiddenFiles();
  8706. }
  8707. else if (Panel->Index == 2)
  8708. {
  8709. Filter(Side);
  8710. }
  8711. }
  8712. //---------------------------------------------------------------------------
  8713. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8714. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8715. {
  8716. DebugAssert(!StatusBar->SimplePanel);
  8717. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8718. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8719. }
  8720. //---------------------------------------------------------------------------
  8721. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8722. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8723. {
  8724. DebugAssert(StatusBar->Panels->Count >= 3);
  8725. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8726. if (FileInfo.HiddenCount > 0)
  8727. {
  8728. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8729. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8730. }
  8731. else
  8732. {
  8733. HiddenFilesPanel->ViewPriority = 0;
  8734. // not really necessary, just to cleanup no-longer-valid data
  8735. HiddenFilesPanel->Caption = L"";
  8736. }
  8737. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8738. if (FileInfo.FilteredCount > 0)
  8739. {
  8740. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8741. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8742. }
  8743. else
  8744. {
  8745. FilteredFilesPanel->ViewPriority = 0;
  8746. // not really necessary, just to cleanup no-longer-valid data
  8747. FilteredFilesPanel->Caption = L"";
  8748. }
  8749. }
  8750. //---------------------------------------------------------------------------
  8751. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8752. TObject * /*Sender*/)
  8753. {
  8754. if (DirView(osOther)->Enabled)
  8755. {
  8756. DirView(osOther)->SetFocus();
  8757. }
  8758. }
  8759. //---------------------------------------------------------------------------
  8760. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8761. {
  8762. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8763. switch (Config.Show)
  8764. {
  8765. case qvShow:
  8766. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8767. {
  8768. Config.Show = qvHide;
  8769. }
  8770. else
  8771. {
  8772. Config.Show = Config.LastHideShow;
  8773. }
  8774. break;
  8775. case qvHideWhenEmpty:
  8776. if (ComponentVisible[fcQueueView])
  8777. {
  8778. Config.Show = qvHide;
  8779. }
  8780. else
  8781. {
  8782. Config.LastHideShow = Config.Show;
  8783. Config.Show = qvShow;
  8784. }
  8785. break;
  8786. case qvHide:
  8787. Config.LastHideShow = Config.Show;
  8788. Config.Show = qvShow;
  8789. break;
  8790. }
  8791. WinConfiguration->QueueView = Config;
  8792. }
  8793. //---------------------------------------------------------------------------
  8794. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8795. {
  8796. UnicodeString Result;
  8797. if (Terminal != NULL)
  8798. {
  8799. switch (WinConfiguration->PathInCaption)
  8800. {
  8801. case picShort:
  8802. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8803. break;
  8804. case picFull:
  8805. Result = Terminal->CurrentDirectory;
  8806. break;
  8807. }
  8808. }
  8809. return Result;
  8810. }
  8811. //---------------------------------------------------------------------------
  8812. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8813. {
  8814. TColor Result = GetWindowColor(FSessionColor);
  8815. return Result;
  8816. }
  8817. //---------------------------------------------------------------------------
  8818. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8819. {
  8820. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8821. return Result;
  8822. }
  8823. //---------------------------------------------------------------------------
  8824. void TCustomScpExplorerForm::UpdatePanelControls(TCustomDirView * ADirView, TCustomDriveView * ADriveView)
  8825. {
  8826. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8827. ADirView->DarkMode = UseDarkTheme;
  8828. ADriveView->DarkMode = UseDarkTheme;
  8829. }
  8830. //---------------------------------------------------------------------------
  8831. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8832. {
  8833. if (!FSessionChanging)
  8834. {
  8835. TTerminalManager::Instance()->UpdateAppTitle();
  8836. }
  8837. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8838. // background to gray on Windows 7 (works on Windows 10).
  8839. // See also EnableControl
  8840. if (Showing)
  8841. {
  8842. if (ManagedSession != NULL)
  8843. {
  8844. // Update path when it changes
  8845. if ((SessionsPageControl->ActivePage != NULL) &&
  8846. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8847. {
  8848. UpdateSessionTab(SessionsPageControl->ActivePage);
  8849. }
  8850. }
  8851. NonVisualDataModule->ReconnectSessionAction->Update();
  8852. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8853. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8854. CenterReconnectToolbar();
  8855. bool HasTerminal = HasActiveTerminal();
  8856. RemoteDirView->Enabled = HasTerminal;
  8857. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8858. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8859. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8860. RemoteDriveView->Color = RemoteDirView->Color;
  8861. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8862. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8863. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8864. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8865. QueueFileList->Enabled = QueueView3->Enabled;
  8866. QueueFileList->Color = QueueView3->Color;
  8867. QueueFileList->Font->Color = QueueView3->Font->Color;
  8868. QueueLabelUpdateStatus();
  8869. UpdatePanelControls(RemoteDirView, RemoteDriveView);
  8870. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8871. if (FImmersiveDarkMode != UseDarkTheme)
  8872. {
  8873. UpdateDarkMode();
  8874. }
  8875. SessionsPageControl->TabTheme = UseDarkTheme ? CurrentTheme : NULL;
  8876. UnicodeString CurrentHiContrastThemeName = (FHiContrastTheme != NULL) ? FHiContrastTheme->Name : EmptyStr;
  8877. bool HiContrast = WinConfiguration->HiContrast;
  8878. UnicodeString NewHiContrastThemeName = HiContrast ? GetThemeName(!UseDarkTheme) : EmptyStr;
  8879. if (CurrentHiContrastThemeName != NewHiContrastThemeName)
  8880. {
  8881. ReleaseHiContrastTheme();
  8882. if (!NewHiContrastThemeName.IsEmpty())
  8883. {
  8884. FHiContrastTheme = GetTBXTheme(NewHiContrastThemeName);
  8885. }
  8886. }
  8887. SessionsPageControl->ActiveTabTheme = HiContrast ? DebugNotNull(FHiContrastTheme) : NULL;
  8888. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8889. MessageDock->Visible = (MessageDock->ToolbarCount > 0);
  8890. }
  8891. }
  8892. //---------------------------------------------------------------------------
  8893. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8894. {
  8895. UpdateControls();
  8896. }
  8897. //---------------------------------------------------------------------------
  8898. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8899. TObject * Sender)
  8900. {
  8901. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8902. DebugAssert(DirView != NULL);
  8903. DoDirViewLoaded(DirView);
  8904. TransferPresetAutoSelect();
  8905. TUnixDirView * UnixDirView = dynamic_cast<TUnixDirView *>(DirView);
  8906. if (UnixDirView != NULL)
  8907. {
  8908. TManagedTerminal * ATerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(UnixDirView->Terminal));
  8909. TTerminalManager::Instance()->TerminalLoadedDirectory(ATerminal);
  8910. }
  8911. }
  8912. //---------------------------------------------------------------------------
  8913. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8914. {
  8915. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8916. // first run after installation
  8917. if (double(Updates.LastCheck) == 0)
  8918. {
  8919. AppLog(L"First run, scheduling updates check for the next run");
  8920. // make sure next time there will be an update (if enabled)
  8921. Updates.LastCheck = TDateTime(1);
  8922. WinConfiguration->Updates = Updates;
  8923. }
  8924. else
  8925. {
  8926. TDateTime Period;
  8927. if (IsUWP() && !IsOfficialPackage())
  8928. {
  8929. Period = DefaultUpdatesPeriod;
  8930. AppLog(L"Thirdparty UWP package, using default updates check period");
  8931. }
  8932. else
  8933. {
  8934. Period = Updates.Period;
  8935. }
  8936. AppLogFmt(L"Updates check period: %.2f", (double(Period)));
  8937. if (double(Period) > 0)
  8938. {
  8939. TDateTime Interval = Now() - Updates.LastCheck;
  8940. AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
  8941. if (Interval >= Period)
  8942. {
  8943. StartUpdateThread(UpdatesChecked);
  8944. }
  8945. }
  8946. }
  8947. }
  8948. //---------------------------------------------------------------------------
  8949. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8950. {
  8951. AppLog(L"Updates check done");
  8952. UnicodeString Message;
  8953. bool New;
  8954. TQueryType Type;
  8955. GetUpdatesMessage(Message, New, Type, false);
  8956. if (!Message.IsEmpty())
  8957. {
  8958. AppLogFmt(L"Updates check message: %s", (Message));
  8959. if (New)
  8960. {
  8961. AppLog(L"New version detected");
  8962. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8963. }
  8964. if (!New && (Type != qtWarning))
  8965. {
  8966. AppLog(L"Posting non-critical updates note");
  8967. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8968. }
  8969. else
  8970. {
  8971. AppLog(L"Posting new version or critical message notification");
  8972. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8973. }
  8974. if (New)
  8975. {
  8976. Configuration->Usage->Inc(L"UpdateNotifications");
  8977. }
  8978. }
  8979. }
  8980. //---------------------------------------------------------------------------
  8981. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8982. {
  8983. RestoreApp();
  8984. bool CanDisplay = !NonVisualDataModule->Busy;
  8985. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8986. {
  8987. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8988. }
  8989. if (CanDisplay)
  8990. {
  8991. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8992. // Probably not needed as CheckForUpdates is blocking since we started using neon for HTTP implementation.
  8993. NonVisualDataModule->StartBusy();
  8994. try
  8995. {
  8996. CheckForUpdates(true);
  8997. }
  8998. __finally
  8999. {
  9000. NonVisualDataModule->EndBusy();
  9001. }
  9002. }
  9003. else
  9004. {
  9005. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  9006. }
  9007. }
  9008. //---------------------------------------------------------------------------
  9009. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  9010. TCopyParamRuleData & Data)
  9011. {
  9012. DebugAssert(Terminal != NULL);
  9013. Data.HostName = Terminal->SessionData->HostNameExpanded;
  9014. Data.UserName = Terminal->SessionData->UserNameExpanded;
  9015. Data.RemoteDirectory = RemoteDirView->PathName;
  9016. }
  9017. //---------------------------------------------------------------------------
  9018. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  9019. {
  9020. // Terminal can be null when we are changing local directory implicitly,
  9021. // because it has been deleted, while no session is connected
  9022. // (Login dialog is open)
  9023. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  9024. {
  9025. DebugAssert(!IsLocalBrowserMode());
  9026. TCopyParamRuleData Data;
  9027. GetTransferPresetAutoSelectData(Data);
  9028. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  9029. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  9030. if (CopyParamIndex < 0)
  9031. {
  9032. // there is no preset that matches autoselection
  9033. // set preset that we consider "default"
  9034. FCopyParamAutoSelected = L""; // forget last autoselected preset
  9035. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  9036. }
  9037. else
  9038. {
  9039. // there is preset matching autoselection
  9040. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  9041. if (CopyParamName == FCopyParamAutoSelected)
  9042. {
  9043. // autoselected the same preset as the last time
  9044. // make no change (i.e. preserve custom user preset, if any)
  9045. }
  9046. else
  9047. {
  9048. // autoselected the different preset then the last time (or there
  9049. // was default preset set)
  9050. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  9051. GUIConfiguration->CopyParamCurrent = CopyParamName;
  9052. }
  9053. }
  9054. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  9055. {
  9056. if (CopyParamIndex >= 0)
  9057. {
  9058. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  9059. }
  9060. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  9061. try
  9062. {
  9063. int Fmt =
  9064. (CopyParamIndex < 0) ?
  9065. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  9066. COPY_PARAM_AUTOSELECTED;
  9067. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  9068. Data->Message = MainInstructions(Message);
  9069. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  9070. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  9071. CopyParamAttrs);
  9072. if (CopyParamIndex >= 0)
  9073. {
  9074. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  9075. Info = FORMAT(L"%s\n \n%s", (Info,
  9076. FMTLOAD(COPY_PARAM_RULE,
  9077. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  9078. }
  9079. Data->Message += L"\n\n" + Info;
  9080. if (WinConfiguration->CopyParamAutoSelectNotice)
  9081. {
  9082. TransferPresetNoteMessage(Data, true);
  9083. }
  9084. else
  9085. {
  9086. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  9087. Data = NULL; // ownership passed
  9088. }
  9089. }
  9090. __finally
  9091. {
  9092. delete Data;
  9093. }
  9094. }
  9095. }
  9096. }
  9097. //---------------------------------------------------------------------------
  9098. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  9099. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  9100. {
  9101. DebugAssert(NoteData != NULL);
  9102. DebugAssert(!IsLocalBrowserMode());
  9103. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  9104. TQueryButtonAlias Aliases[1];
  9105. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  9106. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  9107. Params.Aliases = Aliases;
  9108. Params.AliasesCount = LENOF(Aliases);
  9109. unsigned int Result =
  9110. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  9111. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  9112. switch (Result)
  9113. {
  9114. case qaNeverAskAgain:
  9115. DebugAssert(AllowNeverAskAgain);
  9116. WinConfiguration->CopyParamAutoSelectNotice = false;
  9117. break;
  9118. case qaIgnore:
  9119. PreferencesDialog(pmPresets);
  9120. break;
  9121. }
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  9125. {
  9126. // as of now useless, as this is used for notes only, never for balloons, ...
  9127. RestoreApp();
  9128. // .. and we should never be busy here
  9129. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  9130. {
  9131. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  9132. }
  9133. }
  9134. //---------------------------------------------------------------------------
  9135. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  9136. TPreferencesMode APreferencesMode)
  9137. {
  9138. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  9139. TCopyParamRuleData Data;
  9140. if (Terminal != NULL)
  9141. {
  9142. PreferencesData.reset(new TPreferencesDialogData());
  9143. GetTransferPresetAutoSelectData(Data);
  9144. PreferencesData->CopyParamRuleData = &Data;
  9145. }
  9146. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  9147. }
  9148. //---------------------------------------------------------------------------
  9149. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  9150. const TCustomCommandType & Command)
  9151. {
  9152. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  9153. {
  9154. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  9155. }
  9156. }
  9157. //---------------------------------------------------------------------------
  9158. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  9159. {
  9160. bool RemoteAllowed = CustomCommandRemoteAllowed();
  9161. TCustomCommandType Command;
  9162. // make sure we use local custom command when remote are not supported
  9163. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  9164. {
  9165. Command = FLastCustomCommand;
  9166. }
  9167. else
  9168. {
  9169. Command.Params = Command.Params | ccLocal;
  9170. }
  9171. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  9172. FEditingFocusedAdHocCommand = OnFocused;
  9173. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  9174. int Options =
  9175. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  9176. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  9177. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  9178. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  9179. {
  9180. FLastCustomCommand = Command;
  9181. UpdateCustomCommandsToolbar();
  9182. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  9183. }
  9184. }
  9185. //---------------------------------------------------------------------------
  9186. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  9187. {
  9188. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  9189. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9190. DebugAssert(State > 0);
  9191. if (State <= 0)
  9192. {
  9193. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  9194. }
  9195. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  9196. }
  9197. //---------------------------------------------------------------------------
  9198. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  9199. TCustomCommandType & Command, int & State)
  9200. {
  9201. bool Result = !FLastCustomCommand.Command.IsEmpty();
  9202. if (Result)
  9203. {
  9204. Command = FLastCustomCommand;
  9205. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9206. }
  9207. return Result;
  9208. }
  9209. //---------------------------------------------------------------------------
  9210. void __fastcall TCustomScpExplorerForm::BeforeAction()
  9211. {
  9212. ResetIncrementalSearch();
  9213. }
  9214. //---------------------------------------------------------------------------
  9215. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  9216. {
  9217. DebugAssert(ComponentVisible[Component]);
  9218. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  9219. }
  9220. //---------------------------------------------------------------------------
  9221. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  9222. {
  9223. // when queue panel is resized here directly, the status bar is stretched
  9224. // over whole space the panel occupied
  9225. PostComponentHide(fcQueueView);
  9226. }
  9227. //---------------------------------------------------------------------------
  9228. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  9229. {
  9230. ComponentVisible[fcQueueFileList] = false;
  9231. }
  9232. //---------------------------------------------------------------------------
  9233. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  9234. {
  9235. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  9236. RefreshColorMode();
  9237. ResetSysDarkTheme();
  9238. ConfigurationChanged();
  9239. ConfigureInterface();
  9240. // Should be called for all controls
  9241. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  9242. }
  9243. //---------------------------------------------------------------------------
  9244. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  9245. {
  9246. // Do not handle, when shutting down anyway (maybe also when not setup completely yet?)
  9247. if (!FInvalid &&
  9248. (Message.LParam != 0) &&
  9249. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  9250. {
  9251. ThemeChanged();
  9252. }
  9253. TForm::Dispatch(&Message);
  9254. }
  9255. //---------------------------------------------------------------------------
  9256. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  9257. {
  9258. TMessage * M = static_cast<TMessage*>(Message);
  9259. switch (M->Msg)
  9260. {
  9261. case CM_DIALOGCHAR:
  9262. CMDialogChar(*M);
  9263. break;
  9264. case WM_APPCOMMAND:
  9265. WMAppCommand(*M);
  9266. break;
  9267. case WM_SYSCOMMAND:
  9268. WMSysCommand(*M);
  9269. break;
  9270. case WM_QUERYENDSESSION:
  9271. WMQueryEndSession(*M);
  9272. break;
  9273. case WM_ENDSESSION:
  9274. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  9275. break;
  9276. #ifdef _DEBUG
  9277. case WM_WINDOWPOSCHANGED:
  9278. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  9279. break;
  9280. case CM_CUSTOMSTYLECHANGED:
  9281. TForm::Dispatch(Message);
  9282. break;
  9283. #endif
  9284. case WM_COMPONENT_HIDE:
  9285. {
  9286. Byte Component = static_cast<Byte>(M->WParam);
  9287. // sanity check
  9288. if (ComponentVisible[Component])
  9289. {
  9290. // special treatment
  9291. if (Component == fcQueueView)
  9292. {
  9293. ToggleQueueVisibility();
  9294. DebugAssert(!ComponentVisible[fcQueueView]);
  9295. }
  9296. else
  9297. {
  9298. ComponentVisible[Component] = false;
  9299. }
  9300. }
  9301. }
  9302. break;
  9303. case WM_COPYDATA:
  9304. WMCopyData(*M);
  9305. break;
  9306. case WM_MANAGES_CAPTION:
  9307. // caption managed in TTerminalManager::UpdateAppTitle()
  9308. M->Result = 1;
  9309. break;
  9310. case WM_WANTS_MOUSEWHEEL:
  9311. M->Result = 1;
  9312. break;
  9313. case CM_SHOWINGCHANGED:
  9314. CMShowingChanged(*M);
  9315. break;
  9316. case WM_CLOSE:
  9317. WMClose(*M);
  9318. break;
  9319. case WM_DPICHANGED:
  9320. WMDpiChanged(*M);
  9321. break;
  9322. case WM_SETTINGCHANGE:
  9323. WMSettingChange(*M);
  9324. break;
  9325. case CM_DIALOGKEY:
  9326. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  9327. break;
  9328. case WM_PASTE_FILES:
  9329. PasteFiles();
  9330. break;
  9331. case WM_IS_HIDDEN:
  9332. // To treat master password prompt as a main window while showing it when workspace is loading while
  9333. // the exporer is showing up (Visible is true already)
  9334. M->Result = !FShowing;
  9335. break;
  9336. case WM_SHOWWINDOW:
  9337. if (M->WParam)
  9338. {
  9339. AddStartupSequence(L"J");
  9340. }
  9341. TForm::Dispatch(Message);
  9342. break;
  9343. case WM_QUEUE_CALLBACK:
  9344. WMQueueCallback(*M);
  9345. break;
  9346. default:
  9347. TForm::Dispatch(Message);
  9348. break;
  9349. }
  9350. }
  9351. //---------------------------------------------------------------------------
  9352. void __fastcall TCustomScpExplorerForm::UpdateImages()
  9353. {
  9354. // noop
  9355. }
  9356. //---------------------------------------------------------------------------
  9357. void TCustomScpExplorerForm::RegenerateSessionColorsImageList()
  9358. {
  9359. FSessionColors->Clear();
  9360. AddFixedSessionImages();
  9361. ::RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  9362. UpdateImages();
  9363. }
  9364. //---------------------------------------------------------------------------
  9365. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  9366. {
  9367. TForm::Dispatch(&Message);
  9368. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  9369. UpdatePixelsPerInchMainWindowCounter();
  9370. }
  9371. //---------------------------------------------------------------------------
  9372. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  9373. {
  9374. AppLog(L"Main window WM_CLOSE");
  9375. // Cannot close window while we are busy.
  9376. // We cannot test this in FormCloseQuery as that is called also from
  9377. // Close(), which is called by CloseApplicationAction. So we can be busy
  9378. // there already even, when it is legitimate to close the application.
  9379. // Possibly a better place to handle this would be WMSysCommand.
  9380. if (NonVisualDataModule->Busy)
  9381. {
  9382. Message.Result = 1;
  9383. }
  9384. else
  9385. {
  9386. TForm::Dispatch(&Message);
  9387. }
  9388. }
  9389. //---------------------------------------------------------------------------
  9390. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  9391. {
  9392. if (!FShowingChanged)
  9393. {
  9394. AddStartupSequence(L"D");
  9395. FShowingChanged = true;
  9396. }
  9397. // Ignoring implicit local-local browser of Commander, opened from DoShow
  9398. bool NoSession = (ManagedSession == NULL);
  9399. // This calls TCustomScpExplorerForm::DoShow
  9400. TForm::Dispatch(&Message);
  9401. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  9402. if (Showing && !FStarted)
  9403. {
  9404. FStarted = true;
  9405. InterfaceStarted();
  9406. }
  9407. if (Showing && NoSession)
  9408. {
  9409. // When we are starting minimized (i.e. from an installer),
  9410. // postpone showing Login dialog until we get restored.
  9411. // Otherwise the Login dialog (and Authentication window) show restored
  9412. // over invisible (minimized) main window.
  9413. if (WindowState == wsMinimized)
  9414. {
  9415. FNeedSession = true;
  9416. }
  9417. else
  9418. {
  9419. // This happens before application ever goes idle, so the toolbars would
  9420. // stay enabled (initial state) until the Login dialog is dismissed.
  9421. UpdateActions();
  9422. NonVisualDataModule->StartBusy();
  9423. try
  9424. {
  9425. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  9426. // otherwise the dialog does not receive focus.
  9427. // With Commander interface the ProcessMessages is called already
  9428. // by TDriveView, but with Explorer interface, we need to call it explicily
  9429. Application->ProcessMessages();
  9430. // do not reload sessions, they have been loaded just now (optimization)
  9431. NeedSession(true);
  9432. }
  9433. __finally
  9434. {
  9435. NonVisualDataModule->EndBusy();
  9436. }
  9437. }
  9438. }
  9439. }
  9440. //---------------------------------------------------------------------------
  9441. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  9442. {
  9443. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  9444. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  9445. }
  9446. //---------------------------------------------------------------------------
  9447. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  9448. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  9449. int & MaxHeight)
  9450. {
  9451. // workaround for bug in TWinControl.CalcConstraints
  9452. // Check for empty rect (restore from iconic state) is done there only after
  9453. // call to AdjustClientRect, which enlarges the rect (for forms).
  9454. TRect R = GetClientRect();
  9455. // when restoring from iconic state, place no restrictions
  9456. if (IsRectEmpty(R))
  9457. {
  9458. MinWidth = 0;
  9459. MinHeight = 0;
  9460. MaxWidth = 32000;
  9461. MaxHeight = 32000;
  9462. }
  9463. }
  9464. //---------------------------------------------------------------------------
  9465. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  9466. TSpaceAvailable & ASpaceAvailable, bool & Close)
  9467. {
  9468. // terminal can be already closed (e.g. dropped connection)
  9469. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  9470. {
  9471. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  9472. try
  9473. {
  9474. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  9475. }
  9476. catch(...)
  9477. {
  9478. if (!Terminal->Active)
  9479. {
  9480. Close = true;
  9481. }
  9482. throw;
  9483. }
  9484. }
  9485. }
  9486. //---------------------------------------------------------------------------
  9487. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9488. {
  9489. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9490. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9491. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9492. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9493. {
  9494. OnGetSpaceAvailable = GetSpaceAvailable;
  9495. }
  9496. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9497. OnGetSpaceAvailable);
  9498. }
  9499. //---------------------------------------------------------------------------
  9500. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9501. {
  9502. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9503. Terminal->FillSessionDataForCode(Data.get());
  9504. return Data.release();
  9505. }
  9506. //---------------------------------------------------------------------------
  9507. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9508. {
  9509. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9510. DoGenerateUrlDialog(Data.get(), Paths);
  9511. }
  9512. //---------------------------------------------------------------------------
  9513. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9514. {
  9515. GenerateUrl(NULL);
  9516. }
  9517. //---------------------------------------------------------------------------
  9518. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9519. {
  9520. std::unique_ptr<TStrings> Paths(new TStringList());
  9521. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9522. GenerateUrl(Paths.get());
  9523. }
  9524. //---------------------------------------------------------------------------
  9525. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9526. {
  9527. FSessionColor = value;
  9528. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9529. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9530. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9531. DebugAssert(ColorItem != NULL);
  9532. ColorItem->Color = C;
  9533. NonVisualDataModule->ColorMenuItem->Color = C;
  9534. UpdateControls();
  9535. }
  9536. //---------------------------------------------------------------------------
  9537. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9538. {
  9539. if (value != FSessionColor)
  9540. {
  9541. UpdateSessionColor(value);
  9542. // Is null when called from LastTerminalClosed
  9543. if (Terminal != NULL)
  9544. {
  9545. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9546. }
  9547. }
  9548. }
  9549. //---------------------------------------------------------------------------
  9550. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9551. {
  9552. bool Result = FNoteTimer->Enabled;
  9553. if (Result)
  9554. {
  9555. // cannot cancel note too early
  9556. bool NotEarly =
  9557. (Now() - FNoteShown >
  9558. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9559. if (Force || NotEarly)
  9560. {
  9561. FNoteTimer->Enabled = false;
  9562. FNote = L"";
  9563. SAFE_DESTROY(FNoteData);
  9564. FOnNoteClick = NULL;
  9565. FNoteHints = FNotes->Text;
  9566. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9567. UpdateStatusBar();
  9568. }
  9569. }
  9570. return Result;
  9571. }
  9572. //---------------------------------------------------------------------------
  9573. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9574. {
  9575. DebugAssert(FNoteTimer->Enabled);
  9576. CancelNote(true);
  9577. }
  9578. //---------------------------------------------------------------------------
  9579. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9580. {
  9581. FNoteHints = FNotes->Text.TrimRight();
  9582. }
  9583. //---------------------------------------------------------------------------
  9584. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9585. {
  9586. int P = Note.Pos(L"\n");
  9587. if (P > 0)
  9588. {
  9589. Note.SetLength(P - 1);
  9590. }
  9591. FNotes->Add(FORMAT(L"[%s] %s",
  9592. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9593. while (FNotes->Count > 10)
  9594. {
  9595. FNotes->Delete(0);
  9596. }
  9597. if (UpdateNow)
  9598. {
  9599. UpdateNoteHints();
  9600. UpdateStatusBar();
  9601. }
  9602. }
  9603. //---------------------------------------------------------------------------
  9604. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9605. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9606. {
  9607. int P = Note.Pos(L"\n");
  9608. if (P > 0)
  9609. {
  9610. Note.SetLength(P - 1);
  9611. }
  9612. UpdateNoteHints();
  9613. FNote = Note;
  9614. SAFE_DESTROY(FNoteData);
  9615. FNoteData = NoteData;
  9616. FOnNoteClick = OnNoteClick;
  9617. AddNote(Note, false);
  9618. UpdateStatusBar();
  9619. FNoteShown = Now();
  9620. FNoteTimer->Enabled = false;
  9621. if (Seconds == 0)
  9622. {
  9623. Seconds = WinConfiguration->NotificationsTimeout;
  9624. }
  9625. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9626. FNoteTimer->Enabled = true;
  9627. }
  9628. //---------------------------------------------------------------------------
  9629. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9630. {
  9631. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9632. }
  9633. //---------------------------------------------------------------------------
  9634. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9635. {
  9636. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9637. {
  9638. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9639. }
  9640. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9641. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9642. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9643. 0, NULL, NULL);
  9644. }
  9645. //---------------------------------------------------------------------------
  9646. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9647. {
  9648. bool NewShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9649. UnicodeString Note =
  9650. FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1), (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, (NewShowHiddenFiles ? 2 : 3))));
  9651. PostNote(Note, 0, NULL, NULL);
  9652. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9653. WinConfiguration->ShowHiddenFiles = NewShowHiddenFiles;
  9654. }
  9655. //---------------------------------------------------------------------------
  9656. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9657. {
  9658. WinConfiguration->FormatSizeBytes = Style;
  9659. }
  9660. //---------------------------------------------------------------------------
  9661. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9662. {
  9663. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9664. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9665. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9666. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9667. }
  9668. //---------------------------------------------------------------------------
  9669. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9670. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9671. {
  9672. if (Panel->Index == 0)
  9673. {
  9674. if (FOnNoteClick != NULL)
  9675. {
  9676. // prevent the user data from being freed by possible call
  9677. // to CancelNote or PostNote during call to OnNoteClick
  9678. std::unique_ptr<TObject> NoteData(FNoteData);
  9679. TNotifyEvent OnNoteClick = FOnNoteClick;
  9680. FNoteData = NULL;
  9681. // need to cancel the note as we are going to delete its user data
  9682. CancelNote(true);
  9683. OnNoteClick(NoteData.get());
  9684. }
  9685. }
  9686. if (HasActiveTerminal() &&
  9687. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9688. {
  9689. FileSystemInfo();
  9690. }
  9691. }
  9692. //---------------------------------------------------------------------------
  9693. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9694. {
  9695. // workaround:
  9696. // 1) for unknown reason, disabling window, while minimized,
  9697. // prevents it from restoring, even if it was enabled again meanwhile
  9698. // 2) when disabling the main window, while another has focus
  9699. // minimize is no longer possible
  9700. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9701. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9702. // Shouldn't we use IsApplicationMinimized() here?
  9703. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9704. {
  9705. Enabled = false;
  9706. }
  9707. FLockLevel++;
  9708. }
  9709. //---------------------------------------------------------------------------
  9710. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9711. {
  9712. DebugAssert(FLockLevel > 0);
  9713. FLockLevel--;
  9714. if (FLockLevel == 0)
  9715. {
  9716. DebugAssert(FLockSuspendLevel == 0);
  9717. Enabled = true;
  9718. // VCL_COPY (TCustomForm.SetWindowFocus)
  9719. if (Active && (ActiveControl != NULL))
  9720. {
  9721. ::SetFocus(ActiveControl->Handle);
  9722. if (GetFocus() == ActiveControl->Handle)
  9723. {
  9724. ActiveControl->Perform(CM_UIACTIVATE, 0, 0);
  9725. }
  9726. }
  9727. }
  9728. }
  9729. //---------------------------------------------------------------------------
  9730. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9731. {
  9732. // We need to make sure that window is enabled when the last modal window closes
  9733. // otherwise focus is not restored correctly.
  9734. // So we re-enable the window when modal window opens and
  9735. // disable it back after is closes
  9736. if (FLockLevel > 0)
  9737. {
  9738. // while we have nesting counter, we know that we never be called
  9739. // recursivelly as Application->OnModalBegin is called only
  9740. // for the top-level modal window
  9741. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9742. {
  9743. // won't be disabled when conditions in LockWindow() were not satisfied
  9744. FDisabledOnLockSuspend = !Enabled;
  9745. // When minimized to tray (or actually when set to SW_HIDE),
  9746. // setting Enabled makes the window focusable even when there's
  9747. // modal window over it
  9748. if (!FTrayIcon->Visible)
  9749. {
  9750. Enabled = true;
  9751. }
  9752. }
  9753. FLockSuspendLevel++;
  9754. }
  9755. }
  9756. //---------------------------------------------------------------------------
  9757. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9758. {
  9759. if (FLockSuspendLevel > 0)
  9760. {
  9761. DebugAssert(FLockLevel > 0);
  9762. FLockSuspendLevel--;
  9763. // see comment in SuspendWindowLock
  9764. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9765. {
  9766. // Note that window can be enabled here, when we were minized to tray when
  9767. // was SuspendWindowLock() called.
  9768. // We should possibly do the same check as in LockWindow(),
  9769. // if it is ever possible that the consitions change between
  9770. // SuspendWindowLock() and ResumeWindowLock()
  9771. Enabled = !FDisabledOnLockSuspend;
  9772. }
  9773. }
  9774. }
  9775. //---------------------------------------------------------------------------
  9776. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9777. {
  9778. TTBXComboBoxItem * RemotePathComboBox =
  9779. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9780. if (!TextOnly)
  9781. {
  9782. TStrings * Items = RemotePathComboBox->Strings;
  9783. Items->BeginUpdate();
  9784. try
  9785. {
  9786. Items->Clear();
  9787. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9788. {
  9789. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9790. while (!IsUnixRootPath(APath))
  9791. {
  9792. int P = APath.LastDelimiter(L'/');
  9793. DebugAssert(P >= 0);
  9794. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9795. APath.SetLength(P - 1);
  9796. }
  9797. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9798. }
  9799. }
  9800. __finally
  9801. {
  9802. Items->EndUpdate();
  9803. }
  9804. }
  9805. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9806. // Setting ItemIndex to -1 does not reset its text
  9807. if (RemotePathComboBox->Strings->Count == 0)
  9808. {
  9809. RemotePathComboBox->Text = L"";
  9810. }
  9811. }
  9812. //---------------------------------------------------------------------------
  9813. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9814. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9815. {
  9816. if (AIndex < 0)
  9817. {
  9818. AIndex = Sender->ItemIndex;
  9819. }
  9820. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9821. }
  9822. //---------------------------------------------------------------------------
  9823. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9824. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9825. int & ImageIndex)
  9826. {
  9827. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9828. }
  9829. //---------------------------------------------------------------------------
  9830. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9831. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9832. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9833. {
  9834. if (!IsLocalBrowserMode())
  9835. {
  9836. ARect.Left += (10 * AIndex);
  9837. }
  9838. }
  9839. //---------------------------------------------------------------------------
  9840. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9841. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9842. {
  9843. AWidth += (10 * AIndex);
  9844. }
  9845. //---------------------------------------------------------------------------
  9846. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9847. {
  9848. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9849. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9850. int Index = RemotePathComboBox->ItemIndex;
  9851. while (Index < RemotePathComboBox->Strings->Count - 1)
  9852. {
  9853. APath = UnixExtractFileDir(APath);
  9854. Index++;
  9855. }
  9856. // VanDyke style paths
  9857. if (APath.IsEmpty())
  9858. {
  9859. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9860. APath = ROOTDIRECTORY;
  9861. }
  9862. if (RemoteDirView->Path != APath)
  9863. {
  9864. RemoteDirView->Path = APath;
  9865. }
  9866. }
  9867. //---------------------------------------------------------------------------
  9868. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9869. {
  9870. DoRemotePathComboBoxItemClick(Sender);
  9871. }
  9872. //---------------------------------------------------------------------------
  9873. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9874. {
  9875. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9876. DebugUsedParam(Sender);
  9877. UpdateRemotePathComboBox(true);
  9878. }
  9879. //---------------------------------------------------------------------------
  9880. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9881. {
  9882. DoRemotePathComboBoxCancel(Sender);
  9883. }
  9884. //---------------------------------------------------------------------------
  9885. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9886. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9887. {
  9888. ResetIncrementalSearch();
  9889. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9890. DebugAssert(DirView != NULL);
  9891. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9892. {
  9893. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9894. // OnEditing is called also from TCustomListView::CanEdit
  9895. if (Edit != NULL)
  9896. {
  9897. EditSelectBaseName(Edit);
  9898. }
  9899. }
  9900. }
  9901. //---------------------------------------------------------------------------
  9902. //---------------------------------------------------------------------------
  9903. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9904. {
  9905. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9906. Result->AutoDetectDnD = false;
  9907. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9908. Result->RenderDataOn = rdoEnterAndDropSync;
  9909. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9910. return Result;
  9911. }
  9912. //---------------------------------------------------------------------------
  9913. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9914. {
  9915. if (IsWin10Build(19041))
  9916. {
  9917. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9918. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9919. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9920. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9921. }
  9922. }
  9923. //---------------------------------------------------------------------------
  9924. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9925. {
  9926. TForm::CreateWnd();
  9927. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9928. UpdateDarkMode();
  9929. if (FSessionsDragDropFilesEx == NULL)
  9930. {
  9931. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9932. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9933. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9934. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9935. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9936. }
  9937. if (FQueueDragDropFilesEx == NULL)
  9938. {
  9939. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9940. // No need to set OnDragOver as we do not have any restrictions
  9941. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9942. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9943. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9944. }
  9945. }
  9946. //---------------------------------------------------------------------------
  9947. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9948. {
  9949. TForm::DestroyWnd();
  9950. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9951. FQueueDragDropFilesEx->DragDropControl = NULL;
  9952. }
  9953. //---------------------------------------------------------------------------
  9954. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9955. {
  9956. SideEnter(FCurrentSide);
  9957. FEverShown = true;
  9958. }
  9959. //---------------------------------------------------------------------------
  9960. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9961. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9962. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9963. {
  9964. if (!NonVisualDataModule->Busy)
  9965. {
  9966. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9967. Configuration->Usage->Inc(L"FileFinds");
  9968. LockWindow(true);
  9969. NonVisualDataModule->StartBusy();
  9970. WinConfiguration->LockedInterface = true;
  9971. try
  9972. {
  9973. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9974. }
  9975. __finally
  9976. {
  9977. WinConfiguration->LockedInterface = false;
  9978. NonVisualDataModule->EndBusy();
  9979. UnlockWindow();
  9980. }
  9981. }
  9982. }
  9983. //---------------------------------------------------------------------------
  9984. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9985. {
  9986. if (!NonVisualDataModule->Busy)
  9987. {
  9988. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9989. SetFocus();
  9990. RemoteDirView->Path = UnixExtractFilePath(Path);
  9991. UnicodeString FileName = UnixExtractFileName(Path);
  9992. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9993. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9994. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9995. if (Item == NULL)
  9996. {
  9997. ReloadDirectory(osRemote);
  9998. Item = RemoteDirView->FindFileItem(FileName);
  9999. }
  10000. if (Item != NULL)
  10001. {
  10002. RemoteDirView->ItemFocused = Item;
  10003. RemoteDirView->ItemFocused->MakeVisible(false);
  10004. RemoteDirView->SetFocus();
  10005. }
  10006. }
  10007. }
  10008. //---------------------------------------------------------------------------
  10009. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  10010. {
  10011. bool Result = !NonVisualDataModule->Busy;
  10012. if (Result)
  10013. {
  10014. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  10015. }
  10016. return Result;
  10017. }
  10018. //---------------------------------------------------------------------------
  10019. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  10020. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10021. {
  10022. if (CanOperateOnFoundFiles(ATerminal))
  10023. {
  10024. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished, OnFileOperationFinished);
  10025. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  10026. }
  10027. }
  10028. //---------------------------------------------------------------------------
  10029. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  10030. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10031. {
  10032. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  10033. }
  10034. //---------------------------------------------------------------------------
  10035. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  10036. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10037. {
  10038. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  10039. }
  10040. //---------------------------------------------------------------------------
  10041. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  10042. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10043. {
  10044. if (CanOperateOnFoundFiles(ATerminal))
  10045. {
  10046. for (int Index = 0; Index < FileList->Count; Index++)
  10047. {
  10048. UnicodeString FileName = FileList->Strings[Index];
  10049. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  10050. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  10051. OnFileOperationFinished(osRemote, FileName, true, true);
  10052. }
  10053. }
  10054. }
  10055. //---------------------------------------------------------------------------
  10056. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  10057. {
  10058. FFileFindTerminal = Terminal;
  10059. ShowFileFindDialog(
  10060. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  10061. DoDownloadFoundFiles, DoEditFoundFiles);
  10062. }
  10063. //---------------------------------------------------------------------------
  10064. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  10065. {
  10066. FTaskbarList = TaskbarList;
  10067. }
  10068. //---------------------------------------------------------------------------
  10069. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  10070. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  10071. {
  10072. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10073. if (Index >= 0)
  10074. {
  10075. if (Button == mbLeft)
  10076. {
  10077. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  10078. // If switching tab (switching session) takes long enough for user
  10079. // to actually release the button, "mouse down" is still raised,
  10080. // but we do not get "mouse up" event, so dragging is not cancelled,
  10081. // prevent that by not beginning dragging in the first place.
  10082. int Key = ((GetSystemMetrics(SM_SWAPBUTTON) == 0) ? VK_LBUTTON : VK_RBUTTON);
  10083. if (IsKeyPressed(Key))
  10084. {
  10085. // when user clicks the "+", we get mouse down only after the session
  10086. // is closed, when new session tab is already on X:Y, so dragging
  10087. // starts, prevent that
  10088. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  10089. {
  10090. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10091. if (Terminal != NULL)
  10092. {
  10093. SessionsPageControl->BeginDrag(false);
  10094. }
  10095. }
  10096. }
  10097. }
  10098. else if (Button == mbMiddle)
  10099. {
  10100. // ignore middle-click for "New session tab" and the last local-local tab
  10101. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10102. if ((Session != NULL) && CanCloseSession(Session))
  10103. {
  10104. CloseSessionTab(Index);
  10105. }
  10106. }
  10107. }
  10108. }
  10109. //---------------------------------------------------------------------------
  10110. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  10111. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  10112. {
  10113. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10114. // do not allow dropping on the "+" tab
  10115. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10116. if ((TargetTerminal != NULL) &&
  10117. (SessionsPageControl->ActivePage->PageIndex != Index))
  10118. {
  10119. Configuration->Usage->Inc(L"SessionTabMoves");
  10120. // this is almost redundant as we would recreate tabs in SessionListChanged,
  10121. // but we want to actually prevent that to avoid flicker
  10122. SessionsPageControl->ActivePage->PageIndex = Index;
  10123. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  10124. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  10125. }
  10126. }
  10127. //---------------------------------------------------------------------------
  10128. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  10129. TObject * Sender, TObject * Source, int X, int Y,
  10130. TDragState /*State*/, bool & Accept)
  10131. {
  10132. Accept = (Sender == Source);
  10133. if (Accept)
  10134. {
  10135. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10136. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10137. // do not allow dragging to the "+" tab
  10138. Accept = (Terminal != NULL);
  10139. }
  10140. }
  10141. //---------------------------------------------------------------------------
  10142. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  10143. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  10144. {
  10145. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10146. if (Index < 0)
  10147. {
  10148. Effect = DROPEFFECT_NONE;
  10149. }
  10150. else
  10151. {
  10152. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10153. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  10154. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  10155. {
  10156. Effect = DROPEFFECT_NONE;
  10157. }
  10158. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  10159. {
  10160. Effect = DROPEFFECT_COPY;
  10161. }
  10162. }
  10163. }
  10164. //---------------------------------------------------------------------------
  10165. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  10166. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  10167. {
  10168. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10169. // do not allow dropping on local-local, disconnected and the "+" tab
  10170. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  10171. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10172. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  10173. {
  10174. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  10175. if (!IsFileControl(DropSourceControl, osRemote))
  10176. {
  10177. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  10178. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  10179. // Why don't we use Terminal->CurrentDirectory directly?
  10180. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  10181. // do not force queue, drag drop
  10182. false, true);
  10183. }
  10184. }
  10185. }
  10186. //---------------------------------------------------------------------------
  10187. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  10188. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  10189. {
  10190. // Downloads are handled in RemoteFileControlDDEnd
  10191. if (!IsFileControl(DropSourceControl, osRemote))
  10192. {
  10193. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  10194. Terminal->CurrentDirectory,
  10195. // force queue, drag drop
  10196. true, true);
  10197. }
  10198. }
  10199. //---------------------------------------------------------------------------
  10200. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  10201. {
  10202. FShowing = false;
  10203. // Do not save empty workspace
  10204. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  10205. {
  10206. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  10207. UnicodeString Name = WorkspaceName();
  10208. DoSaveWorkspace(
  10209. Name, DataList.get(),
  10210. !Configuration->DisablePasswordStoring &&
  10211. WinConfiguration->AutoSaveWorkspacePasswords, false);
  10212. WinConfiguration->LastStoredSession = Name;
  10213. }
  10214. AppLog(L"Closing main window");
  10215. }
  10216. //---------------------------------------------------------------------------
  10217. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  10218. {
  10219. TManagedTerminal * ManagedTerminal =
  10220. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  10221. if (ManagedTerminal != NULL)
  10222. {
  10223. ManagedTerminal->DirectoryLoaded = Now();
  10224. }
  10225. }
  10226. //---------------------------------------------------------------------------
  10227. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  10228. TListItem * /*Item*/, bool /*Selected*/)
  10229. {
  10230. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  10231. switch (DirView->LastSelectMethod)
  10232. {
  10233. case smKeyboard:
  10234. Configuration->Usage->Inc(L"KeyboardSelections");
  10235. break;
  10236. case smMouse:
  10237. Configuration->Usage->Inc(L"MouseSelections");
  10238. break;
  10239. }
  10240. }
  10241. //---------------------------------------------------------------------------
  10242. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  10243. {
  10244. if (Color != 0)
  10245. {
  10246. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  10247. }
  10248. else
  10249. {
  10250. return FSessionTabImageIndex;
  10251. }
  10252. }
  10253. //---------------------------------------------------------------------------
  10254. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  10255. {
  10256. TPngImageCollectionItem * Item =
  10257. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  10258. FSessionColors->AddPng(Item->PngImage);
  10259. return FSessionColors->Count - 1;
  10260. }
  10261. //---------------------------------------------------------------------------
  10262. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  10263. {
  10264. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  10265. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  10266. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  10267. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  10268. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  10269. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  10270. }
  10271. //---------------------------------------------------------------------------
  10272. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  10273. {
  10274. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  10275. }
  10276. //---------------------------------------------------------------------------
  10277. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  10278. {
  10279. switch (Side)
  10280. {
  10281. case osLocal:
  10282. return FNewLocalTabTabImageIndex;
  10283. case osRemote:
  10284. case osCurrent:
  10285. return FNewRemoteTabTabImageIndex;
  10286. default:
  10287. DebugFail();
  10288. return -1;
  10289. }
  10290. }
  10291. //---------------------------------------------------------------------------
  10292. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  10293. {
  10294. for (int Index = 0; Index < Control->ControlCount; Index++)
  10295. {
  10296. TControl * AControl = Control->Controls[Index];
  10297. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  10298. if (WinControl != NULL)
  10299. {
  10300. CollectItemsWithTextDisplayMode(WinControl);
  10301. }
  10302. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  10303. if (Toolbar != NULL)
  10304. {
  10305. // we care for top-level items only
  10306. TTBCustomItem * Items = Toolbar->Items;
  10307. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  10308. {
  10309. TTBCustomItem * Item = Items->Items[ItemIndex];
  10310. if (((Item->DisplayMode == nbdmImageAndText) ||
  10311. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  10312. EligibleForImageDisplayMode(Item))
  10313. {
  10314. FItemsWithTextDisplayMode.insert(Item);
  10315. }
  10316. }
  10317. }
  10318. }
  10319. }
  10320. //---------------------------------------------------------------------------
  10321. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  10322. {
  10323. return true;
  10324. }
  10325. //---------------------------------------------------------------------------
  10326. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  10327. {
  10328. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  10329. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  10330. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  10331. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  10332. bool Result = true;
  10333. while (Result && (i != FItemsWithTextDisplayMode.end()))
  10334. {
  10335. TTBCustomItem * Item = *i;
  10336. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  10337. if (Label != NULL)
  10338. {
  10339. // optimization
  10340. if (Label->Visible == SelectiveToolbarText)
  10341. {
  10342. Result = false;
  10343. }
  10344. else
  10345. {
  10346. Label->Visible = SelectiveToolbarText;
  10347. }
  10348. }
  10349. else
  10350. {
  10351. // optimization
  10352. if (Item->DisplayMode == DisplayMode)
  10353. {
  10354. Result = false;
  10355. }
  10356. else
  10357. {
  10358. Item->DisplayMode = DisplayMode;
  10359. }
  10360. }
  10361. ++i;
  10362. }
  10363. UpdateNewTabTab();
  10364. return Result;
  10365. }
  10366. //---------------------------------------------------------------------------
  10367. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  10368. {
  10369. DebugFail();
  10370. }
  10371. //---------------------------------------------------------------------------
  10372. bool __fastcall TCustomScpExplorerForm::IsBusy()
  10373. {
  10374. // Among other, a lock level is non zero, while directory is being loaded,
  10375. // even when it happens as a result of dirview navigation,
  10376. // i.e. when TNonVisualDataModule is NOT FBusy.
  10377. // That's why the TNonVisualDataModule::GetBusy calls this method.
  10378. // Among other this prevents a panel auto update to occur while
  10379. // directory is changing.
  10380. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  10381. }
  10382. //---------------------------------------------------------------------------
  10383. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  10384. {
  10385. // While the window is disabled, we still seem to process menu shortcuts at least,
  10386. // so stop it at least here.
  10387. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  10388. bool Result;
  10389. if (Allowed == aaUpdate)
  10390. {
  10391. Result = true;
  10392. }
  10393. else
  10394. {
  10395. Result = !NonVisualDataModule->Busy;
  10396. if (Result && (Allowed == aaShortCut))
  10397. {
  10398. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  10399. Action->Update();
  10400. Result = Action->Enabled;
  10401. }
  10402. }
  10403. return Result;
  10404. }
  10405. //---------------------------------------------------------------------------
  10406. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  10407. {
  10408. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  10409. }
  10410. //---------------------------------------------------------------------------
  10411. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  10412. {
  10413. // This is somewhat redundant to LockWindow() call from
  10414. // TTerminalManager::TerminalReadDirectoryProgress.
  10415. // But disabling window is known not to block keyboard shorcuts
  10416. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  10417. if (Busy > 0)
  10418. {
  10419. if (NonVisualDataModule->Busy)
  10420. {
  10421. State = false;
  10422. }
  10423. else
  10424. {
  10425. NonVisualDataModule->StartBusy();
  10426. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  10427. LockWindow();
  10428. }
  10429. }
  10430. else if (Busy < 0)
  10431. {
  10432. UnlockWindow();
  10433. NonVisualDataModule->EndBusy();
  10434. }
  10435. else
  10436. {
  10437. State = NonVisualDataModule->Busy;
  10438. }
  10439. }
  10440. //---------------------------------------------------------------------------
  10441. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  10442. {
  10443. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  10444. if (Index >= 0)
  10445. {
  10446. TPopupMenu * PopupMenu = NULL;
  10447. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10448. if (Session != NULL)
  10449. {
  10450. SessionsPageControl->ActivePageIndex = Index;
  10451. if (DebugAlwaysTrue(SessionTabSwitched()))
  10452. {
  10453. // copied from TControl.WMContextMenu
  10454. SendCancelMode(SessionsPageControl);
  10455. // explicit popup instead of using PopupMenu property
  10456. // to avoid menu to popup somewhere within SessionTabSwitched above,
  10457. // while connecting yet not-connected session and hence
  10458. // allowing an access to commands over not-completely connected session
  10459. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  10460. }
  10461. }
  10462. else
  10463. {
  10464. if (SupportsLocalBrowser())
  10465. {
  10466. PopupMenu = NonVisualDataModule->NewTabPopup;
  10467. }
  10468. }
  10469. if (PopupMenu != NULL)
  10470. {
  10471. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  10472. PopupMenu->PopupComponent = SessionsPageControl;
  10473. PopupMenu->Popup(Point.x, Point.y);
  10474. }
  10475. }
  10476. Handled = true;
  10477. }
  10478. //---------------------------------------------------------------------------
  10479. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  10480. {
  10481. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  10482. }
  10483. //---------------------------------------------------------------------------
  10484. void __fastcall TCustomScpExplorerForm::ChangePassword()
  10485. {
  10486. Configuration->Usage->Inc(L"PasswordChanges");
  10487. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  10488. ChangePasswordData->DisableAuthentationsExceptPassword();
  10489. ChangePasswordData->ChangePassword = true;
  10490. std::unique_ptr<TTerminal> ChangePasswordSession(
  10491. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10492. ChangePasswordSession->AutoReadDirectory = false;
  10493. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10494. {
  10495. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10496. }
  10497. else
  10498. {
  10499. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10500. }
  10501. }
  10502. //---------------------------------------------------------------------------
  10503. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10504. {
  10505. // No nice way to assert SSH2
  10506. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10507. }
  10508. //---------------------------------------------------------------------------
  10509. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10510. {
  10511. TOperationVisualizer OperationVisualizer;
  10512. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10513. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10514. }
  10515. //---------------------------------------------------------------------------
  10516. void __fastcall TCustomScpExplorerForm::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  10517. {
  10518. DebugUsedParam(OldDPI);
  10519. DebugAssert(NewDPI == GetControlPixelsPerInch(this));
  10520. GlyphsModule->PixelsPerInch = NewDPI;
  10521. // Can be called too early when primary monitor has non-system dpi
  10522. if (FSessionColors != NULL)
  10523. {
  10524. RegenerateSessionColorsImageList();
  10525. }
  10526. UpdateTabsSize();
  10527. UpdateSessionsPageControlHeight();
  10528. QueueFileListColumnAutoSize();
  10529. }
  10530. //---------------------------------------------------------------------------
  10531. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10532. {
  10533. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10534. }
  10535. //---------------------------------------------------------------------
  10536. class TPublicControl : public TControl
  10537. {
  10538. friend class TCustomScpExplorerForm;
  10539. };
  10540. //---------------------------------------------------------------------------
  10541. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10542. {
  10543. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10544. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10545. }
  10546. //---------------------------------------------------------------------------
  10547. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10548. {
  10549. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10550. OpenBookmark(Side, Bookmark);
  10551. }
  10552. //---------------------------------------------------------------------------
  10553. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10554. {
  10555. DoBookmarkClick(osLocal, Sender);
  10556. }
  10557. //---------------------------------------------------------------------------
  10558. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10559. {
  10560. DoBookmarkClick(osRemote, Sender);
  10561. }
  10562. //---------------------------------------------------------------------------
  10563. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10564. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10565. {
  10566. if (BookmarkList != NULL)
  10567. {
  10568. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10569. if (IsLocalBrowserMode())
  10570. {
  10571. Side = osLocal;
  10572. }
  10573. if (!WinConfiguration->UseLocationProfiles)
  10574. {
  10575. std::unique_ptr<TStringList> Directories(new TStringList());
  10576. Directories->CaseSensitive = (Side == osRemote);
  10577. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10578. {
  10579. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10580. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10581. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10582. {
  10583. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10584. Item->Caption = EscapeHotkey(Directory);
  10585. Item->ShortCut = Bookmark->ShortCut;
  10586. Item->OnClick = OnBookmarkClick;
  10587. Item->Tag = reinterpret_cast<int>(Bookmark);
  10588. Directories->Add(Directory);
  10589. Menu->Add(Item.release());
  10590. }
  10591. }
  10592. }
  10593. else
  10594. {
  10595. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10596. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10597. {
  10598. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10599. if (!Bookmark->Node.IsEmpty())
  10600. {
  10601. Folders->Add(Bookmark->Node);
  10602. }
  10603. }
  10604. for (int Index = 0; Index < Folders->Count; Index++)
  10605. {
  10606. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10607. Item->Caption = Folders->Strings[Index];
  10608. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10609. Folders->Objects[Index] = Item.get();
  10610. Menu->Add(Item.release());
  10611. }
  10612. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10613. {
  10614. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10615. TTBCustomItem * Parent;
  10616. if (!Bookmark->Node.IsEmpty())
  10617. {
  10618. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10619. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10620. }
  10621. else
  10622. {
  10623. Parent = Menu;
  10624. }
  10625. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10626. Item->Caption = Bookmark->Name;
  10627. Item->ShortCut = Bookmark->ShortCut;
  10628. Item->OnClick = OnBookmarkClick;
  10629. Item->Tag = reinterpret_cast<int>(Bookmark);
  10630. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10631. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10632. {
  10633. // No hint for location profiles that are actually mere "bookmarks"
  10634. }
  10635. else
  10636. {
  10637. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10638. UnicodeString LongHint;
  10639. if (!Bookmark->Local.IsEmpty())
  10640. {
  10641. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10642. }
  10643. if (!Bookmark->Remote.IsEmpty())
  10644. {
  10645. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10646. }
  10647. AddToList(Hint, LongHint, L"|");
  10648. Item->Hint = Hint;
  10649. }
  10650. Parent->Add(Item.release());
  10651. }
  10652. }
  10653. AddMenuSeparator(Menu);
  10654. }
  10655. }
  10656. //---------------------------------------------------------------------------
  10657. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10658. {
  10659. Menu->Clear();
  10660. std::unique_ptr<TTBCustomItem> Item;
  10661. Item.reset(new TTBXItem(Owner));
  10662. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10663. Item->Options = Item->Options << tboDefault;
  10664. Menu->Add(Item.release());
  10665. AddMenuSeparator(Menu);
  10666. if (Terminal != NULL)
  10667. {
  10668. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10669. }
  10670. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10671. Item.reset(new TTBXItem(Owner));
  10672. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10673. Menu->Add(Item.release());
  10674. }
  10675. //---------------------------------------------------------------------------
  10676. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10677. {
  10678. bool Result = true;
  10679. bool Remote = !IsSideLocalBrowser(Side);
  10680. try
  10681. {
  10682. UnicodeString APath = Path;
  10683. if (Remote)
  10684. {
  10685. Terminal->ExceptionOnFail = true;
  10686. }
  10687. else
  10688. {
  10689. APath = ExpandEnvironmentVariables(Path);
  10690. }
  10691. try
  10692. {
  10693. DirView(Side)->Path = APath;
  10694. }
  10695. __finally
  10696. {
  10697. if (Remote)
  10698. {
  10699. Terminal->ExceptionOnFail = false;
  10700. }
  10701. }
  10702. }
  10703. catch (Exception & E)
  10704. {
  10705. if (!Remote || Terminal->Active)
  10706. {
  10707. ShowExtendedExceptionEx(Terminal, &E);
  10708. Result = false;
  10709. }
  10710. else
  10711. {
  10712. throw;
  10713. }
  10714. }
  10715. return Result;
  10716. }
  10717. //---------------------------------------------------------------------------
  10718. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10719. {
  10720. // Make sure there some feedback even when loading tiny local folders
  10721. TInstantOperationVisualizer Visualizer;
  10722. DirView(Side)->ReloadDirectory();
  10723. }
  10724. //---------------------------------------------------------------------------
  10725. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10726. {
  10727. if (Index == SessionsPageControl->TabIndex)
  10728. {
  10729. CloseTab();
  10730. }
  10731. else
  10732. {
  10733. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10734. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10735. TTerminalManager * Manager = TTerminalManager::Instance();
  10736. if (!Terminal->Active)
  10737. {
  10738. Manager->FreeTerminal(Terminal);
  10739. }
  10740. else
  10741. {
  10742. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10743. if (CanCloseQueue(Queue))
  10744. {
  10745. Manager->FreeTerminal(Terminal);
  10746. }
  10747. }
  10748. }
  10749. }
  10750. //---------------------------------------------------------------------------
  10751. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10752. {
  10753. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10754. if (Session == NULL)
  10755. {
  10756. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10757. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10758. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10759. //P = SessionsPageControl->ClientToScreen(P);
  10760. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10761. }
  10762. else
  10763. {
  10764. CloseSessionTab(Index);
  10765. }
  10766. }
  10767. //---------------------------------------------------------------------------
  10768. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10769. {
  10770. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10771. {
  10772. TInstantOperationVisualizer Visualizer;
  10773. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10774. // before we create a new data object
  10775. ClipboardClear();
  10776. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10777. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10778. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10779. // Intermediate variable to WORKAROUND a crash in compiler
  10780. TObjectList * ClipboardFakeMonitors =
  10781. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10782. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10783. if (FClipboardDragDropFilesEx.get() == NULL)
  10784. {
  10785. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10786. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10787. }
  10788. FClipboardDragDropFilesEx->FileList->Clear();
  10789. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10790. FClipboardDragDropFilesEx->CopyToClipboard();
  10791. FClipboardTerminal = Terminal;
  10792. // Need full paths, as cwd can be different once files are pasted
  10793. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10794. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10795. {
  10796. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10797. }
  10798. AppLogFmt(L"Created fake clipboard directory \"%s\" and started drive monitors", (FClipboardFakeDirectory));
  10799. }
  10800. }
  10801. //---------------------------------------------------------------------------
  10802. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10803. {
  10804. if (OpenClipboard(0))
  10805. {
  10806. AppLog(L"Clearing clipboard");
  10807. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10808. CloseClipboard();
  10809. }
  10810. }
  10811. //---------------------------------------------------------------------------
  10812. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10813. {
  10814. return !FClipboardFakeDirectory.IsEmpty();
  10815. }
  10816. //---------------------------------------------------------------------------
  10817. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10818. {
  10819. bool Deleted = RemoveDir(ApiPath(FClipboardFakeDirectory));
  10820. AppLogFmt(L"Clearing clipboard, deleted clipboard temporary folder \"%s\" - %d", (FClipboardFakeDirectory, int(Deleted)));
  10821. FClipboardFakeDirectory = UnicodeString();
  10822. FClipboardTerminal = NULL;
  10823. if (FDownloadingFromClipboard)
  10824. {
  10825. // We are called by the monitor, so attempt to release it would deadlock
  10826. FClipboardFakeMonitorsPendingReset = true;
  10827. }
  10828. else
  10829. {
  10830. FClipboardFakeMonitors.reset(NULL);
  10831. }
  10832. }
  10833. //---------------------------------------------------------------------------
  10834. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10835. {
  10836. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10837. {
  10838. ClipboardStop();
  10839. }
  10840. }
  10841. //---------------------------------------------------------------------------
  10842. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10843. {
  10844. TTerminalManager * Manager = TTerminalManager::Instance();
  10845. Manager->ActiveSession = FClipboardTerminal;
  10846. TTransferOperationParam Params;
  10847. Params.TargetDirectory = TargetDirectory;
  10848. Params.DragDrop = DragDrop;
  10849. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10850. }
  10851. //---------------------------------------------------------------------------
  10852. void TCustomScpExplorerForm::PasteFiles()
  10853. {
  10854. // Guard against possible race conditions
  10855. if (!FClipboardPasteTarget.IsEmpty())
  10856. {
  10857. // ClipboardFakeCreated might be called while we are here, so make sure we finish operating on the same path we started with
  10858. UnicodeString Target = FClipboardPasteTarget;
  10859. FClipboardPasteTarget = EmptyStr;
  10860. // Can fail as it can be e.g. locked by AV, so we retry that later
  10861. bool Removed = RemoveDir(ApiPath(Target));
  10862. AppLogFmt(L"First attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10863. try
  10864. {
  10865. if (NonVisualDataModule->Busy)
  10866. {
  10867. AppLog(L"Is busy, cannot paste");
  10868. }
  10869. else
  10870. {
  10871. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10872. FClipboardFakeMonitorsPendingReset = false;
  10873. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10874. TAutoFlag Flag(FDownloadingFromClipboard);
  10875. AppLog(L"Downloading to paste target...");
  10876. ClipboardDownload(ExtractFilePath(Target), NoConfirmation, true);
  10877. AppLog(L"Downloaded to paste target...");
  10878. }
  10879. }
  10880. __finally
  10881. {
  10882. if (!Removed)
  10883. {
  10884. Removed = RemoveDir(ApiPath(Target));
  10885. AppLogFmt(L"Second attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10886. }
  10887. }
  10888. }
  10889. }
  10890. //---------------------------------------------------------------------------
  10891. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10892. {
  10893. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10894. // (as it pumps a Windows message queue while being shutted down)
  10895. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10896. // Is can happen that creation of our temporary directory is detected (even though we are creating it before starting the monitors).
  10897. // It tent do happen with later copy-pastes, probably because everything is cached already and monitors start quickly.
  10898. !IsPathToSameFile(FClipboardFakeDirectory, FileName) &&
  10899. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10900. {
  10901. AppLogFmt(L"Fake clipboard directory pasted to \"%s\"", (FileName));
  10902. FClipboardPasteTarget = FileName;
  10903. // Particularly when pasting to external HDD, the fake directory is strangely recreated if removed here in the monitor callback.
  10904. // Postponing removing (or actually whole pasting operation) seems to help.
  10905. PostMessage(Handle, WM_PASTE_FILES, 0, 0);
  10906. }
  10907. }
  10908. //---------------------------------------------------------------------------
  10909. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10910. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10911. {
  10912. TFileMasks::TParams MaskParams;
  10913. MaskParams.Size = Size;
  10914. MaskParams.Modification = Modification;
  10915. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10916. bool Local = (dynamic_cast<TUnixDirView *>(DirView) == NULL);
  10917. // TUnixDirView::ItemFullFileName returns trailing backslash for directories, what filemask cannot deal with
  10918. if (!Local && Directory)
  10919. {
  10920. FileName = UnixExcludeTrailingBackslash(FileName);
  10921. }
  10922. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10923. {
  10924. bool ImplicitMatch;
  10925. if (Iter->FileMask.Matches(FileName, Local, Directory, &MaskParams, false, ImplicitMatch) &&
  10926. !ImplicitMatch)
  10927. {
  10928. Color = Iter->Color;
  10929. break;
  10930. }
  10931. }
  10932. }
  10933. //---------------------------------------------------------------------------
  10934. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10935. {
  10936. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10937. if (!DirView->IsEditing())
  10938. {
  10939. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10940. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10941. // while searching
  10942. if (Key == VK_BACK)
  10943. {
  10944. if (FIncrementalSearchState.Searching)
  10945. {
  10946. if (FIncrementalSearchState.Text.Length() <= 1)
  10947. {
  10948. ResetIncrementalSearch();
  10949. }
  10950. else
  10951. {
  10952. UnicodeString NewText = LeftStr(FIncrementalSearchState.Text, FIncrementalSearchState.Text.Length() - 1);
  10953. IncrementalSearch(NewText, false, false);
  10954. }
  10955. Key = 0;
  10956. }
  10957. }
  10958. }
  10959. }
  10960. //---------------------------------------------------------------------------
  10961. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10962. {
  10963. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10964. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10965. {
  10966. // Filter control sequences.
  10967. // When not searching yet, prefer use of the space for toggling file selection
  10968. // (so we cannot incrementally search for a string starting with a space).
  10969. if ((Key > VK_SPACE) ||
  10970. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearchState.Searching))
  10971. {
  10972. IncrementalSearch(FIncrementalSearchState.Text + Key, false, false);
  10973. Key = 0;
  10974. }
  10975. }
  10976. }
  10977. //---------------------------------------------------------------------------
  10978. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10979. {
  10980. if (FIncrementalSearchState.Searching)
  10981. {
  10982. FIncrementalSearchState.Reset();
  10983. DirView(osCurrent)->UpdateStatusBar();
  10984. }
  10985. }
  10986. //---------------------------------------------------------------------------
  10987. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10988. {
  10989. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10990. if (Item == NULL)
  10991. {
  10992. MessageBeep(MB_ICONHAND);
  10993. }
  10994. else
  10995. {
  10996. TCustomDirView * ADirView = DirView(osCurrent);
  10997. {
  10998. TAutoNestingCounter Guard(FIncrementalSearching);
  10999. ADirView->FocusItem(Item);
  11000. if (ADirView->NortonLike == nlOff)
  11001. {
  11002. if ((ADirView->Selected != Item) ||
  11003. (ADirView->SelCount > 1))
  11004. {
  11005. ADirView->ClearSelection();
  11006. ADirView->Selected = Item;
  11007. }
  11008. }
  11009. }
  11010. FIncrementalSearchState.Searching = true;
  11011. FIncrementalSearchState.Text = Text;
  11012. Item->MakeVisible(false);
  11013. TListItem * NextItem = SearchFile(Text, true, Reverse);
  11014. FIncrementalSearchState.HaveNext = (NextItem != NULL) && (NextItem != Item);
  11015. ADirView->UpdateStatusBar();
  11016. }
  11017. }
  11018. //---------------------------------------------------------------------------
  11019. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  11020. {
  11021. int Index = Item->Index;
  11022. if (!Reverse)
  11023. {
  11024. Index++;
  11025. if (Index >= Item->Owner->Count)
  11026. {
  11027. Index = 0;
  11028. }
  11029. }
  11030. else
  11031. {
  11032. Index--;
  11033. if (Index < 0)
  11034. {
  11035. Index = Item->Owner->Count - 1;
  11036. }
  11037. }
  11038. return Item->Owner->Item[Index];
  11039. }
  11040. //---------------------------------------------------------------------------
  11041. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  11042. {
  11043. TCustomDirView * ADirView = DirView(osCurrent);
  11044. if (ADirView->Items->Count == 0)
  11045. {
  11046. return NULL;
  11047. }
  11048. else
  11049. {
  11050. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  11051. TListItem * Item = CurrentItem;
  11052. if (SkipCurrent)
  11053. {
  11054. Item = DebugNotNull(GetNextFile(Item, Reverse));
  11055. }
  11056. while (true)
  11057. {
  11058. bool Matches = false;
  11059. switch (WinConfiguration->PanelSearch)
  11060. {
  11061. case isNameStartOnly:
  11062. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item).SubString(1, Text.Length()), Text);
  11063. break;
  11064. case isName:
  11065. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item), Text);
  11066. break;
  11067. case isAll:
  11068. int ColCount = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Count : 1;
  11069. int Index = 0;
  11070. while ((Index < ColCount) && !Matches)
  11071. {
  11072. bool Visible = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Visible[Index] : true;
  11073. if (Visible)
  11074. {
  11075. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  11076. }
  11077. Index++;
  11078. }
  11079. break;
  11080. }
  11081. if (Matches)
  11082. {
  11083. return Item;
  11084. }
  11085. Item = GetNextFile(Item, Reverse);
  11086. if (Item == CurrentItem)
  11087. {
  11088. return NULL;
  11089. }
  11090. }
  11091. }
  11092. }
  11093. //---------------------------------------------------------------------------
  11094. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  11095. {
  11096. ResetIncrementalSearch();
  11097. }
  11098. //---------------------------------------------------------------------------
  11099. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  11100. {
  11101. if (Message.CharCode == VK_TAB)
  11102. {
  11103. if (!FIncrementalSearchState.Text.IsEmpty())
  11104. {
  11105. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  11106. bool Reverse = Shift.Contains(ssShift);
  11107. IncrementalSearch(FIncrementalSearchState.Text, true, Reverse);
  11108. Message.Result = 1;
  11109. return;
  11110. }
  11111. }
  11112. else if (Message.CharCode == VK_ESCAPE)
  11113. {
  11114. if (FIncrementalSearchState.Searching)
  11115. {
  11116. ResetIncrementalSearch();
  11117. Message.Result = 1;
  11118. return;
  11119. }
  11120. }
  11121. TForm::Dispatch(&Message);
  11122. }
  11123. //---------------------------------------------------------------------------
  11124. void __fastcall TCustomScpExplorerForm::Deactivate()
  11125. {
  11126. TForm::Deactivate();
  11127. // E.g. when switching to an internal editor window
  11128. ResetIncrementalSearch();
  11129. }
  11130. //---------------------------------------------------------------------------
  11131. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  11132. {
  11133. // When switching to another application
  11134. ResetIncrementalSearch();
  11135. }
  11136. //---------------------------------------------------------------------------
  11137. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  11138. {
  11139. ResetIncrementalSearch();
  11140. }
  11141. //---------------------------------------------------------------------------
  11142. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  11143. {
  11144. if (FIncrementalSearching <= 0)
  11145. {
  11146. ResetIncrementalSearch();
  11147. }
  11148. }
  11149. //---------------------------------------------------------------------------
  11150. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  11151. {
  11152. CountClicksForWindowPrint(this);
  11153. }
  11154. //---------------------------------------------------------------------------
  11155. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  11156. {
  11157. CenterReconnectToolbar();
  11158. }
  11159. //---------------------------------------------------------------------------
  11160. void TCustomScpExplorerForm::DoBrowseFile(TCustomDirView * DirView, const UnicodeString & FileName)
  11161. {
  11162. if (!FileName.IsEmpty())
  11163. {
  11164. DirView->FocusByName(FileName);
  11165. if (DirView->ItemFocused != NULL)
  11166. {
  11167. DirView->ItemFocused->Selected = true;
  11168. }
  11169. }
  11170. }
  11171. //---------------------------------------------------------------------------
  11172. void __fastcall TCustomScpExplorerForm::BrowseFile(const UnicodeString & FileName)
  11173. {
  11174. DoBrowseFile(RemoteDirView, FileName);
  11175. }
  11176. //---------------------------------------------------------------------------
  11177. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  11178. {
  11179. if (!FQueueStatusUpdating)
  11180. {
  11181. bool Refresh;
  11182. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  11183. {
  11184. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  11185. }
  11186. else
  11187. {
  11188. if (FQueueFileList->GetCount() > 0)
  11189. {
  11190. FQueueFileList->Clear();
  11191. Refresh = true;
  11192. }
  11193. }
  11194. int Count = FQueueFileList->GetCount();
  11195. if (QueueFileList->Items->Count != Count)
  11196. {
  11197. DebugAssert(Refresh);
  11198. QueueFileList->Items->Count = Count;
  11199. }
  11200. if (Refresh)
  11201. {
  11202. QueueFileList->Invalidate();
  11203. }
  11204. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  11205. }
  11206. }
  11207. //---------------------------------------------------------------------------
  11208. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  11209. {
  11210. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  11211. }
  11212. //---------------------------------------------------------------------------
  11213. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  11214. {
  11215. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  11216. // See TSynchronizeChecklistDialog::UpdateTimer
  11217. if (QueueFileList->Items->Count > 0)
  11218. {
  11219. QueueFileList->Items->Item[0]->MakeVisible(false);
  11220. }
  11221. UpdateQueueFileList();
  11222. }
  11223. //---------------------------------------------------------------------------
  11224. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  11225. {
  11226. Active = QueueView3->Focused() || QueueFileList->Focused();
  11227. }
  11228. //---------------------------------------------------------------------------
  11229. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  11230. {
  11231. QueueLabelUpdateStatus();
  11232. }
  11233. //---------------------------------------------------------------------------
  11234. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  11235. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  11236. {
  11237. int State = FQueueFileList->GetState(Item->Index);
  11238. if (State == qfsProcessed)
  11239. {
  11240. Sender->Canvas->Font->Color = clGrayText;
  11241. }
  11242. }
  11243. //---------------------------------------------------------------------------
  11244. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  11245. {
  11246. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  11247. QueueFileList->Column[0]->Width =
  11248. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  11249. }
  11250. //---------------------------------------------------------------------------
  11251. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  11252. {
  11253. QueueFileListColumnAutoSize();
  11254. }
  11255. //---------------------------------------------------------------------------
  11256. void __fastcall TCustomScpExplorerForm::CloseApp()
  11257. {
  11258. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  11259. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  11260. // So we clear the flag here.
  11261. DebugAssert(NonVisualDataModule->Busy);
  11262. NonVisualDataModule->EndBusy();
  11263. try
  11264. {
  11265. Close();
  11266. }
  11267. __finally
  11268. {
  11269. NonVisualDataModule->StartBusy();
  11270. }
  11271. }
  11272. //---------------------------------------------------------------------------
  11273. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  11274. {
  11275. return (Terminal != NULL) && Terminal->Active;
  11276. }
  11277. //---------------------------------------------------------------------------
  11278. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  11279. {
  11280. return (ManagedSession != NULL);
  11281. }
  11282. //---------------------------------------------------------------------------
  11283. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  11284. {
  11285. return IsActiveTerminal(Terminal);
  11286. }
  11287. //---------------------------------------------------------------------------
  11288. void TCustomScpExplorerForm::LocalLocalCopy(
  11289. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  11290. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  11291. {
  11292. DebugFail();
  11293. }
  11294. //---------------------------------------------------------------------------
  11295. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  11296. {
  11297. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  11298. }
  11299. //---------------------------------------------------------------------------
  11300. void TCustomScpExplorerForm::UpdateTabsSize()
  11301. {
  11302. // 1) Changing tab list triggers the OnResize.
  11303. // 2) Is called in TForm constructor, when we are not ready to call SessionListChanged (particularly when starting with colored session)
  11304. if (!FUpdatingSessionTabs && (FSessionColors != NULL))
  11305. {
  11306. // UpdateTabsCaptionTruncation should be enough
  11307. SessionListChanged(true);
  11308. }
  11309. }
  11310. //---------------------------------------------------------------------------
  11311. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  11312. {
  11313. UpdateTabsSize();
  11314. }
  11315. //---------------------------------------------------------------------------
  11316. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  11317. {
  11318. if (ASession == ManagedSession)
  11319. {
  11320. UpdateSession(ASession);
  11321. }
  11322. TSessionData * Data = ASession->StateData;
  11323. UnicodeString Result;
  11324. if (Side == osLocal)
  11325. {
  11326. Result = Data->LocalDirectory;
  11327. }
  11328. else if (DebugAlwaysTrue(Side == osOther))
  11329. {
  11330. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  11331. }
  11332. return Result;
  11333. }
  11334. //---------------------------------------------------------------------------
  11335. UnicodeString TCustomScpExplorerForm::GetTabHintSessionDetails(TManagedTerminal * ASession)
  11336. {
  11337. UnicodeString Title = TTerminalManager::Instance()->GetSessionTitle(ASession, false);
  11338. UnicodeString Result = ASession->SessionData->DefaultSessionName;
  11339. if (Title == Result)
  11340. {
  11341. Result = EmptyStr;
  11342. }
  11343. else
  11344. {
  11345. Result += L"\n";
  11346. }
  11347. return Result;
  11348. }
  11349. //---------------------------------------------------------------------------
  11350. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  11351. {
  11352. UnicodeString Result = GetTabHintSessionDetails(ASession);
  11353. if (!ASession->Active)
  11354. {
  11355. Result += LoadStr(STATUS_NOT_CONNECTED2);
  11356. }
  11357. else
  11358. {
  11359. Result += GetSessionPath(ASession, osRemote);
  11360. }
  11361. return Result;
  11362. }
  11363. //---------------------------------------------------------------------------
  11364. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  11365. {
  11366. return LoadStr(NEW_REMOTE_TAB_HINT);
  11367. }
  11368. //---------------------------------------------------------------------------
  11369. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  11370. {
  11371. if (Index >= 0)
  11372. {
  11373. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  11374. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  11375. if (TabSession == NULL)
  11376. {
  11377. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  11378. if (NewTabTabCaption != TabSheet->Caption)
  11379. {
  11380. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  11381. }
  11382. }
  11383. else
  11384. {
  11385. TTerminalManager * Manager = TTerminalManager::Instance();
  11386. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  11387. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  11388. }
  11389. }
  11390. }
  11391. //---------------------------------------------------------------------------
  11392. typedef std::vector<TListItem *> TListItemsVector;
  11393. struct TCalculateSizeOperation
  11394. {
  11395. TCalculateSizeStats Stats;
  11396. TListItemsVector ListItems;
  11397. size_t Index;
  11398. };
  11399. //---------------------------------------------------------------------------
  11400. void TCustomScpExplorerForm::CalculateDirectorySizes(TOperationSide Side)
  11401. {
  11402. TCalculateSizeOperation CalculateSizeOperation;
  11403. Side = GetSide(Side);
  11404. TCustomDirView * ADirView = DirView(Side);
  11405. bool LocalSide = IsSideLocalBrowser(Side);
  11406. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, LocalSide, NULL, true));
  11407. std::unique_ptr<TStrings> FileList(new TStringList());
  11408. for (int Index = 0; Index < AllFileList->Count; Index++)
  11409. {
  11410. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  11411. if (ADirView->ItemIsDirectory(Item))
  11412. {
  11413. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  11414. CalculateSizeOperation.ListItems.push_back(Item);
  11415. }
  11416. }
  11417. CalculateSizeOperation.Index = 0;
  11418. __int64 Size = 0;
  11419. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation, &CalculateSizeOperation);
  11420. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  11421. FOnFileOperationFinished = DirectorySizeCalculated;
  11422. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation, foCalculateSize);
  11423. TCalculatedSizes CalculatedSizes;
  11424. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  11425. if (LocalSide)
  11426. {
  11427. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, Side);
  11428. ManagedSession->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  11429. }
  11430. else
  11431. {
  11432. TCalculateSizeParams Params;
  11433. Params.Stats = &CalculateSizeOperation.Stats;
  11434. Params.UseCache = true;
  11435. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  11436. }
  11437. }
  11438. //---------------------------------------------------------------------------
  11439. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(
  11440. TOperationSide Side, const UnicodeString & FileName, bool Success, bool NotCancelled)
  11441. {
  11442. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  11443. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  11444. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  11445. // optimization
  11446. bool GotExpectedItem =
  11447. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  11448. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  11449. int Index = -1;
  11450. if (DebugAlwaysTrue(GotExpectedItem))
  11451. {
  11452. Index = FCalculateSizeOperation->Index;
  11453. FCalculateSizeOperation->Index++;
  11454. }
  11455. else
  11456. {
  11457. TListItemsVector::iterator I =
  11458. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  11459. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  11460. {
  11461. Index = I - FCalculateSizeOperation->ListItems.begin();
  11462. }
  11463. }
  11464. if (DebugAlwaysTrue(Index >= 0) && Success && NotCancelled)
  11465. {
  11466. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  11467. ADirView->SetItemCalculatedSize(Item, Size);
  11468. }
  11469. }
  11470. //---------------------------------------------------------------------------
  11471. void __fastcall TCustomScpExplorerForm::MessageDockRequestDock(TObject *, TTBCustomDockableWindow *, bool & Accept)
  11472. {
  11473. Accept = false;
  11474. }
  11475. //---------------------------------------------------------------------------
  11476. void TCustomScpExplorerForm::AutoSizeColumns(TOperationSide Side)
  11477. {
  11478. // Send Ctrl+Gray+ to the list view
  11479. TKeyboardState KeyState;
  11480. GetKeyboardState(KeyState);
  11481. TKeyboardState NewKeyState;
  11482. memset(NewKeyState, 0, sizeof(NewKeyState));
  11483. NewKeyState[VK_CONTROL] = 0x81;
  11484. SetKeyboardState(NewKeyState);
  11485. SendMessage(DirView(Side)->Handle, WM_KEYDOWN, VK_ADD, 0);
  11486. SetKeyboardState(KeyState);
  11487. }
  11488. //---------------------------------------------------------------------------
  11489. void TCustomScpExplorerForm::QueueResetLayoutColumns()
  11490. {
  11491. LoadListViewStr(QueueView3, QueueViewLayoutDefault);
  11492. }
  11493. //---------------------------------------------------------------------------
  11494. void * TCustomScpExplorerForm::SaveFocus()
  11495. {
  11496. return NULL;
  11497. }
  11498. //---------------------------------------------------------------------------
  11499. void TCustomScpExplorerForm::RestoreFocus(void * Focus)
  11500. {
  11501. DebugUsedParam(Focus);
  11502. DebugAssert(Focus == NULL);
  11503. }
  11504. //---------------------------------------------------------------------------
  11505. void TCustomScpExplorerForm::IncrementalSearchStart()
  11506. {
  11507. TCustomDirView * ADirView = DirView(osCurrent);
  11508. ADirView->SetFocus();
  11509. if (!FIncrementalSearchState.Searching)
  11510. {
  11511. FIncrementalSearchState.Searching = true;
  11512. FIncrementalSearchState.HaveNext = false;
  11513. DebugAssert(FIncrementalSearchState.Text.IsEmpty());
  11514. ADirView->UpdateStatusBar();
  11515. }
  11516. }
  11517. //---------------------------------------------------------------------------
  11518. void __fastcall TCustomScpExplorerForm::RemoteDirViewThumbnailNeeded(
  11519. TUnixDirView *, TListItem * Item, TRemoteFile * File, const TSize & Size, TBitmap *& Bitmap)
  11520. {
  11521. // though when downloading to temporary folder, encryption should not be a problem
  11522. if (Terminal->IsCapable[fcBackgroundTransfers] &&
  11523. !File->IsDirectory)
  11524. {
  11525. UnicodeString FileName = File->FullFileName;
  11526. TFileMasks::TParams MaskParams;
  11527. MaskParams.Size = File->Size;
  11528. MaskParams.Modification = File->Modification;
  11529. if ((File->Size <= static_cast<__int64>(WinConfiguration->RemoteThumbnailSizeLimit) * 1024) &&
  11530. FRemoteThumbnailMask.Matches(FileName, false, File->IsDirectory, &MaskParams))
  11531. {
  11532. Bitmap = TTerminalManager::Instance()->ThumbnailNeeded(Terminal, Item->Index, File, Size);
  11533. }
  11534. }
  11535. }
  11536. //---------------------------------------------------------------------------
  11537. TThumbnailDownloadQueueItem * TCustomScpExplorerForm::AddThumbnailDownloadQueueItem(TManagedTerminal * ATerminal)
  11538. {
  11539. DebugAssert(ATerminal == Terminal);
  11540. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  11541. TemporaryFileCopyParam(CopyParam);
  11542. CopyParam.TransferMode = tmBinary;
  11543. UnicodeString SourceDir = ATerminal->CurrentDirectory;
  11544. UnicodeString TempDir, RootTempDir;
  11545. TemporaryDirectoryForRemoteFiles(SourceDir, CopyParam, true, TempDir, RootTempDir);
  11546. TTerminalQueue * AQueue = TTerminalManager::Instance()->FindQueueForTerminal(ATerminal);
  11547. DebugAssert((Queue == NULL) || (AQueue == Queue)); // we might get here before queue is set
  11548. TThumbnailDownloadQueueItem * QueueItem =
  11549. new TThumbnailDownloadQueueItem(this, Terminal, SourceDir, TempDir, &CopyParam);
  11550. AddQueueItem(AQueue, QueueItem, ATerminal);
  11551. return QueueItem;
  11552. }
  11553. //---------------------------------------------------------------------------
  11554. enum { qccRemoteItemVisible, qccRemoteItemRedraw };
  11555. typedef std::pair<int, UnicodeString> TRemoteItemVisibleData;
  11556. //---------------------------------------------------------------------------
  11557. void TCustomScpExplorerForm::PostThumbnailVisibleQueueQuery(int Index, const UnicodeString & FileName)
  11558. {
  11559. // The queue might be destroyed before the WM_QUEUE_CALLBACK is processed
  11560. TRemoteItemVisibleData * Data = new TRemoteItemVisibleData();
  11561. Data->first = Index;
  11562. Data->second = FileName;
  11563. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemVisible, reinterpret_cast<WPARAM>(Data));
  11564. }
  11565. //---------------------------------------------------------------------------
  11566. void TCustomScpExplorerForm::PostThumbnailDrawRequest(int Index)
  11567. {
  11568. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemRedraw, Index);
  11569. }
  11570. //---------------------------------------------------------------------------
  11571. void TCustomScpExplorerForm::WMQueueCallback(TMessage & Message)
  11572. {
  11573. int Command = Message.WParam;
  11574. if (Command == qccRemoteItemVisible)
  11575. {
  11576. TRemoteItemVisibleData * Data = reinterpret_cast<TRemoteItemVisibleData *>(Message.LParam);
  11577. int Index = Data->first;
  11578. UnicodeString FileName = Data->second;
  11579. delete Data;
  11580. TGuard Guard(Terminal->ThumbnailsSection.get());
  11581. bool Visible = False;
  11582. if (Terminal->ThumbnailsEnabled &&
  11583. // though we should better also disable thumbnails once we switch to different view style
  11584. (RemoteDirView->DirViewStyle == dvsThumbnail))
  11585. {
  11586. // The message might be processed, while we are already loading a different directory
  11587. if ((Index >= 0) &&
  11588. (Index < RemoteDirView->Items->Count))
  11589. {
  11590. TListItem * Item = RemoteDirView->Items->Item[Index];
  11591. Visible =
  11592. (RemoteDirView->ItemFullFileName(Item) == FileName) &&
  11593. ListView_IsItemVisible(RemoteDirView->Handle, Index);
  11594. }
  11595. }
  11596. Terminal->ThumbnailVisible(Index, FileName, Visible);
  11597. }
  11598. else if (Command == qccRemoteItemRedraw)
  11599. {
  11600. int Index = Message.LParam;
  11601. if ((Index >= 0) &&
  11602. (Index < RemoteDirView->Items->Count))
  11603. {
  11604. RemoteDirView->InvalidateItem(RemoteDirView->Items->Item[Index]);
  11605. }
  11606. }
  11607. }
  11608. //---------------------------------------------------------------------------
  11609. void TCustomScpExplorerForm::InitializeRemoteThumbnailMask()
  11610. {
  11611. UnicodeString DefaultRemoteThumbnailMask = L"*.jpg;*.jpeg;*.gif;*.png;*.svg;*.bmp;*.raw;*.ico;*.heic;*.webp";
  11612. UnicodeString RemoteThumbnailMask = WinConfiguration->RemoteThumbnailMask;
  11613. if (RemoteThumbnailMask.IsEmpty() ||
  11614. StartsStr(L"+", RemoteThumbnailMask) || StartsStr(L"-", RemoteThumbnailMask) || StartsStr(L"*", RemoteThumbnailMask))
  11615. {
  11616. std::unique_ptr<TStrings> RemoteThumbnailMasks(new TStringList());
  11617. while (!DefaultRemoteThumbnailMask.IsEmpty())
  11618. {
  11619. RemoteThumbnailMasks->Add(CutToChar(DefaultRemoteThumbnailMask, L';', true));
  11620. }
  11621. RemoteThumbnailMasks.reset(ProcessFeatures(RemoteThumbnailMasks.get(), RemoteThumbnailMask));
  11622. RemoteThumbnailMask = EmptyStr;
  11623. for (int Index = 0; Index < RemoteThumbnailMasks->Count; Index++)
  11624. {
  11625. AddToList(RemoteThumbnailMask, RemoteThumbnailMasks->Strings[Index], L";");
  11626. }
  11627. }
  11628. FRemoteThumbnailMask.Masks = RemoteThumbnailMask;
  11629. }
  11630. //---------------------------------------------------------------------------
  11631. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartLoading(TObject *)
  11632. {
  11633. Terminal->StartLoadingDirectory();
  11634. }
  11635. //---------------------------------------------------------------------------
  11636. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartReading(TObject *)
  11637. {
  11638. Terminal->DisableThumbnails();
  11639. }
  11640. //---------------------------------------------------------------------------
  11641. void TCustomScpExplorerForm::ChangeDirViewStyle(TOperationSide Side, TDirViewStyle DirViewStyle)
  11642. {
  11643. TCustomDirView * ADirView = DirView(Side);
  11644. if (ADirView->DirViewStyle != DirViewStyle)
  11645. {
  11646. if (DirViewStyle == dvsThumbnail)
  11647. {
  11648. if (dynamic_cast<TUnixDirView *>(ADirView) != NULL)
  11649. {
  11650. Configuration->Usage->Inc(L"ThumbnailsRemote");
  11651. }
  11652. else
  11653. {
  11654. Configuration->Usage->Inc(L"ThumbnailsLocal");
  11655. }
  11656. }
  11657. ADirView->DirViewStyle = DirViewStyle;
  11658. UpdateControls();
  11659. }
  11660. }