CustomScpExplorer.cpp 358 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Terminal->SessionData->IsSameSite(Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if ((Terminal != NULL) && Terminal->Active &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. (Terminal != NULL) &&
  425. Terminal->Active &&
  426. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  430. {
  431. bool Result = Visible && !NonVisualDataModule->Busy;
  432. return Result;
  433. }
  434. //---------------------------------------------------------------------------
  435. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  436. const UnicodeString & CommandLine)
  437. {
  438. TProgramParams Params(CommandLine);
  439. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  440. if (Result)
  441. {
  442. NonVisualDataModule->StartBusy();
  443. try
  444. {
  445. // this action is initiated from another process,
  446. // so it's likely that our window is not visible,
  447. // and user won't see what is going on
  448. Application->BringToFront();
  449. // reload sessions as we may be asked to open a session
  450. // just stored by another instance
  451. StoredSessions->Reload();
  452. UnicodeString SessionName = Params.Param[1];
  453. std::unique_ptr<TObjectList> DataList(new TObjectList());
  454. UnicodeString DownloadFile; // unused
  455. try
  456. {
  457. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  458. }
  459. catch (EAbort &)
  460. {
  461. // Happens when opening session in PuTTY and in other situations,
  462. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  463. // to process the command-line on its own (or to pass it to yet another instance)
  464. }
  465. if (DataList->Count > 0)
  466. {
  467. TTerminalManager * Manager = TTerminalManager::Instance();
  468. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  469. }
  470. }
  471. __finally
  472. {
  473. NonVisualDataModule->EndBusy();
  474. }
  475. }
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  480. {
  481. if (FTerminal != value)
  482. {
  483. TerminalChanging();
  484. DoSetTerminal(value, false);
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  489. {
  490. FTerminal = value;
  491. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  492. FAllowTransferPresetAutoSelect = false;
  493. try
  494. {
  495. TerminalChanged(Replace);
  496. }
  497. __finally
  498. {
  499. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  500. }
  501. if (Terminal != NULL)
  502. {
  503. TransferPresetAutoSelect();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  508. {
  509. DoSetTerminal(value, true);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  513. {
  514. if (FTerminal != NULL)
  515. {
  516. UpdateTerminal(Terminal);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  521. {
  522. if (Terminal != NULL)
  523. {
  524. UpdateSessionColor((TColor)Terminal->StateData->Color);
  525. }
  526. DoTerminalListChanged();
  527. DebugAssert(!IsLocalBrowserMode()); // TODO
  528. if (Replaced)
  529. {
  530. RemoteDirView->ReplaceTerminal(Terminal);
  531. }
  532. else
  533. {
  534. RemoteDirView->Terminal = Terminal;
  535. }
  536. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  537. if (Terminal != NULL)
  538. {
  539. if (Terminal->Active)
  540. {
  541. Terminal->RefreshDirectory();
  542. }
  543. if (WinConfiguration->PreservePanelState)
  544. {
  545. if (Terminal->RemoteExplorerState != NULL)
  546. {
  547. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  548. }
  549. else
  550. {
  551. DirView(osRemote)->ClearState();
  552. }
  553. }
  554. if (!Replaced && Terminal->Active)
  555. {
  556. InitStatusBar();
  557. }
  558. }
  559. UpdateTransferList();
  560. // Update panels Enable state before refreshing the labels
  561. UpdateControls();
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  565. {
  566. if (Queue != value)
  567. {
  568. if (FQueue != NULL)
  569. {
  570. FQueue->OnListUpdate = NULL;
  571. FQueue->OnQueueItemUpdate = NULL;
  572. }
  573. FQueue = value;
  574. if (FQueue != NULL)
  575. {
  576. DebugAssert(FQueue->OnListUpdate == NULL);
  577. FQueue->OnListUpdate = QueueListUpdate;
  578. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  579. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  580. }
  581. QueueChanged();
  582. }
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  586. TListItem * Item)
  587. {
  588. if (FQueueActedItem == Item)
  589. {
  590. FQueueActedItem = NULL;
  591. if ((QueueView3->PopupMenu != NULL) &&
  592. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  593. {
  594. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  595. ReleaseCapture();
  596. }
  597. }
  598. if (Item->Data == FPendingQueueActionItem)
  599. {
  600. FPendingQueueActionItem = NULL;
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. bool TCustomScpExplorerForm::IsAnythingQueued()
  605. {
  606. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  610. {
  611. {
  612. TGuard Guard(FQueueStatusSection);
  613. FQueueStatusInvalidated = false;
  614. if (FQueue != NULL)
  615. {
  616. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  617. }
  618. }
  619. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  620. {
  621. FMaxQueueLength = FQueueStatus->Count;
  622. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  623. }
  624. {
  625. TAutoFlag Flag(FQueueStatusUpdating);
  626. FQueueController->UpdateQueueStatus(FQueueStatus);
  627. }
  628. UpdateQueueFileList();
  629. SetQueueProgress();
  630. UpdateQueueView();
  631. bool IsEmpty = !IsAnythingQueued();
  632. if (IsEmpty && (Terminal != NULL))
  633. {
  634. TOnceDoneOperation OnceDoneOperation =
  635. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  636. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  637. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  638. {
  639. FQueue->Enabled = false;
  640. }
  641. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  642. {
  643. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  649. {
  650. UnicodeString Result;
  651. if (FQueueStatus != NULL)
  652. {
  653. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  654. {
  655. TFileOperationProgressType * ProgressData =
  656. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  657. if ((ProgressData != NULL) && ProgressData->InProgress)
  658. {
  659. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  660. }
  661. }
  662. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  663. {
  664. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  665. }
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  671. {
  672. ComponentVisible[fcQueueView] =
  673. (WinConfiguration->QueueView.Show == qvShow) ||
  674. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  675. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TCustomScpExplorerForm::QueueChanged()
  679. {
  680. if (FQueueStatus != NULL)
  681. {
  682. // UpdateFileList implementation relies on the status being recreated when session changes
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. UpdateQueueFileList();
  774. }
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  779. {
  780. if (FTaskbarList != NULL)
  781. {
  782. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  783. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  784. }
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  788. {
  789. if (Progress >= 0)
  790. {
  791. if (FTaskbarList != NULL)
  792. {
  793. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  803. {
  804. int OverallProgress;
  805. // FProgressForm is null when this is called from SetQueueProgress
  806. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  807. {
  808. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  809. }
  810. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  811. {
  812. OverallProgress = ProgressData->OverallProgress();
  813. }
  814. else
  815. {
  816. OverallProgress = -1;
  817. }
  818. SetTaskbarListProgressValue(OverallProgress);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  822. {
  823. TTerminalManager::Instance()->QueueStatusUpdated();
  824. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  825. {
  826. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  827. {
  828. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  829. {
  830. TFileOperationProgressType * ProgressData = NULL;
  831. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  832. {
  833. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  834. }
  835. if ((ProgressData != NULL) &&
  836. ProgressData->InProgress)
  837. {
  838. SetTaskbarListProgressValue(ProgressData);
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. else
  846. {
  847. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  848. }
  849. }
  850. else
  851. {
  852. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  853. }
  854. }
  855. UpdateQueueLabel();
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  859. {
  860. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  861. if (FQueueStatus != NULL)
  862. {
  863. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  864. if (ActiveAndPendingPrimaryCount > 0)
  865. {
  866. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  867. }
  868. }
  869. QueueLabel->Caption = Caption;
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  873. {
  874. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  875. static_cast<TComponent*>(GetComponent(fcTransferList)));
  876. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  878. TransferList->Strings->BeginUpdate();
  879. try
  880. {
  881. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  882. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  883. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  884. if (FTransferDropDownHint.IsEmpty())
  885. {
  886. FTransferDropDownHint = TransferDropDown->Hint;
  887. }
  888. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  889. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  890. TransferDropDown->Text = StripHotkey(Name);
  891. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  892. (FTransferDropDownHint, StripHotkey(Name),
  893. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  894. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General))));
  895. // update the label, otherwise when it is updated only on the first draw
  896. // of the list, it is drawn "bold" for some reason
  897. FTransferListHoverIndex = TransferList->ItemIndex;
  898. UpdateTransferLabel();
  899. }
  900. __finally
  901. {
  902. TransferList->Strings->EndUpdate();
  903. }
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  907. {
  908. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  909. DebugAssert(Toolbar != NULL);
  910. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateActions()
  914. {
  915. TForm::UpdateActions();
  916. if (ComponentVisible[fcCustomCommandsBand])
  917. {
  918. UpdateCustomCommandsToolbar();
  919. }
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  923. {
  924. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  931. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  932. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  933. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  934. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  935. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  936. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. RemoteDirView->Invalidate();
  941. }
  942. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  943. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  944. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  945. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  946. UpdateSessionsPageControlHeight();
  947. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  948. UpdateToolbarDisplayMode();
  949. UpdateTransferList();
  950. if (Terminal != NULL)
  951. {
  952. TransferPresetAutoSelect();
  953. }
  954. UpdateQueueView();
  955. UpdateControls();
  956. // this can be called even before constuctor finishes.
  957. if (FEditorManager != NULL)
  958. {
  959. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  960. }
  961. // this can be called even before constuctor finishes.
  962. if (FLocalEditors != NULL)
  963. {
  964. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  965. {
  966. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  967. }
  968. }
  969. if (ComponentVisible[fcCustomCommandsBand])
  970. {
  971. UpdateCustomCommandsToolbar();
  972. }
  973. // show only when keeping queue items forever,
  974. // otherwise, its enough to have in in the context menu
  975. QueueDeleteAllDoneQueueToolbarItem->Visible =
  976. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  977. if (FFileColorsCurrent != WinConfiguration->FileColors)
  978. {
  979. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  980. FFileColorsCurrent = WinConfiguration->FileColors;
  981. FileColorsChanged();
  982. }
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  986. {
  987. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  988. DirView->Invalidate();
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  992. {
  993. DoFileColorsChanged(RemoteDirView);
  994. }
  995. //---------------------------------------------------------------------------
  996. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  997. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  998. void * /*Arg*/)
  999. {
  1000. if (Token != NULL)
  1001. {
  1002. TForm * Editor = dynamic_cast<TForm*>(Token);
  1003. DebugAssert(Editor != NULL);
  1004. ReconfigureEditorForm(Editor);
  1005. }
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1009. {
  1010. WinConfiguration->DDTransferConfirmation = asOn;
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1014. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1015. {
  1016. // noop
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1020. TTransferDirection Direction, TTransferType Type, bool Temp,
  1021. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1022. bool Confirm, bool DragDrop, int Options)
  1023. {
  1024. bool Result = true;
  1025. DebugAssert(Terminal && Terminal->Active);
  1026. // these parameters are known in advance
  1027. int Params =
  1028. FLAGMASK(Type == ttMove, cpDelete);
  1029. bool ToTemp = (Temp && (Direction == tdToLocal));
  1030. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1031. {
  1032. bool DisableNewerOnly =
  1033. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1034. ToTemp;
  1035. Options |=
  1036. FLAGMASK(ToTemp, coTemp) |
  1037. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1038. coDoNotShowAgain;
  1039. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1040. int CopyParamAttrs = (Direction == tdToRemote ?
  1041. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1042. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1043. int OutputOptions =
  1044. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1045. cooDoNotShowAgain);
  1046. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1047. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1048. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1049. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1050. if (Result)
  1051. {
  1052. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1053. {
  1054. if (DragDrop)
  1055. {
  1056. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1057. {
  1058. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1059. NULL, 0, EnableDDTransferConfirmation, NULL);
  1060. }
  1061. WinConfiguration->DDTransferConfirmation = asOff;
  1062. }
  1063. else
  1064. {
  1065. WinConfiguration->ConfirmTransferring = false;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. // User explicitly unchecked "do not show again",
  1071. // so show him the dialog the next time
  1072. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1073. {
  1074. WinConfiguration->DDTransferConfirmation = asOn;
  1075. }
  1076. }
  1077. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1078. }
  1079. }
  1080. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1081. {
  1082. Configuration->Usage->Inc(L"TransfersOnBackground");
  1083. // these parameter are known only after transfer dialog
  1084. Params |=
  1085. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1086. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1087. Result = false;
  1088. ClearTransferSourceSelection(Direction);
  1089. }
  1090. return Result;
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1094. {
  1095. if (FOnFileOperationFinished != NULL)
  1096. {
  1097. FOnFileOperationFinished(UnicodeString(), true);
  1098. }
  1099. else
  1100. {
  1101. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1102. if (HasDirView[Side])
  1103. {
  1104. DirView(Side)->SelectAll(smNone);
  1105. }
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1110. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1111. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1112. int Params)
  1113. {
  1114. DebugAssert(Queue != NULL);
  1115. bool SingleFile = false;
  1116. if (FileList->Count == 1)
  1117. {
  1118. if (Direction == tdToRemote)
  1119. {
  1120. UnicodeString FileName = FileList->Strings[0];
  1121. SingleFile = FileExists(ApiPath(FileName));
  1122. }
  1123. else
  1124. {
  1125. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1126. SingleFile = !File->IsDirectory;
  1127. }
  1128. }
  1129. TQueueItem * QueueItem;
  1130. if (Direction == tdToRemote)
  1131. {
  1132. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1133. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1134. }
  1135. else
  1136. {
  1137. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. AddQueueItem(Queue, QueueItem, Terminal);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1144. {
  1145. if (Queue->IsEmpty)
  1146. {
  1147. Terminal->QueueOperationStart = Now();
  1148. }
  1149. Queue->AddItem(QueueItem);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1153. {
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::InitControls()
  1157. {
  1158. DebugAssert(FDocks != NULL);
  1159. for (int Index = 0; Index < ComponentCount; Index++)
  1160. {
  1161. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1162. if ((Dock != NULL) && (Dock->Tag == 0))
  1163. {
  1164. FDocks->Add(Dock);
  1165. }
  1166. }
  1167. CollectItemsWithTextDisplayMode(this);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1171. {
  1172. ConfigurationChanged();
  1173. QueuePanel->Height =
  1174. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1175. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1176. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1177. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1178. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1179. QueueFileList->Height =
  1180. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1181. if (QueueFileList->Visible)
  1182. {
  1183. AdjustQueueLayout();
  1184. }
  1185. UpdateCustomCommandsToolbar();
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::StoreParams()
  1189. {
  1190. int APixelsPerInch = GetControlPixelsPerInch(this);
  1191. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1192. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1193. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1194. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1195. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1196. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1197. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1198. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1202. {
  1203. if (!FFormRestored)
  1204. {
  1205. FFormRestored = true;
  1206. RestoreFormParams();
  1207. }
  1208. TForm::CreateParams(Params);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1212. {
  1213. DebugAssert(FDocks != NULL);
  1214. for (int Index = 0; Index < FDocks->Count; Index++)
  1215. {
  1216. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1221. {
  1222. SetDockAllowDrag(true);
  1223. while (!ButtonsStr.IsEmpty())
  1224. {
  1225. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1226. UnicodeString Name = CutToChar(S, L'=', true);
  1227. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1228. {
  1229. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1230. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1231. {
  1232. while (!S.IsEmpty())
  1233. {
  1234. UnicodeString S2 = CutToChar(S, L',', true);
  1235. UnicodeString Name = CutToChar(S2, L':', true);
  1236. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1237. {
  1238. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1239. if (SameText(GetToolbarItemName(Item), Name))
  1240. {
  1241. // forward compatibility
  1242. UnicodeString S3 = CutToChar(S2, L':', true);
  1243. bool Visible = StrToIntDef(S3, 0);
  1244. Item->Visible = Visible;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1252. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1256. {
  1257. UnicodeString Result;
  1258. SetDockAllowDrag(true);
  1259. Result = ::GetToolbarsLayoutStr(this);
  1260. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1261. return Result;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1265. {
  1266. UnicodeString Result;
  1267. if (Item->Action != NULL)
  1268. {
  1269. Result = Item->Action->Name;
  1270. Result = RemoveSuffix(Result, L"Action");
  1271. }
  1272. else
  1273. {
  1274. Result = Item->Name;
  1275. Result = RemoveSuffix(Result, L"SubmenuItem");
  1276. Result = RemoveSuffix(Result, L"Item");
  1277. }
  1278. return Result;
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1282. {
  1283. UnicodeString Result;
  1284. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1285. {
  1286. UnicodeString ToolbarStr;
  1287. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1288. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1289. {
  1290. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1291. {
  1292. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1293. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1294. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1295. // and save the changes here only.
  1296. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1297. {
  1298. UnicodeString Name = GetToolbarItemName(Item);
  1299. DebugAssert(Name.Pos(L"TBX") == 0);
  1300. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1301. }
  1302. }
  1303. }
  1304. if (!ToolbarStr.IsEmpty())
  1305. {
  1306. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1307. }
  1308. }
  1309. return Result;
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1313. {
  1314. DebugAssert(FProgressForm == NULL);
  1315. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1316. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1317. FProgressForm->DeleteLocalToRecycleBin =
  1318. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1319. FProgressForm->DeleteRemoteToRecycleBin =
  1320. (Terminal != NULL) &&
  1321. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1322. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1323. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1324. LockWindow();
  1325. // Actually, do not know what hides the progress once the operation finishes
  1326. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1327. SetTaskbarListProgressState(TBPF_NORMAL);
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1331. {
  1332. UnlockWindow();
  1333. SAFE_DESTROY(FProgressForm);
  1334. SetQueueProgress();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1338. TFileOperationProgressType & ProgressData)
  1339. {
  1340. // Download to temporary local directory
  1341. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1342. {
  1343. bool Continue = true;
  1344. FPendingTempSpaceWarn = false;
  1345. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1346. if (!Continue)
  1347. {
  1348. Abort();
  1349. }
  1350. }
  1351. // operation is being executed and we still didn't show up progress form
  1352. if (ProgressData.InProgress && !FProgressForm)
  1353. {
  1354. CreateProgressForm(NULL);
  1355. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1356. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1357. }
  1358. // operation is finished (or terminated), so we hide progress form
  1359. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1360. {
  1361. DestroyProgressForm();
  1362. if (ProgressData.Operation == foCalculateSize)
  1363. {
  1364. // When calculating size before transfer, the abort caused by
  1365. // cancel flag set due to "MoveToQueue" below,
  1366. // is not propagated back to us in ExecuteFileOperation,
  1367. // as it is silently swallowed.
  1368. // So we explicitly (re)throw it here.
  1369. if (FMoveToQueue)
  1370. {
  1371. Abort();
  1372. }
  1373. }
  1374. else
  1375. {
  1376. if ((ProgressData.Cancel == csContinue) &&
  1377. !FAutoOperation)
  1378. {
  1379. OperationComplete(ProgressData.StartTime);
  1380. }
  1381. }
  1382. }
  1383. if (FProgressForm &&
  1384. // Can happen only during synchronization, when ending one of the operations
  1385. ProgressData.InProgress)
  1386. {
  1387. FProgressForm->SetProgressData(ProgressData);
  1388. DebugAssert(ProgressData.InProgress);
  1389. SetTaskbarListProgressValue(&ProgressData);
  1390. if (FProgressForm->Cancel > csContinue)
  1391. {
  1392. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1393. if (FProgressForm->Cancel == csCancelFile)
  1394. {
  1395. FProgressForm->ClearCancel();
  1396. }
  1397. // cancel cancels even the move
  1398. FMoveToQueue = false;
  1399. }
  1400. else if (FProgressForm->MoveToQueue)
  1401. {
  1402. FMoveToQueue = true;
  1403. ProgressData.SetCancelAtLeast(csCancel);
  1404. }
  1405. if ((FTransferResumeList != NULL) &&
  1406. ProgressData.InProgress &&
  1407. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1408. !ProgressData.FullFileName.IsEmpty())
  1409. {
  1410. if ((FTransferResumeList->Count == 0) ||
  1411. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1412. {
  1413. // note that we do not recognize directories from files here
  1414. FTransferResumeList->Add(ProgressData.FullFileName);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1421. const TDateTime & StartTime)
  1422. {
  1423. if (GUIConfiguration->BeepOnFinish &&
  1424. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1425. {
  1426. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1427. DWORD Sound;
  1428. if (!ExtractFileExt(BeepSound).IsEmpty())
  1429. {
  1430. Sound = SND_FILENAME;
  1431. }
  1432. else
  1433. {
  1434. Sound = SND_ALIAS;
  1435. }
  1436. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1437. }
  1438. }
  1439. //---------------------------------------------------------------------------
  1440. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1441. TFileOperationProgressType & ProgressData)
  1442. {
  1443. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1444. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1445. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1446. FileOperationProgress(ProgressData);
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1450. {
  1451. UnicodeString Result;
  1452. if (FProgressForm != NULL)
  1453. {
  1454. Result = FProgressForm->ProgressStr();
  1455. }
  1456. return Result;
  1457. }
  1458. //---------------------------------------------------------------------------
  1459. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1460. bool DragDrop)
  1461. {
  1462. return (!DragDrop && (DropSourceControl == NULL)) ||
  1463. (DropSourceControl == DirView(osOther));
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1467. TFileOperation Operation, TOperationSide Side,
  1468. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1469. TOnceDoneOperation & OnceDoneOperation)
  1470. {
  1471. if (!FAutoOperation)
  1472. {
  1473. // no selection on "/upload", form servers only as event handler
  1474. // (it is not displayed)
  1475. if (PanelOperation(Side, FDragDropOperation) &&
  1476. Visible && (Operation != foCalculateSize) &&
  1477. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1478. {
  1479. if (FOnFileOperationFinished != NULL)
  1480. {
  1481. FOnFileOperationFinished(FileName, Success);
  1482. }
  1483. else
  1484. {
  1485. TCustomDirView * DView = DirView(Side);
  1486. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1487. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1488. // this can happen when local drive is unplugged in the middle of the operation
  1489. if (Item != NULL)
  1490. {
  1491. if (Success) Item->Selected = false;
  1492. DView->MakeProgressVisible(Item);
  1493. }
  1494. }
  1495. }
  1496. if ((Operation == foCopy) || (Operation == foMove))
  1497. {
  1498. DebugAssert(!IsLocalBrowserMode()); // TODO
  1499. if (Side == osLocal)
  1500. {
  1501. Configuration->Usage->Inc(L"UploadedFiles");
  1502. }
  1503. else
  1504. {
  1505. Configuration->Usage->Inc(L"DownloadedFiles");
  1506. }
  1507. }
  1508. }
  1509. if (Success && (FSynchronizeController != NULL))
  1510. {
  1511. DebugAssert(!IsSideLocalBrowser(osRemote));
  1512. if (Operation == foCopy)
  1513. {
  1514. DebugAssert(Side == osLocal);
  1515. FSynchronizeController->LogOperation(soUpload, FileName);
  1516. }
  1517. else if (Operation == foDelete)
  1518. {
  1519. DebugAssert(Side == osRemote);
  1520. FSynchronizeController->LogOperation(soDelete, FileName);
  1521. }
  1522. }
  1523. if (FProgressForm)
  1524. {
  1525. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1526. }
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1530. TFileOperation Operation, TOperationSide Side,
  1531. bool Temp, const UnicodeString & FileName, Boolean Success,
  1532. TOnceDoneOperation & OnceDoneOperation)
  1533. {
  1534. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1535. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1536. OnceDoneOperation);
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1540. {
  1541. return false;
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1545. {
  1546. return false;
  1547. }
  1548. //---------------------------------------------------------------------------
  1549. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1550. {
  1551. return NULL;
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1555. {
  1556. DebugAssert(GetSide(Side) == osRemote);
  1557. DebugUsedParam(Side);
  1558. return RemoteDirView;
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1562. {
  1563. DebugAssert(GetSide(Side) == osRemote);
  1564. DebugUsedParam(Side);
  1565. return RemoteDriveView;
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1569. {
  1570. DebugAssert(GetSide(Side) == osRemote);
  1571. DebugUsedParam(Side);
  1572. return (Terminal != NULL) && Terminal->Active;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1576. TOperationSide Side, int FilesOnly)
  1577. {
  1578. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1582. TOperationSide Side, int FilesOnly)
  1583. {
  1584. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1585. }
  1586. //---------------------------------------------------------------------------
  1587. struct THistoryItemData
  1588. {
  1589. short int Side;
  1590. short int Index;
  1591. };
  1592. //---------------------------------------------------------------------------
  1593. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1594. {
  1595. DirView(Side)->HistoryGo(Index);
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1599. {
  1600. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1601. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1602. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1606. bool Back)
  1607. {
  1608. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1609. {
  1610. TCustomDirView * DView = DirView(Side);
  1611. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1612. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1613. if (ICount > 10)
  1614. {
  1615. ICount = 10;
  1616. }
  1617. Menu->Items->Clear();
  1618. THistoryItemData Data;
  1619. Data.Side = Side;
  1620. for (short int i = 1; i <= ICount; i++)
  1621. {
  1622. TTBCustomItem * Item = new TTBXItem(Menu);
  1623. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1624. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1625. Item->Hint = DView->HistoryPath[Data.Index];
  1626. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1627. Item->Tag = *reinterpret_cast<int*>(&Data);
  1628. Item->OnClick = HistoryItemClick;
  1629. Menu->Items->Add(Item);
  1630. }
  1631. }
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1635. TOperationSide Side, bool Back)
  1636. {
  1637. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1638. {
  1639. // workaround
  1640. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1641. // operator new allocates memory in Pascal code, but calls inline
  1642. // contructor in C++, leading in problems, the function does
  1643. // both in Pascal code
  1644. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1645. UpdateHistoryMenu(Side, Back);
  1646. }
  1647. return FHistoryMenu[Side == osLocal][Back];
  1648. }
  1649. //---------------------------------------------------------------------------
  1650. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1651. TCustomDirView *Sender)
  1652. {
  1653. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1654. UpdateHistoryMenu(Side, true);
  1655. UpdateHistoryMenu(Side, false);
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1659. {
  1660. // remote custom commands can be executed only if the server supports shell commands
  1661. // or have secondary shell
  1662. return (FTerminal != NULL) && FTerminal->Active && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1663. }
  1664. //---------------------------------------------------------------------------
  1665. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1666. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1667. {
  1668. int Result;
  1669. TFileCustomCommand RemoteCustomCommand;
  1670. TLocalCustomCommand LocalCustomCommand;
  1671. TFileCustomCommand * NonInteractiveCustomCommand =
  1672. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1673. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1674. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1675. if (FLAGCLEAR(Command.Params, ccLocal))
  1676. {
  1677. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1678. // custom command that does not operate with files can be executed anytime ...
  1679. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1680. {
  1681. // ... but do not show such command in remote file menu
  1682. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1683. {
  1684. Result = AllowedState;
  1685. }
  1686. else
  1687. {
  1688. Result = -1;
  1689. }
  1690. }
  1691. else
  1692. {
  1693. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1694. {
  1695. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1696. }
  1697. else
  1698. {
  1699. Result = -1;
  1700. }
  1701. }
  1702. }
  1703. else
  1704. {
  1705. // custom command that does not operate with files can be executed anytime
  1706. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1707. {
  1708. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1709. }
  1710. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1711. {
  1712. if ((ListType == ccltAll) || (ListType == ccltFile))
  1713. {
  1714. // special case is "diff"-style command that can be executed over any side,
  1715. // if we have both sides
  1716. Result =
  1717. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1718. // directly (instead of EnableSelectedOperation) to pass
  1719. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1720. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1721. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1722. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1723. }
  1724. else if (ListType == ccltBoth)
  1725. {
  1726. DebugAssert(!IsLocalBrowserMode());
  1727. Result = 1;
  1728. }
  1729. else
  1730. {
  1731. Result = -1;
  1732. }
  1733. }
  1734. else
  1735. {
  1736. if ((ListType == ccltAll) ||
  1737. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1738. {
  1739. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1740. }
  1741. else
  1742. {
  1743. Result = -1;
  1744. }
  1745. }
  1746. }
  1747. return Result;
  1748. }
  1749. //---------------------------------------------------------------------------
  1750. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1751. TStrings * FileList, const TCustomCommandType & ACommand,
  1752. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1753. {
  1754. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1755. {
  1756. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1757. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1758. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1759. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1760. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1761. bool Capture =
  1762. FLAGSET(ACommand.Params, ccShowResults) ||
  1763. FLAGSET(ACommand.Params, ccCopyResults) ||
  1764. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1765. TCaptureOutputEvent OutputEvent = NULL;
  1766. DebugAssert(FCapturedLog == NULL);
  1767. if (Capture)
  1768. {
  1769. FCapturedLog = new TStringList();
  1770. OutputEvent = TerminalCaptureLog;
  1771. }
  1772. try
  1773. {
  1774. if (!RemoteCustomCommand.IsFileCommand(Command))
  1775. {
  1776. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1777. OutputEvent);
  1778. }
  1779. else
  1780. {
  1781. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1782. }
  1783. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1784. {
  1785. if (FLAGSET(ACommand.Params, ccCopyResults))
  1786. {
  1787. CopyToClipboard(FCapturedLog);
  1788. }
  1789. if (FLAGSET(ACommand.Params, ccShowResults))
  1790. {
  1791. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1792. }
  1793. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1794. {
  1795. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1796. }
  1797. }
  1798. }
  1799. __finally
  1800. {
  1801. SAFE_DESTROY(FCapturedLog);
  1802. }
  1803. }
  1804. }
  1805. //---------------------------------------------------------------------------
  1806. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1807. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1808. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1809. {
  1810. DebugAssert(!IsLocalBrowserMode());
  1811. TStrings * LocalFileList = NULL;
  1812. TStrings * RemoteFileList = NULL;
  1813. TStrings * RemoteFileListFull = NULL;
  1814. try
  1815. {
  1816. if (LocalFileCommand)
  1817. {
  1818. if (ALocalFileList == NULL)
  1819. {
  1820. DebugAssert(HasDirView[osLocal]);
  1821. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1822. // directly (instead of EnableSelectedOperation) to pass
  1823. // false to FocusedFileOnlyWhenFocused
  1824. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1825. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1826. }
  1827. else
  1828. {
  1829. LocalFileList = ALocalFileList;
  1830. }
  1831. if (FileListCommand)
  1832. {
  1833. if (LocalFileList->Count != 1)
  1834. {
  1835. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1836. }
  1837. }
  1838. else
  1839. {
  1840. if ((LocalFileList->Count != 1) &&
  1841. (FileList->Count != 1) &&
  1842. (LocalFileList->Count != FileList->Count))
  1843. {
  1844. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1845. }
  1846. }
  1847. }
  1848. UnicodeString RootTempDir;
  1849. UnicodeString TempDir;
  1850. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1851. if (!RemoteFiles)
  1852. {
  1853. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1854. }
  1855. try
  1856. {
  1857. TDateTimes RemoteFileTimes;
  1858. if (RemoteFiles)
  1859. {
  1860. RemoteFileList = FileList;
  1861. }
  1862. else
  1863. {
  1864. RemoteFileList = new TStringList();
  1865. TMakeLocalFileListParams MakeFileListParam;
  1866. MakeFileListParam.FileList = RemoteFileList;
  1867. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1868. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1869. MakeFileListParam.Recursive =
  1870. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1871. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1872. if (!MakeFileListParam.Recursive)
  1873. {
  1874. RemoteFileTimes.clear();
  1875. RemoteFileListFull = new TStringList();
  1876. MakeFileListParam.FileList = RemoteFileListFull;
  1877. MakeFileListParam.Recursive = true;
  1878. MakeFileListParam.IncludeDirs = false;
  1879. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1880. }
  1881. else
  1882. {
  1883. RemoteFileListFull = RemoteFileList;
  1884. }
  1885. }
  1886. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1887. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1888. if (!NonBlocking)
  1889. {
  1890. int Count;
  1891. if (FileListCommand)
  1892. {
  1893. Count = 1;
  1894. }
  1895. else if (LocalFileCommand)
  1896. {
  1897. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1898. }
  1899. else
  1900. {
  1901. Count = RemoteFileList->Count;
  1902. }
  1903. Progress.Start(foCustomCommand, osRemote, Count);
  1904. DebugAssert(FProgressForm != NULL);
  1905. FProgressForm->ReadOnly = true;
  1906. }
  1907. try
  1908. {
  1909. if (FileListCommand)
  1910. {
  1911. UnicodeString LocalFile;
  1912. // MakeFileList does not delimit filenames
  1913. UnicodeString FileList = MakeFileList(RemoteFileList);
  1914. if (LocalFileCommand)
  1915. {
  1916. DebugAssert(LocalFileList->Count == 1);
  1917. LocalFile = LocalFileList->Strings[0];
  1918. }
  1919. TLocalCustomCommand CustomCommand(Data,
  1920. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1921. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1922. if (NonBlocking)
  1923. {
  1924. DebugAssert(!POutput);
  1925. ExecuteShellChecked(ShellCommand);
  1926. }
  1927. else
  1928. {
  1929. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1930. }
  1931. }
  1932. else if (LocalFileCommand)
  1933. {
  1934. if (LocalFileList->Count == 1)
  1935. {
  1936. UnicodeString LocalFile = LocalFileList->Strings[0];
  1937. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1938. {
  1939. UnicodeString FileName = RemoteFileList->Strings[Index];
  1940. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1941. Progress.SetFile(FileNameForProgress);
  1942. TLocalCustomCommand CustomCommand(Data,
  1943. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1944. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1945. TOnceDoneOperation OnceDoneOperation;
  1946. // Do not unselect anything, as it won't work with two panels anyway
  1947. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1948. }
  1949. }
  1950. else if (RemoteFileList->Count == 1)
  1951. {
  1952. UnicodeString FileName = RemoteFileList->Strings[0];
  1953. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1954. {
  1955. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1956. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1957. Progress.SetFile(LocalFileNameOnly);
  1958. TLocalCustomCommand CustomCommand(
  1959. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1960. FileName, LocalFileName, L"");
  1961. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1962. TOnceDoneOperation OnceDoneOperation;
  1963. // Do not unselect anything, as it won't work with two panels anyway
  1964. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1965. }
  1966. }
  1967. else
  1968. {
  1969. if (LocalFileList->Count != RemoteFileList->Count)
  1970. {
  1971. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1972. }
  1973. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1974. {
  1975. UnicodeString FileName = RemoteFileList->Strings[Index];
  1976. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1977. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1978. Progress.SetFile(LocalFileNameOnly); // sic
  1979. TLocalCustomCommand CustomCommand(
  1980. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1981. FileName, LocalFileName, L"");
  1982. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1983. TOnceDoneOperation OnceDoneOperation;
  1984. // Do not unselect anything, as it won't work with two panels anyway
  1985. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1986. }
  1987. }
  1988. }
  1989. else
  1990. {
  1991. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1992. {
  1993. UnicodeString FileName = RemoteFileList->Strings[Index];
  1994. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1995. Progress.SetFile(FileNameForProgress);
  1996. TLocalCustomCommand CustomCommand(Data,
  1997. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1998. FileName, L"", L"");
  1999. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2000. TOnceDoneOperation OnceDoneOperation;
  2001. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2002. }
  2003. }
  2004. }
  2005. __finally
  2006. {
  2007. if (!NonBlocking)
  2008. {
  2009. Progress.Stop();
  2010. }
  2011. }
  2012. DebugAssert(!FAutoOperation);
  2013. if (!RemoteFiles)
  2014. {
  2015. TempDir = IncludeTrailingBackslash(TempDir);
  2016. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2019. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2020. // Skip directories, process only nested files.
  2021. // The check is redundant as FileAge fails for directories anyway.
  2022. !DirectoryExists(FileName))
  2023. {
  2024. UnicodeString RemoteDir =
  2025. UnixExtractFileDir(
  2026. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2027. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2028. TDateTime NewTime;
  2029. if (FileAge(FileName, NewTime) &&
  2030. (NewTime != RemoteFileTimes[Index]))
  2031. {
  2032. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2033. TemporaryFileCopyParam(CopyParam);
  2034. CopyParam.FileMask = L"";
  2035. FAutoOperation = true;
  2036. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2037. TemporaryFilesList->Add(FileName);
  2038. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. __finally
  2045. {
  2046. FAutoOperation = false;
  2047. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2048. {
  2049. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2050. }
  2051. }
  2052. }
  2053. __finally
  2054. {
  2055. if (RemoteFileList != FileList)
  2056. {
  2057. delete RemoteFileList;
  2058. }
  2059. if (LocalFileList != ALocalFileList)
  2060. {
  2061. delete LocalFileList;
  2062. }
  2063. if (RemoteFileListFull != RemoteFileList)
  2064. {
  2065. delete RemoteFileListFull;
  2066. }
  2067. }
  2068. }
  2069. //---------------------------------------------------------------------------
  2070. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2071. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2072. bool FileListCommand, UnicodeString * POutput)
  2073. {
  2074. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2075. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2076. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2077. {
  2078. UnicodeString FileName = SelectedFileList->Strings[Index];
  2079. if (DirectoryExists(FileName))
  2080. {
  2081. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2082. {
  2083. LocalFileList->Add(FileName);
  2084. }
  2085. if (FLAGSET(ACommand.Params, ccRecursive))
  2086. {
  2087. TMakeLocalFileListParams MakeFileListParam;
  2088. MakeFileListParam.FileList = LocalFileList.get();
  2089. MakeFileListParam.FileTimes = NULL;
  2090. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2091. MakeFileListParam.Recursive = true;
  2092. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2093. }
  2094. }
  2095. else
  2096. {
  2097. LocalFileList->Add(FileName);
  2098. }
  2099. }
  2100. UnicodeString RemotePath;
  2101. if (Terminal != NULL)
  2102. {
  2103. RemotePath = Terminal->CurrentDirectory;
  2104. }
  2105. if (FileListCommand)
  2106. {
  2107. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2108. TLocalCustomCommand CustomCommand(
  2109. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2110. L"", L"", FileList);
  2111. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2112. }
  2113. else
  2114. {
  2115. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2116. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2117. DebugAssert(FProgressForm != NULL);
  2118. FProgressForm->ReadOnly = true;
  2119. try
  2120. {
  2121. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2122. {
  2123. UnicodeString FileName = LocalFileList->Strings[Index];
  2124. Progress.SetFile(FileName);
  2125. TLocalCustomCommand CustomCommand(
  2126. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2127. FileName, L"", L"");
  2128. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2129. TOnceDoneOperation OnceDoneOperation;
  2130. Progress.Finish(FileName, true, OnceDoneOperation);
  2131. }
  2132. }
  2133. __finally
  2134. {
  2135. Progress.Stop();
  2136. }
  2137. }
  2138. }
  2139. //---------------------------------------------------------------------------
  2140. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2141. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2142. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2143. {
  2144. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2145. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2146. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2147. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2148. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2149. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2150. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2151. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2152. std::unique_ptr<UnicodeString> POutput;
  2153. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2154. FLAGSET(ACommand.Params, ccCopyResults))
  2155. {
  2156. POutput.reset(new UnicodeString());
  2157. }
  2158. if (!LocalCustomCommand.IsFileCommand(Command))
  2159. {
  2160. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2161. }
  2162. // remote files?
  2163. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2164. {
  2165. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2166. }
  2167. // local files
  2168. else
  2169. {
  2170. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2171. }
  2172. if (POutput.get() != NULL)
  2173. {
  2174. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2175. int P = POutput->Pos(sLineBreak);
  2176. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2177. {
  2178. POutput->SetLength(P - 1);
  2179. }
  2180. // Copy even empty output to clipboard
  2181. if (FLAGSET(ACommand.Params, ccCopyResults))
  2182. {
  2183. CopyToClipboard(*POutput);
  2184. }
  2185. // But do not show an empty message box.
  2186. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2187. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2188. !POutput->IsEmpty())
  2189. {
  2190. TClipboardHandler ClipboardHandler;
  2191. ClipboardHandler.Text = *POutput;
  2192. TMessageParams Params;
  2193. TQueryButtonAlias Aliases[1];
  2194. Aliases[0].Button = qaRetry;
  2195. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2196. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2197. Params.Aliases = Aliases;
  2198. Params.AliasesCount = LENOF(Aliases);
  2199. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2200. }
  2201. }
  2202. }
  2203. //---------------------------------------------------------------------------
  2204. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2205. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2206. {
  2207. TCustomCommandData Data;
  2208. UnicodeString Site;
  2209. UnicodeString RemotePath;
  2210. if (Terminal != NULL)
  2211. {
  2212. Data = TCustomCommandData(Terminal);
  2213. Site = Terminal->SessionData->SessionKey;
  2214. RemotePath = Terminal->CurrentDirectory;
  2215. }
  2216. UnicodeString HelpKeyword = ACommand.HomePage;
  2217. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2218. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2219. {
  2220. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2221. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2222. {
  2223. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2224. }
  2225. else
  2226. {
  2227. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2228. }
  2229. if (!DoCustomCommandOptionsDialog(
  2230. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2231. {
  2232. Abort();
  2233. }
  2234. }
  2235. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2236. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2237. {
  2238. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2239. }
  2240. else
  2241. {
  2242. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2243. }
  2244. }
  2245. //---------------------------------------------------------------------------
  2246. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2247. const TCustomCommandType & Command)
  2248. {
  2249. DebugAssert(FCustomCommandLocalFileList != NULL);
  2250. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2251. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2252. TStrings * LocalFileList = new TStringList();
  2253. TStrings * RemoteFileList = new TStringList();
  2254. try
  2255. {
  2256. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2257. {
  2258. LocalFileList->Clear();
  2259. LocalFileList->AddObject(
  2260. FCustomCommandLocalFileList->Strings[Index],
  2261. FCustomCommandLocalFileList->Objects[Index]);
  2262. RemoteFileList->Clear();
  2263. RemoteFileList->AddObject(
  2264. FCustomCommandRemoteFileList->Strings[Index],
  2265. FCustomCommandRemoteFileList->Objects[Index]);
  2266. CustomCommand(RemoteFileList, Command, LocalFileList);
  2267. }
  2268. }
  2269. __finally
  2270. {
  2271. delete LocalFileList;
  2272. delete RemoteFileList;
  2273. }
  2274. }
  2275. //---------------------------------------------------------------------------
  2276. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2277. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2278. {
  2279. delete FCustomCommandLocalFileList;
  2280. delete FCustomCommandRemoteFileList;
  2281. // takeover ownership,
  2282. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2283. FCustomCommandLocalFileList = LocalFileList;
  2284. FCustomCommandRemoteFileList = RemoteFileList;
  2285. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2286. if (Button != NULL)
  2287. {
  2288. FCustomCommandMenu->Items->Clear();
  2289. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2290. MenuPopup(FCustomCommandMenu, Button);
  2291. }
  2292. else
  2293. {
  2294. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2295. }
  2296. }
  2297. //---------------------------------------------------------------------------
  2298. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2299. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2300. {
  2301. DebugAssert(FCapturedLog != NULL);
  2302. if ((OutputType == cotOutput) || (OutputType == cotError))
  2303. {
  2304. FCapturedLog->Add(AddedLine);
  2305. }
  2306. }
  2307. //---------------------------------------------------------------------------
  2308. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2309. TOperationSide Side)
  2310. {
  2311. return
  2312. (Side == osOther) &&
  2313. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2314. }
  2315. //---------------------------------------------------------------------------
  2316. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2317. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2318. {
  2319. TTBItemOptions O;
  2320. O = Item->Options;
  2321. TCustomDirView * DView = DirView(Side);
  2322. if ((DView->ItemFocused != NULL) &&
  2323. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2324. // when resolving links is disabled, default action is to enter the directory,
  2325. // no matter what DoubleClickAction is configured to
  2326. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2327. // Can only Edit files, but can Open/Copy even directories
  2328. ((DoubleClickAction != dcaEdit) ||
  2329. !DView->ItemIsDirectory(DView->ItemFocused)))
  2330. {
  2331. Item->Options = O << tboDefault;
  2332. }
  2333. else
  2334. {
  2335. Item->Options = O >> tboDefault;
  2336. }
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2340. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2341. {
  2342. TCustomDirView * DView = DirView(Side);
  2343. TListItem * Item = DView->ItemFocused;
  2344. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2345. EnableFocusedOperation[Side])
  2346. {
  2347. TPoint ClientPoint;
  2348. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2349. TPoint(0, 0) : MousePos;
  2350. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2351. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2352. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2353. }
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2357. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2358. {
  2359. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2360. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2361. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2362. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2363. Handled = true;
  2364. }
  2365. //---------------------------------------------------------------------------
  2366. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2367. {
  2368. }
  2369. //---------------------------------------------------------------------------
  2370. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2371. {
  2372. DebugAssert(FErrorList == NULL);
  2373. if (WinConfiguration->ContinueOnError)
  2374. {
  2375. FErrorList = new TStringList();
  2376. Configuration->Usage->Inc(L"ContinuationsOnError");
  2377. }
  2378. NonVisualDataModule->StartBusy();
  2379. }
  2380. //---------------------------------------------------------------------------
  2381. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2382. {
  2383. NonVisualDataModule->EndBusy();
  2384. if (FErrorList)
  2385. {
  2386. HandleErrorList(FErrorList);
  2387. }
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2391. const TCopyParamType & CopyParam)
  2392. {
  2393. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2394. {
  2395. Configuration->Usage->Inc(L"FileMaskUses");
  2396. }
  2397. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2398. {
  2399. Configuration->Usage->Inc(L"OperationMaskUses");
  2400. }
  2401. }
  2402. //---------------------------------------------------------------------------
  2403. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2404. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2405. {
  2406. DebugAssert(!IsLocalBrowserMode());
  2407. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2408. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2409. TTransferOperationParam DefaultParam;
  2410. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2411. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2412. switch (Param.Queue)
  2413. {
  2414. case asOn:
  2415. CopyParam.Queue = true;
  2416. break;
  2417. case asOff:
  2418. CopyParam.Queue = false;
  2419. break;
  2420. case asAuto:
  2421. default:
  2422. // keep default
  2423. break;
  2424. }
  2425. bool Result =
  2426. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2427. if (Result)
  2428. {
  2429. DebugAssert(Terminal);
  2430. bool SelectionRestored = false;
  2431. TCustomDirView * DView = NULL;
  2432. if (HasDirView[Side])
  2433. {
  2434. DView = DirView(Side);
  2435. DView->SaveSelection();
  2436. DView->SaveSelectedNames();
  2437. }
  2438. UpdateCopyParamCounters(CopyParam);
  2439. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2440. DebugAssert(FTransferResumeList == NULL);
  2441. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2442. FMoveToQueue = false;
  2443. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2444. try
  2445. {
  2446. TStrings * PermanentFileList;
  2447. std::unique_ptr<TStrings> PermanentFileListOwner;
  2448. try
  2449. {
  2450. if (Side == osLocal)
  2451. {
  2452. PermanentFileList = FileList;
  2453. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2454. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2455. if (Operation == foMove)
  2456. {
  2457. ReloadLocalDirectory();
  2458. if (DView != NULL)
  2459. {
  2460. DView->RestoreSelection();
  2461. }
  2462. SelectionRestored = true;
  2463. }
  2464. }
  2465. else
  2466. {
  2467. // Clone the file list as it may refer to current directory files,
  2468. // which get destroyed, when the source directory is reloaded after foMove operation.
  2469. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2470. // But for a hotfix, we are not going to do such a big change.
  2471. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2472. PermanentFileList = PermanentFileListOwner.get();
  2473. try
  2474. {
  2475. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2476. }
  2477. __finally
  2478. {
  2479. if (Operation == foMove)
  2480. {
  2481. if (DView != NULL)
  2482. {
  2483. DView->RestoreSelection();
  2484. }
  2485. SelectionRestored = true;
  2486. }
  2487. ReloadLocalDirectory(Param.TargetDirectory);
  2488. }
  2489. }
  2490. }
  2491. catch (EAbort &)
  2492. {
  2493. if (FMoveToQueue)
  2494. {
  2495. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2496. DebugAssert(CopyParam.TransferSkipList == NULL);
  2497. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2498. if (TransferResumeList->Count > 0)
  2499. {
  2500. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2501. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2502. }
  2503. CopyParam.TransferSkipList = TransferResumeList.release();
  2504. // not really needed, just to keep it consistent with TransferResumeList
  2505. FTransferResumeList = NULL;
  2506. FMoveToQueue = false;
  2507. Configuration->Usage->Inc("MovesToBackground");
  2508. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2509. ClearTransferSourceSelection(Direction);
  2510. }
  2511. throw;
  2512. }
  2513. }
  2514. __finally
  2515. {
  2516. if (!SelectionRestored && (DView != NULL))
  2517. {
  2518. DView->DiscardSavedSelection();
  2519. }
  2520. FTransferResumeList = NULL;
  2521. }
  2522. }
  2523. return Result;
  2524. }
  2525. //---------------------------------------------------------------------------
  2526. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2527. TOperationSide Side, TStrings * FileList, void * Param)
  2528. {
  2529. DebugAssert(FileList->Count);
  2530. // We deliberately do not toggle alternative flag (Param), but use OR,
  2531. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2532. // shortcut of CurrentDeleteAlternativeAction
  2533. bool Alternative =
  2534. bool(Param) || UseAlternativeFunction();
  2535. bool Recycle;
  2536. if (IsSideLocalBrowser(Side))
  2537. {
  2538. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2539. }
  2540. else
  2541. {
  2542. Recycle =
  2543. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2544. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2545. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2546. }
  2547. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2548. if (!Result)
  2549. {
  2550. UnicodeString Query;
  2551. if (FileList->Count == 1)
  2552. {
  2553. if (IsSideLocalBrowser(Side))
  2554. {
  2555. Query = ExtractFileName(FileList->Strings[0]);
  2556. }
  2557. else
  2558. {
  2559. Query = UnixExtractFileName(FileList->Strings[0]);
  2560. }
  2561. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2562. }
  2563. else
  2564. {
  2565. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2566. }
  2567. TMessageParams Params(mpNeverAskAgainCheck);
  2568. Params.ImageName = L"Delete file";
  2569. unsigned int Answer =
  2570. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2571. if (Answer == qaNeverAskAgain)
  2572. {
  2573. Result = true;
  2574. if (Recycle)
  2575. {
  2576. WinConfiguration->ConfirmRecycling = false;
  2577. }
  2578. else
  2579. {
  2580. WinConfiguration->ConfirmDeleting = false;
  2581. }
  2582. }
  2583. else
  2584. {
  2585. Result = (Answer == qaOK);
  2586. }
  2587. }
  2588. if (Result)
  2589. {
  2590. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2591. }
  2592. return Result;
  2593. }
  2594. //---------------------------------------------------------------------------
  2595. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2596. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2597. {
  2598. TAutoBatch AutoBatch(this);
  2599. bool Result;
  2600. if ((Operation == foCopy) || (Operation == foMove))
  2601. {
  2602. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2603. }
  2604. else if (Operation == foRename)
  2605. {
  2606. DebugAssert(DirView(Side)->ItemFocused);
  2607. DirView(Side)->ItemFocused->EditCaption();
  2608. Result = true;
  2609. }
  2610. else if (Operation == foDelete)
  2611. {
  2612. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2613. }
  2614. else if (Operation == foSetProperties)
  2615. {
  2616. DirView(osRemote)->SaveSelectedNames();
  2617. Result = SetProperties(Side, FileList);
  2618. }
  2619. else if (Operation == foCustomCommand)
  2620. {
  2621. DebugAssert(Param);
  2622. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2623. DirView(osRemote)->SaveSelectedNames();
  2624. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2625. CustomCommand(FileList, *Command, NULL);
  2626. Result = true;
  2627. }
  2628. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2629. {
  2630. DebugAssert(!IsSideLocalBrowser(Side));
  2631. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2632. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2633. }
  2634. else if (Operation == foLock)
  2635. {
  2636. DebugAssert(!IsSideLocalBrowser(Side));
  2637. LockFiles(FileList, true);
  2638. Result = true;
  2639. }
  2640. else if (Operation == foUnlock)
  2641. {
  2642. DebugAssert(!IsSideLocalBrowser(Side));
  2643. LockFiles(FileList, false);
  2644. Result = true;
  2645. }
  2646. else
  2647. {
  2648. DebugFail();
  2649. }
  2650. return Result;
  2651. }
  2652. //---------------------------------------------------------------------------
  2653. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2654. {
  2655. if (Side == osCurrent)
  2656. {
  2657. Side = FCurrentSide;
  2658. }
  2659. return Side;
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2663. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2664. {
  2665. Side = GetSide(Side);
  2666. bool Result;
  2667. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2668. try
  2669. {
  2670. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2671. }
  2672. __finally
  2673. {
  2674. delete FileList;
  2675. }
  2676. return Result;
  2677. }
  2678. //---------------------------------------------------------------------------
  2679. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2680. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2681. bool NoConfirmation, void * Param)
  2682. {
  2683. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2684. {
  2685. if ((Operation == foCopy) || (Operation == foMove))
  2686. {
  2687. DebugAssert(!IsLocalBrowserMode());
  2688. if (GetSide(Side) == osLocal)
  2689. {
  2690. Configuration->Usage->Inc(L"UploadsCommand");
  2691. }
  2692. else
  2693. {
  2694. Configuration->Usage->Inc(L"DownloadsCommand");
  2695. }
  2696. }
  2697. }
  2698. }
  2699. //---------------------------------------------------------------------------
  2700. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2701. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2702. {
  2703. TTransferOperationParam Param;
  2704. if ((WinConfiguration->Interface != ifCommander) ||
  2705. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2706. {
  2707. Flags &= ~cocShortCutHint;
  2708. }
  2709. TCustomDirView * DView = DirView(Side);
  2710. Param.Options =
  2711. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2712. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2713. if (FLAGSET(Flags, cocQueue))
  2714. {
  2715. Param.Queue = asOn;
  2716. }
  2717. else if (FLAGSET(Flags, cocNonQueue))
  2718. {
  2719. Param.Queue = asOff;
  2720. }
  2721. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2722. }
  2723. //---------------------------------------------------------------------------
  2724. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2725. {
  2726. try
  2727. {
  2728. if (ErrorList->Count)
  2729. {
  2730. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2731. if (MessageDialog(Message, qtError,
  2732. qaOK | qaCancel, HELP_NONE) == qaOK)
  2733. {
  2734. unsigned int Answer;
  2735. int Index = 0;
  2736. do
  2737. {
  2738. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2739. TQueryButtonAlias Aliases[2];
  2740. Aliases[0].Button = qaYes;
  2741. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2742. Aliases[1].Button = qaNo;
  2743. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2744. TMessageParams Params;
  2745. Params.Aliases = Aliases;
  2746. Params.AliasesCount = LENOF(Aliases);
  2747. Answer = MoreMessageDialog(
  2748. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2749. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2750. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2751. qaOK, HELP_NONE, &Params);
  2752. if (Answer == qaNo)
  2753. {
  2754. Index++;
  2755. }
  2756. if (Answer == qaYes)
  2757. {
  2758. Index--;
  2759. }
  2760. }
  2761. while (Answer != qaOK);
  2762. }
  2763. }
  2764. }
  2765. __finally
  2766. {
  2767. TStrings * List = ErrorList;
  2768. ErrorList = NULL;
  2769. for (int i = 0; i < List->Count; i++)
  2770. {
  2771. delete List->Objects[i];
  2772. }
  2773. delete List;
  2774. }
  2775. }
  2776. //---------------------------------------------------------------------------
  2777. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2778. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2779. {
  2780. // needed for checking filemasks, as there's no directory object
  2781. // associated with the file object
  2782. File->FullFileName = FullFileName;
  2783. TFileMasks::TParams MaskParams;
  2784. MaskParams.Size = File->Size;
  2785. MaskParams.Modification = File->Modification;
  2786. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2787. }
  2788. //---------------------------------------------------------------------------
  2789. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2790. {
  2791. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2792. Side = GetSide(Side);
  2793. TCustomDirView * DView = DirView(Side);
  2794. TListItem * FocusedItem = DView->ItemFocused;
  2795. UnicodeString Name;
  2796. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2797. {
  2798. Name = DView->ItemFileName(FocusedItem);
  2799. }
  2800. else
  2801. {
  2802. Name = LoadStr(NEW_FILE);
  2803. }
  2804. UnicodeString Names = Name;
  2805. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2806. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2807. HELP_EDIT_NEW, History.get(), true))
  2808. {
  2809. while (!Names.IsEmpty())
  2810. {
  2811. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2812. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2813. UnicodeString TargetFileName;
  2814. UnicodeString LocalFileName;
  2815. UnicodeString RootTempDir;
  2816. UnicodeString TempDir;
  2817. UnicodeString RemoteDirectory;
  2818. bool ExistingFile = false;
  2819. if (!IsSideLocalBrowser(Side))
  2820. {
  2821. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2822. TRemoteFile * File = NULL;
  2823. if (FTerminal->FileExists(Name, &File) &&
  2824. !File->IsDirectory)
  2825. {
  2826. try
  2827. {
  2828. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2829. ExistingFile = true;
  2830. }
  2831. __finally
  2832. {
  2833. delete File;
  2834. }
  2835. }
  2836. if (!ExistingFile)
  2837. {
  2838. RemoteDirectory = UnixExtractFilePath(Name);
  2839. TemporaryDirectoryForRemoteFiles(
  2840. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2841. TargetFileName = UnixExtractFileName(Name);
  2842. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2843. LocalFileName = TempDir +
  2844. // We probably do not want to trim the VMS version here
  2845. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2846. }
  2847. }
  2848. else
  2849. {
  2850. if (ExtractFilePath(Name).IsEmpty())
  2851. {
  2852. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2853. }
  2854. else
  2855. {
  2856. LocalFileName = ExpandFileName(Name);
  2857. }
  2858. TargetFileName = ExtractFileName(Name);
  2859. }
  2860. if (!ExistingFile)
  2861. {
  2862. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2863. if (NewFile)
  2864. {
  2865. int File = FileCreate(ApiPath(LocalFileName));
  2866. if (File < 0)
  2867. {
  2868. if (!RootTempDir.IsEmpty())
  2869. {
  2870. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2871. }
  2872. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2873. }
  2874. else
  2875. {
  2876. FileClose(File);
  2877. }
  2878. }
  2879. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2880. const TEditorData * ExternalEditor = NULL;
  2881. TFileMasks::TParams MaskParams; // size not known
  2882. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2883. false, MaskParams);
  2884. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2885. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2886. }
  2887. }
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2892. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2893. {
  2894. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2895. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2896. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2897. return
  2898. ((ExecuteFileBy == efInternalEditor)) ||
  2899. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2900. }
  2901. //---------------------------------------------------------------------------
  2902. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2903. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2904. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2905. UnicodeString RemoteDirectory, bool NewFile)
  2906. {
  2907. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2908. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2909. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2910. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2911. Side = GetSide(Side);
  2912. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2913. if (!IsSideLocalBrowser(Side))
  2914. {
  2915. Data->Terminal = Terminal;
  2916. Data->Queue = Queue;
  2917. Data->SessionData = CloneCurrentSessionData();
  2918. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2919. Data->RemoteDirectory = RemoteDirectory;
  2920. Data->SessionName = Terminal->SessionData->SessionName;
  2921. Data->LocalRootDirectory = LocalRootDirectory;
  2922. Data->OriginalFileName = OriginalFileName;
  2923. Data->Command = L""; // will be changed later for external editor
  2924. }
  2925. if (ExecuteFileBy == efInternalEditor)
  2926. {
  2927. if (!IsSideLocalBrowser(Side))
  2928. {
  2929. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2930. L" - " + Terminal->SessionData->SessionName;
  2931. TForm * Editor;
  2932. try
  2933. {
  2934. TNotifyEvent OnFileChanged = NULL;
  2935. TNotifyEvent OnSaveAll = NULL;
  2936. TAnyModifiedEvent OnAnyModified = NULL;
  2937. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2938. if (Terminal->IsCapable[fcBackgroundTransfers])
  2939. {
  2940. OnFileChanged = FEditorManager->FileChanged;
  2941. OnSaveAll = SaveAllInternalEditors;
  2942. OnAnyModified = AnyInternalEditorModified;
  2943. }
  2944. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2945. FEditorManager->FileReload, FEditorManager->FileClosed,
  2946. OnSaveAll, OnAnyModified,
  2947. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2948. }
  2949. catch(...)
  2950. {
  2951. if (!LocalRootDirectory.IsEmpty())
  2952. {
  2953. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2954. }
  2955. throw;
  2956. }
  2957. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2958. }
  2959. else
  2960. {
  2961. DebugAssert(!FStandaloneEditing);
  2962. TForm * Editor =
  2963. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2964. SaveAllInternalEditors, AnyInternalEditorModified,
  2965. L"", false, SessionColor, -1, NewFile);
  2966. FLocalEditors->Add(Editor);
  2967. }
  2968. }
  2969. else
  2970. {
  2971. HANDLE Process;
  2972. if (ExecuteFileBy == efExternalEditor)
  2973. {
  2974. UnicodeString Program, Params, Dir;
  2975. Data->Command = ExternalEditor->ExternalEditor;
  2976. ReformatFileNameCommand(Data->Command);
  2977. SplitCommand(Data->Command, Program, Params, Dir);
  2978. Params = ExpandFileNameCommand(Params, FileName);
  2979. Program = ExpandEnvironmentVariables(Program);
  2980. if (!ExecuteShell(Program, Params, Process))
  2981. {
  2982. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2983. }
  2984. }
  2985. else
  2986. {
  2987. DebugAssert(!IsSideLocalBrowser(Side));
  2988. if (!ExecuteShell(FileName, L"", Process))
  2989. {
  2990. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2991. }
  2992. }
  2993. if (IsSideLocalBrowser(Side) ||
  2994. ((ExecuteFileBy == efShell) &&
  2995. !WinConfiguration->Editor.SDIShellEditor) ||
  2996. ((ExecuteFileBy == efExternalEditor) &&
  2997. !ExternalEditor->SDIExternalEditor))
  2998. {
  2999. // no need for handle
  3000. if (Process != NULL)
  3001. {
  3002. DebugCheck(CloseHandle(Process));
  3003. }
  3004. Process = INVALID_HANDLE_VALUE;
  3005. }
  3006. else
  3007. {
  3008. if (Process == NULL)
  3009. {
  3010. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3011. }
  3012. }
  3013. if (!IsSideLocalBrowser(Side))
  3014. {
  3015. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3016. }
  3017. }
  3018. }
  3019. //---------------------------------------------------------------------------
  3020. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3021. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3022. void * /*Arg*/)
  3023. {
  3024. if (Token != NULL)
  3025. {
  3026. EditorFormFileSave(static_cast<TForm *>(Token));
  3027. }
  3028. }
  3029. //---------------------------------------------------------------------------
  3030. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3031. {
  3032. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3033. {
  3034. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3035. }
  3036. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3040. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3041. void * Arg)
  3042. {
  3043. if ((Token != NULL) &&
  3044. IsEditorFormModified(static_cast<TForm *>(Token)))
  3045. {
  3046. *static_cast<bool *>(Arg) = true;
  3047. }
  3048. }
  3049. //---------------------------------------------------------------------------
  3050. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3051. TObject * /*Sender*/, bool & Modified)
  3052. {
  3053. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3054. {
  3055. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3056. {
  3057. Modified = true;
  3058. }
  3059. }
  3060. if (!Modified)
  3061. {
  3062. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3063. }
  3064. }
  3065. //---------------------------------------------------------------------------
  3066. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3067. {
  3068. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3069. }
  3070. //---------------------------------------------------------------------------
  3071. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3072. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3073. UnicodeString & Result, UnicodeString & RootDirectory)
  3074. {
  3075. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3076. {
  3077. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3078. Result = RootDirectory;
  3079. }
  3080. else
  3081. {
  3082. RootDirectory = L"";
  3083. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3084. Result = IncludeTrailingBackslash(Result);
  3085. }
  3086. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3087. {
  3088. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3089. }
  3090. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3091. {
  3092. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3093. {
  3094. RemoteDirectory.Delete(1, 1);
  3095. }
  3096. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3097. }
  3098. if (!ForceDirectories(ApiPath(Result)))
  3099. {
  3100. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3101. }
  3102. }
  3103. //---------------------------------------------------------------------------
  3104. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3105. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3106. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3107. {
  3108. DebugAssert(!IsLocalBrowserMode());
  3109. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3110. if (ForceText)
  3111. {
  3112. CopyParam.TransferMode = tmAscii;
  3113. }
  3114. TemporaryFileCopyParam(CopyParam);
  3115. if (AllFiles)
  3116. {
  3117. CopyParam.IncludeFileMask = TFileMasks();
  3118. }
  3119. if (TempDir.IsEmpty())
  3120. {
  3121. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3122. }
  3123. DebugAssert(!FAutoOperation);
  3124. FAutoOperation = AutoOperation;
  3125. Terminal->ExceptionOnFail = true;
  3126. try
  3127. {
  3128. try
  3129. {
  3130. // turn off confirmations, as for MDI editors we may possibly download
  3131. // the same file over
  3132. Terminal->CopyToLocal(
  3133. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3134. if (GetTargetNames)
  3135. {
  3136. for (int i = 0; i < FileList->Count; i++)
  3137. {
  3138. FileList->Strings[i] =
  3139. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3140. }
  3141. }
  3142. }
  3143. catch(...)
  3144. {
  3145. if (!RootTempDir.IsEmpty())
  3146. {
  3147. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3148. }
  3149. throw;
  3150. }
  3151. }
  3152. __finally
  3153. {
  3154. FAutoOperation = false;
  3155. Terminal->ExceptionOnFail = false;
  3156. }
  3157. }
  3158. //---------------------------------------------------------------------------
  3159. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3160. {
  3161. // Do not waste time checking for default editor list the next time,
  3162. // or testing if default editor is not notepad.
  3163. bool TryNextTime = false;
  3164. UnicodeString UsageState;
  3165. if (!WinConfiguration->EditorList->IsDefaultList())
  3166. {
  3167. UsageState = "H";
  3168. }
  3169. else
  3170. {
  3171. UnicodeString Executable;
  3172. UnicodeString ExecutableDescription;
  3173. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3174. {
  3175. UnicodeString Message =
  3176. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3177. unsigned int Answer =
  3178. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3179. if (Answer != qaOK)
  3180. {
  3181. UsageState = "R";
  3182. }
  3183. else
  3184. {
  3185. UsageState = "A";
  3186. TEditorData EditorData;
  3187. EditorData.Editor = edExternal;
  3188. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3189. EditorData.ExternalEditorOptionsAutodetect();
  3190. TEditorList EditorList;
  3191. EditorList = *WinConfiguration->EditorList;
  3192. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3193. WinConfiguration->EditorList = &EditorList;
  3194. }
  3195. }
  3196. }
  3197. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3198. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3199. }
  3200. //---------------------------------------------------------------------------
  3201. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3202. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3203. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3204. {
  3205. if (ExecuteFileBy == efDefaultEditor)
  3206. {
  3207. if (!WinConfiguration->OfferedEditorAutoConfig)
  3208. {
  3209. EditorAutoConfig();
  3210. }
  3211. const TEditorPreferences * Editor =
  3212. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3213. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3214. {
  3215. ExecuteFileBy = efInternalEditor;
  3216. ExternalEditor = NULL;
  3217. }
  3218. else if (Editor->Data->Editor == edOpen)
  3219. {
  3220. ExecuteFileBy = efShell;
  3221. ExternalEditor = NULL;
  3222. }
  3223. else
  3224. {
  3225. ExecuteFileBy = efExternalEditor;
  3226. ExternalEditor = Editor->Data;
  3227. }
  3228. }
  3229. }
  3230. //---------------------------------------------------------------------------
  3231. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3232. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3233. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3234. {
  3235. UnicodeString OriginalFileName;
  3236. UnicodeString LocalRootDirectory;
  3237. UnicodeString RemoteDirectory;
  3238. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3239. IsSideLocalBrowser(Side), MaskParams);
  3240. UnicodeString Counter;
  3241. UnicodeString LocalFileName;
  3242. bool Handled = false;
  3243. if (!IsSideLocalBrowser(Side))
  3244. {
  3245. // We need to trim VMS version here, so that we use name without version
  3246. // when uploading back to create a new version of the file
  3247. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3248. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3249. TObject * Token = NULL;
  3250. UnicodeString LocalDirectory;
  3251. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3252. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3253. LocalDirectory))
  3254. {
  3255. if (Token != NULL)
  3256. {
  3257. TForm * Form = dynamic_cast<TForm *>(Token);
  3258. if (Form->WindowState == wsMinimized)
  3259. {
  3260. ShowWindow(Form->Handle, SW_RESTORE);
  3261. }
  3262. else
  3263. {
  3264. Form->SetFocus();
  3265. }
  3266. Handled = true;
  3267. }
  3268. else
  3269. {
  3270. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3271. }
  3272. }
  3273. if (!Handled)
  3274. {
  3275. TStringList * FileList1 = new TStringList();
  3276. try
  3277. {
  3278. FileList1->AddObject(FullFileName, Object);
  3279. TemporarilyDownloadFiles(FileList1,
  3280. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3281. LocalRootDirectory, LocalDirectory, true, true, true);
  3282. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3283. }
  3284. __finally
  3285. {
  3286. delete FileList1;
  3287. }
  3288. switch (ExecuteFileBy)
  3289. {
  3290. case efShell:
  3291. Counter = "RemoteFilesExecuted";
  3292. break;
  3293. case efInternalEditor:
  3294. Counter = "RemoteFilesOpenedInInternalEditor";
  3295. break;
  3296. case efExternalEditor:
  3297. Counter = "RemoteFilesOpenedInExternalEditor";
  3298. break;
  3299. default:
  3300. DebugFail();
  3301. }
  3302. }
  3303. }
  3304. else
  3305. {
  3306. LocalFileName = FullFileName;
  3307. OriginalFileName = ExtractFileName(FullFileName);
  3308. switch (ExecuteFileBy)
  3309. {
  3310. case efShell:
  3311. Counter = "LocalFilesExecuted";
  3312. break;
  3313. case efInternalEditor:
  3314. Counter = "LocalFilesOpenedInInternalEditor";
  3315. break;
  3316. case efExternalEditor:
  3317. Counter = "LocalFilesOpenedInExternalEditor";
  3318. break;
  3319. default:
  3320. DebugFail();
  3321. }
  3322. }
  3323. if (!Handled)
  3324. {
  3325. Configuration->Usage->Inc(Counter);
  3326. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3327. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3328. }
  3329. }
  3330. //---------------------------------------------------------------------------
  3331. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3332. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3333. bool AllSelected, bool OnFocused)
  3334. {
  3335. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3336. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3337. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3338. Side = GetSide(Side);
  3339. TCustomDirView * DView = DirView(Side);
  3340. TStrings * FileList =
  3341. AllSelected ?
  3342. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3343. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3344. try
  3345. {
  3346. DebugAssert(AllSelected || (FileList->Count == 1));
  3347. for (int i = 0; i < FileList->Count; i++)
  3348. {
  3349. UnicodeString ListFileName = FileList->Strings[i];
  3350. UnicodeString FileNameOnly =
  3351. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3352. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3353. if (!DView->ItemIsDirectory(Item))
  3354. {
  3355. UnicodeString FullFileName;
  3356. if (!IsSideLocalBrowser(Side))
  3357. {
  3358. FullFileName = DirView(Side)->Path + ListFileName;
  3359. }
  3360. else
  3361. {
  3362. FullFileName = ListFileName;
  3363. }
  3364. TFileMasks::TParams MaskParams;
  3365. MaskParams.Size = DView->ItemFileSize(Item);
  3366. TDateTimePrecision Precision;
  3367. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3368. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3369. FileList->Objects[i], MaskParams);
  3370. }
  3371. }
  3372. }
  3373. __finally
  3374. {
  3375. delete FileList;
  3376. }
  3377. }
  3378. //---------------------------------------------------------------------------
  3379. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3380. {
  3381. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3382. CopyParam.FileNameCase = ncNoChange;
  3383. CopyParam.PreserveRights = false;
  3384. CopyParam.PreserveReadOnly = false;
  3385. CopyParam.ReplaceInvalidChars = true;
  3386. CopyParam.IncludeFileMask = TFileMasks();
  3387. CopyParam.NewerOnly = false;
  3388. CopyParam.FileMask = L"";
  3389. }
  3390. //---------------------------------------------------------------------------
  3391. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3392. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3393. {
  3394. TTerminalManager * Manager = TTerminalManager::Instance();
  3395. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3396. {
  3397. if (!NonVisualDataModule->Busy)
  3398. {
  3399. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3400. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3401. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3402. if (Data->Terminal == NULL)
  3403. {
  3404. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3405. if (SameSiteTerminal != NULL)
  3406. {
  3407. UnicodeString Message =
  3408. FMTLOAD(EDIT_SESSION_REATTACH,
  3409. (FileNameOnly, Data->SessionName, FileNameOnly));
  3410. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3411. {
  3412. Data->Terminal = Terminal;
  3413. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3414. Data->SessionName = Terminal->SessionData->SessionName;
  3415. // We might also overwrite session data
  3416. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3417. }
  3418. else
  3419. {
  3420. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3421. Abort();
  3422. }
  3423. }
  3424. }
  3425. // foreground session should reconnect itself
  3426. else if (Terminal != Data->Terminal)
  3427. {
  3428. UnicodeString Message =
  3429. MainInstructions(
  3430. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3431. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3432. {
  3433. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3434. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3435. }
  3436. else
  3437. {
  3438. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3439. Abort();
  3440. }
  3441. }
  3442. }
  3443. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3444. {
  3445. Configuration->Usage->Inc(L"EditInactiveSession");
  3446. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3447. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3448. (ExtractFileName(FileName), Data->SessionName)));
  3449. }
  3450. }
  3451. TStrings * FileList = new TStringList();
  3452. try
  3453. {
  3454. FileList->Add(FileName);
  3455. // consider using the same settings (preset) as when the file was downloaded
  3456. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3457. TemporaryFileCopyParam(CopyParam);
  3458. if (Data->ForceText)
  3459. {
  3460. CopyParam.TransferMode = tmAscii;
  3461. }
  3462. // so i do not need to worry if masking algorithm works in all cases
  3463. // ("" means "copy file name", no masking is actually done)
  3464. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3465. {
  3466. CopyParam.FileMask = L"";
  3467. }
  3468. else
  3469. {
  3470. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3471. }
  3472. DebugAssert(Data->Queue != NULL);
  3473. int Params = cpNoConfirmation | cpTemporary;
  3474. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3475. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3476. QueueItem->CompleteEvent = UploadCompleteEvent;
  3477. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3478. }
  3479. __finally
  3480. {
  3481. delete FileList;
  3482. }
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3486. const UnicodeString FileName, const TEditedFileData * Data)
  3487. {
  3488. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3489. DebugAssert(!NonVisualDataModule->Busy);
  3490. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3491. {
  3492. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3493. (ExtractFileName(FileName), Data->SessionName)));
  3494. }
  3495. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3496. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3497. NonVisualDataModule->StartBusy();
  3498. try
  3499. {
  3500. std::unique_ptr<TRemoteFile> File;
  3501. UnicodeString RemoteFileName =
  3502. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3503. FTerminal->ExceptionOnFail = true;
  3504. try
  3505. {
  3506. TRemoteFile * AFile = NULL;
  3507. FTerminal->ReadFile(RemoteFileName, AFile);
  3508. File.reset(AFile);
  3509. if (!File->HaveFullFileName)
  3510. {
  3511. File->FullFileName = RemoteFileName;
  3512. }
  3513. }
  3514. __finally
  3515. {
  3516. FTerminal->ExceptionOnFail = false;
  3517. }
  3518. std::unique_ptr<TStrings> FileList(new TStringList());
  3519. FileList->AddObject(RemoteFileName, File.get());
  3520. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3521. UnicodeString TempDir = ExtractFilePath(FileName);
  3522. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3523. TempDir, true, true, true);
  3524. // sanity check, the target file name should be still the same
  3525. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3526. }
  3527. __finally
  3528. {
  3529. NonVisualDataModule->EndBusy();
  3530. // it actually may not exist anymore...
  3531. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3532. }
  3533. }
  3534. //---------------------------------------------------------------------------
  3535. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3536. const TEditedFileData * Data, bool & KeepOpen)
  3537. {
  3538. // Command is set for external editors only (not for "shell" open).
  3539. if (!Data->Command.IsEmpty())
  3540. {
  3541. bool AnyFound = false;
  3542. bool AnyMDI = false;
  3543. bool AnyNonMDI = false;
  3544. bool AnyDetect = false;
  3545. TEditorList * EditorList = new TEditorList();
  3546. try
  3547. {
  3548. *EditorList = *WinConfiguration->EditorList;
  3549. for (int i = 0; i < EditorList->Count; i++)
  3550. {
  3551. const TEditorPreferences * Editor = EditorList->Editors[i];
  3552. if ((Editor->Data->Editor == edExternal) &&
  3553. (Editor->Data->ExternalEditor == Data->Command))
  3554. {
  3555. AnyFound = true;
  3556. if (Editor->Data->SDIExternalEditor)
  3557. {
  3558. AnyNonMDI = true;
  3559. if (Editor->Data->DetectMDIExternalEditor)
  3560. {
  3561. AnyDetect = true;
  3562. }
  3563. }
  3564. else
  3565. {
  3566. AnyMDI = true;
  3567. }
  3568. }
  3569. }
  3570. bool EnableMDI = false;
  3571. bool DisableDetect = false;
  3572. if (AnyMDI)
  3573. {
  3574. KeepOpen = true;
  3575. if (AnyNonMDI)
  3576. {
  3577. // there is at least one instance of the editor with MDI support enabled,
  3578. // and one with disabled, enable it for all instances
  3579. EnableMDI = true;
  3580. }
  3581. }
  3582. else if (AnyFound && !AnyDetect)
  3583. {
  3584. // at least once instance found but all have MDI autodetection disabled
  3585. // => close the file (default action)
  3586. }
  3587. else
  3588. {
  3589. // no instance of the editor has MDI support enabled
  3590. TMessageParams Params;
  3591. if (AnyFound)
  3592. {
  3593. // there is at least one instance of the editor
  3594. Params.Params |= mpNeverAskAgainCheck;
  3595. }
  3596. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3597. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3598. switch (Answer)
  3599. {
  3600. case qaNeverAskAgain:
  3601. DisableDetect = true;
  3602. break;
  3603. case qaNo:
  3604. EnableMDI = true;
  3605. KeepOpen = true;
  3606. break;
  3607. }
  3608. }
  3609. if (AnyFound && (EnableMDI || DisableDetect))
  3610. {
  3611. bool Changed = false;
  3612. for (int i = 0; i < EditorList->Count; i++)
  3613. {
  3614. const TEditorPreferences * Editor = EditorList->Editors[i];
  3615. if ((Editor->Data->Editor == edExternal) &&
  3616. (Editor->Data->ExternalEditor == Data->Command) &&
  3617. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3618. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3619. {
  3620. Changed = true;
  3621. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3622. if (EnableMDI)
  3623. {
  3624. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3625. }
  3626. if (DisableDetect)
  3627. {
  3628. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3629. }
  3630. EditorList->Change(i, UpdatedEditor);
  3631. }
  3632. }
  3633. if (Changed)
  3634. {
  3635. WinConfiguration->EditorList = EditorList;
  3636. }
  3637. }
  3638. }
  3639. __finally
  3640. {
  3641. delete EditorList;
  3642. }
  3643. }
  3644. else
  3645. {
  3646. // "open" case
  3647. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3648. qaOK, HELP_APP_EARLY_CLOSED);
  3649. }
  3650. }
  3651. //---------------------------------------------------------------------------
  3652. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3653. {
  3654. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3655. }
  3656. //---------------------------------------------------------------------------
  3657. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3658. {
  3659. SideEnter(osRemote);
  3660. }
  3661. //---------------------------------------------------------------------------
  3662. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3663. {
  3664. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3665. SideEnter(osRemote);
  3666. }
  3667. //---------------------------------------------------------------------------
  3668. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3669. {
  3670. FCurrentSide = Side;
  3671. if (Visible)
  3672. {
  3673. UpdateControls();
  3674. }
  3675. }
  3676. //---------------------------------------------------------------------------
  3677. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3678. TStrings * FileList, bool Alternative)
  3679. {
  3680. TCustomDirView * DView = DirView(Side);
  3681. DView->SaveSelection();
  3682. DView->SaveSelectedNames();
  3683. DebugAssert(!FAlternativeDelete);
  3684. FAlternativeDelete = Alternative;
  3685. try
  3686. {
  3687. if (!IsSideLocalBrowser(Side))
  3688. {
  3689. DebugAssert(Terminal != NULL);
  3690. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3691. }
  3692. else
  3693. {
  3694. try
  3695. {
  3696. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3697. }
  3698. __finally
  3699. {
  3700. ReloadLocalDirectory();
  3701. }
  3702. }
  3703. FAlternativeDelete = false;
  3704. }
  3705. catch(...)
  3706. {
  3707. FAlternativeDelete = false;
  3708. DView->DiscardSavedSelection();
  3709. throw;
  3710. }
  3711. DView->RestoreSelection();
  3712. }
  3713. //---------------------------------------------------------------------------
  3714. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3715. {
  3716. DebugAssert(Terminal);
  3717. DebugAssert(!IsLocalBrowserMode());
  3718. RemoteDirView->SaveSelection();
  3719. RemoteDirView->SaveSelectedNames();
  3720. try
  3721. {
  3722. if (Lock)
  3723. {
  3724. Terminal->LockFiles(FileList);
  3725. }
  3726. else
  3727. {
  3728. Terminal->UnlockFiles(FileList);
  3729. }
  3730. }
  3731. catch(...)
  3732. {
  3733. RemoteDirView->DiscardSavedSelection();
  3734. throw;
  3735. }
  3736. RemoteDirView->RestoreSelection();
  3737. }
  3738. //---------------------------------------------------------------------------
  3739. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3740. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3741. bool NoConfirmation, bool Move)
  3742. {
  3743. DebugAssert(Terminal != NULL);
  3744. DebugAssert(!IsLocalBrowserMode());
  3745. // update Terminal->StateData->RemoteDirectory
  3746. UpdateTerminal(Terminal);
  3747. if (Session == NULL)
  3748. {
  3749. Session = TTerminalManager::Instance()->ActiveTerminal;
  3750. }
  3751. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3752. {
  3753. if (RemoteDriveView->DropTarget != NULL)
  3754. {
  3755. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3756. }
  3757. else if (RemoteDirView->DropTarget != NULL)
  3758. {
  3759. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3760. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3761. }
  3762. else
  3763. {
  3764. Target = RemoteDirView->Path;
  3765. }
  3766. }
  3767. else
  3768. {
  3769. Target = Session->StateData->RemoteDirectory;
  3770. }
  3771. Target = UnixIncludeTrailingBackslash(Target);
  3772. if (FileList->Count == 1)
  3773. {
  3774. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3775. }
  3776. else
  3777. {
  3778. FileMask = AnyMask;
  3779. }
  3780. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3781. bool Result = true;
  3782. if (!NoConfirmation)
  3783. {
  3784. bool Multi = (FileList->Count > 1);
  3785. if (Move)
  3786. {
  3787. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3788. }
  3789. else
  3790. {
  3791. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3792. TStrings * Directories = new TStringList;
  3793. try
  3794. {
  3795. for (int Index = 0; Index < Sessions->Count; Index++)
  3796. {
  3797. TManagedTerminal * Terminal =
  3798. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3799. Directories->Add(Terminal->StateData->RemoteDirectory);
  3800. }
  3801. TDirectRemoteCopy AllowDirectCopy;
  3802. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3803. {
  3804. DebugAssert(DirectCopy);
  3805. AllowDirectCopy = drcAllow;
  3806. }
  3807. else if (FTerminal->IsCapable[fcSecondaryShell])
  3808. {
  3809. DebugAssert(DirectCopy);
  3810. AllowDirectCopy = drcConfirmCommandSession;
  3811. }
  3812. else
  3813. {
  3814. DebugAssert(!DirectCopy);
  3815. AllowDirectCopy = drcDisallow;
  3816. }
  3817. void * ASession = Session;
  3818. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3819. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3820. Session = static_cast<TManagedTerminal *>(ASession);
  3821. }
  3822. __finally
  3823. {
  3824. delete Directories;
  3825. }
  3826. }
  3827. }
  3828. return Result;
  3829. }
  3830. //---------------------------------------------------------------------------
  3831. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3832. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3833. {
  3834. DebugAssert(!IsLocalBrowserMode());
  3835. bool DirectCopy;
  3836. UnicodeString Target, FileMask;
  3837. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3838. if (Result)
  3839. {
  3840. if (!Move && !DirectCopy)
  3841. {
  3842. Configuration->Usage->Inc("RemoteCopyTemp");
  3843. UnicodeString RootTempDir;
  3844. UnicodeString TempDir;
  3845. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3846. TStrings * TemporaryFilesList = new TStringList();
  3847. try
  3848. {
  3849. TMakeLocalFileListParams MakeFileListParam;
  3850. MakeFileListParam.FileList = TemporaryFilesList;
  3851. MakeFileListParam.FileTimes = NULL;
  3852. MakeFileListParam.IncludeDirs = true;
  3853. MakeFileListParam.Recursive = false;
  3854. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3855. TTerminalManager::Instance()->ActiveTerminal = Session;
  3856. if (TemporaryFilesList->Count > 0)
  3857. {
  3858. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3859. CopyParam.FileMask = FileMask;
  3860. DebugAssert(!FAutoOperation);
  3861. FAutoOperation = true;
  3862. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3863. }
  3864. }
  3865. __finally
  3866. {
  3867. delete TemporaryFilesList;
  3868. FAutoOperation = false;
  3869. if (!RootTempDir.IsEmpty())
  3870. {
  3871. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3872. }
  3873. }
  3874. }
  3875. else
  3876. {
  3877. RemoteDirView->SaveSelection();
  3878. RemoteDirView->SaveSelectedNames();
  3879. try
  3880. {
  3881. if (Move)
  3882. {
  3883. Configuration->Usage->Inc("RemoteMove");
  3884. Terminal->MoveFiles(FileList, Target, FileMask);
  3885. }
  3886. else
  3887. {
  3888. Configuration->Usage->Inc("RemoteCopyDirect");
  3889. DebugAssert(DirectCopy);
  3890. DebugAssert(Session == FTerminal);
  3891. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3892. FTerminal->CommandSessionOpened ||
  3893. CommandSessionFallback())
  3894. {
  3895. Terminal->CopyFiles(FileList, Target, FileMask);
  3896. }
  3897. }
  3898. }
  3899. catch(...)
  3900. {
  3901. RemoteDirView->DiscardSavedSelection();
  3902. throw;
  3903. }
  3904. RemoteDirView->RestoreSelection();
  3905. }
  3906. }
  3907. return Result;
  3908. }
  3909. //---------------------------------------------------------------------------
  3910. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3911. const UnicodeString & Path, TRemoteProperties & Properties)
  3912. {
  3913. DebugAssert(!IsLocalBrowserMode());
  3914. Properties.Valid = Properties.Valid << vpEncrypt;
  3915. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3916. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3917. }
  3918. //---------------------------------------------------------------------------
  3919. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3920. {
  3921. Side = GetSide(Side);
  3922. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3923. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3924. UnicodeString Name = LoadStr(NEW_FOLDER);
  3925. int AllowedChanges =
  3926. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3927. bool SaveSettings = false;
  3928. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3929. {
  3930. TWindowLock Lock(this);
  3931. if (!IsSideLocalBrowser(Side))
  3932. {
  3933. if (SaveSettings)
  3934. {
  3935. GUIConfiguration->NewDirectoryProperties = Properties;
  3936. }
  3937. CreateRemoteDirectory(Name, Properties);
  3938. }
  3939. else
  3940. {
  3941. DirView(Side)->CreateDirectory(Name);
  3942. }
  3943. }
  3944. }
  3945. //---------------------------------------------------------------------------
  3946. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3947. {
  3948. TWindowLock Lock(this);
  3949. DirView(Side)->ExecuteHomeDirectory();
  3950. }
  3951. //---------------------------------------------------------------------------
  3952. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3953. {
  3954. DoOpenDirectoryDialog(odBrowse, Side);
  3955. }
  3956. //---------------------------------------------------------------------------
  3957. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3958. {
  3959. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3960. bool Result = !Path.IsEmpty();
  3961. if (Result)
  3962. {
  3963. // While we might get here when the session is closed (from location profiles),
  3964. // it's not a problem as the Path setter is noop then
  3965. DirView(Side)->Path = Path;
  3966. }
  3967. return Result;
  3968. }
  3969. //---------------------------------------------------------------------------
  3970. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3971. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3972. bool & Close)
  3973. {
  3974. // terminal can be already closed (e.g. dropped connection)
  3975. if (Terminal != NULL)
  3976. {
  3977. try
  3978. {
  3979. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3980. }
  3981. catch(...)
  3982. {
  3983. if (!Terminal->Active)
  3984. {
  3985. Close = true;
  3986. }
  3987. throw;
  3988. }
  3989. }
  3990. }
  3991. //---------------------------------------------------------------------------
  3992. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3993. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3994. bool & Close)
  3995. {
  3996. // terminal can be already closed (e.g. dropped connection)
  3997. if (Terminal != NULL)
  3998. {
  3999. Configuration->Usage->Inc(L"ChecksumCalculated");
  4000. try
  4001. {
  4002. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4003. }
  4004. catch(...)
  4005. {
  4006. if (!Terminal->Active)
  4007. {
  4008. Close = true;
  4009. }
  4010. throw;
  4011. }
  4012. }
  4013. }
  4014. //---------------------------------------------------------------------------
  4015. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4016. {
  4017. bool Result;
  4018. if (!IsSideLocalBrowser(Side))
  4019. {
  4020. TRemoteTokenList * GroupList = NULL;
  4021. TRemoteTokenList * UserList = NULL;
  4022. try
  4023. {
  4024. TRemoteProperties CurrentProperties;
  4025. if (Terminal->LoadFilesProperties(FileList))
  4026. {
  4027. RemoteDirView->Invalidate();
  4028. }
  4029. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4030. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4031. if (CapableGroupChanging || CapableOwnerChanging)
  4032. {
  4033. if (CapableGroupChanging)
  4034. {
  4035. GroupList = Terminal->Groups->Duplicate();
  4036. }
  4037. if (CapableOwnerChanging)
  4038. {
  4039. UserList = Terminal->Users->Duplicate();
  4040. }
  4041. TRemoteDirectory * Files = Terminal->Files;
  4042. int Count = Files->Count;
  4043. if (Count > 100)
  4044. {
  4045. Count = 100;
  4046. }
  4047. for (int Index = 0; Index < Count; Index++)
  4048. {
  4049. TRemoteFile * File = Files->Files[Index];
  4050. if (CapableGroupChanging)
  4051. {
  4052. GroupList->AddUnique(File->Group);
  4053. }
  4054. if (CapableOwnerChanging)
  4055. {
  4056. UserList->AddUnique(File->Owner);
  4057. }
  4058. }
  4059. // if we haven't collected tokens for all files in current directory,
  4060. // make sure we collect them at least for all selected files.
  4061. // (note that so far the files in FileList has to be from current direcotry)
  4062. if (Count < Files->Count)
  4063. {
  4064. for (int Index = 0; Index < FileList->Count; Index++)
  4065. {
  4066. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4067. if (CapableGroupChanging)
  4068. {
  4069. GroupList->AddUnique(File->Group);
  4070. }
  4071. if (CapableOwnerChanging)
  4072. {
  4073. UserList->AddUnique(File->Owner);
  4074. }
  4075. }
  4076. }
  4077. }
  4078. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4079. int Flags = 0;
  4080. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4081. if (CapableOwnerChanging) Flags |= cpOwner;
  4082. if (CapableGroupChanging) Flags |= cpGroup;
  4083. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4084. if (Terminal->IsCapable[fcCalculatingChecksum])
  4085. {
  4086. CalculateChecksumEvent = CalculateChecksum;
  4087. }
  4088. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4089. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4090. TRemoteProperties NewProperties = CurrentProperties;
  4091. Result =
  4092. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4093. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4094. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4095. CalculateSize, CalculateChecksumEvent);
  4096. if (Result)
  4097. {
  4098. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4099. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4100. }
  4101. }
  4102. __finally
  4103. {
  4104. delete GroupList;
  4105. delete UserList;
  4106. }
  4107. }
  4108. else
  4109. {
  4110. DirView(Side)->DisplayPropertiesMenu();
  4111. Result = true;
  4112. }
  4113. return Result;
  4114. }
  4115. //---------------------------------------------------------------------------
  4116. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4117. {
  4118. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4119. {
  4120. FIgnoreNextDialogChar = Key;
  4121. }
  4122. Key = 0;
  4123. }
  4124. //---------------------------------------------------------------------------
  4125. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4126. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4127. {
  4128. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4129. if (Command != NULL)
  4130. {
  4131. KeyProcessed(Key, Shift);
  4132. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4133. {
  4134. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4135. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4136. false, false, const_cast<TCustomCommandType *>(Command));
  4137. }
  4138. }
  4139. }
  4140. //---------------------------------------------------------------------------
  4141. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4142. {
  4143. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4144. {
  4145. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4146. }
  4147. if (!DirView(osCurrent)->IsEditing())
  4148. {
  4149. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4150. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4151. {
  4152. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4153. if (((Action->ShortCut == KeyShortCut) ||
  4154. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4155. AllowedAction(Action, aaShortCut))
  4156. {
  4157. // Has to be called before the action as the dialog char is already in queue.
  4158. // So when the action consumes message queue, we already need to have the
  4159. // FIgnoreNextDialogChar set
  4160. KeyProcessed(Key, Shift);
  4161. // Reset reference to previous component (when menu/toolbar was clicked).
  4162. // Needed to detect that action was invoked by keyboard shortcut
  4163. // in TNonVisualDataModule::ExplorerActionsExecute
  4164. Action->ActionComponent = NULL;
  4165. Action->Execute();
  4166. return;
  4167. }
  4168. }
  4169. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4170. {
  4171. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4172. {
  4173. KeyProcessed(Key, Shift);
  4174. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4175. return;
  4176. }
  4177. }
  4178. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4179. {
  4180. KeyProcessed(Key, Shift);
  4181. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4182. }
  4183. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4184. if (IsCustomShortCut(CustomShortCut))
  4185. {
  4186. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4187. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4188. if (WinConfiguration->SharedBookmarks != NULL)
  4189. {
  4190. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4191. if ((Bookmark != NULL) &&
  4192. OpenBookmark(FCurrentSide, Bookmark))
  4193. {
  4194. KeyProcessed(Key, Shift);
  4195. }
  4196. }
  4197. }
  4198. }
  4199. TForm::KeyDown(Key, Shift);
  4200. }
  4201. //---------------------------------------------------------------------------
  4202. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4203. {
  4204. DebugAssert(Terminal != NULL);
  4205. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4206. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4207. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4208. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4209. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4210. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4211. // expanded from ?: to avoid memory leaks
  4212. if (SecurityEnabled)
  4213. {
  4214. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4215. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4216. }
  4217. else
  4218. {
  4219. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4220. }
  4221. if (FileSystemInfo.ProtocolName.IsEmpty())
  4222. {
  4223. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4224. }
  4225. else
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4228. }
  4229. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4230. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4231. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4232. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4233. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4234. UnicodeString CompressionStr = CSCompressionStr;
  4235. if (CSCompressionStr != SCCompressionStr)
  4236. {
  4237. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4238. }
  4239. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4240. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4241. UpdateStatusBar();
  4242. }
  4243. //---------------------------------------------------------------------------
  4244. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4245. {
  4246. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4247. DebugAssert(SessionStatusBar != NULL);
  4248. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4249. {
  4250. // note: (Terminal->Status < sshReady) currently never happens here,
  4251. // so STATUS_CONNECTING is never used
  4252. SessionStatusBar->SimplePanel = true;
  4253. SessionStatusBar->SimpleText = LoadStr(
  4254. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4255. }
  4256. else
  4257. {
  4258. DebugAssert(Terminal);
  4259. SessionStatusBar->SimplePanel = false;
  4260. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4261. if (!FNote.IsEmpty())
  4262. {
  4263. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4264. }
  4265. else
  4266. {
  4267. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4268. }
  4269. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4270. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4271. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4272. }
  4273. }
  4274. //---------------------------------------------------------------------------
  4275. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4276. {
  4277. Panel->Caption = L"";
  4278. }
  4279. //---------------------------------------------------------------------------
  4280. void __fastcall TCustomScpExplorerForm::Idle()
  4281. {
  4282. if (FShowing || FStandaloneEditing)
  4283. {
  4284. FEditorManager->Check();
  4285. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4286. // that needs to know if queue view is visible (and it may be closed after queue update)
  4287. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4288. }
  4289. if (FShowing)
  4290. {
  4291. if (!NonVisualDataModule->Busy &&
  4292. // Menu is opened or drag&drop is going on
  4293. (Mouse->Capture == NULL))
  4294. {
  4295. if (FRefreshRemoteDirectory)
  4296. {
  4297. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4298. {
  4299. Terminal->RefreshDirectory();
  4300. }
  4301. FRefreshRemoteDirectory = false;
  4302. }
  4303. if (FRefreshLocalDirectory)
  4304. {
  4305. ReloadLocalDirectory();
  4306. FRefreshLocalDirectory = false;
  4307. }
  4308. if (WinConfiguration->RefreshRemotePanel)
  4309. {
  4310. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4311. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4312. {
  4313. RemoteDirView->ReloadDirectory();
  4314. }
  4315. }
  4316. }
  4317. }
  4318. if (FShowing || FStandaloneEditing)
  4319. {
  4320. if (FQueueStatusInvalidated)
  4321. {
  4322. UpdateQueueStatus(false);
  4323. }
  4324. RefreshQueueItems();
  4325. }
  4326. if (FShowing)
  4327. {
  4328. UpdateStatusBar();
  4329. }
  4330. FIgnoreNextDialogChar = 0;
  4331. }
  4332. //---------------------------------------------------------------------------
  4333. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4334. {
  4335. try
  4336. {
  4337. FUserActionTimer->Enabled = false;
  4338. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4339. {
  4340. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4341. {
  4342. FPendingQueueActionItem->ProcessUserAction();
  4343. }
  4344. }
  4345. }
  4346. __finally
  4347. {
  4348. FPendingQueueActionItem = NULL;
  4349. }
  4350. }
  4351. //---------------------------------------------------------------------------
  4352. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4353. {
  4354. if (WinConfiguration->MinimizeToTray)
  4355. {
  4356. UpdateTrayIcon();
  4357. FTrayIcon->Visible = true;
  4358. if (Visible)
  4359. {
  4360. ShowWindow(Handle, SW_HIDE);
  4361. }
  4362. }
  4363. }
  4364. //---------------------------------------------------------------------------
  4365. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4366. {
  4367. // WORKAROUND
  4368. // When restoring maximized window from minimization,
  4369. // rarely some controls do not align properly.
  4370. // Two instances seen (both for Commander):
  4371. // - When restoring, window is temporarily narrower (not maximized),
  4372. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4373. // Once maximized already, top dock shinks back, but the session PageControl,
  4374. // do not align up, leaving space between TopDock and PageControl.
  4375. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4376. for (int Index = 0; Index < ControlCount; Index++)
  4377. {
  4378. RealignControl(Controls[Index]);
  4379. }
  4380. if (FTrayIcon->Visible)
  4381. {
  4382. FTrayIcon->Visible = false;
  4383. if (Visible)
  4384. {
  4385. ShowWindow(Handle, SW_SHOW);
  4386. }
  4387. }
  4388. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4389. {
  4390. FNeedSession = false;
  4391. NonVisualDataModule->StartBusy();
  4392. try
  4393. {
  4394. NeedSession(true);
  4395. }
  4396. __finally
  4397. {
  4398. NonVisualDataModule->EndBusy();
  4399. }
  4400. }
  4401. }
  4402. //---------------------------------------------------------------------------
  4403. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4404. {
  4405. FTrayIcon->Hint = GetMainForm()->Caption;
  4406. }
  4407. //---------------------------------------------------------------------------
  4408. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4409. {
  4410. UpdateTrayIcon();
  4411. }
  4412. //---------------------------------------------------------------------------
  4413. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4414. {
  4415. // workaround
  4416. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4417. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4418. // But WM_ACTIVATEAPP message can be received even when
  4419. // the main window is minimized to the tray and internal editor window is focused
  4420. // (after another application was previously active)
  4421. if (::IsIconic(Handle))
  4422. {
  4423. if (!IsAppIconic())
  4424. {
  4425. SetAppIconic(true);
  4426. }
  4427. }
  4428. ::ApplicationRestore();
  4429. Application->BringToFront();
  4430. }
  4431. //---------------------------------------------------------------------------
  4432. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4433. {
  4434. RestoreApp();
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4438. {
  4439. if (OpenInNewWindow())
  4440. {
  4441. // todo: Pass FromSite
  4442. ExecuteNewInstance(SessionUrl);
  4443. }
  4444. else
  4445. {
  4446. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4447. }
  4448. }
  4449. //---------------------------------------------------------------------------
  4450. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4451. {
  4452. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4453. StoredSessions->NewSession(SessionName, SessionData);
  4454. // modified only, explicit
  4455. StoredSessions->Save(false, true);
  4456. // encode session name because of slashes in hierarchical sessions
  4457. return EncodeUrlString(SessionName);
  4458. }
  4459. //---------------------------------------------------------------------------
  4460. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4461. {
  4462. // current working directories become defaults here, what is not right
  4463. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4464. return SaveHiddenDuplicateSession(SessionData.get());
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4468. {
  4469. if (OpenInNewWindow())
  4470. {
  4471. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4472. }
  4473. else
  4474. {
  4475. // current working directories become defaults here, what is not right
  4476. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4477. TTerminalManager * Manager = TTerminalManager::Instance();
  4478. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4479. Manager->ActiveTerminal = Terminal;
  4480. }
  4481. }
  4482. //---------------------------------------------------------------------------
  4483. void __fastcall TCustomScpExplorerForm::RenameSession()
  4484. {
  4485. UnicodeString Name = Terminal->SessionData->SessionName;
  4486. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4487. {
  4488. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4489. TSessionData::ValidateName(Name);
  4490. // This is inconsistent with how color (for example) is handled.
  4491. Terminal->SessionData->Name = Name;
  4492. UpdateControls();
  4493. // Add/Remove distinguishing paths from sessions of the same name.
  4494. DoTerminalListChanged();
  4495. }
  4496. }
  4497. //---------------------------------------------------------------------------
  4498. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4499. {
  4500. DebugAssert(Queue != NULL);
  4501. bool Result = Queue->IsEmpty;
  4502. if (!Result)
  4503. {
  4504. SetFocus();
  4505. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4506. }
  4507. return Result;
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4511. {
  4512. return CanCloseQueue(FQueue);
  4513. }
  4514. //---------------------------------------------------------------------------
  4515. void __fastcall TCustomScpExplorerForm::CloseSession()
  4516. {
  4517. if (CanCloseQueue())
  4518. {
  4519. TTerminalManager::Instance()->FreeActiveTerminal();
  4520. }
  4521. }
  4522. //---------------------------------------------------------------------------
  4523. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4524. {
  4525. if (CanCloseQueue())
  4526. {
  4527. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4528. }
  4529. }
  4530. //---------------------------------------------------------------------------
  4531. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4532. {
  4533. RemoteDirView->Terminal = Terminal;
  4534. UpdateRemotePathComboBox(false);
  4535. UpdateControls();
  4536. }
  4537. //---------------------------------------------------------------------------
  4538. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4539. {
  4540. if (DebugAlwaysTrue(!Terminal->Active))
  4541. {
  4542. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4543. }
  4544. }
  4545. //---------------------------------------------------------------------------
  4546. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4547. {
  4548. if (OpenInNewWindow())
  4549. {
  4550. // encode session name because of slashes in hierarchical sessions
  4551. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4552. }
  4553. else
  4554. {
  4555. TTerminalManager * Manager = TTerminalManager::Instance();
  4556. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4557. Manager->ActiveTerminal = Terminal;
  4558. }
  4559. }
  4560. //---------------------------------------------------------------------------
  4561. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4562. {
  4563. TTerminalManager * Manager = TTerminalManager::Instance();
  4564. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4565. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4566. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4567. // FirstTerminal can be null, if some of the
  4568. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4569. {
  4570. FirstTerminal->Disconnected = true;
  4571. FirstTerminal->DisconnectedTemporarily = true;
  4572. }
  4573. Manager->ActiveTerminal = FirstTerminal;
  4574. }
  4575. //---------------------------------------------------------------------------
  4576. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4577. {
  4578. if (OpenInNewWindow())
  4579. {
  4580. ExecuteNewInstance(Name);
  4581. }
  4582. else
  4583. {
  4584. DoOpenFolderOrWorkspace(Name, true);
  4585. }
  4586. }
  4587. //---------------------------------------------------------------------------
  4588. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4589. bool &CanClose)
  4590. {
  4591. if (Terminal != NULL)
  4592. {
  4593. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4594. {
  4595. unsigned int Result;
  4596. TMessageParams Params(mpNeverAskAgainCheck);
  4597. UnicodeString Message;
  4598. int Answers = qaOK | qaCancel;
  4599. if (TTerminalManager::Instance()->Count > 1)
  4600. {
  4601. if (!WinConfiguration->AutoSaveWorkspace)
  4602. {
  4603. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4604. }
  4605. else
  4606. {
  4607. Message = LoadStr(CLOSE_SESSIONS);
  4608. }
  4609. }
  4610. else
  4611. {
  4612. if (!WinConfiguration->AutoSaveWorkspace)
  4613. {
  4614. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4615. }
  4616. else
  4617. {
  4618. Message = LoadStr(CLOSE_SESSION);
  4619. }
  4620. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4621. }
  4622. UnicodeString Note;
  4623. if (WinConfiguration->AutoSaveWorkspace)
  4624. {
  4625. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4626. }
  4627. else
  4628. {
  4629. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4630. Answers = qaYes | qaNo | qaCancel;
  4631. }
  4632. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4633. SetFocus();
  4634. Result = MessageDialog(Message, qtConfirmation,
  4635. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4636. if (Result == qaNeverAskAgain)
  4637. {
  4638. WinConfiguration->ConfirmClosingSession = false;
  4639. }
  4640. if (Result == qaNo)
  4641. {
  4642. CanClose = SaveWorkspace(true);
  4643. // note that the workspace will be saved redundatly again from FormClose
  4644. }
  4645. else
  4646. {
  4647. CanClose =
  4648. (Result == qaOK) ||
  4649. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4650. (Result == qaNeverAskAgain);
  4651. }
  4652. }
  4653. if (CanClose)
  4654. {
  4655. CanClose = CanCloseQueue();
  4656. }
  4657. }
  4658. if (CanClose)
  4659. {
  4660. CanClose =
  4661. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4662. FEditorManager->CloseExternalFilesWithoutProcess();
  4663. if (CanClose)
  4664. {
  4665. while (CanClose && (FLocalEditors->Count > 0))
  4666. {
  4667. int PrevCount = FLocalEditors->Count;
  4668. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4669. CanClose = (FLocalEditors->Count < PrevCount);
  4670. }
  4671. if (CanClose)
  4672. {
  4673. CanClose = FEditorManager->Empty(true);
  4674. if (!CanClose)
  4675. {
  4676. SetFocus();
  4677. CanClose =
  4678. (MessageDialog(
  4679. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4680. }
  4681. }
  4682. }
  4683. }
  4684. }
  4685. //---------------------------------------------------------------------------
  4686. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4687. {
  4688. TForm * Form = dynamic_cast<TForm *>(Sender);
  4689. DebugAssert(Form != NULL);
  4690. Form->Close();
  4691. }
  4692. //---------------------------------------------------------------------------
  4693. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4694. {
  4695. TForm * Form = dynamic_cast<TForm *>(Sender);
  4696. delete Form;
  4697. }
  4698. //---------------------------------------------------------------------------
  4699. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4700. {
  4701. while (FLocalEditors->Count > 0)
  4702. {
  4703. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4704. }
  4705. }
  4706. //---------------------------------------------------------------------------
  4707. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4708. TObject *Sender)
  4709. {
  4710. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4711. try
  4712. {
  4713. SetProperties(osRemote, FileList);
  4714. }
  4715. __finally
  4716. {
  4717. delete FileList;
  4718. }
  4719. }
  4720. //---------------------------------------------------------------------------
  4721. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4722. {
  4723. if (value)
  4724. {
  4725. if (Component == fcCustomCommandsBand)
  4726. {
  4727. UpdateCustomCommandsToolbar();
  4728. }
  4729. if (Component == fcQueueFileList)
  4730. {
  4731. DebugAssert(!QueueFileListSplitter->Visible);
  4732. AdjustQueueLayout();
  4733. UpdateQueueFileList();
  4734. }
  4735. }
  4736. }
  4737. //---------------------------------------------------------------------------
  4738. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4739. {
  4740. int MinHeightLimit =
  4741. GetStaticQueuePanelComponentsHeight() +
  4742. QueueFileListSplitter->Height +
  4743. QueueFileList->Height +
  4744. GetMinQueueViewHeight();
  4745. if (QueuePanel->ClientHeight < MinHeightLimit)
  4746. {
  4747. QueuePanel->ClientHeight = MinHeightLimit;
  4748. }
  4749. }
  4750. //---------------------------------------------------------------------------
  4751. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4752. {
  4753. TControl * Control = GetComponent(Component);
  4754. DebugAssert(Control);
  4755. bool Changed = (Control->Visible != value);
  4756. if (Changed)
  4757. {
  4758. ComponentShowing(Component, value);
  4759. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4760. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4761. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4762. if (value)
  4763. {
  4764. int RemainingHeight = Control->Parent->ClientHeight;
  4765. int RemainingWidth = Control->Parent->ClientWidth;
  4766. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4767. {
  4768. TControl * ChildControl = Control->Parent->Controls[i];
  4769. if (ChildControl->Visible)
  4770. {
  4771. switch (ChildControl->Align)
  4772. {
  4773. case alTop:
  4774. case alBottom:
  4775. RemainingHeight -= ChildControl->Height;
  4776. break;
  4777. case alLeft:
  4778. case alRight:
  4779. RemainingWidth -= ChildControl->Width;
  4780. break;
  4781. }
  4782. }
  4783. }
  4784. int Reserve = ScaleByTextHeight(this, 32);
  4785. // queue in explorer, trees in commander
  4786. if (Control->Height > RemainingHeight - Reserve)
  4787. {
  4788. Control->Height = RemainingHeight / 2;
  4789. }
  4790. if (Control->Width > RemainingWidth - Reserve)
  4791. {
  4792. Control->Width = RemainingWidth / 2;
  4793. }
  4794. }
  4795. Control->Visible = value;
  4796. if (WasFocused && Visible)
  4797. {
  4798. DirView(osCurrent)->SetFocus();
  4799. }
  4800. FixControlsPlacement();
  4801. }
  4802. }
  4803. //---------------------------------------------------------------------------
  4804. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4805. {
  4806. TControl * Control = GetComponent(Component);
  4807. if (Control == NULL)
  4808. {
  4809. return false;
  4810. }
  4811. else
  4812. {
  4813. return Control->Visible;
  4814. }
  4815. }
  4816. //---------------------------------------------------------------------------
  4817. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4818. {
  4819. bool Result;
  4820. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4821. {
  4822. Result = !IsUWP();
  4823. }
  4824. else
  4825. {
  4826. Result = true;
  4827. }
  4828. return Result;
  4829. }
  4830. //---------------------------------------------------------------------------
  4831. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4832. {
  4833. if (DirView(osOther)->ItemFocused != NULL)
  4834. {
  4835. DirView(osOther)->ItemFocused->MakeVisible(false);
  4836. }
  4837. QueueSplitter->Visible = QueuePanel->Visible;
  4838. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4839. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4840. TControl * QueueControlsOrder[] =
  4841. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4842. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4843. }
  4844. //---------------------------------------------------------------------------
  4845. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4846. {
  4847. switch (Component) {
  4848. case fcStatusBar: return RemoteStatusBar;
  4849. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4850. case fcQueueView: return QueuePanel;
  4851. case fcQueueToolbar: return QueueDock;
  4852. case fcRemoteTree: return RemoteDrivePanel;
  4853. case fcSessionsTabs: return SessionsPageControl;
  4854. case fcQueueFileList: return QueueFileList;
  4855. default: return NULL;
  4856. }
  4857. }
  4858. //---------------------------------------------------------------------------
  4859. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4860. TObject *Sender, TListColumn *Column, TPoint &Point)
  4861. {
  4862. DebugAssert(NonVisualDataModule && Column && Sender);
  4863. NonVisualDataModule->ListColumn = Column;
  4864. TPopupMenu * DirViewColumnMenu;
  4865. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4866. {
  4867. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4868. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4869. (Column->Index == uvName);
  4870. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4871. (Column->Index == uvSize);
  4872. }
  4873. else
  4874. {
  4875. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4876. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4877. (Column->Index == dvName);
  4878. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4879. (Column->Index == dvSize);
  4880. }
  4881. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4882. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4883. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4884. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4885. }
  4886. //---------------------------------------------------------------------------
  4887. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4888. TObject *Sender, TListItem *Item, bool &AllowExec)
  4889. {
  4890. DoDirViewExecFile(Sender, Item, AllowExec);
  4891. }
  4892. //---------------------------------------------------------------------------
  4893. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4894. TListItem * Item, bool & AllowExec)
  4895. {
  4896. DebugAssert(Sender && Item && Configuration);
  4897. DebugAssert(AllowExec);
  4898. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4899. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4900. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4901. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4902. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4903. // on files only (not directories)
  4904. // and only when symlinks are resolved (apply to remote panel only)
  4905. if (!ADirView->ItemIsDirectory(Item) &&
  4906. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4907. {
  4908. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4909. !FForceExecution &&
  4910. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4911. {
  4912. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4913. {
  4914. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4915. UnlockWindow();
  4916. try
  4917. {
  4918. ExecuteFileOperation(
  4919. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4920. }
  4921. __finally
  4922. {
  4923. LockWindow();
  4924. }
  4925. AllowExec = false;
  4926. }
  4927. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4928. {
  4929. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4930. {
  4931. ExecuteFile(Side, efDefaultEditor);
  4932. AllowExec = false;
  4933. }
  4934. }
  4935. else
  4936. {
  4937. DebugFail();
  4938. }
  4939. }
  4940. // if we have not done anything special, fall back to default behavior
  4941. if (AllowExec)
  4942. {
  4943. if (Remote && !WinConfiguration->DisableOpenEdit)
  4944. {
  4945. ExecuteFile(osRemote, efShell);
  4946. AllowExec = false;
  4947. }
  4948. }
  4949. }
  4950. }
  4951. //---------------------------------------------------------------------------
  4952. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4953. {
  4954. return ((Side == osRemote) || (Side == osCurrent));
  4955. }
  4956. //---------------------------------------------------------------------------
  4957. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4958. {
  4959. DebugFail();
  4960. }
  4961. //---------------------------------------------------------------------------
  4962. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4963. {
  4964. DebugFail();
  4965. }
  4966. //---------------------------------------------------------------------------
  4967. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4968. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4969. {
  4970. TSynchronizeParamType Params;
  4971. Params.LocalDirectory = LocalDirectory;
  4972. Params.RemoteDirectory = RemoteDirectory;
  4973. int UnusedParams =
  4974. (GUIConfiguration->SynchronizeParams &
  4975. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4976. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4977. Params.Options = GUIConfiguration->SynchronizeOptions;
  4978. bool SaveSettings = false;
  4979. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4980. &DoSynchronizeTooManyDirectories);
  4981. DebugAssert(FSynchronizeController == NULL);
  4982. FSynchronizeController = &Controller;
  4983. bool Result;
  4984. try
  4985. {
  4986. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4987. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4988. int Options =
  4989. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4990. DebugAssert(FOnFeedSynchronizeError == NULL);
  4991. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4992. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4993. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4994. if (Result)
  4995. {
  4996. if (SaveSettings)
  4997. {
  4998. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4999. GUIConfiguration->SynchronizeOptions = Params.Options;
  5000. }
  5001. else
  5002. {
  5003. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5004. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5005. FLAGSET(Params.Options, soSynchronize))
  5006. {
  5007. GUIConfiguration->SynchronizeOptions =
  5008. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5009. soSynchronize;
  5010. }
  5011. }
  5012. LocalDirectory = Params.LocalDirectory;
  5013. RemoteDirectory = Params.RemoteDirectory;
  5014. }
  5015. }
  5016. __finally
  5017. {
  5018. FSynchronizeController = NULL;
  5019. DebugAssert(FOnFeedSynchronizeError == NULL);
  5020. FOnFeedSynchronizeError = NULL;
  5021. }
  5022. return Result;
  5023. }
  5024. //---------------------------------------------------------------------------
  5025. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5026. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5027. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5028. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5029. TSynchronizeOptions * Options, bool Full)
  5030. {
  5031. // Keep-up-to-date mode
  5032. if (Terminal->Status == ssOpened)
  5033. {
  5034. try
  5035. {
  5036. int PParams = Params.Params;
  5037. if (!Full)
  5038. {
  5039. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5040. if (FLAGSET(Params.Options, soRecurse))
  5041. {
  5042. PParams |= TTerminal::spSubDirs;
  5043. }
  5044. }
  5045. else
  5046. {
  5047. // if keepuptodate is non-recursive,
  5048. // full sync before has to be non-recursive as well
  5049. if (FLAGCLEAR(Params.Options, soRecurse))
  5050. {
  5051. PParams |= TTerminal::spNoRecurse;
  5052. }
  5053. }
  5054. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5055. PParams, Checklist, Options);
  5056. }
  5057. catch (Exception & E)
  5058. {
  5059. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5060. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5061. {
  5062. // noop, already logged in MoreMessageDialog
  5063. }
  5064. else
  5065. {
  5066. ShowExtendedExceptionEx(Terminal, &E);
  5067. throw;
  5068. }
  5069. }
  5070. }
  5071. }
  5072. //---------------------------------------------------------------------------
  5073. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5074. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5075. const UnicodeString ErrorStr)
  5076. {
  5077. if (!Directory.IsEmpty())
  5078. {
  5079. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5080. }
  5081. else
  5082. {
  5083. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5084. }
  5085. }
  5086. //---------------------------------------------------------------------------
  5087. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5088. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5089. {
  5090. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5091. {
  5092. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5093. }
  5094. else
  5095. {
  5096. TMessageParams Params(mpNeverAskAgainCheck);
  5097. unsigned int Result = MessageDialog(
  5098. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5099. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5100. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5101. {
  5102. MaxDirectories *= 2;
  5103. if (Result == qaNeverAskAgain)
  5104. {
  5105. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5106. }
  5107. }
  5108. else
  5109. {
  5110. Abort();
  5111. }
  5112. }
  5113. }
  5114. //---------------------------------------------------------------------------
  5115. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5116. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5117. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5118. TSynchronizeOptions * Options)
  5119. {
  5120. // Keep-up-to-date mode
  5121. DebugAssert(!FAutoOperation);
  5122. void * BatchStorage;
  5123. BatchStart(BatchStorage);
  5124. FAutoOperation = true;
  5125. bool AnyOperation = false;
  5126. TDateTime StartTime = Now();
  5127. TSynchronizeChecklist * AChecklist = NULL;
  5128. try
  5129. {
  5130. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5131. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5132. {
  5133. FSynchronizeProgressForm->Start();
  5134. }
  5135. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5136. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5137. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5138. Options);
  5139. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5140. SAFE_DESTROY(FSynchronizeProgressForm);
  5141. AnyOperation = (AChecklist->CheckedCount > 0);
  5142. if (AnyOperation)
  5143. {
  5144. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5145. CreateProgressForm(&SynchronizeProgress);
  5146. try
  5147. {
  5148. Terminal->SynchronizeApply(
  5149. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5150. SynchronizeProcessedItem, NULL, NULL, NULL);
  5151. }
  5152. __finally
  5153. {
  5154. DestroyProgressForm();
  5155. }
  5156. }
  5157. }
  5158. __finally
  5159. {
  5160. if (Checklist == NULL)
  5161. {
  5162. delete AChecklist;
  5163. }
  5164. else
  5165. {
  5166. *Checklist = AChecklist;
  5167. }
  5168. FAutoOperation = false;
  5169. SAFE_DESTROY(FSynchronizeProgressForm);
  5170. BatchEnd(BatchStorage);
  5171. ReloadLocalDirectory();
  5172. if (AnyOperation)
  5173. {
  5174. OperationComplete(StartTime);
  5175. }
  5176. }
  5177. }
  5178. //---------------------------------------------------------------------------
  5179. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5180. {
  5181. // can be called from command line
  5182. return Visible &&
  5183. ((DirView(osRemote)->SelCount > 0) ||
  5184. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5185. }
  5186. //---------------------------------------------------------------------------
  5187. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5188. {
  5189. LogSynchronizeEvent(Terminal, Message);
  5190. }
  5191. //---------------------------------------------------------------------------
  5192. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5193. int Params, TSynchronizeOptions & Options)
  5194. {
  5195. DebugAssert(!IsLocalBrowserMode());
  5196. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5197. {
  5198. Options.Filter = new TStringList();
  5199. Options.Filter->CaseSensitive = false;
  5200. Options.Filter->Duplicates = Types::dupAccept;
  5201. if (DirView(osRemote)->SelCount > 0)
  5202. {
  5203. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5204. }
  5205. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5206. {
  5207. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5208. }
  5209. Options.Filter->Sort();
  5210. }
  5211. }
  5212. //---------------------------------------------------------------------------
  5213. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5214. {
  5215. TCopyParamType Defaults;
  5216. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5217. ConfigStorage->AccessMode = smRead;
  5218. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5219. {
  5220. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5221. }
  5222. ConfigStorage.reset(NULL);
  5223. std::unique_ptr<TStringList> Options(new TStringList());
  5224. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5225. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5226. UnicodeString Result;
  5227. if (Options->Count > 0)
  5228. {
  5229. Result =
  5230. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5231. }
  5232. return Result;
  5233. }
  5234. //---------------------------------------------------------------------------
  5235. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5236. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5237. {
  5238. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5239. UnicodeString AdditionalParams =
  5240. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5241. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5242. SerializeCopyParamForCommandLine(CopyParams),
  5243. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5244. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5245. ExecuteNewInstance(SessionName, AdditionalParams);
  5246. }
  5247. //---------------------------------------------------------------------------
  5248. struct TSynchronizeParams
  5249. {
  5250. UnicodeString LocalDirectory;
  5251. UnicodeString RemoteDirectory;
  5252. TSynchronizeMode Mode;
  5253. TSynchronizeChecklist * Checklist;
  5254. int Params;
  5255. TCopyParamType * CopyParam;
  5256. TDateTime CollectElapsed;
  5257. TDateTime * StartTime;
  5258. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5259. };
  5260. //---------------------------------------------------------------------------
  5261. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5262. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5263. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5264. {
  5265. DebugAssert(!FAutoOperation);
  5266. void * BatchStorage;
  5267. BatchStart(BatchStorage);
  5268. FAutoOperation = true;
  5269. TFileOperationStatistics Statistics;
  5270. TDateTime Start = Now();
  5271. try
  5272. {
  5273. Params.OnProcessedItem = OnProcessedItem;
  5274. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5275. CreateProgressForm(&SynchronizeProgress);
  5276. Terminal->SynchronizeApply(
  5277. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5278. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5279. &Statistics);
  5280. }
  5281. __finally
  5282. {
  5283. Params.OnProcessedItem = NULL;
  5284. FAutoOperation = false;
  5285. DestroyProgressForm();
  5286. BatchEnd(BatchStorage);
  5287. ReloadLocalDirectory();
  5288. }
  5289. if (WinConfiguration->SynchronizeSummary)
  5290. {
  5291. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5292. // The statistics should be 0 anyway in this case
  5293. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5294. {
  5295. Message += L"\n";
  5296. if (Statistics.FilesUploaded > 0)
  5297. {
  5298. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5299. }
  5300. if (Statistics.FilesDownloaded > 0)
  5301. {
  5302. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5303. }
  5304. if (Statistics.FilesDeletedLocal > 0)
  5305. {
  5306. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5307. }
  5308. if (Statistics.FilesDeletedRemote > 0)
  5309. {
  5310. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5311. }
  5312. }
  5313. TDateTime Elapsed = (Now() - Start);
  5314. Message +=
  5315. L"\n" +
  5316. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5317. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5318. TMessageParams Params(mpNeverAskAgainCheck);
  5319. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5320. if (Result == qaNeverAskAgain)
  5321. {
  5322. WinConfiguration->SynchronizeSummary = false;
  5323. }
  5324. }
  5325. }
  5326. //---------------------------------------------------------------------------
  5327. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5328. {
  5329. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5330. {
  5331. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5332. }
  5333. // Not set in keep-up-to-date mode - Synchronize() method
  5334. if (Token != NULL)
  5335. {
  5336. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5337. if (Params.OnProcessedItem != NULL)
  5338. {
  5339. Params.OnProcessedItem(NULL, ChecklistItem);
  5340. }
  5341. }
  5342. }
  5343. //---------------------------------------------------------------------------
  5344. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5345. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5346. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5347. {
  5348. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5349. *Params.StartTime = Now();
  5350. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5351. }
  5352. //---------------------------------------------------------------------------
  5353. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5354. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5355. {
  5356. // terminal can be already closed (e.g. dropped connection)
  5357. if (Terminal != NULL)
  5358. {
  5359. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5360. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5361. }
  5362. }
  5363. //---------------------------------------------------------------------------
  5364. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5365. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5366. {
  5367. DebugAssert(!IsLocalBrowserMode());
  5368. TAutoBatch AutoBatch(this);
  5369. TAutoFlag AutoOperationFlag(FAutoOperation);
  5370. if (Side == osRemote)
  5371. {
  5372. std::unique_ptr<TStrings> FileList(new TStringList());
  5373. FileList->AddObject(FileName, RemoteFile);
  5374. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5375. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5376. RemoteDirView->SaveSelection();
  5377. RemoteDirView->SaveSelectedNames();
  5378. try
  5379. {
  5380. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5381. }
  5382. catch(...)
  5383. {
  5384. RemoteDirView->DiscardSavedSelection();
  5385. throw;
  5386. }
  5387. RemoteDirView->RestoreSelection();
  5388. }
  5389. else if (DebugAlwaysTrue(Side == osLocal))
  5390. {
  5391. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5392. {
  5393. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5394. }
  5395. UnicodeString Directory = ExtractFileDir(FileName);
  5396. ReloadLocalDirectory(Directory);
  5397. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5398. if (!SamePaths(Directory, NewDirectory))
  5399. {
  5400. ReloadLocalDirectory(NewDirectory);
  5401. }
  5402. }
  5403. }
  5404. //---------------------------------------------------------------------------
  5405. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5406. {
  5407. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5408. if (Side == osLocal)
  5409. {
  5410. if (Action == TSynchronizeChecklist::saDownloadNew)
  5411. {
  5412. OpenFolderInExplorer(LocalPath);
  5413. }
  5414. else
  5415. {
  5416. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5417. }
  5418. }
  5419. else if (DebugAlwaysTrue(Side == osRemote))
  5420. {
  5421. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5422. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5423. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5424. if (!LocalPath.IsEmpty())
  5425. {
  5426. SessionData->LocalDirectory = LocalPath;
  5427. }
  5428. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5429. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5430. }
  5431. }
  5432. //---------------------------------------------------------------------------
  5433. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5434. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5435. const TCopyParamType * CopyParams)
  5436. {
  5437. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5438. UnicodeString AdditionalParams =
  5439. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5440. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5441. SerializeCopyParamForCommandLine(CopyParams),
  5442. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5443. LocalDirectory, RemoteDirectory, Mode, Params));
  5444. ExecuteNewInstance(SessionName, AdditionalParams);
  5445. }
  5446. //---------------------------------------------------------------------------
  5447. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5448. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5449. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5450. {
  5451. int Result;
  5452. bool SaveSettings = false;
  5453. int Options =
  5454. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5455. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5456. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5457. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5458. bool Continue =
  5459. (UseDefaults == 0) ||
  5460. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5461. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5462. if (Continue)
  5463. {
  5464. Configuration->Usage->Inc(L"Synchronizations");
  5465. UpdateCopyParamCounters(CopyParam);
  5466. TSynchronizeOptions SynchronizeOptions;
  5467. GetSynchronizeOptions(Params, SynchronizeOptions);
  5468. if (SaveSettings)
  5469. {
  5470. GUIConfiguration->SynchronizeParams = Params;
  5471. }
  5472. else
  5473. {
  5474. SaveMode = false;
  5475. }
  5476. TDateTime StartTime = Now();
  5477. TSynchronizeChecklist * Checklist = NULL;
  5478. try
  5479. {
  5480. DebugAssert(!FAutoOperation);
  5481. FAutoOperation = true;
  5482. try
  5483. {
  5484. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5485. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5486. int Files = -1;
  5487. if (DataList->Count >= 1)
  5488. {
  5489. Files = StrToIntDef(DataList->Strings[0], Files);
  5490. }
  5491. else
  5492. {
  5493. DataList->Add(UnicodeString());
  5494. }
  5495. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5496. FSynchronizeProgressForm->Start();
  5497. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5498. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5499. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5500. &SynchronizeOptions);
  5501. if (Terminal->SessionData->CacheDirectories)
  5502. {
  5503. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5504. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5505. }
  5506. }
  5507. __finally
  5508. {
  5509. FAutoOperation = false;
  5510. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5511. SAFE_DESTROY(FSynchronizeProgressForm);
  5512. }
  5513. TSynchronizeParams SynchronizeParams;
  5514. SynchronizeParams.LocalDirectory = LocalDirectory;
  5515. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5516. SynchronizeParams.Mode = Mode;
  5517. SynchronizeParams.CopyParam = &CopyParam;
  5518. SynchronizeParams.Params = Params;
  5519. SynchronizeParams.Checklist = Checklist;
  5520. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5521. SynchronizeParams.StartTime = &StartTime;
  5522. SynchronizeParams.OnProcessedItem = NULL;
  5523. Result = Checklist->Count;
  5524. if (Checklist->Count > 0)
  5525. {
  5526. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5527. {
  5528. if (!DoSynchronizeChecklistDialog(
  5529. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5530. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5531. {
  5532. Result = -1;
  5533. }
  5534. }
  5535. else
  5536. {
  5537. FullSynchronize(SynchronizeParams, NULL, NULL);
  5538. }
  5539. }
  5540. else
  5541. {
  5542. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5543. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5544. }
  5545. }
  5546. __finally
  5547. {
  5548. delete Checklist;
  5549. }
  5550. OperationComplete(StartTime);
  5551. }
  5552. else
  5553. {
  5554. Result = -1;
  5555. }
  5556. return Result;
  5557. }
  5558. //---------------------------------------------------------------------------
  5559. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5560. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5561. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5562. {
  5563. if (Collect)
  5564. {
  5565. DebugAssert(FSynchronizeProgressForm != NULL);
  5566. if (!FSynchronizeProgressForm->Started)
  5567. {
  5568. FSynchronizeProgressForm->Start();
  5569. }
  5570. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5571. SetTaskbarListProgressValue(CompareProgress);
  5572. }
  5573. else
  5574. {
  5575. DebugAssert(FSynchronizeProgressForm == NULL);
  5576. DebugAssert(FProgressForm != NULL);
  5577. }
  5578. }
  5579. //---------------------------------------------------------------------------
  5580. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5581. {
  5582. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5583. TRemoteFile * File = NULL;
  5584. Terminal->ReadFile(FullFileName, File);
  5585. if (File != NULL)
  5586. {
  5587. std::unique_ptr<TRemoteFile> FileOwner(File);
  5588. TAutoFlag Flag(FStandaloneEditing);
  5589. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5590. Application->ShowMainForm = false;
  5591. Application->Run();
  5592. }
  5593. }
  5594. //---------------------------------------------------------------------------
  5595. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5596. {
  5597. DebugFail();
  5598. }
  5599. //---------------------------------------------------------------------------
  5600. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5601. {
  5602. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5603. SessionData->Assign(Terminal->SessionData);
  5604. UpdateSessionData(SessionData.get());
  5605. Terminal->UpdateSessionCredentials(SessionData.get());
  5606. if (!Terminal->SessionData->HasSessionName())
  5607. {
  5608. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5609. // once IsWorkspace is cleared
  5610. SessionData->Name = UnicodeString();
  5611. SessionData->IsWorkspace = false;
  5612. }
  5613. return SessionData.release();
  5614. }
  5615. //---------------------------------------------------------------------------
  5616. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5617. {
  5618. TSessionData * SessionData = CloneCurrentSessionData();
  5619. try
  5620. {
  5621. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5622. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5623. }
  5624. __finally
  5625. {
  5626. delete SessionData;
  5627. }
  5628. }
  5629. //---------------------------------------------------------------------------
  5630. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5631. {
  5632. TTerminalManager * Manager = TTerminalManager::Instance();
  5633. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5634. if (DebugAlwaysTrue(Terminal != NULL))
  5635. {
  5636. // Update (Managed)Terminal->StateData
  5637. UpdateTerminal(Terminal);
  5638. }
  5639. Manager->SaveWorkspace(DataList.get());
  5640. return DataList.release();
  5641. }
  5642. //---------------------------------------------------------------------------
  5643. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5644. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5645. {
  5646. WinConfiguration->LastWorkspace = Name;
  5647. if (!SavePasswords)
  5648. {
  5649. for (int Index = 0; Index < DataList->Count; Index++)
  5650. {
  5651. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5652. if (SessionData->Link.IsEmpty())
  5653. {
  5654. SessionData->ClearSessionPasswords();
  5655. }
  5656. }
  5657. }
  5658. StoredSessions->NewWorkspace(Name, DataList);
  5659. // modified only
  5660. StoredSessions->Save(false, Explicit);
  5661. }
  5662. //---------------------------------------------------------------------------
  5663. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5664. {
  5665. return
  5666. DefaultStr(WinConfiguration->LastWorkspace,
  5667. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5668. }
  5669. //---------------------------------------------------------------------------
  5670. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5671. {
  5672. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5673. bool AnyNonStoredSessionWithPassword = false;
  5674. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5675. bool AllNonStoredSessionsAnonymous = true;
  5676. TTerminalManager * Manager = TTerminalManager::Instance();
  5677. for (int Index = 0; Index < DataList->Count; Index++)
  5678. {
  5679. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5680. if (SessionData->Link.IsEmpty())
  5681. {
  5682. if (SessionData->HasAnySessionPassword())
  5683. {
  5684. AnyNonStoredSessionWithPassword = true;
  5685. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5686. {
  5687. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5688. }
  5689. }
  5690. if (!SameText(SessionData->UserName, AnonymousUserName))
  5691. {
  5692. AllNonStoredSessionsAnonymous = false;
  5693. }
  5694. }
  5695. }
  5696. bool SavePasswords;
  5697. bool * PSavePasswords;
  5698. bool NotRecommendedSavingPasswords =
  5699. !CustomWinConfiguration->UseMasterPassword &&
  5700. !AllNonStoredSessionsAnonymous;
  5701. if (Configuration->DisablePasswordStoring ||
  5702. !AnyNonStoredSessionWithPassword)
  5703. {
  5704. PSavePasswords = NULL;
  5705. SavePasswords = false;
  5706. }
  5707. else
  5708. {
  5709. PSavePasswords = &SavePasswords;
  5710. SavePasswords =
  5711. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5712. !NotRecommendedSavingPasswords;
  5713. }
  5714. UnicodeString Name = WorkspaceName();
  5715. bool CreateShortcut = false;
  5716. bool Result =
  5717. DoSaveWorkspaceDialog(
  5718. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5719. EnableAutoSave);
  5720. if (Result)
  5721. {
  5722. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5723. if (CreateShortcut)
  5724. {
  5725. TOperationVisualizer Visualizer;
  5726. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5727. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5728. }
  5729. if (EnableAutoSave)
  5730. {
  5731. WinConfiguration->AutoSaveWorkspace = true;
  5732. WinConfiguration->AutoWorkspace = Name;
  5733. if (PSavePasswords != NULL)
  5734. {
  5735. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5736. }
  5737. }
  5738. }
  5739. return Result;
  5740. }
  5741. //---------------------------------------------------------------------------
  5742. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5743. {
  5744. DebugAssert(!IsLocalBrowserMode());
  5745. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5746. if (WinConfiguration->PreservePanelState)
  5747. {
  5748. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5749. }
  5750. UpdateSessionData(Terminal->StateData);
  5751. }
  5752. //---------------------------------------------------------------------------
  5753. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5754. {
  5755. // Keep in sync with TSessionData::CopyStateData
  5756. DebugAssert(!IsLocalBrowserMode());
  5757. DebugAssert(Data != NULL);
  5758. // This is inconsistent with how color (for example) is handled.
  5759. Data->Name = Terminal->SessionData->Name;
  5760. // cannot use RemoteDirView->Path, because it is empty if connection
  5761. // was already closed
  5762. // also only peek, we may not be connected at all atm
  5763. // so make sure we do not try retrieving current directory from the server
  5764. // (particularly with FTP)
  5765. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5766. if (!ACurrentDirectory.IsEmpty())
  5767. {
  5768. Data->RemoteDirectory = ACurrentDirectory;
  5769. }
  5770. Data->Color = SessionColor;
  5771. }
  5772. //---------------------------------------------------------------------------
  5773. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5774. {
  5775. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5776. DebugAssert(Toolbar != NULL);
  5777. for (int i = 0; i < Toolbar->Items->Count; i++)
  5778. {
  5779. TTBXCustomDropDownItem * DropDownItem;
  5780. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5781. if (DropDownItem != NULL)
  5782. {
  5783. ToolbarItemResize(DropDownItem,
  5784. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5785. Toolbar->NonClientWidth);
  5786. break;
  5787. }
  5788. }
  5789. }
  5790. //---------------------------------------------------------------------------
  5791. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5792. {
  5793. Item->EditWidth = Width;
  5794. }
  5795. //---------------------------------------------------------------------------
  5796. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5797. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5798. {
  5799. for (int i = 0; i < Toolbar->Items->Count; i++)
  5800. {
  5801. TTBXCustomDropDownItem * DropDownItem;
  5802. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5803. if (DropDownItem != NULL)
  5804. {
  5805. ASize.x -= DropDownItem->EditWidth;
  5806. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5807. }
  5808. }
  5809. }
  5810. //---------------------------------------------------------------------------
  5811. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5812. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5813. {
  5814. if (WinConfiguration->DDWarnLackOfTempSpace)
  5815. {
  5816. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5817. if (!ADrive.IsEmpty())
  5818. {
  5819. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5820. DebugAssert(RequiredSpace >= 0);
  5821. __int64 RequiredWithReserve;
  5822. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5823. if (FreeSpace < RequiredWithReserve)
  5824. {
  5825. unsigned int Result;
  5826. TMessageParams Params(mpNeverAskAgainCheck);
  5827. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5828. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5829. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5830. if (Result == qaNeverAskAgain)
  5831. {
  5832. WinConfiguration->DDWarnLackOfTempSpace = false;
  5833. }
  5834. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5835. }
  5836. }
  5837. }
  5838. }
  5839. //---------------------------------------------------------------------------
  5840. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5841. {
  5842. DoOpenDirectoryDialog(odAddBookmark, Side);
  5843. }
  5844. //---------------------------------------------------------------------------
  5845. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5846. {
  5847. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5848. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5849. try
  5850. {
  5851. TCustomDirView * DView = DirView(Side);
  5852. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5853. {
  5854. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5855. }
  5856. }
  5857. catch (...)
  5858. {
  5859. delete VisitedDirectories;
  5860. throw;
  5861. }
  5862. return VisitedDirectories;
  5863. }
  5864. //---------------------------------------------------------------------------
  5865. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5866. TOpenDirectoryMode Mode, TOperationSide Side)
  5867. {
  5868. bool Continue = true;
  5869. if (Mode == odAddBookmark)
  5870. {
  5871. TMessageParams Params(mpNeverAskAgainCheck);
  5872. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5873. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5874. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5875. unsigned int Answer =
  5876. MessageDialog(Message,
  5877. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5878. if (Answer == qaNeverAskAgain)
  5879. {
  5880. Continue = true;
  5881. WinConfiguration->UseSharedBookmarks = true;
  5882. }
  5883. else if (Answer == qaOK)
  5884. {
  5885. Continue = true;
  5886. WinConfiguration->UseSharedBookmarks = false;
  5887. }
  5888. else
  5889. {
  5890. Continue = false;
  5891. }
  5892. }
  5893. if (Continue)
  5894. {
  5895. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5896. try
  5897. {
  5898. UnicodeString Name = DirView(Side)->PathName;
  5899. bool Repeat;
  5900. do
  5901. {
  5902. Repeat = false;
  5903. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5904. // do not allow switching to location profiles,
  5905. // if we are not connected
  5906. HasDirView[osLocal] && (Terminal != NULL)))
  5907. {
  5908. TWindowLock Lock(this);
  5909. if (!TryOpenDirectory(Side, Name))
  5910. {
  5911. Repeat = true;
  5912. Mode = odBrowse;
  5913. }
  5914. }
  5915. }
  5916. while (Repeat);
  5917. }
  5918. __finally
  5919. {
  5920. delete VisitedDirectories;
  5921. }
  5922. }
  5923. }
  5924. //---------------------------------------------------------------------------
  5925. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5926. {
  5927. DebugAssert(!FTerminal->CommandSessionOpened);
  5928. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5929. }
  5930. //---------------------------------------------------------------------------
  5931. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5932. {
  5933. bool Result = FTerminal->IsCapable[Capability] ||
  5934. FTerminal->CommandSessionOpened;
  5935. if (!Result)
  5936. {
  5937. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5938. if (!GUIConfiguration->ConfirmCommandSession)
  5939. {
  5940. Result = true;
  5941. }
  5942. else
  5943. {
  5944. TMessageParams Params(mpNeverAskAgainCheck);
  5945. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5946. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5947. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5948. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5949. if (Answer == qaNeverAskAgain)
  5950. {
  5951. GUIConfiguration->ConfirmCommandSession = false;
  5952. Result = true;
  5953. }
  5954. else if (Answer == qaOK)
  5955. {
  5956. Result = true;
  5957. }
  5958. }
  5959. if (Result)
  5960. {
  5961. Result = CommandSessionFallback();
  5962. }
  5963. }
  5964. return Result;
  5965. }
  5966. //---------------------------------------------------------------------------
  5967. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5968. {
  5969. if (EnsureCommandSessionFallback(fcAnyCommand))
  5970. {
  5971. DoConsoleDialog(Terminal, Command);
  5972. }
  5973. }
  5974. //---------------------------------------------------------------------------
  5975. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5976. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5977. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5978. {
  5979. if (!IsSideLocalBrowser(osRemote) &&
  5980. IsFileControl(DropSourceControl, osRemote) &&
  5981. (FDDExtMapFile != NULL))
  5982. {
  5983. Accept = true;
  5984. }
  5985. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5986. DebugAssert(FDDTargetControl != NULL);
  5987. }
  5988. //---------------------------------------------------------------------------
  5989. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5990. _di_IDataObject DataObj, int KeyState,
  5991. const TPoint & Point, int & Effect, bool & Accept)
  5992. {
  5993. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5994. }
  5995. //---------------------------------------------------------------------------
  5996. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5997. _di_IDataObject DataObj, int KeyState,
  5998. const TPoint & Point, int & Effect, bool & Accept)
  5999. {
  6000. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6001. }
  6002. //---------------------------------------------------------------------------
  6003. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6004. TObject * Sender)
  6005. {
  6006. DebugUsedParam(Sender);
  6007. DebugAssert(FDDTargetControl == Sender);
  6008. FDDTargetControl = NULL;
  6009. }
  6010. //---------------------------------------------------------------------------
  6011. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6012. {
  6013. FileControlDDDragLeave(SessionsPageControl);
  6014. }
  6015. //---------------------------------------------------------------------------
  6016. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6017. {
  6018. FileControlDDDragLeave(QueueView3);
  6019. }
  6020. //---------------------------------------------------------------------------
  6021. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6022. {
  6023. DebugAssert(!IsSideLocalBrowser(Side));
  6024. DebugUsedParam(Side);
  6025. bool Edit = false;
  6026. TRemoteFile * File = NULL;
  6027. UnicodeString FileName;
  6028. UnicodeString PointTo;
  6029. bool SymbolicLink = true;
  6030. if (RemoteDirView->ItemFocused)
  6031. {
  6032. DebugAssert(RemoteDirView->ItemFocused->Data);
  6033. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6034. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6035. if (Edit)
  6036. {
  6037. FileName = File->FileName;
  6038. PointTo = File->LinkTo;
  6039. }
  6040. else
  6041. {
  6042. PointTo = File->FileName;
  6043. }
  6044. }
  6045. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6046. Terminal->IsCapable[fcHardLink]))
  6047. {
  6048. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6049. if (Edit)
  6050. {
  6051. DebugAssert(File->FileName == FileName);
  6052. int Params = dfNoRecursive;
  6053. Terminal->ExceptionOnFail = true;
  6054. try
  6055. {
  6056. Terminal->DeleteFile(L"", File, &Params);
  6057. }
  6058. __finally
  6059. {
  6060. Terminal->ExceptionOnFail = false;
  6061. }
  6062. }
  6063. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6064. }
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6068. {
  6069. return
  6070. (IsSideLocalBrowser(Side) ||
  6071. ((Terminal != NULL) &&
  6072. Terminal->Active &&
  6073. Terminal->ResolvingSymlinks &&
  6074. Terminal->IsCapable[fcSymbolicLink]));
  6075. }
  6076. //---------------------------------------------------------------------------
  6077. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6078. {
  6079. return
  6080. !IsSideLocalBrowser(FCurrentSide) &&
  6081. (RemoteDirView->ItemFocused != NULL) &&
  6082. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6083. Terminal->SessionData->ResolveSymlinks;
  6084. }
  6085. //---------------------------------------------------------------------------
  6086. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6087. {
  6088. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6089. FForceExecution = true;
  6090. try
  6091. {
  6092. DirView(osCurrent)->ExecuteCurrentFile();
  6093. }
  6094. __finally
  6095. {
  6096. FForceExecution = false;
  6097. }
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6101. {
  6102. TEditorData ExternalEditor;
  6103. ExternalEditor.Editor = edExternal;
  6104. bool Remember = false;
  6105. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6106. {
  6107. if (Remember)
  6108. {
  6109. TEditorList * EditorList = new TEditorList;
  6110. try
  6111. {
  6112. *EditorList = *WinConfiguration->EditorList;
  6113. bool Found = false;
  6114. int i = 0;
  6115. while (!Found && (i < EditorList->Count))
  6116. {
  6117. const TEditorPreferences * Editor = EditorList->Editors[i];
  6118. if ((Editor->Data->Editor == edExternal) &&
  6119. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6120. {
  6121. Found = true;
  6122. }
  6123. i++;
  6124. }
  6125. if (!Found)
  6126. {
  6127. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6128. WinConfiguration->EditorList = EditorList;
  6129. }
  6130. }
  6131. __finally
  6132. {
  6133. delete EditorList;
  6134. }
  6135. }
  6136. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6137. }
  6138. }
  6139. //---------------------------------------------------------------------------
  6140. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6141. {
  6142. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6143. if (FFileFindTerminal == Sender)
  6144. {
  6145. FFileFindTerminal = NULL;
  6146. HideFileFindDialog();
  6147. }
  6148. if (FClipboardTerminal == Sender)
  6149. {
  6150. ClipboardClear(); // implies ClipboardStop
  6151. }
  6152. }
  6153. //---------------------------------------------------------------------------
  6154. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6155. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6156. {
  6157. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6158. DebugAssert(Terminal != NULL);
  6159. if (Data->Terminal == Terminal)
  6160. {
  6161. Data->Terminal = NULL;
  6162. }
  6163. }
  6164. //---------------------------------------------------------------------------
  6165. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6166. {
  6167. UpdateControls();
  6168. SessionColor = TColor(0);
  6169. UpdateRemotePathComboBox(false);
  6170. NeedSession(false);
  6171. }
  6172. //---------------------------------------------------------------------------
  6173. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6174. {
  6175. try
  6176. {
  6177. // Cache, as the login dialog can change its value
  6178. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6179. try
  6180. {
  6181. if (ShowLogin)
  6182. {
  6183. bool ReloadSessions = !Startup;
  6184. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6185. }
  6186. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6187. // This detects if workspace was saved the last time the main widow was closed
  6188. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6189. {
  6190. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6191. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6192. }
  6193. }
  6194. __finally
  6195. {
  6196. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6197. // (so there was no chance for the user to open any session yet)
  6198. if ((ShowLogin || !Startup) &&
  6199. !WinConfiguration->KeepOpenWhenNoSession &&
  6200. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6201. {
  6202. TerminateApplication();
  6203. }
  6204. }
  6205. }
  6206. catch (EAbort &)
  6207. {
  6208. // swallow
  6209. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6210. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6211. }
  6212. }
  6213. //---------------------------------------------------------------------------
  6214. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6215. {
  6216. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6217. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6218. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6219. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6220. try
  6221. {
  6222. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6223. // Clear the design time unthemed tab
  6224. ((SessionsPageControl->PageCount > 0) &&
  6225. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6226. {
  6227. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6228. }
  6229. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6230. {
  6231. TThemeTabSheet * TabSheet;
  6232. if (Index >= SessionsPageControl->PageCount)
  6233. {
  6234. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6235. TabSheet->PageControl = SessionsPageControl;
  6236. }
  6237. else
  6238. {
  6239. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6240. }
  6241. bool IsSessionTab = (Index < TerminalList->Count);
  6242. if (IsSessionTab)
  6243. {
  6244. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6245. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6246. UpdateSessionTab(TabSheet);
  6247. }
  6248. else
  6249. {
  6250. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6251. TabSheet->Tag = 0; // not really needed
  6252. TabSheet->Shadowed = false;
  6253. // 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)
  6254. UpdateNewSessionTab();
  6255. }
  6256. TabSheet->ShowCloseButton = IsSessionTab;
  6257. }
  6258. }
  6259. __finally
  6260. {
  6261. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6262. }
  6263. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6267. {
  6268. DoTerminalListChanged();
  6269. }
  6270. //---------------------------------------------------------------------------
  6271. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6272. {
  6273. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6274. DebugAssert(TabSheet->ImageIndex == 0);
  6275. TabSheet->Caption =
  6276. WinConfiguration->SelectiveToolbarText ?
  6277. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6278. UnicodeString();
  6279. }
  6280. //---------------------------------------------------------------------------
  6281. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6282. {
  6283. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6284. }
  6285. //---------------------------------------------------------------------------
  6286. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6287. {
  6288. if (DebugAlwaysTrue(TabSheet != NULL))
  6289. {
  6290. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6291. if (DebugAlwaysTrue(ATerminal != NULL))
  6292. {
  6293. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6294. TabSheet->ImageIndex = AddSessionColor(Color);
  6295. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6296. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6297. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6298. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6299. {
  6300. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6301. }
  6302. }
  6303. }
  6304. }
  6305. //---------------------------------------------------------------------------
  6306. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6307. {
  6308. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6309. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6310. bool Result = (Terminal != NULL);
  6311. if (Result)
  6312. {
  6313. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6314. }
  6315. else
  6316. {
  6317. try
  6318. {
  6319. NewSession(false);
  6320. }
  6321. __finally
  6322. {
  6323. DoTerminalListChanged();
  6324. }
  6325. FSessionsPageControlNewSessionTime = Now();
  6326. }
  6327. return Result;
  6328. }
  6329. //---------------------------------------------------------------------------
  6330. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6331. {
  6332. SessionTabSwitched();
  6333. }
  6334. //---------------------------------------------------------------------------
  6335. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6336. {
  6337. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6338. DebugAssert(TransferList != NULL);
  6339. UnicodeString Name;
  6340. if (TransferList->ItemIndex <= 0)
  6341. {
  6342. Name = L"";
  6343. }
  6344. else
  6345. {
  6346. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6347. }
  6348. if (FCopyParamAutoSelected.IsEmpty())
  6349. {
  6350. // if previous preset was not autoselected, make new preset the "default"
  6351. FCopyParamDefault = Name;
  6352. }
  6353. GUIConfiguration->CopyParamCurrent = Name;
  6354. }
  6355. //---------------------------------------------------------------------------
  6356. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6357. {
  6358. // sanity check
  6359. bool ExistingPreset =
  6360. (FTransferListHoverIndex >= 0) &&
  6361. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6362. DebugAssert(ExistingPreset);
  6363. if (ExistingPreset)
  6364. {
  6365. HDC DC = GetDC(0);
  6366. TCanvas * Canvas = new TCanvas();
  6367. try
  6368. {
  6369. Canvas->Handle = DC;
  6370. Canvas->Font = GetToolbarFont(this);
  6371. UnicodeString Name;
  6372. if (FTransferListHoverIndex == 0)
  6373. {
  6374. Name = L"";
  6375. }
  6376. else
  6377. {
  6378. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6379. }
  6380. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6381. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6382. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6383. static_cast<TObject*>(GetComponent(fcTransferList)));
  6384. UnicodeString InfoStr =
  6385. GUIConfiguration->CopyParamPreset[Name].
  6386. GetInfoStr(L"; ",
  6387. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6388. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6389. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6390. {
  6391. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6392. {
  6393. InfoStr.SetLength(InfoStr.Length() - 1);
  6394. }
  6395. InfoStr += Ellipsis;
  6396. }
  6397. // UpdateCaption does not cause invalidation of whole submenu, while
  6398. // setting Caption property does.
  6399. // also it probably does not resize the label, even if necessary
  6400. // (we do not want that anyway)
  6401. TransferLabel->UpdateCaption(InfoStr);
  6402. }
  6403. __finally
  6404. {
  6405. Canvas->Handle = NULL;
  6406. ReleaseDC(0, DC);
  6407. delete Canvas;
  6408. }
  6409. }
  6410. }
  6411. //---------------------------------------------------------------------------
  6412. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6413. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6414. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6415. {
  6416. if (FTransferListHoverIndex != AHoverIndex)
  6417. {
  6418. FTransferListHoverIndex = AHoverIndex;
  6419. UpdateTransferLabel();
  6420. }
  6421. }
  6422. //---------------------------------------------------------------------------
  6423. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6424. {
  6425. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6426. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6427. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6428. {
  6429. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6430. {
  6431. OpenDirectory(GetSide(osCurrent));
  6432. Message.Result = 1;
  6433. }
  6434. else
  6435. {
  6436. TForm::Dispatch(&Message);
  6437. }
  6438. }
  6439. else
  6440. {
  6441. TForm::Dispatch(&Message);
  6442. }
  6443. }
  6444. //---------------------------------------------------------------------------
  6445. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6446. {
  6447. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6448. if ((FIgnoreNextDialogChar != 0) &&
  6449. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6450. {
  6451. Message.Result = 1;
  6452. }
  6453. else
  6454. {
  6455. TForm::Dispatch(&Message);
  6456. }
  6457. FIgnoreNextDialogChar = 0;
  6458. }
  6459. //---------------------------------------------------------------------------
  6460. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6461. {
  6462. // The four low-order bits are used internally by Windows
  6463. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6464. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6465. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6466. // 61730 - restore thru double click - undocumented
  6467. // 61490 - maximize thru double click - undocumented
  6468. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6469. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6470. {
  6471. SysResizing(Cmd);
  6472. }
  6473. TForm::Dispatch(&Message);
  6474. }
  6475. //---------------------------------------------------------------------------
  6476. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6477. {
  6478. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6479. // Also there no point returning TRUE as we are not able to
  6480. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6481. // Hence the process termination might be safer :)
  6482. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6483. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6484. {
  6485. Message.Result = FALSE;
  6486. }
  6487. else
  6488. {
  6489. Message.Result = TRUE;
  6490. }
  6491. // Do not call default handling as that triggers OnCloseQuery,
  6492. // where our implementation will popup confirmation dialogs, what we do not want,
  6493. // as per Vista guidelines:
  6494. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6495. }
  6496. //---------------------------------------------------------------------------
  6497. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6498. {
  6499. if (Message.EndSession && IsApplicationMinimized())
  6500. {
  6501. // WORKAROUND
  6502. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6503. // when it receives WM_ENDSESSION,
  6504. // but that sometimes (particularly when application is minimized) cause crashes.
  6505. // Crash popups message that blocks log off.
  6506. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6507. // so we call ExitProcess() immediately, not even trying to cleanup.
  6508. // It still causes beep, so there's likely some popup, but it does not block
  6509. // log off.
  6510. ExitProcess(0);
  6511. }
  6512. TForm::Dispatch(&Message);
  6513. }
  6514. #ifdef _DEBUG
  6515. //---------------------------------------------------------------------------
  6516. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6517. {
  6518. TForm::Dispatch(&Message);
  6519. }
  6520. #endif
  6521. //---------------------------------------------------------------------------
  6522. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6523. {
  6524. }
  6525. //---------------------------------------------------------------------------
  6526. void __fastcall TCustomScpExplorerForm::DoShow()
  6527. {
  6528. // only now are the controls resized finally, so the size constraints
  6529. // will not conflict with possibly very small window size
  6530. RestoreFormParams();
  6531. // This indicates that the form was rescaled after parameters were loaded and
  6532. // as most probably the parameters were actually saved with the current form scaling
  6533. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6534. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6535. // and no rounding problems will occur.
  6536. // See also RestoreForm.
  6537. // (we should be safe to call RestoreParams unconditionally)
  6538. if (PixelsPerInch != Screen->PixelsPerInch)
  6539. {
  6540. RestoreParams();
  6541. }
  6542. FixControlsPlacement();
  6543. if (Position == poDefaultPosOnly)
  6544. {
  6545. CutFormToDesktop(this);
  6546. }
  6547. TForm::DoShow();
  6548. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6549. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6550. if (Terminal == NULL)
  6551. {
  6552. StartingDisconnected();
  6553. }
  6554. UpdatePixelsPerInchMainWindowCounter();
  6555. FShowing = true;
  6556. }
  6557. //---------------------------------------------------------------------------
  6558. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6559. {
  6560. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6561. }
  6562. //---------------------------------------------------------------------------
  6563. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6564. {
  6565. DoTerminalListChanged();
  6566. }
  6567. //---------------------------------------------------------------------------
  6568. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6569. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6570. TNotifyEvent OnBalloonClick, TObject * UserData)
  6571. {
  6572. bool Do;
  6573. UnicodeString Message;
  6574. if (E == NULL)
  6575. {
  6576. Message = Str;
  6577. Do = true;
  6578. }
  6579. else
  6580. {
  6581. Do = ExceptionMessage(E, Message);
  6582. }
  6583. if (Do && WinConfiguration->BalloonNotifications)
  6584. {
  6585. UnicodeString Title;
  6586. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6587. {
  6588. Message = TrimLeft(Message);
  6589. }
  6590. else
  6591. {
  6592. Message = UnformatMessage(Message);
  6593. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6594. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6595. Title = LoadResourceString(Captions[Type]);
  6596. if (Terminal != NULL)
  6597. {
  6598. Title = FORMAT(L"%s - %s",
  6599. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6600. }
  6601. }
  6602. if (Seconds == 0)
  6603. {
  6604. Seconds = WinConfiguration->NotificationsTimeout;
  6605. }
  6606. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6607. }
  6608. }
  6609. //---------------------------------------------------------------------------
  6610. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6611. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6612. UnicodeString HelpKeyword, const TMessageParams * Params,
  6613. TTerminal * Terminal)
  6614. {
  6615. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6616. (FOnFeedSynchronizeError != NULL)) &&
  6617. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6618. {
  6619. if (FOnFeedSynchronizeError != NULL)
  6620. {
  6621. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6622. }
  6623. else
  6624. {
  6625. DebugAssert(FErrorList != NULL);
  6626. TStringList * MoreMessagesCopy = NULL;
  6627. if (MoreMessages)
  6628. {
  6629. MoreMessagesCopy = new TStringList();
  6630. MoreMessagesCopy->Assign(MoreMessages);
  6631. }
  6632. FErrorList->AddObject(Message, MoreMessagesCopy);
  6633. }
  6634. PopupTrayBalloon(Terminal, Message, Type);
  6635. return ContinueAnswer(Answers);
  6636. }
  6637. else
  6638. {
  6639. bool UseBalloon = FTrayIcon->Visible;
  6640. if (UseBalloon)
  6641. {
  6642. PopupTrayBalloon(Terminal, Message, Type);
  6643. }
  6644. unsigned int Result;
  6645. try
  6646. {
  6647. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6648. }
  6649. __finally
  6650. {
  6651. // cancel only balloon we popped up, otherwise we may cancel notification
  6652. // balloon that was there before the message dialog
  6653. // (such as "dd confirmation opt in balloon)
  6654. if (UseBalloon)
  6655. {
  6656. FTrayIcon->CancelBalloon();
  6657. }
  6658. }
  6659. return Result;
  6660. }
  6661. }
  6662. //---------------------------------------------------------------------------
  6663. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6664. TTerminal * Terminal, Exception * E)
  6665. {
  6666. if (FTrayIcon->Visible)
  6667. {
  6668. PopupTrayBalloon(Terminal, L"", qtError, E);
  6669. }
  6670. // particularly prevent opening new session from jump list,
  6671. // while exception is shown
  6672. NonVisualDataModule->StartBusy();
  6673. try
  6674. {
  6675. ShowExtendedExceptionEx(Terminal, E);
  6676. }
  6677. __finally
  6678. {
  6679. NonVisualDataModule->EndBusy();
  6680. FTrayIcon->CancelBalloon();
  6681. }
  6682. }
  6683. //---------------------------------------------------------------------------
  6684. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6685. {
  6686. if (Terminal->Active)
  6687. {
  6688. InitStatusBar();
  6689. }
  6690. // cannot rely on active page being page for active terminal,
  6691. // as it can happen that active page is the "new session" page
  6692. // (e.g. when reconnecting active terminal, while login dialog
  6693. // invoked from "new session" page is modal)
  6694. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6695. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6696. }
  6697. //---------------------------------------------------------------------------
  6698. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6699. TTerminal * Terminal, Exception * E)
  6700. {
  6701. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6702. if (!Terminal->Active)
  6703. {
  6704. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6705. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6706. {
  6707. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6708. }
  6709. }
  6710. }
  6711. //---------------------------------------------------------------------------
  6712. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6713. UnicodeString Message, TQueryType Type,
  6714. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6715. {
  6716. if ((E == NULL) ||
  6717. ExceptionMessage(E, Message))
  6718. {
  6719. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6720. if (Important)
  6721. {
  6722. Seconds *= 5;
  6723. }
  6724. UnicodeString NoteMessage(UnformatMessage(Message));
  6725. if (Terminal != NULL)
  6726. {
  6727. NoteMessage = FORMAT(L"%s: %s",
  6728. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6729. }
  6730. if (WinConfiguration->BalloonNotifications)
  6731. {
  6732. AddNote(NoteMessage);
  6733. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6734. }
  6735. else
  6736. {
  6737. FlashOnBackground();
  6738. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6739. }
  6740. }
  6741. }
  6742. //---------------------------------------------------------------------------
  6743. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6744. {
  6745. RestoreApp();
  6746. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6747. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6748. !NonVisualDataModule->Busy)
  6749. {
  6750. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6751. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6752. if (!ComponentVisible[fcQueueView])
  6753. {
  6754. ToggleQueueVisibility();
  6755. GoToQueue();
  6756. }
  6757. }
  6758. }
  6759. //---------------------------------------------------------------------------
  6760. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6761. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6762. {
  6763. UnicodeString Message;
  6764. TNotifyEvent OnClick = NULL;
  6765. TObject * UserData = NULL;
  6766. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6767. switch (Event)
  6768. {
  6769. case qeEmptyButMonitored:
  6770. if ((ATerminal != Terminal) || QueueInvisible)
  6771. {
  6772. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6773. OnClick = QueueEmptyNoteClicked;
  6774. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6775. TerminalNoteData->Terminal = ATerminal;
  6776. UserData = TerminalNoteData;
  6777. }
  6778. break;
  6779. case qeEmpty:
  6780. OperationComplete(ATerminal->QueueOperationStart);
  6781. break;
  6782. case qePendingUserAction:
  6783. if ((ATerminal != Terminal) ||
  6784. (QueueInvisible && !IsQueueAutoPopup()))
  6785. {
  6786. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6787. }
  6788. break;
  6789. default:
  6790. DebugFail();
  6791. }
  6792. if (!Message.IsEmpty())
  6793. {
  6794. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6795. }
  6796. }
  6797. //---------------------------------------------------------------------------
  6798. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6799. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6800. {
  6801. if (FDDExtMapFile != NULL)
  6802. {
  6803. CloseHandle(FDDExtMapFile);
  6804. FDDExtMapFile = NULL;
  6805. }
  6806. if (WinConfiguration->DDFakeFile)
  6807. {
  6808. DDFakeFileInitDrag(FileList, Created);
  6809. }
  6810. }
  6811. //---------------------------------------------------------------------------
  6812. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6813. {
  6814. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6815. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6816. {
  6817. FFakeFileDropTarget = FileName;
  6818. }
  6819. }
  6820. //---------------------------------------------------------------------------
  6821. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6822. {
  6823. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6824. if (!ForceDirectories(ApiPath(Result)))
  6825. {
  6826. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6827. }
  6828. FileSetAttr(ApiPath(Result), faHidden);
  6829. return Result;
  6830. }
  6831. //---------------------------------------------------------------------------
  6832. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6833. bool & Created)
  6834. {
  6835. FFakeFileDropTarget = UnicodeString();
  6836. FDragFakeDirectory = CreateFakeTransferDirectory();
  6837. FileList->AddItem(NULL, FDragFakeDirectory);
  6838. Created = true;
  6839. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6840. {
  6841. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6842. }
  6843. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6844. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6845. {
  6846. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6847. TDragExtCommStruct* CommStruct;
  6848. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6849. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6850. DebugAssert(CommStruct != NULL);
  6851. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6852. CommStruct->Dragging = true;
  6853. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6854. LENOF(CommStruct->DropDest));
  6855. NULL_TERMINATE(CommStruct->DropDest);
  6856. UnmapViewOfFile(CommStruct);
  6857. }
  6858. }
  6859. //---------------------------------------------------------------------------
  6860. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6861. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6862. {
  6863. bool Result;
  6864. DebugAssert(!IsLocalBrowserMode());
  6865. if (Sender == RemoteDirView)
  6866. {
  6867. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6868. }
  6869. else
  6870. {
  6871. DebugAssert(Sender == RemoteDriveView);
  6872. TStrings * FileList = RemoteDriveView->DragFileList();
  6873. try
  6874. {
  6875. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6876. }
  6877. __finally
  6878. {
  6879. delete FileList;
  6880. }
  6881. }
  6882. if (FDDTargetControl == RemoteDriveView)
  6883. {
  6884. RemoteDriveView->UpdateDropTarget();
  6885. }
  6886. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6887. // or from tree view to dir view.
  6888. // foMove happens when file/dir is dragged from remote tree view outside of
  6889. // application via dragex
  6890. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6891. (DropSourceControl == RemoteDriveView))
  6892. {
  6893. RemoteDriveView->UpdateDropSource();
  6894. }
  6895. return Result;
  6896. }
  6897. //---------------------------------------------------------------------------
  6898. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6899. {
  6900. DebugAssert(!IsLocalBrowserMode());
  6901. // This also handles drops of remote files to queue.
  6902. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6903. SAFE_DESTROY(FDDFileList);
  6904. if (!FFakeFileDropTarget.IsEmpty())
  6905. {
  6906. RemoveDir(ApiPath(FFakeFileDropTarget));
  6907. }
  6908. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6909. {
  6910. try
  6911. {
  6912. TDragResult DDResult = (Sender == RemoteDirView) ?
  6913. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6914. // Focus is moved to the target application,
  6915. // but as we are going to present the UI, we need to steal the focus back.
  6916. // This most likely won't work though (windows does not allow application
  6917. // to steal focus most of the time)
  6918. Application->BringToFront();
  6919. // On older version of Windows we never got drMove here, see also comment below.
  6920. // On Windows 10, we get the "move".
  6921. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6922. {
  6923. UnicodeString TargetDirectory;
  6924. TFileOperation Operation;
  6925. // drInvalid may mean drMove, see comment below
  6926. switch (DDResult)
  6927. {
  6928. case drCopy:
  6929. Operation = foCopy;
  6930. break;
  6931. case drMove:
  6932. Operation = foMove;
  6933. break;
  6934. default:
  6935. DebugFail();
  6936. case drInvalid:
  6937. // prefer "copy" for safety
  6938. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6939. break;
  6940. }
  6941. TTransferOperationParam Param;
  6942. UnicodeString CounterName;
  6943. bool ForceQueue;
  6944. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6945. {
  6946. // we get drInvalid both if d&d was intercepted by ddext,
  6947. // and when users drops on no-drop location.
  6948. // we tell the difference by existence of response from ddext,
  6949. // so we ignore absence of response in this case
  6950. if (DDResult != drInvalid)
  6951. {
  6952. // here we know that the extension is installed,
  6953. // as it is checked as soon as drag&drop starts from
  6954. // RemoteFileControlDDCreateDragFileList
  6955. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6956. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6957. {
  6958. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6959. }
  6960. else
  6961. {
  6962. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6963. }
  6964. }
  6965. }
  6966. else
  6967. {
  6968. // download using fake file
  6969. Param.Temp = false;
  6970. Param.DragDrop = true;
  6971. if (ForceQueue)
  6972. {
  6973. Param.Queue = asOn;
  6974. }
  6975. if (Sender == RemoteDirView)
  6976. {
  6977. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6978. }
  6979. if (RemoteFileControlFileOperation(Sender, Operation,
  6980. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6981. {
  6982. Configuration->Usage->Inc(CounterName);
  6983. }
  6984. }
  6985. }
  6986. }
  6987. __finally
  6988. {
  6989. CloseHandle(FDDExtMapFile);
  6990. FDDExtMapFile = NULL;
  6991. delete FDragFakeMonitors;
  6992. FDragFakeMonitors = NULL;
  6993. RemoveDir(ApiPath(FDragFakeDirectory));
  6994. FDragFakeDirectory = L"";
  6995. FFakeFileDropTarget = UnicodeString();
  6996. }
  6997. }
  6998. if (FDragDropSshTerminate.get() != NULL)
  6999. {
  7000. FDragDropSshTerminate->Rethrow();
  7001. }
  7002. }
  7003. //---------------------------------------------------------------------------
  7004. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7005. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7006. {
  7007. // Remember drop effect so we know (when user drops files), if we copy or move
  7008. FLastDropEffect = dwEffect;
  7009. }
  7010. //---------------------------------------------------------------------------
  7011. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7012. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7013. {
  7014. bool Result;
  7015. if (FDDTargetControl == QueueView3)
  7016. {
  7017. Directory = DefaultDownloadTargetDirectory();
  7018. Result = true;
  7019. CounterName = L"DownloadsDragDropQueue";
  7020. ForceQueue = true;
  7021. }
  7022. else if (!FFakeFileDropTarget.IsEmpty())
  7023. {
  7024. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7025. Result = true;
  7026. ForceQueue = false;
  7027. CounterName = L"DownloadsDragDropFakeFile";
  7028. }
  7029. else
  7030. {
  7031. ForceQueue = false;
  7032. Enabled = false;
  7033. try
  7034. {
  7035. int Timer = 0;
  7036. Result = false;
  7037. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7038. {
  7039. {
  7040. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7041. TDragExtCommStruct* CommStruct;
  7042. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7043. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7044. DebugAssert(CommStruct != NULL);
  7045. Result = !CommStruct->Dragging;
  7046. if (Result)
  7047. {
  7048. Directory = ExtractFilePath(CommStruct->DropDest);
  7049. CounterName = L"DownloadsDragDropExternalExt";
  7050. }
  7051. UnmapViewOfFile(CommStruct);
  7052. }
  7053. if (!Result)
  7054. {
  7055. Sleep(50);
  7056. Timer += 50;
  7057. Application->ProcessMessages();
  7058. }
  7059. }
  7060. }
  7061. __finally
  7062. {
  7063. Enabled = true;
  7064. }
  7065. }
  7066. return Result;
  7067. }
  7068. //---------------------------------------------------------------------------
  7069. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7070. const UnicodeString TempDir, int SecDelay)
  7071. {
  7072. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7073. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7074. if (FDelayedDeletionTimer == NULL)
  7075. {
  7076. DebugAssert(HandleAllocated());
  7077. FDelayedDeletionTimer = new TTimer(this);
  7078. FDelayedDeletionTimer->Interval = 10000;
  7079. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7080. }
  7081. else
  7082. {
  7083. FDelayedDeletionTimer->Enabled = true;
  7084. }
  7085. }
  7086. //---------------------------------------------------------------------------
  7087. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7088. {
  7089. DebugAssert(FDelayedDeletionList != NULL);
  7090. TDateTime N = Now();
  7091. TDateTime Alert;
  7092. UnicodeString Directory;
  7093. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7094. {
  7095. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7096. if ((N >= Alert) || (Sender == NULL))
  7097. {
  7098. Directory = FDelayedDeletionList->Strings[Index];
  7099. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7100. {
  7101. FDelayedDeletionList->Delete(Index);
  7102. }
  7103. }
  7104. }
  7105. if (FDelayedDeletionList->Count == 0)
  7106. {
  7107. FDelayedDeletionTimer->Enabled = false;
  7108. }
  7109. }
  7110. //---------------------------------------------------------------------------
  7111. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7112. {
  7113. DebugAssert(!IsLocalBrowserMode());
  7114. if (IsFileControl(FDDTargetControl, osRemote) ||
  7115. (FDDTargetControl == SessionsPageControl))
  7116. {
  7117. TTerminal * TargetTerminal = NULL;
  7118. TFileOperation Operation = foNone;
  7119. if (FDDTargetControl == SessionsPageControl)
  7120. {
  7121. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7122. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7123. // do not allow dropping on the "+" tab
  7124. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7125. if (TargetTerminal != NULL)
  7126. {
  7127. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7128. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7129. {
  7130. Operation = foRemoteMove;
  7131. }
  7132. else
  7133. {
  7134. Operation = foRemoteCopy;
  7135. }
  7136. }
  7137. }
  7138. else
  7139. {
  7140. if (FLastDropEffect == DROPEFFECT_MOVE)
  7141. {
  7142. Operation = foRemoteMove;
  7143. }
  7144. else if (FLastDropEffect == DROPEFFECT_COPY)
  7145. {
  7146. Operation = foRemoteCopy;
  7147. }
  7148. }
  7149. if (Operation != foNone)
  7150. {
  7151. RemoteFileControlFileOperation(DropSourceControl,
  7152. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7153. }
  7154. // abort drag&drop
  7155. Abort();
  7156. }
  7157. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7158. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7159. (FDDTargetControl != QueueView3))
  7160. {
  7161. DebugAssert(!FDragTempDir.IsEmpty());
  7162. TTransferType Type;
  7163. UnicodeString TempDir = FDragTempDir;
  7164. // We clear FDragTempDir before calling
  7165. // just in case it fail (raises exception)
  7166. FDragTempDir = L"";
  7167. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7168. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7169. // empty directory parameter means temp directory -> don't display it!
  7170. UnicodeString TargetDir = L"";
  7171. int Options = 0;
  7172. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7173. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7174. {
  7175. Abort();
  7176. }
  7177. // TargetDir is set when dropped on local file control
  7178. // (this was workaround for legacy dirview event handling, now it should be
  7179. // made prettier)
  7180. if (TargetDir.IsEmpty())
  7181. {
  7182. TargetDir = TempDir;
  7183. if (ForceDirectories(ApiPath(TargetDir)))
  7184. {
  7185. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7186. FPendingTempSpaceWarn = true;
  7187. try
  7188. {
  7189. FDragDropOperation = true;
  7190. int Params = cpTemporary |
  7191. (Type == ttMove ? cpDelete : 0);
  7192. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7193. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7194. }
  7195. __finally
  7196. {
  7197. FDragDropOperation = false;
  7198. FPendingTempSpaceWarn = false;
  7199. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7200. }
  7201. }
  7202. else
  7203. {
  7204. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7205. }
  7206. }
  7207. }
  7208. }
  7209. //---------------------------------------------------------------------------
  7210. void __fastcall TCustomScpExplorerForm::DDDownload(
  7211. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7212. {
  7213. DebugAssert(!IsLocalBrowserMode());
  7214. TAutoBatch AutoBatch(this);
  7215. UpdateCopyParamCounters(*CopyParam);
  7216. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7217. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7218. {
  7219. RemoteDriveView->UpdateDropSource();
  7220. }
  7221. }
  7222. //---------------------------------------------------------------------------
  7223. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7224. {
  7225. public:
  7226. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7227. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7228. {
  7229. }
  7230. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7231. {
  7232. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7233. TDataObjectFilesEx::AllowData(FormatEtc);
  7234. }
  7235. };
  7236. //---------------------------------------------------------------------------
  7237. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7238. TObject * Sender, TDataObject *& DataObject)
  7239. {
  7240. if (FDDExtMapFile != NULL)
  7241. {
  7242. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7243. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7244. {
  7245. Abort();
  7246. }
  7247. if (FileList->Count > 0)
  7248. {
  7249. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7250. if (!FilesObject->IsValid(true, true))
  7251. {
  7252. FilesObject->_Release();
  7253. }
  7254. else
  7255. {
  7256. DataObject = FilesObject;
  7257. }
  7258. }
  7259. }
  7260. }
  7261. //---------------------------------------------------------------------------
  7262. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7263. {
  7264. DebugFail();
  7265. }
  7266. //---------------------------------------------------------------------------
  7267. void __fastcall TCustomScpExplorerForm::GoToTree()
  7268. {
  7269. ComponentVisible[fcRemoteTree] = true;
  7270. DriveView(osRemote)->SetFocus();
  7271. }
  7272. //---------------------------------------------------------------------------
  7273. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7274. TPanelExport Export)
  7275. {
  7276. TCustomDirView * DirView = this->DirView(Side);
  7277. std::unique_ptr<TStrings> ExportData(new TStringList());
  7278. switch (Export)
  7279. {
  7280. case pePath:
  7281. ExportData->Add(DirView->PathName);
  7282. break;
  7283. case peFileList:
  7284. case peFullFileList:
  7285. {
  7286. bool FullPath = (Export == peFullFileList);
  7287. DirView->CreateFileList(false, FullPath, ExportData.get());
  7288. for (int Index = 0; Index < ExportData->Count; Index++)
  7289. {
  7290. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7291. {
  7292. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7293. }
  7294. }
  7295. }
  7296. break;
  7297. default:
  7298. DebugFail();
  7299. }
  7300. return ExportData.release();
  7301. }
  7302. //---------------------------------------------------------------------------
  7303. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7304. TPanelExport Export, TPanelExportDestination Destination)
  7305. {
  7306. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7307. PanelExportStore(Side, Export, Destination, ExportData.get());
  7308. }
  7309. //---------------------------------------------------------------------------
  7310. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7311. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7312. TStrings * ExportData)
  7313. {
  7314. if (Destination == pedClipboard)
  7315. {
  7316. TInstantOperationVisualizer Visualizer;
  7317. CopyToClipboard(ExportData);
  7318. }
  7319. else
  7320. {
  7321. DebugFail();
  7322. }
  7323. }
  7324. //---------------------------------------------------------------------------
  7325. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7326. {
  7327. TCustomDirView * DirView = this->DirView(Side);
  7328. UnicodeString Mask = DirView->Mask;
  7329. if (DoFilterMaskDialog(DirView, Mask))
  7330. {
  7331. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7332. Configuration->Usage->Inc(L"Filters");
  7333. }
  7334. }
  7335. //---------------------------------------------------------------------------
  7336. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7337. {
  7338. return FQueueController->DefaultOperation();
  7339. }
  7340. //---------------------------------------------------------------------------
  7341. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7342. TQueueOperation Operation, void ** Param)
  7343. {
  7344. switch (Operation)
  7345. {
  7346. case qoPreferences:
  7347. return true;
  7348. case qoGoTo:
  7349. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7350. case qoOnceEmpty:
  7351. return IsAnythingQueued();
  7352. default:
  7353. return FQueueController->AllowOperation(Operation, Param);
  7354. }
  7355. }
  7356. //---------------------------------------------------------------------------
  7357. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7358. {
  7359. if (DebugAlwaysTrue(QueueView3->Visible))
  7360. {
  7361. QueueView3->SetFocus();
  7362. }
  7363. }
  7364. //---------------------------------------------------------------------------
  7365. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7366. TQueueOperation Operation, void * Param)
  7367. {
  7368. if (Operation == qoGoTo)
  7369. {
  7370. GoToQueue();
  7371. }
  7372. else if (Operation == qoPreferences)
  7373. {
  7374. PreferencesDialog(pmQueue);
  7375. }
  7376. else
  7377. {
  7378. FQueueController->ExecuteOperation(Operation, Param);
  7379. }
  7380. }
  7381. //---------------------------------------------------------------------------
  7382. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7383. {
  7384. return (Queue != NULL) && Queue->Enabled;
  7385. }
  7386. //---------------------------------------------------------------------------
  7387. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7388. {
  7389. DebugAssert(Queue != NULL);
  7390. if (Queue != NULL)
  7391. {
  7392. Queue->Enabled = !Queue->Enabled;
  7393. }
  7394. }
  7395. //---------------------------------------------------------------------------
  7396. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7397. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7398. {
  7399. FQueueActedItem = QueueView3->ItemFocused;
  7400. }
  7401. //---------------------------------------------------------------------------
  7402. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7403. {
  7404. return TopDock->Height + QueueSplitter->Height;
  7405. }
  7406. //---------------------------------------------------------------------------
  7407. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7408. {
  7409. return
  7410. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7411. (QueueDock->Visible ? QueueDock->Height : 0) +
  7412. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7416. {
  7417. return ScaleByTextHeight(this, 48);
  7418. }
  7419. //---------------------------------------------------------------------------
  7420. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7421. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7422. {
  7423. // when queue is hidden by double-clicking splitter, stray attempt to
  7424. // resize the panel with strange value arrives, make sure it is ignored
  7425. if (ComponentVisible[fcQueueView])
  7426. {
  7427. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7428. if (NewSize > MaxHeightLimit)
  7429. {
  7430. NewSize = MaxHeightLimit;
  7431. }
  7432. int MinHeightLimit =
  7433. GetStaticQueuePanelComponentsHeight() +
  7434. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7435. GetMinQueueViewHeight();
  7436. if (NewSize < MinHeightLimit)
  7437. {
  7438. NewSize = MinHeightLimit;
  7439. }
  7440. }
  7441. else
  7442. {
  7443. Accept = false;
  7444. }
  7445. }
  7446. //---------------------------------------------------------------------------
  7447. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7448. {
  7449. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7450. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7451. if (QueueViewHeight < GetMinQueueViewHeight())
  7452. {
  7453. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7454. }
  7455. }
  7456. //---------------------------------------------------------------------------
  7457. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7458. TDragObject *& /*DragObject*/)
  7459. {
  7460. FQueueActedItem = QueueView3->ItemFocused;
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7464. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7465. {
  7466. Accept = true;
  7467. if (Source == QueueView3)
  7468. {
  7469. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7470. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7471. if (Accept)
  7472. {
  7473. TQueueItemProxy * QueueItem;
  7474. TQueueItemProxy * DestQueueItem;
  7475. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7476. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7477. Accept = (QueueItem != DestQueueItem) &&
  7478. (QueueItem->Status == TQueueItem::qsPending) &&
  7479. (DestQueueItem->Status == TQueueItem::qsPending);
  7480. }
  7481. }
  7482. }
  7483. //---------------------------------------------------------------------------
  7484. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7485. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7486. {
  7487. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7488. {
  7489. TQueueItemProxy * QueueItem;
  7490. TQueueItemProxy * DestQueueItem;
  7491. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7492. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7493. QueueItem->Move(DestQueueItem);
  7494. }
  7495. }
  7496. //---------------------------------------------------------------------------
  7497. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7498. {
  7499. if ((QueueView3->ItemFocused == NULL) &&
  7500. (QueueView3->Items->Count > 0))
  7501. {
  7502. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7503. }
  7504. QueueLabelUpdateStatus();
  7505. }
  7506. //---------------------------------------------------------------------------
  7507. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7508. {
  7509. QueueLabelUpdateStatus();
  7510. }
  7511. //---------------------------------------------------------------------------
  7512. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7513. {
  7514. QueueLabel->UpdateStatus();
  7515. }
  7516. //---------------------------------------------------------------------------
  7517. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7518. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7519. {
  7520. if (Selected)
  7521. {
  7522. NonVisualDataModule->UpdateNonVisibleActions();
  7523. }
  7524. }
  7525. //---------------------------------------------------------------------------
  7526. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7527. {
  7528. TDragDropFilesEx * Result = NULL;
  7529. if (Sender == SessionsPageControl)
  7530. {
  7531. Result = FSessionsDragDropFilesEx;
  7532. }
  7533. else if (Sender == QueueView3)
  7534. {
  7535. Result = FQueueDragDropFilesEx;
  7536. }
  7537. else
  7538. {
  7539. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7540. if (DirView != NULL)
  7541. {
  7542. Result = DirView->DragDropFilesEx;
  7543. }
  7544. else
  7545. {
  7546. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7547. if (DriveView != NULL)
  7548. {
  7549. Result = DriveView->DragDropFilesEx;
  7550. }
  7551. }
  7552. }
  7553. DebugAssert(Result != NULL);
  7554. return Result;
  7555. }
  7556. //---------------------------------------------------------------------------
  7557. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7558. {
  7559. return (DView->SelCount == DView->FilesCount);
  7560. }
  7561. //---------------------------------------------------------------------------
  7562. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7563. {
  7564. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7565. }
  7566. //---------------------------------------------------------------------------
  7567. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7568. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7569. {
  7570. DebugAssert(!IsLocalBrowserMode());
  7571. TFileOperation Operation;
  7572. switch (Effect)
  7573. {
  7574. case DROPEFFECT_MOVE:
  7575. Operation = foMove;
  7576. break;
  7577. case DROPEFFECT_COPY:
  7578. // occures on WinXP (reported by user)
  7579. default:
  7580. Operation = foCopy;
  7581. break;
  7582. };
  7583. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7584. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7585. if (DragDropFilesEx->FileList->Count > 0)
  7586. {
  7587. TStrings * FileList = new TStringList();
  7588. try
  7589. {
  7590. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7591. {
  7592. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7593. }
  7594. FDragDropOperation = true;
  7595. TTransferOperationParam Param;
  7596. Param.TargetDirectory = TargetPath;
  7597. // upload, no temp dirs
  7598. Param.Temp = false;
  7599. Param.DragDrop = DragDrop;
  7600. Param.Options =
  7601. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7602. if (ForceQueue)
  7603. {
  7604. Param.Queue = asOn;
  7605. }
  7606. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7607. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7608. {
  7609. if (IsFileControl(DropSourceControl, osLocal))
  7610. {
  7611. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7612. }
  7613. else
  7614. {
  7615. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7616. }
  7617. }
  7618. }
  7619. __finally
  7620. {
  7621. FDragDropOperation = false;
  7622. delete FileList;
  7623. }
  7624. }
  7625. }
  7626. //---------------------------------------------------------------------------
  7627. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7628. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7629. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7630. {
  7631. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7632. }
  7633. //---------------------------------------------------------------------------
  7634. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7635. TObject * Sender, int grfKeyState, int & dwEffect)
  7636. {
  7637. DebugAssert(!IsLocalBrowserMode());
  7638. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7639. if ((dwEffect != DROPEFFECT_NONE) &&
  7640. IsFileControl(DropSourceControl, osRemote))
  7641. {
  7642. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7643. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7644. (RemoteDirView->DropTarget == NULL))
  7645. {
  7646. dwEffect = DROPEFFECT_NONE;
  7647. }
  7648. else
  7649. {
  7650. if (dwEffect == DROPEFFECT_COPY)
  7651. {
  7652. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7653. // currently we support copying always (at least via temporary directory);
  7654. // remove associated checks once this all proves stable and working
  7655. bool CopyCapable = true;
  7656. // if we do not support neither of operations, there's no discussion
  7657. if (!MoveCapable && !CopyCapable)
  7658. {
  7659. dwEffect = DROPEFFECT_NONE;
  7660. }
  7661. else
  7662. {
  7663. // The default effect inside remote panel is move,
  7664. // unless we do not support it, but support copy
  7665. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7666. {
  7667. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7668. }
  7669. else
  7670. {
  7671. // with ctrl-down, we want copy unless it is not supported
  7672. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7673. }
  7674. }
  7675. }
  7676. }
  7677. }
  7678. }
  7679. //---------------------------------------------------------------------------
  7680. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7681. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7682. {
  7683. DebugAssert(!IsLocalBrowserMode());
  7684. if (FDDTotalSize >= 0)
  7685. {
  7686. if (File->IsDirectory)
  7687. {
  7688. FDDTotalSize = -1;
  7689. }
  7690. else
  7691. {
  7692. FDDTotalSize += File->Size;
  7693. }
  7694. }
  7695. DebugAssert(!FDragTempDir.IsEmpty());
  7696. // TODO: this is quite ineffective
  7697. // TODO: what if invalid character replacement is disabled?
  7698. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7699. UnicodeString TransferFileName;
  7700. if (Sender == RemoteDriveView)
  7701. {
  7702. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7703. }
  7704. else
  7705. {
  7706. TransferFileName = File->FileName;
  7707. }
  7708. FDDFileList->AddObject(TransferFileName, File);
  7709. }
  7710. //---------------------------------------------------------------------------
  7711. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7712. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7713. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7714. {
  7715. // sometimes we do not get DDEnd so the list is not released
  7716. SAFE_DESTROY(FDDFileList);
  7717. FDDFileList = new TStringList();
  7718. FDragTempDir = WinConfiguration->TemporaryDir();
  7719. FDDTotalSize = 0;
  7720. FDragDropSshTerminate.reset(NULL);
  7721. }
  7722. //---------------------------------------------------------------------------
  7723. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7724. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7725. HRESULT & Result)
  7726. {
  7727. if (Result == DRAGDROP_S_DROP)
  7728. {
  7729. try
  7730. {
  7731. GlobalDragImageList->HideDragImage();
  7732. try
  7733. {
  7734. RemoteFileControlDDTargetDrop();
  7735. }
  7736. catch(ESshTerminate & E)
  7737. {
  7738. FDragDropSshTerminate.reset(E.Clone());
  7739. }
  7740. }
  7741. catch (Exception &E)
  7742. {
  7743. // If downloading fails we need to cancel drag&drop, otherwise
  7744. // Explorer shows error
  7745. // But by the way exception probably never reach this point as
  7746. // it's catched on way.
  7747. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7748. Result = DRAGDROP_S_CANCEL;
  7749. ShowExtendedException(Terminal, &E);
  7750. }
  7751. }
  7752. }
  7753. //---------------------------------------------------------------------------
  7754. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7755. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7756. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7757. {
  7758. TFileMasks::TParams MaskParams;
  7759. MaskParams.Size = Size;
  7760. MaskParams.Modification = Modification;
  7761. // this does not re-parse the mask if it is the same as the last time
  7762. FDirViewMatchMask = Masks;
  7763. bool ImplicitMatch;
  7764. Matches =
  7765. // RecurseInclude parameter has no effect as the Path is empty
  7766. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7767. (AllowImplicitMatches || !ImplicitMatch);
  7768. }
  7769. //---------------------------------------------------------------------------
  7770. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7771. TObject * Sender, TListItem * Item, WORD & Indexes)
  7772. {
  7773. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7774. UnicodeString Ext;
  7775. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7776. {
  7777. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7778. }
  7779. else
  7780. {
  7781. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7782. }
  7783. if (SameText(Ext, Configuration->PartialExt))
  7784. {
  7785. Indexes |= oiPartial;
  7786. }
  7787. }
  7788. //---------------------------------------------------------------------------
  7789. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7790. {
  7791. return
  7792. DirViewEnabled(osCurrent) &&
  7793. DirView(osCurrent)->CanPasteFromClipBoard();
  7794. }
  7795. //---------------------------------------------------------------------------
  7796. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7797. {
  7798. bool Result = false;
  7799. if (CanPasteToDirViewFromClipBoard())
  7800. {
  7801. Result = true;
  7802. }
  7803. else
  7804. {
  7805. UnicodeString ClipboardText;
  7806. if (NonEmptyTextFromClipboard(ClipboardText))
  7807. {
  7808. if (StoredSessions->IsUrl(ClipboardText))
  7809. {
  7810. Result = true;
  7811. }
  7812. else
  7813. {
  7814. Result = DirViewEnabled(osCurrent);
  7815. }
  7816. }
  7817. }
  7818. return Result;
  7819. }
  7820. //---------------------------------------------------------------------------
  7821. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7822. {
  7823. if (DoesClipboardContainOurFiles())
  7824. {
  7825. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7826. {
  7827. DebugAssert(!IsLocalBrowserMode());
  7828. TTerminalManager * Manager = TTerminalManager::Instance();
  7829. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7830. Manager->ActiveTerminal = FClipboardTerminal;
  7831. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7832. }
  7833. }
  7834. else if (CanPasteToDirViewFromClipBoard())
  7835. {
  7836. DirView(osCurrent)->PasteFromClipBoard();
  7837. }
  7838. else
  7839. {
  7840. UnicodeString ClipboardText;
  7841. if (NonEmptyTextFromClipboard(ClipboardText))
  7842. {
  7843. if (StoredSessions->IsUrl(ClipboardText))
  7844. {
  7845. NewSession(false, ClipboardText);
  7846. }
  7847. else
  7848. {
  7849. DirView(osCurrent)->Path = ClipboardText;
  7850. }
  7851. }
  7852. }
  7853. }
  7854. //---------------------------------------------------------------------------
  7855. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7856. {
  7857. // TBD
  7858. }
  7859. //---------------------------------------------------------------------------
  7860. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7861. {
  7862. TCustomDirView * ADirView = DirView(Side);
  7863. ADirView->SelectAll(Mode);
  7864. ADirView->SetFocus();
  7865. }
  7866. //---------------------------------------------------------------------------
  7867. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7868. {
  7869. TCustomDirView * ADirView = DirView(Side);
  7870. TFileFilter Filter;
  7871. DefaultFileFilter(Filter);
  7872. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7873. {
  7874. Configuration->Usage->Inc(L"MaskSelections");
  7875. ADirView->SelectFiles(Filter, Select);
  7876. ADirView->SetFocus();
  7877. }
  7878. }
  7879. //---------------------------------------------------------------------------
  7880. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7881. {
  7882. TCustomDirView * ADirView = DirView(Side);
  7883. ADirView->RestoreSelectedNames();
  7884. ADirView->SetFocus();
  7885. }
  7886. //---------------------------------------------------------------------------
  7887. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7888. {
  7889. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7890. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7891. {
  7892. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7893. UnicodeString Ext;
  7894. if (!IsSideLocalBrowser(osCurrent))
  7895. {
  7896. Ext = UnixExtractFileExt(FileName);
  7897. }
  7898. else
  7899. {
  7900. Ext = ExtractFileExt(FileName);
  7901. }
  7902. if (Ext.IsEmpty())
  7903. {
  7904. Ext = L".";
  7905. }
  7906. TFileFilter Filter;
  7907. Filter.Masks = FORMAT(L"*%s", (Ext));
  7908. Filter.Directories = false;
  7909. CurrentDirView->SelectFiles(Filter, Select);
  7910. }
  7911. }
  7912. //---------------------------------------------------------------------------
  7913. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7914. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7915. {
  7916. UnicodeString Result;
  7917. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7918. {
  7919. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7920. }
  7921. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7922. {
  7923. // noop
  7924. }
  7925. else
  7926. {
  7927. Result =
  7928. FMTLOAD(FILE_INFO_FORMAT,
  7929. (FormatBytes(FileInfo.SelectedSize),
  7930. FormatBytes(FileInfo.FilesSize),
  7931. FormatNumber(FileInfo.SelectedCount),
  7932. FormatNumber(FileInfo.FilesCount)));
  7933. }
  7934. return Result;
  7935. }
  7936. //---------------------------------------------------------------------------
  7937. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7938. TTBXStatusPanel * Panel, TOperationSide Side)
  7939. {
  7940. if (Panel->Index == 1)
  7941. {
  7942. ToggleShowHiddenFiles();
  7943. }
  7944. else if (Panel->Index == 2)
  7945. {
  7946. Filter(Side);
  7947. }
  7948. }
  7949. //---------------------------------------------------------------------------
  7950. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7951. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7952. {
  7953. DebugAssert(!StatusBar->SimplePanel);
  7954. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7955. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7956. }
  7957. //---------------------------------------------------------------------------
  7958. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7959. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7960. {
  7961. DebugAssert(StatusBar->Panels->Count >= 3);
  7962. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7963. if (FileInfo.HiddenCount > 0)
  7964. {
  7965. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7966. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7967. }
  7968. else
  7969. {
  7970. HiddenFilesPanel->ViewPriority = 0;
  7971. // not really necessary, just to cleanup no-longer-valid data
  7972. HiddenFilesPanel->Caption = L"";
  7973. }
  7974. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7975. if (FileInfo.FilteredCount > 0)
  7976. {
  7977. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7978. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7979. }
  7980. else
  7981. {
  7982. FilteredFilesPanel->ViewPriority = 0;
  7983. // not really necessary, just to cleanup no-longer-valid data
  7984. FilteredFilesPanel->Caption = L"";
  7985. }
  7986. }
  7987. //---------------------------------------------------------------------------
  7988. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7989. TObject * /*Sender*/)
  7990. {
  7991. if (DirView(osRemote)->Enabled)
  7992. {
  7993. DirView(osRemote)->SetFocus();
  7994. }
  7995. }
  7996. //---------------------------------------------------------------------------
  7997. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7998. {
  7999. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8000. switch (Config.Show)
  8001. {
  8002. case qvShow:
  8003. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8004. {
  8005. Config.Show = qvHide;
  8006. }
  8007. else
  8008. {
  8009. Config.Show = Config.LastHideShow;
  8010. }
  8011. break;
  8012. case qvHideWhenEmpty:
  8013. if (ComponentVisible[fcQueueView])
  8014. {
  8015. Config.Show = qvHide;
  8016. }
  8017. else
  8018. {
  8019. Config.LastHideShow = Config.Show;
  8020. Config.Show = qvShow;
  8021. }
  8022. break;
  8023. case qvHide:
  8024. Config.LastHideShow = Config.Show;
  8025. Config.Show = qvShow;
  8026. break;
  8027. }
  8028. WinConfiguration->QueueView = Config;
  8029. }
  8030. //---------------------------------------------------------------------------
  8031. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8032. {
  8033. UnicodeString Result;
  8034. if (FTerminal != NULL)
  8035. {
  8036. switch (WinConfiguration->PathInCaption)
  8037. {
  8038. case picShort:
  8039. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8040. break;
  8041. case picFull:
  8042. Result = FTerminal->CurrentDirectory;
  8043. break;
  8044. }
  8045. }
  8046. return Result;
  8047. }
  8048. //---------------------------------------------------------------------------
  8049. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8050. {
  8051. TColor Result = GetWindowColor(FSessionColor);
  8052. return Result;
  8053. }
  8054. //---------------------------------------------------------------------------
  8055. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8056. {
  8057. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8058. return Result;
  8059. }
  8060. //---------------------------------------------------------------------------
  8061. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8062. {
  8063. TTerminalManager::Instance()->UpdateAppTitle();
  8064. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8065. // background to gray on Windows 7 (works on Windows 10).
  8066. // See also EnableControl
  8067. if (Showing)
  8068. {
  8069. if (Terminal != NULL)
  8070. {
  8071. // Update path when it changes
  8072. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8073. {
  8074. UpdateSessionTab(SessionsPageControl->ActivePage);
  8075. }
  8076. }
  8077. NonVisualDataModule->ReconnectSessionAction->Update();
  8078. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8079. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8080. CenterReconnectToolbar();
  8081. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  8082. if (HasTerminal)
  8083. {
  8084. // TODO needed yet with second local browser?
  8085. if (!RemoteDirView->Enabled)
  8086. {
  8087. RemoteDirView->Enabled = true;
  8088. if (FRemoteDirViewWasFocused)
  8089. {
  8090. ActiveControl = RemoteDirView;
  8091. }
  8092. }
  8093. RemoteDirView->Color = PanelColor();
  8094. }
  8095. else
  8096. {
  8097. if (RemoteDirView->Enabled)
  8098. {
  8099. // This is first called when the form is being constructed
  8100. // (not anymore due to Showing test above)
  8101. // but the false is overriden in the constructor later.
  8102. // An even later in TScpCommanderForm::DoShow()
  8103. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8104. RemoteDirView->Enabled = false;
  8105. }
  8106. RemoteDirView->Color = DisabledPanelColor();
  8107. }
  8108. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8109. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8110. RemoteDriveView->Color = RemoteDirView->Color;
  8111. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8112. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8113. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8114. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8115. QueueFileList->Enabled = QueueView3->Enabled;
  8116. QueueFileList->Color = QueueView3->Color;
  8117. QueueFileList->Font->Color = QueueView3->Font->Color;
  8118. QueueLabelUpdateStatus();
  8119. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8120. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8121. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8122. }
  8123. }
  8124. //---------------------------------------------------------------------------
  8125. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8126. {
  8127. UpdateControls();
  8128. }
  8129. //---------------------------------------------------------------------------
  8130. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8131. TObject * Sender)
  8132. {
  8133. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8134. DebugAssert(DirView != NULL);
  8135. DoDirViewLoaded(DirView);
  8136. TransferPresetAutoSelect();
  8137. }
  8138. //---------------------------------------------------------------------------
  8139. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8140. {
  8141. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8142. // first run after installation
  8143. if (double(Updates.LastCheck) == 0)
  8144. {
  8145. // make sure next time there will be an update (if enabled)
  8146. Updates.LastCheck = TDateTime(1);
  8147. WinConfiguration->Updates = Updates;
  8148. }
  8149. else if ((double(Updates.Period) > 0) &&
  8150. (Now() - Updates.LastCheck >= Updates.Period))
  8151. {
  8152. TThreadMethod OnUpdatesChecked = NULL;
  8153. if (!IsUWP())
  8154. {
  8155. OnUpdatesChecked = UpdatesChecked;
  8156. }
  8157. StartUpdateThread(OnUpdatesChecked);
  8158. }
  8159. }
  8160. //---------------------------------------------------------------------------
  8161. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8162. {
  8163. UnicodeString Message;
  8164. bool New;
  8165. TQueryType Type;
  8166. GetUpdatesMessage(Message, New, Type, false);
  8167. if (!Message.IsEmpty())
  8168. {
  8169. if (New)
  8170. {
  8171. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8172. }
  8173. if (!New && (Type != qtWarning))
  8174. {
  8175. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8176. }
  8177. else
  8178. {
  8179. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8180. }
  8181. if (New)
  8182. {
  8183. Configuration->Usage->Inc(L"UpdateNotifications");
  8184. }
  8185. }
  8186. }
  8187. //---------------------------------------------------------------------------
  8188. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8189. {
  8190. RestoreApp();
  8191. bool CanDisplay = !NonVisualDataModule->Busy;
  8192. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8193. {
  8194. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8195. }
  8196. if (CanDisplay)
  8197. {
  8198. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8199. CheckForUpdates(true);
  8200. }
  8201. else
  8202. {
  8203. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8204. }
  8205. }
  8206. //---------------------------------------------------------------------------
  8207. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8208. TCopyParamRuleData & Data)
  8209. {
  8210. DebugAssert(Terminal != NULL);
  8211. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8212. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8213. Data.RemoteDirectory = RemoteDirView->PathName;
  8214. }
  8215. //---------------------------------------------------------------------------
  8216. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8217. {
  8218. // Terminal can be null when we are changing local directory implicitly,
  8219. // because it has been deleted, while no session is connected
  8220. // (Login dialog is open)
  8221. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8222. {
  8223. DebugAssert(!IsLocalBrowserMode());
  8224. TCopyParamRuleData Data;
  8225. GetTransferPresetAutoSelectData(Data);
  8226. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8227. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8228. if (CopyParamIndex < 0)
  8229. {
  8230. // there is no preset that matches autoselection
  8231. // set preset that we consider "default"
  8232. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8233. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8234. }
  8235. else
  8236. {
  8237. // there is preset matching autoselection
  8238. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8239. if (CopyParamName == FCopyParamAutoSelected)
  8240. {
  8241. // autoselected the same preset as the last time
  8242. // make no change (i.e. preserve custom user preset, if any)
  8243. }
  8244. else
  8245. {
  8246. // autoselected the different preset then the last time (or there
  8247. // was default preset set)
  8248. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8249. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8250. }
  8251. }
  8252. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8253. {
  8254. if (CopyParamIndex >= 0)
  8255. {
  8256. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8257. }
  8258. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8259. try
  8260. {
  8261. int Fmt =
  8262. (CopyParamIndex < 0) ?
  8263. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8264. COPY_PARAM_AUTOSELECTED;
  8265. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8266. Data->Message = MainInstructions(Message);
  8267. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8268. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8269. CopyParamAttrs);
  8270. if (CopyParamIndex >= 0)
  8271. {
  8272. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8273. Info = FORMAT(L"%s\n \n%s", (Info,
  8274. FMTLOAD(COPY_PARAM_RULE,
  8275. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8276. }
  8277. Data->Message += L"\n\n" + Info;
  8278. if (WinConfiguration->CopyParamAutoSelectNotice)
  8279. {
  8280. TransferPresetNoteMessage(Data, true);
  8281. }
  8282. else
  8283. {
  8284. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8285. Data = NULL; // ownership passed
  8286. }
  8287. }
  8288. __finally
  8289. {
  8290. delete Data;
  8291. }
  8292. }
  8293. }
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8297. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8298. {
  8299. DebugAssert(NoteData != NULL);
  8300. DebugAssert(!IsLocalBrowserMode());
  8301. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8302. TQueryButtonAlias Aliases[1];
  8303. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8304. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8305. Params.Aliases = Aliases;
  8306. Params.AliasesCount = LENOF(Aliases);
  8307. unsigned int Result =
  8308. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8309. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8310. switch (Result)
  8311. {
  8312. case qaNeverAskAgain:
  8313. DebugAssert(AllowNeverAskAgain);
  8314. WinConfiguration->CopyParamAutoSelectNotice = false;
  8315. break;
  8316. case qaIgnore:
  8317. PreferencesDialog(pmPresets);
  8318. break;
  8319. }
  8320. }
  8321. //---------------------------------------------------------------------------
  8322. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8323. {
  8324. // as of now useless, as this is used for notes only, never for balloons, ...
  8325. RestoreApp();
  8326. // .. and we should never be busy here
  8327. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8328. {
  8329. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8330. }
  8331. }
  8332. //---------------------------------------------------------------------------
  8333. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8334. TPreferencesMode APreferencesMode)
  8335. {
  8336. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8337. TCopyParamRuleData Data;
  8338. if (Terminal != NULL)
  8339. {
  8340. PreferencesData.reset(new TPreferencesDialogData());
  8341. GetTransferPresetAutoSelectData(Data);
  8342. PreferencesData->CopyParamRuleData = &Data;
  8343. }
  8344. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8345. }
  8346. //---------------------------------------------------------------------------
  8347. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8348. const TCustomCommandType & Command)
  8349. {
  8350. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8351. {
  8352. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8353. }
  8354. }
  8355. //---------------------------------------------------------------------------
  8356. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8357. {
  8358. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8359. TCustomCommandType Command;
  8360. // make sure we use local custom command when remote are not supported
  8361. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8362. {
  8363. Command = FLastCustomCommand;
  8364. }
  8365. else
  8366. {
  8367. Command.Params = Command.Params | ccLocal;
  8368. }
  8369. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8370. FEditingFocusedAdHocCommand = OnFocused;
  8371. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8372. int Options =
  8373. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8374. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8375. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8376. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8377. {
  8378. FLastCustomCommand = Command;
  8379. UpdateCustomCommandsToolbar();
  8380. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8381. }
  8382. }
  8383. //---------------------------------------------------------------------------
  8384. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8385. {
  8386. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8387. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8388. DebugAssert(State > 0);
  8389. if (State <= 0)
  8390. {
  8391. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8392. }
  8393. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8394. }
  8395. //---------------------------------------------------------------------------
  8396. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8397. TCustomCommandType & Command, int & State)
  8398. {
  8399. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8400. if (Result)
  8401. {
  8402. Command = FLastCustomCommand;
  8403. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8404. }
  8405. return Result;
  8406. }
  8407. //---------------------------------------------------------------------------
  8408. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8409. {
  8410. ResetIncrementalSearch();
  8411. }
  8412. //---------------------------------------------------------------------------
  8413. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8414. {
  8415. DebugAssert(ComponentVisible[Component]);
  8416. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8417. }
  8418. //---------------------------------------------------------------------------
  8419. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8420. {
  8421. // when queue panel is resized here directly, the status bar is stretched
  8422. // over whole space the panel occupied
  8423. PostComponentHide(fcQueueView);
  8424. }
  8425. //---------------------------------------------------------------------------
  8426. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8427. {
  8428. ComponentVisible[fcQueueFileList] = false;
  8429. }
  8430. //---------------------------------------------------------------------------
  8431. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8432. {
  8433. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8434. RefreshColorMode();
  8435. WinConfiguration->ResetSysDarkTheme();
  8436. ConfigurationChanged();
  8437. ConfigureInterface();
  8438. // Should be called for all controls
  8439. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8440. }
  8441. //---------------------------------------------------------------------------
  8442. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8443. {
  8444. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8445. if (!FInvalid &&
  8446. (Message.LParam != 0) &&
  8447. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8448. {
  8449. ThemeChanged();
  8450. }
  8451. TForm::Dispatch(&Message);
  8452. }
  8453. //---------------------------------------------------------------------------
  8454. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8455. {
  8456. TMessage * M = static_cast<TMessage*>(Message);
  8457. switch (M->Msg)
  8458. {
  8459. case CM_DIALOGCHAR:
  8460. CMDialogChar(*M);
  8461. break;
  8462. case WM_APPCOMMAND:
  8463. WMAppCommand(*M);
  8464. break;
  8465. case WM_SYSCOMMAND:
  8466. WMSysCommand(*M);
  8467. break;
  8468. case WM_QUERYENDSESSION:
  8469. WMQueryEndSession(*M);
  8470. break;
  8471. case WM_ENDSESSION:
  8472. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8473. break;
  8474. #ifdef _DEBUG
  8475. case WM_WINDOWPOSCHANGED:
  8476. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8477. break;
  8478. case CM_CUSTOMSTYLECHANGED:
  8479. TForm::Dispatch(Message);
  8480. break;
  8481. #endif
  8482. case WM_COMPONENT_HIDE:
  8483. {
  8484. Byte Component = static_cast<Byte>(M->WParam);
  8485. // sanity check
  8486. if (ComponentVisible[Component])
  8487. {
  8488. // special treatment
  8489. if (Component == fcQueueView)
  8490. {
  8491. ToggleQueueVisibility();
  8492. DebugAssert(!ComponentVisible[fcQueueView]);
  8493. }
  8494. else
  8495. {
  8496. ComponentVisible[Component] = false;
  8497. }
  8498. }
  8499. }
  8500. break;
  8501. case WM_COPYDATA:
  8502. WMCopyData(*M);
  8503. break;
  8504. case WM_MANAGES_CAPTION:
  8505. // caption managed in TTerminalManager::UpdateAppTitle()
  8506. M->Result = 1;
  8507. break;
  8508. case WM_WANTS_MOUSEWHEEL:
  8509. M->Result = 1;
  8510. break;
  8511. case CM_SHOWINGCHANGED:
  8512. CMShowingChanged(*M);
  8513. break;
  8514. case WM_CLOSE:
  8515. WMClose(*M);
  8516. break;
  8517. case WM_DPICHANGED:
  8518. WMDpiChanged(*M);
  8519. break;
  8520. case CM_DPICHANGED:
  8521. CMDpiChanged(*M);
  8522. break;
  8523. case WM_SETTINGCHANGE:
  8524. WMSettingChange(*M);
  8525. break;
  8526. case CM_DIALOGKEY:
  8527. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8528. break;
  8529. default:
  8530. TForm::Dispatch(Message);
  8531. break;
  8532. }
  8533. }
  8534. //---------------------------------------------------------------------------
  8535. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8536. {
  8537. // noop
  8538. }
  8539. //---------------------------------------------------------------------------
  8540. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8541. {
  8542. TForm::Dispatch(&Message);
  8543. FSessionColors->Clear();
  8544. AddFixedSessionImages();
  8545. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8546. UpdateImages();
  8547. }
  8548. //---------------------------------------------------------------------------
  8549. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8550. {
  8551. TForm::Dispatch(&Message);
  8552. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8553. UpdatePixelsPerInchMainWindowCounter();
  8554. }
  8555. //---------------------------------------------------------------------------
  8556. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8557. {
  8558. // Cannot close window while we are busy.
  8559. // We cannot test this in FormCloseQuery as that is called also from
  8560. // Close(), which is called by CloseApplicationAction. So we can be busy
  8561. // there already even, when it is legitimate to close the application.
  8562. // Possibly a better place to handle this would be WMSysCommand.
  8563. if (NonVisualDataModule->Busy)
  8564. {
  8565. Message.Result = 1;
  8566. }
  8567. else
  8568. {
  8569. TForm::Dispatch(&Message);
  8570. }
  8571. }
  8572. //---------------------------------------------------------------------------
  8573. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8574. {
  8575. TForm::Dispatch(&Message);
  8576. if (Showing && (Terminal == NULL))
  8577. {
  8578. // When we are starting minimized (i.e. from an installer),
  8579. // postpone showing Login dialog until we get restored.
  8580. // Otherwise the Login dialog (and Authentication window) show restored
  8581. // over invisible (minimized) main window.
  8582. if (WindowState == wsMinimized)
  8583. {
  8584. FNeedSession = true;
  8585. }
  8586. else
  8587. {
  8588. // This happens before application ever goes idle, so the toolbars would
  8589. // stay enabled (initial state) until the Login dialog is dismissed.
  8590. UpdateActions();
  8591. NonVisualDataModule->StartBusy();
  8592. try
  8593. {
  8594. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8595. // otherwise the dialog does not receive focus.
  8596. // With Commander interface the ProcessMessages is called already
  8597. // by TDriveView, but with Explorer interface, we need to call it explicily
  8598. Application->ProcessMessages();
  8599. // do not reload sessions, they have been loaded just now (optimization)
  8600. NeedSession(true);
  8601. }
  8602. __finally
  8603. {
  8604. NonVisualDataModule->EndBusy();
  8605. }
  8606. }
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8611. {
  8612. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8613. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8614. }
  8615. //---------------------------------------------------------------------------
  8616. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8617. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8618. int & MaxHeight)
  8619. {
  8620. // workaround for bug in TWinControl.CalcConstraints
  8621. // Check for empty rect (restore from iconic state) is done there only after
  8622. // call to AdjustClientRect, which enlarges the rect (for forms).
  8623. TRect R = GetClientRect();
  8624. // when restoring from iconic state, place no restrictions
  8625. if (IsRectEmpty(R))
  8626. {
  8627. MinWidth = 0;
  8628. MinHeight = 0;
  8629. MaxWidth = 32000;
  8630. MaxHeight = 32000;
  8631. }
  8632. }
  8633. //---------------------------------------------------------------------------
  8634. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8635. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8636. {
  8637. // terminal can be already closed (e.g. dropped connection)
  8638. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8639. {
  8640. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8641. try
  8642. {
  8643. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8644. }
  8645. catch(...)
  8646. {
  8647. if (!Terminal->Active)
  8648. {
  8649. Close = true;
  8650. }
  8651. throw;
  8652. }
  8653. }
  8654. }
  8655. //---------------------------------------------------------------------------
  8656. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8657. {
  8658. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8659. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8660. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8661. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8662. {
  8663. OnGetSpaceAvailable = GetSpaceAvailable;
  8664. }
  8665. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8666. OnGetSpaceAvailable);
  8667. }
  8668. //---------------------------------------------------------------------------
  8669. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8670. {
  8671. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8672. Terminal->FillSessionDataForCode(Data.get());
  8673. return Data.release();
  8674. }
  8675. //---------------------------------------------------------------------------
  8676. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8677. {
  8678. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8679. DoGenerateUrlDialog(Data.get(), Paths);
  8680. }
  8681. //---------------------------------------------------------------------------
  8682. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8683. {
  8684. GenerateUrl(NULL);
  8685. }
  8686. //---------------------------------------------------------------------------
  8687. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8688. {
  8689. std::unique_ptr<TStrings> Paths(new TStringList());
  8690. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8691. GenerateUrl(Paths.get());
  8692. }
  8693. //---------------------------------------------------------------------------
  8694. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8695. {
  8696. FSessionColor = value;
  8697. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8698. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8699. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8700. DebugAssert(ColorItem != NULL);
  8701. ColorItem->Color = C;
  8702. NonVisualDataModule->ColorMenuItem->Color = C;
  8703. UpdateControls();
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8707. {
  8708. if (value != FSessionColor)
  8709. {
  8710. UpdateSessionColor(value);
  8711. // Is null when called from LastTerminalClosed
  8712. if (Terminal != NULL)
  8713. {
  8714. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8715. }
  8716. }
  8717. }
  8718. //---------------------------------------------------------------------------
  8719. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8720. {
  8721. bool Result = FNoteTimer->Enabled;
  8722. if (Result)
  8723. {
  8724. // cannot cancel note too early
  8725. bool NotEarly =
  8726. (Now() - FNoteShown >
  8727. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8728. if (Force || NotEarly)
  8729. {
  8730. FNoteTimer->Enabled = false;
  8731. FNote = L"";
  8732. SAFE_DESTROY(FNoteData);
  8733. FOnNoteClick = NULL;
  8734. FNoteHints = FNotes->Text;
  8735. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8736. UpdateStatusBar();
  8737. }
  8738. }
  8739. return Result;
  8740. }
  8741. //---------------------------------------------------------------------------
  8742. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8743. {
  8744. DebugAssert(FNoteTimer->Enabled);
  8745. CancelNote(true);
  8746. }
  8747. //---------------------------------------------------------------------------
  8748. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8749. {
  8750. int P = Note.Pos(L"\n");
  8751. if (P > 0)
  8752. {
  8753. Note.SetLength(P - 1);
  8754. }
  8755. FNotes->Add(FORMAT(L"[%s] %s",
  8756. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8757. while (FNotes->Count > 10)
  8758. {
  8759. FNotes->Delete(0);
  8760. }
  8761. if (UpdateNow)
  8762. {
  8763. FNoteHints = FNotes->Text;
  8764. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8765. UpdateStatusBar();
  8766. }
  8767. }
  8768. //---------------------------------------------------------------------------
  8769. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8770. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8771. {
  8772. int P = Note.Pos(L"\n");
  8773. if (P > 0)
  8774. {
  8775. Note.SetLength(P - 1);
  8776. }
  8777. FNoteHints = FNotes->Text;
  8778. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8779. FNote = Note;
  8780. SAFE_DESTROY(FNoteData);
  8781. FNoteData = NoteData;
  8782. FOnNoteClick = OnNoteClick;
  8783. AddNote(Note, false);
  8784. UpdateStatusBar();
  8785. FNoteShown = Now();
  8786. FNoteTimer->Enabled = false;
  8787. if (Seconds == 0)
  8788. {
  8789. Seconds = WinConfiguration->NotificationsTimeout;
  8790. }
  8791. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8792. FNoteTimer->Enabled = true;
  8793. }
  8794. //---------------------------------------------------------------------------
  8795. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8796. {
  8797. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8798. }
  8799. //---------------------------------------------------------------------------
  8800. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8801. {
  8802. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8803. {
  8804. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8805. }
  8806. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8807. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8808. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8809. 0, NULL, NULL);
  8810. }
  8811. //---------------------------------------------------------------------------
  8812. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8813. {
  8814. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8815. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8816. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8817. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8818. }
  8819. //---------------------------------------------------------------------------
  8820. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8821. {
  8822. WinConfiguration->FormatSizeBytes = Style;
  8823. }
  8824. //---------------------------------------------------------------------------
  8825. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8826. {
  8827. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8828. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8829. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8830. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8831. }
  8832. //---------------------------------------------------------------------------
  8833. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8834. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8835. {
  8836. if (Panel->Index == 0)
  8837. {
  8838. if (FOnNoteClick != NULL)
  8839. {
  8840. // prevent the user data from being freed by possible call
  8841. // to CancelNote or PostNote during call to OnNoteClick
  8842. std::unique_ptr<TObject> NoteData(FNoteData);
  8843. TNotifyEvent OnNoteClick = FOnNoteClick;
  8844. FNoteData = NULL;
  8845. // need to cancel the note as we are going to delete its user data
  8846. CancelNote(true);
  8847. OnNoteClick(NoteData.get());
  8848. }
  8849. }
  8850. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8851. {
  8852. FileSystemInfo();
  8853. }
  8854. }
  8855. //---------------------------------------------------------------------------
  8856. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8857. {
  8858. // workaround:
  8859. // 1) for unknown reason, disabling window, while minimized,
  8860. // prevents it from restoring, even if it was enabled again meanwhile
  8861. // 2) when disabling the main window, while another has focus
  8862. // minimize is no longer possible
  8863. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8864. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8865. // Shouldn't we use IsApplicationMinimized() here?
  8866. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8867. {
  8868. Enabled = false;
  8869. }
  8870. FLockLevel++;
  8871. }
  8872. //---------------------------------------------------------------------------
  8873. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8874. {
  8875. DebugAssert(FLockLevel > 0);
  8876. FLockLevel--;
  8877. if (FLockLevel == 0)
  8878. {
  8879. DebugAssert(FLockSuspendLevel == 0);
  8880. Enabled = true;
  8881. }
  8882. }
  8883. //---------------------------------------------------------------------------
  8884. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8885. {
  8886. // We need to make sure that window is enabled when the last modal window closes
  8887. // otherwise focus is not restored correctly.
  8888. // So we re-enable the window when modal window opens and
  8889. // disable it back after is closes
  8890. if (FLockLevel > 0)
  8891. {
  8892. // while we have nesting counter, we know that we never be called
  8893. // recursivelly as Application->OnModalBegin is called only
  8894. // for the top-level modal window
  8895. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8896. {
  8897. // won't be disabled when conditions in LockWindow() were not satisfied
  8898. FDisabledOnLockSuspend = !Enabled;
  8899. // When minimized to tray (or actually when set to SW_HIDE),
  8900. // setting Enabled makes the window focusable even when there's
  8901. // modal window over it
  8902. if (!FTrayIcon->Visible)
  8903. {
  8904. Enabled = true;
  8905. }
  8906. }
  8907. FLockSuspendLevel++;
  8908. }
  8909. }
  8910. //---------------------------------------------------------------------------
  8911. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8912. {
  8913. if (FLockSuspendLevel > 0)
  8914. {
  8915. DebugAssert(FLockLevel > 0);
  8916. FLockSuspendLevel--;
  8917. // see comment in SuspendWindowLock
  8918. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8919. {
  8920. // Note that window can be enabled here, when we were minized to tray when
  8921. // was SuspendWindowLock() called.
  8922. // We should possibly do the same check as in LockWindow(),
  8923. // if it is ever possible that the consitions change between
  8924. // SuspendWindowLock() and ResumeWindowLock()
  8925. Enabled = !FDisabledOnLockSuspend;
  8926. }
  8927. }
  8928. }
  8929. //---------------------------------------------------------------------------
  8930. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8931. {
  8932. if (!TextOnly)
  8933. {
  8934. TTBXComboBoxItem * RemotePathComboBox =
  8935. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8936. TStrings * Items = RemotePathComboBox->Strings;
  8937. Items->BeginUpdate();
  8938. try
  8939. {
  8940. Items->Clear();
  8941. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8942. {
  8943. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8944. while (!IsUnixRootPath(APath))
  8945. {
  8946. int P = APath.LastDelimiter(L'/');
  8947. DebugAssert(P >= 0);
  8948. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8949. APath.SetLength(P - 1);
  8950. }
  8951. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8952. }
  8953. }
  8954. __finally
  8955. {
  8956. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8957. // Setting ItemIndex to -1 does not reset its text
  8958. if (Items->Count == 0)
  8959. {
  8960. RemotePathComboBox->Text = L"";
  8961. }
  8962. Items->EndUpdate();
  8963. }
  8964. }
  8965. }
  8966. //---------------------------------------------------------------------------
  8967. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8968. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8969. int & ImageIndex)
  8970. {
  8971. if (AIndex < 0)
  8972. {
  8973. AIndex = Sender->ItemIndex;
  8974. }
  8975. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8976. }
  8977. //---------------------------------------------------------------------------
  8978. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8979. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8980. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8981. {
  8982. ARect.Left += (10 * AIndex);
  8983. }
  8984. //---------------------------------------------------------------------------
  8985. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8986. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8987. {
  8988. AWidth += (10 * AIndex);
  8989. }
  8990. //---------------------------------------------------------------------------
  8991. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8992. TObject * Sender)
  8993. {
  8994. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8995. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8996. int Index = RemotePathComboBox->ItemIndex;
  8997. while (Index < RemotePathComboBox->Strings->Count - 1)
  8998. {
  8999. APath = UnixExtractFileDir(APath);
  9000. Index++;
  9001. }
  9002. // VanDyke style paths
  9003. if (APath.IsEmpty())
  9004. {
  9005. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9006. APath = ROOTDIRECTORY;
  9007. }
  9008. if (RemoteDirView->Path != APath)
  9009. {
  9010. RemoteDirView->Path = APath;
  9011. }
  9012. }
  9013. //---------------------------------------------------------------------------
  9014. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9015. {
  9016. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9017. DebugUsedParam(Sender);
  9018. UpdateRemotePathComboBox(true);
  9019. }
  9020. //---------------------------------------------------------------------------
  9021. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9022. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9023. {
  9024. ResetIncrementalSearch();
  9025. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9026. DebugAssert(DirView != NULL);
  9027. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9028. {
  9029. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9030. // OnEditing is called also from TCustomListView::CanEdit
  9031. if (Edit != NULL)
  9032. {
  9033. EditSelectBaseName(Edit);
  9034. }
  9035. }
  9036. }
  9037. //---------------------------------------------------------------------------
  9038. //---------------------------------------------------------------------------
  9039. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9040. {
  9041. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9042. Result->AutoDetectDnD = false;
  9043. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9044. Result->RenderDataOn = rdoEnterAndDropSync;
  9045. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9046. return Result;
  9047. }
  9048. //---------------------------------------------------------------------------
  9049. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9050. {
  9051. TForm::CreateWnd();
  9052. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9053. if (FSessionsDragDropFilesEx == NULL)
  9054. {
  9055. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9056. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9057. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9058. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9059. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9060. }
  9061. if (FQueueDragDropFilesEx == NULL)
  9062. {
  9063. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9064. // No need to set OnDragOver as we do not have any restrictions
  9065. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9066. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9067. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9068. }
  9069. }
  9070. //---------------------------------------------------------------------------
  9071. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9072. {
  9073. TForm::DestroyWnd();
  9074. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9075. FQueueDragDropFilesEx->DragDropControl = NULL;
  9076. }
  9077. //---------------------------------------------------------------------------
  9078. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9079. {
  9080. SideEnter(FCurrentSide);
  9081. FEverShown = true;
  9082. }
  9083. //---------------------------------------------------------------------------
  9084. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9085. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9086. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9087. {
  9088. if (!NonVisualDataModule->Busy)
  9089. {
  9090. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9091. Configuration->Usage->Inc(L"FileFinds");
  9092. LockWindow(true);
  9093. NonVisualDataModule->StartBusy();
  9094. WinConfiguration->LockedInterface = true;
  9095. try
  9096. {
  9097. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9098. }
  9099. __finally
  9100. {
  9101. WinConfiguration->LockedInterface = false;
  9102. NonVisualDataModule->EndBusy();
  9103. UnlockWindow();
  9104. }
  9105. }
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9109. {
  9110. if (!NonVisualDataModule->Busy)
  9111. {
  9112. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9113. SetFocus();
  9114. RemoteDirView->Path = UnixExtractFilePath(Path);
  9115. UnicodeString FileName = UnixExtractFileName(Path);
  9116. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9117. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9118. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9119. if (Item == NULL)
  9120. {
  9121. ReloadDirectory(osRemote);
  9122. Item = RemoteDirView->FindFileItem(FileName);
  9123. }
  9124. if (Item != NULL)
  9125. {
  9126. RemoteDirView->ItemFocused = Item;
  9127. RemoteDirView->ItemFocused->MakeVisible(false);
  9128. RemoteDirView->SetFocus();
  9129. }
  9130. }
  9131. }
  9132. //---------------------------------------------------------------------------
  9133. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9134. {
  9135. bool Result = !NonVisualDataModule->Busy;
  9136. if (Result)
  9137. {
  9138. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9139. }
  9140. return Result;
  9141. }
  9142. //---------------------------------------------------------------------------
  9143. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9144. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9145. {
  9146. if (CanOperateOnFoundFiles(ATerminal))
  9147. {
  9148. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9149. FOnFileOperationFinished = OnFileOperationFinished;
  9150. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9151. }
  9152. }
  9153. //---------------------------------------------------------------------------
  9154. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9155. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9156. {
  9157. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9158. }
  9159. //---------------------------------------------------------------------------
  9160. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9161. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9162. {
  9163. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9164. }
  9165. //---------------------------------------------------------------------------
  9166. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9167. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9168. {
  9169. if (CanOperateOnFoundFiles(ATerminal))
  9170. {
  9171. for (int Index = 0; Index < FileList->Count; Index++)
  9172. {
  9173. UnicodeString FileName = FileList->Strings[Index];
  9174. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9175. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9176. OnFileOperationFinished(FileName, true);
  9177. }
  9178. }
  9179. }
  9180. //---------------------------------------------------------------------------
  9181. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9182. {
  9183. FFileFindTerminal = Terminal;
  9184. ShowFileFindDialog(
  9185. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9186. DoDownloadFoundFiles, DoEditFoundFiles);
  9187. }
  9188. //---------------------------------------------------------------------------
  9189. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9190. {
  9191. FTaskbarList = TaskbarList;
  9192. }
  9193. //---------------------------------------------------------------------------
  9194. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9195. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9196. {
  9197. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9198. if (Index >= 0)
  9199. {
  9200. if (Button == mbLeft)
  9201. {
  9202. // "Mouse down" is raised only after tab is switched.
  9203. // If switching tab (switching session) takes long enough for user
  9204. // to actually release the button, "mouse down" is still raised,
  9205. // but we do not get "mouse up" event, so dragging is not cancelled,
  9206. // prevent that by not beginning dragging in the first place.
  9207. if (IsKeyPressed(VK_LBUTTON))
  9208. {
  9209. // when user clicks the "+", we get mouse down only after the session
  9210. // is closed, when new session tab is already on X:Y, so dragging
  9211. // starts, prevent that
  9212. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9213. {
  9214. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9215. if (Terminal != NULL)
  9216. {
  9217. SessionsPageControl->BeginDrag(false);
  9218. }
  9219. }
  9220. }
  9221. }
  9222. else if (Button == mbMiddle)
  9223. {
  9224. // ignore middle-click for "New session tab"
  9225. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9226. if (Terminal != NULL)
  9227. {
  9228. CloseSessionTab(Index);
  9229. }
  9230. }
  9231. }
  9232. }
  9233. //---------------------------------------------------------------------------
  9234. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9235. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9236. {
  9237. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9238. // do not allow dropping on the "+" tab
  9239. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9240. if ((TargetTerminal != NULL) &&
  9241. (SessionsPageControl->ActivePage->PageIndex != Index))
  9242. {
  9243. Configuration->Usage->Inc(L"SessionTabMoves");
  9244. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9245. // but we want to actually prevent that to avoid flicker
  9246. SessionsPageControl->ActivePage->PageIndex = Index;
  9247. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9248. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9249. }
  9250. }
  9251. //---------------------------------------------------------------------------
  9252. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9253. TObject * Sender, TObject * Source, int X, int Y,
  9254. TDragState /*State*/, bool & Accept)
  9255. {
  9256. Accept = (Sender == Source);
  9257. if (Accept)
  9258. {
  9259. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9260. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9261. // do not allow dragging to the "+" tab
  9262. Accept = (Terminal != NULL);
  9263. }
  9264. }
  9265. //---------------------------------------------------------------------------
  9266. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9267. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9268. {
  9269. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9270. if (Index < 0)
  9271. {
  9272. Effect = DROPEFFECT_NONE;
  9273. }
  9274. else
  9275. {
  9276. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9277. // do not allow dropping on the "+" tab
  9278. if (TargetTerminal == NULL)
  9279. {
  9280. Effect = DROPEFFECT_NONE;
  9281. }
  9282. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9283. {
  9284. Effect = DROPEFFECT_COPY;
  9285. }
  9286. }
  9287. }
  9288. //---------------------------------------------------------------------------
  9289. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9290. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9291. {
  9292. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9293. // do not allow dropping on the "+" tab
  9294. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9295. if (TargetTerminal != NULL)
  9296. {
  9297. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9298. if (!IsFileControl(DropSourceControl, osRemote))
  9299. {
  9300. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9301. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9302. // Why don't we use Terminal->CurrentDirectory directly?
  9303. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9304. // do not force queue, drag drop
  9305. false, true);
  9306. }
  9307. }
  9308. }
  9309. //---------------------------------------------------------------------------
  9310. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9311. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9312. {
  9313. // Downloads are handled in RemoteFileControlDDEnd
  9314. if (!IsFileControl(DropSourceControl, osRemote))
  9315. {
  9316. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9317. Terminal->CurrentDirectory,
  9318. // force queue, drag drop
  9319. true, true);
  9320. }
  9321. }
  9322. //---------------------------------------------------------------------------
  9323. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9324. {
  9325. FShowing = false;
  9326. // Do not save empty workspace
  9327. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9328. {
  9329. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9330. UnicodeString Name = WorkspaceName();
  9331. DoSaveWorkspace(
  9332. Name, DataList.get(),
  9333. !Configuration->DisablePasswordStoring &&
  9334. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9335. WinConfiguration->LastStoredSession = Name;
  9336. }
  9337. }
  9338. //---------------------------------------------------------------------------
  9339. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9340. {
  9341. TManagedTerminal * ManagedTerminal =
  9342. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9343. if (ManagedTerminal != NULL)
  9344. {
  9345. ManagedTerminal->DirectoryLoaded = Now();
  9346. }
  9347. }
  9348. //---------------------------------------------------------------------------
  9349. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9350. TListItem * /*Item*/, bool /*Selected*/)
  9351. {
  9352. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9353. switch (DirView->LastSelectMethod)
  9354. {
  9355. case smKeyboard:
  9356. Configuration->Usage->Inc(L"KeyboardSelections");
  9357. break;
  9358. case smMouse:
  9359. Configuration->Usage->Inc(L"MouseSelections");
  9360. break;
  9361. }
  9362. }
  9363. //---------------------------------------------------------------------------
  9364. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9365. {
  9366. if (Color != 0)
  9367. {
  9368. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9369. }
  9370. else
  9371. {
  9372. return FSessionTabImageIndex;
  9373. }
  9374. }
  9375. //---------------------------------------------------------------------------
  9376. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9377. {
  9378. TPngImageCollectionItem * Item =
  9379. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9380. FSessionColors->AddPng(Item->PngImage);
  9381. return FSessionColors->Count - 1;
  9382. }
  9383. //---------------------------------------------------------------------------
  9384. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9385. {
  9386. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9387. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9388. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9389. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9393. {
  9394. for (int Index = 0; Index < Control->ControlCount; Index++)
  9395. {
  9396. TControl * AControl = Control->Controls[Index];
  9397. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9398. if (WinControl != NULL)
  9399. {
  9400. CollectItemsWithTextDisplayMode(WinControl);
  9401. }
  9402. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9403. if (Toolbar != NULL)
  9404. {
  9405. // we care for top-level items only
  9406. TTBCustomItem * Items = Toolbar->Items;
  9407. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9408. {
  9409. TTBCustomItem * Item = Items->Items[ItemIndex];
  9410. if (((Item->DisplayMode == nbdmImageAndText) ||
  9411. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9412. EligibleForImageDisplayMode(Item))
  9413. {
  9414. FItemsWithTextDisplayMode.insert(Item);
  9415. }
  9416. }
  9417. }
  9418. }
  9419. }
  9420. //---------------------------------------------------------------------------
  9421. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9422. {
  9423. return true;
  9424. }
  9425. //---------------------------------------------------------------------------
  9426. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9427. {
  9428. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9429. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9430. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9431. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9432. bool Result = true;
  9433. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9434. {
  9435. TTBCustomItem * Item = *i;
  9436. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9437. if (Label != NULL)
  9438. {
  9439. // optimization
  9440. if (Label->Visible == SelectiveToolbarText)
  9441. {
  9442. Result = false;
  9443. }
  9444. else
  9445. {
  9446. Label->Visible = SelectiveToolbarText;
  9447. }
  9448. }
  9449. else
  9450. {
  9451. // optimization
  9452. if (Item->DisplayMode == DisplayMode)
  9453. {
  9454. Result = false;
  9455. }
  9456. else
  9457. {
  9458. Item->DisplayMode = DisplayMode;
  9459. }
  9460. }
  9461. ++i;
  9462. }
  9463. if (Result)
  9464. {
  9465. UpdateNewSessionTab();
  9466. }
  9467. return Result;
  9468. }
  9469. //---------------------------------------------------------------------------
  9470. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9471. {
  9472. DebugFail();
  9473. }
  9474. //---------------------------------------------------------------------------
  9475. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9476. {
  9477. // Among other, a lock level is non zero, while directory is being loaded,
  9478. // even when it happens as a result of dirview navigation,
  9479. // i.e. when TNonVisualDataModule is NOT FBusy.
  9480. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9481. // Among other this prevents a panel auto update to occur while
  9482. // directory is changing.
  9483. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9484. }
  9485. //---------------------------------------------------------------------------
  9486. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9487. {
  9488. // While the window is disabled, we still seem to process menu shortcuts at least,
  9489. // so stop it at least here.
  9490. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9491. return
  9492. (Allowed == aaUpdate) ||
  9493. !NonVisualDataModule->Busy;
  9494. }
  9495. //---------------------------------------------------------------------------
  9496. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9497. {
  9498. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9499. }
  9500. //---------------------------------------------------------------------------
  9501. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9502. {
  9503. // This is somewhat redundant to LockWindow() call from
  9504. // TTerminalManager::TerminalReadDirectoryProgress.
  9505. // But disabling window is known not to block keyboard shorcuts
  9506. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9507. if (Busy > 0)
  9508. {
  9509. if (NonVisualDataModule->Busy)
  9510. {
  9511. State = false;
  9512. }
  9513. else
  9514. {
  9515. NonVisualDataModule->StartBusy();
  9516. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9517. LockWindow();
  9518. }
  9519. }
  9520. else if (Busy < 0)
  9521. {
  9522. UnlockWindow();
  9523. NonVisualDataModule->EndBusy();
  9524. }
  9525. else
  9526. {
  9527. State = NonVisualDataModule->Busy;
  9528. }
  9529. }
  9530. //---------------------------------------------------------------------------
  9531. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9532. {
  9533. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9534. // no context menu for "New session tab"
  9535. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9536. {
  9537. SessionsPageControl->ActivePageIndex = Index;
  9538. if (DebugAlwaysTrue(SessionTabSwitched()))
  9539. {
  9540. // copied from TControl.WMContextMenu
  9541. SendCancelMode(SessionsPageControl);
  9542. // explicit popup instead of using PopupMenu property
  9543. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9544. // while connecting yet not-connected session and hence
  9545. // allowing an access to commands over not-completelly connected session
  9546. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9547. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9548. PopupMenu->PopupComponent = SessionsPageControl;
  9549. PopupMenu->Popup(Point.x, Point.y);
  9550. }
  9551. }
  9552. Handled = true;
  9553. }
  9554. //---------------------------------------------------------------------------
  9555. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9556. {
  9557. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9558. }
  9559. //---------------------------------------------------------------------------
  9560. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9561. {
  9562. Configuration->Usage->Inc(L"PasswordChanges");
  9563. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9564. ChangePasswordData->DisableAuthentationsExceptPassword();
  9565. ChangePasswordData->ChangePassword = true;
  9566. std::unique_ptr<TTerminal> ChangePasswordSession(
  9567. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9568. ChangePasswordSession->AutoReadDirectory = false;
  9569. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9570. {
  9571. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9572. }
  9573. else
  9574. {
  9575. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9576. }
  9577. }
  9578. //---------------------------------------------------------------------------
  9579. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9580. {
  9581. // No nice way to assert SSH2
  9582. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9583. }
  9584. //---------------------------------------------------------------------------
  9585. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9586. {
  9587. TOperationVisualizer OperationVisualizer;
  9588. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9589. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9590. }
  9591. //---------------------------------------------------------------------------
  9592. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9593. {
  9594. TForm::ChangeScale(M, D);
  9595. int APixelsPerInch = GetControlPixelsPerInch(this);
  9596. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9597. try
  9598. {
  9599. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9600. }
  9601. __finally
  9602. {
  9603. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9604. }
  9605. }
  9606. //---------------------------------------------------------------------------
  9607. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9608. {
  9609. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9610. }
  9611. //---------------------------------------------------------------------
  9612. class TPublicControl : public TControl
  9613. {
  9614. friend class TCustomScpExplorerForm;
  9615. };
  9616. //---------------------------------------------------------------------------
  9617. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9618. {
  9619. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9620. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9621. }
  9622. //---------------------------------------------------------------------------
  9623. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9624. {
  9625. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9626. OpenBookmark(Side, Bookmark);
  9627. }
  9628. //---------------------------------------------------------------------------
  9629. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9630. {
  9631. DoBookmarkClick(osLocal, Sender);
  9632. }
  9633. //---------------------------------------------------------------------------
  9634. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9635. {
  9636. DoBookmarkClick(osRemote, Sender);
  9637. }
  9638. //---------------------------------------------------------------------------
  9639. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9640. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9641. {
  9642. // TODO
  9643. if (BookmarkList != NULL)
  9644. {
  9645. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9646. if (!WinConfiguration->UseLocationProfiles)
  9647. {
  9648. std::unique_ptr<TStringList> Directories(new TStringList());
  9649. Directories->CaseSensitive = (Side == osRemote);
  9650. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9651. {
  9652. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9653. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9654. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9655. {
  9656. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9657. Item->Caption = EscapeHotkey(Directory);
  9658. Item->ShortCut = Bookmark->ShortCut;
  9659. Item->OnClick = OnBookmarkClick;
  9660. Item->Tag = reinterpret_cast<int>(Bookmark);
  9661. Directories->Add(Directory);
  9662. Menu->Add(Item.release());
  9663. }
  9664. }
  9665. }
  9666. else
  9667. {
  9668. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9669. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9670. {
  9671. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9672. if (!Bookmark->Node.IsEmpty())
  9673. {
  9674. Folders->Add(Bookmark->Node);
  9675. }
  9676. }
  9677. for (int Index = 0; Index < Folders->Count; Index++)
  9678. {
  9679. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9680. Item->Caption = Folders->Strings[Index];
  9681. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9682. Folders->Objects[Index] = Item.get();
  9683. Menu->Add(Item.release());
  9684. }
  9685. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9686. {
  9687. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9688. TTBCustomItem * Parent;
  9689. if (!Bookmark->Node.IsEmpty())
  9690. {
  9691. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9692. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9693. }
  9694. else
  9695. {
  9696. Parent = Menu;
  9697. }
  9698. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9699. Item->Caption = Bookmark->Name;
  9700. Item->ShortCut = Bookmark->ShortCut;
  9701. Item->OnClick = OnBookmarkClick;
  9702. Item->Tag = reinterpret_cast<int>(Bookmark);
  9703. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9704. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9705. {
  9706. // No hint for location profiles that are actually mere "bookmarks"
  9707. }
  9708. else
  9709. {
  9710. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9711. UnicodeString LongHint;
  9712. if (!Bookmark->Local.IsEmpty())
  9713. {
  9714. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9715. }
  9716. if (!Bookmark->Remote.IsEmpty())
  9717. {
  9718. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9719. }
  9720. AddToList(Hint, LongHint, L"|");
  9721. Item->Hint = Hint;
  9722. }
  9723. Parent->Add(Item.release());
  9724. }
  9725. }
  9726. AddMenuSeparator(Menu);
  9727. }
  9728. }
  9729. //---------------------------------------------------------------------------
  9730. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9731. {
  9732. Menu->Clear();
  9733. std::unique_ptr<TTBCustomItem> Item;
  9734. Item.reset(new TTBXItem(Owner));
  9735. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9736. Item->Options = Item->Options << tboDefault;
  9737. Menu->Add(Item.release());
  9738. AddMenuSeparator(Menu);
  9739. if (Terminal != NULL)
  9740. {
  9741. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9742. }
  9743. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9744. Item.reset(new TTBXItem(Owner));
  9745. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9746. Menu->Add(Item.release());
  9747. }
  9748. //---------------------------------------------------------------------------
  9749. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9750. {
  9751. bool Result = true;
  9752. try
  9753. {
  9754. if (Side == osRemote)
  9755. {
  9756. Terminal->ExceptionOnFail = true;
  9757. }
  9758. try
  9759. {
  9760. DirView(Side)->Path = Path;
  9761. }
  9762. __finally
  9763. {
  9764. if (Side == osRemote)
  9765. {
  9766. Terminal->ExceptionOnFail = false;
  9767. }
  9768. }
  9769. }
  9770. catch (Exception & E)
  9771. {
  9772. if ((Side != osRemote) || Terminal->Active)
  9773. {
  9774. ShowExtendedExceptionEx(Terminal, &E);
  9775. Result = false;
  9776. }
  9777. else
  9778. {
  9779. throw;
  9780. }
  9781. }
  9782. return Result;
  9783. }
  9784. //---------------------------------------------------------------------------
  9785. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9786. {
  9787. // Make sure there some feedback even when loading tiny local folders
  9788. TInstantOperationVisualizer Visualizer;
  9789. DirView(Side)->ReloadDirectory();
  9790. }
  9791. //---------------------------------------------------------------------------
  9792. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9793. {
  9794. if (Index == SessionsPageControl->TabIndex)
  9795. {
  9796. CloseSession();
  9797. }
  9798. else
  9799. {
  9800. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9801. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9802. TTerminalManager * Manager = TTerminalManager::Instance();
  9803. if (!Terminal->Active)
  9804. {
  9805. Manager->FreeTerminal(Terminal);
  9806. }
  9807. else
  9808. {
  9809. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9810. if (CanCloseQueue(Queue))
  9811. {
  9812. Manager->FreeTerminal(Terminal);
  9813. }
  9814. }
  9815. }
  9816. }
  9817. //---------------------------------------------------------------------------
  9818. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9819. {
  9820. CloseSessionTab(Index);
  9821. }
  9822. //---------------------------------------------------------------------------
  9823. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9824. {
  9825. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9826. {
  9827. TInstantOperationVisualizer Visualizer;
  9828. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9829. // before we create a new data object
  9830. ClipboardClear();
  9831. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9832. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9833. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9834. // Intermediate variable to WORKAROUND a crash in compiler
  9835. TObjectList * ClipboardFakeMonitors =
  9836. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9837. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9838. if (FClipboardDragDropFilesEx.get() == NULL)
  9839. {
  9840. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9841. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9842. }
  9843. FClipboardDragDropFilesEx->FileList->Clear();
  9844. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9845. FClipboardDragDropFilesEx->CopyToClipboard();
  9846. FClipboardTerminal = FTerminal;
  9847. // Need full paths, as cwd can be different once files are pasted
  9848. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9849. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9850. {
  9851. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9852. }
  9853. }
  9854. }
  9855. //---------------------------------------------------------------------------
  9856. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9857. {
  9858. if (OpenClipboard(0))
  9859. {
  9860. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9861. CloseClipboard();
  9862. }
  9863. }
  9864. //---------------------------------------------------------------------------
  9865. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9866. {
  9867. return !FClipboardFakeDirectory.IsEmpty();
  9868. }
  9869. //---------------------------------------------------------------------------
  9870. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9871. {
  9872. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9873. FClipboardFakeDirectory = UnicodeString();
  9874. FClipboardTerminal = NULL;
  9875. // Also called in Idle()
  9876. FClipboardFakeMonitors.reset(NULL);
  9877. }
  9878. //---------------------------------------------------------------------------
  9879. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9880. {
  9881. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9882. {
  9883. ClipboardStop();
  9884. }
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9888. {
  9889. TTerminalManager * Manager = TTerminalManager::Instance();
  9890. Manager->ActiveTerminal = FClipboardTerminal;
  9891. TTransferOperationParam Params;
  9892. Params.TargetDirectory = TargetDirectory;
  9893. Params.DragDrop = DragDrop;
  9894. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9895. }
  9896. //---------------------------------------------------------------------------
  9897. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9898. {
  9899. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9900. // (as it pumps a Windows message queue while being shutted down)
  9901. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9902. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9903. {
  9904. // Can fail as it can be e.g. locked by AV, so we retry that later
  9905. bool Removed = RemoveDir(ApiPath(FileName));
  9906. try
  9907. {
  9908. if (!NonVisualDataModule->Busy)
  9909. {
  9910. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9911. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9912. }
  9913. }
  9914. __finally
  9915. {
  9916. if (!Removed)
  9917. {
  9918. RemoveDir(ApiPath(FileName));
  9919. }
  9920. }
  9921. }
  9922. }
  9923. //---------------------------------------------------------------------------
  9924. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9925. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9926. {
  9927. TFileMasks::TParams MaskParams;
  9928. MaskParams.Size = Size;
  9929. MaskParams.Modification = Modification;
  9930. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9931. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9932. {
  9933. bool ImplicitMatch;
  9934. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9935. !ImplicitMatch)
  9936. {
  9937. Color = Iter->Color;
  9938. break;
  9939. }
  9940. }
  9941. }
  9942. //---------------------------------------------------------------------------
  9943. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9944. {
  9945. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9946. if (!DirView->IsEditing())
  9947. {
  9948. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9949. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9950. // while searching
  9951. if (Key == VK_BACK)
  9952. {
  9953. if (!FIncrementalSearch.IsEmpty())
  9954. {
  9955. if (FIncrementalSearch.Length() == 1)
  9956. {
  9957. ResetIncrementalSearch();
  9958. }
  9959. else
  9960. {
  9961. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9962. IncrementalSearch(NewText, false, false);
  9963. }
  9964. Key = 0;
  9965. }
  9966. }
  9967. }
  9968. }
  9969. //---------------------------------------------------------------------------
  9970. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9971. {
  9972. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9973. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  9974. {
  9975. // Filter control sequences.
  9976. // When not searching yet, prefer use of the space for toggling file selection
  9977. // (so we cannot incrementally search for a string starting with a space).
  9978. if ((Key > VK_SPACE) ||
  9979. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9980. {
  9981. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9982. Key = 0;
  9983. }
  9984. }
  9985. }
  9986. //---------------------------------------------------------------------------
  9987. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  9988. {
  9989. if (!FIncrementalSearch.IsEmpty())
  9990. {
  9991. FIncrementalSearch = L"";
  9992. DirView(osCurrent)->UpdateStatusBar();
  9993. }
  9994. }
  9995. //---------------------------------------------------------------------------
  9996. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  9997. {
  9998. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  9999. if (Item == NULL)
  10000. {
  10001. MessageBeep(MB_ICONHAND);
  10002. }
  10003. else
  10004. {
  10005. TCustomDirView * ADirView = DirView(osCurrent);
  10006. {
  10007. TAutoNestingCounter Guard(FIncrementalSearching);
  10008. ADirView->FocusItem(Item);
  10009. if (ADirView->NortonLike == nlOff)
  10010. {
  10011. if ((ADirView->Selected != Item) ||
  10012. (ADirView->SelCount > 1))
  10013. {
  10014. ADirView->ClearSelection();
  10015. ADirView->Selected = Item;
  10016. }
  10017. }
  10018. }
  10019. FIncrementalSearch = Text;
  10020. Item->MakeVisible(false);
  10021. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10022. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10023. ADirView->UpdateStatusBar();
  10024. }
  10025. }
  10026. //---------------------------------------------------------------------------
  10027. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10028. {
  10029. int Index = Item->Index;
  10030. if (!Reverse)
  10031. {
  10032. Index++;
  10033. if (Index >= Item->Owner->Count)
  10034. {
  10035. Index = 0;
  10036. }
  10037. }
  10038. else
  10039. {
  10040. Index--;
  10041. if (Index < 0)
  10042. {
  10043. Index = Item->Owner->Count - 1;
  10044. }
  10045. }
  10046. return Item->Owner->Item[Index];
  10047. }
  10048. //---------------------------------------------------------------------------
  10049. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10050. {
  10051. TCustomDirView * ADirView = DirView(osCurrent);
  10052. if (ADirView->Items->Count == 0)
  10053. {
  10054. return NULL;
  10055. }
  10056. else
  10057. {
  10058. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10059. TListItem * Item = CurrentItem;
  10060. if (SkipCurrent)
  10061. {
  10062. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10063. }
  10064. while (true)
  10065. {
  10066. bool Matches = false;
  10067. switch (WinConfiguration->PanelSearch)
  10068. {
  10069. case isNameStartOnly:
  10070. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10071. break;
  10072. case isName:
  10073. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10074. break;
  10075. case isAll:
  10076. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10077. int Index = 0;
  10078. while ((Index < ColCount) && !Matches)
  10079. {
  10080. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10081. if (Visible)
  10082. {
  10083. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10084. }
  10085. Index++;
  10086. }
  10087. break;
  10088. }
  10089. if (Matches)
  10090. {
  10091. return Item;
  10092. }
  10093. Item = GetNextFile(Item, Reverse);
  10094. if (Item == CurrentItem)
  10095. {
  10096. return NULL;
  10097. }
  10098. }
  10099. }
  10100. }
  10101. //---------------------------------------------------------------------------
  10102. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10103. {
  10104. ResetIncrementalSearch();
  10105. }
  10106. //---------------------------------------------------------------------------
  10107. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10108. {
  10109. if (Message.CharCode == VK_TAB)
  10110. {
  10111. if (!FIncrementalSearch.IsEmpty())
  10112. {
  10113. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10114. bool Reverse = Shift.Contains(ssShift);
  10115. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10116. Message.Result = 1;
  10117. return;
  10118. }
  10119. }
  10120. else if (Message.CharCode == VK_ESCAPE)
  10121. {
  10122. if (!FIncrementalSearch.IsEmpty())
  10123. {
  10124. ResetIncrementalSearch();
  10125. Message.Result = 1;
  10126. return;
  10127. }
  10128. }
  10129. TForm::Dispatch(&Message);
  10130. }
  10131. //---------------------------------------------------------------------------
  10132. void __fastcall TCustomScpExplorerForm::Deactivate()
  10133. {
  10134. TForm::Deactivate();
  10135. // E.g. when switching to an internal editor window
  10136. ResetIncrementalSearch();
  10137. }
  10138. //---------------------------------------------------------------------------
  10139. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10140. {
  10141. // When switching to another application
  10142. ResetIncrementalSearch();
  10143. }
  10144. //---------------------------------------------------------------------------
  10145. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10146. {
  10147. ResetIncrementalSearch();
  10148. }
  10149. //---------------------------------------------------------------------------
  10150. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10151. {
  10152. if (FIncrementalSearching <= 0)
  10153. {
  10154. ResetIncrementalSearch();
  10155. }
  10156. }
  10157. //---------------------------------------------------------------------------
  10158. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10159. {
  10160. CountClicksForWindowPrint(this);
  10161. }
  10162. //---------------------------------------------------------------------------
  10163. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10164. {
  10165. CenterReconnectToolbar();
  10166. }
  10167. //---------------------------------------------------------------------------
  10168. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10169. {
  10170. if (RemoteDirView->ItemFocused != NULL)
  10171. {
  10172. RemoteDirView->ItemFocused->Selected = true;
  10173. }
  10174. }
  10175. //---------------------------------------------------------------------------
  10176. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10177. {
  10178. if (!FQueueStatusUpdating)
  10179. {
  10180. bool Refresh;
  10181. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10182. {
  10183. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10184. }
  10185. else
  10186. {
  10187. if (FQueueFileList->GetCount() > 0)
  10188. {
  10189. FQueueFileList->Clear();
  10190. Refresh = true;
  10191. }
  10192. }
  10193. int Count = FQueueFileList->GetCount();
  10194. if (QueueFileList->Items->Count != Count)
  10195. {
  10196. DebugAssert(Refresh);
  10197. QueueFileList->Items->Count = Count;
  10198. }
  10199. if (Refresh)
  10200. {
  10201. QueueFileList->Invalidate();
  10202. }
  10203. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10204. }
  10205. }
  10206. //---------------------------------------------------------------------------
  10207. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10208. {
  10209. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10210. }
  10211. //---------------------------------------------------------------------------
  10212. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10213. {
  10214. // should be improved, once we do not refresh the list when switching between details of the same batch
  10215. if (QueueFileList->Items->Count > 0)
  10216. {
  10217. QueueFileList->Items->Item[0]->MakeVisible(false);
  10218. }
  10219. UpdateQueueFileList();
  10220. }
  10221. //---------------------------------------------------------------------------
  10222. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10223. {
  10224. Active = QueueView3->Focused() || QueueFileList->Focused();
  10225. }
  10226. //---------------------------------------------------------------------------
  10227. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10228. {
  10229. QueueLabelUpdateStatus();
  10230. }
  10231. //---------------------------------------------------------------------------
  10232. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10233. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10234. {
  10235. int State = FQueueFileList->GetState(Item->Index);
  10236. if (State == qfsProcessed)
  10237. {
  10238. Sender->Canvas->Font->Color = clGrayText;
  10239. }
  10240. }
  10241. //---------------------------------------------------------------------------
  10242. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10243. {
  10244. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10245. QueueFileList->Column[0]->Width =
  10246. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10247. }
  10248. //---------------------------------------------------------------------------
  10249. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10250. {
  10251. QueueFileListColumnAutoSize();
  10252. }
  10253. //---------------------------------------------------------------------------