CustomScpExplorer.cpp 413 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345
  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);
  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. bool SingleFile = false;
  1279. if (FileList->Count == 1)
  1280. {
  1281. if (Direction == tdToRemote)
  1282. {
  1283. UnicodeString FileName = FileList->Strings[0];
  1284. SingleFile = FileExists(ApiPath(FileName));
  1285. }
  1286. else
  1287. {
  1288. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1289. SingleFile = !File->IsDirectory;
  1290. }
  1291. }
  1292. TQueueItem * QueueItem;
  1293. if (Direction == tdToRemote)
  1294. {
  1295. CopyParam.IncludeFileMask.SetRoots(FileList, TargetDirectory);
  1296. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1297. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1298. }
  1299. else
  1300. {
  1301. CopyParam.IncludeFileMask.SetRoots(TargetDirectory, FileList);
  1302. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1303. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1304. }
  1305. AddQueueItem(Queue, QueueItem, Terminal);
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1309. {
  1310. if (Queue->IsEmpty)
  1311. {
  1312. Terminal->QueueOperationStart = Now();
  1313. }
  1314. Queue->AddItem(QueueItem);
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1318. {
  1319. }
  1320. //---------------------------------------------------------------------------
  1321. void __fastcall TCustomScpExplorerForm::InitControls()
  1322. {
  1323. DebugAssert(FDocks != NULL);
  1324. for (int Index = 0; Index < ComponentCount; Index++)
  1325. {
  1326. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1327. if ((Dock != NULL) && (Dock->Tag == 0))
  1328. {
  1329. FDocks->Add(Dock);
  1330. }
  1331. }
  1332. CollectItemsWithTextDisplayMode(this);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1336. {
  1337. ConfigurationChanged();
  1338. QueuePanel->Height =
  1339. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1340. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1341. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1342. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1343. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1344. QueueFileList->Height =
  1345. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1346. if (QueueFileList->Visible)
  1347. {
  1348. AdjustQueueLayout();
  1349. }
  1350. UpdateCustomCommandsToolbar();
  1351. }
  1352. //---------------------------------------------------------------------------
  1353. void __fastcall TCustomScpExplorerForm::StoreParams()
  1354. {
  1355. int APixelsPerInch = GetControlPixelsPerInch(this);
  1356. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1357. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1358. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1359. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1360. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1361. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1362. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1363. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1367. {
  1368. if (!FFormRestored)
  1369. {
  1370. FFormRestored = true;
  1371. RestoreFormParams();
  1372. }
  1373. TForm::CreateParams(Params);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1377. {
  1378. DebugAssert(FDocks != NULL);
  1379. for (int Index = 0; Index < FDocks->Count; Index++)
  1380. {
  1381. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1382. }
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1386. {
  1387. SetDockAllowDrag(true);
  1388. while (!ButtonsStr.IsEmpty())
  1389. {
  1390. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1391. UnicodeString Name = CutToChar(S, L'=', true);
  1392. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1393. {
  1394. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1395. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1396. {
  1397. while (!S.IsEmpty())
  1398. {
  1399. UnicodeString S2 = CutToChar(S, L',', true);
  1400. UnicodeString Name = CutToChar(S2, L':', true);
  1401. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1402. {
  1403. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1404. if (SameText(GetToolbarItemName(Item), Name))
  1405. {
  1406. // forward compatibility
  1407. UnicodeString S3 = CutToChar(S2, L':', true);
  1408. bool Visible = StrToIntDef(S3, 0);
  1409. Item->Visible = Visible;
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. }
  1416. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1417. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1421. {
  1422. UnicodeString Result;
  1423. SetDockAllowDrag(true);
  1424. Result = ::GetToolbarsLayoutStr(this);
  1425. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1426. return Result;
  1427. }
  1428. //---------------------------------------------------------------------------
  1429. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1430. {
  1431. UnicodeString Result;
  1432. if (Item->Action != NULL)
  1433. {
  1434. Result = Item->Action->Name;
  1435. Result = RemoveSuffix(Result, L"Action", true);
  1436. }
  1437. else
  1438. {
  1439. Result = Item->Name;
  1440. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1441. Result = RemoveSuffix(Result, L"Item", true);
  1442. }
  1443. return Result;
  1444. }
  1445. //---------------------------------------------------------------------------
  1446. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1447. {
  1448. UnicodeString Result;
  1449. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1450. {
  1451. UnicodeString ToolbarStr;
  1452. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1453. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1454. {
  1455. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1456. {
  1457. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1458. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1459. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1460. // and save the changes here only.
  1461. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1462. {
  1463. UnicodeString Name = GetToolbarItemName(Item);
  1464. DebugAssert(Name.Pos(L"TBX") == 0);
  1465. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1466. }
  1467. }
  1468. }
  1469. if (!ToolbarStr.IsEmpty())
  1470. {
  1471. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1472. }
  1473. }
  1474. return Result;
  1475. }
  1476. //---------------------------------------------------------------------------
  1477. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1478. {
  1479. DebugAssert(FProgressForm == NULL);
  1480. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1481. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1482. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1483. FProgressForm->DeleteLocalToRecycleBin =
  1484. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1485. FProgressForm->DeleteRemoteToRecycleBin =
  1486. HasActiveTerminal() &&
  1487. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1488. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1489. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1490. LockWindow();
  1491. // Actually, do not know what hides the progress once the operation finishes
  1492. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1493. SetTaskbarListProgressState(TBPF_NORMAL);
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1497. {
  1498. UnlockWindow();
  1499. SAFE_DESTROY(FProgressForm);
  1500. SetQueueProgress();
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1504. TFileOperationProgressType & ProgressData)
  1505. {
  1506. // Download to temporary local directory
  1507. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1508. {
  1509. bool Continue = true;
  1510. FPendingTempSpaceWarn = false;
  1511. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1512. if (!Continue)
  1513. {
  1514. Abort();
  1515. }
  1516. }
  1517. // operation is being executed and we still didn't show up progress form
  1518. if (ProgressData.InProgress && !FProgressForm)
  1519. {
  1520. CreateProgressForm(NULL);
  1521. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1522. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1523. }
  1524. // operation is finished (or terminated), so we hide progress form
  1525. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1526. {
  1527. DestroyProgressForm();
  1528. if (ProgressData.Operation == foCalculateSize)
  1529. {
  1530. // When calculating size before transfer, the abort caused by
  1531. // cancel flag set due to "MoveToQueue" below,
  1532. // is not propagated back to us in ExecuteFileOperation,
  1533. // as it is silently swallowed.
  1534. // So we explicitly (re)throw it here.
  1535. if (FMoveToQueue)
  1536. {
  1537. Abort();
  1538. }
  1539. }
  1540. else
  1541. {
  1542. if ((ProgressData.Cancel == csContinue) &&
  1543. !FAutoOperation)
  1544. {
  1545. OperationComplete(ProgressData.StartTime);
  1546. }
  1547. }
  1548. }
  1549. if (FProgressForm &&
  1550. // Can happen only during synchronization, when ending one of the operations
  1551. ProgressData.InProgress)
  1552. {
  1553. FProgressForm->SetProgressData(ProgressData);
  1554. DebugAssert(ProgressData.InProgress);
  1555. SetTaskbarListProgressValue(&ProgressData);
  1556. if (FProgressForm->Cancel > csContinue)
  1557. {
  1558. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1559. if (FProgressForm->Cancel == csCancelFile)
  1560. {
  1561. FProgressForm->ClearCancel();
  1562. }
  1563. // cancel cancels even the move
  1564. FMoveToQueue = false;
  1565. }
  1566. else if (FProgressForm->MoveToQueue)
  1567. {
  1568. FMoveToQueue = true;
  1569. ProgressData.SetCancelAtLeast(csCancel);
  1570. }
  1571. if ((FTransferResumeList != NULL) &&
  1572. ProgressData.InProgress &&
  1573. ProgressData.IsTransfer() &&
  1574. !ProgressData.FullFileName.IsEmpty())
  1575. {
  1576. if ((FTransferResumeList->Count == 0) ||
  1577. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1578. {
  1579. // note that we do not recognize directories from files here
  1580. FTransferResumeList->Add(ProgressData.FullFileName);
  1581. }
  1582. }
  1583. }
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1587. const TDateTime & StartTime)
  1588. {
  1589. if (GUIConfiguration->BeepOnFinish &&
  1590. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1591. {
  1592. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1593. DWORD Sound;
  1594. if (!ExtractFileExt(BeepSound).IsEmpty())
  1595. {
  1596. Sound = SND_FILENAME;
  1597. }
  1598. else
  1599. {
  1600. Sound = SND_ALIAS;
  1601. }
  1602. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1603. }
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1607. TFileOperationProgressType & ProgressData)
  1608. {
  1609. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1610. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1611. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1612. FileOperationProgress(ProgressData);
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1616. {
  1617. UnicodeString Result;
  1618. if (FProgressForm != NULL)
  1619. {
  1620. Result = FProgressForm->ProgressStr();
  1621. }
  1622. return Result;
  1623. }
  1624. //---------------------------------------------------------------------------
  1625. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1626. bool DragDrop)
  1627. {
  1628. return (!DragDrop && (DropSourceControl == NULL)) ||
  1629. (DropSourceControl == DirView(osOther));
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1633. {
  1634. TCustomDirView * ADirView = DirView(Side);
  1635. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1636. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1637. // this can happen when local drive is unplugged in the middle of the operation
  1638. if (Item != NULL)
  1639. {
  1640. if (Unselect)
  1641. {
  1642. Item->Selected = false;
  1643. }
  1644. ADirView->MakeProgressVisible(Item);
  1645. }
  1646. return Item;
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1650. TFileOperation Operation, TOperationSide Side,
  1651. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1652. TOnceDoneOperation & OnceDoneOperation)
  1653. {
  1654. if (!FAutoOperation)
  1655. {
  1656. // no selection on "/upload", form serves only as event handler
  1657. // (it is not displayed)
  1658. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1659. ((Operation == FPrimaryOperation) ||
  1660. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1661. {
  1662. TOperationSide DViewSide;
  1663. if ((FProgressSide != osCurrent) &&
  1664. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1665. {
  1666. // assume the operation is over the focused panel
  1667. DViewSide = FProgressSide;
  1668. }
  1669. else
  1670. {
  1671. DViewSide = Side;
  1672. }
  1673. if (FOnFileOperationFinished != NULL)
  1674. {
  1675. FOnFileOperationFinished(DViewSide, FileName, Success);
  1676. }
  1677. else
  1678. {
  1679. VisualiseOperationFinished(DViewSide, FileName, Success);
  1680. }
  1681. }
  1682. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1683. {
  1684. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1685. {
  1686. if (Side == osLocal)
  1687. {
  1688. Configuration->Usage->Inc(L"UploadedFiles");
  1689. }
  1690. else
  1691. {
  1692. Configuration->Usage->Inc(L"DownloadedFiles");
  1693. }
  1694. }
  1695. }
  1696. }
  1697. if (Success && (FSynchronizeController != NULL))
  1698. {
  1699. DebugAssert(!IsSideLocalBrowser(osRemote));
  1700. if (Operation == foCopy)
  1701. {
  1702. DebugAssert(Side == osLocal);
  1703. FSynchronizeController->LogOperation(soUpload, FileName);
  1704. }
  1705. else if (Operation == foDelete)
  1706. {
  1707. DebugAssert(Side == osRemote);
  1708. FSynchronizeController->LogOperation(soDelete, FileName);
  1709. }
  1710. }
  1711. if (FProgressForm)
  1712. {
  1713. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1714. }
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1718. TFileOperation Operation, TOperationSide Side,
  1719. bool Temp, const UnicodeString & FileName, Boolean Success,
  1720. TOnceDoneOperation & OnceDoneOperation)
  1721. {
  1722. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1723. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1724. OnceDoneOperation);
  1725. }
  1726. //---------------------------------------------------------------------------
  1727. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1728. {
  1729. return false;
  1730. }
  1731. //---------------------------------------------------------------------------
  1732. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1733. {
  1734. return false;
  1735. }
  1736. //---------------------------------------------------------------------------
  1737. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1738. {
  1739. return false;
  1740. }
  1741. //---------------------------------------------------------------------------
  1742. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1743. {
  1744. return NULL;
  1745. }
  1746. //---------------------------------------------------------------------------
  1747. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1748. {
  1749. DebugAssert(GetSide(Side) == osRemote);
  1750. DebugUsedParam(Side);
  1751. return RemoteDirView;
  1752. }
  1753. //---------------------------------------------------------------------------
  1754. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1755. {
  1756. DebugAssert(GetSide(Side) == osRemote);
  1757. DebugUsedParam(Side);
  1758. return RemoteDriveView;
  1759. }
  1760. //---------------------------------------------------------------------------
  1761. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1762. {
  1763. DebugAssert(GetSide(Side) == osRemote);
  1764. DebugUsedParam(Side);
  1765. return HasActiveTerminal();
  1766. }
  1767. //---------------------------------------------------------------------------
  1768. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1769. TOperationSide Side, int FilesOnly)
  1770. {
  1771. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1775. TOperationSide Side, int FilesOnly)
  1776. {
  1777. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1778. }
  1779. //---------------------------------------------------------------------------
  1780. struct THistoryItemData
  1781. {
  1782. short int Side;
  1783. short int Index;
  1784. };
  1785. //---------------------------------------------------------------------------
  1786. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1787. {
  1788. DirView(Side)->HistoryGo(Index);
  1789. }
  1790. //---------------------------------------------------------------------------
  1791. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1792. {
  1793. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1794. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1795. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1796. }
  1797. //---------------------------------------------------------------------------
  1798. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1799. bool Back)
  1800. {
  1801. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1802. {
  1803. TCustomDirView * DView = DirView(Side);
  1804. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1805. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1806. if (ICount > 10)
  1807. {
  1808. ICount = 10;
  1809. }
  1810. Menu->Items->Clear();
  1811. THistoryItemData Data;
  1812. Data.Side = Side;
  1813. for (short int i = 1; i <= ICount; i++)
  1814. {
  1815. TTBCustomItem * Item = new TTBXItem(Menu);
  1816. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1817. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1818. Item->Hint = DView->HistoryPath[Data.Index];
  1819. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1820. Item->Tag = *reinterpret_cast<int*>(&Data);
  1821. Item->OnClick = HistoryItemClick;
  1822. Menu->Items->Add(Item);
  1823. }
  1824. }
  1825. }
  1826. //---------------------------------------------------------------------------
  1827. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1828. TOperationSide Side, bool Back)
  1829. {
  1830. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1831. {
  1832. // workaround
  1833. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1834. // operator new allocates memory in Pascal code, but calls inline
  1835. // constructor in C++, leading in problems, the function does
  1836. // both in Pascal code
  1837. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1838. UpdateHistoryMenu(Side, Back);
  1839. }
  1840. return FHistoryMenu[Side == osLocal][Back];
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1844. TCustomDirView *Sender)
  1845. {
  1846. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1847. UpdateHistoryMenu(Side, true);
  1848. UpdateHistoryMenu(Side, false);
  1849. }
  1850. //---------------------------------------------------------------------------
  1851. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1852. {
  1853. // remote custom commands can be executed only if the server supports shell commands
  1854. // or have secondary shell
  1855. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1856. }
  1857. //---------------------------------------------------------------------------
  1858. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1859. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1860. {
  1861. // -1 = hidden, 0 = disabled, 1 = enabled
  1862. int Result;
  1863. TFileCustomCommand RemoteCustomCommand;
  1864. TLocalCustomCommand LocalCustomCommand;
  1865. TFileCustomCommand * NonInteractiveCustomCommand =
  1866. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1867. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1868. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1869. if (FLAGCLEAR(Command.Params, ccLocal))
  1870. {
  1871. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1872. // custom command that does not operate with files can be executed anytime ...
  1873. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1874. {
  1875. // ... but do not show such command in remote file menu
  1876. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1877. {
  1878. Result = AllowedState;
  1879. }
  1880. else
  1881. {
  1882. Result = -1;
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1888. {
  1889. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1890. }
  1891. else
  1892. {
  1893. Result = -1;
  1894. }
  1895. }
  1896. }
  1897. else
  1898. {
  1899. // custom command that does not operate with files can be executed anytime
  1900. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1901. {
  1902. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1903. }
  1904. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1905. {
  1906. if ((ListType == ccltAll) || (ListType == ccltFile))
  1907. {
  1908. // special case is "diff"-style command that can be executed over any side,
  1909. // if we have both sides
  1910. Result =
  1911. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1912. // directly (instead of EnableSelectedOperation) to pass
  1913. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1914. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1915. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1916. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1917. }
  1918. else if (ListType == ccltBoth)
  1919. {
  1920. DebugAssert(!IsLocalBrowserMode());
  1921. Result = 1;
  1922. }
  1923. else
  1924. {
  1925. Result = -1;
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if ((ListType == ccltAll) ||
  1931. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1932. {
  1933. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1934. }
  1935. else
  1936. {
  1937. Result = -1;
  1938. }
  1939. }
  1940. if ((Result > 0) &&
  1941. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1942. !HasActiveTerminal())
  1943. {
  1944. Result = 0;
  1945. }
  1946. }
  1947. return Result;
  1948. }
  1949. //---------------------------------------------------------------------------
  1950. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1951. TStrings * FileList, const TCustomCommandType & ACommand,
  1952. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1953. {
  1954. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1955. {
  1956. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1957. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1958. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1959. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1960. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1961. bool Capture =
  1962. FLAGSET(ACommand.Params, ccShowResults) ||
  1963. FLAGSET(ACommand.Params, ccCopyResults) ||
  1964. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1965. TCaptureOutputEvent OutputEvent = NULL;
  1966. DebugAssert(FCapturedLog == NULL);
  1967. if (Capture)
  1968. {
  1969. FCapturedLog = new TStringList();
  1970. OutputEvent = TerminalCaptureLog;
  1971. }
  1972. try
  1973. {
  1974. if (!RemoteCustomCommand.IsFileCommand(Command))
  1975. {
  1976. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1977. OutputEvent);
  1978. }
  1979. else
  1980. {
  1981. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1982. }
  1983. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1984. {
  1985. if (FLAGSET(ACommand.Params, ccCopyResults))
  1986. {
  1987. CopyToClipboard(FCapturedLog);
  1988. }
  1989. if (FLAGSET(ACommand.Params, ccShowResults))
  1990. {
  1991. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1992. }
  1993. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1994. {
  1995. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1996. }
  1997. }
  1998. }
  1999. __finally
  2000. {
  2001. SAFE_DESTROY(FCapturedLog);
  2002. }
  2003. }
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  2007. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  2008. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  2009. {
  2010. DebugAssert(!IsLocalBrowserMode());
  2011. TStrings * LocalFileList = NULL;
  2012. TStrings * RemoteFileList = NULL;
  2013. TStrings * RemoteFileListFull = NULL;
  2014. try
  2015. {
  2016. if (LocalFileCommand)
  2017. {
  2018. if (ALocalFileList == NULL)
  2019. {
  2020. DebugAssert(HasDirView[osLocal]);
  2021. // Cannot have focus on both panels, so we have to call AnyFileSelected
  2022. // directly (instead of EnableSelectedOperation) to pass
  2023. // false to FocusedFileOnlyWhenFocused
  2024. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  2025. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  2026. }
  2027. else
  2028. {
  2029. LocalFileList = ALocalFileList;
  2030. }
  2031. if (FileListCommand)
  2032. {
  2033. if (LocalFileList->Count != 1)
  2034. {
  2035. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  2036. }
  2037. }
  2038. else
  2039. {
  2040. if ((LocalFileList->Count != 1) &&
  2041. (FileList->Count != 1) &&
  2042. (LocalFileList->Count != FileList->Count))
  2043. {
  2044. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  2045. }
  2046. }
  2047. }
  2048. UnicodeString RootTempDir;
  2049. UnicodeString TempDir;
  2050. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  2051. if (!RemoteFiles)
  2052. {
  2053. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, true, true);
  2054. }
  2055. try
  2056. {
  2057. TDateTimes RemoteFileTimes;
  2058. if (RemoteFiles)
  2059. {
  2060. RemoteFileList = FileList;
  2061. }
  2062. else
  2063. {
  2064. RemoteFileList = new TStringList();
  2065. TMakeLocalFileListParams MakeFileListParam;
  2066. MakeFileListParam.FileList = RemoteFileList;
  2067. MakeFileListParam.FileTimes = &RemoteFileTimes;
  2068. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2069. MakeFileListParam.Recursive =
  2070. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  2071. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2072. if (!MakeFileListParam.Recursive)
  2073. {
  2074. RemoteFileTimes.clear();
  2075. RemoteFileListFull = new TStringList();
  2076. MakeFileListParam.FileList = RemoteFileListFull;
  2077. MakeFileListParam.Recursive = true;
  2078. MakeFileListParam.IncludeDirs = false;
  2079. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2080. }
  2081. else
  2082. {
  2083. RemoteFileListFull = RemoteFileList;
  2084. }
  2085. }
  2086. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  2087. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2088. if (!NonBlocking)
  2089. {
  2090. int Count;
  2091. if (FileListCommand)
  2092. {
  2093. Count = 1;
  2094. }
  2095. else if (LocalFileCommand)
  2096. {
  2097. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  2098. }
  2099. else
  2100. {
  2101. Count = RemoteFileList->Count;
  2102. }
  2103. Progress.Start(foCustomCommand, osRemote, Count);
  2104. DebugAssert(FProgressForm != NULL);
  2105. FProgressForm->ReadOnly = true;
  2106. }
  2107. try
  2108. {
  2109. if (FileListCommand)
  2110. {
  2111. UnicodeString LocalFile;
  2112. // MakeFileList does not delimit filenames
  2113. UnicodeString FileList = MakeFileList(RemoteFileList);
  2114. if (LocalFileCommand)
  2115. {
  2116. DebugAssert(LocalFileList->Count == 1);
  2117. LocalFile = LocalFileList->Strings[0];
  2118. }
  2119. TLocalCustomCommand CustomCommand(Data,
  2120. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  2121. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2122. if (NonBlocking)
  2123. {
  2124. DebugAssert(!POutput);
  2125. ExecuteShellChecked(ShellCommand);
  2126. }
  2127. else
  2128. {
  2129. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2130. }
  2131. }
  2132. else if (LocalFileCommand)
  2133. {
  2134. if (LocalFileList->Count == 1)
  2135. {
  2136. UnicodeString LocalFile = LocalFileList->Strings[0];
  2137. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2138. {
  2139. UnicodeString FileName = RemoteFileList->Strings[Index];
  2140. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2141. Progress.SetFile(FileNameForProgress);
  2142. TLocalCustomCommand CustomCommand(Data,
  2143. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2144. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2145. TOnceDoneOperation OnceDoneOperation;
  2146. // Do not unselect anything, as it won't work with two panels anyway
  2147. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2148. }
  2149. }
  2150. else if (RemoteFileList->Count == 1)
  2151. {
  2152. UnicodeString FileName = RemoteFileList->Strings[0];
  2153. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2154. {
  2155. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2156. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2157. Progress.SetFile(LocalFileNameOnly);
  2158. TLocalCustomCommand CustomCommand(
  2159. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2160. FileName, LocalFileName, L"");
  2161. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2162. TOnceDoneOperation OnceDoneOperation;
  2163. // Do not unselect anything, as it won't work with two panels anyway
  2164. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2165. }
  2166. }
  2167. else
  2168. {
  2169. if (LocalFileList->Count != RemoteFileList->Count)
  2170. {
  2171. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2172. }
  2173. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2174. {
  2175. UnicodeString FileName = RemoteFileList->Strings[Index];
  2176. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2177. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2178. Progress.SetFile(LocalFileNameOnly); // sic
  2179. TLocalCustomCommand CustomCommand(
  2180. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2181. FileName, LocalFileName, L"");
  2182. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2183. TOnceDoneOperation OnceDoneOperation;
  2184. // Do not unselect anything, as it won't work with two panels anyway
  2185. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2186. }
  2187. }
  2188. }
  2189. else
  2190. {
  2191. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2192. {
  2193. UnicodeString FileName = RemoteFileList->Strings[Index];
  2194. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2195. Progress.SetFile(FileNameForProgress);
  2196. TLocalCustomCommand CustomCommand(Data,
  2197. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2198. FileName, L"", L"");
  2199. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2200. TOnceDoneOperation OnceDoneOperation;
  2201. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2202. }
  2203. }
  2204. }
  2205. __finally
  2206. {
  2207. if (!NonBlocking)
  2208. {
  2209. Progress.Stop();
  2210. }
  2211. }
  2212. DebugAssert(!FAutoOperation);
  2213. if (!RemoteFiles)
  2214. {
  2215. TempDir = IncludeTrailingBackslash(TempDir);
  2216. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2217. {
  2218. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2219. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2220. // Skip directories, process only nested files.
  2221. // The check is redundant as FileAge fails for directories anyway.
  2222. !DirectoryExists(FileName))
  2223. {
  2224. UnicodeString RemoteDir =
  2225. UnixExtractFileDir(
  2226. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2227. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2228. TSearchRecSmart SearchRec;
  2229. if (FileSearchRec(FileName, SearchRec) &&
  2230. (SearchRec.GetLastWriteTime() != RemoteFileTimes[Index]))
  2231. {
  2232. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2233. TemporaryFileCopyParam(CopyParam);
  2234. CopyParam.FileMask = L"";
  2235. FAutoOperation = true;
  2236. FMoveToQueue = false;
  2237. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2238. TemporaryFilesList->Add(FileName);
  2239. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2240. }
  2241. }
  2242. }
  2243. }
  2244. }
  2245. __finally
  2246. {
  2247. FAutoOperation = false;
  2248. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2249. {
  2250. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  2251. }
  2252. }
  2253. }
  2254. __finally
  2255. {
  2256. if (RemoteFileList != FileList)
  2257. {
  2258. delete RemoteFileList;
  2259. }
  2260. if (LocalFileList != ALocalFileList)
  2261. {
  2262. delete LocalFileList;
  2263. }
  2264. if (RemoteFileListFull != RemoteFileList)
  2265. {
  2266. delete RemoteFileListFull;
  2267. }
  2268. }
  2269. }
  2270. //---------------------------------------------------------------------------
  2271. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2272. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2273. bool FileListCommand, UnicodeString * POutput)
  2274. {
  2275. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2276. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2277. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2278. {
  2279. UnicodeString FileName = SelectedFileList->Strings[Index];
  2280. if (DirectoryExists(FileName))
  2281. {
  2282. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2283. {
  2284. LocalFileList->Add(FileName);
  2285. }
  2286. if (FLAGSET(ACommand.Params, ccRecursive))
  2287. {
  2288. TMakeLocalFileListParams MakeFileListParam;
  2289. MakeFileListParam.FileList = LocalFileList.get();
  2290. MakeFileListParam.FileTimes = NULL;
  2291. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2292. MakeFileListParam.Recursive = true;
  2293. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2294. }
  2295. }
  2296. else
  2297. {
  2298. LocalFileList->Add(FileName);
  2299. }
  2300. }
  2301. UnicodeString RemotePath;
  2302. if (Terminal != NULL)
  2303. {
  2304. RemotePath = Terminal->CurrentDirectory;
  2305. }
  2306. if (FileListCommand)
  2307. {
  2308. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2309. TLocalCustomCommand CustomCommand(
  2310. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2311. L"", L"", FileList);
  2312. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2313. }
  2314. else
  2315. {
  2316. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2317. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2318. DebugAssert(FProgressForm != NULL);
  2319. FProgressForm->ReadOnly = true;
  2320. try
  2321. {
  2322. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2323. {
  2324. UnicodeString FileName = LocalFileList->Strings[Index];
  2325. Progress.SetFile(FileName);
  2326. TLocalCustomCommand CustomCommand(
  2327. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2328. FileName, L"", L"");
  2329. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2330. TOnceDoneOperation OnceDoneOperation;
  2331. Progress.Finish(FileName, true, OnceDoneOperation);
  2332. }
  2333. }
  2334. __finally
  2335. {
  2336. Progress.Stop();
  2337. }
  2338. }
  2339. }
  2340. //---------------------------------------------------------------------------
  2341. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2342. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2343. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2344. {
  2345. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2346. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2347. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2348. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2349. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2350. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2351. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2352. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2353. std::unique_ptr<UnicodeString> POutput;
  2354. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2355. FLAGSET(ACommand.Params, ccCopyResults))
  2356. {
  2357. POutput.reset(new UnicodeString());
  2358. }
  2359. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  2360. if (!LocalCustomCommand.IsFileCommand(Command))
  2361. {
  2362. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2363. }
  2364. // remote files?
  2365. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2366. {
  2367. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2368. }
  2369. // local files
  2370. else
  2371. {
  2372. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2373. }
  2374. if (POutput.get() != NULL)
  2375. {
  2376. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2377. int P = POutput->Pos(sLineBreak);
  2378. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2379. {
  2380. POutput->SetLength(P - 1);
  2381. }
  2382. // Copy even empty output to clipboard
  2383. if (FLAGSET(ACommand.Params, ccCopyResults))
  2384. {
  2385. CopyToClipboard(*POutput);
  2386. }
  2387. // But do not show an empty message box.
  2388. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2389. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2390. !POutput->IsEmpty())
  2391. {
  2392. TClipboardHandler ClipboardHandler;
  2393. ClipboardHandler.Text = *POutput;
  2394. TMessageParams Params;
  2395. TQueryButtonAlias Aliases[1];
  2396. Aliases[0].Button = qaRetry;
  2397. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2398. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2399. Params.Aliases = Aliases;
  2400. Params.AliasesCount = LENOF(Aliases);
  2401. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2402. }
  2403. }
  2404. }
  2405. //---------------------------------------------------------------------------
  2406. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2407. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2408. {
  2409. TCustomCommandData Data;
  2410. UnicodeString Site;
  2411. UnicodeString RemotePath;
  2412. if (HasActiveTerminal())
  2413. {
  2414. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2415. Data = TCustomCommandData(SessionData.get());
  2416. Site = Terminal->SessionData->SessionKey;
  2417. RemotePath = Terminal->CurrentDirectory;
  2418. }
  2419. UnicodeString HelpKeyword = ACommand.HomePage;
  2420. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2421. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2422. {
  2423. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2424. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2425. {
  2426. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2427. }
  2428. else
  2429. {
  2430. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2431. }
  2432. if (!DoCustomCommandOptionsDialog(
  2433. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2434. {
  2435. Abort();
  2436. }
  2437. }
  2438. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2439. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2440. {
  2441. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2442. }
  2443. else
  2444. {
  2445. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2446. }
  2447. }
  2448. //---------------------------------------------------------------------------
  2449. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2450. const TCustomCommandType & Command)
  2451. {
  2452. DebugAssert(FCustomCommandLocalFileList != NULL);
  2453. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2454. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2455. TStrings * LocalFileList = new TStringList();
  2456. TStrings * RemoteFileList = new TStringList();
  2457. try
  2458. {
  2459. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2460. {
  2461. LocalFileList->Clear();
  2462. LocalFileList->AddObject(
  2463. FCustomCommandLocalFileList->Strings[Index],
  2464. FCustomCommandLocalFileList->Objects[Index]);
  2465. RemoteFileList->Clear();
  2466. RemoteFileList->AddObject(
  2467. FCustomCommandRemoteFileList->Strings[Index],
  2468. FCustomCommandRemoteFileList->Objects[Index]);
  2469. CustomCommand(RemoteFileList, Command, LocalFileList);
  2470. }
  2471. }
  2472. __finally
  2473. {
  2474. delete LocalFileList;
  2475. delete RemoteFileList;
  2476. }
  2477. }
  2478. //---------------------------------------------------------------------------
  2479. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2480. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2481. {
  2482. delete FCustomCommandLocalFileList;
  2483. delete FCustomCommandRemoteFileList;
  2484. // takeover ownership,
  2485. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2486. FCustomCommandLocalFileList = LocalFileList;
  2487. FCustomCommandRemoteFileList = RemoteFileList;
  2488. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2489. if (Button != NULL)
  2490. {
  2491. FCustomCommandMenu->Items->Clear();
  2492. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2493. MenuPopup(FCustomCommandMenu, Button);
  2494. }
  2495. else
  2496. {
  2497. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2498. }
  2499. }
  2500. //---------------------------------------------------------------------------
  2501. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2502. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2503. {
  2504. DebugAssert(FCapturedLog != NULL);
  2505. if ((OutputType == cotOutput) || (OutputType == cotError))
  2506. {
  2507. FCapturedLog->Add(AddedLine);
  2508. }
  2509. }
  2510. //---------------------------------------------------------------------------
  2511. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2512. TOperationSide Side)
  2513. {
  2514. return
  2515. (Side == osOther) &&
  2516. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2517. }
  2518. //---------------------------------------------------------------------------
  2519. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2520. TOperationSide Side, TTBXCustomItem * Item,
  2521. TResolvedDoubleClickAction DoubleClickAction1, TResolvedDoubleClickAction DoubleClickAction2)
  2522. {
  2523. TCustomDirView * DView = DirView(Side);
  2524. bool IsDefault = false;
  2525. if (DView->ItemFocused != NULL)
  2526. {
  2527. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  2528. TResolvedDoubleClickAction DefaultAction =
  2529. WinConfiguration->ResolveDoubleClickAction(DView->ItemIsDirectory(DView->ItemFocused), ATerminal);
  2530. IsDefault = (DefaultAction == DoubleClickAction1) || (DefaultAction == DoubleClickAction2);
  2531. }
  2532. TTBItemOptions O = Item->Options;
  2533. if (IsDefault)
  2534. {
  2535. Item->Options = O << tboDefault;
  2536. }
  2537. else
  2538. {
  2539. Item->Options = O >> tboDefault;
  2540. }
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2544. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2545. {
  2546. TCustomDirView * DView = DirView(Side);
  2547. TListItem * Item = DView->ItemFocused;
  2548. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2549. EnableFocusedOperation[Side])
  2550. {
  2551. TPoint ClientPoint;
  2552. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2553. TPoint(0, 0) : MousePos;
  2554. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2555. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2556. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2557. }
  2558. }
  2559. //---------------------------------------------------------------------------
  2560. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2561. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2562. {
  2563. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, rdcaChangeDir, rdcaOpen);
  2564. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, rdcaEdit, rdcaNone);
  2565. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, rdcaCopy, rdcaNone);
  2566. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2567. Handled = true;
  2568. }
  2569. //---------------------------------------------------------------------------
  2570. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2571. {
  2572. }
  2573. //---------------------------------------------------------------------------
  2574. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2575. {
  2576. DebugAssert(FErrorList == NULL);
  2577. if (WinConfiguration->ContinueOnError)
  2578. {
  2579. FErrorList = new TStringList();
  2580. Configuration->Usage->Inc(L"ContinuationsOnError");
  2581. }
  2582. NonVisualDataModule->StartBusy();
  2583. }
  2584. //---------------------------------------------------------------------------
  2585. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2586. {
  2587. NonVisualDataModule->EndBusy();
  2588. if (FErrorList)
  2589. {
  2590. HandleErrorList(FErrorList);
  2591. }
  2592. }
  2593. //---------------------------------------------------------------------------
  2594. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2595. const TCopyParamType & CopyParam)
  2596. {
  2597. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2598. {
  2599. Configuration->Usage->Inc(L"FileMaskUses");
  2600. }
  2601. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2602. {
  2603. Configuration->Usage->Inc(L"OperationMaskUses");
  2604. }
  2605. }
  2606. //---------------------------------------------------------------------------
  2607. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2608. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2609. {
  2610. DebugAssert(!IsLocalBrowserMode());
  2611. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2612. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2613. TTransferOperationParam DefaultParam;
  2614. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2615. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2616. switch (Param.Queue)
  2617. {
  2618. case asOn:
  2619. CopyParam.Queue = true;
  2620. break;
  2621. case asOff:
  2622. CopyParam.Queue = false;
  2623. break;
  2624. case asAuto:
  2625. default:
  2626. // keep default
  2627. break;
  2628. }
  2629. bool Result =
  2630. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2631. if (Result)
  2632. {
  2633. DebugAssert(Terminal);
  2634. bool SelectionRestored = false;
  2635. TCustomDirView * DView = NULL;
  2636. if (HasDirView[Side])
  2637. {
  2638. DView = DirView(Side);
  2639. DView->SaveSelection();
  2640. DView->SaveSelectedNames();
  2641. }
  2642. UpdateCopyParamCounters(CopyParam);
  2643. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2644. DebugAssert(FTransferResumeList == NULL);
  2645. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2646. FMoveToQueue = false;
  2647. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2648. try
  2649. {
  2650. TStrings * PermanentFileList;
  2651. std::unique_ptr<TStrings> PermanentFileListOwner;
  2652. try
  2653. {
  2654. if (Side == osLocal)
  2655. {
  2656. PermanentFileList = FileList;
  2657. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2658. CopyParam.IncludeFileMask.SetRoots(FileList, Param.TargetDirectory);
  2659. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2660. if (Operation == foMove)
  2661. {
  2662. ReloadLocalDirectory();
  2663. if (DView != NULL)
  2664. {
  2665. DView->RestoreSelection();
  2666. }
  2667. SelectionRestored = true;
  2668. }
  2669. }
  2670. else
  2671. {
  2672. // Clone the file list as it may refer to current directory files,
  2673. // which get destroyed, when the source directory is reloaded after foMove operation.
  2674. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2675. // But for a hotfix, we are not going to do such a big change.
  2676. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2677. PermanentFileList = PermanentFileListOwner.get();
  2678. try
  2679. {
  2680. CopyParam.IncludeFileMask.SetRoots(Param.TargetDirectory, FileList);
  2681. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2682. }
  2683. __finally
  2684. {
  2685. if (Operation == foMove)
  2686. {
  2687. if (DView != NULL)
  2688. {
  2689. DView->RestoreSelection();
  2690. }
  2691. SelectionRestored = true;
  2692. }
  2693. ReloadLocalDirectory(Param.TargetDirectory);
  2694. }
  2695. }
  2696. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2697. if (FMoveToQueue)
  2698. {
  2699. Abort();
  2700. }
  2701. }
  2702. catch (EAbort &)
  2703. {
  2704. if (FMoveToQueue)
  2705. {
  2706. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2707. DebugAssert(CopyParam.TransferSkipList == NULL);
  2708. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2709. if (TransferResumeList->Count > 0)
  2710. {
  2711. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2712. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2713. }
  2714. CopyParam.TransferSkipList = TransferResumeList.release();
  2715. // not really needed, just to keep it consistent with TransferResumeList
  2716. FTransferResumeList = NULL;
  2717. FMoveToQueue = false;
  2718. Configuration->Usage->Inc("MovesToBackground");
  2719. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2720. ClearTransferSourceSelection(Direction);
  2721. }
  2722. throw;
  2723. }
  2724. }
  2725. __finally
  2726. {
  2727. if (!SelectionRestored && (DView != NULL))
  2728. {
  2729. DView->DiscardSavedSelection();
  2730. }
  2731. FTransferResumeList = NULL;
  2732. }
  2733. }
  2734. return Result;
  2735. }
  2736. //---------------------------------------------------------------------------
  2737. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2738. TOperationSide Side, TStrings * FileList, void * Param)
  2739. {
  2740. DebugAssert(FileList->Count);
  2741. // We deliberately do not toggle alternative flag (Param), but use OR,
  2742. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2743. // shortcut of CurrentDeleteAlternativeAction
  2744. bool Alternative =
  2745. bool(Param) || UseAlternativeFunction();
  2746. bool Recycle;
  2747. if (IsSideLocalBrowser(Side))
  2748. {
  2749. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2750. }
  2751. else
  2752. {
  2753. Recycle =
  2754. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2755. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2756. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2757. }
  2758. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2759. if (!Result)
  2760. {
  2761. UnicodeString Query;
  2762. if (FileList->Count == 1)
  2763. {
  2764. if (IsSideLocalBrowser(Side))
  2765. {
  2766. Query = ExtractFileName(FileList->Strings[0]);
  2767. }
  2768. else
  2769. {
  2770. Query = UnixExtractFileName(FileList->Strings[0]);
  2771. }
  2772. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2773. }
  2774. else
  2775. {
  2776. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2777. }
  2778. TMessageParams Params(mpNeverAskAgainCheck);
  2779. Params.ImageName = L"Delete file";
  2780. unsigned int Answer =
  2781. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2782. if (Answer == qaNeverAskAgain)
  2783. {
  2784. Result = true;
  2785. if (Recycle)
  2786. {
  2787. WinConfiguration->ConfirmRecycling = false;
  2788. }
  2789. else
  2790. {
  2791. WinConfiguration->ConfirmDeleting = false;
  2792. }
  2793. }
  2794. else
  2795. {
  2796. Result = (Answer == qaOK);
  2797. }
  2798. }
  2799. if (Result)
  2800. {
  2801. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2802. }
  2803. return Result;
  2804. }
  2805. //---------------------------------------------------------------------------
  2806. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2807. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2808. {
  2809. TAutoBatch AutoBatch(this);
  2810. bool Result;
  2811. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2812. {
  2813. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2814. }
  2815. else if (Operation == foRename)
  2816. {
  2817. DebugAssert(DirView(Side)->ItemFocused);
  2818. DirView(Side)->ItemFocused->EditCaption();
  2819. Result = true;
  2820. }
  2821. else if (Operation == foDelete)
  2822. {
  2823. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2824. }
  2825. else if (Operation == foSetProperties)
  2826. {
  2827. DirView(osRemote)->SaveSelectedNames();
  2828. Result = SetProperties(Side, FileList);
  2829. }
  2830. else if (Operation == foCustomCommand)
  2831. {
  2832. DebugAssert(Param);
  2833. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2834. DirView(osRemote)->SaveSelectedNames();
  2835. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2836. CustomCommand(FileList, *Command, NULL);
  2837. Result = true;
  2838. }
  2839. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2840. {
  2841. DebugAssert(!IsSideLocalBrowser(Side));
  2842. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2843. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2844. }
  2845. else if (Operation == foLock)
  2846. {
  2847. DebugAssert(!IsSideLocalBrowser(Side));
  2848. LockFiles(FileList, true);
  2849. Result = true;
  2850. }
  2851. else if (Operation == foUnlock)
  2852. {
  2853. DebugAssert(!IsSideLocalBrowser(Side));
  2854. LockFiles(FileList, false);
  2855. Result = true;
  2856. }
  2857. else
  2858. {
  2859. DebugFail();
  2860. }
  2861. return Result;
  2862. }
  2863. //---------------------------------------------------------------------------
  2864. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2865. {
  2866. if (Side == osCurrent)
  2867. {
  2868. Side = FCurrentSide;
  2869. }
  2870. return Side;
  2871. }
  2872. //---------------------------------------------------------------------------
  2873. TOperationSide TCustomScpExplorerForm::GetOtherSide(TOperationSide Side)
  2874. {
  2875. TOperationSide Result;
  2876. switch (GetSide(Side))
  2877. {
  2878. case osLocal:
  2879. Result = osOther;
  2880. break;
  2881. case osOther:
  2882. Result = osLocal;
  2883. break;
  2884. default:
  2885. DebugFail();
  2886. Abort();
  2887. }
  2888. return Result;
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2892. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2893. {
  2894. Side = GetSide(Side);
  2895. bool FullPath = IsSideLocalBrowser(Side);
  2896. TCustomDirView * ADirView = DirView(Side);
  2897. std::unique_ptr<TStringList> FileList(new TStringList());
  2898. ADirView->CreateFileList(OnFocused, FullPath, FileList.get());
  2899. bool ReloadProperties =
  2900. !IsSideLocalBrowser(Side) && (Operation == foSetProperties) &&
  2901. DebugAlwaysTrue(HasActiveTerminal()) && Terminal->IsCapable[fcLoadingAdditionalProperties];
  2902. bool Result = ExecuteFileOperation(Operation, Side, FileList.get(), NoConfirmation, Param);
  2903. if (Result && ReloadProperties)
  2904. {
  2905. std::unique_ptr<TStringList> FileList2(new TStringList());
  2906. FileList->CaseSensitive = true;
  2907. FileList->Sort();
  2908. for (int Index = 0; Index < ADirView->Items->Count; Index++)
  2909. {
  2910. TListItem * Item = ADirView->Items->Item[Index];
  2911. UnicodeString FileName = ADirView->ItemFileName(Item);
  2912. int Index2;
  2913. if (FileList->Find(FileName, Index2))
  2914. {
  2915. FileList2->AddObject(FileName, ADirView->ItemData(Item));
  2916. }
  2917. }
  2918. LoadFilesProperties(FileList2.get());
  2919. }
  2920. return Result;
  2921. }
  2922. //---------------------------------------------------------------------------
  2923. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2924. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2925. bool NoConfirmation, void * Param)
  2926. {
  2927. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2928. {
  2929. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2930. {
  2931. DebugAssert(!IsLocalBrowserMode());
  2932. if (GetSide(Side) == osLocal)
  2933. {
  2934. Configuration->Usage->Inc(L"UploadsCommand");
  2935. }
  2936. else
  2937. {
  2938. Configuration->Usage->Inc(L"DownloadsCommand");
  2939. }
  2940. }
  2941. }
  2942. }
  2943. //---------------------------------------------------------------------------
  2944. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2945. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2946. {
  2947. TTransferOperationParam Param;
  2948. if ((WinConfiguration->Interface != ifCommander) ||
  2949. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2950. {
  2951. Flags &= ~cocShortCutHint;
  2952. }
  2953. TCustomDirView * DView = DirView(Side);
  2954. Param.Options =
  2955. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2956. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2957. if (FLAGSET(Flags, cocQueue))
  2958. {
  2959. Param.Queue = asOn;
  2960. }
  2961. else if (FLAGSET(Flags, cocNonQueue))
  2962. {
  2963. Param.Queue = asOff;
  2964. }
  2965. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2966. }
  2967. //---------------------------------------------------------------------------
  2968. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2969. {
  2970. int Count = ErrorList->Count;
  2971. try
  2972. {
  2973. if (ErrorList->Count)
  2974. {
  2975. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2976. if (MessageDialog(Message, qtError,
  2977. qaOK | qaCancel, HELP_NONE) == qaOK)
  2978. {
  2979. unsigned int Answer;
  2980. int Index = 0;
  2981. do
  2982. {
  2983. DebugAssert(Index >= 0 && Index < Count);
  2984. TQueryButtonAlias Aliases[2];
  2985. Aliases[0].Button = qaYes;
  2986. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2987. Aliases[1].Button = qaNo;
  2988. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2989. TMessageParams Params;
  2990. Params.Aliases = Aliases;
  2991. Params.AliasesCount = LENOF(Aliases);
  2992. int No = Index + 1;
  2993. UnicodeString Message = ErrorList->Strings[Index];
  2994. UnicodeString AMainInstructions;
  2995. UnicodeString Details;
  2996. if (ExtractMainInstructions(Message, AMainInstructions))
  2997. {
  2998. Details = Message;
  2999. Message = AMainInstructions;
  3000. }
  3001. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  3002. Answer = MoreMessageDialog(
  3003. Message,
  3004. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  3005. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  3006. qaOK, HELP_NONE, &Params);
  3007. if (Answer == qaNo)
  3008. {
  3009. Index++;
  3010. }
  3011. if (Answer == qaYes)
  3012. {
  3013. Index--;
  3014. }
  3015. }
  3016. while (Answer != qaOK);
  3017. }
  3018. }
  3019. }
  3020. __finally
  3021. {
  3022. TStrings * List = ErrorList;
  3023. ErrorList = NULL;
  3024. for (int i = 0; i < Count; i++)
  3025. {
  3026. delete List->Objects[i];
  3027. }
  3028. delete List;
  3029. }
  3030. }
  3031. //---------------------------------------------------------------------------
  3032. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  3033. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  3034. {
  3035. // needed for checking filemasks, as there's no directory object
  3036. // associated with the file object
  3037. File->FullFileName = FullFileName;
  3038. TFileMasks::TParams MaskParams;
  3039. MaskParams.Size = File->Size;
  3040. MaskParams.Modification = File->Modification;
  3041. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  3042. }
  3043. //---------------------------------------------------------------------------
  3044. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  3045. {
  3046. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3047. Side = GetSide(Side);
  3048. TCustomDirView * DView = DirView(Side);
  3049. TListItem * FocusedItem = DView->ItemFocused;
  3050. UnicodeString Name;
  3051. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  3052. {
  3053. Name = DView->ItemFileName(FocusedItem);
  3054. }
  3055. else
  3056. {
  3057. Name = LoadStr(NEW_FILE);
  3058. }
  3059. UnicodeString Names = Name;
  3060. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  3061. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  3062. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  3063. {
  3064. while (!Names.IsEmpty())
  3065. {
  3066. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  3067. CustomWinConfiguration->History[L"EditFile"] = History.get();
  3068. UnicodeString TargetFileName;
  3069. UnicodeString LocalFileName;
  3070. UnicodeString RootTempDir;
  3071. UnicodeString TempDir;
  3072. UnicodeString RemoteDirectory;
  3073. bool ExistingFile = false;
  3074. if (!IsSideLocalBrowser(Side))
  3075. {
  3076. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  3077. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(Name));
  3078. if ((File.get() != NULL) &&
  3079. !File->IsDirectory)
  3080. {
  3081. ExecuteRemoteFile(Name, File.get(), efDefaultEditor);
  3082. ExistingFile = true;
  3083. }
  3084. File.reset(NULL);
  3085. if (!ExistingFile)
  3086. {
  3087. RemoteDirectory = UnixExtractFilePath(Name);
  3088. TemporaryDirectoryForRemoteFiles(
  3089. RemoteDirectory, GUIConfiguration->CurrentCopyParam, false, TempDir, RootTempDir);
  3090. TargetFileName = UnixExtractFileName(Name);
  3091. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3092. LocalFileName = TempDir +
  3093. // We probably do not want to trim the VMS version here
  3094. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  3095. }
  3096. }
  3097. else
  3098. {
  3099. if (ExtractFilePath(Name).IsEmpty())
  3100. {
  3101. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  3102. }
  3103. else
  3104. {
  3105. LocalFileName = ExpandFileName(Name);
  3106. }
  3107. TargetFileName = ExtractFileName(Name);
  3108. }
  3109. if (!ExistingFile)
  3110. {
  3111. bool NewFile = !FileExists(ApiPath(LocalFileName));
  3112. if (NewFile)
  3113. {
  3114. int File = FileCreate(ApiPath(LocalFileName));
  3115. if (File < 0)
  3116. {
  3117. if (!RootTempDir.IsEmpty())
  3118. {
  3119. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3120. }
  3121. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  3122. }
  3123. else
  3124. {
  3125. FileClose(File);
  3126. }
  3127. }
  3128. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  3129. const TEditorData * ExternalEditor = NULL;
  3130. TFileMasks::TParams MaskParams; // size not known
  3131. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  3132. false, MaskParams);
  3133. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  3134. ExternalEditor, RootTempDir, RemoteDirectory, NewFile, TDateTime());
  3135. }
  3136. }
  3137. }
  3138. }
  3139. //---------------------------------------------------------------------------
  3140. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  3141. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  3142. {
  3143. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3144. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3145. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3146. return
  3147. ((ExecuteFileBy == efInternalEditor)) ||
  3148. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  3149. }
  3150. //---------------------------------------------------------------------------
  3151. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3152. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3153. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3154. UnicodeString RemoteDirectory, bool NewFile, const TDateTime & SourceTimestamp)
  3155. {
  3156. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3157. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3158. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3159. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3160. Side = GetSide(Side);
  3161. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3162. if (!IsSideLocalBrowser(Side))
  3163. {
  3164. Data->Terminal = Terminal;
  3165. Data->SessionData = CloneCurrentSessionData();
  3166. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3167. Data->RemoteDirectory = RemoteDirectory;
  3168. Data->SessionName = Terminal->SessionData->SessionName;
  3169. Data->LocalRootDirectory = LocalRootDirectory;
  3170. Data->OriginalFileName = OriginalFileName;
  3171. Data->Command = L""; // will be changed later for external editor
  3172. // Empty SourceTimestamp indicates that checking was disabled when the file was opened
  3173. if (WinConfiguration->EditorCheckNotModified)
  3174. {
  3175. Data->SourceTimestamp = SourceTimestamp;
  3176. }
  3177. }
  3178. if (ExecuteFileBy == efInternalEditor)
  3179. {
  3180. if (!IsSideLocalBrowser(Side))
  3181. {
  3182. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3183. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3184. TForm * Editor;
  3185. try
  3186. {
  3187. Editor =
  3188. ShowEditorForm(
  3189. FileName, this,
  3190. FEditorManager->FileChanged, FEditorManager->FileReload, FEditorManager->FileClosed,
  3191. SaveAllInternalEditors, AnyInternalEditorModified,
  3192. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3193. }
  3194. catch(...)
  3195. {
  3196. if (!LocalRootDirectory.IsEmpty())
  3197. {
  3198. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory));
  3199. }
  3200. throw;
  3201. }
  3202. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3203. AppLogFmt(L"Opened internal editor with \"%s\"", (FileName));
  3204. }
  3205. else
  3206. {
  3207. DebugAssert(!StandaloneOperation);
  3208. TForm * Editor =
  3209. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3210. SaveAllInternalEditors, AnyInternalEditorModified,
  3211. L"", false, SessionColor, -1, NewFile);
  3212. FLocalEditors->Add(Editor);
  3213. }
  3214. }
  3215. else
  3216. {
  3217. HANDLE Process;
  3218. if (ExecuteFileBy == efExternalEditor)
  3219. {
  3220. UnicodeString Program, Params, Dir;
  3221. Data->Command = ExternalEditor->ExternalEditor;
  3222. ReformatFileNameCommand(Data->Command);
  3223. SplitCommand(Data->Command, Program, Params, Dir);
  3224. Params = ExpandFileNameCommand(Params, FileName);
  3225. Program = ExpandEnvironmentVariables(Program);
  3226. if (!ExecuteShell(Program, Params, Process))
  3227. {
  3228. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3229. }
  3230. }
  3231. else
  3232. {
  3233. DebugAssert(!IsSideLocalBrowser(Side));
  3234. if (!ExecuteShell(FileName, L"", Process))
  3235. {
  3236. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3237. }
  3238. }
  3239. if (IsSideLocalBrowser(Side) ||
  3240. ((ExecuteFileBy == efShell) &&
  3241. !WinConfiguration->Editor.SDIShellEditor) ||
  3242. ((ExecuteFileBy == efExternalEditor) &&
  3243. !ExternalEditor->SDIExternalEditor))
  3244. {
  3245. // no need for handle
  3246. if (Process != NULL)
  3247. {
  3248. DebugCheck(CloseHandle(Process));
  3249. }
  3250. Process = INVALID_HANDLE_VALUE;
  3251. }
  3252. else
  3253. {
  3254. if (Process == NULL)
  3255. {
  3256. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3257. }
  3258. }
  3259. if (!IsSideLocalBrowser(Side))
  3260. {
  3261. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3262. AppLogFmt(L"Opened external editor with remote file \"%s\".", (FileName));
  3263. }
  3264. }
  3265. }
  3266. //---------------------------------------------------------------------------
  3267. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3268. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3269. void * /*Arg*/)
  3270. {
  3271. if (Token != NULL)
  3272. {
  3273. EditorFormFileSave(static_cast<TForm *>(Token));
  3274. }
  3275. }
  3276. //---------------------------------------------------------------------------
  3277. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3278. {
  3279. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3280. {
  3281. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3282. }
  3283. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3284. }
  3285. //---------------------------------------------------------------------------
  3286. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3287. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3288. void * Arg)
  3289. {
  3290. if ((Token != NULL) &&
  3291. IsEditorFormModified(static_cast<TForm *>(Token)))
  3292. {
  3293. *static_cast<bool *>(Arg) = true;
  3294. }
  3295. }
  3296. //---------------------------------------------------------------------------
  3297. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3298. TObject * /*Sender*/, bool & Modified)
  3299. {
  3300. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3301. {
  3302. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3303. {
  3304. Modified = true;
  3305. }
  3306. }
  3307. if (!Modified)
  3308. {
  3309. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3310. }
  3311. }
  3312. //---------------------------------------------------------------------------
  3313. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3314. {
  3315. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3316. }
  3317. //---------------------------------------------------------------------------
  3318. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3319. const UnicodeString & RemoteDirectory, const TCopyParamType & CopyParam, bool Simple,
  3320. UnicodeString & Result, UnicodeString & RootDirectory)
  3321. {
  3322. if (!WinConfiguration->TemporaryDirectoryDeterministic || Simple)
  3323. {
  3324. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3325. Result = RootDirectory;
  3326. }
  3327. else
  3328. {
  3329. RootDirectory = L"";
  3330. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3331. Result = IncludeTrailingBackslash(Result);
  3332. }
  3333. if (WinConfiguration->TemporaryDirectoryAppendSession && !Simple)
  3334. {
  3335. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3336. }
  3337. if (WinConfiguration->TemporaryDirectoryAppendPath && !Simple)
  3338. {
  3339. UnicodeString ARemoteDirectory = RemoteDirectory;
  3340. if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory[1] == L'/'))
  3341. {
  3342. ARemoteDirectory.Delete(1, 1);
  3343. }
  3344. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(ARemoteDirectory)));
  3345. }
  3346. if (!ForceDirectories(ApiPath(Result)))
  3347. {
  3348. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3349. }
  3350. }
  3351. //---------------------------------------------------------------------------
  3352. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3353. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3354. bool GetTargetNames, bool AutoOperation, bool SimpleTempDir)
  3355. {
  3356. DebugAssert(!IsLocalBrowserMode());
  3357. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3358. if (ForceText)
  3359. {
  3360. CopyParam.TransferMode = tmAscii;
  3361. }
  3362. TemporaryFileCopyParam(CopyParam);
  3363. if (TempDir.IsEmpty())
  3364. {
  3365. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, SimpleTempDir, TempDir, RootTempDir);
  3366. }
  3367. DebugAssert(!FAutoOperation);
  3368. FAutoOperation = AutoOperation;
  3369. FMoveToQueue = false;
  3370. Terminal->ExceptionOnFail = true;
  3371. try
  3372. {
  3373. try
  3374. {
  3375. // turn off confirmations, as for MDI editors we may possibly download
  3376. // the same file over
  3377. Terminal->CopyToLocal(
  3378. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3379. if (GetTargetNames)
  3380. {
  3381. for (int i = 0; i < FileList->Count; i++)
  3382. {
  3383. FileList->Strings[i] =
  3384. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3385. }
  3386. }
  3387. }
  3388. catch(...)
  3389. {
  3390. if (!RootTempDir.IsEmpty())
  3391. {
  3392. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3393. }
  3394. throw;
  3395. }
  3396. }
  3397. __finally
  3398. {
  3399. FAutoOperation = false;
  3400. Terminal->ExceptionOnFail = false;
  3401. }
  3402. }
  3403. //---------------------------------------------------------------------------
  3404. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3405. {
  3406. // Do not waste time checking for default editor list the next time,
  3407. // or testing if default editor is not notepad.
  3408. bool TryNextTime = false;
  3409. UnicodeString UsageState;
  3410. if (!WinConfiguration->EditorList->IsDefaultList())
  3411. {
  3412. UsageState = "H";
  3413. }
  3414. else
  3415. {
  3416. UnicodeString Executable;
  3417. UnicodeString ExecutableDescription;
  3418. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3419. {
  3420. UnicodeString Message =
  3421. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3422. unsigned int Answer =
  3423. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3424. if (Answer != qaOK)
  3425. {
  3426. UsageState = "R";
  3427. }
  3428. else
  3429. {
  3430. UsageState = "A";
  3431. TEditorData EditorData;
  3432. EditorData.Editor = edExternal;
  3433. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3434. EditorData.ExternalEditorOptionsAutodetect();
  3435. TEditorList EditorList;
  3436. EditorList = *WinConfiguration->EditorList;
  3437. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3438. WinConfiguration->EditorList = &EditorList;
  3439. }
  3440. }
  3441. }
  3442. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3443. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3444. }
  3445. //---------------------------------------------------------------------------
  3446. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3447. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3448. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3449. {
  3450. if (ExecuteFileBy == efDefaultEditor)
  3451. {
  3452. if (!WinConfiguration->OfferedEditorAutoConfig)
  3453. {
  3454. EditorAutoConfig();
  3455. }
  3456. const TEditorPreferences * Editor =
  3457. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3458. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3459. {
  3460. ExecuteFileBy = efInternalEditor;
  3461. ExternalEditor = NULL;
  3462. }
  3463. else if (Editor->Data->Editor == edOpen)
  3464. {
  3465. ExecuteFileBy = efShell;
  3466. ExternalEditor = NULL;
  3467. }
  3468. else
  3469. {
  3470. ExecuteFileBy = efExternalEditor;
  3471. ExternalEditor = Editor->Data;
  3472. }
  3473. }
  3474. }
  3475. //---------------------------------------------------------------------------
  3476. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3477. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3478. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3479. {
  3480. UnicodeString OriginalFileName;
  3481. UnicodeString LocalRootDirectory;
  3482. UnicodeString RemoteDirectory;
  3483. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3484. IsSideLocalBrowser(Side), MaskParams);
  3485. UnicodeString Counter;
  3486. UnicodeString LocalFileName;
  3487. bool Handled = false;
  3488. if (!IsSideLocalBrowser(Side))
  3489. {
  3490. // We need to trim VMS version here, so that we use name without version
  3491. // when uploading back to create a new version of the file
  3492. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3493. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3494. TObject * Token = NULL;
  3495. UnicodeString LocalDirectory;
  3496. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3497. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3498. LocalDirectory))
  3499. {
  3500. if (Token != NULL)
  3501. {
  3502. TForm * Form = dynamic_cast<TForm *>(Token);
  3503. if (Form->WindowState == wsMinimized)
  3504. {
  3505. ShowWindow(Form->Handle, SW_RESTORE);
  3506. }
  3507. else
  3508. {
  3509. Form->SetFocus();
  3510. }
  3511. Handled = true;
  3512. }
  3513. else
  3514. {
  3515. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3516. }
  3517. }
  3518. if (!Handled)
  3519. {
  3520. TStringList * FileList1 = new TStringList();
  3521. try
  3522. {
  3523. FileList1->AddObject(FullFileName, Object);
  3524. TemporarilyDownloadFiles(FileList1,
  3525. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3526. LocalRootDirectory, LocalDirectory, true, true, false);
  3527. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3528. }
  3529. __finally
  3530. {
  3531. delete FileList1;
  3532. }
  3533. switch (ExecuteFileBy)
  3534. {
  3535. case efShell:
  3536. Counter = "RemoteFilesExecuted";
  3537. break;
  3538. case efInternalEditor:
  3539. Counter = "RemoteFilesOpenedInInternalEditor";
  3540. break;
  3541. case efExternalEditor:
  3542. Counter = "RemoteFilesOpenedInExternalEditor";
  3543. break;
  3544. default:
  3545. DebugFail();
  3546. }
  3547. }
  3548. }
  3549. else
  3550. {
  3551. LocalFileName = FullFileName;
  3552. OriginalFileName = ExtractFileName(FullFileName);
  3553. switch (ExecuteFileBy)
  3554. {
  3555. case efShell:
  3556. Counter = "LocalFilesExecuted";
  3557. break;
  3558. case efInternalEditor:
  3559. Counter = "LocalFilesOpenedInInternalEditor";
  3560. break;
  3561. case efExternalEditor:
  3562. Counter = "LocalFilesOpenedInExternalEditor";
  3563. break;
  3564. default:
  3565. DebugFail();
  3566. }
  3567. }
  3568. if (!Handled)
  3569. {
  3570. Configuration->Usage->Inc(Counter);
  3571. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3572. ExternalEditor, LocalRootDirectory, RemoteDirectory, false, MaskParams.Modification);
  3573. }
  3574. }
  3575. //---------------------------------------------------------------------------
  3576. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3577. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3578. bool AllSelected, bool OnFocused)
  3579. {
  3580. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3581. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3582. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3583. Side = GetSide(Side);
  3584. TCustomDirView * DView = DirView(Side);
  3585. TStrings * FileList =
  3586. AllSelected ?
  3587. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3588. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3589. try
  3590. {
  3591. DebugAssert(AllSelected || (FileList->Count == 1));
  3592. for (int i = 0; i < FileList->Count; i++)
  3593. {
  3594. UnicodeString ListFileName = FileList->Strings[i];
  3595. UnicodeString FileNameOnly =
  3596. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3597. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3598. if (!DView->ItemIsDirectory(Item))
  3599. {
  3600. UnicodeString FullFileName;
  3601. if (!IsSideLocalBrowser(Side))
  3602. {
  3603. FullFileName = DirView(Side)->Path + ListFileName;
  3604. }
  3605. else
  3606. {
  3607. FullFileName = ListFileName;
  3608. }
  3609. TObject * Object = FileList->Objects[i];
  3610. TFileMasks::TParams MaskParams;
  3611. MaskParams.Size = DView->ItemFileSize(Item);
  3612. TDateTimePrecision Precision;
  3613. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3614. std::unique_ptr<TRemoteFile> File;
  3615. if (!IsSideLocalBrowser(Side))
  3616. {
  3617. File.reset(Terminal->TryReadFile(FullFileName));
  3618. if (File.get() != NULL)
  3619. {
  3620. File->FullFileName = FullFileName;
  3621. Object = File.get();
  3622. MaskParams.Size = File->Size;
  3623. MaskParams.Modification = File->Modification;
  3624. }
  3625. }
  3626. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName, Object, MaskParams);
  3627. }
  3628. }
  3629. }
  3630. __finally
  3631. {
  3632. delete FileList;
  3633. }
  3634. }
  3635. //---------------------------------------------------------------------------
  3636. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3637. {
  3638. CopyParam.FileNameCase = ncNoChange;
  3639. CopyParam.PreserveRights = false;
  3640. CopyParam.PreserveReadOnly = false;
  3641. CopyParam.ReplaceInvalidChars = true;
  3642. CopyParam.IncludeFileMask = TFileMasks();
  3643. CopyParam.NewerOnly = false;
  3644. CopyParam.FileMask = L"";
  3645. }
  3646. //---------------------------------------------------------------------------
  3647. bool TCustomScpExplorerForm::EditorCheckNotModified(const TEditedFileData * Data)
  3648. {
  3649. return WinConfiguration->EditorCheckNotModified && (Data->SourceTimestamp != TDateTime());
  3650. }
  3651. //---------------------------------------------------------------------------
  3652. class TEditorUploadQueueItem : public TUploadQueueItem
  3653. {
  3654. public:
  3655. __fastcall TEditorUploadQueueItem(
  3656. TTerminal * Terminal, TStrings * FilesToCopy, const UnicodeString & TargetDir,
  3657. const TCopyParamType * CopyParam, int Params) :
  3658. TUploadQueueItem(Terminal, FilesToCopy, TargetDir, CopyParam, Params, true, false)
  3659. {
  3660. }
  3661. protected:
  3662. virtual void __fastcall DoTransferExecute(TTerminal * Terminal, TParallelOperation * ParallelOperation)
  3663. {
  3664. TUploadQueueItem::DoTransferExecute(Terminal, ParallelOperation);
  3665. TTerminalManager::Instance()->ScpExplorer->EditedFileUploaded(Terminal, CompleteEvent);
  3666. }
  3667. };
  3668. //---------------------------------------------------------------------------
  3669. void TCustomScpExplorerForm::EditedFileUploaded(TTerminal * ATerminal, HANDLE UploadCompleteEvent)
  3670. {
  3671. if (WinConfiguration->EditorCheckNotModified) // optimization
  3672. {
  3673. UnicodeString RemoteFilePath;
  3674. {
  3675. TGuard Guard(FEditorManager->Section);
  3676. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3677. if (DebugAlwaysTrue(Data != NULL) &&
  3678. EditorCheckNotModified(Data))
  3679. {
  3680. RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3681. }
  3682. }
  3683. if (!RemoteFilePath.IsEmpty())
  3684. {
  3685. std::unique_ptr<TRemoteFile> File(ATerminal->TryReadFile(RemoteFilePath));
  3686. if (File.get() != NULL)
  3687. {
  3688. TGuard Guard(FEditorManager->Section);
  3689. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3690. if (DebugAlwaysTrue(Data != NULL))
  3691. {
  3692. Data->SourceTimestamp = File->Modification;
  3693. AppLogFmt(L"Uploaded edited remote file timestamp: %s", (StandardTimestamp(Data->SourceTimestamp)));
  3694. }
  3695. }
  3696. }
  3697. }
  3698. }
  3699. //---------------------------------------------------------------------------
  3700. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(
  3701. const UnicodeString & FileName, TEditedFileData * Data, HANDLE UploadCompleteEvent, bool & Retry)
  3702. {
  3703. TTerminalManager * Manager = TTerminalManager::Instance();
  3704. if ((Manager->ActiveTerminal == Data->Terminal) &&
  3705. Manager->ScheduleTerminalReconnnect(Data->Terminal))
  3706. {
  3707. AppLog(L"Scheduled session reconnect, will retry the upload later");
  3708. Retry = true;
  3709. }
  3710. else if (!IsActiveTerminal(Data->Terminal))
  3711. {
  3712. if (!NonVisualDataModule->Busy)
  3713. {
  3714. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3715. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3716. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3717. if (Data->Terminal == NULL)
  3718. {
  3719. TManagedTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3720. if (SameSiteTerminal != NULL)
  3721. {
  3722. UnicodeString Message =
  3723. FMTLOAD(EDIT_SESSION_REATTACH,
  3724. (FileNameOnly, Data->SessionName, FileNameOnly));
  3725. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3726. {
  3727. Data->Terminal = SameSiteTerminal;
  3728. Data->SessionName = SameSiteTerminal->SessionData->SessionName;
  3729. // We might also overwrite session data
  3730. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3731. }
  3732. else
  3733. {
  3734. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3735. Abort();
  3736. }
  3737. }
  3738. }
  3739. // Foreground session should reconnect itself (except for those disconnected explicitly by the user)
  3740. else if (DebugAlwaysTrue(Terminal->Disconnected || (Terminal != Data->Terminal)))
  3741. {
  3742. UnicodeString Message =
  3743. MainInstructions(
  3744. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3745. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3746. {
  3747. if (Terminal->Disconnected)
  3748. {
  3749. Manager->ActiveSession = Terminal;
  3750. ReconnectSession();
  3751. // Was it reconnected? (if not, Data->Terminal should be nulled now)
  3752. if (!IsActiveTerminal(Data->Terminal) || (Terminal != Data->Terminal))
  3753. {
  3754. Abort();
  3755. }
  3756. }
  3757. else
  3758. {
  3759. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3760. }
  3761. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3762. }
  3763. else
  3764. {
  3765. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3766. Abort();
  3767. }
  3768. }
  3769. }
  3770. if (!IsActiveTerminal(Data->Terminal))
  3771. {
  3772. Configuration->Usage->Inc(L"EditInactiveSession");
  3773. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3774. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3775. (ExtractFileName(FileName), Data->SessionName)));
  3776. }
  3777. }
  3778. if (!Retry && EditorCheckNotModified(Data))
  3779. {
  3780. if (NonVisualDataModule->Busy)
  3781. {
  3782. Retry = true;
  3783. }
  3784. else
  3785. {
  3786. UnicodeString RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3787. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(RemoteFilePath));
  3788. if (File.get() != NULL)
  3789. {
  3790. AppLogFmt(L"Edited remote file timestamp: %s, Original timestamp: %s", (StandardTimestamp(File->Modification), StandardTimestamp(Data->SourceTimestamp)));
  3791. if (File->Modification != Data->SourceTimestamp)
  3792. {
  3793. UnicodeString Message = MainInstructions(LoadStr(EDIT_CHANGED_EXTERNALLY));
  3794. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) != qaOK)
  3795. {
  3796. Abort();
  3797. }
  3798. }
  3799. }
  3800. }
  3801. }
  3802. if (!Retry)
  3803. {
  3804. TStrings * FileList = new TStringList();
  3805. try
  3806. {
  3807. FileList->Add(FileName);
  3808. // Consider using the same settings (preset) as when the file was downloaded.
  3809. // More over this does not reflect the actual session that will do the upload.
  3810. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3811. TemporaryFileCopyParam(CopyParam);
  3812. if (Data->ForceText)
  3813. {
  3814. CopyParam.TransferMode = tmAscii;
  3815. }
  3816. // so i do not need to worry if masking algorithm works in all cases
  3817. // ("" means "copy file name", no masking is actually done)
  3818. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3819. {
  3820. CopyParam.FileMask = L"";
  3821. }
  3822. else
  3823. {
  3824. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3825. }
  3826. int Params = cpNoConfirmation | cpTemporary;
  3827. if (Data->Terminal->IsCapable[fcBackgroundTransfers])
  3828. {
  3829. TTerminalQueue * AQueue = Manager->FindQueueForTerminal(Data->Terminal);
  3830. TQueueItem * QueueItem =
  3831. new TEditorUploadQueueItem(Data->Terminal, FileList, Data->RemoteDirectory, &CopyParam, Params);
  3832. QueueItem->CompleteEvent = UploadCompleteEvent;
  3833. AddQueueItem(AQueue, QueueItem, Data->Terminal);
  3834. }
  3835. else
  3836. {
  3837. if (NonVisualDataModule->Busy)
  3838. {
  3839. Retry = true;
  3840. }
  3841. else
  3842. {
  3843. FMoveToQueue = false;
  3844. Data->Terminal->CopyToRemote(FileList, Data->RemoteDirectory, &CopyParam, Params, NULL);
  3845. SetEvent(UploadCompleteEvent);
  3846. }
  3847. }
  3848. }
  3849. __finally
  3850. {
  3851. delete FileList;
  3852. }
  3853. }
  3854. }
  3855. //---------------------------------------------------------------------------
  3856. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3857. const UnicodeString & FileName, TEditedFileData * Data)
  3858. {
  3859. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3860. DebugAssert(!NonVisualDataModule->Busy);
  3861. if (!IsActiveTerminal(Data->Terminal))
  3862. {
  3863. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3864. (ExtractFileName(FileName), Data->SessionName)));
  3865. }
  3866. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3867. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3868. NonVisualDataModule->StartBusy();
  3869. try
  3870. {
  3871. std::unique_ptr<TRemoteFile> File;
  3872. UnicodeString RemoteFileName =
  3873. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3874. Terminal->ExceptionOnFail = true;
  3875. try
  3876. {
  3877. File.reset(Terminal->ReadFile(RemoteFileName));
  3878. if (!File->HaveFullFileName)
  3879. {
  3880. File->FullFileName = RemoteFileName;
  3881. }
  3882. }
  3883. __finally
  3884. {
  3885. Terminal->ExceptionOnFail = false;
  3886. }
  3887. std::unique_ptr<TStrings> FileList(new TStringList());
  3888. FileList->AddObject(RemoteFileName, File.get());
  3889. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3890. UnicodeString TempDir = ExtractFilePath(FileName);
  3891. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir, TempDir, true, true, false);
  3892. if (EditorCheckNotModified(Data))
  3893. {
  3894. Data->SourceTimestamp = File->Modification;
  3895. }
  3896. // sanity check, the target file name should be still the same
  3897. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3898. }
  3899. __finally
  3900. {
  3901. NonVisualDataModule->EndBusy();
  3902. // it actually may not exist anymore...
  3903. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3904. }
  3905. }
  3906. //---------------------------------------------------------------------------
  3907. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3908. const TEditedFileData * Data, bool & KeepOpen)
  3909. {
  3910. // Command is set for external editors only (not for "shell" open).
  3911. if (!Data->Command.IsEmpty())
  3912. {
  3913. bool AnyFound = false;
  3914. bool AnyMDI = false;
  3915. bool AnyNonMDI = false;
  3916. bool AnyDetect = false;
  3917. TEditorList * EditorList = new TEditorList();
  3918. try
  3919. {
  3920. *EditorList = *WinConfiguration->EditorList;
  3921. for (int i = 0; i < EditorList->Count; i++)
  3922. {
  3923. const TEditorPreferences * Editor = EditorList->Editors[i];
  3924. if ((Editor->Data->Editor == edExternal) &&
  3925. (Editor->Data->ExternalEditor == Data->Command))
  3926. {
  3927. AnyFound = true;
  3928. if (Editor->Data->SDIExternalEditor)
  3929. {
  3930. AnyNonMDI = true;
  3931. if (Editor->Data->DetectMDIExternalEditor)
  3932. {
  3933. AnyDetect = true;
  3934. }
  3935. }
  3936. else
  3937. {
  3938. AnyMDI = true;
  3939. }
  3940. }
  3941. }
  3942. bool EnableMDI = false;
  3943. bool DisableDetect = false;
  3944. if (AnyMDI)
  3945. {
  3946. KeepOpen = true;
  3947. if (AnyNonMDI)
  3948. {
  3949. // there is at least one instance of the editor with MDI support enabled,
  3950. // and one with disabled, enable it for all instances
  3951. EnableMDI = true;
  3952. }
  3953. }
  3954. else if (AnyFound && !AnyDetect)
  3955. {
  3956. // at least once instance found but all have MDI autodetection disabled
  3957. // => close the file (default action)
  3958. }
  3959. else
  3960. {
  3961. // no instance of the editor has MDI support enabled
  3962. TMessageParams Params;
  3963. if (AnyFound)
  3964. {
  3965. // there is at least one instance of the editor
  3966. Params.Params |= mpNeverAskAgainCheck;
  3967. }
  3968. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3969. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3970. switch (Answer)
  3971. {
  3972. case qaNeverAskAgain:
  3973. DisableDetect = true;
  3974. break;
  3975. case qaNo:
  3976. EnableMDI = true;
  3977. KeepOpen = true;
  3978. break;
  3979. }
  3980. }
  3981. if (AnyFound && (EnableMDI || DisableDetect))
  3982. {
  3983. bool Changed = false;
  3984. for (int i = 0; i < EditorList->Count; i++)
  3985. {
  3986. const TEditorPreferences * Editor = EditorList->Editors[i];
  3987. if ((Editor->Data->Editor == edExternal) &&
  3988. (Editor->Data->ExternalEditor == Data->Command) &&
  3989. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3990. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3991. {
  3992. Changed = true;
  3993. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3994. if (EnableMDI)
  3995. {
  3996. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3997. }
  3998. if (DisableDetect)
  3999. {
  4000. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  4001. }
  4002. EditorList->Change(i, UpdatedEditor);
  4003. }
  4004. }
  4005. if (Changed)
  4006. {
  4007. WinConfiguration->EditorList = EditorList;
  4008. }
  4009. }
  4010. }
  4011. __finally
  4012. {
  4013. delete EditorList;
  4014. }
  4015. }
  4016. else
  4017. {
  4018. // "open" case
  4019. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  4020. qaOK, HELP_APP_EARLY_CLOSED);
  4021. }
  4022. }
  4023. //---------------------------------------------------------------------------
  4024. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  4025. {
  4026. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  4027. }
  4028. //---------------------------------------------------------------------------
  4029. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  4030. {
  4031. SideEnter(osRemote);
  4032. }
  4033. //---------------------------------------------------------------------------
  4034. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  4035. {
  4036. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  4037. SideEnter(osRemote);
  4038. }
  4039. //---------------------------------------------------------------------------
  4040. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  4041. {
  4042. FCurrentSide = Side;
  4043. if (Visible)
  4044. {
  4045. UpdateControls();
  4046. }
  4047. }
  4048. //---------------------------------------------------------------------------
  4049. void __fastcall TCustomScpExplorerForm::FileDeleted(TOperationSide Side, const UnicodeString & FileName, bool Success)
  4050. {
  4051. VisualiseOperationFinished(Side, FileName, Success);
  4052. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  4053. {
  4054. FDeletedFiles->Add(FileName);
  4055. }
  4056. }
  4057. //---------------------------------------------------------------------------
  4058. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  4059. TStrings * FileList, bool Alternative)
  4060. {
  4061. TCustomDirView * DView = DirView(Side);
  4062. DView->SaveSelection();
  4063. DView->SaveSelectedNames();
  4064. DebugAssert(!FAlternativeDelete);
  4065. FAlternativeDelete = Alternative;
  4066. try
  4067. {
  4068. if (!IsSideLocalBrowser(Side))
  4069. {
  4070. DebugAssert(Terminal != NULL);
  4071. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  4072. std::unique_ptr<TStrings> PermanentFileList(TRemoteFileList::CloneStrings(FileList));
  4073. std::unique_ptr<TStringList> DeletedFiles(new TStringList());
  4074. DeletedFiles->CaseSensitive = DebugAlwaysTrue(!IsSideLocalBrowser(Side));
  4075. int Params = FLAGMASK(Alternative, dfAlternative);
  4076. try
  4077. {
  4078. DebugAssert(FDeletedFiles == NULL);
  4079. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles, DeletedFiles.get());
  4080. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  4081. FOnFileOperationFinished = FileDeleted;
  4082. FMoveToQueue = false;
  4083. Terminal->DeleteFiles(FileList, Params);
  4084. // Probably not needed for deleting, just for consistency with transfer code
  4085. if (FMoveToQueue)
  4086. {
  4087. Abort();
  4088. }
  4089. }
  4090. catch (EAbort &)
  4091. {
  4092. if (FMoveToQueue)
  4093. {
  4094. DeletedFiles->Sorted = true;
  4095. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  4096. {
  4097. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  4098. {
  4099. // We should always be deleting the first item => what can be used to optimize this code, if needed
  4100. DebugAssert(Index == 0);
  4101. PermanentFileList->Delete(Index);
  4102. Index--;
  4103. }
  4104. }
  4105. FMoveToQueue = false;
  4106. Configuration->Usage->Inc("MovesToBackgroundDelete");
  4107. TQueueItem * QueueItem = new TDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  4108. AddQueueItem(Queue, QueueItem, Terminal);
  4109. ClearOperationSelection(osRemote);
  4110. }
  4111. }
  4112. }
  4113. else
  4114. {
  4115. if (IsLocalBrowserMode())
  4116. {
  4117. Configuration->Usage->Inc(L"LocalLocalDeletes");
  4118. }
  4119. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  4120. try
  4121. {
  4122. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  4123. }
  4124. __finally
  4125. {
  4126. ReloadLocalDirectory();
  4127. }
  4128. }
  4129. FAlternativeDelete = false;
  4130. }
  4131. catch(...)
  4132. {
  4133. FAlternativeDelete = false;
  4134. DView->DiscardSavedSelection();
  4135. throw;
  4136. }
  4137. DView->RestoreSelection();
  4138. }
  4139. //---------------------------------------------------------------------------
  4140. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  4141. {
  4142. DebugAssert(Terminal);
  4143. DebugAssert(!IsLocalBrowserMode());
  4144. RemoteDirView->SaveSelection();
  4145. RemoteDirView->SaveSelectedNames();
  4146. try
  4147. {
  4148. if (Lock)
  4149. {
  4150. Terminal->LockFiles(FileList);
  4151. }
  4152. else
  4153. {
  4154. Terminal->UnlockFiles(FileList);
  4155. }
  4156. }
  4157. catch(...)
  4158. {
  4159. RemoteDirView->DiscardSavedSelection();
  4160. throw;
  4161. }
  4162. RemoteDirView->RestoreSelection();
  4163. }
  4164. //---------------------------------------------------------------------------
  4165. bool TCustomScpExplorerForm::DoDirectoryExists(void * Session, const UnicodeString & Directory)
  4166. {
  4167. TTerminal * ATerminal = (Session == NULL) ? Terminal : reinterpret_cast<TTerminal *>(Session);
  4168. bool Result =
  4169. IsActiveTerminal(ATerminal) &&
  4170. ATerminal->DirectoryExists(Directory);
  4171. return Result;
  4172. }
  4173. //---------------------------------------------------------------------------
  4174. bool TCustomScpExplorerForm::NeedSecondarySessionForRemoteCopy(TStrings * FileList)
  4175. {
  4176. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4177. return
  4178. !Terminal->IsCapable[fcRemoteCopy] ||
  4179. (CopyDirsOnSecondarySession && TRemoteFileList::AnyDirectory(FileList));
  4180. }
  4181. //---------------------------------------------------------------------------
  4182. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  4183. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  4184. bool NoConfirmation, bool Move)
  4185. {
  4186. DebugAssert(Terminal != NULL);
  4187. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  4188. DebugAssert(!IsLocalBrowserMode());
  4189. if (Session == NULL)
  4190. {
  4191. Session = Terminal;
  4192. }
  4193. bool TargetConfirmed = false;
  4194. if (Session == Terminal)
  4195. {
  4196. if (RemoteDriveView->DropTarget != NULL)
  4197. {
  4198. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  4199. TargetConfirmed = true;
  4200. }
  4201. else if (RemoteDirView->DropTarget != NULL)
  4202. {
  4203. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  4204. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  4205. TargetConfirmed = true;
  4206. }
  4207. else
  4208. {
  4209. Target = RemoteDirView->Path;
  4210. }
  4211. }
  4212. else
  4213. {
  4214. Target = GetSessionPath(Session, osRemote);
  4215. }
  4216. Target = UnixIncludeTrailingBackslash(Target);
  4217. if (FileList->Count == 1)
  4218. {
  4219. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  4220. }
  4221. else
  4222. {
  4223. FileMask = AnyMask;
  4224. }
  4225. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  4226. bool Result = true;
  4227. if (!NoConfirmation)
  4228. {
  4229. bool Multi = (FileList->Count > 1);
  4230. if (Move)
  4231. {
  4232. Result = DoRemoteMoveDialog(Multi, Target, FileMask, DoDirectoryExists);
  4233. }
  4234. else
  4235. {
  4236. std::unique_ptr<TStrings> Sessions(new TStringList);
  4237. std::unique_ptr<TStrings> Directories(new TStringList);
  4238. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  4239. for (int Index = 0; Index < SessionList->Count; Index++)
  4240. {
  4241. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  4242. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  4243. {
  4244. Sessions->AddObject(SessionList->Strings[Index], ASession);
  4245. Directories->Add(GetSessionPath(ASession, osRemote));
  4246. }
  4247. }
  4248. bool AnyDirectory = false;
  4249. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4250. if (CopyDirsOnSecondarySession && !Terminal->CommandSessionOpened) // optimization
  4251. {
  4252. for (int Index = 0; !AnyDirectory && (Index < FileList->Count); Index++)
  4253. {
  4254. AnyDirectory = DebugNotNull(dynamic_cast<TRemoteFile *>(FileList->Objects[Index]))->IsDirectory;
  4255. }
  4256. }
  4257. TDirectRemoteCopy AllowDirectCopy;
  4258. if (Terminal->CommandSessionOpened || !NeedSecondarySessionForRemoteCopy(FileList))
  4259. {
  4260. DebugAssert(DirectCopy);
  4261. AllowDirectCopy = drcAllow;
  4262. }
  4263. else if (Terminal->IsCapable[fcSecondaryShell])
  4264. {
  4265. DebugAssert(DirectCopy);
  4266. AllowDirectCopy = Terminal->IsCapable[fcRemoteCopy] ? drcConfirmCommandSessionDirs : drcConfirmCommandSession;
  4267. }
  4268. else
  4269. {
  4270. DebugAssert(!DirectCopy);
  4271. AllowDirectCopy = drcDisallow;
  4272. }
  4273. void * ASession = Session;
  4274. Result = DoRemoteCopyDialog(
  4275. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal,
  4276. DoDirectoryExists, TargetConfirmed);
  4277. Session = static_cast<TManagedTerminal *>(ASession);
  4278. }
  4279. }
  4280. return Result;
  4281. }
  4282. //---------------------------------------------------------------------------
  4283. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  4284. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  4285. {
  4286. DebugAssert(!IsLocalBrowserMode());
  4287. bool DirectCopy;
  4288. UnicodeString Target, FileMask;
  4289. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  4290. if (Result)
  4291. {
  4292. if (!Move && !DirectCopy)
  4293. {
  4294. Configuration->Usage->Inc("RemoteCopyTemp");
  4295. UnicodeString RootTempDir;
  4296. UnicodeString TempDir;
  4297. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  4298. TStrings * TemporaryFilesList = new TStringList();
  4299. try
  4300. {
  4301. TMakeLocalFileListParams MakeFileListParam;
  4302. MakeFileListParam.FileList = TemporaryFilesList;
  4303. MakeFileListParam.FileTimes = NULL;
  4304. MakeFileListParam.IncludeDirs = true;
  4305. MakeFileListParam.Recursive = false;
  4306. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4307. TTerminalManager::Instance()->ActiveSession = Session;
  4308. if (TemporaryFilesList->Count > 0)
  4309. {
  4310. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4311. CopyParam.FileMask = FileMask;
  4312. DebugAssert(!FAutoOperation);
  4313. FAutoOperation = true;
  4314. FMoveToQueue = false;
  4315. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4316. }
  4317. }
  4318. __finally
  4319. {
  4320. delete TemporaryFilesList;
  4321. FAutoOperation = false;
  4322. if (!RootTempDir.IsEmpty())
  4323. {
  4324. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  4325. }
  4326. }
  4327. }
  4328. else
  4329. {
  4330. RemoteDirView->SaveSelection();
  4331. RemoteDirView->SaveSelectedNames();
  4332. try
  4333. {
  4334. if (Move)
  4335. {
  4336. Configuration->Usage->Inc("RemoteMove");
  4337. Terminal->MoveFiles(FileList, Target, FileMask, false);
  4338. }
  4339. else
  4340. {
  4341. Configuration->Usage->Inc("RemoteCopyDirect");
  4342. DebugAssert(DirectCopy);
  4343. DebugAssert(Session == Terminal);
  4344. if (!NeedSecondarySessionForRemoteCopy(FileList) ||
  4345. Terminal->CommandSessionOpened ||
  4346. CommandSessionFallback())
  4347. {
  4348. Terminal->CopyFiles(FileList, Target, FileMask, false);
  4349. }
  4350. }
  4351. }
  4352. catch(...)
  4353. {
  4354. RemoteDirView->DiscardSavedSelection();
  4355. throw;
  4356. }
  4357. RemoteDirView->RestoreSelection();
  4358. }
  4359. }
  4360. return Result;
  4361. }
  4362. //---------------------------------------------------------------------------
  4363. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4364. const UnicodeString & Path, TRemoteProperties & Properties)
  4365. {
  4366. DebugAssert(!IsLocalBrowserMode());
  4367. Properties.Valid = Properties.Valid << vpEncrypt;
  4368. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4369. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4370. }
  4371. //---------------------------------------------------------------------------
  4372. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4373. {
  4374. Side = GetSide(Side);
  4375. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4376. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4377. UnicodeString Name = LoadStr(NEW_FOLDER);
  4378. int AllowedChanges =
  4379. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4380. bool SaveSettings = false;
  4381. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4382. {
  4383. TWindowLock Lock(this);
  4384. if (!IsSideLocalBrowser(Side))
  4385. {
  4386. if (SaveSettings)
  4387. {
  4388. GUIConfiguration->NewDirectoryProperties = Properties;
  4389. }
  4390. CreateRemoteDirectory(Name, Properties);
  4391. }
  4392. else
  4393. {
  4394. DirView(Side)->CreateDirectory(Name);
  4395. }
  4396. }
  4397. }
  4398. //---------------------------------------------------------------------------
  4399. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4400. {
  4401. TWindowLock Lock(this);
  4402. DirView(Side)->ExecuteHomeDirectory();
  4403. }
  4404. //---------------------------------------------------------------------------
  4405. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4406. {
  4407. DoOpenDirectoryDialog(odBrowse, Side);
  4408. }
  4409. //---------------------------------------------------------------------------
  4410. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4411. {
  4412. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4413. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4414. bool Result = !Path.IsEmpty();
  4415. if (Result)
  4416. {
  4417. TryOpenDirectory(Side, Path);
  4418. }
  4419. return Result;
  4420. }
  4421. //---------------------------------------------------------------------------
  4422. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4423. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4424. bool & Close)
  4425. {
  4426. // terminal can be already closed (e.g. dropped connection)
  4427. if (Terminal != NULL)
  4428. {
  4429. try
  4430. {
  4431. TCalculateSizeParams Params;
  4432. Params.Stats = &Stats;
  4433. Terminal->CalculateFilesSize(FileList, Size, Params);
  4434. }
  4435. catch(...)
  4436. {
  4437. if (!Terminal->Active)
  4438. {
  4439. Close = true;
  4440. }
  4441. throw;
  4442. }
  4443. }
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4447. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4448. bool & Close)
  4449. {
  4450. if ((Terminal != NULL) && // terminal can be already closed (e.g. dropped connection)
  4451. EnsureCommandSessionFallback(fcCalculatingChecksum))
  4452. {
  4453. Configuration->Usage->Inc(L"ChecksumCalculated");
  4454. try
  4455. {
  4456. Terminal->CalculateFilesChecksum(Alg, FileList, OnCalculatedChecksum);
  4457. }
  4458. catch(...)
  4459. {
  4460. if (!Terminal->Active)
  4461. {
  4462. Close = true;
  4463. }
  4464. throw;
  4465. }
  4466. }
  4467. }
  4468. //---------------------------------------------------------------------------
  4469. void TCustomScpExplorerForm::LoadFilesProperties(TStrings * FileList)
  4470. {
  4471. if (Terminal->LoadFilesProperties(FileList))
  4472. {
  4473. RemoteDirView->Invalidate();
  4474. }
  4475. }
  4476. //---------------------------------------------------------------------------
  4477. bool TCustomScpExplorerForm::CanCalculateChecksum()
  4478. {
  4479. return
  4480. Terminal->IsCapable[fcCalculatingChecksum] ||
  4481. (Terminal->IsCapable[fcSecondaryShell] && !Terminal->IsEncryptingFiles());
  4482. }
  4483. //---------------------------------------------------------------------------
  4484. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4485. {
  4486. bool Result;
  4487. if (!IsSideLocalBrowser(Side))
  4488. {
  4489. TRemoteTokenList * GroupList = NULL;
  4490. TRemoteTokenList * UserList = NULL;
  4491. try
  4492. {
  4493. TRemoteProperties CurrentProperties;
  4494. LoadFilesProperties(FileList);
  4495. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4496. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4497. if (CapableGroupChanging || CapableOwnerChanging)
  4498. {
  4499. if (CapableGroupChanging)
  4500. {
  4501. GroupList = Terminal->Groups->Duplicate();
  4502. }
  4503. if (CapableOwnerChanging)
  4504. {
  4505. UserList = Terminal->Users->Duplicate();
  4506. }
  4507. TRemoteDirectory * Files = Terminal->Files;
  4508. int Count = Files->Count;
  4509. if (Count > 100)
  4510. {
  4511. Count = 100;
  4512. }
  4513. for (int Index = 0; Index < Count; Index++)
  4514. {
  4515. TRemoteFile * File = Files->Files[Index];
  4516. if (CapableGroupChanging)
  4517. {
  4518. GroupList->AddUnique(File->Group);
  4519. }
  4520. if (CapableOwnerChanging)
  4521. {
  4522. UserList->AddUnique(File->Owner);
  4523. }
  4524. }
  4525. // if we haven't collected tokens for all files in current directory,
  4526. // make sure we collect them at least for all selected files.
  4527. // (note that so far the files in FileList has to be from current direcotry)
  4528. if (Count < Files->Count)
  4529. {
  4530. for (int Index = 0; Index < FileList->Count; Index++)
  4531. {
  4532. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4533. if (CapableGroupChanging)
  4534. {
  4535. GroupList->AddUnique(File->Group);
  4536. }
  4537. if (CapableOwnerChanging)
  4538. {
  4539. UserList->AddUnique(File->Owner);
  4540. }
  4541. }
  4542. }
  4543. }
  4544. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4545. bool CapableAclChanging = Terminal->IsCapable[fcAclChangingFiles];
  4546. if (CapableAclChanging && TRemoteFileList::AnyDirectory(FileList))
  4547. {
  4548. CapableAclChanging = false;
  4549. CurrentProperties.Valid = CurrentProperties.Valid >> vpRights;
  4550. }
  4551. int Flags = 0;
  4552. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4553. if (CapableAclChanging) Flags |= cpAcl;
  4554. if (CapableOwnerChanging) Flags |= cpOwner;
  4555. if (CapableGroupChanging) Flags |= cpGroup;
  4556. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4557. if (CanCalculateChecksum())
  4558. {
  4559. CalculateChecksumEvent = CalculateChecksum;
  4560. }
  4561. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4562. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4563. TRemoteProperties NewProperties = CurrentProperties;
  4564. Result =
  4565. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4566. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4567. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4568. CalculateSize, CalculateChecksumEvent);
  4569. if (Result)
  4570. {
  4571. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4572. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4573. }
  4574. }
  4575. __finally
  4576. {
  4577. delete GroupList;
  4578. delete UserList;
  4579. }
  4580. }
  4581. else
  4582. {
  4583. DirView(Side)->DisplayPropertiesMenu();
  4584. Result = true;
  4585. }
  4586. return Result;
  4587. }
  4588. //---------------------------------------------------------------------------
  4589. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4590. {
  4591. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4592. {
  4593. FIgnoreNextDialogChar = Key;
  4594. }
  4595. Key = 0;
  4596. }
  4597. //---------------------------------------------------------------------------
  4598. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4599. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4600. {
  4601. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4602. if (Command != NULL)
  4603. {
  4604. KeyProcessed(Key, Shift);
  4605. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4606. {
  4607. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4608. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4609. false, false, const_cast<TCustomCommandType *>(Command));
  4610. }
  4611. }
  4612. }
  4613. //---------------------------------------------------------------------------
  4614. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4615. {
  4616. if (!NonVisualDataModule->Busy)
  4617. {
  4618. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4619. {
  4620. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4621. }
  4622. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4623. {
  4624. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4625. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4626. {
  4627. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4628. // But so far it's not a problem, as it does what we want.
  4629. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4630. if (((Action->ShortCut == KeyShortCut) ||
  4631. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4632. AllowedAction(Action, aaShortCut))
  4633. {
  4634. // Has to be called before the action as the dialog char is already in queue.
  4635. // So when the action consumes message queue, we already need to have the
  4636. // FIgnoreNextDialogChar set
  4637. KeyProcessed(Key, Shift);
  4638. // Reset reference to previous component (when menu/toolbar was clicked).
  4639. // Needed to detect that action was invoked by keyboard shortcut
  4640. // in TNonVisualDataModule::ExplorerActionsExecute
  4641. Action->ActionComponent = NULL;
  4642. Action->Execute();
  4643. return;
  4644. }
  4645. }
  4646. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4647. {
  4648. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4649. {
  4650. KeyProcessed(Key, Shift);
  4651. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4652. return;
  4653. }
  4654. }
  4655. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4656. {
  4657. KeyProcessed(Key, Shift);
  4658. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4659. }
  4660. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4661. if (IsCustomShortCut(CustomShortCut))
  4662. {
  4663. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4664. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4665. if (WinConfiguration->SharedBookmarks != NULL)
  4666. {
  4667. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4668. if ((Bookmark != NULL) &&
  4669. OpenBookmark(FCurrentSide, Bookmark))
  4670. {
  4671. KeyProcessed(Key, Shift);
  4672. }
  4673. }
  4674. }
  4675. }
  4676. }
  4677. TForm::KeyDown(Key, Shift);
  4678. }
  4679. //---------------------------------------------------------------------------
  4680. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4681. {
  4682. bool OpenedTerminal = false;
  4683. UnicodeString ProtocolName;
  4684. UnicodeString ProtocolNameHint;
  4685. UnicodeString SecurityProtocolName;
  4686. UnicodeString DurationHint;
  4687. // See the comment in TScpCommanderForm::UpdateControls()
  4688. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4689. if (ActiveTerminal != NULL)
  4690. {
  4691. // Active is not enough here
  4692. if (ActiveTerminal->Status == ssOpened)
  4693. {
  4694. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4695. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4696. if (FileSystemInfo.ProtocolName.IsEmpty())
  4697. {
  4698. ProtocolName = SessionInfo.ProtocolName;
  4699. }
  4700. else
  4701. {
  4702. ProtocolName = FileSystemInfo.ProtocolName;
  4703. }
  4704. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4705. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4706. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4707. OpenedTerminal = true;
  4708. }
  4709. else if (ActiveTerminal->Status > ssClosed)
  4710. {
  4711. ProtocolName = LoadStr(STATUS_CONNECTING);
  4712. }
  4713. else
  4714. {
  4715. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4716. }
  4717. }
  4718. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4719. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4720. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4721. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4722. if (ProtocolStatusPanel->Caption != ProtocolName)
  4723. {
  4724. ProtocolStatusPanel->Caption = ProtocolName;
  4725. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4726. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4727. }
  4728. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4729. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4730. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4731. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4732. SecurityStatusPanel->Enabled = SecurityEnabled;
  4733. UnicodeString SecurityProtocolHint;
  4734. if (SecurityEnabled)
  4735. {
  4736. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4737. }
  4738. else
  4739. {
  4740. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4741. }
  4742. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4743. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4744. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4745. DurationStatusPanel->Hint = DurationHint;
  4746. UpdateStatusBar();
  4747. }
  4748. //---------------------------------------------------------------------------
  4749. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4750. {
  4751. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4752. DebugAssert(SessionStatusBar != NULL);
  4753. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4754. if (!FNote.IsEmpty())
  4755. {
  4756. NoteStatusPanel->Caption = FNote;
  4757. }
  4758. else
  4759. {
  4760. UpdateStatusPanelText(NoteStatusPanel);
  4761. }
  4762. NoteStatusPanel->Hint = FNoteHints;
  4763. UnicodeString LoginTime;
  4764. // See the comment in TScpCommanderForm::UpdateControls()
  4765. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4766. // Active is not enough here
  4767. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4768. {
  4769. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4770. LoginTime = FormatDateTimeSpan(Now() - SessionInfo.LoginTime);
  4771. }
  4772. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4773. DurationStatusPanel->Caption = LoginTime;
  4774. }
  4775. //---------------------------------------------------------------------------
  4776. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4777. {
  4778. Panel->Caption = L"";
  4779. }
  4780. //---------------------------------------------------------------------------
  4781. void __fastcall TCustomScpExplorerForm::Idle()
  4782. {
  4783. if (FShowing ||
  4784. // Particularly for
  4785. // - Standalone editing
  4786. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4787. // while "keeping remote directory up to date".
  4788. StandaloneOperation)
  4789. {
  4790. FEditorManager->Check();
  4791. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4792. // that needs to know if queue view is visible (and it may be closed after queue update)
  4793. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4794. }
  4795. if (FShowing)
  4796. {
  4797. if (!NonVisualDataModule->Busy &&
  4798. // Menu is opened or drag&drop is going on
  4799. (Mouse->Capture == NULL))
  4800. {
  4801. if (FRefreshRemoteDirectory)
  4802. {
  4803. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4804. {
  4805. Terminal->RefreshDirectory();
  4806. }
  4807. FRefreshRemoteDirectory = false;
  4808. }
  4809. if (FRefreshLocalDirectory)
  4810. {
  4811. ReloadLocalDirectory();
  4812. FRefreshLocalDirectory = false;
  4813. }
  4814. if (WinConfiguration->RefreshRemotePanel)
  4815. {
  4816. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4817. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4818. {
  4819. RemoteDirView->ReloadDirectory();
  4820. }
  4821. }
  4822. }
  4823. // TB2 shows accels on Alt key down, but hides it only after menu modal loop finishes.
  4824. // But if Alt is used to switch apps or for keyboard shortcut, the menu modal loop does not happen and accelerators stay displayed.
  4825. // It's difficult to fix this in TB2, as there's no "up" equivalent to CM_DIALOGKEY, which shows the accels.
  4826. // 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.
  4827. TTBCustomToolbar * MenuToolbar = DebugNotNull(dynamic_cast<TTBCustomToolbar *>(GetComponent(fcMenu)));
  4828. MenuToolbar->Idle();
  4829. }
  4830. if (FShowing || StandaloneOperation)
  4831. {
  4832. if (FQueueStatusInvalidated)
  4833. {
  4834. UpdateQueueStatus(false);
  4835. }
  4836. RefreshQueueItems();
  4837. }
  4838. if (FShowing)
  4839. {
  4840. UpdateStatusBar();
  4841. }
  4842. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4843. {
  4844. FClipboardFakeMonitorsPendingReset = false;
  4845. FClipboardFakeMonitors.reset(NULL);
  4846. }
  4847. FIgnoreNextDialogChar = 0;
  4848. }
  4849. //---------------------------------------------------------------------------
  4850. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4851. {
  4852. try
  4853. {
  4854. FUserActionTimer->Enabled = false;
  4855. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4856. {
  4857. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4858. {
  4859. FPendingQueueActionItem->ProcessUserAction();
  4860. }
  4861. }
  4862. }
  4863. __finally
  4864. {
  4865. FPendingQueueActionItem = NULL;
  4866. }
  4867. }
  4868. //---------------------------------------------------------------------------
  4869. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4870. {
  4871. if (WinConfiguration->MinimizeToTray)
  4872. {
  4873. UpdateTrayIcon();
  4874. FTrayIcon->Visible = true;
  4875. if (Visible)
  4876. {
  4877. ShowWindow(Handle, SW_HIDE);
  4878. }
  4879. }
  4880. }
  4881. //---------------------------------------------------------------------------
  4882. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4883. {
  4884. // WORKAROUND
  4885. // When restoring maximized window from minimization,
  4886. // rarely some controls do not align properly.
  4887. // Two instances seen (both for Commander):
  4888. // - When restoring, window is temporarily narrower (not maximized),
  4889. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4890. // Once maximized already, top dock shinks back, but the session PageControl,
  4891. // do not align up, leaving space between TopDock and PageControl.
  4892. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4893. for (int Index = 0; Index < ControlCount; Index++)
  4894. {
  4895. RealignControl(Controls[Index]);
  4896. }
  4897. if (FTrayIcon->Visible)
  4898. {
  4899. FTrayIcon->Visible = false;
  4900. if (Visible)
  4901. {
  4902. ShowWindow(Handle, SW_SHOW);
  4903. }
  4904. }
  4905. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4906. {
  4907. FNeedSession = false;
  4908. NonVisualDataModule->StartBusy();
  4909. try
  4910. {
  4911. NeedSession(true);
  4912. }
  4913. __finally
  4914. {
  4915. NonVisualDataModule->EndBusy();
  4916. }
  4917. }
  4918. }
  4919. //---------------------------------------------------------------------------
  4920. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4921. {
  4922. FTrayIcon->Hint = GetMainForm()->Caption;
  4923. }
  4924. //---------------------------------------------------------------------------
  4925. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4926. {
  4927. UpdateTrayIcon();
  4928. }
  4929. //---------------------------------------------------------------------------
  4930. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4931. {
  4932. // workaround
  4933. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4934. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4935. // But WM_ACTIVATEAPP message can be received even when
  4936. // the main window is minimized to the tray and internal editor window is focused
  4937. // (after another application was previously active)
  4938. if (::IsIconic(Handle))
  4939. {
  4940. if (!IsAppIconic())
  4941. {
  4942. SetAppIconic(true);
  4943. }
  4944. }
  4945. ::ApplicationRestore();
  4946. Application->BringToFront();
  4947. }
  4948. //---------------------------------------------------------------------------
  4949. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4950. {
  4951. RestoreApp();
  4952. }
  4953. //---------------------------------------------------------------------------
  4954. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4955. {
  4956. if (OpenInNewWindow())
  4957. {
  4958. ExecuteNewInstance(SessionUrl);
  4959. }
  4960. else
  4961. {
  4962. TTerminalManager::Instance()->NewSession(SessionUrl);
  4963. }
  4964. }
  4965. //---------------------------------------------------------------------------
  4966. void TCustomScpExplorerForm::NewTab(TOperationSide, bool)
  4967. {
  4968. NewSession();
  4969. }
  4970. //---------------------------------------------------------------------------
  4971. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4972. {
  4973. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4974. StoredSessions->NewSession(SessionName, SessionData);
  4975. // modified only, explicit
  4976. StoredSessions->Save(false, true);
  4977. // encode session name because of slashes in hierarchical sessions
  4978. return EncodeUrlString(SessionName);
  4979. }
  4980. //---------------------------------------------------------------------------
  4981. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4982. {
  4983. // current working directories become defaults here, what is not right
  4984. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4985. return SaveHiddenDuplicateSession(SessionData.get());
  4986. }
  4987. //---------------------------------------------------------------------------
  4988. void __fastcall TCustomScpExplorerForm::DuplicateTab()
  4989. {
  4990. if (OpenInNewWindow())
  4991. {
  4992. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4993. }
  4994. else
  4995. {
  4996. // current working directories become defaults here, what is not right
  4997. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4998. TTerminalManager * Manager = TTerminalManager::Instance();
  4999. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  5000. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  5001. // We definitely want these
  5002. ASession->Disconnected = ManagedSession->Disconnected;
  5003. // Not sure about these two
  5004. ASession->Permanent = ManagedSession->Permanent;
  5005. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  5006. Manager->ActiveSession = ASession;
  5007. }
  5008. }
  5009. //---------------------------------------------------------------------------
  5010. void __fastcall TCustomScpExplorerForm::RenameTab()
  5011. {
  5012. UnicodeString Name = ManagedSession->SessionData->SessionName;
  5013. if (InputDialog(LoadStr(RENAME_TAB_TITLE), LoadStr(RENAME_TAB_PROMPT), Name, HELP_TAB_RENAME) &&
  5014. // When submitting the default name, do not fix it
  5015. (Name != ManagedSession->SessionData->SessionName))
  5016. {
  5017. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  5018. TSessionData::ValidateName(Name);
  5019. // This is inconsistent with how color (for example) is handled.
  5020. ManagedSession->SessionData->Name = Name;
  5021. UpdateControls();
  5022. // Add/Remove distinguishing paths from sessions of the same name.
  5023. SessionListChanged();
  5024. }
  5025. }
  5026. //---------------------------------------------------------------------------
  5027. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  5028. {
  5029. DebugAssert(Queue != NULL);
  5030. bool Result = Queue->IsEmpty;
  5031. if (!Result)
  5032. {
  5033. SetFocus();
  5034. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  5035. }
  5036. return Result;
  5037. }
  5038. //---------------------------------------------------------------------------
  5039. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  5040. {
  5041. return CanCloseQueue(FQueue);
  5042. }
  5043. //---------------------------------------------------------------------------
  5044. void __fastcall TCustomScpExplorerForm::CloseTab()
  5045. {
  5046. if (CanCloseQueue())
  5047. {
  5048. TTerminalManager::Instance()->FreeActiveTerminal();
  5049. }
  5050. }
  5051. //---------------------------------------------------------------------------
  5052. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  5053. {
  5054. if (CanCloseQueue())
  5055. {
  5056. TTerminalManager::Instance()->DisconnectActiveTerminal();
  5057. }
  5058. }
  5059. //---------------------------------------------------------------------------
  5060. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  5061. {
  5062. DetachTerminal(Terminal);
  5063. RemoteDirView->Terminal = Terminal;
  5064. UpdateRemotePathComboBox(false);
  5065. InitStatusBar();
  5066. UpdateControls();
  5067. }
  5068. //---------------------------------------------------------------------------
  5069. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  5070. {
  5071. InitStatusBar();
  5072. }
  5073. //---------------------------------------------------------------------------
  5074. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  5075. {
  5076. if (DebugAlwaysTrue(!Terminal->Active))
  5077. {
  5078. TTerminalManager::Instance()->ReconnectActiveTerminal();
  5079. }
  5080. }
  5081. //---------------------------------------------------------------------------
  5082. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  5083. {
  5084. if (OpenInNewWindow())
  5085. {
  5086. // encode session name because of slashes in hierarchical sessions
  5087. ExecuteNewInstance(EncodeUrlString(Data->Name));
  5088. }
  5089. else
  5090. {
  5091. TTerminalManager * Manager = TTerminalManager::Instance();
  5092. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  5093. Manager->ActiveSession = Terminal;
  5094. }
  5095. }
  5096. //---------------------------------------------------------------------------
  5097. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  5098. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  5099. {
  5100. TTerminalManager * Manager = TTerminalManager::Instance();
  5101. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5102. // This asks for a master password. Maybe we should postpone asking until a connection is actually opened.
  5103. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  5104. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  5105. {
  5106. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  5107. // FirstSession can be null, if none of the workspace sites exist anymore
  5108. // or if all workspace sessions are not suported by the interface
  5109. // (when trying to open all local-local workspace in "explorer" interface)
  5110. if (FirstSession != NULL)
  5111. {
  5112. if (!ConnectFirstTerminal)
  5113. {
  5114. FirstSession->Disconnected = true;
  5115. FirstSession->DisconnectedTemporarily = true;
  5116. }
  5117. Manager->ActiveSession = FirstSession;
  5118. }
  5119. }
  5120. }
  5121. //---------------------------------------------------------------------------
  5122. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  5123. {
  5124. if (OpenInNewWindow())
  5125. {
  5126. ExecuteNewInstance(Name);
  5127. }
  5128. else
  5129. {
  5130. DoOpenFolderOrWorkspace(Name, true, false);
  5131. }
  5132. }
  5133. //---------------------------------------------------------------------------
  5134. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  5135. bool &CanClose)
  5136. {
  5137. AppLog(L"Windows close query");
  5138. // See the comment in CloseApp()
  5139. if (NonVisualDataModule->Busy)
  5140. {
  5141. CanClose = false;
  5142. }
  5143. else
  5144. {
  5145. TTerminalManager * Manager = TTerminalManager::Instance();
  5146. int ActiveSessions = 0;
  5147. for (int Index = 0; Index < Manager->Count; Index++)
  5148. {
  5149. if (Manager->Sessions[Index]->Active)
  5150. {
  5151. ActiveSessions++;
  5152. }
  5153. }
  5154. // Confirm, when there's at least one active remote session or
  5155. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  5156. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  5157. WinConfiguration->ConfirmClosingSession)
  5158. {
  5159. unsigned int Result;
  5160. TMessageParams Params(mpNeverAskAgainCheck);
  5161. UnicodeString Message;
  5162. int Answers = qaOK | qaCancel;
  5163. // The current session is the only active session
  5164. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  5165. {
  5166. if (!WinConfiguration->AutoSaveWorkspace)
  5167. {
  5168. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  5169. }
  5170. else
  5171. {
  5172. Message = LoadStr(CLOSE_SESSION);
  5173. }
  5174. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  5175. }
  5176. // Multiple active sessions or one active session, but it's not the current one
  5177. else if (ActiveSessions > 0)
  5178. {
  5179. if (!WinConfiguration->AutoSaveWorkspace)
  5180. {
  5181. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  5182. }
  5183. else
  5184. {
  5185. Message = LoadStr(CLOSE_SESSIONS);
  5186. }
  5187. }
  5188. // Multiple tabs, but all are inactive or local, and saving of worspace is not enabled
  5189. else
  5190. {
  5191. DebugAlwaysTrue(Manager->Count > 1);
  5192. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  5193. Message = LoadStr(CLOSE_WORKSPACE);
  5194. }
  5195. UnicodeString Note;
  5196. if (WinConfiguration->AutoSaveWorkspace)
  5197. {
  5198. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  5199. }
  5200. else
  5201. {
  5202. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  5203. Answers = qaYes | qaNo | qaCancel;
  5204. }
  5205. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  5206. SetFocus();
  5207. Result = MessageDialog(Message, qtConfirmation,
  5208. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  5209. if (Result == qaNeverAskAgain)
  5210. {
  5211. WinConfiguration->ConfirmClosingSession = false;
  5212. }
  5213. if (Result == qaNo)
  5214. {
  5215. CanClose = SaveWorkspace(true);
  5216. // note that the workspace will be saved redundatly again from FormClose
  5217. }
  5218. else
  5219. {
  5220. CanClose =
  5221. (Result == qaOK) ||
  5222. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  5223. (Result == qaNeverAskAgain);
  5224. }
  5225. }
  5226. if (CanClose && HasActiveTerminal())
  5227. {
  5228. CanClose = CanCloseQueue();
  5229. }
  5230. }
  5231. if (CanClose)
  5232. {
  5233. CanClose =
  5234. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  5235. FEditorManager->CloseExternalFilesWithoutProcess();
  5236. if (CanClose)
  5237. {
  5238. while (CanClose && (FLocalEditors->Count > 0))
  5239. {
  5240. int PrevCount = FLocalEditors->Count;
  5241. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  5242. CanClose = (FLocalEditors->Count < PrevCount);
  5243. }
  5244. if (CanClose)
  5245. {
  5246. CanClose = FEditorManager->Empty(true);
  5247. if (!CanClose)
  5248. {
  5249. SetFocus();
  5250. CanClose =
  5251. (MessageDialog(
  5252. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  5253. }
  5254. }
  5255. }
  5256. }
  5257. }
  5258. //---------------------------------------------------------------------------
  5259. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  5260. {
  5261. TForm * Form = dynamic_cast<TForm *>(Sender);
  5262. DebugAssert(Form != NULL);
  5263. Form->Close();
  5264. }
  5265. //---------------------------------------------------------------------------
  5266. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  5267. {
  5268. TForm * Form = dynamic_cast<TForm *>(Sender);
  5269. delete Form;
  5270. }
  5271. //---------------------------------------------------------------------------
  5272. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  5273. {
  5274. while (FLocalEditors->Count > 0)
  5275. {
  5276. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  5277. }
  5278. }
  5279. //---------------------------------------------------------------------------
  5280. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  5281. TObject *Sender)
  5282. {
  5283. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  5284. try
  5285. {
  5286. SetProperties(osRemote, FileList);
  5287. }
  5288. __finally
  5289. {
  5290. delete FileList;
  5291. }
  5292. }
  5293. //---------------------------------------------------------------------------
  5294. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  5295. {
  5296. if (value)
  5297. {
  5298. if (Component == fcCustomCommandsBand)
  5299. {
  5300. UpdateCustomCommandsToolbar();
  5301. }
  5302. if (Component == fcQueueFileList)
  5303. {
  5304. DebugAssert(!QueueFileListSplitter->Visible);
  5305. AdjustQueueLayout();
  5306. UpdateQueueFileList();
  5307. }
  5308. }
  5309. }
  5310. //---------------------------------------------------------------------------
  5311. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5312. {
  5313. int MinHeightLimit =
  5314. GetStaticQueuePanelComponentsHeight() +
  5315. QueueFileListSplitter->Height +
  5316. QueueFileList->Height +
  5317. GetMinQueueViewHeight();
  5318. if (QueuePanel->ClientHeight < MinHeightLimit)
  5319. {
  5320. QueuePanel->ClientHeight = MinHeightLimit;
  5321. }
  5322. }
  5323. //---------------------------------------------------------------------------
  5324. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5325. {
  5326. TControl * Control = GetComponent(Component);
  5327. DebugAssert(Control);
  5328. bool Changed = (Control->Visible != value);
  5329. if (Changed)
  5330. {
  5331. ComponentShowing(Component, value);
  5332. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5333. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5334. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5335. if (value)
  5336. {
  5337. int RemainingHeight = Control->Parent->ClientHeight;
  5338. int RemainingWidth = Control->Parent->ClientWidth;
  5339. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5340. {
  5341. TControl * ChildControl = Control->Parent->Controls[i];
  5342. if (ChildControl->Visible)
  5343. {
  5344. switch (ChildControl->Align)
  5345. {
  5346. case alTop:
  5347. case alBottom:
  5348. RemainingHeight -= ChildControl->Height;
  5349. break;
  5350. case alLeft:
  5351. case alRight:
  5352. RemainingWidth -= ChildControl->Width;
  5353. break;
  5354. }
  5355. }
  5356. }
  5357. int Reserve = ScaleByTextHeight(this, 32);
  5358. // queue in explorer, trees in commander
  5359. if (Control->Height > RemainingHeight - Reserve)
  5360. {
  5361. Control->Height = RemainingHeight / 2;
  5362. }
  5363. if (Control->Width > RemainingWidth - Reserve)
  5364. {
  5365. Control->Width = RemainingWidth / 2;
  5366. }
  5367. }
  5368. Control->Visible = value;
  5369. if (WasFocused && Visible)
  5370. {
  5371. DirView(osCurrent)->SetFocus();
  5372. }
  5373. FixControlsPlacement();
  5374. }
  5375. }
  5376. //---------------------------------------------------------------------------
  5377. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5378. {
  5379. TControl * Control = GetComponent(Component);
  5380. if (Control == NULL)
  5381. {
  5382. return false;
  5383. }
  5384. else
  5385. {
  5386. return Control->Visible;
  5387. }
  5388. }
  5389. //---------------------------------------------------------------------------
  5390. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5391. {
  5392. bool Result;
  5393. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5394. {
  5395. Result = !IsUWP();
  5396. }
  5397. else
  5398. {
  5399. Result = true;
  5400. }
  5401. return Result;
  5402. }
  5403. //---------------------------------------------------------------------------
  5404. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5405. {
  5406. if (DirView->ItemFocused != NULL)
  5407. {
  5408. DirView->ItemFocused->MakeVisible(false);
  5409. }
  5410. }
  5411. //---------------------------------------------------------------------------
  5412. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5413. {
  5414. MakeFocusedItemVisible(RemoteDirView);
  5415. QueueSplitter->Visible = QueuePanel->Visible;
  5416. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5417. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5418. TControl * TopControlsOrder[] =
  5419. { TopDock, MessageDock, SessionsPageControl };
  5420. SetVerticalControlsOrder(TopControlsOrder, LENOF(TopControlsOrder));
  5421. TControl * QueueControlsOrder[] =
  5422. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5423. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5424. }
  5425. //---------------------------------------------------------------------------
  5426. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5427. {
  5428. switch (Component) {
  5429. case fcStatusBar: return RemoteStatusBar;
  5430. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5431. case fcQueueView: return QueuePanel;
  5432. case fcQueueToolbar: return QueueDock;
  5433. case fcRemoteTree: return RemoteDrivePanel;
  5434. case fcSessionsTabs: return SessionsPageControl;
  5435. case fcQueueFileList: return QueueFileList;
  5436. default: return NULL;
  5437. }
  5438. }
  5439. //---------------------------------------------------------------------------
  5440. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5441. TObject *Sender, TListColumn *Column, TPoint &Point)
  5442. {
  5443. DebugAssert(NonVisualDataModule && Column && Sender);
  5444. NonVisualDataModule->ListColumn = Column;
  5445. TPopupMenu * DirViewColumnMenu;
  5446. if (Sender == DirView(osOther))
  5447. {
  5448. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5449. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible = (Column->Index == uvName);
  5450. bool SizeColumn = (Column->Index == uvSize);
  5451. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible = SizeColumn;
  5452. NonVisualDataModule->RemoteCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5453. }
  5454. else
  5455. {
  5456. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5457. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible = (Column->Index == dvName);
  5458. bool SizeColumn = (Column->Index == dvSize);
  5459. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible = SizeColumn;
  5460. NonVisualDataModule->LocalCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5461. }
  5462. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5463. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5464. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5465. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5466. }
  5467. //---------------------------------------------------------------------------
  5468. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5469. TObject *Sender, TListItem *Item, bool &AllowExec)
  5470. {
  5471. DoDirViewExecFile(Sender, Item, AllowExec);
  5472. }
  5473. //---------------------------------------------------------------------------
  5474. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5475. TListItem * Item, bool & AllowExec)
  5476. {
  5477. DebugAssert(Sender && Item && Configuration);
  5478. DebugAssert(AllowExec);
  5479. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5480. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5481. bool Remote = !IsSideLocalBrowser(Side);
  5482. DebugAssert(Item == ADirView->ItemFocused);
  5483. bool IsDirectory = ADirView->ItemIsDirectory(Item);
  5484. TResolvedDoubleClickAction Action;
  5485. if (FForceExecution)
  5486. {
  5487. Action = IsDirectory ? rdcaChangeDir : rdcaOpen;
  5488. }
  5489. else
  5490. {
  5491. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  5492. Action = WinConfiguration->ResolveDoubleClickAction(IsDirectory, ATerminal);
  5493. }
  5494. if (Action == rdcaCopy)
  5495. {
  5496. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5497. UnlockWindow();
  5498. try
  5499. {
  5500. if (IsLocalBrowserMode())
  5501. {
  5502. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5503. }
  5504. else
  5505. {
  5506. if (HasActiveTerminal())
  5507. {
  5508. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5509. }
  5510. }
  5511. }
  5512. __finally
  5513. {
  5514. LockWindow();
  5515. }
  5516. AllowExec = false;
  5517. }
  5518. else if (Action == rdcaEdit)
  5519. {
  5520. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5521. {
  5522. ExecuteFile(Side, efDefaultEditor);
  5523. AllowExec = false;
  5524. }
  5525. }
  5526. else if (Action == rdcaOpen)
  5527. {
  5528. if (DebugAlwaysTrue(!IsDirectory) && Remote && !WinConfiguration->DisableOpenEdit)
  5529. {
  5530. ExecuteFile(osRemote, efShell);
  5531. AllowExec = false;
  5532. }
  5533. }
  5534. }
  5535. //---------------------------------------------------------------------------
  5536. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5537. {
  5538. return ((Side == osRemote) || (Side == osCurrent));
  5539. }
  5540. //---------------------------------------------------------------------------
  5541. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5542. {
  5543. DebugFail();
  5544. }
  5545. //---------------------------------------------------------------------------
  5546. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5547. {
  5548. DebugFail();
  5549. }
  5550. //---------------------------------------------------------------------------
  5551. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5552. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5553. {
  5554. TSynchronizeParamType Params;
  5555. Params.LocalDirectory = LocalDirectory;
  5556. Params.RemoteDirectory = RemoteDirectory;
  5557. int UnusedParams =
  5558. (GUIConfiguration->SynchronizeParams &
  5559. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5560. TTerminal::spCaseSensitive | TTerminal::spMirror | TTerminal::spByChecksum));
  5561. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5562. Params.Options = GUIConfiguration->SynchronizeOptions;
  5563. bool SaveSettings = false;
  5564. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5565. &DoSynchronizeTooManyDirectories);
  5566. DebugAssert(FSynchronizeController == NULL);
  5567. FSynchronizeController = &Controller;
  5568. bool Result;
  5569. try
  5570. {
  5571. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5572. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5573. int Options =
  5574. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5575. DebugAssert(FOnFeedSynchronizeError == NULL);
  5576. DebugAssert(FOnSynchronizeAbort == NULL);
  5577. DebugAssert(FSynchronizeTerminal == NULL);
  5578. FSynchronizeTerminal = Terminal;
  5579. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5580. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5581. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5582. if (Result)
  5583. {
  5584. if (SaveSettings)
  5585. {
  5586. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5587. GUIConfiguration->SynchronizeOptions = Params.Options;
  5588. }
  5589. else
  5590. {
  5591. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5592. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5593. FLAGSET(Params.Options, soSynchronize))
  5594. {
  5595. GUIConfiguration->SynchronizeOptions =
  5596. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5597. soSynchronize;
  5598. }
  5599. }
  5600. LocalDirectory = Params.LocalDirectory;
  5601. RemoteDirectory = Params.RemoteDirectory;
  5602. }
  5603. }
  5604. __finally
  5605. {
  5606. FSynchronizeController = NULL;
  5607. DebugAssert(FOnFeedSynchronizeError == NULL);
  5608. FOnFeedSynchronizeError = NULL;
  5609. DebugAssert(FOnSynchronizeAbort == NULL);
  5610. FOnSynchronizeAbort = NULL;
  5611. FSynchronizeTerminal = NULL;
  5612. }
  5613. return Result;
  5614. }
  5615. //---------------------------------------------------------------------------
  5616. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5617. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5618. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5619. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5620. TSynchronizeOptions * Options, bool Full)
  5621. {
  5622. // Keep-up-to-date mode
  5623. if (Terminal->Status == ssOpened)
  5624. {
  5625. try
  5626. {
  5627. int PParams = Params.Params;
  5628. if (!Full)
  5629. {
  5630. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5631. if (FLAGSET(Params.Options, soRecurse))
  5632. {
  5633. PParams |= TTerminal::spSubDirs;
  5634. }
  5635. }
  5636. else
  5637. {
  5638. // if keepuptodate is non-recursive,
  5639. // full sync before has to be non-recursive as well
  5640. if (FLAGCLEAR(Params.Options, soRecurse))
  5641. {
  5642. PParams |= TTerminal::spNoRecurse;
  5643. }
  5644. }
  5645. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5646. PParams, Checklist, Options);
  5647. }
  5648. catch (Exception & E)
  5649. {
  5650. if (!Terminal->Active)
  5651. {
  5652. ShowExtendedExceptionEx(Terminal, &E);
  5653. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5654. if (!Terminal->Active)
  5655. {
  5656. throw;
  5657. }
  5658. }
  5659. else
  5660. {
  5661. if (FLAGSET(Params.Options, soContinueOnError) &&
  5662. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5663. {
  5664. // noop, already logged in MoreMessageDialog
  5665. }
  5666. else
  5667. {
  5668. // We get mostly EAbort here, so this is noop.
  5669. // Exception is an error when listing directories while looking for differences.
  5670. ShowExtendedExceptionEx(Terminal, &E);
  5671. throw;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. }
  5677. //---------------------------------------------------------------------------
  5678. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5679. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5680. const UnicodeString ErrorStr)
  5681. {
  5682. if (!Directory.IsEmpty())
  5683. {
  5684. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5685. }
  5686. else
  5687. {
  5688. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5689. }
  5690. }
  5691. //---------------------------------------------------------------------------
  5692. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5693. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5694. {
  5695. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5696. {
  5697. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5698. }
  5699. else
  5700. {
  5701. TMessageParams Params(mpNeverAskAgainCheck);
  5702. unsigned int Result = MessageDialog(
  5703. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5704. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5705. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5706. {
  5707. MaxDirectories *= 2;
  5708. if (Result == qaNeverAskAgain)
  5709. {
  5710. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5711. }
  5712. }
  5713. else
  5714. {
  5715. Abort();
  5716. }
  5717. }
  5718. }
  5719. //---------------------------------------------------------------------------
  5720. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5721. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5722. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5723. TSynchronizeOptions * Options)
  5724. {
  5725. // Keep-up-to-date mode
  5726. DebugAssert(!FAutoOperation);
  5727. void * BatchStorage;
  5728. BatchStart(BatchStorage);
  5729. FAutoOperation = true;
  5730. bool AnyOperation = false;
  5731. TDateTime StartTime = Now();
  5732. TSynchronizeChecklist * AChecklist = NULL;
  5733. try
  5734. {
  5735. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5736. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5737. {
  5738. FSynchronizeProgressForm->Start();
  5739. }
  5740. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5741. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5742. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5743. Options);
  5744. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5745. SAFE_DESTROY(FSynchronizeProgressForm);
  5746. AnyOperation = (AChecklist->CheckedCount > 0);
  5747. if (AnyOperation)
  5748. {
  5749. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5750. CreateProgressForm(&SynchronizeProgress);
  5751. try
  5752. {
  5753. Terminal->SynchronizeApply(
  5754. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5755. SynchronizeProcessedItem, NULL, NULL, NULL);
  5756. }
  5757. __finally
  5758. {
  5759. DestroyProgressForm();
  5760. }
  5761. }
  5762. }
  5763. __finally
  5764. {
  5765. if (Checklist == NULL)
  5766. {
  5767. delete AChecklist;
  5768. }
  5769. else
  5770. {
  5771. *Checklist = AChecklist;
  5772. }
  5773. FAutoOperation = false;
  5774. SAFE_DESTROY(FSynchronizeProgressForm);
  5775. BatchEnd(BatchStorage);
  5776. ReloadLocalDirectory();
  5777. if (AnyOperation)
  5778. {
  5779. OperationComplete(StartTime);
  5780. }
  5781. }
  5782. }
  5783. //---------------------------------------------------------------------------
  5784. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5785. {
  5786. // can be called from command line
  5787. return Visible &&
  5788. ((DirView(osRemote)->SelCount > 0) ||
  5789. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5790. }
  5791. //---------------------------------------------------------------------------
  5792. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5793. {
  5794. LogSynchronizeEvent(Terminal, Message);
  5795. }
  5796. //---------------------------------------------------------------------------
  5797. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5798. int Params, TSynchronizeOptions & Options)
  5799. {
  5800. DebugAssert(!IsLocalBrowserMode());
  5801. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5802. {
  5803. Options.Filter = new TStringList();
  5804. Options.Filter->CaseSensitive = false;
  5805. Options.Filter->Duplicates = Types::dupAccept;
  5806. if (DirView(osRemote)->SelCount > 0)
  5807. {
  5808. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5809. }
  5810. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5811. {
  5812. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5813. }
  5814. Options.Filter->Sort();
  5815. }
  5816. }
  5817. //---------------------------------------------------------------------------
  5818. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5819. {
  5820. TCopyParamType Defaults;
  5821. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5822. ConfigStorage->AccessMode = smRead;
  5823. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5824. {
  5825. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5826. }
  5827. ConfigStorage.reset(NULL);
  5828. std::unique_ptr<TStringList> Options(new TStringList());
  5829. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5830. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5831. UnicodeString Result;
  5832. if (Options->Count > 0)
  5833. {
  5834. Result =
  5835. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5836. }
  5837. return Result;
  5838. }
  5839. //---------------------------------------------------------------------------
  5840. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5841. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5842. {
  5843. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5844. UnicodeString AdditionalParams =
  5845. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5846. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5847. SerializeCopyParamForCommandLine(CopyParams),
  5848. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5849. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5850. ExecuteNewInstance(SessionName, AdditionalParams);
  5851. }
  5852. //---------------------------------------------------------------------------
  5853. struct TSynchronizeParams
  5854. {
  5855. UnicodeString LocalDirectory;
  5856. UnicodeString RemoteDirectory;
  5857. TSynchronizeMode Mode;
  5858. TSynchronizeChecklist * Checklist;
  5859. int Params;
  5860. TCopyParamType * CopyParam;
  5861. TDateTime CollectElapsed;
  5862. TDateTime * StartTime;
  5863. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5864. };
  5865. //---------------------------------------------------------------------------
  5866. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5867. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5868. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5869. {
  5870. DebugAssert(!FAutoOperation);
  5871. void * BatchStorage;
  5872. BatchStart(BatchStorage);
  5873. FAutoOperation = true;
  5874. TFileOperationStatistics Statistics;
  5875. TDateTime Start = Now();
  5876. try
  5877. {
  5878. Params.OnProcessedItem = OnProcessedItem;
  5879. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5880. CreateProgressForm(&SynchronizeProgress);
  5881. Terminal->SynchronizeApply(
  5882. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5883. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5884. &Statistics);
  5885. }
  5886. __finally
  5887. {
  5888. Params.OnProcessedItem = NULL;
  5889. FAutoOperation = false;
  5890. DestroyProgressForm();
  5891. BatchEnd(BatchStorage);
  5892. ReloadLocalDirectory();
  5893. }
  5894. if (WinConfiguration->SynchronizeSummary)
  5895. {
  5896. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5897. // The statistics should be 0 anyway in this case
  5898. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5899. {
  5900. Message += L"\n";
  5901. if (Statistics.FilesUploaded > 0)
  5902. {
  5903. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5904. }
  5905. if (Statistics.FilesDownloaded > 0)
  5906. {
  5907. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5908. }
  5909. if (Statistics.FilesDeletedLocal > 0)
  5910. {
  5911. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5912. }
  5913. if (Statistics.FilesDeletedRemote > 0)
  5914. {
  5915. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5916. }
  5917. }
  5918. TDateTime Elapsed = (Now() - Start);
  5919. Message +=
  5920. L"\n" +
  5921. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Params.CollectElapsed))) + L"\n" +
  5922. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Elapsed)));
  5923. TMessageParams Params(mpNeverAskAgainCheck);
  5924. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5925. if (Result == qaNeverAskAgain)
  5926. {
  5927. WinConfiguration->SynchronizeSummary = false;
  5928. }
  5929. }
  5930. }
  5931. //---------------------------------------------------------------------------
  5932. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5933. {
  5934. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5935. {
  5936. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5937. }
  5938. // Not set in keep-up-to-date mode - Synchronize() method
  5939. if (Token != NULL)
  5940. {
  5941. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5942. if (Params.OnProcessedItem != NULL)
  5943. {
  5944. Params.OnProcessedItem(NULL, ChecklistItem);
  5945. }
  5946. }
  5947. }
  5948. //---------------------------------------------------------------------------
  5949. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5950. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5951. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5952. {
  5953. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5954. *Params.StartTime = Now();
  5955. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5956. }
  5957. //---------------------------------------------------------------------------
  5958. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5959. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5960. {
  5961. // terminal can be already closed (e.g. dropped connection)
  5962. if (Terminal != NULL)
  5963. {
  5964. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5965. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5966. }
  5967. }
  5968. //---------------------------------------------------------------------------
  5969. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5970. TOperationSide Side, TStrings * FileList, const UnicodeString & NewFileName, bool TargetIsDirectory, void * Token)
  5971. {
  5972. DebugAssert(!IsLocalBrowserMode());
  5973. TAutoBatch AutoBatch(this);
  5974. TAutoFlag AutoOperationFlag(FAutoOperation);
  5975. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5976. if (Side == osRemote)
  5977. {
  5978. UnicodeString Target;
  5979. UnicodeString FileMask;
  5980. if (TargetIsDirectory)
  5981. {
  5982. Target = NewFileName;
  5983. Terminal->CreateTargetDirectory(Target, faDirectory, Params.CopyParam);
  5984. }
  5985. else
  5986. {
  5987. Target = UnixExtractFileDir(NewFileName);
  5988. FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5989. }
  5990. RemoteDirView->SaveSelection();
  5991. RemoteDirView->SaveSelectedNames();
  5992. try
  5993. {
  5994. Terminal->MoveFiles(FileList, Target, FileMask, false);
  5995. }
  5996. catch(...)
  5997. {
  5998. RemoteDirView->DiscardSavedSelection();
  5999. throw;
  6000. }
  6001. RemoteDirView->RestoreSelection();
  6002. }
  6003. else if (DebugAlwaysTrue(Side == osLocal))
  6004. {
  6005. std::unique_ptr<TStrings> Directories(CreateSortedStringList());
  6006. if (TargetIsDirectory)
  6007. {
  6008. if (!ForceDirectories(ApiPath(NewFileName)))
  6009. {
  6010. throw EOSExtException(FMTLOAD(CREATE_DIR_ERROR, (NewFileName)));
  6011. }
  6012. Directories->Add(NewFileName);
  6013. }
  6014. else
  6015. {
  6016. Directories->Add(ExtractFileDir(NewFileName));
  6017. }
  6018. for (int Index = 0; Index < FileList->Count; Index++)
  6019. {
  6020. UnicodeString FileName = FileList->Strings[Index];
  6021. UnicodeString Directory = ExtractFileDir(FileName);
  6022. Directories->Add(Directory);
  6023. UnicodeString NewFilePath = NewFileName;
  6024. if (TargetIsDirectory)
  6025. {
  6026. NewFilePath = TPath::Combine(NewFilePath, ExtractFileName(FileName));
  6027. }
  6028. if (!MoveFile(ApiPath(FileName).c_str(), ApiPath(NewFilePath).c_str()))
  6029. {
  6030. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFilePath)));
  6031. }
  6032. }
  6033. for (int Index = 0; Index < Directories->Count; Index++)
  6034. {
  6035. ReloadLocalDirectory(Directories->Strings[Index]);
  6036. }
  6037. }
  6038. }
  6039. //---------------------------------------------------------------------------
  6040. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  6041. {
  6042. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  6043. if (Side == osLocal)
  6044. {
  6045. if (Action == TSynchronizeChecklist::saDownloadNew)
  6046. {
  6047. OpenFolderInExplorer(LocalPath);
  6048. }
  6049. else
  6050. {
  6051. OpenFileInExplorer(CombinePaths(LocalPath, Item->GetFileName()));
  6052. }
  6053. }
  6054. else if (DebugAlwaysTrue(Side == osRemote))
  6055. {
  6056. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  6057. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  6058. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  6059. if (!LocalPath.IsEmpty())
  6060. {
  6061. SessionData->LocalDirectory = LocalPath;
  6062. }
  6063. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  6064. ExecuteNewInstance(SessionName, FORMAT(L"%s=\"%s\"", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  6065. }
  6066. }
  6067. //---------------------------------------------------------------------------
  6068. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  6069. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6070. const TCopyParamType * CopyParams)
  6071. {
  6072. UnicodeString SessionName = CreateHiddenDuplicateSession();
  6073. UnicodeString AdditionalParams =
  6074. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  6075. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  6076. SerializeCopyParamForCommandLine(CopyParams),
  6077. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  6078. LocalDirectory, RemoteDirectory, Mode, Params));
  6079. ExecuteNewInstance(SessionName, AdditionalParams);
  6080. }
  6081. //---------------------------------------------------------------------------
  6082. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  6083. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  6084. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  6085. {
  6086. int Result;
  6087. bool SaveSettings = false;
  6088. int Options =
  6089. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  6090. FLAGMASK(!CanCalculateChecksum(), fsoDisableByChecksum) |
  6091. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  6092. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  6093. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  6094. bool Continue =
  6095. ((UseDefaults == 0) ||
  6096. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  6097. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults)) &&
  6098. (FLAGCLEAR(Params, TTerminal::spByChecksum) || EnsureCommandSessionFallback(fcCalculatingChecksum));
  6099. if (Continue)
  6100. {
  6101. Configuration->Usage->Inc(L"Synchronizations");
  6102. CopyParam.IncludeFileMask.SetRoots(LocalDirectory, RemoteDirectory);
  6103. UpdateCopyParamCounters(CopyParam);
  6104. TSynchronizeOptions SynchronizeOptions;
  6105. GetSynchronizeOptions(Params, SynchronizeOptions);
  6106. if (SaveSettings)
  6107. {
  6108. GUIConfiguration->SynchronizeParams = Params;
  6109. }
  6110. else
  6111. {
  6112. SaveMode = false;
  6113. }
  6114. TDateTime StartTime = Now();
  6115. TSynchronizeChecklist * Checklist = NULL;
  6116. try
  6117. {
  6118. DebugAssert(!FAutoOperation);
  6119. FAutoOperation = true;
  6120. try
  6121. {
  6122. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  6123. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  6124. int Files = -1;
  6125. if (DataList->Count >= 1)
  6126. {
  6127. Files = StrToIntDef(DataList->Strings[0], Files);
  6128. }
  6129. else
  6130. {
  6131. DataList->Add(UnicodeString());
  6132. }
  6133. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  6134. FSynchronizeProgressForm->Start();
  6135. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  6136. static_cast<TTerminal::TSynchronizeMode>(Mode),
  6137. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  6138. &SynchronizeOptions);
  6139. if (Terminal->SessionData->CacheDirectories)
  6140. {
  6141. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  6142. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  6143. }
  6144. }
  6145. __finally
  6146. {
  6147. FAutoOperation = false;
  6148. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  6149. SAFE_DESTROY(FSynchronizeProgressForm);
  6150. }
  6151. TSynchronizeParams SynchronizeParams;
  6152. SynchronizeParams.LocalDirectory = LocalDirectory;
  6153. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  6154. SynchronizeParams.Mode = Mode;
  6155. SynchronizeParams.CopyParam = &CopyParam;
  6156. SynchronizeParams.Params = Params;
  6157. SynchronizeParams.Checklist = Checklist;
  6158. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  6159. SynchronizeParams.StartTime = &StartTime;
  6160. SynchronizeParams.OnProcessedItem = NULL;
  6161. Result = Checklist->Count;
  6162. if (Checklist->Count > 0)
  6163. {
  6164. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  6165. {
  6166. if (!DoSynchronizeChecklistDialog(
  6167. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  6168. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  6169. {
  6170. Result = -1;
  6171. }
  6172. }
  6173. else
  6174. {
  6175. FullSynchronize(SynchronizeParams, NULL, NULL);
  6176. }
  6177. }
  6178. else
  6179. {
  6180. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  6181. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  6182. }
  6183. }
  6184. __finally
  6185. {
  6186. delete Checklist;
  6187. }
  6188. OperationComplete(StartTime);
  6189. }
  6190. else
  6191. {
  6192. Result = -1;
  6193. }
  6194. return Result;
  6195. }
  6196. //---------------------------------------------------------------------------
  6197. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  6198. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6199. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  6200. {
  6201. if (Collect)
  6202. {
  6203. DebugAssert(FSynchronizeProgressForm != NULL);
  6204. if (!FSynchronizeProgressForm->Started)
  6205. {
  6206. FSynchronizeProgressForm->Start();
  6207. }
  6208. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  6209. SetTaskbarListProgressValue(CompareProgress);
  6210. }
  6211. else
  6212. {
  6213. DebugAssert(FSynchronizeProgressForm == NULL);
  6214. DebugAssert(FProgressForm != NULL);
  6215. }
  6216. }
  6217. //---------------------------------------------------------------------------
  6218. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  6219. {
  6220. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  6221. std::unique_ptr<TRemoteFile> File(Terminal->ReadFile(FullFileName));
  6222. if (File.get() != NULL)
  6223. {
  6224. ExecuteRemoteFile(FullFileName, File.get(), efInternalEditor);
  6225. Application->ShowMainForm = false;
  6226. Application->Run();
  6227. }
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  6231. {
  6232. DebugFail();
  6233. }
  6234. //---------------------------------------------------------------------------
  6235. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  6236. {
  6237. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  6238. SessionData->Assign(ManagedSession->SessionData);
  6239. UpdateSessionData(SessionData.get());
  6240. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  6241. if (IsActiveTerminal(ManagedSession))
  6242. {
  6243. ManagedSession->UpdateSessionCredentials(SessionData.get());
  6244. }
  6245. if (!ManagedSession->SessionData->HasSessionName())
  6246. {
  6247. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  6248. // once IsWorkspace is cleared
  6249. SessionData->Name = UnicodeString();
  6250. }
  6251. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  6252. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  6253. SessionData->IsWorkspace = false;
  6254. return SessionData.release();
  6255. }
  6256. //---------------------------------------------------------------------------
  6257. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  6258. {
  6259. TSessionData * SessionData = CloneCurrentSessionData();
  6260. try
  6261. {
  6262. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  6263. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  6264. }
  6265. __finally
  6266. {
  6267. delete SessionData;
  6268. }
  6269. }
  6270. //---------------------------------------------------------------------------
  6271. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  6272. {
  6273. TTerminalManager * Manager = TTerminalManager::Instance();
  6274. std::unique_ptr<TObjectList> DataList(new TObjectList());
  6275. if (DebugAlwaysTrue(ManagedSession != NULL))
  6276. {
  6277. // Update ManagedSession->StateData
  6278. UpdateSession(ManagedSession);
  6279. }
  6280. Manager->SaveWorkspace(DataList.get());
  6281. return DataList.release();
  6282. }
  6283. //---------------------------------------------------------------------------
  6284. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  6285. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  6286. {
  6287. WinConfiguration->LastWorkspace = Name;
  6288. if (!SavePasswords)
  6289. {
  6290. for (int Index = 0; Index < DataList->Count; Index++)
  6291. {
  6292. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6293. if (SessionData->Link.IsEmpty())
  6294. {
  6295. SessionData->ClearSessionPasswords();
  6296. }
  6297. }
  6298. }
  6299. StoredSessions->NewWorkspace(Name, DataList);
  6300. // modified only
  6301. StoredSessions->Save(false, Explicit);
  6302. }
  6303. //---------------------------------------------------------------------------
  6304. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  6305. {
  6306. return
  6307. DefaultStr(WinConfiguration->LastWorkspace,
  6308. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  6309. }
  6310. //---------------------------------------------------------------------------
  6311. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  6312. {
  6313. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  6314. bool AnyNonStoredSessionWithPassword = false;
  6315. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  6316. bool AllNonStoredSessionsAnonymous = true;
  6317. TTerminalManager * Manager = TTerminalManager::Instance();
  6318. for (int Index = 0; Index < DataList->Count; Index++)
  6319. {
  6320. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6321. if (SessionData->Link.IsEmpty())
  6322. {
  6323. if (SessionData->HasAnySessionPassword())
  6324. {
  6325. AnyNonStoredSessionWithPassword = true;
  6326. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  6327. {
  6328. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  6329. }
  6330. }
  6331. if (!SameText(SessionData->UserName, AnonymousUserName))
  6332. {
  6333. AllNonStoredSessionsAnonymous = false;
  6334. }
  6335. }
  6336. }
  6337. bool SavePasswords;
  6338. bool * PSavePasswords;
  6339. bool NotRecommendedSavingPasswords =
  6340. !CustomWinConfiguration->UseMasterPassword &&
  6341. !AllNonStoredSessionsAnonymous;
  6342. if (Configuration->DisablePasswordStoring ||
  6343. !AnyNonStoredSessionWithPassword)
  6344. {
  6345. PSavePasswords = NULL;
  6346. SavePasswords = false;
  6347. }
  6348. else
  6349. {
  6350. PSavePasswords = &SavePasswords;
  6351. SavePasswords =
  6352. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6353. !NotRecommendedSavingPasswords;
  6354. }
  6355. UnicodeString Name = WorkspaceName();
  6356. bool CreateShortcut = false;
  6357. bool Result =
  6358. DoSaveWorkspaceDialog(
  6359. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6360. EnableAutoSave);
  6361. if (Result)
  6362. {
  6363. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6364. if (CreateShortcut)
  6365. {
  6366. TOperationVisualizer Visualizer;
  6367. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6368. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6369. }
  6370. if (EnableAutoSave)
  6371. {
  6372. WinConfiguration->AutoSaveWorkspace = true;
  6373. WinConfiguration->AutoWorkspace = Name;
  6374. if (PSavePasswords != NULL)
  6375. {
  6376. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6377. }
  6378. }
  6379. }
  6380. return Result;
  6381. }
  6382. //---------------------------------------------------------------------------
  6383. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6384. {
  6385. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6386. DebugAssert(Session == ManagedSession);
  6387. if (!IsLocalBrowserMode())
  6388. {
  6389. SAFE_DESTROY(Session->RemoteExplorerState);
  6390. if (WinConfiguration->PreservePanelState)
  6391. {
  6392. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6393. }
  6394. }
  6395. UpdateSessionData(Session->StateData);
  6396. }
  6397. //---------------------------------------------------------------------------
  6398. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6399. {
  6400. // Keep in sync with TSessionData::CopyStateData
  6401. DebugAssert(Data != NULL);
  6402. // This is inconsistent with how color (for example) is handled.
  6403. Data->Name = ManagedSession->SessionData->Name;
  6404. if (!IsLocalBrowserMode())
  6405. {
  6406. // cannot use RemoteDirView->Path, because it is empty if connection
  6407. // was already closed
  6408. // also only peek, we may not be connected at all atm
  6409. // so make sure we do not try retrieving current directory from the server
  6410. // (particularly with FTP)
  6411. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6412. if (!ACurrentDirectory.IsEmpty())
  6413. {
  6414. Data->RemoteDirectory = ACurrentDirectory;
  6415. }
  6416. }
  6417. Data->Color = SessionColor;
  6418. }
  6419. //---------------------------------------------------------------------------
  6420. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6421. {
  6422. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6423. DebugAssert(Toolbar != NULL);
  6424. for (int i = 0; i < Toolbar->Items->Count; i++)
  6425. {
  6426. TTBXCustomDropDownItem * DropDownItem;
  6427. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6428. if (DropDownItem != NULL)
  6429. {
  6430. ToolbarItemResize(DropDownItem,
  6431. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6432. Toolbar->NonClientWidth);
  6433. break;
  6434. }
  6435. }
  6436. }
  6437. //---------------------------------------------------------------------------
  6438. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6439. {
  6440. Item->EditWidth = Width;
  6441. }
  6442. //---------------------------------------------------------------------------
  6443. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6444. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6445. {
  6446. for (int i = 0; i < Toolbar->Items->Count; i++)
  6447. {
  6448. TTBXCustomDropDownItem * DropDownItem;
  6449. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6450. if (DropDownItem != NULL)
  6451. {
  6452. ASize.x -= DropDownItem->EditWidth;
  6453. TControl * Control = this;
  6454. ASize.x += ScaleByTextHeight(Control, 50) /* minimal combo width */;
  6455. }
  6456. }
  6457. }
  6458. //---------------------------------------------------------------------------
  6459. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6460. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6461. {
  6462. if (WinConfiguration->DDWarnLackOfTempSpace)
  6463. {
  6464. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6465. if (!ADrive.IsEmpty())
  6466. {
  6467. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6468. DebugAssert(RequiredSpace >= 0);
  6469. __int64 RequiredWithReserve;
  6470. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6471. if (FreeSpace < RequiredWithReserve)
  6472. {
  6473. unsigned int Result;
  6474. TMessageParams Params(mpNeverAskAgainCheck);
  6475. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6476. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6477. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6478. if (Result == qaNeverAskAgain)
  6479. {
  6480. WinConfiguration->DDWarnLackOfTempSpace = false;
  6481. }
  6482. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6483. }
  6484. }
  6485. }
  6486. }
  6487. //---------------------------------------------------------------------------
  6488. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6489. {
  6490. DoOpenDirectoryDialog(odAddBookmark, Side);
  6491. }
  6492. //---------------------------------------------------------------------------
  6493. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6494. {
  6495. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6496. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6497. try
  6498. {
  6499. TCustomDirView * DView = DirView(Side);
  6500. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6501. {
  6502. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6503. }
  6504. }
  6505. catch (...)
  6506. {
  6507. delete VisitedDirectories;
  6508. throw;
  6509. }
  6510. return VisitedDirectories;
  6511. }
  6512. //---------------------------------------------------------------------------
  6513. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6514. TOpenDirectoryMode Mode, TOperationSide Side)
  6515. {
  6516. bool Continue = true;
  6517. if (Mode == odAddBookmark)
  6518. {
  6519. TMessageParams Params(mpNeverAskAgainCheck);
  6520. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6521. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6522. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6523. unsigned int Answer =
  6524. MessageDialog(Message,
  6525. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6526. if (Answer == qaNeverAskAgain)
  6527. {
  6528. Continue = true;
  6529. WinConfiguration->UseSharedBookmarks = true;
  6530. }
  6531. else if (Answer == qaOK)
  6532. {
  6533. Continue = true;
  6534. WinConfiguration->UseSharedBookmarks = false;
  6535. }
  6536. else
  6537. {
  6538. Continue = false;
  6539. }
  6540. }
  6541. if (Continue)
  6542. {
  6543. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6544. try
  6545. {
  6546. UnicodeString Name = DirView(Side)->PathName;
  6547. bool Repeat;
  6548. do
  6549. {
  6550. Repeat = false;
  6551. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6552. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6553. // do not allow switching to location profiles,
  6554. // if we are not connected
  6555. HasDirView[osLocal] && IsActiveTerminal(Terminal)))
  6556. {
  6557. TWindowLock Lock(this);
  6558. if (!TryOpenDirectory(Side, Name))
  6559. {
  6560. Repeat = true;
  6561. Mode = odBrowse;
  6562. }
  6563. }
  6564. }
  6565. while (Repeat);
  6566. }
  6567. __finally
  6568. {
  6569. delete VisitedDirectories;
  6570. }
  6571. }
  6572. }
  6573. //---------------------------------------------------------------------------
  6574. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6575. {
  6576. DebugAssert(!Terminal->CommandSessionOpened);
  6577. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6578. }
  6579. //---------------------------------------------------------------------------
  6580. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6581. {
  6582. bool Result = Terminal->IsCapable[Capability] ||
  6583. Terminal->CommandSessionOpened;
  6584. if (!Result)
  6585. {
  6586. // We might get here for example when "checksum" synchronization is requested from command-line
  6587. // on server that supports neither checksum nor shell
  6588. if (!Terminal->IsCapable[fcSecondaryShell])
  6589. {
  6590. NotSupported();
  6591. }
  6592. else if (!GUIConfiguration->ConfirmCommandSession)
  6593. {
  6594. Result = true;
  6595. }
  6596. else
  6597. {
  6598. TMessageParams Params(mpNeverAskAgainCheck);
  6599. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6600. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6601. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6602. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6603. if (Answer == qaNeverAskAgain)
  6604. {
  6605. GUIConfiguration->ConfirmCommandSession = false;
  6606. Result = true;
  6607. }
  6608. else if (Answer == qaOK)
  6609. {
  6610. Result = true;
  6611. }
  6612. }
  6613. if (Result)
  6614. {
  6615. Result = CommandSessionFallback();
  6616. }
  6617. }
  6618. return Result;
  6619. }
  6620. //---------------------------------------------------------------------------
  6621. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6622. {
  6623. if (EnsureCommandSessionFallback(fcAnyCommand))
  6624. {
  6625. DoConsoleDialog(Terminal, Command);
  6626. }
  6627. }
  6628. //---------------------------------------------------------------------------
  6629. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6630. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6631. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6632. {
  6633. if (!IsSideLocalBrowser(osRemote) &&
  6634. IsFileControl(DropSourceControl, osRemote) &&
  6635. (FDDExtMapFile != NULL))
  6636. {
  6637. Accept = true;
  6638. }
  6639. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6640. DebugAssert(FDDTargetControl != NULL);
  6641. }
  6642. //---------------------------------------------------------------------------
  6643. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6644. _di_IDataObject DataObj, int KeyState,
  6645. const TPoint & Point, int & Effect, bool & Accept)
  6646. {
  6647. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6648. }
  6649. //---------------------------------------------------------------------------
  6650. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6651. _di_IDataObject DataObj, int KeyState,
  6652. const TPoint & Point, int & Effect, bool & Accept)
  6653. {
  6654. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6655. }
  6656. //---------------------------------------------------------------------------
  6657. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6658. TObject * Sender)
  6659. {
  6660. DebugUsedParam(Sender);
  6661. DebugAssert(FDDTargetControl == Sender);
  6662. FDDTargetControl = NULL;
  6663. }
  6664. //---------------------------------------------------------------------------
  6665. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave(int)
  6666. {
  6667. FileControlDDDragLeave(SessionsPageControl);
  6668. }
  6669. //---------------------------------------------------------------------------
  6670. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave(int)
  6671. {
  6672. FileControlDDDragLeave(QueueView3);
  6673. }
  6674. //---------------------------------------------------------------------------
  6675. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6676. {
  6677. DebugAssert(!IsSideLocalBrowser(Side));
  6678. DebugUsedParam(Side);
  6679. bool Edit = false;
  6680. TRemoteFile * File = NULL;
  6681. UnicodeString FileName;
  6682. UnicodeString PointTo;
  6683. bool SymbolicLink = true;
  6684. if (RemoteDirView->ItemFocused)
  6685. {
  6686. DebugAssert(RemoteDirView->ItemFocused->Data);
  6687. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6688. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6689. if (Edit)
  6690. {
  6691. FileName = File->FileName;
  6692. PointTo = File->LinkTo;
  6693. }
  6694. else if (!File->IsParentDirectory)
  6695. {
  6696. PointTo = File->FileName;
  6697. }
  6698. }
  6699. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6700. Terminal->IsCapable[fcHardLink]))
  6701. {
  6702. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6703. if (Edit)
  6704. {
  6705. DebugAssert(File->FileName == FileName);
  6706. int Params = dfNoRecursive;
  6707. Terminal->ExceptionOnFail = true;
  6708. try
  6709. {
  6710. Terminal->DeleteFile(L"", File, &Params);
  6711. }
  6712. __finally
  6713. {
  6714. Terminal->ExceptionOnFail = false;
  6715. }
  6716. }
  6717. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6718. }
  6719. }
  6720. //---------------------------------------------------------------------------
  6721. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6722. {
  6723. return
  6724. (IsSideLocalBrowser(Side) ||
  6725. (HasActiveTerminal() &&
  6726. Terminal->ResolvingSymlinks &&
  6727. Terminal->IsCapable[fcSymbolicLink]));
  6728. }
  6729. //---------------------------------------------------------------------------
  6730. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6731. {
  6732. return
  6733. !IsSideLocalBrowser(FCurrentSide) &&
  6734. (RemoteDirView->ItemFocused != NULL) &&
  6735. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6736. Terminal->SessionData->ResolveSymlinks;
  6737. }
  6738. //---------------------------------------------------------------------------
  6739. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6740. {
  6741. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6742. FForceExecution = true;
  6743. try
  6744. {
  6745. DirView(osCurrent)->ExecuteCurrentFile();
  6746. }
  6747. __finally
  6748. {
  6749. FForceExecution = false;
  6750. }
  6751. }
  6752. //---------------------------------------------------------------------------
  6753. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6754. {
  6755. TEditorData ExternalEditor;
  6756. ExternalEditor.Editor = edExternal;
  6757. bool Remember = false;
  6758. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6759. {
  6760. if (Remember)
  6761. {
  6762. TEditorList * EditorList = new TEditorList;
  6763. try
  6764. {
  6765. *EditorList = *WinConfiguration->EditorList;
  6766. bool Found = false;
  6767. int i = 0;
  6768. while (!Found && (i < EditorList->Count))
  6769. {
  6770. const TEditorPreferences * Editor = EditorList->Editors[i];
  6771. if ((Editor->Data->Editor == edExternal) &&
  6772. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6773. {
  6774. Found = true;
  6775. }
  6776. i++;
  6777. }
  6778. if (!Found)
  6779. {
  6780. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6781. WinConfiguration->EditorList = EditorList;
  6782. }
  6783. }
  6784. __finally
  6785. {
  6786. delete EditorList;
  6787. }
  6788. }
  6789. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6790. }
  6791. }
  6792. //---------------------------------------------------------------------------
  6793. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6794. {
  6795. if (FFileFindTerminal == ATerminal)
  6796. {
  6797. FFileFindTerminal = NULL;
  6798. HideFileFindDialog();
  6799. }
  6800. if (FClipboardTerminal == ATerminal)
  6801. {
  6802. ClipboardClear(); // implies ClipboardStop
  6803. }
  6804. if ((FOnSynchronizeAbort != NULL) &&
  6805. (ATerminal == FManagedSession))
  6806. {
  6807. FOnSynchronizeAbort(NULL);
  6808. }
  6809. }
  6810. //---------------------------------------------------------------------------
  6811. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6812. {
  6813. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6814. DetachTerminal(Sender);
  6815. }
  6816. //---------------------------------------------------------------------------
  6817. void __fastcall TCustomScpExplorerForm::FileTerminalReplaced(
  6818. const UnicodeString FileName, TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6819. {
  6820. TManagedTerminal * ATerminal = static_cast<TManagedTerminal *>(Arg);
  6821. if (Data->Terminal == Terminal)
  6822. {
  6823. Data->Terminal = ATerminal;
  6824. }
  6825. }
  6826. //---------------------------------------------------------------------------
  6827. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6828. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6829. {
  6830. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6831. DebugAssert(Terminal != NULL);
  6832. if (Data->Terminal == Terminal)
  6833. {
  6834. Data->Terminal = NULL;
  6835. }
  6836. }
  6837. //---------------------------------------------------------------------------
  6838. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6839. {
  6840. return NULL;
  6841. }
  6842. //---------------------------------------------------------------------------
  6843. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6844. {
  6845. UpdateControls();
  6846. SessionColor = TColor(0);
  6847. UpdateRemotePathComboBox(false);
  6848. NeedSession(false);
  6849. }
  6850. //---------------------------------------------------------------------------
  6851. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6852. {
  6853. try
  6854. {
  6855. // Cache, as the login dialog can change its value.
  6856. // See also DoShow. Also see TTerminalManager::NewSession.
  6857. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6858. try
  6859. {
  6860. if (ShowLogin)
  6861. {
  6862. bool ReloadSessions = !Startup;
  6863. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6864. }
  6865. }
  6866. __finally
  6867. {
  6868. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6869. // (so there was no chance for the user to open any session yet)
  6870. if ((ShowLogin || !Startup) &&
  6871. !WinConfiguration->KeepOpenWhenNoSession &&
  6872. // this rules out the implicit Commander's local-local browser
  6873. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6874. {
  6875. TerminateApplication();
  6876. }
  6877. }
  6878. }
  6879. catch (EAbort &)
  6880. {
  6881. // swallow
  6882. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6883. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6884. }
  6885. }
  6886. //---------------------------------------------------------------------------
  6887. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6888. {
  6889. TTerminalManager * Manager = TTerminalManager::Instance();
  6890. DebugAssert(!Manager->Updating);
  6891. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6892. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6893. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6894. SessionsPageControl->LockDrawing();
  6895. try
  6896. {
  6897. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6898. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6899. {
  6900. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6901. }
  6902. for (int Index = 0; Index <= Manager->Count; Index++)
  6903. {
  6904. TThemeTabSheet * TabSheet;
  6905. if (Index >= SessionsPageControl->PageCount)
  6906. {
  6907. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6908. TabSheet->PageControl = SessionsPageControl;
  6909. }
  6910. else
  6911. {
  6912. TabSheet = SessionsPageControl->Pages[Index];
  6913. }
  6914. bool IsSessionTab = (Index < Manager->Count);
  6915. if (IsSessionTab)
  6916. {
  6917. TTerminal * Terminal = Manager->Sessions[Index];
  6918. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6919. TabSheet->CaptionTruncation = WinConfiguration->SessionTabCaptionTruncation ? tttEllipsis : tttNone;
  6920. UpdateSessionTab(TabSheet);
  6921. }
  6922. else
  6923. {
  6924. TabSheet->Tag = 0; // not really needed
  6925. TabSheet->Shadowed = false;
  6926. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6927. TabSheet->CaptionTruncation = GetNewTabTabCaptionTruncation();
  6928. // 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)
  6929. UpdateNewTabTab();
  6930. }
  6931. }
  6932. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6933. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6934. {
  6935. SessionsPageControl->UpdateTabsCaptionTruncation();
  6936. }
  6937. }
  6938. __finally
  6939. {
  6940. SessionsPageControl->UnlockDrawing();
  6941. }
  6942. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6943. }
  6944. //---------------------------------------------------------------------------
  6945. TThemeTabCaptionTruncation TCustomScpExplorerForm::GetNewTabTabCaptionTruncation()
  6946. {
  6947. return WinConfiguration->SessionTabCaptionTruncation ? tttNoText : tttNone;
  6948. }
  6949. //---------------------------------------------------------------------------
  6950. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6951. {
  6952. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6953. }
  6954. //---------------------------------------------------------------------------
  6955. TThemeTabSheet * TCustomScpExplorerForm::GetNewTabTab()
  6956. {
  6957. return SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6958. }
  6959. //---------------------------------------------------------------------------
  6960. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6961. {
  6962. TThemeTabSheet * TabSheet = GetNewTabTab();
  6963. UnicodeString TabCaption;
  6964. if (WinConfiguration->SelectiveToolbarText)
  6965. {
  6966. TabCaption = GetNewTabTabCaption();
  6967. }
  6968. TabSheet->BaseCaption = TabCaption;
  6969. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6970. }
  6971. //---------------------------------------------------------------------------
  6972. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6973. {
  6974. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6975. }
  6976. //---------------------------------------------------------------------------
  6977. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6978. {
  6979. DebugFail();
  6980. return UnicodeString();
  6981. }
  6982. //---------------------------------------------------------------------------
  6983. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  6984. {
  6985. if (DebugAlwaysTrue(TabSheet != NULL))
  6986. {
  6987. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6988. if (DebugAlwaysTrue(ASession != NULL))
  6989. {
  6990. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6991. if (ASession->LocalBrowser)
  6992. {
  6993. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6994. }
  6995. else
  6996. {
  6997. TabSheet->ImageIndex = AddSessionColor(Color);
  6998. }
  6999. TTerminalManager * Manager = TTerminalManager::Instance();
  7000. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  7001. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  7002. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  7003. }
  7004. }
  7005. }
  7006. //---------------------------------------------------------------------------
  7007. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  7008. {
  7009. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  7010. }
  7011. //---------------------------------------------------------------------------
  7012. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  7013. {
  7014. DebugAssert(SessionsPageControl->ActivePage != NULL);
  7015. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  7016. bool Result = (Session != NULL);
  7017. if (Result)
  7018. {
  7019. TTerminalManager::Instance()->ActiveSession = Session;
  7020. }
  7021. else
  7022. {
  7023. try
  7024. {
  7025. NewTab();
  7026. }
  7027. __finally
  7028. {
  7029. SessionListChanged();
  7030. }
  7031. FSessionsPageControlNewTabTime = Now();
  7032. }
  7033. return Result;
  7034. }
  7035. //---------------------------------------------------------------------------
  7036. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  7037. {
  7038. TWindowLock Lock(this);
  7039. SessionTabSwitched();
  7040. }
  7041. //---------------------------------------------------------------------------
  7042. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  7043. {
  7044. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  7045. DebugAssert(TransferList != NULL);
  7046. UnicodeString Name;
  7047. if (TransferList->ItemIndex <= 0)
  7048. {
  7049. Name = L"";
  7050. }
  7051. else
  7052. {
  7053. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  7054. }
  7055. if (FCopyParamAutoSelected.IsEmpty())
  7056. {
  7057. // if previous preset was not autoselected, make new preset the "default"
  7058. FCopyParamDefault = Name;
  7059. }
  7060. GUIConfiguration->CopyParamCurrent = Name;
  7061. }
  7062. //---------------------------------------------------------------------------
  7063. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  7064. {
  7065. // sanity check
  7066. bool ExistingPreset =
  7067. (FTransferListHoverIndex >= 0) &&
  7068. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  7069. DebugAssert(ExistingPreset);
  7070. if (ExistingPreset)
  7071. {
  7072. HDC DC = GetDC(0);
  7073. TCanvas * Canvas = new TCanvas();
  7074. try
  7075. {
  7076. Canvas->Handle = DC;
  7077. Canvas->Font = GetToolbarFont(this);
  7078. UnicodeString Name;
  7079. if (FTransferListHoverIndex == 0)
  7080. {
  7081. Name = L"";
  7082. }
  7083. else
  7084. {
  7085. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  7086. }
  7087. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  7088. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  7089. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  7090. static_cast<TObject*>(GetComponent(fcTransferList)));
  7091. UnicodeString InfoStr =
  7092. GUIConfiguration->CopyParamPreset[Name].
  7093. GetInfoStr(L"; ",
  7094. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  7095. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  7096. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  7097. {
  7098. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  7099. {
  7100. InfoStr.SetLength(InfoStr.Length() - 1);
  7101. }
  7102. InfoStr += Ellipsis;
  7103. }
  7104. // UpdateCaption does not cause invalidation of whole submenu, while
  7105. // setting Caption property does.
  7106. // also it probably does not resize the label, even if necessary
  7107. // (we do not want that anyway)
  7108. TransferLabel->UpdateCaption(InfoStr);
  7109. }
  7110. __finally
  7111. {
  7112. Canvas->Handle = NULL;
  7113. ReleaseDC(0, DC);
  7114. delete Canvas;
  7115. }
  7116. }
  7117. }
  7118. //---------------------------------------------------------------------------
  7119. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  7120. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  7121. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  7122. {
  7123. if (FTransferListHoverIndex != AHoverIndex)
  7124. {
  7125. FTransferListHoverIndex = AHoverIndex;
  7126. UpdateTransferLabel();
  7127. }
  7128. }
  7129. //---------------------------------------------------------------------------
  7130. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  7131. {
  7132. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  7133. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  7134. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  7135. {
  7136. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  7137. {
  7138. if (!NonVisualDataModule->Busy)
  7139. {
  7140. OpenDirectory(GetSide(osCurrent));
  7141. }
  7142. Message.Result = 1;
  7143. }
  7144. else
  7145. {
  7146. TForm::Dispatch(&Message);
  7147. }
  7148. }
  7149. else
  7150. {
  7151. TForm::Dispatch(&Message);
  7152. }
  7153. }
  7154. //---------------------------------------------------------------------------
  7155. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  7156. {
  7157. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  7158. if ((FIgnoreNextDialogChar != 0) &&
  7159. (towupper(Message.CharCode) == towupper(FIgnoreNextDialogChar)))
  7160. {
  7161. Message.Result = 1;
  7162. }
  7163. else
  7164. {
  7165. TForm::Dispatch(&Message);
  7166. }
  7167. FIgnoreNextDialogChar = 0;
  7168. }
  7169. //---------------------------------------------------------------------------
  7170. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  7171. {
  7172. // The four low-order bits are used internally by Windows
  7173. unsigned int Cmd = (Message.WParam & 0xFFF0);
  7174. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  7175. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  7176. // 61730 - restore thru double click - undocumented
  7177. // 61490 - maximize thru double click - undocumented
  7178. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  7179. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  7180. {
  7181. SysResizing(Cmd);
  7182. }
  7183. TForm::Dispatch(&Message);
  7184. }
  7185. //---------------------------------------------------------------------------
  7186. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  7187. {
  7188. AppLog(L"Windows session end query");
  7189. // We were actually never able to make ENDSESSION_CRITICAL happen.
  7190. // Also there no point returning TRUE as we are not able to
  7191. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  7192. // Hence the process termination might be safer :)
  7193. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  7194. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  7195. {
  7196. Message.Result = FALSE;
  7197. }
  7198. else
  7199. {
  7200. Message.Result = TRUE;
  7201. }
  7202. // Do not call default handling as that triggers OnCloseQuery,
  7203. // where our implementation will popup confirmation dialogs, what we do not want,
  7204. // as per Vista guidelines:
  7205. // https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  7206. }
  7207. //---------------------------------------------------------------------------
  7208. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  7209. {
  7210. AppLog(L"Windows session end");
  7211. if (Message.EndSession && IsApplicationMinimized())
  7212. {
  7213. // WORKAROUND
  7214. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  7215. // when it receives WM_ENDSESSION,
  7216. // but that sometimes (particularly when application is minimized) cause crashes.
  7217. // Crash popups message that blocks log off.
  7218. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  7219. // so we call ExitProcess() immediately, not even trying to cleanup.
  7220. // It still causes beep, so there's likely some popup, but it does not block
  7221. // log off.
  7222. ExitProcess(0);
  7223. }
  7224. TForm::Dispatch(&Message);
  7225. }
  7226. #ifdef _DEBUG
  7227. //---------------------------------------------------------------------------
  7228. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  7229. {
  7230. TForm::Dispatch(&Message);
  7231. }
  7232. #endif
  7233. //---------------------------------------------------------------------------
  7234. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  7235. {
  7236. }
  7237. //---------------------------------------------------------------------------
  7238. void __fastcall TCustomScpExplorerForm::DoShow()
  7239. {
  7240. // Called from TCustomScpExplorerForm::CMShowingChanged
  7241. // only now are the controls resized finally, so the size constraints
  7242. // will not conflict with possibly very small window size
  7243. RestoreFormParams();
  7244. // This indicates that the form was rescaled after parameters were loaded and
  7245. // as most probably the parameters were actually saved with the current form scaling
  7246. // (windows was the last time likely closed on the same monitor, where it is starting now),
  7247. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  7248. // and no rounding problems will occur.
  7249. // See also RestoreForm.
  7250. // (we should be safe to call RestoreParams unconditionally)
  7251. if (PixelsPerInch != Screen->PixelsPerInch)
  7252. {
  7253. RestoreParams();
  7254. }
  7255. FixControlsPlacement();
  7256. if (Position == poDefaultPosOnly)
  7257. {
  7258. CutFormToDesktop(this);
  7259. }
  7260. TForm::DoShow();
  7261. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  7262. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  7263. // This was previously in NeedSession, where other related code is.
  7264. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  7265. // unpleasantly shows briefly.
  7266. if ((ManagedSession == NULL) &&
  7267. !WinConfiguration->ShowLoginWhenNoSession &&
  7268. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  7269. // This detects if workspace was saved the last time the main widow was closed
  7270. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  7271. {
  7272. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  7273. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  7274. }
  7275. // Before main window displays
  7276. if (ManagedSession == NULL)
  7277. {
  7278. StartingWithoutSession();
  7279. }
  7280. UpdatePixelsPerInchMainWindowCounter();
  7281. FShowing = true;
  7282. }
  7283. //---------------------------------------------------------------------------
  7284. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  7285. {
  7286. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  7287. }
  7288. //---------------------------------------------------------------------------
  7289. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  7290. {
  7291. SessionListChanged();
  7292. InitStatusBar();
  7293. UpdateControls();
  7294. }
  7295. //---------------------------------------------------------------------------
  7296. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  7297. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  7298. TNotifyEvent OnBalloonClick, TObject * UserData)
  7299. {
  7300. bool Do;
  7301. UnicodeString Message;
  7302. if (E == NULL)
  7303. {
  7304. Message = Str;
  7305. Do = true;
  7306. }
  7307. else
  7308. {
  7309. Do = ExceptionMessage(E, Message);
  7310. }
  7311. if (Do && WinConfiguration->BalloonNotifications)
  7312. {
  7313. UnicodeString Title;
  7314. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  7315. {
  7316. Message = TrimLeft(Message);
  7317. }
  7318. else
  7319. {
  7320. Message = UnformatMessage(Message);
  7321. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  7322. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  7323. Title = LoadResourceString(Captions[Type]);
  7324. if (Terminal != NULL)
  7325. {
  7326. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal->PrimaryTerminal));
  7327. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  7328. }
  7329. }
  7330. if (Seconds == 0)
  7331. {
  7332. Seconds = WinConfiguration->NotificationsTimeout;
  7333. }
  7334. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  7335. }
  7336. }
  7337. //---------------------------------------------------------------------------
  7338. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  7339. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  7340. UnicodeString HelpKeyword, const TMessageParams * Params,
  7341. TTerminal * Terminal)
  7342. {
  7343. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  7344. (FOnFeedSynchronizeError != NULL)) &&
  7345. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  7346. {
  7347. if (FOnFeedSynchronizeError != NULL)
  7348. {
  7349. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  7350. }
  7351. else
  7352. {
  7353. DebugAssert(FErrorList != NULL);
  7354. TStringList * MoreMessagesCopy = NULL;
  7355. if (MoreMessages)
  7356. {
  7357. MoreMessagesCopy = new TStringList();
  7358. MoreMessagesCopy->Assign(MoreMessages);
  7359. }
  7360. FErrorList->AddObject(Message, MoreMessagesCopy);
  7361. }
  7362. PopupTrayBalloon(Terminal, Message, Type);
  7363. return ContinueAnswer(Answers);
  7364. }
  7365. else
  7366. {
  7367. bool UseBalloon = FTrayIcon->Visible;
  7368. if (UseBalloon)
  7369. {
  7370. PopupTrayBalloon(Terminal, Message, Type);
  7371. }
  7372. unsigned int Result;
  7373. try
  7374. {
  7375. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7376. }
  7377. __finally
  7378. {
  7379. // cancel only balloon we popped up, otherwise we may cancel notification
  7380. // balloon that was there before the message dialog
  7381. // (such as "dd confirmation opt in balloon)
  7382. if (UseBalloon)
  7383. {
  7384. FTrayIcon->CancelBalloon();
  7385. }
  7386. }
  7387. return Result;
  7388. }
  7389. }
  7390. //---------------------------------------------------------------------------
  7391. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7392. TTerminal * Terminal, Exception * E)
  7393. {
  7394. if (FTrayIcon->Visible)
  7395. {
  7396. PopupTrayBalloon(Terminal, L"", qtError, E);
  7397. }
  7398. // particularly prevent opening new session from jump list,
  7399. // while exception is shown
  7400. NonVisualDataModule->StartBusy();
  7401. try
  7402. {
  7403. ShowExtendedExceptionEx(Terminal, E);
  7404. }
  7405. __finally
  7406. {
  7407. NonVisualDataModule->EndBusy();
  7408. FTrayIcon->CancelBalloon();
  7409. }
  7410. }
  7411. //---------------------------------------------------------------------------
  7412. void __fastcall TCustomScpExplorerForm::SessionReady()
  7413. {
  7414. InitStatusBar();
  7415. // cannot rely on active page being page for active terminal,
  7416. // as it can happen that active page is the "new session" page
  7417. // (e.g. when reconnecting active terminal, while login dialog
  7418. // invoked from "new session" page is modal)
  7419. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7420. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7424. TTerminal * Terminal, Exception * E)
  7425. {
  7426. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7427. if (!Terminal->Active)
  7428. {
  7429. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7430. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7431. {
  7432. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7433. }
  7434. }
  7435. }
  7436. //---------------------------------------------------------------------------
  7437. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7438. UnicodeString Message, TQueryType Type,
  7439. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7440. {
  7441. if ((E == NULL) ||
  7442. ExceptionMessage(E, Message))
  7443. {
  7444. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7445. if (Important)
  7446. {
  7447. Seconds *= 5;
  7448. }
  7449. UnicodeString NoteMessage(UnformatMessage(Message));
  7450. if (Terminal != NULL)
  7451. {
  7452. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7453. NoteMessage = FORMAT(L"%s: %s",
  7454. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7455. }
  7456. if (WinConfiguration->BalloonNotifications)
  7457. {
  7458. AddNote(NoteMessage);
  7459. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7460. }
  7461. else
  7462. {
  7463. FlashOnBackground();
  7464. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7465. }
  7466. }
  7467. }
  7468. //---------------------------------------------------------------------------
  7469. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7470. {
  7471. RestoreApp();
  7472. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7473. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7474. !NonVisualDataModule->Busy)
  7475. {
  7476. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7477. TTerminalManager::Instance()->ActiveSession = Terminal;
  7478. if (!ComponentVisible[fcQueueView])
  7479. {
  7480. ToggleQueueVisibility();
  7481. GoToQueue();
  7482. }
  7483. }
  7484. }
  7485. //---------------------------------------------------------------------------
  7486. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7487. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7488. {
  7489. UnicodeString Message;
  7490. TNotifyEvent OnClick = NULL;
  7491. TObject * UserData = NULL;
  7492. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7493. switch (Event)
  7494. {
  7495. case qeEmptyButMonitored:
  7496. if ((ATerminal != Terminal) || QueueInvisible)
  7497. {
  7498. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7499. OnClick = QueueEmptyNoteClicked;
  7500. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7501. TerminalNoteData->Terminal = ATerminal;
  7502. UserData = TerminalNoteData;
  7503. }
  7504. break;
  7505. case qeEmpty:
  7506. OperationComplete(ATerminal->QueueOperationStart);
  7507. break;
  7508. case qePendingUserAction:
  7509. if ((ATerminal != Terminal) ||
  7510. (QueueInvisible && !IsQueueAutoPopup()))
  7511. {
  7512. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7513. }
  7514. break;
  7515. default:
  7516. DebugFail();
  7517. }
  7518. if (!Message.IsEmpty())
  7519. {
  7520. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7521. }
  7522. }
  7523. //---------------------------------------------------------------------------
  7524. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7525. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7526. {
  7527. if (FDDExtMapFile != NULL)
  7528. {
  7529. CloseHandle(FDDExtMapFile);
  7530. FDDExtMapFile = NULL;
  7531. }
  7532. if (WinConfiguration->DDFakeFile)
  7533. {
  7534. DDFakeFileInitDrag(FileList, Created);
  7535. }
  7536. }
  7537. //---------------------------------------------------------------------------
  7538. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7539. {
  7540. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7541. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7542. {
  7543. FFakeFileDropTarget = FileName;
  7544. }
  7545. }
  7546. //---------------------------------------------------------------------------
  7547. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7548. {
  7549. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7550. if (!ForceDirectories(ApiPath(Result)))
  7551. {
  7552. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7553. }
  7554. FileSetAttr(ApiPath(Result), faHidden);
  7555. return Result;
  7556. }
  7557. //---------------------------------------------------------------------------
  7558. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7559. bool & Created)
  7560. {
  7561. FFakeFileDropTarget = UnicodeString();
  7562. FDragFakeDirectory = CreateFakeTransferDirectory();
  7563. FileList->AddItem(NULL, FDragFakeDirectory);
  7564. Created = true;
  7565. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7566. {
  7567. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7568. }
  7569. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7570. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7571. {
  7572. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7573. TDragExtCommStruct* CommStruct;
  7574. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7575. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7576. DebugAssert(CommStruct != NULL);
  7577. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7578. CommStruct->Dragging = true;
  7579. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7580. LENOF(CommStruct->DropDest));
  7581. NULL_TERMINATE(CommStruct->DropDest);
  7582. UnmapViewOfFile(CommStruct);
  7583. }
  7584. }
  7585. //---------------------------------------------------------------------------
  7586. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7587. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7588. {
  7589. bool Result;
  7590. DebugAssert(!IsLocalBrowserMode());
  7591. if (Sender == RemoteDirView)
  7592. {
  7593. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7594. }
  7595. else
  7596. {
  7597. DebugAssert(Sender == RemoteDriveView);
  7598. TStrings * FileList = RemoteDriveView->DragFileList();
  7599. try
  7600. {
  7601. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7602. }
  7603. __finally
  7604. {
  7605. delete FileList;
  7606. }
  7607. }
  7608. if (FDDTargetControl == RemoteDriveView)
  7609. {
  7610. RemoteDriveView->UpdateDropTarget();
  7611. }
  7612. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7613. // or from tree view to dir view.
  7614. // foMove happens when file/dir is dragged from remote tree view outside of
  7615. // application via dragex
  7616. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7617. (DropSourceControl == RemoteDriveView))
  7618. {
  7619. RemoteDriveView->UpdateDropSource();
  7620. }
  7621. return Result;
  7622. }
  7623. //---------------------------------------------------------------------------
  7624. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7625. {
  7626. DebugAssert(!IsLocalBrowserMode());
  7627. // This also handles drops of remote files to queue.
  7628. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7629. SAFE_DESTROY(FDDFileList);
  7630. if (!FFakeFileDropTarget.IsEmpty())
  7631. {
  7632. RemoveDir(ApiPath(FFakeFileDropTarget));
  7633. }
  7634. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7635. {
  7636. try
  7637. {
  7638. TDragResult DDResult = (Sender == RemoteDirView) ?
  7639. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7640. // Focus is moved to the target application,
  7641. // but as we are going to present the UI, we need to steal the focus back.
  7642. // This most likely won't work though (windows does not allow application
  7643. // to steal focus most of the time)
  7644. Application->BringToFront();
  7645. // On older version of Windows we never got drMove here, see also comment below.
  7646. // On Windows 10, we get the "move".
  7647. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7648. {
  7649. UnicodeString TargetDirectory;
  7650. TFileOperation Operation;
  7651. // drInvalid may mean drMove, see comment below
  7652. switch (DDResult)
  7653. {
  7654. case drCopy:
  7655. Operation = foCopy;
  7656. break;
  7657. case drMove:
  7658. Operation = foMove;
  7659. break;
  7660. default:
  7661. DebugFail();
  7662. case drInvalid:
  7663. // prefer "copy" for safety
  7664. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7665. break;
  7666. }
  7667. TTransferOperationParam Param;
  7668. UnicodeString CounterName;
  7669. bool ForceQueue;
  7670. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7671. {
  7672. // we get drInvalid both if d&d was intercepted by ddext,
  7673. // and when users drops on no-drop location.
  7674. // we tell the difference by existence of response from ddext,
  7675. // so we ignore absence of response in this case
  7676. if (DDResult != drInvalid)
  7677. {
  7678. // here we know that the extension is installed,
  7679. // as it is checked as soon as drag&drop starts from
  7680. // RemoteFileControlDDCreateDragFileList
  7681. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7682. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7683. {
  7684. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7685. }
  7686. else
  7687. {
  7688. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7689. }
  7690. }
  7691. }
  7692. else
  7693. {
  7694. // download using fake file
  7695. Param.Temp = false;
  7696. Param.DragDrop = true;
  7697. if (ForceQueue)
  7698. {
  7699. Param.Queue = asOn;
  7700. }
  7701. if (Sender == RemoteDirView)
  7702. {
  7703. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7704. }
  7705. if (RemoteFileControlFileOperation(Sender, Operation,
  7706. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7707. {
  7708. Configuration->Usage->Inc(CounterName);
  7709. }
  7710. }
  7711. }
  7712. }
  7713. __finally
  7714. {
  7715. CloseHandle(FDDExtMapFile);
  7716. FDDExtMapFile = NULL;
  7717. delete FDragFakeMonitors;
  7718. FDragFakeMonitors = NULL;
  7719. RemoveDir(ApiPath(FDragFakeDirectory));
  7720. FDragFakeDirectory = L"";
  7721. FFakeFileDropTarget = UnicodeString();
  7722. }
  7723. }
  7724. if (FDragDropSshTerminate.get() != NULL)
  7725. {
  7726. FDragDropSshTerminate->Rethrow();
  7727. }
  7728. }
  7729. //---------------------------------------------------------------------------
  7730. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7731. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7732. {
  7733. // Remember drop effect so we know (when user drops files), if we copy or move
  7734. FLastDropEffect = dwEffect;
  7735. }
  7736. //---------------------------------------------------------------------------
  7737. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7738. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7739. {
  7740. bool Result;
  7741. if (FDDTargetControl == QueueView3)
  7742. {
  7743. Directory = DefaultDownloadTargetDirectory();
  7744. Result = true;
  7745. CounterName = L"DownloadsDragDropQueue";
  7746. ForceQueue = true;
  7747. }
  7748. else if (!FFakeFileDropTarget.IsEmpty())
  7749. {
  7750. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7751. Result = true;
  7752. ForceQueue = false;
  7753. CounterName = L"DownloadsDragDropFakeFile";
  7754. }
  7755. else
  7756. {
  7757. ForceQueue = false;
  7758. Enabled = false;
  7759. try
  7760. {
  7761. int Timer = 0;
  7762. Result = false;
  7763. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7764. {
  7765. {
  7766. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7767. TDragExtCommStruct* CommStruct;
  7768. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7769. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7770. DebugAssert(CommStruct != NULL);
  7771. Result = !CommStruct->Dragging;
  7772. if (Result)
  7773. {
  7774. Directory = ExtractFilePath(CommStruct->DropDest);
  7775. CounterName = L"DownloadsDragDropExternalExt";
  7776. }
  7777. UnmapViewOfFile(CommStruct);
  7778. }
  7779. if (!Result)
  7780. {
  7781. Sleep(50);
  7782. Timer += 50;
  7783. Application->ProcessMessages();
  7784. }
  7785. }
  7786. }
  7787. __finally
  7788. {
  7789. Enabled = true;
  7790. }
  7791. }
  7792. return Result;
  7793. }
  7794. //---------------------------------------------------------------------------
  7795. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7796. const UnicodeString TempDir, int SecDelay)
  7797. {
  7798. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7799. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7800. if (FDelayedDeletionTimer == NULL)
  7801. {
  7802. DebugAssert(HandleAllocated());
  7803. FDelayedDeletionTimer = new TTimer(this);
  7804. FDelayedDeletionTimer->Interval = 10000;
  7805. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7806. }
  7807. else
  7808. {
  7809. FDelayedDeletionTimer->Enabled = true;
  7810. }
  7811. }
  7812. //---------------------------------------------------------------------------
  7813. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7814. {
  7815. DebugAssert(FDelayedDeletionList != NULL);
  7816. TDateTime N = Now();
  7817. TDateTime Alert;
  7818. UnicodeString Directory;
  7819. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7820. {
  7821. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7822. if ((N >= Alert) || (Sender == NULL))
  7823. {
  7824. Directory = FDelayedDeletionList->Strings[Index];
  7825. if (RecursiveDeleteFile(ExcludeTrailingBackslash(Directory)))
  7826. {
  7827. FDelayedDeletionList->Delete(Index);
  7828. }
  7829. }
  7830. }
  7831. if (FDelayedDeletionList->Count == 0)
  7832. {
  7833. FDelayedDeletionTimer->Enabled = false;
  7834. }
  7835. }
  7836. //---------------------------------------------------------------------------
  7837. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7838. {
  7839. DebugAssert(!IsLocalBrowserMode());
  7840. if (IsFileControl(FDDTargetControl, osRemote) ||
  7841. (FDDTargetControl == SessionsPageControl))
  7842. {
  7843. TManagedTerminal * TargetTerminal = NULL;
  7844. TFileOperation Operation = foNone;
  7845. if (FDDTargetControl == SessionsPageControl)
  7846. {
  7847. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7848. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7849. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7850. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7851. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7852. {
  7853. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7854. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7855. {
  7856. Operation = foRemoteMove;
  7857. }
  7858. else
  7859. {
  7860. Operation = foRemoteCopy;
  7861. }
  7862. }
  7863. }
  7864. else
  7865. {
  7866. if (FLastDropEffect == DROPEFFECT_MOVE)
  7867. {
  7868. Operation = foRemoteMove;
  7869. }
  7870. else if (FLastDropEffect == DROPEFFECT_COPY)
  7871. {
  7872. Operation = foRemoteCopy;
  7873. }
  7874. }
  7875. if (Operation != foNone)
  7876. {
  7877. RemoteFileControlFileOperation(DropSourceControl,
  7878. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7879. }
  7880. // abort drag&drop
  7881. Abort();
  7882. }
  7883. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7884. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7885. (FDDTargetControl != QueueView3))
  7886. {
  7887. DebugAssert(!FDragTempDir.IsEmpty());
  7888. TTransferType Type;
  7889. UnicodeString TempDir = FDragTempDir;
  7890. // We clear FDragTempDir before calling
  7891. // just in case it fail (raises exception)
  7892. FDragTempDir = L"";
  7893. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7894. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7895. // empty directory parameter means temp directory -> don't display it!
  7896. UnicodeString TargetDir = L"";
  7897. int Options = 0;
  7898. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7899. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7900. {
  7901. Abort();
  7902. }
  7903. // TargetDir is set when dropped on local file control
  7904. // (this was workaround for legacy dirview event handling, now it should be
  7905. // made prettier)
  7906. if (TargetDir.IsEmpty())
  7907. {
  7908. TargetDir = TempDir;
  7909. if (ForceDirectories(ApiPath(TargetDir)))
  7910. {
  7911. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7912. FPendingTempSpaceWarn = true;
  7913. try
  7914. {
  7915. FDragDropOperation = true;
  7916. int Params = cpTemporary |
  7917. (Type == ttMove ? cpDelete : 0);
  7918. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7919. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7920. }
  7921. __finally
  7922. {
  7923. FDragDropOperation = false;
  7924. FPendingTempSpaceWarn = false;
  7925. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7926. }
  7927. }
  7928. else
  7929. {
  7930. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7931. }
  7932. }
  7933. }
  7934. }
  7935. //---------------------------------------------------------------------------
  7936. void __fastcall TCustomScpExplorerForm::DDDownload(
  7937. TStrings * FilesToCopy, const UnicodeString & TargetDir, TCopyParamType * CopyParam, int Params)
  7938. {
  7939. DebugAssert(!IsLocalBrowserMode());
  7940. TAutoBatch AutoBatch(this);
  7941. CopyParam->IncludeFileMask.SetRoots(TargetDir, FilesToCopy);
  7942. UpdateCopyParamCounters(*CopyParam);
  7943. FMoveToQueue = false;
  7944. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7945. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7946. {
  7947. RemoteDriveView->UpdateDropSource();
  7948. }
  7949. }
  7950. //---------------------------------------------------------------------------
  7951. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7952. {
  7953. public:
  7954. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7955. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7956. {
  7957. }
  7958. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7959. {
  7960. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7961. TDataObjectFilesEx::AllowData(FormatEtc);
  7962. }
  7963. };
  7964. //---------------------------------------------------------------------------
  7965. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7966. TObject * Sender, TDataObject *& DataObject)
  7967. {
  7968. if (FDDExtMapFile != NULL)
  7969. {
  7970. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7971. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7972. {
  7973. Abort();
  7974. }
  7975. if (FileList->Count > 0)
  7976. {
  7977. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7978. if (!FilesObject->IsValid(true, true))
  7979. {
  7980. FilesObject->_Release();
  7981. }
  7982. else
  7983. {
  7984. DataObject = FilesObject;
  7985. }
  7986. }
  7987. }
  7988. }
  7989. //---------------------------------------------------------------------------
  7990. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7991. {
  7992. DebugFail();
  7993. }
  7994. //---------------------------------------------------------------------------
  7995. void __fastcall TCustomScpExplorerForm::GoToTree()
  7996. {
  7997. ComponentVisible[fcRemoteTree] = true;
  7998. DriveView(osRemote)->SetFocus();
  7999. }
  8000. //---------------------------------------------------------------------------
  8001. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8002. TPanelExport Export)
  8003. {
  8004. TCustomDirView * DirView = this->DirView(Side);
  8005. std::unique_ptr<TStrings> ExportData(new TStringList());
  8006. switch (Export)
  8007. {
  8008. case pePath:
  8009. ExportData->Add(DirView->PathName);
  8010. break;
  8011. case peFileList:
  8012. case peFullFileList:
  8013. {
  8014. bool FullPath = (Export == peFullFileList);
  8015. DirView->CreateFileList(false, FullPath, ExportData.get());
  8016. for (int Index = 0; Index < ExportData->Count; Index++)
  8017. {
  8018. if (ExportData->Strings[Index].Pos(L" ") > 0)
  8019. {
  8020. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  8021. }
  8022. }
  8023. }
  8024. break;
  8025. default:
  8026. DebugFail();
  8027. }
  8028. return ExportData.release();
  8029. }
  8030. //---------------------------------------------------------------------------
  8031. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8032. TPanelExport Export, TPanelExportDestination Destination)
  8033. {
  8034. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  8035. PanelExportStore(Side, Export, Destination, ExportData.get());
  8036. }
  8037. //---------------------------------------------------------------------------
  8038. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  8039. TPanelExport /*Export*/, TPanelExportDestination Destination,
  8040. TStrings * ExportData)
  8041. {
  8042. if (Destination == pedClipboard)
  8043. {
  8044. TInstantOperationVisualizer Visualizer;
  8045. CopyToClipboard(ExportData);
  8046. }
  8047. else
  8048. {
  8049. DebugFail();
  8050. }
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  8054. {
  8055. TCustomDirView * DirView = this->DirView(Side);
  8056. UnicodeString Mask = DirView->Mask;
  8057. if (DoFilterMaskDialog(DirView, Mask))
  8058. {
  8059. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  8060. Configuration->Usage->Inc(L"Filters");
  8061. }
  8062. }
  8063. //---------------------------------------------------------------------------
  8064. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  8065. {
  8066. return FQueueController->DefaultOperation();
  8067. }
  8068. //---------------------------------------------------------------------------
  8069. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  8070. TQueueOperation Operation, void ** Param)
  8071. {
  8072. switch (Operation)
  8073. {
  8074. case qoPreferences:
  8075. return true;
  8076. case qoGoTo:
  8077. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  8078. case qoOnceEmpty:
  8079. return IsAnythingQueued();
  8080. default:
  8081. return FQueueController->AllowOperation(Operation, Param);
  8082. }
  8083. }
  8084. //---------------------------------------------------------------------------
  8085. void __fastcall TCustomScpExplorerForm::GoToQueue()
  8086. {
  8087. if (DebugAlwaysTrue(QueueView3->Visible))
  8088. {
  8089. QueueView3->SetFocus();
  8090. }
  8091. }
  8092. //---------------------------------------------------------------------------
  8093. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  8094. TQueueOperation Operation, void * Param)
  8095. {
  8096. if (Operation == qoGoTo)
  8097. {
  8098. GoToQueue();
  8099. }
  8100. else if (Operation == qoPreferences)
  8101. {
  8102. PreferencesDialog(pmQueue);
  8103. }
  8104. else
  8105. {
  8106. FQueueController->ExecuteOperation(Operation, Param);
  8107. }
  8108. }
  8109. //---------------------------------------------------------------------------
  8110. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  8111. {
  8112. return (Queue != NULL) && Queue->Enabled;
  8113. }
  8114. //---------------------------------------------------------------------------
  8115. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  8116. {
  8117. DebugAssert(Queue != NULL);
  8118. if (Queue != NULL)
  8119. {
  8120. Queue->Enabled = !Queue->Enabled;
  8121. }
  8122. }
  8123. //---------------------------------------------------------------------------
  8124. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  8125. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  8126. {
  8127. FQueueActedItem = QueueView3->ItemFocused;
  8128. }
  8129. //---------------------------------------------------------------------------
  8130. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  8131. {
  8132. return TopDock->Height + (MessageDock->Visible ? MessageDock->Height : 0) + QueueSplitter->Height;
  8133. }
  8134. //---------------------------------------------------------------------------
  8135. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  8136. {
  8137. return
  8138. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  8139. (QueueDock->Visible ? QueueDock->Height : 0) +
  8140. (QueueLabel->Visible ? QueueLabel->Height : 0);
  8141. }
  8142. //---------------------------------------------------------------------------
  8143. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  8144. {
  8145. return ScaleByTextHeight(this, 48);
  8146. }
  8147. //---------------------------------------------------------------------------
  8148. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  8149. TObject * /*Sender*/, int & NewSize, bool & Accept)
  8150. {
  8151. // when queue is hidden by double-clicking splitter, stray attempt to
  8152. // resize the panel with strange value arrives, make sure it is ignored
  8153. if (ComponentVisible[fcQueueView])
  8154. {
  8155. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  8156. if (NewSize > MaxHeightLimit)
  8157. {
  8158. NewSize = MaxHeightLimit;
  8159. }
  8160. int MinHeightLimit =
  8161. GetStaticQueuePanelComponentsHeight() +
  8162. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  8163. GetMinQueueViewHeight();
  8164. if (NewSize < MinHeightLimit)
  8165. {
  8166. NewSize = MinHeightLimit;
  8167. }
  8168. }
  8169. else
  8170. {
  8171. Accept = false;
  8172. }
  8173. }
  8174. //---------------------------------------------------------------------------
  8175. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  8176. {
  8177. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  8178. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  8179. if (QueueViewHeight < GetMinQueueViewHeight())
  8180. {
  8181. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  8182. }
  8183. }
  8184. //---------------------------------------------------------------------------
  8185. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  8186. TDragObject *& /*DragObject*/)
  8187. {
  8188. FQueueActedItem = QueueView3->ItemFocused;
  8189. FQueueScrollOnDragOver->StartDrag();
  8190. }
  8191. //---------------------------------------------------------------------------
  8192. void __fastcall TCustomScpExplorerForm::QueueView3EndDrag(
  8193. TObject *, TObject * DebugUsedArg(Target), int DebugUsedArg(X), int DebugUsedArg(Y))
  8194. {
  8195. FQueueScrollOnDragOver->EndDrag();
  8196. }
  8197. //---------------------------------------------------------------------------
  8198. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  8199. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  8200. {
  8201. Accept = true;
  8202. if (Source == QueueView3)
  8203. {
  8204. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  8205. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  8206. if (Accept)
  8207. {
  8208. TQueueItemProxy * QueueItem;
  8209. TQueueItemProxy * DestQueueItem;
  8210. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8211. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  8212. Accept = (QueueItem != DestQueueItem) &&
  8213. (QueueItem->Status == TQueueItem::qsPending) &&
  8214. (DestQueueItem->Status == TQueueItem::qsPending);
  8215. }
  8216. FQueueScrollOnDragOver->DragOver(TPoint(X, Y));
  8217. }
  8218. }
  8219. //---------------------------------------------------------------------------
  8220. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  8221. TObject * /*Source*/, int /*X*/, int /*Y*/)
  8222. {
  8223. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  8224. {
  8225. TQueueItemProxy * QueueItem;
  8226. TQueueItemProxy * DestQueueItem;
  8227. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8228. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  8229. QueueItem->Move(DestQueueItem);
  8230. }
  8231. }
  8232. //---------------------------------------------------------------------------
  8233. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  8234. {
  8235. if ((QueueView3->ItemFocused == NULL) &&
  8236. (QueueView3->Items->Count > 0))
  8237. {
  8238. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  8239. }
  8240. QueueLabelUpdateStatus();
  8241. }
  8242. //---------------------------------------------------------------------------
  8243. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  8244. {
  8245. QueueLabelUpdateStatus();
  8246. }
  8247. //---------------------------------------------------------------------------
  8248. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  8249. {
  8250. QueueLabel->UpdateStatus();
  8251. }
  8252. //---------------------------------------------------------------------------
  8253. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  8254. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  8255. {
  8256. if (Selected)
  8257. {
  8258. NonVisualDataModule->UpdateNonVisibleActions();
  8259. }
  8260. }
  8261. //---------------------------------------------------------------------------
  8262. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  8263. {
  8264. TDragDropFilesEx * Result = NULL;
  8265. if (Sender == SessionsPageControl)
  8266. {
  8267. Result = FSessionsDragDropFilesEx;
  8268. }
  8269. else if (Sender == QueueView3)
  8270. {
  8271. Result = FQueueDragDropFilesEx;
  8272. }
  8273. else
  8274. {
  8275. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8276. if (DirView != NULL)
  8277. {
  8278. Result = DirView->DragDropFilesEx;
  8279. }
  8280. else
  8281. {
  8282. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  8283. if (DriveView != NULL)
  8284. {
  8285. Result = DriveView->DragDropFilesEx;
  8286. }
  8287. }
  8288. }
  8289. DebugAssert(Result != NULL);
  8290. return Result;
  8291. }
  8292. //---------------------------------------------------------------------------
  8293. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  8294. {
  8295. return (DView->SelCount == DView->FilesCount);
  8296. }
  8297. //---------------------------------------------------------------------------
  8298. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  8299. {
  8300. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  8301. }
  8302. //---------------------------------------------------------------------------
  8303. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  8304. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  8305. {
  8306. DebugAssert(!IsLocalBrowserMode());
  8307. TFileOperation Operation;
  8308. switch (Effect)
  8309. {
  8310. case DROPEFFECT_MOVE:
  8311. Operation = foMove;
  8312. break;
  8313. case DROPEFFECT_COPY:
  8314. // occures on WinXP (reported by user)
  8315. default:
  8316. Operation = foCopy;
  8317. break;
  8318. };
  8319. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  8320. // see a comment in TUnixDirView::PerformItemDragDropOperation
  8321. if (DragDropFilesEx->FileList->Count > 0)
  8322. {
  8323. TStrings * FileList = new TStringList();
  8324. try
  8325. {
  8326. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  8327. {
  8328. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  8329. }
  8330. FDragDropOperation = true;
  8331. TTransferOperationParam Param;
  8332. Param.TargetDirectory = TargetPath;
  8333. // upload, no temp dirs
  8334. Param.Temp = false;
  8335. Param.DragDrop = DragDrop;
  8336. Param.Options =
  8337. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  8338. if (ForceQueue)
  8339. {
  8340. Param.Queue = asOn;
  8341. }
  8342. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  8343. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  8344. {
  8345. if (IsFileControl(DropSourceControl, osLocal))
  8346. {
  8347. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  8348. }
  8349. else
  8350. {
  8351. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  8352. }
  8353. }
  8354. }
  8355. __finally
  8356. {
  8357. FDragDropOperation = false;
  8358. delete FileList;
  8359. }
  8360. }
  8361. }
  8362. //---------------------------------------------------------------------------
  8363. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  8364. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  8365. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  8366. {
  8367. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  8368. }
  8369. //---------------------------------------------------------------------------
  8370. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  8371. TObject * Sender, int grfKeyState, int & dwEffect)
  8372. {
  8373. DebugAssert(!IsLocalBrowserMode());
  8374. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  8375. if ((dwEffect != DROPEFFECT_NONE) &&
  8376. IsFileControl(DropSourceControl, osRemote))
  8377. {
  8378. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8379. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8380. (RemoteDirView->DropTarget == NULL))
  8381. {
  8382. dwEffect = DROPEFFECT_NONE;
  8383. }
  8384. else
  8385. {
  8386. if (dwEffect == DROPEFFECT_COPY)
  8387. {
  8388. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8389. // currently we support copying always (at least via temporary directory);
  8390. // remove associated checks once this all proves stable and working
  8391. bool CopyCapable = true;
  8392. // if we do not support neither of operations, there's no discussion
  8393. if (!MoveCapable && !CopyCapable)
  8394. {
  8395. dwEffect = DROPEFFECT_NONE;
  8396. }
  8397. else
  8398. {
  8399. // The default effect inside remote panel is move,
  8400. // unless we do not support it, but support copy
  8401. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8402. {
  8403. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8404. }
  8405. else
  8406. {
  8407. // with ctrl-down, we want copy unless it is not supported
  8408. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8409. }
  8410. }
  8411. }
  8412. }
  8413. }
  8414. }
  8415. //---------------------------------------------------------------------------
  8416. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8417. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8418. {
  8419. DebugAssert(!IsLocalBrowserMode());
  8420. if (FDDTotalSize >= 0)
  8421. {
  8422. if (File->IsDirectory)
  8423. {
  8424. FDDTotalSize = -1;
  8425. }
  8426. else
  8427. {
  8428. FDDTotalSize += File->Size;
  8429. }
  8430. }
  8431. DebugAssert(!FDragTempDir.IsEmpty());
  8432. // TODO: this is quite ineffective
  8433. // TODO: what if invalid character replacement is disabled?
  8434. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8435. UnicodeString TransferFileName;
  8436. if (Sender == RemoteDriveView)
  8437. {
  8438. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8439. }
  8440. else
  8441. {
  8442. TransferFileName = File->FileName;
  8443. }
  8444. FDDFileList->AddObject(TransferFileName, File);
  8445. }
  8446. //---------------------------------------------------------------------------
  8447. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8448. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8449. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8450. {
  8451. // sometimes we do not get DDEnd so the list is not released
  8452. SAFE_DESTROY(FDDFileList);
  8453. FDDFileList = new TStringList();
  8454. FDragTempDir = WinConfiguration->TemporaryDir();
  8455. FDDTotalSize = 0;
  8456. FDragDropSshTerminate.reset(NULL);
  8457. }
  8458. //---------------------------------------------------------------------------
  8459. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8460. TObject * /*Sender*/, LongBool /*FEscapePressed*/, int /*grfKeyState*/,
  8461. HRESULT & Result)
  8462. {
  8463. if (Result == DRAGDROP_S_DROP)
  8464. {
  8465. try
  8466. {
  8467. GlobalDragImageList->HideDragImage();
  8468. try
  8469. {
  8470. RemoteFileControlDDTargetDrop();
  8471. }
  8472. catch(ESshTerminate & E)
  8473. {
  8474. FDragDropSshTerminate.reset(E.Clone());
  8475. }
  8476. }
  8477. catch (Exception &E)
  8478. {
  8479. // If downloading fails we need to cancel drag&drop, otherwise
  8480. // Explorer shows error
  8481. // But by the way exception probably never reach this point as
  8482. // it's catched on way.
  8483. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8484. Result = DRAGDROP_S_CANCEL;
  8485. ShowExtendedException(Terminal, &E);
  8486. }
  8487. }
  8488. }
  8489. //---------------------------------------------------------------------------
  8490. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8491. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8492. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8493. {
  8494. TFileMasks::TParams MaskParams;
  8495. MaskParams.Size = Size;
  8496. MaskParams.Modification = Modification;
  8497. // this does not re-parse the mask if it is the same as the last time
  8498. FDirViewMatchMask = Masks;
  8499. bool ImplicitMatch;
  8500. Matches =
  8501. // Local and RecurseInclude parameters have no effect as there's no path.
  8502. // This should use potential MatchesFileName overload with ImplicitMatch argument.
  8503. FDirViewMatchMask.Matches(FileName, false, Directory, &MaskParams, true, ImplicitMatch) &&
  8504. (AllowImplicitMatches || !ImplicitMatch);
  8505. }
  8506. //---------------------------------------------------------------------------
  8507. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8508. TObject * Sender, TListItem * Item, WORD & Indexes)
  8509. {
  8510. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8511. if (GetPartialFileExtLen(DirView->ItemFileName(Item)) > 0)
  8512. {
  8513. Indexes |= oiPartial;
  8514. }
  8515. }
  8516. //---------------------------------------------------------------------------
  8517. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8518. {
  8519. return
  8520. DirViewEnabled(osCurrent) &&
  8521. DirView(osCurrent)->CanPasteFromClipBoard();
  8522. }
  8523. //---------------------------------------------------------------------------
  8524. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8525. {
  8526. bool Result = false;
  8527. if (CanPasteToDirViewFromClipBoard())
  8528. {
  8529. Result = true;
  8530. }
  8531. else
  8532. {
  8533. UnicodeString ClipboardText;
  8534. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8535. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8536. {
  8537. if (StoredSessions->IsUrl(ClipboardText))
  8538. {
  8539. Result = true;
  8540. }
  8541. else
  8542. {
  8543. Result = DirViewEnabled(osCurrent);
  8544. }
  8545. }
  8546. }
  8547. return Result;
  8548. }
  8549. //---------------------------------------------------------------------------
  8550. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8551. {
  8552. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8553. if (DoesClipboardContainOurFiles())
  8554. {
  8555. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8556. {
  8557. DebugAssert(!IsLocalBrowserMode());
  8558. TTerminalManager * Manager = TTerminalManager::Instance();
  8559. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8560. Manager->ActiveSession = FClipboardTerminal;
  8561. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8562. }
  8563. }
  8564. else if (CanPasteToDirViewFromClipBoard())
  8565. {
  8566. DirView(osCurrent)->PasteFromClipBoard();
  8567. }
  8568. else
  8569. {
  8570. UnicodeString ClipboardText;
  8571. if (NonEmptyTextFromClipboard(ClipboardText))
  8572. {
  8573. if (StoredSessions->IsUrl(ClipboardText))
  8574. {
  8575. NewSession(ClipboardText);
  8576. }
  8577. else
  8578. {
  8579. DirView(osCurrent)->Path = ClipboardText;
  8580. }
  8581. }
  8582. }
  8583. }
  8584. //---------------------------------------------------------------------------
  8585. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8586. {
  8587. // TBD
  8588. }
  8589. //---------------------------------------------------------------------------
  8590. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8591. {
  8592. TCustomDirView * ADirView = DirView(Side);
  8593. ADirView->SelectAll(Mode);
  8594. ADirView->SetFocus();
  8595. }
  8596. //---------------------------------------------------------------------------
  8597. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8598. {
  8599. TCustomDirView * ADirView = DirView(Side);
  8600. TFileFilter Filter;
  8601. DefaultFileFilter(Filter);
  8602. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8603. {
  8604. Configuration->Usage->Inc(L"MaskSelections");
  8605. ADirView->SelectFiles(Filter, Select);
  8606. ADirView->SetFocus();
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8611. {
  8612. TCustomDirView * ADirView = DirView(Side);
  8613. ADirView->RestoreSelectedNames();
  8614. ADirView->SetFocus();
  8615. }
  8616. //---------------------------------------------------------------------------
  8617. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8618. {
  8619. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8620. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8621. {
  8622. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8623. UnicodeString Ext;
  8624. if (!IsSideLocalBrowser(osCurrent))
  8625. {
  8626. Ext = UnixExtractFileExt(FileName);
  8627. }
  8628. else
  8629. {
  8630. Ext = ExtractFileExt(FileName);
  8631. }
  8632. if (Ext.IsEmpty())
  8633. {
  8634. Ext = L".";
  8635. }
  8636. TFileFilter Filter;
  8637. Filter.Masks = FORMAT(L"*%s", (Ext));
  8638. Filter.Directories = false;
  8639. CurrentDirView->SelectFiles(Filter, Select);
  8640. }
  8641. }
  8642. //---------------------------------------------------------------------------
  8643. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8644. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8645. {
  8646. UnicodeString Result;
  8647. if (FIncrementalSearchState.Searching && (Side == GetSide(osCurrent)))
  8648. {
  8649. Result = FormatIncrementalSearchStatus(FIncrementalSearchState);
  8650. }
  8651. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8652. {
  8653. // noop
  8654. }
  8655. else
  8656. {
  8657. Result =
  8658. FMTLOAD(FILE_INFO_FORMAT,
  8659. (FormatBytes(FileInfo.SelectedSize),
  8660. FormatBytes(FileInfo.FilesSize),
  8661. FormatNumber(FileInfo.SelectedCount),
  8662. FormatNumber(FileInfo.FilesCount)));
  8663. }
  8664. return Result;
  8665. }
  8666. //---------------------------------------------------------------------------
  8667. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8668. TTBXStatusPanel * Panel, TOperationSide Side)
  8669. {
  8670. if (Panel->Index == 1)
  8671. {
  8672. ToggleShowHiddenFiles();
  8673. }
  8674. else if (Panel->Index == 2)
  8675. {
  8676. Filter(Side);
  8677. }
  8678. }
  8679. //---------------------------------------------------------------------------
  8680. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8681. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8682. {
  8683. DebugAssert(!StatusBar->SimplePanel);
  8684. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8685. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8686. }
  8687. //---------------------------------------------------------------------------
  8688. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8689. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8690. {
  8691. DebugAssert(StatusBar->Panels->Count >= 3);
  8692. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8693. if (FileInfo.HiddenCount > 0)
  8694. {
  8695. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8696. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8697. }
  8698. else
  8699. {
  8700. HiddenFilesPanel->ViewPriority = 0;
  8701. // not really necessary, just to cleanup no-longer-valid data
  8702. HiddenFilesPanel->Caption = L"";
  8703. }
  8704. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8705. if (FileInfo.FilteredCount > 0)
  8706. {
  8707. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8708. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8709. }
  8710. else
  8711. {
  8712. FilteredFilesPanel->ViewPriority = 0;
  8713. // not really necessary, just to cleanup no-longer-valid data
  8714. FilteredFilesPanel->Caption = L"";
  8715. }
  8716. }
  8717. //---------------------------------------------------------------------------
  8718. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8719. TObject * /*Sender*/)
  8720. {
  8721. if (DirView(osOther)->Enabled)
  8722. {
  8723. DirView(osOther)->SetFocus();
  8724. }
  8725. }
  8726. //---------------------------------------------------------------------------
  8727. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8728. {
  8729. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8730. switch (Config.Show)
  8731. {
  8732. case qvShow:
  8733. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8734. {
  8735. Config.Show = qvHide;
  8736. }
  8737. else
  8738. {
  8739. Config.Show = Config.LastHideShow;
  8740. }
  8741. break;
  8742. case qvHideWhenEmpty:
  8743. if (ComponentVisible[fcQueueView])
  8744. {
  8745. Config.Show = qvHide;
  8746. }
  8747. else
  8748. {
  8749. Config.LastHideShow = Config.Show;
  8750. Config.Show = qvShow;
  8751. }
  8752. break;
  8753. case qvHide:
  8754. Config.LastHideShow = Config.Show;
  8755. Config.Show = qvShow;
  8756. break;
  8757. }
  8758. WinConfiguration->QueueView = Config;
  8759. }
  8760. //---------------------------------------------------------------------------
  8761. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8762. {
  8763. UnicodeString Result;
  8764. if (Terminal != NULL)
  8765. {
  8766. switch (WinConfiguration->PathInCaption)
  8767. {
  8768. case picShort:
  8769. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8770. break;
  8771. case picFull:
  8772. Result = Terminal->CurrentDirectory;
  8773. break;
  8774. }
  8775. }
  8776. return Result;
  8777. }
  8778. //---------------------------------------------------------------------------
  8779. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8780. {
  8781. TColor Result = GetWindowColor(FSessionColor);
  8782. return Result;
  8783. }
  8784. //---------------------------------------------------------------------------
  8785. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8786. {
  8787. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8788. return Result;
  8789. }
  8790. //---------------------------------------------------------------------------
  8791. void TCustomScpExplorerForm::UpdatePanelControls(TCustomDirView * ADirView, TCustomDriveView * ADriveView)
  8792. {
  8793. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8794. ADirView->DarkMode = UseDarkTheme;
  8795. ADriveView->DarkMode = UseDarkTheme;
  8796. }
  8797. //---------------------------------------------------------------------------
  8798. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8799. {
  8800. if (!FSessionChanging)
  8801. {
  8802. TTerminalManager::Instance()->UpdateAppTitle();
  8803. }
  8804. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8805. // background to gray on Windows 7 (works on Windows 10).
  8806. // See also EnableControl
  8807. if (Showing)
  8808. {
  8809. if (ManagedSession != NULL)
  8810. {
  8811. // Update path when it changes
  8812. if ((SessionsPageControl->ActivePage != NULL) &&
  8813. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8814. {
  8815. UpdateSessionTab(SessionsPageControl->ActivePage);
  8816. }
  8817. }
  8818. NonVisualDataModule->ReconnectSessionAction->Update();
  8819. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8820. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8821. CenterReconnectToolbar();
  8822. bool HasTerminal = HasActiveTerminal();
  8823. RemoteDirView->Enabled = HasTerminal;
  8824. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8825. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8826. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8827. RemoteDriveView->Color = RemoteDirView->Color;
  8828. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8829. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8830. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8831. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8832. QueueFileList->Enabled = QueueView3->Enabled;
  8833. QueueFileList->Color = QueueView3->Color;
  8834. QueueFileList->Font->Color = QueueView3->Font->Color;
  8835. QueueLabelUpdateStatus();
  8836. UpdatePanelControls(RemoteDirView, RemoteDriveView);
  8837. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8838. if (FImmersiveDarkMode != UseDarkTheme)
  8839. {
  8840. UpdateDarkMode();
  8841. }
  8842. SessionsPageControl->TabTheme = UseDarkTheme ? CurrentTheme : NULL;
  8843. UnicodeString CurrentHiContrastThemeName = (FHiContrastTheme != NULL) ? FHiContrastTheme->Name : EmptyStr;
  8844. bool HiContrast = WinConfiguration->HiContrast;
  8845. UnicodeString NewHiContrastThemeName = HiContrast ? GetThemeName(!UseDarkTheme) : EmptyStr;
  8846. if (CurrentHiContrastThemeName != NewHiContrastThemeName)
  8847. {
  8848. ReleaseHiContrastTheme();
  8849. if (!NewHiContrastThemeName.IsEmpty())
  8850. {
  8851. FHiContrastTheme = GetTBXTheme(NewHiContrastThemeName);
  8852. }
  8853. }
  8854. SessionsPageControl->ActiveTabTheme = HiContrast ? DebugNotNull(FHiContrastTheme) : NULL;
  8855. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8856. MessageDock->Visible = (MessageDock->ToolbarCount > 0);
  8857. }
  8858. }
  8859. //---------------------------------------------------------------------------
  8860. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8861. {
  8862. UpdateControls();
  8863. }
  8864. //---------------------------------------------------------------------------
  8865. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8866. TObject * Sender)
  8867. {
  8868. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8869. DebugAssert(DirView != NULL);
  8870. DoDirViewLoaded(DirView);
  8871. TransferPresetAutoSelect();
  8872. TUnixDirView * UnixDirView = dynamic_cast<TUnixDirView *>(DirView);
  8873. if (UnixDirView != NULL)
  8874. {
  8875. TManagedTerminal * ATerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(UnixDirView->Terminal));
  8876. TTerminalManager::Instance()->TerminalLoadedDirectory(ATerminal);
  8877. }
  8878. }
  8879. //---------------------------------------------------------------------------
  8880. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8881. {
  8882. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8883. // first run after installation
  8884. if (double(Updates.LastCheck) == 0)
  8885. {
  8886. AppLog(L"First run, scheduling updates check for the next run");
  8887. // make sure next time there will be an update (if enabled)
  8888. Updates.LastCheck = TDateTime(1);
  8889. WinConfiguration->Updates = Updates;
  8890. }
  8891. else
  8892. {
  8893. TDateTime Period;
  8894. if (IsUWP() && !IsOfficialPackage())
  8895. {
  8896. Period = DefaultUpdatesPeriod;
  8897. AppLog(L"Thirdparty UWP package, using default updates check period");
  8898. }
  8899. else
  8900. {
  8901. Period = Updates.Period;
  8902. }
  8903. AppLogFmt(L"Updates check period: %.2f", (double(Period)));
  8904. if (double(Period) > 0)
  8905. {
  8906. TDateTime Interval = Now() - Updates.LastCheck;
  8907. AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
  8908. if (Interval >= Period)
  8909. {
  8910. StartUpdateThread(UpdatesChecked);
  8911. }
  8912. }
  8913. }
  8914. }
  8915. //---------------------------------------------------------------------------
  8916. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8917. {
  8918. AppLog(L"Updates check done");
  8919. UnicodeString Message;
  8920. bool New;
  8921. TQueryType Type;
  8922. GetUpdatesMessage(Message, New, Type, false);
  8923. if (!Message.IsEmpty())
  8924. {
  8925. AppLogFmt(L"Updates check message: %s", (Message));
  8926. if (New)
  8927. {
  8928. AppLog(L"New version detected");
  8929. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8930. }
  8931. if (!New && (Type != qtWarning))
  8932. {
  8933. AppLog(L"Posting non-critical updates note");
  8934. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8935. }
  8936. else
  8937. {
  8938. AppLog(L"Posting new version or critical message notification");
  8939. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8940. }
  8941. if (New)
  8942. {
  8943. Configuration->Usage->Inc(L"UpdateNotifications");
  8944. }
  8945. }
  8946. }
  8947. //---------------------------------------------------------------------------
  8948. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8949. {
  8950. RestoreApp();
  8951. bool CanDisplay = !NonVisualDataModule->Busy;
  8952. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8953. {
  8954. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8955. }
  8956. if (CanDisplay)
  8957. {
  8958. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8959. // Probably not needed as CheckForUpdates is blocking since we started using neon for HTTP implementation.
  8960. NonVisualDataModule->StartBusy();
  8961. try
  8962. {
  8963. CheckForUpdates(true);
  8964. }
  8965. __finally
  8966. {
  8967. NonVisualDataModule->EndBusy();
  8968. }
  8969. }
  8970. else
  8971. {
  8972. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8973. }
  8974. }
  8975. //---------------------------------------------------------------------------
  8976. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8977. TCopyParamRuleData & Data)
  8978. {
  8979. DebugAssert(Terminal != NULL);
  8980. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8981. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8982. Data.RemoteDirectory = RemoteDirView->PathName;
  8983. }
  8984. //---------------------------------------------------------------------------
  8985. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8986. {
  8987. // Terminal can be null when we are changing local directory implicitly,
  8988. // because it has been deleted, while no session is connected
  8989. // (Login dialog is open)
  8990. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8991. {
  8992. DebugAssert(!IsLocalBrowserMode());
  8993. TCopyParamRuleData Data;
  8994. GetTransferPresetAutoSelectData(Data);
  8995. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8996. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8997. if (CopyParamIndex < 0)
  8998. {
  8999. // there is no preset that matches autoselection
  9000. // set preset that we consider "default"
  9001. FCopyParamAutoSelected = L""; // forget last autoselected preset
  9002. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  9003. }
  9004. else
  9005. {
  9006. // there is preset matching autoselection
  9007. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  9008. if (CopyParamName == FCopyParamAutoSelected)
  9009. {
  9010. // autoselected the same preset as the last time
  9011. // make no change (i.e. preserve custom user preset, if any)
  9012. }
  9013. else
  9014. {
  9015. // autoselected the different preset then the last time (or there
  9016. // was default preset set)
  9017. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  9018. GUIConfiguration->CopyParamCurrent = CopyParamName;
  9019. }
  9020. }
  9021. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  9022. {
  9023. if (CopyParamIndex >= 0)
  9024. {
  9025. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  9026. }
  9027. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  9028. try
  9029. {
  9030. int Fmt =
  9031. (CopyParamIndex < 0) ?
  9032. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  9033. COPY_PARAM_AUTOSELECTED;
  9034. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  9035. Data->Message = MainInstructions(Message);
  9036. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  9037. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  9038. CopyParamAttrs);
  9039. if (CopyParamIndex >= 0)
  9040. {
  9041. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  9042. Info = FORMAT(L"%s\n \n%s", (Info,
  9043. FMTLOAD(COPY_PARAM_RULE,
  9044. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  9045. }
  9046. Data->Message += L"\n\n" + Info;
  9047. if (WinConfiguration->CopyParamAutoSelectNotice)
  9048. {
  9049. TransferPresetNoteMessage(Data, true);
  9050. }
  9051. else
  9052. {
  9053. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  9054. Data = NULL; // ownership passed
  9055. }
  9056. }
  9057. __finally
  9058. {
  9059. delete Data;
  9060. }
  9061. }
  9062. }
  9063. }
  9064. //---------------------------------------------------------------------------
  9065. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  9066. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  9067. {
  9068. DebugAssert(NoteData != NULL);
  9069. DebugAssert(!IsLocalBrowserMode());
  9070. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  9071. TQueryButtonAlias Aliases[1];
  9072. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  9073. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  9074. Params.Aliases = Aliases;
  9075. Params.AliasesCount = LENOF(Aliases);
  9076. unsigned int Result =
  9077. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  9078. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  9079. switch (Result)
  9080. {
  9081. case qaNeverAskAgain:
  9082. DebugAssert(AllowNeverAskAgain);
  9083. WinConfiguration->CopyParamAutoSelectNotice = false;
  9084. break;
  9085. case qaIgnore:
  9086. PreferencesDialog(pmPresets);
  9087. break;
  9088. }
  9089. }
  9090. //---------------------------------------------------------------------------
  9091. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  9092. {
  9093. // as of now useless, as this is used for notes only, never for balloons, ...
  9094. RestoreApp();
  9095. // .. and we should never be busy here
  9096. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  9097. {
  9098. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  9099. }
  9100. }
  9101. //---------------------------------------------------------------------------
  9102. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  9103. TPreferencesMode APreferencesMode)
  9104. {
  9105. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  9106. TCopyParamRuleData Data;
  9107. if (Terminal != NULL)
  9108. {
  9109. PreferencesData.reset(new TPreferencesDialogData());
  9110. GetTransferPresetAutoSelectData(Data);
  9111. PreferencesData->CopyParamRuleData = &Data;
  9112. }
  9113. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  9114. }
  9115. //---------------------------------------------------------------------------
  9116. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  9117. const TCustomCommandType & Command)
  9118. {
  9119. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  9120. {
  9121. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  9122. }
  9123. }
  9124. //---------------------------------------------------------------------------
  9125. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  9126. {
  9127. bool RemoteAllowed = CustomCommandRemoteAllowed();
  9128. TCustomCommandType Command;
  9129. // make sure we use local custom command when remote are not supported
  9130. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  9131. {
  9132. Command = FLastCustomCommand;
  9133. }
  9134. else
  9135. {
  9136. Command.Params = Command.Params | ccLocal;
  9137. }
  9138. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  9139. FEditingFocusedAdHocCommand = OnFocused;
  9140. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  9141. int Options =
  9142. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  9143. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  9144. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  9145. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  9146. {
  9147. FLastCustomCommand = Command;
  9148. UpdateCustomCommandsToolbar();
  9149. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  9150. }
  9151. }
  9152. //---------------------------------------------------------------------------
  9153. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  9154. {
  9155. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  9156. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9157. DebugAssert(State > 0);
  9158. if (State <= 0)
  9159. {
  9160. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  9161. }
  9162. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  9163. }
  9164. //---------------------------------------------------------------------------
  9165. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  9166. TCustomCommandType & Command, int & State)
  9167. {
  9168. bool Result = !FLastCustomCommand.Command.IsEmpty();
  9169. if (Result)
  9170. {
  9171. Command = FLastCustomCommand;
  9172. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9173. }
  9174. return Result;
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::BeforeAction()
  9178. {
  9179. ResetIncrementalSearch();
  9180. }
  9181. //---------------------------------------------------------------------------
  9182. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  9183. {
  9184. DebugAssert(ComponentVisible[Component]);
  9185. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  9186. }
  9187. //---------------------------------------------------------------------------
  9188. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  9189. {
  9190. // when queue panel is resized here directly, the status bar is stretched
  9191. // over whole space the panel occupied
  9192. PostComponentHide(fcQueueView);
  9193. }
  9194. //---------------------------------------------------------------------------
  9195. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  9196. {
  9197. ComponentVisible[fcQueueFileList] = false;
  9198. }
  9199. //---------------------------------------------------------------------------
  9200. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  9201. {
  9202. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  9203. RefreshColorMode();
  9204. ResetSysDarkTheme();
  9205. ConfigurationChanged();
  9206. ConfigureInterface();
  9207. // Should be called for all controls
  9208. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  9209. }
  9210. //---------------------------------------------------------------------------
  9211. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  9212. {
  9213. // Do not handle, when shutting down anyway (maybe also when not setup completely yet?)
  9214. if (!FInvalid &&
  9215. (Message.LParam != 0) &&
  9216. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  9217. {
  9218. ThemeChanged();
  9219. }
  9220. TForm::Dispatch(&Message);
  9221. }
  9222. //---------------------------------------------------------------------------
  9223. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  9224. {
  9225. TMessage * M = static_cast<TMessage*>(Message);
  9226. switch (M->Msg)
  9227. {
  9228. case CM_DIALOGCHAR:
  9229. CMDialogChar(*M);
  9230. break;
  9231. case WM_APPCOMMAND:
  9232. WMAppCommand(*M);
  9233. break;
  9234. case WM_SYSCOMMAND:
  9235. WMSysCommand(*M);
  9236. break;
  9237. case WM_QUERYENDSESSION:
  9238. WMQueryEndSession(*M);
  9239. break;
  9240. case WM_ENDSESSION:
  9241. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  9242. break;
  9243. #ifdef _DEBUG
  9244. case WM_WINDOWPOSCHANGED:
  9245. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  9246. break;
  9247. case CM_CUSTOMSTYLECHANGED:
  9248. TForm::Dispatch(Message);
  9249. break;
  9250. #endif
  9251. case WM_COMPONENT_HIDE:
  9252. {
  9253. Byte Component = static_cast<Byte>(M->WParam);
  9254. // sanity check
  9255. if (ComponentVisible[Component])
  9256. {
  9257. // special treatment
  9258. if (Component == fcQueueView)
  9259. {
  9260. ToggleQueueVisibility();
  9261. DebugAssert(!ComponentVisible[fcQueueView]);
  9262. }
  9263. else
  9264. {
  9265. ComponentVisible[Component] = false;
  9266. }
  9267. }
  9268. }
  9269. break;
  9270. case WM_COPYDATA:
  9271. WMCopyData(*M);
  9272. break;
  9273. case WM_MANAGES_CAPTION:
  9274. // caption managed in TTerminalManager::UpdateAppTitle()
  9275. M->Result = 1;
  9276. break;
  9277. case WM_WANTS_MOUSEWHEEL:
  9278. M->Result = 1;
  9279. break;
  9280. case CM_SHOWINGCHANGED:
  9281. CMShowingChanged(*M);
  9282. break;
  9283. case WM_CLOSE:
  9284. WMClose(*M);
  9285. break;
  9286. case WM_DPICHANGED:
  9287. WMDpiChanged(*M);
  9288. break;
  9289. case WM_SETTINGCHANGE:
  9290. WMSettingChange(*M);
  9291. break;
  9292. case CM_DIALOGKEY:
  9293. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  9294. break;
  9295. case WM_PASTE_FILES:
  9296. PasteFiles();
  9297. break;
  9298. case WM_IS_HIDDEN:
  9299. // To treat master password prompt as a main window while showing it when workspace is loading while
  9300. // the exporer is showing up (Visible is true already)
  9301. M->Result = !FShowing;
  9302. break;
  9303. case WM_SHOWWINDOW:
  9304. if (M->WParam)
  9305. {
  9306. AddStartupSequence(L"J");
  9307. }
  9308. TForm::Dispatch(Message);
  9309. break;
  9310. case WM_QUEUE_CALLBACK:
  9311. WMQueueCallback(*M);
  9312. break;
  9313. default:
  9314. TForm::Dispatch(Message);
  9315. break;
  9316. }
  9317. }
  9318. //---------------------------------------------------------------------------
  9319. void __fastcall TCustomScpExplorerForm::UpdateImages()
  9320. {
  9321. // noop
  9322. }
  9323. //---------------------------------------------------------------------------
  9324. void TCustomScpExplorerForm::RegenerateSessionColorsImageList()
  9325. {
  9326. FSessionColors->Clear();
  9327. AddFixedSessionImages();
  9328. ::RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  9329. UpdateImages();
  9330. }
  9331. //---------------------------------------------------------------------------
  9332. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  9333. {
  9334. TForm::Dispatch(&Message);
  9335. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  9336. UpdatePixelsPerInchMainWindowCounter();
  9337. }
  9338. //---------------------------------------------------------------------------
  9339. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  9340. {
  9341. AppLog(L"Main window WM_CLOSE");
  9342. // Cannot close window while we are busy.
  9343. // We cannot test this in FormCloseQuery as that is called also from
  9344. // Close(), which is called by CloseApplicationAction. So we can be busy
  9345. // there already even, when it is legitimate to close the application.
  9346. // Possibly a better place to handle this would be WMSysCommand.
  9347. if (NonVisualDataModule->Busy)
  9348. {
  9349. Message.Result = 1;
  9350. }
  9351. else
  9352. {
  9353. TForm::Dispatch(&Message);
  9354. }
  9355. }
  9356. //---------------------------------------------------------------------------
  9357. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  9358. {
  9359. if (!FShowingChanged)
  9360. {
  9361. AddStartupSequence(L"D");
  9362. FShowingChanged = true;
  9363. }
  9364. // Ignoring implicit local-local browser of Commander, opened from DoShow
  9365. bool NoSession = (ManagedSession == NULL);
  9366. // This calls TCustomScpExplorerForm::DoShow
  9367. TForm::Dispatch(&Message);
  9368. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  9369. if (Showing && !FStarted)
  9370. {
  9371. FStarted = true;
  9372. InterfaceStarted();
  9373. }
  9374. if (Showing && NoSession)
  9375. {
  9376. // When we are starting minimized (i.e. from an installer),
  9377. // postpone showing Login dialog until we get restored.
  9378. // Otherwise the Login dialog (and Authentication window) show restored
  9379. // over invisible (minimized) main window.
  9380. if (WindowState == wsMinimized)
  9381. {
  9382. FNeedSession = true;
  9383. }
  9384. else
  9385. {
  9386. // This happens before application ever goes idle, so the toolbars would
  9387. // stay enabled (initial state) until the Login dialog is dismissed.
  9388. UpdateActions();
  9389. NonVisualDataModule->StartBusy();
  9390. try
  9391. {
  9392. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  9393. // otherwise the dialog does not receive focus.
  9394. // With Commander interface the ProcessMessages is called already
  9395. // by TDriveView, but with Explorer interface, we need to call it explicily
  9396. Application->ProcessMessages();
  9397. // do not reload sessions, they have been loaded just now (optimization)
  9398. NeedSession(true);
  9399. }
  9400. __finally
  9401. {
  9402. NonVisualDataModule->EndBusy();
  9403. }
  9404. }
  9405. }
  9406. }
  9407. //---------------------------------------------------------------------------
  9408. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  9409. {
  9410. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  9411. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  9412. }
  9413. //---------------------------------------------------------------------------
  9414. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  9415. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  9416. int & MaxHeight)
  9417. {
  9418. // workaround for bug in TWinControl.CalcConstraints
  9419. // Check for empty rect (restore from iconic state) is done there only after
  9420. // call to AdjustClientRect, which enlarges the rect (for forms).
  9421. TRect R = GetClientRect();
  9422. // when restoring from iconic state, place no restrictions
  9423. if (IsRectEmpty(R))
  9424. {
  9425. MinWidth = 0;
  9426. MinHeight = 0;
  9427. MaxWidth = 32000;
  9428. MaxHeight = 32000;
  9429. }
  9430. }
  9431. //---------------------------------------------------------------------------
  9432. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  9433. TSpaceAvailable & ASpaceAvailable, bool & Close)
  9434. {
  9435. // terminal can be already closed (e.g. dropped connection)
  9436. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  9437. {
  9438. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  9439. try
  9440. {
  9441. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  9442. }
  9443. catch(...)
  9444. {
  9445. if (!Terminal->Active)
  9446. {
  9447. Close = true;
  9448. }
  9449. throw;
  9450. }
  9451. }
  9452. }
  9453. //---------------------------------------------------------------------------
  9454. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9455. {
  9456. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9457. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9458. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9459. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9460. {
  9461. OnGetSpaceAvailable = GetSpaceAvailable;
  9462. }
  9463. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9464. OnGetSpaceAvailable);
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9468. {
  9469. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9470. Terminal->FillSessionDataForCode(Data.get());
  9471. return Data.release();
  9472. }
  9473. //---------------------------------------------------------------------------
  9474. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9475. {
  9476. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9477. DoGenerateUrlDialog(Data.get(), Paths);
  9478. }
  9479. //---------------------------------------------------------------------------
  9480. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9481. {
  9482. GenerateUrl(NULL);
  9483. }
  9484. //---------------------------------------------------------------------------
  9485. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9486. {
  9487. std::unique_ptr<TStrings> Paths(new TStringList());
  9488. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9489. GenerateUrl(Paths.get());
  9490. }
  9491. //---------------------------------------------------------------------------
  9492. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9493. {
  9494. FSessionColor = value;
  9495. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9496. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9497. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9498. DebugAssert(ColorItem != NULL);
  9499. ColorItem->Color = C;
  9500. NonVisualDataModule->ColorMenuItem->Color = C;
  9501. UpdateControls();
  9502. }
  9503. //---------------------------------------------------------------------------
  9504. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9505. {
  9506. if (value != FSessionColor)
  9507. {
  9508. UpdateSessionColor(value);
  9509. // Is null when called from LastTerminalClosed
  9510. if (Terminal != NULL)
  9511. {
  9512. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9513. }
  9514. }
  9515. }
  9516. //---------------------------------------------------------------------------
  9517. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9518. {
  9519. bool Result = FNoteTimer->Enabled;
  9520. if (Result)
  9521. {
  9522. // cannot cancel note too early
  9523. bool NotEarly =
  9524. (Now() - FNoteShown >
  9525. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9526. if (Force || NotEarly)
  9527. {
  9528. FNoteTimer->Enabled = false;
  9529. FNote = L"";
  9530. SAFE_DESTROY(FNoteData);
  9531. FOnNoteClick = NULL;
  9532. FNoteHints = FNotes->Text;
  9533. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9534. UpdateStatusBar();
  9535. }
  9536. }
  9537. return Result;
  9538. }
  9539. //---------------------------------------------------------------------------
  9540. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9541. {
  9542. DebugAssert(FNoteTimer->Enabled);
  9543. CancelNote(true);
  9544. }
  9545. //---------------------------------------------------------------------------
  9546. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9547. {
  9548. FNoteHints = FNotes->Text.TrimRight();
  9549. }
  9550. //---------------------------------------------------------------------------
  9551. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9552. {
  9553. int P = Note.Pos(L"\n");
  9554. if (P > 0)
  9555. {
  9556. Note.SetLength(P - 1);
  9557. }
  9558. FNotes->Add(FORMAT(L"[%s] %s",
  9559. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9560. while (FNotes->Count > 10)
  9561. {
  9562. FNotes->Delete(0);
  9563. }
  9564. if (UpdateNow)
  9565. {
  9566. UpdateNoteHints();
  9567. UpdateStatusBar();
  9568. }
  9569. }
  9570. //---------------------------------------------------------------------------
  9571. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9572. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9573. {
  9574. int P = Note.Pos(L"\n");
  9575. if (P > 0)
  9576. {
  9577. Note.SetLength(P - 1);
  9578. }
  9579. UpdateNoteHints();
  9580. FNote = Note;
  9581. SAFE_DESTROY(FNoteData);
  9582. FNoteData = NoteData;
  9583. FOnNoteClick = OnNoteClick;
  9584. AddNote(Note, false);
  9585. UpdateStatusBar();
  9586. FNoteShown = Now();
  9587. FNoteTimer->Enabled = false;
  9588. if (Seconds == 0)
  9589. {
  9590. Seconds = WinConfiguration->NotificationsTimeout;
  9591. }
  9592. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9593. FNoteTimer->Enabled = true;
  9594. }
  9595. //---------------------------------------------------------------------------
  9596. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9597. {
  9598. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9599. }
  9600. //---------------------------------------------------------------------------
  9601. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9602. {
  9603. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9604. {
  9605. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9606. }
  9607. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9608. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9609. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9610. 0, NULL, NULL);
  9611. }
  9612. //---------------------------------------------------------------------------
  9613. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9614. {
  9615. bool NewShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9616. UnicodeString Note =
  9617. FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1), (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, (NewShowHiddenFiles ? 2 : 3))));
  9618. PostNote(Note, 0, NULL, NULL);
  9619. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9620. WinConfiguration->ShowHiddenFiles = NewShowHiddenFiles;
  9621. }
  9622. //---------------------------------------------------------------------------
  9623. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9624. {
  9625. WinConfiguration->FormatSizeBytes = Style;
  9626. }
  9627. //---------------------------------------------------------------------------
  9628. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9629. {
  9630. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9631. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9632. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9633. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9634. }
  9635. //---------------------------------------------------------------------------
  9636. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9637. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9638. {
  9639. if (Panel->Index == 0)
  9640. {
  9641. if (FOnNoteClick != NULL)
  9642. {
  9643. // prevent the user data from being freed by possible call
  9644. // to CancelNote or PostNote during call to OnNoteClick
  9645. std::unique_ptr<TObject> NoteData(FNoteData);
  9646. TNotifyEvent OnNoteClick = FOnNoteClick;
  9647. FNoteData = NULL;
  9648. // need to cancel the note as we are going to delete its user data
  9649. CancelNote(true);
  9650. OnNoteClick(NoteData.get());
  9651. }
  9652. }
  9653. if (HasActiveTerminal() &&
  9654. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9655. {
  9656. FileSystemInfo();
  9657. }
  9658. }
  9659. //---------------------------------------------------------------------------
  9660. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9661. {
  9662. // workaround:
  9663. // 1) for unknown reason, disabling window, while minimized,
  9664. // prevents it from restoring, even if it was enabled again meanwhile
  9665. // 2) when disabling the main window, while another has focus
  9666. // minimize is no longer possible
  9667. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9668. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9669. // Shouldn't we use IsApplicationMinimized() here?
  9670. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9671. {
  9672. Enabled = false;
  9673. }
  9674. FLockLevel++;
  9675. }
  9676. //---------------------------------------------------------------------------
  9677. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9678. {
  9679. DebugAssert(FLockLevel > 0);
  9680. FLockLevel--;
  9681. if (FLockLevel == 0)
  9682. {
  9683. DebugAssert(FLockSuspendLevel == 0);
  9684. Enabled = true;
  9685. // VCL_COPY (TCustomForm.SetWindowFocus)
  9686. if (Active && (ActiveControl != NULL))
  9687. {
  9688. ::SetFocus(ActiveControl->Handle);
  9689. if (GetFocus() == ActiveControl->Handle)
  9690. {
  9691. ActiveControl->Perform(CM_UIACTIVATE, 0, 0);
  9692. }
  9693. }
  9694. }
  9695. }
  9696. //---------------------------------------------------------------------------
  9697. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9698. {
  9699. // We need to make sure that window is enabled when the last modal window closes
  9700. // otherwise focus is not restored correctly.
  9701. // So we re-enable the window when modal window opens and
  9702. // disable it back after is closes
  9703. if (FLockLevel > 0)
  9704. {
  9705. // while we have nesting counter, we know that we never be called
  9706. // recursivelly as Application->OnModalBegin is called only
  9707. // for the top-level modal window
  9708. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9709. {
  9710. // won't be disabled when conditions in LockWindow() were not satisfied
  9711. FDisabledOnLockSuspend = !Enabled;
  9712. // When minimized to tray (or actually when set to SW_HIDE),
  9713. // setting Enabled makes the window focusable even when there's
  9714. // modal window over it
  9715. if (!FTrayIcon->Visible)
  9716. {
  9717. Enabled = true;
  9718. }
  9719. }
  9720. FLockSuspendLevel++;
  9721. }
  9722. }
  9723. //---------------------------------------------------------------------------
  9724. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9725. {
  9726. if (FLockSuspendLevel > 0)
  9727. {
  9728. DebugAssert(FLockLevel > 0);
  9729. FLockSuspendLevel--;
  9730. // see comment in SuspendWindowLock
  9731. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9732. {
  9733. // Note that window can be enabled here, when we were minized to tray when
  9734. // was SuspendWindowLock() called.
  9735. // We should possibly do the same check as in LockWindow(),
  9736. // if it is ever possible that the consitions change between
  9737. // SuspendWindowLock() and ResumeWindowLock()
  9738. Enabled = !FDisabledOnLockSuspend;
  9739. }
  9740. }
  9741. }
  9742. //---------------------------------------------------------------------------
  9743. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9744. {
  9745. TTBXComboBoxItem * RemotePathComboBox =
  9746. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9747. if (!TextOnly)
  9748. {
  9749. TStrings * Items = RemotePathComboBox->Strings;
  9750. Items->BeginUpdate();
  9751. try
  9752. {
  9753. Items->Clear();
  9754. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9755. {
  9756. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9757. while (!IsUnixRootPath(APath))
  9758. {
  9759. int P = APath.LastDelimiter(L'/');
  9760. DebugAssert(P >= 0);
  9761. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9762. APath.SetLength(P - 1);
  9763. }
  9764. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9765. }
  9766. }
  9767. __finally
  9768. {
  9769. Items->EndUpdate();
  9770. }
  9771. }
  9772. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9773. // Setting ItemIndex to -1 does not reset its text
  9774. if (RemotePathComboBox->Strings->Count == 0)
  9775. {
  9776. RemotePathComboBox->Text = L"";
  9777. }
  9778. }
  9779. //---------------------------------------------------------------------------
  9780. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9781. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9782. {
  9783. if (AIndex < 0)
  9784. {
  9785. AIndex = Sender->ItemIndex;
  9786. }
  9787. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9788. }
  9789. //---------------------------------------------------------------------------
  9790. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9791. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9792. int & ImageIndex)
  9793. {
  9794. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9795. }
  9796. //---------------------------------------------------------------------------
  9797. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9798. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9799. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9800. {
  9801. if (!IsLocalBrowserMode())
  9802. {
  9803. ARect.Left += (10 * AIndex);
  9804. }
  9805. }
  9806. //---------------------------------------------------------------------------
  9807. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9808. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9809. {
  9810. AWidth += (10 * AIndex);
  9811. }
  9812. //---------------------------------------------------------------------------
  9813. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9814. {
  9815. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9816. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9817. int Index = RemotePathComboBox->ItemIndex;
  9818. while (Index < RemotePathComboBox->Strings->Count - 1)
  9819. {
  9820. APath = UnixExtractFileDir(APath);
  9821. Index++;
  9822. }
  9823. // VanDyke style paths
  9824. if (APath.IsEmpty())
  9825. {
  9826. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9827. APath = ROOTDIRECTORY;
  9828. }
  9829. if (RemoteDirView->Path != APath)
  9830. {
  9831. RemoteDirView->Path = APath;
  9832. }
  9833. }
  9834. //---------------------------------------------------------------------------
  9835. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9836. {
  9837. DoRemotePathComboBoxItemClick(Sender);
  9838. }
  9839. //---------------------------------------------------------------------------
  9840. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9841. {
  9842. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9843. DebugUsedParam(Sender);
  9844. UpdateRemotePathComboBox(true);
  9845. }
  9846. //---------------------------------------------------------------------------
  9847. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9848. {
  9849. DoRemotePathComboBoxCancel(Sender);
  9850. }
  9851. //---------------------------------------------------------------------------
  9852. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9853. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9854. {
  9855. ResetIncrementalSearch();
  9856. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9857. DebugAssert(DirView != NULL);
  9858. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9859. {
  9860. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9861. // OnEditing is called also from TCustomListView::CanEdit
  9862. if (Edit != NULL)
  9863. {
  9864. EditSelectBaseName(Edit);
  9865. }
  9866. }
  9867. }
  9868. //---------------------------------------------------------------------------
  9869. //---------------------------------------------------------------------------
  9870. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9871. {
  9872. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9873. Result->AutoDetectDnD = false;
  9874. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9875. Result->RenderDataOn = rdoEnterAndDropSync;
  9876. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9877. return Result;
  9878. }
  9879. //---------------------------------------------------------------------------
  9880. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9881. {
  9882. if (IsWin10Build(19041))
  9883. {
  9884. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9885. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9886. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9887. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9888. }
  9889. }
  9890. //---------------------------------------------------------------------------
  9891. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9892. {
  9893. TForm::CreateWnd();
  9894. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9895. UpdateDarkMode();
  9896. if (FSessionsDragDropFilesEx == NULL)
  9897. {
  9898. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9899. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9900. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9901. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9902. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9903. }
  9904. if (FQueueDragDropFilesEx == NULL)
  9905. {
  9906. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9907. // No need to set OnDragOver as we do not have any restrictions
  9908. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9909. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9910. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9911. }
  9912. }
  9913. //---------------------------------------------------------------------------
  9914. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9915. {
  9916. TForm::DestroyWnd();
  9917. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9918. FQueueDragDropFilesEx->DragDropControl = NULL;
  9919. }
  9920. //---------------------------------------------------------------------------
  9921. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9922. {
  9923. SideEnter(FCurrentSide);
  9924. FEverShown = true;
  9925. }
  9926. //---------------------------------------------------------------------------
  9927. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9928. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9929. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9930. {
  9931. if (!NonVisualDataModule->Busy)
  9932. {
  9933. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9934. Configuration->Usage->Inc(L"FileFinds");
  9935. LockWindow(true);
  9936. NonVisualDataModule->StartBusy();
  9937. WinConfiguration->LockedInterface = true;
  9938. try
  9939. {
  9940. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9941. }
  9942. __finally
  9943. {
  9944. WinConfiguration->LockedInterface = false;
  9945. NonVisualDataModule->EndBusy();
  9946. UnlockWindow();
  9947. }
  9948. }
  9949. }
  9950. //---------------------------------------------------------------------------
  9951. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9952. {
  9953. if (!NonVisualDataModule->Busy)
  9954. {
  9955. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9956. SetFocus();
  9957. RemoteDirView->Path = UnixExtractFilePath(Path);
  9958. UnicodeString FileName = UnixExtractFileName(Path);
  9959. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9960. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9961. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9962. if (Item == NULL)
  9963. {
  9964. ReloadDirectory(osRemote);
  9965. Item = RemoteDirView->FindFileItem(FileName);
  9966. }
  9967. if (Item != NULL)
  9968. {
  9969. RemoteDirView->ItemFocused = Item;
  9970. RemoteDirView->ItemFocused->MakeVisible(false);
  9971. RemoteDirView->SetFocus();
  9972. }
  9973. }
  9974. }
  9975. //---------------------------------------------------------------------------
  9976. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9977. {
  9978. bool Result = !NonVisualDataModule->Busy;
  9979. if (Result)
  9980. {
  9981. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9982. }
  9983. return Result;
  9984. }
  9985. //---------------------------------------------------------------------------
  9986. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9987. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9988. {
  9989. if (CanOperateOnFoundFiles(ATerminal))
  9990. {
  9991. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished, OnFileOperationFinished);
  9992. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9993. }
  9994. }
  9995. //---------------------------------------------------------------------------
  9996. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9997. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9998. {
  9999. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  10000. }
  10001. //---------------------------------------------------------------------------
  10002. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  10003. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10004. {
  10005. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  10006. }
  10007. //---------------------------------------------------------------------------
  10008. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  10009. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10010. {
  10011. if (CanOperateOnFoundFiles(ATerminal))
  10012. {
  10013. for (int Index = 0; Index < FileList->Count; Index++)
  10014. {
  10015. UnicodeString FileName = FileList->Strings[Index];
  10016. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  10017. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  10018. OnFileOperationFinished(osRemote, FileName, true);
  10019. }
  10020. }
  10021. }
  10022. //---------------------------------------------------------------------------
  10023. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  10024. {
  10025. FFileFindTerminal = Terminal;
  10026. ShowFileFindDialog(
  10027. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  10028. DoDownloadFoundFiles, DoEditFoundFiles);
  10029. }
  10030. //---------------------------------------------------------------------------
  10031. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  10032. {
  10033. FTaskbarList = TaskbarList;
  10034. }
  10035. //---------------------------------------------------------------------------
  10036. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  10037. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  10038. {
  10039. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10040. if (Index >= 0)
  10041. {
  10042. if (Button == mbLeft)
  10043. {
  10044. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  10045. // If switching tab (switching session) takes long enough for user
  10046. // to actually release the button, "mouse down" is still raised,
  10047. // but we do not get "mouse up" event, so dragging is not cancelled,
  10048. // prevent that by not beginning dragging in the first place.
  10049. int Key = ((GetSystemMetrics(SM_SWAPBUTTON) == 0) ? VK_LBUTTON : VK_RBUTTON);
  10050. if (IsKeyPressed(Key))
  10051. {
  10052. // when user clicks the "+", we get mouse down only after the session
  10053. // is closed, when new session tab is already on X:Y, so dragging
  10054. // starts, prevent that
  10055. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  10056. {
  10057. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10058. if (Terminal != NULL)
  10059. {
  10060. SessionsPageControl->BeginDrag(false);
  10061. }
  10062. }
  10063. }
  10064. }
  10065. else if (Button == mbMiddle)
  10066. {
  10067. // ignore middle-click for "New session tab" and the last local-local tab
  10068. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10069. if ((Session != NULL) && CanCloseSession(Session))
  10070. {
  10071. CloseSessionTab(Index);
  10072. }
  10073. }
  10074. }
  10075. }
  10076. //---------------------------------------------------------------------------
  10077. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  10078. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  10079. {
  10080. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10081. // do not allow dropping on the "+" tab
  10082. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10083. if ((TargetTerminal != NULL) &&
  10084. (SessionsPageControl->ActivePage->PageIndex != Index))
  10085. {
  10086. Configuration->Usage->Inc(L"SessionTabMoves");
  10087. // this is almost redundant as we would recreate tabs in SessionListChanged,
  10088. // but we want to actually prevent that to avoid flicker
  10089. SessionsPageControl->ActivePage->PageIndex = Index;
  10090. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  10091. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  10092. }
  10093. }
  10094. //---------------------------------------------------------------------------
  10095. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  10096. TObject * Sender, TObject * Source, int X, int Y,
  10097. TDragState /*State*/, bool & Accept)
  10098. {
  10099. Accept = (Sender == Source);
  10100. if (Accept)
  10101. {
  10102. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10103. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10104. // do not allow dragging to the "+" tab
  10105. Accept = (Terminal != NULL);
  10106. }
  10107. }
  10108. //---------------------------------------------------------------------------
  10109. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  10110. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  10111. {
  10112. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10113. if (Index < 0)
  10114. {
  10115. Effect = DROPEFFECT_NONE;
  10116. }
  10117. else
  10118. {
  10119. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10120. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  10121. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  10122. {
  10123. Effect = DROPEFFECT_NONE;
  10124. }
  10125. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  10126. {
  10127. Effect = DROPEFFECT_COPY;
  10128. }
  10129. }
  10130. }
  10131. //---------------------------------------------------------------------------
  10132. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  10133. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  10134. {
  10135. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10136. // do not allow dropping on local-local, disconnected and the "+" tab
  10137. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  10138. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10139. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  10140. {
  10141. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  10142. if (!IsFileControl(DropSourceControl, osRemote))
  10143. {
  10144. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  10145. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  10146. // Why don't we use Terminal->CurrentDirectory directly?
  10147. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  10148. // do not force queue, drag drop
  10149. false, true);
  10150. }
  10151. }
  10152. }
  10153. //---------------------------------------------------------------------------
  10154. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  10155. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  10156. {
  10157. // Downloads are handled in RemoteFileControlDDEnd
  10158. if (!IsFileControl(DropSourceControl, osRemote))
  10159. {
  10160. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  10161. Terminal->CurrentDirectory,
  10162. // force queue, drag drop
  10163. true, true);
  10164. }
  10165. }
  10166. //---------------------------------------------------------------------------
  10167. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  10168. {
  10169. FShowing = false;
  10170. // Do not save empty workspace
  10171. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  10172. {
  10173. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  10174. UnicodeString Name = WorkspaceName();
  10175. DoSaveWorkspace(
  10176. Name, DataList.get(),
  10177. !Configuration->DisablePasswordStoring &&
  10178. WinConfiguration->AutoSaveWorkspacePasswords, false);
  10179. WinConfiguration->LastStoredSession = Name;
  10180. }
  10181. AppLog(L"Closing main window");
  10182. }
  10183. //---------------------------------------------------------------------------
  10184. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  10185. {
  10186. TManagedTerminal * ManagedTerminal =
  10187. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  10188. if (ManagedTerminal != NULL)
  10189. {
  10190. ManagedTerminal->DirectoryLoaded = Now();
  10191. }
  10192. }
  10193. //---------------------------------------------------------------------------
  10194. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  10195. TListItem * /*Item*/, bool /*Selected*/)
  10196. {
  10197. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  10198. switch (DirView->LastSelectMethod)
  10199. {
  10200. case smKeyboard:
  10201. Configuration->Usage->Inc(L"KeyboardSelections");
  10202. break;
  10203. case smMouse:
  10204. Configuration->Usage->Inc(L"MouseSelections");
  10205. break;
  10206. }
  10207. }
  10208. //---------------------------------------------------------------------------
  10209. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  10210. {
  10211. if (Color != 0)
  10212. {
  10213. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  10214. }
  10215. else
  10216. {
  10217. return FSessionTabImageIndex;
  10218. }
  10219. }
  10220. //---------------------------------------------------------------------------
  10221. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  10222. {
  10223. TPngImageCollectionItem * Item =
  10224. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  10225. FSessionColors->AddPng(Item->PngImage);
  10226. return FSessionColors->Count - 1;
  10227. }
  10228. //---------------------------------------------------------------------------
  10229. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  10230. {
  10231. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  10232. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  10233. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  10234. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  10235. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  10236. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  10237. }
  10238. //---------------------------------------------------------------------------
  10239. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  10240. {
  10241. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  10245. {
  10246. switch (Side)
  10247. {
  10248. case osLocal:
  10249. return FNewLocalTabTabImageIndex;
  10250. case osRemote:
  10251. case osCurrent:
  10252. return FNewRemoteTabTabImageIndex;
  10253. default:
  10254. DebugFail();
  10255. return -1;
  10256. }
  10257. }
  10258. //---------------------------------------------------------------------------
  10259. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  10260. {
  10261. for (int Index = 0; Index < Control->ControlCount; Index++)
  10262. {
  10263. TControl * AControl = Control->Controls[Index];
  10264. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  10265. if (WinControl != NULL)
  10266. {
  10267. CollectItemsWithTextDisplayMode(WinControl);
  10268. }
  10269. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  10270. if (Toolbar != NULL)
  10271. {
  10272. // we care for top-level items only
  10273. TTBCustomItem * Items = Toolbar->Items;
  10274. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  10275. {
  10276. TTBCustomItem * Item = Items->Items[ItemIndex];
  10277. if (((Item->DisplayMode == nbdmImageAndText) ||
  10278. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  10279. EligibleForImageDisplayMode(Item))
  10280. {
  10281. FItemsWithTextDisplayMode.insert(Item);
  10282. }
  10283. }
  10284. }
  10285. }
  10286. }
  10287. //---------------------------------------------------------------------------
  10288. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  10289. {
  10290. return true;
  10291. }
  10292. //---------------------------------------------------------------------------
  10293. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  10294. {
  10295. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  10296. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  10297. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  10298. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  10299. bool Result = true;
  10300. while (Result && (i != FItemsWithTextDisplayMode.end()))
  10301. {
  10302. TTBCustomItem * Item = *i;
  10303. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  10304. if (Label != NULL)
  10305. {
  10306. // optimization
  10307. if (Label->Visible == SelectiveToolbarText)
  10308. {
  10309. Result = false;
  10310. }
  10311. else
  10312. {
  10313. Label->Visible = SelectiveToolbarText;
  10314. }
  10315. }
  10316. else
  10317. {
  10318. // optimization
  10319. if (Item->DisplayMode == DisplayMode)
  10320. {
  10321. Result = false;
  10322. }
  10323. else
  10324. {
  10325. Item->DisplayMode = DisplayMode;
  10326. }
  10327. }
  10328. ++i;
  10329. }
  10330. UpdateNewTabTab();
  10331. return Result;
  10332. }
  10333. //---------------------------------------------------------------------------
  10334. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  10335. {
  10336. DebugFail();
  10337. }
  10338. //---------------------------------------------------------------------------
  10339. bool __fastcall TCustomScpExplorerForm::IsBusy()
  10340. {
  10341. // Among other, a lock level is non zero, while directory is being loaded,
  10342. // even when it happens as a result of dirview navigation,
  10343. // i.e. when TNonVisualDataModule is NOT FBusy.
  10344. // That's why the TNonVisualDataModule::GetBusy calls this method.
  10345. // Among other this prevents a panel auto update to occur while
  10346. // directory is changing.
  10347. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  10348. }
  10349. //---------------------------------------------------------------------------
  10350. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  10351. {
  10352. // While the window is disabled, we still seem to process menu shortcuts at least,
  10353. // so stop it at least here.
  10354. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  10355. bool Result;
  10356. if (Allowed == aaUpdate)
  10357. {
  10358. Result = true;
  10359. }
  10360. else
  10361. {
  10362. Result = !NonVisualDataModule->Busy;
  10363. if (Result && (Allowed == aaShortCut))
  10364. {
  10365. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  10366. Action->Update();
  10367. Result = Action->Enabled;
  10368. }
  10369. }
  10370. return Result;
  10371. }
  10372. //---------------------------------------------------------------------------
  10373. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  10374. {
  10375. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  10376. }
  10377. //---------------------------------------------------------------------------
  10378. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  10379. {
  10380. // This is somewhat redundant to LockWindow() call from
  10381. // TTerminalManager::TerminalReadDirectoryProgress.
  10382. // But disabling window is known not to block keyboard shorcuts
  10383. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  10384. if (Busy > 0)
  10385. {
  10386. if (NonVisualDataModule->Busy)
  10387. {
  10388. State = false;
  10389. }
  10390. else
  10391. {
  10392. NonVisualDataModule->StartBusy();
  10393. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  10394. LockWindow();
  10395. }
  10396. }
  10397. else if (Busy < 0)
  10398. {
  10399. UnlockWindow();
  10400. NonVisualDataModule->EndBusy();
  10401. }
  10402. else
  10403. {
  10404. State = NonVisualDataModule->Busy;
  10405. }
  10406. }
  10407. //---------------------------------------------------------------------------
  10408. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  10409. {
  10410. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  10411. if (Index >= 0)
  10412. {
  10413. TPopupMenu * PopupMenu = NULL;
  10414. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10415. if (Session != NULL)
  10416. {
  10417. SessionsPageControl->ActivePageIndex = Index;
  10418. if (DebugAlwaysTrue(SessionTabSwitched()))
  10419. {
  10420. // copied from TControl.WMContextMenu
  10421. SendCancelMode(SessionsPageControl);
  10422. // explicit popup instead of using PopupMenu property
  10423. // to avoid menu to popup somewhere within SessionTabSwitched above,
  10424. // while connecting yet not-connected session and hence
  10425. // allowing an access to commands over not-completely connected session
  10426. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  10427. }
  10428. }
  10429. else
  10430. {
  10431. if (SupportsLocalBrowser())
  10432. {
  10433. PopupMenu = NonVisualDataModule->NewTabPopup;
  10434. }
  10435. }
  10436. if (PopupMenu != NULL)
  10437. {
  10438. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  10439. PopupMenu->PopupComponent = SessionsPageControl;
  10440. PopupMenu->Popup(Point.x, Point.y);
  10441. }
  10442. }
  10443. Handled = true;
  10444. }
  10445. //---------------------------------------------------------------------------
  10446. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  10447. {
  10448. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  10449. }
  10450. //---------------------------------------------------------------------------
  10451. void __fastcall TCustomScpExplorerForm::ChangePassword()
  10452. {
  10453. Configuration->Usage->Inc(L"PasswordChanges");
  10454. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  10455. ChangePasswordData->DisableAuthentationsExceptPassword();
  10456. ChangePasswordData->ChangePassword = true;
  10457. std::unique_ptr<TTerminal> ChangePasswordSession(
  10458. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10459. ChangePasswordSession->AutoReadDirectory = false;
  10460. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10461. {
  10462. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10463. }
  10464. else
  10465. {
  10466. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10467. }
  10468. }
  10469. //---------------------------------------------------------------------------
  10470. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10471. {
  10472. // No nice way to assert SSH2
  10473. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10474. }
  10475. //---------------------------------------------------------------------------
  10476. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10477. {
  10478. TOperationVisualizer OperationVisualizer;
  10479. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10480. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10481. }
  10482. //---------------------------------------------------------------------------
  10483. void __fastcall TCustomScpExplorerForm::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  10484. {
  10485. DebugUsedParam(OldDPI);
  10486. DebugAssert(NewDPI == GetControlPixelsPerInch(this));
  10487. GlyphsModule->PixelsPerInch = NewDPI;
  10488. // Can be called too early when primary monitor has non-system dpi
  10489. if (FSessionColors != NULL)
  10490. {
  10491. RegenerateSessionColorsImageList();
  10492. }
  10493. UpdateTabsSize();
  10494. UpdateSessionsPageControlHeight();
  10495. QueueFileListColumnAutoSize();
  10496. }
  10497. //---------------------------------------------------------------------------
  10498. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10499. {
  10500. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10501. }
  10502. //---------------------------------------------------------------------
  10503. class TPublicControl : public TControl
  10504. {
  10505. friend class TCustomScpExplorerForm;
  10506. };
  10507. //---------------------------------------------------------------------------
  10508. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10509. {
  10510. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10511. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10512. }
  10513. //---------------------------------------------------------------------------
  10514. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10515. {
  10516. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10517. OpenBookmark(Side, Bookmark);
  10518. }
  10519. //---------------------------------------------------------------------------
  10520. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10521. {
  10522. DoBookmarkClick(osLocal, Sender);
  10523. }
  10524. //---------------------------------------------------------------------------
  10525. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10526. {
  10527. DoBookmarkClick(osRemote, Sender);
  10528. }
  10529. //---------------------------------------------------------------------------
  10530. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10531. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10532. {
  10533. if (BookmarkList != NULL)
  10534. {
  10535. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10536. if (IsLocalBrowserMode())
  10537. {
  10538. Side = osLocal;
  10539. }
  10540. if (!WinConfiguration->UseLocationProfiles)
  10541. {
  10542. std::unique_ptr<TStringList> Directories(new TStringList());
  10543. Directories->CaseSensitive = (Side == osRemote);
  10544. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10545. {
  10546. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10547. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10548. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10549. {
  10550. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10551. Item->Caption = EscapeHotkey(Directory);
  10552. Item->ShortCut = Bookmark->ShortCut;
  10553. Item->OnClick = OnBookmarkClick;
  10554. Item->Tag = reinterpret_cast<int>(Bookmark);
  10555. Directories->Add(Directory);
  10556. Menu->Add(Item.release());
  10557. }
  10558. }
  10559. }
  10560. else
  10561. {
  10562. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10563. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10564. {
  10565. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10566. if (!Bookmark->Node.IsEmpty())
  10567. {
  10568. Folders->Add(Bookmark->Node);
  10569. }
  10570. }
  10571. for (int Index = 0; Index < Folders->Count; Index++)
  10572. {
  10573. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10574. Item->Caption = Folders->Strings[Index];
  10575. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10576. Folders->Objects[Index] = Item.get();
  10577. Menu->Add(Item.release());
  10578. }
  10579. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10580. {
  10581. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10582. TTBCustomItem * Parent;
  10583. if (!Bookmark->Node.IsEmpty())
  10584. {
  10585. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10586. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10587. }
  10588. else
  10589. {
  10590. Parent = Menu;
  10591. }
  10592. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10593. Item->Caption = Bookmark->Name;
  10594. Item->ShortCut = Bookmark->ShortCut;
  10595. Item->OnClick = OnBookmarkClick;
  10596. Item->Tag = reinterpret_cast<int>(Bookmark);
  10597. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10598. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10599. {
  10600. // No hint for location profiles that are actually mere "bookmarks"
  10601. }
  10602. else
  10603. {
  10604. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10605. UnicodeString LongHint;
  10606. if (!Bookmark->Local.IsEmpty())
  10607. {
  10608. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10609. }
  10610. if (!Bookmark->Remote.IsEmpty())
  10611. {
  10612. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10613. }
  10614. AddToList(Hint, LongHint, L"|");
  10615. Item->Hint = Hint;
  10616. }
  10617. Parent->Add(Item.release());
  10618. }
  10619. }
  10620. AddMenuSeparator(Menu);
  10621. }
  10622. }
  10623. //---------------------------------------------------------------------------
  10624. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10625. {
  10626. Menu->Clear();
  10627. std::unique_ptr<TTBCustomItem> Item;
  10628. Item.reset(new TTBXItem(Owner));
  10629. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10630. Item->Options = Item->Options << tboDefault;
  10631. Menu->Add(Item.release());
  10632. AddMenuSeparator(Menu);
  10633. if (Terminal != NULL)
  10634. {
  10635. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10636. }
  10637. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10638. Item.reset(new TTBXItem(Owner));
  10639. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10640. Menu->Add(Item.release());
  10641. }
  10642. //---------------------------------------------------------------------------
  10643. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10644. {
  10645. bool Result = true;
  10646. bool Remote = !IsSideLocalBrowser(Side);
  10647. try
  10648. {
  10649. UnicodeString APath = Path;
  10650. if (Remote)
  10651. {
  10652. Terminal->ExceptionOnFail = true;
  10653. }
  10654. else
  10655. {
  10656. APath = ExpandEnvironmentVariables(Path);
  10657. }
  10658. try
  10659. {
  10660. DirView(Side)->Path = APath;
  10661. }
  10662. __finally
  10663. {
  10664. if (Remote)
  10665. {
  10666. Terminal->ExceptionOnFail = false;
  10667. }
  10668. }
  10669. }
  10670. catch (Exception & E)
  10671. {
  10672. if (!Remote || Terminal->Active)
  10673. {
  10674. ShowExtendedExceptionEx(Terminal, &E);
  10675. Result = false;
  10676. }
  10677. else
  10678. {
  10679. throw;
  10680. }
  10681. }
  10682. return Result;
  10683. }
  10684. //---------------------------------------------------------------------------
  10685. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10686. {
  10687. // Make sure there some feedback even when loading tiny local folders
  10688. TInstantOperationVisualizer Visualizer;
  10689. DirView(Side)->ReloadDirectory();
  10690. }
  10691. //---------------------------------------------------------------------------
  10692. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10693. {
  10694. if (Index == SessionsPageControl->TabIndex)
  10695. {
  10696. CloseTab();
  10697. }
  10698. else
  10699. {
  10700. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10701. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10702. TTerminalManager * Manager = TTerminalManager::Instance();
  10703. if (!Terminal->Active)
  10704. {
  10705. Manager->FreeTerminal(Terminal);
  10706. }
  10707. else
  10708. {
  10709. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10710. if (CanCloseQueue(Queue))
  10711. {
  10712. Manager->FreeTerminal(Terminal);
  10713. }
  10714. }
  10715. }
  10716. }
  10717. //---------------------------------------------------------------------------
  10718. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10719. {
  10720. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10721. if (Session == NULL)
  10722. {
  10723. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10724. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10725. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10726. //P = SessionsPageControl->ClientToScreen(P);
  10727. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10728. }
  10729. else
  10730. {
  10731. CloseSessionTab(Index);
  10732. }
  10733. }
  10734. //---------------------------------------------------------------------------
  10735. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10736. {
  10737. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10738. {
  10739. TInstantOperationVisualizer Visualizer;
  10740. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10741. // before we create a new data object
  10742. ClipboardClear();
  10743. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10744. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10745. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10746. // Intermediate variable to WORKAROUND a crash in compiler
  10747. TObjectList * ClipboardFakeMonitors =
  10748. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10749. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10750. if (FClipboardDragDropFilesEx.get() == NULL)
  10751. {
  10752. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10753. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10754. }
  10755. FClipboardDragDropFilesEx->FileList->Clear();
  10756. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10757. FClipboardDragDropFilesEx->CopyToClipboard();
  10758. FClipboardTerminal = Terminal;
  10759. // Need full paths, as cwd can be different once files are pasted
  10760. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10761. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10762. {
  10763. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10764. }
  10765. AppLogFmt(L"Created fake clipboard directory \"%s\" and started drive monitors", (FClipboardFakeDirectory));
  10766. }
  10767. }
  10768. //---------------------------------------------------------------------------
  10769. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10770. {
  10771. if (OpenClipboard(0))
  10772. {
  10773. AppLog(L"Clearing clipboard");
  10774. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10775. CloseClipboard();
  10776. }
  10777. }
  10778. //---------------------------------------------------------------------------
  10779. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10780. {
  10781. return !FClipboardFakeDirectory.IsEmpty();
  10782. }
  10783. //---------------------------------------------------------------------------
  10784. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10785. {
  10786. bool Deleted = RemoveDir(ApiPath(FClipboardFakeDirectory));
  10787. AppLogFmt(L"Clearing clipboard, deleted clipboard temporary folder \"%s\" - %d", (FClipboardFakeDirectory, int(Deleted)));
  10788. FClipboardFakeDirectory = UnicodeString();
  10789. FClipboardTerminal = NULL;
  10790. if (FDownloadingFromClipboard)
  10791. {
  10792. // We are called by the monitor, so attempt to release it would deadlock
  10793. FClipboardFakeMonitorsPendingReset = true;
  10794. }
  10795. else
  10796. {
  10797. FClipboardFakeMonitors.reset(NULL);
  10798. }
  10799. }
  10800. //---------------------------------------------------------------------------
  10801. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10802. {
  10803. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10804. {
  10805. ClipboardStop();
  10806. }
  10807. }
  10808. //---------------------------------------------------------------------------
  10809. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10810. {
  10811. TTerminalManager * Manager = TTerminalManager::Instance();
  10812. Manager->ActiveSession = FClipboardTerminal;
  10813. TTransferOperationParam Params;
  10814. Params.TargetDirectory = TargetDirectory;
  10815. Params.DragDrop = DragDrop;
  10816. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10817. }
  10818. //---------------------------------------------------------------------------
  10819. void TCustomScpExplorerForm::PasteFiles()
  10820. {
  10821. // Guard against possible race conditions
  10822. if (!FClipboardPasteTarget.IsEmpty())
  10823. {
  10824. // ClipboardFakeCreated might be called while we are here, so make sure we finish operating on the same path we started with
  10825. UnicodeString Target = FClipboardPasteTarget;
  10826. FClipboardPasteTarget = EmptyStr;
  10827. // Can fail as it can be e.g. locked by AV, so we retry that later
  10828. bool Removed = RemoveDir(ApiPath(Target));
  10829. AppLogFmt(L"First attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10830. try
  10831. {
  10832. if (NonVisualDataModule->Busy)
  10833. {
  10834. AppLog(L"Is busy, cannot paste");
  10835. }
  10836. else
  10837. {
  10838. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10839. FClipboardFakeMonitorsPendingReset = false;
  10840. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10841. TAutoFlag Flag(FDownloadingFromClipboard);
  10842. AppLog(L"Downloading to paste target...");
  10843. ClipboardDownload(ExtractFilePath(Target), NoConfirmation, true);
  10844. AppLog(L"Downloaded to paste target...");
  10845. }
  10846. }
  10847. __finally
  10848. {
  10849. if (!Removed)
  10850. {
  10851. Removed = RemoveDir(ApiPath(Target));
  10852. AppLogFmt(L"Second attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10853. }
  10854. }
  10855. }
  10856. }
  10857. //---------------------------------------------------------------------------
  10858. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10859. {
  10860. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10861. // (as it pumps a Windows message queue while being shutted down)
  10862. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10863. // Is can happen that creation of our temporary directory is detected (even though we are creating it before starting the monitors).
  10864. // It tent do happen with later copy-pastes, probably because everything is cached already and monitors start quickly.
  10865. !IsPathToSameFile(FClipboardFakeDirectory, FileName) &&
  10866. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10867. {
  10868. AppLogFmt(L"Fake clipboard directory pasted to \"%s\"", (FileName));
  10869. FClipboardPasteTarget = FileName;
  10870. // Particularly when pasting to external HDD, the fake directory is strangely recreated if removed here in the monitor callback.
  10871. // Postponing removing (or actually whole pasting operation) seems to help.
  10872. PostMessage(Handle, WM_PASTE_FILES, 0, 0);
  10873. }
  10874. }
  10875. //---------------------------------------------------------------------------
  10876. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10877. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10878. {
  10879. TFileMasks::TParams MaskParams;
  10880. MaskParams.Size = Size;
  10881. MaskParams.Modification = Modification;
  10882. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10883. bool Local = (dynamic_cast<TUnixDirView *>(DirView) == NULL);
  10884. // TUnixDirView::ItemFullFileName returns trailing backslash for directories, what filemask cannot deal with
  10885. if (!Local && Directory)
  10886. {
  10887. FileName = UnixExcludeTrailingBackslash(FileName);
  10888. }
  10889. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10890. {
  10891. bool ImplicitMatch;
  10892. if (Iter->FileMask.Matches(FileName, Local, Directory, &MaskParams, false, ImplicitMatch) &&
  10893. !ImplicitMatch)
  10894. {
  10895. Color = Iter->Color;
  10896. break;
  10897. }
  10898. }
  10899. }
  10900. //---------------------------------------------------------------------------
  10901. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10902. {
  10903. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10904. if (!DirView->IsEditing())
  10905. {
  10906. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10907. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10908. // while searching
  10909. if (Key == VK_BACK)
  10910. {
  10911. if (FIncrementalSearchState.Searching)
  10912. {
  10913. if (FIncrementalSearchState.Text.Length() <= 1)
  10914. {
  10915. ResetIncrementalSearch();
  10916. }
  10917. else
  10918. {
  10919. UnicodeString NewText = LeftStr(FIncrementalSearchState.Text, FIncrementalSearchState.Text.Length() - 1);
  10920. IncrementalSearch(NewText, false, false);
  10921. }
  10922. Key = 0;
  10923. }
  10924. }
  10925. }
  10926. }
  10927. //---------------------------------------------------------------------------
  10928. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10929. {
  10930. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10931. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10932. {
  10933. // Filter control sequences.
  10934. // When not searching yet, prefer use of the space for toggling file selection
  10935. // (so we cannot incrementally search for a string starting with a space).
  10936. if ((Key > VK_SPACE) ||
  10937. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearchState.Searching))
  10938. {
  10939. IncrementalSearch(FIncrementalSearchState.Text + Key, false, false);
  10940. Key = 0;
  10941. }
  10942. }
  10943. }
  10944. //---------------------------------------------------------------------------
  10945. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10946. {
  10947. if (FIncrementalSearchState.Searching)
  10948. {
  10949. FIncrementalSearchState.Reset();
  10950. DirView(osCurrent)->UpdateStatusBar();
  10951. }
  10952. }
  10953. //---------------------------------------------------------------------------
  10954. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10955. {
  10956. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10957. if (Item == NULL)
  10958. {
  10959. MessageBeep(MB_ICONHAND);
  10960. }
  10961. else
  10962. {
  10963. TCustomDirView * ADirView = DirView(osCurrent);
  10964. {
  10965. TAutoNestingCounter Guard(FIncrementalSearching);
  10966. ADirView->FocusItem(Item);
  10967. if (ADirView->NortonLike == nlOff)
  10968. {
  10969. if ((ADirView->Selected != Item) ||
  10970. (ADirView->SelCount > 1))
  10971. {
  10972. ADirView->ClearSelection();
  10973. ADirView->Selected = Item;
  10974. }
  10975. }
  10976. }
  10977. FIncrementalSearchState.Searching = true;
  10978. FIncrementalSearchState.Text = Text;
  10979. Item->MakeVisible(false);
  10980. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10981. FIncrementalSearchState.HaveNext = (NextItem != NULL) && (NextItem != Item);
  10982. ADirView->UpdateStatusBar();
  10983. }
  10984. }
  10985. //---------------------------------------------------------------------------
  10986. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10987. {
  10988. int Index = Item->Index;
  10989. if (!Reverse)
  10990. {
  10991. Index++;
  10992. if (Index >= Item->Owner->Count)
  10993. {
  10994. Index = 0;
  10995. }
  10996. }
  10997. else
  10998. {
  10999. Index--;
  11000. if (Index < 0)
  11001. {
  11002. Index = Item->Owner->Count - 1;
  11003. }
  11004. }
  11005. return Item->Owner->Item[Index];
  11006. }
  11007. //---------------------------------------------------------------------------
  11008. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  11009. {
  11010. TCustomDirView * ADirView = DirView(osCurrent);
  11011. if (ADirView->Items->Count == 0)
  11012. {
  11013. return NULL;
  11014. }
  11015. else
  11016. {
  11017. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  11018. TListItem * Item = CurrentItem;
  11019. if (SkipCurrent)
  11020. {
  11021. Item = DebugNotNull(GetNextFile(Item, Reverse));
  11022. }
  11023. while (true)
  11024. {
  11025. bool Matches = false;
  11026. switch (WinConfiguration->PanelSearch)
  11027. {
  11028. case isNameStartOnly:
  11029. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item).SubString(1, Text.Length()), Text);
  11030. break;
  11031. case isName:
  11032. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item), Text);
  11033. break;
  11034. case isAll:
  11035. int ColCount = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Count : 1;
  11036. int Index = 0;
  11037. while ((Index < ColCount) && !Matches)
  11038. {
  11039. bool Visible = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Visible[Index] : true;
  11040. if (Visible)
  11041. {
  11042. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  11043. }
  11044. Index++;
  11045. }
  11046. break;
  11047. }
  11048. if (Matches)
  11049. {
  11050. return Item;
  11051. }
  11052. Item = GetNextFile(Item, Reverse);
  11053. if (Item == CurrentItem)
  11054. {
  11055. return NULL;
  11056. }
  11057. }
  11058. }
  11059. }
  11060. //---------------------------------------------------------------------------
  11061. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  11062. {
  11063. ResetIncrementalSearch();
  11064. }
  11065. //---------------------------------------------------------------------------
  11066. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  11067. {
  11068. if (Message.CharCode == VK_TAB)
  11069. {
  11070. if (!FIncrementalSearchState.Text.IsEmpty())
  11071. {
  11072. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  11073. bool Reverse = Shift.Contains(ssShift);
  11074. IncrementalSearch(FIncrementalSearchState.Text, true, Reverse);
  11075. Message.Result = 1;
  11076. return;
  11077. }
  11078. }
  11079. else if (Message.CharCode == VK_ESCAPE)
  11080. {
  11081. if (FIncrementalSearchState.Searching)
  11082. {
  11083. ResetIncrementalSearch();
  11084. Message.Result = 1;
  11085. return;
  11086. }
  11087. }
  11088. TForm::Dispatch(&Message);
  11089. }
  11090. //---------------------------------------------------------------------------
  11091. void __fastcall TCustomScpExplorerForm::Deactivate()
  11092. {
  11093. TForm::Deactivate();
  11094. // E.g. when switching to an internal editor window
  11095. ResetIncrementalSearch();
  11096. }
  11097. //---------------------------------------------------------------------------
  11098. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  11099. {
  11100. // When switching to another application
  11101. ResetIncrementalSearch();
  11102. }
  11103. //---------------------------------------------------------------------------
  11104. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  11105. {
  11106. ResetIncrementalSearch();
  11107. }
  11108. //---------------------------------------------------------------------------
  11109. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  11110. {
  11111. if (FIncrementalSearching <= 0)
  11112. {
  11113. ResetIncrementalSearch();
  11114. }
  11115. }
  11116. //---------------------------------------------------------------------------
  11117. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  11118. {
  11119. CountClicksForWindowPrint(this);
  11120. }
  11121. //---------------------------------------------------------------------------
  11122. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  11123. {
  11124. CenterReconnectToolbar();
  11125. }
  11126. //---------------------------------------------------------------------------
  11127. void TCustomScpExplorerForm::DoBrowseFile(TCustomDirView * DirView, const UnicodeString & FileName)
  11128. {
  11129. if (!FileName.IsEmpty())
  11130. {
  11131. DirView->FocusByName(FileName);
  11132. if (DirView->ItemFocused != NULL)
  11133. {
  11134. DirView->ItemFocused->Selected = true;
  11135. }
  11136. }
  11137. }
  11138. //---------------------------------------------------------------------------
  11139. void __fastcall TCustomScpExplorerForm::BrowseFile(const UnicodeString & FileName)
  11140. {
  11141. DoBrowseFile(RemoteDirView, FileName);
  11142. }
  11143. //---------------------------------------------------------------------------
  11144. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  11145. {
  11146. if (!FQueueStatusUpdating)
  11147. {
  11148. bool Refresh;
  11149. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  11150. {
  11151. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  11152. }
  11153. else
  11154. {
  11155. if (FQueueFileList->GetCount() > 0)
  11156. {
  11157. FQueueFileList->Clear();
  11158. Refresh = true;
  11159. }
  11160. }
  11161. int Count = FQueueFileList->GetCount();
  11162. if (QueueFileList->Items->Count != Count)
  11163. {
  11164. DebugAssert(Refresh);
  11165. QueueFileList->Items->Count = Count;
  11166. }
  11167. if (Refresh)
  11168. {
  11169. QueueFileList->Invalidate();
  11170. }
  11171. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  11172. }
  11173. }
  11174. //---------------------------------------------------------------------------
  11175. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  11176. {
  11177. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  11178. }
  11179. //---------------------------------------------------------------------------
  11180. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  11181. {
  11182. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  11183. // See TSynchronizeChecklistDialog::UpdateTimer
  11184. if (QueueFileList->Items->Count > 0)
  11185. {
  11186. QueueFileList->Items->Item[0]->MakeVisible(false);
  11187. }
  11188. UpdateQueueFileList();
  11189. }
  11190. //---------------------------------------------------------------------------
  11191. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  11192. {
  11193. Active = QueueView3->Focused() || QueueFileList->Focused();
  11194. }
  11195. //---------------------------------------------------------------------------
  11196. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  11197. {
  11198. QueueLabelUpdateStatus();
  11199. }
  11200. //---------------------------------------------------------------------------
  11201. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  11202. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  11203. {
  11204. int State = FQueueFileList->GetState(Item->Index);
  11205. if (State == qfsProcessed)
  11206. {
  11207. Sender->Canvas->Font->Color = clGrayText;
  11208. }
  11209. }
  11210. //---------------------------------------------------------------------------
  11211. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  11212. {
  11213. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  11214. QueueFileList->Column[0]->Width =
  11215. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  11216. }
  11217. //---------------------------------------------------------------------------
  11218. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  11219. {
  11220. QueueFileListColumnAutoSize();
  11221. }
  11222. //---------------------------------------------------------------------------
  11223. void __fastcall TCustomScpExplorerForm::CloseApp()
  11224. {
  11225. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  11226. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  11227. // So we clear the flag here.
  11228. DebugAssert(NonVisualDataModule->Busy);
  11229. NonVisualDataModule->EndBusy();
  11230. try
  11231. {
  11232. Close();
  11233. }
  11234. __finally
  11235. {
  11236. NonVisualDataModule->StartBusy();
  11237. }
  11238. }
  11239. //---------------------------------------------------------------------------
  11240. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  11241. {
  11242. return (Terminal != NULL) && Terminal->Active;
  11243. }
  11244. //---------------------------------------------------------------------------
  11245. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  11246. {
  11247. return (ManagedSession != NULL);
  11248. }
  11249. //---------------------------------------------------------------------------
  11250. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  11251. {
  11252. return IsActiveTerminal(Terminal);
  11253. }
  11254. //---------------------------------------------------------------------------
  11255. void TCustomScpExplorerForm::LocalLocalCopy(
  11256. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  11257. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  11258. {
  11259. DebugFail();
  11260. }
  11261. //---------------------------------------------------------------------------
  11262. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  11263. {
  11264. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  11265. }
  11266. //---------------------------------------------------------------------------
  11267. void TCustomScpExplorerForm::UpdateTabsSize()
  11268. {
  11269. // 1) Changing tab list triggers the OnResize.
  11270. // 2) Is called in TForm constructor, when we are not ready to call SessionListChanged (particularly when starting with colored session)
  11271. if (!FUpdatingSessionTabs && (FSessionColors != NULL))
  11272. {
  11273. // UpdateTabsCaptionTruncation should be enough
  11274. SessionListChanged(true);
  11275. }
  11276. }
  11277. //---------------------------------------------------------------------------
  11278. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  11279. {
  11280. UpdateTabsSize();
  11281. }
  11282. //---------------------------------------------------------------------------
  11283. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  11284. {
  11285. if (ASession == ManagedSession)
  11286. {
  11287. UpdateSession(ASession);
  11288. }
  11289. TSessionData * Data = ASession->StateData;
  11290. UnicodeString Result;
  11291. if (Side == osLocal)
  11292. {
  11293. Result = Data->LocalDirectory;
  11294. }
  11295. else if (DebugAlwaysTrue(Side == osOther))
  11296. {
  11297. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  11298. }
  11299. return Result;
  11300. }
  11301. //---------------------------------------------------------------------------
  11302. UnicodeString TCustomScpExplorerForm::GetTabHintSessionDetails(TManagedTerminal * ASession)
  11303. {
  11304. UnicodeString Title = TTerminalManager::Instance()->GetSessionTitle(ASession, false);
  11305. UnicodeString Result = ASession->SessionData->DefaultSessionName;
  11306. if (Title == Result)
  11307. {
  11308. Result = EmptyStr;
  11309. }
  11310. else
  11311. {
  11312. Result += L"\n";
  11313. }
  11314. return Result;
  11315. }
  11316. //---------------------------------------------------------------------------
  11317. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  11318. {
  11319. UnicodeString Result = GetTabHintSessionDetails(ASession);
  11320. if (!ASession->Active)
  11321. {
  11322. Result += LoadStr(STATUS_NOT_CONNECTED2);
  11323. }
  11324. else
  11325. {
  11326. Result += GetSessionPath(ASession, osRemote);
  11327. }
  11328. return Result;
  11329. }
  11330. //---------------------------------------------------------------------------
  11331. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  11332. {
  11333. return LoadStr(NEW_REMOTE_TAB_HINT);
  11334. }
  11335. //---------------------------------------------------------------------------
  11336. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  11337. {
  11338. if (Index >= 0)
  11339. {
  11340. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  11341. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  11342. if (TabSession == NULL)
  11343. {
  11344. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  11345. if (NewTabTabCaption != TabSheet->Caption)
  11346. {
  11347. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  11348. }
  11349. }
  11350. else
  11351. {
  11352. TTerminalManager * Manager = TTerminalManager::Instance();
  11353. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  11354. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  11355. }
  11356. }
  11357. }
  11358. //---------------------------------------------------------------------------
  11359. typedef std::vector<TListItem *> TListItemsVector;
  11360. struct TCalculateSizeOperation
  11361. {
  11362. TCalculateSizeStats Stats;
  11363. TListItemsVector ListItems;
  11364. size_t Index;
  11365. };
  11366. //---------------------------------------------------------------------------
  11367. void TCustomScpExplorerForm::CalculateDirectorySizes(TOperationSide Side)
  11368. {
  11369. TCalculateSizeOperation CalculateSizeOperation;
  11370. Side = GetSide(Side);
  11371. TCustomDirView * ADirView = DirView(Side);
  11372. bool LocalSide = IsSideLocalBrowser(Side);
  11373. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, LocalSide, NULL, true));
  11374. std::unique_ptr<TStrings> FileList(new TStringList());
  11375. for (int Index = 0; Index < AllFileList->Count; Index++)
  11376. {
  11377. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  11378. if (ADirView->ItemIsDirectory(Item))
  11379. {
  11380. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  11381. CalculateSizeOperation.ListItems.push_back(Item);
  11382. }
  11383. }
  11384. CalculateSizeOperation.Index = 0;
  11385. __int64 Size = 0;
  11386. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation, &CalculateSizeOperation);
  11387. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  11388. FOnFileOperationFinished = DirectorySizeCalculated;
  11389. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation, foCalculateSize);
  11390. TCalculatedSizes CalculatedSizes;
  11391. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  11392. if (LocalSide)
  11393. {
  11394. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, Side);
  11395. ManagedSession->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  11396. }
  11397. else
  11398. {
  11399. TCalculateSizeParams Params;
  11400. Params.Stats = &CalculateSizeOperation.Stats;
  11401. Params.UseCache = true;
  11402. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  11403. }
  11404. }
  11405. //---------------------------------------------------------------------------
  11406. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(TOperationSide Side, const UnicodeString & FileName, bool Success)
  11407. {
  11408. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  11409. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  11410. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  11411. // optimization
  11412. bool GotExpectedItem =
  11413. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  11414. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  11415. int Index = -1;
  11416. if (DebugAlwaysTrue(GotExpectedItem))
  11417. {
  11418. Index = FCalculateSizeOperation->Index;
  11419. FCalculateSizeOperation->Index++;
  11420. }
  11421. else
  11422. {
  11423. TListItemsVector::iterator I =
  11424. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  11425. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  11426. {
  11427. Index = I - FCalculateSizeOperation->ListItems.begin();
  11428. }
  11429. }
  11430. if (DebugAlwaysTrue(Index >= 0) && Success)
  11431. {
  11432. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  11433. ADirView->SetItemCalculatedSize(Item, Size);
  11434. }
  11435. }
  11436. //---------------------------------------------------------------------------
  11437. void __fastcall TCustomScpExplorerForm::MessageDockRequestDock(TObject *, TTBCustomDockableWindow *, bool & Accept)
  11438. {
  11439. Accept = false;
  11440. }
  11441. //---------------------------------------------------------------------------
  11442. void TCustomScpExplorerForm::AutoSizeColumns(TOperationSide Side)
  11443. {
  11444. // Send Ctrl+Gray+ to the list view
  11445. TKeyboardState KeyState;
  11446. GetKeyboardState(KeyState);
  11447. TKeyboardState NewKeyState;
  11448. memset(NewKeyState, 0, sizeof(NewKeyState));
  11449. NewKeyState[VK_CONTROL] = 0x81;
  11450. SetKeyboardState(NewKeyState);
  11451. SendMessage(DirView(Side)->Handle, WM_KEYDOWN, VK_ADD, 0);
  11452. SetKeyboardState(KeyState);
  11453. }
  11454. //---------------------------------------------------------------------------
  11455. void TCustomScpExplorerForm::QueueResetLayoutColumns()
  11456. {
  11457. LoadListViewStr(QueueView3, QueueViewLayoutDefault);
  11458. }
  11459. //---------------------------------------------------------------------------
  11460. void * TCustomScpExplorerForm::SaveFocus()
  11461. {
  11462. return NULL;
  11463. }
  11464. //---------------------------------------------------------------------------
  11465. void TCustomScpExplorerForm::RestoreFocus(void * Focus)
  11466. {
  11467. DebugUsedParam(Focus);
  11468. DebugAssert(Focus == NULL);
  11469. }
  11470. //---------------------------------------------------------------------------
  11471. void TCustomScpExplorerForm::IncrementalSearchStart()
  11472. {
  11473. TCustomDirView * ADirView = DirView(osCurrent);
  11474. ADirView->SetFocus();
  11475. if (!FIncrementalSearchState.Searching)
  11476. {
  11477. FIncrementalSearchState.Searching = true;
  11478. FIncrementalSearchState.HaveNext = false;
  11479. DebugAssert(FIncrementalSearchState.Text.IsEmpty());
  11480. ADirView->UpdateStatusBar();
  11481. }
  11482. }
  11483. //---------------------------------------------------------------------------
  11484. void __fastcall TCustomScpExplorerForm::RemoteDirViewThumbnailNeeded(
  11485. TUnixDirView *, TListItem * Item, TRemoteFile * File, const TSize & Size, TBitmap *& Bitmap)
  11486. {
  11487. // though when downloading to temporary folder, encryption should not be a problem
  11488. if (Terminal->IsCapable[fcBackgroundTransfers] &&
  11489. !File->IsDirectory)
  11490. {
  11491. UnicodeString FileName = File->FullFileName;
  11492. TFileMasks::TParams MaskParams;
  11493. MaskParams.Size = File->Size;
  11494. MaskParams.Modification = File->Modification;
  11495. if ((File->Size <= static_cast<__int64>(WinConfiguration->RemoteThumbnailSizeLimit) * 1024) &&
  11496. FRemoteThumbnailMask.Matches(FileName, false, File->IsDirectory, &MaskParams))
  11497. {
  11498. Bitmap = TTerminalManager::Instance()->ThumbnailNeeded(Terminal, Item->Index, File, Size);
  11499. }
  11500. }
  11501. }
  11502. //---------------------------------------------------------------------------
  11503. TThumbnailDownloadQueueItem * TCustomScpExplorerForm::AddThumbnailDownloadQueueItem(TManagedTerminal * ATerminal)
  11504. {
  11505. DebugAssert(ATerminal == Terminal);
  11506. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  11507. TemporaryFileCopyParam(CopyParam);
  11508. CopyParam.TransferMode = tmBinary;
  11509. UnicodeString SourceDir = ATerminal->CurrentDirectory;
  11510. UnicodeString TempDir, RootTempDir;
  11511. TemporaryDirectoryForRemoteFiles(SourceDir, CopyParam, true, TempDir, RootTempDir);
  11512. TTerminalQueue * AQueue = TTerminalManager::Instance()->FindQueueForTerminal(ATerminal);
  11513. DebugAssert((Queue == NULL) || (AQueue == Queue)); // we might get here before queue is set
  11514. TThumbnailDownloadQueueItem * QueueItem =
  11515. new TThumbnailDownloadQueueItem(this, Terminal, SourceDir, TempDir, &CopyParam);
  11516. AddQueueItem(AQueue, QueueItem, ATerminal);
  11517. return QueueItem;
  11518. }
  11519. //---------------------------------------------------------------------------
  11520. enum { qccRemoteItemVisible, qccRemoteItemRedraw };
  11521. typedef std::pair<int, UnicodeString> TRemoteItemVisibleData;
  11522. //---------------------------------------------------------------------------
  11523. void TCustomScpExplorerForm::PostThumbnailVisibleQueueQuery(int Index, const UnicodeString & FileName)
  11524. {
  11525. // The queue might be destroyed before the WM_QUEUE_CALLBACK is processed
  11526. TRemoteItemVisibleData * Data = new TRemoteItemVisibleData();
  11527. Data->first = Index;
  11528. Data->second = FileName;
  11529. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemVisible, reinterpret_cast<WPARAM>(Data));
  11530. }
  11531. //---------------------------------------------------------------------------
  11532. void TCustomScpExplorerForm::PostThumbnailDrawRequest(int Index)
  11533. {
  11534. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemRedraw, Index);
  11535. }
  11536. //---------------------------------------------------------------------------
  11537. void TCustomScpExplorerForm::WMQueueCallback(TMessage & Message)
  11538. {
  11539. int Command = Message.WParam;
  11540. if (Command == qccRemoteItemVisible)
  11541. {
  11542. TRemoteItemVisibleData * Data = reinterpret_cast<TRemoteItemVisibleData *>(Message.LParam);
  11543. int Index = Data->first;
  11544. UnicodeString FileName = Data->second;
  11545. delete Data;
  11546. TGuard Guard(Terminal->ThumbnailsSection.get());
  11547. bool Visible = False;
  11548. if (Terminal->ThumbnailsEnabled &&
  11549. // though we should better also disable thumbnails once we switch to different view style
  11550. (RemoteDirView->DirViewStyle == dvsThumbnail))
  11551. {
  11552. // The message might be processed, while we are already loading a different directory
  11553. if ((Index >= 0) &&
  11554. (Index < RemoteDirView->Items->Count))
  11555. {
  11556. TListItem * Item = RemoteDirView->Items->Item[Index];
  11557. Visible =
  11558. (RemoteDirView->ItemFullFileName(Item) == FileName) &&
  11559. ListView_IsItemVisible(RemoteDirView->Handle, Index);
  11560. }
  11561. }
  11562. Terminal->ThumbnailVisible(Index, FileName, Visible);
  11563. }
  11564. else if (Command == qccRemoteItemRedraw)
  11565. {
  11566. int Index = Message.LParam;
  11567. if ((Index >= 0) &&
  11568. (Index < RemoteDirView->Items->Count))
  11569. {
  11570. RemoteDirView->InvalidateItem(RemoteDirView->Items->Item[Index]);
  11571. }
  11572. }
  11573. }
  11574. //---------------------------------------------------------------------------
  11575. void TCustomScpExplorerForm::InitializeRemoteThumbnailMask()
  11576. {
  11577. UnicodeString DefaultRemoteThumbnailMask = L"*.jpg;*.jpeg;*.gif;*.png;*.svg;*.bmp;*.raw;*.ico;*.heic";
  11578. UnicodeString RemoteThumbnailMask = WinConfiguration->RemoteThumbnailMask;
  11579. if (RemoteThumbnailMask.IsEmpty() ||
  11580. StartsStr(L"+", RemoteThumbnailMask) || StartsStr(L"-", RemoteThumbnailMask) || StartsStr(L"*", RemoteThumbnailMask))
  11581. {
  11582. std::unique_ptr<TStrings> RemoteThumbnailMasks(new TStringList());
  11583. while (!DefaultRemoteThumbnailMask.IsEmpty())
  11584. {
  11585. RemoteThumbnailMasks->Add(CutToChar(DefaultRemoteThumbnailMask, L';', true));
  11586. }
  11587. RemoteThumbnailMasks.reset(ProcessFeatures(RemoteThumbnailMasks.get(), RemoteThumbnailMask));
  11588. RemoteThumbnailMask = EmptyStr;
  11589. for (int Index = 0; Index < RemoteThumbnailMasks->Count; Index++)
  11590. {
  11591. AddToList(RemoteThumbnailMask, RemoteThumbnailMasks->Strings[Index], L";");
  11592. }
  11593. }
  11594. FRemoteThumbnailMask.Masks = RemoteThumbnailMask;
  11595. }
  11596. //---------------------------------------------------------------------------
  11597. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartLoading(TObject *)
  11598. {
  11599. Terminal->StartLoadingDirectory();
  11600. }
  11601. //---------------------------------------------------------------------------
  11602. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartReading(TObject *)
  11603. {
  11604. Terminal->DisableThumbnails();
  11605. }
  11606. //---------------------------------------------------------------------------
  11607. void TCustomScpExplorerForm::ChangeDirViewStyle(TOperationSide Side, TDirViewStyle DirViewStyle)
  11608. {
  11609. TCustomDirView * ADirView = DirView(Side);
  11610. if (ADirView->DirViewStyle != DirViewStyle)
  11611. {
  11612. if (DirViewStyle == dvsThumbnail)
  11613. {
  11614. if (dynamic_cast<TUnixDirView *>(ADirView) != NULL)
  11615. {
  11616. Configuration->Usage->Inc(L"ThumbnailsRemote");
  11617. }
  11618. else
  11619. {
  11620. Configuration->Usage->Inc(L"ThumbnailsLocal");
  11621. }
  11622. }
  11623. ADirView->DirViewStyle = DirViewStyle;
  11624. UpdateControls();
  11625. }
  11626. }