CustomScpExplorer.cpp 364 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 3;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  198. FEditorManager = new TEditorManager();
  199. FEditorManager->OnFileChange = ExecutedFileChanged;
  200. FEditorManager->OnFileReload = ExecutedFileReload;
  201. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  202. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  203. FLocalEditors = new TList();
  204. FQueueStatus = NULL;
  205. FQueueStatusSection = new TCriticalSection();
  206. FQueueStatusInvalidated = false;
  207. FQueueItemInvalidated = false;
  208. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. }
  548. InitStatusBar();
  549. UpdateTransferList();
  550. // Update panels Enable state before refreshing the labels
  551. UpdateControls();
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  555. {
  556. if (Queue != value)
  557. {
  558. if (FQueue != NULL)
  559. {
  560. FQueue->OnListUpdate = NULL;
  561. FQueue->OnQueueItemUpdate = NULL;
  562. }
  563. FQueue = value;
  564. if (FQueue != NULL)
  565. {
  566. DebugAssert(FQueue->OnListUpdate == NULL);
  567. FQueue->OnListUpdate = QueueListUpdate;
  568. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  569. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  570. }
  571. QueueChanged();
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  576. TListItem * Item)
  577. {
  578. if (FQueueActedItem == Item)
  579. {
  580. FQueueActedItem = NULL;
  581. if ((QueueView3->PopupMenu != NULL) &&
  582. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  583. {
  584. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  585. ReleaseCapture();
  586. }
  587. }
  588. if (Item->Data == FPendingQueueActionItem)
  589. {
  590. FPendingQueueActionItem = NULL;
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. bool TCustomScpExplorerForm::IsAnythingQueued()
  595. {
  596. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  600. {
  601. {
  602. TGuard Guard(FQueueStatusSection);
  603. FQueueStatusInvalidated = false;
  604. if (FQueue != NULL)
  605. {
  606. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  607. }
  608. }
  609. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  610. {
  611. FMaxQueueLength = FQueueStatus->Count;
  612. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  613. }
  614. {
  615. TAutoFlag Flag(FQueueStatusUpdating);
  616. FQueueController->UpdateQueueStatus(FQueueStatus);
  617. }
  618. UpdateQueueFileList();
  619. SetQueueProgress();
  620. UpdateQueueView();
  621. bool IsEmpty = !IsAnythingQueued();
  622. if (IsEmpty && (Terminal != NULL))
  623. {
  624. TOnceDoneOperation OnceDoneOperation =
  625. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  626. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  627. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  628. {
  629. FQueue->Enabled = false;
  630. }
  631. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  632. {
  633. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  634. }
  635. }
  636. }
  637. //---------------------------------------------------------------------------
  638. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  639. {
  640. UnicodeString Result;
  641. if (FQueueStatus != NULL)
  642. {
  643. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  644. {
  645. TFileOperationProgressType * ProgressData =
  646. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  647. if ((ProgressData != NULL) && ProgressData->InProgress)
  648. {
  649. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  650. }
  651. }
  652. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  653. {
  654. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  655. }
  656. }
  657. return Result;
  658. }
  659. //---------------------------------------------------------------------------
  660. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  661. {
  662. ComponentVisible[fcQueueView] =
  663. (WinConfiguration->QueueView.Show == qvShow) ||
  664. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  665. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TCustomScpExplorerForm::QueueChanged()
  669. {
  670. if (FQueueStatus != NULL)
  671. {
  672. // UpdateFileList implementation relies on the status being recreated when session changes
  673. delete FQueueStatus;
  674. FQueueStatus = NULL;
  675. }
  676. UpdateQueueStatus(true);
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  680. {
  681. if (FQueue == Queue)
  682. {
  683. FQueueStatusInvalidated = true;
  684. }
  685. }
  686. //---------------------------------------------------------------------------
  687. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  688. TQueueItem * Item)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. TGuard Guard(FQueueStatusSection);
  693. // this may be running in parallel with QueueChanged
  694. if (FQueueStatus != NULL)
  695. {
  696. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  697. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  698. {
  699. FRefreshLocalDirectory = (QueueItem == NULL) ||
  700. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  701. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  702. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  703. }
  704. if (QueueItem != NULL)
  705. {
  706. QueueItem->UserData = (void*)true;
  707. FQueueItemInvalidated = true;
  708. }
  709. }
  710. }
  711. }
  712. //---------------------------------------------------------------------------
  713. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  714. {
  715. // during standalone editing, we have no way to see/control queue,
  716. // so we have to always popup prompts automatically
  717. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  721. {
  722. if (FQueueStatus != NULL)
  723. {
  724. bool QueueAutoPopup = IsQueueAutoPopup();
  725. bool NeedRefresh = FQueueController->NeedRefresh();
  726. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  727. FQueueItemInvalidated = false;
  728. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  729. bool Updated = false;
  730. TQueueItemProxy * QueueItem;
  731. bool WasUserAction;
  732. for (int Index = 0; Index < Limit; Index++)
  733. {
  734. bool Update = false;
  735. QueueItem = FQueueStatus->Items[Index];
  736. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  737. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  738. (FPendingQueueActionItem == NULL))
  739. {
  740. FPendingQueueActionItem = QueueItem;
  741. FUserActionTimer->Enabled = true;
  742. }
  743. if ((bool)QueueItem->UserData)
  744. {
  745. QueueItem->UserData = (void*)false;
  746. QueueItem->Update();
  747. Updated = true;
  748. Update = true;
  749. }
  750. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  751. {
  752. Update = true;
  753. }
  754. if (Update)
  755. {
  756. FQueueController->RefreshQueueItem(QueueItem);
  757. }
  758. }
  759. if (Updated)
  760. {
  761. NonVisualDataModule->UpdateNonVisibleActions();
  762. SetQueueProgress();
  763. UpdateQueueFileList();
  764. }
  765. }
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  769. {
  770. if (FTaskbarList != NULL)
  771. {
  772. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  773. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  778. {
  779. if (Progress >= 0)
  780. {
  781. if (FTaskbarList != NULL)
  782. {
  783. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  784. }
  785. }
  786. else
  787. {
  788. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  789. }
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  793. {
  794. int OverallProgress;
  795. // FProgressForm is null when this is called from SetQueueProgress
  796. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  797. {
  798. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  799. }
  800. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  801. {
  802. OverallProgress = ProgressData->OverallProgress();
  803. }
  804. else
  805. {
  806. OverallProgress = -1;
  807. }
  808. SetTaskbarListProgressValue(OverallProgress);
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  812. {
  813. TTerminalManager::Instance()->QueueStatusUpdated();
  814. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  815. {
  816. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  817. {
  818. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  819. {
  820. TFileOperationProgressType * ProgressData = NULL;
  821. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  822. {
  823. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  824. }
  825. if ((ProgressData != NULL) &&
  826. ProgressData->InProgress)
  827. {
  828. SetTaskbarListProgressValue(ProgressData);
  829. }
  830. else
  831. {
  832. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  833. }
  834. }
  835. else
  836. {
  837. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  838. }
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. UpdateQueueLabel();
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  849. {
  850. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  851. if (FQueueStatus != NULL)
  852. {
  853. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  854. if (ActiveAndPendingPrimaryCount > 0)
  855. {
  856. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  857. }
  858. }
  859. QueueLabel->Caption = Caption;
  860. }
  861. //---------------------------------------------------------------------------
  862. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  863. {
  864. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  865. static_cast<TComponent*>(GetComponent(fcTransferList)));
  866. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  867. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  868. TransferList->Strings->BeginUpdate();
  869. try
  870. {
  871. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  872. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  873. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  874. if (FTransferDropDownHint.IsEmpty())
  875. {
  876. FTransferDropDownHint = TransferDropDown->Hint;
  877. }
  878. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  879. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  880. TransferDropDown->Text = StripHotkey(Name);
  881. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  882. (FTransferDropDownHint, StripHotkey(Name),
  883. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  884. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  885. // update the label, otherwise when it is updated only on the first draw
  886. // of the list, it is drawn "bold" for some reason
  887. FTransferListHoverIndex = TransferList->ItemIndex;
  888. UpdateTransferLabel();
  889. }
  890. __finally
  891. {
  892. TransferList->Strings->EndUpdate();
  893. }
  894. }
  895. //---------------------------------------------------------------------------
  896. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  897. {
  898. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  899. DebugAssert(Toolbar != NULL);
  900. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  901. }
  902. //---------------------------------------------------------------------------
  903. void __fastcall TCustomScpExplorerForm::UpdateActions()
  904. {
  905. TForm::UpdateActions();
  906. if (ComponentVisible[fcCustomCommandsBand])
  907. {
  908. UpdateCustomCommandsToolbar();
  909. }
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  913. {
  914. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  918. {
  919. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  920. {
  921. DirView->RowSelect = WinConfiguration->FullRowSelect;
  922. // selection is not redrawn automatically when RowSelect changes
  923. DirView->Invalidate();
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  931. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  932. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  933. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  934. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  935. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  936. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  937. UpdateRowSelect(RemoteDirView);
  938. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  939. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  940. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  941. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  942. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  943. UpdateSessionsPageControlHeight();
  944. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  945. UpdateToolbarDisplayMode();
  946. UpdateTransferList();
  947. if (Terminal != NULL)
  948. {
  949. TransferPresetAutoSelect();
  950. }
  951. UpdateQueueView();
  952. UpdateControls();
  953. // this can be called even before constuctor finishes.
  954. if (FEditorManager != NULL)
  955. {
  956. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  957. }
  958. // this can be called even before constuctor finishes.
  959. if (FLocalEditors != NULL)
  960. {
  961. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  962. {
  963. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  964. }
  965. }
  966. if (ComponentVisible[fcCustomCommandsBand])
  967. {
  968. UpdateCustomCommandsToolbar();
  969. }
  970. // show only when keeping queue items forever,
  971. // otherwise, its enough to have in in the context menu
  972. QueueDeleteAllDoneQueueToolbarItem->Visible =
  973. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  974. if (FFileColorsCurrent != WinConfiguration->FileColors)
  975. {
  976. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  977. FFileColorsCurrent = WinConfiguration->FileColors;
  978. FileColorsChanged();
  979. }
  980. }
  981. //---------------------------------------------------------------------------
  982. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  983. {
  984. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  985. DirView->Invalidate();
  986. }
  987. //---------------------------------------------------------------------------
  988. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  989. {
  990. DoFileColorsChanged(RemoteDirView);
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  994. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  995. void * /*Arg*/)
  996. {
  997. if (Token != NULL)
  998. {
  999. TForm * Editor = dynamic_cast<TForm*>(Token);
  1000. DebugAssert(Editor != NULL);
  1001. ReconfigureEditorForm(Editor);
  1002. }
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1006. {
  1007. WinConfiguration->DDTransferConfirmation = asOn;
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1011. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1012. {
  1013. // noop
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1017. {
  1018. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1022. {
  1023. if (DoNotShowAgain)
  1024. {
  1025. if (DragDrop)
  1026. {
  1027. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1028. {
  1029. PopupTrayBalloon(
  1030. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1031. }
  1032. WinConfiguration->DDTransferConfirmation = asOff;
  1033. }
  1034. else
  1035. {
  1036. WinConfiguration->ConfirmTransferring = false;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. // User explicitly unchecked "do not show again",
  1042. // so show him the dialog the next time
  1043. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1044. {
  1045. WinConfiguration->DDTransferConfirmation = asOn;
  1046. }
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1051. TTransferDirection Direction, TTransferType Type, bool Temp,
  1052. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1053. bool Confirm, bool DragDrop, int Options)
  1054. {
  1055. bool Result = true;
  1056. DebugAssert(HasActiveTerminal());
  1057. // these parameters are known in advance
  1058. int Params =
  1059. FLAGMASK(Type == ttMove, cpDelete);
  1060. bool ToTemp = (Temp && (Direction == tdToLocal));
  1061. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1062. {
  1063. bool DisableNewerOnly =
  1064. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1065. ToTemp;
  1066. Options |=
  1067. FLAGMASK(ToTemp, coTemp) |
  1068. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1069. coDoNotShowAgain;
  1070. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1071. int CopyParamAttrs = (Direction == tdToRemote ?
  1072. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1073. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1074. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1075. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1076. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1077. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1078. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1079. if (Result)
  1080. {
  1081. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1082. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1083. }
  1084. }
  1085. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1086. {
  1087. Configuration->Usage->Inc(L"TransfersOnBackground");
  1088. // these parameter are known only after transfer dialog
  1089. Params |=
  1090. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1091. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1092. Result = false;
  1093. ClearTransferSourceSelection(Direction);
  1094. }
  1095. return Result;
  1096. }
  1097. //---------------------------------------------------------------------------
  1098. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1099. {
  1100. if (FOnFileOperationFinished != NULL)
  1101. {
  1102. FOnFileOperationFinished(UnicodeString(), true);
  1103. }
  1104. else
  1105. {
  1106. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1107. if (HasDirView[Side])
  1108. {
  1109. DirView(Side)->SelectAll(smNone);
  1110. }
  1111. }
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1115. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1116. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1117. int Params)
  1118. {
  1119. DebugAssert(Queue != NULL);
  1120. bool SingleFile = false;
  1121. if (FileList->Count == 1)
  1122. {
  1123. if (Direction == tdToRemote)
  1124. {
  1125. UnicodeString FileName = FileList->Strings[0];
  1126. SingleFile = FileExists(ApiPath(FileName));
  1127. }
  1128. else
  1129. {
  1130. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1131. SingleFile = !File->IsDirectory;
  1132. }
  1133. }
  1134. TQueueItem * QueueItem;
  1135. if (Direction == tdToRemote)
  1136. {
  1137. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. else
  1141. {
  1142. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1143. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1144. }
  1145. AddQueueItem(Queue, QueueItem, Terminal);
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1149. {
  1150. if (Queue->IsEmpty)
  1151. {
  1152. Terminal->QueueOperationStart = Now();
  1153. }
  1154. Queue->AddItem(QueueItem);
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1158. {
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TCustomScpExplorerForm::InitControls()
  1162. {
  1163. DebugAssert(FDocks != NULL);
  1164. for (int Index = 0; Index < ComponentCount; Index++)
  1165. {
  1166. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1167. if ((Dock != NULL) && (Dock->Tag == 0))
  1168. {
  1169. FDocks->Add(Dock);
  1170. }
  1171. }
  1172. CollectItemsWithTextDisplayMode(this);
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1176. {
  1177. ConfigurationChanged();
  1178. QueuePanel->Height =
  1179. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1180. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1181. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1182. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1183. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1184. QueueFileList->Height =
  1185. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1186. if (QueueFileList->Visible)
  1187. {
  1188. AdjustQueueLayout();
  1189. }
  1190. UpdateCustomCommandsToolbar();
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TCustomScpExplorerForm::StoreParams()
  1194. {
  1195. int APixelsPerInch = GetControlPixelsPerInch(this);
  1196. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1197. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1198. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1199. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1200. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1201. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1202. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1203. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1207. {
  1208. if (!FFormRestored)
  1209. {
  1210. FFormRestored = true;
  1211. RestoreFormParams();
  1212. }
  1213. TForm::CreateParams(Params);
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1217. {
  1218. DebugAssert(FDocks != NULL);
  1219. for (int Index = 0; Index < FDocks->Count; Index++)
  1220. {
  1221. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1222. }
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1226. {
  1227. SetDockAllowDrag(true);
  1228. while (!ButtonsStr.IsEmpty())
  1229. {
  1230. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1231. UnicodeString Name = CutToChar(S, L'=', true);
  1232. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1233. {
  1234. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1235. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1236. {
  1237. while (!S.IsEmpty())
  1238. {
  1239. UnicodeString S2 = CutToChar(S, L',', true);
  1240. UnicodeString Name = CutToChar(S2, L':', true);
  1241. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1242. {
  1243. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1244. if (SameText(GetToolbarItemName(Item), Name))
  1245. {
  1246. // forward compatibility
  1247. UnicodeString S3 = CutToChar(S2, L':', true);
  1248. bool Visible = StrToIntDef(S3, 0);
  1249. Item->Visible = Visible;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1257. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1261. {
  1262. UnicodeString Result;
  1263. SetDockAllowDrag(true);
  1264. Result = ::GetToolbarsLayoutStr(this);
  1265. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1266. return Result;
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1270. {
  1271. UnicodeString Result;
  1272. if (Item->Action != NULL)
  1273. {
  1274. Result = Item->Action->Name;
  1275. Result = RemoveSuffix(Result, L"Action", true);
  1276. }
  1277. else
  1278. {
  1279. Result = Item->Name;
  1280. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1281. Result = RemoveSuffix(Result, L"Item", true);
  1282. }
  1283. return Result;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1287. {
  1288. UnicodeString Result;
  1289. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1290. {
  1291. UnicodeString ToolbarStr;
  1292. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1293. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1294. {
  1295. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1296. {
  1297. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1298. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1299. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1300. // and save the changes here only.
  1301. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1302. {
  1303. UnicodeString Name = GetToolbarItemName(Item);
  1304. DebugAssert(Name.Pos(L"TBX") == 0);
  1305. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1306. }
  1307. }
  1308. }
  1309. if (!ToolbarStr.IsEmpty())
  1310. {
  1311. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1312. }
  1313. }
  1314. return Result;
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1318. {
  1319. DebugAssert(FProgressForm == NULL);
  1320. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1321. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1322. FProgressForm->DeleteLocalToRecycleBin =
  1323. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1324. FProgressForm->DeleteRemoteToRecycleBin =
  1325. (Terminal != NULL) &&
  1326. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1327. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1328. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1329. LockWindow();
  1330. // Actually, do not know what hides the progress once the operation finishes
  1331. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1332. SetTaskbarListProgressState(TBPF_NORMAL);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1336. {
  1337. UnlockWindow();
  1338. SAFE_DESTROY(FProgressForm);
  1339. SetQueueProgress();
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1343. TFileOperationProgressType & ProgressData)
  1344. {
  1345. // Download to temporary local directory
  1346. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1347. {
  1348. bool Continue = true;
  1349. FPendingTempSpaceWarn = false;
  1350. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1351. if (!Continue)
  1352. {
  1353. Abort();
  1354. }
  1355. }
  1356. // operation is being executed and we still didn't show up progress form
  1357. if (ProgressData.InProgress && !FProgressForm)
  1358. {
  1359. CreateProgressForm(NULL);
  1360. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1361. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1362. }
  1363. // operation is finished (or terminated), so we hide progress form
  1364. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1365. {
  1366. DestroyProgressForm();
  1367. if (ProgressData.Operation == foCalculateSize)
  1368. {
  1369. // When calculating size before transfer, the abort caused by
  1370. // cancel flag set due to "MoveToQueue" below,
  1371. // is not propagated back to us in ExecuteFileOperation,
  1372. // as it is silently swallowed.
  1373. // So we explicitly (re)throw it here.
  1374. if (FMoveToQueue)
  1375. {
  1376. Abort();
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if ((ProgressData.Cancel == csContinue) &&
  1382. !FAutoOperation)
  1383. {
  1384. OperationComplete(ProgressData.StartTime);
  1385. }
  1386. }
  1387. }
  1388. if (FProgressForm &&
  1389. // Can happen only during synchronization, when ending one of the operations
  1390. ProgressData.InProgress)
  1391. {
  1392. FProgressForm->SetProgressData(ProgressData);
  1393. DebugAssert(ProgressData.InProgress);
  1394. SetTaskbarListProgressValue(&ProgressData);
  1395. if (FProgressForm->Cancel > csContinue)
  1396. {
  1397. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1398. if (FProgressForm->Cancel == csCancelFile)
  1399. {
  1400. FProgressForm->ClearCancel();
  1401. }
  1402. // cancel cancels even the move
  1403. FMoveToQueue = false;
  1404. }
  1405. else if (FProgressForm->MoveToQueue)
  1406. {
  1407. FMoveToQueue = true;
  1408. ProgressData.SetCancelAtLeast(csCancel);
  1409. }
  1410. if ((FTransferResumeList != NULL) &&
  1411. ProgressData.InProgress &&
  1412. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1413. !ProgressData.FullFileName.IsEmpty())
  1414. {
  1415. if ((FTransferResumeList->Count == 0) ||
  1416. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1417. {
  1418. // note that we do not recognize directories from files here
  1419. FTransferResumeList->Add(ProgressData.FullFileName);
  1420. }
  1421. }
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1426. const TDateTime & StartTime)
  1427. {
  1428. if (GUIConfiguration->BeepOnFinish &&
  1429. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1430. {
  1431. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1432. DWORD Sound;
  1433. if (!ExtractFileExt(BeepSound).IsEmpty())
  1434. {
  1435. Sound = SND_FILENAME;
  1436. }
  1437. else
  1438. {
  1439. Sound = SND_ALIAS;
  1440. }
  1441. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1442. }
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1446. TFileOperationProgressType & ProgressData)
  1447. {
  1448. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1449. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1450. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1451. FileOperationProgress(ProgressData);
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1455. {
  1456. UnicodeString Result;
  1457. if (FProgressForm != NULL)
  1458. {
  1459. Result = FProgressForm->ProgressStr();
  1460. }
  1461. return Result;
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1465. bool DragDrop)
  1466. {
  1467. return (!DragDrop && (DropSourceControl == NULL)) ||
  1468. (DropSourceControl == DirView(osOther));
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1472. TFileOperation Operation, TOperationSide Side,
  1473. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1474. TOnceDoneOperation & OnceDoneOperation)
  1475. {
  1476. if (!FAutoOperation)
  1477. {
  1478. // no selection on "/upload", form serves only as event handler
  1479. // (it is not displayed)
  1480. if (PanelOperation(Side, FDragDropOperation) &&
  1481. Visible && (Operation != foCalculateSize) &&
  1482. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1483. {
  1484. if (FOnFileOperationFinished != NULL)
  1485. {
  1486. FOnFileOperationFinished(FileName, Success);
  1487. }
  1488. else
  1489. {
  1490. TOperationSide DViewSide;
  1491. if ((FProgressSide != osCurrent) &&
  1492. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1493. {
  1494. // assume the operation is over the focused panel
  1495. DViewSide = FProgressSide;
  1496. }
  1497. else
  1498. {
  1499. DViewSide = Side;
  1500. }
  1501. TCustomDirView * DView = DirView(DViewSide);
  1502. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1503. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1504. // this can happen when local drive is unplugged in the middle of the operation
  1505. if (Item != NULL)
  1506. {
  1507. if (Success) Item->Selected = false;
  1508. DView->MakeProgressVisible(Item);
  1509. }
  1510. }
  1511. }
  1512. if ((Operation == foCopy) || (Operation == foMove))
  1513. {
  1514. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1515. {
  1516. if (Side == osLocal)
  1517. {
  1518. Configuration->Usage->Inc(L"UploadedFiles");
  1519. }
  1520. else
  1521. {
  1522. Configuration->Usage->Inc(L"DownloadedFiles");
  1523. }
  1524. }
  1525. }
  1526. }
  1527. if (Success && (FSynchronizeController != NULL))
  1528. {
  1529. DebugAssert(!IsSideLocalBrowser(osRemote));
  1530. if (Operation == foCopy)
  1531. {
  1532. DebugAssert(Side == osLocal);
  1533. FSynchronizeController->LogOperation(soUpload, FileName);
  1534. }
  1535. else if (Operation == foDelete)
  1536. {
  1537. DebugAssert(Side == osRemote);
  1538. FSynchronizeController->LogOperation(soDelete, FileName);
  1539. }
  1540. }
  1541. if (FProgressForm)
  1542. {
  1543. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1544. }
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1548. TFileOperation Operation, TOperationSide Side,
  1549. bool Temp, const UnicodeString & FileName, Boolean Success,
  1550. TOnceDoneOperation & OnceDoneOperation)
  1551. {
  1552. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1553. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1554. OnceDoneOperation);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1558. {
  1559. return false;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1563. {
  1564. return false;
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1568. {
  1569. return NULL;
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1573. {
  1574. DebugAssert(GetSide(Side) == osRemote);
  1575. DebugUsedParam(Side);
  1576. return RemoteDirView;
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1580. {
  1581. DebugAssert(GetSide(Side) == osRemote);
  1582. DebugUsedParam(Side);
  1583. return RemoteDriveView;
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1587. {
  1588. DebugAssert(GetSide(Side) == osRemote);
  1589. DebugUsedParam(Side);
  1590. return HasActiveTerminal();
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1594. TOperationSide Side, int FilesOnly)
  1595. {
  1596. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1600. TOperationSide Side, int FilesOnly)
  1601. {
  1602. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. struct THistoryItemData
  1606. {
  1607. short int Side;
  1608. short int Index;
  1609. };
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1612. {
  1613. DirView(Side)->HistoryGo(Index);
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1617. {
  1618. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1619. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1620. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1624. bool Back)
  1625. {
  1626. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1627. {
  1628. TCustomDirView * DView = DirView(Side);
  1629. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1630. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1631. if (ICount > 10)
  1632. {
  1633. ICount = 10;
  1634. }
  1635. Menu->Items->Clear();
  1636. THistoryItemData Data;
  1637. Data.Side = Side;
  1638. for (short int i = 1; i <= ICount; i++)
  1639. {
  1640. TTBCustomItem * Item = new TTBXItem(Menu);
  1641. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1642. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1643. Item->Hint = DView->HistoryPath[Data.Index];
  1644. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1645. Item->Tag = *reinterpret_cast<int*>(&Data);
  1646. Item->OnClick = HistoryItemClick;
  1647. Menu->Items->Add(Item);
  1648. }
  1649. }
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1653. TOperationSide Side, bool Back)
  1654. {
  1655. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1656. {
  1657. // workaround
  1658. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1659. // operator new allocates memory in Pascal code, but calls inline
  1660. // contructor in C++, leading in problems, the function does
  1661. // both in Pascal code
  1662. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1663. UpdateHistoryMenu(Side, Back);
  1664. }
  1665. return FHistoryMenu[Side == osLocal][Back];
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1669. TCustomDirView *Sender)
  1670. {
  1671. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1672. UpdateHistoryMenu(Side, true);
  1673. UpdateHistoryMenu(Side, false);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1677. {
  1678. // remote custom commands can be executed only if the server supports shell commands
  1679. // or have secondary shell
  1680. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1684. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1685. {
  1686. // -1 = hidden, 0 = disabled, 1 = enabled
  1687. int Result;
  1688. TFileCustomCommand RemoteCustomCommand;
  1689. TLocalCustomCommand LocalCustomCommand;
  1690. TFileCustomCommand * NonInteractiveCustomCommand =
  1691. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1692. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1693. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1694. if (FLAGCLEAR(Command.Params, ccLocal))
  1695. {
  1696. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1697. // custom command that does not operate with files can be executed anytime ...
  1698. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1699. {
  1700. // ... but do not show such command in remote file menu
  1701. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1702. {
  1703. Result = AllowedState;
  1704. }
  1705. else
  1706. {
  1707. Result = -1;
  1708. }
  1709. }
  1710. else
  1711. {
  1712. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1713. {
  1714. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1715. }
  1716. else
  1717. {
  1718. Result = -1;
  1719. }
  1720. }
  1721. }
  1722. else
  1723. {
  1724. // custom command that does not operate with files can be executed anytime
  1725. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1726. {
  1727. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1728. }
  1729. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1730. {
  1731. if ((ListType == ccltAll) || (ListType == ccltFile))
  1732. {
  1733. // special case is "diff"-style command that can be executed over any side,
  1734. // if we have both sides
  1735. Result =
  1736. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1737. // directly (instead of EnableSelectedOperation) to pass
  1738. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1739. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1740. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1741. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1742. }
  1743. else if (ListType == ccltBoth)
  1744. {
  1745. DebugAssert(!IsLocalBrowserMode());
  1746. Result = 1;
  1747. }
  1748. else
  1749. {
  1750. Result = -1;
  1751. }
  1752. }
  1753. else
  1754. {
  1755. if ((ListType == ccltAll) ||
  1756. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1757. {
  1758. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1759. }
  1760. else
  1761. {
  1762. Result = -1;
  1763. }
  1764. }
  1765. if ((Result > 0) &&
  1766. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1767. !HasActiveTerminal())
  1768. {
  1769. Result = 0;
  1770. }
  1771. }
  1772. return Result;
  1773. }
  1774. //---------------------------------------------------------------------------
  1775. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1776. TStrings * FileList, const TCustomCommandType & ACommand,
  1777. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1778. {
  1779. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1780. {
  1781. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1782. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1783. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1784. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1785. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1786. bool Capture =
  1787. FLAGSET(ACommand.Params, ccShowResults) ||
  1788. FLAGSET(ACommand.Params, ccCopyResults) ||
  1789. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1790. TCaptureOutputEvent OutputEvent = NULL;
  1791. DebugAssert(FCapturedLog == NULL);
  1792. if (Capture)
  1793. {
  1794. FCapturedLog = new TStringList();
  1795. OutputEvent = TerminalCaptureLog;
  1796. }
  1797. try
  1798. {
  1799. if (!RemoteCustomCommand.IsFileCommand(Command))
  1800. {
  1801. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1802. OutputEvent);
  1803. }
  1804. else
  1805. {
  1806. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1807. }
  1808. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1809. {
  1810. if (FLAGSET(ACommand.Params, ccCopyResults))
  1811. {
  1812. CopyToClipboard(FCapturedLog);
  1813. }
  1814. if (FLAGSET(ACommand.Params, ccShowResults))
  1815. {
  1816. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1817. }
  1818. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1819. {
  1820. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1821. }
  1822. }
  1823. }
  1824. __finally
  1825. {
  1826. SAFE_DESTROY(FCapturedLog);
  1827. }
  1828. }
  1829. }
  1830. //---------------------------------------------------------------------------
  1831. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1832. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1833. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1834. {
  1835. DebugAssert(!IsLocalBrowserMode());
  1836. TStrings * LocalFileList = NULL;
  1837. TStrings * RemoteFileList = NULL;
  1838. TStrings * RemoteFileListFull = NULL;
  1839. try
  1840. {
  1841. if (LocalFileCommand)
  1842. {
  1843. if (ALocalFileList == NULL)
  1844. {
  1845. DebugAssert(HasDirView[osLocal]);
  1846. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1847. // directly (instead of EnableSelectedOperation) to pass
  1848. // false to FocusedFileOnlyWhenFocused
  1849. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1850. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1851. }
  1852. else
  1853. {
  1854. LocalFileList = ALocalFileList;
  1855. }
  1856. if (FileListCommand)
  1857. {
  1858. if (LocalFileList->Count != 1)
  1859. {
  1860. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1861. }
  1862. }
  1863. else
  1864. {
  1865. if ((LocalFileList->Count != 1) &&
  1866. (FileList->Count != 1) &&
  1867. (LocalFileList->Count != FileList->Count))
  1868. {
  1869. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1870. }
  1871. }
  1872. }
  1873. UnicodeString RootTempDir;
  1874. UnicodeString TempDir;
  1875. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1876. if (!RemoteFiles)
  1877. {
  1878. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1879. }
  1880. try
  1881. {
  1882. TDateTimes RemoteFileTimes;
  1883. if (RemoteFiles)
  1884. {
  1885. RemoteFileList = FileList;
  1886. }
  1887. else
  1888. {
  1889. RemoteFileList = new TStringList();
  1890. TMakeLocalFileListParams MakeFileListParam;
  1891. MakeFileListParam.FileList = RemoteFileList;
  1892. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1893. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1894. MakeFileListParam.Recursive =
  1895. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1896. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1897. if (!MakeFileListParam.Recursive)
  1898. {
  1899. RemoteFileTimes.clear();
  1900. RemoteFileListFull = new TStringList();
  1901. MakeFileListParam.FileList = RemoteFileListFull;
  1902. MakeFileListParam.Recursive = true;
  1903. MakeFileListParam.IncludeDirs = false;
  1904. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1905. }
  1906. else
  1907. {
  1908. RemoteFileListFull = RemoteFileList;
  1909. }
  1910. }
  1911. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1912. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1913. if (!NonBlocking)
  1914. {
  1915. int Count;
  1916. if (FileListCommand)
  1917. {
  1918. Count = 1;
  1919. }
  1920. else if (LocalFileCommand)
  1921. {
  1922. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1923. }
  1924. else
  1925. {
  1926. Count = RemoteFileList->Count;
  1927. }
  1928. Progress.Start(foCustomCommand, osRemote, Count);
  1929. DebugAssert(FProgressForm != NULL);
  1930. FProgressForm->ReadOnly = true;
  1931. }
  1932. try
  1933. {
  1934. if (FileListCommand)
  1935. {
  1936. UnicodeString LocalFile;
  1937. // MakeFileList does not delimit filenames
  1938. UnicodeString FileList = MakeFileList(RemoteFileList);
  1939. if (LocalFileCommand)
  1940. {
  1941. DebugAssert(LocalFileList->Count == 1);
  1942. LocalFile = LocalFileList->Strings[0];
  1943. }
  1944. TLocalCustomCommand CustomCommand(Data,
  1945. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1946. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1947. if (NonBlocking)
  1948. {
  1949. DebugAssert(!POutput);
  1950. ExecuteShellChecked(ShellCommand);
  1951. }
  1952. else
  1953. {
  1954. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1955. }
  1956. }
  1957. else if (LocalFileCommand)
  1958. {
  1959. if (LocalFileList->Count == 1)
  1960. {
  1961. UnicodeString LocalFile = LocalFileList->Strings[0];
  1962. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1963. {
  1964. UnicodeString FileName = RemoteFileList->Strings[Index];
  1965. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1966. Progress.SetFile(FileNameForProgress);
  1967. TLocalCustomCommand CustomCommand(Data,
  1968. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else if (RemoteFileList->Count == 1)
  1976. {
  1977. UnicodeString FileName = RemoteFileList->Strings[0];
  1978. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1979. {
  1980. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1981. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1982. Progress.SetFile(LocalFileNameOnly);
  1983. TLocalCustomCommand CustomCommand(
  1984. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1985. FileName, LocalFileName, L"");
  1986. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1987. TOnceDoneOperation OnceDoneOperation;
  1988. // Do not unselect anything, as it won't work with two panels anyway
  1989. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1990. }
  1991. }
  1992. else
  1993. {
  1994. if (LocalFileList->Count != RemoteFileList->Count)
  1995. {
  1996. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1997. }
  1998. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1999. {
  2000. UnicodeString FileName = RemoteFileList->Strings[Index];
  2001. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2002. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2003. Progress.SetFile(LocalFileNameOnly); // sic
  2004. TLocalCustomCommand CustomCommand(
  2005. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, LocalFileName, L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. // Do not unselect anything, as it won't work with two panels anyway
  2010. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2011. }
  2012. }
  2013. }
  2014. else
  2015. {
  2016. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileList->Strings[Index];
  2019. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2020. Progress.SetFile(FileNameForProgress);
  2021. TLocalCustomCommand CustomCommand(Data,
  2022. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2023. FileName, L"", L"");
  2024. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2025. TOnceDoneOperation OnceDoneOperation;
  2026. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2027. }
  2028. }
  2029. }
  2030. __finally
  2031. {
  2032. if (!NonBlocking)
  2033. {
  2034. Progress.Stop();
  2035. }
  2036. }
  2037. DebugAssert(!FAutoOperation);
  2038. if (!RemoteFiles)
  2039. {
  2040. TempDir = IncludeTrailingBackslash(TempDir);
  2041. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2042. {
  2043. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2044. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2045. // Skip directories, process only nested files.
  2046. // The check is redundant as FileAge fails for directories anyway.
  2047. !DirectoryExists(FileName))
  2048. {
  2049. UnicodeString RemoteDir =
  2050. UnixExtractFileDir(
  2051. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2052. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2053. TDateTime NewTime;
  2054. if (FileAge(FileName, NewTime) &&
  2055. (NewTime != RemoteFileTimes[Index]))
  2056. {
  2057. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2058. TemporaryFileCopyParam(CopyParam);
  2059. CopyParam.FileMask = L"";
  2060. FAutoOperation = true;
  2061. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2062. TemporaryFilesList->Add(FileName);
  2063. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. __finally
  2070. {
  2071. FAutoOperation = false;
  2072. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2073. {
  2074. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2075. }
  2076. }
  2077. }
  2078. __finally
  2079. {
  2080. if (RemoteFileList != FileList)
  2081. {
  2082. delete RemoteFileList;
  2083. }
  2084. if (LocalFileList != ALocalFileList)
  2085. {
  2086. delete LocalFileList;
  2087. }
  2088. if (RemoteFileListFull != RemoteFileList)
  2089. {
  2090. delete RemoteFileListFull;
  2091. }
  2092. }
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2096. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2097. bool FileListCommand, UnicodeString * POutput)
  2098. {
  2099. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2100. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2101. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2102. {
  2103. UnicodeString FileName = SelectedFileList->Strings[Index];
  2104. if (DirectoryExists(FileName))
  2105. {
  2106. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2107. {
  2108. LocalFileList->Add(FileName);
  2109. }
  2110. if (FLAGSET(ACommand.Params, ccRecursive))
  2111. {
  2112. TMakeLocalFileListParams MakeFileListParam;
  2113. MakeFileListParam.FileList = LocalFileList.get();
  2114. MakeFileListParam.FileTimes = NULL;
  2115. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2116. MakeFileListParam.Recursive = true;
  2117. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2118. }
  2119. }
  2120. else
  2121. {
  2122. LocalFileList->Add(FileName);
  2123. }
  2124. }
  2125. UnicodeString RemotePath;
  2126. if (Terminal != NULL)
  2127. {
  2128. RemotePath = Terminal->CurrentDirectory;
  2129. }
  2130. if (FileListCommand)
  2131. {
  2132. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. L"", L"", FileList);
  2136. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. }
  2138. else
  2139. {
  2140. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2141. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2142. DebugAssert(FProgressForm != NULL);
  2143. FProgressForm->ReadOnly = true;
  2144. try
  2145. {
  2146. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2147. {
  2148. UnicodeString FileName = LocalFileList->Strings[Index];
  2149. Progress.SetFile(FileName);
  2150. TLocalCustomCommand CustomCommand(
  2151. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2152. FileName, L"", L"");
  2153. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2154. TOnceDoneOperation OnceDoneOperation;
  2155. Progress.Finish(FileName, true, OnceDoneOperation);
  2156. }
  2157. }
  2158. __finally
  2159. {
  2160. Progress.Stop();
  2161. }
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2166. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2167. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2168. {
  2169. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2170. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2171. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2172. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2173. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2174. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2175. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2176. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2177. std::unique_ptr<UnicodeString> POutput;
  2178. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2179. FLAGSET(ACommand.Params, ccCopyResults))
  2180. {
  2181. POutput.reset(new UnicodeString());
  2182. }
  2183. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2184. FProgressSide = FCurrentSide;
  2185. if (!LocalCustomCommand.IsFileCommand(Command))
  2186. {
  2187. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2188. }
  2189. // remote files?
  2190. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2191. {
  2192. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2193. }
  2194. // local files
  2195. else
  2196. {
  2197. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2198. }
  2199. if (POutput.get() != NULL)
  2200. {
  2201. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2202. int P = POutput->Pos(sLineBreak);
  2203. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2204. {
  2205. POutput->SetLength(P - 1);
  2206. }
  2207. // Copy even empty output to clipboard
  2208. if (FLAGSET(ACommand.Params, ccCopyResults))
  2209. {
  2210. CopyToClipboard(*POutput);
  2211. }
  2212. // But do not show an empty message box.
  2213. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2214. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2215. !POutput->IsEmpty())
  2216. {
  2217. TClipboardHandler ClipboardHandler;
  2218. ClipboardHandler.Text = *POutput;
  2219. TMessageParams Params;
  2220. TQueryButtonAlias Aliases[1];
  2221. Aliases[0].Button = qaRetry;
  2222. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2223. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2224. Params.Aliases = Aliases;
  2225. Params.AliasesCount = LENOF(Aliases);
  2226. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2227. }
  2228. }
  2229. }
  2230. //---------------------------------------------------------------------------
  2231. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2232. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2233. {
  2234. TCustomCommandData Data;
  2235. UnicodeString Site;
  2236. UnicodeString RemotePath;
  2237. if (HasActiveTerminal())
  2238. {
  2239. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2240. Data = TCustomCommandData(SessionData.get());
  2241. Site = Terminal->SessionData->SessionKey;
  2242. RemotePath = Terminal->CurrentDirectory;
  2243. }
  2244. UnicodeString HelpKeyword = ACommand.HomePage;
  2245. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2246. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2247. {
  2248. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2249. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2250. {
  2251. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2252. }
  2253. else
  2254. {
  2255. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2256. }
  2257. if (!DoCustomCommandOptionsDialog(
  2258. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2259. {
  2260. Abort();
  2261. }
  2262. }
  2263. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2264. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2265. {
  2266. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2267. }
  2268. else
  2269. {
  2270. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2271. }
  2272. }
  2273. //---------------------------------------------------------------------------
  2274. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2275. const TCustomCommandType & Command)
  2276. {
  2277. DebugAssert(FCustomCommandLocalFileList != NULL);
  2278. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2279. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2280. TStrings * LocalFileList = new TStringList();
  2281. TStrings * RemoteFileList = new TStringList();
  2282. try
  2283. {
  2284. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2285. {
  2286. LocalFileList->Clear();
  2287. LocalFileList->AddObject(
  2288. FCustomCommandLocalFileList->Strings[Index],
  2289. FCustomCommandLocalFileList->Objects[Index]);
  2290. RemoteFileList->Clear();
  2291. RemoteFileList->AddObject(
  2292. FCustomCommandRemoteFileList->Strings[Index],
  2293. FCustomCommandRemoteFileList->Objects[Index]);
  2294. CustomCommand(RemoteFileList, Command, LocalFileList);
  2295. }
  2296. }
  2297. __finally
  2298. {
  2299. delete LocalFileList;
  2300. delete RemoteFileList;
  2301. }
  2302. }
  2303. //---------------------------------------------------------------------------
  2304. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2305. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2306. {
  2307. delete FCustomCommandLocalFileList;
  2308. delete FCustomCommandRemoteFileList;
  2309. // takeover ownership,
  2310. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2311. FCustomCommandLocalFileList = LocalFileList;
  2312. FCustomCommandRemoteFileList = RemoteFileList;
  2313. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2314. if (Button != NULL)
  2315. {
  2316. FCustomCommandMenu->Items->Clear();
  2317. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2318. MenuPopup(FCustomCommandMenu, Button);
  2319. }
  2320. else
  2321. {
  2322. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2323. }
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2327. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2328. {
  2329. DebugAssert(FCapturedLog != NULL);
  2330. if ((OutputType == cotOutput) || (OutputType == cotError))
  2331. {
  2332. FCapturedLog->Add(AddedLine);
  2333. }
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2337. TOperationSide Side)
  2338. {
  2339. return
  2340. (Side == osOther) &&
  2341. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2345. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2346. {
  2347. TTBItemOptions O;
  2348. O = Item->Options;
  2349. TCustomDirView * DView = DirView(Side);
  2350. if ((DView->ItemFocused != NULL) &&
  2351. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2352. // when resolving links is disabled, default action is to enter the directory,
  2353. // no matter what DoubleClickAction is configured to
  2354. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2355. // Can only Edit files, but can Open/Copy even directories
  2356. ((DoubleClickAction != dcaEdit) ||
  2357. !DView->ItemIsDirectory(DView->ItemFocused)))
  2358. {
  2359. Item->Options = O << tboDefault;
  2360. }
  2361. else
  2362. {
  2363. Item->Options = O >> tboDefault;
  2364. }
  2365. }
  2366. //---------------------------------------------------------------------------
  2367. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2368. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2369. {
  2370. TCustomDirView * DView = DirView(Side);
  2371. TListItem * Item = DView->ItemFocused;
  2372. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2373. EnableFocusedOperation[Side])
  2374. {
  2375. TPoint ClientPoint;
  2376. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2377. TPoint(0, 0) : MousePos;
  2378. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2379. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2380. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2381. }
  2382. }
  2383. //---------------------------------------------------------------------------
  2384. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2385. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2386. {
  2387. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2388. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2389. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2390. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2391. Handled = true;
  2392. }
  2393. //---------------------------------------------------------------------------
  2394. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2395. {
  2396. }
  2397. //---------------------------------------------------------------------------
  2398. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2399. {
  2400. DebugAssert(FErrorList == NULL);
  2401. if (WinConfiguration->ContinueOnError)
  2402. {
  2403. FErrorList = new TStringList();
  2404. Configuration->Usage->Inc(L"ContinuationsOnError");
  2405. }
  2406. NonVisualDataModule->StartBusy();
  2407. }
  2408. //---------------------------------------------------------------------------
  2409. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2410. {
  2411. NonVisualDataModule->EndBusy();
  2412. if (FErrorList)
  2413. {
  2414. HandleErrorList(FErrorList);
  2415. }
  2416. }
  2417. //---------------------------------------------------------------------------
  2418. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2419. const TCopyParamType & CopyParam)
  2420. {
  2421. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2422. {
  2423. Configuration->Usage->Inc(L"FileMaskUses");
  2424. }
  2425. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2426. {
  2427. Configuration->Usage->Inc(L"OperationMaskUses");
  2428. }
  2429. }
  2430. //---------------------------------------------------------------------------
  2431. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2432. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2433. {
  2434. DebugAssert(!IsLocalBrowserMode());
  2435. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2436. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2437. TTransferOperationParam DefaultParam;
  2438. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2439. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2440. switch (Param.Queue)
  2441. {
  2442. case asOn:
  2443. CopyParam.Queue = true;
  2444. break;
  2445. case asOff:
  2446. CopyParam.Queue = false;
  2447. break;
  2448. case asAuto:
  2449. default:
  2450. // keep default
  2451. break;
  2452. }
  2453. bool Result =
  2454. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2455. if (Result)
  2456. {
  2457. DebugAssert(Terminal);
  2458. bool SelectionRestored = false;
  2459. TCustomDirView * DView = NULL;
  2460. if (HasDirView[Side])
  2461. {
  2462. DView = DirView(Side);
  2463. DView->SaveSelection();
  2464. DView->SaveSelectedNames();
  2465. }
  2466. UpdateCopyParamCounters(CopyParam);
  2467. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2468. DebugAssert(FTransferResumeList == NULL);
  2469. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2470. FMoveToQueue = false;
  2471. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2472. try
  2473. {
  2474. TStrings * PermanentFileList;
  2475. std::unique_ptr<TStrings> PermanentFileListOwner;
  2476. try
  2477. {
  2478. if (Side == osLocal)
  2479. {
  2480. PermanentFileList = FileList;
  2481. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2482. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2483. if (Operation == foMove)
  2484. {
  2485. ReloadLocalDirectory();
  2486. if (DView != NULL)
  2487. {
  2488. DView->RestoreSelection();
  2489. }
  2490. SelectionRestored = true;
  2491. }
  2492. }
  2493. else
  2494. {
  2495. // Clone the file list as it may refer to current directory files,
  2496. // which get destroyed, when the source directory is reloaded after foMove operation.
  2497. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2498. // But for a hotfix, we are not going to do such a big change.
  2499. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2500. PermanentFileList = PermanentFileListOwner.get();
  2501. try
  2502. {
  2503. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2504. }
  2505. __finally
  2506. {
  2507. if (Operation == foMove)
  2508. {
  2509. if (DView != NULL)
  2510. {
  2511. DView->RestoreSelection();
  2512. }
  2513. SelectionRestored = true;
  2514. }
  2515. ReloadLocalDirectory(Param.TargetDirectory);
  2516. }
  2517. }
  2518. }
  2519. catch (EAbort &)
  2520. {
  2521. if (FMoveToQueue)
  2522. {
  2523. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2524. DebugAssert(CopyParam.TransferSkipList == NULL);
  2525. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2526. if (TransferResumeList->Count > 0)
  2527. {
  2528. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2529. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2530. }
  2531. CopyParam.TransferSkipList = TransferResumeList.release();
  2532. // not really needed, just to keep it consistent with TransferResumeList
  2533. FTransferResumeList = NULL;
  2534. FMoveToQueue = false;
  2535. Configuration->Usage->Inc("MovesToBackground");
  2536. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2537. ClearTransferSourceSelection(Direction);
  2538. }
  2539. throw;
  2540. }
  2541. }
  2542. __finally
  2543. {
  2544. if (!SelectionRestored && (DView != NULL))
  2545. {
  2546. DView->DiscardSavedSelection();
  2547. }
  2548. FTransferResumeList = NULL;
  2549. }
  2550. }
  2551. return Result;
  2552. }
  2553. //---------------------------------------------------------------------------
  2554. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2555. TOperationSide Side, TStrings * FileList, void * Param)
  2556. {
  2557. DebugAssert(FileList->Count);
  2558. // We deliberately do not toggle alternative flag (Param), but use OR,
  2559. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2560. // shortcut of CurrentDeleteAlternativeAction
  2561. bool Alternative =
  2562. bool(Param) || UseAlternativeFunction();
  2563. bool Recycle;
  2564. if (IsSideLocalBrowser(Side))
  2565. {
  2566. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2567. }
  2568. else
  2569. {
  2570. Recycle =
  2571. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2572. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2573. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2574. }
  2575. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2576. if (!Result)
  2577. {
  2578. UnicodeString Query;
  2579. if (FileList->Count == 1)
  2580. {
  2581. if (IsSideLocalBrowser(Side))
  2582. {
  2583. Query = ExtractFileName(FileList->Strings[0]);
  2584. }
  2585. else
  2586. {
  2587. Query = UnixExtractFileName(FileList->Strings[0]);
  2588. }
  2589. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2590. }
  2591. else
  2592. {
  2593. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2594. }
  2595. TMessageParams Params(mpNeverAskAgainCheck);
  2596. Params.ImageName = L"Delete file";
  2597. unsigned int Answer =
  2598. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2599. if (Answer == qaNeverAskAgain)
  2600. {
  2601. Result = true;
  2602. if (Recycle)
  2603. {
  2604. WinConfiguration->ConfirmRecycling = false;
  2605. }
  2606. else
  2607. {
  2608. WinConfiguration->ConfirmDeleting = false;
  2609. }
  2610. }
  2611. else
  2612. {
  2613. Result = (Answer == qaOK);
  2614. }
  2615. }
  2616. if (Result)
  2617. {
  2618. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2619. }
  2620. return Result;
  2621. }
  2622. //---------------------------------------------------------------------------
  2623. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2624. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2625. {
  2626. TAutoBatch AutoBatch(this);
  2627. bool Result;
  2628. if ((Operation == foCopy) || (Operation == foMove))
  2629. {
  2630. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2631. }
  2632. else if (Operation == foRename)
  2633. {
  2634. DebugAssert(DirView(Side)->ItemFocused);
  2635. DirView(Side)->ItemFocused->EditCaption();
  2636. Result = true;
  2637. }
  2638. else if (Operation == foDelete)
  2639. {
  2640. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2641. }
  2642. else if (Operation == foSetProperties)
  2643. {
  2644. DirView(osRemote)->SaveSelectedNames();
  2645. Result = SetProperties(Side, FileList);
  2646. }
  2647. else if (Operation == foCustomCommand)
  2648. {
  2649. DebugAssert(Param);
  2650. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2651. DirView(osRemote)->SaveSelectedNames();
  2652. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2653. CustomCommand(FileList, *Command, NULL);
  2654. Result = true;
  2655. }
  2656. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2657. {
  2658. DebugAssert(!IsSideLocalBrowser(Side));
  2659. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2660. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2661. }
  2662. else if (Operation == foLock)
  2663. {
  2664. DebugAssert(!IsSideLocalBrowser(Side));
  2665. LockFiles(FileList, true);
  2666. Result = true;
  2667. }
  2668. else if (Operation == foUnlock)
  2669. {
  2670. DebugAssert(!IsSideLocalBrowser(Side));
  2671. LockFiles(FileList, false);
  2672. Result = true;
  2673. }
  2674. else
  2675. {
  2676. DebugFail();
  2677. }
  2678. return Result;
  2679. }
  2680. //---------------------------------------------------------------------------
  2681. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2682. {
  2683. if (Side == osCurrent)
  2684. {
  2685. Side = FCurrentSide;
  2686. }
  2687. return Side;
  2688. }
  2689. //---------------------------------------------------------------------------
  2690. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2691. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2692. {
  2693. Side = GetSide(Side);
  2694. bool Result;
  2695. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2696. try
  2697. {
  2698. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2699. }
  2700. __finally
  2701. {
  2702. delete FileList;
  2703. }
  2704. return Result;
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2708. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2709. bool NoConfirmation, void * Param)
  2710. {
  2711. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2712. {
  2713. if ((Operation == foCopy) || (Operation == foMove))
  2714. {
  2715. DebugAssert(!IsLocalBrowserMode());
  2716. if (GetSide(Side) == osLocal)
  2717. {
  2718. Configuration->Usage->Inc(L"UploadsCommand");
  2719. }
  2720. else
  2721. {
  2722. Configuration->Usage->Inc(L"DownloadsCommand");
  2723. }
  2724. }
  2725. }
  2726. }
  2727. //---------------------------------------------------------------------------
  2728. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2729. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2730. {
  2731. TTransferOperationParam Param;
  2732. if ((WinConfiguration->Interface != ifCommander) ||
  2733. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2734. {
  2735. Flags &= ~cocShortCutHint;
  2736. }
  2737. TCustomDirView * DView = DirView(Side);
  2738. Param.Options =
  2739. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2740. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2741. if (FLAGSET(Flags, cocQueue))
  2742. {
  2743. Param.Queue = asOn;
  2744. }
  2745. else if (FLAGSET(Flags, cocNonQueue))
  2746. {
  2747. Param.Queue = asOff;
  2748. }
  2749. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2750. }
  2751. //---------------------------------------------------------------------------
  2752. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2753. {
  2754. try
  2755. {
  2756. if (ErrorList->Count)
  2757. {
  2758. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2759. if (MessageDialog(Message, qtError,
  2760. qaOK | qaCancel, HELP_NONE) == qaOK)
  2761. {
  2762. unsigned int Answer;
  2763. int Index = 0;
  2764. do
  2765. {
  2766. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2767. TQueryButtonAlias Aliases[2];
  2768. Aliases[0].Button = qaYes;
  2769. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2770. Aliases[1].Button = qaNo;
  2771. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2772. TMessageParams Params;
  2773. Params.Aliases = Aliases;
  2774. Params.AliasesCount = LENOF(Aliases);
  2775. Answer = MoreMessageDialog(
  2776. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2777. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2778. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2779. qaOK, HELP_NONE, &Params);
  2780. if (Answer == qaNo)
  2781. {
  2782. Index++;
  2783. }
  2784. if (Answer == qaYes)
  2785. {
  2786. Index--;
  2787. }
  2788. }
  2789. while (Answer != qaOK);
  2790. }
  2791. }
  2792. }
  2793. __finally
  2794. {
  2795. TStrings * List = ErrorList;
  2796. ErrorList = NULL;
  2797. for (int i = 0; i < List->Count; i++)
  2798. {
  2799. delete List->Objects[i];
  2800. }
  2801. delete List;
  2802. }
  2803. }
  2804. //---------------------------------------------------------------------------
  2805. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2806. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2807. {
  2808. // needed for checking filemasks, as there's no directory object
  2809. // associated with the file object
  2810. File->FullFileName = FullFileName;
  2811. TFileMasks::TParams MaskParams;
  2812. MaskParams.Size = File->Size;
  2813. MaskParams.Modification = File->Modification;
  2814. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2818. {
  2819. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2820. Side = GetSide(Side);
  2821. TCustomDirView * DView = DirView(Side);
  2822. TListItem * FocusedItem = DView->ItemFocused;
  2823. UnicodeString Name;
  2824. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2825. {
  2826. Name = DView->ItemFileName(FocusedItem);
  2827. }
  2828. else
  2829. {
  2830. Name = LoadStr(NEW_FILE);
  2831. }
  2832. UnicodeString Names = Name;
  2833. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2834. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2835. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2836. {
  2837. while (!Names.IsEmpty())
  2838. {
  2839. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2840. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2841. UnicodeString TargetFileName;
  2842. UnicodeString LocalFileName;
  2843. UnicodeString RootTempDir;
  2844. UnicodeString TempDir;
  2845. UnicodeString RemoteDirectory;
  2846. bool ExistingFile = false;
  2847. if (!IsSideLocalBrowser(Side))
  2848. {
  2849. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2850. TRemoteFile * File = NULL;
  2851. if (Terminal->FileExists(Name, &File) &&
  2852. !File->IsDirectory)
  2853. {
  2854. try
  2855. {
  2856. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2857. ExistingFile = true;
  2858. }
  2859. __finally
  2860. {
  2861. delete File;
  2862. }
  2863. }
  2864. if (!ExistingFile)
  2865. {
  2866. RemoteDirectory = UnixExtractFilePath(Name);
  2867. TemporaryDirectoryForRemoteFiles(
  2868. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2869. TargetFileName = UnixExtractFileName(Name);
  2870. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2871. LocalFileName = TempDir +
  2872. // We probably do not want to trim the VMS version here
  2873. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2874. }
  2875. }
  2876. else
  2877. {
  2878. if (ExtractFilePath(Name).IsEmpty())
  2879. {
  2880. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2881. }
  2882. else
  2883. {
  2884. LocalFileName = ExpandFileName(Name);
  2885. }
  2886. TargetFileName = ExtractFileName(Name);
  2887. }
  2888. if (!ExistingFile)
  2889. {
  2890. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2891. if (NewFile)
  2892. {
  2893. int File = FileCreate(ApiPath(LocalFileName));
  2894. if (File < 0)
  2895. {
  2896. if (!RootTempDir.IsEmpty())
  2897. {
  2898. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2899. }
  2900. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2901. }
  2902. else
  2903. {
  2904. FileClose(File);
  2905. }
  2906. }
  2907. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2908. const TEditorData * ExternalEditor = NULL;
  2909. TFileMasks::TParams MaskParams; // size not known
  2910. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2911. false, MaskParams);
  2912. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2913. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2914. }
  2915. }
  2916. }
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2920. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2921. {
  2922. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2923. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2924. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2925. return
  2926. ((ExecuteFileBy == efInternalEditor)) ||
  2927. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2928. }
  2929. //---------------------------------------------------------------------------
  2930. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2931. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2932. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2933. UnicodeString RemoteDirectory, bool NewFile)
  2934. {
  2935. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2936. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2937. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2938. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2939. Side = GetSide(Side);
  2940. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2941. if (!IsSideLocalBrowser(Side))
  2942. {
  2943. Data->Terminal = Terminal;
  2944. Data->Queue = Queue;
  2945. Data->SessionData = CloneCurrentSessionData();
  2946. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2947. Data->RemoteDirectory = RemoteDirectory;
  2948. Data->SessionName = Terminal->SessionData->SessionName;
  2949. Data->LocalRootDirectory = LocalRootDirectory;
  2950. Data->OriginalFileName = OriginalFileName;
  2951. Data->Command = L""; // will be changed later for external editor
  2952. }
  2953. if (ExecuteFileBy == efInternalEditor)
  2954. {
  2955. if (!IsSideLocalBrowser(Side))
  2956. {
  2957. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2958. L" - " + Terminal->SessionData->SessionName;
  2959. TForm * Editor;
  2960. try
  2961. {
  2962. TNotifyEvent OnFileChanged = NULL;
  2963. TNotifyEvent OnSaveAll = NULL;
  2964. TAnyModifiedEvent OnAnyModified = NULL;
  2965. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2966. if (Terminal->IsCapable[fcBackgroundTransfers])
  2967. {
  2968. OnFileChanged = FEditorManager->FileChanged;
  2969. OnSaveAll = SaveAllInternalEditors;
  2970. OnAnyModified = AnyInternalEditorModified;
  2971. }
  2972. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2973. FEditorManager->FileReload, FEditorManager->FileClosed,
  2974. OnSaveAll, OnAnyModified,
  2975. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2976. }
  2977. catch(...)
  2978. {
  2979. if (!LocalRootDirectory.IsEmpty())
  2980. {
  2981. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2982. }
  2983. throw;
  2984. }
  2985. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2986. }
  2987. else
  2988. {
  2989. DebugAssert(!FStandaloneEditing);
  2990. TForm * Editor =
  2991. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2992. SaveAllInternalEditors, AnyInternalEditorModified,
  2993. L"", false, SessionColor, -1, NewFile);
  2994. FLocalEditors->Add(Editor);
  2995. }
  2996. }
  2997. else
  2998. {
  2999. HANDLE Process;
  3000. if (ExecuteFileBy == efExternalEditor)
  3001. {
  3002. UnicodeString Program, Params, Dir;
  3003. Data->Command = ExternalEditor->ExternalEditor;
  3004. ReformatFileNameCommand(Data->Command);
  3005. SplitCommand(Data->Command, Program, Params, Dir);
  3006. Params = ExpandFileNameCommand(Params, FileName);
  3007. Program = ExpandEnvironmentVariables(Program);
  3008. if (!ExecuteShell(Program, Params, Process))
  3009. {
  3010. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3011. }
  3012. }
  3013. else
  3014. {
  3015. DebugAssert(!IsSideLocalBrowser(Side));
  3016. if (!ExecuteShell(FileName, L"", Process))
  3017. {
  3018. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3019. }
  3020. }
  3021. if (IsSideLocalBrowser(Side) ||
  3022. ((ExecuteFileBy == efShell) &&
  3023. !WinConfiguration->Editor.SDIShellEditor) ||
  3024. ((ExecuteFileBy == efExternalEditor) &&
  3025. !ExternalEditor->SDIExternalEditor))
  3026. {
  3027. // no need for handle
  3028. if (Process != NULL)
  3029. {
  3030. DebugCheck(CloseHandle(Process));
  3031. }
  3032. Process = INVALID_HANDLE_VALUE;
  3033. }
  3034. else
  3035. {
  3036. if (Process == NULL)
  3037. {
  3038. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3039. }
  3040. }
  3041. if (!IsSideLocalBrowser(Side))
  3042. {
  3043. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3044. }
  3045. }
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * /*Arg*/)
  3051. {
  3052. if (Token != NULL)
  3053. {
  3054. EditorFormFileSave(static_cast<TForm *>(Token));
  3055. }
  3056. }
  3057. //---------------------------------------------------------------------------
  3058. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3059. {
  3060. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3061. {
  3062. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3063. }
  3064. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3068. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3069. void * Arg)
  3070. {
  3071. if ((Token != NULL) &&
  3072. IsEditorFormModified(static_cast<TForm *>(Token)))
  3073. {
  3074. *static_cast<bool *>(Arg) = true;
  3075. }
  3076. }
  3077. //---------------------------------------------------------------------------
  3078. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3079. TObject * /*Sender*/, bool & Modified)
  3080. {
  3081. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3082. {
  3083. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3084. {
  3085. Modified = true;
  3086. }
  3087. }
  3088. if (!Modified)
  3089. {
  3090. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3091. }
  3092. }
  3093. //---------------------------------------------------------------------------
  3094. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3095. {
  3096. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3097. }
  3098. //---------------------------------------------------------------------------
  3099. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3100. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3101. UnicodeString & Result, UnicodeString & RootDirectory)
  3102. {
  3103. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3104. {
  3105. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3106. Result = RootDirectory;
  3107. }
  3108. else
  3109. {
  3110. RootDirectory = L"";
  3111. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3112. Result = IncludeTrailingBackslash(Result);
  3113. }
  3114. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3115. {
  3116. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3117. }
  3118. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3119. {
  3120. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3121. {
  3122. RemoteDirectory.Delete(1, 1);
  3123. }
  3124. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3125. }
  3126. if (!ForceDirectories(ApiPath(Result)))
  3127. {
  3128. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3129. }
  3130. }
  3131. //---------------------------------------------------------------------------
  3132. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3133. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3134. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3135. {
  3136. DebugAssert(!IsLocalBrowserMode());
  3137. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3138. if (ForceText)
  3139. {
  3140. CopyParam.TransferMode = tmAscii;
  3141. }
  3142. TemporaryFileCopyParam(CopyParam);
  3143. if (AllFiles)
  3144. {
  3145. CopyParam.IncludeFileMask = TFileMasks();
  3146. }
  3147. if (TempDir.IsEmpty())
  3148. {
  3149. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3150. }
  3151. DebugAssert(!FAutoOperation);
  3152. FAutoOperation = AutoOperation;
  3153. Terminal->ExceptionOnFail = true;
  3154. try
  3155. {
  3156. try
  3157. {
  3158. // turn off confirmations, as for MDI editors we may possibly download
  3159. // the same file over
  3160. Terminal->CopyToLocal(
  3161. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3162. if (GetTargetNames)
  3163. {
  3164. for (int i = 0; i < FileList->Count; i++)
  3165. {
  3166. FileList->Strings[i] =
  3167. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3168. }
  3169. }
  3170. }
  3171. catch(...)
  3172. {
  3173. if (!RootTempDir.IsEmpty())
  3174. {
  3175. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3176. }
  3177. throw;
  3178. }
  3179. }
  3180. __finally
  3181. {
  3182. FAutoOperation = false;
  3183. Terminal->ExceptionOnFail = false;
  3184. }
  3185. }
  3186. //---------------------------------------------------------------------------
  3187. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3188. {
  3189. // Do not waste time checking for default editor list the next time,
  3190. // or testing if default editor is not notepad.
  3191. bool TryNextTime = false;
  3192. UnicodeString UsageState;
  3193. if (!WinConfiguration->EditorList->IsDefaultList())
  3194. {
  3195. UsageState = "H";
  3196. }
  3197. else
  3198. {
  3199. UnicodeString Executable;
  3200. UnicodeString ExecutableDescription;
  3201. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3202. {
  3203. UnicodeString Message =
  3204. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3205. unsigned int Answer =
  3206. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3207. if (Answer != qaOK)
  3208. {
  3209. UsageState = "R";
  3210. }
  3211. else
  3212. {
  3213. UsageState = "A";
  3214. TEditorData EditorData;
  3215. EditorData.Editor = edExternal;
  3216. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3217. EditorData.ExternalEditorOptionsAutodetect();
  3218. TEditorList EditorList;
  3219. EditorList = *WinConfiguration->EditorList;
  3220. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3221. WinConfiguration->EditorList = &EditorList;
  3222. }
  3223. }
  3224. }
  3225. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3226. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3227. }
  3228. //---------------------------------------------------------------------------
  3229. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3230. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3231. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3232. {
  3233. if (ExecuteFileBy == efDefaultEditor)
  3234. {
  3235. if (!WinConfiguration->OfferedEditorAutoConfig)
  3236. {
  3237. EditorAutoConfig();
  3238. }
  3239. const TEditorPreferences * Editor =
  3240. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3241. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3242. {
  3243. ExecuteFileBy = efInternalEditor;
  3244. ExternalEditor = NULL;
  3245. }
  3246. else if (Editor->Data->Editor == edOpen)
  3247. {
  3248. ExecuteFileBy = efShell;
  3249. ExternalEditor = NULL;
  3250. }
  3251. else
  3252. {
  3253. ExecuteFileBy = efExternalEditor;
  3254. ExternalEditor = Editor->Data;
  3255. }
  3256. }
  3257. }
  3258. //---------------------------------------------------------------------------
  3259. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3260. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3261. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3262. {
  3263. UnicodeString OriginalFileName;
  3264. UnicodeString LocalRootDirectory;
  3265. UnicodeString RemoteDirectory;
  3266. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3267. IsSideLocalBrowser(Side), MaskParams);
  3268. UnicodeString Counter;
  3269. UnicodeString LocalFileName;
  3270. bool Handled = false;
  3271. if (!IsSideLocalBrowser(Side))
  3272. {
  3273. // We need to trim VMS version here, so that we use name without version
  3274. // when uploading back to create a new version of the file
  3275. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3276. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3277. TObject * Token = NULL;
  3278. UnicodeString LocalDirectory;
  3279. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3280. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3281. LocalDirectory))
  3282. {
  3283. if (Token != NULL)
  3284. {
  3285. TForm * Form = dynamic_cast<TForm *>(Token);
  3286. if (Form->WindowState == wsMinimized)
  3287. {
  3288. ShowWindow(Form->Handle, SW_RESTORE);
  3289. }
  3290. else
  3291. {
  3292. Form->SetFocus();
  3293. }
  3294. Handled = true;
  3295. }
  3296. else
  3297. {
  3298. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3299. }
  3300. }
  3301. if (!Handled)
  3302. {
  3303. TStringList * FileList1 = new TStringList();
  3304. try
  3305. {
  3306. FileList1->AddObject(FullFileName, Object);
  3307. TemporarilyDownloadFiles(FileList1,
  3308. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3309. LocalRootDirectory, LocalDirectory, true, true, true);
  3310. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3311. }
  3312. __finally
  3313. {
  3314. delete FileList1;
  3315. }
  3316. switch (ExecuteFileBy)
  3317. {
  3318. case efShell:
  3319. Counter = "RemoteFilesExecuted";
  3320. break;
  3321. case efInternalEditor:
  3322. Counter = "RemoteFilesOpenedInInternalEditor";
  3323. break;
  3324. case efExternalEditor:
  3325. Counter = "RemoteFilesOpenedInExternalEditor";
  3326. break;
  3327. default:
  3328. DebugFail();
  3329. }
  3330. }
  3331. }
  3332. else
  3333. {
  3334. LocalFileName = FullFileName;
  3335. OriginalFileName = ExtractFileName(FullFileName);
  3336. switch (ExecuteFileBy)
  3337. {
  3338. case efShell:
  3339. Counter = "LocalFilesExecuted";
  3340. break;
  3341. case efInternalEditor:
  3342. Counter = "LocalFilesOpenedInInternalEditor";
  3343. break;
  3344. case efExternalEditor:
  3345. Counter = "LocalFilesOpenedInExternalEditor";
  3346. break;
  3347. default:
  3348. DebugFail();
  3349. }
  3350. }
  3351. if (!Handled)
  3352. {
  3353. Configuration->Usage->Inc(Counter);
  3354. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3355. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3356. }
  3357. }
  3358. //---------------------------------------------------------------------------
  3359. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3360. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3361. bool AllSelected, bool OnFocused)
  3362. {
  3363. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3364. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3365. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3366. Side = GetSide(Side);
  3367. TCustomDirView * DView = DirView(Side);
  3368. TStrings * FileList =
  3369. AllSelected ?
  3370. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3371. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3372. try
  3373. {
  3374. DebugAssert(AllSelected || (FileList->Count == 1));
  3375. for (int i = 0; i < FileList->Count; i++)
  3376. {
  3377. UnicodeString ListFileName = FileList->Strings[i];
  3378. UnicodeString FileNameOnly =
  3379. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3380. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3381. if (!DView->ItemIsDirectory(Item))
  3382. {
  3383. UnicodeString FullFileName;
  3384. if (!IsSideLocalBrowser(Side))
  3385. {
  3386. FullFileName = DirView(Side)->Path + ListFileName;
  3387. }
  3388. else
  3389. {
  3390. FullFileName = ListFileName;
  3391. }
  3392. TFileMasks::TParams MaskParams;
  3393. MaskParams.Size = DView->ItemFileSize(Item);
  3394. TDateTimePrecision Precision;
  3395. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3396. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3397. FileList->Objects[i], MaskParams);
  3398. }
  3399. }
  3400. }
  3401. __finally
  3402. {
  3403. delete FileList;
  3404. }
  3405. }
  3406. //---------------------------------------------------------------------------
  3407. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3408. {
  3409. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3410. CopyParam.FileNameCase = ncNoChange;
  3411. CopyParam.PreserveRights = false;
  3412. CopyParam.PreserveReadOnly = false;
  3413. CopyParam.ReplaceInvalidChars = true;
  3414. CopyParam.IncludeFileMask = TFileMasks();
  3415. CopyParam.NewerOnly = false;
  3416. CopyParam.FileMask = L"";
  3417. }
  3418. //---------------------------------------------------------------------------
  3419. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3420. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3421. {
  3422. TTerminalManager * Manager = TTerminalManager::Instance();
  3423. if (!IsActiveTerminal(Data->Terminal))
  3424. {
  3425. if (!NonVisualDataModule->Busy)
  3426. {
  3427. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3428. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3429. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3430. if (Data->Terminal == NULL)
  3431. {
  3432. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3433. if (SameSiteTerminal != NULL)
  3434. {
  3435. UnicodeString Message =
  3436. FMTLOAD(EDIT_SESSION_REATTACH,
  3437. (FileNameOnly, Data->SessionName, FileNameOnly));
  3438. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3439. {
  3440. Data->Terminal = Terminal;
  3441. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3442. Data->SessionName = Terminal->SessionData->SessionName;
  3443. // We might also overwrite session data
  3444. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3445. }
  3446. else
  3447. {
  3448. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3449. Abort();
  3450. }
  3451. }
  3452. }
  3453. // foreground session should reconnect itself
  3454. else if (Terminal != Data->Terminal)
  3455. {
  3456. UnicodeString Message =
  3457. MainInstructions(
  3458. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3459. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3460. {
  3461. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3462. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3463. }
  3464. else
  3465. {
  3466. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3467. Abort();
  3468. }
  3469. }
  3470. }
  3471. if (!IsActiveTerminal(Data->Terminal))
  3472. {
  3473. Configuration->Usage->Inc(L"EditInactiveSession");
  3474. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3475. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3476. (ExtractFileName(FileName), Data->SessionName)));
  3477. }
  3478. }
  3479. TStrings * FileList = new TStringList();
  3480. try
  3481. {
  3482. FileList->Add(FileName);
  3483. // consider using the same settings (preset) as when the file was downloaded
  3484. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3485. TemporaryFileCopyParam(CopyParam);
  3486. if (Data->ForceText)
  3487. {
  3488. CopyParam.TransferMode = tmAscii;
  3489. }
  3490. // so i do not need to worry if masking algorithm works in all cases
  3491. // ("" means "copy file name", no masking is actually done)
  3492. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3493. {
  3494. CopyParam.FileMask = L"";
  3495. }
  3496. else
  3497. {
  3498. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3499. }
  3500. DebugAssert(Data->Queue != NULL);
  3501. int Params = cpNoConfirmation | cpTemporary;
  3502. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3503. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3504. QueueItem->CompleteEvent = UploadCompleteEvent;
  3505. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3506. }
  3507. __finally
  3508. {
  3509. delete FileList;
  3510. }
  3511. }
  3512. //---------------------------------------------------------------------------
  3513. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3514. const UnicodeString FileName, const TEditedFileData * Data)
  3515. {
  3516. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3517. DebugAssert(!NonVisualDataModule->Busy);
  3518. if (!IsActiveTerminal(Data->Terminal))
  3519. {
  3520. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3521. (ExtractFileName(FileName), Data->SessionName)));
  3522. }
  3523. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3524. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3525. NonVisualDataModule->StartBusy();
  3526. try
  3527. {
  3528. std::unique_ptr<TRemoteFile> File;
  3529. UnicodeString RemoteFileName =
  3530. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3531. Terminal->ExceptionOnFail = true;
  3532. try
  3533. {
  3534. TRemoteFile * AFile = NULL;
  3535. Terminal->ReadFile(RemoteFileName, AFile);
  3536. File.reset(AFile);
  3537. if (!File->HaveFullFileName)
  3538. {
  3539. File->FullFileName = RemoteFileName;
  3540. }
  3541. }
  3542. __finally
  3543. {
  3544. Terminal->ExceptionOnFail = false;
  3545. }
  3546. std::unique_ptr<TStrings> FileList(new TStringList());
  3547. FileList->AddObject(RemoteFileName, File.get());
  3548. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3549. UnicodeString TempDir = ExtractFilePath(FileName);
  3550. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3551. TempDir, true, true, true);
  3552. // sanity check, the target file name should be still the same
  3553. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3554. }
  3555. __finally
  3556. {
  3557. NonVisualDataModule->EndBusy();
  3558. // it actually may not exist anymore...
  3559. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3560. }
  3561. }
  3562. //---------------------------------------------------------------------------
  3563. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3564. const TEditedFileData * Data, bool & KeepOpen)
  3565. {
  3566. // Command is set for external editors only (not for "shell" open).
  3567. if (!Data->Command.IsEmpty())
  3568. {
  3569. bool AnyFound = false;
  3570. bool AnyMDI = false;
  3571. bool AnyNonMDI = false;
  3572. bool AnyDetect = false;
  3573. TEditorList * EditorList = new TEditorList();
  3574. try
  3575. {
  3576. *EditorList = *WinConfiguration->EditorList;
  3577. for (int i = 0; i < EditorList->Count; i++)
  3578. {
  3579. const TEditorPreferences * Editor = EditorList->Editors[i];
  3580. if ((Editor->Data->Editor == edExternal) &&
  3581. (Editor->Data->ExternalEditor == Data->Command))
  3582. {
  3583. AnyFound = true;
  3584. if (Editor->Data->SDIExternalEditor)
  3585. {
  3586. AnyNonMDI = true;
  3587. if (Editor->Data->DetectMDIExternalEditor)
  3588. {
  3589. AnyDetect = true;
  3590. }
  3591. }
  3592. else
  3593. {
  3594. AnyMDI = true;
  3595. }
  3596. }
  3597. }
  3598. bool EnableMDI = false;
  3599. bool DisableDetect = false;
  3600. if (AnyMDI)
  3601. {
  3602. KeepOpen = true;
  3603. if (AnyNonMDI)
  3604. {
  3605. // there is at least one instance of the editor with MDI support enabled,
  3606. // and one with disabled, enable it for all instances
  3607. EnableMDI = true;
  3608. }
  3609. }
  3610. else if (AnyFound && !AnyDetect)
  3611. {
  3612. // at least once instance found but all have MDI autodetection disabled
  3613. // => close the file (default action)
  3614. }
  3615. else
  3616. {
  3617. // no instance of the editor has MDI support enabled
  3618. TMessageParams Params;
  3619. if (AnyFound)
  3620. {
  3621. // there is at least one instance of the editor
  3622. Params.Params |= mpNeverAskAgainCheck;
  3623. }
  3624. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3625. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3626. switch (Answer)
  3627. {
  3628. case qaNeverAskAgain:
  3629. DisableDetect = true;
  3630. break;
  3631. case qaNo:
  3632. EnableMDI = true;
  3633. KeepOpen = true;
  3634. break;
  3635. }
  3636. }
  3637. if (AnyFound && (EnableMDI || DisableDetect))
  3638. {
  3639. bool Changed = false;
  3640. for (int i = 0; i < EditorList->Count; i++)
  3641. {
  3642. const TEditorPreferences * Editor = EditorList->Editors[i];
  3643. if ((Editor->Data->Editor == edExternal) &&
  3644. (Editor->Data->ExternalEditor == Data->Command) &&
  3645. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3646. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3647. {
  3648. Changed = true;
  3649. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3650. if (EnableMDI)
  3651. {
  3652. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3653. }
  3654. if (DisableDetect)
  3655. {
  3656. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3657. }
  3658. EditorList->Change(i, UpdatedEditor);
  3659. }
  3660. }
  3661. if (Changed)
  3662. {
  3663. WinConfiguration->EditorList = EditorList;
  3664. }
  3665. }
  3666. }
  3667. __finally
  3668. {
  3669. delete EditorList;
  3670. }
  3671. }
  3672. else
  3673. {
  3674. // "open" case
  3675. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3676. qaOK, HELP_APP_EARLY_CLOSED);
  3677. }
  3678. }
  3679. //---------------------------------------------------------------------------
  3680. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3681. {
  3682. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3686. {
  3687. SideEnter(osRemote);
  3688. }
  3689. //---------------------------------------------------------------------------
  3690. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3691. {
  3692. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3693. SideEnter(osRemote);
  3694. }
  3695. //---------------------------------------------------------------------------
  3696. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3697. {
  3698. FCurrentSide = Side;
  3699. if (Visible)
  3700. {
  3701. UpdateControls();
  3702. }
  3703. }
  3704. //---------------------------------------------------------------------------
  3705. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3706. TStrings * FileList, bool Alternative)
  3707. {
  3708. TCustomDirView * DView = DirView(Side);
  3709. DView->SaveSelection();
  3710. DView->SaveSelectedNames();
  3711. DebugAssert(!FAlternativeDelete);
  3712. FAlternativeDelete = Alternative;
  3713. try
  3714. {
  3715. if (!IsSideLocalBrowser(Side))
  3716. {
  3717. DebugAssert(Terminal != NULL);
  3718. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3719. }
  3720. else
  3721. {
  3722. if (IsLocalBrowserMode())
  3723. {
  3724. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3725. }
  3726. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3727. FProgressSide = FCurrentSide;
  3728. try
  3729. {
  3730. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3731. }
  3732. __finally
  3733. {
  3734. ReloadLocalDirectory();
  3735. }
  3736. }
  3737. FAlternativeDelete = false;
  3738. }
  3739. catch(...)
  3740. {
  3741. FAlternativeDelete = false;
  3742. DView->DiscardSavedSelection();
  3743. throw;
  3744. }
  3745. DView->RestoreSelection();
  3746. }
  3747. //---------------------------------------------------------------------------
  3748. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3749. {
  3750. DebugAssert(Terminal);
  3751. DebugAssert(!IsLocalBrowserMode());
  3752. RemoteDirView->SaveSelection();
  3753. RemoteDirView->SaveSelectedNames();
  3754. try
  3755. {
  3756. if (Lock)
  3757. {
  3758. Terminal->LockFiles(FileList);
  3759. }
  3760. else
  3761. {
  3762. Terminal->UnlockFiles(FileList);
  3763. }
  3764. }
  3765. catch(...)
  3766. {
  3767. RemoteDirView->DiscardSavedSelection();
  3768. throw;
  3769. }
  3770. RemoteDirView->RestoreSelection();
  3771. }
  3772. //---------------------------------------------------------------------------
  3773. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3774. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3775. bool NoConfirmation, bool Move)
  3776. {
  3777. DebugAssert(Terminal != NULL);
  3778. DebugAssert(!IsLocalBrowserMode());
  3779. // update Terminal->StateData->RemoteDirectory
  3780. UpdateTerminal(Terminal);
  3781. if (Session == NULL)
  3782. {
  3783. Session = TTerminalManager::Instance()->ActiveTerminal;
  3784. }
  3785. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3786. {
  3787. if (RemoteDriveView->DropTarget != NULL)
  3788. {
  3789. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3790. }
  3791. else if (RemoteDirView->DropTarget != NULL)
  3792. {
  3793. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3794. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3795. }
  3796. else
  3797. {
  3798. Target = RemoteDirView->Path;
  3799. }
  3800. }
  3801. else
  3802. {
  3803. Target = Session->StateData->RemoteDirectory;
  3804. }
  3805. Target = UnixIncludeTrailingBackslash(Target);
  3806. if (FileList->Count == 1)
  3807. {
  3808. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3809. }
  3810. else
  3811. {
  3812. FileMask = AnyMask;
  3813. }
  3814. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3815. bool Result = true;
  3816. if (!NoConfirmation)
  3817. {
  3818. bool Multi = (FileList->Count > 1);
  3819. if (Move)
  3820. {
  3821. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3822. }
  3823. else
  3824. {
  3825. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3826. TStrings * Directories = new TStringList;
  3827. try
  3828. {
  3829. for (int Index = 0; Index < Sessions->Count; Index++)
  3830. {
  3831. TManagedTerminal * Terminal =
  3832. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3833. Directories->Add(Terminal->StateData->RemoteDirectory);
  3834. }
  3835. TDirectRemoteCopy AllowDirectCopy;
  3836. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3837. {
  3838. DebugAssert(DirectCopy);
  3839. AllowDirectCopy = drcAllow;
  3840. }
  3841. else if (Terminal->IsCapable[fcSecondaryShell])
  3842. {
  3843. DebugAssert(DirectCopy);
  3844. AllowDirectCopy = drcConfirmCommandSession;
  3845. }
  3846. else
  3847. {
  3848. DebugAssert(!DirectCopy);
  3849. AllowDirectCopy = drcDisallow;
  3850. }
  3851. void * ASession = Session;
  3852. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3853. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3854. Session = static_cast<TManagedTerminal *>(ASession);
  3855. }
  3856. __finally
  3857. {
  3858. delete Directories;
  3859. }
  3860. }
  3861. }
  3862. return Result;
  3863. }
  3864. //---------------------------------------------------------------------------
  3865. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3866. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3867. {
  3868. DebugAssert(!IsLocalBrowserMode());
  3869. bool DirectCopy;
  3870. UnicodeString Target, FileMask;
  3871. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3872. if (Result)
  3873. {
  3874. if (!Move && !DirectCopy)
  3875. {
  3876. Configuration->Usage->Inc("RemoteCopyTemp");
  3877. UnicodeString RootTempDir;
  3878. UnicodeString TempDir;
  3879. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3880. TStrings * TemporaryFilesList = new TStringList();
  3881. try
  3882. {
  3883. TMakeLocalFileListParams MakeFileListParam;
  3884. MakeFileListParam.FileList = TemporaryFilesList;
  3885. MakeFileListParam.FileTimes = NULL;
  3886. MakeFileListParam.IncludeDirs = true;
  3887. MakeFileListParam.Recursive = false;
  3888. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  3889. TTerminalManager::Instance()->ActiveTerminal = Session;
  3890. if (TemporaryFilesList->Count > 0)
  3891. {
  3892. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3893. CopyParam.FileMask = FileMask;
  3894. DebugAssert(!FAutoOperation);
  3895. FAutoOperation = true;
  3896. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3897. }
  3898. }
  3899. __finally
  3900. {
  3901. delete TemporaryFilesList;
  3902. FAutoOperation = false;
  3903. if (!RootTempDir.IsEmpty())
  3904. {
  3905. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3906. }
  3907. }
  3908. }
  3909. else
  3910. {
  3911. RemoteDirView->SaveSelection();
  3912. RemoteDirView->SaveSelectedNames();
  3913. try
  3914. {
  3915. if (Move)
  3916. {
  3917. Configuration->Usage->Inc("RemoteMove");
  3918. Terminal->MoveFiles(FileList, Target, FileMask);
  3919. }
  3920. else
  3921. {
  3922. Configuration->Usage->Inc("RemoteCopyDirect");
  3923. DebugAssert(DirectCopy);
  3924. DebugAssert(Session == Terminal);
  3925. if (Terminal->IsCapable[fcRemoteCopy] ||
  3926. Terminal->CommandSessionOpened ||
  3927. CommandSessionFallback())
  3928. {
  3929. Terminal->CopyFiles(FileList, Target, FileMask);
  3930. }
  3931. }
  3932. }
  3933. catch(...)
  3934. {
  3935. RemoteDirView->DiscardSavedSelection();
  3936. throw;
  3937. }
  3938. RemoteDirView->RestoreSelection();
  3939. }
  3940. }
  3941. return Result;
  3942. }
  3943. //---------------------------------------------------------------------------
  3944. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3945. const UnicodeString & Path, TRemoteProperties & Properties)
  3946. {
  3947. DebugAssert(!IsLocalBrowserMode());
  3948. Properties.Valid = Properties.Valid << vpEncrypt;
  3949. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3950. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3951. }
  3952. //---------------------------------------------------------------------------
  3953. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3954. {
  3955. Side = GetSide(Side);
  3956. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3957. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3958. UnicodeString Name = LoadStr(NEW_FOLDER);
  3959. int AllowedChanges =
  3960. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3961. bool SaveSettings = false;
  3962. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3963. {
  3964. TWindowLock Lock(this);
  3965. if (!IsSideLocalBrowser(Side))
  3966. {
  3967. if (SaveSettings)
  3968. {
  3969. GUIConfiguration->NewDirectoryProperties = Properties;
  3970. }
  3971. CreateRemoteDirectory(Name, Properties);
  3972. }
  3973. else
  3974. {
  3975. DirView(Side)->CreateDirectory(Name);
  3976. }
  3977. }
  3978. }
  3979. //---------------------------------------------------------------------------
  3980. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3981. {
  3982. TWindowLock Lock(this);
  3983. DirView(Side)->ExecuteHomeDirectory();
  3984. }
  3985. //---------------------------------------------------------------------------
  3986. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3987. {
  3988. DoOpenDirectoryDialog(odBrowse, Side);
  3989. }
  3990. //---------------------------------------------------------------------------
  3991. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3992. {
  3993. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3994. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3995. bool Result = !Path.IsEmpty();
  3996. if (Result)
  3997. {
  3998. // While we might get here when the session is closed (from location profiles),
  3999. // it's not a problem as the Path setter is noop then
  4000. DirView(Side)->Path = Path;
  4001. }
  4002. return Result;
  4003. }
  4004. //---------------------------------------------------------------------------
  4005. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4006. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4007. bool & Close)
  4008. {
  4009. // terminal can be already closed (e.g. dropped connection)
  4010. if (Terminal != NULL)
  4011. {
  4012. try
  4013. {
  4014. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4015. }
  4016. catch(...)
  4017. {
  4018. if (!Terminal->Active)
  4019. {
  4020. Close = true;
  4021. }
  4022. throw;
  4023. }
  4024. }
  4025. }
  4026. //---------------------------------------------------------------------------
  4027. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4028. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4029. bool & Close)
  4030. {
  4031. // terminal can be already closed (e.g. dropped connection)
  4032. if (Terminal != NULL)
  4033. {
  4034. Configuration->Usage->Inc(L"ChecksumCalculated");
  4035. try
  4036. {
  4037. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4038. }
  4039. catch(...)
  4040. {
  4041. if (!Terminal->Active)
  4042. {
  4043. Close = true;
  4044. }
  4045. throw;
  4046. }
  4047. }
  4048. }
  4049. //---------------------------------------------------------------------------
  4050. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4051. {
  4052. bool Result;
  4053. if (!IsSideLocalBrowser(Side))
  4054. {
  4055. TRemoteTokenList * GroupList = NULL;
  4056. TRemoteTokenList * UserList = NULL;
  4057. try
  4058. {
  4059. TRemoteProperties CurrentProperties;
  4060. if (Terminal->LoadFilesProperties(FileList))
  4061. {
  4062. RemoteDirView->Invalidate();
  4063. }
  4064. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4065. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4066. if (CapableGroupChanging || CapableOwnerChanging)
  4067. {
  4068. if (CapableGroupChanging)
  4069. {
  4070. GroupList = Terminal->Groups->Duplicate();
  4071. }
  4072. if (CapableOwnerChanging)
  4073. {
  4074. UserList = Terminal->Users->Duplicate();
  4075. }
  4076. TRemoteDirectory * Files = Terminal->Files;
  4077. int Count = Files->Count;
  4078. if (Count > 100)
  4079. {
  4080. Count = 100;
  4081. }
  4082. for (int Index = 0; Index < Count; Index++)
  4083. {
  4084. TRemoteFile * File = Files->Files[Index];
  4085. if (CapableGroupChanging)
  4086. {
  4087. GroupList->AddUnique(File->Group);
  4088. }
  4089. if (CapableOwnerChanging)
  4090. {
  4091. UserList->AddUnique(File->Owner);
  4092. }
  4093. }
  4094. // if we haven't collected tokens for all files in current directory,
  4095. // make sure we collect them at least for all selected files.
  4096. // (note that so far the files in FileList has to be from current direcotry)
  4097. if (Count < Files->Count)
  4098. {
  4099. for (int Index = 0; Index < FileList->Count; Index++)
  4100. {
  4101. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4102. if (CapableGroupChanging)
  4103. {
  4104. GroupList->AddUnique(File->Group);
  4105. }
  4106. if (CapableOwnerChanging)
  4107. {
  4108. UserList->AddUnique(File->Owner);
  4109. }
  4110. }
  4111. }
  4112. }
  4113. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4114. int Flags = 0;
  4115. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4116. if (CapableOwnerChanging) Flags |= cpOwner;
  4117. if (CapableGroupChanging) Flags |= cpGroup;
  4118. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4119. if (Terminal->IsCapable[fcCalculatingChecksum])
  4120. {
  4121. CalculateChecksumEvent = CalculateChecksum;
  4122. }
  4123. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4124. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4125. TRemoteProperties NewProperties = CurrentProperties;
  4126. Result =
  4127. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4128. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4129. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4130. CalculateSize, CalculateChecksumEvent);
  4131. if (Result)
  4132. {
  4133. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4134. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4135. }
  4136. }
  4137. __finally
  4138. {
  4139. delete GroupList;
  4140. delete UserList;
  4141. }
  4142. }
  4143. else
  4144. {
  4145. DirView(Side)->DisplayPropertiesMenu();
  4146. Result = true;
  4147. }
  4148. return Result;
  4149. }
  4150. //---------------------------------------------------------------------------
  4151. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4152. {
  4153. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4154. {
  4155. FIgnoreNextDialogChar = Key;
  4156. }
  4157. Key = 0;
  4158. }
  4159. //---------------------------------------------------------------------------
  4160. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4161. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4162. {
  4163. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4164. if (Command != NULL)
  4165. {
  4166. KeyProcessed(Key, Shift);
  4167. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4168. {
  4169. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4170. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4171. false, false, const_cast<TCustomCommandType *>(Command));
  4172. }
  4173. }
  4174. }
  4175. //---------------------------------------------------------------------------
  4176. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4177. {
  4178. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4179. {
  4180. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4181. }
  4182. if (!DirView(osCurrent)->IsEditing())
  4183. {
  4184. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4185. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4186. {
  4187. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4188. // But so far it's not a problem, as it does what we want.
  4189. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4190. if (((Action->ShortCut == KeyShortCut) ||
  4191. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4192. AllowedAction(Action, aaShortCut))
  4193. {
  4194. // Has to be called before the action as the dialog char is already in queue.
  4195. // So when the action consumes message queue, we already need to have the
  4196. // FIgnoreNextDialogChar set
  4197. KeyProcessed(Key, Shift);
  4198. // Reset reference to previous component (when menu/toolbar was clicked).
  4199. // Needed to detect that action was invoked by keyboard shortcut
  4200. // in TNonVisualDataModule::ExplorerActionsExecute
  4201. Action->ActionComponent = NULL;
  4202. Action->Execute();
  4203. return;
  4204. }
  4205. }
  4206. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4207. {
  4208. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4209. {
  4210. KeyProcessed(Key, Shift);
  4211. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4212. return;
  4213. }
  4214. }
  4215. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4216. {
  4217. KeyProcessed(Key, Shift);
  4218. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4219. }
  4220. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4221. if (IsCustomShortCut(CustomShortCut))
  4222. {
  4223. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4224. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4225. if (WinConfiguration->SharedBookmarks != NULL)
  4226. {
  4227. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4228. if ((Bookmark != NULL) &&
  4229. OpenBookmark(FCurrentSide, Bookmark))
  4230. {
  4231. KeyProcessed(Key, Shift);
  4232. }
  4233. }
  4234. }
  4235. }
  4236. TForm::KeyDown(Key, Shift);
  4237. }
  4238. //---------------------------------------------------------------------------
  4239. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4240. {
  4241. bool OpenedTerminal = false;
  4242. UnicodeString ProtocolName;
  4243. UnicodeString ProtocolNameHint;
  4244. UnicodeString SecurityProtocolName;
  4245. UnicodeString DurationHint;
  4246. // See the comment in TScpCommanderForm::UpdateControls()
  4247. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4248. if (ActiveTerminal != NULL)
  4249. {
  4250. // Active is not enough here
  4251. if (ActiveTerminal->Status == ssOpened)
  4252. {
  4253. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4254. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4255. if (FileSystemInfo.ProtocolName.IsEmpty())
  4256. {
  4257. ProtocolName = SessionInfo.ProtocolName;
  4258. }
  4259. else
  4260. {
  4261. ProtocolName = FileSystemInfo.ProtocolName;
  4262. }
  4263. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4264. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4265. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4266. OpenedTerminal = true;
  4267. }
  4268. else if (ActiveTerminal->Status > ssClosed)
  4269. {
  4270. ProtocolName = LoadStr(STATUS_CONNECTING);
  4271. }
  4272. else
  4273. {
  4274. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4275. }
  4276. }
  4277. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4278. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4279. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4280. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4281. if (ProtocolStatusPanel->Caption != ProtocolName)
  4282. {
  4283. ProtocolStatusPanel->Caption = ProtocolName;
  4284. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4285. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4286. }
  4287. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4288. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4289. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4290. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4291. SecurityStatusPanel->Enabled = SecurityEnabled;
  4292. UnicodeString SecurityProtocolHint;
  4293. if (SecurityEnabled)
  4294. {
  4295. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4296. }
  4297. else
  4298. {
  4299. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4300. }
  4301. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4302. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4303. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4304. DurationStatusPanel->Hint = DurationHint;
  4305. UpdateStatusBar();
  4306. }
  4307. //---------------------------------------------------------------------------
  4308. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4309. {
  4310. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4311. DebugAssert(SessionStatusBar != NULL);
  4312. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4313. if (!FNote.IsEmpty())
  4314. {
  4315. NoteStatusPanel->Caption = FNote;
  4316. }
  4317. else
  4318. {
  4319. UpdateStatusPanelText(NoteStatusPanel);
  4320. }
  4321. NoteStatusPanel->Hint = FNoteHints;
  4322. UnicodeString LoginTime;
  4323. // See the comment in TScpCommanderForm::UpdateControls()
  4324. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4325. // Active is not enough here
  4326. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4327. {
  4328. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4329. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4330. }
  4331. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4332. DurationStatusPanel->Caption = LoginTime;
  4333. }
  4334. //---------------------------------------------------------------------------
  4335. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4336. {
  4337. Panel->Caption = L"";
  4338. }
  4339. //---------------------------------------------------------------------------
  4340. void __fastcall TCustomScpExplorerForm::Idle()
  4341. {
  4342. if (FShowing || FStandaloneEditing)
  4343. {
  4344. FEditorManager->Check();
  4345. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4346. // that needs to know if queue view is visible (and it may be closed after queue update)
  4347. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4348. }
  4349. if (FShowing)
  4350. {
  4351. if (!NonVisualDataModule->Busy &&
  4352. // Menu is opened or drag&drop is going on
  4353. (Mouse->Capture == NULL))
  4354. {
  4355. if (FRefreshRemoteDirectory)
  4356. {
  4357. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4358. {
  4359. Terminal->RefreshDirectory();
  4360. }
  4361. FRefreshRemoteDirectory = false;
  4362. }
  4363. if (FRefreshLocalDirectory)
  4364. {
  4365. ReloadLocalDirectory();
  4366. FRefreshLocalDirectory = false;
  4367. }
  4368. if (WinConfiguration->RefreshRemotePanel)
  4369. {
  4370. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4371. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4372. {
  4373. RemoteDirView->ReloadDirectory();
  4374. }
  4375. }
  4376. }
  4377. }
  4378. if (FShowing || FStandaloneEditing)
  4379. {
  4380. if (FQueueStatusInvalidated)
  4381. {
  4382. UpdateQueueStatus(false);
  4383. }
  4384. RefreshQueueItems();
  4385. }
  4386. if (FShowing)
  4387. {
  4388. UpdateStatusBar();
  4389. }
  4390. FIgnoreNextDialogChar = 0;
  4391. }
  4392. //---------------------------------------------------------------------------
  4393. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4394. {
  4395. try
  4396. {
  4397. FUserActionTimer->Enabled = false;
  4398. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4399. {
  4400. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4401. {
  4402. FPendingQueueActionItem->ProcessUserAction();
  4403. }
  4404. }
  4405. }
  4406. __finally
  4407. {
  4408. FPendingQueueActionItem = NULL;
  4409. }
  4410. }
  4411. //---------------------------------------------------------------------------
  4412. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4413. {
  4414. if (WinConfiguration->MinimizeToTray)
  4415. {
  4416. UpdateTrayIcon();
  4417. FTrayIcon->Visible = true;
  4418. if (Visible)
  4419. {
  4420. ShowWindow(Handle, SW_HIDE);
  4421. }
  4422. }
  4423. }
  4424. //---------------------------------------------------------------------------
  4425. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4426. {
  4427. // WORKAROUND
  4428. // When restoring maximized window from minimization,
  4429. // rarely some controls do not align properly.
  4430. // Two instances seen (both for Commander):
  4431. // - When restoring, window is temporarily narrower (not maximized),
  4432. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4433. // Once maximized already, top dock shinks back, but the session PageControl,
  4434. // do not align up, leaving space between TopDock and PageControl.
  4435. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4436. for (int Index = 0; Index < ControlCount; Index++)
  4437. {
  4438. RealignControl(Controls[Index]);
  4439. }
  4440. if (FTrayIcon->Visible)
  4441. {
  4442. FTrayIcon->Visible = false;
  4443. if (Visible)
  4444. {
  4445. ShowWindow(Handle, SW_SHOW);
  4446. }
  4447. }
  4448. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4449. {
  4450. FNeedSession = false;
  4451. NonVisualDataModule->StartBusy();
  4452. try
  4453. {
  4454. NeedSession(true);
  4455. }
  4456. __finally
  4457. {
  4458. NonVisualDataModule->EndBusy();
  4459. }
  4460. }
  4461. }
  4462. //---------------------------------------------------------------------------
  4463. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4464. {
  4465. FTrayIcon->Hint = GetMainForm()->Caption;
  4466. }
  4467. //---------------------------------------------------------------------------
  4468. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4469. {
  4470. UpdateTrayIcon();
  4471. }
  4472. //---------------------------------------------------------------------------
  4473. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4474. {
  4475. // workaround
  4476. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4477. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4478. // But WM_ACTIVATEAPP message can be received even when
  4479. // the main window is minimized to the tray and internal editor window is focused
  4480. // (after another application was previously active)
  4481. if (::IsIconic(Handle))
  4482. {
  4483. if (!IsAppIconic())
  4484. {
  4485. SetAppIconic(true);
  4486. }
  4487. }
  4488. ::ApplicationRestore();
  4489. Application->BringToFront();
  4490. }
  4491. //---------------------------------------------------------------------------
  4492. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4493. {
  4494. RestoreApp();
  4495. }
  4496. //---------------------------------------------------------------------------
  4497. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4498. {
  4499. if (OpenInNewWindow())
  4500. {
  4501. // todo: Pass FromSite
  4502. ExecuteNewInstance(SessionUrl);
  4503. }
  4504. else
  4505. {
  4506. TTerminalManager::Instance()->NewSession(SessionUrl);
  4507. }
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4511. {
  4512. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4513. StoredSessions->NewSession(SessionName, SessionData);
  4514. // modified only, explicit
  4515. StoredSessions->Save(false, true);
  4516. // encode session name because of slashes in hierarchical sessions
  4517. return EncodeUrlString(SessionName);
  4518. }
  4519. //---------------------------------------------------------------------------
  4520. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4521. {
  4522. // current working directories become defaults here, what is not right
  4523. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4524. return SaveHiddenDuplicateSession(SessionData.get());
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4528. {
  4529. if (OpenInNewWindow())
  4530. {
  4531. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4532. }
  4533. else
  4534. {
  4535. // current working directories become defaults here, what is not right
  4536. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4537. TTerminalManager * Manager = TTerminalManager::Instance();
  4538. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4539. Manager->ActiveTerminal = Terminal;
  4540. }
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. void __fastcall TCustomScpExplorerForm::RenameSession()
  4544. {
  4545. UnicodeString Name = Terminal->SessionData->SessionName;
  4546. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4547. {
  4548. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4549. TSessionData::ValidateName(Name);
  4550. // This is inconsistent with how color (for example) is handled.
  4551. Terminal->SessionData->Name = Name;
  4552. UpdateControls();
  4553. // Add/Remove distinguishing paths from sessions of the same name.
  4554. DoTerminalListChanged();
  4555. }
  4556. }
  4557. //---------------------------------------------------------------------------
  4558. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4559. {
  4560. DebugAssert(Queue != NULL);
  4561. bool Result = Queue->IsEmpty;
  4562. if (!Result)
  4563. {
  4564. SetFocus();
  4565. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4566. }
  4567. return Result;
  4568. }
  4569. //---------------------------------------------------------------------------
  4570. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4571. {
  4572. return CanCloseQueue(FQueue);
  4573. }
  4574. //---------------------------------------------------------------------------
  4575. void __fastcall TCustomScpExplorerForm::CloseSession()
  4576. {
  4577. if (CanCloseQueue())
  4578. {
  4579. TTerminalManager::Instance()->FreeActiveTerminal();
  4580. }
  4581. }
  4582. //---------------------------------------------------------------------------
  4583. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4584. {
  4585. if (CanCloseQueue())
  4586. {
  4587. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4588. }
  4589. }
  4590. //---------------------------------------------------------------------------
  4591. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4592. {
  4593. DetachTerminal(Terminal);
  4594. RemoteDirView->Terminal = Terminal;
  4595. UpdateRemotePathComboBox(false);
  4596. InitStatusBar();
  4597. UpdateControls();
  4598. }
  4599. //---------------------------------------------------------------------------
  4600. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4601. {
  4602. InitStatusBar();
  4603. }
  4604. //---------------------------------------------------------------------------
  4605. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4606. {
  4607. if (DebugAlwaysTrue(!Terminal->Active))
  4608. {
  4609. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4610. }
  4611. }
  4612. //---------------------------------------------------------------------------
  4613. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4614. {
  4615. if (OpenInNewWindow())
  4616. {
  4617. // encode session name because of slashes in hierarchical sessions
  4618. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4619. }
  4620. else
  4621. {
  4622. TTerminalManager * Manager = TTerminalManager::Instance();
  4623. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4624. Manager->ActiveTerminal = Terminal;
  4625. }
  4626. }
  4627. //---------------------------------------------------------------------------
  4628. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4629. {
  4630. TTerminalManager * Manager = TTerminalManager::Instance();
  4631. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4632. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4633. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4634. // FirstTerminal can be null, if some of the
  4635. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4636. {
  4637. FirstTerminal->Disconnected = true;
  4638. FirstTerminal->DisconnectedTemporarily = true;
  4639. }
  4640. Manager->ActiveTerminal = FirstTerminal;
  4641. }
  4642. //---------------------------------------------------------------------------
  4643. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4644. {
  4645. if (OpenInNewWindow())
  4646. {
  4647. ExecuteNewInstance(Name);
  4648. }
  4649. else
  4650. {
  4651. DoOpenFolderOrWorkspace(Name, true);
  4652. }
  4653. }
  4654. //---------------------------------------------------------------------------
  4655. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4656. bool &CanClose)
  4657. {
  4658. // See the comment in CloseApp()
  4659. if (NonVisualDataModule->Busy)
  4660. {
  4661. CanClose = false;
  4662. }
  4663. else if (Terminal != NULL)
  4664. {
  4665. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4666. {
  4667. unsigned int Result;
  4668. TMessageParams Params(mpNeverAskAgainCheck);
  4669. UnicodeString Message;
  4670. int Answers = qaOK | qaCancel;
  4671. if (TTerminalManager::Instance()->Count > 1)
  4672. {
  4673. if (!WinConfiguration->AutoSaveWorkspace)
  4674. {
  4675. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4676. }
  4677. else
  4678. {
  4679. Message = LoadStr(CLOSE_SESSIONS);
  4680. }
  4681. }
  4682. else
  4683. {
  4684. if (!WinConfiguration->AutoSaveWorkspace)
  4685. {
  4686. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4687. }
  4688. else
  4689. {
  4690. Message = LoadStr(CLOSE_SESSION);
  4691. }
  4692. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4693. }
  4694. UnicodeString Note;
  4695. if (WinConfiguration->AutoSaveWorkspace)
  4696. {
  4697. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4698. }
  4699. else
  4700. {
  4701. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4702. Answers = qaYes | qaNo | qaCancel;
  4703. }
  4704. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4705. SetFocus();
  4706. Result = MessageDialog(Message, qtConfirmation,
  4707. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4708. if (Result == qaNeverAskAgain)
  4709. {
  4710. WinConfiguration->ConfirmClosingSession = false;
  4711. }
  4712. if (Result == qaNo)
  4713. {
  4714. CanClose = SaveWorkspace(true);
  4715. // note that the workspace will be saved redundatly again from FormClose
  4716. }
  4717. else
  4718. {
  4719. CanClose =
  4720. (Result == qaOK) ||
  4721. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4722. (Result == qaNeverAskAgain);
  4723. }
  4724. }
  4725. if (CanClose)
  4726. {
  4727. CanClose = CanCloseQueue();
  4728. }
  4729. }
  4730. if (CanClose)
  4731. {
  4732. CanClose =
  4733. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4734. FEditorManager->CloseExternalFilesWithoutProcess();
  4735. if (CanClose)
  4736. {
  4737. while (CanClose && (FLocalEditors->Count > 0))
  4738. {
  4739. int PrevCount = FLocalEditors->Count;
  4740. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4741. CanClose = (FLocalEditors->Count < PrevCount);
  4742. }
  4743. if (CanClose)
  4744. {
  4745. CanClose = FEditorManager->Empty(true);
  4746. if (!CanClose)
  4747. {
  4748. SetFocus();
  4749. CanClose =
  4750. (MessageDialog(
  4751. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4752. }
  4753. }
  4754. }
  4755. }
  4756. }
  4757. //---------------------------------------------------------------------------
  4758. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4759. {
  4760. TForm * Form = dynamic_cast<TForm *>(Sender);
  4761. DebugAssert(Form != NULL);
  4762. Form->Close();
  4763. }
  4764. //---------------------------------------------------------------------------
  4765. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4766. {
  4767. TForm * Form = dynamic_cast<TForm *>(Sender);
  4768. delete Form;
  4769. }
  4770. //---------------------------------------------------------------------------
  4771. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4772. {
  4773. while (FLocalEditors->Count > 0)
  4774. {
  4775. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4776. }
  4777. }
  4778. //---------------------------------------------------------------------------
  4779. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4780. TObject *Sender)
  4781. {
  4782. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4783. try
  4784. {
  4785. SetProperties(osRemote, FileList);
  4786. }
  4787. __finally
  4788. {
  4789. delete FileList;
  4790. }
  4791. }
  4792. //---------------------------------------------------------------------------
  4793. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4794. {
  4795. if (value)
  4796. {
  4797. if (Component == fcCustomCommandsBand)
  4798. {
  4799. UpdateCustomCommandsToolbar();
  4800. }
  4801. if (Component == fcQueueFileList)
  4802. {
  4803. DebugAssert(!QueueFileListSplitter->Visible);
  4804. AdjustQueueLayout();
  4805. UpdateQueueFileList();
  4806. }
  4807. }
  4808. }
  4809. //---------------------------------------------------------------------------
  4810. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4811. {
  4812. int MinHeightLimit =
  4813. GetStaticQueuePanelComponentsHeight() +
  4814. QueueFileListSplitter->Height +
  4815. QueueFileList->Height +
  4816. GetMinQueueViewHeight();
  4817. if (QueuePanel->ClientHeight < MinHeightLimit)
  4818. {
  4819. QueuePanel->ClientHeight = MinHeightLimit;
  4820. }
  4821. }
  4822. //---------------------------------------------------------------------------
  4823. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4824. {
  4825. TControl * Control = GetComponent(Component);
  4826. DebugAssert(Control);
  4827. bool Changed = (Control->Visible != value);
  4828. if (Changed)
  4829. {
  4830. ComponentShowing(Component, value);
  4831. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4832. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4833. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4834. if (value)
  4835. {
  4836. int RemainingHeight = Control->Parent->ClientHeight;
  4837. int RemainingWidth = Control->Parent->ClientWidth;
  4838. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4839. {
  4840. TControl * ChildControl = Control->Parent->Controls[i];
  4841. if (ChildControl->Visible)
  4842. {
  4843. switch (ChildControl->Align)
  4844. {
  4845. case alTop:
  4846. case alBottom:
  4847. RemainingHeight -= ChildControl->Height;
  4848. break;
  4849. case alLeft:
  4850. case alRight:
  4851. RemainingWidth -= ChildControl->Width;
  4852. break;
  4853. }
  4854. }
  4855. }
  4856. int Reserve = ScaleByTextHeight(this, 32);
  4857. // queue in explorer, trees in commander
  4858. if (Control->Height > RemainingHeight - Reserve)
  4859. {
  4860. Control->Height = RemainingHeight / 2;
  4861. }
  4862. if (Control->Width > RemainingWidth - Reserve)
  4863. {
  4864. Control->Width = RemainingWidth / 2;
  4865. }
  4866. }
  4867. Control->Visible = value;
  4868. if (WasFocused && Visible)
  4869. {
  4870. DirView(osCurrent)->SetFocus();
  4871. }
  4872. FixControlsPlacement();
  4873. }
  4874. }
  4875. //---------------------------------------------------------------------------
  4876. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4877. {
  4878. TControl * Control = GetComponent(Component);
  4879. if (Control == NULL)
  4880. {
  4881. return false;
  4882. }
  4883. else
  4884. {
  4885. return Control->Visible;
  4886. }
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4890. {
  4891. bool Result;
  4892. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4893. {
  4894. Result = !IsUWP();
  4895. }
  4896. else
  4897. {
  4898. Result = true;
  4899. }
  4900. return Result;
  4901. }
  4902. //---------------------------------------------------------------------------
  4903. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4904. {
  4905. if (DirView->ItemFocused != NULL)
  4906. {
  4907. DirView->ItemFocused->MakeVisible(false);
  4908. }
  4909. }
  4910. //---------------------------------------------------------------------------
  4911. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4912. {
  4913. MakeFocusedItemVisible(RemoteDirView);
  4914. QueueSplitter->Visible = QueuePanel->Visible;
  4915. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4916. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4917. TControl * QueueControlsOrder[] =
  4918. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4919. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4920. }
  4921. //---------------------------------------------------------------------------
  4922. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4923. {
  4924. switch (Component) {
  4925. case fcStatusBar: return RemoteStatusBar;
  4926. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4927. case fcQueueView: return QueuePanel;
  4928. case fcQueueToolbar: return QueueDock;
  4929. case fcRemoteTree: return RemoteDrivePanel;
  4930. case fcSessionsTabs: return SessionsPageControl;
  4931. case fcQueueFileList: return QueueFileList;
  4932. default: return NULL;
  4933. }
  4934. }
  4935. //---------------------------------------------------------------------------
  4936. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4937. TObject *Sender, TListColumn *Column, TPoint &Point)
  4938. {
  4939. DebugAssert(NonVisualDataModule && Column && Sender);
  4940. NonVisualDataModule->ListColumn = Column;
  4941. TPopupMenu * DirViewColumnMenu;
  4942. if (Sender == DirView(osOther))
  4943. {
  4944. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4945. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4946. (Column->Index == uvName);
  4947. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4948. (Column->Index == uvSize);
  4949. }
  4950. else
  4951. {
  4952. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4953. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4954. (Column->Index == dvName);
  4955. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4956. (Column->Index == dvSize);
  4957. }
  4958. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4959. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4960. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4961. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4962. }
  4963. //---------------------------------------------------------------------------
  4964. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4965. TObject *Sender, TListItem *Item, bool &AllowExec)
  4966. {
  4967. DoDirViewExecFile(Sender, Item, AllowExec);
  4968. }
  4969. //---------------------------------------------------------------------------
  4970. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4971. TListItem * Item, bool & AllowExec)
  4972. {
  4973. DebugAssert(Sender && Item && Configuration);
  4974. DebugAssert(AllowExec);
  4975. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4976. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4977. bool Remote = !IsSideLocalBrowser(Side);
  4978. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4979. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4980. // on files only (not directories)
  4981. // and only when symlinks are resolved (apply to remote panel only)
  4982. if (!ADirView->ItemIsDirectory(Item) &&
  4983. (ResolvedSymlinks || FForceExecution))
  4984. {
  4985. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4986. !FForceExecution && ResolvedSymlinks)
  4987. {
  4988. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4989. {
  4990. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4991. UnlockWindow();
  4992. try
  4993. {
  4994. if (IsLocalBrowserMode())
  4995. {
  4996. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  4997. }
  4998. else
  4999. {
  5000. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5001. }
  5002. }
  5003. __finally
  5004. {
  5005. LockWindow();
  5006. }
  5007. AllowExec = false;
  5008. }
  5009. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5010. {
  5011. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5012. {
  5013. ExecuteFile(Side, efDefaultEditor);
  5014. AllowExec = false;
  5015. }
  5016. }
  5017. else
  5018. {
  5019. DebugFail();
  5020. }
  5021. }
  5022. // if we have not done anything special, fall back to default behavior
  5023. if (AllowExec)
  5024. {
  5025. if (Remote && !WinConfiguration->DisableOpenEdit)
  5026. {
  5027. ExecuteFile(osRemote, efShell);
  5028. AllowExec = false;
  5029. }
  5030. }
  5031. }
  5032. }
  5033. //---------------------------------------------------------------------------
  5034. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5035. {
  5036. return ((Side == osRemote) || (Side == osCurrent));
  5037. }
  5038. //---------------------------------------------------------------------------
  5039. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5040. {
  5041. DebugFail();
  5042. }
  5043. //---------------------------------------------------------------------------
  5044. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5045. {
  5046. DebugFail();
  5047. }
  5048. //---------------------------------------------------------------------------
  5049. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5050. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5051. {
  5052. TSynchronizeParamType Params;
  5053. Params.LocalDirectory = LocalDirectory;
  5054. Params.RemoteDirectory = RemoteDirectory;
  5055. int UnusedParams =
  5056. (GUIConfiguration->SynchronizeParams &
  5057. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5058. TTerminal::spCaseSensitive));
  5059. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5060. Params.Options = GUIConfiguration->SynchronizeOptions;
  5061. bool SaveSettings = false;
  5062. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5063. &DoSynchronizeTooManyDirectories);
  5064. DebugAssert(FSynchronizeController == NULL);
  5065. FSynchronizeController = &Controller;
  5066. bool Result;
  5067. try
  5068. {
  5069. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5070. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5071. int Options =
  5072. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5073. DebugAssert(FOnFeedSynchronizeError == NULL);
  5074. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5075. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5076. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5077. if (Result)
  5078. {
  5079. if (SaveSettings)
  5080. {
  5081. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5082. GUIConfiguration->SynchronizeOptions = Params.Options;
  5083. }
  5084. else
  5085. {
  5086. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5087. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5088. FLAGSET(Params.Options, soSynchronize))
  5089. {
  5090. GUIConfiguration->SynchronizeOptions =
  5091. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5092. soSynchronize;
  5093. }
  5094. }
  5095. LocalDirectory = Params.LocalDirectory;
  5096. RemoteDirectory = Params.RemoteDirectory;
  5097. }
  5098. }
  5099. __finally
  5100. {
  5101. FSynchronizeController = NULL;
  5102. DebugAssert(FOnFeedSynchronizeError == NULL);
  5103. FOnFeedSynchronizeError = NULL;
  5104. }
  5105. return Result;
  5106. }
  5107. //---------------------------------------------------------------------------
  5108. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5109. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5110. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5111. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5112. TSynchronizeOptions * Options, bool Full)
  5113. {
  5114. // Keep-up-to-date mode
  5115. if (Terminal->Status == ssOpened)
  5116. {
  5117. try
  5118. {
  5119. int PParams = Params.Params;
  5120. if (!Full)
  5121. {
  5122. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5123. if (FLAGSET(Params.Options, soRecurse))
  5124. {
  5125. PParams |= TTerminal::spSubDirs;
  5126. }
  5127. }
  5128. else
  5129. {
  5130. // if keepuptodate is non-recursive,
  5131. // full sync before has to be non-recursive as well
  5132. if (FLAGCLEAR(Params.Options, soRecurse))
  5133. {
  5134. PParams |= TTerminal::spNoRecurse;
  5135. }
  5136. }
  5137. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5138. PParams, Checklist, Options);
  5139. }
  5140. catch (Exception & E)
  5141. {
  5142. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5143. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5144. {
  5145. // noop, already logged in MoreMessageDialog
  5146. }
  5147. else
  5148. {
  5149. ShowExtendedExceptionEx(Terminal, &E);
  5150. throw;
  5151. }
  5152. }
  5153. }
  5154. }
  5155. //---------------------------------------------------------------------------
  5156. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5157. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5158. const UnicodeString ErrorStr)
  5159. {
  5160. if (!Directory.IsEmpty())
  5161. {
  5162. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5163. }
  5164. else
  5165. {
  5166. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5167. }
  5168. }
  5169. //---------------------------------------------------------------------------
  5170. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5171. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5172. {
  5173. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5174. {
  5175. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5176. }
  5177. else
  5178. {
  5179. TMessageParams Params(mpNeverAskAgainCheck);
  5180. unsigned int Result = MessageDialog(
  5181. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5182. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5183. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5184. {
  5185. MaxDirectories *= 2;
  5186. if (Result == qaNeverAskAgain)
  5187. {
  5188. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5189. }
  5190. }
  5191. else
  5192. {
  5193. Abort();
  5194. }
  5195. }
  5196. }
  5197. //---------------------------------------------------------------------------
  5198. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5199. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5200. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5201. TSynchronizeOptions * Options)
  5202. {
  5203. // Keep-up-to-date mode
  5204. DebugAssert(!FAutoOperation);
  5205. void * BatchStorage;
  5206. BatchStart(BatchStorage);
  5207. FAutoOperation = true;
  5208. bool AnyOperation = false;
  5209. TDateTime StartTime = Now();
  5210. TSynchronizeChecklist * AChecklist = NULL;
  5211. try
  5212. {
  5213. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5214. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5215. {
  5216. FSynchronizeProgressForm->Start();
  5217. }
  5218. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5219. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5220. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5221. Options);
  5222. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5223. SAFE_DESTROY(FSynchronizeProgressForm);
  5224. AnyOperation = (AChecklist->CheckedCount > 0);
  5225. if (AnyOperation)
  5226. {
  5227. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5228. CreateProgressForm(&SynchronizeProgress);
  5229. try
  5230. {
  5231. Terminal->SynchronizeApply(
  5232. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5233. SynchronizeProcessedItem, NULL, NULL, NULL);
  5234. }
  5235. __finally
  5236. {
  5237. DestroyProgressForm();
  5238. }
  5239. }
  5240. }
  5241. __finally
  5242. {
  5243. if (Checklist == NULL)
  5244. {
  5245. delete AChecklist;
  5246. }
  5247. else
  5248. {
  5249. *Checklist = AChecklist;
  5250. }
  5251. FAutoOperation = false;
  5252. SAFE_DESTROY(FSynchronizeProgressForm);
  5253. BatchEnd(BatchStorage);
  5254. ReloadLocalDirectory();
  5255. if (AnyOperation)
  5256. {
  5257. OperationComplete(StartTime);
  5258. }
  5259. }
  5260. }
  5261. //---------------------------------------------------------------------------
  5262. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5263. {
  5264. // can be called from command line
  5265. return Visible &&
  5266. ((DirView(osRemote)->SelCount > 0) ||
  5267. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5268. }
  5269. //---------------------------------------------------------------------------
  5270. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5271. {
  5272. LogSynchronizeEvent(Terminal, Message);
  5273. }
  5274. //---------------------------------------------------------------------------
  5275. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5276. int Params, TSynchronizeOptions & Options)
  5277. {
  5278. DebugAssert(!IsLocalBrowserMode());
  5279. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5280. {
  5281. Options.Filter = new TStringList();
  5282. Options.Filter->CaseSensitive = false;
  5283. Options.Filter->Duplicates = Types::dupAccept;
  5284. if (DirView(osRemote)->SelCount > 0)
  5285. {
  5286. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5287. }
  5288. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5289. {
  5290. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5291. }
  5292. Options.Filter->Sort();
  5293. }
  5294. }
  5295. //---------------------------------------------------------------------------
  5296. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5297. {
  5298. TCopyParamType Defaults;
  5299. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5300. ConfigStorage->AccessMode = smRead;
  5301. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5302. {
  5303. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5304. }
  5305. ConfigStorage.reset(NULL);
  5306. std::unique_ptr<TStringList> Options(new TStringList());
  5307. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5308. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5309. UnicodeString Result;
  5310. if (Options->Count > 0)
  5311. {
  5312. Result =
  5313. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5314. }
  5315. return Result;
  5316. }
  5317. //---------------------------------------------------------------------------
  5318. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5319. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5320. {
  5321. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5322. UnicodeString AdditionalParams =
  5323. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5324. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5325. SerializeCopyParamForCommandLine(CopyParams),
  5326. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5327. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5328. ExecuteNewInstance(SessionName, AdditionalParams);
  5329. }
  5330. //---------------------------------------------------------------------------
  5331. struct TSynchronizeParams
  5332. {
  5333. UnicodeString LocalDirectory;
  5334. UnicodeString RemoteDirectory;
  5335. TSynchronizeMode Mode;
  5336. TSynchronizeChecklist * Checklist;
  5337. int Params;
  5338. TCopyParamType * CopyParam;
  5339. TDateTime CollectElapsed;
  5340. TDateTime * StartTime;
  5341. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5342. };
  5343. //---------------------------------------------------------------------------
  5344. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5345. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5346. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5347. {
  5348. DebugAssert(!FAutoOperation);
  5349. void * BatchStorage;
  5350. BatchStart(BatchStorage);
  5351. FAutoOperation = true;
  5352. TFileOperationStatistics Statistics;
  5353. TDateTime Start = Now();
  5354. try
  5355. {
  5356. Params.OnProcessedItem = OnProcessedItem;
  5357. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5358. CreateProgressForm(&SynchronizeProgress);
  5359. Terminal->SynchronizeApply(
  5360. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5361. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5362. &Statistics);
  5363. }
  5364. __finally
  5365. {
  5366. Params.OnProcessedItem = NULL;
  5367. FAutoOperation = false;
  5368. DestroyProgressForm();
  5369. BatchEnd(BatchStorage);
  5370. ReloadLocalDirectory();
  5371. }
  5372. if (WinConfiguration->SynchronizeSummary)
  5373. {
  5374. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5375. // The statistics should be 0 anyway in this case
  5376. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5377. {
  5378. Message += L"\n";
  5379. if (Statistics.FilesUploaded > 0)
  5380. {
  5381. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5382. }
  5383. if (Statistics.FilesDownloaded > 0)
  5384. {
  5385. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5386. }
  5387. if (Statistics.FilesDeletedLocal > 0)
  5388. {
  5389. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5390. }
  5391. if (Statistics.FilesDeletedRemote > 0)
  5392. {
  5393. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5394. }
  5395. }
  5396. TDateTime Elapsed = (Now() - Start);
  5397. Message +=
  5398. L"\n" +
  5399. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5400. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5401. TMessageParams Params(mpNeverAskAgainCheck);
  5402. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5403. if (Result == qaNeverAskAgain)
  5404. {
  5405. WinConfiguration->SynchronizeSummary = false;
  5406. }
  5407. }
  5408. }
  5409. //---------------------------------------------------------------------------
  5410. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5411. {
  5412. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5413. {
  5414. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5415. }
  5416. // Not set in keep-up-to-date mode - Synchronize() method
  5417. if (Token != NULL)
  5418. {
  5419. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5420. if (Params.OnProcessedItem != NULL)
  5421. {
  5422. Params.OnProcessedItem(NULL, ChecklistItem);
  5423. }
  5424. }
  5425. }
  5426. //---------------------------------------------------------------------------
  5427. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5428. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5429. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5430. {
  5431. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5432. *Params.StartTime = Now();
  5433. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5434. }
  5435. //---------------------------------------------------------------------------
  5436. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5437. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5438. {
  5439. // terminal can be already closed (e.g. dropped connection)
  5440. if (Terminal != NULL)
  5441. {
  5442. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5443. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5444. }
  5445. }
  5446. //---------------------------------------------------------------------------
  5447. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5448. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5449. {
  5450. DebugAssert(!IsLocalBrowserMode());
  5451. TAutoBatch AutoBatch(this);
  5452. TAutoFlag AutoOperationFlag(FAutoOperation);
  5453. if (Side == osRemote)
  5454. {
  5455. std::unique_ptr<TStrings> FileList(new TStringList());
  5456. FileList->AddObject(FileName, RemoteFile);
  5457. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5458. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5459. RemoteDirView->SaveSelection();
  5460. RemoteDirView->SaveSelectedNames();
  5461. try
  5462. {
  5463. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5464. }
  5465. catch(...)
  5466. {
  5467. RemoteDirView->DiscardSavedSelection();
  5468. throw;
  5469. }
  5470. RemoteDirView->RestoreSelection();
  5471. }
  5472. else if (DebugAlwaysTrue(Side == osLocal))
  5473. {
  5474. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5475. {
  5476. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5477. }
  5478. UnicodeString Directory = ExtractFileDir(FileName);
  5479. ReloadLocalDirectory(Directory);
  5480. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5481. if (!SamePaths(Directory, NewDirectory))
  5482. {
  5483. ReloadLocalDirectory(NewDirectory);
  5484. }
  5485. }
  5486. }
  5487. //---------------------------------------------------------------------------
  5488. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5489. {
  5490. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5491. if (Side == osLocal)
  5492. {
  5493. if (Action == TSynchronizeChecklist::saDownloadNew)
  5494. {
  5495. OpenFolderInExplorer(LocalPath);
  5496. }
  5497. else
  5498. {
  5499. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5500. }
  5501. }
  5502. else if (DebugAlwaysTrue(Side == osRemote))
  5503. {
  5504. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5505. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5506. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5507. if (!LocalPath.IsEmpty())
  5508. {
  5509. SessionData->LocalDirectory = LocalPath;
  5510. }
  5511. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5512. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5513. }
  5514. }
  5515. //---------------------------------------------------------------------------
  5516. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5517. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5518. const TCopyParamType * CopyParams)
  5519. {
  5520. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5521. UnicodeString AdditionalParams =
  5522. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5523. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5524. SerializeCopyParamForCommandLine(CopyParams),
  5525. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5526. LocalDirectory, RemoteDirectory, Mode, Params));
  5527. ExecuteNewInstance(SessionName, AdditionalParams);
  5528. }
  5529. //---------------------------------------------------------------------------
  5530. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5531. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5532. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5533. {
  5534. int Result;
  5535. bool SaveSettings = false;
  5536. int Options =
  5537. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5538. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5539. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5540. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5541. bool Continue =
  5542. (UseDefaults == 0) ||
  5543. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5544. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5545. if (Continue)
  5546. {
  5547. Configuration->Usage->Inc(L"Synchronizations");
  5548. UpdateCopyParamCounters(CopyParam);
  5549. TSynchronizeOptions SynchronizeOptions;
  5550. GetSynchronizeOptions(Params, SynchronizeOptions);
  5551. if (SaveSettings)
  5552. {
  5553. GUIConfiguration->SynchronizeParams = Params;
  5554. }
  5555. else
  5556. {
  5557. SaveMode = false;
  5558. }
  5559. TDateTime StartTime = Now();
  5560. TSynchronizeChecklist * Checklist = NULL;
  5561. try
  5562. {
  5563. DebugAssert(!FAutoOperation);
  5564. FAutoOperation = true;
  5565. try
  5566. {
  5567. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5568. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5569. int Files = -1;
  5570. if (DataList->Count >= 1)
  5571. {
  5572. Files = StrToIntDef(DataList->Strings[0], Files);
  5573. }
  5574. else
  5575. {
  5576. DataList->Add(UnicodeString());
  5577. }
  5578. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5579. FSynchronizeProgressForm->Start();
  5580. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5581. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5582. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5583. &SynchronizeOptions);
  5584. if (Terminal->SessionData->CacheDirectories)
  5585. {
  5586. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5587. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5588. }
  5589. }
  5590. __finally
  5591. {
  5592. FAutoOperation = false;
  5593. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5594. SAFE_DESTROY(FSynchronizeProgressForm);
  5595. }
  5596. TSynchronizeParams SynchronizeParams;
  5597. SynchronizeParams.LocalDirectory = LocalDirectory;
  5598. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5599. SynchronizeParams.Mode = Mode;
  5600. SynchronizeParams.CopyParam = &CopyParam;
  5601. SynchronizeParams.Params = Params;
  5602. SynchronizeParams.Checklist = Checklist;
  5603. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5604. SynchronizeParams.StartTime = &StartTime;
  5605. SynchronizeParams.OnProcessedItem = NULL;
  5606. Result = Checklist->Count;
  5607. if (Checklist->Count > 0)
  5608. {
  5609. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5610. {
  5611. if (!DoSynchronizeChecklistDialog(
  5612. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5613. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5614. {
  5615. Result = -1;
  5616. }
  5617. }
  5618. else
  5619. {
  5620. FullSynchronize(SynchronizeParams, NULL, NULL);
  5621. }
  5622. }
  5623. else
  5624. {
  5625. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5626. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5627. }
  5628. }
  5629. __finally
  5630. {
  5631. delete Checklist;
  5632. }
  5633. OperationComplete(StartTime);
  5634. }
  5635. else
  5636. {
  5637. Result = -1;
  5638. }
  5639. return Result;
  5640. }
  5641. //---------------------------------------------------------------------------
  5642. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5643. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5644. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5645. {
  5646. if (Collect)
  5647. {
  5648. DebugAssert(FSynchronizeProgressForm != NULL);
  5649. if (!FSynchronizeProgressForm->Started)
  5650. {
  5651. FSynchronizeProgressForm->Start();
  5652. }
  5653. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5654. SetTaskbarListProgressValue(CompareProgress);
  5655. }
  5656. else
  5657. {
  5658. DebugAssert(FSynchronizeProgressForm == NULL);
  5659. DebugAssert(FProgressForm != NULL);
  5660. }
  5661. }
  5662. //---------------------------------------------------------------------------
  5663. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5664. {
  5665. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5666. TRemoteFile * File = NULL;
  5667. Terminal->ReadFile(FullFileName, File);
  5668. if (File != NULL)
  5669. {
  5670. std::unique_ptr<TRemoteFile> FileOwner(File);
  5671. TAutoFlag Flag(FStandaloneEditing);
  5672. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5673. Application->ShowMainForm = false;
  5674. Application->Run();
  5675. }
  5676. }
  5677. //---------------------------------------------------------------------------
  5678. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5679. {
  5680. DebugFail();
  5681. }
  5682. //---------------------------------------------------------------------------
  5683. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5684. {
  5685. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5686. SessionData->Assign(Terminal->SessionData);
  5687. UpdateSessionData(SessionData.get());
  5688. Terminal->UpdateSessionCredentials(SessionData.get());
  5689. if (!Terminal->SessionData->HasSessionName())
  5690. {
  5691. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5692. // once IsWorkspace is cleared
  5693. SessionData->Name = UnicodeString();
  5694. SessionData->IsWorkspace = false;
  5695. }
  5696. return SessionData.release();
  5697. }
  5698. //---------------------------------------------------------------------------
  5699. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5700. {
  5701. TSessionData * SessionData = CloneCurrentSessionData();
  5702. try
  5703. {
  5704. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5705. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5706. }
  5707. __finally
  5708. {
  5709. delete SessionData;
  5710. }
  5711. }
  5712. //---------------------------------------------------------------------------
  5713. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5714. {
  5715. TTerminalManager * Manager = TTerminalManager::Instance();
  5716. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5717. if (DebugAlwaysTrue(Terminal != NULL))
  5718. {
  5719. // Update (Managed)Terminal->StateData
  5720. UpdateTerminal(Terminal);
  5721. }
  5722. Manager->SaveWorkspace(DataList.get());
  5723. return DataList.release();
  5724. }
  5725. //---------------------------------------------------------------------------
  5726. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5727. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5728. {
  5729. WinConfiguration->LastWorkspace = Name;
  5730. if (!SavePasswords)
  5731. {
  5732. for (int Index = 0; Index < DataList->Count; Index++)
  5733. {
  5734. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5735. if (SessionData->Link.IsEmpty())
  5736. {
  5737. SessionData->ClearSessionPasswords();
  5738. }
  5739. }
  5740. }
  5741. StoredSessions->NewWorkspace(Name, DataList);
  5742. // modified only
  5743. StoredSessions->Save(false, Explicit);
  5744. }
  5745. //---------------------------------------------------------------------------
  5746. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5747. {
  5748. return
  5749. DefaultStr(WinConfiguration->LastWorkspace,
  5750. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5751. }
  5752. //---------------------------------------------------------------------------
  5753. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5754. {
  5755. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5756. bool AnyNonStoredSessionWithPassword = false;
  5757. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5758. bool AllNonStoredSessionsAnonymous = true;
  5759. TTerminalManager * Manager = TTerminalManager::Instance();
  5760. for (int Index = 0; Index < DataList->Count; Index++)
  5761. {
  5762. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5763. if (SessionData->Link.IsEmpty())
  5764. {
  5765. if (SessionData->HasAnySessionPassword())
  5766. {
  5767. AnyNonStoredSessionWithPassword = true;
  5768. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5769. {
  5770. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5771. }
  5772. }
  5773. if (!SameText(SessionData->UserName, AnonymousUserName))
  5774. {
  5775. AllNonStoredSessionsAnonymous = false;
  5776. }
  5777. }
  5778. }
  5779. bool SavePasswords;
  5780. bool * PSavePasswords;
  5781. bool NotRecommendedSavingPasswords =
  5782. !CustomWinConfiguration->UseMasterPassword &&
  5783. !AllNonStoredSessionsAnonymous;
  5784. if (Configuration->DisablePasswordStoring ||
  5785. !AnyNonStoredSessionWithPassword)
  5786. {
  5787. PSavePasswords = NULL;
  5788. SavePasswords = false;
  5789. }
  5790. else
  5791. {
  5792. PSavePasswords = &SavePasswords;
  5793. SavePasswords =
  5794. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5795. !NotRecommendedSavingPasswords;
  5796. }
  5797. UnicodeString Name = WorkspaceName();
  5798. bool CreateShortcut = false;
  5799. bool Result =
  5800. DoSaveWorkspaceDialog(
  5801. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5802. EnableAutoSave);
  5803. if (Result)
  5804. {
  5805. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5806. if (CreateShortcut)
  5807. {
  5808. TOperationVisualizer Visualizer;
  5809. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5810. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5811. }
  5812. if (EnableAutoSave)
  5813. {
  5814. WinConfiguration->AutoSaveWorkspace = true;
  5815. WinConfiguration->AutoWorkspace = Name;
  5816. if (PSavePasswords != NULL)
  5817. {
  5818. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5819. }
  5820. }
  5821. }
  5822. return Result;
  5823. }
  5824. //---------------------------------------------------------------------------
  5825. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5826. {
  5827. DebugAssert(!IsLocalBrowserMode());
  5828. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5829. if (WinConfiguration->PreservePanelState)
  5830. {
  5831. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5832. }
  5833. UpdateSessionData(Terminal->StateData);
  5834. }
  5835. //---------------------------------------------------------------------------
  5836. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5837. {
  5838. // Keep in sync with TSessionData::CopyStateData
  5839. DebugAssert(!IsLocalBrowserMode());
  5840. DebugAssert(Data != NULL);
  5841. // This is inconsistent with how color (for example) is handled.
  5842. Data->Name = Terminal->SessionData->Name;
  5843. // cannot use RemoteDirView->Path, because it is empty if connection
  5844. // was already closed
  5845. // also only peek, we may not be connected at all atm
  5846. // so make sure we do not try retrieving current directory from the server
  5847. // (particularly with FTP)
  5848. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5849. if (!ACurrentDirectory.IsEmpty())
  5850. {
  5851. Data->RemoteDirectory = ACurrentDirectory;
  5852. }
  5853. Data->Color = SessionColor;
  5854. }
  5855. //---------------------------------------------------------------------------
  5856. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5857. {
  5858. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5859. DebugAssert(Toolbar != NULL);
  5860. for (int i = 0; i < Toolbar->Items->Count; i++)
  5861. {
  5862. TTBXCustomDropDownItem * DropDownItem;
  5863. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5864. if (DropDownItem != NULL)
  5865. {
  5866. ToolbarItemResize(DropDownItem,
  5867. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5868. Toolbar->NonClientWidth);
  5869. break;
  5870. }
  5871. }
  5872. }
  5873. //---------------------------------------------------------------------------
  5874. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5875. {
  5876. Item->EditWidth = Width;
  5877. }
  5878. //---------------------------------------------------------------------------
  5879. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5880. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5881. {
  5882. for (int i = 0; i < Toolbar->Items->Count; i++)
  5883. {
  5884. TTBXCustomDropDownItem * DropDownItem;
  5885. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5886. if (DropDownItem != NULL)
  5887. {
  5888. ASize.x -= DropDownItem->EditWidth;
  5889. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5890. }
  5891. }
  5892. }
  5893. //---------------------------------------------------------------------------
  5894. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5895. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5896. {
  5897. if (WinConfiguration->DDWarnLackOfTempSpace)
  5898. {
  5899. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5900. if (!ADrive.IsEmpty())
  5901. {
  5902. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5903. DebugAssert(RequiredSpace >= 0);
  5904. __int64 RequiredWithReserve;
  5905. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5906. if (FreeSpace < RequiredWithReserve)
  5907. {
  5908. unsigned int Result;
  5909. TMessageParams Params(mpNeverAskAgainCheck);
  5910. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5911. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5912. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5913. if (Result == qaNeverAskAgain)
  5914. {
  5915. WinConfiguration->DDWarnLackOfTempSpace = false;
  5916. }
  5917. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5918. }
  5919. }
  5920. }
  5921. }
  5922. //---------------------------------------------------------------------------
  5923. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5924. {
  5925. DoOpenDirectoryDialog(odAddBookmark, Side);
  5926. }
  5927. //---------------------------------------------------------------------------
  5928. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5929. {
  5930. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5931. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5932. try
  5933. {
  5934. TCustomDirView * DView = DirView(Side);
  5935. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5936. {
  5937. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5938. }
  5939. }
  5940. catch (...)
  5941. {
  5942. delete VisitedDirectories;
  5943. throw;
  5944. }
  5945. return VisitedDirectories;
  5946. }
  5947. //---------------------------------------------------------------------------
  5948. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5949. TOpenDirectoryMode Mode, TOperationSide Side)
  5950. {
  5951. bool Continue = true;
  5952. if (Mode == odAddBookmark)
  5953. {
  5954. TMessageParams Params(mpNeverAskAgainCheck);
  5955. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5956. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5957. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5958. unsigned int Answer =
  5959. MessageDialog(Message,
  5960. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5961. if (Answer == qaNeverAskAgain)
  5962. {
  5963. Continue = true;
  5964. WinConfiguration->UseSharedBookmarks = true;
  5965. }
  5966. else if (Answer == qaOK)
  5967. {
  5968. Continue = true;
  5969. WinConfiguration->UseSharedBookmarks = false;
  5970. }
  5971. else
  5972. {
  5973. Continue = false;
  5974. }
  5975. }
  5976. if (Continue)
  5977. {
  5978. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5979. try
  5980. {
  5981. UnicodeString Name = DirView(Side)->PathName;
  5982. bool Repeat;
  5983. do
  5984. {
  5985. Repeat = false;
  5986. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5987. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5988. // do not allow switching to location profiles,
  5989. // if we are not connected
  5990. HasDirView[osLocal] && (Terminal != NULL)))
  5991. {
  5992. TWindowLock Lock(this);
  5993. if (!TryOpenDirectory(Side, Name))
  5994. {
  5995. Repeat = true;
  5996. Mode = odBrowse;
  5997. }
  5998. }
  5999. }
  6000. while (Repeat);
  6001. }
  6002. __finally
  6003. {
  6004. delete VisitedDirectories;
  6005. }
  6006. }
  6007. }
  6008. //---------------------------------------------------------------------------
  6009. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6010. {
  6011. DebugAssert(!Terminal->CommandSessionOpened);
  6012. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6013. }
  6014. //---------------------------------------------------------------------------
  6015. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6016. {
  6017. bool Result = Terminal->IsCapable[Capability] ||
  6018. Terminal->CommandSessionOpened;
  6019. if (!Result)
  6020. {
  6021. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6022. if (!GUIConfiguration->ConfirmCommandSession)
  6023. {
  6024. Result = true;
  6025. }
  6026. else
  6027. {
  6028. TMessageParams Params(mpNeverAskAgainCheck);
  6029. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6030. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6031. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6032. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6033. if (Answer == qaNeverAskAgain)
  6034. {
  6035. GUIConfiguration->ConfirmCommandSession = false;
  6036. Result = true;
  6037. }
  6038. else if (Answer == qaOK)
  6039. {
  6040. Result = true;
  6041. }
  6042. }
  6043. if (Result)
  6044. {
  6045. Result = CommandSessionFallback();
  6046. }
  6047. }
  6048. return Result;
  6049. }
  6050. //---------------------------------------------------------------------------
  6051. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6052. {
  6053. if (EnsureCommandSessionFallback(fcAnyCommand))
  6054. {
  6055. DoConsoleDialog(Terminal, Command);
  6056. }
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6060. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6061. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6062. {
  6063. if (!IsSideLocalBrowser(osRemote) &&
  6064. IsFileControl(DropSourceControl, osRemote) &&
  6065. (FDDExtMapFile != NULL))
  6066. {
  6067. Accept = true;
  6068. }
  6069. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6070. DebugAssert(FDDTargetControl != NULL);
  6071. }
  6072. //---------------------------------------------------------------------------
  6073. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6074. _di_IDataObject DataObj, int KeyState,
  6075. const TPoint & Point, int & Effect, bool & Accept)
  6076. {
  6077. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6078. }
  6079. //---------------------------------------------------------------------------
  6080. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6081. _di_IDataObject DataObj, int KeyState,
  6082. const TPoint & Point, int & Effect, bool & Accept)
  6083. {
  6084. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6085. }
  6086. //---------------------------------------------------------------------------
  6087. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6088. TObject * Sender)
  6089. {
  6090. DebugUsedParam(Sender);
  6091. DebugAssert(FDDTargetControl == Sender);
  6092. FDDTargetControl = NULL;
  6093. }
  6094. //---------------------------------------------------------------------------
  6095. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6096. {
  6097. FileControlDDDragLeave(SessionsPageControl);
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6101. {
  6102. FileControlDDDragLeave(QueueView3);
  6103. }
  6104. //---------------------------------------------------------------------------
  6105. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6106. {
  6107. DebugAssert(!IsSideLocalBrowser(Side));
  6108. DebugUsedParam(Side);
  6109. bool Edit = false;
  6110. TRemoteFile * File = NULL;
  6111. UnicodeString FileName;
  6112. UnicodeString PointTo;
  6113. bool SymbolicLink = true;
  6114. if (RemoteDirView->ItemFocused)
  6115. {
  6116. DebugAssert(RemoteDirView->ItemFocused->Data);
  6117. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6118. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6119. if (Edit)
  6120. {
  6121. FileName = File->FileName;
  6122. PointTo = File->LinkTo;
  6123. }
  6124. else
  6125. {
  6126. PointTo = File->FileName;
  6127. }
  6128. }
  6129. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6130. Terminal->IsCapable[fcHardLink]))
  6131. {
  6132. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6133. if (Edit)
  6134. {
  6135. DebugAssert(File->FileName == FileName);
  6136. int Params = dfNoRecursive;
  6137. Terminal->ExceptionOnFail = true;
  6138. try
  6139. {
  6140. Terminal->DeleteFile(L"", File, &Params);
  6141. }
  6142. __finally
  6143. {
  6144. Terminal->ExceptionOnFail = false;
  6145. }
  6146. }
  6147. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6148. }
  6149. }
  6150. //---------------------------------------------------------------------------
  6151. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6152. {
  6153. return
  6154. (IsSideLocalBrowser(Side) ||
  6155. (HasActiveTerminal() &&
  6156. Terminal->ResolvingSymlinks &&
  6157. Terminal->IsCapable[fcSymbolicLink]));
  6158. }
  6159. //---------------------------------------------------------------------------
  6160. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6161. {
  6162. return
  6163. !IsSideLocalBrowser(FCurrentSide) &&
  6164. (RemoteDirView->ItemFocused != NULL) &&
  6165. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6166. Terminal->SessionData->ResolveSymlinks;
  6167. }
  6168. //---------------------------------------------------------------------------
  6169. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6170. {
  6171. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6172. FForceExecution = true;
  6173. try
  6174. {
  6175. DirView(osCurrent)->ExecuteCurrentFile();
  6176. }
  6177. __finally
  6178. {
  6179. FForceExecution = false;
  6180. }
  6181. }
  6182. //---------------------------------------------------------------------------
  6183. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6184. {
  6185. TEditorData ExternalEditor;
  6186. ExternalEditor.Editor = edExternal;
  6187. bool Remember = false;
  6188. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6189. {
  6190. if (Remember)
  6191. {
  6192. TEditorList * EditorList = new TEditorList;
  6193. try
  6194. {
  6195. *EditorList = *WinConfiguration->EditorList;
  6196. bool Found = false;
  6197. int i = 0;
  6198. while (!Found && (i < EditorList->Count))
  6199. {
  6200. const TEditorPreferences * Editor = EditorList->Editors[i];
  6201. if ((Editor->Data->Editor == edExternal) &&
  6202. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6203. {
  6204. Found = true;
  6205. }
  6206. i++;
  6207. }
  6208. if (!Found)
  6209. {
  6210. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6211. WinConfiguration->EditorList = EditorList;
  6212. }
  6213. }
  6214. __finally
  6215. {
  6216. delete EditorList;
  6217. }
  6218. }
  6219. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6220. }
  6221. }
  6222. //---------------------------------------------------------------------------
  6223. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6224. {
  6225. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6226. if (FFileFindTerminal == ATerminal)
  6227. {
  6228. FFileFindTerminal = NULL;
  6229. HideFileFindDialog();
  6230. }
  6231. if (FClipboardTerminal == ATerminal)
  6232. {
  6233. ClipboardClear(); // implies ClipboardStop
  6234. }
  6235. }
  6236. //---------------------------------------------------------------------------
  6237. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6238. {
  6239. DetachTerminal(Sender);
  6240. }
  6241. //---------------------------------------------------------------------------
  6242. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6243. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6244. {
  6245. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6246. DebugAssert(Terminal != NULL);
  6247. if (Data->Terminal == Terminal)
  6248. {
  6249. Data->Terminal = NULL;
  6250. }
  6251. }
  6252. //---------------------------------------------------------------------------
  6253. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6254. {
  6255. UpdateControls();
  6256. SessionColor = TColor(0);
  6257. UpdateRemotePathComboBox(false);
  6258. NeedSession(false);
  6259. }
  6260. //---------------------------------------------------------------------------
  6261. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6262. {
  6263. try
  6264. {
  6265. // Cache, as the login dialog can change its value.
  6266. // See also DoShow. Also see TTerminalManager::NewSession.
  6267. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6268. try
  6269. {
  6270. if (ShowLogin)
  6271. {
  6272. bool ReloadSessions = !Startup;
  6273. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6274. }
  6275. }
  6276. __finally
  6277. {
  6278. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6279. // (so there was no chance for the user to open any session yet)
  6280. if ((ShowLogin || !Startup) &&
  6281. !WinConfiguration->KeepOpenWhenNoSession &&
  6282. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6283. {
  6284. TerminateApplication();
  6285. }
  6286. }
  6287. }
  6288. catch (EAbort &)
  6289. {
  6290. // swallow
  6291. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6292. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6293. }
  6294. }
  6295. //---------------------------------------------------------------------------
  6296. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6297. {
  6298. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6299. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6300. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6301. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6302. try
  6303. {
  6304. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6305. // Clear the design time unthemed tab
  6306. ((SessionsPageControl->PageCount > 0) &&
  6307. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6308. {
  6309. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6310. }
  6311. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6312. {
  6313. TThemeTabSheet * TabSheet;
  6314. if (Index >= SessionsPageControl->PageCount)
  6315. {
  6316. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6317. TabSheet->PageControl = SessionsPageControl;
  6318. }
  6319. else
  6320. {
  6321. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6322. }
  6323. bool IsSessionTab = (Index < TerminalList->Count);
  6324. if (IsSessionTab)
  6325. {
  6326. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6327. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6328. UpdateSessionTab(TabSheet);
  6329. }
  6330. else
  6331. {
  6332. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6333. TabSheet->Tag = 0; // not really needed
  6334. TabSheet->Shadowed = false;
  6335. // 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)
  6336. UpdateNewSessionTab();
  6337. }
  6338. TabSheet->ShowCloseButton = IsSessionTab;
  6339. }
  6340. }
  6341. __finally
  6342. {
  6343. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6344. }
  6345. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6346. }
  6347. //---------------------------------------------------------------------------
  6348. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6349. {
  6350. DoTerminalListChanged();
  6351. }
  6352. //---------------------------------------------------------------------------
  6353. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6354. {
  6355. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6356. DebugAssert(TabSheet->ImageIndex == 0);
  6357. TabSheet->Caption =
  6358. WinConfiguration->SelectiveToolbarText ?
  6359. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6360. UnicodeString();
  6361. }
  6362. //---------------------------------------------------------------------------
  6363. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6364. {
  6365. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6366. }
  6367. //---------------------------------------------------------------------------
  6368. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6369. {
  6370. if (DebugAlwaysTrue(TabSheet != NULL))
  6371. {
  6372. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6373. if (DebugAlwaysTrue(ATerminal != NULL))
  6374. {
  6375. TColor Color = (ATerminal == Terminal) ? FSessionColor : ATerminal->StateData->Color;
  6376. TabSheet->ImageIndex = AddSessionColor(Color);
  6377. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6378. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6379. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6380. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6381. {
  6382. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6383. }
  6384. }
  6385. }
  6386. }
  6387. //---------------------------------------------------------------------------
  6388. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6389. {
  6390. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6391. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6392. bool Result = (Terminal != NULL);
  6393. if (Result)
  6394. {
  6395. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6396. }
  6397. else
  6398. {
  6399. try
  6400. {
  6401. NewSession();
  6402. }
  6403. __finally
  6404. {
  6405. DoTerminalListChanged();
  6406. }
  6407. FSessionsPageControlNewSessionTime = Now();
  6408. }
  6409. return Result;
  6410. }
  6411. //---------------------------------------------------------------------------
  6412. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6413. {
  6414. SessionTabSwitched();
  6415. }
  6416. //---------------------------------------------------------------------------
  6417. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6418. {
  6419. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6420. DebugAssert(TransferList != NULL);
  6421. UnicodeString Name;
  6422. if (TransferList->ItemIndex <= 0)
  6423. {
  6424. Name = L"";
  6425. }
  6426. else
  6427. {
  6428. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6429. }
  6430. if (FCopyParamAutoSelected.IsEmpty())
  6431. {
  6432. // if previous preset was not autoselected, make new preset the "default"
  6433. FCopyParamDefault = Name;
  6434. }
  6435. GUIConfiguration->CopyParamCurrent = Name;
  6436. }
  6437. //---------------------------------------------------------------------------
  6438. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6439. {
  6440. // sanity check
  6441. bool ExistingPreset =
  6442. (FTransferListHoverIndex >= 0) &&
  6443. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6444. DebugAssert(ExistingPreset);
  6445. if (ExistingPreset)
  6446. {
  6447. HDC DC = GetDC(0);
  6448. TCanvas * Canvas = new TCanvas();
  6449. try
  6450. {
  6451. Canvas->Handle = DC;
  6452. Canvas->Font = GetToolbarFont(this);
  6453. UnicodeString Name;
  6454. if (FTransferListHoverIndex == 0)
  6455. {
  6456. Name = L"";
  6457. }
  6458. else
  6459. {
  6460. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6461. }
  6462. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6463. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6464. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6465. static_cast<TObject*>(GetComponent(fcTransferList)));
  6466. UnicodeString InfoStr =
  6467. GUIConfiguration->CopyParamPreset[Name].
  6468. GetInfoStr(L"; ",
  6469. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6470. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6471. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6472. {
  6473. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6474. {
  6475. InfoStr.SetLength(InfoStr.Length() - 1);
  6476. }
  6477. InfoStr += Ellipsis;
  6478. }
  6479. // UpdateCaption does not cause invalidation of whole submenu, while
  6480. // setting Caption property does.
  6481. // also it probably does not resize the label, even if necessary
  6482. // (we do not want that anyway)
  6483. TransferLabel->UpdateCaption(InfoStr);
  6484. }
  6485. __finally
  6486. {
  6487. Canvas->Handle = NULL;
  6488. ReleaseDC(0, DC);
  6489. delete Canvas;
  6490. }
  6491. }
  6492. }
  6493. //---------------------------------------------------------------------------
  6494. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6495. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6496. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6497. {
  6498. if (FTransferListHoverIndex != AHoverIndex)
  6499. {
  6500. FTransferListHoverIndex = AHoverIndex;
  6501. UpdateTransferLabel();
  6502. }
  6503. }
  6504. //---------------------------------------------------------------------------
  6505. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6506. {
  6507. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6508. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6509. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6510. {
  6511. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6512. {
  6513. if (!NonVisualDataModule->Busy)
  6514. {
  6515. OpenDirectory(GetSide(osCurrent));
  6516. }
  6517. Message.Result = 1;
  6518. }
  6519. else
  6520. {
  6521. TForm::Dispatch(&Message);
  6522. }
  6523. }
  6524. else
  6525. {
  6526. TForm::Dispatch(&Message);
  6527. }
  6528. }
  6529. //---------------------------------------------------------------------------
  6530. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6531. {
  6532. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6533. if ((FIgnoreNextDialogChar != 0) &&
  6534. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6535. {
  6536. Message.Result = 1;
  6537. }
  6538. else
  6539. {
  6540. TForm::Dispatch(&Message);
  6541. }
  6542. FIgnoreNextDialogChar = 0;
  6543. }
  6544. //---------------------------------------------------------------------------
  6545. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6546. {
  6547. // The four low-order bits are used internally by Windows
  6548. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6549. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6550. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6551. // 61730 - restore thru double click - undocumented
  6552. // 61490 - maximize thru double click - undocumented
  6553. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6554. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6555. {
  6556. SysResizing(Cmd);
  6557. }
  6558. TForm::Dispatch(&Message);
  6559. }
  6560. //---------------------------------------------------------------------------
  6561. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6562. {
  6563. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6564. // Also there no point returning TRUE as we are not able to
  6565. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6566. // Hence the process termination might be safer :)
  6567. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6568. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6569. {
  6570. Message.Result = FALSE;
  6571. }
  6572. else
  6573. {
  6574. Message.Result = TRUE;
  6575. }
  6576. // Do not call default handling as that triggers OnCloseQuery,
  6577. // where our implementation will popup confirmation dialogs, what we do not want,
  6578. // as per Vista guidelines:
  6579. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6580. }
  6581. //---------------------------------------------------------------------------
  6582. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6583. {
  6584. if (Message.EndSession && IsApplicationMinimized())
  6585. {
  6586. // WORKAROUND
  6587. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6588. // when it receives WM_ENDSESSION,
  6589. // but that sometimes (particularly when application is minimized) cause crashes.
  6590. // Crash popups message that blocks log off.
  6591. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6592. // so we call ExitProcess() immediately, not even trying to cleanup.
  6593. // It still causes beep, so there's likely some popup, but it does not block
  6594. // log off.
  6595. ExitProcess(0);
  6596. }
  6597. TForm::Dispatch(&Message);
  6598. }
  6599. #ifdef _DEBUG
  6600. //---------------------------------------------------------------------------
  6601. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6602. {
  6603. TForm::Dispatch(&Message);
  6604. }
  6605. #endif
  6606. //---------------------------------------------------------------------------
  6607. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6608. {
  6609. }
  6610. //---------------------------------------------------------------------------
  6611. void __fastcall TCustomScpExplorerForm::DoShow()
  6612. {
  6613. // only now are the controls resized finally, so the size constraints
  6614. // will not conflict with possibly very small window size
  6615. RestoreFormParams();
  6616. // This indicates that the form was rescaled after parameters were loaded and
  6617. // as most probably the parameters were actually saved with the current form scaling
  6618. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6619. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6620. // and no rounding problems will occur.
  6621. // See also RestoreForm.
  6622. // (we should be safe to call RestoreParams unconditionally)
  6623. if (PixelsPerInch != Screen->PixelsPerInch)
  6624. {
  6625. RestoreParams();
  6626. }
  6627. FixControlsPlacement();
  6628. if (Position == poDefaultPosOnly)
  6629. {
  6630. CutFormToDesktop(this);
  6631. }
  6632. TForm::DoShow();
  6633. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6634. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6635. // This was previously in NeedSession, where other related code is.
  6636. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6637. // unpleasanly shows briefly.
  6638. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6639. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6640. // This detects if workspace was saved the last time the main widow was closed
  6641. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6642. {
  6643. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6644. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6645. }
  6646. if (Terminal == NULL)
  6647. {
  6648. StartingDisconnected();
  6649. }
  6650. UpdatePixelsPerInchMainWindowCounter();
  6651. FShowing = true;
  6652. }
  6653. //---------------------------------------------------------------------------
  6654. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6655. {
  6656. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6657. }
  6658. //---------------------------------------------------------------------------
  6659. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6660. {
  6661. DoTerminalListChanged();
  6662. InitStatusBar();
  6663. UpdateControls();
  6664. }
  6665. //---------------------------------------------------------------------------
  6666. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6667. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6668. TNotifyEvent OnBalloonClick, TObject * UserData)
  6669. {
  6670. bool Do;
  6671. UnicodeString Message;
  6672. if (E == NULL)
  6673. {
  6674. Message = Str;
  6675. Do = true;
  6676. }
  6677. else
  6678. {
  6679. Do = ExceptionMessage(E, Message);
  6680. }
  6681. if (Do && WinConfiguration->BalloonNotifications)
  6682. {
  6683. UnicodeString Title;
  6684. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6685. {
  6686. Message = TrimLeft(Message);
  6687. }
  6688. else
  6689. {
  6690. Message = UnformatMessage(Message);
  6691. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6692. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6693. Title = LoadResourceString(Captions[Type]);
  6694. if (Terminal != NULL)
  6695. {
  6696. Title = FORMAT(L"%s - %s",
  6697. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6698. }
  6699. }
  6700. if (Seconds == 0)
  6701. {
  6702. Seconds = WinConfiguration->NotificationsTimeout;
  6703. }
  6704. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6705. }
  6706. }
  6707. //---------------------------------------------------------------------------
  6708. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6709. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6710. UnicodeString HelpKeyword, const TMessageParams * Params,
  6711. TTerminal * Terminal)
  6712. {
  6713. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6714. (FOnFeedSynchronizeError != NULL)) &&
  6715. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6716. {
  6717. if (FOnFeedSynchronizeError != NULL)
  6718. {
  6719. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6720. }
  6721. else
  6722. {
  6723. DebugAssert(FErrorList != NULL);
  6724. TStringList * MoreMessagesCopy = NULL;
  6725. if (MoreMessages)
  6726. {
  6727. MoreMessagesCopy = new TStringList();
  6728. MoreMessagesCopy->Assign(MoreMessages);
  6729. }
  6730. FErrorList->AddObject(Message, MoreMessagesCopy);
  6731. }
  6732. PopupTrayBalloon(Terminal, Message, Type);
  6733. return ContinueAnswer(Answers);
  6734. }
  6735. else
  6736. {
  6737. bool UseBalloon = FTrayIcon->Visible;
  6738. if (UseBalloon)
  6739. {
  6740. PopupTrayBalloon(Terminal, Message, Type);
  6741. }
  6742. unsigned int Result;
  6743. try
  6744. {
  6745. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6746. }
  6747. __finally
  6748. {
  6749. // cancel only balloon we popped up, otherwise we may cancel notification
  6750. // balloon that was there before the message dialog
  6751. // (such as "dd confirmation opt in balloon)
  6752. if (UseBalloon)
  6753. {
  6754. FTrayIcon->CancelBalloon();
  6755. }
  6756. }
  6757. return Result;
  6758. }
  6759. }
  6760. //---------------------------------------------------------------------------
  6761. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6762. TTerminal * Terminal, Exception * E)
  6763. {
  6764. if (FTrayIcon->Visible)
  6765. {
  6766. PopupTrayBalloon(Terminal, L"", qtError, E);
  6767. }
  6768. // particularly prevent opening new session from jump list,
  6769. // while exception is shown
  6770. NonVisualDataModule->StartBusy();
  6771. try
  6772. {
  6773. ShowExtendedExceptionEx(Terminal, E);
  6774. }
  6775. __finally
  6776. {
  6777. NonVisualDataModule->EndBusy();
  6778. FTrayIcon->CancelBalloon();
  6779. }
  6780. }
  6781. //---------------------------------------------------------------------------
  6782. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6783. {
  6784. if (Terminal->Active)
  6785. {
  6786. InitStatusBar();
  6787. }
  6788. // cannot rely on active page being page for active terminal,
  6789. // as it can happen that active page is the "new session" page
  6790. // (e.g. when reconnecting active terminal, while login dialog
  6791. // invoked from "new session" page is modal)
  6792. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6793. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6794. }
  6795. //---------------------------------------------------------------------------
  6796. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6797. TTerminal * Terminal, Exception * E)
  6798. {
  6799. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6800. if (!Terminal->Active)
  6801. {
  6802. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6803. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6804. {
  6805. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6806. }
  6807. }
  6808. }
  6809. //---------------------------------------------------------------------------
  6810. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6811. UnicodeString Message, TQueryType Type,
  6812. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6813. {
  6814. if ((E == NULL) ||
  6815. ExceptionMessage(E, Message))
  6816. {
  6817. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6818. if (Important)
  6819. {
  6820. Seconds *= 5;
  6821. }
  6822. UnicodeString NoteMessage(UnformatMessage(Message));
  6823. if (Terminal != NULL)
  6824. {
  6825. NoteMessage = FORMAT(L"%s: %s",
  6826. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6827. }
  6828. if (WinConfiguration->BalloonNotifications)
  6829. {
  6830. AddNote(NoteMessage);
  6831. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6832. }
  6833. else
  6834. {
  6835. FlashOnBackground();
  6836. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6837. }
  6838. }
  6839. }
  6840. //---------------------------------------------------------------------------
  6841. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6842. {
  6843. RestoreApp();
  6844. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6845. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6846. !NonVisualDataModule->Busy)
  6847. {
  6848. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6849. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6850. if (!ComponentVisible[fcQueueView])
  6851. {
  6852. ToggleQueueVisibility();
  6853. GoToQueue();
  6854. }
  6855. }
  6856. }
  6857. //---------------------------------------------------------------------------
  6858. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6859. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6860. {
  6861. UnicodeString Message;
  6862. TNotifyEvent OnClick = NULL;
  6863. TObject * UserData = NULL;
  6864. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6865. switch (Event)
  6866. {
  6867. case qeEmptyButMonitored:
  6868. if ((ATerminal != Terminal) || QueueInvisible)
  6869. {
  6870. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6871. OnClick = QueueEmptyNoteClicked;
  6872. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6873. TerminalNoteData->Terminal = ATerminal;
  6874. UserData = TerminalNoteData;
  6875. }
  6876. break;
  6877. case qeEmpty:
  6878. OperationComplete(ATerminal->QueueOperationStart);
  6879. break;
  6880. case qePendingUserAction:
  6881. if ((ATerminal != Terminal) ||
  6882. (QueueInvisible && !IsQueueAutoPopup()))
  6883. {
  6884. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6885. }
  6886. break;
  6887. default:
  6888. DebugFail();
  6889. }
  6890. if (!Message.IsEmpty())
  6891. {
  6892. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6893. }
  6894. }
  6895. //---------------------------------------------------------------------------
  6896. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6897. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6898. {
  6899. if (FDDExtMapFile != NULL)
  6900. {
  6901. CloseHandle(FDDExtMapFile);
  6902. FDDExtMapFile = NULL;
  6903. }
  6904. if (WinConfiguration->DDFakeFile)
  6905. {
  6906. DDFakeFileInitDrag(FileList, Created);
  6907. }
  6908. }
  6909. //---------------------------------------------------------------------------
  6910. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6911. {
  6912. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6913. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6914. {
  6915. FFakeFileDropTarget = FileName;
  6916. }
  6917. }
  6918. //---------------------------------------------------------------------------
  6919. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6920. {
  6921. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6922. if (!ForceDirectories(ApiPath(Result)))
  6923. {
  6924. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6925. }
  6926. FileSetAttr(ApiPath(Result), faHidden);
  6927. return Result;
  6928. }
  6929. //---------------------------------------------------------------------------
  6930. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6931. bool & Created)
  6932. {
  6933. FFakeFileDropTarget = UnicodeString();
  6934. FDragFakeDirectory = CreateFakeTransferDirectory();
  6935. FileList->AddItem(NULL, FDragFakeDirectory);
  6936. Created = true;
  6937. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6938. {
  6939. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6940. }
  6941. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6942. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6943. {
  6944. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6945. TDragExtCommStruct* CommStruct;
  6946. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6947. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6948. DebugAssert(CommStruct != NULL);
  6949. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6950. CommStruct->Dragging = true;
  6951. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6952. LENOF(CommStruct->DropDest));
  6953. NULL_TERMINATE(CommStruct->DropDest);
  6954. UnmapViewOfFile(CommStruct);
  6955. }
  6956. }
  6957. //---------------------------------------------------------------------------
  6958. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6959. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6960. {
  6961. bool Result;
  6962. DebugAssert(!IsLocalBrowserMode());
  6963. if (Sender == RemoteDirView)
  6964. {
  6965. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6966. }
  6967. else
  6968. {
  6969. DebugAssert(Sender == RemoteDriveView);
  6970. TStrings * FileList = RemoteDriveView->DragFileList();
  6971. try
  6972. {
  6973. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6974. }
  6975. __finally
  6976. {
  6977. delete FileList;
  6978. }
  6979. }
  6980. if (FDDTargetControl == RemoteDriveView)
  6981. {
  6982. RemoteDriveView->UpdateDropTarget();
  6983. }
  6984. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6985. // or from tree view to dir view.
  6986. // foMove happens when file/dir is dragged from remote tree view outside of
  6987. // application via dragex
  6988. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6989. (DropSourceControl == RemoteDriveView))
  6990. {
  6991. RemoteDriveView->UpdateDropSource();
  6992. }
  6993. return Result;
  6994. }
  6995. //---------------------------------------------------------------------------
  6996. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6997. {
  6998. DebugAssert(!IsLocalBrowserMode());
  6999. // This also handles drops of remote files to queue.
  7000. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7001. SAFE_DESTROY(FDDFileList);
  7002. if (!FFakeFileDropTarget.IsEmpty())
  7003. {
  7004. RemoveDir(ApiPath(FFakeFileDropTarget));
  7005. }
  7006. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7007. {
  7008. try
  7009. {
  7010. TDragResult DDResult = (Sender == RemoteDirView) ?
  7011. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7012. // Focus is moved to the target application,
  7013. // but as we are going to present the UI, we need to steal the focus back.
  7014. // This most likely won't work though (windows does not allow application
  7015. // to steal focus most of the time)
  7016. Application->BringToFront();
  7017. // On older version of Windows we never got drMove here, see also comment below.
  7018. // On Windows 10, we get the "move".
  7019. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7020. {
  7021. UnicodeString TargetDirectory;
  7022. TFileOperation Operation;
  7023. // drInvalid may mean drMove, see comment below
  7024. switch (DDResult)
  7025. {
  7026. case drCopy:
  7027. Operation = foCopy;
  7028. break;
  7029. case drMove:
  7030. Operation = foMove;
  7031. break;
  7032. default:
  7033. DebugFail();
  7034. case drInvalid:
  7035. // prefer "copy" for safety
  7036. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7037. break;
  7038. }
  7039. TTransferOperationParam Param;
  7040. UnicodeString CounterName;
  7041. bool ForceQueue;
  7042. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7043. {
  7044. // we get drInvalid both if d&d was intercepted by ddext,
  7045. // and when users drops on no-drop location.
  7046. // we tell the difference by existence of response from ddext,
  7047. // so we ignore absence of response in this case
  7048. if (DDResult != drInvalid)
  7049. {
  7050. // here we know that the extension is installed,
  7051. // as it is checked as soon as drag&drop starts from
  7052. // RemoteFileControlDDCreateDragFileList
  7053. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7054. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7055. {
  7056. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7057. }
  7058. else
  7059. {
  7060. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7061. }
  7062. }
  7063. }
  7064. else
  7065. {
  7066. // download using fake file
  7067. Param.Temp = false;
  7068. Param.DragDrop = true;
  7069. if (ForceQueue)
  7070. {
  7071. Param.Queue = asOn;
  7072. }
  7073. if (Sender == RemoteDirView)
  7074. {
  7075. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7076. }
  7077. if (RemoteFileControlFileOperation(Sender, Operation,
  7078. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7079. {
  7080. Configuration->Usage->Inc(CounterName);
  7081. }
  7082. }
  7083. }
  7084. }
  7085. __finally
  7086. {
  7087. CloseHandle(FDDExtMapFile);
  7088. FDDExtMapFile = NULL;
  7089. delete FDragFakeMonitors;
  7090. FDragFakeMonitors = NULL;
  7091. RemoveDir(ApiPath(FDragFakeDirectory));
  7092. FDragFakeDirectory = L"";
  7093. FFakeFileDropTarget = UnicodeString();
  7094. }
  7095. }
  7096. if (FDragDropSshTerminate.get() != NULL)
  7097. {
  7098. FDragDropSshTerminate->Rethrow();
  7099. }
  7100. }
  7101. //---------------------------------------------------------------------------
  7102. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7103. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7104. {
  7105. // Remember drop effect so we know (when user drops files), if we copy or move
  7106. FLastDropEffect = dwEffect;
  7107. }
  7108. //---------------------------------------------------------------------------
  7109. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7110. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7111. {
  7112. bool Result;
  7113. if (FDDTargetControl == QueueView3)
  7114. {
  7115. Directory = DefaultDownloadTargetDirectory();
  7116. Result = true;
  7117. CounterName = L"DownloadsDragDropQueue";
  7118. ForceQueue = true;
  7119. }
  7120. else if (!FFakeFileDropTarget.IsEmpty())
  7121. {
  7122. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7123. Result = true;
  7124. ForceQueue = false;
  7125. CounterName = L"DownloadsDragDropFakeFile";
  7126. }
  7127. else
  7128. {
  7129. ForceQueue = false;
  7130. Enabled = false;
  7131. try
  7132. {
  7133. int Timer = 0;
  7134. Result = false;
  7135. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7136. {
  7137. {
  7138. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7139. TDragExtCommStruct* CommStruct;
  7140. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7141. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7142. DebugAssert(CommStruct != NULL);
  7143. Result = !CommStruct->Dragging;
  7144. if (Result)
  7145. {
  7146. Directory = ExtractFilePath(CommStruct->DropDest);
  7147. CounterName = L"DownloadsDragDropExternalExt";
  7148. }
  7149. UnmapViewOfFile(CommStruct);
  7150. }
  7151. if (!Result)
  7152. {
  7153. Sleep(50);
  7154. Timer += 50;
  7155. Application->ProcessMessages();
  7156. }
  7157. }
  7158. }
  7159. __finally
  7160. {
  7161. Enabled = true;
  7162. }
  7163. }
  7164. return Result;
  7165. }
  7166. //---------------------------------------------------------------------------
  7167. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7168. const UnicodeString TempDir, int SecDelay)
  7169. {
  7170. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7171. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7172. if (FDelayedDeletionTimer == NULL)
  7173. {
  7174. DebugAssert(HandleAllocated());
  7175. FDelayedDeletionTimer = new TTimer(this);
  7176. FDelayedDeletionTimer->Interval = 10000;
  7177. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7178. }
  7179. else
  7180. {
  7181. FDelayedDeletionTimer->Enabled = true;
  7182. }
  7183. }
  7184. //---------------------------------------------------------------------------
  7185. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7186. {
  7187. DebugAssert(FDelayedDeletionList != NULL);
  7188. TDateTime N = Now();
  7189. TDateTime Alert;
  7190. UnicodeString Directory;
  7191. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7192. {
  7193. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7194. if ((N >= Alert) || (Sender == NULL))
  7195. {
  7196. Directory = FDelayedDeletionList->Strings[Index];
  7197. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7198. {
  7199. FDelayedDeletionList->Delete(Index);
  7200. }
  7201. }
  7202. }
  7203. if (FDelayedDeletionList->Count == 0)
  7204. {
  7205. FDelayedDeletionTimer->Enabled = false;
  7206. }
  7207. }
  7208. //---------------------------------------------------------------------------
  7209. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7210. {
  7211. DebugAssert(!IsLocalBrowserMode());
  7212. if (IsFileControl(FDDTargetControl, osRemote) ||
  7213. (FDDTargetControl == SessionsPageControl))
  7214. {
  7215. TTerminal * TargetTerminal = NULL;
  7216. TFileOperation Operation = foNone;
  7217. if (FDDTargetControl == SessionsPageControl)
  7218. {
  7219. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7220. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7221. // do not allow dropping on the "+" tab
  7222. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7223. if (TargetTerminal != NULL)
  7224. {
  7225. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7226. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7227. {
  7228. Operation = foRemoteMove;
  7229. }
  7230. else
  7231. {
  7232. Operation = foRemoteCopy;
  7233. }
  7234. }
  7235. }
  7236. else
  7237. {
  7238. if (FLastDropEffect == DROPEFFECT_MOVE)
  7239. {
  7240. Operation = foRemoteMove;
  7241. }
  7242. else if (FLastDropEffect == DROPEFFECT_COPY)
  7243. {
  7244. Operation = foRemoteCopy;
  7245. }
  7246. }
  7247. if (Operation != foNone)
  7248. {
  7249. RemoteFileControlFileOperation(DropSourceControl,
  7250. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7251. }
  7252. // abort drag&drop
  7253. Abort();
  7254. }
  7255. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7256. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7257. (FDDTargetControl != QueueView3))
  7258. {
  7259. DebugAssert(!FDragTempDir.IsEmpty());
  7260. TTransferType Type;
  7261. UnicodeString TempDir = FDragTempDir;
  7262. // We clear FDragTempDir before calling
  7263. // just in case it fail (raises exception)
  7264. FDragTempDir = L"";
  7265. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7266. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7267. // empty directory parameter means temp directory -> don't display it!
  7268. UnicodeString TargetDir = L"";
  7269. int Options = 0;
  7270. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7271. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7272. {
  7273. Abort();
  7274. }
  7275. // TargetDir is set when dropped on local file control
  7276. // (this was workaround for legacy dirview event handling, now it should be
  7277. // made prettier)
  7278. if (TargetDir.IsEmpty())
  7279. {
  7280. TargetDir = TempDir;
  7281. if (ForceDirectories(ApiPath(TargetDir)))
  7282. {
  7283. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7284. FPendingTempSpaceWarn = true;
  7285. try
  7286. {
  7287. FDragDropOperation = true;
  7288. int Params = cpTemporary |
  7289. (Type == ttMove ? cpDelete : 0);
  7290. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7291. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7292. }
  7293. __finally
  7294. {
  7295. FDragDropOperation = false;
  7296. FPendingTempSpaceWarn = false;
  7297. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7298. }
  7299. }
  7300. else
  7301. {
  7302. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7303. }
  7304. }
  7305. }
  7306. }
  7307. //---------------------------------------------------------------------------
  7308. void __fastcall TCustomScpExplorerForm::DDDownload(
  7309. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7310. {
  7311. DebugAssert(!IsLocalBrowserMode());
  7312. TAutoBatch AutoBatch(this);
  7313. UpdateCopyParamCounters(*CopyParam);
  7314. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7315. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7316. {
  7317. RemoteDriveView->UpdateDropSource();
  7318. }
  7319. }
  7320. //---------------------------------------------------------------------------
  7321. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7322. {
  7323. public:
  7324. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7325. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7326. {
  7327. }
  7328. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7329. {
  7330. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7331. TDataObjectFilesEx::AllowData(FormatEtc);
  7332. }
  7333. };
  7334. //---------------------------------------------------------------------------
  7335. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7336. TObject * Sender, TDataObject *& DataObject)
  7337. {
  7338. if (FDDExtMapFile != NULL)
  7339. {
  7340. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7341. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7342. {
  7343. Abort();
  7344. }
  7345. if (FileList->Count > 0)
  7346. {
  7347. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7348. if (!FilesObject->IsValid(true, true))
  7349. {
  7350. FilesObject->_Release();
  7351. }
  7352. else
  7353. {
  7354. DataObject = FilesObject;
  7355. }
  7356. }
  7357. }
  7358. }
  7359. //---------------------------------------------------------------------------
  7360. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7361. {
  7362. DebugFail();
  7363. }
  7364. //---------------------------------------------------------------------------
  7365. void __fastcall TCustomScpExplorerForm::GoToTree()
  7366. {
  7367. ComponentVisible[fcRemoteTree] = true;
  7368. DriveView(osRemote)->SetFocus();
  7369. }
  7370. //---------------------------------------------------------------------------
  7371. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7372. TPanelExport Export)
  7373. {
  7374. TCustomDirView * DirView = this->DirView(Side);
  7375. std::unique_ptr<TStrings> ExportData(new TStringList());
  7376. switch (Export)
  7377. {
  7378. case pePath:
  7379. ExportData->Add(DirView->PathName);
  7380. break;
  7381. case peFileList:
  7382. case peFullFileList:
  7383. {
  7384. bool FullPath = (Export == peFullFileList);
  7385. DirView->CreateFileList(false, FullPath, ExportData.get());
  7386. for (int Index = 0; Index < ExportData->Count; Index++)
  7387. {
  7388. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7389. {
  7390. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7391. }
  7392. }
  7393. }
  7394. break;
  7395. default:
  7396. DebugFail();
  7397. }
  7398. return ExportData.release();
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7402. TPanelExport Export, TPanelExportDestination Destination)
  7403. {
  7404. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7405. PanelExportStore(Side, Export, Destination, ExportData.get());
  7406. }
  7407. //---------------------------------------------------------------------------
  7408. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7409. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7410. TStrings * ExportData)
  7411. {
  7412. if (Destination == pedClipboard)
  7413. {
  7414. TInstantOperationVisualizer Visualizer;
  7415. CopyToClipboard(ExportData);
  7416. }
  7417. else
  7418. {
  7419. DebugFail();
  7420. }
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7424. {
  7425. TCustomDirView * DirView = this->DirView(Side);
  7426. UnicodeString Mask = DirView->Mask;
  7427. if (DoFilterMaskDialog(DirView, Mask))
  7428. {
  7429. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7430. Configuration->Usage->Inc(L"Filters");
  7431. }
  7432. }
  7433. //---------------------------------------------------------------------------
  7434. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7435. {
  7436. return FQueueController->DefaultOperation();
  7437. }
  7438. //---------------------------------------------------------------------------
  7439. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7440. TQueueOperation Operation, void ** Param)
  7441. {
  7442. switch (Operation)
  7443. {
  7444. case qoPreferences:
  7445. return true;
  7446. case qoGoTo:
  7447. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7448. case qoOnceEmpty:
  7449. return IsAnythingQueued();
  7450. default:
  7451. return FQueueController->AllowOperation(Operation, Param);
  7452. }
  7453. }
  7454. //---------------------------------------------------------------------------
  7455. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7456. {
  7457. if (DebugAlwaysTrue(QueueView3->Visible))
  7458. {
  7459. QueueView3->SetFocus();
  7460. }
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7464. TQueueOperation Operation, void * Param)
  7465. {
  7466. if (Operation == qoGoTo)
  7467. {
  7468. GoToQueue();
  7469. }
  7470. else if (Operation == qoPreferences)
  7471. {
  7472. PreferencesDialog(pmQueue);
  7473. }
  7474. else
  7475. {
  7476. FQueueController->ExecuteOperation(Operation, Param);
  7477. }
  7478. }
  7479. //---------------------------------------------------------------------------
  7480. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7481. {
  7482. return (Queue != NULL) && Queue->Enabled;
  7483. }
  7484. //---------------------------------------------------------------------------
  7485. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7486. {
  7487. DebugAssert(Queue != NULL);
  7488. if (Queue != NULL)
  7489. {
  7490. Queue->Enabled = !Queue->Enabled;
  7491. }
  7492. }
  7493. //---------------------------------------------------------------------------
  7494. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7495. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7496. {
  7497. FQueueActedItem = QueueView3->ItemFocused;
  7498. }
  7499. //---------------------------------------------------------------------------
  7500. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7501. {
  7502. return TopDock->Height + QueueSplitter->Height;
  7503. }
  7504. //---------------------------------------------------------------------------
  7505. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7506. {
  7507. return
  7508. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7509. (QueueDock->Visible ? QueueDock->Height : 0) +
  7510. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7511. }
  7512. //---------------------------------------------------------------------------
  7513. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7514. {
  7515. return ScaleByTextHeight(this, 48);
  7516. }
  7517. //---------------------------------------------------------------------------
  7518. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7519. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7520. {
  7521. // when queue is hidden by double-clicking splitter, stray attempt to
  7522. // resize the panel with strange value arrives, make sure it is ignored
  7523. if (ComponentVisible[fcQueueView])
  7524. {
  7525. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7526. if (NewSize > MaxHeightLimit)
  7527. {
  7528. NewSize = MaxHeightLimit;
  7529. }
  7530. int MinHeightLimit =
  7531. GetStaticQueuePanelComponentsHeight() +
  7532. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7533. GetMinQueueViewHeight();
  7534. if (NewSize < MinHeightLimit)
  7535. {
  7536. NewSize = MinHeightLimit;
  7537. }
  7538. }
  7539. else
  7540. {
  7541. Accept = false;
  7542. }
  7543. }
  7544. //---------------------------------------------------------------------------
  7545. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7546. {
  7547. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7548. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7549. if (QueueViewHeight < GetMinQueueViewHeight())
  7550. {
  7551. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7552. }
  7553. }
  7554. //---------------------------------------------------------------------------
  7555. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7556. TDragObject *& /*DragObject*/)
  7557. {
  7558. FQueueActedItem = QueueView3->ItemFocused;
  7559. }
  7560. //---------------------------------------------------------------------------
  7561. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7562. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7563. {
  7564. Accept = true;
  7565. if (Source == QueueView3)
  7566. {
  7567. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7568. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7569. if (Accept)
  7570. {
  7571. TQueueItemProxy * QueueItem;
  7572. TQueueItemProxy * DestQueueItem;
  7573. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7574. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7575. Accept = (QueueItem != DestQueueItem) &&
  7576. (QueueItem->Status == TQueueItem::qsPending) &&
  7577. (DestQueueItem->Status == TQueueItem::qsPending);
  7578. }
  7579. }
  7580. }
  7581. //---------------------------------------------------------------------------
  7582. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7583. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7584. {
  7585. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7586. {
  7587. TQueueItemProxy * QueueItem;
  7588. TQueueItemProxy * DestQueueItem;
  7589. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7590. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7591. QueueItem->Move(DestQueueItem);
  7592. }
  7593. }
  7594. //---------------------------------------------------------------------------
  7595. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7596. {
  7597. if ((QueueView3->ItemFocused == NULL) &&
  7598. (QueueView3->Items->Count > 0))
  7599. {
  7600. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7601. }
  7602. QueueLabelUpdateStatus();
  7603. }
  7604. //---------------------------------------------------------------------------
  7605. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7606. {
  7607. QueueLabelUpdateStatus();
  7608. }
  7609. //---------------------------------------------------------------------------
  7610. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7611. {
  7612. QueueLabel->UpdateStatus();
  7613. }
  7614. //---------------------------------------------------------------------------
  7615. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7616. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7617. {
  7618. if (Selected)
  7619. {
  7620. NonVisualDataModule->UpdateNonVisibleActions();
  7621. }
  7622. }
  7623. //---------------------------------------------------------------------------
  7624. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7625. {
  7626. TDragDropFilesEx * Result = NULL;
  7627. if (Sender == SessionsPageControl)
  7628. {
  7629. Result = FSessionsDragDropFilesEx;
  7630. }
  7631. else if (Sender == QueueView3)
  7632. {
  7633. Result = FQueueDragDropFilesEx;
  7634. }
  7635. else
  7636. {
  7637. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7638. if (DirView != NULL)
  7639. {
  7640. Result = DirView->DragDropFilesEx;
  7641. }
  7642. else
  7643. {
  7644. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7645. if (DriveView != NULL)
  7646. {
  7647. Result = DriveView->DragDropFilesEx;
  7648. }
  7649. }
  7650. }
  7651. DebugAssert(Result != NULL);
  7652. return Result;
  7653. }
  7654. //---------------------------------------------------------------------------
  7655. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7656. {
  7657. return (DView->SelCount == DView->FilesCount);
  7658. }
  7659. //---------------------------------------------------------------------------
  7660. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7661. {
  7662. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7663. }
  7664. //---------------------------------------------------------------------------
  7665. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7666. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7667. {
  7668. DebugAssert(!IsLocalBrowserMode());
  7669. TFileOperation Operation;
  7670. switch (Effect)
  7671. {
  7672. case DROPEFFECT_MOVE:
  7673. Operation = foMove;
  7674. break;
  7675. case DROPEFFECT_COPY:
  7676. // occures on WinXP (reported by user)
  7677. default:
  7678. Operation = foCopy;
  7679. break;
  7680. };
  7681. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7682. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7683. if (DragDropFilesEx->FileList->Count > 0)
  7684. {
  7685. TStrings * FileList = new TStringList();
  7686. try
  7687. {
  7688. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7689. {
  7690. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7691. }
  7692. FDragDropOperation = true;
  7693. TTransferOperationParam Param;
  7694. Param.TargetDirectory = TargetPath;
  7695. // upload, no temp dirs
  7696. Param.Temp = false;
  7697. Param.DragDrop = DragDrop;
  7698. Param.Options =
  7699. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7700. if (ForceQueue)
  7701. {
  7702. Param.Queue = asOn;
  7703. }
  7704. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7705. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7706. {
  7707. if (IsFileControl(DropSourceControl, osLocal))
  7708. {
  7709. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7710. }
  7711. else
  7712. {
  7713. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7714. }
  7715. }
  7716. }
  7717. __finally
  7718. {
  7719. FDragDropOperation = false;
  7720. delete FileList;
  7721. }
  7722. }
  7723. }
  7724. //---------------------------------------------------------------------------
  7725. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7726. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7727. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7728. {
  7729. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7730. }
  7731. //---------------------------------------------------------------------------
  7732. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7733. TObject * Sender, int grfKeyState, int & dwEffect)
  7734. {
  7735. DebugAssert(!IsLocalBrowserMode());
  7736. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7737. if ((dwEffect != DROPEFFECT_NONE) &&
  7738. IsFileControl(DropSourceControl, osRemote))
  7739. {
  7740. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7741. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7742. (RemoteDirView->DropTarget == NULL))
  7743. {
  7744. dwEffect = DROPEFFECT_NONE;
  7745. }
  7746. else
  7747. {
  7748. if (dwEffect == DROPEFFECT_COPY)
  7749. {
  7750. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7751. // currently we support copying always (at least via temporary directory);
  7752. // remove associated checks once this all proves stable and working
  7753. bool CopyCapable = true;
  7754. // if we do not support neither of operations, there's no discussion
  7755. if (!MoveCapable && !CopyCapable)
  7756. {
  7757. dwEffect = DROPEFFECT_NONE;
  7758. }
  7759. else
  7760. {
  7761. // The default effect inside remote panel is move,
  7762. // unless we do not support it, but support copy
  7763. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7764. {
  7765. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7766. }
  7767. else
  7768. {
  7769. // with ctrl-down, we want copy unless it is not supported
  7770. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7771. }
  7772. }
  7773. }
  7774. }
  7775. }
  7776. }
  7777. //---------------------------------------------------------------------------
  7778. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7779. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7780. {
  7781. DebugAssert(!IsLocalBrowserMode());
  7782. if (FDDTotalSize >= 0)
  7783. {
  7784. if (File->IsDirectory)
  7785. {
  7786. FDDTotalSize = -1;
  7787. }
  7788. else
  7789. {
  7790. FDDTotalSize += File->Size;
  7791. }
  7792. }
  7793. DebugAssert(!FDragTempDir.IsEmpty());
  7794. // TODO: this is quite ineffective
  7795. // TODO: what if invalid character replacement is disabled?
  7796. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7797. UnicodeString TransferFileName;
  7798. if (Sender == RemoteDriveView)
  7799. {
  7800. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7801. }
  7802. else
  7803. {
  7804. TransferFileName = File->FileName;
  7805. }
  7806. FDDFileList->AddObject(TransferFileName, File);
  7807. }
  7808. //---------------------------------------------------------------------------
  7809. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7810. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7811. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7812. {
  7813. // sometimes we do not get DDEnd so the list is not released
  7814. SAFE_DESTROY(FDDFileList);
  7815. FDDFileList = new TStringList();
  7816. FDragTempDir = WinConfiguration->TemporaryDir();
  7817. FDDTotalSize = 0;
  7818. FDragDropSshTerminate.reset(NULL);
  7819. }
  7820. //---------------------------------------------------------------------------
  7821. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7822. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7823. HRESULT & Result)
  7824. {
  7825. if (Result == DRAGDROP_S_DROP)
  7826. {
  7827. try
  7828. {
  7829. GlobalDragImageList->HideDragImage();
  7830. try
  7831. {
  7832. RemoteFileControlDDTargetDrop();
  7833. }
  7834. catch(ESshTerminate & E)
  7835. {
  7836. FDragDropSshTerminate.reset(E.Clone());
  7837. }
  7838. }
  7839. catch (Exception &E)
  7840. {
  7841. // If downloading fails we need to cancel drag&drop, otherwise
  7842. // Explorer shows error
  7843. // But by the way exception probably never reach this point as
  7844. // it's catched on way.
  7845. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7846. Result = DRAGDROP_S_CANCEL;
  7847. ShowExtendedException(Terminal, &E);
  7848. }
  7849. }
  7850. }
  7851. //---------------------------------------------------------------------------
  7852. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7853. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7854. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7855. {
  7856. TFileMasks::TParams MaskParams;
  7857. MaskParams.Size = Size;
  7858. MaskParams.Modification = Modification;
  7859. // this does not re-parse the mask if it is the same as the last time
  7860. FDirViewMatchMask = Masks;
  7861. bool ImplicitMatch;
  7862. Matches =
  7863. // RecurseInclude parameter has no effect as the Path is empty
  7864. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7865. (AllowImplicitMatches || !ImplicitMatch);
  7866. }
  7867. //---------------------------------------------------------------------------
  7868. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7869. TObject * Sender, TListItem * Item, WORD & Indexes)
  7870. {
  7871. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7872. UnicodeString Ext;
  7873. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7874. {
  7875. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7876. }
  7877. else
  7878. {
  7879. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7880. }
  7881. if (SameText(Ext, Configuration->PartialExt))
  7882. {
  7883. Indexes |= oiPartial;
  7884. }
  7885. }
  7886. //---------------------------------------------------------------------------
  7887. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7888. {
  7889. return
  7890. DirViewEnabled(osCurrent) &&
  7891. DirView(osCurrent)->CanPasteFromClipBoard();
  7892. }
  7893. //---------------------------------------------------------------------------
  7894. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7895. {
  7896. bool Result = false;
  7897. if (CanPasteToDirViewFromClipBoard())
  7898. {
  7899. Result = true;
  7900. }
  7901. else
  7902. {
  7903. UnicodeString ClipboardText;
  7904. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7905. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7906. {
  7907. if (StoredSessions->IsUrl(ClipboardText))
  7908. {
  7909. Result = true;
  7910. }
  7911. else
  7912. {
  7913. Result = DirViewEnabled(osCurrent);
  7914. }
  7915. }
  7916. }
  7917. return Result;
  7918. }
  7919. //---------------------------------------------------------------------------
  7920. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7921. {
  7922. if (DoesClipboardContainOurFiles())
  7923. {
  7924. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7925. {
  7926. DebugAssert(!IsLocalBrowserMode());
  7927. TTerminalManager * Manager = TTerminalManager::Instance();
  7928. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7929. Manager->ActiveTerminal = FClipboardTerminal;
  7930. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7931. }
  7932. }
  7933. else if (CanPasteToDirViewFromClipBoard())
  7934. {
  7935. DirView(osCurrent)->PasteFromClipBoard();
  7936. }
  7937. else
  7938. {
  7939. UnicodeString ClipboardText;
  7940. if (NonEmptyTextFromClipboard(ClipboardText))
  7941. {
  7942. if (StoredSessions->IsUrl(ClipboardText))
  7943. {
  7944. NewSession(ClipboardText);
  7945. }
  7946. else
  7947. {
  7948. DirView(osCurrent)->Path = ClipboardText;
  7949. }
  7950. }
  7951. }
  7952. }
  7953. //---------------------------------------------------------------------------
  7954. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7955. {
  7956. // TBD
  7957. }
  7958. //---------------------------------------------------------------------------
  7959. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7960. {
  7961. TCustomDirView * ADirView = DirView(Side);
  7962. ADirView->SelectAll(Mode);
  7963. ADirView->SetFocus();
  7964. }
  7965. //---------------------------------------------------------------------------
  7966. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7967. {
  7968. TCustomDirView * ADirView = DirView(Side);
  7969. TFileFilter Filter;
  7970. DefaultFileFilter(Filter);
  7971. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7972. {
  7973. Configuration->Usage->Inc(L"MaskSelections");
  7974. ADirView->SelectFiles(Filter, Select);
  7975. ADirView->SetFocus();
  7976. }
  7977. }
  7978. //---------------------------------------------------------------------------
  7979. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7980. {
  7981. TCustomDirView * ADirView = DirView(Side);
  7982. ADirView->RestoreSelectedNames();
  7983. ADirView->SetFocus();
  7984. }
  7985. //---------------------------------------------------------------------------
  7986. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7987. {
  7988. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7989. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7990. {
  7991. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7992. UnicodeString Ext;
  7993. if (!IsSideLocalBrowser(osCurrent))
  7994. {
  7995. Ext = UnixExtractFileExt(FileName);
  7996. }
  7997. else
  7998. {
  7999. Ext = ExtractFileExt(FileName);
  8000. }
  8001. if (Ext.IsEmpty())
  8002. {
  8003. Ext = L".";
  8004. }
  8005. TFileFilter Filter;
  8006. Filter.Masks = FORMAT(L"*%s", (Ext));
  8007. Filter.Directories = false;
  8008. CurrentDirView->SelectFiles(Filter, Select);
  8009. }
  8010. }
  8011. //---------------------------------------------------------------------------
  8012. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8013. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8014. {
  8015. UnicodeString Result;
  8016. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8017. {
  8018. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8019. }
  8020. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8021. {
  8022. // noop
  8023. }
  8024. else
  8025. {
  8026. Result =
  8027. FMTLOAD(FILE_INFO_FORMAT,
  8028. (FormatBytes(FileInfo.SelectedSize),
  8029. FormatBytes(FileInfo.FilesSize),
  8030. FormatNumber(FileInfo.SelectedCount),
  8031. FormatNumber(FileInfo.FilesCount)));
  8032. }
  8033. return Result;
  8034. }
  8035. //---------------------------------------------------------------------------
  8036. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8037. TTBXStatusPanel * Panel, TOperationSide Side)
  8038. {
  8039. if (Panel->Index == 1)
  8040. {
  8041. ToggleShowHiddenFiles();
  8042. }
  8043. else if (Panel->Index == 2)
  8044. {
  8045. Filter(Side);
  8046. }
  8047. }
  8048. //---------------------------------------------------------------------------
  8049. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8050. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8051. {
  8052. DebugAssert(!StatusBar->SimplePanel);
  8053. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8054. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8055. }
  8056. //---------------------------------------------------------------------------
  8057. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8058. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8059. {
  8060. DebugAssert(StatusBar->Panels->Count >= 3);
  8061. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8062. if (FileInfo.HiddenCount > 0)
  8063. {
  8064. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8065. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8066. }
  8067. else
  8068. {
  8069. HiddenFilesPanel->ViewPriority = 0;
  8070. // not really necessary, just to cleanup no-longer-valid data
  8071. HiddenFilesPanel->Caption = L"";
  8072. }
  8073. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8074. if (FileInfo.FilteredCount > 0)
  8075. {
  8076. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8077. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8078. }
  8079. else
  8080. {
  8081. FilteredFilesPanel->ViewPriority = 0;
  8082. // not really necessary, just to cleanup no-longer-valid data
  8083. FilteredFilesPanel->Caption = L"";
  8084. }
  8085. }
  8086. //---------------------------------------------------------------------------
  8087. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8088. TObject * /*Sender*/)
  8089. {
  8090. if (DirView(osOther)->Enabled)
  8091. {
  8092. DirView(osOther)->SetFocus();
  8093. }
  8094. }
  8095. //---------------------------------------------------------------------------
  8096. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8097. {
  8098. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8099. switch (Config.Show)
  8100. {
  8101. case qvShow:
  8102. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8103. {
  8104. Config.Show = qvHide;
  8105. }
  8106. else
  8107. {
  8108. Config.Show = Config.LastHideShow;
  8109. }
  8110. break;
  8111. case qvHideWhenEmpty:
  8112. if (ComponentVisible[fcQueueView])
  8113. {
  8114. Config.Show = qvHide;
  8115. }
  8116. else
  8117. {
  8118. Config.LastHideShow = Config.Show;
  8119. Config.Show = qvShow;
  8120. }
  8121. break;
  8122. case qvHide:
  8123. Config.LastHideShow = Config.Show;
  8124. Config.Show = qvShow;
  8125. break;
  8126. }
  8127. WinConfiguration->QueueView = Config;
  8128. }
  8129. //---------------------------------------------------------------------------
  8130. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8131. {
  8132. UnicodeString Result;
  8133. if (Terminal != NULL)
  8134. {
  8135. switch (WinConfiguration->PathInCaption)
  8136. {
  8137. case picShort:
  8138. Result = TTerminalManager::Instance()->GetTerminalShortPath(Terminal);
  8139. break;
  8140. case picFull:
  8141. Result = Terminal->CurrentDirectory;
  8142. break;
  8143. }
  8144. }
  8145. return Result;
  8146. }
  8147. //---------------------------------------------------------------------------
  8148. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8149. {
  8150. TColor Result = GetWindowColor(FSessionColor);
  8151. return Result;
  8152. }
  8153. //---------------------------------------------------------------------------
  8154. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8155. {
  8156. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8157. return Result;
  8158. }
  8159. //---------------------------------------------------------------------------
  8160. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8161. {
  8162. TTerminalManager::Instance()->UpdateAppTitle();
  8163. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8164. // background to gray on Windows 7 (works on Windows 10).
  8165. // See also EnableControl
  8166. if (Showing)
  8167. {
  8168. if (Terminal != NULL)
  8169. {
  8170. // Update path when it changes
  8171. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8172. {
  8173. UpdateSessionTab(SessionsPageControl->ActivePage);
  8174. }
  8175. }
  8176. NonVisualDataModule->ReconnectSessionAction->Update();
  8177. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8178. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8179. CenterReconnectToolbar();
  8180. bool HasTerminal = HasActiveTerminal();
  8181. RemoteDirView->Enabled = HasTerminal;
  8182. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8183. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8184. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8185. RemoteDriveView->Color = RemoteDirView->Color;
  8186. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8187. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8188. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8189. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8190. QueueFileList->Enabled = QueueView3->Enabled;
  8191. QueueFileList->Color = QueueView3->Color;
  8192. QueueFileList->Font->Color = QueueView3->Font->Color;
  8193. QueueLabelUpdateStatus();
  8194. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8195. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8196. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8197. }
  8198. }
  8199. //---------------------------------------------------------------------------
  8200. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8201. {
  8202. UpdateControls();
  8203. }
  8204. //---------------------------------------------------------------------------
  8205. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8206. TObject * Sender)
  8207. {
  8208. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8209. DebugAssert(DirView != NULL);
  8210. DoDirViewLoaded(DirView);
  8211. TransferPresetAutoSelect();
  8212. }
  8213. //---------------------------------------------------------------------------
  8214. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8215. {
  8216. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8217. // first run after installation
  8218. if (double(Updates.LastCheck) == 0)
  8219. {
  8220. // make sure next time there will be an update (if enabled)
  8221. Updates.LastCheck = TDateTime(1);
  8222. WinConfiguration->Updates = Updates;
  8223. }
  8224. else if ((double(Updates.Period) > 0) &&
  8225. (Now() - Updates.LastCheck >= Updates.Period))
  8226. {
  8227. TThreadMethod OnUpdatesChecked = NULL;
  8228. if (!IsUWP())
  8229. {
  8230. OnUpdatesChecked = UpdatesChecked;
  8231. }
  8232. StartUpdateThread(OnUpdatesChecked);
  8233. }
  8234. }
  8235. //---------------------------------------------------------------------------
  8236. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8237. {
  8238. UnicodeString Message;
  8239. bool New;
  8240. TQueryType Type;
  8241. GetUpdatesMessage(Message, New, Type, false);
  8242. if (!Message.IsEmpty())
  8243. {
  8244. if (New)
  8245. {
  8246. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8247. }
  8248. if (!New && (Type != qtWarning))
  8249. {
  8250. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8251. }
  8252. else
  8253. {
  8254. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8255. }
  8256. if (New)
  8257. {
  8258. Configuration->Usage->Inc(L"UpdateNotifications");
  8259. }
  8260. }
  8261. }
  8262. //---------------------------------------------------------------------------
  8263. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8264. {
  8265. RestoreApp();
  8266. bool CanDisplay = !NonVisualDataModule->Busy;
  8267. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8268. {
  8269. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8270. }
  8271. if (CanDisplay)
  8272. {
  8273. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8274. CheckForUpdates(true);
  8275. }
  8276. else
  8277. {
  8278. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8279. }
  8280. }
  8281. //---------------------------------------------------------------------------
  8282. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8283. TCopyParamRuleData & Data)
  8284. {
  8285. DebugAssert(Terminal != NULL);
  8286. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8287. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8288. Data.RemoteDirectory = RemoteDirView->PathName;
  8289. }
  8290. //---------------------------------------------------------------------------
  8291. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8292. {
  8293. // Terminal can be null when we are changing local directory implicitly,
  8294. // because it has been deleted, while no session is connected
  8295. // (Login dialog is open)
  8296. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8297. {
  8298. DebugAssert(!IsLocalBrowserMode());
  8299. TCopyParamRuleData Data;
  8300. GetTransferPresetAutoSelectData(Data);
  8301. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8302. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8303. if (CopyParamIndex < 0)
  8304. {
  8305. // there is no preset that matches autoselection
  8306. // set preset that we consider "default"
  8307. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8308. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8309. }
  8310. else
  8311. {
  8312. // there is preset matching autoselection
  8313. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8314. if (CopyParamName == FCopyParamAutoSelected)
  8315. {
  8316. // autoselected the same preset as the last time
  8317. // make no change (i.e. preserve custom user preset, if any)
  8318. }
  8319. else
  8320. {
  8321. // autoselected the different preset then the last time (or there
  8322. // was default preset set)
  8323. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8324. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8325. }
  8326. }
  8327. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8328. {
  8329. if (CopyParamIndex >= 0)
  8330. {
  8331. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8332. }
  8333. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8334. try
  8335. {
  8336. int Fmt =
  8337. (CopyParamIndex < 0) ?
  8338. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8339. COPY_PARAM_AUTOSELECTED;
  8340. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8341. Data->Message = MainInstructions(Message);
  8342. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8343. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8344. CopyParamAttrs);
  8345. if (CopyParamIndex >= 0)
  8346. {
  8347. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8348. Info = FORMAT(L"%s\n \n%s", (Info,
  8349. FMTLOAD(COPY_PARAM_RULE,
  8350. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8351. }
  8352. Data->Message += L"\n\n" + Info;
  8353. if (WinConfiguration->CopyParamAutoSelectNotice)
  8354. {
  8355. TransferPresetNoteMessage(Data, true);
  8356. }
  8357. else
  8358. {
  8359. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8360. Data = NULL; // ownership passed
  8361. }
  8362. }
  8363. __finally
  8364. {
  8365. delete Data;
  8366. }
  8367. }
  8368. }
  8369. }
  8370. //---------------------------------------------------------------------------
  8371. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8372. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8373. {
  8374. DebugAssert(NoteData != NULL);
  8375. DebugAssert(!IsLocalBrowserMode());
  8376. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8377. TQueryButtonAlias Aliases[1];
  8378. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8379. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8380. Params.Aliases = Aliases;
  8381. Params.AliasesCount = LENOF(Aliases);
  8382. unsigned int Result =
  8383. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8384. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8385. switch (Result)
  8386. {
  8387. case qaNeverAskAgain:
  8388. DebugAssert(AllowNeverAskAgain);
  8389. WinConfiguration->CopyParamAutoSelectNotice = false;
  8390. break;
  8391. case qaIgnore:
  8392. PreferencesDialog(pmPresets);
  8393. break;
  8394. }
  8395. }
  8396. //---------------------------------------------------------------------------
  8397. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8398. {
  8399. // as of now useless, as this is used for notes only, never for balloons, ...
  8400. RestoreApp();
  8401. // .. and we should never be busy here
  8402. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8403. {
  8404. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8405. }
  8406. }
  8407. //---------------------------------------------------------------------------
  8408. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8409. TPreferencesMode APreferencesMode)
  8410. {
  8411. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8412. TCopyParamRuleData Data;
  8413. if (Terminal != NULL)
  8414. {
  8415. PreferencesData.reset(new TPreferencesDialogData());
  8416. GetTransferPresetAutoSelectData(Data);
  8417. PreferencesData->CopyParamRuleData = &Data;
  8418. }
  8419. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8420. }
  8421. //---------------------------------------------------------------------------
  8422. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8423. const TCustomCommandType & Command)
  8424. {
  8425. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8426. {
  8427. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8428. }
  8429. }
  8430. //---------------------------------------------------------------------------
  8431. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8432. {
  8433. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8434. TCustomCommandType Command;
  8435. // make sure we use local custom command when remote are not supported
  8436. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8437. {
  8438. Command = FLastCustomCommand;
  8439. }
  8440. else
  8441. {
  8442. Command.Params = Command.Params | ccLocal;
  8443. }
  8444. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8445. FEditingFocusedAdHocCommand = OnFocused;
  8446. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8447. int Options =
  8448. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8449. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8450. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8451. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8452. {
  8453. FLastCustomCommand = Command;
  8454. UpdateCustomCommandsToolbar();
  8455. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8456. }
  8457. }
  8458. //---------------------------------------------------------------------------
  8459. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8460. {
  8461. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8462. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8463. DebugAssert(State > 0);
  8464. if (State <= 0)
  8465. {
  8466. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8467. }
  8468. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8469. }
  8470. //---------------------------------------------------------------------------
  8471. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8472. TCustomCommandType & Command, int & State)
  8473. {
  8474. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8475. if (Result)
  8476. {
  8477. Command = FLastCustomCommand;
  8478. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8479. }
  8480. return Result;
  8481. }
  8482. //---------------------------------------------------------------------------
  8483. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8484. {
  8485. ResetIncrementalSearch();
  8486. }
  8487. //---------------------------------------------------------------------------
  8488. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8489. {
  8490. DebugAssert(ComponentVisible[Component]);
  8491. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8492. }
  8493. //---------------------------------------------------------------------------
  8494. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8495. {
  8496. // when queue panel is resized here directly, the status bar is stretched
  8497. // over whole space the panel occupied
  8498. PostComponentHide(fcQueueView);
  8499. }
  8500. //---------------------------------------------------------------------------
  8501. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8502. {
  8503. ComponentVisible[fcQueueFileList] = false;
  8504. }
  8505. //---------------------------------------------------------------------------
  8506. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8507. {
  8508. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8509. RefreshColorMode();
  8510. ResetSysDarkTheme();
  8511. ConfigurationChanged();
  8512. ConfigureInterface();
  8513. // Should be called for all controls
  8514. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8515. }
  8516. //---------------------------------------------------------------------------
  8517. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8518. {
  8519. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8520. if (!FInvalid &&
  8521. (Message.LParam != 0) &&
  8522. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8523. {
  8524. ThemeChanged();
  8525. }
  8526. TForm::Dispatch(&Message);
  8527. }
  8528. //---------------------------------------------------------------------------
  8529. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8530. {
  8531. TMessage * M = static_cast<TMessage*>(Message);
  8532. switch (M->Msg)
  8533. {
  8534. case CM_DIALOGCHAR:
  8535. CMDialogChar(*M);
  8536. break;
  8537. case WM_APPCOMMAND:
  8538. WMAppCommand(*M);
  8539. break;
  8540. case WM_SYSCOMMAND:
  8541. WMSysCommand(*M);
  8542. break;
  8543. case WM_QUERYENDSESSION:
  8544. WMQueryEndSession(*M);
  8545. break;
  8546. case WM_ENDSESSION:
  8547. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8548. break;
  8549. #ifdef _DEBUG
  8550. case WM_WINDOWPOSCHANGED:
  8551. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8552. break;
  8553. case CM_CUSTOMSTYLECHANGED:
  8554. TForm::Dispatch(Message);
  8555. break;
  8556. #endif
  8557. case WM_COMPONENT_HIDE:
  8558. {
  8559. Byte Component = static_cast<Byte>(M->WParam);
  8560. // sanity check
  8561. if (ComponentVisible[Component])
  8562. {
  8563. // special treatment
  8564. if (Component == fcQueueView)
  8565. {
  8566. ToggleQueueVisibility();
  8567. DebugAssert(!ComponentVisible[fcQueueView]);
  8568. }
  8569. else
  8570. {
  8571. ComponentVisible[Component] = false;
  8572. }
  8573. }
  8574. }
  8575. break;
  8576. case WM_COPYDATA:
  8577. WMCopyData(*M);
  8578. break;
  8579. case WM_MANAGES_CAPTION:
  8580. // caption managed in TTerminalManager::UpdateAppTitle()
  8581. M->Result = 1;
  8582. break;
  8583. case WM_WANTS_MOUSEWHEEL:
  8584. M->Result = 1;
  8585. break;
  8586. case CM_SHOWINGCHANGED:
  8587. CMShowingChanged(*M);
  8588. break;
  8589. case WM_CLOSE:
  8590. WMClose(*M);
  8591. break;
  8592. case WM_DPICHANGED:
  8593. WMDpiChanged(*M);
  8594. break;
  8595. case CM_DPICHANGED:
  8596. CMDpiChanged(*M);
  8597. break;
  8598. case WM_SETTINGCHANGE:
  8599. WMSettingChange(*M);
  8600. break;
  8601. case CM_DIALOGKEY:
  8602. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8603. break;
  8604. default:
  8605. TForm::Dispatch(Message);
  8606. break;
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8611. {
  8612. // noop
  8613. }
  8614. //---------------------------------------------------------------------------
  8615. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8616. {
  8617. TForm::Dispatch(&Message);
  8618. FSessionColors->Clear();
  8619. AddFixedSessionImages();
  8620. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8621. UpdateImages();
  8622. }
  8623. //---------------------------------------------------------------------------
  8624. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8625. {
  8626. TForm::Dispatch(&Message);
  8627. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8628. UpdatePixelsPerInchMainWindowCounter();
  8629. }
  8630. //---------------------------------------------------------------------------
  8631. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8632. {
  8633. // Cannot close window while we are busy.
  8634. // We cannot test this in FormCloseQuery as that is called also from
  8635. // Close(), which is called by CloseApplicationAction. So we can be busy
  8636. // there already even, when it is legitimate to close the application.
  8637. // Possibly a better place to handle this would be WMSysCommand.
  8638. if (NonVisualDataModule->Busy)
  8639. {
  8640. Message.Result = 1;
  8641. }
  8642. else
  8643. {
  8644. TForm::Dispatch(&Message);
  8645. }
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8649. {
  8650. TForm::Dispatch(&Message);
  8651. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8652. if (Showing && !FStarted)
  8653. {
  8654. FStarted = true;
  8655. InterfaceStarted();
  8656. }
  8657. if (Showing && (Terminal == NULL))
  8658. {
  8659. // When we are starting minimized (i.e. from an installer),
  8660. // postpone showing Login dialog until we get restored.
  8661. // Otherwise the Login dialog (and Authentication window) show restored
  8662. // over invisible (minimized) main window.
  8663. if (WindowState == wsMinimized)
  8664. {
  8665. FNeedSession = true;
  8666. }
  8667. else
  8668. {
  8669. // This happens before application ever goes idle, so the toolbars would
  8670. // stay enabled (initial state) until the Login dialog is dismissed.
  8671. UpdateActions();
  8672. NonVisualDataModule->StartBusy();
  8673. try
  8674. {
  8675. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8676. // otherwise the dialog does not receive focus.
  8677. // With Commander interface the ProcessMessages is called already
  8678. // by TDriveView, but with Explorer interface, we need to call it explicily
  8679. Application->ProcessMessages();
  8680. // do not reload sessions, they have been loaded just now (optimization)
  8681. NeedSession(true);
  8682. }
  8683. __finally
  8684. {
  8685. NonVisualDataModule->EndBusy();
  8686. }
  8687. }
  8688. }
  8689. }
  8690. //---------------------------------------------------------------------------
  8691. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8692. {
  8693. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8694. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8695. }
  8696. //---------------------------------------------------------------------------
  8697. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8698. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8699. int & MaxHeight)
  8700. {
  8701. // workaround for bug in TWinControl.CalcConstraints
  8702. // Check for empty rect (restore from iconic state) is done there only after
  8703. // call to AdjustClientRect, which enlarges the rect (for forms).
  8704. TRect R = GetClientRect();
  8705. // when restoring from iconic state, place no restrictions
  8706. if (IsRectEmpty(R))
  8707. {
  8708. MinWidth = 0;
  8709. MinHeight = 0;
  8710. MaxWidth = 32000;
  8711. MaxHeight = 32000;
  8712. }
  8713. }
  8714. //---------------------------------------------------------------------------
  8715. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8716. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8717. {
  8718. // terminal can be already closed (e.g. dropped connection)
  8719. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8720. {
  8721. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8722. try
  8723. {
  8724. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8725. }
  8726. catch(...)
  8727. {
  8728. if (!Terminal->Active)
  8729. {
  8730. Close = true;
  8731. }
  8732. throw;
  8733. }
  8734. }
  8735. }
  8736. //---------------------------------------------------------------------------
  8737. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8738. {
  8739. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8740. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8741. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8742. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8743. {
  8744. OnGetSpaceAvailable = GetSpaceAvailable;
  8745. }
  8746. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8747. OnGetSpaceAvailable);
  8748. }
  8749. //---------------------------------------------------------------------------
  8750. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8751. {
  8752. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8753. Terminal->FillSessionDataForCode(Data.get());
  8754. return Data.release();
  8755. }
  8756. //---------------------------------------------------------------------------
  8757. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8758. {
  8759. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8760. DoGenerateUrlDialog(Data.get(), Paths);
  8761. }
  8762. //---------------------------------------------------------------------------
  8763. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8764. {
  8765. GenerateUrl(NULL);
  8766. }
  8767. //---------------------------------------------------------------------------
  8768. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8769. {
  8770. std::unique_ptr<TStrings> Paths(new TStringList());
  8771. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8772. GenerateUrl(Paths.get());
  8773. }
  8774. //---------------------------------------------------------------------------
  8775. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8776. {
  8777. FSessionColor = value;
  8778. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8779. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8780. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8781. DebugAssert(ColorItem != NULL);
  8782. ColorItem->Color = C;
  8783. NonVisualDataModule->ColorMenuItem->Color = C;
  8784. UpdateControls();
  8785. }
  8786. //---------------------------------------------------------------------------
  8787. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8788. {
  8789. if (value != FSessionColor)
  8790. {
  8791. UpdateSessionColor(value);
  8792. // Is null when called from LastTerminalClosed
  8793. if (Terminal != NULL)
  8794. {
  8795. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8796. }
  8797. }
  8798. }
  8799. //---------------------------------------------------------------------------
  8800. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8801. {
  8802. bool Result = FNoteTimer->Enabled;
  8803. if (Result)
  8804. {
  8805. // cannot cancel note too early
  8806. bool NotEarly =
  8807. (Now() - FNoteShown >
  8808. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8809. if (Force || NotEarly)
  8810. {
  8811. FNoteTimer->Enabled = false;
  8812. FNote = L"";
  8813. SAFE_DESTROY(FNoteData);
  8814. FOnNoteClick = NULL;
  8815. FNoteHints = FNotes->Text;
  8816. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8817. UpdateStatusBar();
  8818. }
  8819. }
  8820. return Result;
  8821. }
  8822. //---------------------------------------------------------------------------
  8823. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8824. {
  8825. DebugAssert(FNoteTimer->Enabled);
  8826. CancelNote(true);
  8827. }
  8828. //---------------------------------------------------------------------------
  8829. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8830. {
  8831. FNoteHints = FNotes->Text.TrimRight();
  8832. }
  8833. //---------------------------------------------------------------------------
  8834. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8835. {
  8836. int P = Note.Pos(L"\n");
  8837. if (P > 0)
  8838. {
  8839. Note.SetLength(P - 1);
  8840. }
  8841. FNotes->Add(FORMAT(L"[%s] %s",
  8842. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8843. while (FNotes->Count > 10)
  8844. {
  8845. FNotes->Delete(0);
  8846. }
  8847. if (UpdateNow)
  8848. {
  8849. UpdateNoteHints();
  8850. UpdateStatusBar();
  8851. }
  8852. }
  8853. //---------------------------------------------------------------------------
  8854. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8855. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8856. {
  8857. int P = Note.Pos(L"\n");
  8858. if (P > 0)
  8859. {
  8860. Note.SetLength(P - 1);
  8861. }
  8862. UpdateNoteHints();
  8863. FNote = Note;
  8864. SAFE_DESTROY(FNoteData);
  8865. FNoteData = NoteData;
  8866. FOnNoteClick = OnNoteClick;
  8867. AddNote(Note, false);
  8868. UpdateStatusBar();
  8869. FNoteShown = Now();
  8870. FNoteTimer->Enabled = false;
  8871. if (Seconds == 0)
  8872. {
  8873. Seconds = WinConfiguration->NotificationsTimeout;
  8874. }
  8875. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8876. FNoteTimer->Enabled = true;
  8877. }
  8878. //---------------------------------------------------------------------------
  8879. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8880. {
  8881. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8882. }
  8883. //---------------------------------------------------------------------------
  8884. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8885. {
  8886. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8887. {
  8888. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8889. }
  8890. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8891. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8892. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8893. 0, NULL, NULL);
  8894. }
  8895. //---------------------------------------------------------------------------
  8896. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8897. {
  8898. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8899. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8900. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8901. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8902. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8906. {
  8907. WinConfiguration->FormatSizeBytes = Style;
  8908. }
  8909. //---------------------------------------------------------------------------
  8910. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8911. {
  8912. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8913. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8914. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8915. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8916. }
  8917. //---------------------------------------------------------------------------
  8918. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8919. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8920. {
  8921. if (Panel->Index == 0)
  8922. {
  8923. if (FOnNoteClick != NULL)
  8924. {
  8925. // prevent the user data from being freed by possible call
  8926. // to CancelNote or PostNote during call to OnNoteClick
  8927. std::unique_ptr<TObject> NoteData(FNoteData);
  8928. TNotifyEvent OnNoteClick = FOnNoteClick;
  8929. FNoteData = NULL;
  8930. // need to cancel the note as we are going to delete its user data
  8931. CancelNote(true);
  8932. OnNoteClick(NoteData.get());
  8933. }
  8934. }
  8935. if (HasActiveTerminal() &&
  8936. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8937. {
  8938. FileSystemInfo();
  8939. }
  8940. }
  8941. //---------------------------------------------------------------------------
  8942. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8943. {
  8944. // workaround:
  8945. // 1) for unknown reason, disabling window, while minimized,
  8946. // prevents it from restoring, even if it was enabled again meanwhile
  8947. // 2) when disabling the main window, while another has focus
  8948. // minimize is no longer possible
  8949. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8950. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8951. // Shouldn't we use IsApplicationMinimized() here?
  8952. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8953. {
  8954. Enabled = false;
  8955. }
  8956. FLockLevel++;
  8957. }
  8958. //---------------------------------------------------------------------------
  8959. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8960. {
  8961. DebugAssert(FLockLevel > 0);
  8962. FLockLevel--;
  8963. if (FLockLevel == 0)
  8964. {
  8965. DebugAssert(FLockSuspendLevel == 0);
  8966. Enabled = true;
  8967. }
  8968. }
  8969. //---------------------------------------------------------------------------
  8970. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8971. {
  8972. // We need to make sure that window is enabled when the last modal window closes
  8973. // otherwise focus is not restored correctly.
  8974. // So we re-enable the window when modal window opens and
  8975. // disable it back after is closes
  8976. if (FLockLevel > 0)
  8977. {
  8978. // while we have nesting counter, we know that we never be called
  8979. // recursivelly as Application->OnModalBegin is called only
  8980. // for the top-level modal window
  8981. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8982. {
  8983. // won't be disabled when conditions in LockWindow() were not satisfied
  8984. FDisabledOnLockSuspend = !Enabled;
  8985. // When minimized to tray (or actually when set to SW_HIDE),
  8986. // setting Enabled makes the window focusable even when there's
  8987. // modal window over it
  8988. if (!FTrayIcon->Visible)
  8989. {
  8990. Enabled = true;
  8991. }
  8992. }
  8993. FLockSuspendLevel++;
  8994. }
  8995. }
  8996. //---------------------------------------------------------------------------
  8997. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8998. {
  8999. if (FLockSuspendLevel > 0)
  9000. {
  9001. DebugAssert(FLockLevel > 0);
  9002. FLockSuspendLevel--;
  9003. // see comment in SuspendWindowLock
  9004. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9005. {
  9006. // Note that window can be enabled here, when we were minized to tray when
  9007. // was SuspendWindowLock() called.
  9008. // We should possibly do the same check as in LockWindow(),
  9009. // if it is ever possible that the consitions change between
  9010. // SuspendWindowLock() and ResumeWindowLock()
  9011. Enabled = !FDisabledOnLockSuspend;
  9012. }
  9013. }
  9014. }
  9015. //---------------------------------------------------------------------------
  9016. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9017. {
  9018. TTBXComboBoxItem * RemotePathComboBox =
  9019. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9020. if (!TextOnly)
  9021. {
  9022. TStrings * Items = RemotePathComboBox->Strings;
  9023. Items->BeginUpdate();
  9024. try
  9025. {
  9026. Items->Clear();
  9027. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9028. {
  9029. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9030. while (!IsUnixRootPath(APath))
  9031. {
  9032. int P = APath.LastDelimiter(L'/');
  9033. DebugAssert(P >= 0);
  9034. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9035. APath.SetLength(P - 1);
  9036. }
  9037. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9038. }
  9039. }
  9040. __finally
  9041. {
  9042. Items->EndUpdate();
  9043. }
  9044. }
  9045. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9046. // Setting ItemIndex to -1 does not reset its text
  9047. if (RemotePathComboBox->Strings->Count == 0)
  9048. {
  9049. RemotePathComboBox->Text = L"";
  9050. }
  9051. }
  9052. //---------------------------------------------------------------------------
  9053. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9054. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9055. {
  9056. if (AIndex < 0)
  9057. {
  9058. AIndex = Sender->ItemIndex;
  9059. }
  9060. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9061. }
  9062. //---------------------------------------------------------------------------
  9063. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9064. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9065. int & ImageIndex)
  9066. {
  9067. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9068. }
  9069. //---------------------------------------------------------------------------
  9070. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9071. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9072. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9073. {
  9074. if (!IsLocalBrowserMode())
  9075. {
  9076. ARect.Left += (10 * AIndex);
  9077. }
  9078. }
  9079. //---------------------------------------------------------------------------
  9080. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9081. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9082. {
  9083. AWidth += (10 * AIndex);
  9084. }
  9085. //---------------------------------------------------------------------------
  9086. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9087. {
  9088. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9089. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9090. int Index = RemotePathComboBox->ItemIndex;
  9091. while (Index < RemotePathComboBox->Strings->Count - 1)
  9092. {
  9093. APath = UnixExtractFileDir(APath);
  9094. Index++;
  9095. }
  9096. // VanDyke style paths
  9097. if (APath.IsEmpty())
  9098. {
  9099. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9100. APath = ROOTDIRECTORY;
  9101. }
  9102. if (RemoteDirView->Path != APath)
  9103. {
  9104. RemoteDirView->Path = APath;
  9105. }
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9109. {
  9110. DoRemotePathComboBoxItemClick(Sender);
  9111. }
  9112. //---------------------------------------------------------------------------
  9113. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9114. {
  9115. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9116. DebugUsedParam(Sender);
  9117. UpdateRemotePathComboBox(true);
  9118. }
  9119. //---------------------------------------------------------------------------
  9120. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9121. {
  9122. DoRemotePathComboBoxCancel(Sender);
  9123. }
  9124. //---------------------------------------------------------------------------
  9125. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9126. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9127. {
  9128. ResetIncrementalSearch();
  9129. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9130. DebugAssert(DirView != NULL);
  9131. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9132. {
  9133. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9134. // OnEditing is called also from TCustomListView::CanEdit
  9135. if (Edit != NULL)
  9136. {
  9137. EditSelectBaseName(Edit);
  9138. }
  9139. }
  9140. }
  9141. //---------------------------------------------------------------------------
  9142. //---------------------------------------------------------------------------
  9143. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9144. {
  9145. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9146. Result->AutoDetectDnD = false;
  9147. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9148. Result->RenderDataOn = rdoEnterAndDropSync;
  9149. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9150. return Result;
  9151. }
  9152. //---------------------------------------------------------------------------
  9153. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9154. {
  9155. TForm::CreateWnd();
  9156. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9157. if (FSessionsDragDropFilesEx == NULL)
  9158. {
  9159. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9160. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9161. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9162. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9163. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9164. }
  9165. if (FQueueDragDropFilesEx == NULL)
  9166. {
  9167. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9168. // No need to set OnDragOver as we do not have any restrictions
  9169. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9170. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9171. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9172. }
  9173. }
  9174. //---------------------------------------------------------------------------
  9175. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9176. {
  9177. TForm::DestroyWnd();
  9178. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9179. FQueueDragDropFilesEx->DragDropControl = NULL;
  9180. }
  9181. //---------------------------------------------------------------------------
  9182. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9183. {
  9184. SideEnter(FCurrentSide);
  9185. FEverShown = true;
  9186. }
  9187. //---------------------------------------------------------------------------
  9188. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9189. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9190. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9191. {
  9192. if (!NonVisualDataModule->Busy)
  9193. {
  9194. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9195. Configuration->Usage->Inc(L"FileFinds");
  9196. LockWindow(true);
  9197. NonVisualDataModule->StartBusy();
  9198. WinConfiguration->LockedInterface = true;
  9199. try
  9200. {
  9201. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9202. }
  9203. __finally
  9204. {
  9205. WinConfiguration->LockedInterface = false;
  9206. NonVisualDataModule->EndBusy();
  9207. UnlockWindow();
  9208. }
  9209. }
  9210. }
  9211. //---------------------------------------------------------------------------
  9212. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9213. {
  9214. if (!NonVisualDataModule->Busy)
  9215. {
  9216. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9217. SetFocus();
  9218. RemoteDirView->Path = UnixExtractFilePath(Path);
  9219. UnicodeString FileName = UnixExtractFileName(Path);
  9220. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9221. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9222. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9223. if (Item == NULL)
  9224. {
  9225. ReloadDirectory(osRemote);
  9226. Item = RemoteDirView->FindFileItem(FileName);
  9227. }
  9228. if (Item != NULL)
  9229. {
  9230. RemoteDirView->ItemFocused = Item;
  9231. RemoteDirView->ItemFocused->MakeVisible(false);
  9232. RemoteDirView->SetFocus();
  9233. }
  9234. }
  9235. }
  9236. //---------------------------------------------------------------------------
  9237. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9238. {
  9239. bool Result = !NonVisualDataModule->Busy;
  9240. if (Result)
  9241. {
  9242. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9243. }
  9244. return Result;
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9248. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9249. {
  9250. if (CanOperateOnFoundFiles(ATerminal))
  9251. {
  9252. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9253. FOnFileOperationFinished = OnFileOperationFinished;
  9254. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9255. }
  9256. }
  9257. //---------------------------------------------------------------------------
  9258. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9259. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9260. {
  9261. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9262. }
  9263. //---------------------------------------------------------------------------
  9264. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9265. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9266. {
  9267. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9268. }
  9269. //---------------------------------------------------------------------------
  9270. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9271. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9272. {
  9273. if (CanOperateOnFoundFiles(ATerminal))
  9274. {
  9275. for (int Index = 0; Index < FileList->Count; Index++)
  9276. {
  9277. UnicodeString FileName = FileList->Strings[Index];
  9278. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9279. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9280. OnFileOperationFinished(FileName, true);
  9281. }
  9282. }
  9283. }
  9284. //---------------------------------------------------------------------------
  9285. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9286. {
  9287. FFileFindTerminal = Terminal;
  9288. ShowFileFindDialog(
  9289. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9290. DoDownloadFoundFiles, DoEditFoundFiles);
  9291. }
  9292. //---------------------------------------------------------------------------
  9293. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9294. {
  9295. FTaskbarList = TaskbarList;
  9296. }
  9297. //---------------------------------------------------------------------------
  9298. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9299. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9300. {
  9301. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9302. if (Index >= 0)
  9303. {
  9304. if (Button == mbLeft)
  9305. {
  9306. // "Mouse down" is raised only after tab is switched.
  9307. // If switching tab (switching session) takes long enough for user
  9308. // to actually release the button, "mouse down" is still raised,
  9309. // but we do not get "mouse up" event, so dragging is not cancelled,
  9310. // prevent that by not beginning dragging in the first place.
  9311. if (IsKeyPressed(VK_LBUTTON))
  9312. {
  9313. // when user clicks the "+", we get mouse down only after the session
  9314. // is closed, when new session tab is already on X:Y, so dragging
  9315. // starts, prevent that
  9316. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9317. {
  9318. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9319. if (Terminal != NULL)
  9320. {
  9321. SessionsPageControl->BeginDrag(false);
  9322. }
  9323. }
  9324. }
  9325. }
  9326. else if (Button == mbMiddle)
  9327. {
  9328. // ignore middle-click for "New session tab"
  9329. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9330. if (Terminal != NULL)
  9331. {
  9332. CloseSessionTab(Index);
  9333. }
  9334. }
  9335. }
  9336. }
  9337. //---------------------------------------------------------------------------
  9338. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9339. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9340. {
  9341. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9342. // do not allow dropping on the "+" tab
  9343. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9344. if ((TargetTerminal != NULL) &&
  9345. (SessionsPageControl->ActivePage->PageIndex != Index))
  9346. {
  9347. Configuration->Usage->Inc(L"SessionTabMoves");
  9348. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9349. // but we want to actually prevent that to avoid flicker
  9350. SessionsPageControl->ActivePage->PageIndex = Index;
  9351. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9352. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9353. }
  9354. }
  9355. //---------------------------------------------------------------------------
  9356. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9357. TObject * Sender, TObject * Source, int X, int Y,
  9358. TDragState /*State*/, bool & Accept)
  9359. {
  9360. Accept = (Sender == Source);
  9361. if (Accept)
  9362. {
  9363. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9364. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9365. // do not allow dragging to the "+" tab
  9366. Accept = (Terminal != NULL);
  9367. }
  9368. }
  9369. //---------------------------------------------------------------------------
  9370. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9371. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9372. {
  9373. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9374. if (Index < 0)
  9375. {
  9376. Effect = DROPEFFECT_NONE;
  9377. }
  9378. else
  9379. {
  9380. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9381. // do not allow dropping on the "+" tab
  9382. if (TargetTerminal == NULL)
  9383. {
  9384. Effect = DROPEFFECT_NONE;
  9385. }
  9386. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9387. {
  9388. Effect = DROPEFFECT_COPY;
  9389. }
  9390. }
  9391. }
  9392. //---------------------------------------------------------------------------
  9393. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9394. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9395. {
  9396. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9397. // do not allow dropping on the "+" tab
  9398. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9399. if (TargetTerminal != NULL)
  9400. {
  9401. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9402. if (!IsFileControl(DropSourceControl, osRemote))
  9403. {
  9404. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9405. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9406. // Why don't we use Terminal->CurrentDirectory directly?
  9407. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9408. // do not force queue, drag drop
  9409. false, true);
  9410. }
  9411. }
  9412. }
  9413. //---------------------------------------------------------------------------
  9414. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9415. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9416. {
  9417. // Downloads are handled in RemoteFileControlDDEnd
  9418. if (!IsFileControl(DropSourceControl, osRemote))
  9419. {
  9420. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9421. Terminal->CurrentDirectory,
  9422. // force queue, drag drop
  9423. true, true);
  9424. }
  9425. }
  9426. //---------------------------------------------------------------------------
  9427. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9428. {
  9429. FShowing = false;
  9430. // Do not save empty workspace
  9431. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9432. {
  9433. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9434. UnicodeString Name = WorkspaceName();
  9435. DoSaveWorkspace(
  9436. Name, DataList.get(),
  9437. !Configuration->DisablePasswordStoring &&
  9438. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9439. WinConfiguration->LastStoredSession = Name;
  9440. }
  9441. }
  9442. //---------------------------------------------------------------------------
  9443. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9444. {
  9445. TManagedTerminal * ManagedTerminal =
  9446. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9447. if (ManagedTerminal != NULL)
  9448. {
  9449. ManagedTerminal->DirectoryLoaded = Now();
  9450. }
  9451. }
  9452. //---------------------------------------------------------------------------
  9453. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9454. TListItem * /*Item*/, bool /*Selected*/)
  9455. {
  9456. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9457. switch (DirView->LastSelectMethod)
  9458. {
  9459. case smKeyboard:
  9460. Configuration->Usage->Inc(L"KeyboardSelections");
  9461. break;
  9462. case smMouse:
  9463. Configuration->Usage->Inc(L"MouseSelections");
  9464. break;
  9465. }
  9466. }
  9467. //---------------------------------------------------------------------------
  9468. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9469. {
  9470. if (Color != 0)
  9471. {
  9472. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9473. }
  9474. else
  9475. {
  9476. return FSessionTabImageIndex;
  9477. }
  9478. }
  9479. //---------------------------------------------------------------------------
  9480. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9481. {
  9482. TPngImageCollectionItem * Item =
  9483. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9484. FSessionColors->AddPng(Item->PngImage);
  9485. return FSessionColors->Count - 1;
  9486. }
  9487. //---------------------------------------------------------------------------
  9488. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9489. {
  9490. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9491. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9492. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9493. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9494. }
  9495. //---------------------------------------------------------------------------
  9496. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9497. {
  9498. for (int Index = 0; Index < Control->ControlCount; Index++)
  9499. {
  9500. TControl * AControl = Control->Controls[Index];
  9501. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9502. if (WinControl != NULL)
  9503. {
  9504. CollectItemsWithTextDisplayMode(WinControl);
  9505. }
  9506. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9507. if (Toolbar != NULL)
  9508. {
  9509. // we care for top-level items only
  9510. TTBCustomItem * Items = Toolbar->Items;
  9511. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9512. {
  9513. TTBCustomItem * Item = Items->Items[ItemIndex];
  9514. if (((Item->DisplayMode == nbdmImageAndText) ||
  9515. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9516. EligibleForImageDisplayMode(Item))
  9517. {
  9518. FItemsWithTextDisplayMode.insert(Item);
  9519. }
  9520. }
  9521. }
  9522. }
  9523. }
  9524. //---------------------------------------------------------------------------
  9525. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9526. {
  9527. return true;
  9528. }
  9529. //---------------------------------------------------------------------------
  9530. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9531. {
  9532. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9533. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9534. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9535. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9536. bool Result = true;
  9537. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9538. {
  9539. TTBCustomItem * Item = *i;
  9540. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9541. if (Label != NULL)
  9542. {
  9543. // optimization
  9544. if (Label->Visible == SelectiveToolbarText)
  9545. {
  9546. Result = false;
  9547. }
  9548. else
  9549. {
  9550. Label->Visible = SelectiveToolbarText;
  9551. }
  9552. }
  9553. else
  9554. {
  9555. // optimization
  9556. if (Item->DisplayMode == DisplayMode)
  9557. {
  9558. Result = false;
  9559. }
  9560. else
  9561. {
  9562. Item->DisplayMode = DisplayMode;
  9563. }
  9564. }
  9565. ++i;
  9566. }
  9567. if (Result)
  9568. {
  9569. UpdateNewSessionTab();
  9570. }
  9571. return Result;
  9572. }
  9573. //---------------------------------------------------------------------------
  9574. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9575. {
  9576. DebugFail();
  9577. }
  9578. //---------------------------------------------------------------------------
  9579. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9580. {
  9581. // Among other, a lock level is non zero, while directory is being loaded,
  9582. // even when it happens as a result of dirview navigation,
  9583. // i.e. when TNonVisualDataModule is NOT FBusy.
  9584. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9585. // Among other this prevents a panel auto update to occur while
  9586. // directory is changing.
  9587. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9588. }
  9589. //---------------------------------------------------------------------------
  9590. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9591. {
  9592. // While the window is disabled, we still seem to process menu shortcuts at least,
  9593. // so stop it at least here.
  9594. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9595. bool Result;
  9596. if (Allowed == aaUpdate)
  9597. {
  9598. Result = true;
  9599. }
  9600. else
  9601. {
  9602. Result = !NonVisualDataModule->Busy;
  9603. if (Result && (Allowed == aaShortCut))
  9604. {
  9605. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9606. Action->Update();
  9607. Result = Action->Enabled;
  9608. }
  9609. }
  9610. return Result;
  9611. }
  9612. //---------------------------------------------------------------------------
  9613. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9614. {
  9615. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9616. }
  9617. //---------------------------------------------------------------------------
  9618. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9619. {
  9620. // This is somewhat redundant to LockWindow() call from
  9621. // TTerminalManager::TerminalReadDirectoryProgress.
  9622. // But disabling window is known not to block keyboard shorcuts
  9623. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9624. if (Busy > 0)
  9625. {
  9626. if (NonVisualDataModule->Busy)
  9627. {
  9628. State = false;
  9629. }
  9630. else
  9631. {
  9632. NonVisualDataModule->StartBusy();
  9633. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9634. LockWindow();
  9635. }
  9636. }
  9637. else if (Busy < 0)
  9638. {
  9639. UnlockWindow();
  9640. NonVisualDataModule->EndBusy();
  9641. }
  9642. else
  9643. {
  9644. State = NonVisualDataModule->Busy;
  9645. }
  9646. }
  9647. //---------------------------------------------------------------------------
  9648. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9649. {
  9650. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9651. // no context menu for "New session tab"
  9652. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9653. {
  9654. SessionsPageControl->ActivePageIndex = Index;
  9655. if (DebugAlwaysTrue(SessionTabSwitched()))
  9656. {
  9657. // copied from TControl.WMContextMenu
  9658. SendCancelMode(SessionsPageControl);
  9659. // explicit popup instead of using PopupMenu property
  9660. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9661. // while connecting yet not-connected session and hence
  9662. // allowing an access to commands over not-completelly connected session
  9663. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9664. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9665. PopupMenu->PopupComponent = SessionsPageControl;
  9666. PopupMenu->Popup(Point.x, Point.y);
  9667. }
  9668. }
  9669. Handled = true;
  9670. }
  9671. //---------------------------------------------------------------------------
  9672. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9673. {
  9674. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9675. }
  9676. //---------------------------------------------------------------------------
  9677. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9678. {
  9679. Configuration->Usage->Inc(L"PasswordChanges");
  9680. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9681. ChangePasswordData->DisableAuthentationsExceptPassword();
  9682. ChangePasswordData->ChangePassword = true;
  9683. std::unique_ptr<TTerminal> ChangePasswordSession(
  9684. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9685. ChangePasswordSession->AutoReadDirectory = false;
  9686. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9687. {
  9688. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9689. }
  9690. else
  9691. {
  9692. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9693. }
  9694. }
  9695. //---------------------------------------------------------------------------
  9696. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9697. {
  9698. // No nice way to assert SSH2
  9699. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9700. }
  9701. //---------------------------------------------------------------------------
  9702. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9703. {
  9704. TOperationVisualizer OperationVisualizer;
  9705. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9706. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9707. }
  9708. //---------------------------------------------------------------------------
  9709. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9710. {
  9711. TForm::ChangeScale(M, D);
  9712. int APixelsPerInch = GetControlPixelsPerInch(this);
  9713. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9714. try
  9715. {
  9716. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9717. }
  9718. __finally
  9719. {
  9720. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9721. }
  9722. }
  9723. //---------------------------------------------------------------------------
  9724. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9725. {
  9726. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9727. }
  9728. //---------------------------------------------------------------------
  9729. class TPublicControl : public TControl
  9730. {
  9731. friend class TCustomScpExplorerForm;
  9732. };
  9733. //---------------------------------------------------------------------------
  9734. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9735. {
  9736. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9737. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9738. }
  9739. //---------------------------------------------------------------------------
  9740. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9741. {
  9742. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9743. OpenBookmark(Side, Bookmark);
  9744. }
  9745. //---------------------------------------------------------------------------
  9746. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9747. {
  9748. DoBookmarkClick(osLocal, Sender);
  9749. }
  9750. //---------------------------------------------------------------------------
  9751. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9752. {
  9753. DoBookmarkClick(osRemote, Sender);
  9754. }
  9755. //---------------------------------------------------------------------------
  9756. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9757. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9758. {
  9759. if (BookmarkList != NULL)
  9760. {
  9761. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9762. if (IsLocalBrowserMode())
  9763. {
  9764. Side = osLocal;
  9765. }
  9766. if (!WinConfiguration->UseLocationProfiles)
  9767. {
  9768. std::unique_ptr<TStringList> Directories(new TStringList());
  9769. Directories->CaseSensitive = (Side == osRemote);
  9770. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9771. {
  9772. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9773. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9774. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9775. {
  9776. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9777. Item->Caption = EscapeHotkey(Directory);
  9778. Item->ShortCut = Bookmark->ShortCut;
  9779. Item->OnClick = OnBookmarkClick;
  9780. Item->Tag = reinterpret_cast<int>(Bookmark);
  9781. Directories->Add(Directory);
  9782. Menu->Add(Item.release());
  9783. }
  9784. }
  9785. }
  9786. else
  9787. {
  9788. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9789. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9790. {
  9791. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9792. if (!Bookmark->Node.IsEmpty())
  9793. {
  9794. Folders->Add(Bookmark->Node);
  9795. }
  9796. }
  9797. for (int Index = 0; Index < Folders->Count; Index++)
  9798. {
  9799. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9800. Item->Caption = Folders->Strings[Index];
  9801. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9802. Folders->Objects[Index] = Item.get();
  9803. Menu->Add(Item.release());
  9804. }
  9805. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9806. {
  9807. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9808. TTBCustomItem * Parent;
  9809. if (!Bookmark->Node.IsEmpty())
  9810. {
  9811. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9812. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9813. }
  9814. else
  9815. {
  9816. Parent = Menu;
  9817. }
  9818. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9819. Item->Caption = Bookmark->Name;
  9820. Item->ShortCut = Bookmark->ShortCut;
  9821. Item->OnClick = OnBookmarkClick;
  9822. Item->Tag = reinterpret_cast<int>(Bookmark);
  9823. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9824. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9825. {
  9826. // No hint for location profiles that are actually mere "bookmarks"
  9827. }
  9828. else
  9829. {
  9830. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9831. UnicodeString LongHint;
  9832. if (!Bookmark->Local.IsEmpty())
  9833. {
  9834. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9835. }
  9836. if (!Bookmark->Remote.IsEmpty())
  9837. {
  9838. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9839. }
  9840. AddToList(Hint, LongHint, L"|");
  9841. Item->Hint = Hint;
  9842. }
  9843. Parent->Add(Item.release());
  9844. }
  9845. }
  9846. AddMenuSeparator(Menu);
  9847. }
  9848. }
  9849. //---------------------------------------------------------------------------
  9850. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9851. {
  9852. Menu->Clear();
  9853. std::unique_ptr<TTBCustomItem> Item;
  9854. Item.reset(new TTBXItem(Owner));
  9855. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9856. Item->Options = Item->Options << tboDefault;
  9857. Menu->Add(Item.release());
  9858. AddMenuSeparator(Menu);
  9859. if (Terminal != NULL)
  9860. {
  9861. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9862. }
  9863. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9864. Item.reset(new TTBXItem(Owner));
  9865. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9866. Menu->Add(Item.release());
  9867. }
  9868. //---------------------------------------------------------------------------
  9869. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9870. {
  9871. bool Result = true;
  9872. bool Remote = !IsSideLocalBrowser(Side);
  9873. try
  9874. {
  9875. if (Remote)
  9876. {
  9877. Terminal->ExceptionOnFail = true;
  9878. }
  9879. try
  9880. {
  9881. DirView(Side)->Path = Path;
  9882. }
  9883. __finally
  9884. {
  9885. if (Remote)
  9886. {
  9887. Terminal->ExceptionOnFail = false;
  9888. }
  9889. }
  9890. }
  9891. catch (Exception & E)
  9892. {
  9893. if (!Remote || Terminal->Active)
  9894. {
  9895. ShowExtendedExceptionEx(Terminal, &E);
  9896. Result = false;
  9897. }
  9898. else
  9899. {
  9900. throw;
  9901. }
  9902. }
  9903. return Result;
  9904. }
  9905. //---------------------------------------------------------------------------
  9906. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9907. {
  9908. // Make sure there some feedback even when loading tiny local folders
  9909. TInstantOperationVisualizer Visualizer;
  9910. DirView(Side)->ReloadDirectory();
  9911. }
  9912. //---------------------------------------------------------------------------
  9913. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9914. {
  9915. if (Index == SessionsPageControl->TabIndex)
  9916. {
  9917. CloseSession();
  9918. }
  9919. else
  9920. {
  9921. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9922. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9923. TTerminalManager * Manager = TTerminalManager::Instance();
  9924. if (!Terminal->Active)
  9925. {
  9926. Manager->FreeTerminal(Terminal);
  9927. }
  9928. else
  9929. {
  9930. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9931. if (CanCloseQueue(Queue))
  9932. {
  9933. Manager->FreeTerminal(Terminal);
  9934. }
  9935. }
  9936. }
  9937. }
  9938. //---------------------------------------------------------------------------
  9939. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9940. {
  9941. CloseSessionTab(Index);
  9942. }
  9943. //---------------------------------------------------------------------------
  9944. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9945. {
  9946. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9947. {
  9948. TInstantOperationVisualizer Visualizer;
  9949. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9950. // before we create a new data object
  9951. ClipboardClear();
  9952. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9953. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9954. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9955. // Intermediate variable to WORKAROUND a crash in compiler
  9956. TObjectList * ClipboardFakeMonitors =
  9957. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9958. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9959. if (FClipboardDragDropFilesEx.get() == NULL)
  9960. {
  9961. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9962. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9963. }
  9964. FClipboardDragDropFilesEx->FileList->Clear();
  9965. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9966. FClipboardDragDropFilesEx->CopyToClipboard();
  9967. FClipboardTerminal = Terminal;
  9968. // Need full paths, as cwd can be different once files are pasted
  9969. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9970. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9971. {
  9972. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9973. }
  9974. }
  9975. }
  9976. //---------------------------------------------------------------------------
  9977. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9978. {
  9979. if (OpenClipboard(0))
  9980. {
  9981. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9982. CloseClipboard();
  9983. }
  9984. }
  9985. //---------------------------------------------------------------------------
  9986. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9987. {
  9988. return !FClipboardFakeDirectory.IsEmpty();
  9989. }
  9990. //---------------------------------------------------------------------------
  9991. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9992. {
  9993. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9994. FClipboardFakeDirectory = UnicodeString();
  9995. FClipboardTerminal = NULL;
  9996. // Also called in Idle()
  9997. FClipboardFakeMonitors.reset(NULL);
  9998. }
  9999. //---------------------------------------------------------------------------
  10000. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10001. {
  10002. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10003. {
  10004. ClipboardStop();
  10005. }
  10006. }
  10007. //---------------------------------------------------------------------------
  10008. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10009. {
  10010. TTerminalManager * Manager = TTerminalManager::Instance();
  10011. Manager->ActiveTerminal = FClipboardTerminal;
  10012. TTransferOperationParam Params;
  10013. Params.TargetDirectory = TargetDirectory;
  10014. Params.DragDrop = DragDrop;
  10015. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10016. }
  10017. //---------------------------------------------------------------------------
  10018. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10019. {
  10020. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10021. // (as it pumps a Windows message queue while being shutted down)
  10022. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10023. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10024. {
  10025. // Can fail as it can be e.g. locked by AV, so we retry that later
  10026. bool Removed = RemoveDir(ApiPath(FileName));
  10027. try
  10028. {
  10029. if (!NonVisualDataModule->Busy)
  10030. {
  10031. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10032. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10033. }
  10034. }
  10035. __finally
  10036. {
  10037. if (!Removed)
  10038. {
  10039. RemoveDir(ApiPath(FileName));
  10040. }
  10041. }
  10042. }
  10043. }
  10044. //---------------------------------------------------------------------------
  10045. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10046. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10047. {
  10048. TFileMasks::TParams MaskParams;
  10049. MaskParams.Size = Size;
  10050. MaskParams.Modification = Modification;
  10051. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10052. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10053. {
  10054. bool ImplicitMatch;
  10055. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10056. !ImplicitMatch)
  10057. {
  10058. Color = Iter->Color;
  10059. break;
  10060. }
  10061. }
  10062. }
  10063. //---------------------------------------------------------------------------
  10064. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10065. {
  10066. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10067. if (!DirView->IsEditing())
  10068. {
  10069. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10070. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10071. // while searching
  10072. if (Key == VK_BACK)
  10073. {
  10074. if (!FIncrementalSearch.IsEmpty())
  10075. {
  10076. if (FIncrementalSearch.Length() == 1)
  10077. {
  10078. ResetIncrementalSearch();
  10079. }
  10080. else
  10081. {
  10082. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10083. IncrementalSearch(NewText, false, false);
  10084. }
  10085. Key = 0;
  10086. }
  10087. }
  10088. }
  10089. }
  10090. //---------------------------------------------------------------------------
  10091. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10092. {
  10093. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10094. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10095. {
  10096. // Filter control sequences.
  10097. // When not searching yet, prefer use of the space for toggling file selection
  10098. // (so we cannot incrementally search for a string starting with a space).
  10099. if ((Key > VK_SPACE) ||
  10100. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10101. {
  10102. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10103. Key = 0;
  10104. }
  10105. }
  10106. }
  10107. //---------------------------------------------------------------------------
  10108. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10109. {
  10110. if (!FIncrementalSearch.IsEmpty())
  10111. {
  10112. FIncrementalSearch = L"";
  10113. DirView(osCurrent)->UpdateStatusBar();
  10114. }
  10115. }
  10116. //---------------------------------------------------------------------------
  10117. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10118. {
  10119. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10120. if (Item == NULL)
  10121. {
  10122. MessageBeep(MB_ICONHAND);
  10123. }
  10124. else
  10125. {
  10126. TCustomDirView * ADirView = DirView(osCurrent);
  10127. {
  10128. TAutoNestingCounter Guard(FIncrementalSearching);
  10129. ADirView->FocusItem(Item);
  10130. if (ADirView->NortonLike == nlOff)
  10131. {
  10132. if ((ADirView->Selected != Item) ||
  10133. (ADirView->SelCount > 1))
  10134. {
  10135. ADirView->ClearSelection();
  10136. ADirView->Selected = Item;
  10137. }
  10138. }
  10139. }
  10140. FIncrementalSearch = Text;
  10141. Item->MakeVisible(false);
  10142. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10143. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10144. ADirView->UpdateStatusBar();
  10145. }
  10146. }
  10147. //---------------------------------------------------------------------------
  10148. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10149. {
  10150. int Index = Item->Index;
  10151. if (!Reverse)
  10152. {
  10153. Index++;
  10154. if (Index >= Item->Owner->Count)
  10155. {
  10156. Index = 0;
  10157. }
  10158. }
  10159. else
  10160. {
  10161. Index--;
  10162. if (Index < 0)
  10163. {
  10164. Index = Item->Owner->Count - 1;
  10165. }
  10166. }
  10167. return Item->Owner->Item[Index];
  10168. }
  10169. //---------------------------------------------------------------------------
  10170. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10171. {
  10172. TCustomDirView * ADirView = DirView(osCurrent);
  10173. if (ADirView->Items->Count == 0)
  10174. {
  10175. return NULL;
  10176. }
  10177. else
  10178. {
  10179. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10180. TListItem * Item = CurrentItem;
  10181. if (SkipCurrent)
  10182. {
  10183. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10184. }
  10185. while (true)
  10186. {
  10187. bool Matches = false;
  10188. switch (WinConfiguration->PanelSearch)
  10189. {
  10190. case isNameStartOnly:
  10191. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10192. break;
  10193. case isName:
  10194. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10195. break;
  10196. case isAll:
  10197. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10198. int Index = 0;
  10199. while ((Index < ColCount) && !Matches)
  10200. {
  10201. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10202. if (Visible)
  10203. {
  10204. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10205. }
  10206. Index++;
  10207. }
  10208. break;
  10209. }
  10210. if (Matches)
  10211. {
  10212. return Item;
  10213. }
  10214. Item = GetNextFile(Item, Reverse);
  10215. if (Item == CurrentItem)
  10216. {
  10217. return NULL;
  10218. }
  10219. }
  10220. }
  10221. }
  10222. //---------------------------------------------------------------------------
  10223. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10224. {
  10225. ResetIncrementalSearch();
  10226. }
  10227. //---------------------------------------------------------------------------
  10228. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10229. {
  10230. if (Message.CharCode == VK_TAB)
  10231. {
  10232. if (!FIncrementalSearch.IsEmpty())
  10233. {
  10234. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10235. bool Reverse = Shift.Contains(ssShift);
  10236. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10237. Message.Result = 1;
  10238. return;
  10239. }
  10240. }
  10241. else if (Message.CharCode == VK_ESCAPE)
  10242. {
  10243. if (!FIncrementalSearch.IsEmpty())
  10244. {
  10245. ResetIncrementalSearch();
  10246. Message.Result = 1;
  10247. return;
  10248. }
  10249. }
  10250. TForm::Dispatch(&Message);
  10251. }
  10252. //---------------------------------------------------------------------------
  10253. void __fastcall TCustomScpExplorerForm::Deactivate()
  10254. {
  10255. TForm::Deactivate();
  10256. // E.g. when switching to an internal editor window
  10257. ResetIncrementalSearch();
  10258. }
  10259. //---------------------------------------------------------------------------
  10260. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10261. {
  10262. // When switching to another application
  10263. ResetIncrementalSearch();
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10267. {
  10268. ResetIncrementalSearch();
  10269. }
  10270. //---------------------------------------------------------------------------
  10271. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10272. {
  10273. if (FIncrementalSearching <= 0)
  10274. {
  10275. ResetIncrementalSearch();
  10276. }
  10277. }
  10278. //---------------------------------------------------------------------------
  10279. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10280. {
  10281. CountClicksForWindowPrint(this);
  10282. }
  10283. //---------------------------------------------------------------------------
  10284. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10285. {
  10286. CenterReconnectToolbar();
  10287. }
  10288. //---------------------------------------------------------------------------
  10289. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10290. {
  10291. if (RemoteDirView->ItemFocused != NULL)
  10292. {
  10293. RemoteDirView->ItemFocused->Selected = true;
  10294. }
  10295. }
  10296. //---------------------------------------------------------------------------
  10297. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10298. {
  10299. if (!FQueueStatusUpdating)
  10300. {
  10301. bool Refresh;
  10302. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10303. {
  10304. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10305. }
  10306. else
  10307. {
  10308. if (FQueueFileList->GetCount() > 0)
  10309. {
  10310. FQueueFileList->Clear();
  10311. Refresh = true;
  10312. }
  10313. }
  10314. int Count = FQueueFileList->GetCount();
  10315. if (QueueFileList->Items->Count != Count)
  10316. {
  10317. DebugAssert(Refresh);
  10318. QueueFileList->Items->Count = Count;
  10319. }
  10320. if (Refresh)
  10321. {
  10322. QueueFileList->Invalidate();
  10323. }
  10324. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10325. }
  10326. }
  10327. //---------------------------------------------------------------------------
  10328. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10329. {
  10330. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10331. }
  10332. //---------------------------------------------------------------------------
  10333. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10334. {
  10335. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10336. // See TSynchronizeChecklistDialog::UpdateTimer
  10337. if (QueueFileList->Items->Count > 0)
  10338. {
  10339. QueueFileList->Items->Item[0]->MakeVisible(false);
  10340. }
  10341. UpdateQueueFileList();
  10342. }
  10343. //---------------------------------------------------------------------------
  10344. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10345. {
  10346. Active = QueueView3->Focused() || QueueFileList->Focused();
  10347. }
  10348. //---------------------------------------------------------------------------
  10349. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10350. {
  10351. QueueLabelUpdateStatus();
  10352. }
  10353. //---------------------------------------------------------------------------
  10354. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10355. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10356. {
  10357. int State = FQueueFileList->GetState(Item->Index);
  10358. if (State == qfsProcessed)
  10359. {
  10360. Sender->Canvas->Font->Color = clGrayText;
  10361. }
  10362. }
  10363. //---------------------------------------------------------------------------
  10364. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10365. {
  10366. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10367. QueueFileList->Column[0]->Width =
  10368. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10369. }
  10370. //---------------------------------------------------------------------------
  10371. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10372. {
  10373. QueueFileListColumnAutoSize();
  10374. }
  10375. //---------------------------------------------------------------------------
  10376. void __fastcall TCustomScpExplorerForm::CloseApp()
  10377. {
  10378. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10379. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10380. // So we clear the flag here.
  10381. DebugAssert(NonVisualDataModule->Busy);
  10382. NonVisualDataModule->EndBusy();
  10383. try
  10384. {
  10385. Close();
  10386. }
  10387. __finally
  10388. {
  10389. NonVisualDataModule->StartBusy();
  10390. }
  10391. }
  10392. //---------------------------------------------------------------------------
  10393. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10394. {
  10395. return (Terminal != NULL) && Terminal->Active;
  10396. }
  10397. //---------------------------------------------------------------------------
  10398. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10399. {
  10400. return IsActiveTerminal(Terminal);
  10401. }
  10402. //---------------------------------------------------------------------------
  10403. void TCustomScpExplorerForm::LocalLocalCopy(
  10404. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10405. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10406. {
  10407. DebugFail();
  10408. }
  10409. //---------------------------------------------------------------------------
  10410. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10411. {
  10412. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10413. }