CustomScpExplorer.cpp 363 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019
  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 = 4;
  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. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if (HasActiveTerminal() &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. HasActiveTerminal() &&
  425. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  429. {
  430. bool Result = Visible && !NonVisualDataModule->Busy;
  431. return Result;
  432. }
  433. //---------------------------------------------------------------------------
  434. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  435. const UnicodeString & CommandLine)
  436. {
  437. TProgramParams Params(CommandLine);
  438. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  439. if (Result)
  440. {
  441. NonVisualDataModule->StartBusy();
  442. try
  443. {
  444. // this action is initiated from another process,
  445. // so it's likely that our window is not visible,
  446. // and user won't see what is going on
  447. Application->BringToFront();
  448. // reload sessions as we may be asked to open a session
  449. // just stored by another instance
  450. StoredSessions->Reload();
  451. UnicodeString SessionName = Params.Param[1];
  452. std::unique_ptr<TObjectList> DataList(new TObjectList());
  453. try
  454. {
  455. UnicodeString DownloadFile; // unused
  456. int Flags = GetCommandLineParseUrlFlags(&Params);
  457. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  458. }
  459. catch (EAbort &)
  460. {
  461. // Happens when opening session in PuTTY and in other situations,
  462. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  463. // to process the command-line on its own (or to pass it to yet another instance)
  464. }
  465. if (DataList->Count > 0)
  466. {
  467. TTerminalManager * Manager = TTerminalManager::Instance();
  468. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  469. }
  470. }
  471. __finally
  472. {
  473. NonVisualDataModule->EndBusy();
  474. }
  475. }
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  480. {
  481. if (FTerminal != value)
  482. {
  483. TerminalChanging();
  484. DoSetTerminal(value, false);
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  489. {
  490. FTerminal = value;
  491. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  492. FAllowTransferPresetAutoSelect = false;
  493. try
  494. {
  495. TerminalChanged(Replace);
  496. }
  497. __finally
  498. {
  499. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  500. }
  501. if (Terminal != NULL)
  502. {
  503. TransferPresetAutoSelect();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  508. {
  509. DoSetTerminal(value, true);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  513. {
  514. if (FTerminal != NULL)
  515. {
  516. UpdateTerminal(Terminal);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  521. {
  522. if (Terminal != NULL)
  523. {
  524. UpdateSessionColor((TColor)Terminal->StateData->Color);
  525. }
  526. DoTerminalListChanged();
  527. DebugAssert(!IsLocalBrowserMode());
  528. if (Replaced)
  529. {
  530. RemoteDirView->ReplaceTerminal(Terminal);
  531. }
  532. else
  533. {
  534. RemoteDirView->Terminal = Terminal;
  535. }
  536. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  537. if (Terminal != NULL)
  538. {
  539. if (Terminal->Active)
  540. {
  541. Terminal->RefreshDirectory();
  542. }
  543. if (WinConfiguration->PreservePanelState)
  544. {
  545. if (Terminal->RemoteExplorerState != NULL)
  546. {
  547. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  548. }
  549. else
  550. {
  551. DirView(osRemote)->ClearState();
  552. }
  553. }
  554. if (!Replaced && Terminal->Active)
  555. {
  556. InitStatusBar();
  557. }
  558. }
  559. UpdateTransferList();
  560. // Update panels Enable state before refreshing the labels
  561. UpdateControls();
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  565. {
  566. if (Queue != value)
  567. {
  568. if (FQueue != NULL)
  569. {
  570. FQueue->OnListUpdate = NULL;
  571. FQueue->OnQueueItemUpdate = NULL;
  572. }
  573. FQueue = value;
  574. if (FQueue != NULL)
  575. {
  576. DebugAssert(FQueue->OnListUpdate == NULL);
  577. FQueue->OnListUpdate = QueueListUpdate;
  578. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  579. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  580. }
  581. QueueChanged();
  582. }
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  586. TListItem * Item)
  587. {
  588. if (FQueueActedItem == Item)
  589. {
  590. FQueueActedItem = NULL;
  591. if ((QueueView3->PopupMenu != NULL) &&
  592. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  593. {
  594. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  595. ReleaseCapture();
  596. }
  597. }
  598. if (Item->Data == FPendingQueueActionItem)
  599. {
  600. FPendingQueueActionItem = NULL;
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. bool TCustomScpExplorerForm::IsAnythingQueued()
  605. {
  606. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  610. {
  611. {
  612. TGuard Guard(FQueueStatusSection);
  613. FQueueStatusInvalidated = false;
  614. if (FQueue != NULL)
  615. {
  616. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  617. }
  618. }
  619. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  620. {
  621. FMaxQueueLength = FQueueStatus->Count;
  622. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  623. }
  624. {
  625. TAutoFlag Flag(FQueueStatusUpdating);
  626. FQueueController->UpdateQueueStatus(FQueueStatus);
  627. }
  628. UpdateQueueFileList();
  629. SetQueueProgress();
  630. UpdateQueueView();
  631. bool IsEmpty = !IsAnythingQueued();
  632. if (IsEmpty && (Terminal != NULL))
  633. {
  634. TOnceDoneOperation OnceDoneOperation =
  635. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  636. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  637. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  638. {
  639. FQueue->Enabled = false;
  640. }
  641. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  642. {
  643. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  649. {
  650. UnicodeString Result;
  651. if (FQueueStatus != NULL)
  652. {
  653. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  654. {
  655. TFileOperationProgressType * ProgressData =
  656. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  657. if ((ProgressData != NULL) && ProgressData->InProgress)
  658. {
  659. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  660. }
  661. }
  662. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  663. {
  664. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  665. }
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  671. {
  672. ComponentVisible[fcQueueView] =
  673. (WinConfiguration->QueueView.Show == qvShow) ||
  674. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  675. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TCustomScpExplorerForm::QueueChanged()
  679. {
  680. if (FQueueStatus != NULL)
  681. {
  682. // UpdateFileList implementation relies on the status being recreated when session changes
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. UpdateQueueFileList();
  774. }
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  779. {
  780. if (FTaskbarList != NULL)
  781. {
  782. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  783. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  784. }
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  788. {
  789. if (Progress >= 0)
  790. {
  791. if (FTaskbarList != NULL)
  792. {
  793. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  803. {
  804. int OverallProgress;
  805. // FProgressForm is null when this is called from SetQueueProgress
  806. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  807. {
  808. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  809. }
  810. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  811. {
  812. OverallProgress = ProgressData->OverallProgress();
  813. }
  814. else
  815. {
  816. OverallProgress = -1;
  817. }
  818. SetTaskbarListProgressValue(OverallProgress);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  822. {
  823. TTerminalManager::Instance()->QueueStatusUpdated();
  824. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  825. {
  826. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  827. {
  828. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  829. {
  830. TFileOperationProgressType * ProgressData = NULL;
  831. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  832. {
  833. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  834. }
  835. if ((ProgressData != NULL) &&
  836. ProgressData->InProgress)
  837. {
  838. SetTaskbarListProgressValue(ProgressData);
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. else
  846. {
  847. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  848. }
  849. }
  850. else
  851. {
  852. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  853. }
  854. }
  855. UpdateQueueLabel();
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  859. {
  860. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  861. if (FQueueStatus != NULL)
  862. {
  863. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  864. if (ActiveAndPendingPrimaryCount > 0)
  865. {
  866. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  867. }
  868. }
  869. QueueLabel->Caption = Caption;
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  873. {
  874. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  875. static_cast<TComponent*>(GetComponent(fcTransferList)));
  876. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  878. TransferList->Strings->BeginUpdate();
  879. try
  880. {
  881. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  882. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  883. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  884. if (FTransferDropDownHint.IsEmpty())
  885. {
  886. FTransferDropDownHint = TransferDropDown->Hint;
  887. }
  888. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  889. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  890. TransferDropDown->Text = StripHotkey(Name);
  891. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  892. (FTransferDropDownHint, StripHotkey(Name),
  893. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  894. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  895. // update the label, otherwise when it is updated only on the first draw
  896. // of the list, it is drawn "bold" for some reason
  897. FTransferListHoverIndex = TransferList->ItemIndex;
  898. UpdateTransferLabel();
  899. }
  900. __finally
  901. {
  902. TransferList->Strings->EndUpdate();
  903. }
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  907. {
  908. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  909. DebugAssert(Toolbar != NULL);
  910. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateActions()
  914. {
  915. TForm::UpdateActions();
  916. if (ComponentVisible[fcCustomCommandsBand])
  917. {
  918. UpdateCustomCommandsToolbar();
  919. }
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  923. {
  924. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  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. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  938. {
  939. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  940. // selection is not redrawn automatically when RowSelect changes
  941. RemoteDirView->Invalidate();
  942. }
  943. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  944. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  945. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  946. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  947. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  948. UpdateSessionsPageControlHeight();
  949. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  950. UpdateToolbarDisplayMode();
  951. UpdateTransferList();
  952. if (Terminal != NULL)
  953. {
  954. TransferPresetAutoSelect();
  955. }
  956. UpdateQueueView();
  957. UpdateControls();
  958. // this can be called even before constuctor finishes.
  959. if (FEditorManager != NULL)
  960. {
  961. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  962. }
  963. // this can be called even before constuctor finishes.
  964. if (FLocalEditors != NULL)
  965. {
  966. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  967. {
  968. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  969. }
  970. }
  971. if (ComponentVisible[fcCustomCommandsBand])
  972. {
  973. UpdateCustomCommandsToolbar();
  974. }
  975. // show only when keeping queue items forever,
  976. // otherwise, its enough to have in in the context menu
  977. QueueDeleteAllDoneQueueToolbarItem->Visible =
  978. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  979. if (FFileColorsCurrent != WinConfiguration->FileColors)
  980. {
  981. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  982. FFileColorsCurrent = WinConfiguration->FileColors;
  983. FileColorsChanged();
  984. }
  985. }
  986. //---------------------------------------------------------------------------
  987. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  988. {
  989. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  990. DirView->Invalidate();
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  994. {
  995. DoFileColorsChanged(RemoteDirView);
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  999. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1000. void * /*Arg*/)
  1001. {
  1002. if (Token != NULL)
  1003. {
  1004. TForm * Editor = dynamic_cast<TForm*>(Token);
  1005. DebugAssert(Editor != NULL);
  1006. ReconfigureEditorForm(Editor);
  1007. }
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1011. {
  1012. WinConfiguration->DDTransferConfirmation = asOn;
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1016. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1017. {
  1018. // noop
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1022. TTransferDirection Direction, TTransferType Type, bool Temp,
  1023. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1024. bool Confirm, bool DragDrop, int Options)
  1025. {
  1026. bool Result = true;
  1027. DebugAssert(HasActiveTerminal());
  1028. // these parameters are known in advance
  1029. int Params =
  1030. FLAGMASK(Type == ttMove, cpDelete);
  1031. bool ToTemp = (Temp && (Direction == tdToLocal));
  1032. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1033. {
  1034. bool DisableNewerOnly =
  1035. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1036. ToTemp;
  1037. Options |=
  1038. FLAGMASK(ToTemp, coTemp) |
  1039. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1040. coDoNotShowAgain;
  1041. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1042. int CopyParamAttrs = (Direction == tdToRemote ?
  1043. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1044. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1045. int OutputOptions =
  1046. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1047. cooDoNotShowAgain);
  1048. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1049. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1050. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1051. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1052. if (Result)
  1053. {
  1054. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1055. {
  1056. if (DragDrop)
  1057. {
  1058. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1059. {
  1060. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1061. NULL, 0, EnableDDTransferConfirmation, NULL);
  1062. }
  1063. WinConfiguration->DDTransferConfirmation = asOff;
  1064. }
  1065. else
  1066. {
  1067. WinConfiguration->ConfirmTransferring = false;
  1068. }
  1069. }
  1070. else
  1071. {
  1072. // User explicitly unchecked "do not show again",
  1073. // so show him the dialog the next time
  1074. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1075. {
  1076. WinConfiguration->DDTransferConfirmation = asOn;
  1077. }
  1078. }
  1079. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1080. }
  1081. }
  1082. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1083. {
  1084. Configuration->Usage->Inc(L"TransfersOnBackground");
  1085. // these parameter are known only after transfer dialog
  1086. Params |=
  1087. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1088. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1089. Result = false;
  1090. ClearTransferSourceSelection(Direction);
  1091. }
  1092. return Result;
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1096. {
  1097. if (FOnFileOperationFinished != NULL)
  1098. {
  1099. FOnFileOperationFinished(UnicodeString(), true);
  1100. }
  1101. else
  1102. {
  1103. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1104. if (HasDirView[Side])
  1105. {
  1106. DirView(Side)->SelectAll(smNone);
  1107. }
  1108. }
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1112. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1113. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1114. int Params)
  1115. {
  1116. DebugAssert(Queue != NULL);
  1117. bool SingleFile = false;
  1118. if (FileList->Count == 1)
  1119. {
  1120. if (Direction == tdToRemote)
  1121. {
  1122. UnicodeString FileName = FileList->Strings[0];
  1123. SingleFile = FileExists(ApiPath(FileName));
  1124. }
  1125. else
  1126. {
  1127. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1128. SingleFile = !File->IsDirectory;
  1129. }
  1130. }
  1131. TQueueItem * QueueItem;
  1132. if (Direction == tdToRemote)
  1133. {
  1134. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1135. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1136. }
  1137. else
  1138. {
  1139. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1140. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1141. }
  1142. AddQueueItem(Queue, QueueItem, Terminal);
  1143. }
  1144. //---------------------------------------------------------------------------
  1145. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1146. {
  1147. if (Queue->IsEmpty)
  1148. {
  1149. Terminal->QueueOperationStart = Now();
  1150. }
  1151. Queue->AddItem(QueueItem);
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1155. {
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TCustomScpExplorerForm::InitControls()
  1159. {
  1160. DebugAssert(FDocks != NULL);
  1161. for (int Index = 0; Index < ComponentCount; Index++)
  1162. {
  1163. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1164. if ((Dock != NULL) && (Dock->Tag == 0))
  1165. {
  1166. FDocks->Add(Dock);
  1167. }
  1168. }
  1169. CollectItemsWithTextDisplayMode(this);
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1173. {
  1174. ConfigurationChanged();
  1175. QueuePanel->Height =
  1176. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1177. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1178. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1179. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1180. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1181. QueueFileList->Height =
  1182. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1183. if (QueueFileList->Visible)
  1184. {
  1185. AdjustQueueLayout();
  1186. }
  1187. UpdateCustomCommandsToolbar();
  1188. }
  1189. //---------------------------------------------------------------------------
  1190. void __fastcall TCustomScpExplorerForm::StoreParams()
  1191. {
  1192. int APixelsPerInch = GetControlPixelsPerInch(this);
  1193. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1194. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1195. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1196. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1197. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1198. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1199. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1200. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1204. {
  1205. if (!FFormRestored)
  1206. {
  1207. FFormRestored = true;
  1208. RestoreFormParams();
  1209. }
  1210. TForm::CreateParams(Params);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1214. {
  1215. DebugAssert(FDocks != NULL);
  1216. for (int Index = 0; Index < FDocks->Count; Index++)
  1217. {
  1218. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1219. }
  1220. }
  1221. //---------------------------------------------------------------------------
  1222. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1223. {
  1224. SetDockAllowDrag(true);
  1225. while (!ButtonsStr.IsEmpty())
  1226. {
  1227. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1228. UnicodeString Name = CutToChar(S, L'=', true);
  1229. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1230. {
  1231. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1232. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1233. {
  1234. while (!S.IsEmpty())
  1235. {
  1236. UnicodeString S2 = CutToChar(S, L',', true);
  1237. UnicodeString Name = CutToChar(S2, L':', true);
  1238. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1239. {
  1240. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1241. if (SameText(GetToolbarItemName(Item), Name))
  1242. {
  1243. // forward compatibility
  1244. UnicodeString S3 = CutToChar(S2, L':', true);
  1245. bool Visible = StrToIntDef(S3, 0);
  1246. Item->Visible = Visible;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1254. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1258. {
  1259. UnicodeString Result;
  1260. SetDockAllowDrag(true);
  1261. Result = ::GetToolbarsLayoutStr(this);
  1262. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1263. return Result;
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1267. {
  1268. UnicodeString Result;
  1269. if (Item->Action != NULL)
  1270. {
  1271. Result = Item->Action->Name;
  1272. Result = RemoveSuffix(Result, L"Action", true);
  1273. }
  1274. else
  1275. {
  1276. Result = Item->Name;
  1277. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1278. Result = RemoveSuffix(Result, L"Item", true);
  1279. }
  1280. return Result;
  1281. }
  1282. //---------------------------------------------------------------------------
  1283. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1284. {
  1285. UnicodeString Result;
  1286. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1287. {
  1288. UnicodeString ToolbarStr;
  1289. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1290. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1291. {
  1292. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1293. {
  1294. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1295. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1296. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1297. // and save the changes here only.
  1298. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1299. {
  1300. UnicodeString Name = GetToolbarItemName(Item);
  1301. DebugAssert(Name.Pos(L"TBX") == 0);
  1302. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1303. }
  1304. }
  1305. }
  1306. if (!ToolbarStr.IsEmpty())
  1307. {
  1308. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1309. }
  1310. }
  1311. return Result;
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1315. {
  1316. DebugAssert(FProgressForm == NULL);
  1317. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1318. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1319. FProgressForm->DeleteLocalToRecycleBin =
  1320. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1321. FProgressForm->DeleteRemoteToRecycleBin =
  1322. (Terminal != NULL) &&
  1323. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1324. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1325. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1326. LockWindow();
  1327. // Actually, do not know what hides the progress once the operation finishes
  1328. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1329. SetTaskbarListProgressState(TBPF_NORMAL);
  1330. }
  1331. //---------------------------------------------------------------------------
  1332. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1333. {
  1334. UnlockWindow();
  1335. SAFE_DESTROY(FProgressForm);
  1336. SetQueueProgress();
  1337. }
  1338. //---------------------------------------------------------------------------
  1339. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1340. TFileOperationProgressType & ProgressData)
  1341. {
  1342. // Download to temporary local directory
  1343. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1344. {
  1345. bool Continue = true;
  1346. FPendingTempSpaceWarn = false;
  1347. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1348. if (!Continue)
  1349. {
  1350. Abort();
  1351. }
  1352. }
  1353. // operation is being executed and we still didn't show up progress form
  1354. if (ProgressData.InProgress && !FProgressForm)
  1355. {
  1356. CreateProgressForm(NULL);
  1357. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1358. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1359. }
  1360. // operation is finished (or terminated), so we hide progress form
  1361. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1362. {
  1363. DestroyProgressForm();
  1364. if (ProgressData.Operation == foCalculateSize)
  1365. {
  1366. // When calculating size before transfer, the abort caused by
  1367. // cancel flag set due to "MoveToQueue" below,
  1368. // is not propagated back to us in ExecuteFileOperation,
  1369. // as it is silently swallowed.
  1370. // So we explicitly (re)throw it here.
  1371. if (FMoveToQueue)
  1372. {
  1373. Abort();
  1374. }
  1375. }
  1376. else
  1377. {
  1378. if ((ProgressData.Cancel == csContinue) &&
  1379. !FAutoOperation)
  1380. {
  1381. OperationComplete(ProgressData.StartTime);
  1382. }
  1383. }
  1384. }
  1385. if (FProgressForm &&
  1386. // Can happen only during synchronization, when ending one of the operations
  1387. ProgressData.InProgress)
  1388. {
  1389. FProgressForm->SetProgressData(ProgressData);
  1390. DebugAssert(ProgressData.InProgress);
  1391. SetTaskbarListProgressValue(&ProgressData);
  1392. if (FProgressForm->Cancel > csContinue)
  1393. {
  1394. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1395. if (FProgressForm->Cancel == csCancelFile)
  1396. {
  1397. FProgressForm->ClearCancel();
  1398. }
  1399. // cancel cancels even the move
  1400. FMoveToQueue = false;
  1401. }
  1402. else if (FProgressForm->MoveToQueue)
  1403. {
  1404. FMoveToQueue = true;
  1405. ProgressData.SetCancelAtLeast(csCancel);
  1406. }
  1407. if ((FTransferResumeList != NULL) &&
  1408. ProgressData.InProgress &&
  1409. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1410. !ProgressData.FullFileName.IsEmpty())
  1411. {
  1412. if ((FTransferResumeList->Count == 0) ||
  1413. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1414. {
  1415. // note that we do not recognize directories from files here
  1416. FTransferResumeList->Add(ProgressData.FullFileName);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1423. const TDateTime & StartTime)
  1424. {
  1425. if (GUIConfiguration->BeepOnFinish &&
  1426. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1427. {
  1428. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1429. DWORD Sound;
  1430. if (!ExtractFileExt(BeepSound).IsEmpty())
  1431. {
  1432. Sound = SND_FILENAME;
  1433. }
  1434. else
  1435. {
  1436. Sound = SND_ALIAS;
  1437. }
  1438. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1439. }
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1443. TFileOperationProgressType & ProgressData)
  1444. {
  1445. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1446. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1447. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1448. FileOperationProgress(ProgressData);
  1449. }
  1450. //---------------------------------------------------------------------------
  1451. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1452. {
  1453. UnicodeString Result;
  1454. if (FProgressForm != NULL)
  1455. {
  1456. Result = FProgressForm->ProgressStr();
  1457. }
  1458. return Result;
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1462. bool DragDrop)
  1463. {
  1464. return (!DragDrop && (DropSourceControl == NULL)) ||
  1465. (DropSourceControl == DirView(osOther));
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1469. TFileOperation Operation, TOperationSide Side,
  1470. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1471. TOnceDoneOperation & OnceDoneOperation)
  1472. {
  1473. if (!FAutoOperation)
  1474. {
  1475. // no selection on "/upload", form serves only as event handler
  1476. // (it is not displayed)
  1477. if (PanelOperation(Side, FDragDropOperation) &&
  1478. Visible && (Operation != foCalculateSize) &&
  1479. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1480. {
  1481. if (FOnFileOperationFinished != NULL)
  1482. {
  1483. FOnFileOperationFinished(FileName, Success);
  1484. }
  1485. else
  1486. {
  1487. TCustomDirView * DView = DirView(Side);
  1488. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1489. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1490. // this can happen when local drive is unplugged in the middle of the operation
  1491. if (Item != NULL)
  1492. {
  1493. if (Success) Item->Selected = false;
  1494. DView->MakeProgressVisible(Item);
  1495. }
  1496. }
  1497. }
  1498. if ((Operation == foCopy) || (Operation == foMove))
  1499. {
  1500. DebugAssert(!IsLocalBrowserMode());
  1501. if (Side == osLocal)
  1502. {
  1503. Configuration->Usage->Inc(L"UploadedFiles");
  1504. }
  1505. else
  1506. {
  1507. Configuration->Usage->Inc(L"DownloadedFiles");
  1508. }
  1509. }
  1510. }
  1511. if (Success && (FSynchronizeController != NULL))
  1512. {
  1513. DebugAssert(!IsSideLocalBrowser(osRemote));
  1514. if (Operation == foCopy)
  1515. {
  1516. DebugAssert(Side == osLocal);
  1517. FSynchronizeController->LogOperation(soUpload, FileName);
  1518. }
  1519. else if (Operation == foDelete)
  1520. {
  1521. DebugAssert(Side == osRemote);
  1522. FSynchronizeController->LogOperation(soDelete, FileName);
  1523. }
  1524. }
  1525. if (FProgressForm)
  1526. {
  1527. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1528. }
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1532. TFileOperation Operation, TOperationSide Side,
  1533. bool Temp, const UnicodeString & FileName, Boolean Success,
  1534. TOnceDoneOperation & OnceDoneOperation)
  1535. {
  1536. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1537. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1538. OnceDoneOperation);
  1539. }
  1540. //---------------------------------------------------------------------------
  1541. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1542. {
  1543. return false;
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1547. {
  1548. return false;
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1552. {
  1553. return NULL;
  1554. }
  1555. //---------------------------------------------------------------------------
  1556. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1557. {
  1558. DebugAssert(GetSide(Side) == osRemote);
  1559. DebugUsedParam(Side);
  1560. return RemoteDirView;
  1561. }
  1562. //---------------------------------------------------------------------------
  1563. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1564. {
  1565. DebugAssert(GetSide(Side) == osRemote);
  1566. DebugUsedParam(Side);
  1567. return RemoteDriveView;
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1571. {
  1572. DebugAssert(GetSide(Side) == osRemote);
  1573. DebugUsedParam(Side);
  1574. return HasActiveTerminal();
  1575. }
  1576. //---------------------------------------------------------------------------
  1577. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1578. TOperationSide Side, int FilesOnly)
  1579. {
  1580. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1584. TOperationSide Side, int FilesOnly)
  1585. {
  1586. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. struct THistoryItemData
  1590. {
  1591. short int Side;
  1592. short int Index;
  1593. };
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1596. {
  1597. DirView(Side)->HistoryGo(Index);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1601. {
  1602. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1603. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1604. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1608. bool Back)
  1609. {
  1610. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1611. {
  1612. TCustomDirView * DView = DirView(Side);
  1613. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1614. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1615. if (ICount > 10)
  1616. {
  1617. ICount = 10;
  1618. }
  1619. Menu->Items->Clear();
  1620. THistoryItemData Data;
  1621. Data.Side = Side;
  1622. for (short int i = 1; i <= ICount; i++)
  1623. {
  1624. TTBCustomItem * Item = new TTBXItem(Menu);
  1625. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1626. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1627. Item->Hint = DView->HistoryPath[Data.Index];
  1628. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1629. Item->Tag = *reinterpret_cast<int*>(&Data);
  1630. Item->OnClick = HistoryItemClick;
  1631. Menu->Items->Add(Item);
  1632. }
  1633. }
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1637. TOperationSide Side, bool Back)
  1638. {
  1639. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1640. {
  1641. // workaround
  1642. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1643. // operator new allocates memory in Pascal code, but calls inline
  1644. // contructor in C++, leading in problems, the function does
  1645. // both in Pascal code
  1646. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1647. UpdateHistoryMenu(Side, Back);
  1648. }
  1649. return FHistoryMenu[Side == osLocal][Back];
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1653. TCustomDirView *Sender)
  1654. {
  1655. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1656. UpdateHistoryMenu(Side, true);
  1657. UpdateHistoryMenu(Side, false);
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1661. {
  1662. // remote custom commands can be executed only if the server supports shell commands
  1663. // or have secondary shell
  1664. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1668. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1669. {
  1670. // -1 = hidden, 0 = disabled, 1 = enabled
  1671. int Result;
  1672. TFileCustomCommand RemoteCustomCommand;
  1673. TLocalCustomCommand LocalCustomCommand;
  1674. TFileCustomCommand * NonInteractiveCustomCommand =
  1675. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1676. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1677. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1678. if (FLAGCLEAR(Command.Params, ccLocal))
  1679. {
  1680. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1681. // custom command that does not operate with files can be executed anytime ...
  1682. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1683. {
  1684. // ... but do not show such command in remote file menu
  1685. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1686. {
  1687. Result = AllowedState;
  1688. }
  1689. else
  1690. {
  1691. Result = -1;
  1692. }
  1693. }
  1694. else
  1695. {
  1696. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1697. {
  1698. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1699. }
  1700. else
  1701. {
  1702. Result = -1;
  1703. }
  1704. }
  1705. }
  1706. else
  1707. {
  1708. // custom command that does not operate with files can be executed anytime
  1709. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1710. {
  1711. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1712. }
  1713. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1714. {
  1715. if ((ListType == ccltAll) || (ListType == ccltFile))
  1716. {
  1717. // special case is "diff"-style command that can be executed over any side,
  1718. // if we have both sides
  1719. Result =
  1720. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1721. // directly (instead of EnableSelectedOperation) to pass
  1722. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1723. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1724. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1725. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1726. }
  1727. else if (ListType == ccltBoth)
  1728. {
  1729. DebugAssert(!IsLocalBrowserMode());
  1730. Result = 1;
  1731. }
  1732. else
  1733. {
  1734. Result = -1;
  1735. }
  1736. }
  1737. else
  1738. {
  1739. if ((ListType == ccltAll) ||
  1740. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1741. {
  1742. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1743. }
  1744. else
  1745. {
  1746. Result = -1;
  1747. }
  1748. }
  1749. if ((Result > 0) &&
  1750. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1751. !HasActiveTerminal())
  1752. {
  1753. Result = 0;
  1754. }
  1755. }
  1756. return Result;
  1757. }
  1758. //---------------------------------------------------------------------------
  1759. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1760. TStrings * FileList, const TCustomCommandType & ACommand,
  1761. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1762. {
  1763. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1764. {
  1765. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1766. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1767. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1768. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1769. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1770. bool Capture =
  1771. FLAGSET(ACommand.Params, ccShowResults) ||
  1772. FLAGSET(ACommand.Params, ccCopyResults) ||
  1773. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1774. TCaptureOutputEvent OutputEvent = NULL;
  1775. DebugAssert(FCapturedLog == NULL);
  1776. if (Capture)
  1777. {
  1778. FCapturedLog = new TStringList();
  1779. OutputEvent = TerminalCaptureLog;
  1780. }
  1781. try
  1782. {
  1783. if (!RemoteCustomCommand.IsFileCommand(Command))
  1784. {
  1785. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1786. OutputEvent);
  1787. }
  1788. else
  1789. {
  1790. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1791. }
  1792. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1793. {
  1794. if (FLAGSET(ACommand.Params, ccCopyResults))
  1795. {
  1796. CopyToClipboard(FCapturedLog);
  1797. }
  1798. if (FLAGSET(ACommand.Params, ccShowResults))
  1799. {
  1800. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1801. }
  1802. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1803. {
  1804. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1805. }
  1806. }
  1807. }
  1808. __finally
  1809. {
  1810. SAFE_DESTROY(FCapturedLog);
  1811. }
  1812. }
  1813. }
  1814. //---------------------------------------------------------------------------
  1815. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1816. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1817. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1818. {
  1819. DebugAssert(!IsLocalBrowserMode());
  1820. TStrings * LocalFileList = NULL;
  1821. TStrings * RemoteFileList = NULL;
  1822. TStrings * RemoteFileListFull = NULL;
  1823. try
  1824. {
  1825. if (LocalFileCommand)
  1826. {
  1827. if (ALocalFileList == NULL)
  1828. {
  1829. DebugAssert(HasDirView[osLocal]);
  1830. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1831. // directly (instead of EnableSelectedOperation) to pass
  1832. // false to FocusedFileOnlyWhenFocused
  1833. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1834. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1835. }
  1836. else
  1837. {
  1838. LocalFileList = ALocalFileList;
  1839. }
  1840. if (FileListCommand)
  1841. {
  1842. if (LocalFileList->Count != 1)
  1843. {
  1844. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1845. }
  1846. }
  1847. else
  1848. {
  1849. if ((LocalFileList->Count != 1) &&
  1850. (FileList->Count != 1) &&
  1851. (LocalFileList->Count != FileList->Count))
  1852. {
  1853. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1854. }
  1855. }
  1856. }
  1857. UnicodeString RootTempDir;
  1858. UnicodeString TempDir;
  1859. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1860. if (!RemoteFiles)
  1861. {
  1862. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1863. }
  1864. try
  1865. {
  1866. TDateTimes RemoteFileTimes;
  1867. if (RemoteFiles)
  1868. {
  1869. RemoteFileList = FileList;
  1870. }
  1871. else
  1872. {
  1873. RemoteFileList = new TStringList();
  1874. TMakeLocalFileListParams MakeFileListParam;
  1875. MakeFileListParam.FileList = RemoteFileList;
  1876. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1877. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1878. MakeFileListParam.Recursive =
  1879. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1880. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1881. if (!MakeFileListParam.Recursive)
  1882. {
  1883. RemoteFileTimes.clear();
  1884. RemoteFileListFull = new TStringList();
  1885. MakeFileListParam.FileList = RemoteFileListFull;
  1886. MakeFileListParam.Recursive = true;
  1887. MakeFileListParam.IncludeDirs = false;
  1888. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1889. }
  1890. else
  1891. {
  1892. RemoteFileListFull = RemoteFileList;
  1893. }
  1894. }
  1895. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1896. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1897. if (!NonBlocking)
  1898. {
  1899. int Count;
  1900. if (FileListCommand)
  1901. {
  1902. Count = 1;
  1903. }
  1904. else if (LocalFileCommand)
  1905. {
  1906. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1907. }
  1908. else
  1909. {
  1910. Count = RemoteFileList->Count;
  1911. }
  1912. Progress.Start(foCustomCommand, osRemote, Count);
  1913. DebugAssert(FProgressForm != NULL);
  1914. FProgressForm->ReadOnly = true;
  1915. }
  1916. try
  1917. {
  1918. if (FileListCommand)
  1919. {
  1920. UnicodeString LocalFile;
  1921. // MakeFileList does not delimit filenames
  1922. UnicodeString FileList = MakeFileList(RemoteFileList);
  1923. if (LocalFileCommand)
  1924. {
  1925. DebugAssert(LocalFileList->Count == 1);
  1926. LocalFile = LocalFileList->Strings[0];
  1927. }
  1928. TLocalCustomCommand CustomCommand(Data,
  1929. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1930. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1931. if (NonBlocking)
  1932. {
  1933. DebugAssert(!POutput);
  1934. ExecuteShellChecked(ShellCommand);
  1935. }
  1936. else
  1937. {
  1938. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1939. }
  1940. }
  1941. else if (LocalFileCommand)
  1942. {
  1943. if (LocalFileList->Count == 1)
  1944. {
  1945. UnicodeString LocalFile = LocalFileList->Strings[0];
  1946. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1947. {
  1948. UnicodeString FileName = RemoteFileList->Strings[Index];
  1949. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1950. Progress.SetFile(FileNameForProgress);
  1951. TLocalCustomCommand CustomCommand(Data,
  1952. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1953. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1954. TOnceDoneOperation OnceDoneOperation;
  1955. // Do not unselect anything, as it won't work with two panels anyway
  1956. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1957. }
  1958. }
  1959. else if (RemoteFileList->Count == 1)
  1960. {
  1961. UnicodeString FileName = RemoteFileList->Strings[0];
  1962. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1963. {
  1964. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1965. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1966. Progress.SetFile(LocalFileNameOnly);
  1967. TLocalCustomCommand CustomCommand(
  1968. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1969. FileName, LocalFileName, L"");
  1970. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1971. TOnceDoneOperation OnceDoneOperation;
  1972. // Do not unselect anything, as it won't work with two panels anyway
  1973. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1974. }
  1975. }
  1976. else
  1977. {
  1978. if (LocalFileList->Count != RemoteFileList->Count)
  1979. {
  1980. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1981. }
  1982. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1983. {
  1984. UnicodeString FileName = RemoteFileList->Strings[Index];
  1985. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1986. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1987. Progress.SetFile(LocalFileNameOnly); // sic
  1988. TLocalCustomCommand CustomCommand(
  1989. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1990. FileName, LocalFileName, L"");
  1991. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1992. TOnceDoneOperation OnceDoneOperation;
  1993. // Do not unselect anything, as it won't work with two panels anyway
  1994. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1995. }
  1996. }
  1997. }
  1998. else
  1999. {
  2000. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2001. {
  2002. UnicodeString FileName = RemoteFileList->Strings[Index];
  2003. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2004. Progress.SetFile(FileNameForProgress);
  2005. TLocalCustomCommand CustomCommand(Data,
  2006. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2007. FileName, L"", L"");
  2008. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2009. TOnceDoneOperation OnceDoneOperation;
  2010. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2011. }
  2012. }
  2013. }
  2014. __finally
  2015. {
  2016. if (!NonBlocking)
  2017. {
  2018. Progress.Stop();
  2019. }
  2020. }
  2021. DebugAssert(!FAutoOperation);
  2022. if (!RemoteFiles)
  2023. {
  2024. TempDir = IncludeTrailingBackslash(TempDir);
  2025. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2026. {
  2027. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2028. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2029. // Skip directories, process only nested files.
  2030. // The check is redundant as FileAge fails for directories anyway.
  2031. !DirectoryExists(FileName))
  2032. {
  2033. UnicodeString RemoteDir =
  2034. UnixExtractFileDir(
  2035. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2036. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2037. TDateTime NewTime;
  2038. if (FileAge(FileName, NewTime) &&
  2039. (NewTime != RemoteFileTimes[Index]))
  2040. {
  2041. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2042. TemporaryFileCopyParam(CopyParam);
  2043. CopyParam.FileMask = L"";
  2044. FAutoOperation = true;
  2045. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2046. TemporaryFilesList->Add(FileName);
  2047. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. __finally
  2054. {
  2055. FAutoOperation = false;
  2056. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2057. {
  2058. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2059. }
  2060. }
  2061. }
  2062. __finally
  2063. {
  2064. if (RemoteFileList != FileList)
  2065. {
  2066. delete RemoteFileList;
  2067. }
  2068. if (LocalFileList != ALocalFileList)
  2069. {
  2070. delete LocalFileList;
  2071. }
  2072. if (RemoteFileListFull != RemoteFileList)
  2073. {
  2074. delete RemoteFileListFull;
  2075. }
  2076. }
  2077. }
  2078. //---------------------------------------------------------------------------
  2079. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2080. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2081. bool FileListCommand, UnicodeString * POutput)
  2082. {
  2083. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2084. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2085. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2086. {
  2087. UnicodeString FileName = SelectedFileList->Strings[Index];
  2088. if (DirectoryExists(FileName))
  2089. {
  2090. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2091. {
  2092. LocalFileList->Add(FileName);
  2093. }
  2094. if (FLAGSET(ACommand.Params, ccRecursive))
  2095. {
  2096. TMakeLocalFileListParams MakeFileListParam;
  2097. MakeFileListParam.FileList = LocalFileList.get();
  2098. MakeFileListParam.FileTimes = NULL;
  2099. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2100. MakeFileListParam.Recursive = true;
  2101. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2102. }
  2103. }
  2104. else
  2105. {
  2106. LocalFileList->Add(FileName);
  2107. }
  2108. }
  2109. UnicodeString RemotePath;
  2110. if (Terminal != NULL)
  2111. {
  2112. RemotePath = Terminal->CurrentDirectory;
  2113. }
  2114. if (FileListCommand)
  2115. {
  2116. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2117. TLocalCustomCommand CustomCommand(
  2118. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2119. L"", L"", FileList);
  2120. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2121. }
  2122. else
  2123. {
  2124. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2125. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2126. DebugAssert(FProgressForm != NULL);
  2127. FProgressForm->ReadOnly = true;
  2128. try
  2129. {
  2130. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2131. {
  2132. UnicodeString FileName = LocalFileList->Strings[Index];
  2133. Progress.SetFile(FileName);
  2134. TLocalCustomCommand CustomCommand(
  2135. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2136. FileName, L"", L"");
  2137. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2138. TOnceDoneOperation OnceDoneOperation;
  2139. Progress.Finish(FileName, true, OnceDoneOperation);
  2140. }
  2141. }
  2142. __finally
  2143. {
  2144. Progress.Stop();
  2145. }
  2146. }
  2147. }
  2148. //---------------------------------------------------------------------------
  2149. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2150. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2151. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2152. {
  2153. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2154. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2155. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2156. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2157. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2158. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2159. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2160. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2161. std::unique_ptr<UnicodeString> POutput;
  2162. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2163. FLAGSET(ACommand.Params, ccCopyResults))
  2164. {
  2165. POutput.reset(new UnicodeString());
  2166. }
  2167. if (!LocalCustomCommand.IsFileCommand(Command))
  2168. {
  2169. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2170. }
  2171. // remote files?
  2172. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2173. {
  2174. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2175. }
  2176. // local files
  2177. else
  2178. {
  2179. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2180. }
  2181. if (POutput.get() != NULL)
  2182. {
  2183. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2184. int P = POutput->Pos(sLineBreak);
  2185. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2186. {
  2187. POutput->SetLength(P - 1);
  2188. }
  2189. // Copy even empty output to clipboard
  2190. if (FLAGSET(ACommand.Params, ccCopyResults))
  2191. {
  2192. CopyToClipboard(*POutput);
  2193. }
  2194. // But do not show an empty message box.
  2195. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2196. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2197. !POutput->IsEmpty())
  2198. {
  2199. TClipboardHandler ClipboardHandler;
  2200. ClipboardHandler.Text = *POutput;
  2201. TMessageParams Params;
  2202. TQueryButtonAlias Aliases[1];
  2203. Aliases[0].Button = qaRetry;
  2204. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2205. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2206. Params.Aliases = Aliases;
  2207. Params.AliasesCount = LENOF(Aliases);
  2208. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2209. }
  2210. }
  2211. }
  2212. //---------------------------------------------------------------------------
  2213. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2214. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2215. {
  2216. TCustomCommandData Data;
  2217. UnicodeString Site;
  2218. UnicodeString RemotePath;
  2219. if (HasActiveTerminal())
  2220. {
  2221. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2222. Data = TCustomCommandData(SessionData.get());
  2223. Site = Terminal->SessionData->SessionKey;
  2224. RemotePath = Terminal->CurrentDirectory;
  2225. }
  2226. UnicodeString HelpKeyword = ACommand.HomePage;
  2227. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2228. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2229. {
  2230. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2231. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2232. {
  2233. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2234. }
  2235. else
  2236. {
  2237. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2238. }
  2239. if (!DoCustomCommandOptionsDialog(
  2240. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2241. {
  2242. Abort();
  2243. }
  2244. }
  2245. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2246. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2247. {
  2248. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2249. }
  2250. else
  2251. {
  2252. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2253. }
  2254. }
  2255. //---------------------------------------------------------------------------
  2256. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2257. const TCustomCommandType & Command)
  2258. {
  2259. DebugAssert(FCustomCommandLocalFileList != NULL);
  2260. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2261. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2262. TStrings * LocalFileList = new TStringList();
  2263. TStrings * RemoteFileList = new TStringList();
  2264. try
  2265. {
  2266. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2267. {
  2268. LocalFileList->Clear();
  2269. LocalFileList->AddObject(
  2270. FCustomCommandLocalFileList->Strings[Index],
  2271. FCustomCommandLocalFileList->Objects[Index]);
  2272. RemoteFileList->Clear();
  2273. RemoteFileList->AddObject(
  2274. FCustomCommandRemoteFileList->Strings[Index],
  2275. FCustomCommandRemoteFileList->Objects[Index]);
  2276. CustomCommand(RemoteFileList, Command, LocalFileList);
  2277. }
  2278. }
  2279. __finally
  2280. {
  2281. delete LocalFileList;
  2282. delete RemoteFileList;
  2283. }
  2284. }
  2285. //---------------------------------------------------------------------------
  2286. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2287. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2288. {
  2289. delete FCustomCommandLocalFileList;
  2290. delete FCustomCommandRemoteFileList;
  2291. // takeover ownership,
  2292. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2293. FCustomCommandLocalFileList = LocalFileList;
  2294. FCustomCommandRemoteFileList = RemoteFileList;
  2295. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2296. if (Button != NULL)
  2297. {
  2298. FCustomCommandMenu->Items->Clear();
  2299. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2300. MenuPopup(FCustomCommandMenu, Button);
  2301. }
  2302. else
  2303. {
  2304. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2305. }
  2306. }
  2307. //---------------------------------------------------------------------------
  2308. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2309. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2310. {
  2311. DebugAssert(FCapturedLog != NULL);
  2312. if ((OutputType == cotOutput) || (OutputType == cotError))
  2313. {
  2314. FCapturedLog->Add(AddedLine);
  2315. }
  2316. }
  2317. //---------------------------------------------------------------------------
  2318. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2319. TOperationSide Side)
  2320. {
  2321. return
  2322. (Side == osOther) &&
  2323. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2327. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2328. {
  2329. TTBItemOptions O;
  2330. O = Item->Options;
  2331. TCustomDirView * DView = DirView(Side);
  2332. if ((DView->ItemFocused != NULL) &&
  2333. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2334. // when resolving links is disabled, default action is to enter the directory,
  2335. // no matter what DoubleClickAction is configured to
  2336. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2337. // Can only Edit files, but can Open/Copy even directories
  2338. ((DoubleClickAction != dcaEdit) ||
  2339. !DView->ItemIsDirectory(DView->ItemFocused)))
  2340. {
  2341. Item->Options = O << tboDefault;
  2342. }
  2343. else
  2344. {
  2345. Item->Options = O >> tboDefault;
  2346. }
  2347. }
  2348. //---------------------------------------------------------------------------
  2349. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2350. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2351. {
  2352. TCustomDirView * DView = DirView(Side);
  2353. TListItem * Item = DView->ItemFocused;
  2354. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2355. EnableFocusedOperation[Side])
  2356. {
  2357. TPoint ClientPoint;
  2358. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2359. TPoint(0, 0) : MousePos;
  2360. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2361. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2362. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2363. }
  2364. }
  2365. //---------------------------------------------------------------------------
  2366. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2367. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2368. {
  2369. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2370. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2371. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2372. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2373. Handled = true;
  2374. }
  2375. //---------------------------------------------------------------------------
  2376. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2377. {
  2378. }
  2379. //---------------------------------------------------------------------------
  2380. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2381. {
  2382. DebugAssert(FErrorList == NULL);
  2383. if (WinConfiguration->ContinueOnError)
  2384. {
  2385. FErrorList = new TStringList();
  2386. Configuration->Usage->Inc(L"ContinuationsOnError");
  2387. }
  2388. NonVisualDataModule->StartBusy();
  2389. }
  2390. //---------------------------------------------------------------------------
  2391. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2392. {
  2393. NonVisualDataModule->EndBusy();
  2394. if (FErrorList)
  2395. {
  2396. HandleErrorList(FErrorList);
  2397. }
  2398. }
  2399. //---------------------------------------------------------------------------
  2400. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2401. const TCopyParamType & CopyParam)
  2402. {
  2403. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2404. {
  2405. Configuration->Usage->Inc(L"FileMaskUses");
  2406. }
  2407. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2408. {
  2409. Configuration->Usage->Inc(L"OperationMaskUses");
  2410. }
  2411. }
  2412. //---------------------------------------------------------------------------
  2413. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2414. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2415. {
  2416. DebugAssert(!IsLocalBrowserMode());
  2417. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2418. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2419. TTransferOperationParam DefaultParam;
  2420. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2421. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2422. switch (Param.Queue)
  2423. {
  2424. case asOn:
  2425. CopyParam.Queue = true;
  2426. break;
  2427. case asOff:
  2428. CopyParam.Queue = false;
  2429. break;
  2430. case asAuto:
  2431. default:
  2432. // keep default
  2433. break;
  2434. }
  2435. bool Result =
  2436. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2437. if (Result)
  2438. {
  2439. DebugAssert(Terminal);
  2440. bool SelectionRestored = false;
  2441. TCustomDirView * DView = NULL;
  2442. if (HasDirView[Side])
  2443. {
  2444. DView = DirView(Side);
  2445. DView->SaveSelection();
  2446. DView->SaveSelectedNames();
  2447. }
  2448. UpdateCopyParamCounters(CopyParam);
  2449. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2450. DebugAssert(FTransferResumeList == NULL);
  2451. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2452. FMoveToQueue = false;
  2453. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2454. try
  2455. {
  2456. TStrings * PermanentFileList;
  2457. std::unique_ptr<TStrings> PermanentFileListOwner;
  2458. try
  2459. {
  2460. if (Side == osLocal)
  2461. {
  2462. PermanentFileList = FileList;
  2463. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2464. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2465. if (Operation == foMove)
  2466. {
  2467. ReloadLocalDirectory();
  2468. if (DView != NULL)
  2469. {
  2470. DView->RestoreSelection();
  2471. }
  2472. SelectionRestored = true;
  2473. }
  2474. }
  2475. else
  2476. {
  2477. // Clone the file list as it may refer to current directory files,
  2478. // which get destroyed, when the source directory is reloaded after foMove operation.
  2479. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2480. // But for a hotfix, we are not going to do such a big change.
  2481. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2482. PermanentFileList = PermanentFileListOwner.get();
  2483. try
  2484. {
  2485. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2486. }
  2487. __finally
  2488. {
  2489. if (Operation == foMove)
  2490. {
  2491. if (DView != NULL)
  2492. {
  2493. DView->RestoreSelection();
  2494. }
  2495. SelectionRestored = true;
  2496. }
  2497. ReloadLocalDirectory(Param.TargetDirectory);
  2498. }
  2499. }
  2500. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2501. if (FMoveToQueue)
  2502. {
  2503. Abort();
  2504. }
  2505. }
  2506. catch (EAbort &)
  2507. {
  2508. if (FMoveToQueue)
  2509. {
  2510. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2511. DebugAssert(CopyParam.TransferSkipList == NULL);
  2512. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2513. if (TransferResumeList->Count > 0)
  2514. {
  2515. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2516. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2517. }
  2518. CopyParam.TransferSkipList = TransferResumeList.release();
  2519. // not really needed, just to keep it consistent with TransferResumeList
  2520. FTransferResumeList = NULL;
  2521. FMoveToQueue = false;
  2522. Configuration->Usage->Inc("MovesToBackground");
  2523. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2524. ClearTransferSourceSelection(Direction);
  2525. }
  2526. throw;
  2527. }
  2528. }
  2529. __finally
  2530. {
  2531. if (!SelectionRestored && (DView != NULL))
  2532. {
  2533. DView->DiscardSavedSelection();
  2534. }
  2535. FTransferResumeList = NULL;
  2536. }
  2537. }
  2538. return Result;
  2539. }
  2540. //---------------------------------------------------------------------------
  2541. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2542. TOperationSide Side, TStrings * FileList, void * Param)
  2543. {
  2544. DebugAssert(FileList->Count);
  2545. // We deliberately do not toggle alternative flag (Param), but use OR,
  2546. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2547. // shortcut of CurrentDeleteAlternativeAction
  2548. bool Alternative =
  2549. bool(Param) || UseAlternativeFunction();
  2550. bool Recycle;
  2551. if (IsSideLocalBrowser(Side))
  2552. {
  2553. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2554. }
  2555. else
  2556. {
  2557. Recycle =
  2558. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2559. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2560. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2561. }
  2562. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2563. if (!Result)
  2564. {
  2565. UnicodeString Query;
  2566. if (FileList->Count == 1)
  2567. {
  2568. if (IsSideLocalBrowser(Side))
  2569. {
  2570. Query = ExtractFileName(FileList->Strings[0]);
  2571. }
  2572. else
  2573. {
  2574. Query = UnixExtractFileName(FileList->Strings[0]);
  2575. }
  2576. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2577. }
  2578. else
  2579. {
  2580. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2581. }
  2582. TMessageParams Params(mpNeverAskAgainCheck);
  2583. Params.ImageName = L"Delete file";
  2584. unsigned int Answer =
  2585. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2586. if (Answer == qaNeverAskAgain)
  2587. {
  2588. Result = true;
  2589. if (Recycle)
  2590. {
  2591. WinConfiguration->ConfirmRecycling = false;
  2592. }
  2593. else
  2594. {
  2595. WinConfiguration->ConfirmDeleting = false;
  2596. }
  2597. }
  2598. else
  2599. {
  2600. Result = (Answer == qaOK);
  2601. }
  2602. }
  2603. if (Result)
  2604. {
  2605. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2606. }
  2607. return Result;
  2608. }
  2609. //---------------------------------------------------------------------------
  2610. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2611. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2612. {
  2613. TAutoBatch AutoBatch(this);
  2614. bool Result;
  2615. if ((Operation == foCopy) || (Operation == foMove))
  2616. {
  2617. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2618. }
  2619. else if (Operation == foRename)
  2620. {
  2621. DebugAssert(DirView(Side)->ItemFocused);
  2622. DirView(Side)->ItemFocused->EditCaption();
  2623. Result = true;
  2624. }
  2625. else if (Operation == foDelete)
  2626. {
  2627. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2628. }
  2629. else if (Operation == foSetProperties)
  2630. {
  2631. DirView(osRemote)->SaveSelectedNames();
  2632. Result = SetProperties(Side, FileList);
  2633. }
  2634. else if (Operation == foCustomCommand)
  2635. {
  2636. DebugAssert(Param);
  2637. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2638. DirView(osRemote)->SaveSelectedNames();
  2639. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2640. CustomCommand(FileList, *Command, NULL);
  2641. Result = true;
  2642. }
  2643. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2644. {
  2645. DebugAssert(!IsSideLocalBrowser(Side));
  2646. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2647. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2648. }
  2649. else if (Operation == foLock)
  2650. {
  2651. DebugAssert(!IsSideLocalBrowser(Side));
  2652. LockFiles(FileList, true);
  2653. Result = true;
  2654. }
  2655. else if (Operation == foUnlock)
  2656. {
  2657. DebugAssert(!IsSideLocalBrowser(Side));
  2658. LockFiles(FileList, false);
  2659. Result = true;
  2660. }
  2661. else
  2662. {
  2663. DebugFail();
  2664. }
  2665. return Result;
  2666. }
  2667. //---------------------------------------------------------------------------
  2668. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2669. {
  2670. if (Side == osCurrent)
  2671. {
  2672. Side = FCurrentSide;
  2673. }
  2674. return Side;
  2675. }
  2676. //---------------------------------------------------------------------------
  2677. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2678. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2679. {
  2680. Side = GetSide(Side);
  2681. bool Result;
  2682. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2683. try
  2684. {
  2685. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2686. }
  2687. __finally
  2688. {
  2689. delete FileList;
  2690. }
  2691. return Result;
  2692. }
  2693. //---------------------------------------------------------------------------
  2694. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2695. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2696. bool NoConfirmation, void * Param)
  2697. {
  2698. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2699. {
  2700. if ((Operation == foCopy) || (Operation == foMove))
  2701. {
  2702. DebugAssert(!IsLocalBrowserMode());
  2703. if (GetSide(Side) == osLocal)
  2704. {
  2705. Configuration->Usage->Inc(L"UploadsCommand");
  2706. }
  2707. else
  2708. {
  2709. Configuration->Usage->Inc(L"DownloadsCommand");
  2710. }
  2711. }
  2712. }
  2713. }
  2714. //---------------------------------------------------------------------------
  2715. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2716. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2717. {
  2718. TTransferOperationParam Param;
  2719. if ((WinConfiguration->Interface != ifCommander) ||
  2720. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2721. {
  2722. Flags &= ~cocShortCutHint;
  2723. }
  2724. TCustomDirView * DView = DirView(Side);
  2725. Param.Options =
  2726. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2727. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2728. if (FLAGSET(Flags, cocQueue))
  2729. {
  2730. Param.Queue = asOn;
  2731. }
  2732. else if (FLAGSET(Flags, cocNonQueue))
  2733. {
  2734. Param.Queue = asOff;
  2735. }
  2736. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2737. }
  2738. //---------------------------------------------------------------------------
  2739. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2740. {
  2741. try
  2742. {
  2743. if (ErrorList->Count)
  2744. {
  2745. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2746. if (MessageDialog(Message, qtError,
  2747. qaOK | qaCancel, HELP_NONE) == qaOK)
  2748. {
  2749. unsigned int Answer;
  2750. int Index = 0;
  2751. do
  2752. {
  2753. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2754. TQueryButtonAlias Aliases[2];
  2755. Aliases[0].Button = qaYes;
  2756. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2757. Aliases[1].Button = qaNo;
  2758. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2759. TMessageParams Params;
  2760. Params.Aliases = Aliases;
  2761. Params.AliasesCount = LENOF(Aliases);
  2762. Answer = MoreMessageDialog(
  2763. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2764. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2765. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2766. qaOK, HELP_NONE, &Params);
  2767. if (Answer == qaNo)
  2768. {
  2769. Index++;
  2770. }
  2771. if (Answer == qaYes)
  2772. {
  2773. Index--;
  2774. }
  2775. }
  2776. while (Answer != qaOK);
  2777. }
  2778. }
  2779. }
  2780. __finally
  2781. {
  2782. TStrings * List = ErrorList;
  2783. ErrorList = NULL;
  2784. for (int i = 0; i < List->Count; i++)
  2785. {
  2786. delete List->Objects[i];
  2787. }
  2788. delete List;
  2789. }
  2790. }
  2791. //---------------------------------------------------------------------------
  2792. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2793. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2794. {
  2795. // needed for checking filemasks, as there's no directory object
  2796. // associated with the file object
  2797. File->FullFileName = FullFileName;
  2798. TFileMasks::TParams MaskParams;
  2799. MaskParams.Size = File->Size;
  2800. MaskParams.Modification = File->Modification;
  2801. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2802. }
  2803. //---------------------------------------------------------------------------
  2804. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2805. {
  2806. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2807. Side = GetSide(Side);
  2808. TCustomDirView * DView = DirView(Side);
  2809. TListItem * FocusedItem = DView->ItemFocused;
  2810. UnicodeString Name;
  2811. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2812. {
  2813. Name = DView->ItemFileName(FocusedItem);
  2814. }
  2815. else
  2816. {
  2817. Name = LoadStr(NEW_FILE);
  2818. }
  2819. UnicodeString Names = Name;
  2820. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2821. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2822. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2823. {
  2824. while (!Names.IsEmpty())
  2825. {
  2826. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2827. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2828. UnicodeString TargetFileName;
  2829. UnicodeString LocalFileName;
  2830. UnicodeString RootTempDir;
  2831. UnicodeString TempDir;
  2832. UnicodeString RemoteDirectory;
  2833. bool ExistingFile = false;
  2834. if (!IsSideLocalBrowser(Side))
  2835. {
  2836. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2837. TRemoteFile * File = NULL;
  2838. if (FTerminal->FileExists(Name, &File) &&
  2839. !File->IsDirectory)
  2840. {
  2841. try
  2842. {
  2843. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2844. ExistingFile = true;
  2845. }
  2846. __finally
  2847. {
  2848. delete File;
  2849. }
  2850. }
  2851. if (!ExistingFile)
  2852. {
  2853. RemoteDirectory = UnixExtractFilePath(Name);
  2854. TemporaryDirectoryForRemoteFiles(
  2855. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2856. TargetFileName = UnixExtractFileName(Name);
  2857. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2858. LocalFileName = TempDir +
  2859. // We probably do not want to trim the VMS version here
  2860. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2861. }
  2862. }
  2863. else
  2864. {
  2865. if (ExtractFilePath(Name).IsEmpty())
  2866. {
  2867. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2868. }
  2869. else
  2870. {
  2871. LocalFileName = ExpandFileName(Name);
  2872. }
  2873. TargetFileName = ExtractFileName(Name);
  2874. }
  2875. if (!ExistingFile)
  2876. {
  2877. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2878. if (NewFile)
  2879. {
  2880. int File = FileCreate(ApiPath(LocalFileName));
  2881. if (File < 0)
  2882. {
  2883. if (!RootTempDir.IsEmpty())
  2884. {
  2885. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2886. }
  2887. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2888. }
  2889. else
  2890. {
  2891. FileClose(File);
  2892. }
  2893. }
  2894. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2895. const TEditorData * ExternalEditor = NULL;
  2896. TFileMasks::TParams MaskParams; // size not known
  2897. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2898. false, MaskParams);
  2899. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2900. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2901. }
  2902. }
  2903. }
  2904. }
  2905. //---------------------------------------------------------------------------
  2906. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2907. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2908. {
  2909. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2910. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2911. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2912. return
  2913. ((ExecuteFileBy == efInternalEditor)) ||
  2914. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2915. }
  2916. //---------------------------------------------------------------------------
  2917. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2918. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2919. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2920. UnicodeString RemoteDirectory, bool NewFile)
  2921. {
  2922. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2923. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2924. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2925. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2926. Side = GetSide(Side);
  2927. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2928. if (!IsSideLocalBrowser(Side))
  2929. {
  2930. Data->Terminal = Terminal;
  2931. Data->Queue = Queue;
  2932. Data->SessionData = CloneCurrentSessionData();
  2933. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2934. Data->RemoteDirectory = RemoteDirectory;
  2935. Data->SessionName = Terminal->SessionData->SessionName;
  2936. Data->LocalRootDirectory = LocalRootDirectory;
  2937. Data->OriginalFileName = OriginalFileName;
  2938. Data->Command = L""; // will be changed later for external editor
  2939. }
  2940. if (ExecuteFileBy == efInternalEditor)
  2941. {
  2942. if (!IsSideLocalBrowser(Side))
  2943. {
  2944. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2945. L" - " + Terminal->SessionData->SessionName;
  2946. TForm * Editor;
  2947. try
  2948. {
  2949. TNotifyEvent OnFileChanged = NULL;
  2950. TNotifyEvent OnSaveAll = NULL;
  2951. TAnyModifiedEvent OnAnyModified = NULL;
  2952. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2953. if (Terminal->IsCapable[fcBackgroundTransfers])
  2954. {
  2955. OnFileChanged = FEditorManager->FileChanged;
  2956. OnSaveAll = SaveAllInternalEditors;
  2957. OnAnyModified = AnyInternalEditorModified;
  2958. }
  2959. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2960. FEditorManager->FileReload, FEditorManager->FileClosed,
  2961. OnSaveAll, OnAnyModified,
  2962. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2963. }
  2964. catch(...)
  2965. {
  2966. if (!LocalRootDirectory.IsEmpty())
  2967. {
  2968. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2969. }
  2970. throw;
  2971. }
  2972. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2973. }
  2974. else
  2975. {
  2976. DebugAssert(!FStandaloneEditing);
  2977. TForm * Editor =
  2978. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2979. SaveAllInternalEditors, AnyInternalEditorModified,
  2980. L"", false, SessionColor, -1, NewFile);
  2981. FLocalEditors->Add(Editor);
  2982. }
  2983. }
  2984. else
  2985. {
  2986. HANDLE Process;
  2987. if (ExecuteFileBy == efExternalEditor)
  2988. {
  2989. UnicodeString Program, Params, Dir;
  2990. Data->Command = ExternalEditor->ExternalEditor;
  2991. ReformatFileNameCommand(Data->Command);
  2992. SplitCommand(Data->Command, Program, Params, Dir);
  2993. Params = ExpandFileNameCommand(Params, FileName);
  2994. Program = ExpandEnvironmentVariables(Program);
  2995. if (!ExecuteShell(Program, Params, Process))
  2996. {
  2997. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2998. }
  2999. }
  3000. else
  3001. {
  3002. DebugAssert(!IsSideLocalBrowser(Side));
  3003. if (!ExecuteShell(FileName, L"", Process))
  3004. {
  3005. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3006. }
  3007. }
  3008. if (IsSideLocalBrowser(Side) ||
  3009. ((ExecuteFileBy == efShell) &&
  3010. !WinConfiguration->Editor.SDIShellEditor) ||
  3011. ((ExecuteFileBy == efExternalEditor) &&
  3012. !ExternalEditor->SDIExternalEditor))
  3013. {
  3014. // no need for handle
  3015. if (Process != NULL)
  3016. {
  3017. DebugCheck(CloseHandle(Process));
  3018. }
  3019. Process = INVALID_HANDLE_VALUE;
  3020. }
  3021. else
  3022. {
  3023. if (Process == NULL)
  3024. {
  3025. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3026. }
  3027. }
  3028. if (!IsSideLocalBrowser(Side))
  3029. {
  3030. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3031. }
  3032. }
  3033. }
  3034. //---------------------------------------------------------------------------
  3035. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3036. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3037. void * /*Arg*/)
  3038. {
  3039. if (Token != NULL)
  3040. {
  3041. EditorFormFileSave(static_cast<TForm *>(Token));
  3042. }
  3043. }
  3044. //---------------------------------------------------------------------------
  3045. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3046. {
  3047. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3048. {
  3049. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3050. }
  3051. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3052. }
  3053. //---------------------------------------------------------------------------
  3054. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3055. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3056. void * Arg)
  3057. {
  3058. if ((Token != NULL) &&
  3059. IsEditorFormModified(static_cast<TForm *>(Token)))
  3060. {
  3061. *static_cast<bool *>(Arg) = true;
  3062. }
  3063. }
  3064. //---------------------------------------------------------------------------
  3065. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3066. TObject * /*Sender*/, bool & Modified)
  3067. {
  3068. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3069. {
  3070. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3071. {
  3072. Modified = true;
  3073. }
  3074. }
  3075. if (!Modified)
  3076. {
  3077. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3078. }
  3079. }
  3080. //---------------------------------------------------------------------------
  3081. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3082. {
  3083. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3084. }
  3085. //---------------------------------------------------------------------------
  3086. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3087. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3088. UnicodeString & Result, UnicodeString & RootDirectory)
  3089. {
  3090. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3091. {
  3092. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3093. Result = RootDirectory;
  3094. }
  3095. else
  3096. {
  3097. RootDirectory = L"";
  3098. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3099. Result = IncludeTrailingBackslash(Result);
  3100. }
  3101. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3102. {
  3103. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3104. }
  3105. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3106. {
  3107. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3108. {
  3109. RemoteDirectory.Delete(1, 1);
  3110. }
  3111. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3112. }
  3113. if (!ForceDirectories(ApiPath(Result)))
  3114. {
  3115. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3116. }
  3117. }
  3118. //---------------------------------------------------------------------------
  3119. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3120. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3121. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3122. {
  3123. DebugAssert(!IsLocalBrowserMode());
  3124. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3125. if (ForceText)
  3126. {
  3127. CopyParam.TransferMode = tmAscii;
  3128. }
  3129. TemporaryFileCopyParam(CopyParam);
  3130. if (AllFiles)
  3131. {
  3132. CopyParam.IncludeFileMask = TFileMasks();
  3133. }
  3134. if (TempDir.IsEmpty())
  3135. {
  3136. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3137. }
  3138. DebugAssert(!FAutoOperation);
  3139. FAutoOperation = AutoOperation;
  3140. Terminal->ExceptionOnFail = true;
  3141. try
  3142. {
  3143. try
  3144. {
  3145. // turn off confirmations, as for MDI editors we may possibly download
  3146. // the same file over
  3147. Terminal->CopyToLocal(
  3148. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3149. if (GetTargetNames)
  3150. {
  3151. for (int i = 0; i < FileList->Count; i++)
  3152. {
  3153. FileList->Strings[i] =
  3154. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3155. }
  3156. }
  3157. }
  3158. catch(...)
  3159. {
  3160. if (!RootTempDir.IsEmpty())
  3161. {
  3162. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3163. }
  3164. throw;
  3165. }
  3166. }
  3167. __finally
  3168. {
  3169. FAutoOperation = false;
  3170. Terminal->ExceptionOnFail = false;
  3171. }
  3172. }
  3173. //---------------------------------------------------------------------------
  3174. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3175. {
  3176. // Do not waste time checking for default editor list the next time,
  3177. // or testing if default editor is not notepad.
  3178. bool TryNextTime = false;
  3179. UnicodeString UsageState;
  3180. if (!WinConfiguration->EditorList->IsDefaultList())
  3181. {
  3182. UsageState = "H";
  3183. }
  3184. else
  3185. {
  3186. UnicodeString Executable;
  3187. UnicodeString ExecutableDescription;
  3188. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3189. {
  3190. UnicodeString Message =
  3191. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3192. unsigned int Answer =
  3193. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3194. if (Answer != qaOK)
  3195. {
  3196. UsageState = "R";
  3197. }
  3198. else
  3199. {
  3200. UsageState = "A";
  3201. TEditorData EditorData;
  3202. EditorData.Editor = edExternal;
  3203. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3204. EditorData.ExternalEditorOptionsAutodetect();
  3205. TEditorList EditorList;
  3206. EditorList = *WinConfiguration->EditorList;
  3207. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3208. WinConfiguration->EditorList = &EditorList;
  3209. }
  3210. }
  3211. }
  3212. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3213. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3214. }
  3215. //---------------------------------------------------------------------------
  3216. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3217. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3218. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3219. {
  3220. if (ExecuteFileBy == efDefaultEditor)
  3221. {
  3222. if (!WinConfiguration->OfferedEditorAutoConfig)
  3223. {
  3224. EditorAutoConfig();
  3225. }
  3226. const TEditorPreferences * Editor =
  3227. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3228. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3229. {
  3230. ExecuteFileBy = efInternalEditor;
  3231. ExternalEditor = NULL;
  3232. }
  3233. else if (Editor->Data->Editor == edOpen)
  3234. {
  3235. ExecuteFileBy = efShell;
  3236. ExternalEditor = NULL;
  3237. }
  3238. else
  3239. {
  3240. ExecuteFileBy = efExternalEditor;
  3241. ExternalEditor = Editor->Data;
  3242. }
  3243. }
  3244. }
  3245. //---------------------------------------------------------------------------
  3246. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3247. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3248. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3249. {
  3250. UnicodeString OriginalFileName;
  3251. UnicodeString LocalRootDirectory;
  3252. UnicodeString RemoteDirectory;
  3253. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3254. IsSideLocalBrowser(Side), MaskParams);
  3255. UnicodeString Counter;
  3256. UnicodeString LocalFileName;
  3257. bool Handled = false;
  3258. if (!IsSideLocalBrowser(Side))
  3259. {
  3260. // We need to trim VMS version here, so that we use name without version
  3261. // when uploading back to create a new version of the file
  3262. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3263. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3264. TObject * Token = NULL;
  3265. UnicodeString LocalDirectory;
  3266. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3267. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3268. LocalDirectory))
  3269. {
  3270. if (Token != NULL)
  3271. {
  3272. TForm * Form = dynamic_cast<TForm *>(Token);
  3273. if (Form->WindowState == wsMinimized)
  3274. {
  3275. ShowWindow(Form->Handle, SW_RESTORE);
  3276. }
  3277. else
  3278. {
  3279. Form->SetFocus();
  3280. }
  3281. Handled = true;
  3282. }
  3283. else
  3284. {
  3285. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3286. }
  3287. }
  3288. if (!Handled)
  3289. {
  3290. TStringList * FileList1 = new TStringList();
  3291. try
  3292. {
  3293. FileList1->AddObject(FullFileName, Object);
  3294. TemporarilyDownloadFiles(FileList1,
  3295. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3296. LocalRootDirectory, LocalDirectory, true, true, true);
  3297. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3298. }
  3299. __finally
  3300. {
  3301. delete FileList1;
  3302. }
  3303. switch (ExecuteFileBy)
  3304. {
  3305. case efShell:
  3306. Counter = "RemoteFilesExecuted";
  3307. break;
  3308. case efInternalEditor:
  3309. Counter = "RemoteFilesOpenedInInternalEditor";
  3310. break;
  3311. case efExternalEditor:
  3312. Counter = "RemoteFilesOpenedInExternalEditor";
  3313. break;
  3314. default:
  3315. DebugFail();
  3316. }
  3317. }
  3318. }
  3319. else
  3320. {
  3321. LocalFileName = FullFileName;
  3322. OriginalFileName = ExtractFileName(FullFileName);
  3323. switch (ExecuteFileBy)
  3324. {
  3325. case efShell:
  3326. Counter = "LocalFilesExecuted";
  3327. break;
  3328. case efInternalEditor:
  3329. Counter = "LocalFilesOpenedInInternalEditor";
  3330. break;
  3331. case efExternalEditor:
  3332. Counter = "LocalFilesOpenedInExternalEditor";
  3333. break;
  3334. default:
  3335. DebugFail();
  3336. }
  3337. }
  3338. if (!Handled)
  3339. {
  3340. Configuration->Usage->Inc(Counter);
  3341. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3342. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3343. }
  3344. }
  3345. //---------------------------------------------------------------------------
  3346. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3347. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3348. bool AllSelected, bool OnFocused)
  3349. {
  3350. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3351. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3352. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3353. Side = GetSide(Side);
  3354. TCustomDirView * DView = DirView(Side);
  3355. TStrings * FileList =
  3356. AllSelected ?
  3357. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3358. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3359. try
  3360. {
  3361. DebugAssert(AllSelected || (FileList->Count == 1));
  3362. for (int i = 0; i < FileList->Count; i++)
  3363. {
  3364. UnicodeString ListFileName = FileList->Strings[i];
  3365. UnicodeString FileNameOnly =
  3366. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3367. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3368. if (!DView->ItemIsDirectory(Item))
  3369. {
  3370. UnicodeString FullFileName;
  3371. if (!IsSideLocalBrowser(Side))
  3372. {
  3373. FullFileName = DirView(Side)->Path + ListFileName;
  3374. }
  3375. else
  3376. {
  3377. FullFileName = ListFileName;
  3378. }
  3379. TFileMasks::TParams MaskParams;
  3380. MaskParams.Size = DView->ItemFileSize(Item);
  3381. TDateTimePrecision Precision;
  3382. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3383. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3384. FileList->Objects[i], MaskParams);
  3385. }
  3386. }
  3387. }
  3388. __finally
  3389. {
  3390. delete FileList;
  3391. }
  3392. }
  3393. //---------------------------------------------------------------------------
  3394. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3395. {
  3396. CopyParam.FileNameCase = ncNoChange;
  3397. CopyParam.PreserveRights = false;
  3398. CopyParam.PreserveReadOnly = false;
  3399. CopyParam.ReplaceInvalidChars = true;
  3400. CopyParam.IncludeFileMask = TFileMasks();
  3401. CopyParam.NewerOnly = false;
  3402. CopyParam.FileMask = L"";
  3403. }
  3404. //---------------------------------------------------------------------------
  3405. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3406. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3407. {
  3408. TTerminalManager * Manager = TTerminalManager::Instance();
  3409. if (!IsActiveTerminal(Data->Terminal))
  3410. {
  3411. if (!NonVisualDataModule->Busy)
  3412. {
  3413. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3414. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3415. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3416. if (Data->Terminal == NULL)
  3417. {
  3418. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3419. if (SameSiteTerminal != NULL)
  3420. {
  3421. UnicodeString Message =
  3422. FMTLOAD(EDIT_SESSION_REATTACH,
  3423. (FileNameOnly, Data->SessionName, FileNameOnly));
  3424. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3425. {
  3426. Data->Terminal = Terminal;
  3427. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3428. Data->SessionName = Terminal->SessionData->SessionName;
  3429. // We might also overwrite session data
  3430. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3431. }
  3432. else
  3433. {
  3434. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3435. Abort();
  3436. }
  3437. }
  3438. }
  3439. // foreground session should reconnect itself
  3440. else if (Terminal != Data->Terminal)
  3441. {
  3442. UnicodeString Message =
  3443. MainInstructions(
  3444. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3445. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3446. {
  3447. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3448. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3449. }
  3450. else
  3451. {
  3452. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3453. Abort();
  3454. }
  3455. }
  3456. }
  3457. if (!IsActiveTerminal(Data->Terminal))
  3458. {
  3459. Configuration->Usage->Inc(L"EditInactiveSession");
  3460. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3461. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3462. (ExtractFileName(FileName), Data->SessionName)));
  3463. }
  3464. }
  3465. TStrings * FileList = new TStringList();
  3466. try
  3467. {
  3468. FileList->Add(FileName);
  3469. // consider using the same settings (preset) as when the file was downloaded
  3470. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3471. TemporaryFileCopyParam(CopyParam);
  3472. if (Data->ForceText)
  3473. {
  3474. CopyParam.TransferMode = tmAscii;
  3475. }
  3476. // so i do not need to worry if masking algorithm works in all cases
  3477. // ("" means "copy file name", no masking is actually done)
  3478. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3479. {
  3480. CopyParam.FileMask = L"";
  3481. }
  3482. else
  3483. {
  3484. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3485. }
  3486. DebugAssert(Data->Queue != NULL);
  3487. int Params = cpNoConfirmation | cpTemporary;
  3488. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3489. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3490. QueueItem->CompleteEvent = UploadCompleteEvent;
  3491. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3492. }
  3493. __finally
  3494. {
  3495. delete FileList;
  3496. }
  3497. }
  3498. //---------------------------------------------------------------------------
  3499. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3500. const UnicodeString FileName, const TEditedFileData * Data)
  3501. {
  3502. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3503. DebugAssert(!NonVisualDataModule->Busy);
  3504. if (!IsActiveTerminal(Data->Terminal))
  3505. {
  3506. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3507. (ExtractFileName(FileName), Data->SessionName)));
  3508. }
  3509. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3510. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3511. NonVisualDataModule->StartBusy();
  3512. try
  3513. {
  3514. std::unique_ptr<TRemoteFile> File;
  3515. UnicodeString RemoteFileName =
  3516. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3517. FTerminal->ExceptionOnFail = true;
  3518. try
  3519. {
  3520. TRemoteFile * AFile = NULL;
  3521. FTerminal->ReadFile(RemoteFileName, AFile);
  3522. File.reset(AFile);
  3523. if (!File->HaveFullFileName)
  3524. {
  3525. File->FullFileName = RemoteFileName;
  3526. }
  3527. }
  3528. __finally
  3529. {
  3530. FTerminal->ExceptionOnFail = false;
  3531. }
  3532. std::unique_ptr<TStrings> FileList(new TStringList());
  3533. FileList->AddObject(RemoteFileName, File.get());
  3534. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3535. UnicodeString TempDir = ExtractFilePath(FileName);
  3536. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3537. TempDir, true, true, true);
  3538. // sanity check, the target file name should be still the same
  3539. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3540. }
  3541. __finally
  3542. {
  3543. NonVisualDataModule->EndBusy();
  3544. // it actually may not exist anymore...
  3545. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3546. }
  3547. }
  3548. //---------------------------------------------------------------------------
  3549. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3550. const TEditedFileData * Data, bool & KeepOpen)
  3551. {
  3552. // Command is set for external editors only (not for "shell" open).
  3553. if (!Data->Command.IsEmpty())
  3554. {
  3555. bool AnyFound = false;
  3556. bool AnyMDI = false;
  3557. bool AnyNonMDI = false;
  3558. bool AnyDetect = false;
  3559. TEditorList * EditorList = new TEditorList();
  3560. try
  3561. {
  3562. *EditorList = *WinConfiguration->EditorList;
  3563. for (int i = 0; i < EditorList->Count; i++)
  3564. {
  3565. const TEditorPreferences * Editor = EditorList->Editors[i];
  3566. if ((Editor->Data->Editor == edExternal) &&
  3567. (Editor->Data->ExternalEditor == Data->Command))
  3568. {
  3569. AnyFound = true;
  3570. if (Editor->Data->SDIExternalEditor)
  3571. {
  3572. AnyNonMDI = true;
  3573. if (Editor->Data->DetectMDIExternalEditor)
  3574. {
  3575. AnyDetect = true;
  3576. }
  3577. }
  3578. else
  3579. {
  3580. AnyMDI = true;
  3581. }
  3582. }
  3583. }
  3584. bool EnableMDI = false;
  3585. bool DisableDetect = false;
  3586. if (AnyMDI)
  3587. {
  3588. KeepOpen = true;
  3589. if (AnyNonMDI)
  3590. {
  3591. // there is at least one instance of the editor with MDI support enabled,
  3592. // and one with disabled, enable it for all instances
  3593. EnableMDI = true;
  3594. }
  3595. }
  3596. else if (AnyFound && !AnyDetect)
  3597. {
  3598. // at least once instance found but all have MDI autodetection disabled
  3599. // => close the file (default action)
  3600. }
  3601. else
  3602. {
  3603. // no instance of the editor has MDI support enabled
  3604. TMessageParams Params;
  3605. if (AnyFound)
  3606. {
  3607. // there is at least one instance of the editor
  3608. Params.Params |= mpNeverAskAgainCheck;
  3609. }
  3610. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3611. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3612. switch (Answer)
  3613. {
  3614. case qaNeverAskAgain:
  3615. DisableDetect = true;
  3616. break;
  3617. case qaNo:
  3618. EnableMDI = true;
  3619. KeepOpen = true;
  3620. break;
  3621. }
  3622. }
  3623. if (AnyFound && (EnableMDI || DisableDetect))
  3624. {
  3625. bool Changed = false;
  3626. for (int i = 0; i < EditorList->Count; i++)
  3627. {
  3628. const TEditorPreferences * Editor = EditorList->Editors[i];
  3629. if ((Editor->Data->Editor == edExternal) &&
  3630. (Editor->Data->ExternalEditor == Data->Command) &&
  3631. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3632. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3633. {
  3634. Changed = true;
  3635. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3636. if (EnableMDI)
  3637. {
  3638. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3639. }
  3640. if (DisableDetect)
  3641. {
  3642. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3643. }
  3644. EditorList->Change(i, UpdatedEditor);
  3645. }
  3646. }
  3647. if (Changed)
  3648. {
  3649. WinConfiguration->EditorList = EditorList;
  3650. }
  3651. }
  3652. }
  3653. __finally
  3654. {
  3655. delete EditorList;
  3656. }
  3657. }
  3658. else
  3659. {
  3660. // "open" case
  3661. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3662. qaOK, HELP_APP_EARLY_CLOSED);
  3663. }
  3664. }
  3665. //---------------------------------------------------------------------------
  3666. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3667. {
  3668. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3669. }
  3670. //---------------------------------------------------------------------------
  3671. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3672. {
  3673. SideEnter(osRemote);
  3674. }
  3675. //---------------------------------------------------------------------------
  3676. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3677. {
  3678. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3679. SideEnter(osRemote);
  3680. }
  3681. //---------------------------------------------------------------------------
  3682. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3683. {
  3684. FCurrentSide = Side;
  3685. if (Visible)
  3686. {
  3687. UpdateControls();
  3688. }
  3689. }
  3690. //---------------------------------------------------------------------------
  3691. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3692. TStrings * FileList, bool Alternative)
  3693. {
  3694. TCustomDirView * DView = DirView(Side);
  3695. DView->SaveSelection();
  3696. DView->SaveSelectedNames();
  3697. DebugAssert(!FAlternativeDelete);
  3698. FAlternativeDelete = Alternative;
  3699. try
  3700. {
  3701. if (!IsSideLocalBrowser(Side))
  3702. {
  3703. DebugAssert(Terminal != NULL);
  3704. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3705. }
  3706. else
  3707. {
  3708. try
  3709. {
  3710. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3711. }
  3712. __finally
  3713. {
  3714. ReloadLocalDirectory();
  3715. }
  3716. }
  3717. FAlternativeDelete = false;
  3718. }
  3719. catch(...)
  3720. {
  3721. FAlternativeDelete = false;
  3722. DView->DiscardSavedSelection();
  3723. throw;
  3724. }
  3725. DView->RestoreSelection();
  3726. }
  3727. //---------------------------------------------------------------------------
  3728. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3729. {
  3730. DebugAssert(Terminal);
  3731. DebugAssert(!IsLocalBrowserMode());
  3732. RemoteDirView->SaveSelection();
  3733. RemoteDirView->SaveSelectedNames();
  3734. try
  3735. {
  3736. if (Lock)
  3737. {
  3738. Terminal->LockFiles(FileList);
  3739. }
  3740. else
  3741. {
  3742. Terminal->UnlockFiles(FileList);
  3743. }
  3744. }
  3745. catch(...)
  3746. {
  3747. RemoteDirView->DiscardSavedSelection();
  3748. throw;
  3749. }
  3750. RemoteDirView->RestoreSelection();
  3751. }
  3752. //---------------------------------------------------------------------------
  3753. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3754. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3755. bool NoConfirmation, bool Move)
  3756. {
  3757. DebugAssert(Terminal != NULL);
  3758. DebugAssert(!IsLocalBrowserMode());
  3759. // update Terminal->StateData->RemoteDirectory
  3760. UpdateTerminal(Terminal);
  3761. if (Session == NULL)
  3762. {
  3763. Session = TTerminalManager::Instance()->ActiveTerminal;
  3764. }
  3765. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3766. {
  3767. if (RemoteDriveView->DropTarget != NULL)
  3768. {
  3769. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3770. }
  3771. else if (RemoteDirView->DropTarget != NULL)
  3772. {
  3773. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3774. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3775. }
  3776. else
  3777. {
  3778. Target = RemoteDirView->Path;
  3779. }
  3780. }
  3781. else
  3782. {
  3783. Target = Session->StateData->RemoteDirectory;
  3784. }
  3785. Target = UnixIncludeTrailingBackslash(Target);
  3786. if (FileList->Count == 1)
  3787. {
  3788. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3789. }
  3790. else
  3791. {
  3792. FileMask = AnyMask;
  3793. }
  3794. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3795. bool Result = true;
  3796. if (!NoConfirmation)
  3797. {
  3798. bool Multi = (FileList->Count > 1);
  3799. if (Move)
  3800. {
  3801. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3802. }
  3803. else
  3804. {
  3805. std::unique_ptr<TStrings> Sessions(new TStringList);
  3806. std::unique_ptr<TStrings> Directories(new TStringList);
  3807. TStrings * SessionList = TTerminalManager::Instance()->TerminalList;
  3808. for (int Index = 0; Index < SessionList->Count; Index++)
  3809. {
  3810. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3811. if (IsActiveTerminal(ASession))
  3812. {
  3813. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3814. Directories->Add(ASession->StateData->RemoteDirectory);
  3815. }
  3816. }
  3817. TDirectRemoteCopy AllowDirectCopy;
  3818. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3819. {
  3820. DebugAssert(DirectCopy);
  3821. AllowDirectCopy = drcAllow;
  3822. }
  3823. else if (FTerminal->IsCapable[fcSecondaryShell])
  3824. {
  3825. DebugAssert(DirectCopy);
  3826. AllowDirectCopy = drcConfirmCommandSession;
  3827. }
  3828. else
  3829. {
  3830. DebugAssert(!DirectCopy);
  3831. AllowDirectCopy = drcDisallow;
  3832. }
  3833. void * ASession = Session;
  3834. Result = DoRemoteCopyDialog(
  3835. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3836. Session = static_cast<TManagedTerminal *>(ASession);
  3837. }
  3838. }
  3839. return Result;
  3840. }
  3841. //---------------------------------------------------------------------------
  3842. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3843. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3844. {
  3845. DebugAssert(!IsLocalBrowserMode());
  3846. bool DirectCopy;
  3847. UnicodeString Target, FileMask;
  3848. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3849. if (Result)
  3850. {
  3851. if (!Move && !DirectCopy)
  3852. {
  3853. Configuration->Usage->Inc("RemoteCopyTemp");
  3854. UnicodeString RootTempDir;
  3855. UnicodeString TempDir;
  3856. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3857. TStrings * TemporaryFilesList = new TStringList();
  3858. try
  3859. {
  3860. TMakeLocalFileListParams MakeFileListParam;
  3861. MakeFileListParam.FileList = TemporaryFilesList;
  3862. MakeFileListParam.FileTimes = NULL;
  3863. MakeFileListParam.IncludeDirs = true;
  3864. MakeFileListParam.Recursive = false;
  3865. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3866. TTerminalManager::Instance()->ActiveTerminal = Session;
  3867. if (TemporaryFilesList->Count > 0)
  3868. {
  3869. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3870. CopyParam.FileMask = FileMask;
  3871. DebugAssert(!FAutoOperation);
  3872. FAutoOperation = true;
  3873. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3874. }
  3875. }
  3876. __finally
  3877. {
  3878. delete TemporaryFilesList;
  3879. FAutoOperation = false;
  3880. if (!RootTempDir.IsEmpty())
  3881. {
  3882. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3883. }
  3884. }
  3885. }
  3886. else
  3887. {
  3888. RemoteDirView->SaveSelection();
  3889. RemoteDirView->SaveSelectedNames();
  3890. try
  3891. {
  3892. if (Move)
  3893. {
  3894. Configuration->Usage->Inc("RemoteMove");
  3895. Terminal->MoveFiles(FileList, Target, FileMask);
  3896. }
  3897. else
  3898. {
  3899. Configuration->Usage->Inc("RemoteCopyDirect");
  3900. DebugAssert(DirectCopy);
  3901. DebugAssert(Session == FTerminal);
  3902. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3903. FTerminal->CommandSessionOpened ||
  3904. CommandSessionFallback())
  3905. {
  3906. Terminal->CopyFiles(FileList, Target, FileMask);
  3907. }
  3908. }
  3909. }
  3910. catch(...)
  3911. {
  3912. RemoteDirView->DiscardSavedSelection();
  3913. throw;
  3914. }
  3915. RemoteDirView->RestoreSelection();
  3916. }
  3917. }
  3918. return Result;
  3919. }
  3920. //---------------------------------------------------------------------------
  3921. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3922. const UnicodeString & Path, TRemoteProperties & Properties)
  3923. {
  3924. DebugAssert(!IsLocalBrowserMode());
  3925. Properties.Valid = Properties.Valid << vpEncrypt;
  3926. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3927. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3928. }
  3929. //---------------------------------------------------------------------------
  3930. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3931. {
  3932. Side = GetSide(Side);
  3933. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3934. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3935. UnicodeString Name = LoadStr(NEW_FOLDER);
  3936. int AllowedChanges =
  3937. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3938. bool SaveSettings = false;
  3939. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3940. {
  3941. TWindowLock Lock(this);
  3942. if (!IsSideLocalBrowser(Side))
  3943. {
  3944. if (SaveSettings)
  3945. {
  3946. GUIConfiguration->NewDirectoryProperties = Properties;
  3947. }
  3948. CreateRemoteDirectory(Name, Properties);
  3949. }
  3950. else
  3951. {
  3952. DirView(Side)->CreateDirectory(Name);
  3953. }
  3954. }
  3955. }
  3956. //---------------------------------------------------------------------------
  3957. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3958. {
  3959. TWindowLock Lock(this);
  3960. DirView(Side)->ExecuteHomeDirectory();
  3961. }
  3962. //---------------------------------------------------------------------------
  3963. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3964. {
  3965. DoOpenDirectoryDialog(odBrowse, Side);
  3966. }
  3967. //---------------------------------------------------------------------------
  3968. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3969. {
  3970. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3971. bool Result = !Path.IsEmpty();
  3972. if (Result)
  3973. {
  3974. // While we might get here when the session is closed (from location profiles),
  3975. // it's not a problem as the Path setter is noop then
  3976. DirView(Side)->Path = Path;
  3977. }
  3978. return Result;
  3979. }
  3980. //---------------------------------------------------------------------------
  3981. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3982. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3983. bool & Close)
  3984. {
  3985. // terminal can be already closed (e.g. dropped connection)
  3986. if (Terminal != NULL)
  3987. {
  3988. try
  3989. {
  3990. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3991. }
  3992. catch(...)
  3993. {
  3994. if (!Terminal->Active)
  3995. {
  3996. Close = true;
  3997. }
  3998. throw;
  3999. }
  4000. }
  4001. }
  4002. //---------------------------------------------------------------------------
  4003. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4004. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4005. bool & Close)
  4006. {
  4007. // terminal can be already closed (e.g. dropped connection)
  4008. if (Terminal != NULL)
  4009. {
  4010. Configuration->Usage->Inc(L"ChecksumCalculated");
  4011. try
  4012. {
  4013. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4014. }
  4015. catch(...)
  4016. {
  4017. if (!Terminal->Active)
  4018. {
  4019. Close = true;
  4020. }
  4021. throw;
  4022. }
  4023. }
  4024. }
  4025. //---------------------------------------------------------------------------
  4026. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4027. {
  4028. bool Result;
  4029. if (!IsSideLocalBrowser(Side))
  4030. {
  4031. TRemoteTokenList * GroupList = NULL;
  4032. TRemoteTokenList * UserList = NULL;
  4033. try
  4034. {
  4035. TRemoteProperties CurrentProperties;
  4036. if (Terminal->LoadFilesProperties(FileList))
  4037. {
  4038. RemoteDirView->Invalidate();
  4039. }
  4040. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4041. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4042. if (CapableGroupChanging || CapableOwnerChanging)
  4043. {
  4044. if (CapableGroupChanging)
  4045. {
  4046. GroupList = Terminal->Groups->Duplicate();
  4047. }
  4048. if (CapableOwnerChanging)
  4049. {
  4050. UserList = Terminal->Users->Duplicate();
  4051. }
  4052. TRemoteDirectory * Files = Terminal->Files;
  4053. int Count = Files->Count;
  4054. if (Count > 100)
  4055. {
  4056. Count = 100;
  4057. }
  4058. for (int Index = 0; Index < Count; Index++)
  4059. {
  4060. TRemoteFile * File = Files->Files[Index];
  4061. if (CapableGroupChanging)
  4062. {
  4063. GroupList->AddUnique(File->Group);
  4064. }
  4065. if (CapableOwnerChanging)
  4066. {
  4067. UserList->AddUnique(File->Owner);
  4068. }
  4069. }
  4070. // if we haven't collected tokens for all files in current directory,
  4071. // make sure we collect them at least for all selected files.
  4072. // (note that so far the files in FileList has to be from current direcotry)
  4073. if (Count < Files->Count)
  4074. {
  4075. for (int Index = 0; Index < FileList->Count; Index++)
  4076. {
  4077. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4078. if (CapableGroupChanging)
  4079. {
  4080. GroupList->AddUnique(File->Group);
  4081. }
  4082. if (CapableOwnerChanging)
  4083. {
  4084. UserList->AddUnique(File->Owner);
  4085. }
  4086. }
  4087. }
  4088. }
  4089. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4090. int Flags = 0;
  4091. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4092. if (CapableOwnerChanging) Flags |= cpOwner;
  4093. if (CapableGroupChanging) Flags |= cpGroup;
  4094. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4095. if (Terminal->IsCapable[fcCalculatingChecksum])
  4096. {
  4097. CalculateChecksumEvent = CalculateChecksum;
  4098. }
  4099. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4100. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4101. TRemoteProperties NewProperties = CurrentProperties;
  4102. Result =
  4103. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4104. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4105. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4106. CalculateSize, CalculateChecksumEvent);
  4107. if (Result)
  4108. {
  4109. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4110. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4111. }
  4112. }
  4113. __finally
  4114. {
  4115. delete GroupList;
  4116. delete UserList;
  4117. }
  4118. }
  4119. else
  4120. {
  4121. DirView(Side)->DisplayPropertiesMenu();
  4122. Result = true;
  4123. }
  4124. return Result;
  4125. }
  4126. //---------------------------------------------------------------------------
  4127. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4128. {
  4129. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4130. {
  4131. FIgnoreNextDialogChar = Key;
  4132. }
  4133. Key = 0;
  4134. }
  4135. //---------------------------------------------------------------------------
  4136. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4137. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4138. {
  4139. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4140. if (Command != NULL)
  4141. {
  4142. KeyProcessed(Key, Shift);
  4143. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4144. {
  4145. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4146. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4147. false, false, const_cast<TCustomCommandType *>(Command));
  4148. }
  4149. }
  4150. }
  4151. //---------------------------------------------------------------------------
  4152. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4153. {
  4154. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4155. {
  4156. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4157. }
  4158. if (!DirView(osCurrent)->IsEditing())
  4159. {
  4160. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4161. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4162. {
  4163. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4164. if (((Action->ShortCut == KeyShortCut) ||
  4165. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4166. AllowedAction(Action, aaShortCut))
  4167. {
  4168. // Has to be called before the action as the dialog char is already in queue.
  4169. // So when the action consumes message queue, we already need to have the
  4170. // FIgnoreNextDialogChar set
  4171. KeyProcessed(Key, Shift);
  4172. // Reset reference to previous component (when menu/toolbar was clicked).
  4173. // Needed to detect that action was invoked by keyboard shortcut
  4174. // in TNonVisualDataModule::ExplorerActionsExecute
  4175. Action->ActionComponent = NULL;
  4176. Action->Execute();
  4177. return;
  4178. }
  4179. }
  4180. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4181. {
  4182. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4183. {
  4184. KeyProcessed(Key, Shift);
  4185. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4186. return;
  4187. }
  4188. }
  4189. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4190. {
  4191. KeyProcessed(Key, Shift);
  4192. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4193. }
  4194. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4195. if (IsCustomShortCut(CustomShortCut))
  4196. {
  4197. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4198. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4199. if (WinConfiguration->SharedBookmarks != NULL)
  4200. {
  4201. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4202. if ((Bookmark != NULL) &&
  4203. OpenBookmark(FCurrentSide, Bookmark))
  4204. {
  4205. KeyProcessed(Key, Shift);
  4206. }
  4207. }
  4208. }
  4209. }
  4210. TForm::KeyDown(Key, Shift);
  4211. }
  4212. //---------------------------------------------------------------------------
  4213. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4214. {
  4215. DebugAssert(Terminal != NULL);
  4216. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4217. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4218. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4219. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4220. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4221. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4222. // expanded from ?: to avoid memory leaks
  4223. if (SecurityEnabled)
  4224. {
  4225. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4226. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4227. }
  4228. else
  4229. {
  4230. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4231. }
  4232. if (FileSystemInfo.ProtocolName.IsEmpty())
  4233. {
  4234. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4235. }
  4236. else
  4237. {
  4238. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4239. }
  4240. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4241. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4242. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4243. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4244. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4245. UnicodeString CompressionStr = CSCompressionStr;
  4246. if (CSCompressionStr != SCCompressionStr)
  4247. {
  4248. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4249. }
  4250. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4251. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4252. UpdateStatusBar();
  4253. }
  4254. //---------------------------------------------------------------------------
  4255. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4256. {
  4257. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4258. DebugAssert(SessionStatusBar != NULL);
  4259. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4260. {
  4261. // note: (Terminal->Status < sshReady) currently never happens here,
  4262. // so STATUS_CONNECTING is never used
  4263. SessionStatusBar->SimplePanel = true;
  4264. SessionStatusBar->SimpleText = LoadStr(
  4265. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4266. }
  4267. else
  4268. {
  4269. DebugAssert(Terminal);
  4270. SessionStatusBar->SimplePanel = false;
  4271. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4272. if (!FNote.IsEmpty())
  4273. {
  4274. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4275. }
  4276. else
  4277. {
  4278. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4279. }
  4280. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4281. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4282. }
  4283. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4284. }
  4285. //---------------------------------------------------------------------------
  4286. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4287. {
  4288. Panel->Caption = L"";
  4289. }
  4290. //---------------------------------------------------------------------------
  4291. void __fastcall TCustomScpExplorerForm::Idle()
  4292. {
  4293. if (FShowing || FStandaloneEditing)
  4294. {
  4295. FEditorManager->Check();
  4296. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4297. // that needs to know if queue view is visible (and it may be closed after queue update)
  4298. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4299. }
  4300. if (FShowing)
  4301. {
  4302. if (!NonVisualDataModule->Busy &&
  4303. // Menu is opened or drag&drop is going on
  4304. (Mouse->Capture == NULL))
  4305. {
  4306. if (FRefreshRemoteDirectory)
  4307. {
  4308. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4309. {
  4310. Terminal->RefreshDirectory();
  4311. }
  4312. FRefreshRemoteDirectory = false;
  4313. }
  4314. if (FRefreshLocalDirectory)
  4315. {
  4316. ReloadLocalDirectory();
  4317. FRefreshLocalDirectory = false;
  4318. }
  4319. if (WinConfiguration->RefreshRemotePanel)
  4320. {
  4321. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4322. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4323. {
  4324. RemoteDirView->ReloadDirectory();
  4325. }
  4326. }
  4327. }
  4328. }
  4329. if (FShowing || FStandaloneEditing)
  4330. {
  4331. if (FQueueStatusInvalidated)
  4332. {
  4333. UpdateQueueStatus(false);
  4334. }
  4335. RefreshQueueItems();
  4336. }
  4337. if (FShowing)
  4338. {
  4339. UpdateStatusBar();
  4340. }
  4341. FIgnoreNextDialogChar = 0;
  4342. }
  4343. //---------------------------------------------------------------------------
  4344. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4345. {
  4346. try
  4347. {
  4348. FUserActionTimer->Enabled = false;
  4349. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4350. {
  4351. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4352. {
  4353. FPendingQueueActionItem->ProcessUserAction();
  4354. }
  4355. }
  4356. }
  4357. __finally
  4358. {
  4359. FPendingQueueActionItem = NULL;
  4360. }
  4361. }
  4362. //---------------------------------------------------------------------------
  4363. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4364. {
  4365. if (WinConfiguration->MinimizeToTray)
  4366. {
  4367. UpdateTrayIcon();
  4368. FTrayIcon->Visible = true;
  4369. if (Visible)
  4370. {
  4371. ShowWindow(Handle, SW_HIDE);
  4372. }
  4373. }
  4374. }
  4375. //---------------------------------------------------------------------------
  4376. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4377. {
  4378. // WORKAROUND
  4379. // When restoring maximized window from minimization,
  4380. // rarely some controls do not align properly.
  4381. // Two instances seen (both for Commander):
  4382. // - When restoring, window is temporarily narrower (not maximized),
  4383. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4384. // Once maximized already, top dock shinks back, but the session PageControl,
  4385. // do not align up, leaving space between TopDock and PageControl.
  4386. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4387. for (int Index = 0; Index < ControlCount; Index++)
  4388. {
  4389. RealignControl(Controls[Index]);
  4390. }
  4391. if (FTrayIcon->Visible)
  4392. {
  4393. FTrayIcon->Visible = false;
  4394. if (Visible)
  4395. {
  4396. ShowWindow(Handle, SW_SHOW);
  4397. }
  4398. }
  4399. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4400. {
  4401. FNeedSession = false;
  4402. NonVisualDataModule->StartBusy();
  4403. try
  4404. {
  4405. NeedSession(true);
  4406. }
  4407. __finally
  4408. {
  4409. NonVisualDataModule->EndBusy();
  4410. }
  4411. }
  4412. }
  4413. //---------------------------------------------------------------------------
  4414. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4415. {
  4416. FTrayIcon->Hint = GetMainForm()->Caption;
  4417. }
  4418. //---------------------------------------------------------------------------
  4419. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4420. {
  4421. UpdateTrayIcon();
  4422. }
  4423. //---------------------------------------------------------------------------
  4424. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4425. {
  4426. // workaround
  4427. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4428. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4429. // But WM_ACTIVATEAPP message can be received even when
  4430. // the main window is minimized to the tray and internal editor window is focused
  4431. // (after another application was previously active)
  4432. if (::IsIconic(Handle))
  4433. {
  4434. if (!IsAppIconic())
  4435. {
  4436. SetAppIconic(true);
  4437. }
  4438. }
  4439. ::ApplicationRestore();
  4440. Application->BringToFront();
  4441. }
  4442. //---------------------------------------------------------------------------
  4443. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4444. {
  4445. RestoreApp();
  4446. }
  4447. //---------------------------------------------------------------------------
  4448. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4449. {
  4450. if (OpenInNewWindow())
  4451. {
  4452. ExecuteNewInstance(SessionUrl);
  4453. }
  4454. else
  4455. {
  4456. TTerminalManager::Instance()->NewSession(SessionUrl);
  4457. }
  4458. }
  4459. //---------------------------------------------------------------------------
  4460. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4461. {
  4462. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4463. StoredSessions->NewSession(SessionName, SessionData);
  4464. // modified only, explicit
  4465. StoredSessions->Save(false, true);
  4466. // encode session name because of slashes in hierarchical sessions
  4467. return EncodeUrlString(SessionName);
  4468. }
  4469. //---------------------------------------------------------------------------
  4470. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4471. {
  4472. // current working directories become defaults here, what is not right
  4473. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4474. return SaveHiddenDuplicateSession(SessionData.get());
  4475. }
  4476. //---------------------------------------------------------------------------
  4477. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4478. {
  4479. if (OpenInNewWindow())
  4480. {
  4481. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4482. }
  4483. else
  4484. {
  4485. // current working directories become defaults here, what is not right
  4486. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4487. TTerminalManager * Manager = TTerminalManager::Instance();
  4488. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4489. // We definitelly want this
  4490. ATerminal->Disconnected = Terminal->Disconnected;
  4491. // Not sure about these two
  4492. ATerminal->Permanent = Terminal->Permanent;
  4493. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4494. Manager->ActiveTerminal = ATerminal;
  4495. }
  4496. }
  4497. //---------------------------------------------------------------------------
  4498. void __fastcall TCustomScpExplorerForm::RenameSession()
  4499. {
  4500. UnicodeString Name = Terminal->SessionData->SessionName;
  4501. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4502. {
  4503. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4504. TSessionData::ValidateName(Name);
  4505. // This is inconsistent with how color (for example) is handled.
  4506. Terminal->SessionData->Name = Name;
  4507. UpdateControls();
  4508. // Add/Remove distinguishing paths from sessions of the same name.
  4509. DoTerminalListChanged();
  4510. }
  4511. }
  4512. //---------------------------------------------------------------------------
  4513. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4514. {
  4515. DebugAssert(Queue != NULL);
  4516. bool Result = Queue->IsEmpty;
  4517. if (!Result)
  4518. {
  4519. SetFocus();
  4520. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4521. }
  4522. return Result;
  4523. }
  4524. //---------------------------------------------------------------------------
  4525. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4526. {
  4527. return CanCloseQueue(FQueue);
  4528. }
  4529. //---------------------------------------------------------------------------
  4530. void __fastcall TCustomScpExplorerForm::CloseSession()
  4531. {
  4532. if (CanCloseQueue())
  4533. {
  4534. TTerminalManager::Instance()->FreeActiveTerminal();
  4535. }
  4536. }
  4537. //---------------------------------------------------------------------------
  4538. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4539. {
  4540. if (CanCloseQueue())
  4541. {
  4542. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4543. }
  4544. }
  4545. //---------------------------------------------------------------------------
  4546. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4547. {
  4548. DetachTerminal(Terminal);
  4549. RemoteDirView->Terminal = Terminal;
  4550. UpdateRemotePathComboBox(false);
  4551. UpdateControls();
  4552. }
  4553. //---------------------------------------------------------------------------
  4554. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4555. {
  4556. if (DebugAlwaysTrue(!Terminal->Active))
  4557. {
  4558. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4559. }
  4560. }
  4561. //---------------------------------------------------------------------------
  4562. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4563. {
  4564. if (OpenInNewWindow())
  4565. {
  4566. // encode session name because of slashes in hierarchical sessions
  4567. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4568. }
  4569. else
  4570. {
  4571. TTerminalManager * Manager = TTerminalManager::Instance();
  4572. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4573. Manager->ActiveTerminal = Terminal;
  4574. }
  4575. }
  4576. //---------------------------------------------------------------------------
  4577. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4578. {
  4579. TTerminalManager * Manager = TTerminalManager::Instance();
  4580. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4581. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4582. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4583. // FirstTerminal can be null, if some of the
  4584. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4585. {
  4586. FirstTerminal->Disconnected = true;
  4587. FirstTerminal->DisconnectedTemporarily = true;
  4588. }
  4589. Manager->ActiveTerminal = FirstTerminal;
  4590. }
  4591. //---------------------------------------------------------------------------
  4592. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4593. {
  4594. if (OpenInNewWindow())
  4595. {
  4596. ExecuteNewInstance(Name);
  4597. }
  4598. else
  4599. {
  4600. DoOpenFolderOrWorkspace(Name, true);
  4601. }
  4602. }
  4603. //---------------------------------------------------------------------------
  4604. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4605. bool &CanClose)
  4606. {
  4607. // See the comment in CloseApp()
  4608. if (NonVisualDataModule->Busy)
  4609. {
  4610. CanClose = false;
  4611. }
  4612. else
  4613. {
  4614. TTerminalManager * Manager = TTerminalManager::Instance();
  4615. int ActiveSessions = 0;
  4616. for (int Index = 0; Index < Manager->Count; Index++)
  4617. {
  4618. if (Manager->Terminals[Index]->Active)
  4619. {
  4620. ActiveSessions++;
  4621. }
  4622. }
  4623. // Confirm, when there's at least one active remote session
  4624. if ((ActiveSessions > 0) &&
  4625. WinConfiguration->ConfirmClosingSession)
  4626. {
  4627. unsigned int Result;
  4628. TMessageParams Params(mpNeverAskAgainCheck);
  4629. UnicodeString Message;
  4630. int Answers = qaOK | qaCancel;
  4631. // The current session is the only active session
  4632. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4633. {
  4634. if (!WinConfiguration->AutoSaveWorkspace)
  4635. {
  4636. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4637. }
  4638. else
  4639. {
  4640. Message = LoadStr(CLOSE_SESSION);
  4641. }
  4642. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4643. }
  4644. // Multiple active sessions or one active session, but it's not the current one
  4645. else if (DebugAlwaysTrue(ActiveSessions > 0))
  4646. {
  4647. if (!WinConfiguration->AutoSaveWorkspace)
  4648. {
  4649. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4650. }
  4651. else
  4652. {
  4653. Message = LoadStr(CLOSE_SESSIONS);
  4654. }
  4655. }
  4656. UnicodeString Note;
  4657. if (WinConfiguration->AutoSaveWorkspace)
  4658. {
  4659. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4660. }
  4661. else
  4662. {
  4663. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4664. Answers = qaYes | qaNo | qaCancel;
  4665. }
  4666. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4667. SetFocus();
  4668. Result = MessageDialog(Message, qtConfirmation,
  4669. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4670. if (Result == qaNeverAskAgain)
  4671. {
  4672. WinConfiguration->ConfirmClosingSession = false;
  4673. }
  4674. if (Result == qaNo)
  4675. {
  4676. CanClose = SaveWorkspace(true);
  4677. // note that the workspace will be saved redundatly again from FormClose
  4678. }
  4679. else
  4680. {
  4681. CanClose =
  4682. (Result == qaOK) ||
  4683. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4684. (Result == qaNeverAskAgain);
  4685. }
  4686. }
  4687. if (CanClose && HasActiveTerminal())
  4688. {
  4689. CanClose = CanCloseQueue();
  4690. }
  4691. }
  4692. if (CanClose)
  4693. {
  4694. CanClose =
  4695. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4696. FEditorManager->CloseExternalFilesWithoutProcess();
  4697. if (CanClose)
  4698. {
  4699. while (CanClose && (FLocalEditors->Count > 0))
  4700. {
  4701. int PrevCount = FLocalEditors->Count;
  4702. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4703. CanClose = (FLocalEditors->Count < PrevCount);
  4704. }
  4705. if (CanClose)
  4706. {
  4707. CanClose = FEditorManager->Empty(true);
  4708. if (!CanClose)
  4709. {
  4710. SetFocus();
  4711. CanClose =
  4712. (MessageDialog(
  4713. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4714. }
  4715. }
  4716. }
  4717. }
  4718. }
  4719. //---------------------------------------------------------------------------
  4720. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4721. {
  4722. TForm * Form = dynamic_cast<TForm *>(Sender);
  4723. DebugAssert(Form != NULL);
  4724. Form->Close();
  4725. }
  4726. //---------------------------------------------------------------------------
  4727. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4728. {
  4729. TForm * Form = dynamic_cast<TForm *>(Sender);
  4730. delete Form;
  4731. }
  4732. //---------------------------------------------------------------------------
  4733. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4734. {
  4735. while (FLocalEditors->Count > 0)
  4736. {
  4737. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4738. }
  4739. }
  4740. //---------------------------------------------------------------------------
  4741. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4742. TObject *Sender)
  4743. {
  4744. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4745. try
  4746. {
  4747. SetProperties(osRemote, FileList);
  4748. }
  4749. __finally
  4750. {
  4751. delete FileList;
  4752. }
  4753. }
  4754. //---------------------------------------------------------------------------
  4755. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4756. {
  4757. if (value)
  4758. {
  4759. if (Component == fcCustomCommandsBand)
  4760. {
  4761. UpdateCustomCommandsToolbar();
  4762. }
  4763. if (Component == fcQueueFileList)
  4764. {
  4765. DebugAssert(!QueueFileListSplitter->Visible);
  4766. AdjustQueueLayout();
  4767. UpdateQueueFileList();
  4768. }
  4769. }
  4770. }
  4771. //---------------------------------------------------------------------------
  4772. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4773. {
  4774. int MinHeightLimit =
  4775. GetStaticQueuePanelComponentsHeight() +
  4776. QueueFileListSplitter->Height +
  4777. QueueFileList->Height +
  4778. GetMinQueueViewHeight();
  4779. if (QueuePanel->ClientHeight < MinHeightLimit)
  4780. {
  4781. QueuePanel->ClientHeight = MinHeightLimit;
  4782. }
  4783. }
  4784. //---------------------------------------------------------------------------
  4785. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4786. {
  4787. TControl * Control = GetComponent(Component);
  4788. DebugAssert(Control);
  4789. bool Changed = (Control->Visible != value);
  4790. if (Changed)
  4791. {
  4792. ComponentShowing(Component, value);
  4793. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4794. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4795. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4796. if (value)
  4797. {
  4798. int RemainingHeight = Control->Parent->ClientHeight;
  4799. int RemainingWidth = Control->Parent->ClientWidth;
  4800. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4801. {
  4802. TControl * ChildControl = Control->Parent->Controls[i];
  4803. if (ChildControl->Visible)
  4804. {
  4805. switch (ChildControl->Align)
  4806. {
  4807. case alTop:
  4808. case alBottom:
  4809. RemainingHeight -= ChildControl->Height;
  4810. break;
  4811. case alLeft:
  4812. case alRight:
  4813. RemainingWidth -= ChildControl->Width;
  4814. break;
  4815. }
  4816. }
  4817. }
  4818. int Reserve = ScaleByTextHeight(this, 32);
  4819. // queue in explorer, trees in commander
  4820. if (Control->Height > RemainingHeight - Reserve)
  4821. {
  4822. Control->Height = RemainingHeight / 2;
  4823. }
  4824. if (Control->Width > RemainingWidth - Reserve)
  4825. {
  4826. Control->Width = RemainingWidth / 2;
  4827. }
  4828. }
  4829. Control->Visible = value;
  4830. if (WasFocused && Visible)
  4831. {
  4832. DirView(osCurrent)->SetFocus();
  4833. }
  4834. FixControlsPlacement();
  4835. }
  4836. }
  4837. //---------------------------------------------------------------------------
  4838. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4839. {
  4840. TControl * Control = GetComponent(Component);
  4841. if (Control == NULL)
  4842. {
  4843. return false;
  4844. }
  4845. else
  4846. {
  4847. return Control->Visible;
  4848. }
  4849. }
  4850. //---------------------------------------------------------------------------
  4851. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4852. {
  4853. bool Result;
  4854. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4855. {
  4856. Result = !IsUWP();
  4857. }
  4858. else
  4859. {
  4860. Result = true;
  4861. }
  4862. return Result;
  4863. }
  4864. //---------------------------------------------------------------------------
  4865. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4866. {
  4867. if (DirView(osOther)->ItemFocused != NULL)
  4868. {
  4869. DirView(osOther)->ItemFocused->MakeVisible(false);
  4870. }
  4871. QueueSplitter->Visible = QueuePanel->Visible;
  4872. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4873. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4874. TControl * QueueControlsOrder[] =
  4875. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4876. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4877. }
  4878. //---------------------------------------------------------------------------
  4879. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4880. {
  4881. switch (Component) {
  4882. case fcStatusBar: return RemoteStatusBar;
  4883. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4884. case fcQueueView: return QueuePanel;
  4885. case fcQueueToolbar: return QueueDock;
  4886. case fcRemoteTree: return RemoteDrivePanel;
  4887. case fcSessionsTabs: return SessionsPageControl;
  4888. case fcQueueFileList: return QueueFileList;
  4889. default: return NULL;
  4890. }
  4891. }
  4892. //---------------------------------------------------------------------------
  4893. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4894. TObject *Sender, TListColumn *Column, TPoint &Point)
  4895. {
  4896. DebugAssert(NonVisualDataModule && Column && Sender);
  4897. NonVisualDataModule->ListColumn = Column;
  4898. TPopupMenu * DirViewColumnMenu;
  4899. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4900. {
  4901. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4902. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4903. (Column->Index == uvName);
  4904. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4905. (Column->Index == uvSize);
  4906. }
  4907. else
  4908. {
  4909. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4910. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4911. (Column->Index == dvName);
  4912. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4913. (Column->Index == dvSize);
  4914. }
  4915. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4916. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4917. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4918. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4919. }
  4920. //---------------------------------------------------------------------------
  4921. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4922. TObject *Sender, TListItem *Item, bool &AllowExec)
  4923. {
  4924. DoDirViewExecFile(Sender, Item, AllowExec);
  4925. }
  4926. //---------------------------------------------------------------------------
  4927. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4928. TListItem * Item, bool & AllowExec)
  4929. {
  4930. DebugAssert(Sender && Item && Configuration);
  4931. DebugAssert(AllowExec);
  4932. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4933. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4934. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4935. TOperationSide Side = (Remote ? osRemote : osLocal);
  4936. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4937. // on files only (not directories)
  4938. // and only when symlinks are resolved (apply to remote panel only)
  4939. if (!ADirView->ItemIsDirectory(Item) &&
  4940. (ResolvedSymlinks || FForceExecution))
  4941. {
  4942. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4943. !FForceExecution && ResolvedSymlinks)
  4944. {
  4945. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4946. {
  4947. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4948. UnlockWindow();
  4949. try
  4950. {
  4951. ExecuteFileOperation(
  4952. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4953. }
  4954. __finally
  4955. {
  4956. LockWindow();
  4957. }
  4958. AllowExec = false;
  4959. }
  4960. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4961. {
  4962. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4963. {
  4964. ExecuteFile(Side, efDefaultEditor);
  4965. AllowExec = false;
  4966. }
  4967. }
  4968. else
  4969. {
  4970. DebugFail();
  4971. }
  4972. }
  4973. // if we have not done anything special, fall back to default behavior
  4974. if (AllowExec)
  4975. {
  4976. if (Remote && !WinConfiguration->DisableOpenEdit)
  4977. {
  4978. ExecuteFile(osRemote, efShell);
  4979. AllowExec = false;
  4980. }
  4981. }
  4982. }
  4983. }
  4984. //---------------------------------------------------------------------------
  4985. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4986. {
  4987. return ((Side == osRemote) || (Side == osCurrent));
  4988. }
  4989. //---------------------------------------------------------------------------
  4990. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4991. {
  4992. DebugFail();
  4993. }
  4994. //---------------------------------------------------------------------------
  4995. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4996. {
  4997. DebugFail();
  4998. }
  4999. //---------------------------------------------------------------------------
  5000. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5001. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5002. {
  5003. TSynchronizeParamType Params;
  5004. Params.LocalDirectory = LocalDirectory;
  5005. Params.RemoteDirectory = RemoteDirectory;
  5006. int UnusedParams =
  5007. (GUIConfiguration->SynchronizeParams &
  5008. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5009. TTerminal::spCaseSensitive));
  5010. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5011. Params.Options = GUIConfiguration->SynchronizeOptions;
  5012. bool SaveSettings = false;
  5013. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5014. &DoSynchronizeTooManyDirectories);
  5015. DebugAssert(FSynchronizeController == NULL);
  5016. FSynchronizeController = &Controller;
  5017. bool Result;
  5018. try
  5019. {
  5020. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5021. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5022. int Options =
  5023. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5024. DebugAssert(FOnFeedSynchronizeError == NULL);
  5025. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5026. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5027. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5028. if (Result)
  5029. {
  5030. if (SaveSettings)
  5031. {
  5032. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5033. GUIConfiguration->SynchronizeOptions = Params.Options;
  5034. }
  5035. else
  5036. {
  5037. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5038. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5039. FLAGSET(Params.Options, soSynchronize))
  5040. {
  5041. GUIConfiguration->SynchronizeOptions =
  5042. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5043. soSynchronize;
  5044. }
  5045. }
  5046. LocalDirectory = Params.LocalDirectory;
  5047. RemoteDirectory = Params.RemoteDirectory;
  5048. }
  5049. }
  5050. __finally
  5051. {
  5052. FSynchronizeController = NULL;
  5053. DebugAssert(FOnFeedSynchronizeError == NULL);
  5054. FOnFeedSynchronizeError = NULL;
  5055. }
  5056. return Result;
  5057. }
  5058. //---------------------------------------------------------------------------
  5059. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5060. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5061. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5062. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5063. TSynchronizeOptions * Options, bool Full)
  5064. {
  5065. // Keep-up-to-date mode
  5066. if (Terminal->Status == ssOpened)
  5067. {
  5068. try
  5069. {
  5070. int PParams = Params.Params;
  5071. if (!Full)
  5072. {
  5073. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5074. if (FLAGSET(Params.Options, soRecurse))
  5075. {
  5076. PParams |= TTerminal::spSubDirs;
  5077. }
  5078. }
  5079. else
  5080. {
  5081. // if keepuptodate is non-recursive,
  5082. // full sync before has to be non-recursive as well
  5083. if (FLAGCLEAR(Params.Options, soRecurse))
  5084. {
  5085. PParams |= TTerminal::spNoRecurse;
  5086. }
  5087. }
  5088. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5089. PParams, Checklist, Options);
  5090. }
  5091. catch (Exception & E)
  5092. {
  5093. if (!Terminal->Active)
  5094. {
  5095. ShowExtendedExceptionEx(Terminal, &E);
  5096. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5097. if (!Terminal->Active)
  5098. {
  5099. throw;
  5100. }
  5101. }
  5102. else
  5103. {
  5104. if (FLAGSET(Params.Options, soContinueOnError) &&
  5105. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5106. {
  5107. // noop, already logged in MoreMessageDialog
  5108. }
  5109. else
  5110. {
  5111. // We get mostly EAbort here, so this is noop.
  5112. // Exception is an error when listing directories while looking for differences.
  5113. ShowExtendedExceptionEx(Terminal, &E);
  5114. throw;
  5115. }
  5116. }
  5117. }
  5118. }
  5119. }
  5120. //---------------------------------------------------------------------------
  5121. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5122. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5123. const UnicodeString ErrorStr)
  5124. {
  5125. if (!Directory.IsEmpty())
  5126. {
  5127. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5128. }
  5129. else
  5130. {
  5131. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5132. }
  5133. }
  5134. //---------------------------------------------------------------------------
  5135. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5136. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5137. {
  5138. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5139. {
  5140. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5141. }
  5142. else
  5143. {
  5144. TMessageParams Params(mpNeverAskAgainCheck);
  5145. unsigned int Result = MessageDialog(
  5146. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5147. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5148. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5149. {
  5150. MaxDirectories *= 2;
  5151. if (Result == qaNeverAskAgain)
  5152. {
  5153. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5154. }
  5155. }
  5156. else
  5157. {
  5158. Abort();
  5159. }
  5160. }
  5161. }
  5162. //---------------------------------------------------------------------------
  5163. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5164. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5165. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5166. TSynchronizeOptions * Options)
  5167. {
  5168. // Keep-up-to-date mode
  5169. DebugAssert(!FAutoOperation);
  5170. void * BatchStorage;
  5171. BatchStart(BatchStorage);
  5172. FAutoOperation = true;
  5173. bool AnyOperation = false;
  5174. TDateTime StartTime = Now();
  5175. TSynchronizeChecklist * AChecklist = NULL;
  5176. try
  5177. {
  5178. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5179. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5180. {
  5181. FSynchronizeProgressForm->Start();
  5182. }
  5183. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5184. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5185. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5186. Options);
  5187. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5188. SAFE_DESTROY(FSynchronizeProgressForm);
  5189. AnyOperation = (AChecklist->CheckedCount > 0);
  5190. if (AnyOperation)
  5191. {
  5192. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5193. CreateProgressForm(&SynchronizeProgress);
  5194. try
  5195. {
  5196. Terminal->SynchronizeApply(
  5197. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5198. SynchronizeProcessedItem, NULL, NULL, NULL);
  5199. }
  5200. __finally
  5201. {
  5202. DestroyProgressForm();
  5203. }
  5204. }
  5205. }
  5206. __finally
  5207. {
  5208. if (Checklist == NULL)
  5209. {
  5210. delete AChecklist;
  5211. }
  5212. else
  5213. {
  5214. *Checklist = AChecklist;
  5215. }
  5216. FAutoOperation = false;
  5217. SAFE_DESTROY(FSynchronizeProgressForm);
  5218. BatchEnd(BatchStorage);
  5219. ReloadLocalDirectory();
  5220. if (AnyOperation)
  5221. {
  5222. OperationComplete(StartTime);
  5223. }
  5224. }
  5225. }
  5226. //---------------------------------------------------------------------------
  5227. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5228. {
  5229. // can be called from command line
  5230. return Visible &&
  5231. ((DirView(osRemote)->SelCount > 0) ||
  5232. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5233. }
  5234. //---------------------------------------------------------------------------
  5235. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5236. {
  5237. LogSynchronizeEvent(Terminal, Message);
  5238. }
  5239. //---------------------------------------------------------------------------
  5240. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5241. int Params, TSynchronizeOptions & Options)
  5242. {
  5243. DebugAssert(!IsLocalBrowserMode());
  5244. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5245. {
  5246. Options.Filter = new TStringList();
  5247. Options.Filter->CaseSensitive = false;
  5248. Options.Filter->Duplicates = Types::dupAccept;
  5249. if (DirView(osRemote)->SelCount > 0)
  5250. {
  5251. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5252. }
  5253. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5254. {
  5255. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5256. }
  5257. Options.Filter->Sort();
  5258. }
  5259. }
  5260. //---------------------------------------------------------------------------
  5261. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5262. {
  5263. TCopyParamType Defaults;
  5264. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5265. ConfigStorage->AccessMode = smRead;
  5266. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5267. {
  5268. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5269. }
  5270. ConfigStorage.reset(NULL);
  5271. std::unique_ptr<TStringList> Options(new TStringList());
  5272. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5273. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5274. UnicodeString Result;
  5275. if (Options->Count > 0)
  5276. {
  5277. Result =
  5278. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5279. }
  5280. return Result;
  5281. }
  5282. //---------------------------------------------------------------------------
  5283. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5284. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5285. {
  5286. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5287. UnicodeString AdditionalParams =
  5288. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5289. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5290. SerializeCopyParamForCommandLine(CopyParams),
  5291. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5292. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5293. ExecuteNewInstance(SessionName, AdditionalParams);
  5294. }
  5295. //---------------------------------------------------------------------------
  5296. struct TSynchronizeParams
  5297. {
  5298. UnicodeString LocalDirectory;
  5299. UnicodeString RemoteDirectory;
  5300. TSynchronizeMode Mode;
  5301. TSynchronizeChecklist * Checklist;
  5302. int Params;
  5303. TCopyParamType * CopyParam;
  5304. TDateTime CollectElapsed;
  5305. TDateTime * StartTime;
  5306. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5307. };
  5308. //---------------------------------------------------------------------------
  5309. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5310. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5311. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5312. {
  5313. DebugAssert(!FAutoOperation);
  5314. void * BatchStorage;
  5315. BatchStart(BatchStorage);
  5316. FAutoOperation = true;
  5317. TFileOperationStatistics Statistics;
  5318. TDateTime Start = Now();
  5319. try
  5320. {
  5321. Params.OnProcessedItem = OnProcessedItem;
  5322. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5323. CreateProgressForm(&SynchronizeProgress);
  5324. Terminal->SynchronizeApply(
  5325. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5326. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5327. &Statistics);
  5328. }
  5329. __finally
  5330. {
  5331. Params.OnProcessedItem = NULL;
  5332. FAutoOperation = false;
  5333. DestroyProgressForm();
  5334. BatchEnd(BatchStorage);
  5335. ReloadLocalDirectory();
  5336. }
  5337. if (WinConfiguration->SynchronizeSummary)
  5338. {
  5339. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5340. // The statistics should be 0 anyway in this case
  5341. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5342. {
  5343. Message += L"\n";
  5344. if (Statistics.FilesUploaded > 0)
  5345. {
  5346. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5347. }
  5348. if (Statistics.FilesDownloaded > 0)
  5349. {
  5350. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5351. }
  5352. if (Statistics.FilesDeletedLocal > 0)
  5353. {
  5354. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5355. }
  5356. if (Statistics.FilesDeletedRemote > 0)
  5357. {
  5358. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5359. }
  5360. }
  5361. TDateTime Elapsed = (Now() - Start);
  5362. Message +=
  5363. L"\n" +
  5364. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5365. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5366. TMessageParams Params(mpNeverAskAgainCheck);
  5367. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5368. if (Result == qaNeverAskAgain)
  5369. {
  5370. WinConfiguration->SynchronizeSummary = false;
  5371. }
  5372. }
  5373. }
  5374. //---------------------------------------------------------------------------
  5375. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5376. {
  5377. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5378. {
  5379. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5380. }
  5381. // Not set in keep-up-to-date mode - Synchronize() method
  5382. if (Token != NULL)
  5383. {
  5384. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5385. if (Params.OnProcessedItem != NULL)
  5386. {
  5387. Params.OnProcessedItem(NULL, ChecklistItem);
  5388. }
  5389. }
  5390. }
  5391. //---------------------------------------------------------------------------
  5392. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5393. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5394. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5395. {
  5396. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5397. *Params.StartTime = Now();
  5398. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5399. }
  5400. //---------------------------------------------------------------------------
  5401. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5402. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5403. {
  5404. // terminal can be already closed (e.g. dropped connection)
  5405. if (Terminal != NULL)
  5406. {
  5407. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5408. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5409. }
  5410. }
  5411. //---------------------------------------------------------------------------
  5412. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5413. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5414. {
  5415. DebugAssert(!IsLocalBrowserMode());
  5416. TAutoBatch AutoBatch(this);
  5417. TAutoFlag AutoOperationFlag(FAutoOperation);
  5418. if (Side == osRemote)
  5419. {
  5420. std::unique_ptr<TStrings> FileList(new TStringList());
  5421. FileList->AddObject(FileName, RemoteFile);
  5422. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5423. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5424. RemoteDirView->SaveSelection();
  5425. RemoteDirView->SaveSelectedNames();
  5426. try
  5427. {
  5428. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5429. }
  5430. catch(...)
  5431. {
  5432. RemoteDirView->DiscardSavedSelection();
  5433. throw;
  5434. }
  5435. RemoteDirView->RestoreSelection();
  5436. }
  5437. else if (DebugAlwaysTrue(Side == osLocal))
  5438. {
  5439. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5440. {
  5441. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5442. }
  5443. UnicodeString Directory = ExtractFileDir(FileName);
  5444. ReloadLocalDirectory(Directory);
  5445. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5446. if (!SamePaths(Directory, NewDirectory))
  5447. {
  5448. ReloadLocalDirectory(NewDirectory);
  5449. }
  5450. }
  5451. }
  5452. //---------------------------------------------------------------------------
  5453. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5454. {
  5455. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5456. if (Side == osLocal)
  5457. {
  5458. if (Action == TSynchronizeChecklist::saDownloadNew)
  5459. {
  5460. OpenFolderInExplorer(LocalPath);
  5461. }
  5462. else
  5463. {
  5464. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5465. }
  5466. }
  5467. else if (DebugAlwaysTrue(Side == osRemote))
  5468. {
  5469. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5470. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5471. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5472. if (!LocalPath.IsEmpty())
  5473. {
  5474. SessionData->LocalDirectory = LocalPath;
  5475. }
  5476. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5477. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5478. }
  5479. }
  5480. //---------------------------------------------------------------------------
  5481. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5482. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5483. const TCopyParamType * CopyParams)
  5484. {
  5485. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5486. UnicodeString AdditionalParams =
  5487. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5488. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5489. SerializeCopyParamForCommandLine(CopyParams),
  5490. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5491. LocalDirectory, RemoteDirectory, Mode, Params));
  5492. ExecuteNewInstance(SessionName, AdditionalParams);
  5493. }
  5494. //---------------------------------------------------------------------------
  5495. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5496. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5497. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5498. {
  5499. int Result;
  5500. bool SaveSettings = false;
  5501. int Options =
  5502. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5503. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5504. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5505. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5506. bool Continue =
  5507. (UseDefaults == 0) ||
  5508. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5509. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5510. if (Continue)
  5511. {
  5512. Configuration->Usage->Inc(L"Synchronizations");
  5513. UpdateCopyParamCounters(CopyParam);
  5514. TSynchronizeOptions SynchronizeOptions;
  5515. GetSynchronizeOptions(Params, SynchronizeOptions);
  5516. if (SaveSettings)
  5517. {
  5518. GUIConfiguration->SynchronizeParams = Params;
  5519. }
  5520. else
  5521. {
  5522. SaveMode = false;
  5523. }
  5524. TDateTime StartTime = Now();
  5525. TSynchronizeChecklist * Checklist = NULL;
  5526. try
  5527. {
  5528. DebugAssert(!FAutoOperation);
  5529. FAutoOperation = true;
  5530. try
  5531. {
  5532. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5533. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5534. int Files = -1;
  5535. if (DataList->Count >= 1)
  5536. {
  5537. Files = StrToIntDef(DataList->Strings[0], Files);
  5538. }
  5539. else
  5540. {
  5541. DataList->Add(UnicodeString());
  5542. }
  5543. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5544. FSynchronizeProgressForm->Start();
  5545. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5546. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5547. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5548. &SynchronizeOptions);
  5549. if (Terminal->SessionData->CacheDirectories)
  5550. {
  5551. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5552. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5553. }
  5554. }
  5555. __finally
  5556. {
  5557. FAutoOperation = false;
  5558. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5559. SAFE_DESTROY(FSynchronizeProgressForm);
  5560. }
  5561. TSynchronizeParams SynchronizeParams;
  5562. SynchronizeParams.LocalDirectory = LocalDirectory;
  5563. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5564. SynchronizeParams.Mode = Mode;
  5565. SynchronizeParams.CopyParam = &CopyParam;
  5566. SynchronizeParams.Params = Params;
  5567. SynchronizeParams.Checklist = Checklist;
  5568. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5569. SynchronizeParams.StartTime = &StartTime;
  5570. SynchronizeParams.OnProcessedItem = NULL;
  5571. Result = Checklist->Count;
  5572. if (Checklist->Count > 0)
  5573. {
  5574. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5575. {
  5576. if (!DoSynchronizeChecklistDialog(
  5577. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5578. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5579. {
  5580. Result = -1;
  5581. }
  5582. }
  5583. else
  5584. {
  5585. FullSynchronize(SynchronizeParams, NULL, NULL);
  5586. }
  5587. }
  5588. else
  5589. {
  5590. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5591. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5592. }
  5593. }
  5594. __finally
  5595. {
  5596. delete Checklist;
  5597. }
  5598. OperationComplete(StartTime);
  5599. }
  5600. else
  5601. {
  5602. Result = -1;
  5603. }
  5604. return Result;
  5605. }
  5606. //---------------------------------------------------------------------------
  5607. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5608. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5609. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5610. {
  5611. if (Collect)
  5612. {
  5613. DebugAssert(FSynchronizeProgressForm != NULL);
  5614. if (!FSynchronizeProgressForm->Started)
  5615. {
  5616. FSynchronizeProgressForm->Start();
  5617. }
  5618. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5619. SetTaskbarListProgressValue(CompareProgress);
  5620. }
  5621. else
  5622. {
  5623. DebugAssert(FSynchronizeProgressForm == NULL);
  5624. DebugAssert(FProgressForm != NULL);
  5625. }
  5626. }
  5627. //---------------------------------------------------------------------------
  5628. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5629. {
  5630. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5631. TRemoteFile * File = NULL;
  5632. Terminal->ReadFile(FullFileName, File);
  5633. if (File != NULL)
  5634. {
  5635. std::unique_ptr<TRemoteFile> FileOwner(File);
  5636. TAutoFlag Flag(FStandaloneEditing);
  5637. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5638. Application->ShowMainForm = false;
  5639. Application->Run();
  5640. }
  5641. }
  5642. //---------------------------------------------------------------------------
  5643. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5644. {
  5645. DebugFail();
  5646. }
  5647. //---------------------------------------------------------------------------
  5648. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5649. {
  5650. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5651. SessionData->Assign(Terminal->SessionData);
  5652. UpdateSessionData(SessionData.get());
  5653. if (Terminal->Active)
  5654. {
  5655. Terminal->UpdateSessionCredentials(SessionData.get());
  5656. }
  5657. if (!Terminal->SessionData->HasSessionName())
  5658. {
  5659. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5660. // once IsWorkspace is cleared
  5661. SessionData->Name = UnicodeString();
  5662. }
  5663. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  5664. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  5665. SessionData->IsWorkspace = false;
  5666. return SessionData.release();
  5667. }
  5668. //---------------------------------------------------------------------------
  5669. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5670. {
  5671. TSessionData * SessionData = CloneCurrentSessionData();
  5672. try
  5673. {
  5674. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5675. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5676. }
  5677. __finally
  5678. {
  5679. delete SessionData;
  5680. }
  5681. }
  5682. //---------------------------------------------------------------------------
  5683. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5684. {
  5685. TTerminalManager * Manager = TTerminalManager::Instance();
  5686. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5687. if (DebugAlwaysTrue(Terminal != NULL))
  5688. {
  5689. // Update (Managed)Terminal->StateData
  5690. UpdateTerminal(Terminal);
  5691. }
  5692. Manager->SaveWorkspace(DataList.get());
  5693. return DataList.release();
  5694. }
  5695. //---------------------------------------------------------------------------
  5696. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5697. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5698. {
  5699. WinConfiguration->LastWorkspace = Name;
  5700. if (!SavePasswords)
  5701. {
  5702. for (int Index = 0; Index < DataList->Count; Index++)
  5703. {
  5704. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5705. if (SessionData->Link.IsEmpty())
  5706. {
  5707. SessionData->ClearSessionPasswords();
  5708. }
  5709. }
  5710. }
  5711. StoredSessions->NewWorkspace(Name, DataList);
  5712. // modified only
  5713. StoredSessions->Save(false, Explicit);
  5714. }
  5715. //---------------------------------------------------------------------------
  5716. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5717. {
  5718. return
  5719. DefaultStr(WinConfiguration->LastWorkspace,
  5720. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5721. }
  5722. //---------------------------------------------------------------------------
  5723. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5724. {
  5725. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5726. bool AnyNonStoredSessionWithPassword = false;
  5727. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5728. bool AllNonStoredSessionsAnonymous = true;
  5729. TTerminalManager * Manager = TTerminalManager::Instance();
  5730. for (int Index = 0; Index < DataList->Count; Index++)
  5731. {
  5732. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5733. if (SessionData->Link.IsEmpty())
  5734. {
  5735. if (SessionData->HasAnySessionPassword())
  5736. {
  5737. AnyNonStoredSessionWithPassword = true;
  5738. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5739. {
  5740. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5741. }
  5742. }
  5743. if (!SameText(SessionData->UserName, AnonymousUserName))
  5744. {
  5745. AllNonStoredSessionsAnonymous = false;
  5746. }
  5747. }
  5748. }
  5749. bool SavePasswords;
  5750. bool * PSavePasswords;
  5751. bool NotRecommendedSavingPasswords =
  5752. !CustomWinConfiguration->UseMasterPassword &&
  5753. !AllNonStoredSessionsAnonymous;
  5754. if (Configuration->DisablePasswordStoring ||
  5755. !AnyNonStoredSessionWithPassword)
  5756. {
  5757. PSavePasswords = NULL;
  5758. SavePasswords = false;
  5759. }
  5760. else
  5761. {
  5762. PSavePasswords = &SavePasswords;
  5763. SavePasswords =
  5764. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5765. !NotRecommendedSavingPasswords;
  5766. }
  5767. UnicodeString Name = WorkspaceName();
  5768. bool CreateShortcut = false;
  5769. bool Result =
  5770. DoSaveWorkspaceDialog(
  5771. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5772. EnableAutoSave);
  5773. if (Result)
  5774. {
  5775. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5776. if (CreateShortcut)
  5777. {
  5778. TOperationVisualizer Visualizer;
  5779. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5780. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5781. }
  5782. if (EnableAutoSave)
  5783. {
  5784. WinConfiguration->AutoSaveWorkspace = true;
  5785. WinConfiguration->AutoWorkspace = Name;
  5786. if (PSavePasswords != NULL)
  5787. {
  5788. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5789. }
  5790. }
  5791. }
  5792. return Result;
  5793. }
  5794. //---------------------------------------------------------------------------
  5795. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5796. {
  5797. DebugAssert(!IsLocalBrowserMode());
  5798. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5799. if (WinConfiguration->PreservePanelState)
  5800. {
  5801. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5802. }
  5803. UpdateSessionData(Terminal->StateData);
  5804. }
  5805. //---------------------------------------------------------------------------
  5806. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5807. {
  5808. // Keep in sync with TSessionData::CopyStateData
  5809. DebugAssert(!IsLocalBrowserMode());
  5810. DebugAssert(Data != NULL);
  5811. // This is inconsistent with how color (for example) is handled.
  5812. Data->Name = Terminal->SessionData->Name;
  5813. // cannot use RemoteDirView->Path, because it is empty if connection
  5814. // was already closed
  5815. // also only peek, we may not be connected at all atm
  5816. // so make sure we do not try retrieving current directory from the server
  5817. // (particularly with FTP)
  5818. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5819. if (!ACurrentDirectory.IsEmpty())
  5820. {
  5821. Data->RemoteDirectory = ACurrentDirectory;
  5822. }
  5823. Data->Color = SessionColor;
  5824. }
  5825. //---------------------------------------------------------------------------
  5826. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5827. {
  5828. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5829. DebugAssert(Toolbar != NULL);
  5830. for (int i = 0; i < Toolbar->Items->Count; i++)
  5831. {
  5832. TTBXCustomDropDownItem * DropDownItem;
  5833. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5834. if (DropDownItem != NULL)
  5835. {
  5836. ToolbarItemResize(DropDownItem,
  5837. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5838. Toolbar->NonClientWidth);
  5839. break;
  5840. }
  5841. }
  5842. }
  5843. //---------------------------------------------------------------------------
  5844. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5845. {
  5846. Item->EditWidth = Width;
  5847. }
  5848. //---------------------------------------------------------------------------
  5849. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5850. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5851. {
  5852. for (int i = 0; i < Toolbar->Items->Count; i++)
  5853. {
  5854. TTBXCustomDropDownItem * DropDownItem;
  5855. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5856. if (DropDownItem != NULL)
  5857. {
  5858. ASize.x -= DropDownItem->EditWidth;
  5859. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5860. }
  5861. }
  5862. }
  5863. //---------------------------------------------------------------------------
  5864. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5865. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5866. {
  5867. if (WinConfiguration->DDWarnLackOfTempSpace)
  5868. {
  5869. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5870. if (!ADrive.IsEmpty())
  5871. {
  5872. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5873. DebugAssert(RequiredSpace >= 0);
  5874. __int64 RequiredWithReserve;
  5875. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5876. if (FreeSpace < RequiredWithReserve)
  5877. {
  5878. unsigned int Result;
  5879. TMessageParams Params(mpNeverAskAgainCheck);
  5880. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5881. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5882. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5883. if (Result == qaNeverAskAgain)
  5884. {
  5885. WinConfiguration->DDWarnLackOfTempSpace = false;
  5886. }
  5887. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5888. }
  5889. }
  5890. }
  5891. }
  5892. //---------------------------------------------------------------------------
  5893. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5894. {
  5895. DoOpenDirectoryDialog(odAddBookmark, Side);
  5896. }
  5897. //---------------------------------------------------------------------------
  5898. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5899. {
  5900. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5901. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5902. try
  5903. {
  5904. TCustomDirView * DView = DirView(Side);
  5905. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5906. {
  5907. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5908. }
  5909. }
  5910. catch (...)
  5911. {
  5912. delete VisitedDirectories;
  5913. throw;
  5914. }
  5915. return VisitedDirectories;
  5916. }
  5917. //---------------------------------------------------------------------------
  5918. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5919. TOpenDirectoryMode Mode, TOperationSide Side)
  5920. {
  5921. bool Continue = true;
  5922. if (Mode == odAddBookmark)
  5923. {
  5924. TMessageParams Params(mpNeverAskAgainCheck);
  5925. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5926. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5927. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5928. unsigned int Answer =
  5929. MessageDialog(Message,
  5930. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5931. if (Answer == qaNeverAskAgain)
  5932. {
  5933. Continue = true;
  5934. WinConfiguration->UseSharedBookmarks = true;
  5935. }
  5936. else if (Answer == qaOK)
  5937. {
  5938. Continue = true;
  5939. WinConfiguration->UseSharedBookmarks = false;
  5940. }
  5941. else
  5942. {
  5943. Continue = false;
  5944. }
  5945. }
  5946. if (Continue)
  5947. {
  5948. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5949. try
  5950. {
  5951. UnicodeString Name = DirView(Side)->PathName;
  5952. bool Repeat;
  5953. do
  5954. {
  5955. Repeat = false;
  5956. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5957. // do not allow switching to location profiles,
  5958. // if we are not connected
  5959. HasDirView[osLocal] && (Terminal != NULL)))
  5960. {
  5961. TWindowLock Lock(this);
  5962. if (!TryOpenDirectory(Side, Name))
  5963. {
  5964. Repeat = true;
  5965. Mode = odBrowse;
  5966. }
  5967. }
  5968. }
  5969. while (Repeat);
  5970. }
  5971. __finally
  5972. {
  5973. delete VisitedDirectories;
  5974. }
  5975. }
  5976. }
  5977. //---------------------------------------------------------------------------
  5978. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5979. {
  5980. DebugAssert(!FTerminal->CommandSessionOpened);
  5981. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5982. }
  5983. //---------------------------------------------------------------------------
  5984. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5985. {
  5986. bool Result = FTerminal->IsCapable[Capability] ||
  5987. FTerminal->CommandSessionOpened;
  5988. if (!Result)
  5989. {
  5990. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5991. if (!GUIConfiguration->ConfirmCommandSession)
  5992. {
  5993. Result = true;
  5994. }
  5995. else
  5996. {
  5997. TMessageParams Params(mpNeverAskAgainCheck);
  5998. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5999. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6000. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6001. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6002. if (Answer == qaNeverAskAgain)
  6003. {
  6004. GUIConfiguration->ConfirmCommandSession = false;
  6005. Result = true;
  6006. }
  6007. else if (Answer == qaOK)
  6008. {
  6009. Result = true;
  6010. }
  6011. }
  6012. if (Result)
  6013. {
  6014. Result = CommandSessionFallback();
  6015. }
  6016. }
  6017. return Result;
  6018. }
  6019. //---------------------------------------------------------------------------
  6020. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6021. {
  6022. if (EnsureCommandSessionFallback(fcAnyCommand))
  6023. {
  6024. DoConsoleDialog(Terminal, Command);
  6025. }
  6026. }
  6027. //---------------------------------------------------------------------------
  6028. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6029. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6030. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6031. {
  6032. if (!IsSideLocalBrowser(osRemote) &&
  6033. IsFileControl(DropSourceControl, osRemote) &&
  6034. (FDDExtMapFile != NULL))
  6035. {
  6036. Accept = true;
  6037. }
  6038. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6039. DebugAssert(FDDTargetControl != NULL);
  6040. }
  6041. //---------------------------------------------------------------------------
  6042. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6043. _di_IDataObject DataObj, int KeyState,
  6044. const TPoint & Point, int & Effect, bool & Accept)
  6045. {
  6046. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6047. }
  6048. //---------------------------------------------------------------------------
  6049. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6050. _di_IDataObject DataObj, int KeyState,
  6051. const TPoint & Point, int & Effect, bool & Accept)
  6052. {
  6053. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6054. }
  6055. //---------------------------------------------------------------------------
  6056. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6057. TObject * Sender)
  6058. {
  6059. DebugUsedParam(Sender);
  6060. DebugAssert(FDDTargetControl == Sender);
  6061. FDDTargetControl = NULL;
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6065. {
  6066. FileControlDDDragLeave(SessionsPageControl);
  6067. }
  6068. //---------------------------------------------------------------------------
  6069. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6070. {
  6071. FileControlDDDragLeave(QueueView3);
  6072. }
  6073. //---------------------------------------------------------------------------
  6074. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6075. {
  6076. DebugAssert(!IsSideLocalBrowser(Side));
  6077. DebugUsedParam(Side);
  6078. bool Edit = false;
  6079. TRemoteFile * File = NULL;
  6080. UnicodeString FileName;
  6081. UnicodeString PointTo;
  6082. bool SymbolicLink = true;
  6083. if (RemoteDirView->ItemFocused)
  6084. {
  6085. DebugAssert(RemoteDirView->ItemFocused->Data);
  6086. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6087. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6088. if (Edit)
  6089. {
  6090. FileName = File->FileName;
  6091. PointTo = File->LinkTo;
  6092. }
  6093. else
  6094. {
  6095. PointTo = File->FileName;
  6096. }
  6097. }
  6098. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6099. Terminal->IsCapable[fcHardLink]))
  6100. {
  6101. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6102. if (Edit)
  6103. {
  6104. DebugAssert(File->FileName == FileName);
  6105. int Params = dfNoRecursive;
  6106. Terminal->ExceptionOnFail = true;
  6107. try
  6108. {
  6109. Terminal->DeleteFile(L"", File, &Params);
  6110. }
  6111. __finally
  6112. {
  6113. Terminal->ExceptionOnFail = false;
  6114. }
  6115. }
  6116. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6117. }
  6118. }
  6119. //---------------------------------------------------------------------------
  6120. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6121. {
  6122. return
  6123. (IsSideLocalBrowser(Side) ||
  6124. (HasActiveTerminal() &&
  6125. Terminal->ResolvingSymlinks &&
  6126. Terminal->IsCapable[fcSymbolicLink]));
  6127. }
  6128. //---------------------------------------------------------------------------
  6129. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6130. {
  6131. return
  6132. !IsSideLocalBrowser(FCurrentSide) &&
  6133. (RemoteDirView->ItemFocused != NULL) &&
  6134. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6135. Terminal->SessionData->ResolveSymlinks;
  6136. }
  6137. //---------------------------------------------------------------------------
  6138. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6139. {
  6140. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6141. FForceExecution = true;
  6142. try
  6143. {
  6144. DirView(osCurrent)->ExecuteCurrentFile();
  6145. }
  6146. __finally
  6147. {
  6148. FForceExecution = false;
  6149. }
  6150. }
  6151. //---------------------------------------------------------------------------
  6152. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6153. {
  6154. TEditorData ExternalEditor;
  6155. ExternalEditor.Editor = edExternal;
  6156. bool Remember = false;
  6157. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6158. {
  6159. if (Remember)
  6160. {
  6161. TEditorList * EditorList = new TEditorList;
  6162. try
  6163. {
  6164. *EditorList = *WinConfiguration->EditorList;
  6165. bool Found = false;
  6166. int i = 0;
  6167. while (!Found && (i < EditorList->Count))
  6168. {
  6169. const TEditorPreferences * Editor = EditorList->Editors[i];
  6170. if ((Editor->Data->Editor == edExternal) &&
  6171. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6172. {
  6173. Found = true;
  6174. }
  6175. i++;
  6176. }
  6177. if (!Found)
  6178. {
  6179. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6180. WinConfiguration->EditorList = EditorList;
  6181. }
  6182. }
  6183. __finally
  6184. {
  6185. delete EditorList;
  6186. }
  6187. }
  6188. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6189. }
  6190. }
  6191. //---------------------------------------------------------------------------
  6192. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6193. {
  6194. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6195. if (FFileFindTerminal == ATerminal)
  6196. {
  6197. FFileFindTerminal = NULL;
  6198. HideFileFindDialog();
  6199. }
  6200. if (FClipboardTerminal == ATerminal)
  6201. {
  6202. ClipboardClear(); // implies ClipboardStop
  6203. }
  6204. }
  6205. //---------------------------------------------------------------------------
  6206. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6207. {
  6208. DetachTerminal(Sender);
  6209. }
  6210. //---------------------------------------------------------------------------
  6211. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6212. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6213. {
  6214. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6215. DebugAssert(Terminal != NULL);
  6216. if (Data->Terminal == Terminal)
  6217. {
  6218. Data->Terminal = NULL;
  6219. }
  6220. }
  6221. //---------------------------------------------------------------------------
  6222. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6223. {
  6224. UpdateControls();
  6225. SessionColor = TColor(0);
  6226. UpdateRemotePathComboBox(false);
  6227. NeedSession(false);
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6231. {
  6232. try
  6233. {
  6234. // Cache, as the login dialog can change its value
  6235. // See also DoShow. Also see TTerminalManager::NewSession.
  6236. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6237. try
  6238. {
  6239. if (ShowLogin)
  6240. {
  6241. bool ReloadSessions = !Startup;
  6242. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6243. }
  6244. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6245. // This detects if workspace was saved the last time the main widow was closed
  6246. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6247. {
  6248. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6249. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6250. }
  6251. }
  6252. __finally
  6253. {
  6254. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6255. // (so there was no chance for the user to open any session yet)
  6256. if ((ShowLogin || !Startup) &&
  6257. !WinConfiguration->KeepOpenWhenNoSession &&
  6258. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6259. {
  6260. TerminateApplication();
  6261. }
  6262. }
  6263. }
  6264. catch (EAbort &)
  6265. {
  6266. // swallow
  6267. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6268. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6269. }
  6270. }
  6271. //---------------------------------------------------------------------------
  6272. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6273. {
  6274. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6275. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6276. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6277. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6278. try
  6279. {
  6280. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6281. // Clear the design time unthemed tab
  6282. ((SessionsPageControl->PageCount > 0) &&
  6283. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6284. {
  6285. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6286. }
  6287. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6288. {
  6289. TThemeTabSheet * TabSheet;
  6290. if (Index >= SessionsPageControl->PageCount)
  6291. {
  6292. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6293. TabSheet->PageControl = SessionsPageControl;
  6294. }
  6295. else
  6296. {
  6297. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6298. }
  6299. bool IsSessionTab = (Index < TerminalList->Count);
  6300. if (IsSessionTab)
  6301. {
  6302. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6303. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6304. UpdateSessionTab(TabSheet);
  6305. }
  6306. else
  6307. {
  6308. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6309. TabSheet->Tag = 0; // not really needed
  6310. TabSheet->Shadowed = false;
  6311. // 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)
  6312. UpdateNewSessionTab();
  6313. }
  6314. TabSheet->ShowCloseButton = IsSessionTab;
  6315. }
  6316. }
  6317. __finally
  6318. {
  6319. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6320. }
  6321. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6322. }
  6323. //---------------------------------------------------------------------------
  6324. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6325. {
  6326. DoTerminalListChanged();
  6327. }
  6328. //---------------------------------------------------------------------------
  6329. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6330. {
  6331. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6332. DebugAssert(TabSheet->ImageIndex == 0);
  6333. TabSheet->Caption =
  6334. WinConfiguration->SelectiveToolbarText ?
  6335. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6336. UnicodeString();
  6337. }
  6338. //---------------------------------------------------------------------------
  6339. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6340. {
  6341. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6342. }
  6343. //---------------------------------------------------------------------------
  6344. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6345. {
  6346. if (DebugAlwaysTrue(TabSheet != NULL))
  6347. {
  6348. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6349. if (DebugAlwaysTrue(ATerminal != NULL))
  6350. {
  6351. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6352. TabSheet->ImageIndex = AddSessionColor(Color);
  6353. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6354. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6355. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6356. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6357. {
  6358. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6359. }
  6360. }
  6361. }
  6362. }
  6363. //---------------------------------------------------------------------------
  6364. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6365. {
  6366. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6367. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6368. bool Result = (Terminal != NULL);
  6369. if (Result)
  6370. {
  6371. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6372. }
  6373. else
  6374. {
  6375. try
  6376. {
  6377. NewSession();
  6378. }
  6379. __finally
  6380. {
  6381. DoTerminalListChanged();
  6382. }
  6383. FSessionsPageControlNewSessionTime = Now();
  6384. }
  6385. return Result;
  6386. }
  6387. //---------------------------------------------------------------------------
  6388. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6389. {
  6390. SessionTabSwitched();
  6391. }
  6392. //---------------------------------------------------------------------------
  6393. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6394. {
  6395. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6396. DebugAssert(TransferList != NULL);
  6397. UnicodeString Name;
  6398. if (TransferList->ItemIndex <= 0)
  6399. {
  6400. Name = L"";
  6401. }
  6402. else
  6403. {
  6404. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6405. }
  6406. if (FCopyParamAutoSelected.IsEmpty())
  6407. {
  6408. // if previous preset was not autoselected, make new preset the "default"
  6409. FCopyParamDefault = Name;
  6410. }
  6411. GUIConfiguration->CopyParamCurrent = Name;
  6412. }
  6413. //---------------------------------------------------------------------------
  6414. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6415. {
  6416. // sanity check
  6417. bool ExistingPreset =
  6418. (FTransferListHoverIndex >= 0) &&
  6419. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6420. DebugAssert(ExistingPreset);
  6421. if (ExistingPreset)
  6422. {
  6423. HDC DC = GetDC(0);
  6424. TCanvas * Canvas = new TCanvas();
  6425. try
  6426. {
  6427. Canvas->Handle = DC;
  6428. Canvas->Font = GetToolbarFont(this);
  6429. UnicodeString Name;
  6430. if (FTransferListHoverIndex == 0)
  6431. {
  6432. Name = L"";
  6433. }
  6434. else
  6435. {
  6436. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6437. }
  6438. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6439. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6440. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6441. static_cast<TObject*>(GetComponent(fcTransferList)));
  6442. UnicodeString InfoStr =
  6443. GUIConfiguration->CopyParamPreset[Name].
  6444. GetInfoStr(L"; ",
  6445. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6446. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6447. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6448. {
  6449. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6450. {
  6451. InfoStr.SetLength(InfoStr.Length() - 1);
  6452. }
  6453. InfoStr += Ellipsis;
  6454. }
  6455. // UpdateCaption does not cause invalidation of whole submenu, while
  6456. // setting Caption property does.
  6457. // also it probably does not resize the label, even if necessary
  6458. // (we do not want that anyway)
  6459. TransferLabel->UpdateCaption(InfoStr);
  6460. }
  6461. __finally
  6462. {
  6463. Canvas->Handle = NULL;
  6464. ReleaseDC(0, DC);
  6465. delete Canvas;
  6466. }
  6467. }
  6468. }
  6469. //---------------------------------------------------------------------------
  6470. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6471. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6472. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6473. {
  6474. if (FTransferListHoverIndex != AHoverIndex)
  6475. {
  6476. FTransferListHoverIndex = AHoverIndex;
  6477. UpdateTransferLabel();
  6478. }
  6479. }
  6480. //---------------------------------------------------------------------------
  6481. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6482. {
  6483. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6484. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6485. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6486. {
  6487. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6488. {
  6489. if (!NonVisualDataModule->Busy)
  6490. {
  6491. OpenDirectory(GetSide(osCurrent));
  6492. }
  6493. Message.Result = 1;
  6494. }
  6495. else
  6496. {
  6497. TForm::Dispatch(&Message);
  6498. }
  6499. }
  6500. else
  6501. {
  6502. TForm::Dispatch(&Message);
  6503. }
  6504. }
  6505. //---------------------------------------------------------------------------
  6506. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6507. {
  6508. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6509. if ((FIgnoreNextDialogChar != 0) &&
  6510. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6511. {
  6512. Message.Result = 1;
  6513. }
  6514. else
  6515. {
  6516. TForm::Dispatch(&Message);
  6517. }
  6518. FIgnoreNextDialogChar = 0;
  6519. }
  6520. //---------------------------------------------------------------------------
  6521. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6522. {
  6523. // The four low-order bits are used internally by Windows
  6524. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6525. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6526. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6527. // 61730 - restore thru double click - undocumented
  6528. // 61490 - maximize thru double click - undocumented
  6529. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6530. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6531. {
  6532. SysResizing(Cmd);
  6533. }
  6534. TForm::Dispatch(&Message);
  6535. }
  6536. //---------------------------------------------------------------------------
  6537. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6538. {
  6539. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6540. // Also there no point returning TRUE as we are not able to
  6541. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6542. // Hence the process termination might be safer :)
  6543. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6544. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6545. {
  6546. Message.Result = FALSE;
  6547. }
  6548. else
  6549. {
  6550. Message.Result = TRUE;
  6551. }
  6552. // Do not call default handling as that triggers OnCloseQuery,
  6553. // where our implementation will popup confirmation dialogs, what we do not want,
  6554. // as per Vista guidelines:
  6555. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6556. }
  6557. //---------------------------------------------------------------------------
  6558. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6559. {
  6560. if (Message.EndSession && IsApplicationMinimized())
  6561. {
  6562. // WORKAROUND
  6563. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6564. // when it receives WM_ENDSESSION,
  6565. // but that sometimes (particularly when application is minimized) cause crashes.
  6566. // Crash popups message that blocks log off.
  6567. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6568. // so we call ExitProcess() immediately, not even trying to cleanup.
  6569. // It still causes beep, so there's likely some popup, but it does not block
  6570. // log off.
  6571. ExitProcess(0);
  6572. }
  6573. TForm::Dispatch(&Message);
  6574. }
  6575. #ifdef _DEBUG
  6576. //---------------------------------------------------------------------------
  6577. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6578. {
  6579. TForm::Dispatch(&Message);
  6580. }
  6581. #endif
  6582. //---------------------------------------------------------------------------
  6583. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6584. {
  6585. }
  6586. //---------------------------------------------------------------------------
  6587. void __fastcall TCustomScpExplorerForm::DoShow()
  6588. {
  6589. // only now are the controls resized finally, so the size constraints
  6590. // will not conflict with possibly very small window size
  6591. RestoreFormParams();
  6592. // This indicates that the form was rescaled after parameters were loaded and
  6593. // as most probably the parameters were actually saved with the current form scaling
  6594. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6595. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6596. // and no rounding problems will occur.
  6597. // See also RestoreForm.
  6598. // (we should be safe to call RestoreParams unconditionally)
  6599. if (PixelsPerInch != Screen->PixelsPerInch)
  6600. {
  6601. RestoreParams();
  6602. }
  6603. FixControlsPlacement();
  6604. if (Position == poDefaultPosOnly)
  6605. {
  6606. CutFormToDesktop(this);
  6607. }
  6608. TForm::DoShow();
  6609. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6610. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6611. if (Terminal == NULL)
  6612. {
  6613. StartingDisconnected();
  6614. }
  6615. UpdatePixelsPerInchMainWindowCounter();
  6616. FShowing = true;
  6617. }
  6618. //---------------------------------------------------------------------------
  6619. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6620. {
  6621. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6622. }
  6623. //---------------------------------------------------------------------------
  6624. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6625. {
  6626. DoTerminalListChanged();
  6627. }
  6628. //---------------------------------------------------------------------------
  6629. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6630. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6631. TNotifyEvent OnBalloonClick, TObject * UserData)
  6632. {
  6633. bool Do;
  6634. UnicodeString Message;
  6635. if (E == NULL)
  6636. {
  6637. Message = Str;
  6638. Do = true;
  6639. }
  6640. else
  6641. {
  6642. Do = ExceptionMessage(E, Message);
  6643. }
  6644. if (Do && WinConfiguration->BalloonNotifications)
  6645. {
  6646. UnicodeString Title;
  6647. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6648. {
  6649. Message = TrimLeft(Message);
  6650. }
  6651. else
  6652. {
  6653. Message = UnformatMessage(Message);
  6654. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6655. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6656. Title = LoadResourceString(Captions[Type]);
  6657. if (Terminal != NULL)
  6658. {
  6659. Title = FORMAT(L"%s - %s",
  6660. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6661. }
  6662. }
  6663. if (Seconds == 0)
  6664. {
  6665. Seconds = WinConfiguration->NotificationsTimeout;
  6666. }
  6667. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6668. }
  6669. }
  6670. //---------------------------------------------------------------------------
  6671. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6672. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6673. UnicodeString HelpKeyword, const TMessageParams * Params,
  6674. TTerminal * Terminal)
  6675. {
  6676. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6677. (FOnFeedSynchronizeError != NULL)) &&
  6678. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6679. {
  6680. if (FOnFeedSynchronizeError != NULL)
  6681. {
  6682. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6683. }
  6684. else
  6685. {
  6686. DebugAssert(FErrorList != NULL);
  6687. TStringList * MoreMessagesCopy = NULL;
  6688. if (MoreMessages)
  6689. {
  6690. MoreMessagesCopy = new TStringList();
  6691. MoreMessagesCopy->Assign(MoreMessages);
  6692. }
  6693. FErrorList->AddObject(Message, MoreMessagesCopy);
  6694. }
  6695. PopupTrayBalloon(Terminal, Message, Type);
  6696. return ContinueAnswer(Answers);
  6697. }
  6698. else
  6699. {
  6700. bool UseBalloon = FTrayIcon->Visible;
  6701. if (UseBalloon)
  6702. {
  6703. PopupTrayBalloon(Terminal, Message, Type);
  6704. }
  6705. unsigned int Result;
  6706. try
  6707. {
  6708. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6709. }
  6710. __finally
  6711. {
  6712. // cancel only balloon we popped up, otherwise we may cancel notification
  6713. // balloon that was there before the message dialog
  6714. // (such as "dd confirmation opt in balloon)
  6715. if (UseBalloon)
  6716. {
  6717. FTrayIcon->CancelBalloon();
  6718. }
  6719. }
  6720. return Result;
  6721. }
  6722. }
  6723. //---------------------------------------------------------------------------
  6724. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6725. TTerminal * Terminal, Exception * E)
  6726. {
  6727. if (FTrayIcon->Visible)
  6728. {
  6729. PopupTrayBalloon(Terminal, L"", qtError, E);
  6730. }
  6731. // particularly prevent opening new session from jump list,
  6732. // while exception is shown
  6733. NonVisualDataModule->StartBusy();
  6734. try
  6735. {
  6736. ShowExtendedExceptionEx(Terminal, E);
  6737. }
  6738. __finally
  6739. {
  6740. NonVisualDataModule->EndBusy();
  6741. FTrayIcon->CancelBalloon();
  6742. }
  6743. }
  6744. //---------------------------------------------------------------------------
  6745. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6746. {
  6747. if (Terminal->Active)
  6748. {
  6749. InitStatusBar();
  6750. }
  6751. // cannot rely on active page being page for active terminal,
  6752. // as it can happen that active page is the "new session" page
  6753. // (e.g. when reconnecting active terminal, while login dialog
  6754. // invoked from "new session" page is modal)
  6755. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6756. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6757. }
  6758. //---------------------------------------------------------------------------
  6759. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6760. TTerminal * Terminal, Exception * E)
  6761. {
  6762. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6763. if (!Terminal->Active)
  6764. {
  6765. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6766. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6767. {
  6768. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6769. }
  6770. }
  6771. }
  6772. //---------------------------------------------------------------------------
  6773. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6774. UnicodeString Message, TQueryType Type,
  6775. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6776. {
  6777. if ((E == NULL) ||
  6778. ExceptionMessage(E, Message))
  6779. {
  6780. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6781. if (Important)
  6782. {
  6783. Seconds *= 5;
  6784. }
  6785. UnicodeString NoteMessage(UnformatMessage(Message));
  6786. if (Terminal != NULL)
  6787. {
  6788. NoteMessage = FORMAT(L"%s: %s",
  6789. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6790. }
  6791. if (WinConfiguration->BalloonNotifications)
  6792. {
  6793. AddNote(NoteMessage);
  6794. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6795. }
  6796. else
  6797. {
  6798. FlashOnBackground();
  6799. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6800. }
  6801. }
  6802. }
  6803. //---------------------------------------------------------------------------
  6804. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6805. {
  6806. RestoreApp();
  6807. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6808. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6809. !NonVisualDataModule->Busy)
  6810. {
  6811. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6812. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6813. if (!ComponentVisible[fcQueueView])
  6814. {
  6815. ToggleQueueVisibility();
  6816. GoToQueue();
  6817. }
  6818. }
  6819. }
  6820. //---------------------------------------------------------------------------
  6821. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6822. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6823. {
  6824. UnicodeString Message;
  6825. TNotifyEvent OnClick = NULL;
  6826. TObject * UserData = NULL;
  6827. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6828. switch (Event)
  6829. {
  6830. case qeEmptyButMonitored:
  6831. if ((ATerminal != Terminal) || QueueInvisible)
  6832. {
  6833. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6834. OnClick = QueueEmptyNoteClicked;
  6835. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6836. TerminalNoteData->Terminal = ATerminal;
  6837. UserData = TerminalNoteData;
  6838. }
  6839. break;
  6840. case qeEmpty:
  6841. OperationComplete(ATerminal->QueueOperationStart);
  6842. break;
  6843. case qePendingUserAction:
  6844. if ((ATerminal != Terminal) ||
  6845. (QueueInvisible && !IsQueueAutoPopup()))
  6846. {
  6847. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6848. }
  6849. break;
  6850. default:
  6851. DebugFail();
  6852. }
  6853. if (!Message.IsEmpty())
  6854. {
  6855. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6856. }
  6857. }
  6858. //---------------------------------------------------------------------------
  6859. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6860. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6861. {
  6862. if (FDDExtMapFile != NULL)
  6863. {
  6864. CloseHandle(FDDExtMapFile);
  6865. FDDExtMapFile = NULL;
  6866. }
  6867. if (WinConfiguration->DDFakeFile)
  6868. {
  6869. DDFakeFileInitDrag(FileList, Created);
  6870. }
  6871. }
  6872. //---------------------------------------------------------------------------
  6873. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6874. {
  6875. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6876. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6877. {
  6878. FFakeFileDropTarget = FileName;
  6879. }
  6880. }
  6881. //---------------------------------------------------------------------------
  6882. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6883. {
  6884. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6885. if (!ForceDirectories(ApiPath(Result)))
  6886. {
  6887. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6888. }
  6889. FileSetAttr(ApiPath(Result), faHidden);
  6890. return Result;
  6891. }
  6892. //---------------------------------------------------------------------------
  6893. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6894. bool & Created)
  6895. {
  6896. FFakeFileDropTarget = UnicodeString();
  6897. FDragFakeDirectory = CreateFakeTransferDirectory();
  6898. FileList->AddItem(NULL, FDragFakeDirectory);
  6899. Created = true;
  6900. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6901. {
  6902. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6903. }
  6904. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6905. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6906. {
  6907. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6908. TDragExtCommStruct* CommStruct;
  6909. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6910. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6911. DebugAssert(CommStruct != NULL);
  6912. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6913. CommStruct->Dragging = true;
  6914. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6915. LENOF(CommStruct->DropDest));
  6916. NULL_TERMINATE(CommStruct->DropDest);
  6917. UnmapViewOfFile(CommStruct);
  6918. }
  6919. }
  6920. //---------------------------------------------------------------------------
  6921. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6922. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6923. {
  6924. bool Result;
  6925. DebugAssert(!IsLocalBrowserMode());
  6926. if (Sender == RemoteDirView)
  6927. {
  6928. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6929. }
  6930. else
  6931. {
  6932. DebugAssert(Sender == RemoteDriveView);
  6933. TStrings * FileList = RemoteDriveView->DragFileList();
  6934. try
  6935. {
  6936. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6937. }
  6938. __finally
  6939. {
  6940. delete FileList;
  6941. }
  6942. }
  6943. if (FDDTargetControl == RemoteDriveView)
  6944. {
  6945. RemoteDriveView->UpdateDropTarget();
  6946. }
  6947. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6948. // or from tree view to dir view.
  6949. // foMove happens when file/dir is dragged from remote tree view outside of
  6950. // application via dragex
  6951. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6952. (DropSourceControl == RemoteDriveView))
  6953. {
  6954. RemoteDriveView->UpdateDropSource();
  6955. }
  6956. return Result;
  6957. }
  6958. //---------------------------------------------------------------------------
  6959. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6960. {
  6961. DebugAssert(!IsLocalBrowserMode());
  6962. // This also handles drops of remote files to queue.
  6963. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6964. SAFE_DESTROY(FDDFileList);
  6965. if (!FFakeFileDropTarget.IsEmpty())
  6966. {
  6967. RemoveDir(ApiPath(FFakeFileDropTarget));
  6968. }
  6969. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6970. {
  6971. try
  6972. {
  6973. TDragResult DDResult = (Sender == RemoteDirView) ?
  6974. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6975. // Focus is moved to the target application,
  6976. // but as we are going to present the UI, we need to steal the focus back.
  6977. // This most likely won't work though (windows does not allow application
  6978. // to steal focus most of the time)
  6979. Application->BringToFront();
  6980. // On older version of Windows we never got drMove here, see also comment below.
  6981. // On Windows 10, we get the "move".
  6982. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6983. {
  6984. UnicodeString TargetDirectory;
  6985. TFileOperation Operation;
  6986. // drInvalid may mean drMove, see comment below
  6987. switch (DDResult)
  6988. {
  6989. case drCopy:
  6990. Operation = foCopy;
  6991. break;
  6992. case drMove:
  6993. Operation = foMove;
  6994. break;
  6995. default:
  6996. DebugFail();
  6997. case drInvalid:
  6998. // prefer "copy" for safety
  6999. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7000. break;
  7001. }
  7002. TTransferOperationParam Param;
  7003. UnicodeString CounterName;
  7004. bool ForceQueue;
  7005. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7006. {
  7007. // we get drInvalid both if d&d was intercepted by ddext,
  7008. // and when users drops on no-drop location.
  7009. // we tell the difference by existence of response from ddext,
  7010. // so we ignore absence of response in this case
  7011. if (DDResult != drInvalid)
  7012. {
  7013. // here we know that the extension is installed,
  7014. // as it is checked as soon as drag&drop starts from
  7015. // RemoteFileControlDDCreateDragFileList
  7016. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7017. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7018. {
  7019. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7020. }
  7021. else
  7022. {
  7023. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7024. }
  7025. }
  7026. }
  7027. else
  7028. {
  7029. // download using fake file
  7030. Param.Temp = false;
  7031. Param.DragDrop = true;
  7032. if (ForceQueue)
  7033. {
  7034. Param.Queue = asOn;
  7035. }
  7036. if (Sender == RemoteDirView)
  7037. {
  7038. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7039. }
  7040. if (RemoteFileControlFileOperation(Sender, Operation,
  7041. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7042. {
  7043. Configuration->Usage->Inc(CounterName);
  7044. }
  7045. }
  7046. }
  7047. }
  7048. __finally
  7049. {
  7050. CloseHandle(FDDExtMapFile);
  7051. FDDExtMapFile = NULL;
  7052. delete FDragFakeMonitors;
  7053. FDragFakeMonitors = NULL;
  7054. RemoveDir(ApiPath(FDragFakeDirectory));
  7055. FDragFakeDirectory = L"";
  7056. FFakeFileDropTarget = UnicodeString();
  7057. }
  7058. }
  7059. if (FDragDropSshTerminate.get() != NULL)
  7060. {
  7061. FDragDropSshTerminate->Rethrow();
  7062. }
  7063. }
  7064. //---------------------------------------------------------------------------
  7065. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7066. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7067. {
  7068. // Remember drop effect so we know (when user drops files), if we copy or move
  7069. FLastDropEffect = dwEffect;
  7070. }
  7071. //---------------------------------------------------------------------------
  7072. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7073. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7074. {
  7075. bool Result;
  7076. if (FDDTargetControl == QueueView3)
  7077. {
  7078. Directory = DefaultDownloadTargetDirectory();
  7079. Result = true;
  7080. CounterName = L"DownloadsDragDropQueue";
  7081. ForceQueue = true;
  7082. }
  7083. else if (!FFakeFileDropTarget.IsEmpty())
  7084. {
  7085. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7086. Result = true;
  7087. ForceQueue = false;
  7088. CounterName = L"DownloadsDragDropFakeFile";
  7089. }
  7090. else
  7091. {
  7092. ForceQueue = false;
  7093. Enabled = false;
  7094. try
  7095. {
  7096. int Timer = 0;
  7097. Result = false;
  7098. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7099. {
  7100. {
  7101. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7102. TDragExtCommStruct* CommStruct;
  7103. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7104. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7105. DebugAssert(CommStruct != NULL);
  7106. Result = !CommStruct->Dragging;
  7107. if (Result)
  7108. {
  7109. Directory = ExtractFilePath(CommStruct->DropDest);
  7110. CounterName = L"DownloadsDragDropExternalExt";
  7111. }
  7112. UnmapViewOfFile(CommStruct);
  7113. }
  7114. if (!Result)
  7115. {
  7116. Sleep(50);
  7117. Timer += 50;
  7118. Application->ProcessMessages();
  7119. }
  7120. }
  7121. }
  7122. __finally
  7123. {
  7124. Enabled = true;
  7125. }
  7126. }
  7127. return Result;
  7128. }
  7129. //---------------------------------------------------------------------------
  7130. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7131. const UnicodeString TempDir, int SecDelay)
  7132. {
  7133. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7134. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7135. if (FDelayedDeletionTimer == NULL)
  7136. {
  7137. DebugAssert(HandleAllocated());
  7138. FDelayedDeletionTimer = new TTimer(this);
  7139. FDelayedDeletionTimer->Interval = 10000;
  7140. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7141. }
  7142. else
  7143. {
  7144. FDelayedDeletionTimer->Enabled = true;
  7145. }
  7146. }
  7147. //---------------------------------------------------------------------------
  7148. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7149. {
  7150. DebugAssert(FDelayedDeletionList != NULL);
  7151. TDateTime N = Now();
  7152. TDateTime Alert;
  7153. UnicodeString Directory;
  7154. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7155. {
  7156. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7157. if ((N >= Alert) || (Sender == NULL))
  7158. {
  7159. Directory = FDelayedDeletionList->Strings[Index];
  7160. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7161. {
  7162. FDelayedDeletionList->Delete(Index);
  7163. }
  7164. }
  7165. }
  7166. if (FDelayedDeletionList->Count == 0)
  7167. {
  7168. FDelayedDeletionTimer->Enabled = false;
  7169. }
  7170. }
  7171. //---------------------------------------------------------------------------
  7172. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7173. {
  7174. DebugAssert(!IsLocalBrowserMode());
  7175. if (IsFileControl(FDDTargetControl, osRemote) ||
  7176. (FDDTargetControl == SessionsPageControl))
  7177. {
  7178. TTerminal * TargetTerminal = NULL;
  7179. TFileOperation Operation = foNone;
  7180. if (FDDTargetControl == SessionsPageControl)
  7181. {
  7182. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7183. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7184. // do not allow dropping on the "+" and disconnected tabs
  7185. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7186. if (IsActiveTerminal(TargetTerminal))
  7187. {
  7188. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7189. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7190. {
  7191. Operation = foRemoteMove;
  7192. }
  7193. else
  7194. {
  7195. Operation = foRemoteCopy;
  7196. }
  7197. }
  7198. }
  7199. else
  7200. {
  7201. if (FLastDropEffect == DROPEFFECT_MOVE)
  7202. {
  7203. Operation = foRemoteMove;
  7204. }
  7205. else if (FLastDropEffect == DROPEFFECT_COPY)
  7206. {
  7207. Operation = foRemoteCopy;
  7208. }
  7209. }
  7210. if (Operation != foNone)
  7211. {
  7212. RemoteFileControlFileOperation(DropSourceControl,
  7213. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7214. }
  7215. // abort drag&drop
  7216. Abort();
  7217. }
  7218. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7219. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7220. (FDDTargetControl != QueueView3))
  7221. {
  7222. DebugAssert(!FDragTempDir.IsEmpty());
  7223. TTransferType Type;
  7224. UnicodeString TempDir = FDragTempDir;
  7225. // We clear FDragTempDir before calling
  7226. // just in case it fail (raises exception)
  7227. FDragTempDir = L"";
  7228. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7229. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7230. // empty directory parameter means temp directory -> don't display it!
  7231. UnicodeString TargetDir = L"";
  7232. int Options = 0;
  7233. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7234. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7235. {
  7236. Abort();
  7237. }
  7238. // TargetDir is set when dropped on local file control
  7239. // (this was workaround for legacy dirview event handling, now it should be
  7240. // made prettier)
  7241. if (TargetDir.IsEmpty())
  7242. {
  7243. TargetDir = TempDir;
  7244. if (ForceDirectories(ApiPath(TargetDir)))
  7245. {
  7246. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7247. FPendingTempSpaceWarn = true;
  7248. try
  7249. {
  7250. FDragDropOperation = true;
  7251. int Params = cpTemporary |
  7252. (Type == ttMove ? cpDelete : 0);
  7253. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7254. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7255. }
  7256. __finally
  7257. {
  7258. FDragDropOperation = false;
  7259. FPendingTempSpaceWarn = false;
  7260. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7261. }
  7262. }
  7263. else
  7264. {
  7265. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7266. }
  7267. }
  7268. }
  7269. }
  7270. //---------------------------------------------------------------------------
  7271. void __fastcall TCustomScpExplorerForm::DDDownload(
  7272. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7273. {
  7274. DebugAssert(!IsLocalBrowserMode());
  7275. TAutoBatch AutoBatch(this);
  7276. UpdateCopyParamCounters(*CopyParam);
  7277. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7278. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7279. {
  7280. RemoteDriveView->UpdateDropSource();
  7281. }
  7282. }
  7283. //---------------------------------------------------------------------------
  7284. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7285. {
  7286. public:
  7287. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7288. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7289. {
  7290. }
  7291. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7292. {
  7293. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7294. TDataObjectFilesEx::AllowData(FormatEtc);
  7295. }
  7296. };
  7297. //---------------------------------------------------------------------------
  7298. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7299. TObject * Sender, TDataObject *& DataObject)
  7300. {
  7301. if (FDDExtMapFile != NULL)
  7302. {
  7303. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7304. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7305. {
  7306. Abort();
  7307. }
  7308. if (FileList->Count > 0)
  7309. {
  7310. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7311. if (!FilesObject->IsValid(true, true))
  7312. {
  7313. FilesObject->_Release();
  7314. }
  7315. else
  7316. {
  7317. DataObject = FilesObject;
  7318. }
  7319. }
  7320. }
  7321. }
  7322. //---------------------------------------------------------------------------
  7323. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7324. {
  7325. DebugFail();
  7326. }
  7327. //---------------------------------------------------------------------------
  7328. void __fastcall TCustomScpExplorerForm::GoToTree()
  7329. {
  7330. ComponentVisible[fcRemoteTree] = true;
  7331. DriveView(osRemote)->SetFocus();
  7332. }
  7333. //---------------------------------------------------------------------------
  7334. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7335. TPanelExport Export)
  7336. {
  7337. TCustomDirView * DirView = this->DirView(Side);
  7338. std::unique_ptr<TStrings> ExportData(new TStringList());
  7339. switch (Export)
  7340. {
  7341. case pePath:
  7342. ExportData->Add(DirView->PathName);
  7343. break;
  7344. case peFileList:
  7345. case peFullFileList:
  7346. {
  7347. bool FullPath = (Export == peFullFileList);
  7348. DirView->CreateFileList(false, FullPath, ExportData.get());
  7349. for (int Index = 0; Index < ExportData->Count; Index++)
  7350. {
  7351. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7352. {
  7353. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7354. }
  7355. }
  7356. }
  7357. break;
  7358. default:
  7359. DebugFail();
  7360. }
  7361. return ExportData.release();
  7362. }
  7363. //---------------------------------------------------------------------------
  7364. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7365. TPanelExport Export, TPanelExportDestination Destination)
  7366. {
  7367. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7368. PanelExportStore(Side, Export, Destination, ExportData.get());
  7369. }
  7370. //---------------------------------------------------------------------------
  7371. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7372. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7373. TStrings * ExportData)
  7374. {
  7375. if (Destination == pedClipboard)
  7376. {
  7377. TInstantOperationVisualizer Visualizer;
  7378. CopyToClipboard(ExportData);
  7379. }
  7380. else
  7381. {
  7382. DebugFail();
  7383. }
  7384. }
  7385. //---------------------------------------------------------------------------
  7386. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7387. {
  7388. TCustomDirView * DirView = this->DirView(Side);
  7389. UnicodeString Mask = DirView->Mask;
  7390. if (DoFilterMaskDialog(DirView, Mask))
  7391. {
  7392. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7393. Configuration->Usage->Inc(L"Filters");
  7394. }
  7395. }
  7396. //---------------------------------------------------------------------------
  7397. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7398. {
  7399. return FQueueController->DefaultOperation();
  7400. }
  7401. //---------------------------------------------------------------------------
  7402. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7403. TQueueOperation Operation, void ** Param)
  7404. {
  7405. switch (Operation)
  7406. {
  7407. case qoPreferences:
  7408. return true;
  7409. case qoGoTo:
  7410. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7411. case qoOnceEmpty:
  7412. return IsAnythingQueued();
  7413. default:
  7414. return FQueueController->AllowOperation(Operation, Param);
  7415. }
  7416. }
  7417. //---------------------------------------------------------------------------
  7418. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7419. {
  7420. if (DebugAlwaysTrue(QueueView3->Visible))
  7421. {
  7422. QueueView3->SetFocus();
  7423. }
  7424. }
  7425. //---------------------------------------------------------------------------
  7426. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7427. TQueueOperation Operation, void * Param)
  7428. {
  7429. if (Operation == qoGoTo)
  7430. {
  7431. GoToQueue();
  7432. }
  7433. else if (Operation == qoPreferences)
  7434. {
  7435. PreferencesDialog(pmQueue);
  7436. }
  7437. else
  7438. {
  7439. FQueueController->ExecuteOperation(Operation, Param);
  7440. }
  7441. }
  7442. //---------------------------------------------------------------------------
  7443. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7444. {
  7445. return (Queue != NULL) && Queue->Enabled;
  7446. }
  7447. //---------------------------------------------------------------------------
  7448. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7449. {
  7450. DebugAssert(Queue != NULL);
  7451. if (Queue != NULL)
  7452. {
  7453. Queue->Enabled = !Queue->Enabled;
  7454. }
  7455. }
  7456. //---------------------------------------------------------------------------
  7457. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7458. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7459. {
  7460. FQueueActedItem = QueueView3->ItemFocused;
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7464. {
  7465. return TopDock->Height + QueueSplitter->Height;
  7466. }
  7467. //---------------------------------------------------------------------------
  7468. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7469. {
  7470. return
  7471. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7472. (QueueDock->Visible ? QueueDock->Height : 0) +
  7473. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7474. }
  7475. //---------------------------------------------------------------------------
  7476. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7477. {
  7478. return ScaleByTextHeight(this, 48);
  7479. }
  7480. //---------------------------------------------------------------------------
  7481. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7482. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7483. {
  7484. // when queue is hidden by double-clicking splitter, stray attempt to
  7485. // resize the panel with strange value arrives, make sure it is ignored
  7486. if (ComponentVisible[fcQueueView])
  7487. {
  7488. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7489. if (NewSize > MaxHeightLimit)
  7490. {
  7491. NewSize = MaxHeightLimit;
  7492. }
  7493. int MinHeightLimit =
  7494. GetStaticQueuePanelComponentsHeight() +
  7495. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7496. GetMinQueueViewHeight();
  7497. if (NewSize < MinHeightLimit)
  7498. {
  7499. NewSize = MinHeightLimit;
  7500. }
  7501. }
  7502. else
  7503. {
  7504. Accept = false;
  7505. }
  7506. }
  7507. //---------------------------------------------------------------------------
  7508. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7509. {
  7510. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7511. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7512. if (QueueViewHeight < GetMinQueueViewHeight())
  7513. {
  7514. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7515. }
  7516. }
  7517. //---------------------------------------------------------------------------
  7518. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7519. TDragObject *& /*DragObject*/)
  7520. {
  7521. FQueueActedItem = QueueView3->ItemFocused;
  7522. }
  7523. //---------------------------------------------------------------------------
  7524. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7525. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7526. {
  7527. Accept = true;
  7528. if (Source == QueueView3)
  7529. {
  7530. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7531. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7532. if (Accept)
  7533. {
  7534. TQueueItemProxy * QueueItem;
  7535. TQueueItemProxy * DestQueueItem;
  7536. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7537. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7538. Accept = (QueueItem != DestQueueItem) &&
  7539. (QueueItem->Status == TQueueItem::qsPending) &&
  7540. (DestQueueItem->Status == TQueueItem::qsPending);
  7541. }
  7542. }
  7543. }
  7544. //---------------------------------------------------------------------------
  7545. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7546. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7547. {
  7548. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7549. {
  7550. TQueueItemProxy * QueueItem;
  7551. TQueueItemProxy * DestQueueItem;
  7552. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7553. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7554. QueueItem->Move(DestQueueItem);
  7555. }
  7556. }
  7557. //---------------------------------------------------------------------------
  7558. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7559. {
  7560. if ((QueueView3->ItemFocused == NULL) &&
  7561. (QueueView3->Items->Count > 0))
  7562. {
  7563. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7564. }
  7565. QueueLabelUpdateStatus();
  7566. }
  7567. //---------------------------------------------------------------------------
  7568. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7569. {
  7570. QueueLabelUpdateStatus();
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7574. {
  7575. QueueLabel->UpdateStatus();
  7576. }
  7577. //---------------------------------------------------------------------------
  7578. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7579. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7580. {
  7581. if (Selected)
  7582. {
  7583. NonVisualDataModule->UpdateNonVisibleActions();
  7584. }
  7585. }
  7586. //---------------------------------------------------------------------------
  7587. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7588. {
  7589. TDragDropFilesEx * Result = NULL;
  7590. if (Sender == SessionsPageControl)
  7591. {
  7592. Result = FSessionsDragDropFilesEx;
  7593. }
  7594. else if (Sender == QueueView3)
  7595. {
  7596. Result = FQueueDragDropFilesEx;
  7597. }
  7598. else
  7599. {
  7600. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7601. if (DirView != NULL)
  7602. {
  7603. Result = DirView->DragDropFilesEx;
  7604. }
  7605. else
  7606. {
  7607. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7608. if (DriveView != NULL)
  7609. {
  7610. Result = DriveView->DragDropFilesEx;
  7611. }
  7612. }
  7613. }
  7614. DebugAssert(Result != NULL);
  7615. return Result;
  7616. }
  7617. //---------------------------------------------------------------------------
  7618. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7619. {
  7620. return (DView->SelCount == DView->FilesCount);
  7621. }
  7622. //---------------------------------------------------------------------------
  7623. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7624. {
  7625. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7626. }
  7627. //---------------------------------------------------------------------------
  7628. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7629. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7630. {
  7631. DebugAssert(!IsLocalBrowserMode());
  7632. TFileOperation Operation;
  7633. switch (Effect)
  7634. {
  7635. case DROPEFFECT_MOVE:
  7636. Operation = foMove;
  7637. break;
  7638. case DROPEFFECT_COPY:
  7639. // occures on WinXP (reported by user)
  7640. default:
  7641. Operation = foCopy;
  7642. break;
  7643. };
  7644. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7645. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7646. if (DragDropFilesEx->FileList->Count > 0)
  7647. {
  7648. TStrings * FileList = new TStringList();
  7649. try
  7650. {
  7651. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7652. {
  7653. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7654. }
  7655. FDragDropOperation = true;
  7656. TTransferOperationParam Param;
  7657. Param.TargetDirectory = TargetPath;
  7658. // upload, no temp dirs
  7659. Param.Temp = false;
  7660. Param.DragDrop = DragDrop;
  7661. Param.Options =
  7662. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7663. if (ForceQueue)
  7664. {
  7665. Param.Queue = asOn;
  7666. }
  7667. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7668. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7669. {
  7670. if (IsFileControl(DropSourceControl, osLocal))
  7671. {
  7672. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7673. }
  7674. else
  7675. {
  7676. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7677. }
  7678. }
  7679. }
  7680. __finally
  7681. {
  7682. FDragDropOperation = false;
  7683. delete FileList;
  7684. }
  7685. }
  7686. }
  7687. //---------------------------------------------------------------------------
  7688. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7689. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7690. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7691. {
  7692. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7693. }
  7694. //---------------------------------------------------------------------------
  7695. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7696. TObject * Sender, int grfKeyState, int & dwEffect)
  7697. {
  7698. DebugAssert(!IsLocalBrowserMode());
  7699. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7700. if ((dwEffect != DROPEFFECT_NONE) &&
  7701. IsFileControl(DropSourceControl, osRemote))
  7702. {
  7703. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7704. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7705. (RemoteDirView->DropTarget == NULL))
  7706. {
  7707. dwEffect = DROPEFFECT_NONE;
  7708. }
  7709. else
  7710. {
  7711. if (dwEffect == DROPEFFECT_COPY)
  7712. {
  7713. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7714. // currently we support copying always (at least via temporary directory);
  7715. // remove associated checks once this all proves stable and working
  7716. bool CopyCapable = true;
  7717. // if we do not support neither of operations, there's no discussion
  7718. if (!MoveCapable && !CopyCapable)
  7719. {
  7720. dwEffect = DROPEFFECT_NONE;
  7721. }
  7722. else
  7723. {
  7724. // The default effect inside remote panel is move,
  7725. // unless we do not support it, but support copy
  7726. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7727. {
  7728. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7729. }
  7730. else
  7731. {
  7732. // with ctrl-down, we want copy unless it is not supported
  7733. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7734. }
  7735. }
  7736. }
  7737. }
  7738. }
  7739. }
  7740. //---------------------------------------------------------------------------
  7741. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7742. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7743. {
  7744. DebugAssert(!IsLocalBrowserMode());
  7745. if (FDDTotalSize >= 0)
  7746. {
  7747. if (File->IsDirectory)
  7748. {
  7749. FDDTotalSize = -1;
  7750. }
  7751. else
  7752. {
  7753. FDDTotalSize += File->Size;
  7754. }
  7755. }
  7756. DebugAssert(!FDragTempDir.IsEmpty());
  7757. // TODO: this is quite ineffective
  7758. // TODO: what if invalid character replacement is disabled?
  7759. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7760. UnicodeString TransferFileName;
  7761. if (Sender == RemoteDriveView)
  7762. {
  7763. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7764. }
  7765. else
  7766. {
  7767. TransferFileName = File->FileName;
  7768. }
  7769. FDDFileList->AddObject(TransferFileName, File);
  7770. }
  7771. //---------------------------------------------------------------------------
  7772. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7773. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7774. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7775. {
  7776. // sometimes we do not get DDEnd so the list is not released
  7777. SAFE_DESTROY(FDDFileList);
  7778. FDDFileList = new TStringList();
  7779. FDragTempDir = WinConfiguration->TemporaryDir();
  7780. FDDTotalSize = 0;
  7781. FDragDropSshTerminate.reset(NULL);
  7782. }
  7783. //---------------------------------------------------------------------------
  7784. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7785. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7786. HRESULT & Result)
  7787. {
  7788. if (Result == DRAGDROP_S_DROP)
  7789. {
  7790. try
  7791. {
  7792. GlobalDragImageList->HideDragImage();
  7793. try
  7794. {
  7795. RemoteFileControlDDTargetDrop();
  7796. }
  7797. catch(ESshTerminate & E)
  7798. {
  7799. FDragDropSshTerminate.reset(E.Clone());
  7800. }
  7801. }
  7802. catch (Exception &E)
  7803. {
  7804. // If downloading fails we need to cancel drag&drop, otherwise
  7805. // Explorer shows error
  7806. // But by the way exception probably never reach this point as
  7807. // it's catched on way.
  7808. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7809. Result = DRAGDROP_S_CANCEL;
  7810. ShowExtendedException(Terminal, &E);
  7811. }
  7812. }
  7813. }
  7814. //---------------------------------------------------------------------------
  7815. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7816. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7817. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7818. {
  7819. TFileMasks::TParams MaskParams;
  7820. MaskParams.Size = Size;
  7821. MaskParams.Modification = Modification;
  7822. // this does not re-parse the mask if it is the same as the last time
  7823. FDirViewMatchMask = Masks;
  7824. bool ImplicitMatch;
  7825. Matches =
  7826. // RecurseInclude parameter has no effect as the Path is empty
  7827. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7828. (AllowImplicitMatches || !ImplicitMatch);
  7829. }
  7830. //---------------------------------------------------------------------------
  7831. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7832. TObject * Sender, TListItem * Item, WORD & Indexes)
  7833. {
  7834. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7835. UnicodeString Ext;
  7836. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7837. {
  7838. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7839. }
  7840. else
  7841. {
  7842. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7843. }
  7844. if (SameText(Ext, Configuration->PartialExt))
  7845. {
  7846. Indexes |= oiPartial;
  7847. }
  7848. }
  7849. //---------------------------------------------------------------------------
  7850. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7851. {
  7852. return
  7853. DirViewEnabled(osCurrent) &&
  7854. DirView(osCurrent)->CanPasteFromClipBoard();
  7855. }
  7856. //---------------------------------------------------------------------------
  7857. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7858. {
  7859. bool Result = false;
  7860. if (CanPasteToDirViewFromClipBoard())
  7861. {
  7862. Result = true;
  7863. }
  7864. else
  7865. {
  7866. UnicodeString ClipboardText;
  7867. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7868. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7869. {
  7870. if (StoredSessions->IsUrl(ClipboardText))
  7871. {
  7872. Result = true;
  7873. }
  7874. else
  7875. {
  7876. Result = DirViewEnabled(osCurrent);
  7877. }
  7878. }
  7879. }
  7880. return Result;
  7881. }
  7882. //---------------------------------------------------------------------------
  7883. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7884. {
  7885. if (DoesClipboardContainOurFiles())
  7886. {
  7887. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7888. {
  7889. DebugAssert(!IsLocalBrowserMode());
  7890. TTerminalManager * Manager = TTerminalManager::Instance();
  7891. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7892. Manager->ActiveTerminal = FClipboardTerminal;
  7893. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7894. }
  7895. }
  7896. else if (CanPasteToDirViewFromClipBoard())
  7897. {
  7898. DirView(osCurrent)->PasteFromClipBoard();
  7899. }
  7900. else
  7901. {
  7902. UnicodeString ClipboardText;
  7903. if (NonEmptyTextFromClipboard(ClipboardText))
  7904. {
  7905. if (StoredSessions->IsUrl(ClipboardText))
  7906. {
  7907. NewSession(ClipboardText);
  7908. }
  7909. else
  7910. {
  7911. DirView(osCurrent)->Path = ClipboardText;
  7912. }
  7913. }
  7914. }
  7915. }
  7916. //---------------------------------------------------------------------------
  7917. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7918. {
  7919. // TBD
  7920. }
  7921. //---------------------------------------------------------------------------
  7922. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7923. {
  7924. TCustomDirView * ADirView = DirView(Side);
  7925. ADirView->SelectAll(Mode);
  7926. ADirView->SetFocus();
  7927. }
  7928. //---------------------------------------------------------------------------
  7929. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7930. {
  7931. TCustomDirView * ADirView = DirView(Side);
  7932. TFileFilter Filter;
  7933. DefaultFileFilter(Filter);
  7934. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7935. {
  7936. Configuration->Usage->Inc(L"MaskSelections");
  7937. ADirView->SelectFiles(Filter, Select);
  7938. ADirView->SetFocus();
  7939. }
  7940. }
  7941. //---------------------------------------------------------------------------
  7942. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7943. {
  7944. TCustomDirView * ADirView = DirView(Side);
  7945. ADirView->RestoreSelectedNames();
  7946. ADirView->SetFocus();
  7947. }
  7948. //---------------------------------------------------------------------------
  7949. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7950. {
  7951. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7952. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7953. {
  7954. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7955. UnicodeString Ext;
  7956. if (!IsSideLocalBrowser(osCurrent))
  7957. {
  7958. Ext = UnixExtractFileExt(FileName);
  7959. }
  7960. else
  7961. {
  7962. Ext = ExtractFileExt(FileName);
  7963. }
  7964. if (Ext.IsEmpty())
  7965. {
  7966. Ext = L".";
  7967. }
  7968. TFileFilter Filter;
  7969. Filter.Masks = FORMAT(L"*%s", (Ext));
  7970. Filter.Directories = false;
  7971. CurrentDirView->SelectFiles(Filter, Select);
  7972. }
  7973. }
  7974. //---------------------------------------------------------------------------
  7975. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7976. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7977. {
  7978. UnicodeString Result;
  7979. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7980. {
  7981. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7982. }
  7983. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7984. {
  7985. // noop
  7986. }
  7987. else
  7988. {
  7989. Result =
  7990. FMTLOAD(FILE_INFO_FORMAT,
  7991. (FormatBytes(FileInfo.SelectedSize),
  7992. FormatBytes(FileInfo.FilesSize),
  7993. FormatNumber(FileInfo.SelectedCount),
  7994. FormatNumber(FileInfo.FilesCount)));
  7995. }
  7996. return Result;
  7997. }
  7998. //---------------------------------------------------------------------------
  7999. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8000. TTBXStatusPanel * Panel, TOperationSide Side)
  8001. {
  8002. if (Panel->Index == 1)
  8003. {
  8004. ToggleShowHiddenFiles();
  8005. }
  8006. else if (Panel->Index == 2)
  8007. {
  8008. Filter(Side);
  8009. }
  8010. }
  8011. //---------------------------------------------------------------------------
  8012. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8013. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8014. {
  8015. DebugAssert(!StatusBar->SimplePanel);
  8016. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8017. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8018. }
  8019. //---------------------------------------------------------------------------
  8020. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8021. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8022. {
  8023. DebugAssert(StatusBar->Panels->Count >= 3);
  8024. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8025. if (FileInfo.HiddenCount > 0)
  8026. {
  8027. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8028. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8029. }
  8030. else
  8031. {
  8032. HiddenFilesPanel->ViewPriority = 0;
  8033. // not really necessary, just to cleanup no-longer-valid data
  8034. HiddenFilesPanel->Caption = L"";
  8035. }
  8036. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8037. if (FileInfo.FilteredCount > 0)
  8038. {
  8039. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8040. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8041. }
  8042. else
  8043. {
  8044. FilteredFilesPanel->ViewPriority = 0;
  8045. // not really necessary, just to cleanup no-longer-valid data
  8046. FilteredFilesPanel->Caption = L"";
  8047. }
  8048. }
  8049. //---------------------------------------------------------------------------
  8050. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8051. TObject * /*Sender*/)
  8052. {
  8053. if (DirView(osRemote)->Enabled)
  8054. {
  8055. DirView(osRemote)->SetFocus();
  8056. }
  8057. }
  8058. //---------------------------------------------------------------------------
  8059. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8060. {
  8061. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8062. switch (Config.Show)
  8063. {
  8064. case qvShow:
  8065. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8066. {
  8067. Config.Show = qvHide;
  8068. }
  8069. else
  8070. {
  8071. Config.Show = Config.LastHideShow;
  8072. }
  8073. break;
  8074. case qvHideWhenEmpty:
  8075. if (ComponentVisible[fcQueueView])
  8076. {
  8077. Config.Show = qvHide;
  8078. }
  8079. else
  8080. {
  8081. Config.LastHideShow = Config.Show;
  8082. Config.Show = qvShow;
  8083. }
  8084. break;
  8085. case qvHide:
  8086. Config.LastHideShow = Config.Show;
  8087. Config.Show = qvShow;
  8088. break;
  8089. }
  8090. WinConfiguration->QueueView = Config;
  8091. }
  8092. //---------------------------------------------------------------------------
  8093. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8094. {
  8095. UnicodeString Result;
  8096. if (FTerminal != NULL)
  8097. {
  8098. switch (WinConfiguration->PathInCaption)
  8099. {
  8100. case picShort:
  8101. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8102. break;
  8103. case picFull:
  8104. Result = FTerminal->CurrentDirectory;
  8105. break;
  8106. }
  8107. }
  8108. return Result;
  8109. }
  8110. //---------------------------------------------------------------------------
  8111. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8112. {
  8113. TColor Result = GetWindowColor(FSessionColor);
  8114. return Result;
  8115. }
  8116. //---------------------------------------------------------------------------
  8117. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8118. {
  8119. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8120. return Result;
  8121. }
  8122. //---------------------------------------------------------------------------
  8123. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8124. {
  8125. TTerminalManager::Instance()->UpdateAppTitle();
  8126. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8127. // background to gray on Windows 7 (works on Windows 10).
  8128. // See also EnableControl
  8129. if (Showing)
  8130. {
  8131. if (Terminal != NULL)
  8132. {
  8133. // Update path when it changes
  8134. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8135. {
  8136. UpdateSessionTab(SessionsPageControl->ActivePage);
  8137. }
  8138. }
  8139. NonVisualDataModule->ReconnectSessionAction->Update();
  8140. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8141. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8142. CenterReconnectToolbar();
  8143. bool HasTerminal = HasActiveTerminal();
  8144. if (HasTerminal)
  8145. {
  8146. if (!RemoteDirView->Enabled)
  8147. {
  8148. RemoteDirView->Enabled = true;
  8149. if (FRemoteDirViewWasFocused)
  8150. {
  8151. ActiveControl = RemoteDirView;
  8152. }
  8153. }
  8154. RemoteDirView->Color = PanelColor();
  8155. }
  8156. else
  8157. {
  8158. if (RemoteDirView->Enabled)
  8159. {
  8160. // This is first called when the form is being constructed
  8161. // (not anymore due to Showing test above)
  8162. // but the false is overriden in the constructor later.
  8163. // An even later in TScpCommanderForm::DoShow()
  8164. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8165. RemoteDirView->Enabled = false;
  8166. }
  8167. RemoteDirView->Color = DisabledPanelColor();
  8168. }
  8169. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8170. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8171. RemoteDriveView->Color = RemoteDirView->Color;
  8172. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8173. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8174. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8175. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8176. QueueFileList->Enabled = QueueView3->Enabled;
  8177. QueueFileList->Color = QueueView3->Color;
  8178. QueueFileList->Font->Color = QueueView3->Font->Color;
  8179. QueueLabelUpdateStatus();
  8180. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8181. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8182. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8183. {
  8184. UpdateDarkMode();
  8185. }
  8186. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8187. }
  8188. }
  8189. //---------------------------------------------------------------------------
  8190. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8191. {
  8192. UpdateControls();
  8193. }
  8194. //---------------------------------------------------------------------------
  8195. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8196. TObject * Sender)
  8197. {
  8198. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8199. DebugAssert(DirView != NULL);
  8200. DoDirViewLoaded(DirView);
  8201. TransferPresetAutoSelect();
  8202. }
  8203. //---------------------------------------------------------------------------
  8204. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8205. {
  8206. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8207. // first run after installation
  8208. if (double(Updates.LastCheck) == 0)
  8209. {
  8210. // make sure next time there will be an update (if enabled)
  8211. Updates.LastCheck = TDateTime(1);
  8212. WinConfiguration->Updates = Updates;
  8213. }
  8214. else if ((double(Updates.Period) > 0) &&
  8215. (Now() - Updates.LastCheck >= Updates.Period))
  8216. {
  8217. TThreadMethod OnUpdatesChecked = NULL;
  8218. if (!IsUWP())
  8219. {
  8220. OnUpdatesChecked = UpdatesChecked;
  8221. }
  8222. StartUpdateThread(OnUpdatesChecked);
  8223. }
  8224. }
  8225. //---------------------------------------------------------------------------
  8226. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8227. {
  8228. UnicodeString Message;
  8229. bool New;
  8230. TQueryType Type;
  8231. GetUpdatesMessage(Message, New, Type, false);
  8232. if (!Message.IsEmpty())
  8233. {
  8234. if (New)
  8235. {
  8236. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8237. }
  8238. if (!New && (Type != qtWarning))
  8239. {
  8240. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8241. }
  8242. else
  8243. {
  8244. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8245. }
  8246. if (New)
  8247. {
  8248. Configuration->Usage->Inc(L"UpdateNotifications");
  8249. }
  8250. }
  8251. }
  8252. //---------------------------------------------------------------------------
  8253. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8254. {
  8255. RestoreApp();
  8256. bool CanDisplay = !NonVisualDataModule->Busy;
  8257. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8258. {
  8259. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8260. }
  8261. if (CanDisplay)
  8262. {
  8263. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8264. CheckForUpdates(true);
  8265. }
  8266. else
  8267. {
  8268. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8269. }
  8270. }
  8271. //---------------------------------------------------------------------------
  8272. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8273. TCopyParamRuleData & Data)
  8274. {
  8275. DebugAssert(Terminal != NULL);
  8276. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8277. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8278. Data.RemoteDirectory = RemoteDirView->PathName;
  8279. }
  8280. //---------------------------------------------------------------------------
  8281. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8282. {
  8283. // Terminal can be null when we are changing local directory implicitly,
  8284. // because it has been deleted, while no session is connected
  8285. // (Login dialog is open)
  8286. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8287. {
  8288. DebugAssert(!IsLocalBrowserMode());
  8289. TCopyParamRuleData Data;
  8290. GetTransferPresetAutoSelectData(Data);
  8291. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8292. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8293. if (CopyParamIndex < 0)
  8294. {
  8295. // there is no preset that matches autoselection
  8296. // set preset that we consider "default"
  8297. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8298. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8299. }
  8300. else
  8301. {
  8302. // there is preset matching autoselection
  8303. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8304. if (CopyParamName == FCopyParamAutoSelected)
  8305. {
  8306. // autoselected the same preset as the last time
  8307. // make no change (i.e. preserve custom user preset, if any)
  8308. }
  8309. else
  8310. {
  8311. // autoselected the different preset then the last time (or there
  8312. // was default preset set)
  8313. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8314. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8315. }
  8316. }
  8317. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8318. {
  8319. if (CopyParamIndex >= 0)
  8320. {
  8321. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8322. }
  8323. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8324. try
  8325. {
  8326. int Fmt =
  8327. (CopyParamIndex < 0) ?
  8328. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8329. COPY_PARAM_AUTOSELECTED;
  8330. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8331. Data->Message = MainInstructions(Message);
  8332. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8333. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8334. CopyParamAttrs);
  8335. if (CopyParamIndex >= 0)
  8336. {
  8337. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8338. Info = FORMAT(L"%s\n \n%s", (Info,
  8339. FMTLOAD(COPY_PARAM_RULE,
  8340. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8341. }
  8342. Data->Message += L"\n\n" + Info;
  8343. if (WinConfiguration->CopyParamAutoSelectNotice)
  8344. {
  8345. TransferPresetNoteMessage(Data, true);
  8346. }
  8347. else
  8348. {
  8349. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8350. Data = NULL; // ownership passed
  8351. }
  8352. }
  8353. __finally
  8354. {
  8355. delete Data;
  8356. }
  8357. }
  8358. }
  8359. }
  8360. //---------------------------------------------------------------------------
  8361. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8362. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8363. {
  8364. DebugAssert(NoteData != NULL);
  8365. DebugAssert(!IsLocalBrowserMode());
  8366. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8367. TQueryButtonAlias Aliases[1];
  8368. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8369. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8370. Params.Aliases = Aliases;
  8371. Params.AliasesCount = LENOF(Aliases);
  8372. unsigned int Result =
  8373. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8374. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8375. switch (Result)
  8376. {
  8377. case qaNeverAskAgain:
  8378. DebugAssert(AllowNeverAskAgain);
  8379. WinConfiguration->CopyParamAutoSelectNotice = false;
  8380. break;
  8381. case qaIgnore:
  8382. PreferencesDialog(pmPresets);
  8383. break;
  8384. }
  8385. }
  8386. //---------------------------------------------------------------------------
  8387. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8388. {
  8389. // as of now useless, as this is used for notes only, never for balloons, ...
  8390. RestoreApp();
  8391. // .. and we should never be busy here
  8392. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8393. {
  8394. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8395. }
  8396. }
  8397. //---------------------------------------------------------------------------
  8398. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8399. TPreferencesMode APreferencesMode)
  8400. {
  8401. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8402. TCopyParamRuleData Data;
  8403. if (Terminal != NULL)
  8404. {
  8405. PreferencesData.reset(new TPreferencesDialogData());
  8406. GetTransferPresetAutoSelectData(Data);
  8407. PreferencesData->CopyParamRuleData = &Data;
  8408. }
  8409. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8410. }
  8411. //---------------------------------------------------------------------------
  8412. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8413. const TCustomCommandType & Command)
  8414. {
  8415. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8416. {
  8417. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8418. }
  8419. }
  8420. //---------------------------------------------------------------------------
  8421. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8422. {
  8423. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8424. TCustomCommandType Command;
  8425. // make sure we use local custom command when remote are not supported
  8426. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8427. {
  8428. Command = FLastCustomCommand;
  8429. }
  8430. else
  8431. {
  8432. Command.Params = Command.Params | ccLocal;
  8433. }
  8434. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8435. FEditingFocusedAdHocCommand = OnFocused;
  8436. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8437. int Options =
  8438. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8439. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8440. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8441. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8442. {
  8443. FLastCustomCommand = Command;
  8444. UpdateCustomCommandsToolbar();
  8445. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8446. }
  8447. }
  8448. //---------------------------------------------------------------------------
  8449. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8450. {
  8451. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8452. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8453. DebugAssert(State > 0);
  8454. if (State <= 0)
  8455. {
  8456. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8457. }
  8458. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8459. }
  8460. //---------------------------------------------------------------------------
  8461. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8462. TCustomCommandType & Command, int & State)
  8463. {
  8464. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8465. if (Result)
  8466. {
  8467. Command = FLastCustomCommand;
  8468. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8469. }
  8470. return Result;
  8471. }
  8472. //---------------------------------------------------------------------------
  8473. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8474. {
  8475. ResetIncrementalSearch();
  8476. }
  8477. //---------------------------------------------------------------------------
  8478. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8479. {
  8480. DebugAssert(ComponentVisible[Component]);
  8481. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8482. }
  8483. //---------------------------------------------------------------------------
  8484. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8485. {
  8486. // when queue panel is resized here directly, the status bar is stretched
  8487. // over whole space the panel occupied
  8488. PostComponentHide(fcQueueView);
  8489. }
  8490. //---------------------------------------------------------------------------
  8491. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8492. {
  8493. ComponentVisible[fcQueueFileList] = false;
  8494. }
  8495. //---------------------------------------------------------------------------
  8496. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8497. {
  8498. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8499. RefreshColorMode();
  8500. ResetSysDarkTheme();
  8501. ConfigurationChanged();
  8502. ConfigureInterface();
  8503. // Should be called for all controls
  8504. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8505. }
  8506. //---------------------------------------------------------------------------
  8507. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8508. {
  8509. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8510. if (!FInvalid &&
  8511. (Message.LParam != 0) &&
  8512. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8513. {
  8514. ThemeChanged();
  8515. }
  8516. TForm::Dispatch(&Message);
  8517. }
  8518. //---------------------------------------------------------------------------
  8519. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8520. {
  8521. TMessage * M = static_cast<TMessage*>(Message);
  8522. switch (M->Msg)
  8523. {
  8524. case CM_DIALOGCHAR:
  8525. CMDialogChar(*M);
  8526. break;
  8527. case WM_APPCOMMAND:
  8528. WMAppCommand(*M);
  8529. break;
  8530. case WM_SYSCOMMAND:
  8531. WMSysCommand(*M);
  8532. break;
  8533. case WM_QUERYENDSESSION:
  8534. WMQueryEndSession(*M);
  8535. break;
  8536. case WM_ENDSESSION:
  8537. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8538. break;
  8539. #ifdef _DEBUG
  8540. case WM_WINDOWPOSCHANGED:
  8541. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8542. break;
  8543. case CM_CUSTOMSTYLECHANGED:
  8544. TForm::Dispatch(Message);
  8545. break;
  8546. #endif
  8547. case WM_COMPONENT_HIDE:
  8548. {
  8549. Byte Component = static_cast<Byte>(M->WParam);
  8550. // sanity check
  8551. if (ComponentVisible[Component])
  8552. {
  8553. // special treatment
  8554. if (Component == fcQueueView)
  8555. {
  8556. ToggleQueueVisibility();
  8557. DebugAssert(!ComponentVisible[fcQueueView]);
  8558. }
  8559. else
  8560. {
  8561. ComponentVisible[Component] = false;
  8562. }
  8563. }
  8564. }
  8565. break;
  8566. case WM_COPYDATA:
  8567. WMCopyData(*M);
  8568. break;
  8569. case WM_MANAGES_CAPTION:
  8570. // caption managed in TTerminalManager::UpdateAppTitle()
  8571. M->Result = 1;
  8572. break;
  8573. case WM_WANTS_MOUSEWHEEL:
  8574. M->Result = 1;
  8575. break;
  8576. case CM_SHOWINGCHANGED:
  8577. CMShowingChanged(*M);
  8578. break;
  8579. case WM_CLOSE:
  8580. WMClose(*M);
  8581. break;
  8582. case WM_DPICHANGED:
  8583. WMDpiChanged(*M);
  8584. break;
  8585. case CM_DPICHANGED:
  8586. CMDpiChanged(*M);
  8587. break;
  8588. case WM_SETTINGCHANGE:
  8589. WMSettingChange(*M);
  8590. break;
  8591. case CM_DIALOGKEY:
  8592. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8593. break;
  8594. default:
  8595. TForm::Dispatch(Message);
  8596. break;
  8597. }
  8598. }
  8599. //---------------------------------------------------------------------------
  8600. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8601. {
  8602. // noop
  8603. }
  8604. //---------------------------------------------------------------------------
  8605. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8606. {
  8607. TForm::Dispatch(&Message);
  8608. FSessionColors->Clear();
  8609. AddFixedSessionImages();
  8610. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8611. UpdateImages();
  8612. }
  8613. //---------------------------------------------------------------------------
  8614. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8615. {
  8616. TForm::Dispatch(&Message);
  8617. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8618. UpdatePixelsPerInchMainWindowCounter();
  8619. }
  8620. //---------------------------------------------------------------------------
  8621. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8622. {
  8623. // Cannot close window while we are busy.
  8624. // We cannot test this in FormCloseQuery as that is called also from
  8625. // Close(), which is called by CloseApplicationAction. So we can be busy
  8626. // there already even, when it is legitimate to close the application.
  8627. // Possibly a better place to handle this would be WMSysCommand.
  8628. if (NonVisualDataModule->Busy)
  8629. {
  8630. Message.Result = 1;
  8631. }
  8632. else
  8633. {
  8634. TForm::Dispatch(&Message);
  8635. }
  8636. }
  8637. //---------------------------------------------------------------------------
  8638. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8639. {
  8640. TForm::Dispatch(&Message);
  8641. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8642. if (Showing && !FStarted)
  8643. {
  8644. FStarted = true;
  8645. InterfaceStarted();
  8646. }
  8647. if (Showing && (Terminal == NULL))
  8648. {
  8649. // When we are starting minimized (i.e. from an installer),
  8650. // postpone showing Login dialog until we get restored.
  8651. // Otherwise the Login dialog (and Authentication window) show restored
  8652. // over invisible (minimized) main window.
  8653. if (WindowState == wsMinimized)
  8654. {
  8655. FNeedSession = true;
  8656. }
  8657. else
  8658. {
  8659. // This happens before application ever goes idle, so the toolbars would
  8660. // stay enabled (initial state) until the Login dialog is dismissed.
  8661. UpdateActions();
  8662. NonVisualDataModule->StartBusy();
  8663. try
  8664. {
  8665. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8666. // otherwise the dialog does not receive focus.
  8667. // With Commander interface the ProcessMessages is called already
  8668. // by TDriveView, but with Explorer interface, we need to call it explicily
  8669. Application->ProcessMessages();
  8670. // do not reload sessions, they have been loaded just now (optimization)
  8671. NeedSession(true);
  8672. }
  8673. __finally
  8674. {
  8675. NonVisualDataModule->EndBusy();
  8676. }
  8677. }
  8678. }
  8679. }
  8680. //---------------------------------------------------------------------------
  8681. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8682. {
  8683. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8684. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8685. }
  8686. //---------------------------------------------------------------------------
  8687. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8688. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8689. int & MaxHeight)
  8690. {
  8691. // workaround for bug in TWinControl.CalcConstraints
  8692. // Check for empty rect (restore from iconic state) is done there only after
  8693. // call to AdjustClientRect, which enlarges the rect (for forms).
  8694. TRect R = GetClientRect();
  8695. // when restoring from iconic state, place no restrictions
  8696. if (IsRectEmpty(R))
  8697. {
  8698. MinWidth = 0;
  8699. MinHeight = 0;
  8700. MaxWidth = 32000;
  8701. MaxHeight = 32000;
  8702. }
  8703. }
  8704. //---------------------------------------------------------------------------
  8705. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8706. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8707. {
  8708. // terminal can be already closed (e.g. dropped connection)
  8709. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8710. {
  8711. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8712. try
  8713. {
  8714. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8715. }
  8716. catch(...)
  8717. {
  8718. if (!Terminal->Active)
  8719. {
  8720. Close = true;
  8721. }
  8722. throw;
  8723. }
  8724. }
  8725. }
  8726. //---------------------------------------------------------------------------
  8727. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8728. {
  8729. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8730. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8731. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8732. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8733. {
  8734. OnGetSpaceAvailable = GetSpaceAvailable;
  8735. }
  8736. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8737. OnGetSpaceAvailable);
  8738. }
  8739. //---------------------------------------------------------------------------
  8740. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8741. {
  8742. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8743. Terminal->FillSessionDataForCode(Data.get());
  8744. return Data.release();
  8745. }
  8746. //---------------------------------------------------------------------------
  8747. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8748. {
  8749. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8750. DoGenerateUrlDialog(Data.get(), Paths);
  8751. }
  8752. //---------------------------------------------------------------------------
  8753. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8754. {
  8755. GenerateUrl(NULL);
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8759. {
  8760. std::unique_ptr<TStrings> Paths(new TStringList());
  8761. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8762. GenerateUrl(Paths.get());
  8763. }
  8764. //---------------------------------------------------------------------------
  8765. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8766. {
  8767. FSessionColor = value;
  8768. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8769. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8770. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8771. DebugAssert(ColorItem != NULL);
  8772. ColorItem->Color = C;
  8773. NonVisualDataModule->ColorMenuItem->Color = C;
  8774. UpdateControls();
  8775. }
  8776. //---------------------------------------------------------------------------
  8777. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8778. {
  8779. if (value != FSessionColor)
  8780. {
  8781. UpdateSessionColor(value);
  8782. // Is null when called from LastTerminalClosed
  8783. if (Terminal != NULL)
  8784. {
  8785. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8786. }
  8787. }
  8788. }
  8789. //---------------------------------------------------------------------------
  8790. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8791. {
  8792. bool Result = FNoteTimer->Enabled;
  8793. if (Result)
  8794. {
  8795. // cannot cancel note too early
  8796. bool NotEarly =
  8797. (Now() - FNoteShown >
  8798. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8799. if (Force || NotEarly)
  8800. {
  8801. FNoteTimer->Enabled = false;
  8802. FNote = L"";
  8803. SAFE_DESTROY(FNoteData);
  8804. FOnNoteClick = NULL;
  8805. FNoteHints = FNotes->Text;
  8806. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8807. UpdateStatusBar();
  8808. }
  8809. }
  8810. return Result;
  8811. }
  8812. //---------------------------------------------------------------------------
  8813. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8814. {
  8815. DebugAssert(FNoteTimer->Enabled);
  8816. CancelNote(true);
  8817. }
  8818. //---------------------------------------------------------------------------
  8819. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8820. {
  8821. FNoteHints = FNotes->Text.TrimRight();
  8822. }
  8823. //---------------------------------------------------------------------------
  8824. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8825. {
  8826. int P = Note.Pos(L"\n");
  8827. if (P > 0)
  8828. {
  8829. Note.SetLength(P - 1);
  8830. }
  8831. FNotes->Add(FORMAT(L"[%s] %s",
  8832. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8833. while (FNotes->Count > 10)
  8834. {
  8835. FNotes->Delete(0);
  8836. }
  8837. if (UpdateNow)
  8838. {
  8839. UpdateNoteHints();
  8840. UpdateStatusBar();
  8841. }
  8842. }
  8843. //---------------------------------------------------------------------------
  8844. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8845. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8846. {
  8847. int P = Note.Pos(L"\n");
  8848. if (P > 0)
  8849. {
  8850. Note.SetLength(P - 1);
  8851. }
  8852. UpdateNoteHints();
  8853. FNote = Note;
  8854. SAFE_DESTROY(FNoteData);
  8855. FNoteData = NoteData;
  8856. FOnNoteClick = OnNoteClick;
  8857. AddNote(Note, false);
  8858. UpdateStatusBar();
  8859. FNoteShown = Now();
  8860. FNoteTimer->Enabled = false;
  8861. if (Seconds == 0)
  8862. {
  8863. Seconds = WinConfiguration->NotificationsTimeout;
  8864. }
  8865. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8866. FNoteTimer->Enabled = true;
  8867. }
  8868. //---------------------------------------------------------------------------
  8869. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8870. {
  8871. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8872. }
  8873. //---------------------------------------------------------------------------
  8874. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8875. {
  8876. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8877. {
  8878. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8879. }
  8880. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8881. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8882. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8883. 0, NULL, NULL);
  8884. }
  8885. //---------------------------------------------------------------------------
  8886. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8887. {
  8888. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8889. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8890. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8891. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8892. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8893. }
  8894. //---------------------------------------------------------------------------
  8895. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8896. {
  8897. WinConfiguration->FormatSizeBytes = Style;
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8901. {
  8902. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8903. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8904. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8905. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8906. }
  8907. //---------------------------------------------------------------------------
  8908. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8909. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8910. {
  8911. if (Panel->Index == 0)
  8912. {
  8913. if (FOnNoteClick != NULL)
  8914. {
  8915. // prevent the user data from being freed by possible call
  8916. // to CancelNote or PostNote during call to OnNoteClick
  8917. std::unique_ptr<TObject> NoteData(FNoteData);
  8918. TNotifyEvent OnNoteClick = FOnNoteClick;
  8919. FNoteData = NULL;
  8920. // need to cancel the note as we are going to delete its user data
  8921. CancelNote(true);
  8922. OnNoteClick(NoteData.get());
  8923. }
  8924. }
  8925. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8926. {
  8927. FileSystemInfo();
  8928. }
  8929. }
  8930. //---------------------------------------------------------------------------
  8931. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8932. {
  8933. // workaround:
  8934. // 1) for unknown reason, disabling window, while minimized,
  8935. // prevents it from restoring, even if it was enabled again meanwhile
  8936. // 2) when disabling the main window, while another has focus
  8937. // minimize is no longer possible
  8938. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8939. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8940. // Shouldn't we use IsApplicationMinimized() here?
  8941. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8942. {
  8943. Enabled = false;
  8944. }
  8945. FLockLevel++;
  8946. }
  8947. //---------------------------------------------------------------------------
  8948. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8949. {
  8950. DebugAssert(FLockLevel > 0);
  8951. FLockLevel--;
  8952. if (FLockLevel == 0)
  8953. {
  8954. DebugAssert(FLockSuspendLevel == 0);
  8955. Enabled = true;
  8956. }
  8957. }
  8958. //---------------------------------------------------------------------------
  8959. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8960. {
  8961. // We need to make sure that window is enabled when the last modal window closes
  8962. // otherwise focus is not restored correctly.
  8963. // So we re-enable the window when modal window opens and
  8964. // disable it back after is closes
  8965. if (FLockLevel > 0)
  8966. {
  8967. // while we have nesting counter, we know that we never be called
  8968. // recursivelly as Application->OnModalBegin is called only
  8969. // for the top-level modal window
  8970. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8971. {
  8972. // won't be disabled when conditions in LockWindow() were not satisfied
  8973. FDisabledOnLockSuspend = !Enabled;
  8974. // When minimized to tray (or actually when set to SW_HIDE),
  8975. // setting Enabled makes the window focusable even when there's
  8976. // modal window over it
  8977. if (!FTrayIcon->Visible)
  8978. {
  8979. Enabled = true;
  8980. }
  8981. }
  8982. FLockSuspendLevel++;
  8983. }
  8984. }
  8985. //---------------------------------------------------------------------------
  8986. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8987. {
  8988. if (FLockSuspendLevel > 0)
  8989. {
  8990. DebugAssert(FLockLevel > 0);
  8991. FLockSuspendLevel--;
  8992. // see comment in SuspendWindowLock
  8993. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8994. {
  8995. // Note that window can be enabled here, when we were minized to tray when
  8996. // was SuspendWindowLock() called.
  8997. // We should possibly do the same check as in LockWindow(),
  8998. // if it is ever possible that the consitions change between
  8999. // SuspendWindowLock() and ResumeWindowLock()
  9000. Enabled = !FDisabledOnLockSuspend;
  9001. }
  9002. }
  9003. }
  9004. //---------------------------------------------------------------------------
  9005. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9006. {
  9007. TTBXComboBoxItem * RemotePathComboBox =
  9008. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9009. if (!TextOnly)
  9010. {
  9011. TStrings * Items = RemotePathComboBox->Strings;
  9012. Items->BeginUpdate();
  9013. try
  9014. {
  9015. Items->Clear();
  9016. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9017. {
  9018. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9019. while (!IsUnixRootPath(APath))
  9020. {
  9021. int P = APath.LastDelimiter(L'/');
  9022. DebugAssert(P >= 0);
  9023. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9024. APath.SetLength(P - 1);
  9025. }
  9026. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9027. }
  9028. }
  9029. __finally
  9030. {
  9031. Items->EndUpdate();
  9032. }
  9033. }
  9034. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9035. // Setting ItemIndex to -1 does not reset its text
  9036. if (RemotePathComboBox->Strings->Count == 0)
  9037. {
  9038. RemotePathComboBox->Text = L"";
  9039. }
  9040. }
  9041. //---------------------------------------------------------------------------
  9042. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9043. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9044. int & ImageIndex)
  9045. {
  9046. if (AIndex < 0)
  9047. {
  9048. AIndex = Sender->ItemIndex;
  9049. }
  9050. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9051. }
  9052. //---------------------------------------------------------------------------
  9053. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9054. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9055. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9056. {
  9057. ARect.Left += (10 * AIndex);
  9058. }
  9059. //---------------------------------------------------------------------------
  9060. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9061. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9062. {
  9063. AWidth += (10 * AIndex);
  9064. }
  9065. //---------------------------------------------------------------------------
  9066. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9067. TObject * Sender)
  9068. {
  9069. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9070. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9071. int Index = RemotePathComboBox->ItemIndex;
  9072. while (Index < RemotePathComboBox->Strings->Count - 1)
  9073. {
  9074. APath = UnixExtractFileDir(APath);
  9075. Index++;
  9076. }
  9077. // VanDyke style paths
  9078. if (APath.IsEmpty())
  9079. {
  9080. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9081. APath = ROOTDIRECTORY;
  9082. }
  9083. if (RemoteDirView->Path != APath)
  9084. {
  9085. RemoteDirView->Path = APath;
  9086. }
  9087. }
  9088. //---------------------------------------------------------------------------
  9089. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9090. {
  9091. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9092. DebugUsedParam(Sender);
  9093. UpdateRemotePathComboBox(true);
  9094. }
  9095. //---------------------------------------------------------------------------
  9096. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9097. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9098. {
  9099. ResetIncrementalSearch();
  9100. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9101. DebugAssert(DirView != NULL);
  9102. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9103. {
  9104. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9105. // OnEditing is called also from TCustomListView::CanEdit
  9106. if (Edit != NULL)
  9107. {
  9108. EditSelectBaseName(Edit);
  9109. }
  9110. }
  9111. }
  9112. //---------------------------------------------------------------------------
  9113. //---------------------------------------------------------------------------
  9114. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9115. {
  9116. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9117. Result->AutoDetectDnD = false;
  9118. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9119. Result->RenderDataOn = rdoEnterAndDropSync;
  9120. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9121. return Result;
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9125. {
  9126. if (IsWin10Build(2004))
  9127. {
  9128. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9129. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9130. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9131. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9132. }
  9133. }
  9134. //---------------------------------------------------------------------------
  9135. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9136. {
  9137. TForm::CreateWnd();
  9138. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9139. UpdateDarkMode();
  9140. if (FSessionsDragDropFilesEx == NULL)
  9141. {
  9142. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9143. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9144. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9145. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9146. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9147. }
  9148. if (FQueueDragDropFilesEx == NULL)
  9149. {
  9150. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9151. // No need to set OnDragOver as we do not have any restrictions
  9152. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9153. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9154. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9155. }
  9156. }
  9157. //---------------------------------------------------------------------------
  9158. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9159. {
  9160. TForm::DestroyWnd();
  9161. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9162. FQueueDragDropFilesEx->DragDropControl = NULL;
  9163. }
  9164. //---------------------------------------------------------------------------
  9165. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9166. {
  9167. SideEnter(FCurrentSide);
  9168. FEverShown = true;
  9169. }
  9170. //---------------------------------------------------------------------------
  9171. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9172. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9173. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9174. {
  9175. if (!NonVisualDataModule->Busy)
  9176. {
  9177. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9178. Configuration->Usage->Inc(L"FileFinds");
  9179. LockWindow(true);
  9180. NonVisualDataModule->StartBusy();
  9181. WinConfiguration->LockedInterface = true;
  9182. try
  9183. {
  9184. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9185. }
  9186. __finally
  9187. {
  9188. WinConfiguration->LockedInterface = false;
  9189. NonVisualDataModule->EndBusy();
  9190. UnlockWindow();
  9191. }
  9192. }
  9193. }
  9194. //---------------------------------------------------------------------------
  9195. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9196. {
  9197. if (!NonVisualDataModule->Busy)
  9198. {
  9199. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9200. SetFocus();
  9201. RemoteDirView->Path = UnixExtractFilePath(Path);
  9202. UnicodeString FileName = UnixExtractFileName(Path);
  9203. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9204. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9205. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9206. if (Item == NULL)
  9207. {
  9208. ReloadDirectory(osRemote);
  9209. Item = RemoteDirView->FindFileItem(FileName);
  9210. }
  9211. if (Item != NULL)
  9212. {
  9213. RemoteDirView->ItemFocused = Item;
  9214. RemoteDirView->ItemFocused->MakeVisible(false);
  9215. RemoteDirView->SetFocus();
  9216. }
  9217. }
  9218. }
  9219. //---------------------------------------------------------------------------
  9220. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9221. {
  9222. bool Result = !NonVisualDataModule->Busy;
  9223. if (Result)
  9224. {
  9225. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9226. }
  9227. return Result;
  9228. }
  9229. //---------------------------------------------------------------------------
  9230. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9231. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9232. {
  9233. if (CanOperateOnFoundFiles(ATerminal))
  9234. {
  9235. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9236. FOnFileOperationFinished = OnFileOperationFinished;
  9237. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9238. }
  9239. }
  9240. //---------------------------------------------------------------------------
  9241. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9242. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9243. {
  9244. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9248. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9249. {
  9250. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9251. }
  9252. //---------------------------------------------------------------------------
  9253. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9254. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9255. {
  9256. if (CanOperateOnFoundFiles(ATerminal))
  9257. {
  9258. for (int Index = 0; Index < FileList->Count; Index++)
  9259. {
  9260. UnicodeString FileName = FileList->Strings[Index];
  9261. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9262. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9263. OnFileOperationFinished(FileName, true);
  9264. }
  9265. }
  9266. }
  9267. //---------------------------------------------------------------------------
  9268. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9269. {
  9270. FFileFindTerminal = Terminal;
  9271. ShowFileFindDialog(
  9272. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9273. DoDownloadFoundFiles, DoEditFoundFiles);
  9274. }
  9275. //---------------------------------------------------------------------------
  9276. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9277. {
  9278. FTaskbarList = TaskbarList;
  9279. }
  9280. //---------------------------------------------------------------------------
  9281. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9282. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9283. {
  9284. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9285. if (Index >= 0)
  9286. {
  9287. if (Button == mbLeft)
  9288. {
  9289. // "Mouse down" is raised only after tab is switched.
  9290. // If switching tab (switching session) takes long enough for user
  9291. // to actually release the button, "mouse down" is still raised,
  9292. // but we do not get "mouse up" event, so dragging is not cancelled,
  9293. // prevent that by not beginning dragging in the first place.
  9294. if (IsKeyPressed(VK_LBUTTON))
  9295. {
  9296. // when user clicks the "+", we get mouse down only after the session
  9297. // is closed, when new session tab is already on X:Y, so dragging
  9298. // starts, prevent that
  9299. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9300. {
  9301. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9302. if (Terminal != NULL)
  9303. {
  9304. SessionsPageControl->BeginDrag(false);
  9305. }
  9306. }
  9307. }
  9308. }
  9309. else if (Button == mbMiddle)
  9310. {
  9311. // ignore middle-click for "New session tab"
  9312. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9313. if (Terminal != NULL)
  9314. {
  9315. CloseSessionTab(Index);
  9316. }
  9317. }
  9318. }
  9319. }
  9320. //---------------------------------------------------------------------------
  9321. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9322. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9323. {
  9324. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9325. // do not allow dropping on the "+" tab
  9326. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9327. if ((TargetTerminal != NULL) &&
  9328. (SessionsPageControl->ActivePage->PageIndex != Index))
  9329. {
  9330. Configuration->Usage->Inc(L"SessionTabMoves");
  9331. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9332. // but we want to actually prevent that to avoid flicker
  9333. SessionsPageControl->ActivePage->PageIndex = Index;
  9334. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9335. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9336. }
  9337. }
  9338. //---------------------------------------------------------------------------
  9339. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9340. TObject * Sender, TObject * Source, int X, int Y,
  9341. TDragState /*State*/, bool & Accept)
  9342. {
  9343. Accept = (Sender == Source);
  9344. if (Accept)
  9345. {
  9346. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9347. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9348. // do not allow dragging to the "+" tab
  9349. Accept = (Terminal != NULL);
  9350. }
  9351. }
  9352. //---------------------------------------------------------------------------
  9353. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9354. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9355. {
  9356. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9357. if (Index < 0)
  9358. {
  9359. Effect = DROPEFFECT_NONE;
  9360. }
  9361. else
  9362. {
  9363. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9364. // do not allow dropping on the "+" and disconnected tabs
  9365. if (!IsActiveTerminal(TargetTerminal))
  9366. {
  9367. Effect = DROPEFFECT_NONE;
  9368. }
  9369. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9370. {
  9371. Effect = DROPEFFECT_COPY;
  9372. }
  9373. }
  9374. }
  9375. //---------------------------------------------------------------------------
  9376. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9377. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9378. {
  9379. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9380. // do not allow dropping on the "+" and disconnected tabs
  9381. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9382. if (IsActiveTerminal(TargetTerminal))
  9383. {
  9384. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9385. if (!IsFileControl(DropSourceControl, osRemote))
  9386. {
  9387. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9388. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9389. // Why don't we use Terminal->CurrentDirectory directly?
  9390. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9391. // do not force queue, drag drop
  9392. false, true);
  9393. }
  9394. }
  9395. }
  9396. //---------------------------------------------------------------------------
  9397. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9398. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9399. {
  9400. // Downloads are handled in RemoteFileControlDDEnd
  9401. if (!IsFileControl(DropSourceControl, osRemote))
  9402. {
  9403. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9404. Terminal->CurrentDirectory,
  9405. // force queue, drag drop
  9406. true, true);
  9407. }
  9408. }
  9409. //---------------------------------------------------------------------------
  9410. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9411. {
  9412. FShowing = false;
  9413. // Do not save empty workspace
  9414. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9415. {
  9416. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9417. UnicodeString Name = WorkspaceName();
  9418. DoSaveWorkspace(
  9419. Name, DataList.get(),
  9420. !Configuration->DisablePasswordStoring &&
  9421. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9422. WinConfiguration->LastStoredSession = Name;
  9423. }
  9424. }
  9425. //---------------------------------------------------------------------------
  9426. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9427. {
  9428. TManagedTerminal * ManagedTerminal =
  9429. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9430. if (ManagedTerminal != NULL)
  9431. {
  9432. ManagedTerminal->DirectoryLoaded = Now();
  9433. }
  9434. }
  9435. //---------------------------------------------------------------------------
  9436. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9437. TListItem * /*Item*/, bool /*Selected*/)
  9438. {
  9439. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9440. switch (DirView->LastSelectMethod)
  9441. {
  9442. case smKeyboard:
  9443. Configuration->Usage->Inc(L"KeyboardSelections");
  9444. break;
  9445. case smMouse:
  9446. Configuration->Usage->Inc(L"MouseSelections");
  9447. break;
  9448. }
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9452. {
  9453. if (Color != 0)
  9454. {
  9455. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9456. }
  9457. else
  9458. {
  9459. return FSessionTabImageIndex;
  9460. }
  9461. }
  9462. //---------------------------------------------------------------------------
  9463. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9464. {
  9465. TPngImageCollectionItem * Item =
  9466. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9467. FSessionColors->AddPng(Item->PngImage);
  9468. return FSessionColors->Count - 1;
  9469. }
  9470. //---------------------------------------------------------------------------
  9471. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9472. {
  9473. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9474. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9475. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9476. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9477. }
  9478. //---------------------------------------------------------------------------
  9479. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9480. {
  9481. for (int Index = 0; Index < Control->ControlCount; Index++)
  9482. {
  9483. TControl * AControl = Control->Controls[Index];
  9484. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9485. if (WinControl != NULL)
  9486. {
  9487. CollectItemsWithTextDisplayMode(WinControl);
  9488. }
  9489. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9490. if (Toolbar != NULL)
  9491. {
  9492. // we care for top-level items only
  9493. TTBCustomItem * Items = Toolbar->Items;
  9494. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9495. {
  9496. TTBCustomItem * Item = Items->Items[ItemIndex];
  9497. if (((Item->DisplayMode == nbdmImageAndText) ||
  9498. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9499. EligibleForImageDisplayMode(Item))
  9500. {
  9501. FItemsWithTextDisplayMode.insert(Item);
  9502. }
  9503. }
  9504. }
  9505. }
  9506. }
  9507. //---------------------------------------------------------------------------
  9508. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9509. {
  9510. return true;
  9511. }
  9512. //---------------------------------------------------------------------------
  9513. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9514. {
  9515. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9516. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9517. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9518. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9519. bool Result = true;
  9520. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9521. {
  9522. TTBCustomItem * Item = *i;
  9523. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9524. if (Label != NULL)
  9525. {
  9526. // optimization
  9527. if (Label->Visible == SelectiveToolbarText)
  9528. {
  9529. Result = false;
  9530. }
  9531. else
  9532. {
  9533. Label->Visible = SelectiveToolbarText;
  9534. }
  9535. }
  9536. else
  9537. {
  9538. // optimization
  9539. if (Item->DisplayMode == DisplayMode)
  9540. {
  9541. Result = false;
  9542. }
  9543. else
  9544. {
  9545. Item->DisplayMode = DisplayMode;
  9546. }
  9547. }
  9548. ++i;
  9549. }
  9550. if (Result)
  9551. {
  9552. UpdateNewSessionTab();
  9553. }
  9554. return Result;
  9555. }
  9556. //---------------------------------------------------------------------------
  9557. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9558. {
  9559. DebugFail();
  9560. }
  9561. //---------------------------------------------------------------------------
  9562. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9563. {
  9564. // Among other, a lock level is non zero, while directory is being loaded,
  9565. // even when it happens as a result of dirview navigation,
  9566. // i.e. when TNonVisualDataModule is NOT FBusy.
  9567. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9568. // Among other this prevents a panel auto update to occur while
  9569. // directory is changing.
  9570. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9571. }
  9572. //---------------------------------------------------------------------------
  9573. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9574. {
  9575. // While the window is disabled, we still seem to process menu shortcuts at least,
  9576. // so stop it at least here.
  9577. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9578. return
  9579. (Allowed == aaUpdate) ||
  9580. !NonVisualDataModule->Busy;
  9581. }
  9582. //---------------------------------------------------------------------------
  9583. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9584. {
  9585. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9586. }
  9587. //---------------------------------------------------------------------------
  9588. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9589. {
  9590. // This is somewhat redundant to LockWindow() call from
  9591. // TTerminalManager::TerminalReadDirectoryProgress.
  9592. // But disabling window is known not to block keyboard shorcuts
  9593. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9594. if (Busy > 0)
  9595. {
  9596. if (NonVisualDataModule->Busy)
  9597. {
  9598. State = false;
  9599. }
  9600. else
  9601. {
  9602. NonVisualDataModule->StartBusy();
  9603. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9604. LockWindow();
  9605. }
  9606. }
  9607. else if (Busy < 0)
  9608. {
  9609. UnlockWindow();
  9610. NonVisualDataModule->EndBusy();
  9611. }
  9612. else
  9613. {
  9614. State = NonVisualDataModule->Busy;
  9615. }
  9616. }
  9617. //---------------------------------------------------------------------------
  9618. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9619. {
  9620. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9621. // no context menu for "New session tab"
  9622. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9623. {
  9624. SessionsPageControl->ActivePageIndex = Index;
  9625. if (DebugAlwaysTrue(SessionTabSwitched()))
  9626. {
  9627. // copied from TControl.WMContextMenu
  9628. SendCancelMode(SessionsPageControl);
  9629. // explicit popup instead of using PopupMenu property
  9630. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9631. // while connecting yet not-connected session and hence
  9632. // allowing an access to commands over not-completelly connected session
  9633. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9634. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9635. PopupMenu->PopupComponent = SessionsPageControl;
  9636. PopupMenu->Popup(Point.x, Point.y);
  9637. }
  9638. }
  9639. Handled = true;
  9640. }
  9641. //---------------------------------------------------------------------------
  9642. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9643. {
  9644. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9645. }
  9646. //---------------------------------------------------------------------------
  9647. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9648. {
  9649. Configuration->Usage->Inc(L"PasswordChanges");
  9650. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9651. ChangePasswordData->DisableAuthentationsExceptPassword();
  9652. ChangePasswordData->ChangePassword = true;
  9653. std::unique_ptr<TTerminal> ChangePasswordSession(
  9654. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9655. ChangePasswordSession->AutoReadDirectory = false;
  9656. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9657. {
  9658. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9659. }
  9660. else
  9661. {
  9662. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9663. }
  9664. }
  9665. //---------------------------------------------------------------------------
  9666. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9667. {
  9668. // No nice way to assert SSH2
  9669. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9670. }
  9671. //---------------------------------------------------------------------------
  9672. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9673. {
  9674. TOperationVisualizer OperationVisualizer;
  9675. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9676. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9677. }
  9678. //---------------------------------------------------------------------------
  9679. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9680. {
  9681. TForm::ChangeScale(M, D);
  9682. int APixelsPerInch = GetControlPixelsPerInch(this);
  9683. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9684. try
  9685. {
  9686. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9687. }
  9688. __finally
  9689. {
  9690. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9691. }
  9692. }
  9693. //---------------------------------------------------------------------------
  9694. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9695. {
  9696. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9697. }
  9698. //---------------------------------------------------------------------
  9699. class TPublicControl : public TControl
  9700. {
  9701. friend class TCustomScpExplorerForm;
  9702. };
  9703. //---------------------------------------------------------------------------
  9704. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9705. {
  9706. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9707. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9708. }
  9709. //---------------------------------------------------------------------------
  9710. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9711. {
  9712. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9713. OpenBookmark(Side, Bookmark);
  9714. }
  9715. //---------------------------------------------------------------------------
  9716. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9717. {
  9718. DoBookmarkClick(osLocal, Sender);
  9719. }
  9720. //---------------------------------------------------------------------------
  9721. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9722. {
  9723. DoBookmarkClick(osRemote, Sender);
  9724. }
  9725. //---------------------------------------------------------------------------
  9726. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9727. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9728. {
  9729. if (BookmarkList != NULL)
  9730. {
  9731. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9732. if (!WinConfiguration->UseLocationProfiles)
  9733. {
  9734. std::unique_ptr<TStringList> Directories(new TStringList());
  9735. Directories->CaseSensitive = (Side == osRemote);
  9736. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9737. {
  9738. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9739. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9740. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9741. {
  9742. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9743. Item->Caption = EscapeHotkey(Directory);
  9744. Item->ShortCut = Bookmark->ShortCut;
  9745. Item->OnClick = OnBookmarkClick;
  9746. Item->Tag = reinterpret_cast<int>(Bookmark);
  9747. Directories->Add(Directory);
  9748. Menu->Add(Item.release());
  9749. }
  9750. }
  9751. }
  9752. else
  9753. {
  9754. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9755. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9756. {
  9757. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9758. if (!Bookmark->Node.IsEmpty())
  9759. {
  9760. Folders->Add(Bookmark->Node);
  9761. }
  9762. }
  9763. for (int Index = 0; Index < Folders->Count; Index++)
  9764. {
  9765. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9766. Item->Caption = Folders->Strings[Index];
  9767. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9768. Folders->Objects[Index] = Item.get();
  9769. Menu->Add(Item.release());
  9770. }
  9771. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9772. {
  9773. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9774. TTBCustomItem * Parent;
  9775. if (!Bookmark->Node.IsEmpty())
  9776. {
  9777. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9778. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9779. }
  9780. else
  9781. {
  9782. Parent = Menu;
  9783. }
  9784. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9785. Item->Caption = Bookmark->Name;
  9786. Item->ShortCut = Bookmark->ShortCut;
  9787. Item->OnClick = OnBookmarkClick;
  9788. Item->Tag = reinterpret_cast<int>(Bookmark);
  9789. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9790. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9791. {
  9792. // No hint for location profiles that are actually mere "bookmarks"
  9793. }
  9794. else
  9795. {
  9796. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9797. UnicodeString LongHint;
  9798. if (!Bookmark->Local.IsEmpty())
  9799. {
  9800. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9801. }
  9802. if (!Bookmark->Remote.IsEmpty())
  9803. {
  9804. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9805. }
  9806. AddToList(Hint, LongHint, L"|");
  9807. Item->Hint = Hint;
  9808. }
  9809. Parent->Add(Item.release());
  9810. }
  9811. }
  9812. AddMenuSeparator(Menu);
  9813. }
  9814. }
  9815. //---------------------------------------------------------------------------
  9816. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9817. {
  9818. Menu->Clear();
  9819. std::unique_ptr<TTBCustomItem> Item;
  9820. Item.reset(new TTBXItem(Owner));
  9821. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9822. Item->Options = Item->Options << tboDefault;
  9823. Menu->Add(Item.release());
  9824. AddMenuSeparator(Menu);
  9825. if (Terminal != NULL)
  9826. {
  9827. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9828. }
  9829. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9830. Item.reset(new TTBXItem(Owner));
  9831. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9832. Menu->Add(Item.release());
  9833. }
  9834. //---------------------------------------------------------------------------
  9835. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9836. {
  9837. bool Result = true;
  9838. try
  9839. {
  9840. if (Side == osRemote)
  9841. {
  9842. Terminal->ExceptionOnFail = true;
  9843. }
  9844. try
  9845. {
  9846. DirView(Side)->Path = Path;
  9847. }
  9848. __finally
  9849. {
  9850. if (Side == osRemote)
  9851. {
  9852. Terminal->ExceptionOnFail = false;
  9853. }
  9854. }
  9855. }
  9856. catch (Exception & E)
  9857. {
  9858. if ((Side != osRemote) || Terminal->Active)
  9859. {
  9860. ShowExtendedExceptionEx(Terminal, &E);
  9861. Result = false;
  9862. }
  9863. else
  9864. {
  9865. throw;
  9866. }
  9867. }
  9868. return Result;
  9869. }
  9870. //---------------------------------------------------------------------------
  9871. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9872. {
  9873. // Make sure there some feedback even when loading tiny local folders
  9874. TInstantOperationVisualizer Visualizer;
  9875. DirView(Side)->ReloadDirectory();
  9876. }
  9877. //---------------------------------------------------------------------------
  9878. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9879. {
  9880. if (Index == SessionsPageControl->TabIndex)
  9881. {
  9882. CloseSession();
  9883. }
  9884. else
  9885. {
  9886. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9887. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9888. TTerminalManager * Manager = TTerminalManager::Instance();
  9889. if (!Terminal->Active)
  9890. {
  9891. Manager->FreeTerminal(Terminal);
  9892. }
  9893. else
  9894. {
  9895. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9896. if (CanCloseQueue(Queue))
  9897. {
  9898. Manager->FreeTerminal(Terminal);
  9899. }
  9900. }
  9901. }
  9902. }
  9903. //---------------------------------------------------------------------------
  9904. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9905. {
  9906. CloseSessionTab(Index);
  9907. }
  9908. //---------------------------------------------------------------------------
  9909. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9910. {
  9911. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9912. {
  9913. TInstantOperationVisualizer Visualizer;
  9914. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9915. // before we create a new data object
  9916. ClipboardClear();
  9917. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9918. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9919. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9920. // Intermediate variable to WORKAROUND a crash in compiler
  9921. TObjectList * ClipboardFakeMonitors =
  9922. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9923. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9924. if (FClipboardDragDropFilesEx.get() == NULL)
  9925. {
  9926. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9927. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9928. }
  9929. FClipboardDragDropFilesEx->FileList->Clear();
  9930. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9931. FClipboardDragDropFilesEx->CopyToClipboard();
  9932. FClipboardTerminal = FTerminal;
  9933. // Need full paths, as cwd can be different once files are pasted
  9934. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9935. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9936. {
  9937. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9938. }
  9939. }
  9940. }
  9941. //---------------------------------------------------------------------------
  9942. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9943. {
  9944. if (OpenClipboard(0))
  9945. {
  9946. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9947. CloseClipboard();
  9948. }
  9949. }
  9950. //---------------------------------------------------------------------------
  9951. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9952. {
  9953. return !FClipboardFakeDirectory.IsEmpty();
  9954. }
  9955. //---------------------------------------------------------------------------
  9956. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9957. {
  9958. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9959. FClipboardFakeDirectory = UnicodeString();
  9960. FClipboardTerminal = NULL;
  9961. // Also called in Idle()
  9962. FClipboardFakeMonitors.reset(NULL);
  9963. }
  9964. //---------------------------------------------------------------------------
  9965. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9966. {
  9967. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9968. {
  9969. ClipboardStop();
  9970. }
  9971. }
  9972. //---------------------------------------------------------------------------
  9973. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9974. {
  9975. TTerminalManager * Manager = TTerminalManager::Instance();
  9976. Manager->ActiveTerminal = FClipboardTerminal;
  9977. TTransferOperationParam Params;
  9978. Params.TargetDirectory = TargetDirectory;
  9979. Params.DragDrop = DragDrop;
  9980. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9981. }
  9982. //---------------------------------------------------------------------------
  9983. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9984. {
  9985. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9986. // (as it pumps a Windows message queue while being shutted down)
  9987. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9988. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9989. {
  9990. // Can fail as it can be e.g. locked by AV, so we retry that later
  9991. bool Removed = RemoveDir(ApiPath(FileName));
  9992. try
  9993. {
  9994. if (!NonVisualDataModule->Busy)
  9995. {
  9996. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9997. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9998. }
  9999. }
  10000. __finally
  10001. {
  10002. if (!Removed)
  10003. {
  10004. RemoveDir(ApiPath(FileName));
  10005. }
  10006. }
  10007. }
  10008. }
  10009. //---------------------------------------------------------------------------
  10010. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10011. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10012. {
  10013. TFileMasks::TParams MaskParams;
  10014. MaskParams.Size = Size;
  10015. MaskParams.Modification = Modification;
  10016. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10017. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10018. {
  10019. bool ImplicitMatch;
  10020. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10021. !ImplicitMatch)
  10022. {
  10023. Color = Iter->Color;
  10024. break;
  10025. }
  10026. }
  10027. }
  10028. //---------------------------------------------------------------------------
  10029. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10030. {
  10031. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10032. if (!DirView->IsEditing())
  10033. {
  10034. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10035. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10036. // while searching
  10037. if (Key == VK_BACK)
  10038. {
  10039. if (!FIncrementalSearch.IsEmpty())
  10040. {
  10041. if (FIncrementalSearch.Length() == 1)
  10042. {
  10043. ResetIncrementalSearch();
  10044. }
  10045. else
  10046. {
  10047. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10048. IncrementalSearch(NewText, false, false);
  10049. }
  10050. Key = 0;
  10051. }
  10052. }
  10053. }
  10054. }
  10055. //---------------------------------------------------------------------------
  10056. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10057. {
  10058. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10059. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10060. {
  10061. // Filter control sequences.
  10062. // When not searching yet, prefer use of the space for toggling file selection
  10063. // (so we cannot incrementally search for a string starting with a space).
  10064. if ((Key > VK_SPACE) ||
  10065. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10066. {
  10067. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10068. Key = 0;
  10069. }
  10070. }
  10071. }
  10072. //---------------------------------------------------------------------------
  10073. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10074. {
  10075. if (!FIncrementalSearch.IsEmpty())
  10076. {
  10077. FIncrementalSearch = L"";
  10078. DirView(osCurrent)->UpdateStatusBar();
  10079. }
  10080. }
  10081. //---------------------------------------------------------------------------
  10082. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10083. {
  10084. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10085. if (Item == NULL)
  10086. {
  10087. MessageBeep(MB_ICONHAND);
  10088. }
  10089. else
  10090. {
  10091. TCustomDirView * ADirView = DirView(osCurrent);
  10092. {
  10093. TAutoNestingCounter Guard(FIncrementalSearching);
  10094. ADirView->FocusItem(Item);
  10095. if (ADirView->NortonLike == nlOff)
  10096. {
  10097. if ((ADirView->Selected != Item) ||
  10098. (ADirView->SelCount > 1))
  10099. {
  10100. ADirView->ClearSelection();
  10101. ADirView->Selected = Item;
  10102. }
  10103. }
  10104. }
  10105. FIncrementalSearch = Text;
  10106. Item->MakeVisible(false);
  10107. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10108. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10109. ADirView->UpdateStatusBar();
  10110. }
  10111. }
  10112. //---------------------------------------------------------------------------
  10113. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10114. {
  10115. int Index = Item->Index;
  10116. if (!Reverse)
  10117. {
  10118. Index++;
  10119. if (Index >= Item->Owner->Count)
  10120. {
  10121. Index = 0;
  10122. }
  10123. }
  10124. else
  10125. {
  10126. Index--;
  10127. if (Index < 0)
  10128. {
  10129. Index = Item->Owner->Count - 1;
  10130. }
  10131. }
  10132. return Item->Owner->Item[Index];
  10133. }
  10134. //---------------------------------------------------------------------------
  10135. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10136. {
  10137. TCustomDirView * ADirView = DirView(osCurrent);
  10138. if (ADirView->Items->Count == 0)
  10139. {
  10140. return NULL;
  10141. }
  10142. else
  10143. {
  10144. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10145. TListItem * Item = CurrentItem;
  10146. if (SkipCurrent)
  10147. {
  10148. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10149. }
  10150. while (true)
  10151. {
  10152. bool Matches = false;
  10153. switch (WinConfiguration->PanelSearch)
  10154. {
  10155. case isNameStartOnly:
  10156. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10157. break;
  10158. case isName:
  10159. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10160. break;
  10161. case isAll:
  10162. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10163. int Index = 0;
  10164. while ((Index < ColCount) && !Matches)
  10165. {
  10166. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10167. if (Visible)
  10168. {
  10169. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10170. }
  10171. Index++;
  10172. }
  10173. break;
  10174. }
  10175. if (Matches)
  10176. {
  10177. return Item;
  10178. }
  10179. Item = GetNextFile(Item, Reverse);
  10180. if (Item == CurrentItem)
  10181. {
  10182. return NULL;
  10183. }
  10184. }
  10185. }
  10186. }
  10187. //---------------------------------------------------------------------------
  10188. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10189. {
  10190. ResetIncrementalSearch();
  10191. }
  10192. //---------------------------------------------------------------------------
  10193. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10194. {
  10195. if (Message.CharCode == VK_TAB)
  10196. {
  10197. if (!FIncrementalSearch.IsEmpty())
  10198. {
  10199. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10200. bool Reverse = Shift.Contains(ssShift);
  10201. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10202. Message.Result = 1;
  10203. return;
  10204. }
  10205. }
  10206. else if (Message.CharCode == VK_ESCAPE)
  10207. {
  10208. if (!FIncrementalSearch.IsEmpty())
  10209. {
  10210. ResetIncrementalSearch();
  10211. Message.Result = 1;
  10212. return;
  10213. }
  10214. }
  10215. TForm::Dispatch(&Message);
  10216. }
  10217. //---------------------------------------------------------------------------
  10218. void __fastcall TCustomScpExplorerForm::Deactivate()
  10219. {
  10220. TForm::Deactivate();
  10221. // E.g. when switching to an internal editor window
  10222. ResetIncrementalSearch();
  10223. }
  10224. //---------------------------------------------------------------------------
  10225. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10226. {
  10227. // When switching to another application
  10228. ResetIncrementalSearch();
  10229. }
  10230. //---------------------------------------------------------------------------
  10231. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10232. {
  10233. ResetIncrementalSearch();
  10234. }
  10235. //---------------------------------------------------------------------------
  10236. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10237. {
  10238. if (FIncrementalSearching <= 0)
  10239. {
  10240. ResetIncrementalSearch();
  10241. }
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10245. {
  10246. CountClicksForWindowPrint(this);
  10247. }
  10248. //---------------------------------------------------------------------------
  10249. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10250. {
  10251. CenterReconnectToolbar();
  10252. }
  10253. //---------------------------------------------------------------------------
  10254. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10255. {
  10256. if (RemoteDirView->ItemFocused != NULL)
  10257. {
  10258. RemoteDirView->ItemFocused->Selected = true;
  10259. }
  10260. }
  10261. //---------------------------------------------------------------------------
  10262. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10263. {
  10264. if (!FQueueStatusUpdating)
  10265. {
  10266. bool Refresh;
  10267. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10268. {
  10269. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10270. }
  10271. else
  10272. {
  10273. if (FQueueFileList->GetCount() > 0)
  10274. {
  10275. FQueueFileList->Clear();
  10276. Refresh = true;
  10277. }
  10278. }
  10279. int Count = FQueueFileList->GetCount();
  10280. if (QueueFileList->Items->Count != Count)
  10281. {
  10282. DebugAssert(Refresh);
  10283. QueueFileList->Items->Count = Count;
  10284. }
  10285. if (Refresh)
  10286. {
  10287. QueueFileList->Invalidate();
  10288. }
  10289. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10290. }
  10291. }
  10292. //---------------------------------------------------------------------------
  10293. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10294. {
  10295. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10296. }
  10297. //---------------------------------------------------------------------------
  10298. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10299. {
  10300. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10301. // See TSynchronizeChecklistDialog::UpdateTimer
  10302. if (QueueFileList->Items->Count > 0)
  10303. {
  10304. QueueFileList->Items->Item[0]->MakeVisible(false);
  10305. }
  10306. UpdateQueueFileList();
  10307. }
  10308. //---------------------------------------------------------------------------
  10309. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10310. {
  10311. Active = QueueView3->Focused() || QueueFileList->Focused();
  10312. }
  10313. //---------------------------------------------------------------------------
  10314. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10315. {
  10316. QueueLabelUpdateStatus();
  10317. }
  10318. //---------------------------------------------------------------------------
  10319. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10320. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10321. {
  10322. int State = FQueueFileList->GetState(Item->Index);
  10323. if (State == qfsProcessed)
  10324. {
  10325. Sender->Canvas->Font->Color = clGrayText;
  10326. }
  10327. }
  10328. //---------------------------------------------------------------------------
  10329. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10330. {
  10331. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10332. QueueFileList->Column[0]->Width =
  10333. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10334. }
  10335. //---------------------------------------------------------------------------
  10336. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10337. {
  10338. QueueFileListColumnAutoSize();
  10339. }
  10340. //---------------------------------------------------------------------------
  10341. void __fastcall TCustomScpExplorerForm::CloseApp()
  10342. {
  10343. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10344. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10345. // So we clear the flag here.
  10346. DebugAssert(NonVisualDataModule->Busy);
  10347. NonVisualDataModule->EndBusy();
  10348. try
  10349. {
  10350. Close();
  10351. }
  10352. __finally
  10353. {
  10354. NonVisualDataModule->StartBusy();
  10355. }
  10356. }
  10357. //---------------------------------------------------------------------------
  10358. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10359. {
  10360. return (Terminal != NULL) && Terminal->Active;
  10361. }
  10362. //---------------------------------------------------------------------------
  10363. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10364. {
  10365. return IsActiveTerminal(Terminal);
  10366. }