CustomScpExplorer.cpp 371 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 3;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FSessionChanging = false;
  178. FCopyParamDefault = L"";
  179. FSynchronizeController = NULL;
  180. FPendingQueueActionItem = NULL;
  181. FLockLevel = 0;
  182. FLockSuspendLevel = 0;
  183. FDisabledOnLockSuspend = false;
  184. FAlternativeDelete = false;
  185. FTrayIcon = new ::TTrayIcon(0);
  186. FTrayIcon->OnClick = TrayIconClick;
  187. FMaxQueueLength = 0;
  188. FLastContextPopupScreenPoint = TPoint(-1, -1);
  189. FTransferResumeList = NULL;
  190. FMoveToQueue = false;
  191. FStandaloneEditing = false;
  192. FOnFeedSynchronizeError = NULL;
  193. FNeedSession = false;
  194. FDoNotIdleCurrentTerminal = 0;
  195. FIncrementalSearching = 0;
  196. FIncrementalSearchHaveNext = false;
  197. FQueueFileList.reset(new TQueueFileList());
  198. FProgressSide = osCurrent;
  199. FEditorManager = new TEditorManager();
  200. FEditorManager->OnFileChange = ExecutedFileChanged;
  201. FEditorManager->OnFileReload = ExecutedFileReload;
  202. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  203. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  204. FLocalEditors = new TList();
  205. FQueueStatus = NULL;
  206. FQueueStatusSection = new TCriticalSection();
  207. FQueueStatusInvalidated = false;
  208. FQueueItemInvalidated = false;
  209. FQueueStatusUpdating = false;
  210. FQueueActedItem = NULL;
  211. FQueueController = new TQueueController(QueueView3);
  212. FUserActionTimer = new TTimer(this);
  213. FUserActionTimer->Enabled = false;
  214. FUserActionTimer->Interval = 10;
  215. FUserActionTimer->OnTimer = UserActionTimer;
  216. FNotes = new TStringList();
  217. FNoteTimer = new TTimer(this);
  218. FNoteTimer->Enabled = false;
  219. FNoteTimer->OnTimer = NoteTimer;
  220. FOnNoteClick = NULL;
  221. FOle32Library = LoadLibrary(L"Ole32.dll");
  222. FDragMoveCursor = FOle32Library != NULL ?
  223. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  224. UseSystemSettings(this);
  225. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  226. static_cast<TObject*>(GetComponent(fcTransferList)));
  227. DebugAssert(TransferList != NULL);
  228. FTransferListHoverIndex = -1;
  229. TransferList->OnChange = TransferListChange;
  230. TransferList->OnDrawItem = TransferListDrawItem;
  231. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))), true);
  232. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  233. UseDesktopFont(SessionsPageControl);
  234. UpdateSessionsPageControlHeight();
  235. UseDesktopFont(RemoteDirView);
  236. UseDesktopFont(RemoteDriveView);
  237. UseDesktopFont(QueueView3);
  238. UseDesktopFont(QueueFileList);
  239. UseDesktopFont(QueueLabel);
  240. UseDesktopFont(RemoteStatusBar);
  241. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  242. QueueSplitter->ShowHint = true;
  243. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  244. QueueFileListSplitter->ShowHint = true;
  245. RemotePanelSplitter->ShowHint = true;
  246. UpdateImages();
  247. FCustomCommandMenu = CreateTBXPopupMenu(this);
  248. FCustomCommandLocalFileList = NULL;
  249. FCustomCommandRemoteFileList = NULL;
  250. FSessionColors = new TPngImageList(this);
  251. FSessionColors->ColorDepth = cd32Bit;
  252. AddFixedSessionImages();
  253. SessionsPageControl->Images = FSessionColors;
  254. UpdateQueueLabel();
  255. CreateHiddenWindow();
  256. StartUpdates();
  257. }
  258. //---------------------------------------------------------------------------
  259. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  260. {
  261. FInvalid = true;
  262. // this has to be one of the very first things to do
  263. StopUpdateThread();
  264. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  265. TTerminalManager::Instance()->ScpExplorer = NULL;
  266. delete FCustomCommandLocalFileList;
  267. delete FCustomCommandRemoteFileList;
  268. delete FCustomCommandMenu;
  269. delete FTrayIcon;
  270. FTrayIcon = NULL;
  271. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  272. delete FEditorManager;
  273. ForceCloseLocalEditors();
  274. delete FLocalEditors;
  275. HideFileFindDialog();
  276. if (FDelayedDeletionTimer)
  277. {
  278. DoDelayedDeletion(NULL);
  279. SAFE_DESTROY(FDelayedDeletionTimer);
  280. }
  281. SAFE_DESTROY(FDelayedDeletionList);
  282. // sometimes we do not get DDEnd so the list is not released
  283. SAFE_DESTROY(FDDFileList);
  284. DebugAssert(FSynchronizeController == NULL);
  285. CloseHandle(FDDExtMutex);
  286. FDDExtMutex = NULL;
  287. FreeLibrary(FOle32Library);
  288. FOle32Library = NULL;
  289. FDragMoveCursor = NULL;
  290. DebugAssert(!FErrorList);
  291. if (FEverShown)
  292. {
  293. // when window is never shown (like when running command-line operation),
  294. // particularly window site is not restored correctly (BoundsRect value set
  295. // in RestoreForm gets lost during handle allocation), so we do not want
  296. // it to be stored
  297. StoreParams();
  298. }
  299. ManagedSession = NULL;
  300. Queue = NULL;
  301. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  302. NonVisualDataModule->ScpExplorer = NULL;
  303. delete FQueueController;
  304. FQueueController = NULL;
  305. delete FQueueStatusSection;
  306. FQueueStatusSection = NULL;
  307. delete FQueueStatus;
  308. FQueueStatus = NULL;
  309. delete FUserActionTimer;
  310. FUserActionTimer = NULL;
  311. delete FNoteTimer;
  312. delete FNotes;
  313. delete FNoteData;
  314. SAFE_DESTROY(FDocks);
  315. SessionsPageControl->Images = NULL;
  316. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  317. SAFE_DESTROY(FSessionColors);
  318. SAFE_DESTROY(FSessionsDragDropFilesEx);
  319. SAFE_DESTROY(FHistoryMenu[0][0]);
  320. SAFE_DESTROY(FHistoryMenu[0][1]);
  321. SAFE_DESTROY(FHistoryMenu[1][0]);
  322. SAFE_DESTROY(FHistoryMenu[1][1]);
  323. if (FHiddenWindow != NULL)
  324. {
  325. DestroyWindow(FHiddenWindow);
  326. FHiddenWindow = NULL;
  327. }
  328. }
  329. //---------------------------------------------------------------------------
  330. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  331. {
  332. std::unique_ptr<TSessionData> Data;
  333. if (!Session.IsEmpty())
  334. {
  335. bool DefaultsOnly;
  336. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  337. }
  338. TTerminalManager * Manager = TTerminalManager::Instance();
  339. for (int Index = 0; Index < Manager->Count; Index++)
  340. {
  341. TTerminal * Terminal = Manager->Sessions[Index];
  342. if (Session.IsEmpty() ||
  343. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  344. {
  345. if (Path.IsEmpty())
  346. {
  347. Terminal->ClearCaches();
  348. }
  349. else
  350. {
  351. Terminal->DirectoryModified(Path, true);
  352. }
  353. }
  354. }
  355. // We should flag a pending refresh for the background terminals or busy foreground terminals
  356. if (HasActiveTerminal() &&
  357. CanCommandLineFromAnotherInstance() &&
  358. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  359. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  360. {
  361. Terminal->ReloadDirectory();
  362. }
  363. }
  364. //---------------------------------------------------------------------------
  365. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  366. {
  367. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  368. size_t MessageSize = sizeof(TCopyDataMessage);
  369. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  370. if (Result)
  371. {
  372. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  373. Result = (Message.Version == TCopyDataMessage::Version1);
  374. if (Result)
  375. {
  376. switch (Message.Command)
  377. {
  378. case TCopyDataMessage::CommandCanCommandLine:
  379. Result = CanCommandLineFromAnotherInstance();
  380. break;
  381. case TCopyDataMessage::CommandCommandLine:
  382. {
  383. UnicodeString CommandLine(Message.CommandLine);
  384. Result = CommandLineFromAnotherInstance(CommandLine);
  385. }
  386. break;
  387. case TCopyDataMessage::RefreshPanel:
  388. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  389. break;
  390. case TCopyDataMessage::MainWindowCheck:
  391. Result = true;
  392. break;
  393. default:
  394. Result = false;
  395. break;
  396. }
  397. }
  398. }
  399. Message.Result = Result ? 1 : 0;
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  403. {
  404. WNDCLASS WindowClass = {0};
  405. WindowClass.lpfnWndProc = DefWindowProc;
  406. WindowClass.hInstance = HInstance;
  407. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  408. FHiddenWindow = NULL;
  409. if (RegisterClass(&WindowClass))
  410. {
  411. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  412. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  413. }
  414. }
  415. //---------------------------------------------------------------------------
  416. bool __fastcall TCustomScpExplorerForm::CanConsole()
  417. {
  418. return
  419. HasActiveTerminal() &&
  420. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  421. }
  422. //---------------------------------------------------------------------------
  423. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  424. {
  425. bool Result = Visible && !NonVisualDataModule->Busy;
  426. return Result;
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  430. const UnicodeString & CommandLine)
  431. {
  432. TProgramParams Params(CommandLine);
  433. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  434. if (Result)
  435. {
  436. NonVisualDataModule->StartBusy();
  437. try
  438. {
  439. // this action is initiated from another process,
  440. // so it's likely that our window is not visible,
  441. // and user won't see what is going on
  442. Application->BringToFront();
  443. // reload sessions as we may be asked to open a session
  444. // just stored by another instance
  445. StoredSessions->Reload();
  446. UnicodeString SessionName = Params.Param[1];
  447. std::unique_ptr<TObjectList> DataList(new TObjectList());
  448. UnicodeString DownloadFile; // unused
  449. try
  450. {
  451. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  452. }
  453. catch (EAbort &)
  454. {
  455. // Happens when opening session in PuTTY and in other situations,
  456. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  457. // to process the command-line on its own (or to pass it to yet another instance)
  458. }
  459. if (DataList->Count > 0)
  460. {
  461. TTerminalManager * Manager = TTerminalManager::Instance();
  462. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  463. }
  464. }
  465. __finally
  466. {
  467. NonVisualDataModule->EndBusy();
  468. }
  469. }
  470. return Result;
  471. }
  472. //---------------------------------------------------------------------------
  473. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  474. {
  475. TManagedTerminal * Result;
  476. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  477. {
  478. Result = FManagedSession;
  479. }
  480. else
  481. {
  482. Result = NULL;
  483. }
  484. return Result;
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  488. {
  489. if (FManagedSession != value)
  490. {
  491. SessionChanging();
  492. DoSetManagedSession(value, false);
  493. }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  497. {
  498. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  499. FManagedSession = value;
  500. {
  501. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  502. FAllowTransferPresetAutoSelect = false;
  503. TAutoFlag SessionChangingFlag(FSessionChanging);
  504. SessionChanged(Replace);
  505. }
  506. if (Terminal != NULL)
  507. {
  508. TransferPresetAutoSelect();
  509. }
  510. // Update app and tab titles, prevented above by FSessionChanging.
  511. UpdateControls();
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  515. {
  516. DoSetManagedSession(value, true);
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::SessionChanging()
  520. {
  521. if (ManagedSession != NULL)
  522. {
  523. UpdateSession(ManagedSession);
  524. }
  525. }
  526. //---------------------------------------------------------------------------
  527. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  528. {
  529. if (Terminal != NULL)
  530. {
  531. UpdateSessionColor((TColor)Terminal->StateData->Color);
  532. }
  533. if (!TTerminalManager::Instance()->Updating)
  534. {
  535. SessionListChanged();
  536. }
  537. if (Terminal != NULL)
  538. {
  539. if (Replaced)
  540. {
  541. RemoteDirView->ReplaceTerminal(Terminal);
  542. }
  543. else
  544. {
  545. RemoteDirView->Terminal = Terminal;
  546. }
  547. if (Terminal->Active)
  548. {
  549. Terminal->RefreshDirectory();
  550. }
  551. if (WinConfiguration->PreservePanelState)
  552. {
  553. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  554. }
  555. }
  556. else
  557. {
  558. RemoteDirView->Terminal = NULL;
  559. }
  560. InitStatusBar();
  561. UpdateTransferList();
  562. // Update panels Enable state before refreshing the labels
  563. UpdateControls();
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  567. {
  568. if (Queue != value)
  569. {
  570. if (FQueue != NULL)
  571. {
  572. FQueue->OnListUpdate = NULL;
  573. FQueue->OnQueueItemUpdate = NULL;
  574. }
  575. FQueue = value;
  576. if (FQueue != NULL)
  577. {
  578. DebugAssert(FQueue->OnListUpdate == NULL);
  579. FQueue->OnListUpdate = QueueListUpdate;
  580. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  581. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  582. }
  583. QueueChanged();
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  588. TListItem * Item)
  589. {
  590. if (FQueueActedItem == Item)
  591. {
  592. FQueueActedItem = NULL;
  593. if ((QueueView3->PopupMenu != NULL) &&
  594. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  595. {
  596. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  597. ReleaseCapture();
  598. }
  599. }
  600. if (Item->Data == FPendingQueueActionItem)
  601. {
  602. FPendingQueueActionItem = NULL;
  603. }
  604. }
  605. //---------------------------------------------------------------------------
  606. bool TCustomScpExplorerForm::IsAnythingQueued()
  607. {
  608. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  612. {
  613. {
  614. TGuard Guard(FQueueStatusSection);
  615. FQueueStatusInvalidated = false;
  616. if (FQueue != NULL)
  617. {
  618. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  619. }
  620. }
  621. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  622. {
  623. FMaxQueueLength = FQueueStatus->Count;
  624. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  625. }
  626. {
  627. TAutoFlag Flag(FQueueStatusUpdating);
  628. FQueueController->UpdateQueueStatus(FQueueStatus);
  629. }
  630. UpdateQueueFileList();
  631. SetQueueProgress();
  632. UpdateQueueView();
  633. bool IsEmpty = !IsAnythingQueued();
  634. if (IsEmpty && (Terminal != NULL))
  635. {
  636. TOnceDoneOperation OnceDoneOperation =
  637. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  638. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  639. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  640. {
  641. FQueue->Enabled = false;
  642. }
  643. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  644. {
  645. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  646. }
  647. }
  648. }
  649. //---------------------------------------------------------------------------
  650. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  651. {
  652. UnicodeString Result;
  653. if (FQueueStatus != NULL)
  654. {
  655. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  656. {
  657. TFileOperationProgressType * ProgressData =
  658. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  659. if ((ProgressData != NULL) && ProgressData->InProgress)
  660. {
  661. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  662. }
  663. }
  664. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  665. {
  666. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  667. }
  668. }
  669. return Result;
  670. }
  671. //---------------------------------------------------------------------------
  672. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  673. {
  674. ComponentVisible[fcQueueView] =
  675. !IsLocalBrowserMode() &&
  676. ((WinConfiguration->QueueView.Show == qvShow) ||
  677. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  678. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  679. }
  680. //---------------------------------------------------------------------------
  681. void __fastcall TCustomScpExplorerForm::QueueChanged()
  682. {
  683. if (FQueueStatus != NULL)
  684. {
  685. // UpdateFileList implementation relies on the status being recreated when session changes
  686. delete FQueueStatus;
  687. FQueueStatus = NULL;
  688. }
  689. UpdateQueueStatus(true);
  690. }
  691. //---------------------------------------------------------------------------
  692. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  693. {
  694. if (FQueue == Queue)
  695. {
  696. FQueueStatusInvalidated = true;
  697. }
  698. }
  699. //---------------------------------------------------------------------------
  700. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  701. TQueueItem * Item)
  702. {
  703. if (FQueue == Queue)
  704. {
  705. TGuard Guard(FQueueStatusSection);
  706. // this may be running in parallel with QueueChanged
  707. if (FQueueStatus != NULL)
  708. {
  709. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  710. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  711. {
  712. FRefreshLocalDirectory = (QueueItem == NULL) ||
  713. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  714. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  715. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  716. }
  717. if (QueueItem != NULL)
  718. {
  719. QueueItem->UserData = (void*)true;
  720. FQueueItemInvalidated = true;
  721. }
  722. }
  723. }
  724. }
  725. //---------------------------------------------------------------------------
  726. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  727. {
  728. // during standalone editing, we have no way to see/control queue,
  729. // so we have to always popup prompts automatically
  730. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  734. {
  735. if (FQueueStatus != NULL)
  736. {
  737. bool QueueAutoPopup = IsQueueAutoPopup();
  738. bool NeedRefresh = FQueueController->NeedRefresh();
  739. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  740. FQueueItemInvalidated = false;
  741. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  742. bool Updated = false;
  743. TQueueItemProxy * QueueItem;
  744. bool WasUserAction;
  745. for (int Index = 0; Index < Limit; Index++)
  746. {
  747. bool Update = false;
  748. QueueItem = FQueueStatus->Items[Index];
  749. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  750. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  751. (FPendingQueueActionItem == NULL))
  752. {
  753. FPendingQueueActionItem = QueueItem;
  754. FUserActionTimer->Enabled = true;
  755. }
  756. if ((bool)QueueItem->UserData)
  757. {
  758. QueueItem->UserData = (void*)false;
  759. QueueItem->Update();
  760. Updated = true;
  761. Update = true;
  762. }
  763. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  764. {
  765. Update = true;
  766. }
  767. if (Update)
  768. {
  769. FQueueController->RefreshQueueItem(QueueItem);
  770. }
  771. }
  772. if (Updated)
  773. {
  774. NonVisualDataModule->UpdateNonVisibleActions();
  775. SetQueueProgress();
  776. UpdateQueueFileList();
  777. }
  778. }
  779. }
  780. //---------------------------------------------------------------------------
  781. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  782. {
  783. if (FTaskbarList != NULL)
  784. {
  785. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  786. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  787. }
  788. }
  789. //---------------------------------------------------------------------------
  790. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  791. {
  792. if (Progress >= 0)
  793. {
  794. if (FTaskbarList != NULL)
  795. {
  796. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  797. }
  798. }
  799. else
  800. {
  801. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  802. }
  803. }
  804. //---------------------------------------------------------------------------
  805. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  806. {
  807. int OverallProgress;
  808. // FProgressForm is null when this is called from SetQueueProgress
  809. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  810. {
  811. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  812. }
  813. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  814. {
  815. OverallProgress = ProgressData->OverallProgress();
  816. }
  817. else
  818. {
  819. OverallProgress = -1;
  820. }
  821. SetTaskbarListProgressValue(OverallProgress);
  822. }
  823. //---------------------------------------------------------------------------
  824. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  825. {
  826. TTerminalManager::Instance()->QueueStatusUpdated();
  827. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  828. {
  829. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  830. {
  831. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  832. {
  833. TFileOperationProgressType * ProgressData = NULL;
  834. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  835. {
  836. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  837. }
  838. if ((ProgressData != NULL) &&
  839. ProgressData->InProgress)
  840. {
  841. SetTaskbarListProgressValue(ProgressData);
  842. }
  843. else
  844. {
  845. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  846. }
  847. }
  848. else
  849. {
  850. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  851. }
  852. }
  853. else
  854. {
  855. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  856. }
  857. }
  858. UpdateQueueLabel();
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  862. {
  863. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  864. if (FQueueStatus != NULL)
  865. {
  866. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  867. if (ActiveAndPendingPrimaryCount > 0)
  868. {
  869. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  870. }
  871. }
  872. QueueLabel->Caption = Caption;
  873. }
  874. //---------------------------------------------------------------------------
  875. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  876. {
  877. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  878. static_cast<TComponent*>(GetComponent(fcTransferList)));
  879. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  880. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  881. TransferList->Strings->BeginUpdate();
  882. try
  883. {
  884. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  885. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  886. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  887. if (FTransferDropDownHint.IsEmpty())
  888. {
  889. FTransferDropDownHint = TransferDropDown->Hint;
  890. }
  891. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  892. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  893. TransferDropDown->Text = StripHotkey(Name);
  894. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  895. (FTransferDropDownHint, StripHotkey(Name),
  896. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  897. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  898. // update the label, otherwise when it is updated only on the first draw
  899. // of the list, it is drawn "bold" for some reason
  900. FTransferListHoverIndex = TransferList->ItemIndex;
  901. UpdateTransferLabel();
  902. }
  903. __finally
  904. {
  905. TransferList->Strings->EndUpdate();
  906. }
  907. }
  908. //---------------------------------------------------------------------------
  909. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  910. {
  911. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  912. DebugAssert(Toolbar != NULL);
  913. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  914. }
  915. //---------------------------------------------------------------------------
  916. void __fastcall TCustomScpExplorerForm::UpdateActions()
  917. {
  918. TForm::UpdateActions();
  919. if (ComponentVisible[fcCustomCommandsBand])
  920. {
  921. UpdateCustomCommandsToolbar();
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  926. {
  927. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  931. {
  932. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  933. {
  934. DirView->RowSelect = WinConfiguration->FullRowSelect;
  935. // selection is not redrawn automatically when RowSelect changes
  936. DirView->Invalidate();
  937. }
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  941. {
  942. Color = GetBtnFaceColor();
  943. DebugAssert(Configuration && RemoteDirView);
  944. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  945. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  946. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  947. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  948. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  949. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  950. UpdateRowSelect(RemoteDirView);
  951. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  952. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  953. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  954. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  955. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  956. UpdateSessionsPageControlHeight();
  957. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  958. UpdateToolbarDisplayMode();
  959. UpdateTransferList();
  960. if (Terminal != NULL)
  961. {
  962. TransferPresetAutoSelect();
  963. }
  964. UpdateQueueView();
  965. UpdateControls();
  966. // this can be called even before constuctor finishes.
  967. if (FEditorManager != NULL)
  968. {
  969. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  970. }
  971. // this can be called even before constuctor finishes.
  972. if (FLocalEditors != NULL)
  973. {
  974. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  975. {
  976. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  977. }
  978. }
  979. if (ComponentVisible[fcCustomCommandsBand])
  980. {
  981. UpdateCustomCommandsToolbar();
  982. }
  983. // show only when keeping queue items forever,
  984. // otherwise, its enough to have in in the context menu
  985. QueueDeleteAllDoneQueueToolbarItem->Visible =
  986. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  987. if (FFileColorsCurrent != WinConfiguration->FileColors)
  988. {
  989. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  990. FFileColorsCurrent = WinConfiguration->FileColors;
  991. FileColorsChanged();
  992. }
  993. }
  994. //---------------------------------------------------------------------------
  995. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  996. {
  997. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  998. DirView->Invalidate();
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1002. {
  1003. DoFileColorsChanged(RemoteDirView);
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1007. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1008. void * /*Arg*/)
  1009. {
  1010. if (Token != NULL)
  1011. {
  1012. TForm * Editor = dynamic_cast<TForm*>(Token);
  1013. DebugAssert(Editor != NULL);
  1014. ReconfigureEditorForm(Editor);
  1015. }
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1019. {
  1020. WinConfiguration->DDTransferConfirmation = asOn;
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1024. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1025. {
  1026. // noop
  1027. }
  1028. //---------------------------------------------------------------------------
  1029. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1030. {
  1031. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1035. {
  1036. if (DoNotShowAgain)
  1037. {
  1038. if (DragDrop)
  1039. {
  1040. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1041. {
  1042. PopupTrayBalloon(
  1043. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1044. }
  1045. WinConfiguration->DDTransferConfirmation = asOff;
  1046. }
  1047. else
  1048. {
  1049. WinConfiguration->ConfirmTransferring = false;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. // User explicitly unchecked "do not show again",
  1055. // so show him the dialog the next time
  1056. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1057. {
  1058. WinConfiguration->DDTransferConfirmation = asOn;
  1059. }
  1060. }
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1064. TTransferDirection Direction, TTransferType Type, bool Temp,
  1065. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1066. bool Confirm, bool DragDrop, int Options)
  1067. {
  1068. bool Result = true;
  1069. DebugAssert(HasActiveTerminal());
  1070. // these parameters are known in advance
  1071. int Params =
  1072. FLAGMASK(Type == ttMove, cpDelete);
  1073. bool ToTemp = (Temp && (Direction == tdToLocal));
  1074. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1075. {
  1076. bool DisableNewerOnly =
  1077. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1078. ToTemp;
  1079. Options |=
  1080. FLAGMASK(ToTemp, coTemp) |
  1081. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1082. coDoNotShowAgain;
  1083. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1084. int CopyParamAttrs = (Direction == tdToRemote ?
  1085. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1086. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1087. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1088. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1089. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1090. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1091. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1092. if (Result)
  1093. {
  1094. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1095. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1096. }
  1097. }
  1098. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1099. {
  1100. Configuration->Usage->Inc(L"TransfersOnBackground");
  1101. // these parameter are known only after transfer dialog
  1102. Params |=
  1103. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1104. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1105. Result = false;
  1106. ClearTransferSourceSelection(Direction);
  1107. }
  1108. return Result;
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1112. {
  1113. if (FOnFileOperationFinished != NULL)
  1114. {
  1115. FOnFileOperationFinished(UnicodeString(), true);
  1116. }
  1117. else
  1118. {
  1119. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1120. if (HasDirView[Side])
  1121. {
  1122. DirView(Side)->SelectAll(smNone);
  1123. }
  1124. }
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1128. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1129. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1130. int Params)
  1131. {
  1132. DebugAssert(Queue != NULL);
  1133. bool SingleFile = false;
  1134. if (FileList->Count == 1)
  1135. {
  1136. if (Direction == tdToRemote)
  1137. {
  1138. UnicodeString FileName = FileList->Strings[0];
  1139. SingleFile = FileExists(ApiPath(FileName));
  1140. }
  1141. else
  1142. {
  1143. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1144. SingleFile = !File->IsDirectory;
  1145. }
  1146. }
  1147. TQueueItem * QueueItem;
  1148. if (Direction == tdToRemote)
  1149. {
  1150. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1151. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1152. }
  1153. else
  1154. {
  1155. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1156. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1157. }
  1158. AddQueueItem(Queue, QueueItem, Terminal);
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1162. {
  1163. if (Queue->IsEmpty)
  1164. {
  1165. Terminal->QueueOperationStart = Now();
  1166. }
  1167. Queue->AddItem(QueueItem);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1171. {
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TCustomScpExplorerForm::InitControls()
  1175. {
  1176. DebugAssert(FDocks != NULL);
  1177. for (int Index = 0; Index < ComponentCount; Index++)
  1178. {
  1179. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1180. if ((Dock != NULL) && (Dock->Tag == 0))
  1181. {
  1182. FDocks->Add(Dock);
  1183. }
  1184. }
  1185. CollectItemsWithTextDisplayMode(this);
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1189. {
  1190. ConfigurationChanged();
  1191. QueuePanel->Height =
  1192. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1193. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1194. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1195. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1196. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1197. QueueFileList->Height =
  1198. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1199. if (QueueFileList->Visible)
  1200. {
  1201. AdjustQueueLayout();
  1202. }
  1203. UpdateCustomCommandsToolbar();
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TCustomScpExplorerForm::StoreParams()
  1207. {
  1208. int APixelsPerInch = GetControlPixelsPerInch(this);
  1209. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1210. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1211. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1212. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1213. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1214. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1215. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1216. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1217. }
  1218. //---------------------------------------------------------------------------
  1219. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1220. {
  1221. if (!FFormRestored)
  1222. {
  1223. FFormRestored = true;
  1224. RestoreFormParams();
  1225. }
  1226. TForm::CreateParams(Params);
  1227. }
  1228. //---------------------------------------------------------------------------
  1229. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1230. {
  1231. DebugAssert(FDocks != NULL);
  1232. for (int Index = 0; Index < FDocks->Count; Index++)
  1233. {
  1234. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1235. }
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1239. {
  1240. SetDockAllowDrag(true);
  1241. while (!ButtonsStr.IsEmpty())
  1242. {
  1243. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1244. UnicodeString Name = CutToChar(S, L'=', true);
  1245. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1246. {
  1247. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1248. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1249. {
  1250. while (!S.IsEmpty())
  1251. {
  1252. UnicodeString S2 = CutToChar(S, L',', true);
  1253. UnicodeString Name = CutToChar(S2, L':', true);
  1254. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1255. {
  1256. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1257. if (SameText(GetToolbarItemName(Item), Name))
  1258. {
  1259. // forward compatibility
  1260. UnicodeString S3 = CutToChar(S2, L':', true);
  1261. bool Visible = StrToIntDef(S3, 0);
  1262. Item->Visible = Visible;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1270. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1274. {
  1275. UnicodeString Result;
  1276. SetDockAllowDrag(true);
  1277. Result = ::GetToolbarsLayoutStr(this);
  1278. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1283. {
  1284. UnicodeString Result;
  1285. if (Item->Action != NULL)
  1286. {
  1287. Result = Item->Action->Name;
  1288. Result = RemoveSuffix(Result, L"Action", true);
  1289. }
  1290. else
  1291. {
  1292. Result = Item->Name;
  1293. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1294. Result = RemoveSuffix(Result, L"Item", true);
  1295. }
  1296. return Result;
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1300. {
  1301. UnicodeString Result;
  1302. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1303. {
  1304. UnicodeString ToolbarStr;
  1305. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1306. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1307. {
  1308. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1309. {
  1310. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1311. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1312. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1313. // and save the changes here only.
  1314. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1315. {
  1316. UnicodeString Name = GetToolbarItemName(Item);
  1317. DebugAssert(Name.Pos(L"TBX") == 0);
  1318. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1319. }
  1320. }
  1321. }
  1322. if (!ToolbarStr.IsEmpty())
  1323. {
  1324. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1325. }
  1326. }
  1327. return Result;
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1331. {
  1332. DebugAssert(FProgressForm == NULL);
  1333. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1334. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1335. FProgressForm->DeleteLocalToRecycleBin =
  1336. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1337. FProgressForm->DeleteRemoteToRecycleBin =
  1338. (Terminal != NULL) &&
  1339. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1340. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1341. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1342. LockWindow();
  1343. // Actually, do not know what hides the progress once the operation finishes
  1344. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1345. SetTaskbarListProgressState(TBPF_NORMAL);
  1346. }
  1347. //---------------------------------------------------------------------------
  1348. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1349. {
  1350. UnlockWindow();
  1351. SAFE_DESTROY(FProgressForm);
  1352. SetQueueProgress();
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1356. TFileOperationProgressType & ProgressData)
  1357. {
  1358. // Download to temporary local directory
  1359. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1360. {
  1361. bool Continue = true;
  1362. FPendingTempSpaceWarn = false;
  1363. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1364. if (!Continue)
  1365. {
  1366. Abort();
  1367. }
  1368. }
  1369. // operation is being executed and we still didn't show up progress form
  1370. if (ProgressData.InProgress && !FProgressForm)
  1371. {
  1372. CreateProgressForm(NULL);
  1373. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1374. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1375. }
  1376. // operation is finished (or terminated), so we hide progress form
  1377. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1378. {
  1379. DestroyProgressForm();
  1380. if (ProgressData.Operation == foCalculateSize)
  1381. {
  1382. // When calculating size before transfer, the abort caused by
  1383. // cancel flag set due to "MoveToQueue" below,
  1384. // is not propagated back to us in ExecuteFileOperation,
  1385. // as it is silently swallowed.
  1386. // So we explicitly (re)throw it here.
  1387. if (FMoveToQueue)
  1388. {
  1389. Abort();
  1390. }
  1391. }
  1392. else
  1393. {
  1394. if ((ProgressData.Cancel == csContinue) &&
  1395. !FAutoOperation)
  1396. {
  1397. OperationComplete(ProgressData.StartTime);
  1398. }
  1399. }
  1400. }
  1401. if (FProgressForm &&
  1402. // Can happen only during synchronization, when ending one of the operations
  1403. ProgressData.InProgress)
  1404. {
  1405. FProgressForm->SetProgressData(ProgressData);
  1406. DebugAssert(ProgressData.InProgress);
  1407. SetTaskbarListProgressValue(&ProgressData);
  1408. if (FProgressForm->Cancel > csContinue)
  1409. {
  1410. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1411. if (FProgressForm->Cancel == csCancelFile)
  1412. {
  1413. FProgressForm->ClearCancel();
  1414. }
  1415. // cancel cancels even the move
  1416. FMoveToQueue = false;
  1417. }
  1418. else if (FProgressForm->MoveToQueue)
  1419. {
  1420. FMoveToQueue = true;
  1421. ProgressData.SetCancelAtLeast(csCancel);
  1422. }
  1423. if ((FTransferResumeList != NULL) &&
  1424. ProgressData.InProgress &&
  1425. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1426. !ProgressData.FullFileName.IsEmpty())
  1427. {
  1428. if ((FTransferResumeList->Count == 0) ||
  1429. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1430. {
  1431. // note that we do not recognize directories from files here
  1432. FTransferResumeList->Add(ProgressData.FullFileName);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1439. const TDateTime & StartTime)
  1440. {
  1441. if (GUIConfiguration->BeepOnFinish &&
  1442. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1443. {
  1444. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1445. DWORD Sound;
  1446. if (!ExtractFileExt(BeepSound).IsEmpty())
  1447. {
  1448. Sound = SND_FILENAME;
  1449. }
  1450. else
  1451. {
  1452. Sound = SND_ALIAS;
  1453. }
  1454. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1455. }
  1456. }
  1457. //---------------------------------------------------------------------------
  1458. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1459. TFileOperationProgressType & ProgressData)
  1460. {
  1461. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1462. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1463. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1464. FileOperationProgress(ProgressData);
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1468. {
  1469. UnicodeString Result;
  1470. if (FProgressForm != NULL)
  1471. {
  1472. Result = FProgressForm->ProgressStr();
  1473. }
  1474. return Result;
  1475. }
  1476. //---------------------------------------------------------------------------
  1477. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1478. bool DragDrop)
  1479. {
  1480. return (!DragDrop && (DropSourceControl == NULL)) ||
  1481. (DropSourceControl == DirView(osOther));
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1485. TFileOperation Operation, TOperationSide Side,
  1486. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1487. TOnceDoneOperation & OnceDoneOperation)
  1488. {
  1489. if (!FAutoOperation)
  1490. {
  1491. // no selection on "/upload", form serves only as event handler
  1492. // (it is not displayed)
  1493. if (PanelOperation(Side, FDragDropOperation) &&
  1494. Visible && (Operation != foCalculateSize) &&
  1495. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1496. {
  1497. if (FOnFileOperationFinished != NULL)
  1498. {
  1499. FOnFileOperationFinished(FileName, Success);
  1500. }
  1501. else
  1502. {
  1503. TOperationSide DViewSide;
  1504. if ((FProgressSide != osCurrent) &&
  1505. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1506. {
  1507. // assume the operation is over the focused panel
  1508. DViewSide = FProgressSide;
  1509. }
  1510. else
  1511. {
  1512. DViewSide = Side;
  1513. }
  1514. TCustomDirView * DView = DirView(DViewSide);
  1515. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1516. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1517. // this can happen when local drive is unplugged in the middle of the operation
  1518. if (Item != NULL)
  1519. {
  1520. if (Success) Item->Selected = false;
  1521. DView->MakeProgressVisible(Item);
  1522. }
  1523. }
  1524. }
  1525. if ((Operation == foCopy) || (Operation == foMove))
  1526. {
  1527. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1528. {
  1529. if (Side == osLocal)
  1530. {
  1531. Configuration->Usage->Inc(L"UploadedFiles");
  1532. }
  1533. else
  1534. {
  1535. Configuration->Usage->Inc(L"DownloadedFiles");
  1536. }
  1537. }
  1538. }
  1539. }
  1540. if (Success && (FSynchronizeController != NULL))
  1541. {
  1542. DebugAssert(!IsSideLocalBrowser(osRemote));
  1543. if (Operation == foCopy)
  1544. {
  1545. DebugAssert(Side == osLocal);
  1546. FSynchronizeController->LogOperation(soUpload, FileName);
  1547. }
  1548. else if (Operation == foDelete)
  1549. {
  1550. DebugAssert(Side == osRemote);
  1551. FSynchronizeController->LogOperation(soDelete, FileName);
  1552. }
  1553. }
  1554. if (FProgressForm)
  1555. {
  1556. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1557. }
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1561. TFileOperation Operation, TOperationSide Side,
  1562. bool Temp, const UnicodeString & FileName, Boolean Success,
  1563. TOnceDoneOperation & OnceDoneOperation)
  1564. {
  1565. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1566. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1567. OnceDoneOperation);
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1571. {
  1572. return false;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1576. {
  1577. return false;
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1581. {
  1582. return false;
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1586. {
  1587. return NULL;
  1588. }
  1589. //---------------------------------------------------------------------------
  1590. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1591. {
  1592. DebugAssert(GetSide(Side) == osRemote);
  1593. DebugUsedParam(Side);
  1594. return RemoteDirView;
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1598. {
  1599. DebugAssert(GetSide(Side) == osRemote);
  1600. DebugUsedParam(Side);
  1601. return RemoteDriveView;
  1602. }
  1603. //---------------------------------------------------------------------------
  1604. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1605. {
  1606. DebugAssert(GetSide(Side) == osRemote);
  1607. DebugUsedParam(Side);
  1608. return HasActiveTerminal();
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1612. TOperationSide Side, int FilesOnly)
  1613. {
  1614. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1618. TOperationSide Side, int FilesOnly)
  1619. {
  1620. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. struct THistoryItemData
  1624. {
  1625. short int Side;
  1626. short int Index;
  1627. };
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1630. {
  1631. DirView(Side)->HistoryGo(Index);
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1635. {
  1636. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1637. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1638. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1639. }
  1640. //---------------------------------------------------------------------------
  1641. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1642. bool Back)
  1643. {
  1644. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1645. {
  1646. TCustomDirView * DView = DirView(Side);
  1647. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1648. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1649. if (ICount > 10)
  1650. {
  1651. ICount = 10;
  1652. }
  1653. Menu->Items->Clear();
  1654. THistoryItemData Data;
  1655. Data.Side = Side;
  1656. for (short int i = 1; i <= ICount; i++)
  1657. {
  1658. TTBCustomItem * Item = new TTBXItem(Menu);
  1659. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1660. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1661. Item->Hint = DView->HistoryPath[Data.Index];
  1662. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1663. Item->Tag = *reinterpret_cast<int*>(&Data);
  1664. Item->OnClick = HistoryItemClick;
  1665. Menu->Items->Add(Item);
  1666. }
  1667. }
  1668. }
  1669. //---------------------------------------------------------------------------
  1670. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1671. TOperationSide Side, bool Back)
  1672. {
  1673. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1674. {
  1675. // workaround
  1676. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1677. // operator new allocates memory in Pascal code, but calls inline
  1678. // contructor in C++, leading in problems, the function does
  1679. // both in Pascal code
  1680. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1681. UpdateHistoryMenu(Side, Back);
  1682. }
  1683. return FHistoryMenu[Side == osLocal][Back];
  1684. }
  1685. //---------------------------------------------------------------------------
  1686. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1687. TCustomDirView *Sender)
  1688. {
  1689. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1690. UpdateHistoryMenu(Side, true);
  1691. UpdateHistoryMenu(Side, false);
  1692. }
  1693. //---------------------------------------------------------------------------
  1694. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1695. {
  1696. // remote custom commands can be executed only if the server supports shell commands
  1697. // or have secondary shell
  1698. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1699. }
  1700. //---------------------------------------------------------------------------
  1701. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1702. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1703. {
  1704. // -1 = hidden, 0 = disabled, 1 = enabled
  1705. int Result;
  1706. TFileCustomCommand RemoteCustomCommand;
  1707. TLocalCustomCommand LocalCustomCommand;
  1708. TFileCustomCommand * NonInteractiveCustomCommand =
  1709. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1710. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1711. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1712. if (FLAGCLEAR(Command.Params, ccLocal))
  1713. {
  1714. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1715. // custom command that does not operate with files can be executed anytime ...
  1716. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1717. {
  1718. // ... but do not show such command in remote file menu
  1719. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1720. {
  1721. Result = AllowedState;
  1722. }
  1723. else
  1724. {
  1725. Result = -1;
  1726. }
  1727. }
  1728. else
  1729. {
  1730. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1731. {
  1732. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1733. }
  1734. else
  1735. {
  1736. Result = -1;
  1737. }
  1738. }
  1739. }
  1740. else
  1741. {
  1742. // custom command that does not operate with files can be executed anytime
  1743. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1744. {
  1745. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1746. }
  1747. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1748. {
  1749. if ((ListType == ccltAll) || (ListType == ccltFile))
  1750. {
  1751. // special case is "diff"-style command that can be executed over any side,
  1752. // if we have both sides
  1753. Result =
  1754. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1755. // directly (instead of EnableSelectedOperation) to pass
  1756. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1757. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1758. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1759. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1760. }
  1761. else if (ListType == ccltBoth)
  1762. {
  1763. DebugAssert(!IsLocalBrowserMode());
  1764. Result = 1;
  1765. }
  1766. else
  1767. {
  1768. Result = -1;
  1769. }
  1770. }
  1771. else
  1772. {
  1773. if ((ListType == ccltAll) ||
  1774. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1775. {
  1776. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1777. }
  1778. else
  1779. {
  1780. Result = -1;
  1781. }
  1782. }
  1783. if ((Result > 0) &&
  1784. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1785. !HasActiveTerminal())
  1786. {
  1787. Result = 0;
  1788. }
  1789. }
  1790. return Result;
  1791. }
  1792. //---------------------------------------------------------------------------
  1793. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1794. TStrings * FileList, const TCustomCommandType & ACommand,
  1795. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1796. {
  1797. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1798. {
  1799. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1800. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1801. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1802. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1803. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1804. bool Capture =
  1805. FLAGSET(ACommand.Params, ccShowResults) ||
  1806. FLAGSET(ACommand.Params, ccCopyResults) ||
  1807. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1808. TCaptureOutputEvent OutputEvent = NULL;
  1809. DebugAssert(FCapturedLog == NULL);
  1810. if (Capture)
  1811. {
  1812. FCapturedLog = new TStringList();
  1813. OutputEvent = TerminalCaptureLog;
  1814. }
  1815. try
  1816. {
  1817. if (!RemoteCustomCommand.IsFileCommand(Command))
  1818. {
  1819. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1820. OutputEvent);
  1821. }
  1822. else
  1823. {
  1824. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1825. }
  1826. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1827. {
  1828. if (FLAGSET(ACommand.Params, ccCopyResults))
  1829. {
  1830. CopyToClipboard(FCapturedLog);
  1831. }
  1832. if (FLAGSET(ACommand.Params, ccShowResults))
  1833. {
  1834. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1835. }
  1836. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1837. {
  1838. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1839. }
  1840. }
  1841. }
  1842. __finally
  1843. {
  1844. SAFE_DESTROY(FCapturedLog);
  1845. }
  1846. }
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1850. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1851. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1852. {
  1853. DebugAssert(!IsLocalBrowserMode());
  1854. TStrings * LocalFileList = NULL;
  1855. TStrings * RemoteFileList = NULL;
  1856. TStrings * RemoteFileListFull = NULL;
  1857. try
  1858. {
  1859. if (LocalFileCommand)
  1860. {
  1861. if (ALocalFileList == NULL)
  1862. {
  1863. DebugAssert(HasDirView[osLocal]);
  1864. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1865. // directly (instead of EnableSelectedOperation) to pass
  1866. // false to FocusedFileOnlyWhenFocused
  1867. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1868. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1869. }
  1870. else
  1871. {
  1872. LocalFileList = ALocalFileList;
  1873. }
  1874. if (FileListCommand)
  1875. {
  1876. if (LocalFileList->Count != 1)
  1877. {
  1878. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1879. }
  1880. }
  1881. else
  1882. {
  1883. if ((LocalFileList->Count != 1) &&
  1884. (FileList->Count != 1) &&
  1885. (LocalFileList->Count != FileList->Count))
  1886. {
  1887. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1888. }
  1889. }
  1890. }
  1891. UnicodeString RootTempDir;
  1892. UnicodeString TempDir;
  1893. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1894. if (!RemoteFiles)
  1895. {
  1896. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1897. }
  1898. try
  1899. {
  1900. TDateTimes RemoteFileTimes;
  1901. if (RemoteFiles)
  1902. {
  1903. RemoteFileList = FileList;
  1904. }
  1905. else
  1906. {
  1907. RemoteFileList = new TStringList();
  1908. TMakeLocalFileListParams MakeFileListParam;
  1909. MakeFileListParam.FileList = RemoteFileList;
  1910. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1911. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1912. MakeFileListParam.Recursive =
  1913. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1914. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1915. if (!MakeFileListParam.Recursive)
  1916. {
  1917. RemoteFileTimes.clear();
  1918. RemoteFileListFull = new TStringList();
  1919. MakeFileListParam.FileList = RemoteFileListFull;
  1920. MakeFileListParam.Recursive = true;
  1921. MakeFileListParam.IncludeDirs = false;
  1922. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1923. }
  1924. else
  1925. {
  1926. RemoteFileListFull = RemoteFileList;
  1927. }
  1928. }
  1929. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1930. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1931. if (!NonBlocking)
  1932. {
  1933. int Count;
  1934. if (FileListCommand)
  1935. {
  1936. Count = 1;
  1937. }
  1938. else if (LocalFileCommand)
  1939. {
  1940. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1941. }
  1942. else
  1943. {
  1944. Count = RemoteFileList->Count;
  1945. }
  1946. Progress.Start(foCustomCommand, osRemote, Count);
  1947. DebugAssert(FProgressForm != NULL);
  1948. FProgressForm->ReadOnly = true;
  1949. }
  1950. try
  1951. {
  1952. if (FileListCommand)
  1953. {
  1954. UnicodeString LocalFile;
  1955. // MakeFileList does not delimit filenames
  1956. UnicodeString FileList = MakeFileList(RemoteFileList);
  1957. if (LocalFileCommand)
  1958. {
  1959. DebugAssert(LocalFileList->Count == 1);
  1960. LocalFile = LocalFileList->Strings[0];
  1961. }
  1962. TLocalCustomCommand CustomCommand(Data,
  1963. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1964. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1965. if (NonBlocking)
  1966. {
  1967. DebugAssert(!POutput);
  1968. ExecuteShellChecked(ShellCommand);
  1969. }
  1970. else
  1971. {
  1972. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1973. }
  1974. }
  1975. else if (LocalFileCommand)
  1976. {
  1977. if (LocalFileList->Count == 1)
  1978. {
  1979. UnicodeString LocalFile = LocalFileList->Strings[0];
  1980. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1981. {
  1982. UnicodeString FileName = RemoteFileList->Strings[Index];
  1983. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1984. Progress.SetFile(FileNameForProgress);
  1985. TLocalCustomCommand CustomCommand(Data,
  1986. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1987. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1988. TOnceDoneOperation OnceDoneOperation;
  1989. // Do not unselect anything, as it won't work with two panels anyway
  1990. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1991. }
  1992. }
  1993. else if (RemoteFileList->Count == 1)
  1994. {
  1995. UnicodeString FileName = RemoteFileList->Strings[0];
  1996. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1997. {
  1998. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1999. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2000. Progress.SetFile(LocalFileNameOnly);
  2001. TLocalCustomCommand CustomCommand(
  2002. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2003. FileName, LocalFileName, L"");
  2004. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2005. TOnceDoneOperation OnceDoneOperation;
  2006. // Do not unselect anything, as it won't work with two panels anyway
  2007. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2008. }
  2009. }
  2010. else
  2011. {
  2012. if (LocalFileList->Count != RemoteFileList->Count)
  2013. {
  2014. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2015. }
  2016. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileList->Strings[Index];
  2019. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2020. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2021. Progress.SetFile(LocalFileNameOnly); // sic
  2022. TLocalCustomCommand CustomCommand(
  2023. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2024. FileName, LocalFileName, L"");
  2025. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2026. TOnceDoneOperation OnceDoneOperation;
  2027. // Do not unselect anything, as it won't work with two panels anyway
  2028. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2029. }
  2030. }
  2031. }
  2032. else
  2033. {
  2034. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2035. {
  2036. UnicodeString FileName = RemoteFileList->Strings[Index];
  2037. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2038. Progress.SetFile(FileNameForProgress);
  2039. TLocalCustomCommand CustomCommand(Data,
  2040. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2041. FileName, L"", L"");
  2042. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2043. TOnceDoneOperation OnceDoneOperation;
  2044. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2045. }
  2046. }
  2047. }
  2048. __finally
  2049. {
  2050. if (!NonBlocking)
  2051. {
  2052. Progress.Stop();
  2053. }
  2054. }
  2055. DebugAssert(!FAutoOperation);
  2056. if (!RemoteFiles)
  2057. {
  2058. TempDir = IncludeTrailingBackslash(TempDir);
  2059. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2060. {
  2061. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2062. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2063. // Skip directories, process only nested files.
  2064. // The check is redundant as FileAge fails for directories anyway.
  2065. !DirectoryExists(FileName))
  2066. {
  2067. UnicodeString RemoteDir =
  2068. UnixExtractFileDir(
  2069. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2070. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2071. TDateTime NewTime;
  2072. if (FileAge(FileName, NewTime) &&
  2073. (NewTime != RemoteFileTimes[Index]))
  2074. {
  2075. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2076. TemporaryFileCopyParam(CopyParam);
  2077. CopyParam.FileMask = L"";
  2078. FAutoOperation = true;
  2079. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2080. TemporaryFilesList->Add(FileName);
  2081. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. __finally
  2088. {
  2089. FAutoOperation = false;
  2090. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2091. {
  2092. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2093. }
  2094. }
  2095. }
  2096. __finally
  2097. {
  2098. if (RemoteFileList != FileList)
  2099. {
  2100. delete RemoteFileList;
  2101. }
  2102. if (LocalFileList != ALocalFileList)
  2103. {
  2104. delete LocalFileList;
  2105. }
  2106. if (RemoteFileListFull != RemoteFileList)
  2107. {
  2108. delete RemoteFileListFull;
  2109. }
  2110. }
  2111. }
  2112. //---------------------------------------------------------------------------
  2113. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2114. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2115. bool FileListCommand, UnicodeString * POutput)
  2116. {
  2117. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2118. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2119. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2120. {
  2121. UnicodeString FileName = SelectedFileList->Strings[Index];
  2122. if (DirectoryExists(FileName))
  2123. {
  2124. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2125. {
  2126. LocalFileList->Add(FileName);
  2127. }
  2128. if (FLAGSET(ACommand.Params, ccRecursive))
  2129. {
  2130. TMakeLocalFileListParams MakeFileListParam;
  2131. MakeFileListParam.FileList = LocalFileList.get();
  2132. MakeFileListParam.FileTimes = NULL;
  2133. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2134. MakeFileListParam.Recursive = true;
  2135. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2136. }
  2137. }
  2138. else
  2139. {
  2140. LocalFileList->Add(FileName);
  2141. }
  2142. }
  2143. UnicodeString RemotePath;
  2144. if (Terminal != NULL)
  2145. {
  2146. RemotePath = Terminal->CurrentDirectory;
  2147. }
  2148. if (FileListCommand)
  2149. {
  2150. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2151. TLocalCustomCommand CustomCommand(
  2152. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2153. L"", L"", FileList);
  2154. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2155. }
  2156. else
  2157. {
  2158. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2159. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2160. DebugAssert(FProgressForm != NULL);
  2161. FProgressForm->ReadOnly = true;
  2162. try
  2163. {
  2164. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2165. {
  2166. UnicodeString FileName = LocalFileList->Strings[Index];
  2167. Progress.SetFile(FileName);
  2168. TLocalCustomCommand CustomCommand(
  2169. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2170. FileName, L"", L"");
  2171. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2172. TOnceDoneOperation OnceDoneOperation;
  2173. Progress.Finish(FileName, true, OnceDoneOperation);
  2174. }
  2175. }
  2176. __finally
  2177. {
  2178. Progress.Stop();
  2179. }
  2180. }
  2181. }
  2182. //---------------------------------------------------------------------------
  2183. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2184. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2185. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2186. {
  2187. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2188. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2189. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2190. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2191. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2192. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2193. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2194. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2195. std::unique_ptr<UnicodeString> POutput;
  2196. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2197. FLAGSET(ACommand.Params, ccCopyResults))
  2198. {
  2199. POutput.reset(new UnicodeString());
  2200. }
  2201. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2202. FProgressSide = FCurrentSide;
  2203. if (!LocalCustomCommand.IsFileCommand(Command))
  2204. {
  2205. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2206. }
  2207. // remote files?
  2208. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2209. {
  2210. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2211. }
  2212. // local files
  2213. else
  2214. {
  2215. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2216. }
  2217. if (POutput.get() != NULL)
  2218. {
  2219. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2220. int P = POutput->Pos(sLineBreak);
  2221. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2222. {
  2223. POutput->SetLength(P - 1);
  2224. }
  2225. // Copy even empty output to clipboard
  2226. if (FLAGSET(ACommand.Params, ccCopyResults))
  2227. {
  2228. CopyToClipboard(*POutput);
  2229. }
  2230. // But do not show an empty message box.
  2231. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2232. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2233. !POutput->IsEmpty())
  2234. {
  2235. TClipboardHandler ClipboardHandler;
  2236. ClipboardHandler.Text = *POutput;
  2237. TMessageParams Params;
  2238. TQueryButtonAlias Aliases[1];
  2239. Aliases[0].Button = qaRetry;
  2240. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2241. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2242. Params.Aliases = Aliases;
  2243. Params.AliasesCount = LENOF(Aliases);
  2244. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2245. }
  2246. }
  2247. }
  2248. //---------------------------------------------------------------------------
  2249. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2250. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2251. {
  2252. TCustomCommandData Data;
  2253. UnicodeString Site;
  2254. UnicodeString RemotePath;
  2255. if (HasActiveTerminal())
  2256. {
  2257. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2258. Data = TCustomCommandData(SessionData.get());
  2259. Site = Terminal->SessionData->SessionKey;
  2260. RemotePath = Terminal->CurrentDirectory;
  2261. }
  2262. UnicodeString HelpKeyword = ACommand.HomePage;
  2263. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2264. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2265. {
  2266. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2267. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2268. {
  2269. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2270. }
  2271. else
  2272. {
  2273. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2274. }
  2275. if (!DoCustomCommandOptionsDialog(
  2276. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2277. {
  2278. Abort();
  2279. }
  2280. }
  2281. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2282. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2283. {
  2284. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2285. }
  2286. else
  2287. {
  2288. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2289. }
  2290. }
  2291. //---------------------------------------------------------------------------
  2292. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2293. const TCustomCommandType & Command)
  2294. {
  2295. DebugAssert(FCustomCommandLocalFileList != NULL);
  2296. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2297. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2298. TStrings * LocalFileList = new TStringList();
  2299. TStrings * RemoteFileList = new TStringList();
  2300. try
  2301. {
  2302. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2303. {
  2304. LocalFileList->Clear();
  2305. LocalFileList->AddObject(
  2306. FCustomCommandLocalFileList->Strings[Index],
  2307. FCustomCommandLocalFileList->Objects[Index]);
  2308. RemoteFileList->Clear();
  2309. RemoteFileList->AddObject(
  2310. FCustomCommandRemoteFileList->Strings[Index],
  2311. FCustomCommandRemoteFileList->Objects[Index]);
  2312. CustomCommand(RemoteFileList, Command, LocalFileList);
  2313. }
  2314. }
  2315. __finally
  2316. {
  2317. delete LocalFileList;
  2318. delete RemoteFileList;
  2319. }
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2323. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2324. {
  2325. delete FCustomCommandLocalFileList;
  2326. delete FCustomCommandRemoteFileList;
  2327. // takeover ownership,
  2328. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2329. FCustomCommandLocalFileList = LocalFileList;
  2330. FCustomCommandRemoteFileList = RemoteFileList;
  2331. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2332. if (Button != NULL)
  2333. {
  2334. FCustomCommandMenu->Items->Clear();
  2335. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2336. MenuPopup(FCustomCommandMenu, Button);
  2337. }
  2338. else
  2339. {
  2340. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2341. }
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2345. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2346. {
  2347. DebugAssert(FCapturedLog != NULL);
  2348. if ((OutputType == cotOutput) || (OutputType == cotError))
  2349. {
  2350. FCapturedLog->Add(AddedLine);
  2351. }
  2352. }
  2353. //---------------------------------------------------------------------------
  2354. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2355. TOperationSide Side)
  2356. {
  2357. return
  2358. (Side == osOther) &&
  2359. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2360. }
  2361. //---------------------------------------------------------------------------
  2362. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2363. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2364. {
  2365. TTBItemOptions O;
  2366. O = Item->Options;
  2367. TCustomDirView * DView = DirView(Side);
  2368. if ((DView->ItemFocused != NULL) &&
  2369. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2370. // when resolving links is disabled, default action is to enter the directory,
  2371. // no matter what DoubleClickAction is configured to
  2372. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2373. // Can only Edit files, but can Open/Copy even directories
  2374. ((DoubleClickAction != dcaEdit) ||
  2375. !DView->ItemIsDirectory(DView->ItemFocused)))
  2376. {
  2377. Item->Options = O << tboDefault;
  2378. }
  2379. else
  2380. {
  2381. Item->Options = O >> tboDefault;
  2382. }
  2383. }
  2384. //---------------------------------------------------------------------------
  2385. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2386. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2387. {
  2388. TCustomDirView * DView = DirView(Side);
  2389. TListItem * Item = DView->ItemFocused;
  2390. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2391. EnableFocusedOperation[Side])
  2392. {
  2393. TPoint ClientPoint;
  2394. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2395. TPoint(0, 0) : MousePos;
  2396. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2397. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2398. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2399. }
  2400. }
  2401. //---------------------------------------------------------------------------
  2402. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2403. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2404. {
  2405. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2406. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2407. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2408. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2409. Handled = true;
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2413. {
  2414. }
  2415. //---------------------------------------------------------------------------
  2416. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2417. {
  2418. DebugAssert(FErrorList == NULL);
  2419. if (WinConfiguration->ContinueOnError)
  2420. {
  2421. FErrorList = new TStringList();
  2422. Configuration->Usage->Inc(L"ContinuationsOnError");
  2423. }
  2424. NonVisualDataModule->StartBusy();
  2425. }
  2426. //---------------------------------------------------------------------------
  2427. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2428. {
  2429. NonVisualDataModule->EndBusy();
  2430. if (FErrorList)
  2431. {
  2432. HandleErrorList(FErrorList);
  2433. }
  2434. }
  2435. //---------------------------------------------------------------------------
  2436. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2437. const TCopyParamType & CopyParam)
  2438. {
  2439. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2440. {
  2441. Configuration->Usage->Inc(L"FileMaskUses");
  2442. }
  2443. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2444. {
  2445. Configuration->Usage->Inc(L"OperationMaskUses");
  2446. }
  2447. }
  2448. //---------------------------------------------------------------------------
  2449. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2450. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2451. {
  2452. DebugAssert(!IsLocalBrowserMode());
  2453. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2454. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2455. TTransferOperationParam DefaultParam;
  2456. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2457. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2458. switch (Param.Queue)
  2459. {
  2460. case asOn:
  2461. CopyParam.Queue = true;
  2462. break;
  2463. case asOff:
  2464. CopyParam.Queue = false;
  2465. break;
  2466. case asAuto:
  2467. default:
  2468. // keep default
  2469. break;
  2470. }
  2471. bool Result =
  2472. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2473. if (Result)
  2474. {
  2475. DebugAssert(Terminal);
  2476. bool SelectionRestored = false;
  2477. TCustomDirView * DView = NULL;
  2478. if (HasDirView[Side])
  2479. {
  2480. DView = DirView(Side);
  2481. DView->SaveSelection();
  2482. DView->SaveSelectedNames();
  2483. }
  2484. UpdateCopyParamCounters(CopyParam);
  2485. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2486. DebugAssert(FTransferResumeList == NULL);
  2487. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2488. FMoveToQueue = false;
  2489. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2490. try
  2491. {
  2492. TStrings * PermanentFileList;
  2493. std::unique_ptr<TStrings> PermanentFileListOwner;
  2494. try
  2495. {
  2496. if (Side == osLocal)
  2497. {
  2498. PermanentFileList = FileList;
  2499. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2500. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2501. if (Operation == foMove)
  2502. {
  2503. ReloadLocalDirectory();
  2504. if (DView != NULL)
  2505. {
  2506. DView->RestoreSelection();
  2507. }
  2508. SelectionRestored = true;
  2509. }
  2510. }
  2511. else
  2512. {
  2513. // Clone the file list as it may refer to current directory files,
  2514. // which get destroyed, when the source directory is reloaded after foMove operation.
  2515. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2516. // But for a hotfix, we are not going to do such a big change.
  2517. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2518. PermanentFileList = PermanentFileListOwner.get();
  2519. try
  2520. {
  2521. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2522. }
  2523. __finally
  2524. {
  2525. if (Operation == foMove)
  2526. {
  2527. if (DView != NULL)
  2528. {
  2529. DView->RestoreSelection();
  2530. }
  2531. SelectionRestored = true;
  2532. }
  2533. ReloadLocalDirectory(Param.TargetDirectory);
  2534. }
  2535. }
  2536. }
  2537. catch (EAbort &)
  2538. {
  2539. if (FMoveToQueue)
  2540. {
  2541. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2542. DebugAssert(CopyParam.TransferSkipList == NULL);
  2543. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2544. if (TransferResumeList->Count > 0)
  2545. {
  2546. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2547. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2548. }
  2549. CopyParam.TransferSkipList = TransferResumeList.release();
  2550. // not really needed, just to keep it consistent with TransferResumeList
  2551. FTransferResumeList = NULL;
  2552. FMoveToQueue = false;
  2553. Configuration->Usage->Inc("MovesToBackground");
  2554. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2555. ClearTransferSourceSelection(Direction);
  2556. }
  2557. throw;
  2558. }
  2559. }
  2560. __finally
  2561. {
  2562. if (!SelectionRestored && (DView != NULL))
  2563. {
  2564. DView->DiscardSavedSelection();
  2565. }
  2566. FTransferResumeList = NULL;
  2567. }
  2568. }
  2569. return Result;
  2570. }
  2571. //---------------------------------------------------------------------------
  2572. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2573. TOperationSide Side, TStrings * FileList, void * Param)
  2574. {
  2575. DebugAssert(FileList->Count);
  2576. // We deliberately do not toggle alternative flag (Param), but use OR,
  2577. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2578. // shortcut of CurrentDeleteAlternativeAction
  2579. bool Alternative =
  2580. bool(Param) || UseAlternativeFunction();
  2581. bool Recycle;
  2582. if (IsSideLocalBrowser(Side))
  2583. {
  2584. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2585. }
  2586. else
  2587. {
  2588. Recycle =
  2589. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2590. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2591. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2592. }
  2593. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2594. if (!Result)
  2595. {
  2596. UnicodeString Query;
  2597. if (FileList->Count == 1)
  2598. {
  2599. if (IsSideLocalBrowser(Side))
  2600. {
  2601. Query = ExtractFileName(FileList->Strings[0]);
  2602. }
  2603. else
  2604. {
  2605. Query = UnixExtractFileName(FileList->Strings[0]);
  2606. }
  2607. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2608. }
  2609. else
  2610. {
  2611. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2612. }
  2613. TMessageParams Params(mpNeverAskAgainCheck);
  2614. Params.ImageName = L"Delete file";
  2615. unsigned int Answer =
  2616. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2617. if (Answer == qaNeverAskAgain)
  2618. {
  2619. Result = true;
  2620. if (Recycle)
  2621. {
  2622. WinConfiguration->ConfirmRecycling = false;
  2623. }
  2624. else
  2625. {
  2626. WinConfiguration->ConfirmDeleting = false;
  2627. }
  2628. }
  2629. else
  2630. {
  2631. Result = (Answer == qaOK);
  2632. }
  2633. }
  2634. if (Result)
  2635. {
  2636. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2637. }
  2638. return Result;
  2639. }
  2640. //---------------------------------------------------------------------------
  2641. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2642. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2643. {
  2644. TAutoBatch AutoBatch(this);
  2645. bool Result;
  2646. if ((Operation == foCopy) || (Operation == foMove))
  2647. {
  2648. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2649. }
  2650. else if (Operation == foRename)
  2651. {
  2652. DebugAssert(DirView(Side)->ItemFocused);
  2653. DirView(Side)->ItemFocused->EditCaption();
  2654. Result = true;
  2655. }
  2656. else if (Operation == foDelete)
  2657. {
  2658. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2659. }
  2660. else if (Operation == foSetProperties)
  2661. {
  2662. DirView(osRemote)->SaveSelectedNames();
  2663. Result = SetProperties(Side, FileList);
  2664. }
  2665. else if (Operation == foCustomCommand)
  2666. {
  2667. DebugAssert(Param);
  2668. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2669. DirView(osRemote)->SaveSelectedNames();
  2670. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2671. CustomCommand(FileList, *Command, NULL);
  2672. Result = true;
  2673. }
  2674. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2675. {
  2676. DebugAssert(!IsSideLocalBrowser(Side));
  2677. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2678. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2679. }
  2680. else if (Operation == foLock)
  2681. {
  2682. DebugAssert(!IsSideLocalBrowser(Side));
  2683. LockFiles(FileList, true);
  2684. Result = true;
  2685. }
  2686. else if (Operation == foUnlock)
  2687. {
  2688. DebugAssert(!IsSideLocalBrowser(Side));
  2689. LockFiles(FileList, false);
  2690. Result = true;
  2691. }
  2692. else
  2693. {
  2694. DebugFail();
  2695. }
  2696. return Result;
  2697. }
  2698. //---------------------------------------------------------------------------
  2699. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2700. {
  2701. if (Side == osCurrent)
  2702. {
  2703. Side = FCurrentSide;
  2704. }
  2705. return Side;
  2706. }
  2707. //---------------------------------------------------------------------------
  2708. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2709. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2710. {
  2711. Side = GetSide(Side);
  2712. bool Result;
  2713. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2714. try
  2715. {
  2716. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2717. }
  2718. __finally
  2719. {
  2720. delete FileList;
  2721. }
  2722. return Result;
  2723. }
  2724. //---------------------------------------------------------------------------
  2725. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2726. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2727. bool NoConfirmation, void * Param)
  2728. {
  2729. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2730. {
  2731. if ((Operation == foCopy) || (Operation == foMove))
  2732. {
  2733. DebugAssert(!IsLocalBrowserMode());
  2734. if (GetSide(Side) == osLocal)
  2735. {
  2736. Configuration->Usage->Inc(L"UploadsCommand");
  2737. }
  2738. else
  2739. {
  2740. Configuration->Usage->Inc(L"DownloadsCommand");
  2741. }
  2742. }
  2743. }
  2744. }
  2745. //---------------------------------------------------------------------------
  2746. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2747. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2748. {
  2749. TTransferOperationParam Param;
  2750. if ((WinConfiguration->Interface != ifCommander) ||
  2751. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2752. {
  2753. Flags &= ~cocShortCutHint;
  2754. }
  2755. TCustomDirView * DView = DirView(Side);
  2756. Param.Options =
  2757. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2758. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2759. if (FLAGSET(Flags, cocQueue))
  2760. {
  2761. Param.Queue = asOn;
  2762. }
  2763. else if (FLAGSET(Flags, cocNonQueue))
  2764. {
  2765. Param.Queue = asOff;
  2766. }
  2767. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2768. }
  2769. //---------------------------------------------------------------------------
  2770. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2771. {
  2772. try
  2773. {
  2774. if (ErrorList->Count)
  2775. {
  2776. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2777. if (MessageDialog(Message, qtError,
  2778. qaOK | qaCancel, HELP_NONE) == qaOK)
  2779. {
  2780. unsigned int Answer;
  2781. int Index = 0;
  2782. do
  2783. {
  2784. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2785. TQueryButtonAlias Aliases[2];
  2786. Aliases[0].Button = qaYes;
  2787. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2788. Aliases[1].Button = qaNo;
  2789. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2790. TMessageParams Params;
  2791. Params.Aliases = Aliases;
  2792. Params.AliasesCount = LENOF(Aliases);
  2793. Answer = MoreMessageDialog(
  2794. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2795. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2796. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2797. qaOK, HELP_NONE, &Params);
  2798. if (Answer == qaNo)
  2799. {
  2800. Index++;
  2801. }
  2802. if (Answer == qaYes)
  2803. {
  2804. Index--;
  2805. }
  2806. }
  2807. while (Answer != qaOK);
  2808. }
  2809. }
  2810. }
  2811. __finally
  2812. {
  2813. TStrings * List = ErrorList;
  2814. ErrorList = NULL;
  2815. for (int i = 0; i < List->Count; i++)
  2816. {
  2817. delete List->Objects[i];
  2818. }
  2819. delete List;
  2820. }
  2821. }
  2822. //---------------------------------------------------------------------------
  2823. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2824. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2825. {
  2826. // needed for checking filemasks, as there's no directory object
  2827. // associated with the file object
  2828. File->FullFileName = FullFileName;
  2829. TFileMasks::TParams MaskParams;
  2830. MaskParams.Size = File->Size;
  2831. MaskParams.Modification = File->Modification;
  2832. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2833. }
  2834. //---------------------------------------------------------------------------
  2835. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2836. {
  2837. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2838. Side = GetSide(Side);
  2839. TCustomDirView * DView = DirView(Side);
  2840. TListItem * FocusedItem = DView->ItemFocused;
  2841. UnicodeString Name;
  2842. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2843. {
  2844. Name = DView->ItemFileName(FocusedItem);
  2845. }
  2846. else
  2847. {
  2848. Name = LoadStr(NEW_FILE);
  2849. }
  2850. UnicodeString Names = Name;
  2851. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2852. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2853. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2854. {
  2855. while (!Names.IsEmpty())
  2856. {
  2857. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2858. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2859. UnicodeString TargetFileName;
  2860. UnicodeString LocalFileName;
  2861. UnicodeString RootTempDir;
  2862. UnicodeString TempDir;
  2863. UnicodeString RemoteDirectory;
  2864. bool ExistingFile = false;
  2865. if (!IsSideLocalBrowser(Side))
  2866. {
  2867. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2868. TRemoteFile * File = NULL;
  2869. if (Terminal->FileExists(Name, &File) &&
  2870. !File->IsDirectory)
  2871. {
  2872. try
  2873. {
  2874. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2875. ExistingFile = true;
  2876. }
  2877. __finally
  2878. {
  2879. delete File;
  2880. }
  2881. }
  2882. if (!ExistingFile)
  2883. {
  2884. RemoteDirectory = UnixExtractFilePath(Name);
  2885. TemporaryDirectoryForRemoteFiles(
  2886. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2887. TargetFileName = UnixExtractFileName(Name);
  2888. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2889. LocalFileName = TempDir +
  2890. // We probably do not want to trim the VMS version here
  2891. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2892. }
  2893. }
  2894. else
  2895. {
  2896. if (ExtractFilePath(Name).IsEmpty())
  2897. {
  2898. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2899. }
  2900. else
  2901. {
  2902. LocalFileName = ExpandFileName(Name);
  2903. }
  2904. TargetFileName = ExtractFileName(Name);
  2905. }
  2906. if (!ExistingFile)
  2907. {
  2908. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2909. if (NewFile)
  2910. {
  2911. int File = FileCreate(ApiPath(LocalFileName));
  2912. if (File < 0)
  2913. {
  2914. if (!RootTempDir.IsEmpty())
  2915. {
  2916. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2917. }
  2918. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2919. }
  2920. else
  2921. {
  2922. FileClose(File);
  2923. }
  2924. }
  2925. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2926. const TEditorData * ExternalEditor = NULL;
  2927. TFileMasks::TParams MaskParams; // size not known
  2928. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2929. false, MaskParams);
  2930. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2931. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2932. }
  2933. }
  2934. }
  2935. }
  2936. //---------------------------------------------------------------------------
  2937. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2938. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2939. {
  2940. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2941. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2942. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2943. return
  2944. ((ExecuteFileBy == efInternalEditor)) ||
  2945. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2946. }
  2947. //---------------------------------------------------------------------------
  2948. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2949. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2950. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2951. UnicodeString RemoteDirectory, bool NewFile)
  2952. {
  2953. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2954. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2955. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2956. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2957. Side = GetSide(Side);
  2958. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2959. if (!IsSideLocalBrowser(Side))
  2960. {
  2961. Data->Terminal = Terminal;
  2962. Data->Queue = Queue;
  2963. Data->SessionData = CloneCurrentSessionData();
  2964. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2965. Data->RemoteDirectory = RemoteDirectory;
  2966. Data->SessionName = Terminal->SessionData->SessionName;
  2967. Data->LocalRootDirectory = LocalRootDirectory;
  2968. Data->OriginalFileName = OriginalFileName;
  2969. Data->Command = L""; // will be changed later for external editor
  2970. }
  2971. if (ExecuteFileBy == efInternalEditor)
  2972. {
  2973. if (!IsSideLocalBrowser(Side))
  2974. {
  2975. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  2976. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  2977. TForm * Editor;
  2978. try
  2979. {
  2980. TNotifyEvent OnFileChanged = NULL;
  2981. TNotifyEvent OnSaveAll = NULL;
  2982. TAnyModifiedEvent OnAnyModified = NULL;
  2983. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2984. if (Terminal->IsCapable[fcBackgroundTransfers])
  2985. {
  2986. OnFileChanged = FEditorManager->FileChanged;
  2987. OnSaveAll = SaveAllInternalEditors;
  2988. OnAnyModified = AnyInternalEditorModified;
  2989. }
  2990. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2991. FEditorManager->FileReload, FEditorManager->FileClosed,
  2992. OnSaveAll, OnAnyModified,
  2993. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2994. }
  2995. catch(...)
  2996. {
  2997. if (!LocalRootDirectory.IsEmpty())
  2998. {
  2999. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  3000. }
  3001. throw;
  3002. }
  3003. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3004. }
  3005. else
  3006. {
  3007. DebugAssert(!FStandaloneEditing);
  3008. TForm * Editor =
  3009. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3010. SaveAllInternalEditors, AnyInternalEditorModified,
  3011. L"", false, SessionColor, -1, NewFile);
  3012. FLocalEditors->Add(Editor);
  3013. }
  3014. }
  3015. else
  3016. {
  3017. HANDLE Process;
  3018. if (ExecuteFileBy == efExternalEditor)
  3019. {
  3020. UnicodeString Program, Params, Dir;
  3021. Data->Command = ExternalEditor->ExternalEditor;
  3022. ReformatFileNameCommand(Data->Command);
  3023. SplitCommand(Data->Command, Program, Params, Dir);
  3024. Params = ExpandFileNameCommand(Params, FileName);
  3025. Program = ExpandEnvironmentVariables(Program);
  3026. if (!ExecuteShell(Program, Params, Process))
  3027. {
  3028. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3029. }
  3030. }
  3031. else
  3032. {
  3033. DebugAssert(!IsSideLocalBrowser(Side));
  3034. if (!ExecuteShell(FileName, L"", Process))
  3035. {
  3036. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3037. }
  3038. }
  3039. if (IsSideLocalBrowser(Side) ||
  3040. ((ExecuteFileBy == efShell) &&
  3041. !WinConfiguration->Editor.SDIShellEditor) ||
  3042. ((ExecuteFileBy == efExternalEditor) &&
  3043. !ExternalEditor->SDIExternalEditor))
  3044. {
  3045. // no need for handle
  3046. if (Process != NULL)
  3047. {
  3048. DebugCheck(CloseHandle(Process));
  3049. }
  3050. Process = INVALID_HANDLE_VALUE;
  3051. }
  3052. else
  3053. {
  3054. if (Process == NULL)
  3055. {
  3056. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3057. }
  3058. }
  3059. if (!IsSideLocalBrowser(Side))
  3060. {
  3061. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3062. }
  3063. }
  3064. }
  3065. //---------------------------------------------------------------------------
  3066. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3067. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3068. void * /*Arg*/)
  3069. {
  3070. if (Token != NULL)
  3071. {
  3072. EditorFormFileSave(static_cast<TForm *>(Token));
  3073. }
  3074. }
  3075. //---------------------------------------------------------------------------
  3076. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3077. {
  3078. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3079. {
  3080. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3081. }
  3082. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3083. }
  3084. //---------------------------------------------------------------------------
  3085. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3086. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3087. void * Arg)
  3088. {
  3089. if ((Token != NULL) &&
  3090. IsEditorFormModified(static_cast<TForm *>(Token)))
  3091. {
  3092. *static_cast<bool *>(Arg) = true;
  3093. }
  3094. }
  3095. //---------------------------------------------------------------------------
  3096. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3097. TObject * /*Sender*/, bool & Modified)
  3098. {
  3099. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3100. {
  3101. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3102. {
  3103. Modified = true;
  3104. }
  3105. }
  3106. if (!Modified)
  3107. {
  3108. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3109. }
  3110. }
  3111. //---------------------------------------------------------------------------
  3112. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3113. {
  3114. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3115. }
  3116. //---------------------------------------------------------------------------
  3117. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3118. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3119. UnicodeString & Result, UnicodeString & RootDirectory)
  3120. {
  3121. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3122. {
  3123. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3124. Result = RootDirectory;
  3125. }
  3126. else
  3127. {
  3128. RootDirectory = L"";
  3129. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3130. Result = IncludeTrailingBackslash(Result);
  3131. }
  3132. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3133. {
  3134. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3135. }
  3136. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3137. {
  3138. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3139. {
  3140. RemoteDirectory.Delete(1, 1);
  3141. }
  3142. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3143. }
  3144. if (!ForceDirectories(ApiPath(Result)))
  3145. {
  3146. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3147. }
  3148. }
  3149. //---------------------------------------------------------------------------
  3150. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3151. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3152. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3153. {
  3154. DebugAssert(!IsLocalBrowserMode());
  3155. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3156. if (ForceText)
  3157. {
  3158. CopyParam.TransferMode = tmAscii;
  3159. }
  3160. TemporaryFileCopyParam(CopyParam);
  3161. if (AllFiles)
  3162. {
  3163. CopyParam.IncludeFileMask = TFileMasks();
  3164. }
  3165. if (TempDir.IsEmpty())
  3166. {
  3167. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3168. }
  3169. DebugAssert(!FAutoOperation);
  3170. FAutoOperation = AutoOperation;
  3171. Terminal->ExceptionOnFail = true;
  3172. try
  3173. {
  3174. try
  3175. {
  3176. // turn off confirmations, as for MDI editors we may possibly download
  3177. // the same file over
  3178. Terminal->CopyToLocal(
  3179. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3180. if (GetTargetNames)
  3181. {
  3182. for (int i = 0; i < FileList->Count; i++)
  3183. {
  3184. FileList->Strings[i] =
  3185. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3186. }
  3187. }
  3188. }
  3189. catch(...)
  3190. {
  3191. if (!RootTempDir.IsEmpty())
  3192. {
  3193. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3194. }
  3195. throw;
  3196. }
  3197. }
  3198. __finally
  3199. {
  3200. FAutoOperation = false;
  3201. Terminal->ExceptionOnFail = false;
  3202. }
  3203. }
  3204. //---------------------------------------------------------------------------
  3205. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3206. {
  3207. // Do not waste time checking for default editor list the next time,
  3208. // or testing if default editor is not notepad.
  3209. bool TryNextTime = false;
  3210. UnicodeString UsageState;
  3211. if (!WinConfiguration->EditorList->IsDefaultList())
  3212. {
  3213. UsageState = "H";
  3214. }
  3215. else
  3216. {
  3217. UnicodeString Executable;
  3218. UnicodeString ExecutableDescription;
  3219. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3220. {
  3221. UnicodeString Message =
  3222. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3223. unsigned int Answer =
  3224. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3225. if (Answer != qaOK)
  3226. {
  3227. UsageState = "R";
  3228. }
  3229. else
  3230. {
  3231. UsageState = "A";
  3232. TEditorData EditorData;
  3233. EditorData.Editor = edExternal;
  3234. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3235. EditorData.ExternalEditorOptionsAutodetect();
  3236. TEditorList EditorList;
  3237. EditorList = *WinConfiguration->EditorList;
  3238. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3239. WinConfiguration->EditorList = &EditorList;
  3240. }
  3241. }
  3242. }
  3243. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3244. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3245. }
  3246. //---------------------------------------------------------------------------
  3247. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3248. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3249. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3250. {
  3251. if (ExecuteFileBy == efDefaultEditor)
  3252. {
  3253. if (!WinConfiguration->OfferedEditorAutoConfig)
  3254. {
  3255. EditorAutoConfig();
  3256. }
  3257. const TEditorPreferences * Editor =
  3258. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3259. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3260. {
  3261. ExecuteFileBy = efInternalEditor;
  3262. ExternalEditor = NULL;
  3263. }
  3264. else if (Editor->Data->Editor == edOpen)
  3265. {
  3266. ExecuteFileBy = efShell;
  3267. ExternalEditor = NULL;
  3268. }
  3269. else
  3270. {
  3271. ExecuteFileBy = efExternalEditor;
  3272. ExternalEditor = Editor->Data;
  3273. }
  3274. }
  3275. }
  3276. //---------------------------------------------------------------------------
  3277. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3278. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3279. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3280. {
  3281. UnicodeString OriginalFileName;
  3282. UnicodeString LocalRootDirectory;
  3283. UnicodeString RemoteDirectory;
  3284. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3285. IsSideLocalBrowser(Side), MaskParams);
  3286. UnicodeString Counter;
  3287. UnicodeString LocalFileName;
  3288. bool Handled = false;
  3289. if (!IsSideLocalBrowser(Side))
  3290. {
  3291. // We need to trim VMS version here, so that we use name without version
  3292. // when uploading back to create a new version of the file
  3293. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3294. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3295. TObject * Token = NULL;
  3296. UnicodeString LocalDirectory;
  3297. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3298. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3299. LocalDirectory))
  3300. {
  3301. if (Token != NULL)
  3302. {
  3303. TForm * Form = dynamic_cast<TForm *>(Token);
  3304. if (Form->WindowState == wsMinimized)
  3305. {
  3306. ShowWindow(Form->Handle, SW_RESTORE);
  3307. }
  3308. else
  3309. {
  3310. Form->SetFocus();
  3311. }
  3312. Handled = true;
  3313. }
  3314. else
  3315. {
  3316. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3317. }
  3318. }
  3319. if (!Handled)
  3320. {
  3321. TStringList * FileList1 = new TStringList();
  3322. try
  3323. {
  3324. FileList1->AddObject(FullFileName, Object);
  3325. TemporarilyDownloadFiles(FileList1,
  3326. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3327. LocalRootDirectory, LocalDirectory, true, true, true);
  3328. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3329. }
  3330. __finally
  3331. {
  3332. delete FileList1;
  3333. }
  3334. switch (ExecuteFileBy)
  3335. {
  3336. case efShell:
  3337. Counter = "RemoteFilesExecuted";
  3338. break;
  3339. case efInternalEditor:
  3340. Counter = "RemoteFilesOpenedInInternalEditor";
  3341. break;
  3342. case efExternalEditor:
  3343. Counter = "RemoteFilesOpenedInExternalEditor";
  3344. break;
  3345. default:
  3346. DebugFail();
  3347. }
  3348. }
  3349. }
  3350. else
  3351. {
  3352. LocalFileName = FullFileName;
  3353. OriginalFileName = ExtractFileName(FullFileName);
  3354. switch (ExecuteFileBy)
  3355. {
  3356. case efShell:
  3357. Counter = "LocalFilesExecuted";
  3358. break;
  3359. case efInternalEditor:
  3360. Counter = "LocalFilesOpenedInInternalEditor";
  3361. break;
  3362. case efExternalEditor:
  3363. Counter = "LocalFilesOpenedInExternalEditor";
  3364. break;
  3365. default:
  3366. DebugFail();
  3367. }
  3368. }
  3369. if (!Handled)
  3370. {
  3371. Configuration->Usage->Inc(Counter);
  3372. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3373. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3374. }
  3375. }
  3376. //---------------------------------------------------------------------------
  3377. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3378. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3379. bool AllSelected, bool OnFocused)
  3380. {
  3381. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3382. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3383. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3384. Side = GetSide(Side);
  3385. TCustomDirView * DView = DirView(Side);
  3386. TStrings * FileList =
  3387. AllSelected ?
  3388. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3389. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3390. try
  3391. {
  3392. DebugAssert(AllSelected || (FileList->Count == 1));
  3393. for (int i = 0; i < FileList->Count; i++)
  3394. {
  3395. UnicodeString ListFileName = FileList->Strings[i];
  3396. UnicodeString FileNameOnly =
  3397. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3398. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3399. if (!DView->ItemIsDirectory(Item))
  3400. {
  3401. UnicodeString FullFileName;
  3402. if (!IsSideLocalBrowser(Side))
  3403. {
  3404. FullFileName = DirView(Side)->Path + ListFileName;
  3405. }
  3406. else
  3407. {
  3408. FullFileName = ListFileName;
  3409. }
  3410. TFileMasks::TParams MaskParams;
  3411. MaskParams.Size = DView->ItemFileSize(Item);
  3412. TDateTimePrecision Precision;
  3413. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3414. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3415. FileList->Objects[i], MaskParams);
  3416. }
  3417. }
  3418. }
  3419. __finally
  3420. {
  3421. delete FileList;
  3422. }
  3423. }
  3424. //---------------------------------------------------------------------------
  3425. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3426. {
  3427. CopyParam.FileNameCase = ncNoChange;
  3428. CopyParam.PreserveRights = false;
  3429. CopyParam.PreserveReadOnly = false;
  3430. CopyParam.ReplaceInvalidChars = true;
  3431. CopyParam.IncludeFileMask = TFileMasks();
  3432. CopyParam.NewerOnly = false;
  3433. CopyParam.FileMask = L"";
  3434. }
  3435. //---------------------------------------------------------------------------
  3436. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3437. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3438. {
  3439. TTerminalManager * Manager = TTerminalManager::Instance();
  3440. if (!IsActiveTerminal(Data->Terminal))
  3441. {
  3442. if (!NonVisualDataModule->Busy)
  3443. {
  3444. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3445. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3446. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3447. if (Data->Terminal == NULL)
  3448. {
  3449. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3450. if (SameSiteTerminal != NULL)
  3451. {
  3452. UnicodeString Message =
  3453. FMTLOAD(EDIT_SESSION_REATTACH,
  3454. (FileNameOnly, Data->SessionName, FileNameOnly));
  3455. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3456. {
  3457. Data->Terminal = Terminal;
  3458. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3459. Data->SessionName = Terminal->SessionData->SessionName;
  3460. // We might also overwrite session data
  3461. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3462. }
  3463. else
  3464. {
  3465. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3466. Abort();
  3467. }
  3468. }
  3469. }
  3470. // foreground session should reconnect itself
  3471. else if (Terminal != Data->Terminal)
  3472. {
  3473. UnicodeString Message =
  3474. MainInstructions(
  3475. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3476. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3477. {
  3478. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3479. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3480. }
  3481. else
  3482. {
  3483. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3484. Abort();
  3485. }
  3486. }
  3487. }
  3488. if (!IsActiveTerminal(Data->Terminal))
  3489. {
  3490. Configuration->Usage->Inc(L"EditInactiveSession");
  3491. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3492. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3493. (ExtractFileName(FileName), Data->SessionName)));
  3494. }
  3495. }
  3496. TStrings * FileList = new TStringList();
  3497. try
  3498. {
  3499. FileList->Add(FileName);
  3500. // consider using the same settings (preset) as when the file was downloaded
  3501. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3502. TemporaryFileCopyParam(CopyParam);
  3503. if (Data->ForceText)
  3504. {
  3505. CopyParam.TransferMode = tmAscii;
  3506. }
  3507. // so i do not need to worry if masking algorithm works in all cases
  3508. // ("" means "copy file name", no masking is actually done)
  3509. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3510. {
  3511. CopyParam.FileMask = L"";
  3512. }
  3513. else
  3514. {
  3515. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3516. }
  3517. DebugAssert(Data->Queue != NULL);
  3518. int Params = cpNoConfirmation | cpTemporary;
  3519. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3520. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3521. QueueItem->CompleteEvent = UploadCompleteEvent;
  3522. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3523. }
  3524. __finally
  3525. {
  3526. delete FileList;
  3527. }
  3528. }
  3529. //---------------------------------------------------------------------------
  3530. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3531. const UnicodeString FileName, const TEditedFileData * Data)
  3532. {
  3533. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3534. DebugAssert(!NonVisualDataModule->Busy);
  3535. if (!IsActiveTerminal(Data->Terminal))
  3536. {
  3537. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3538. (ExtractFileName(FileName), Data->SessionName)));
  3539. }
  3540. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3541. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3542. NonVisualDataModule->StartBusy();
  3543. try
  3544. {
  3545. std::unique_ptr<TRemoteFile> File;
  3546. UnicodeString RemoteFileName =
  3547. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3548. Terminal->ExceptionOnFail = true;
  3549. try
  3550. {
  3551. TRemoteFile * AFile = NULL;
  3552. Terminal->ReadFile(RemoteFileName, AFile);
  3553. File.reset(AFile);
  3554. if (!File->HaveFullFileName)
  3555. {
  3556. File->FullFileName = RemoteFileName;
  3557. }
  3558. }
  3559. __finally
  3560. {
  3561. Terminal->ExceptionOnFail = false;
  3562. }
  3563. std::unique_ptr<TStrings> FileList(new TStringList());
  3564. FileList->AddObject(RemoteFileName, File.get());
  3565. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3566. UnicodeString TempDir = ExtractFilePath(FileName);
  3567. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3568. TempDir, true, true, true);
  3569. // sanity check, the target file name should be still the same
  3570. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3571. }
  3572. __finally
  3573. {
  3574. NonVisualDataModule->EndBusy();
  3575. // it actually may not exist anymore...
  3576. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3577. }
  3578. }
  3579. //---------------------------------------------------------------------------
  3580. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3581. const TEditedFileData * Data, bool & KeepOpen)
  3582. {
  3583. // Command is set for external editors only (not for "shell" open).
  3584. if (!Data->Command.IsEmpty())
  3585. {
  3586. bool AnyFound = false;
  3587. bool AnyMDI = false;
  3588. bool AnyNonMDI = false;
  3589. bool AnyDetect = false;
  3590. TEditorList * EditorList = new TEditorList();
  3591. try
  3592. {
  3593. *EditorList = *WinConfiguration->EditorList;
  3594. for (int i = 0; i < EditorList->Count; i++)
  3595. {
  3596. const TEditorPreferences * Editor = EditorList->Editors[i];
  3597. if ((Editor->Data->Editor == edExternal) &&
  3598. (Editor->Data->ExternalEditor == Data->Command))
  3599. {
  3600. AnyFound = true;
  3601. if (Editor->Data->SDIExternalEditor)
  3602. {
  3603. AnyNonMDI = true;
  3604. if (Editor->Data->DetectMDIExternalEditor)
  3605. {
  3606. AnyDetect = true;
  3607. }
  3608. }
  3609. else
  3610. {
  3611. AnyMDI = true;
  3612. }
  3613. }
  3614. }
  3615. bool EnableMDI = false;
  3616. bool DisableDetect = false;
  3617. if (AnyMDI)
  3618. {
  3619. KeepOpen = true;
  3620. if (AnyNonMDI)
  3621. {
  3622. // there is at least one instance of the editor with MDI support enabled,
  3623. // and one with disabled, enable it for all instances
  3624. EnableMDI = true;
  3625. }
  3626. }
  3627. else if (AnyFound && !AnyDetect)
  3628. {
  3629. // at least once instance found but all have MDI autodetection disabled
  3630. // => close the file (default action)
  3631. }
  3632. else
  3633. {
  3634. // no instance of the editor has MDI support enabled
  3635. TMessageParams Params;
  3636. if (AnyFound)
  3637. {
  3638. // there is at least one instance of the editor
  3639. Params.Params |= mpNeverAskAgainCheck;
  3640. }
  3641. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3642. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3643. switch (Answer)
  3644. {
  3645. case qaNeverAskAgain:
  3646. DisableDetect = true;
  3647. break;
  3648. case qaNo:
  3649. EnableMDI = true;
  3650. KeepOpen = true;
  3651. break;
  3652. }
  3653. }
  3654. if (AnyFound && (EnableMDI || DisableDetect))
  3655. {
  3656. bool Changed = false;
  3657. for (int i = 0; i < EditorList->Count; i++)
  3658. {
  3659. const TEditorPreferences * Editor = EditorList->Editors[i];
  3660. if ((Editor->Data->Editor == edExternal) &&
  3661. (Editor->Data->ExternalEditor == Data->Command) &&
  3662. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3663. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3664. {
  3665. Changed = true;
  3666. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3667. if (EnableMDI)
  3668. {
  3669. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3670. }
  3671. if (DisableDetect)
  3672. {
  3673. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3674. }
  3675. EditorList->Change(i, UpdatedEditor);
  3676. }
  3677. }
  3678. if (Changed)
  3679. {
  3680. WinConfiguration->EditorList = EditorList;
  3681. }
  3682. }
  3683. }
  3684. __finally
  3685. {
  3686. delete EditorList;
  3687. }
  3688. }
  3689. else
  3690. {
  3691. // "open" case
  3692. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3693. qaOK, HELP_APP_EARLY_CLOSED);
  3694. }
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3698. {
  3699. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3700. }
  3701. //---------------------------------------------------------------------------
  3702. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3703. {
  3704. SideEnter(osRemote);
  3705. }
  3706. //---------------------------------------------------------------------------
  3707. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3708. {
  3709. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3710. SideEnter(osRemote);
  3711. }
  3712. //---------------------------------------------------------------------------
  3713. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3714. {
  3715. FCurrentSide = Side;
  3716. if (Visible)
  3717. {
  3718. UpdateControls();
  3719. }
  3720. }
  3721. //---------------------------------------------------------------------------
  3722. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3723. TStrings * FileList, bool Alternative)
  3724. {
  3725. TCustomDirView * DView = DirView(Side);
  3726. DView->SaveSelection();
  3727. DView->SaveSelectedNames();
  3728. DebugAssert(!FAlternativeDelete);
  3729. FAlternativeDelete = Alternative;
  3730. try
  3731. {
  3732. if (!IsSideLocalBrowser(Side))
  3733. {
  3734. DebugAssert(Terminal != NULL);
  3735. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3736. }
  3737. else
  3738. {
  3739. if (IsLocalBrowserMode())
  3740. {
  3741. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3742. }
  3743. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3744. FProgressSide = FCurrentSide;
  3745. try
  3746. {
  3747. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3748. }
  3749. __finally
  3750. {
  3751. ReloadLocalDirectory();
  3752. }
  3753. }
  3754. FAlternativeDelete = false;
  3755. }
  3756. catch(...)
  3757. {
  3758. FAlternativeDelete = false;
  3759. DView->DiscardSavedSelection();
  3760. throw;
  3761. }
  3762. DView->RestoreSelection();
  3763. }
  3764. //---------------------------------------------------------------------------
  3765. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3766. {
  3767. DebugAssert(Terminal);
  3768. DebugAssert(!IsLocalBrowserMode());
  3769. RemoteDirView->SaveSelection();
  3770. RemoteDirView->SaveSelectedNames();
  3771. try
  3772. {
  3773. if (Lock)
  3774. {
  3775. Terminal->LockFiles(FileList);
  3776. }
  3777. else
  3778. {
  3779. Terminal->UnlockFiles(FileList);
  3780. }
  3781. }
  3782. catch(...)
  3783. {
  3784. RemoteDirView->DiscardSavedSelection();
  3785. throw;
  3786. }
  3787. RemoteDirView->RestoreSelection();
  3788. }
  3789. //---------------------------------------------------------------------------
  3790. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3791. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3792. bool NoConfirmation, bool Move)
  3793. {
  3794. DebugAssert(Terminal != NULL);
  3795. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  3796. DebugAssert(!IsLocalBrowserMode());
  3797. // update Terminal->StateData->RemoteDirectory
  3798. UpdateSession(Terminal);
  3799. if (Session == NULL)
  3800. {
  3801. Session = Terminal;
  3802. }
  3803. if (Session == Terminal)
  3804. {
  3805. if (RemoteDriveView->DropTarget != NULL)
  3806. {
  3807. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3808. }
  3809. else if (RemoteDirView->DropTarget != NULL)
  3810. {
  3811. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3812. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3813. }
  3814. else
  3815. {
  3816. Target = RemoteDirView->Path;
  3817. }
  3818. }
  3819. else
  3820. {
  3821. Target = Session->StateData->RemoteDirectory;
  3822. }
  3823. Target = UnixIncludeTrailingBackslash(Target);
  3824. if (FileList->Count == 1)
  3825. {
  3826. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3827. }
  3828. else
  3829. {
  3830. FileMask = AnyMask;
  3831. }
  3832. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3833. bool Result = true;
  3834. if (!NoConfirmation)
  3835. {
  3836. bool Multi = (FileList->Count > 1);
  3837. if (Move)
  3838. {
  3839. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3840. }
  3841. else
  3842. {
  3843. std::unique_ptr<TStrings> Sessions(new TStringList);
  3844. std::unique_ptr<TStrings> Directories(new TStringList);
  3845. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  3846. for (int Index = 0; Index < SessionList->Count; Index++)
  3847. {
  3848. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3849. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  3850. {
  3851. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3852. Directories->Add(ASession->StateData->RemoteDirectory);
  3853. }
  3854. }
  3855. TDirectRemoteCopy AllowDirectCopy;
  3856. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3857. {
  3858. DebugAssert(DirectCopy);
  3859. AllowDirectCopy = drcAllow;
  3860. }
  3861. else if (Terminal->IsCapable[fcSecondaryShell])
  3862. {
  3863. DebugAssert(DirectCopy);
  3864. AllowDirectCopy = drcConfirmCommandSession;
  3865. }
  3866. else
  3867. {
  3868. DebugAssert(!DirectCopy);
  3869. AllowDirectCopy = drcDisallow;
  3870. }
  3871. void * ASession = Session;
  3872. Result = DoRemoteCopyDialog(
  3873. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal);
  3874. Session = static_cast<TManagedTerminal *>(ASession);
  3875. }
  3876. }
  3877. return Result;
  3878. }
  3879. //---------------------------------------------------------------------------
  3880. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3881. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3882. {
  3883. DebugAssert(!IsLocalBrowserMode());
  3884. bool DirectCopy;
  3885. UnicodeString Target, FileMask;
  3886. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3887. if (Result)
  3888. {
  3889. if (!Move && !DirectCopy)
  3890. {
  3891. Configuration->Usage->Inc("RemoteCopyTemp");
  3892. UnicodeString RootTempDir;
  3893. UnicodeString TempDir;
  3894. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3895. TStrings * TemporaryFilesList = new TStringList();
  3896. try
  3897. {
  3898. TMakeLocalFileListParams MakeFileListParam;
  3899. MakeFileListParam.FileList = TemporaryFilesList;
  3900. MakeFileListParam.FileTimes = NULL;
  3901. MakeFileListParam.IncludeDirs = true;
  3902. MakeFileListParam.Recursive = false;
  3903. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  3904. TTerminalManager::Instance()->ActiveSession = Session;
  3905. if (TemporaryFilesList->Count > 0)
  3906. {
  3907. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3908. CopyParam.FileMask = FileMask;
  3909. DebugAssert(!FAutoOperation);
  3910. FAutoOperation = true;
  3911. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3912. }
  3913. }
  3914. __finally
  3915. {
  3916. delete TemporaryFilesList;
  3917. FAutoOperation = false;
  3918. if (!RootTempDir.IsEmpty())
  3919. {
  3920. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3921. }
  3922. }
  3923. }
  3924. else
  3925. {
  3926. RemoteDirView->SaveSelection();
  3927. RemoteDirView->SaveSelectedNames();
  3928. try
  3929. {
  3930. if (Move)
  3931. {
  3932. Configuration->Usage->Inc("RemoteMove");
  3933. Terminal->MoveFiles(FileList, Target, FileMask);
  3934. }
  3935. else
  3936. {
  3937. Configuration->Usage->Inc("RemoteCopyDirect");
  3938. DebugAssert(DirectCopy);
  3939. DebugAssert(Session == Terminal);
  3940. if (Terminal->IsCapable[fcRemoteCopy] ||
  3941. Terminal->CommandSessionOpened ||
  3942. CommandSessionFallback())
  3943. {
  3944. Terminal->CopyFiles(FileList, Target, FileMask);
  3945. }
  3946. }
  3947. }
  3948. catch(...)
  3949. {
  3950. RemoteDirView->DiscardSavedSelection();
  3951. throw;
  3952. }
  3953. RemoteDirView->RestoreSelection();
  3954. }
  3955. }
  3956. return Result;
  3957. }
  3958. //---------------------------------------------------------------------------
  3959. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3960. const UnicodeString & Path, TRemoteProperties & Properties)
  3961. {
  3962. DebugAssert(!IsLocalBrowserMode());
  3963. Properties.Valid = Properties.Valid << vpEncrypt;
  3964. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3965. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3966. }
  3967. //---------------------------------------------------------------------------
  3968. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3969. {
  3970. Side = GetSide(Side);
  3971. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3972. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3973. UnicodeString Name = LoadStr(NEW_FOLDER);
  3974. int AllowedChanges =
  3975. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3976. bool SaveSettings = false;
  3977. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3978. {
  3979. TWindowLock Lock(this);
  3980. if (!IsSideLocalBrowser(Side))
  3981. {
  3982. if (SaveSettings)
  3983. {
  3984. GUIConfiguration->NewDirectoryProperties = Properties;
  3985. }
  3986. CreateRemoteDirectory(Name, Properties);
  3987. }
  3988. else
  3989. {
  3990. DirView(Side)->CreateDirectory(Name);
  3991. }
  3992. }
  3993. }
  3994. //---------------------------------------------------------------------------
  3995. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3996. {
  3997. TWindowLock Lock(this);
  3998. DirView(Side)->ExecuteHomeDirectory();
  3999. }
  4000. //---------------------------------------------------------------------------
  4001. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4002. {
  4003. DoOpenDirectoryDialog(odBrowse, Side);
  4004. }
  4005. //---------------------------------------------------------------------------
  4006. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4007. {
  4008. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4009. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4010. bool Result = !Path.IsEmpty();
  4011. if (Result)
  4012. {
  4013. // While we might get here when the session is closed (from location profiles),
  4014. // it's not a problem as the Path setter is noop then
  4015. DirView(Side)->Path = Path;
  4016. }
  4017. return Result;
  4018. }
  4019. //---------------------------------------------------------------------------
  4020. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4021. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4022. bool & Close)
  4023. {
  4024. // terminal can be already closed (e.g. dropped connection)
  4025. if (Terminal != NULL)
  4026. {
  4027. try
  4028. {
  4029. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4030. }
  4031. catch(...)
  4032. {
  4033. if (!Terminal->Active)
  4034. {
  4035. Close = true;
  4036. }
  4037. throw;
  4038. }
  4039. }
  4040. }
  4041. //---------------------------------------------------------------------------
  4042. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4043. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4044. bool & Close)
  4045. {
  4046. // terminal can be already closed (e.g. dropped connection)
  4047. if (Terminal != NULL)
  4048. {
  4049. Configuration->Usage->Inc(L"ChecksumCalculated");
  4050. try
  4051. {
  4052. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4053. }
  4054. catch(...)
  4055. {
  4056. if (!Terminal->Active)
  4057. {
  4058. Close = true;
  4059. }
  4060. throw;
  4061. }
  4062. }
  4063. }
  4064. //---------------------------------------------------------------------------
  4065. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4066. {
  4067. bool Result;
  4068. if (!IsSideLocalBrowser(Side))
  4069. {
  4070. TRemoteTokenList * GroupList = NULL;
  4071. TRemoteTokenList * UserList = NULL;
  4072. try
  4073. {
  4074. TRemoteProperties CurrentProperties;
  4075. if (Terminal->LoadFilesProperties(FileList))
  4076. {
  4077. RemoteDirView->Invalidate();
  4078. }
  4079. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4080. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4081. if (CapableGroupChanging || CapableOwnerChanging)
  4082. {
  4083. if (CapableGroupChanging)
  4084. {
  4085. GroupList = Terminal->Groups->Duplicate();
  4086. }
  4087. if (CapableOwnerChanging)
  4088. {
  4089. UserList = Terminal->Users->Duplicate();
  4090. }
  4091. TRemoteDirectory * Files = Terminal->Files;
  4092. int Count = Files->Count;
  4093. if (Count > 100)
  4094. {
  4095. Count = 100;
  4096. }
  4097. for (int Index = 0; Index < Count; Index++)
  4098. {
  4099. TRemoteFile * File = Files->Files[Index];
  4100. if (CapableGroupChanging)
  4101. {
  4102. GroupList->AddUnique(File->Group);
  4103. }
  4104. if (CapableOwnerChanging)
  4105. {
  4106. UserList->AddUnique(File->Owner);
  4107. }
  4108. }
  4109. // if we haven't collected tokens for all files in current directory,
  4110. // make sure we collect them at least for all selected files.
  4111. // (note that so far the files in FileList has to be from current direcotry)
  4112. if (Count < Files->Count)
  4113. {
  4114. for (int Index = 0; Index < FileList->Count; Index++)
  4115. {
  4116. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4117. if (CapableGroupChanging)
  4118. {
  4119. GroupList->AddUnique(File->Group);
  4120. }
  4121. if (CapableOwnerChanging)
  4122. {
  4123. UserList->AddUnique(File->Owner);
  4124. }
  4125. }
  4126. }
  4127. }
  4128. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4129. int Flags = 0;
  4130. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4131. if (CapableOwnerChanging) Flags |= cpOwner;
  4132. if (CapableGroupChanging) Flags |= cpGroup;
  4133. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4134. if (Terminal->IsCapable[fcCalculatingChecksum])
  4135. {
  4136. CalculateChecksumEvent = CalculateChecksum;
  4137. }
  4138. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4139. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4140. TRemoteProperties NewProperties = CurrentProperties;
  4141. Result =
  4142. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4143. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4144. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4145. CalculateSize, CalculateChecksumEvent);
  4146. if (Result)
  4147. {
  4148. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4149. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4150. }
  4151. }
  4152. __finally
  4153. {
  4154. delete GroupList;
  4155. delete UserList;
  4156. }
  4157. }
  4158. else
  4159. {
  4160. DirView(Side)->DisplayPropertiesMenu();
  4161. Result = true;
  4162. }
  4163. return Result;
  4164. }
  4165. //---------------------------------------------------------------------------
  4166. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4167. {
  4168. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4169. {
  4170. FIgnoreNextDialogChar = Key;
  4171. }
  4172. Key = 0;
  4173. }
  4174. //---------------------------------------------------------------------------
  4175. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4176. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4177. {
  4178. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4179. if (Command != NULL)
  4180. {
  4181. KeyProcessed(Key, Shift);
  4182. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4183. {
  4184. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4185. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4186. false, false, const_cast<TCustomCommandType *>(Command));
  4187. }
  4188. }
  4189. }
  4190. //---------------------------------------------------------------------------
  4191. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4192. {
  4193. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4194. {
  4195. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4196. }
  4197. if (!DirView(osCurrent)->IsEditing())
  4198. {
  4199. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4200. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4201. {
  4202. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4203. // But so far it's not a problem, as it does what we want.
  4204. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4205. if (((Action->ShortCut == KeyShortCut) ||
  4206. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4207. AllowedAction(Action, aaShortCut))
  4208. {
  4209. // Has to be called before the action as the dialog char is already in queue.
  4210. // So when the action consumes message queue, we already need to have the
  4211. // FIgnoreNextDialogChar set
  4212. KeyProcessed(Key, Shift);
  4213. // Reset reference to previous component (when menu/toolbar was clicked).
  4214. // Needed to detect that action was invoked by keyboard shortcut
  4215. // in TNonVisualDataModule::ExplorerActionsExecute
  4216. Action->ActionComponent = NULL;
  4217. Action->Execute();
  4218. return;
  4219. }
  4220. }
  4221. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4222. {
  4223. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4224. {
  4225. KeyProcessed(Key, Shift);
  4226. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4227. return;
  4228. }
  4229. }
  4230. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4231. {
  4232. KeyProcessed(Key, Shift);
  4233. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4234. }
  4235. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4236. if (IsCustomShortCut(CustomShortCut))
  4237. {
  4238. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4239. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4240. if (WinConfiguration->SharedBookmarks != NULL)
  4241. {
  4242. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4243. if ((Bookmark != NULL) &&
  4244. OpenBookmark(FCurrentSide, Bookmark))
  4245. {
  4246. KeyProcessed(Key, Shift);
  4247. }
  4248. }
  4249. }
  4250. }
  4251. TForm::KeyDown(Key, Shift);
  4252. }
  4253. //---------------------------------------------------------------------------
  4254. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4255. {
  4256. bool OpenedTerminal = false;
  4257. UnicodeString ProtocolName;
  4258. UnicodeString ProtocolNameHint;
  4259. UnicodeString SecurityProtocolName;
  4260. UnicodeString DurationHint;
  4261. // See the comment in TScpCommanderForm::UpdateControls()
  4262. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4263. if (ActiveTerminal != NULL)
  4264. {
  4265. // Active is not enough here
  4266. if (ActiveTerminal->Status == ssOpened)
  4267. {
  4268. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4269. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4270. if (FileSystemInfo.ProtocolName.IsEmpty())
  4271. {
  4272. ProtocolName = SessionInfo.ProtocolName;
  4273. }
  4274. else
  4275. {
  4276. ProtocolName = FileSystemInfo.ProtocolName;
  4277. }
  4278. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4279. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4280. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4281. OpenedTerminal = true;
  4282. }
  4283. else if (ActiveTerminal->Status > ssClosed)
  4284. {
  4285. ProtocolName = LoadStr(STATUS_CONNECTING);
  4286. }
  4287. else
  4288. {
  4289. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4290. }
  4291. }
  4292. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4293. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4294. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4295. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4296. if (ProtocolStatusPanel->Caption != ProtocolName)
  4297. {
  4298. ProtocolStatusPanel->Caption = ProtocolName;
  4299. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4300. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4301. }
  4302. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4303. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4304. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4305. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4306. SecurityStatusPanel->Enabled = SecurityEnabled;
  4307. UnicodeString SecurityProtocolHint;
  4308. if (SecurityEnabled)
  4309. {
  4310. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4311. }
  4312. else
  4313. {
  4314. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4315. }
  4316. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4317. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4318. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4319. DurationStatusPanel->Hint = DurationHint;
  4320. UpdateStatusBar();
  4321. }
  4322. //---------------------------------------------------------------------------
  4323. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4324. {
  4325. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4326. DebugAssert(SessionStatusBar != NULL);
  4327. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4328. if (!FNote.IsEmpty())
  4329. {
  4330. NoteStatusPanel->Caption = FNote;
  4331. }
  4332. else
  4333. {
  4334. UpdateStatusPanelText(NoteStatusPanel);
  4335. }
  4336. NoteStatusPanel->Hint = FNoteHints;
  4337. UnicodeString LoginTime;
  4338. // See the comment in TScpCommanderForm::UpdateControls()
  4339. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4340. // Active is not enough here
  4341. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4342. {
  4343. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4344. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4345. }
  4346. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4347. DurationStatusPanel->Caption = LoginTime;
  4348. }
  4349. //---------------------------------------------------------------------------
  4350. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4351. {
  4352. Panel->Caption = L"";
  4353. }
  4354. //---------------------------------------------------------------------------
  4355. void __fastcall TCustomScpExplorerForm::Idle()
  4356. {
  4357. if (FShowing || FStandaloneEditing)
  4358. {
  4359. FEditorManager->Check();
  4360. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4361. // that needs to know if queue view is visible (and it may be closed after queue update)
  4362. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4363. }
  4364. if (FShowing)
  4365. {
  4366. if (!NonVisualDataModule->Busy &&
  4367. // Menu is opened or drag&drop is going on
  4368. (Mouse->Capture == NULL))
  4369. {
  4370. if (FRefreshRemoteDirectory)
  4371. {
  4372. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4373. {
  4374. Terminal->RefreshDirectory();
  4375. }
  4376. FRefreshRemoteDirectory = false;
  4377. }
  4378. if (FRefreshLocalDirectory)
  4379. {
  4380. ReloadLocalDirectory();
  4381. FRefreshLocalDirectory = false;
  4382. }
  4383. if (WinConfiguration->RefreshRemotePanel)
  4384. {
  4385. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4386. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4387. {
  4388. RemoteDirView->ReloadDirectory();
  4389. }
  4390. }
  4391. }
  4392. }
  4393. if (FShowing || FStandaloneEditing)
  4394. {
  4395. if (FQueueStatusInvalidated)
  4396. {
  4397. UpdateQueueStatus(false);
  4398. }
  4399. RefreshQueueItems();
  4400. }
  4401. if (FShowing)
  4402. {
  4403. UpdateStatusBar();
  4404. }
  4405. FIgnoreNextDialogChar = 0;
  4406. }
  4407. //---------------------------------------------------------------------------
  4408. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4409. {
  4410. try
  4411. {
  4412. FUserActionTimer->Enabled = false;
  4413. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4414. {
  4415. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4416. {
  4417. FPendingQueueActionItem->ProcessUserAction();
  4418. }
  4419. }
  4420. }
  4421. __finally
  4422. {
  4423. FPendingQueueActionItem = NULL;
  4424. }
  4425. }
  4426. //---------------------------------------------------------------------------
  4427. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4428. {
  4429. if (WinConfiguration->MinimizeToTray)
  4430. {
  4431. UpdateTrayIcon();
  4432. FTrayIcon->Visible = true;
  4433. if (Visible)
  4434. {
  4435. ShowWindow(Handle, SW_HIDE);
  4436. }
  4437. }
  4438. }
  4439. //---------------------------------------------------------------------------
  4440. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4441. {
  4442. // WORKAROUND
  4443. // When restoring maximized window from minimization,
  4444. // rarely some controls do not align properly.
  4445. // Two instances seen (both for Commander):
  4446. // - When restoring, window is temporarily narrower (not maximized),
  4447. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4448. // Once maximized already, top dock shinks back, but the session PageControl,
  4449. // do not align up, leaving space between TopDock and PageControl.
  4450. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4451. for (int Index = 0; Index < ControlCount; Index++)
  4452. {
  4453. RealignControl(Controls[Index]);
  4454. }
  4455. if (FTrayIcon->Visible)
  4456. {
  4457. FTrayIcon->Visible = false;
  4458. if (Visible)
  4459. {
  4460. ShowWindow(Handle, SW_SHOW);
  4461. }
  4462. }
  4463. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4464. {
  4465. FNeedSession = false;
  4466. NonVisualDataModule->StartBusy();
  4467. try
  4468. {
  4469. NeedSession(true);
  4470. }
  4471. __finally
  4472. {
  4473. NonVisualDataModule->EndBusy();
  4474. }
  4475. }
  4476. }
  4477. //---------------------------------------------------------------------------
  4478. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4479. {
  4480. FTrayIcon->Hint = GetMainForm()->Caption;
  4481. }
  4482. //---------------------------------------------------------------------------
  4483. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4484. {
  4485. UpdateTrayIcon();
  4486. }
  4487. //---------------------------------------------------------------------------
  4488. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4489. {
  4490. // workaround
  4491. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4492. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4493. // But WM_ACTIVATEAPP message can be received even when
  4494. // the main window is minimized to the tray and internal editor window is focused
  4495. // (after another application was previously active)
  4496. if (::IsIconic(Handle))
  4497. {
  4498. if (!IsAppIconic())
  4499. {
  4500. SetAppIconic(true);
  4501. }
  4502. }
  4503. ::ApplicationRestore();
  4504. Application->BringToFront();
  4505. }
  4506. //---------------------------------------------------------------------------
  4507. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4508. {
  4509. RestoreApp();
  4510. }
  4511. //---------------------------------------------------------------------------
  4512. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4513. {
  4514. if (OpenInNewWindow())
  4515. {
  4516. ExecuteNewInstance(SessionUrl);
  4517. }
  4518. else
  4519. {
  4520. TTerminalManager::Instance()->NewSession(SessionUrl);
  4521. }
  4522. }
  4523. //---------------------------------------------------------------------------
  4524. void TCustomScpExplorerForm::NewTab(TOperationSide)
  4525. {
  4526. NewSession();
  4527. }
  4528. //---------------------------------------------------------------------------
  4529. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4530. {
  4531. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4532. StoredSessions->NewSession(SessionName, SessionData);
  4533. // modified only, explicit
  4534. StoredSessions->Save(false, true);
  4535. // encode session name because of slashes in hierarchical sessions
  4536. return EncodeUrlString(SessionName);
  4537. }
  4538. //---------------------------------------------------------------------------
  4539. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4540. {
  4541. // current working directories become defaults here, what is not right
  4542. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4543. return SaveHiddenDuplicateSession(SessionData.get());
  4544. }
  4545. //---------------------------------------------------------------------------
  4546. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4547. {
  4548. if (OpenInNewWindow())
  4549. {
  4550. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4551. }
  4552. else
  4553. {
  4554. // current working directories become defaults here, what is not right
  4555. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4556. TTerminalManager * Manager = TTerminalManager::Instance();
  4557. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  4558. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  4559. // We definitelly want these
  4560. ASession->Disconnected = ManagedSession->Disconnected;
  4561. // Not sure about these two
  4562. ASession->Permanent = ManagedSession->Permanent;
  4563. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  4564. Manager->ActiveSession = ASession;
  4565. }
  4566. }
  4567. //---------------------------------------------------------------------------
  4568. void __fastcall TCustomScpExplorerForm::RenameSession()
  4569. {
  4570. UnicodeString Name = ManagedSession->SessionData->SessionName;
  4571. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME) &&
  4572. // When submitting the default name, do not fix it
  4573. (Name != ManagedSession->SessionData->SessionName))
  4574. {
  4575. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4576. TSessionData::ValidateName(Name);
  4577. // This is inconsistent with how color (for example) is handled.
  4578. ManagedSession->SessionData->Name = Name;
  4579. UpdateControls();
  4580. // Add/Remove distinguishing paths from sessions of the same name.
  4581. SessionListChanged();
  4582. }
  4583. }
  4584. //---------------------------------------------------------------------------
  4585. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4586. {
  4587. DebugAssert(Queue != NULL);
  4588. bool Result = Queue->IsEmpty;
  4589. if (!Result)
  4590. {
  4591. SetFocus();
  4592. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4593. }
  4594. return Result;
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4598. {
  4599. return CanCloseQueue(FQueue);
  4600. }
  4601. //---------------------------------------------------------------------------
  4602. void __fastcall TCustomScpExplorerForm::CloseSession()
  4603. {
  4604. if (CanCloseQueue())
  4605. {
  4606. TTerminalManager::Instance()->FreeActiveTerminal();
  4607. }
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4611. {
  4612. if (CanCloseQueue())
  4613. {
  4614. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4615. }
  4616. }
  4617. //---------------------------------------------------------------------------
  4618. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4619. {
  4620. DetachTerminal(Terminal);
  4621. RemoteDirView->Terminal = Terminal;
  4622. UpdateRemotePathComboBox(false);
  4623. InitStatusBar();
  4624. UpdateControls();
  4625. }
  4626. //---------------------------------------------------------------------------
  4627. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4628. {
  4629. InitStatusBar();
  4630. }
  4631. //---------------------------------------------------------------------------
  4632. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4633. {
  4634. if (DebugAlwaysTrue(!Terminal->Active))
  4635. {
  4636. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4637. }
  4638. }
  4639. //---------------------------------------------------------------------------
  4640. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4641. {
  4642. if (OpenInNewWindow())
  4643. {
  4644. // encode session name because of slashes in hierarchical sessions
  4645. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4646. }
  4647. else
  4648. {
  4649. TTerminalManager * Manager = TTerminalManager::Instance();
  4650. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4651. Manager->ActiveSession = Terminal;
  4652. }
  4653. }
  4654. //---------------------------------------------------------------------------
  4655. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4656. {
  4657. TTerminalManager * Manager = TTerminalManager::Instance();
  4658. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4659. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4660. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  4661. // FirstSession can be null, if some of the
  4662. if (!ConnectFirstTerminal && (FirstSession != NULL))
  4663. {
  4664. FirstSession->Disconnected = true;
  4665. FirstSession->DisconnectedTemporarily = true;
  4666. }
  4667. Manager->ActiveSession = FirstSession;
  4668. }
  4669. //---------------------------------------------------------------------------
  4670. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4671. {
  4672. if (OpenInNewWindow())
  4673. {
  4674. ExecuteNewInstance(Name);
  4675. }
  4676. else
  4677. {
  4678. DoOpenFolderOrWorkspace(Name, true);
  4679. }
  4680. }
  4681. //---------------------------------------------------------------------------
  4682. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4683. bool &CanClose)
  4684. {
  4685. // See the comment in CloseApp()
  4686. if (NonVisualDataModule->Busy)
  4687. {
  4688. CanClose = false;
  4689. }
  4690. else
  4691. {
  4692. TTerminalManager * Manager = TTerminalManager::Instance();
  4693. int ActiveSessions = 0;
  4694. for (int Index = 0; Index < Manager->Count; Index++)
  4695. {
  4696. if (Manager->Sessions[Index]->Active)
  4697. {
  4698. ActiveSessions++;
  4699. }
  4700. }
  4701. // Confirm, when there's at least one active remote session or
  4702. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  4703. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  4704. WinConfiguration->ConfirmClosingSession)
  4705. {
  4706. unsigned int Result;
  4707. TMessageParams Params(mpNeverAskAgainCheck);
  4708. UnicodeString Message;
  4709. int Answers = qaOK | qaCancel;
  4710. // The current session is the only active session
  4711. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4712. {
  4713. if (!WinConfiguration->AutoSaveWorkspace)
  4714. {
  4715. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4716. }
  4717. else
  4718. {
  4719. Message = LoadStr(CLOSE_SESSION);
  4720. }
  4721. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4722. }
  4723. // Multiple active sessions or one active session, but it's not the current one
  4724. else if (ActiveSessions > 0)
  4725. {
  4726. if (!WinConfiguration->AutoSaveWorkspace)
  4727. {
  4728. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4729. }
  4730. else
  4731. {
  4732. Message = LoadStr(CLOSE_SESSIONS);
  4733. }
  4734. }
  4735. // Multiple tabs, but all are intactive or local, and saving of worspace is not enabled
  4736. else
  4737. {
  4738. DebugAlwaysTrue(Manager->Count > 1);
  4739. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  4740. Message = LoadStr(CLOSE_WORKSPACE);
  4741. }
  4742. UnicodeString Note;
  4743. if (WinConfiguration->AutoSaveWorkspace)
  4744. {
  4745. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4746. }
  4747. else
  4748. {
  4749. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4750. Answers = qaYes | qaNo | qaCancel;
  4751. }
  4752. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4753. SetFocus();
  4754. Result = MessageDialog(Message, qtConfirmation,
  4755. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4756. if (Result == qaNeverAskAgain)
  4757. {
  4758. WinConfiguration->ConfirmClosingSession = false;
  4759. }
  4760. if (Result == qaNo)
  4761. {
  4762. CanClose = SaveWorkspace(true);
  4763. // note that the workspace will be saved redundatly again from FormClose
  4764. }
  4765. else
  4766. {
  4767. CanClose =
  4768. (Result == qaOK) ||
  4769. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4770. (Result == qaNeverAskAgain);
  4771. }
  4772. }
  4773. if (CanClose && HasActiveTerminal())
  4774. {
  4775. CanClose = CanCloseQueue();
  4776. }
  4777. }
  4778. if (CanClose)
  4779. {
  4780. CanClose =
  4781. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4782. FEditorManager->CloseExternalFilesWithoutProcess();
  4783. if (CanClose)
  4784. {
  4785. while (CanClose && (FLocalEditors->Count > 0))
  4786. {
  4787. int PrevCount = FLocalEditors->Count;
  4788. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4789. CanClose = (FLocalEditors->Count < PrevCount);
  4790. }
  4791. if (CanClose)
  4792. {
  4793. CanClose = FEditorManager->Empty(true);
  4794. if (!CanClose)
  4795. {
  4796. SetFocus();
  4797. CanClose =
  4798. (MessageDialog(
  4799. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4800. }
  4801. }
  4802. }
  4803. }
  4804. }
  4805. //---------------------------------------------------------------------------
  4806. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4807. {
  4808. TForm * Form = dynamic_cast<TForm *>(Sender);
  4809. DebugAssert(Form != NULL);
  4810. Form->Close();
  4811. }
  4812. //---------------------------------------------------------------------------
  4813. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4814. {
  4815. TForm * Form = dynamic_cast<TForm *>(Sender);
  4816. delete Form;
  4817. }
  4818. //---------------------------------------------------------------------------
  4819. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4820. {
  4821. while (FLocalEditors->Count > 0)
  4822. {
  4823. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4824. }
  4825. }
  4826. //---------------------------------------------------------------------------
  4827. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4828. TObject *Sender)
  4829. {
  4830. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4831. try
  4832. {
  4833. SetProperties(osRemote, FileList);
  4834. }
  4835. __finally
  4836. {
  4837. delete FileList;
  4838. }
  4839. }
  4840. //---------------------------------------------------------------------------
  4841. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4842. {
  4843. if (value)
  4844. {
  4845. if (Component == fcCustomCommandsBand)
  4846. {
  4847. UpdateCustomCommandsToolbar();
  4848. }
  4849. if (Component == fcQueueFileList)
  4850. {
  4851. DebugAssert(!QueueFileListSplitter->Visible);
  4852. AdjustQueueLayout();
  4853. UpdateQueueFileList();
  4854. }
  4855. }
  4856. }
  4857. //---------------------------------------------------------------------------
  4858. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4859. {
  4860. int MinHeightLimit =
  4861. GetStaticQueuePanelComponentsHeight() +
  4862. QueueFileListSplitter->Height +
  4863. QueueFileList->Height +
  4864. GetMinQueueViewHeight();
  4865. if (QueuePanel->ClientHeight < MinHeightLimit)
  4866. {
  4867. QueuePanel->ClientHeight = MinHeightLimit;
  4868. }
  4869. }
  4870. //---------------------------------------------------------------------------
  4871. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4872. {
  4873. TControl * Control = GetComponent(Component);
  4874. DebugAssert(Control);
  4875. bool Changed = (Control->Visible != value);
  4876. if (Changed)
  4877. {
  4878. ComponentShowing(Component, value);
  4879. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4880. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4881. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4882. if (value)
  4883. {
  4884. int RemainingHeight = Control->Parent->ClientHeight;
  4885. int RemainingWidth = Control->Parent->ClientWidth;
  4886. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4887. {
  4888. TControl * ChildControl = Control->Parent->Controls[i];
  4889. if (ChildControl->Visible)
  4890. {
  4891. switch (ChildControl->Align)
  4892. {
  4893. case alTop:
  4894. case alBottom:
  4895. RemainingHeight -= ChildControl->Height;
  4896. break;
  4897. case alLeft:
  4898. case alRight:
  4899. RemainingWidth -= ChildControl->Width;
  4900. break;
  4901. }
  4902. }
  4903. }
  4904. int Reserve = ScaleByTextHeight(this, 32);
  4905. // queue in explorer, trees in commander
  4906. if (Control->Height > RemainingHeight - Reserve)
  4907. {
  4908. Control->Height = RemainingHeight / 2;
  4909. }
  4910. if (Control->Width > RemainingWidth - Reserve)
  4911. {
  4912. Control->Width = RemainingWidth / 2;
  4913. }
  4914. }
  4915. Control->Visible = value;
  4916. if (WasFocused && Visible)
  4917. {
  4918. DirView(osCurrent)->SetFocus();
  4919. }
  4920. FixControlsPlacement();
  4921. }
  4922. }
  4923. //---------------------------------------------------------------------------
  4924. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4925. {
  4926. TControl * Control = GetComponent(Component);
  4927. if (Control == NULL)
  4928. {
  4929. return false;
  4930. }
  4931. else
  4932. {
  4933. return Control->Visible;
  4934. }
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4938. {
  4939. bool Result;
  4940. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4941. {
  4942. Result = !IsUWP();
  4943. }
  4944. else
  4945. {
  4946. Result = true;
  4947. }
  4948. return Result;
  4949. }
  4950. //---------------------------------------------------------------------------
  4951. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4952. {
  4953. if (DirView->ItemFocused != NULL)
  4954. {
  4955. DirView->ItemFocused->MakeVisible(false);
  4956. }
  4957. }
  4958. //---------------------------------------------------------------------------
  4959. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4960. {
  4961. MakeFocusedItemVisible(RemoteDirView);
  4962. QueueSplitter->Visible = QueuePanel->Visible;
  4963. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4964. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4965. TControl * QueueControlsOrder[] =
  4966. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4967. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4968. }
  4969. //---------------------------------------------------------------------------
  4970. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4971. {
  4972. switch (Component) {
  4973. case fcStatusBar: return RemoteStatusBar;
  4974. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4975. case fcQueueView: return QueuePanel;
  4976. case fcQueueToolbar: return QueueDock;
  4977. case fcRemoteTree: return RemoteDrivePanel;
  4978. case fcSessionsTabs: return SessionsPageControl;
  4979. case fcQueueFileList: return QueueFileList;
  4980. default: return NULL;
  4981. }
  4982. }
  4983. //---------------------------------------------------------------------------
  4984. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4985. TObject *Sender, TListColumn *Column, TPoint &Point)
  4986. {
  4987. DebugAssert(NonVisualDataModule && Column && Sender);
  4988. NonVisualDataModule->ListColumn = Column;
  4989. TPopupMenu * DirViewColumnMenu;
  4990. if (Sender == DirView(osOther))
  4991. {
  4992. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4993. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4994. (Column->Index == uvName);
  4995. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4996. (Column->Index == uvSize);
  4997. }
  4998. else
  4999. {
  5000. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5001. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  5002. (Column->Index == dvName);
  5003. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  5004. (Column->Index == dvSize);
  5005. }
  5006. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5007. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5008. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5009. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5010. }
  5011. //---------------------------------------------------------------------------
  5012. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5013. TObject *Sender, TListItem *Item, bool &AllowExec)
  5014. {
  5015. DoDirViewExecFile(Sender, Item, AllowExec);
  5016. }
  5017. //---------------------------------------------------------------------------
  5018. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5019. TListItem * Item, bool & AllowExec)
  5020. {
  5021. DebugAssert(Sender && Item && Configuration);
  5022. DebugAssert(AllowExec);
  5023. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5024. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5025. bool Remote = !IsSideLocalBrowser(Side);
  5026. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  5027. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  5028. // on files only (not directories)
  5029. // and only when symlinks are resolved (apply to remote panel only)
  5030. if (!ADirView->ItemIsDirectory(Item) &&
  5031. (ResolvedSymlinks || FForceExecution))
  5032. {
  5033. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  5034. !FForceExecution && ResolvedSymlinks)
  5035. {
  5036. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5037. {
  5038. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5039. UnlockWindow();
  5040. try
  5041. {
  5042. if (IsLocalBrowserMode())
  5043. {
  5044. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5045. }
  5046. else
  5047. {
  5048. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5049. }
  5050. }
  5051. __finally
  5052. {
  5053. LockWindow();
  5054. }
  5055. AllowExec = false;
  5056. }
  5057. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5058. {
  5059. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5060. {
  5061. ExecuteFile(Side, efDefaultEditor);
  5062. AllowExec = false;
  5063. }
  5064. }
  5065. else
  5066. {
  5067. DebugFail();
  5068. }
  5069. }
  5070. // if we have not done anything special, fall back to default behavior
  5071. if (AllowExec)
  5072. {
  5073. if (Remote && !WinConfiguration->DisableOpenEdit)
  5074. {
  5075. ExecuteFile(osRemote, efShell);
  5076. AllowExec = false;
  5077. }
  5078. }
  5079. }
  5080. }
  5081. //---------------------------------------------------------------------------
  5082. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5083. {
  5084. return ((Side == osRemote) || (Side == osCurrent));
  5085. }
  5086. //---------------------------------------------------------------------------
  5087. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5088. {
  5089. DebugFail();
  5090. }
  5091. //---------------------------------------------------------------------------
  5092. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5093. {
  5094. DebugFail();
  5095. }
  5096. //---------------------------------------------------------------------------
  5097. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5098. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5099. {
  5100. TSynchronizeParamType Params;
  5101. Params.LocalDirectory = LocalDirectory;
  5102. Params.RemoteDirectory = RemoteDirectory;
  5103. int UnusedParams =
  5104. (GUIConfiguration->SynchronizeParams &
  5105. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5106. TTerminal::spCaseSensitive));
  5107. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5108. Params.Options = GUIConfiguration->SynchronizeOptions;
  5109. bool SaveSettings = false;
  5110. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5111. &DoSynchronizeTooManyDirectories);
  5112. DebugAssert(FSynchronizeController == NULL);
  5113. FSynchronizeController = &Controller;
  5114. bool Result;
  5115. try
  5116. {
  5117. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5118. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5119. int Options =
  5120. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5121. DebugAssert(FOnFeedSynchronizeError == NULL);
  5122. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5123. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5124. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5125. if (Result)
  5126. {
  5127. if (SaveSettings)
  5128. {
  5129. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5130. GUIConfiguration->SynchronizeOptions = Params.Options;
  5131. }
  5132. else
  5133. {
  5134. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5135. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5136. FLAGSET(Params.Options, soSynchronize))
  5137. {
  5138. GUIConfiguration->SynchronizeOptions =
  5139. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5140. soSynchronize;
  5141. }
  5142. }
  5143. LocalDirectory = Params.LocalDirectory;
  5144. RemoteDirectory = Params.RemoteDirectory;
  5145. }
  5146. }
  5147. __finally
  5148. {
  5149. FSynchronizeController = NULL;
  5150. DebugAssert(FOnFeedSynchronizeError == NULL);
  5151. FOnFeedSynchronizeError = NULL;
  5152. }
  5153. return Result;
  5154. }
  5155. //---------------------------------------------------------------------------
  5156. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5157. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5158. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5159. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5160. TSynchronizeOptions * Options, bool Full)
  5161. {
  5162. // Keep-up-to-date mode
  5163. if (Terminal->Status == ssOpened)
  5164. {
  5165. try
  5166. {
  5167. int PParams = Params.Params;
  5168. if (!Full)
  5169. {
  5170. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5171. if (FLAGSET(Params.Options, soRecurse))
  5172. {
  5173. PParams |= TTerminal::spSubDirs;
  5174. }
  5175. }
  5176. else
  5177. {
  5178. // if keepuptodate is non-recursive,
  5179. // full sync before has to be non-recursive as well
  5180. if (FLAGCLEAR(Params.Options, soRecurse))
  5181. {
  5182. PParams |= TTerminal::spNoRecurse;
  5183. }
  5184. }
  5185. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5186. PParams, Checklist, Options);
  5187. }
  5188. catch (Exception & E)
  5189. {
  5190. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5191. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5192. {
  5193. // noop, already logged in MoreMessageDialog
  5194. }
  5195. else
  5196. {
  5197. ShowExtendedExceptionEx(Terminal, &E);
  5198. throw;
  5199. }
  5200. }
  5201. }
  5202. }
  5203. //---------------------------------------------------------------------------
  5204. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5205. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5206. const UnicodeString ErrorStr)
  5207. {
  5208. if (!Directory.IsEmpty())
  5209. {
  5210. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5211. }
  5212. else
  5213. {
  5214. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5215. }
  5216. }
  5217. //---------------------------------------------------------------------------
  5218. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5219. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5220. {
  5221. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5222. {
  5223. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5224. }
  5225. else
  5226. {
  5227. TMessageParams Params(mpNeverAskAgainCheck);
  5228. unsigned int Result = MessageDialog(
  5229. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5230. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5231. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5232. {
  5233. MaxDirectories *= 2;
  5234. if (Result == qaNeverAskAgain)
  5235. {
  5236. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5237. }
  5238. }
  5239. else
  5240. {
  5241. Abort();
  5242. }
  5243. }
  5244. }
  5245. //---------------------------------------------------------------------------
  5246. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5247. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5248. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5249. TSynchronizeOptions * Options)
  5250. {
  5251. // Keep-up-to-date mode
  5252. DebugAssert(!FAutoOperation);
  5253. void * BatchStorage;
  5254. BatchStart(BatchStorage);
  5255. FAutoOperation = true;
  5256. bool AnyOperation = false;
  5257. TDateTime StartTime = Now();
  5258. TSynchronizeChecklist * AChecklist = NULL;
  5259. try
  5260. {
  5261. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5262. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5263. {
  5264. FSynchronizeProgressForm->Start();
  5265. }
  5266. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5267. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5268. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5269. Options);
  5270. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5271. SAFE_DESTROY(FSynchronizeProgressForm);
  5272. AnyOperation = (AChecklist->CheckedCount > 0);
  5273. if (AnyOperation)
  5274. {
  5275. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5276. CreateProgressForm(&SynchronizeProgress);
  5277. try
  5278. {
  5279. Terminal->SynchronizeApply(
  5280. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5281. SynchronizeProcessedItem, NULL, NULL, NULL);
  5282. }
  5283. __finally
  5284. {
  5285. DestroyProgressForm();
  5286. }
  5287. }
  5288. }
  5289. __finally
  5290. {
  5291. if (Checklist == NULL)
  5292. {
  5293. delete AChecklist;
  5294. }
  5295. else
  5296. {
  5297. *Checklist = AChecklist;
  5298. }
  5299. FAutoOperation = false;
  5300. SAFE_DESTROY(FSynchronizeProgressForm);
  5301. BatchEnd(BatchStorage);
  5302. ReloadLocalDirectory();
  5303. if (AnyOperation)
  5304. {
  5305. OperationComplete(StartTime);
  5306. }
  5307. }
  5308. }
  5309. //---------------------------------------------------------------------------
  5310. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5311. {
  5312. // can be called from command line
  5313. return Visible &&
  5314. ((DirView(osRemote)->SelCount > 0) ||
  5315. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5316. }
  5317. //---------------------------------------------------------------------------
  5318. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5319. {
  5320. LogSynchronizeEvent(Terminal, Message);
  5321. }
  5322. //---------------------------------------------------------------------------
  5323. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5324. int Params, TSynchronizeOptions & Options)
  5325. {
  5326. DebugAssert(!IsLocalBrowserMode());
  5327. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5328. {
  5329. Options.Filter = new TStringList();
  5330. Options.Filter->CaseSensitive = false;
  5331. Options.Filter->Duplicates = Types::dupAccept;
  5332. if (DirView(osRemote)->SelCount > 0)
  5333. {
  5334. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5335. }
  5336. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5337. {
  5338. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5339. }
  5340. Options.Filter->Sort();
  5341. }
  5342. }
  5343. //---------------------------------------------------------------------------
  5344. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5345. {
  5346. TCopyParamType Defaults;
  5347. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5348. ConfigStorage->AccessMode = smRead;
  5349. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5350. {
  5351. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5352. }
  5353. ConfigStorage.reset(NULL);
  5354. std::unique_ptr<TStringList> Options(new TStringList());
  5355. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5356. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5357. UnicodeString Result;
  5358. if (Options->Count > 0)
  5359. {
  5360. Result =
  5361. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5362. }
  5363. return Result;
  5364. }
  5365. //---------------------------------------------------------------------------
  5366. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5367. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5368. {
  5369. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5370. UnicodeString AdditionalParams =
  5371. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5372. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5373. SerializeCopyParamForCommandLine(CopyParams),
  5374. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5375. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5376. ExecuteNewInstance(SessionName, AdditionalParams);
  5377. }
  5378. //---------------------------------------------------------------------------
  5379. struct TSynchronizeParams
  5380. {
  5381. UnicodeString LocalDirectory;
  5382. UnicodeString RemoteDirectory;
  5383. TSynchronizeMode Mode;
  5384. TSynchronizeChecklist * Checklist;
  5385. int Params;
  5386. TCopyParamType * CopyParam;
  5387. TDateTime CollectElapsed;
  5388. TDateTime * StartTime;
  5389. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5390. };
  5391. //---------------------------------------------------------------------------
  5392. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5393. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5394. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5395. {
  5396. DebugAssert(!FAutoOperation);
  5397. void * BatchStorage;
  5398. BatchStart(BatchStorage);
  5399. FAutoOperation = true;
  5400. TFileOperationStatistics Statistics;
  5401. TDateTime Start = Now();
  5402. try
  5403. {
  5404. Params.OnProcessedItem = OnProcessedItem;
  5405. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5406. CreateProgressForm(&SynchronizeProgress);
  5407. Terminal->SynchronizeApply(
  5408. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5409. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5410. &Statistics);
  5411. }
  5412. __finally
  5413. {
  5414. Params.OnProcessedItem = NULL;
  5415. FAutoOperation = false;
  5416. DestroyProgressForm();
  5417. BatchEnd(BatchStorage);
  5418. ReloadLocalDirectory();
  5419. }
  5420. if (WinConfiguration->SynchronizeSummary)
  5421. {
  5422. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5423. // The statistics should be 0 anyway in this case
  5424. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5425. {
  5426. Message += L"\n";
  5427. if (Statistics.FilesUploaded > 0)
  5428. {
  5429. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5430. }
  5431. if (Statistics.FilesDownloaded > 0)
  5432. {
  5433. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5434. }
  5435. if (Statistics.FilesDeletedLocal > 0)
  5436. {
  5437. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5438. }
  5439. if (Statistics.FilesDeletedRemote > 0)
  5440. {
  5441. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5442. }
  5443. }
  5444. TDateTime Elapsed = (Now() - Start);
  5445. Message +=
  5446. L"\n" +
  5447. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5448. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5449. TMessageParams Params(mpNeverAskAgainCheck);
  5450. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5451. if (Result == qaNeverAskAgain)
  5452. {
  5453. WinConfiguration->SynchronizeSummary = false;
  5454. }
  5455. }
  5456. }
  5457. //---------------------------------------------------------------------------
  5458. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5459. {
  5460. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5461. {
  5462. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5463. }
  5464. // Not set in keep-up-to-date mode - Synchronize() method
  5465. if (Token != NULL)
  5466. {
  5467. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5468. if (Params.OnProcessedItem != NULL)
  5469. {
  5470. Params.OnProcessedItem(NULL, ChecklistItem);
  5471. }
  5472. }
  5473. }
  5474. //---------------------------------------------------------------------------
  5475. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5476. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5477. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5478. {
  5479. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5480. *Params.StartTime = Now();
  5481. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5482. }
  5483. //---------------------------------------------------------------------------
  5484. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5485. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5486. {
  5487. // terminal can be already closed (e.g. dropped connection)
  5488. if (Terminal != NULL)
  5489. {
  5490. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5491. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5492. }
  5493. }
  5494. //---------------------------------------------------------------------------
  5495. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5496. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5497. {
  5498. DebugAssert(!IsLocalBrowserMode());
  5499. TAutoBatch AutoBatch(this);
  5500. TAutoFlag AutoOperationFlag(FAutoOperation);
  5501. if (Side == osRemote)
  5502. {
  5503. std::unique_ptr<TStrings> FileList(new TStringList());
  5504. FileList->AddObject(FileName, RemoteFile);
  5505. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5506. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5507. RemoteDirView->SaveSelection();
  5508. RemoteDirView->SaveSelectedNames();
  5509. try
  5510. {
  5511. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5512. }
  5513. catch(...)
  5514. {
  5515. RemoteDirView->DiscardSavedSelection();
  5516. throw;
  5517. }
  5518. RemoteDirView->RestoreSelection();
  5519. }
  5520. else if (DebugAlwaysTrue(Side == osLocal))
  5521. {
  5522. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5523. {
  5524. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5525. }
  5526. UnicodeString Directory = ExtractFileDir(FileName);
  5527. ReloadLocalDirectory(Directory);
  5528. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5529. if (!SamePaths(Directory, NewDirectory))
  5530. {
  5531. ReloadLocalDirectory(NewDirectory);
  5532. }
  5533. }
  5534. }
  5535. //---------------------------------------------------------------------------
  5536. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5537. {
  5538. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5539. if (Side == osLocal)
  5540. {
  5541. if (Action == TSynchronizeChecklist::saDownloadNew)
  5542. {
  5543. OpenFolderInExplorer(LocalPath);
  5544. }
  5545. else
  5546. {
  5547. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5548. }
  5549. }
  5550. else if (DebugAlwaysTrue(Side == osRemote))
  5551. {
  5552. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5553. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5554. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5555. if (!LocalPath.IsEmpty())
  5556. {
  5557. SessionData->LocalDirectory = LocalPath;
  5558. }
  5559. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5560. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5561. }
  5562. }
  5563. //---------------------------------------------------------------------------
  5564. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5565. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5566. const TCopyParamType * CopyParams)
  5567. {
  5568. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5569. UnicodeString AdditionalParams =
  5570. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5571. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5572. SerializeCopyParamForCommandLine(CopyParams),
  5573. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5574. LocalDirectory, RemoteDirectory, Mode, Params));
  5575. ExecuteNewInstance(SessionName, AdditionalParams);
  5576. }
  5577. //---------------------------------------------------------------------------
  5578. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5579. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5580. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5581. {
  5582. int Result;
  5583. bool SaveSettings = false;
  5584. int Options =
  5585. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5586. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5587. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5588. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5589. bool Continue =
  5590. (UseDefaults == 0) ||
  5591. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5592. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5593. if (Continue)
  5594. {
  5595. Configuration->Usage->Inc(L"Synchronizations");
  5596. UpdateCopyParamCounters(CopyParam);
  5597. TSynchronizeOptions SynchronizeOptions;
  5598. GetSynchronizeOptions(Params, SynchronizeOptions);
  5599. if (SaveSettings)
  5600. {
  5601. GUIConfiguration->SynchronizeParams = Params;
  5602. }
  5603. else
  5604. {
  5605. SaveMode = false;
  5606. }
  5607. TDateTime StartTime = Now();
  5608. TSynchronizeChecklist * Checklist = NULL;
  5609. try
  5610. {
  5611. DebugAssert(!FAutoOperation);
  5612. FAutoOperation = true;
  5613. try
  5614. {
  5615. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5616. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5617. int Files = -1;
  5618. if (DataList->Count >= 1)
  5619. {
  5620. Files = StrToIntDef(DataList->Strings[0], Files);
  5621. }
  5622. else
  5623. {
  5624. DataList->Add(UnicodeString());
  5625. }
  5626. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5627. FSynchronizeProgressForm->Start();
  5628. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5629. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5630. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5631. &SynchronizeOptions);
  5632. if (Terminal->SessionData->CacheDirectories)
  5633. {
  5634. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5635. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5636. }
  5637. }
  5638. __finally
  5639. {
  5640. FAutoOperation = false;
  5641. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5642. SAFE_DESTROY(FSynchronizeProgressForm);
  5643. }
  5644. TSynchronizeParams SynchronizeParams;
  5645. SynchronizeParams.LocalDirectory = LocalDirectory;
  5646. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5647. SynchronizeParams.Mode = Mode;
  5648. SynchronizeParams.CopyParam = &CopyParam;
  5649. SynchronizeParams.Params = Params;
  5650. SynchronizeParams.Checklist = Checklist;
  5651. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5652. SynchronizeParams.StartTime = &StartTime;
  5653. SynchronizeParams.OnProcessedItem = NULL;
  5654. Result = Checklist->Count;
  5655. if (Checklist->Count > 0)
  5656. {
  5657. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5658. {
  5659. if (!DoSynchronizeChecklistDialog(
  5660. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5661. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5662. {
  5663. Result = -1;
  5664. }
  5665. }
  5666. else
  5667. {
  5668. FullSynchronize(SynchronizeParams, NULL, NULL);
  5669. }
  5670. }
  5671. else
  5672. {
  5673. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5674. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5675. }
  5676. }
  5677. __finally
  5678. {
  5679. delete Checklist;
  5680. }
  5681. OperationComplete(StartTime);
  5682. }
  5683. else
  5684. {
  5685. Result = -1;
  5686. }
  5687. return Result;
  5688. }
  5689. //---------------------------------------------------------------------------
  5690. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5691. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5692. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5693. {
  5694. if (Collect)
  5695. {
  5696. DebugAssert(FSynchronizeProgressForm != NULL);
  5697. if (!FSynchronizeProgressForm->Started)
  5698. {
  5699. FSynchronizeProgressForm->Start();
  5700. }
  5701. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5702. SetTaskbarListProgressValue(CompareProgress);
  5703. }
  5704. else
  5705. {
  5706. DebugAssert(FSynchronizeProgressForm == NULL);
  5707. DebugAssert(FProgressForm != NULL);
  5708. }
  5709. }
  5710. //---------------------------------------------------------------------------
  5711. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5712. {
  5713. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5714. TRemoteFile * File = NULL;
  5715. Terminal->ReadFile(FullFileName, File);
  5716. if (File != NULL)
  5717. {
  5718. std::unique_ptr<TRemoteFile> FileOwner(File);
  5719. TAutoFlag Flag(FStandaloneEditing);
  5720. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5721. Application->ShowMainForm = false;
  5722. Application->Run();
  5723. }
  5724. }
  5725. //---------------------------------------------------------------------------
  5726. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5727. {
  5728. DebugFail();
  5729. }
  5730. //---------------------------------------------------------------------------
  5731. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5732. {
  5733. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5734. SessionData->Assign(ManagedSession->SessionData);
  5735. UpdateSessionData(SessionData.get());
  5736. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  5737. if (IsActiveTerminal(ManagedSession))
  5738. {
  5739. ManagedSession->UpdateSessionCredentials(SessionData.get());
  5740. }
  5741. if (!ManagedSession->SessionData->HasSessionName())
  5742. {
  5743. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5744. // once IsWorkspace is cleared
  5745. SessionData->Name = UnicodeString();
  5746. SessionData->IsWorkspace = false;
  5747. }
  5748. return SessionData.release();
  5749. }
  5750. //---------------------------------------------------------------------------
  5751. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5752. {
  5753. TSessionData * SessionData = CloneCurrentSessionData();
  5754. try
  5755. {
  5756. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5757. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5758. }
  5759. __finally
  5760. {
  5761. delete SessionData;
  5762. }
  5763. }
  5764. //---------------------------------------------------------------------------
  5765. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5766. {
  5767. TTerminalManager * Manager = TTerminalManager::Instance();
  5768. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5769. if (DebugAlwaysTrue(ManagedSession != NULL))
  5770. {
  5771. // Update ManagedSession->StateData
  5772. UpdateSession(ManagedSession);
  5773. }
  5774. Manager->SaveWorkspace(DataList.get());
  5775. return DataList.release();
  5776. }
  5777. //---------------------------------------------------------------------------
  5778. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5779. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5780. {
  5781. WinConfiguration->LastWorkspace = Name;
  5782. if (!SavePasswords)
  5783. {
  5784. for (int Index = 0; Index < DataList->Count; Index++)
  5785. {
  5786. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5787. if (SessionData->Link.IsEmpty())
  5788. {
  5789. SessionData->ClearSessionPasswords();
  5790. }
  5791. }
  5792. }
  5793. StoredSessions->NewWorkspace(Name, DataList);
  5794. // modified only
  5795. StoredSessions->Save(false, Explicit);
  5796. }
  5797. //---------------------------------------------------------------------------
  5798. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5799. {
  5800. return
  5801. DefaultStr(WinConfiguration->LastWorkspace,
  5802. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5803. }
  5804. //---------------------------------------------------------------------------
  5805. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5806. {
  5807. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5808. bool AnyNonStoredSessionWithPassword = false;
  5809. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5810. bool AllNonStoredSessionsAnonymous = true;
  5811. TTerminalManager * Manager = TTerminalManager::Instance();
  5812. for (int Index = 0; Index < DataList->Count; Index++)
  5813. {
  5814. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5815. if (SessionData->Link.IsEmpty())
  5816. {
  5817. if (SessionData->HasAnySessionPassword())
  5818. {
  5819. AnyNonStoredSessionWithPassword = true;
  5820. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5821. {
  5822. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5823. }
  5824. }
  5825. if (!SameText(SessionData->UserName, AnonymousUserName))
  5826. {
  5827. AllNonStoredSessionsAnonymous = false;
  5828. }
  5829. }
  5830. }
  5831. bool SavePasswords;
  5832. bool * PSavePasswords;
  5833. bool NotRecommendedSavingPasswords =
  5834. !CustomWinConfiguration->UseMasterPassword &&
  5835. !AllNonStoredSessionsAnonymous;
  5836. if (Configuration->DisablePasswordStoring ||
  5837. !AnyNonStoredSessionWithPassword)
  5838. {
  5839. PSavePasswords = NULL;
  5840. SavePasswords = false;
  5841. }
  5842. else
  5843. {
  5844. PSavePasswords = &SavePasswords;
  5845. SavePasswords =
  5846. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5847. !NotRecommendedSavingPasswords;
  5848. }
  5849. UnicodeString Name = WorkspaceName();
  5850. bool CreateShortcut = false;
  5851. bool Result =
  5852. DoSaveWorkspaceDialog(
  5853. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5854. EnableAutoSave);
  5855. if (Result)
  5856. {
  5857. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5858. if (CreateShortcut)
  5859. {
  5860. TOperationVisualizer Visualizer;
  5861. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5862. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5863. }
  5864. if (EnableAutoSave)
  5865. {
  5866. WinConfiguration->AutoSaveWorkspace = true;
  5867. WinConfiguration->AutoWorkspace = Name;
  5868. if (PSavePasswords != NULL)
  5869. {
  5870. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5871. }
  5872. }
  5873. }
  5874. return Result;
  5875. }
  5876. //---------------------------------------------------------------------------
  5877. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  5878. {
  5879. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  5880. DebugAssert(Session == ManagedSession);
  5881. if (!IsLocalBrowserMode())
  5882. {
  5883. SAFE_DESTROY(Session->RemoteExplorerState);
  5884. if (WinConfiguration->PreservePanelState)
  5885. {
  5886. Session->RemoteExplorerState = RemoteDirView->SaveState();
  5887. }
  5888. }
  5889. UpdateSessionData(Session->StateData);
  5890. }
  5891. //---------------------------------------------------------------------------
  5892. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5893. {
  5894. // Keep in sync with TSessionData::CopyStateData
  5895. DebugAssert(Data != NULL);
  5896. // This is inconsistent with how color (for example) is handled.
  5897. Data->Name = ManagedSession->SessionData->Name;
  5898. if (!IsLocalBrowserMode())
  5899. {
  5900. // cannot use RemoteDirView->Path, because it is empty if connection
  5901. // was already closed
  5902. // also only peek, we may not be connected at all atm
  5903. // so make sure we do not try retrieving current directory from the server
  5904. // (particularly with FTP)
  5905. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5906. if (!ACurrentDirectory.IsEmpty())
  5907. {
  5908. Data->RemoteDirectory = ACurrentDirectory;
  5909. }
  5910. }
  5911. Data->Color = SessionColor;
  5912. }
  5913. //---------------------------------------------------------------------------
  5914. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5915. {
  5916. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5917. DebugAssert(Toolbar != NULL);
  5918. for (int i = 0; i < Toolbar->Items->Count; i++)
  5919. {
  5920. TTBXCustomDropDownItem * DropDownItem;
  5921. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5922. if (DropDownItem != NULL)
  5923. {
  5924. ToolbarItemResize(DropDownItem,
  5925. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5926. Toolbar->NonClientWidth);
  5927. break;
  5928. }
  5929. }
  5930. }
  5931. //---------------------------------------------------------------------------
  5932. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5933. {
  5934. Item->EditWidth = Width;
  5935. }
  5936. //---------------------------------------------------------------------------
  5937. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5938. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5939. {
  5940. for (int i = 0; i < Toolbar->Items->Count; i++)
  5941. {
  5942. TTBXCustomDropDownItem * DropDownItem;
  5943. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5944. if (DropDownItem != NULL)
  5945. {
  5946. ASize.x -= DropDownItem->EditWidth;
  5947. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5948. }
  5949. }
  5950. }
  5951. //---------------------------------------------------------------------------
  5952. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5953. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5954. {
  5955. if (WinConfiguration->DDWarnLackOfTempSpace)
  5956. {
  5957. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5958. if (!ADrive.IsEmpty())
  5959. {
  5960. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5961. DebugAssert(RequiredSpace >= 0);
  5962. __int64 RequiredWithReserve;
  5963. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5964. if (FreeSpace < RequiredWithReserve)
  5965. {
  5966. unsigned int Result;
  5967. TMessageParams Params(mpNeverAskAgainCheck);
  5968. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5969. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5970. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5971. if (Result == qaNeverAskAgain)
  5972. {
  5973. WinConfiguration->DDWarnLackOfTempSpace = false;
  5974. }
  5975. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5976. }
  5977. }
  5978. }
  5979. }
  5980. //---------------------------------------------------------------------------
  5981. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5982. {
  5983. DoOpenDirectoryDialog(odAddBookmark, Side);
  5984. }
  5985. //---------------------------------------------------------------------------
  5986. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5987. {
  5988. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5989. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5990. try
  5991. {
  5992. TCustomDirView * DView = DirView(Side);
  5993. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5994. {
  5995. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5996. }
  5997. }
  5998. catch (...)
  5999. {
  6000. delete VisitedDirectories;
  6001. throw;
  6002. }
  6003. return VisitedDirectories;
  6004. }
  6005. //---------------------------------------------------------------------------
  6006. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6007. TOpenDirectoryMode Mode, TOperationSide Side)
  6008. {
  6009. bool Continue = true;
  6010. if (Mode == odAddBookmark)
  6011. {
  6012. TMessageParams Params(mpNeverAskAgainCheck);
  6013. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6014. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6015. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6016. unsigned int Answer =
  6017. MessageDialog(Message,
  6018. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6019. if (Answer == qaNeverAskAgain)
  6020. {
  6021. Continue = true;
  6022. WinConfiguration->UseSharedBookmarks = true;
  6023. }
  6024. else if (Answer == qaOK)
  6025. {
  6026. Continue = true;
  6027. WinConfiguration->UseSharedBookmarks = false;
  6028. }
  6029. else
  6030. {
  6031. Continue = false;
  6032. }
  6033. }
  6034. if (Continue)
  6035. {
  6036. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6037. try
  6038. {
  6039. UnicodeString Name = DirView(Side)->PathName;
  6040. bool Repeat;
  6041. do
  6042. {
  6043. Repeat = false;
  6044. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6045. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6046. // do not allow switching to location profiles,
  6047. // if we are not connected
  6048. HasDirView[osLocal] && (Terminal != NULL)))
  6049. {
  6050. TWindowLock Lock(this);
  6051. if (!TryOpenDirectory(Side, Name))
  6052. {
  6053. Repeat = true;
  6054. Mode = odBrowse;
  6055. }
  6056. }
  6057. }
  6058. while (Repeat);
  6059. }
  6060. __finally
  6061. {
  6062. delete VisitedDirectories;
  6063. }
  6064. }
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6068. {
  6069. DebugAssert(!Terminal->CommandSessionOpened);
  6070. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6071. }
  6072. //---------------------------------------------------------------------------
  6073. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6074. {
  6075. bool Result = Terminal->IsCapable[Capability] ||
  6076. Terminal->CommandSessionOpened;
  6077. if (!Result)
  6078. {
  6079. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6080. if (!GUIConfiguration->ConfirmCommandSession)
  6081. {
  6082. Result = true;
  6083. }
  6084. else
  6085. {
  6086. TMessageParams Params(mpNeverAskAgainCheck);
  6087. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6088. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6089. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6090. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6091. if (Answer == qaNeverAskAgain)
  6092. {
  6093. GUIConfiguration->ConfirmCommandSession = false;
  6094. Result = true;
  6095. }
  6096. else if (Answer == qaOK)
  6097. {
  6098. Result = true;
  6099. }
  6100. }
  6101. if (Result)
  6102. {
  6103. Result = CommandSessionFallback();
  6104. }
  6105. }
  6106. return Result;
  6107. }
  6108. //---------------------------------------------------------------------------
  6109. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6110. {
  6111. if (EnsureCommandSessionFallback(fcAnyCommand))
  6112. {
  6113. DoConsoleDialog(Terminal, Command);
  6114. }
  6115. }
  6116. //---------------------------------------------------------------------------
  6117. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6118. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6119. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6120. {
  6121. if (!IsSideLocalBrowser(osRemote) &&
  6122. IsFileControl(DropSourceControl, osRemote) &&
  6123. (FDDExtMapFile != NULL))
  6124. {
  6125. Accept = true;
  6126. }
  6127. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6128. DebugAssert(FDDTargetControl != NULL);
  6129. }
  6130. //---------------------------------------------------------------------------
  6131. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6132. _di_IDataObject DataObj, int KeyState,
  6133. const TPoint & Point, int & Effect, bool & Accept)
  6134. {
  6135. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6136. }
  6137. //---------------------------------------------------------------------------
  6138. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6139. _di_IDataObject DataObj, int KeyState,
  6140. const TPoint & Point, int & Effect, bool & Accept)
  6141. {
  6142. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6143. }
  6144. //---------------------------------------------------------------------------
  6145. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6146. TObject * Sender)
  6147. {
  6148. DebugUsedParam(Sender);
  6149. DebugAssert(FDDTargetControl == Sender);
  6150. FDDTargetControl = NULL;
  6151. }
  6152. //---------------------------------------------------------------------------
  6153. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6154. {
  6155. FileControlDDDragLeave(SessionsPageControl);
  6156. }
  6157. //---------------------------------------------------------------------------
  6158. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6159. {
  6160. FileControlDDDragLeave(QueueView3);
  6161. }
  6162. //---------------------------------------------------------------------------
  6163. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6164. {
  6165. DebugAssert(!IsSideLocalBrowser(Side));
  6166. DebugUsedParam(Side);
  6167. bool Edit = false;
  6168. TRemoteFile * File = NULL;
  6169. UnicodeString FileName;
  6170. UnicodeString PointTo;
  6171. bool SymbolicLink = true;
  6172. if (RemoteDirView->ItemFocused)
  6173. {
  6174. DebugAssert(RemoteDirView->ItemFocused->Data);
  6175. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6176. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6177. if (Edit)
  6178. {
  6179. FileName = File->FileName;
  6180. PointTo = File->LinkTo;
  6181. }
  6182. else
  6183. {
  6184. PointTo = File->FileName;
  6185. }
  6186. }
  6187. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6188. Terminal->IsCapable[fcHardLink]))
  6189. {
  6190. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6191. if (Edit)
  6192. {
  6193. DebugAssert(File->FileName == FileName);
  6194. int Params = dfNoRecursive;
  6195. Terminal->ExceptionOnFail = true;
  6196. try
  6197. {
  6198. Terminal->DeleteFile(L"", File, &Params);
  6199. }
  6200. __finally
  6201. {
  6202. Terminal->ExceptionOnFail = false;
  6203. }
  6204. }
  6205. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6206. }
  6207. }
  6208. //---------------------------------------------------------------------------
  6209. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6210. {
  6211. return
  6212. (IsSideLocalBrowser(Side) ||
  6213. (HasActiveTerminal() &&
  6214. Terminal->ResolvingSymlinks &&
  6215. Terminal->IsCapable[fcSymbolicLink]));
  6216. }
  6217. //---------------------------------------------------------------------------
  6218. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6219. {
  6220. return
  6221. !IsSideLocalBrowser(FCurrentSide) &&
  6222. (RemoteDirView->ItemFocused != NULL) &&
  6223. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6224. Terminal->SessionData->ResolveSymlinks;
  6225. }
  6226. //---------------------------------------------------------------------------
  6227. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6228. {
  6229. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6230. FForceExecution = true;
  6231. try
  6232. {
  6233. DirView(osCurrent)->ExecuteCurrentFile();
  6234. }
  6235. __finally
  6236. {
  6237. FForceExecution = false;
  6238. }
  6239. }
  6240. //---------------------------------------------------------------------------
  6241. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6242. {
  6243. TEditorData ExternalEditor;
  6244. ExternalEditor.Editor = edExternal;
  6245. bool Remember = false;
  6246. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6247. {
  6248. if (Remember)
  6249. {
  6250. TEditorList * EditorList = new TEditorList;
  6251. try
  6252. {
  6253. *EditorList = *WinConfiguration->EditorList;
  6254. bool Found = false;
  6255. int i = 0;
  6256. while (!Found && (i < EditorList->Count))
  6257. {
  6258. const TEditorPreferences * Editor = EditorList->Editors[i];
  6259. if ((Editor->Data->Editor == edExternal) &&
  6260. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6261. {
  6262. Found = true;
  6263. }
  6264. i++;
  6265. }
  6266. if (!Found)
  6267. {
  6268. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6269. WinConfiguration->EditorList = EditorList;
  6270. }
  6271. }
  6272. __finally
  6273. {
  6274. delete EditorList;
  6275. }
  6276. }
  6277. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6278. }
  6279. }
  6280. //---------------------------------------------------------------------------
  6281. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6282. {
  6283. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6284. if (FFileFindTerminal == ATerminal)
  6285. {
  6286. FFileFindTerminal = NULL;
  6287. HideFileFindDialog();
  6288. }
  6289. if (FClipboardTerminal == ATerminal)
  6290. {
  6291. ClipboardClear(); // implies ClipboardStop
  6292. }
  6293. }
  6294. //---------------------------------------------------------------------------
  6295. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6296. {
  6297. DetachTerminal(Sender);
  6298. }
  6299. //---------------------------------------------------------------------------
  6300. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6301. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6302. {
  6303. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6304. DebugAssert(Terminal != NULL);
  6305. if (Data->Terminal == Terminal)
  6306. {
  6307. Data->Terminal = NULL;
  6308. }
  6309. }
  6310. //---------------------------------------------------------------------------
  6311. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6312. {
  6313. return NULL;
  6314. }
  6315. //---------------------------------------------------------------------------
  6316. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6317. {
  6318. UpdateControls();
  6319. SessionColor = TColor(0);
  6320. UpdateRemotePathComboBox(false);
  6321. NeedSession(false);
  6322. }
  6323. //---------------------------------------------------------------------------
  6324. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6325. {
  6326. try
  6327. {
  6328. // Cache, as the login dialog can change its value.
  6329. // See also DoShow. Also see TTerminalManager::NewSession.
  6330. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6331. try
  6332. {
  6333. if (ShowLogin)
  6334. {
  6335. bool ReloadSessions = !Startup;
  6336. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6337. }
  6338. }
  6339. __finally
  6340. {
  6341. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6342. // (so there was no chance for the user to open any session yet)
  6343. if ((ShowLogin || !Startup) &&
  6344. !WinConfiguration->KeepOpenWhenNoSession &&
  6345. // this rules out the implicit Commander's local-local browser
  6346. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6347. {
  6348. TerminateApplication();
  6349. }
  6350. }
  6351. }
  6352. catch (EAbort &)
  6353. {
  6354. // swallow
  6355. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6356. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6357. }
  6358. }
  6359. //---------------------------------------------------------------------------
  6360. void __fastcall TCustomScpExplorerForm::SessionListChanged()
  6361. {
  6362. TTerminalManager * Manager = TTerminalManager::Instance();
  6363. DebugAssert(!Manager->Updating);
  6364. TStrings * SessionList = Manager->SessionList;
  6365. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6366. Configuration->Usage->SetMax(L"MaxOpenedSessions", SessionList->Count);
  6367. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6368. try
  6369. {
  6370. while ((SessionsPageControl->PageCount > SessionList->Count + 1) ||
  6371. // Clear the design time unthemed tab
  6372. ((SessionsPageControl->PageCount > 0) &&
  6373. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6374. {
  6375. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6376. }
  6377. for (int Index = 0; Index <= SessionList->Count; Index++)
  6378. {
  6379. TThemeTabSheet * TabSheet;
  6380. if (Index >= SessionsPageControl->PageCount)
  6381. {
  6382. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6383. TabSheet->PageControl = SessionsPageControl;
  6384. }
  6385. else
  6386. {
  6387. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6388. }
  6389. bool IsSessionTab = (Index < SessionList->Count);
  6390. if (IsSessionTab)
  6391. {
  6392. TTerminal * Terminal = dynamic_cast<TTerminal *>(SessionList->Objects[Index]);
  6393. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6394. UpdateSessionTab(TabSheet);
  6395. }
  6396. else
  6397. {
  6398. TabSheet->Tag = 0; // not really needed
  6399. TabSheet->Shadowed = false;
  6400. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6401. // 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)
  6402. UpdateNewTabTab();
  6403. }
  6404. }
  6405. }
  6406. __finally
  6407. {
  6408. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6409. }
  6410. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6411. }
  6412. //---------------------------------------------------------------------------
  6413. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6414. {
  6415. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6416. UnicodeString TabCaption;
  6417. if (WinConfiguration->SelectiveToolbarText)
  6418. {
  6419. TabCaption = StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6420. }
  6421. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6422. // When starting, we can get here with the design-time unthemed tab
  6423. if ((ThemeTabSheet != NULL) && (ThemeTabSheet->Button != ttbNone))
  6424. {
  6425. TabCaption = SessionsPageControl->FormatCaptionWithTabButton(TabCaption);
  6426. }
  6427. TabSheet->Caption = TabCaption;
  6428. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6429. }
  6430. //---------------------------------------------------------------------------
  6431. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6432. {
  6433. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6434. }
  6435. //---------------------------------------------------------------------------
  6436. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6437. {
  6438. DebugFail();
  6439. return UnicodeString();
  6440. }
  6441. //---------------------------------------------------------------------------
  6442. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6443. {
  6444. if (DebugAlwaysTrue(TabSheet != NULL))
  6445. {
  6446. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6447. if (DebugAlwaysTrue(ASession != NULL))
  6448. {
  6449. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6450. if (ASession->LocalBrowser)
  6451. {
  6452. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6453. }
  6454. else
  6455. {
  6456. TabSheet->ImageIndex = AddSessionColor(Color);
  6457. }
  6458. TTerminalManager * Manager = TTerminalManager::Instance();
  6459. UnicodeString TabCaption = Manager->GetSessionTitle(ASession, true);
  6460. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6461. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6462. {
  6463. ThemeTabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  6464. ThemeTabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  6465. if (ThemeTabSheet->Button != ttbNone)
  6466. {
  6467. TabCaption = SessionsPageControl->FormatCaptionWithTabButton(TabCaption);
  6468. }
  6469. }
  6470. TabSheet->Caption = TabCaption;
  6471. }
  6472. }
  6473. }
  6474. //---------------------------------------------------------------------------
  6475. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  6476. {
  6477. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  6478. }
  6479. //---------------------------------------------------------------------------
  6480. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6481. {
  6482. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6483. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6484. bool Result = (Session != NULL);
  6485. if (Result)
  6486. {
  6487. TTerminalManager::Instance()->ActiveSession = Session;
  6488. }
  6489. else
  6490. {
  6491. try
  6492. {
  6493. NewTab();
  6494. }
  6495. __finally
  6496. {
  6497. SessionListChanged();
  6498. }
  6499. FSessionsPageControlNewTabTime = Now();
  6500. }
  6501. return Result;
  6502. }
  6503. //---------------------------------------------------------------------------
  6504. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6505. {
  6506. SessionTabSwitched();
  6507. }
  6508. //---------------------------------------------------------------------------
  6509. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6510. {
  6511. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6512. DebugAssert(TransferList != NULL);
  6513. UnicodeString Name;
  6514. if (TransferList->ItemIndex <= 0)
  6515. {
  6516. Name = L"";
  6517. }
  6518. else
  6519. {
  6520. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6521. }
  6522. if (FCopyParamAutoSelected.IsEmpty())
  6523. {
  6524. // if previous preset was not autoselected, make new preset the "default"
  6525. FCopyParamDefault = Name;
  6526. }
  6527. GUIConfiguration->CopyParamCurrent = Name;
  6528. }
  6529. //---------------------------------------------------------------------------
  6530. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6531. {
  6532. // sanity check
  6533. bool ExistingPreset =
  6534. (FTransferListHoverIndex >= 0) &&
  6535. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6536. DebugAssert(ExistingPreset);
  6537. if (ExistingPreset)
  6538. {
  6539. HDC DC = GetDC(0);
  6540. TCanvas * Canvas = new TCanvas();
  6541. try
  6542. {
  6543. Canvas->Handle = DC;
  6544. Canvas->Font = GetToolbarFont(this);
  6545. UnicodeString Name;
  6546. if (FTransferListHoverIndex == 0)
  6547. {
  6548. Name = L"";
  6549. }
  6550. else
  6551. {
  6552. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6553. }
  6554. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6555. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6556. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6557. static_cast<TObject*>(GetComponent(fcTransferList)));
  6558. UnicodeString InfoStr =
  6559. GUIConfiguration->CopyParamPreset[Name].
  6560. GetInfoStr(L"; ",
  6561. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6562. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6563. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6564. {
  6565. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6566. {
  6567. InfoStr.SetLength(InfoStr.Length() - 1);
  6568. }
  6569. InfoStr += Ellipsis;
  6570. }
  6571. // UpdateCaption does not cause invalidation of whole submenu, while
  6572. // setting Caption property does.
  6573. // also it probably does not resize the label, even if necessary
  6574. // (we do not want that anyway)
  6575. TransferLabel->UpdateCaption(InfoStr);
  6576. }
  6577. __finally
  6578. {
  6579. Canvas->Handle = NULL;
  6580. ReleaseDC(0, DC);
  6581. delete Canvas;
  6582. }
  6583. }
  6584. }
  6585. //---------------------------------------------------------------------------
  6586. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6587. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6588. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6589. {
  6590. if (FTransferListHoverIndex != AHoverIndex)
  6591. {
  6592. FTransferListHoverIndex = AHoverIndex;
  6593. UpdateTransferLabel();
  6594. }
  6595. }
  6596. //---------------------------------------------------------------------------
  6597. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6598. {
  6599. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6600. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6601. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6602. {
  6603. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6604. {
  6605. if (!NonVisualDataModule->Busy)
  6606. {
  6607. OpenDirectory(GetSide(osCurrent));
  6608. }
  6609. Message.Result = 1;
  6610. }
  6611. else
  6612. {
  6613. TForm::Dispatch(&Message);
  6614. }
  6615. }
  6616. else
  6617. {
  6618. TForm::Dispatch(&Message);
  6619. }
  6620. }
  6621. //---------------------------------------------------------------------------
  6622. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6623. {
  6624. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6625. if ((FIgnoreNextDialogChar != 0) &&
  6626. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6627. {
  6628. Message.Result = 1;
  6629. }
  6630. else
  6631. {
  6632. TForm::Dispatch(&Message);
  6633. }
  6634. FIgnoreNextDialogChar = 0;
  6635. }
  6636. //---------------------------------------------------------------------------
  6637. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6638. {
  6639. // The four low-order bits are used internally by Windows
  6640. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6641. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6642. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6643. // 61730 - restore thru double click - undocumented
  6644. // 61490 - maximize thru double click - undocumented
  6645. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6646. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6647. {
  6648. SysResizing(Cmd);
  6649. }
  6650. TForm::Dispatch(&Message);
  6651. }
  6652. //---------------------------------------------------------------------------
  6653. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6654. {
  6655. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6656. // Also there no point returning TRUE as we are not able to
  6657. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6658. // Hence the process termination might be safer :)
  6659. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6660. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6661. {
  6662. Message.Result = FALSE;
  6663. }
  6664. else
  6665. {
  6666. Message.Result = TRUE;
  6667. }
  6668. // Do not call default handling as that triggers OnCloseQuery,
  6669. // where our implementation will popup confirmation dialogs, what we do not want,
  6670. // as per Vista guidelines:
  6671. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6672. }
  6673. //---------------------------------------------------------------------------
  6674. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6675. {
  6676. if (Message.EndSession && IsApplicationMinimized())
  6677. {
  6678. // WORKAROUND
  6679. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6680. // when it receives WM_ENDSESSION,
  6681. // but that sometimes (particularly when application is minimized) cause crashes.
  6682. // Crash popups message that blocks log off.
  6683. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6684. // so we call ExitProcess() immediately, not even trying to cleanup.
  6685. // It still causes beep, so there's likely some popup, but it does not block
  6686. // log off.
  6687. ExitProcess(0);
  6688. }
  6689. TForm::Dispatch(&Message);
  6690. }
  6691. #ifdef _DEBUG
  6692. //---------------------------------------------------------------------------
  6693. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6694. {
  6695. TForm::Dispatch(&Message);
  6696. }
  6697. #endif
  6698. //---------------------------------------------------------------------------
  6699. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6700. {
  6701. }
  6702. //---------------------------------------------------------------------------
  6703. void __fastcall TCustomScpExplorerForm::DoShow()
  6704. {
  6705. // Called from TCustomScpExplorerForm::CMShowingChanged
  6706. // only now are the controls resized finally, so the size constraints
  6707. // will not conflict with possibly very small window size
  6708. RestoreFormParams();
  6709. // This indicates that the form was rescaled after parameters were loaded and
  6710. // as most probably the parameters were actually saved with the current form scaling
  6711. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6712. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6713. // and no rounding problems will occur.
  6714. // See also RestoreForm.
  6715. // (we should be safe to call RestoreParams unconditionally)
  6716. if (PixelsPerInch != Screen->PixelsPerInch)
  6717. {
  6718. RestoreParams();
  6719. }
  6720. FixControlsPlacement();
  6721. if (Position == poDefaultPosOnly)
  6722. {
  6723. CutFormToDesktop(this);
  6724. }
  6725. TForm::DoShow();
  6726. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6727. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6728. // This was previously in NeedSession, where other related code is.
  6729. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6730. // unpleasanly shows briefly.
  6731. if ((ManagedSession == NULL) &&
  6732. !WinConfiguration->ShowLoginWhenNoSession &&
  6733. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6734. // This detects if workspace was saved the last time the main widow was closed
  6735. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6736. {
  6737. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6738. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6739. }
  6740. // Before main window displays
  6741. if (ManagedSession == NULL)
  6742. {
  6743. StartingWithoutSession();
  6744. }
  6745. UpdatePixelsPerInchMainWindowCounter();
  6746. FShowing = true;
  6747. }
  6748. //---------------------------------------------------------------------------
  6749. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6750. {
  6751. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6752. }
  6753. //---------------------------------------------------------------------------
  6754. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  6755. {
  6756. SessionListChanged();
  6757. InitStatusBar();
  6758. UpdateControls();
  6759. }
  6760. //---------------------------------------------------------------------------
  6761. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6762. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6763. TNotifyEvent OnBalloonClick, TObject * UserData)
  6764. {
  6765. bool Do;
  6766. UnicodeString Message;
  6767. if (E == NULL)
  6768. {
  6769. Message = Str;
  6770. Do = true;
  6771. }
  6772. else
  6773. {
  6774. Do = ExceptionMessage(E, Message);
  6775. }
  6776. if (Do && WinConfiguration->BalloonNotifications)
  6777. {
  6778. UnicodeString Title;
  6779. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6780. {
  6781. Message = TrimLeft(Message);
  6782. }
  6783. else
  6784. {
  6785. Message = UnformatMessage(Message);
  6786. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6787. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6788. Title = LoadResourceString(Captions[Type]);
  6789. if (Terminal != NULL)
  6790. {
  6791. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6792. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  6793. }
  6794. }
  6795. if (Seconds == 0)
  6796. {
  6797. Seconds = WinConfiguration->NotificationsTimeout;
  6798. }
  6799. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6800. }
  6801. }
  6802. //---------------------------------------------------------------------------
  6803. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6804. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6805. UnicodeString HelpKeyword, const TMessageParams * Params,
  6806. TTerminal * Terminal)
  6807. {
  6808. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6809. (FOnFeedSynchronizeError != NULL)) &&
  6810. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6811. {
  6812. if (FOnFeedSynchronizeError != NULL)
  6813. {
  6814. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6815. }
  6816. else
  6817. {
  6818. DebugAssert(FErrorList != NULL);
  6819. TStringList * MoreMessagesCopy = NULL;
  6820. if (MoreMessages)
  6821. {
  6822. MoreMessagesCopy = new TStringList();
  6823. MoreMessagesCopy->Assign(MoreMessages);
  6824. }
  6825. FErrorList->AddObject(Message, MoreMessagesCopy);
  6826. }
  6827. PopupTrayBalloon(Terminal, Message, Type);
  6828. return ContinueAnswer(Answers);
  6829. }
  6830. else
  6831. {
  6832. bool UseBalloon = FTrayIcon->Visible;
  6833. if (UseBalloon)
  6834. {
  6835. PopupTrayBalloon(Terminal, Message, Type);
  6836. }
  6837. unsigned int Result;
  6838. try
  6839. {
  6840. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6841. }
  6842. __finally
  6843. {
  6844. // cancel only balloon we popped up, otherwise we may cancel notification
  6845. // balloon that was there before the message dialog
  6846. // (such as "dd confirmation opt in balloon)
  6847. if (UseBalloon)
  6848. {
  6849. FTrayIcon->CancelBalloon();
  6850. }
  6851. }
  6852. return Result;
  6853. }
  6854. }
  6855. //---------------------------------------------------------------------------
  6856. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6857. TTerminal * Terminal, Exception * E)
  6858. {
  6859. if (FTrayIcon->Visible)
  6860. {
  6861. PopupTrayBalloon(Terminal, L"", qtError, E);
  6862. }
  6863. // particularly prevent opening new session from jump list,
  6864. // while exception is shown
  6865. NonVisualDataModule->StartBusy();
  6866. try
  6867. {
  6868. ShowExtendedExceptionEx(Terminal, E);
  6869. }
  6870. __finally
  6871. {
  6872. NonVisualDataModule->EndBusy();
  6873. FTrayIcon->CancelBalloon();
  6874. }
  6875. }
  6876. //---------------------------------------------------------------------------
  6877. void __fastcall TCustomScpExplorerForm::SessionReady()
  6878. {
  6879. InitStatusBar();
  6880. // cannot rely on active page being page for active terminal,
  6881. // as it can happen that active page is the "new session" page
  6882. // (e.g. when reconnecting active terminal, while login dialog
  6883. // invoked from "new session" page is modal)
  6884. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6885. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  6886. }
  6887. //---------------------------------------------------------------------------
  6888. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6889. TTerminal * Terminal, Exception * E)
  6890. {
  6891. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6892. if (!Terminal->Active)
  6893. {
  6894. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6895. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6896. {
  6897. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6898. }
  6899. }
  6900. }
  6901. //---------------------------------------------------------------------------
  6902. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6903. UnicodeString Message, TQueryType Type,
  6904. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6905. {
  6906. if ((E == NULL) ||
  6907. ExceptionMessage(E, Message))
  6908. {
  6909. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6910. if (Important)
  6911. {
  6912. Seconds *= 5;
  6913. }
  6914. UnicodeString NoteMessage(UnformatMessage(Message));
  6915. if (Terminal != NULL)
  6916. {
  6917. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6918. NoteMessage = FORMAT(L"%s: %s",
  6919. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  6920. }
  6921. if (WinConfiguration->BalloonNotifications)
  6922. {
  6923. AddNote(NoteMessage);
  6924. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6925. }
  6926. else
  6927. {
  6928. FlashOnBackground();
  6929. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6930. }
  6931. }
  6932. }
  6933. //---------------------------------------------------------------------------
  6934. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6935. {
  6936. RestoreApp();
  6937. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6938. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6939. !NonVisualDataModule->Busy)
  6940. {
  6941. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6942. TTerminalManager::Instance()->ActiveSession = Terminal;
  6943. if (!ComponentVisible[fcQueueView])
  6944. {
  6945. ToggleQueueVisibility();
  6946. GoToQueue();
  6947. }
  6948. }
  6949. }
  6950. //---------------------------------------------------------------------------
  6951. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6952. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6953. {
  6954. UnicodeString Message;
  6955. TNotifyEvent OnClick = NULL;
  6956. TObject * UserData = NULL;
  6957. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6958. switch (Event)
  6959. {
  6960. case qeEmptyButMonitored:
  6961. if ((ATerminal != Terminal) || QueueInvisible)
  6962. {
  6963. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6964. OnClick = QueueEmptyNoteClicked;
  6965. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6966. TerminalNoteData->Terminal = ATerminal;
  6967. UserData = TerminalNoteData;
  6968. }
  6969. break;
  6970. case qeEmpty:
  6971. OperationComplete(ATerminal->QueueOperationStart);
  6972. break;
  6973. case qePendingUserAction:
  6974. if ((ATerminal != Terminal) ||
  6975. (QueueInvisible && !IsQueueAutoPopup()))
  6976. {
  6977. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6978. }
  6979. break;
  6980. default:
  6981. DebugFail();
  6982. }
  6983. if (!Message.IsEmpty())
  6984. {
  6985. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6986. }
  6987. }
  6988. //---------------------------------------------------------------------------
  6989. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6990. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6991. {
  6992. if (FDDExtMapFile != NULL)
  6993. {
  6994. CloseHandle(FDDExtMapFile);
  6995. FDDExtMapFile = NULL;
  6996. }
  6997. if (WinConfiguration->DDFakeFile)
  6998. {
  6999. DDFakeFileInitDrag(FileList, Created);
  7000. }
  7001. }
  7002. //---------------------------------------------------------------------------
  7003. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7004. {
  7005. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7006. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7007. {
  7008. FFakeFileDropTarget = FileName;
  7009. }
  7010. }
  7011. //---------------------------------------------------------------------------
  7012. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7013. {
  7014. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7015. if (!ForceDirectories(ApiPath(Result)))
  7016. {
  7017. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7018. }
  7019. FileSetAttr(ApiPath(Result), faHidden);
  7020. return Result;
  7021. }
  7022. //---------------------------------------------------------------------------
  7023. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7024. bool & Created)
  7025. {
  7026. FFakeFileDropTarget = UnicodeString();
  7027. FDragFakeDirectory = CreateFakeTransferDirectory();
  7028. FileList->AddItem(NULL, FDragFakeDirectory);
  7029. Created = true;
  7030. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7031. {
  7032. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7033. }
  7034. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7035. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7036. {
  7037. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7038. TDragExtCommStruct* CommStruct;
  7039. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7040. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7041. DebugAssert(CommStruct != NULL);
  7042. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7043. CommStruct->Dragging = true;
  7044. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7045. LENOF(CommStruct->DropDest));
  7046. NULL_TERMINATE(CommStruct->DropDest);
  7047. UnmapViewOfFile(CommStruct);
  7048. }
  7049. }
  7050. //---------------------------------------------------------------------------
  7051. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7052. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7053. {
  7054. bool Result;
  7055. DebugAssert(!IsLocalBrowserMode());
  7056. if (Sender == RemoteDirView)
  7057. {
  7058. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7059. }
  7060. else
  7061. {
  7062. DebugAssert(Sender == RemoteDriveView);
  7063. TStrings * FileList = RemoteDriveView->DragFileList();
  7064. try
  7065. {
  7066. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7067. }
  7068. __finally
  7069. {
  7070. delete FileList;
  7071. }
  7072. }
  7073. if (FDDTargetControl == RemoteDriveView)
  7074. {
  7075. RemoteDriveView->UpdateDropTarget();
  7076. }
  7077. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7078. // or from tree view to dir view.
  7079. // foMove happens when file/dir is dragged from remote tree view outside of
  7080. // application via dragex
  7081. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7082. (DropSourceControl == RemoteDriveView))
  7083. {
  7084. RemoteDriveView->UpdateDropSource();
  7085. }
  7086. return Result;
  7087. }
  7088. //---------------------------------------------------------------------------
  7089. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7090. {
  7091. DebugAssert(!IsLocalBrowserMode());
  7092. // This also handles drops of remote files to queue.
  7093. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7094. SAFE_DESTROY(FDDFileList);
  7095. if (!FFakeFileDropTarget.IsEmpty())
  7096. {
  7097. RemoveDir(ApiPath(FFakeFileDropTarget));
  7098. }
  7099. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7100. {
  7101. try
  7102. {
  7103. TDragResult DDResult = (Sender == RemoteDirView) ?
  7104. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7105. // Focus is moved to the target application,
  7106. // but as we are going to present the UI, we need to steal the focus back.
  7107. // This most likely won't work though (windows does not allow application
  7108. // to steal focus most of the time)
  7109. Application->BringToFront();
  7110. // On older version of Windows we never got drMove here, see also comment below.
  7111. // On Windows 10, we get the "move".
  7112. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7113. {
  7114. UnicodeString TargetDirectory;
  7115. TFileOperation Operation;
  7116. // drInvalid may mean drMove, see comment below
  7117. switch (DDResult)
  7118. {
  7119. case drCopy:
  7120. Operation = foCopy;
  7121. break;
  7122. case drMove:
  7123. Operation = foMove;
  7124. break;
  7125. default:
  7126. DebugFail();
  7127. case drInvalid:
  7128. // prefer "copy" for safety
  7129. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7130. break;
  7131. }
  7132. TTransferOperationParam Param;
  7133. UnicodeString CounterName;
  7134. bool ForceQueue;
  7135. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7136. {
  7137. // we get drInvalid both if d&d was intercepted by ddext,
  7138. // and when users drops on no-drop location.
  7139. // we tell the difference by existence of response from ddext,
  7140. // so we ignore absence of response in this case
  7141. if (DDResult != drInvalid)
  7142. {
  7143. // here we know that the extension is installed,
  7144. // as it is checked as soon as drag&drop starts from
  7145. // RemoteFileControlDDCreateDragFileList
  7146. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7147. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7148. {
  7149. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7150. }
  7151. else
  7152. {
  7153. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7154. }
  7155. }
  7156. }
  7157. else
  7158. {
  7159. // download using fake file
  7160. Param.Temp = false;
  7161. Param.DragDrop = true;
  7162. if (ForceQueue)
  7163. {
  7164. Param.Queue = asOn;
  7165. }
  7166. if (Sender == RemoteDirView)
  7167. {
  7168. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7169. }
  7170. if (RemoteFileControlFileOperation(Sender, Operation,
  7171. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7172. {
  7173. Configuration->Usage->Inc(CounterName);
  7174. }
  7175. }
  7176. }
  7177. }
  7178. __finally
  7179. {
  7180. CloseHandle(FDDExtMapFile);
  7181. FDDExtMapFile = NULL;
  7182. delete FDragFakeMonitors;
  7183. FDragFakeMonitors = NULL;
  7184. RemoveDir(ApiPath(FDragFakeDirectory));
  7185. FDragFakeDirectory = L"";
  7186. FFakeFileDropTarget = UnicodeString();
  7187. }
  7188. }
  7189. if (FDragDropSshTerminate.get() != NULL)
  7190. {
  7191. FDragDropSshTerminate->Rethrow();
  7192. }
  7193. }
  7194. //---------------------------------------------------------------------------
  7195. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7196. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7197. {
  7198. // Remember drop effect so we know (when user drops files), if we copy or move
  7199. FLastDropEffect = dwEffect;
  7200. }
  7201. //---------------------------------------------------------------------------
  7202. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7203. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7204. {
  7205. bool Result;
  7206. if (FDDTargetControl == QueueView3)
  7207. {
  7208. Directory = DefaultDownloadTargetDirectory();
  7209. Result = true;
  7210. CounterName = L"DownloadsDragDropQueue";
  7211. ForceQueue = true;
  7212. }
  7213. else if (!FFakeFileDropTarget.IsEmpty())
  7214. {
  7215. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7216. Result = true;
  7217. ForceQueue = false;
  7218. CounterName = L"DownloadsDragDropFakeFile";
  7219. }
  7220. else
  7221. {
  7222. ForceQueue = false;
  7223. Enabled = false;
  7224. try
  7225. {
  7226. int Timer = 0;
  7227. Result = false;
  7228. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7229. {
  7230. {
  7231. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7232. TDragExtCommStruct* CommStruct;
  7233. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7234. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7235. DebugAssert(CommStruct != NULL);
  7236. Result = !CommStruct->Dragging;
  7237. if (Result)
  7238. {
  7239. Directory = ExtractFilePath(CommStruct->DropDest);
  7240. CounterName = L"DownloadsDragDropExternalExt";
  7241. }
  7242. UnmapViewOfFile(CommStruct);
  7243. }
  7244. if (!Result)
  7245. {
  7246. Sleep(50);
  7247. Timer += 50;
  7248. Application->ProcessMessages();
  7249. }
  7250. }
  7251. }
  7252. __finally
  7253. {
  7254. Enabled = true;
  7255. }
  7256. }
  7257. return Result;
  7258. }
  7259. //---------------------------------------------------------------------------
  7260. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7261. const UnicodeString TempDir, int SecDelay)
  7262. {
  7263. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7264. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7265. if (FDelayedDeletionTimer == NULL)
  7266. {
  7267. DebugAssert(HandleAllocated());
  7268. FDelayedDeletionTimer = new TTimer(this);
  7269. FDelayedDeletionTimer->Interval = 10000;
  7270. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7271. }
  7272. else
  7273. {
  7274. FDelayedDeletionTimer->Enabled = true;
  7275. }
  7276. }
  7277. //---------------------------------------------------------------------------
  7278. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7279. {
  7280. DebugAssert(FDelayedDeletionList != NULL);
  7281. TDateTime N = Now();
  7282. TDateTime Alert;
  7283. UnicodeString Directory;
  7284. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7285. {
  7286. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7287. if ((N >= Alert) || (Sender == NULL))
  7288. {
  7289. Directory = FDelayedDeletionList->Strings[Index];
  7290. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7291. {
  7292. FDelayedDeletionList->Delete(Index);
  7293. }
  7294. }
  7295. }
  7296. if (FDelayedDeletionList->Count == 0)
  7297. {
  7298. FDelayedDeletionTimer->Enabled = false;
  7299. }
  7300. }
  7301. //---------------------------------------------------------------------------
  7302. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7303. {
  7304. DebugAssert(!IsLocalBrowserMode());
  7305. if (IsFileControl(FDDTargetControl, osRemote) ||
  7306. (FDDTargetControl == SessionsPageControl))
  7307. {
  7308. TManagedTerminal * TargetTerminal = NULL;
  7309. TFileOperation Operation = foNone;
  7310. if (FDDTargetControl == SessionsPageControl)
  7311. {
  7312. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7313. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7314. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7315. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7316. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7317. {
  7318. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7319. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7320. {
  7321. Operation = foRemoteMove;
  7322. }
  7323. else
  7324. {
  7325. Operation = foRemoteCopy;
  7326. }
  7327. }
  7328. }
  7329. else
  7330. {
  7331. if (FLastDropEffect == DROPEFFECT_MOVE)
  7332. {
  7333. Operation = foRemoteMove;
  7334. }
  7335. else if (FLastDropEffect == DROPEFFECT_COPY)
  7336. {
  7337. Operation = foRemoteCopy;
  7338. }
  7339. }
  7340. if (Operation != foNone)
  7341. {
  7342. RemoteFileControlFileOperation(DropSourceControl,
  7343. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7344. }
  7345. // abort drag&drop
  7346. Abort();
  7347. }
  7348. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7349. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7350. (FDDTargetControl != QueueView3))
  7351. {
  7352. DebugAssert(!FDragTempDir.IsEmpty());
  7353. TTransferType Type;
  7354. UnicodeString TempDir = FDragTempDir;
  7355. // We clear FDragTempDir before calling
  7356. // just in case it fail (raises exception)
  7357. FDragTempDir = L"";
  7358. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7359. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7360. // empty directory parameter means temp directory -> don't display it!
  7361. UnicodeString TargetDir = L"";
  7362. int Options = 0;
  7363. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7364. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7365. {
  7366. Abort();
  7367. }
  7368. // TargetDir is set when dropped on local file control
  7369. // (this was workaround for legacy dirview event handling, now it should be
  7370. // made prettier)
  7371. if (TargetDir.IsEmpty())
  7372. {
  7373. TargetDir = TempDir;
  7374. if (ForceDirectories(ApiPath(TargetDir)))
  7375. {
  7376. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7377. FPendingTempSpaceWarn = true;
  7378. try
  7379. {
  7380. FDragDropOperation = true;
  7381. int Params = cpTemporary |
  7382. (Type == ttMove ? cpDelete : 0);
  7383. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7384. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7385. }
  7386. __finally
  7387. {
  7388. FDragDropOperation = false;
  7389. FPendingTempSpaceWarn = false;
  7390. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7391. }
  7392. }
  7393. else
  7394. {
  7395. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7396. }
  7397. }
  7398. }
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. void __fastcall TCustomScpExplorerForm::DDDownload(
  7402. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7403. {
  7404. DebugAssert(!IsLocalBrowserMode());
  7405. TAutoBatch AutoBatch(this);
  7406. UpdateCopyParamCounters(*CopyParam);
  7407. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7408. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7409. {
  7410. RemoteDriveView->UpdateDropSource();
  7411. }
  7412. }
  7413. //---------------------------------------------------------------------------
  7414. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7415. {
  7416. public:
  7417. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7418. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7419. {
  7420. }
  7421. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7422. {
  7423. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7424. TDataObjectFilesEx::AllowData(FormatEtc);
  7425. }
  7426. };
  7427. //---------------------------------------------------------------------------
  7428. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7429. TObject * Sender, TDataObject *& DataObject)
  7430. {
  7431. if (FDDExtMapFile != NULL)
  7432. {
  7433. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7434. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7435. {
  7436. Abort();
  7437. }
  7438. if (FileList->Count > 0)
  7439. {
  7440. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7441. if (!FilesObject->IsValid(true, true))
  7442. {
  7443. FilesObject->_Release();
  7444. }
  7445. else
  7446. {
  7447. DataObject = FilesObject;
  7448. }
  7449. }
  7450. }
  7451. }
  7452. //---------------------------------------------------------------------------
  7453. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7454. {
  7455. DebugFail();
  7456. }
  7457. //---------------------------------------------------------------------------
  7458. void __fastcall TCustomScpExplorerForm::GoToTree()
  7459. {
  7460. ComponentVisible[fcRemoteTree] = true;
  7461. DriveView(osRemote)->SetFocus();
  7462. }
  7463. //---------------------------------------------------------------------------
  7464. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7465. TPanelExport Export)
  7466. {
  7467. TCustomDirView * DirView = this->DirView(Side);
  7468. std::unique_ptr<TStrings> ExportData(new TStringList());
  7469. switch (Export)
  7470. {
  7471. case pePath:
  7472. ExportData->Add(DirView->PathName);
  7473. break;
  7474. case peFileList:
  7475. case peFullFileList:
  7476. {
  7477. bool FullPath = (Export == peFullFileList);
  7478. DirView->CreateFileList(false, FullPath, ExportData.get());
  7479. for (int Index = 0; Index < ExportData->Count; Index++)
  7480. {
  7481. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7482. {
  7483. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7484. }
  7485. }
  7486. }
  7487. break;
  7488. default:
  7489. DebugFail();
  7490. }
  7491. return ExportData.release();
  7492. }
  7493. //---------------------------------------------------------------------------
  7494. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7495. TPanelExport Export, TPanelExportDestination Destination)
  7496. {
  7497. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7498. PanelExportStore(Side, Export, Destination, ExportData.get());
  7499. }
  7500. //---------------------------------------------------------------------------
  7501. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7502. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7503. TStrings * ExportData)
  7504. {
  7505. if (Destination == pedClipboard)
  7506. {
  7507. TInstantOperationVisualizer Visualizer;
  7508. CopyToClipboard(ExportData);
  7509. }
  7510. else
  7511. {
  7512. DebugFail();
  7513. }
  7514. }
  7515. //---------------------------------------------------------------------------
  7516. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7517. {
  7518. TCustomDirView * DirView = this->DirView(Side);
  7519. UnicodeString Mask = DirView->Mask;
  7520. if (DoFilterMaskDialog(DirView, Mask))
  7521. {
  7522. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7523. Configuration->Usage->Inc(L"Filters");
  7524. }
  7525. }
  7526. //---------------------------------------------------------------------------
  7527. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7528. {
  7529. return FQueueController->DefaultOperation();
  7530. }
  7531. //---------------------------------------------------------------------------
  7532. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7533. TQueueOperation Operation, void ** Param)
  7534. {
  7535. switch (Operation)
  7536. {
  7537. case qoPreferences:
  7538. return true;
  7539. case qoGoTo:
  7540. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7541. case qoOnceEmpty:
  7542. return IsAnythingQueued();
  7543. default:
  7544. return FQueueController->AllowOperation(Operation, Param);
  7545. }
  7546. }
  7547. //---------------------------------------------------------------------------
  7548. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7549. {
  7550. if (DebugAlwaysTrue(QueueView3->Visible))
  7551. {
  7552. QueueView3->SetFocus();
  7553. }
  7554. }
  7555. //---------------------------------------------------------------------------
  7556. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7557. TQueueOperation Operation, void * Param)
  7558. {
  7559. if (Operation == qoGoTo)
  7560. {
  7561. GoToQueue();
  7562. }
  7563. else if (Operation == qoPreferences)
  7564. {
  7565. PreferencesDialog(pmQueue);
  7566. }
  7567. else
  7568. {
  7569. FQueueController->ExecuteOperation(Operation, Param);
  7570. }
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7574. {
  7575. return (Queue != NULL) && Queue->Enabled;
  7576. }
  7577. //---------------------------------------------------------------------------
  7578. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7579. {
  7580. DebugAssert(Queue != NULL);
  7581. if (Queue != NULL)
  7582. {
  7583. Queue->Enabled = !Queue->Enabled;
  7584. }
  7585. }
  7586. //---------------------------------------------------------------------------
  7587. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7588. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7589. {
  7590. FQueueActedItem = QueueView3->ItemFocused;
  7591. }
  7592. //---------------------------------------------------------------------------
  7593. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7594. {
  7595. return TopDock->Height + QueueSplitter->Height;
  7596. }
  7597. //---------------------------------------------------------------------------
  7598. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7599. {
  7600. return
  7601. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7602. (QueueDock->Visible ? QueueDock->Height : 0) +
  7603. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7604. }
  7605. //---------------------------------------------------------------------------
  7606. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7607. {
  7608. return ScaleByTextHeight(this, 48);
  7609. }
  7610. //---------------------------------------------------------------------------
  7611. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7612. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7613. {
  7614. // when queue is hidden by double-clicking splitter, stray attempt to
  7615. // resize the panel with strange value arrives, make sure it is ignored
  7616. if (ComponentVisible[fcQueueView])
  7617. {
  7618. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7619. if (NewSize > MaxHeightLimit)
  7620. {
  7621. NewSize = MaxHeightLimit;
  7622. }
  7623. int MinHeightLimit =
  7624. GetStaticQueuePanelComponentsHeight() +
  7625. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7626. GetMinQueueViewHeight();
  7627. if (NewSize < MinHeightLimit)
  7628. {
  7629. NewSize = MinHeightLimit;
  7630. }
  7631. }
  7632. else
  7633. {
  7634. Accept = false;
  7635. }
  7636. }
  7637. //---------------------------------------------------------------------------
  7638. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7639. {
  7640. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7641. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7642. if (QueueViewHeight < GetMinQueueViewHeight())
  7643. {
  7644. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7645. }
  7646. }
  7647. //---------------------------------------------------------------------------
  7648. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7649. TDragObject *& /*DragObject*/)
  7650. {
  7651. FQueueActedItem = QueueView3->ItemFocused;
  7652. }
  7653. //---------------------------------------------------------------------------
  7654. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7655. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7656. {
  7657. Accept = true;
  7658. if (Source == QueueView3)
  7659. {
  7660. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7661. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7662. if (Accept)
  7663. {
  7664. TQueueItemProxy * QueueItem;
  7665. TQueueItemProxy * DestQueueItem;
  7666. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7667. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7668. Accept = (QueueItem != DestQueueItem) &&
  7669. (QueueItem->Status == TQueueItem::qsPending) &&
  7670. (DestQueueItem->Status == TQueueItem::qsPending);
  7671. }
  7672. }
  7673. }
  7674. //---------------------------------------------------------------------------
  7675. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7676. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7677. {
  7678. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7679. {
  7680. TQueueItemProxy * QueueItem;
  7681. TQueueItemProxy * DestQueueItem;
  7682. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7683. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7684. QueueItem->Move(DestQueueItem);
  7685. }
  7686. }
  7687. //---------------------------------------------------------------------------
  7688. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7689. {
  7690. if ((QueueView3->ItemFocused == NULL) &&
  7691. (QueueView3->Items->Count > 0))
  7692. {
  7693. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7694. }
  7695. QueueLabelUpdateStatus();
  7696. }
  7697. //---------------------------------------------------------------------------
  7698. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7699. {
  7700. QueueLabelUpdateStatus();
  7701. }
  7702. //---------------------------------------------------------------------------
  7703. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7704. {
  7705. QueueLabel->UpdateStatus();
  7706. }
  7707. //---------------------------------------------------------------------------
  7708. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7709. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7710. {
  7711. if (Selected)
  7712. {
  7713. NonVisualDataModule->UpdateNonVisibleActions();
  7714. }
  7715. }
  7716. //---------------------------------------------------------------------------
  7717. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7718. {
  7719. TDragDropFilesEx * Result = NULL;
  7720. if (Sender == SessionsPageControl)
  7721. {
  7722. Result = FSessionsDragDropFilesEx;
  7723. }
  7724. else if (Sender == QueueView3)
  7725. {
  7726. Result = FQueueDragDropFilesEx;
  7727. }
  7728. else
  7729. {
  7730. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7731. if (DirView != NULL)
  7732. {
  7733. Result = DirView->DragDropFilesEx;
  7734. }
  7735. else
  7736. {
  7737. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7738. if (DriveView != NULL)
  7739. {
  7740. Result = DriveView->DragDropFilesEx;
  7741. }
  7742. }
  7743. }
  7744. DebugAssert(Result != NULL);
  7745. return Result;
  7746. }
  7747. //---------------------------------------------------------------------------
  7748. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7749. {
  7750. return (DView->SelCount == DView->FilesCount);
  7751. }
  7752. //---------------------------------------------------------------------------
  7753. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7754. {
  7755. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7756. }
  7757. //---------------------------------------------------------------------------
  7758. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7759. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7760. {
  7761. DebugAssert(!IsLocalBrowserMode());
  7762. TFileOperation Operation;
  7763. switch (Effect)
  7764. {
  7765. case DROPEFFECT_MOVE:
  7766. Operation = foMove;
  7767. break;
  7768. case DROPEFFECT_COPY:
  7769. // occures on WinXP (reported by user)
  7770. default:
  7771. Operation = foCopy;
  7772. break;
  7773. };
  7774. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7775. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7776. if (DragDropFilesEx->FileList->Count > 0)
  7777. {
  7778. TStrings * FileList = new TStringList();
  7779. try
  7780. {
  7781. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7782. {
  7783. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7784. }
  7785. FDragDropOperation = true;
  7786. TTransferOperationParam Param;
  7787. Param.TargetDirectory = TargetPath;
  7788. // upload, no temp dirs
  7789. Param.Temp = false;
  7790. Param.DragDrop = DragDrop;
  7791. Param.Options =
  7792. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7793. if (ForceQueue)
  7794. {
  7795. Param.Queue = asOn;
  7796. }
  7797. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7798. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7799. {
  7800. if (IsFileControl(DropSourceControl, osLocal))
  7801. {
  7802. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7803. }
  7804. else
  7805. {
  7806. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7807. }
  7808. }
  7809. }
  7810. __finally
  7811. {
  7812. FDragDropOperation = false;
  7813. delete FileList;
  7814. }
  7815. }
  7816. }
  7817. //---------------------------------------------------------------------------
  7818. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7819. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7820. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7821. {
  7822. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7823. }
  7824. //---------------------------------------------------------------------------
  7825. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7826. TObject * Sender, int grfKeyState, int & dwEffect)
  7827. {
  7828. DebugAssert(!IsLocalBrowserMode());
  7829. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7830. if ((dwEffect != DROPEFFECT_NONE) &&
  7831. IsFileControl(DropSourceControl, osRemote))
  7832. {
  7833. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7834. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7835. (RemoteDirView->DropTarget == NULL))
  7836. {
  7837. dwEffect = DROPEFFECT_NONE;
  7838. }
  7839. else
  7840. {
  7841. if (dwEffect == DROPEFFECT_COPY)
  7842. {
  7843. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7844. // currently we support copying always (at least via temporary directory);
  7845. // remove associated checks once this all proves stable and working
  7846. bool CopyCapable = true;
  7847. // if we do not support neither of operations, there's no discussion
  7848. if (!MoveCapable && !CopyCapable)
  7849. {
  7850. dwEffect = DROPEFFECT_NONE;
  7851. }
  7852. else
  7853. {
  7854. // The default effect inside remote panel is move,
  7855. // unless we do not support it, but support copy
  7856. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7857. {
  7858. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7859. }
  7860. else
  7861. {
  7862. // with ctrl-down, we want copy unless it is not supported
  7863. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7864. }
  7865. }
  7866. }
  7867. }
  7868. }
  7869. }
  7870. //---------------------------------------------------------------------------
  7871. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7872. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7873. {
  7874. DebugAssert(!IsLocalBrowserMode());
  7875. if (FDDTotalSize >= 0)
  7876. {
  7877. if (File->IsDirectory)
  7878. {
  7879. FDDTotalSize = -1;
  7880. }
  7881. else
  7882. {
  7883. FDDTotalSize += File->Size;
  7884. }
  7885. }
  7886. DebugAssert(!FDragTempDir.IsEmpty());
  7887. // TODO: this is quite ineffective
  7888. // TODO: what if invalid character replacement is disabled?
  7889. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7890. UnicodeString TransferFileName;
  7891. if (Sender == RemoteDriveView)
  7892. {
  7893. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7894. }
  7895. else
  7896. {
  7897. TransferFileName = File->FileName;
  7898. }
  7899. FDDFileList->AddObject(TransferFileName, File);
  7900. }
  7901. //---------------------------------------------------------------------------
  7902. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7903. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7904. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7905. {
  7906. // sometimes we do not get DDEnd so the list is not released
  7907. SAFE_DESTROY(FDDFileList);
  7908. FDDFileList = new TStringList();
  7909. FDragTempDir = WinConfiguration->TemporaryDir();
  7910. FDDTotalSize = 0;
  7911. FDragDropSshTerminate.reset(NULL);
  7912. }
  7913. //---------------------------------------------------------------------------
  7914. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7915. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7916. HRESULT & Result)
  7917. {
  7918. if (Result == DRAGDROP_S_DROP)
  7919. {
  7920. try
  7921. {
  7922. GlobalDragImageList->HideDragImage();
  7923. try
  7924. {
  7925. RemoteFileControlDDTargetDrop();
  7926. }
  7927. catch(ESshTerminate & E)
  7928. {
  7929. FDragDropSshTerminate.reset(E.Clone());
  7930. }
  7931. }
  7932. catch (Exception &E)
  7933. {
  7934. // If downloading fails we need to cancel drag&drop, otherwise
  7935. // Explorer shows error
  7936. // But by the way exception probably never reach this point as
  7937. // it's catched on way.
  7938. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7939. Result = DRAGDROP_S_CANCEL;
  7940. ShowExtendedException(Terminal, &E);
  7941. }
  7942. }
  7943. }
  7944. //---------------------------------------------------------------------------
  7945. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7946. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7947. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7948. {
  7949. TFileMasks::TParams MaskParams;
  7950. MaskParams.Size = Size;
  7951. MaskParams.Modification = Modification;
  7952. // this does not re-parse the mask if it is the same as the last time
  7953. FDirViewMatchMask = Masks;
  7954. bool ImplicitMatch;
  7955. Matches =
  7956. // RecurseInclude parameter has no effect as the Path is empty
  7957. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7958. (AllowImplicitMatches || !ImplicitMatch);
  7959. }
  7960. //---------------------------------------------------------------------------
  7961. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7962. TObject * Sender, TListItem * Item, WORD & Indexes)
  7963. {
  7964. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7965. UnicodeString Ext;
  7966. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7967. {
  7968. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7969. }
  7970. else
  7971. {
  7972. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7973. }
  7974. if (SameText(Ext, Configuration->PartialExt))
  7975. {
  7976. Indexes |= oiPartial;
  7977. }
  7978. }
  7979. //---------------------------------------------------------------------------
  7980. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7981. {
  7982. return
  7983. DirViewEnabled(osCurrent) &&
  7984. DirView(osCurrent)->CanPasteFromClipBoard();
  7985. }
  7986. //---------------------------------------------------------------------------
  7987. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7988. {
  7989. bool Result = false;
  7990. if (CanPasteToDirViewFromClipBoard())
  7991. {
  7992. Result = true;
  7993. }
  7994. else
  7995. {
  7996. UnicodeString ClipboardText;
  7997. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7998. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7999. {
  8000. if (StoredSessions->IsUrl(ClipboardText))
  8001. {
  8002. Result = true;
  8003. }
  8004. else
  8005. {
  8006. Result = DirViewEnabled(osCurrent);
  8007. }
  8008. }
  8009. }
  8010. return Result;
  8011. }
  8012. //---------------------------------------------------------------------------
  8013. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8014. {
  8015. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8016. if (DoesClipboardContainOurFiles())
  8017. {
  8018. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8019. {
  8020. DebugAssert(!IsLocalBrowserMode());
  8021. TTerminalManager * Manager = TTerminalManager::Instance();
  8022. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8023. Manager->ActiveSession = FClipboardTerminal;
  8024. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8025. }
  8026. }
  8027. else if (CanPasteToDirViewFromClipBoard())
  8028. {
  8029. DirView(osCurrent)->PasteFromClipBoard();
  8030. }
  8031. else
  8032. {
  8033. UnicodeString ClipboardText;
  8034. if (NonEmptyTextFromClipboard(ClipboardText))
  8035. {
  8036. if (StoredSessions->IsUrl(ClipboardText))
  8037. {
  8038. NewSession(ClipboardText);
  8039. }
  8040. else
  8041. {
  8042. DirView(osCurrent)->Path = ClipboardText;
  8043. }
  8044. }
  8045. }
  8046. }
  8047. //---------------------------------------------------------------------------
  8048. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8049. {
  8050. // TBD
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8054. {
  8055. TCustomDirView * ADirView = DirView(Side);
  8056. ADirView->SelectAll(Mode);
  8057. ADirView->SetFocus();
  8058. }
  8059. //---------------------------------------------------------------------------
  8060. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8061. {
  8062. TCustomDirView * ADirView = DirView(Side);
  8063. TFileFilter Filter;
  8064. DefaultFileFilter(Filter);
  8065. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8066. {
  8067. Configuration->Usage->Inc(L"MaskSelections");
  8068. ADirView->SelectFiles(Filter, Select);
  8069. ADirView->SetFocus();
  8070. }
  8071. }
  8072. //---------------------------------------------------------------------------
  8073. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8074. {
  8075. TCustomDirView * ADirView = DirView(Side);
  8076. ADirView->RestoreSelectedNames();
  8077. ADirView->SetFocus();
  8078. }
  8079. //---------------------------------------------------------------------------
  8080. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8081. {
  8082. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8083. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8084. {
  8085. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8086. UnicodeString Ext;
  8087. if (!IsSideLocalBrowser(osCurrent))
  8088. {
  8089. Ext = UnixExtractFileExt(FileName);
  8090. }
  8091. else
  8092. {
  8093. Ext = ExtractFileExt(FileName);
  8094. }
  8095. if (Ext.IsEmpty())
  8096. {
  8097. Ext = L".";
  8098. }
  8099. TFileFilter Filter;
  8100. Filter.Masks = FORMAT(L"*%s", (Ext));
  8101. Filter.Directories = false;
  8102. CurrentDirView->SelectFiles(Filter, Select);
  8103. }
  8104. }
  8105. //---------------------------------------------------------------------------
  8106. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8107. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8108. {
  8109. UnicodeString Result;
  8110. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8111. {
  8112. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8113. }
  8114. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8115. {
  8116. // noop
  8117. }
  8118. else
  8119. {
  8120. Result =
  8121. FMTLOAD(FILE_INFO_FORMAT,
  8122. (FormatBytes(FileInfo.SelectedSize),
  8123. FormatBytes(FileInfo.FilesSize),
  8124. FormatNumber(FileInfo.SelectedCount),
  8125. FormatNumber(FileInfo.FilesCount)));
  8126. }
  8127. return Result;
  8128. }
  8129. //---------------------------------------------------------------------------
  8130. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8131. TTBXStatusPanel * Panel, TOperationSide Side)
  8132. {
  8133. if (Panel->Index == 1)
  8134. {
  8135. ToggleShowHiddenFiles();
  8136. }
  8137. else if (Panel->Index == 2)
  8138. {
  8139. Filter(Side);
  8140. }
  8141. }
  8142. //---------------------------------------------------------------------------
  8143. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8144. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8145. {
  8146. DebugAssert(!StatusBar->SimplePanel);
  8147. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8148. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8149. }
  8150. //---------------------------------------------------------------------------
  8151. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8152. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8153. {
  8154. DebugAssert(StatusBar->Panels->Count >= 3);
  8155. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8156. if (FileInfo.HiddenCount > 0)
  8157. {
  8158. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8159. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8160. }
  8161. else
  8162. {
  8163. HiddenFilesPanel->ViewPriority = 0;
  8164. // not really necessary, just to cleanup no-longer-valid data
  8165. HiddenFilesPanel->Caption = L"";
  8166. }
  8167. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8168. if (FileInfo.FilteredCount > 0)
  8169. {
  8170. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8171. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8172. }
  8173. else
  8174. {
  8175. FilteredFilesPanel->ViewPriority = 0;
  8176. // not really necessary, just to cleanup no-longer-valid data
  8177. FilteredFilesPanel->Caption = L"";
  8178. }
  8179. }
  8180. //---------------------------------------------------------------------------
  8181. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8182. TObject * /*Sender*/)
  8183. {
  8184. if (DirView(osOther)->Enabled)
  8185. {
  8186. DirView(osOther)->SetFocus();
  8187. }
  8188. }
  8189. //---------------------------------------------------------------------------
  8190. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8191. {
  8192. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8193. switch (Config.Show)
  8194. {
  8195. case qvShow:
  8196. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8197. {
  8198. Config.Show = qvHide;
  8199. }
  8200. else
  8201. {
  8202. Config.Show = Config.LastHideShow;
  8203. }
  8204. break;
  8205. case qvHideWhenEmpty:
  8206. if (ComponentVisible[fcQueueView])
  8207. {
  8208. Config.Show = qvHide;
  8209. }
  8210. else
  8211. {
  8212. Config.LastHideShow = Config.Show;
  8213. Config.Show = qvShow;
  8214. }
  8215. break;
  8216. case qvHide:
  8217. Config.LastHideShow = Config.Show;
  8218. Config.Show = qvShow;
  8219. break;
  8220. }
  8221. WinConfiguration->QueueView = Config;
  8222. }
  8223. //---------------------------------------------------------------------------
  8224. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8225. {
  8226. UnicodeString Result;
  8227. if (Terminal != NULL)
  8228. {
  8229. switch (WinConfiguration->PathInCaption)
  8230. {
  8231. case picShort:
  8232. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8233. break;
  8234. case picFull:
  8235. Result = Terminal->CurrentDirectory;
  8236. break;
  8237. }
  8238. }
  8239. return Result;
  8240. }
  8241. //---------------------------------------------------------------------------
  8242. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8243. {
  8244. TColor Result = GetWindowColor(FSessionColor);
  8245. return Result;
  8246. }
  8247. //---------------------------------------------------------------------------
  8248. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8249. {
  8250. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8251. return Result;
  8252. }
  8253. //---------------------------------------------------------------------------
  8254. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8255. {
  8256. if (!FSessionChanging)
  8257. {
  8258. TTerminalManager::Instance()->UpdateAppTitle();
  8259. }
  8260. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8261. // background to gray on Windows 7 (works on Windows 10).
  8262. // See also EnableControl
  8263. if (Showing)
  8264. {
  8265. if (ManagedSession != NULL)
  8266. {
  8267. // Update path when it changes
  8268. if ((SessionsPageControl->ActivePage != NULL) &&
  8269. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8270. {
  8271. UpdateSessionTab(SessionsPageControl->ActivePage);
  8272. }
  8273. }
  8274. NonVisualDataModule->ReconnectSessionAction->Update();
  8275. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8276. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8277. CenterReconnectToolbar();
  8278. bool HasTerminal = HasActiveTerminal();
  8279. RemoteDirView->Enabled = HasTerminal;
  8280. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8281. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8282. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8283. RemoteDriveView->Color = RemoteDirView->Color;
  8284. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8285. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8286. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8287. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8288. QueueFileList->Enabled = QueueView3->Enabled;
  8289. QueueFileList->Color = QueueView3->Color;
  8290. QueueFileList->Font->Color = QueueView3->Font->Color;
  8291. QueueLabelUpdateStatus();
  8292. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8293. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8294. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8295. {
  8296. UpdateDarkMode();
  8297. }
  8298. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8299. }
  8300. }
  8301. //---------------------------------------------------------------------------
  8302. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8303. {
  8304. UpdateControls();
  8305. }
  8306. //---------------------------------------------------------------------------
  8307. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8308. TObject * Sender)
  8309. {
  8310. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8311. DebugAssert(DirView != NULL);
  8312. DoDirViewLoaded(DirView);
  8313. TransferPresetAutoSelect();
  8314. }
  8315. //---------------------------------------------------------------------------
  8316. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8317. {
  8318. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8319. // first run after installation
  8320. if (double(Updates.LastCheck) == 0)
  8321. {
  8322. // make sure next time there will be an update (if enabled)
  8323. Updates.LastCheck = TDateTime(1);
  8324. WinConfiguration->Updates = Updates;
  8325. }
  8326. else if ((double(Updates.Period) > 0) &&
  8327. (Now() - Updates.LastCheck >= Updates.Period))
  8328. {
  8329. TThreadMethod OnUpdatesChecked = NULL;
  8330. if (!IsUWP())
  8331. {
  8332. OnUpdatesChecked = UpdatesChecked;
  8333. }
  8334. StartUpdateThread(OnUpdatesChecked);
  8335. }
  8336. }
  8337. //---------------------------------------------------------------------------
  8338. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8339. {
  8340. UnicodeString Message;
  8341. bool New;
  8342. TQueryType Type;
  8343. GetUpdatesMessage(Message, New, Type, false);
  8344. if (!Message.IsEmpty())
  8345. {
  8346. if (New)
  8347. {
  8348. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8349. }
  8350. if (!New && (Type != qtWarning))
  8351. {
  8352. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8353. }
  8354. else
  8355. {
  8356. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8357. }
  8358. if (New)
  8359. {
  8360. Configuration->Usage->Inc(L"UpdateNotifications");
  8361. }
  8362. }
  8363. }
  8364. //---------------------------------------------------------------------------
  8365. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8366. {
  8367. RestoreApp();
  8368. bool CanDisplay = !NonVisualDataModule->Busy;
  8369. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8370. {
  8371. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8372. }
  8373. if (CanDisplay)
  8374. {
  8375. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8376. CheckForUpdates(true);
  8377. }
  8378. else
  8379. {
  8380. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8381. }
  8382. }
  8383. //---------------------------------------------------------------------------
  8384. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8385. TCopyParamRuleData & Data)
  8386. {
  8387. DebugAssert(Terminal != NULL);
  8388. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8389. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8390. Data.RemoteDirectory = RemoteDirView->PathName;
  8391. }
  8392. //---------------------------------------------------------------------------
  8393. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8394. {
  8395. // Terminal can be null when we are changing local directory implicitly,
  8396. // because it has been deleted, while no session is connected
  8397. // (Login dialog is open)
  8398. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8399. {
  8400. DebugAssert(!IsLocalBrowserMode());
  8401. TCopyParamRuleData Data;
  8402. GetTransferPresetAutoSelectData(Data);
  8403. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8404. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8405. if (CopyParamIndex < 0)
  8406. {
  8407. // there is no preset that matches autoselection
  8408. // set preset that we consider "default"
  8409. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8410. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8411. }
  8412. else
  8413. {
  8414. // there is preset matching autoselection
  8415. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8416. if (CopyParamName == FCopyParamAutoSelected)
  8417. {
  8418. // autoselected the same preset as the last time
  8419. // make no change (i.e. preserve custom user preset, if any)
  8420. }
  8421. else
  8422. {
  8423. // autoselected the different preset then the last time (or there
  8424. // was default preset set)
  8425. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8426. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8427. }
  8428. }
  8429. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8430. {
  8431. if (CopyParamIndex >= 0)
  8432. {
  8433. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8434. }
  8435. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8436. try
  8437. {
  8438. int Fmt =
  8439. (CopyParamIndex < 0) ?
  8440. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8441. COPY_PARAM_AUTOSELECTED;
  8442. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8443. Data->Message = MainInstructions(Message);
  8444. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8445. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8446. CopyParamAttrs);
  8447. if (CopyParamIndex >= 0)
  8448. {
  8449. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8450. Info = FORMAT(L"%s\n \n%s", (Info,
  8451. FMTLOAD(COPY_PARAM_RULE,
  8452. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8453. }
  8454. Data->Message += L"\n\n" + Info;
  8455. if (WinConfiguration->CopyParamAutoSelectNotice)
  8456. {
  8457. TransferPresetNoteMessage(Data, true);
  8458. }
  8459. else
  8460. {
  8461. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8462. Data = NULL; // ownership passed
  8463. }
  8464. }
  8465. __finally
  8466. {
  8467. delete Data;
  8468. }
  8469. }
  8470. }
  8471. }
  8472. //---------------------------------------------------------------------------
  8473. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8474. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8475. {
  8476. DebugAssert(NoteData != NULL);
  8477. DebugAssert(!IsLocalBrowserMode());
  8478. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8479. TQueryButtonAlias Aliases[1];
  8480. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8481. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8482. Params.Aliases = Aliases;
  8483. Params.AliasesCount = LENOF(Aliases);
  8484. unsigned int Result =
  8485. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8486. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8487. switch (Result)
  8488. {
  8489. case qaNeverAskAgain:
  8490. DebugAssert(AllowNeverAskAgain);
  8491. WinConfiguration->CopyParamAutoSelectNotice = false;
  8492. break;
  8493. case qaIgnore:
  8494. PreferencesDialog(pmPresets);
  8495. break;
  8496. }
  8497. }
  8498. //---------------------------------------------------------------------------
  8499. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8500. {
  8501. // as of now useless, as this is used for notes only, never for balloons, ...
  8502. RestoreApp();
  8503. // .. and we should never be busy here
  8504. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8505. {
  8506. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8507. }
  8508. }
  8509. //---------------------------------------------------------------------------
  8510. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8511. TPreferencesMode APreferencesMode)
  8512. {
  8513. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8514. TCopyParamRuleData Data;
  8515. if (Terminal != NULL)
  8516. {
  8517. PreferencesData.reset(new TPreferencesDialogData());
  8518. GetTransferPresetAutoSelectData(Data);
  8519. PreferencesData->CopyParamRuleData = &Data;
  8520. }
  8521. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8522. }
  8523. //---------------------------------------------------------------------------
  8524. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8525. const TCustomCommandType & Command)
  8526. {
  8527. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8528. {
  8529. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8530. }
  8531. }
  8532. //---------------------------------------------------------------------------
  8533. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8534. {
  8535. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8536. TCustomCommandType Command;
  8537. // make sure we use local custom command when remote are not supported
  8538. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8539. {
  8540. Command = FLastCustomCommand;
  8541. }
  8542. else
  8543. {
  8544. Command.Params = Command.Params | ccLocal;
  8545. }
  8546. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8547. FEditingFocusedAdHocCommand = OnFocused;
  8548. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8549. int Options =
  8550. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8551. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8552. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8553. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8554. {
  8555. FLastCustomCommand = Command;
  8556. UpdateCustomCommandsToolbar();
  8557. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8558. }
  8559. }
  8560. //---------------------------------------------------------------------------
  8561. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8562. {
  8563. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8564. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8565. DebugAssert(State > 0);
  8566. if (State <= 0)
  8567. {
  8568. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8569. }
  8570. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8571. }
  8572. //---------------------------------------------------------------------------
  8573. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8574. TCustomCommandType & Command, int & State)
  8575. {
  8576. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8577. if (Result)
  8578. {
  8579. Command = FLastCustomCommand;
  8580. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8581. }
  8582. return Result;
  8583. }
  8584. //---------------------------------------------------------------------------
  8585. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8586. {
  8587. ResetIncrementalSearch();
  8588. }
  8589. //---------------------------------------------------------------------------
  8590. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8591. {
  8592. DebugAssert(ComponentVisible[Component]);
  8593. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8594. }
  8595. //---------------------------------------------------------------------------
  8596. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8597. {
  8598. // when queue panel is resized here directly, the status bar is stretched
  8599. // over whole space the panel occupied
  8600. PostComponentHide(fcQueueView);
  8601. }
  8602. //---------------------------------------------------------------------------
  8603. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8604. {
  8605. ComponentVisible[fcQueueFileList] = false;
  8606. }
  8607. //---------------------------------------------------------------------------
  8608. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8609. {
  8610. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8611. RefreshColorMode();
  8612. ResetSysDarkTheme();
  8613. ConfigurationChanged();
  8614. ConfigureInterface();
  8615. // Should be called for all controls
  8616. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8617. }
  8618. //---------------------------------------------------------------------------
  8619. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8620. {
  8621. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8622. if (!FInvalid &&
  8623. (Message.LParam != 0) &&
  8624. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8625. {
  8626. ThemeChanged();
  8627. }
  8628. TForm::Dispatch(&Message);
  8629. }
  8630. //---------------------------------------------------------------------------
  8631. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8632. {
  8633. TMessage * M = static_cast<TMessage*>(Message);
  8634. switch (M->Msg)
  8635. {
  8636. case CM_DIALOGCHAR:
  8637. CMDialogChar(*M);
  8638. break;
  8639. case WM_APPCOMMAND:
  8640. WMAppCommand(*M);
  8641. break;
  8642. case WM_SYSCOMMAND:
  8643. WMSysCommand(*M);
  8644. break;
  8645. case WM_QUERYENDSESSION:
  8646. WMQueryEndSession(*M);
  8647. break;
  8648. case WM_ENDSESSION:
  8649. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8650. break;
  8651. #ifdef _DEBUG
  8652. case WM_WINDOWPOSCHANGED:
  8653. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8654. break;
  8655. case CM_CUSTOMSTYLECHANGED:
  8656. TForm::Dispatch(Message);
  8657. break;
  8658. #endif
  8659. case WM_COMPONENT_HIDE:
  8660. {
  8661. Byte Component = static_cast<Byte>(M->WParam);
  8662. // sanity check
  8663. if (ComponentVisible[Component])
  8664. {
  8665. // special treatment
  8666. if (Component == fcQueueView)
  8667. {
  8668. ToggleQueueVisibility();
  8669. DebugAssert(!ComponentVisible[fcQueueView]);
  8670. }
  8671. else
  8672. {
  8673. ComponentVisible[Component] = false;
  8674. }
  8675. }
  8676. }
  8677. break;
  8678. case WM_COPYDATA:
  8679. WMCopyData(*M);
  8680. break;
  8681. case WM_MANAGES_CAPTION:
  8682. // caption managed in TTerminalManager::UpdateAppTitle()
  8683. M->Result = 1;
  8684. break;
  8685. case WM_WANTS_MOUSEWHEEL:
  8686. M->Result = 1;
  8687. break;
  8688. case CM_SHOWINGCHANGED:
  8689. CMShowingChanged(*M);
  8690. break;
  8691. case WM_CLOSE:
  8692. WMClose(*M);
  8693. break;
  8694. case WM_DPICHANGED:
  8695. WMDpiChanged(*M);
  8696. break;
  8697. case CM_DPICHANGED:
  8698. CMDpiChanged(*M);
  8699. break;
  8700. case WM_SETTINGCHANGE:
  8701. WMSettingChange(*M);
  8702. break;
  8703. case CM_DIALOGKEY:
  8704. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8705. break;
  8706. default:
  8707. TForm::Dispatch(Message);
  8708. break;
  8709. }
  8710. }
  8711. //---------------------------------------------------------------------------
  8712. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8713. {
  8714. // noop
  8715. }
  8716. //---------------------------------------------------------------------------
  8717. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8718. {
  8719. TForm::Dispatch(&Message);
  8720. FSessionColors->Clear();
  8721. AddFixedSessionImages();
  8722. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8723. UpdateImages();
  8724. }
  8725. //---------------------------------------------------------------------------
  8726. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8727. {
  8728. TForm::Dispatch(&Message);
  8729. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8730. UpdatePixelsPerInchMainWindowCounter();
  8731. }
  8732. //---------------------------------------------------------------------------
  8733. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8734. {
  8735. // Cannot close window while we are busy.
  8736. // We cannot test this in FormCloseQuery as that is called also from
  8737. // Close(), which is called by CloseApplicationAction. So we can be busy
  8738. // there already even, when it is legitimate to close the application.
  8739. // Possibly a better place to handle this would be WMSysCommand.
  8740. if (NonVisualDataModule->Busy)
  8741. {
  8742. Message.Result = 1;
  8743. }
  8744. else
  8745. {
  8746. TForm::Dispatch(&Message);
  8747. }
  8748. }
  8749. //---------------------------------------------------------------------------
  8750. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8751. {
  8752. // Ignoring implicit local-local browser of Commander, opened from DoShow
  8753. bool NoSession = (ManagedSession == NULL);
  8754. // This calls TCustomScpExplorerForm::DoShow
  8755. TForm::Dispatch(&Message);
  8756. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8757. if (Showing && !FStarted)
  8758. {
  8759. FStarted = true;
  8760. InterfaceStarted();
  8761. }
  8762. if (Showing && NoSession)
  8763. {
  8764. // When we are starting minimized (i.e. from an installer),
  8765. // postpone showing Login dialog until we get restored.
  8766. // Otherwise the Login dialog (and Authentication window) show restored
  8767. // over invisible (minimized) main window.
  8768. if (WindowState == wsMinimized)
  8769. {
  8770. FNeedSession = true;
  8771. }
  8772. else
  8773. {
  8774. // This happens before application ever goes idle, so the toolbars would
  8775. // stay enabled (initial state) until the Login dialog is dismissed.
  8776. UpdateActions();
  8777. NonVisualDataModule->StartBusy();
  8778. try
  8779. {
  8780. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8781. // otherwise the dialog does not receive focus.
  8782. // With Commander interface the ProcessMessages is called already
  8783. // by TDriveView, but with Explorer interface, we need to call it explicily
  8784. Application->ProcessMessages();
  8785. // do not reload sessions, they have been loaded just now (optimization)
  8786. NeedSession(true);
  8787. }
  8788. __finally
  8789. {
  8790. NonVisualDataModule->EndBusy();
  8791. }
  8792. }
  8793. }
  8794. }
  8795. //---------------------------------------------------------------------------
  8796. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8797. {
  8798. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8799. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8800. }
  8801. //---------------------------------------------------------------------------
  8802. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8803. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8804. int & MaxHeight)
  8805. {
  8806. // workaround for bug in TWinControl.CalcConstraints
  8807. // Check for empty rect (restore from iconic state) is done there only after
  8808. // call to AdjustClientRect, which enlarges the rect (for forms).
  8809. TRect R = GetClientRect();
  8810. // when restoring from iconic state, place no restrictions
  8811. if (IsRectEmpty(R))
  8812. {
  8813. MinWidth = 0;
  8814. MinHeight = 0;
  8815. MaxWidth = 32000;
  8816. MaxHeight = 32000;
  8817. }
  8818. }
  8819. //---------------------------------------------------------------------------
  8820. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8821. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8822. {
  8823. // terminal can be already closed (e.g. dropped connection)
  8824. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8825. {
  8826. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8827. try
  8828. {
  8829. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8830. }
  8831. catch(...)
  8832. {
  8833. if (!Terminal->Active)
  8834. {
  8835. Close = true;
  8836. }
  8837. throw;
  8838. }
  8839. }
  8840. }
  8841. //---------------------------------------------------------------------------
  8842. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8843. {
  8844. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8845. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8846. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8847. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8848. {
  8849. OnGetSpaceAvailable = GetSpaceAvailable;
  8850. }
  8851. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8852. OnGetSpaceAvailable);
  8853. }
  8854. //---------------------------------------------------------------------------
  8855. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8856. {
  8857. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8858. Terminal->FillSessionDataForCode(Data.get());
  8859. return Data.release();
  8860. }
  8861. //---------------------------------------------------------------------------
  8862. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8863. {
  8864. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8865. DoGenerateUrlDialog(Data.get(), Paths);
  8866. }
  8867. //---------------------------------------------------------------------------
  8868. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8869. {
  8870. GenerateUrl(NULL);
  8871. }
  8872. //---------------------------------------------------------------------------
  8873. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8874. {
  8875. std::unique_ptr<TStrings> Paths(new TStringList());
  8876. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8877. GenerateUrl(Paths.get());
  8878. }
  8879. //---------------------------------------------------------------------------
  8880. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8881. {
  8882. FSessionColor = value;
  8883. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8884. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8885. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8886. DebugAssert(ColorItem != NULL);
  8887. ColorItem->Color = C;
  8888. NonVisualDataModule->ColorMenuItem->Color = C;
  8889. UpdateControls();
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8893. {
  8894. if (value != FSessionColor)
  8895. {
  8896. UpdateSessionColor(value);
  8897. // Is null when called from LastTerminalClosed
  8898. if (Terminal != NULL)
  8899. {
  8900. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8901. }
  8902. }
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8906. {
  8907. bool Result = FNoteTimer->Enabled;
  8908. if (Result)
  8909. {
  8910. // cannot cancel note too early
  8911. bool NotEarly =
  8912. (Now() - FNoteShown >
  8913. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8914. if (Force || NotEarly)
  8915. {
  8916. FNoteTimer->Enabled = false;
  8917. FNote = L"";
  8918. SAFE_DESTROY(FNoteData);
  8919. FOnNoteClick = NULL;
  8920. FNoteHints = FNotes->Text;
  8921. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8922. UpdateStatusBar();
  8923. }
  8924. }
  8925. return Result;
  8926. }
  8927. //---------------------------------------------------------------------------
  8928. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8929. {
  8930. DebugAssert(FNoteTimer->Enabled);
  8931. CancelNote(true);
  8932. }
  8933. //---------------------------------------------------------------------------
  8934. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8935. {
  8936. FNoteHints = FNotes->Text.TrimRight();
  8937. }
  8938. //---------------------------------------------------------------------------
  8939. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8940. {
  8941. int P = Note.Pos(L"\n");
  8942. if (P > 0)
  8943. {
  8944. Note.SetLength(P - 1);
  8945. }
  8946. FNotes->Add(FORMAT(L"[%s] %s",
  8947. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8948. while (FNotes->Count > 10)
  8949. {
  8950. FNotes->Delete(0);
  8951. }
  8952. if (UpdateNow)
  8953. {
  8954. UpdateNoteHints();
  8955. UpdateStatusBar();
  8956. }
  8957. }
  8958. //---------------------------------------------------------------------------
  8959. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8960. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8961. {
  8962. int P = Note.Pos(L"\n");
  8963. if (P > 0)
  8964. {
  8965. Note.SetLength(P - 1);
  8966. }
  8967. UpdateNoteHints();
  8968. FNote = Note;
  8969. SAFE_DESTROY(FNoteData);
  8970. FNoteData = NoteData;
  8971. FOnNoteClick = OnNoteClick;
  8972. AddNote(Note, false);
  8973. UpdateStatusBar();
  8974. FNoteShown = Now();
  8975. FNoteTimer->Enabled = false;
  8976. if (Seconds == 0)
  8977. {
  8978. Seconds = WinConfiguration->NotificationsTimeout;
  8979. }
  8980. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8981. FNoteTimer->Enabled = true;
  8982. }
  8983. //---------------------------------------------------------------------------
  8984. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8985. {
  8986. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8987. }
  8988. //---------------------------------------------------------------------------
  8989. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8990. {
  8991. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8992. {
  8993. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8994. }
  8995. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8996. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8997. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8998. 0, NULL, NULL);
  8999. }
  9000. //---------------------------------------------------------------------------
  9001. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9002. {
  9003. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  9004. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  9005. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  9006. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9007. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9008. }
  9009. //---------------------------------------------------------------------------
  9010. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9011. {
  9012. WinConfiguration->FormatSizeBytes = Style;
  9013. }
  9014. //---------------------------------------------------------------------------
  9015. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9016. {
  9017. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9018. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9019. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9020. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9021. }
  9022. //---------------------------------------------------------------------------
  9023. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9024. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9025. {
  9026. if (Panel->Index == 0)
  9027. {
  9028. if (FOnNoteClick != NULL)
  9029. {
  9030. // prevent the user data from being freed by possible call
  9031. // to CancelNote or PostNote during call to OnNoteClick
  9032. std::unique_ptr<TObject> NoteData(FNoteData);
  9033. TNotifyEvent OnNoteClick = FOnNoteClick;
  9034. FNoteData = NULL;
  9035. // need to cancel the note as we are going to delete its user data
  9036. CancelNote(true);
  9037. OnNoteClick(NoteData.get());
  9038. }
  9039. }
  9040. if (HasActiveTerminal() &&
  9041. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9042. {
  9043. FileSystemInfo();
  9044. }
  9045. }
  9046. //---------------------------------------------------------------------------
  9047. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9048. {
  9049. // workaround:
  9050. // 1) for unknown reason, disabling window, while minimized,
  9051. // prevents it from restoring, even if it was enabled again meanwhile
  9052. // 2) when disabling the main window, while another has focus
  9053. // minimize is no longer possible
  9054. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9055. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9056. // Shouldn't we use IsApplicationMinimized() here?
  9057. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9058. {
  9059. Enabled = false;
  9060. }
  9061. FLockLevel++;
  9062. }
  9063. //---------------------------------------------------------------------------
  9064. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9065. {
  9066. DebugAssert(FLockLevel > 0);
  9067. FLockLevel--;
  9068. if (FLockLevel == 0)
  9069. {
  9070. DebugAssert(FLockSuspendLevel == 0);
  9071. Enabled = true;
  9072. }
  9073. }
  9074. //---------------------------------------------------------------------------
  9075. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9076. {
  9077. // We need to make sure that window is enabled when the last modal window closes
  9078. // otherwise focus is not restored correctly.
  9079. // So we re-enable the window when modal window opens and
  9080. // disable it back after is closes
  9081. if (FLockLevel > 0)
  9082. {
  9083. // while we have nesting counter, we know that we never be called
  9084. // recursivelly as Application->OnModalBegin is called only
  9085. // for the top-level modal window
  9086. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9087. {
  9088. // won't be disabled when conditions in LockWindow() were not satisfied
  9089. FDisabledOnLockSuspend = !Enabled;
  9090. // When minimized to tray (or actually when set to SW_HIDE),
  9091. // setting Enabled makes the window focusable even when there's
  9092. // modal window over it
  9093. if (!FTrayIcon->Visible)
  9094. {
  9095. Enabled = true;
  9096. }
  9097. }
  9098. FLockSuspendLevel++;
  9099. }
  9100. }
  9101. //---------------------------------------------------------------------------
  9102. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9103. {
  9104. if (FLockSuspendLevel > 0)
  9105. {
  9106. DebugAssert(FLockLevel > 0);
  9107. FLockSuspendLevel--;
  9108. // see comment in SuspendWindowLock
  9109. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9110. {
  9111. // Note that window can be enabled here, when we were minized to tray when
  9112. // was SuspendWindowLock() called.
  9113. // We should possibly do the same check as in LockWindow(),
  9114. // if it is ever possible that the consitions change between
  9115. // SuspendWindowLock() and ResumeWindowLock()
  9116. Enabled = !FDisabledOnLockSuspend;
  9117. }
  9118. }
  9119. }
  9120. //---------------------------------------------------------------------------
  9121. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9122. {
  9123. TTBXComboBoxItem * RemotePathComboBox =
  9124. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9125. if (!TextOnly)
  9126. {
  9127. TStrings * Items = RemotePathComboBox->Strings;
  9128. Items->BeginUpdate();
  9129. try
  9130. {
  9131. Items->Clear();
  9132. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9133. {
  9134. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9135. while (!IsUnixRootPath(APath))
  9136. {
  9137. int P = APath.LastDelimiter(L'/');
  9138. DebugAssert(P >= 0);
  9139. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9140. APath.SetLength(P - 1);
  9141. }
  9142. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9143. }
  9144. }
  9145. __finally
  9146. {
  9147. Items->EndUpdate();
  9148. }
  9149. }
  9150. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9151. // Setting ItemIndex to -1 does not reset its text
  9152. if (RemotePathComboBox->Strings->Count == 0)
  9153. {
  9154. RemotePathComboBox->Text = L"";
  9155. }
  9156. }
  9157. //---------------------------------------------------------------------------
  9158. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9159. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9160. {
  9161. if (AIndex < 0)
  9162. {
  9163. AIndex = Sender->ItemIndex;
  9164. }
  9165. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9166. }
  9167. //---------------------------------------------------------------------------
  9168. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9169. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9170. int & ImageIndex)
  9171. {
  9172. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9173. }
  9174. //---------------------------------------------------------------------------
  9175. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9176. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9177. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9178. {
  9179. if (!IsLocalBrowserMode())
  9180. {
  9181. ARect.Left += (10 * AIndex);
  9182. }
  9183. }
  9184. //---------------------------------------------------------------------------
  9185. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9186. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9187. {
  9188. AWidth += (10 * AIndex);
  9189. }
  9190. //---------------------------------------------------------------------------
  9191. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9192. {
  9193. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9194. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9195. int Index = RemotePathComboBox->ItemIndex;
  9196. while (Index < RemotePathComboBox->Strings->Count - 1)
  9197. {
  9198. APath = UnixExtractFileDir(APath);
  9199. Index++;
  9200. }
  9201. // VanDyke style paths
  9202. if (APath.IsEmpty())
  9203. {
  9204. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9205. APath = ROOTDIRECTORY;
  9206. }
  9207. if (RemoteDirView->Path != APath)
  9208. {
  9209. RemoteDirView->Path = APath;
  9210. }
  9211. }
  9212. //---------------------------------------------------------------------------
  9213. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9214. {
  9215. DoRemotePathComboBoxItemClick(Sender);
  9216. }
  9217. //---------------------------------------------------------------------------
  9218. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9219. {
  9220. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9221. DebugUsedParam(Sender);
  9222. UpdateRemotePathComboBox(true);
  9223. }
  9224. //---------------------------------------------------------------------------
  9225. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9226. {
  9227. DoRemotePathComboBoxCancel(Sender);
  9228. }
  9229. //---------------------------------------------------------------------------
  9230. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9231. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9232. {
  9233. ResetIncrementalSearch();
  9234. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9235. DebugAssert(DirView != NULL);
  9236. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9237. {
  9238. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9239. // OnEditing is called also from TCustomListView::CanEdit
  9240. if (Edit != NULL)
  9241. {
  9242. EditSelectBaseName(Edit);
  9243. }
  9244. }
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. //---------------------------------------------------------------------------
  9248. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9249. {
  9250. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9251. Result->AutoDetectDnD = false;
  9252. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9253. Result->RenderDataOn = rdoEnterAndDropSync;
  9254. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9255. return Result;
  9256. }
  9257. //---------------------------------------------------------------------------
  9258. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9259. {
  9260. if (IsWin10Build(2004))
  9261. {
  9262. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9263. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9264. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9265. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9266. }
  9267. }
  9268. //---------------------------------------------------------------------------
  9269. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9270. {
  9271. TForm::CreateWnd();
  9272. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9273. UpdateDarkMode();
  9274. if (FSessionsDragDropFilesEx == NULL)
  9275. {
  9276. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9277. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9278. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9279. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9280. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9281. }
  9282. if (FQueueDragDropFilesEx == NULL)
  9283. {
  9284. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9285. // No need to set OnDragOver as we do not have any restrictions
  9286. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9287. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9288. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9289. }
  9290. }
  9291. //---------------------------------------------------------------------------
  9292. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9293. {
  9294. TForm::DestroyWnd();
  9295. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9296. FQueueDragDropFilesEx->DragDropControl = NULL;
  9297. }
  9298. //---------------------------------------------------------------------------
  9299. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9300. {
  9301. SideEnter(FCurrentSide);
  9302. FEverShown = true;
  9303. }
  9304. //---------------------------------------------------------------------------
  9305. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9306. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9307. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9308. {
  9309. if (!NonVisualDataModule->Busy)
  9310. {
  9311. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9312. Configuration->Usage->Inc(L"FileFinds");
  9313. LockWindow(true);
  9314. NonVisualDataModule->StartBusy();
  9315. WinConfiguration->LockedInterface = true;
  9316. try
  9317. {
  9318. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9319. }
  9320. __finally
  9321. {
  9322. WinConfiguration->LockedInterface = false;
  9323. NonVisualDataModule->EndBusy();
  9324. UnlockWindow();
  9325. }
  9326. }
  9327. }
  9328. //---------------------------------------------------------------------------
  9329. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9330. {
  9331. if (!NonVisualDataModule->Busy)
  9332. {
  9333. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9334. SetFocus();
  9335. RemoteDirView->Path = UnixExtractFilePath(Path);
  9336. UnicodeString FileName = UnixExtractFileName(Path);
  9337. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9338. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9339. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9340. if (Item == NULL)
  9341. {
  9342. ReloadDirectory(osRemote);
  9343. Item = RemoteDirView->FindFileItem(FileName);
  9344. }
  9345. if (Item != NULL)
  9346. {
  9347. RemoteDirView->ItemFocused = Item;
  9348. RemoteDirView->ItemFocused->MakeVisible(false);
  9349. RemoteDirView->SetFocus();
  9350. }
  9351. }
  9352. }
  9353. //---------------------------------------------------------------------------
  9354. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9355. {
  9356. bool Result = !NonVisualDataModule->Busy;
  9357. if (Result)
  9358. {
  9359. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9360. }
  9361. return Result;
  9362. }
  9363. //---------------------------------------------------------------------------
  9364. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9365. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9366. {
  9367. if (CanOperateOnFoundFiles(ATerminal))
  9368. {
  9369. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9370. FOnFileOperationFinished = OnFileOperationFinished;
  9371. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9372. }
  9373. }
  9374. //---------------------------------------------------------------------------
  9375. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9376. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9377. {
  9378. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9379. }
  9380. //---------------------------------------------------------------------------
  9381. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9382. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9383. {
  9384. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9385. }
  9386. //---------------------------------------------------------------------------
  9387. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9388. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9389. {
  9390. if (CanOperateOnFoundFiles(ATerminal))
  9391. {
  9392. for (int Index = 0; Index < FileList->Count; Index++)
  9393. {
  9394. UnicodeString FileName = FileList->Strings[Index];
  9395. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9396. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9397. OnFileOperationFinished(FileName, true);
  9398. }
  9399. }
  9400. }
  9401. //---------------------------------------------------------------------------
  9402. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9403. {
  9404. FFileFindTerminal = Terminal;
  9405. ShowFileFindDialog(
  9406. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9407. DoDownloadFoundFiles, DoEditFoundFiles);
  9408. }
  9409. //---------------------------------------------------------------------------
  9410. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9411. {
  9412. FTaskbarList = TaskbarList;
  9413. }
  9414. //---------------------------------------------------------------------------
  9415. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9416. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9417. {
  9418. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9419. if (Index >= 0)
  9420. {
  9421. if (Button == mbLeft)
  9422. {
  9423. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  9424. // If switching tab (switching session) takes long enough for user
  9425. // to actually release the button, "mouse down" is still raised,
  9426. // but we do not get "mouse up" event, so dragging is not cancelled,
  9427. // prevent that by not beginning dragging in the first place.
  9428. if (IsKeyPressed(VK_LBUTTON))
  9429. {
  9430. // when user clicks the "+", we get mouse down only after the session
  9431. // is closed, when new session tab is already on X:Y, so dragging
  9432. // starts, prevent that
  9433. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  9434. {
  9435. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9436. if (Terminal != NULL)
  9437. {
  9438. SessionsPageControl->BeginDrag(false);
  9439. }
  9440. }
  9441. }
  9442. }
  9443. else if (Button == mbMiddle)
  9444. {
  9445. // ignore middle-click for "New session tab" and the last local-local tab
  9446. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9447. if ((Session != NULL) && CanCloseSession(Session))
  9448. {
  9449. CloseSessionTab(Index);
  9450. }
  9451. }
  9452. }
  9453. }
  9454. //---------------------------------------------------------------------------
  9455. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9456. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9457. {
  9458. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9459. // do not allow dropping on the "+" tab
  9460. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9461. if ((TargetTerminal != NULL) &&
  9462. (SessionsPageControl->ActivePage->PageIndex != Index))
  9463. {
  9464. Configuration->Usage->Inc(L"SessionTabMoves");
  9465. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9466. // but we want to actually prevent that to avoid flicker
  9467. SessionsPageControl->ActivePage->PageIndex = Index;
  9468. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9469. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9470. }
  9471. }
  9472. //---------------------------------------------------------------------------
  9473. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9474. TObject * Sender, TObject * Source, int X, int Y,
  9475. TDragState /*State*/, bool & Accept)
  9476. {
  9477. Accept = (Sender == Source);
  9478. if (Accept)
  9479. {
  9480. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9481. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9482. // do not allow dragging to the "+" tab
  9483. Accept = (Terminal != NULL);
  9484. }
  9485. }
  9486. //---------------------------------------------------------------------------
  9487. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9488. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9489. {
  9490. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9491. if (Index < 0)
  9492. {
  9493. Effect = DROPEFFECT_NONE;
  9494. }
  9495. else
  9496. {
  9497. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9498. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  9499. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  9500. {
  9501. Effect = DROPEFFECT_NONE;
  9502. }
  9503. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  9504. {
  9505. Effect = DROPEFFECT_COPY;
  9506. }
  9507. }
  9508. }
  9509. //---------------------------------------------------------------------------
  9510. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9511. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9512. {
  9513. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9514. // do not allow dropping on local-local, disconnected and the "+" tab
  9515. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  9516. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9517. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  9518. {
  9519. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9520. if (!IsFileControl(DropSourceControl, osRemote))
  9521. {
  9522. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9523. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9524. // Why don't we use Terminal->CurrentDirectory directly?
  9525. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9526. // do not force queue, drag drop
  9527. false, true);
  9528. }
  9529. }
  9530. }
  9531. //---------------------------------------------------------------------------
  9532. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9533. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9534. {
  9535. // Downloads are handled in RemoteFileControlDDEnd
  9536. if (!IsFileControl(DropSourceControl, osRemote))
  9537. {
  9538. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9539. Terminal->CurrentDirectory,
  9540. // force queue, drag drop
  9541. true, true);
  9542. }
  9543. }
  9544. //---------------------------------------------------------------------------
  9545. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9546. {
  9547. FShowing = false;
  9548. // Do not save empty workspace
  9549. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  9550. {
  9551. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9552. UnicodeString Name = WorkspaceName();
  9553. DoSaveWorkspace(
  9554. Name, DataList.get(),
  9555. !Configuration->DisablePasswordStoring &&
  9556. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9557. WinConfiguration->LastStoredSession = Name;
  9558. }
  9559. }
  9560. //---------------------------------------------------------------------------
  9561. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9562. {
  9563. TManagedTerminal * ManagedTerminal =
  9564. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9565. if (ManagedTerminal != NULL)
  9566. {
  9567. ManagedTerminal->DirectoryLoaded = Now();
  9568. }
  9569. }
  9570. //---------------------------------------------------------------------------
  9571. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9572. TListItem * /*Item*/, bool /*Selected*/)
  9573. {
  9574. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9575. switch (DirView->LastSelectMethod)
  9576. {
  9577. case smKeyboard:
  9578. Configuration->Usage->Inc(L"KeyboardSelections");
  9579. break;
  9580. case smMouse:
  9581. Configuration->Usage->Inc(L"MouseSelections");
  9582. break;
  9583. }
  9584. }
  9585. //---------------------------------------------------------------------------
  9586. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9587. {
  9588. if (Color != 0)
  9589. {
  9590. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9591. }
  9592. else
  9593. {
  9594. return FSessionTabImageIndex;
  9595. }
  9596. }
  9597. //---------------------------------------------------------------------------
  9598. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9599. {
  9600. TPngImageCollectionItem * Item =
  9601. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9602. FSessionColors->AddPng(Item->PngImage);
  9603. return FSessionColors->Count - 1;
  9604. }
  9605. //---------------------------------------------------------------------------
  9606. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9607. {
  9608. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9609. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  9610. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  9611. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9612. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9613. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  9614. }
  9615. //---------------------------------------------------------------------------
  9616. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  9617. {
  9618. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  9619. }
  9620. //---------------------------------------------------------------------------
  9621. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  9622. {
  9623. switch (Side)
  9624. {
  9625. case osLocal:
  9626. return FNewLocalTabTabImageIndex;
  9627. case osRemote:
  9628. case osCurrent:
  9629. return FNewRemoteTabTabImageIndex;
  9630. default:
  9631. DebugFail();
  9632. return -1;
  9633. }
  9634. }
  9635. //---------------------------------------------------------------------------
  9636. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9637. {
  9638. for (int Index = 0; Index < Control->ControlCount; Index++)
  9639. {
  9640. TControl * AControl = Control->Controls[Index];
  9641. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9642. if (WinControl != NULL)
  9643. {
  9644. CollectItemsWithTextDisplayMode(WinControl);
  9645. }
  9646. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9647. if (Toolbar != NULL)
  9648. {
  9649. // we care for top-level items only
  9650. TTBCustomItem * Items = Toolbar->Items;
  9651. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9652. {
  9653. TTBCustomItem * Item = Items->Items[ItemIndex];
  9654. if (((Item->DisplayMode == nbdmImageAndText) ||
  9655. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9656. EligibleForImageDisplayMode(Item))
  9657. {
  9658. FItemsWithTextDisplayMode.insert(Item);
  9659. }
  9660. }
  9661. }
  9662. }
  9663. }
  9664. //---------------------------------------------------------------------------
  9665. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9666. {
  9667. return true;
  9668. }
  9669. //---------------------------------------------------------------------------
  9670. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9671. {
  9672. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9673. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9674. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9675. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9676. bool Result = true;
  9677. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9678. {
  9679. TTBCustomItem * Item = *i;
  9680. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9681. if (Label != NULL)
  9682. {
  9683. // optimization
  9684. if (Label->Visible == SelectiveToolbarText)
  9685. {
  9686. Result = false;
  9687. }
  9688. else
  9689. {
  9690. Label->Visible = SelectiveToolbarText;
  9691. }
  9692. }
  9693. else
  9694. {
  9695. // optimization
  9696. if (Item->DisplayMode == DisplayMode)
  9697. {
  9698. Result = false;
  9699. }
  9700. else
  9701. {
  9702. Item->DisplayMode = DisplayMode;
  9703. }
  9704. }
  9705. ++i;
  9706. }
  9707. UpdateNewTabTab();
  9708. return Result;
  9709. }
  9710. //---------------------------------------------------------------------------
  9711. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9712. {
  9713. DebugFail();
  9714. }
  9715. //---------------------------------------------------------------------------
  9716. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9717. {
  9718. // Among other, a lock level is non zero, while directory is being loaded,
  9719. // even when it happens as a result of dirview navigation,
  9720. // i.e. when TNonVisualDataModule is NOT FBusy.
  9721. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9722. // Among other this prevents a panel auto update to occur while
  9723. // directory is changing.
  9724. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9725. }
  9726. //---------------------------------------------------------------------------
  9727. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9728. {
  9729. // While the window is disabled, we still seem to process menu shortcuts at least,
  9730. // so stop it at least here.
  9731. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9732. bool Result;
  9733. if (Allowed == aaUpdate)
  9734. {
  9735. Result = true;
  9736. }
  9737. else
  9738. {
  9739. Result = !NonVisualDataModule->Busy;
  9740. if (Result && (Allowed == aaShortCut))
  9741. {
  9742. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9743. Action->Update();
  9744. Result = Action->Enabled;
  9745. }
  9746. }
  9747. return Result;
  9748. }
  9749. //---------------------------------------------------------------------------
  9750. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9751. {
  9752. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9753. }
  9754. //---------------------------------------------------------------------------
  9755. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9756. {
  9757. // This is somewhat redundant to LockWindow() call from
  9758. // TTerminalManager::TerminalReadDirectoryProgress.
  9759. // But disabling window is known not to block keyboard shorcuts
  9760. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9761. if (Busy > 0)
  9762. {
  9763. if (NonVisualDataModule->Busy)
  9764. {
  9765. State = false;
  9766. }
  9767. else
  9768. {
  9769. NonVisualDataModule->StartBusy();
  9770. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9771. LockWindow();
  9772. }
  9773. }
  9774. else if (Busy < 0)
  9775. {
  9776. UnlockWindow();
  9777. NonVisualDataModule->EndBusy();
  9778. }
  9779. else
  9780. {
  9781. State = NonVisualDataModule->Busy;
  9782. }
  9783. }
  9784. //---------------------------------------------------------------------------
  9785. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9786. {
  9787. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9788. if (Index >= 0)
  9789. {
  9790. TPopupMenu * PopupMenu = NULL;
  9791. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9792. if (Session != NULL)
  9793. {
  9794. SessionsPageControl->ActivePageIndex = Index;
  9795. if (DebugAlwaysTrue(SessionTabSwitched()))
  9796. {
  9797. // copied from TControl.WMContextMenu
  9798. SendCancelMode(SessionsPageControl);
  9799. // explicit popup instead of using PopupMenu property
  9800. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9801. // while connecting yet not-connected session and hence
  9802. // allowing an access to commands over not-completelly connected session
  9803. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  9804. }
  9805. }
  9806. else
  9807. {
  9808. if (SupportsLocalBrowser())
  9809. {
  9810. PopupMenu = NonVisualDataModule->NewTabPopup;
  9811. }
  9812. }
  9813. if (PopupMenu != NULL)
  9814. {
  9815. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9816. PopupMenu->PopupComponent = SessionsPageControl;
  9817. PopupMenu->Popup(Point.x, Point.y);
  9818. }
  9819. }
  9820. Handled = true;
  9821. }
  9822. //---------------------------------------------------------------------------
  9823. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9824. {
  9825. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9826. }
  9827. //---------------------------------------------------------------------------
  9828. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9829. {
  9830. Configuration->Usage->Inc(L"PasswordChanges");
  9831. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9832. ChangePasswordData->DisableAuthentationsExceptPassword();
  9833. ChangePasswordData->ChangePassword = true;
  9834. std::unique_ptr<TTerminal> ChangePasswordSession(
  9835. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9836. ChangePasswordSession->AutoReadDirectory = false;
  9837. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9838. {
  9839. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9840. }
  9841. else
  9842. {
  9843. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9844. }
  9845. }
  9846. //---------------------------------------------------------------------------
  9847. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9848. {
  9849. // No nice way to assert SSH2
  9850. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9851. }
  9852. //---------------------------------------------------------------------------
  9853. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9854. {
  9855. TOperationVisualizer OperationVisualizer;
  9856. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9857. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9858. }
  9859. //---------------------------------------------------------------------------
  9860. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9861. {
  9862. TForm::ChangeScale(M, D);
  9863. int APixelsPerInch = GetControlPixelsPerInch(this);
  9864. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9865. try
  9866. {
  9867. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9868. }
  9869. __finally
  9870. {
  9871. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9872. }
  9873. }
  9874. //---------------------------------------------------------------------------
  9875. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9876. {
  9877. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9878. }
  9879. //---------------------------------------------------------------------
  9880. class TPublicControl : public TControl
  9881. {
  9882. friend class TCustomScpExplorerForm;
  9883. };
  9884. //---------------------------------------------------------------------------
  9885. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9886. {
  9887. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9888. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9889. }
  9890. //---------------------------------------------------------------------------
  9891. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9892. {
  9893. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9894. OpenBookmark(Side, Bookmark);
  9895. }
  9896. //---------------------------------------------------------------------------
  9897. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9898. {
  9899. DoBookmarkClick(osLocal, Sender);
  9900. }
  9901. //---------------------------------------------------------------------------
  9902. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9903. {
  9904. DoBookmarkClick(osRemote, Sender);
  9905. }
  9906. //---------------------------------------------------------------------------
  9907. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9908. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9909. {
  9910. if (BookmarkList != NULL)
  9911. {
  9912. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9913. if (IsLocalBrowserMode())
  9914. {
  9915. Side = osLocal;
  9916. }
  9917. if (!WinConfiguration->UseLocationProfiles)
  9918. {
  9919. std::unique_ptr<TStringList> Directories(new TStringList());
  9920. Directories->CaseSensitive = (Side == osRemote);
  9921. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9922. {
  9923. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9924. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9925. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9926. {
  9927. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9928. Item->Caption = EscapeHotkey(Directory);
  9929. Item->ShortCut = Bookmark->ShortCut;
  9930. Item->OnClick = OnBookmarkClick;
  9931. Item->Tag = reinterpret_cast<int>(Bookmark);
  9932. Directories->Add(Directory);
  9933. Menu->Add(Item.release());
  9934. }
  9935. }
  9936. }
  9937. else
  9938. {
  9939. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9940. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9941. {
  9942. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9943. if (!Bookmark->Node.IsEmpty())
  9944. {
  9945. Folders->Add(Bookmark->Node);
  9946. }
  9947. }
  9948. for (int Index = 0; Index < Folders->Count; Index++)
  9949. {
  9950. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9951. Item->Caption = Folders->Strings[Index];
  9952. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9953. Folders->Objects[Index] = Item.get();
  9954. Menu->Add(Item.release());
  9955. }
  9956. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9957. {
  9958. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9959. TTBCustomItem * Parent;
  9960. if (!Bookmark->Node.IsEmpty())
  9961. {
  9962. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9963. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9964. }
  9965. else
  9966. {
  9967. Parent = Menu;
  9968. }
  9969. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9970. Item->Caption = Bookmark->Name;
  9971. Item->ShortCut = Bookmark->ShortCut;
  9972. Item->OnClick = OnBookmarkClick;
  9973. Item->Tag = reinterpret_cast<int>(Bookmark);
  9974. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9975. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9976. {
  9977. // No hint for location profiles that are actually mere "bookmarks"
  9978. }
  9979. else
  9980. {
  9981. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9982. UnicodeString LongHint;
  9983. if (!Bookmark->Local.IsEmpty())
  9984. {
  9985. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9986. }
  9987. if (!Bookmark->Remote.IsEmpty())
  9988. {
  9989. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9990. }
  9991. AddToList(Hint, LongHint, L"|");
  9992. Item->Hint = Hint;
  9993. }
  9994. Parent->Add(Item.release());
  9995. }
  9996. }
  9997. AddMenuSeparator(Menu);
  9998. }
  9999. }
  10000. //---------------------------------------------------------------------------
  10001. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10002. {
  10003. Menu->Clear();
  10004. std::unique_ptr<TTBCustomItem> Item;
  10005. Item.reset(new TTBXItem(Owner));
  10006. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10007. Item->Options = Item->Options << tboDefault;
  10008. Menu->Add(Item.release());
  10009. AddMenuSeparator(Menu);
  10010. if (Terminal != NULL)
  10011. {
  10012. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10013. }
  10014. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10015. Item.reset(new TTBXItem(Owner));
  10016. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10017. Menu->Add(Item.release());
  10018. }
  10019. //---------------------------------------------------------------------------
  10020. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10021. {
  10022. bool Result = true;
  10023. bool Remote = !IsSideLocalBrowser(Side);
  10024. try
  10025. {
  10026. if (Remote)
  10027. {
  10028. Terminal->ExceptionOnFail = true;
  10029. }
  10030. try
  10031. {
  10032. DirView(Side)->Path = Path;
  10033. }
  10034. __finally
  10035. {
  10036. if (Remote)
  10037. {
  10038. Terminal->ExceptionOnFail = false;
  10039. }
  10040. }
  10041. }
  10042. catch (Exception & E)
  10043. {
  10044. if (!Remote || Terminal->Active)
  10045. {
  10046. ShowExtendedExceptionEx(Terminal, &E);
  10047. Result = false;
  10048. }
  10049. else
  10050. {
  10051. throw;
  10052. }
  10053. }
  10054. return Result;
  10055. }
  10056. //---------------------------------------------------------------------------
  10057. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10058. {
  10059. // Make sure there some feedback even when loading tiny local folders
  10060. TInstantOperationVisualizer Visualizer;
  10061. DirView(Side)->ReloadDirectory();
  10062. }
  10063. //---------------------------------------------------------------------------
  10064. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10065. {
  10066. if (Index == SessionsPageControl->TabIndex)
  10067. {
  10068. CloseSession();
  10069. }
  10070. else
  10071. {
  10072. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10073. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10074. TTerminalManager * Manager = TTerminalManager::Instance();
  10075. if (!Terminal->Active)
  10076. {
  10077. Manager->FreeTerminal(Terminal);
  10078. }
  10079. else
  10080. {
  10081. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10082. if (CanCloseQueue(Queue))
  10083. {
  10084. Manager->FreeTerminal(Terminal);
  10085. }
  10086. }
  10087. }
  10088. }
  10089. //---------------------------------------------------------------------------
  10090. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10091. {
  10092. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10093. if (Session == NULL)
  10094. {
  10095. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10096. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10097. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10098. //P = SessionsPageControl->ClientToScreen(P);
  10099. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10100. }
  10101. else
  10102. {
  10103. CloseSessionTab(Index);
  10104. }
  10105. }
  10106. //---------------------------------------------------------------------------
  10107. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10108. {
  10109. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10110. {
  10111. TInstantOperationVisualizer Visualizer;
  10112. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10113. // before we create a new data object
  10114. ClipboardClear();
  10115. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10116. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10117. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10118. // Intermediate variable to WORKAROUND a crash in compiler
  10119. TObjectList * ClipboardFakeMonitors =
  10120. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10121. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10122. if (FClipboardDragDropFilesEx.get() == NULL)
  10123. {
  10124. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10125. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10126. }
  10127. FClipboardDragDropFilesEx->FileList->Clear();
  10128. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10129. FClipboardDragDropFilesEx->CopyToClipboard();
  10130. FClipboardTerminal = Terminal;
  10131. // Need full paths, as cwd can be different once files are pasted
  10132. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10133. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10134. {
  10135. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10136. }
  10137. }
  10138. }
  10139. //---------------------------------------------------------------------------
  10140. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10141. {
  10142. if (OpenClipboard(0))
  10143. {
  10144. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10145. CloseClipboard();
  10146. }
  10147. }
  10148. //---------------------------------------------------------------------------
  10149. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10150. {
  10151. return !FClipboardFakeDirectory.IsEmpty();
  10152. }
  10153. //---------------------------------------------------------------------------
  10154. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10155. {
  10156. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10157. FClipboardFakeDirectory = UnicodeString();
  10158. FClipboardTerminal = NULL;
  10159. // Also called in Idle()
  10160. FClipboardFakeMonitors.reset(NULL);
  10161. }
  10162. //---------------------------------------------------------------------------
  10163. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10164. {
  10165. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10166. {
  10167. ClipboardStop();
  10168. }
  10169. }
  10170. //---------------------------------------------------------------------------
  10171. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10172. {
  10173. TTerminalManager * Manager = TTerminalManager::Instance();
  10174. Manager->ActiveSession = FClipboardTerminal;
  10175. TTransferOperationParam Params;
  10176. Params.TargetDirectory = TargetDirectory;
  10177. Params.DragDrop = DragDrop;
  10178. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10179. }
  10180. //---------------------------------------------------------------------------
  10181. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10182. {
  10183. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10184. // (as it pumps a Windows message queue while being shutted down)
  10185. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10186. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10187. {
  10188. // Can fail as it can be e.g. locked by AV, so we retry that later
  10189. bool Removed = RemoveDir(ApiPath(FileName));
  10190. try
  10191. {
  10192. if (!NonVisualDataModule->Busy)
  10193. {
  10194. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10195. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10196. }
  10197. }
  10198. __finally
  10199. {
  10200. if (!Removed)
  10201. {
  10202. RemoveDir(ApiPath(FileName));
  10203. }
  10204. }
  10205. }
  10206. }
  10207. //---------------------------------------------------------------------------
  10208. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10209. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10210. {
  10211. TFileMasks::TParams MaskParams;
  10212. MaskParams.Size = Size;
  10213. MaskParams.Modification = Modification;
  10214. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10215. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10216. {
  10217. bool ImplicitMatch;
  10218. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10219. !ImplicitMatch)
  10220. {
  10221. Color = Iter->Color;
  10222. break;
  10223. }
  10224. }
  10225. }
  10226. //---------------------------------------------------------------------------
  10227. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10228. {
  10229. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10230. if (!DirView->IsEditing())
  10231. {
  10232. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10233. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10234. // while searching
  10235. if (Key == VK_BACK)
  10236. {
  10237. if (!FIncrementalSearch.IsEmpty())
  10238. {
  10239. if (FIncrementalSearch.Length() == 1)
  10240. {
  10241. ResetIncrementalSearch();
  10242. }
  10243. else
  10244. {
  10245. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10246. IncrementalSearch(NewText, false, false);
  10247. }
  10248. Key = 0;
  10249. }
  10250. }
  10251. }
  10252. }
  10253. //---------------------------------------------------------------------------
  10254. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10255. {
  10256. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10257. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10258. {
  10259. // Filter control sequences.
  10260. // When not searching yet, prefer use of the space for toggling file selection
  10261. // (so we cannot incrementally search for a string starting with a space).
  10262. if ((Key > VK_SPACE) ||
  10263. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10264. {
  10265. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10266. Key = 0;
  10267. }
  10268. }
  10269. }
  10270. //---------------------------------------------------------------------------
  10271. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10272. {
  10273. if (!FIncrementalSearch.IsEmpty())
  10274. {
  10275. FIncrementalSearch = L"";
  10276. DirView(osCurrent)->UpdateStatusBar();
  10277. }
  10278. }
  10279. //---------------------------------------------------------------------------
  10280. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10281. {
  10282. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10283. if (Item == NULL)
  10284. {
  10285. MessageBeep(MB_ICONHAND);
  10286. }
  10287. else
  10288. {
  10289. TCustomDirView * ADirView = DirView(osCurrent);
  10290. {
  10291. TAutoNestingCounter Guard(FIncrementalSearching);
  10292. ADirView->FocusItem(Item);
  10293. if (ADirView->NortonLike == nlOff)
  10294. {
  10295. if ((ADirView->Selected != Item) ||
  10296. (ADirView->SelCount > 1))
  10297. {
  10298. ADirView->ClearSelection();
  10299. ADirView->Selected = Item;
  10300. }
  10301. }
  10302. }
  10303. FIncrementalSearch = Text;
  10304. Item->MakeVisible(false);
  10305. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10306. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10307. ADirView->UpdateStatusBar();
  10308. }
  10309. }
  10310. //---------------------------------------------------------------------------
  10311. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10312. {
  10313. int Index = Item->Index;
  10314. if (!Reverse)
  10315. {
  10316. Index++;
  10317. if (Index >= Item->Owner->Count)
  10318. {
  10319. Index = 0;
  10320. }
  10321. }
  10322. else
  10323. {
  10324. Index--;
  10325. if (Index < 0)
  10326. {
  10327. Index = Item->Owner->Count - 1;
  10328. }
  10329. }
  10330. return Item->Owner->Item[Index];
  10331. }
  10332. //---------------------------------------------------------------------------
  10333. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10334. {
  10335. TCustomDirView * ADirView = DirView(osCurrent);
  10336. if (ADirView->Items->Count == 0)
  10337. {
  10338. return NULL;
  10339. }
  10340. else
  10341. {
  10342. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10343. TListItem * Item = CurrentItem;
  10344. if (SkipCurrent)
  10345. {
  10346. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10347. }
  10348. while (true)
  10349. {
  10350. bool Matches = false;
  10351. switch (WinConfiguration->PanelSearch)
  10352. {
  10353. case isNameStartOnly:
  10354. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10355. break;
  10356. case isName:
  10357. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10358. break;
  10359. case isAll:
  10360. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10361. int Index = 0;
  10362. while ((Index < ColCount) && !Matches)
  10363. {
  10364. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10365. if (Visible)
  10366. {
  10367. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10368. }
  10369. Index++;
  10370. }
  10371. break;
  10372. }
  10373. if (Matches)
  10374. {
  10375. return Item;
  10376. }
  10377. Item = GetNextFile(Item, Reverse);
  10378. if (Item == CurrentItem)
  10379. {
  10380. return NULL;
  10381. }
  10382. }
  10383. }
  10384. }
  10385. //---------------------------------------------------------------------------
  10386. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10387. {
  10388. ResetIncrementalSearch();
  10389. }
  10390. //---------------------------------------------------------------------------
  10391. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10392. {
  10393. if (Message.CharCode == VK_TAB)
  10394. {
  10395. if (!FIncrementalSearch.IsEmpty())
  10396. {
  10397. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10398. bool Reverse = Shift.Contains(ssShift);
  10399. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10400. Message.Result = 1;
  10401. return;
  10402. }
  10403. }
  10404. else if (Message.CharCode == VK_ESCAPE)
  10405. {
  10406. if (!FIncrementalSearch.IsEmpty())
  10407. {
  10408. ResetIncrementalSearch();
  10409. Message.Result = 1;
  10410. return;
  10411. }
  10412. }
  10413. TForm::Dispatch(&Message);
  10414. }
  10415. //---------------------------------------------------------------------------
  10416. void __fastcall TCustomScpExplorerForm::Deactivate()
  10417. {
  10418. TForm::Deactivate();
  10419. // E.g. when switching to an internal editor window
  10420. ResetIncrementalSearch();
  10421. }
  10422. //---------------------------------------------------------------------------
  10423. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10424. {
  10425. // When switching to another application
  10426. ResetIncrementalSearch();
  10427. }
  10428. //---------------------------------------------------------------------------
  10429. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10430. {
  10431. ResetIncrementalSearch();
  10432. }
  10433. //---------------------------------------------------------------------------
  10434. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10435. {
  10436. if (FIncrementalSearching <= 0)
  10437. {
  10438. ResetIncrementalSearch();
  10439. }
  10440. }
  10441. //---------------------------------------------------------------------------
  10442. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10443. {
  10444. CountClicksForWindowPrint(this);
  10445. }
  10446. //---------------------------------------------------------------------------
  10447. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10448. {
  10449. CenterReconnectToolbar();
  10450. }
  10451. //---------------------------------------------------------------------------
  10452. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10453. {
  10454. if (RemoteDirView->ItemFocused != NULL)
  10455. {
  10456. RemoteDirView->ItemFocused->Selected = true;
  10457. }
  10458. }
  10459. //---------------------------------------------------------------------------
  10460. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10461. {
  10462. if (!FQueueStatusUpdating)
  10463. {
  10464. bool Refresh;
  10465. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10466. {
  10467. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10468. }
  10469. else
  10470. {
  10471. if (FQueueFileList->GetCount() > 0)
  10472. {
  10473. FQueueFileList->Clear();
  10474. Refresh = true;
  10475. }
  10476. }
  10477. int Count = FQueueFileList->GetCount();
  10478. if (QueueFileList->Items->Count != Count)
  10479. {
  10480. DebugAssert(Refresh);
  10481. QueueFileList->Items->Count = Count;
  10482. }
  10483. if (Refresh)
  10484. {
  10485. QueueFileList->Invalidate();
  10486. }
  10487. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10488. }
  10489. }
  10490. //---------------------------------------------------------------------------
  10491. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10492. {
  10493. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10494. }
  10495. //---------------------------------------------------------------------------
  10496. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10497. {
  10498. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10499. // See TSynchronizeChecklistDialog::UpdateTimer
  10500. if (QueueFileList->Items->Count > 0)
  10501. {
  10502. QueueFileList->Items->Item[0]->MakeVisible(false);
  10503. }
  10504. UpdateQueueFileList();
  10505. }
  10506. //---------------------------------------------------------------------------
  10507. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10508. {
  10509. Active = QueueView3->Focused() || QueueFileList->Focused();
  10510. }
  10511. //---------------------------------------------------------------------------
  10512. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10513. {
  10514. QueueLabelUpdateStatus();
  10515. }
  10516. //---------------------------------------------------------------------------
  10517. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10518. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10519. {
  10520. int State = FQueueFileList->GetState(Item->Index);
  10521. if (State == qfsProcessed)
  10522. {
  10523. Sender->Canvas->Font->Color = clGrayText;
  10524. }
  10525. }
  10526. //---------------------------------------------------------------------------
  10527. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10528. {
  10529. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10530. QueueFileList->Column[0]->Width =
  10531. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10532. }
  10533. //---------------------------------------------------------------------------
  10534. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10535. {
  10536. QueueFileListColumnAutoSize();
  10537. }
  10538. //---------------------------------------------------------------------------
  10539. void __fastcall TCustomScpExplorerForm::CloseApp()
  10540. {
  10541. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10542. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10543. // So we clear the flag here.
  10544. DebugAssert(NonVisualDataModule->Busy);
  10545. NonVisualDataModule->EndBusy();
  10546. try
  10547. {
  10548. Close();
  10549. }
  10550. __finally
  10551. {
  10552. NonVisualDataModule->StartBusy();
  10553. }
  10554. }
  10555. //---------------------------------------------------------------------------
  10556. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10557. {
  10558. return (Terminal != NULL) && Terminal->Active;
  10559. }
  10560. //---------------------------------------------------------------------------
  10561. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10562. {
  10563. return (ManagedSession != NULL);
  10564. }
  10565. //---------------------------------------------------------------------------
  10566. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10567. {
  10568. return IsActiveTerminal(Terminal);
  10569. }
  10570. //---------------------------------------------------------------------------
  10571. void TCustomScpExplorerForm::LocalLocalCopy(
  10572. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10573. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10574. {
  10575. DebugFail();
  10576. }
  10577. //---------------------------------------------------------------------------
  10578. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10579. {
  10580. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10581. }