CustomScpExplorer.cpp 359 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938
  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. if (!FStarted)
  4317. {
  4318. FStarted = true;
  4319. InterfaceStarted();
  4320. }
  4321. }
  4322. }
  4323. if (FShowing || FStandaloneEditing)
  4324. {
  4325. if (FQueueStatusInvalidated)
  4326. {
  4327. UpdateQueueStatus(false);
  4328. }
  4329. RefreshQueueItems();
  4330. }
  4331. if (FShowing)
  4332. {
  4333. UpdateStatusBar();
  4334. }
  4335. FIgnoreNextDialogChar = 0;
  4336. }
  4337. //---------------------------------------------------------------------------
  4338. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4339. {
  4340. try
  4341. {
  4342. FUserActionTimer->Enabled = false;
  4343. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4344. {
  4345. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4346. {
  4347. FPendingQueueActionItem->ProcessUserAction();
  4348. }
  4349. }
  4350. }
  4351. __finally
  4352. {
  4353. FPendingQueueActionItem = NULL;
  4354. }
  4355. }
  4356. //---------------------------------------------------------------------------
  4357. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4358. {
  4359. if (WinConfiguration->MinimizeToTray)
  4360. {
  4361. UpdateTrayIcon();
  4362. FTrayIcon->Visible = true;
  4363. if (Visible)
  4364. {
  4365. ShowWindow(Handle, SW_HIDE);
  4366. }
  4367. }
  4368. }
  4369. //---------------------------------------------------------------------------
  4370. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4371. {
  4372. // WORKAROUND
  4373. // When restoring maximized window from minimization,
  4374. // rarely some controls do not align properly.
  4375. // Two instances seen (both for Commander):
  4376. // - When restoring, window is temporarily narrower (not maximized),
  4377. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4378. // Once maximized already, top dock shinks back, but the session PageControl,
  4379. // do not align up, leaving space between TopDock and PageControl.
  4380. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4381. for (int Index = 0; Index < ControlCount; Index++)
  4382. {
  4383. RealignControl(Controls[Index]);
  4384. }
  4385. if (FTrayIcon->Visible)
  4386. {
  4387. FTrayIcon->Visible = false;
  4388. if (Visible)
  4389. {
  4390. ShowWindow(Handle, SW_SHOW);
  4391. }
  4392. }
  4393. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4394. {
  4395. FNeedSession = false;
  4396. NonVisualDataModule->StartBusy();
  4397. try
  4398. {
  4399. NeedSession(true);
  4400. }
  4401. __finally
  4402. {
  4403. NonVisualDataModule->EndBusy();
  4404. }
  4405. }
  4406. }
  4407. //---------------------------------------------------------------------------
  4408. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4409. {
  4410. FTrayIcon->Hint = GetMainForm()->Caption;
  4411. }
  4412. //---------------------------------------------------------------------------
  4413. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4414. {
  4415. UpdateTrayIcon();
  4416. }
  4417. //---------------------------------------------------------------------------
  4418. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4419. {
  4420. // workaround
  4421. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4422. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4423. // But WM_ACTIVATEAPP message can be received even when
  4424. // the main window is minimized to the tray and internal editor window is focused
  4425. // (after another application was previously active)
  4426. if (::IsIconic(Handle))
  4427. {
  4428. if (!IsAppIconic())
  4429. {
  4430. SetAppIconic(true);
  4431. }
  4432. }
  4433. ::ApplicationRestore();
  4434. Application->BringToFront();
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4438. {
  4439. RestoreApp();
  4440. }
  4441. //---------------------------------------------------------------------------
  4442. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4443. {
  4444. if (OpenInNewWindow())
  4445. {
  4446. // todo: Pass FromSite
  4447. ExecuteNewInstance(SessionUrl);
  4448. }
  4449. else
  4450. {
  4451. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4452. }
  4453. }
  4454. //---------------------------------------------------------------------------
  4455. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4456. {
  4457. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4458. StoredSessions->NewSession(SessionName, SessionData);
  4459. // modified only, explicit
  4460. StoredSessions->Save(false, true);
  4461. // encode session name because of slashes in hierarchical sessions
  4462. return EncodeUrlString(SessionName);
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4466. {
  4467. // current working directories become defaults here, what is not right
  4468. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4469. return SaveHiddenDuplicateSession(SessionData.get());
  4470. }
  4471. //---------------------------------------------------------------------------
  4472. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4473. {
  4474. if (OpenInNewWindow())
  4475. {
  4476. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4477. }
  4478. else
  4479. {
  4480. // current working directories become defaults here, what is not right
  4481. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4482. TTerminalManager * Manager = TTerminalManager::Instance();
  4483. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4484. Manager->ActiveTerminal = Terminal;
  4485. }
  4486. }
  4487. //---------------------------------------------------------------------------
  4488. void __fastcall TCustomScpExplorerForm::RenameSession()
  4489. {
  4490. UnicodeString Name = Terminal->SessionData->SessionName;
  4491. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4492. {
  4493. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4494. TSessionData::ValidateName(Name);
  4495. // This is inconsistent with how color (for example) is handled.
  4496. Terminal->SessionData->Name = Name;
  4497. UpdateControls();
  4498. // Add/Remove distinguishing paths from sessions of the same name.
  4499. DoTerminalListChanged();
  4500. }
  4501. }
  4502. //---------------------------------------------------------------------------
  4503. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4504. {
  4505. DebugAssert(Queue != NULL);
  4506. bool Result = Queue->IsEmpty;
  4507. if (!Result)
  4508. {
  4509. SetFocus();
  4510. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4511. }
  4512. return Result;
  4513. }
  4514. //---------------------------------------------------------------------------
  4515. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4516. {
  4517. return CanCloseQueue(FQueue);
  4518. }
  4519. //---------------------------------------------------------------------------
  4520. void __fastcall TCustomScpExplorerForm::CloseSession()
  4521. {
  4522. if (CanCloseQueue())
  4523. {
  4524. TTerminalManager::Instance()->FreeActiveTerminal();
  4525. }
  4526. }
  4527. //---------------------------------------------------------------------------
  4528. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4529. {
  4530. if (CanCloseQueue())
  4531. {
  4532. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4533. }
  4534. }
  4535. //---------------------------------------------------------------------------
  4536. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4537. {
  4538. DetachTerminal(Terminal);
  4539. RemoteDirView->Terminal = Terminal;
  4540. UpdateRemotePathComboBox(false);
  4541. UpdateControls();
  4542. }
  4543. //---------------------------------------------------------------------------
  4544. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4545. {
  4546. if (DebugAlwaysTrue(!Terminal->Active))
  4547. {
  4548. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4549. }
  4550. }
  4551. //---------------------------------------------------------------------------
  4552. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4553. {
  4554. if (OpenInNewWindow())
  4555. {
  4556. // encode session name because of slashes in hierarchical sessions
  4557. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4558. }
  4559. else
  4560. {
  4561. TTerminalManager * Manager = TTerminalManager::Instance();
  4562. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4563. Manager->ActiveTerminal = Terminal;
  4564. }
  4565. }
  4566. //---------------------------------------------------------------------------
  4567. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4568. {
  4569. TTerminalManager * Manager = TTerminalManager::Instance();
  4570. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4571. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4572. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4573. // FirstTerminal can be null, if some of the
  4574. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4575. {
  4576. FirstTerminal->Disconnected = true;
  4577. FirstTerminal->DisconnectedTemporarily = true;
  4578. }
  4579. Manager->ActiveTerminal = FirstTerminal;
  4580. }
  4581. //---------------------------------------------------------------------------
  4582. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4583. {
  4584. if (OpenInNewWindow())
  4585. {
  4586. ExecuteNewInstance(Name);
  4587. }
  4588. else
  4589. {
  4590. DoOpenFolderOrWorkspace(Name, true);
  4591. }
  4592. }
  4593. //---------------------------------------------------------------------------
  4594. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4595. bool &CanClose)
  4596. {
  4597. // See the comment in CloseApp()
  4598. if (NonVisualDataModule->Busy)
  4599. {
  4600. CanClose = false;
  4601. }
  4602. else if (Terminal != NULL)
  4603. {
  4604. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4605. {
  4606. unsigned int Result;
  4607. TMessageParams Params(mpNeverAskAgainCheck);
  4608. UnicodeString Message;
  4609. int Answers = qaOK | qaCancel;
  4610. if (TTerminalManager::Instance()->Count > 1)
  4611. {
  4612. if (!WinConfiguration->AutoSaveWorkspace)
  4613. {
  4614. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4615. }
  4616. else
  4617. {
  4618. Message = LoadStr(CLOSE_SESSIONS);
  4619. }
  4620. }
  4621. else
  4622. {
  4623. if (!WinConfiguration->AutoSaveWorkspace)
  4624. {
  4625. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4626. }
  4627. else
  4628. {
  4629. Message = LoadStr(CLOSE_SESSION);
  4630. }
  4631. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4632. }
  4633. UnicodeString Note;
  4634. if (WinConfiguration->AutoSaveWorkspace)
  4635. {
  4636. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4637. }
  4638. else
  4639. {
  4640. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4641. Answers = qaYes | qaNo | qaCancel;
  4642. }
  4643. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4644. SetFocus();
  4645. Result = MessageDialog(Message, qtConfirmation,
  4646. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4647. if (Result == qaNeverAskAgain)
  4648. {
  4649. WinConfiguration->ConfirmClosingSession = false;
  4650. }
  4651. if (Result == qaNo)
  4652. {
  4653. CanClose = SaveWorkspace(true);
  4654. // note that the workspace will be saved redundatly again from FormClose
  4655. }
  4656. else
  4657. {
  4658. CanClose =
  4659. (Result == qaOK) ||
  4660. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4661. (Result == qaNeverAskAgain);
  4662. }
  4663. }
  4664. if (CanClose)
  4665. {
  4666. CanClose = CanCloseQueue();
  4667. }
  4668. }
  4669. if (CanClose)
  4670. {
  4671. CanClose =
  4672. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4673. FEditorManager->CloseExternalFilesWithoutProcess();
  4674. if (CanClose)
  4675. {
  4676. while (CanClose && (FLocalEditors->Count > 0))
  4677. {
  4678. int PrevCount = FLocalEditors->Count;
  4679. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4680. CanClose = (FLocalEditors->Count < PrevCount);
  4681. }
  4682. if (CanClose)
  4683. {
  4684. CanClose = FEditorManager->Empty(true);
  4685. if (!CanClose)
  4686. {
  4687. SetFocus();
  4688. CanClose =
  4689. (MessageDialog(
  4690. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4691. }
  4692. }
  4693. }
  4694. }
  4695. }
  4696. //---------------------------------------------------------------------------
  4697. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4698. {
  4699. TForm * Form = dynamic_cast<TForm *>(Sender);
  4700. DebugAssert(Form != NULL);
  4701. Form->Close();
  4702. }
  4703. //---------------------------------------------------------------------------
  4704. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4705. {
  4706. TForm * Form = dynamic_cast<TForm *>(Sender);
  4707. delete Form;
  4708. }
  4709. //---------------------------------------------------------------------------
  4710. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4711. {
  4712. while (FLocalEditors->Count > 0)
  4713. {
  4714. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4715. }
  4716. }
  4717. //---------------------------------------------------------------------------
  4718. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4719. TObject *Sender)
  4720. {
  4721. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4722. try
  4723. {
  4724. SetProperties(osRemote, FileList);
  4725. }
  4726. __finally
  4727. {
  4728. delete FileList;
  4729. }
  4730. }
  4731. //---------------------------------------------------------------------------
  4732. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4733. {
  4734. if (value)
  4735. {
  4736. if (Component == fcCustomCommandsBand)
  4737. {
  4738. UpdateCustomCommandsToolbar();
  4739. }
  4740. if (Component == fcQueueFileList)
  4741. {
  4742. DebugAssert(!QueueFileListSplitter->Visible);
  4743. AdjustQueueLayout();
  4744. UpdateQueueFileList();
  4745. }
  4746. }
  4747. }
  4748. //---------------------------------------------------------------------------
  4749. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4750. {
  4751. int MinHeightLimit =
  4752. GetStaticQueuePanelComponentsHeight() +
  4753. QueueFileListSplitter->Height +
  4754. QueueFileList->Height +
  4755. GetMinQueueViewHeight();
  4756. if (QueuePanel->ClientHeight < MinHeightLimit)
  4757. {
  4758. QueuePanel->ClientHeight = MinHeightLimit;
  4759. }
  4760. }
  4761. //---------------------------------------------------------------------------
  4762. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4763. {
  4764. TControl * Control = GetComponent(Component);
  4765. DebugAssert(Control);
  4766. bool Changed = (Control->Visible != value);
  4767. if (Changed)
  4768. {
  4769. ComponentShowing(Component, value);
  4770. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4771. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4772. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4773. if (value)
  4774. {
  4775. int RemainingHeight = Control->Parent->ClientHeight;
  4776. int RemainingWidth = Control->Parent->ClientWidth;
  4777. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4778. {
  4779. TControl * ChildControl = Control->Parent->Controls[i];
  4780. if (ChildControl->Visible)
  4781. {
  4782. switch (ChildControl->Align)
  4783. {
  4784. case alTop:
  4785. case alBottom:
  4786. RemainingHeight -= ChildControl->Height;
  4787. break;
  4788. case alLeft:
  4789. case alRight:
  4790. RemainingWidth -= ChildControl->Width;
  4791. break;
  4792. }
  4793. }
  4794. }
  4795. int Reserve = ScaleByTextHeight(this, 32);
  4796. // queue in explorer, trees in commander
  4797. if (Control->Height > RemainingHeight - Reserve)
  4798. {
  4799. Control->Height = RemainingHeight / 2;
  4800. }
  4801. if (Control->Width > RemainingWidth - Reserve)
  4802. {
  4803. Control->Width = RemainingWidth / 2;
  4804. }
  4805. }
  4806. Control->Visible = value;
  4807. if (WasFocused && Visible)
  4808. {
  4809. DirView(osCurrent)->SetFocus();
  4810. }
  4811. FixControlsPlacement();
  4812. }
  4813. }
  4814. //---------------------------------------------------------------------------
  4815. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4816. {
  4817. TControl * Control = GetComponent(Component);
  4818. if (Control == NULL)
  4819. {
  4820. return false;
  4821. }
  4822. else
  4823. {
  4824. return Control->Visible;
  4825. }
  4826. }
  4827. //---------------------------------------------------------------------------
  4828. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4829. {
  4830. bool Result;
  4831. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4832. {
  4833. Result = !IsUWP();
  4834. }
  4835. else
  4836. {
  4837. Result = true;
  4838. }
  4839. return Result;
  4840. }
  4841. //---------------------------------------------------------------------------
  4842. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4843. {
  4844. if (DirView(osOther)->ItemFocused != NULL)
  4845. {
  4846. DirView(osOther)->ItemFocused->MakeVisible(false);
  4847. }
  4848. QueueSplitter->Visible = QueuePanel->Visible;
  4849. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4850. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4851. TControl * QueueControlsOrder[] =
  4852. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4853. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4854. }
  4855. //---------------------------------------------------------------------------
  4856. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4857. {
  4858. switch (Component) {
  4859. case fcStatusBar: return RemoteStatusBar;
  4860. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4861. case fcQueueView: return QueuePanel;
  4862. case fcQueueToolbar: return QueueDock;
  4863. case fcRemoteTree: return RemoteDrivePanel;
  4864. case fcSessionsTabs: return SessionsPageControl;
  4865. case fcQueueFileList: return QueueFileList;
  4866. default: return NULL;
  4867. }
  4868. }
  4869. //---------------------------------------------------------------------------
  4870. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4871. TObject *Sender, TListColumn *Column, TPoint &Point)
  4872. {
  4873. DebugAssert(NonVisualDataModule && Column && Sender);
  4874. NonVisualDataModule->ListColumn = Column;
  4875. TPopupMenu * DirViewColumnMenu;
  4876. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4877. {
  4878. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4879. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4880. (Column->Index == uvName);
  4881. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4882. (Column->Index == uvSize);
  4883. }
  4884. else
  4885. {
  4886. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4887. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4888. (Column->Index == dvName);
  4889. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4890. (Column->Index == dvSize);
  4891. }
  4892. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4893. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4894. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4895. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4896. }
  4897. //---------------------------------------------------------------------------
  4898. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4899. TObject *Sender, TListItem *Item, bool &AllowExec)
  4900. {
  4901. DoDirViewExecFile(Sender, Item, AllowExec);
  4902. }
  4903. //---------------------------------------------------------------------------
  4904. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4905. TListItem * Item, bool & AllowExec)
  4906. {
  4907. DebugAssert(Sender && Item && Configuration);
  4908. DebugAssert(AllowExec);
  4909. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4910. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4911. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4912. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4913. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4914. // on files only (not directories)
  4915. // and only when symlinks are resolved (apply to remote panel only)
  4916. if (!ADirView->ItemIsDirectory(Item) &&
  4917. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4918. {
  4919. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4920. !FForceExecution &&
  4921. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4922. {
  4923. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4924. {
  4925. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4926. UnlockWindow();
  4927. try
  4928. {
  4929. ExecuteFileOperation(
  4930. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4931. }
  4932. __finally
  4933. {
  4934. LockWindow();
  4935. }
  4936. AllowExec = false;
  4937. }
  4938. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4939. {
  4940. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4941. {
  4942. ExecuteFile(Side, efDefaultEditor);
  4943. AllowExec = false;
  4944. }
  4945. }
  4946. else
  4947. {
  4948. DebugFail();
  4949. }
  4950. }
  4951. // if we have not done anything special, fall back to default behavior
  4952. if (AllowExec)
  4953. {
  4954. if (Remote && !WinConfiguration->DisableOpenEdit)
  4955. {
  4956. ExecuteFile(osRemote, efShell);
  4957. AllowExec = false;
  4958. }
  4959. }
  4960. }
  4961. }
  4962. //---------------------------------------------------------------------------
  4963. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4964. {
  4965. return ((Side == osRemote) || (Side == osCurrent));
  4966. }
  4967. //---------------------------------------------------------------------------
  4968. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4969. {
  4970. DebugFail();
  4971. }
  4972. //---------------------------------------------------------------------------
  4973. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4974. {
  4975. DebugFail();
  4976. }
  4977. //---------------------------------------------------------------------------
  4978. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4979. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4980. {
  4981. TSynchronizeParamType Params;
  4982. Params.LocalDirectory = LocalDirectory;
  4983. Params.RemoteDirectory = RemoteDirectory;
  4984. int UnusedParams =
  4985. (GUIConfiguration->SynchronizeParams &
  4986. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4987. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4988. Params.Options = GUIConfiguration->SynchronizeOptions;
  4989. bool SaveSettings = false;
  4990. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4991. &DoSynchronizeTooManyDirectories);
  4992. DebugAssert(FSynchronizeController == NULL);
  4993. FSynchronizeController = &Controller;
  4994. bool Result;
  4995. try
  4996. {
  4997. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4998. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4999. int Options =
  5000. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5001. DebugAssert(FOnFeedSynchronizeError == NULL);
  5002. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5003. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5004. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5005. if (Result)
  5006. {
  5007. if (SaveSettings)
  5008. {
  5009. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5010. GUIConfiguration->SynchronizeOptions = Params.Options;
  5011. }
  5012. else
  5013. {
  5014. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5015. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5016. FLAGSET(Params.Options, soSynchronize))
  5017. {
  5018. GUIConfiguration->SynchronizeOptions =
  5019. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5020. soSynchronize;
  5021. }
  5022. }
  5023. LocalDirectory = Params.LocalDirectory;
  5024. RemoteDirectory = Params.RemoteDirectory;
  5025. }
  5026. }
  5027. __finally
  5028. {
  5029. FSynchronizeController = NULL;
  5030. DebugAssert(FOnFeedSynchronizeError == NULL);
  5031. FOnFeedSynchronizeError = NULL;
  5032. }
  5033. return Result;
  5034. }
  5035. //---------------------------------------------------------------------------
  5036. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5037. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5038. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5039. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5040. TSynchronizeOptions * Options, bool Full)
  5041. {
  5042. // Keep-up-to-date mode
  5043. if (Terminal->Status == ssOpened)
  5044. {
  5045. try
  5046. {
  5047. int PParams = Params.Params;
  5048. if (!Full)
  5049. {
  5050. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5051. if (FLAGSET(Params.Options, soRecurse))
  5052. {
  5053. PParams |= TTerminal::spSubDirs;
  5054. }
  5055. }
  5056. else
  5057. {
  5058. // if keepuptodate is non-recursive,
  5059. // full sync before has to be non-recursive as well
  5060. if (FLAGCLEAR(Params.Options, soRecurse))
  5061. {
  5062. PParams |= TTerminal::spNoRecurse;
  5063. }
  5064. }
  5065. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5066. PParams, Checklist, Options);
  5067. }
  5068. catch (Exception & E)
  5069. {
  5070. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5071. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5072. {
  5073. // noop, already logged in MoreMessageDialog
  5074. }
  5075. else
  5076. {
  5077. ShowExtendedExceptionEx(Terminal, &E);
  5078. throw;
  5079. }
  5080. }
  5081. }
  5082. }
  5083. //---------------------------------------------------------------------------
  5084. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5085. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5086. const UnicodeString ErrorStr)
  5087. {
  5088. if (!Directory.IsEmpty())
  5089. {
  5090. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5091. }
  5092. else
  5093. {
  5094. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5095. }
  5096. }
  5097. //---------------------------------------------------------------------------
  5098. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5099. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5100. {
  5101. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5102. {
  5103. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5104. }
  5105. else
  5106. {
  5107. TMessageParams Params(mpNeverAskAgainCheck);
  5108. unsigned int Result = MessageDialog(
  5109. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5110. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5111. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5112. {
  5113. MaxDirectories *= 2;
  5114. if (Result == qaNeverAskAgain)
  5115. {
  5116. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5117. }
  5118. }
  5119. else
  5120. {
  5121. Abort();
  5122. }
  5123. }
  5124. }
  5125. //---------------------------------------------------------------------------
  5126. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5127. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5128. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5129. TSynchronizeOptions * Options)
  5130. {
  5131. // Keep-up-to-date mode
  5132. DebugAssert(!FAutoOperation);
  5133. void * BatchStorage;
  5134. BatchStart(BatchStorage);
  5135. FAutoOperation = true;
  5136. bool AnyOperation = false;
  5137. TDateTime StartTime = Now();
  5138. TSynchronizeChecklist * AChecklist = NULL;
  5139. try
  5140. {
  5141. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5142. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5143. {
  5144. FSynchronizeProgressForm->Start();
  5145. }
  5146. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5147. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5148. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5149. Options);
  5150. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5151. SAFE_DESTROY(FSynchronizeProgressForm);
  5152. AnyOperation = (AChecklist->CheckedCount > 0);
  5153. if (AnyOperation)
  5154. {
  5155. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5156. CreateProgressForm(&SynchronizeProgress);
  5157. try
  5158. {
  5159. Terminal->SynchronizeApply(
  5160. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5161. SynchronizeProcessedItem, NULL, NULL, NULL);
  5162. }
  5163. __finally
  5164. {
  5165. DestroyProgressForm();
  5166. }
  5167. }
  5168. }
  5169. __finally
  5170. {
  5171. if (Checklist == NULL)
  5172. {
  5173. delete AChecklist;
  5174. }
  5175. else
  5176. {
  5177. *Checklist = AChecklist;
  5178. }
  5179. FAutoOperation = false;
  5180. SAFE_DESTROY(FSynchronizeProgressForm);
  5181. BatchEnd(BatchStorage);
  5182. ReloadLocalDirectory();
  5183. if (AnyOperation)
  5184. {
  5185. OperationComplete(StartTime);
  5186. }
  5187. }
  5188. }
  5189. //---------------------------------------------------------------------------
  5190. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5191. {
  5192. // can be called from command line
  5193. return Visible &&
  5194. ((DirView(osRemote)->SelCount > 0) ||
  5195. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5196. }
  5197. //---------------------------------------------------------------------------
  5198. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5199. {
  5200. LogSynchronizeEvent(Terminal, Message);
  5201. }
  5202. //---------------------------------------------------------------------------
  5203. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5204. int Params, TSynchronizeOptions & Options)
  5205. {
  5206. DebugAssert(!IsLocalBrowserMode());
  5207. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5208. {
  5209. Options.Filter = new TStringList();
  5210. Options.Filter->CaseSensitive = false;
  5211. Options.Filter->Duplicates = Types::dupAccept;
  5212. if (DirView(osRemote)->SelCount > 0)
  5213. {
  5214. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5215. }
  5216. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5217. {
  5218. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5219. }
  5220. Options.Filter->Sort();
  5221. }
  5222. }
  5223. //---------------------------------------------------------------------------
  5224. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5225. {
  5226. TCopyParamType Defaults;
  5227. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5228. ConfigStorage->AccessMode = smRead;
  5229. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5230. {
  5231. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5232. }
  5233. ConfigStorage.reset(NULL);
  5234. std::unique_ptr<TStringList> Options(new TStringList());
  5235. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5236. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5237. UnicodeString Result;
  5238. if (Options->Count > 0)
  5239. {
  5240. Result =
  5241. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5242. }
  5243. return Result;
  5244. }
  5245. //---------------------------------------------------------------------------
  5246. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5247. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5248. {
  5249. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5250. UnicodeString AdditionalParams =
  5251. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5252. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5253. SerializeCopyParamForCommandLine(CopyParams),
  5254. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5255. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5256. ExecuteNewInstance(SessionName, AdditionalParams);
  5257. }
  5258. //---------------------------------------------------------------------------
  5259. struct TSynchronizeParams
  5260. {
  5261. UnicodeString LocalDirectory;
  5262. UnicodeString RemoteDirectory;
  5263. TSynchronizeMode Mode;
  5264. TSynchronizeChecklist * Checklist;
  5265. int Params;
  5266. TCopyParamType * CopyParam;
  5267. TDateTime CollectElapsed;
  5268. TDateTime * StartTime;
  5269. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5270. };
  5271. //---------------------------------------------------------------------------
  5272. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5273. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5274. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5275. {
  5276. DebugAssert(!FAutoOperation);
  5277. void * BatchStorage;
  5278. BatchStart(BatchStorage);
  5279. FAutoOperation = true;
  5280. TFileOperationStatistics Statistics;
  5281. TDateTime Start = Now();
  5282. try
  5283. {
  5284. Params.OnProcessedItem = OnProcessedItem;
  5285. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5286. CreateProgressForm(&SynchronizeProgress);
  5287. Terminal->SynchronizeApply(
  5288. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5289. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5290. &Statistics);
  5291. }
  5292. __finally
  5293. {
  5294. Params.OnProcessedItem = NULL;
  5295. FAutoOperation = false;
  5296. DestroyProgressForm();
  5297. BatchEnd(BatchStorage);
  5298. ReloadLocalDirectory();
  5299. }
  5300. if (WinConfiguration->SynchronizeSummary)
  5301. {
  5302. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5303. // The statistics should be 0 anyway in this case
  5304. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5305. {
  5306. Message += L"\n";
  5307. if (Statistics.FilesUploaded > 0)
  5308. {
  5309. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5310. }
  5311. if (Statistics.FilesDownloaded > 0)
  5312. {
  5313. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5314. }
  5315. if (Statistics.FilesDeletedLocal > 0)
  5316. {
  5317. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5318. }
  5319. if (Statistics.FilesDeletedRemote > 0)
  5320. {
  5321. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5322. }
  5323. }
  5324. TDateTime Elapsed = (Now() - Start);
  5325. Message +=
  5326. L"\n" +
  5327. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5328. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5329. TMessageParams Params(mpNeverAskAgainCheck);
  5330. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5331. if (Result == qaNeverAskAgain)
  5332. {
  5333. WinConfiguration->SynchronizeSummary = false;
  5334. }
  5335. }
  5336. }
  5337. //---------------------------------------------------------------------------
  5338. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5339. {
  5340. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5341. {
  5342. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5343. }
  5344. // Not set in keep-up-to-date mode - Synchronize() method
  5345. if (Token != NULL)
  5346. {
  5347. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5348. if (Params.OnProcessedItem != NULL)
  5349. {
  5350. Params.OnProcessedItem(NULL, ChecklistItem);
  5351. }
  5352. }
  5353. }
  5354. //---------------------------------------------------------------------------
  5355. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5356. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5357. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5358. {
  5359. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5360. *Params.StartTime = Now();
  5361. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5362. }
  5363. //---------------------------------------------------------------------------
  5364. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5365. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5366. {
  5367. // terminal can be already closed (e.g. dropped connection)
  5368. if (Terminal != NULL)
  5369. {
  5370. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5371. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5372. }
  5373. }
  5374. //---------------------------------------------------------------------------
  5375. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5376. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5377. {
  5378. DebugAssert(!IsLocalBrowserMode());
  5379. TAutoBatch AutoBatch(this);
  5380. TAutoFlag AutoOperationFlag(FAutoOperation);
  5381. if (Side == osRemote)
  5382. {
  5383. std::unique_ptr<TStrings> FileList(new TStringList());
  5384. FileList->AddObject(FileName, RemoteFile);
  5385. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5386. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5387. RemoteDirView->SaveSelection();
  5388. RemoteDirView->SaveSelectedNames();
  5389. try
  5390. {
  5391. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5392. }
  5393. catch(...)
  5394. {
  5395. RemoteDirView->DiscardSavedSelection();
  5396. throw;
  5397. }
  5398. RemoteDirView->RestoreSelection();
  5399. }
  5400. else if (DebugAlwaysTrue(Side == osLocal))
  5401. {
  5402. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5403. {
  5404. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5405. }
  5406. UnicodeString Directory = ExtractFileDir(FileName);
  5407. ReloadLocalDirectory(Directory);
  5408. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5409. if (!SamePaths(Directory, NewDirectory))
  5410. {
  5411. ReloadLocalDirectory(NewDirectory);
  5412. }
  5413. }
  5414. }
  5415. //---------------------------------------------------------------------------
  5416. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5417. {
  5418. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5419. if (Side == osLocal)
  5420. {
  5421. if (Action == TSynchronizeChecklist::saDownloadNew)
  5422. {
  5423. OpenFolderInExplorer(LocalPath);
  5424. }
  5425. else
  5426. {
  5427. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5428. }
  5429. }
  5430. else if (DebugAlwaysTrue(Side == osRemote))
  5431. {
  5432. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5433. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5434. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5435. if (!LocalPath.IsEmpty())
  5436. {
  5437. SessionData->LocalDirectory = LocalPath;
  5438. }
  5439. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5440. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5441. }
  5442. }
  5443. //---------------------------------------------------------------------------
  5444. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5445. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5446. const TCopyParamType * CopyParams)
  5447. {
  5448. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5449. UnicodeString AdditionalParams =
  5450. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5451. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5452. SerializeCopyParamForCommandLine(CopyParams),
  5453. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5454. LocalDirectory, RemoteDirectory, Mode, Params));
  5455. ExecuteNewInstance(SessionName, AdditionalParams);
  5456. }
  5457. //---------------------------------------------------------------------------
  5458. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5459. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5460. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5461. {
  5462. int Result;
  5463. bool SaveSettings = false;
  5464. int Options =
  5465. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5466. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5467. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5468. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5469. bool Continue =
  5470. (UseDefaults == 0) ||
  5471. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5472. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5473. if (Continue)
  5474. {
  5475. Configuration->Usage->Inc(L"Synchronizations");
  5476. UpdateCopyParamCounters(CopyParam);
  5477. TSynchronizeOptions SynchronizeOptions;
  5478. GetSynchronizeOptions(Params, SynchronizeOptions);
  5479. if (SaveSettings)
  5480. {
  5481. GUIConfiguration->SynchronizeParams = Params;
  5482. }
  5483. else
  5484. {
  5485. SaveMode = false;
  5486. }
  5487. TDateTime StartTime = Now();
  5488. TSynchronizeChecklist * Checklist = NULL;
  5489. try
  5490. {
  5491. DebugAssert(!FAutoOperation);
  5492. FAutoOperation = true;
  5493. try
  5494. {
  5495. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5496. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5497. int Files = -1;
  5498. if (DataList->Count >= 1)
  5499. {
  5500. Files = StrToIntDef(DataList->Strings[0], Files);
  5501. }
  5502. else
  5503. {
  5504. DataList->Add(UnicodeString());
  5505. }
  5506. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5507. FSynchronizeProgressForm->Start();
  5508. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5509. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5510. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5511. &SynchronizeOptions);
  5512. if (Terminal->SessionData->CacheDirectories)
  5513. {
  5514. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5515. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5516. }
  5517. }
  5518. __finally
  5519. {
  5520. FAutoOperation = false;
  5521. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5522. SAFE_DESTROY(FSynchronizeProgressForm);
  5523. }
  5524. TSynchronizeParams SynchronizeParams;
  5525. SynchronizeParams.LocalDirectory = LocalDirectory;
  5526. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5527. SynchronizeParams.Mode = Mode;
  5528. SynchronizeParams.CopyParam = &CopyParam;
  5529. SynchronizeParams.Params = Params;
  5530. SynchronizeParams.Checklist = Checklist;
  5531. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5532. SynchronizeParams.StartTime = &StartTime;
  5533. SynchronizeParams.OnProcessedItem = NULL;
  5534. Result = Checklist->Count;
  5535. if (Checklist->Count > 0)
  5536. {
  5537. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5538. {
  5539. if (!DoSynchronizeChecklistDialog(
  5540. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5541. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5542. {
  5543. Result = -1;
  5544. }
  5545. }
  5546. else
  5547. {
  5548. FullSynchronize(SynchronizeParams, NULL, NULL);
  5549. }
  5550. }
  5551. else
  5552. {
  5553. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5554. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5555. }
  5556. }
  5557. __finally
  5558. {
  5559. delete Checklist;
  5560. }
  5561. OperationComplete(StartTime);
  5562. }
  5563. else
  5564. {
  5565. Result = -1;
  5566. }
  5567. return Result;
  5568. }
  5569. //---------------------------------------------------------------------------
  5570. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5571. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5572. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5573. {
  5574. if (Collect)
  5575. {
  5576. DebugAssert(FSynchronizeProgressForm != NULL);
  5577. if (!FSynchronizeProgressForm->Started)
  5578. {
  5579. FSynchronizeProgressForm->Start();
  5580. }
  5581. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5582. SetTaskbarListProgressValue(CompareProgress);
  5583. }
  5584. else
  5585. {
  5586. DebugAssert(FSynchronizeProgressForm == NULL);
  5587. DebugAssert(FProgressForm != NULL);
  5588. }
  5589. }
  5590. //---------------------------------------------------------------------------
  5591. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5592. {
  5593. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5594. TRemoteFile * File = NULL;
  5595. Terminal->ReadFile(FullFileName, File);
  5596. if (File != NULL)
  5597. {
  5598. std::unique_ptr<TRemoteFile> FileOwner(File);
  5599. TAutoFlag Flag(FStandaloneEditing);
  5600. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5601. Application->ShowMainForm = false;
  5602. Application->Run();
  5603. }
  5604. }
  5605. //---------------------------------------------------------------------------
  5606. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5607. {
  5608. DebugFail();
  5609. }
  5610. //---------------------------------------------------------------------------
  5611. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5612. {
  5613. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5614. SessionData->Assign(Terminal->SessionData);
  5615. UpdateSessionData(SessionData.get());
  5616. Terminal->UpdateSessionCredentials(SessionData.get());
  5617. if (!Terminal->SessionData->HasSessionName())
  5618. {
  5619. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5620. // once IsWorkspace is cleared
  5621. SessionData->Name = UnicodeString();
  5622. SessionData->IsWorkspace = false;
  5623. }
  5624. return SessionData.release();
  5625. }
  5626. //---------------------------------------------------------------------------
  5627. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5628. {
  5629. TSessionData * SessionData = CloneCurrentSessionData();
  5630. try
  5631. {
  5632. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5633. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5634. }
  5635. __finally
  5636. {
  5637. delete SessionData;
  5638. }
  5639. }
  5640. //---------------------------------------------------------------------------
  5641. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5642. {
  5643. TTerminalManager * Manager = TTerminalManager::Instance();
  5644. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5645. if (DebugAlwaysTrue(Terminal != NULL))
  5646. {
  5647. // Update (Managed)Terminal->StateData
  5648. UpdateTerminal(Terminal);
  5649. }
  5650. Manager->SaveWorkspace(DataList.get());
  5651. return DataList.release();
  5652. }
  5653. //---------------------------------------------------------------------------
  5654. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5655. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5656. {
  5657. WinConfiguration->LastWorkspace = Name;
  5658. if (!SavePasswords)
  5659. {
  5660. for (int Index = 0; Index < DataList->Count; Index++)
  5661. {
  5662. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5663. if (SessionData->Link.IsEmpty())
  5664. {
  5665. SessionData->ClearSessionPasswords();
  5666. }
  5667. }
  5668. }
  5669. StoredSessions->NewWorkspace(Name, DataList);
  5670. // modified only
  5671. StoredSessions->Save(false, Explicit);
  5672. }
  5673. //---------------------------------------------------------------------------
  5674. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5675. {
  5676. return
  5677. DefaultStr(WinConfiguration->LastWorkspace,
  5678. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5679. }
  5680. //---------------------------------------------------------------------------
  5681. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5682. {
  5683. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5684. bool AnyNonStoredSessionWithPassword = false;
  5685. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5686. bool AllNonStoredSessionsAnonymous = true;
  5687. TTerminalManager * Manager = TTerminalManager::Instance();
  5688. for (int Index = 0; Index < DataList->Count; Index++)
  5689. {
  5690. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5691. if (SessionData->Link.IsEmpty())
  5692. {
  5693. if (SessionData->HasAnySessionPassword())
  5694. {
  5695. AnyNonStoredSessionWithPassword = true;
  5696. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5697. {
  5698. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5699. }
  5700. }
  5701. if (!SameText(SessionData->UserName, AnonymousUserName))
  5702. {
  5703. AllNonStoredSessionsAnonymous = false;
  5704. }
  5705. }
  5706. }
  5707. bool SavePasswords;
  5708. bool * PSavePasswords;
  5709. bool NotRecommendedSavingPasswords =
  5710. !CustomWinConfiguration->UseMasterPassword &&
  5711. !AllNonStoredSessionsAnonymous;
  5712. if (Configuration->DisablePasswordStoring ||
  5713. !AnyNonStoredSessionWithPassword)
  5714. {
  5715. PSavePasswords = NULL;
  5716. SavePasswords = false;
  5717. }
  5718. else
  5719. {
  5720. PSavePasswords = &SavePasswords;
  5721. SavePasswords =
  5722. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5723. !NotRecommendedSavingPasswords;
  5724. }
  5725. UnicodeString Name = WorkspaceName();
  5726. bool CreateShortcut = false;
  5727. bool Result =
  5728. DoSaveWorkspaceDialog(
  5729. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5730. EnableAutoSave);
  5731. if (Result)
  5732. {
  5733. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5734. if (CreateShortcut)
  5735. {
  5736. TOperationVisualizer Visualizer;
  5737. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5738. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5739. }
  5740. if (EnableAutoSave)
  5741. {
  5742. WinConfiguration->AutoSaveWorkspace = true;
  5743. WinConfiguration->AutoWorkspace = Name;
  5744. if (PSavePasswords != NULL)
  5745. {
  5746. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5747. }
  5748. }
  5749. }
  5750. return Result;
  5751. }
  5752. //---------------------------------------------------------------------------
  5753. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5754. {
  5755. DebugAssert(!IsLocalBrowserMode());
  5756. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5757. if (WinConfiguration->PreservePanelState)
  5758. {
  5759. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5760. }
  5761. UpdateSessionData(Terminal->StateData);
  5762. }
  5763. //---------------------------------------------------------------------------
  5764. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5765. {
  5766. // Keep in sync with TSessionData::CopyStateData
  5767. DebugAssert(!IsLocalBrowserMode());
  5768. DebugAssert(Data != NULL);
  5769. // This is inconsistent with how color (for example) is handled.
  5770. Data->Name = Terminal->SessionData->Name;
  5771. // cannot use RemoteDirView->Path, because it is empty if connection
  5772. // was already closed
  5773. // also only peek, we may not be connected at all atm
  5774. // so make sure we do not try retrieving current directory from the server
  5775. // (particularly with FTP)
  5776. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5777. if (!ACurrentDirectory.IsEmpty())
  5778. {
  5779. Data->RemoteDirectory = ACurrentDirectory;
  5780. }
  5781. Data->Color = SessionColor;
  5782. }
  5783. //---------------------------------------------------------------------------
  5784. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5785. {
  5786. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5787. DebugAssert(Toolbar != NULL);
  5788. for (int i = 0; i < Toolbar->Items->Count; i++)
  5789. {
  5790. TTBXCustomDropDownItem * DropDownItem;
  5791. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5792. if (DropDownItem != NULL)
  5793. {
  5794. ToolbarItemResize(DropDownItem,
  5795. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5796. Toolbar->NonClientWidth);
  5797. break;
  5798. }
  5799. }
  5800. }
  5801. //---------------------------------------------------------------------------
  5802. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5803. {
  5804. Item->EditWidth = Width;
  5805. }
  5806. //---------------------------------------------------------------------------
  5807. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5808. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5809. {
  5810. for (int i = 0; i < Toolbar->Items->Count; i++)
  5811. {
  5812. TTBXCustomDropDownItem * DropDownItem;
  5813. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5814. if (DropDownItem != NULL)
  5815. {
  5816. ASize.x -= DropDownItem->EditWidth;
  5817. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5818. }
  5819. }
  5820. }
  5821. //---------------------------------------------------------------------------
  5822. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5823. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5824. {
  5825. if (WinConfiguration->DDWarnLackOfTempSpace)
  5826. {
  5827. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5828. if (!ADrive.IsEmpty())
  5829. {
  5830. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5831. DebugAssert(RequiredSpace >= 0);
  5832. __int64 RequiredWithReserve;
  5833. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5834. if (FreeSpace < RequiredWithReserve)
  5835. {
  5836. unsigned int Result;
  5837. TMessageParams Params(mpNeverAskAgainCheck);
  5838. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5839. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5840. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5841. if (Result == qaNeverAskAgain)
  5842. {
  5843. WinConfiguration->DDWarnLackOfTempSpace = false;
  5844. }
  5845. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5846. }
  5847. }
  5848. }
  5849. }
  5850. //---------------------------------------------------------------------------
  5851. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5852. {
  5853. DoOpenDirectoryDialog(odAddBookmark, Side);
  5854. }
  5855. //---------------------------------------------------------------------------
  5856. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5857. {
  5858. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5859. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5860. try
  5861. {
  5862. TCustomDirView * DView = DirView(Side);
  5863. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5864. {
  5865. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5866. }
  5867. }
  5868. catch (...)
  5869. {
  5870. delete VisitedDirectories;
  5871. throw;
  5872. }
  5873. return VisitedDirectories;
  5874. }
  5875. //---------------------------------------------------------------------------
  5876. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5877. TOpenDirectoryMode Mode, TOperationSide Side)
  5878. {
  5879. bool Continue = true;
  5880. if (Mode == odAddBookmark)
  5881. {
  5882. TMessageParams Params(mpNeverAskAgainCheck);
  5883. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5884. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5885. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5886. unsigned int Answer =
  5887. MessageDialog(Message,
  5888. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5889. if (Answer == qaNeverAskAgain)
  5890. {
  5891. Continue = true;
  5892. WinConfiguration->UseSharedBookmarks = true;
  5893. }
  5894. else if (Answer == qaOK)
  5895. {
  5896. Continue = true;
  5897. WinConfiguration->UseSharedBookmarks = false;
  5898. }
  5899. else
  5900. {
  5901. Continue = false;
  5902. }
  5903. }
  5904. if (Continue)
  5905. {
  5906. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5907. try
  5908. {
  5909. UnicodeString Name = DirView(Side)->PathName;
  5910. bool Repeat;
  5911. do
  5912. {
  5913. Repeat = false;
  5914. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5915. // do not allow switching to location profiles,
  5916. // if we are not connected
  5917. HasDirView[osLocal] && (Terminal != NULL)))
  5918. {
  5919. TWindowLock Lock(this);
  5920. if (!TryOpenDirectory(Side, Name))
  5921. {
  5922. Repeat = true;
  5923. Mode = odBrowse;
  5924. }
  5925. }
  5926. }
  5927. while (Repeat);
  5928. }
  5929. __finally
  5930. {
  5931. delete VisitedDirectories;
  5932. }
  5933. }
  5934. }
  5935. //---------------------------------------------------------------------------
  5936. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5937. {
  5938. DebugAssert(!FTerminal->CommandSessionOpened);
  5939. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5940. }
  5941. //---------------------------------------------------------------------------
  5942. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5943. {
  5944. bool Result = FTerminal->IsCapable[Capability] ||
  5945. FTerminal->CommandSessionOpened;
  5946. if (!Result)
  5947. {
  5948. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5949. if (!GUIConfiguration->ConfirmCommandSession)
  5950. {
  5951. Result = true;
  5952. }
  5953. else
  5954. {
  5955. TMessageParams Params(mpNeverAskAgainCheck);
  5956. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5957. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5958. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5959. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5960. if (Answer == qaNeverAskAgain)
  5961. {
  5962. GUIConfiguration->ConfirmCommandSession = false;
  5963. Result = true;
  5964. }
  5965. else if (Answer == qaOK)
  5966. {
  5967. Result = true;
  5968. }
  5969. }
  5970. if (Result)
  5971. {
  5972. Result = CommandSessionFallback();
  5973. }
  5974. }
  5975. return Result;
  5976. }
  5977. //---------------------------------------------------------------------------
  5978. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5979. {
  5980. if (EnsureCommandSessionFallback(fcAnyCommand))
  5981. {
  5982. DoConsoleDialog(Terminal, Command);
  5983. }
  5984. }
  5985. //---------------------------------------------------------------------------
  5986. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5987. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5988. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5989. {
  5990. if (!IsSideLocalBrowser(osRemote) &&
  5991. IsFileControl(DropSourceControl, osRemote) &&
  5992. (FDDExtMapFile != NULL))
  5993. {
  5994. Accept = true;
  5995. }
  5996. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5997. DebugAssert(FDDTargetControl != NULL);
  5998. }
  5999. //---------------------------------------------------------------------------
  6000. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6001. _di_IDataObject DataObj, int KeyState,
  6002. const TPoint & Point, int & Effect, bool & Accept)
  6003. {
  6004. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6005. }
  6006. //---------------------------------------------------------------------------
  6007. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6008. _di_IDataObject DataObj, int KeyState,
  6009. const TPoint & Point, int & Effect, bool & Accept)
  6010. {
  6011. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6012. }
  6013. //---------------------------------------------------------------------------
  6014. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6015. TObject * Sender)
  6016. {
  6017. DebugUsedParam(Sender);
  6018. DebugAssert(FDDTargetControl == Sender);
  6019. FDDTargetControl = NULL;
  6020. }
  6021. //---------------------------------------------------------------------------
  6022. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6023. {
  6024. FileControlDDDragLeave(SessionsPageControl);
  6025. }
  6026. //---------------------------------------------------------------------------
  6027. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6028. {
  6029. FileControlDDDragLeave(QueueView3);
  6030. }
  6031. //---------------------------------------------------------------------------
  6032. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6033. {
  6034. DebugAssert(!IsSideLocalBrowser(Side));
  6035. DebugUsedParam(Side);
  6036. bool Edit = false;
  6037. TRemoteFile * File = NULL;
  6038. UnicodeString FileName;
  6039. UnicodeString PointTo;
  6040. bool SymbolicLink = true;
  6041. if (RemoteDirView->ItemFocused)
  6042. {
  6043. DebugAssert(RemoteDirView->ItemFocused->Data);
  6044. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6045. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6046. if (Edit)
  6047. {
  6048. FileName = File->FileName;
  6049. PointTo = File->LinkTo;
  6050. }
  6051. else
  6052. {
  6053. PointTo = File->FileName;
  6054. }
  6055. }
  6056. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6057. Terminal->IsCapable[fcHardLink]))
  6058. {
  6059. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6060. if (Edit)
  6061. {
  6062. DebugAssert(File->FileName == FileName);
  6063. int Params = dfNoRecursive;
  6064. Terminal->ExceptionOnFail = true;
  6065. try
  6066. {
  6067. Terminal->DeleteFile(L"", File, &Params);
  6068. }
  6069. __finally
  6070. {
  6071. Terminal->ExceptionOnFail = false;
  6072. }
  6073. }
  6074. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6075. }
  6076. }
  6077. //---------------------------------------------------------------------------
  6078. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6079. {
  6080. return
  6081. (IsSideLocalBrowser(Side) ||
  6082. ((Terminal != NULL) &&
  6083. Terminal->Active &&
  6084. Terminal->ResolvingSymlinks &&
  6085. Terminal->IsCapable[fcSymbolicLink]));
  6086. }
  6087. //---------------------------------------------------------------------------
  6088. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6089. {
  6090. return
  6091. !IsSideLocalBrowser(FCurrentSide) &&
  6092. (RemoteDirView->ItemFocused != NULL) &&
  6093. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6094. Terminal->SessionData->ResolveSymlinks;
  6095. }
  6096. //---------------------------------------------------------------------------
  6097. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6098. {
  6099. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6100. FForceExecution = true;
  6101. try
  6102. {
  6103. DirView(osCurrent)->ExecuteCurrentFile();
  6104. }
  6105. __finally
  6106. {
  6107. FForceExecution = false;
  6108. }
  6109. }
  6110. //---------------------------------------------------------------------------
  6111. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6112. {
  6113. TEditorData ExternalEditor;
  6114. ExternalEditor.Editor = edExternal;
  6115. bool Remember = false;
  6116. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6117. {
  6118. if (Remember)
  6119. {
  6120. TEditorList * EditorList = new TEditorList;
  6121. try
  6122. {
  6123. *EditorList = *WinConfiguration->EditorList;
  6124. bool Found = false;
  6125. int i = 0;
  6126. while (!Found && (i < EditorList->Count))
  6127. {
  6128. const TEditorPreferences * Editor = EditorList->Editors[i];
  6129. if ((Editor->Data->Editor == edExternal) &&
  6130. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6131. {
  6132. Found = true;
  6133. }
  6134. i++;
  6135. }
  6136. if (!Found)
  6137. {
  6138. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6139. WinConfiguration->EditorList = EditorList;
  6140. }
  6141. }
  6142. __finally
  6143. {
  6144. delete EditorList;
  6145. }
  6146. }
  6147. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6148. }
  6149. }
  6150. //---------------------------------------------------------------------------
  6151. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6152. {
  6153. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6154. if (FFileFindTerminal == ATerminal)
  6155. {
  6156. FFileFindTerminal = NULL;
  6157. HideFileFindDialog();
  6158. }
  6159. if (FClipboardTerminal == ATerminal)
  6160. {
  6161. ClipboardClear(); // implies ClipboardStop
  6162. }
  6163. }
  6164. //---------------------------------------------------------------------------
  6165. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6166. {
  6167. DetachTerminal(Sender);
  6168. }
  6169. //---------------------------------------------------------------------------
  6170. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6171. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6172. {
  6173. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6174. DebugAssert(Terminal != NULL);
  6175. if (Data->Terminal == Terminal)
  6176. {
  6177. Data->Terminal = NULL;
  6178. }
  6179. }
  6180. //---------------------------------------------------------------------------
  6181. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6182. {
  6183. UpdateControls();
  6184. SessionColor = TColor(0);
  6185. UpdateRemotePathComboBox(false);
  6186. NeedSession(false);
  6187. }
  6188. //---------------------------------------------------------------------------
  6189. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6190. {
  6191. try
  6192. {
  6193. // Cache, as the login dialog can change its value
  6194. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6195. try
  6196. {
  6197. if (ShowLogin)
  6198. {
  6199. bool ReloadSessions = !Startup;
  6200. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6201. }
  6202. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6203. // This detects if workspace was saved the last time the main widow was closed
  6204. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6205. {
  6206. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6207. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6208. }
  6209. }
  6210. __finally
  6211. {
  6212. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6213. // (so there was no chance for the user to open any session yet)
  6214. if ((ShowLogin || !Startup) &&
  6215. !WinConfiguration->KeepOpenWhenNoSession &&
  6216. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6217. {
  6218. TerminateApplication();
  6219. }
  6220. }
  6221. }
  6222. catch (EAbort &)
  6223. {
  6224. // swallow
  6225. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6226. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6227. }
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6231. {
  6232. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6233. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6234. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6235. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6236. try
  6237. {
  6238. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6239. // Clear the design time unthemed tab
  6240. ((SessionsPageControl->PageCount > 0) &&
  6241. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6242. {
  6243. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6244. }
  6245. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6246. {
  6247. TThemeTabSheet * TabSheet;
  6248. if (Index >= SessionsPageControl->PageCount)
  6249. {
  6250. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6251. TabSheet->PageControl = SessionsPageControl;
  6252. }
  6253. else
  6254. {
  6255. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6256. }
  6257. bool IsSessionTab = (Index < TerminalList->Count);
  6258. if (IsSessionTab)
  6259. {
  6260. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6261. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6262. UpdateSessionTab(TabSheet);
  6263. }
  6264. else
  6265. {
  6266. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6267. TabSheet->Tag = 0; // not really needed
  6268. TabSheet->Shadowed = false;
  6269. // 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)
  6270. UpdateNewSessionTab();
  6271. }
  6272. TabSheet->ShowCloseButton = IsSessionTab;
  6273. }
  6274. }
  6275. __finally
  6276. {
  6277. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6278. }
  6279. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6280. }
  6281. //---------------------------------------------------------------------------
  6282. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6283. {
  6284. DoTerminalListChanged();
  6285. }
  6286. //---------------------------------------------------------------------------
  6287. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6288. {
  6289. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6290. DebugAssert(TabSheet->ImageIndex == 0);
  6291. TabSheet->Caption =
  6292. WinConfiguration->SelectiveToolbarText ?
  6293. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6294. UnicodeString();
  6295. }
  6296. //---------------------------------------------------------------------------
  6297. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6298. {
  6299. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6300. }
  6301. //---------------------------------------------------------------------------
  6302. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6303. {
  6304. if (DebugAlwaysTrue(TabSheet != NULL))
  6305. {
  6306. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6307. if (DebugAlwaysTrue(ATerminal != NULL))
  6308. {
  6309. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6310. TabSheet->ImageIndex = AddSessionColor(Color);
  6311. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6312. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6313. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6314. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6315. {
  6316. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6317. }
  6318. }
  6319. }
  6320. }
  6321. //---------------------------------------------------------------------------
  6322. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6323. {
  6324. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6325. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6326. bool Result = (Terminal != NULL);
  6327. if (Result)
  6328. {
  6329. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6330. }
  6331. else
  6332. {
  6333. try
  6334. {
  6335. NewSession(false);
  6336. }
  6337. __finally
  6338. {
  6339. DoTerminalListChanged();
  6340. }
  6341. FSessionsPageControlNewSessionTime = Now();
  6342. }
  6343. return Result;
  6344. }
  6345. //---------------------------------------------------------------------------
  6346. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6347. {
  6348. SessionTabSwitched();
  6349. }
  6350. //---------------------------------------------------------------------------
  6351. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6352. {
  6353. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6354. DebugAssert(TransferList != NULL);
  6355. UnicodeString Name;
  6356. if (TransferList->ItemIndex <= 0)
  6357. {
  6358. Name = L"";
  6359. }
  6360. else
  6361. {
  6362. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6363. }
  6364. if (FCopyParamAutoSelected.IsEmpty())
  6365. {
  6366. // if previous preset was not autoselected, make new preset the "default"
  6367. FCopyParamDefault = Name;
  6368. }
  6369. GUIConfiguration->CopyParamCurrent = Name;
  6370. }
  6371. //---------------------------------------------------------------------------
  6372. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6373. {
  6374. // sanity check
  6375. bool ExistingPreset =
  6376. (FTransferListHoverIndex >= 0) &&
  6377. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6378. DebugAssert(ExistingPreset);
  6379. if (ExistingPreset)
  6380. {
  6381. HDC DC = GetDC(0);
  6382. TCanvas * Canvas = new TCanvas();
  6383. try
  6384. {
  6385. Canvas->Handle = DC;
  6386. Canvas->Font = GetToolbarFont(this);
  6387. UnicodeString Name;
  6388. if (FTransferListHoverIndex == 0)
  6389. {
  6390. Name = L"";
  6391. }
  6392. else
  6393. {
  6394. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6395. }
  6396. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6397. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6398. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6399. static_cast<TObject*>(GetComponent(fcTransferList)));
  6400. UnicodeString InfoStr =
  6401. GUIConfiguration->CopyParamPreset[Name].
  6402. GetInfoStr(L"; ",
  6403. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6404. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6405. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6406. {
  6407. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6408. {
  6409. InfoStr.SetLength(InfoStr.Length() - 1);
  6410. }
  6411. InfoStr += Ellipsis;
  6412. }
  6413. // UpdateCaption does not cause invalidation of whole submenu, while
  6414. // setting Caption property does.
  6415. // also it probably does not resize the label, even if necessary
  6416. // (we do not want that anyway)
  6417. TransferLabel->UpdateCaption(InfoStr);
  6418. }
  6419. __finally
  6420. {
  6421. Canvas->Handle = NULL;
  6422. ReleaseDC(0, DC);
  6423. delete Canvas;
  6424. }
  6425. }
  6426. }
  6427. //---------------------------------------------------------------------------
  6428. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6429. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6430. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6431. {
  6432. if (FTransferListHoverIndex != AHoverIndex)
  6433. {
  6434. FTransferListHoverIndex = AHoverIndex;
  6435. UpdateTransferLabel();
  6436. }
  6437. }
  6438. //---------------------------------------------------------------------------
  6439. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6440. {
  6441. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6442. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6443. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6444. {
  6445. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6446. {
  6447. if (!NonVisualDataModule->Busy)
  6448. {
  6449. OpenDirectory(GetSide(osCurrent));
  6450. }
  6451. Message.Result = 1;
  6452. }
  6453. else
  6454. {
  6455. TForm::Dispatch(&Message);
  6456. }
  6457. }
  6458. else
  6459. {
  6460. TForm::Dispatch(&Message);
  6461. }
  6462. }
  6463. //---------------------------------------------------------------------------
  6464. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6465. {
  6466. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6467. if ((FIgnoreNextDialogChar != 0) &&
  6468. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6469. {
  6470. Message.Result = 1;
  6471. }
  6472. else
  6473. {
  6474. TForm::Dispatch(&Message);
  6475. }
  6476. FIgnoreNextDialogChar = 0;
  6477. }
  6478. //---------------------------------------------------------------------------
  6479. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6480. {
  6481. // The four low-order bits are used internally by Windows
  6482. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6483. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6484. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6485. // 61730 - restore thru double click - undocumented
  6486. // 61490 - maximize thru double click - undocumented
  6487. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6488. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6489. {
  6490. SysResizing(Cmd);
  6491. }
  6492. TForm::Dispatch(&Message);
  6493. }
  6494. //---------------------------------------------------------------------------
  6495. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6496. {
  6497. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6498. // Also there no point returning TRUE as we are not able to
  6499. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6500. // Hence the process termination might be safer :)
  6501. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6502. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6503. {
  6504. Message.Result = FALSE;
  6505. }
  6506. else
  6507. {
  6508. Message.Result = TRUE;
  6509. }
  6510. // Do not call default handling as that triggers OnCloseQuery,
  6511. // where our implementation will popup confirmation dialogs, what we do not want,
  6512. // as per Vista guidelines:
  6513. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6514. }
  6515. //---------------------------------------------------------------------------
  6516. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6517. {
  6518. if (Message.EndSession && IsApplicationMinimized())
  6519. {
  6520. // WORKAROUND
  6521. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6522. // when it receives WM_ENDSESSION,
  6523. // but that sometimes (particularly when application is minimized) cause crashes.
  6524. // Crash popups message that blocks log off.
  6525. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6526. // so we call ExitProcess() immediately, not even trying to cleanup.
  6527. // It still causes beep, so there's likely some popup, but it does not block
  6528. // log off.
  6529. ExitProcess(0);
  6530. }
  6531. TForm::Dispatch(&Message);
  6532. }
  6533. #ifdef _DEBUG
  6534. //---------------------------------------------------------------------------
  6535. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6536. {
  6537. TForm::Dispatch(&Message);
  6538. }
  6539. #endif
  6540. //---------------------------------------------------------------------------
  6541. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6542. {
  6543. }
  6544. //---------------------------------------------------------------------------
  6545. void __fastcall TCustomScpExplorerForm::DoShow()
  6546. {
  6547. // only now are the controls resized finally, so the size constraints
  6548. // will not conflict with possibly very small window size
  6549. RestoreFormParams();
  6550. // This indicates that the form was rescaled after parameters were loaded and
  6551. // as most probably the parameters were actually saved with the current form scaling
  6552. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6553. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6554. // and no rounding problems will occur.
  6555. // See also RestoreForm.
  6556. // (we should be safe to call RestoreParams unconditionally)
  6557. if (PixelsPerInch != Screen->PixelsPerInch)
  6558. {
  6559. RestoreParams();
  6560. }
  6561. FixControlsPlacement();
  6562. if (Position == poDefaultPosOnly)
  6563. {
  6564. CutFormToDesktop(this);
  6565. }
  6566. TForm::DoShow();
  6567. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6568. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6569. if (Terminal == NULL)
  6570. {
  6571. StartingDisconnected();
  6572. }
  6573. UpdatePixelsPerInchMainWindowCounter();
  6574. FShowing = true;
  6575. }
  6576. //---------------------------------------------------------------------------
  6577. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6578. {
  6579. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6580. }
  6581. //---------------------------------------------------------------------------
  6582. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6583. {
  6584. DoTerminalListChanged();
  6585. }
  6586. //---------------------------------------------------------------------------
  6587. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6588. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6589. TNotifyEvent OnBalloonClick, TObject * UserData)
  6590. {
  6591. bool Do;
  6592. UnicodeString Message;
  6593. if (E == NULL)
  6594. {
  6595. Message = Str;
  6596. Do = true;
  6597. }
  6598. else
  6599. {
  6600. Do = ExceptionMessage(E, Message);
  6601. }
  6602. if (Do && WinConfiguration->BalloonNotifications)
  6603. {
  6604. UnicodeString Title;
  6605. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6606. {
  6607. Message = TrimLeft(Message);
  6608. }
  6609. else
  6610. {
  6611. Message = UnformatMessage(Message);
  6612. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6613. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6614. Title = LoadResourceString(Captions[Type]);
  6615. if (Terminal != NULL)
  6616. {
  6617. Title = FORMAT(L"%s - %s",
  6618. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6619. }
  6620. }
  6621. if (Seconds == 0)
  6622. {
  6623. Seconds = WinConfiguration->NotificationsTimeout;
  6624. }
  6625. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6626. }
  6627. }
  6628. //---------------------------------------------------------------------------
  6629. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6630. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6631. UnicodeString HelpKeyword, const TMessageParams * Params,
  6632. TTerminal * Terminal)
  6633. {
  6634. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6635. (FOnFeedSynchronizeError != NULL)) &&
  6636. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6637. {
  6638. if (FOnFeedSynchronizeError != NULL)
  6639. {
  6640. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6641. }
  6642. else
  6643. {
  6644. DebugAssert(FErrorList != NULL);
  6645. TStringList * MoreMessagesCopy = NULL;
  6646. if (MoreMessages)
  6647. {
  6648. MoreMessagesCopy = new TStringList();
  6649. MoreMessagesCopy->Assign(MoreMessages);
  6650. }
  6651. FErrorList->AddObject(Message, MoreMessagesCopy);
  6652. }
  6653. PopupTrayBalloon(Terminal, Message, Type);
  6654. return ContinueAnswer(Answers);
  6655. }
  6656. else
  6657. {
  6658. bool UseBalloon = FTrayIcon->Visible;
  6659. if (UseBalloon)
  6660. {
  6661. PopupTrayBalloon(Terminal, Message, Type);
  6662. }
  6663. unsigned int Result;
  6664. try
  6665. {
  6666. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6667. }
  6668. __finally
  6669. {
  6670. // cancel only balloon we popped up, otherwise we may cancel notification
  6671. // balloon that was there before the message dialog
  6672. // (such as "dd confirmation opt in balloon)
  6673. if (UseBalloon)
  6674. {
  6675. FTrayIcon->CancelBalloon();
  6676. }
  6677. }
  6678. return Result;
  6679. }
  6680. }
  6681. //---------------------------------------------------------------------------
  6682. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6683. TTerminal * Terminal, Exception * E)
  6684. {
  6685. if (FTrayIcon->Visible)
  6686. {
  6687. PopupTrayBalloon(Terminal, L"", qtError, E);
  6688. }
  6689. // particularly prevent opening new session from jump list,
  6690. // while exception is shown
  6691. NonVisualDataModule->StartBusy();
  6692. try
  6693. {
  6694. ShowExtendedExceptionEx(Terminal, E);
  6695. }
  6696. __finally
  6697. {
  6698. NonVisualDataModule->EndBusy();
  6699. FTrayIcon->CancelBalloon();
  6700. }
  6701. }
  6702. //---------------------------------------------------------------------------
  6703. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6704. {
  6705. if (Terminal->Active)
  6706. {
  6707. InitStatusBar();
  6708. }
  6709. // cannot rely on active page being page for active terminal,
  6710. // as it can happen that active page is the "new session" page
  6711. // (e.g. when reconnecting active terminal, while login dialog
  6712. // invoked from "new session" page is modal)
  6713. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6714. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6715. }
  6716. //---------------------------------------------------------------------------
  6717. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6718. TTerminal * Terminal, Exception * E)
  6719. {
  6720. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6721. if (!Terminal->Active)
  6722. {
  6723. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6724. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6725. {
  6726. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6727. }
  6728. }
  6729. }
  6730. //---------------------------------------------------------------------------
  6731. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6732. UnicodeString Message, TQueryType Type,
  6733. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6734. {
  6735. if ((E == NULL) ||
  6736. ExceptionMessage(E, Message))
  6737. {
  6738. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6739. if (Important)
  6740. {
  6741. Seconds *= 5;
  6742. }
  6743. UnicodeString NoteMessage(UnformatMessage(Message));
  6744. if (Terminal != NULL)
  6745. {
  6746. NoteMessage = FORMAT(L"%s: %s",
  6747. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6748. }
  6749. if (WinConfiguration->BalloonNotifications)
  6750. {
  6751. AddNote(NoteMessage);
  6752. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6753. }
  6754. else
  6755. {
  6756. FlashOnBackground();
  6757. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6758. }
  6759. }
  6760. }
  6761. //---------------------------------------------------------------------------
  6762. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6763. {
  6764. RestoreApp();
  6765. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6766. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6767. !NonVisualDataModule->Busy)
  6768. {
  6769. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6770. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6771. if (!ComponentVisible[fcQueueView])
  6772. {
  6773. ToggleQueueVisibility();
  6774. GoToQueue();
  6775. }
  6776. }
  6777. }
  6778. //---------------------------------------------------------------------------
  6779. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6780. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6781. {
  6782. UnicodeString Message;
  6783. TNotifyEvent OnClick = NULL;
  6784. TObject * UserData = NULL;
  6785. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6786. switch (Event)
  6787. {
  6788. case qeEmptyButMonitored:
  6789. if ((ATerminal != Terminal) || QueueInvisible)
  6790. {
  6791. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6792. OnClick = QueueEmptyNoteClicked;
  6793. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6794. TerminalNoteData->Terminal = ATerminal;
  6795. UserData = TerminalNoteData;
  6796. }
  6797. break;
  6798. case qeEmpty:
  6799. OperationComplete(ATerminal->QueueOperationStart);
  6800. break;
  6801. case qePendingUserAction:
  6802. if ((ATerminal != Terminal) ||
  6803. (QueueInvisible && !IsQueueAutoPopup()))
  6804. {
  6805. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6806. }
  6807. break;
  6808. default:
  6809. DebugFail();
  6810. }
  6811. if (!Message.IsEmpty())
  6812. {
  6813. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6814. }
  6815. }
  6816. //---------------------------------------------------------------------------
  6817. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6818. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6819. {
  6820. if (FDDExtMapFile != NULL)
  6821. {
  6822. CloseHandle(FDDExtMapFile);
  6823. FDDExtMapFile = NULL;
  6824. }
  6825. if (WinConfiguration->DDFakeFile)
  6826. {
  6827. DDFakeFileInitDrag(FileList, Created);
  6828. }
  6829. }
  6830. //---------------------------------------------------------------------------
  6831. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6832. {
  6833. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6834. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6835. {
  6836. FFakeFileDropTarget = FileName;
  6837. }
  6838. }
  6839. //---------------------------------------------------------------------------
  6840. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6841. {
  6842. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6843. if (!ForceDirectories(ApiPath(Result)))
  6844. {
  6845. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6846. }
  6847. FileSetAttr(ApiPath(Result), faHidden);
  6848. return Result;
  6849. }
  6850. //---------------------------------------------------------------------------
  6851. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6852. bool & Created)
  6853. {
  6854. FFakeFileDropTarget = UnicodeString();
  6855. FDragFakeDirectory = CreateFakeTransferDirectory();
  6856. FileList->AddItem(NULL, FDragFakeDirectory);
  6857. Created = true;
  6858. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6859. {
  6860. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6861. }
  6862. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6863. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6864. {
  6865. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6866. TDragExtCommStruct* CommStruct;
  6867. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6868. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6869. DebugAssert(CommStruct != NULL);
  6870. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6871. CommStruct->Dragging = true;
  6872. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6873. LENOF(CommStruct->DropDest));
  6874. NULL_TERMINATE(CommStruct->DropDest);
  6875. UnmapViewOfFile(CommStruct);
  6876. }
  6877. }
  6878. //---------------------------------------------------------------------------
  6879. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6880. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6881. {
  6882. bool Result;
  6883. DebugAssert(!IsLocalBrowserMode());
  6884. if (Sender == RemoteDirView)
  6885. {
  6886. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6887. }
  6888. else
  6889. {
  6890. DebugAssert(Sender == RemoteDriveView);
  6891. TStrings * FileList = RemoteDriveView->DragFileList();
  6892. try
  6893. {
  6894. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6895. }
  6896. __finally
  6897. {
  6898. delete FileList;
  6899. }
  6900. }
  6901. if (FDDTargetControl == RemoteDriveView)
  6902. {
  6903. RemoteDriveView->UpdateDropTarget();
  6904. }
  6905. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6906. // or from tree view to dir view.
  6907. // foMove happens when file/dir is dragged from remote tree view outside of
  6908. // application via dragex
  6909. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6910. (DropSourceControl == RemoteDriveView))
  6911. {
  6912. RemoteDriveView->UpdateDropSource();
  6913. }
  6914. return Result;
  6915. }
  6916. //---------------------------------------------------------------------------
  6917. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6918. {
  6919. DebugAssert(!IsLocalBrowserMode());
  6920. // This also handles drops of remote files to queue.
  6921. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6922. SAFE_DESTROY(FDDFileList);
  6923. if (!FFakeFileDropTarget.IsEmpty())
  6924. {
  6925. RemoveDir(ApiPath(FFakeFileDropTarget));
  6926. }
  6927. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6928. {
  6929. try
  6930. {
  6931. TDragResult DDResult = (Sender == RemoteDirView) ?
  6932. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6933. // Focus is moved to the target application,
  6934. // but as we are going to present the UI, we need to steal the focus back.
  6935. // This most likely won't work though (windows does not allow application
  6936. // to steal focus most of the time)
  6937. Application->BringToFront();
  6938. // On older version of Windows we never got drMove here, see also comment below.
  6939. // On Windows 10, we get the "move".
  6940. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6941. {
  6942. UnicodeString TargetDirectory;
  6943. TFileOperation Operation;
  6944. // drInvalid may mean drMove, see comment below
  6945. switch (DDResult)
  6946. {
  6947. case drCopy:
  6948. Operation = foCopy;
  6949. break;
  6950. case drMove:
  6951. Operation = foMove;
  6952. break;
  6953. default:
  6954. DebugFail();
  6955. case drInvalid:
  6956. // prefer "copy" for safety
  6957. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6958. break;
  6959. }
  6960. TTransferOperationParam Param;
  6961. UnicodeString CounterName;
  6962. bool ForceQueue;
  6963. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6964. {
  6965. // we get drInvalid both if d&d was intercepted by ddext,
  6966. // and when users drops on no-drop location.
  6967. // we tell the difference by existence of response from ddext,
  6968. // so we ignore absence of response in this case
  6969. if (DDResult != drInvalid)
  6970. {
  6971. // here we know that the extension is installed,
  6972. // as it is checked as soon as drag&drop starts from
  6973. // RemoteFileControlDDCreateDragFileList
  6974. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6975. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6976. {
  6977. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6978. }
  6979. else
  6980. {
  6981. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6982. }
  6983. }
  6984. }
  6985. else
  6986. {
  6987. // download using fake file
  6988. Param.Temp = false;
  6989. Param.DragDrop = true;
  6990. if (ForceQueue)
  6991. {
  6992. Param.Queue = asOn;
  6993. }
  6994. if (Sender == RemoteDirView)
  6995. {
  6996. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6997. }
  6998. if (RemoteFileControlFileOperation(Sender, Operation,
  6999. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7000. {
  7001. Configuration->Usage->Inc(CounterName);
  7002. }
  7003. }
  7004. }
  7005. }
  7006. __finally
  7007. {
  7008. CloseHandle(FDDExtMapFile);
  7009. FDDExtMapFile = NULL;
  7010. delete FDragFakeMonitors;
  7011. FDragFakeMonitors = NULL;
  7012. RemoveDir(ApiPath(FDragFakeDirectory));
  7013. FDragFakeDirectory = L"";
  7014. FFakeFileDropTarget = UnicodeString();
  7015. }
  7016. }
  7017. if (FDragDropSshTerminate.get() != NULL)
  7018. {
  7019. FDragDropSshTerminate->Rethrow();
  7020. }
  7021. }
  7022. //---------------------------------------------------------------------------
  7023. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7024. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7025. {
  7026. // Remember drop effect so we know (when user drops files), if we copy or move
  7027. FLastDropEffect = dwEffect;
  7028. }
  7029. //---------------------------------------------------------------------------
  7030. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7031. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7032. {
  7033. bool Result;
  7034. if (FDDTargetControl == QueueView3)
  7035. {
  7036. Directory = DefaultDownloadTargetDirectory();
  7037. Result = true;
  7038. CounterName = L"DownloadsDragDropQueue";
  7039. ForceQueue = true;
  7040. }
  7041. else if (!FFakeFileDropTarget.IsEmpty())
  7042. {
  7043. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7044. Result = true;
  7045. ForceQueue = false;
  7046. CounterName = L"DownloadsDragDropFakeFile";
  7047. }
  7048. else
  7049. {
  7050. ForceQueue = false;
  7051. Enabled = false;
  7052. try
  7053. {
  7054. int Timer = 0;
  7055. Result = false;
  7056. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7057. {
  7058. {
  7059. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7060. TDragExtCommStruct* CommStruct;
  7061. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7062. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7063. DebugAssert(CommStruct != NULL);
  7064. Result = !CommStruct->Dragging;
  7065. if (Result)
  7066. {
  7067. Directory = ExtractFilePath(CommStruct->DropDest);
  7068. CounterName = L"DownloadsDragDropExternalExt";
  7069. }
  7070. UnmapViewOfFile(CommStruct);
  7071. }
  7072. if (!Result)
  7073. {
  7074. Sleep(50);
  7075. Timer += 50;
  7076. Application->ProcessMessages();
  7077. }
  7078. }
  7079. }
  7080. __finally
  7081. {
  7082. Enabled = true;
  7083. }
  7084. }
  7085. return Result;
  7086. }
  7087. //---------------------------------------------------------------------------
  7088. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7089. const UnicodeString TempDir, int SecDelay)
  7090. {
  7091. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7092. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7093. if (FDelayedDeletionTimer == NULL)
  7094. {
  7095. DebugAssert(HandleAllocated());
  7096. FDelayedDeletionTimer = new TTimer(this);
  7097. FDelayedDeletionTimer->Interval = 10000;
  7098. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7099. }
  7100. else
  7101. {
  7102. FDelayedDeletionTimer->Enabled = true;
  7103. }
  7104. }
  7105. //---------------------------------------------------------------------------
  7106. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7107. {
  7108. DebugAssert(FDelayedDeletionList != NULL);
  7109. TDateTime N = Now();
  7110. TDateTime Alert;
  7111. UnicodeString Directory;
  7112. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7113. {
  7114. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7115. if ((N >= Alert) || (Sender == NULL))
  7116. {
  7117. Directory = FDelayedDeletionList->Strings[Index];
  7118. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7119. {
  7120. FDelayedDeletionList->Delete(Index);
  7121. }
  7122. }
  7123. }
  7124. if (FDelayedDeletionList->Count == 0)
  7125. {
  7126. FDelayedDeletionTimer->Enabled = false;
  7127. }
  7128. }
  7129. //---------------------------------------------------------------------------
  7130. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7131. {
  7132. DebugAssert(!IsLocalBrowserMode());
  7133. if (IsFileControl(FDDTargetControl, osRemote) ||
  7134. (FDDTargetControl == SessionsPageControl))
  7135. {
  7136. TTerminal * TargetTerminal = NULL;
  7137. TFileOperation Operation = foNone;
  7138. if (FDDTargetControl == SessionsPageControl)
  7139. {
  7140. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7141. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7142. // do not allow dropping on the "+" tab
  7143. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7144. if (TargetTerminal != NULL)
  7145. {
  7146. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7147. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7148. {
  7149. Operation = foRemoteMove;
  7150. }
  7151. else
  7152. {
  7153. Operation = foRemoteCopy;
  7154. }
  7155. }
  7156. }
  7157. else
  7158. {
  7159. if (FLastDropEffect == DROPEFFECT_MOVE)
  7160. {
  7161. Operation = foRemoteMove;
  7162. }
  7163. else if (FLastDropEffect == DROPEFFECT_COPY)
  7164. {
  7165. Operation = foRemoteCopy;
  7166. }
  7167. }
  7168. if (Operation != foNone)
  7169. {
  7170. RemoteFileControlFileOperation(DropSourceControl,
  7171. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7172. }
  7173. // abort drag&drop
  7174. Abort();
  7175. }
  7176. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7177. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7178. (FDDTargetControl != QueueView3))
  7179. {
  7180. DebugAssert(!FDragTempDir.IsEmpty());
  7181. TTransferType Type;
  7182. UnicodeString TempDir = FDragTempDir;
  7183. // We clear FDragTempDir before calling
  7184. // just in case it fail (raises exception)
  7185. FDragTempDir = L"";
  7186. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7187. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7188. // empty directory parameter means temp directory -> don't display it!
  7189. UnicodeString TargetDir = L"";
  7190. int Options = 0;
  7191. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7192. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7193. {
  7194. Abort();
  7195. }
  7196. // TargetDir is set when dropped on local file control
  7197. // (this was workaround for legacy dirview event handling, now it should be
  7198. // made prettier)
  7199. if (TargetDir.IsEmpty())
  7200. {
  7201. TargetDir = TempDir;
  7202. if (ForceDirectories(ApiPath(TargetDir)))
  7203. {
  7204. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7205. FPendingTempSpaceWarn = true;
  7206. try
  7207. {
  7208. FDragDropOperation = true;
  7209. int Params = cpTemporary |
  7210. (Type == ttMove ? cpDelete : 0);
  7211. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7212. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7213. }
  7214. __finally
  7215. {
  7216. FDragDropOperation = false;
  7217. FPendingTempSpaceWarn = false;
  7218. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7219. }
  7220. }
  7221. else
  7222. {
  7223. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7224. }
  7225. }
  7226. }
  7227. }
  7228. //---------------------------------------------------------------------------
  7229. void __fastcall TCustomScpExplorerForm::DDDownload(
  7230. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7231. {
  7232. DebugAssert(!IsLocalBrowserMode());
  7233. TAutoBatch AutoBatch(this);
  7234. UpdateCopyParamCounters(*CopyParam);
  7235. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7236. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7237. {
  7238. RemoteDriveView->UpdateDropSource();
  7239. }
  7240. }
  7241. //---------------------------------------------------------------------------
  7242. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7243. {
  7244. public:
  7245. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7246. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7247. {
  7248. }
  7249. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7250. {
  7251. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7252. TDataObjectFilesEx::AllowData(FormatEtc);
  7253. }
  7254. };
  7255. //---------------------------------------------------------------------------
  7256. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7257. TObject * Sender, TDataObject *& DataObject)
  7258. {
  7259. if (FDDExtMapFile != NULL)
  7260. {
  7261. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7262. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7263. {
  7264. Abort();
  7265. }
  7266. if (FileList->Count > 0)
  7267. {
  7268. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7269. if (!FilesObject->IsValid(true, true))
  7270. {
  7271. FilesObject->_Release();
  7272. }
  7273. else
  7274. {
  7275. DataObject = FilesObject;
  7276. }
  7277. }
  7278. }
  7279. }
  7280. //---------------------------------------------------------------------------
  7281. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7282. {
  7283. DebugFail();
  7284. }
  7285. //---------------------------------------------------------------------------
  7286. void __fastcall TCustomScpExplorerForm::GoToTree()
  7287. {
  7288. ComponentVisible[fcRemoteTree] = true;
  7289. DriveView(osRemote)->SetFocus();
  7290. }
  7291. //---------------------------------------------------------------------------
  7292. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7293. TPanelExport Export)
  7294. {
  7295. TCustomDirView * DirView = this->DirView(Side);
  7296. std::unique_ptr<TStrings> ExportData(new TStringList());
  7297. switch (Export)
  7298. {
  7299. case pePath:
  7300. ExportData->Add(DirView->PathName);
  7301. break;
  7302. case peFileList:
  7303. case peFullFileList:
  7304. {
  7305. bool FullPath = (Export == peFullFileList);
  7306. DirView->CreateFileList(false, FullPath, ExportData.get());
  7307. for (int Index = 0; Index < ExportData->Count; Index++)
  7308. {
  7309. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7310. {
  7311. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7312. }
  7313. }
  7314. }
  7315. break;
  7316. default:
  7317. DebugFail();
  7318. }
  7319. return ExportData.release();
  7320. }
  7321. //---------------------------------------------------------------------------
  7322. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7323. TPanelExport Export, TPanelExportDestination Destination)
  7324. {
  7325. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7326. PanelExportStore(Side, Export, Destination, ExportData.get());
  7327. }
  7328. //---------------------------------------------------------------------------
  7329. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7330. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7331. TStrings * ExportData)
  7332. {
  7333. if (Destination == pedClipboard)
  7334. {
  7335. TInstantOperationVisualizer Visualizer;
  7336. CopyToClipboard(ExportData);
  7337. }
  7338. else
  7339. {
  7340. DebugFail();
  7341. }
  7342. }
  7343. //---------------------------------------------------------------------------
  7344. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7345. {
  7346. TCustomDirView * DirView = this->DirView(Side);
  7347. UnicodeString Mask = DirView->Mask;
  7348. if (DoFilterMaskDialog(DirView, Mask))
  7349. {
  7350. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7351. Configuration->Usage->Inc(L"Filters");
  7352. }
  7353. }
  7354. //---------------------------------------------------------------------------
  7355. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7356. {
  7357. return FQueueController->DefaultOperation();
  7358. }
  7359. //---------------------------------------------------------------------------
  7360. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7361. TQueueOperation Operation, void ** Param)
  7362. {
  7363. switch (Operation)
  7364. {
  7365. case qoPreferences:
  7366. return true;
  7367. case qoGoTo:
  7368. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7369. case qoOnceEmpty:
  7370. return IsAnythingQueued();
  7371. default:
  7372. return FQueueController->AllowOperation(Operation, Param);
  7373. }
  7374. }
  7375. //---------------------------------------------------------------------------
  7376. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7377. {
  7378. if (DebugAlwaysTrue(QueueView3->Visible))
  7379. {
  7380. QueueView3->SetFocus();
  7381. }
  7382. }
  7383. //---------------------------------------------------------------------------
  7384. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7385. TQueueOperation Operation, void * Param)
  7386. {
  7387. if (Operation == qoGoTo)
  7388. {
  7389. GoToQueue();
  7390. }
  7391. else if (Operation == qoPreferences)
  7392. {
  7393. PreferencesDialog(pmQueue);
  7394. }
  7395. else
  7396. {
  7397. FQueueController->ExecuteOperation(Operation, Param);
  7398. }
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7402. {
  7403. return (Queue != NULL) && Queue->Enabled;
  7404. }
  7405. //---------------------------------------------------------------------------
  7406. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7407. {
  7408. DebugAssert(Queue != NULL);
  7409. if (Queue != NULL)
  7410. {
  7411. Queue->Enabled = !Queue->Enabled;
  7412. }
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7416. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7417. {
  7418. FQueueActedItem = QueueView3->ItemFocused;
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7422. {
  7423. return TopDock->Height + QueueSplitter->Height;
  7424. }
  7425. //---------------------------------------------------------------------------
  7426. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7427. {
  7428. return
  7429. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7430. (QueueDock->Visible ? QueueDock->Height : 0) +
  7431. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7432. }
  7433. //---------------------------------------------------------------------------
  7434. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7435. {
  7436. return ScaleByTextHeight(this, 48);
  7437. }
  7438. //---------------------------------------------------------------------------
  7439. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7440. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7441. {
  7442. // when queue is hidden by double-clicking splitter, stray attempt to
  7443. // resize the panel with strange value arrives, make sure it is ignored
  7444. if (ComponentVisible[fcQueueView])
  7445. {
  7446. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7447. if (NewSize > MaxHeightLimit)
  7448. {
  7449. NewSize = MaxHeightLimit;
  7450. }
  7451. int MinHeightLimit =
  7452. GetStaticQueuePanelComponentsHeight() +
  7453. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7454. GetMinQueueViewHeight();
  7455. if (NewSize < MinHeightLimit)
  7456. {
  7457. NewSize = MinHeightLimit;
  7458. }
  7459. }
  7460. else
  7461. {
  7462. Accept = false;
  7463. }
  7464. }
  7465. //---------------------------------------------------------------------------
  7466. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7467. {
  7468. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7469. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7470. if (QueueViewHeight < GetMinQueueViewHeight())
  7471. {
  7472. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7473. }
  7474. }
  7475. //---------------------------------------------------------------------------
  7476. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7477. TDragObject *& /*DragObject*/)
  7478. {
  7479. FQueueActedItem = QueueView3->ItemFocused;
  7480. }
  7481. //---------------------------------------------------------------------------
  7482. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7483. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7484. {
  7485. Accept = true;
  7486. if (Source == QueueView3)
  7487. {
  7488. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7489. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7490. if (Accept)
  7491. {
  7492. TQueueItemProxy * QueueItem;
  7493. TQueueItemProxy * DestQueueItem;
  7494. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7495. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7496. Accept = (QueueItem != DestQueueItem) &&
  7497. (QueueItem->Status == TQueueItem::qsPending) &&
  7498. (DestQueueItem->Status == TQueueItem::qsPending);
  7499. }
  7500. }
  7501. }
  7502. //---------------------------------------------------------------------------
  7503. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7504. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7505. {
  7506. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7507. {
  7508. TQueueItemProxy * QueueItem;
  7509. TQueueItemProxy * DestQueueItem;
  7510. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7511. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7512. QueueItem->Move(DestQueueItem);
  7513. }
  7514. }
  7515. //---------------------------------------------------------------------------
  7516. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7517. {
  7518. if ((QueueView3->ItemFocused == NULL) &&
  7519. (QueueView3->Items->Count > 0))
  7520. {
  7521. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7522. }
  7523. QueueLabelUpdateStatus();
  7524. }
  7525. //---------------------------------------------------------------------------
  7526. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7527. {
  7528. QueueLabelUpdateStatus();
  7529. }
  7530. //---------------------------------------------------------------------------
  7531. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7532. {
  7533. QueueLabel->UpdateStatus();
  7534. }
  7535. //---------------------------------------------------------------------------
  7536. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7537. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7538. {
  7539. if (Selected)
  7540. {
  7541. NonVisualDataModule->UpdateNonVisibleActions();
  7542. }
  7543. }
  7544. //---------------------------------------------------------------------------
  7545. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7546. {
  7547. TDragDropFilesEx * Result = NULL;
  7548. if (Sender == SessionsPageControl)
  7549. {
  7550. Result = FSessionsDragDropFilesEx;
  7551. }
  7552. else if (Sender == QueueView3)
  7553. {
  7554. Result = FQueueDragDropFilesEx;
  7555. }
  7556. else
  7557. {
  7558. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7559. if (DirView != NULL)
  7560. {
  7561. Result = DirView->DragDropFilesEx;
  7562. }
  7563. else
  7564. {
  7565. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7566. if (DriveView != NULL)
  7567. {
  7568. Result = DriveView->DragDropFilesEx;
  7569. }
  7570. }
  7571. }
  7572. DebugAssert(Result != NULL);
  7573. return Result;
  7574. }
  7575. //---------------------------------------------------------------------------
  7576. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7577. {
  7578. return (DView->SelCount == DView->FilesCount);
  7579. }
  7580. //---------------------------------------------------------------------------
  7581. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7582. {
  7583. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7584. }
  7585. //---------------------------------------------------------------------------
  7586. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7587. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7588. {
  7589. DebugAssert(!IsLocalBrowserMode());
  7590. TFileOperation Operation;
  7591. switch (Effect)
  7592. {
  7593. case DROPEFFECT_MOVE:
  7594. Operation = foMove;
  7595. break;
  7596. case DROPEFFECT_COPY:
  7597. // occures on WinXP (reported by user)
  7598. default:
  7599. Operation = foCopy;
  7600. break;
  7601. };
  7602. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7603. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7604. if (DragDropFilesEx->FileList->Count > 0)
  7605. {
  7606. TStrings * FileList = new TStringList();
  7607. try
  7608. {
  7609. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7610. {
  7611. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7612. }
  7613. FDragDropOperation = true;
  7614. TTransferOperationParam Param;
  7615. Param.TargetDirectory = TargetPath;
  7616. // upload, no temp dirs
  7617. Param.Temp = false;
  7618. Param.DragDrop = DragDrop;
  7619. Param.Options =
  7620. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7621. if (ForceQueue)
  7622. {
  7623. Param.Queue = asOn;
  7624. }
  7625. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7626. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7627. {
  7628. if (IsFileControl(DropSourceControl, osLocal))
  7629. {
  7630. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7631. }
  7632. else
  7633. {
  7634. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7635. }
  7636. }
  7637. }
  7638. __finally
  7639. {
  7640. FDragDropOperation = false;
  7641. delete FileList;
  7642. }
  7643. }
  7644. }
  7645. //---------------------------------------------------------------------------
  7646. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7647. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7648. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7649. {
  7650. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7651. }
  7652. //---------------------------------------------------------------------------
  7653. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7654. TObject * Sender, int grfKeyState, int & dwEffect)
  7655. {
  7656. DebugAssert(!IsLocalBrowserMode());
  7657. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7658. if ((dwEffect != DROPEFFECT_NONE) &&
  7659. IsFileControl(DropSourceControl, osRemote))
  7660. {
  7661. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7662. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7663. (RemoteDirView->DropTarget == NULL))
  7664. {
  7665. dwEffect = DROPEFFECT_NONE;
  7666. }
  7667. else
  7668. {
  7669. if (dwEffect == DROPEFFECT_COPY)
  7670. {
  7671. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7672. // currently we support copying always (at least via temporary directory);
  7673. // remove associated checks once this all proves stable and working
  7674. bool CopyCapable = true;
  7675. // if we do not support neither of operations, there's no discussion
  7676. if (!MoveCapable && !CopyCapable)
  7677. {
  7678. dwEffect = DROPEFFECT_NONE;
  7679. }
  7680. else
  7681. {
  7682. // The default effect inside remote panel is move,
  7683. // unless we do not support it, but support copy
  7684. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7685. {
  7686. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7687. }
  7688. else
  7689. {
  7690. // with ctrl-down, we want copy unless it is not supported
  7691. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7692. }
  7693. }
  7694. }
  7695. }
  7696. }
  7697. }
  7698. //---------------------------------------------------------------------------
  7699. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7700. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7701. {
  7702. DebugAssert(!IsLocalBrowserMode());
  7703. if (FDDTotalSize >= 0)
  7704. {
  7705. if (File->IsDirectory)
  7706. {
  7707. FDDTotalSize = -1;
  7708. }
  7709. else
  7710. {
  7711. FDDTotalSize += File->Size;
  7712. }
  7713. }
  7714. DebugAssert(!FDragTempDir.IsEmpty());
  7715. // TODO: this is quite ineffective
  7716. // TODO: what if invalid character replacement is disabled?
  7717. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7718. UnicodeString TransferFileName;
  7719. if (Sender == RemoteDriveView)
  7720. {
  7721. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7722. }
  7723. else
  7724. {
  7725. TransferFileName = File->FileName;
  7726. }
  7727. FDDFileList->AddObject(TransferFileName, File);
  7728. }
  7729. //---------------------------------------------------------------------------
  7730. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7731. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7732. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7733. {
  7734. // sometimes we do not get DDEnd so the list is not released
  7735. SAFE_DESTROY(FDDFileList);
  7736. FDDFileList = new TStringList();
  7737. FDragTempDir = WinConfiguration->TemporaryDir();
  7738. FDDTotalSize = 0;
  7739. FDragDropSshTerminate.reset(NULL);
  7740. }
  7741. //---------------------------------------------------------------------------
  7742. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7743. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7744. HRESULT & Result)
  7745. {
  7746. if (Result == DRAGDROP_S_DROP)
  7747. {
  7748. try
  7749. {
  7750. GlobalDragImageList->HideDragImage();
  7751. try
  7752. {
  7753. RemoteFileControlDDTargetDrop();
  7754. }
  7755. catch(ESshTerminate & E)
  7756. {
  7757. FDragDropSshTerminate.reset(E.Clone());
  7758. }
  7759. }
  7760. catch (Exception &E)
  7761. {
  7762. // If downloading fails we need to cancel drag&drop, otherwise
  7763. // Explorer shows error
  7764. // But by the way exception probably never reach this point as
  7765. // it's catched on way.
  7766. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7767. Result = DRAGDROP_S_CANCEL;
  7768. ShowExtendedException(Terminal, &E);
  7769. }
  7770. }
  7771. }
  7772. //---------------------------------------------------------------------------
  7773. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7774. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7775. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7776. {
  7777. TFileMasks::TParams MaskParams;
  7778. MaskParams.Size = Size;
  7779. MaskParams.Modification = Modification;
  7780. // this does not re-parse the mask if it is the same as the last time
  7781. FDirViewMatchMask = Masks;
  7782. bool ImplicitMatch;
  7783. Matches =
  7784. // RecurseInclude parameter has no effect as the Path is empty
  7785. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7786. (AllowImplicitMatches || !ImplicitMatch);
  7787. }
  7788. //---------------------------------------------------------------------------
  7789. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7790. TObject * Sender, TListItem * Item, WORD & Indexes)
  7791. {
  7792. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7793. UnicodeString Ext;
  7794. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7795. {
  7796. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7797. }
  7798. else
  7799. {
  7800. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7801. }
  7802. if (SameText(Ext, Configuration->PartialExt))
  7803. {
  7804. Indexes |= oiPartial;
  7805. }
  7806. }
  7807. //---------------------------------------------------------------------------
  7808. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7809. {
  7810. return
  7811. DirViewEnabled(osCurrent) &&
  7812. DirView(osCurrent)->CanPasteFromClipBoard();
  7813. }
  7814. //---------------------------------------------------------------------------
  7815. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7816. {
  7817. bool Result = false;
  7818. if (CanPasteToDirViewFromClipBoard())
  7819. {
  7820. Result = true;
  7821. }
  7822. else
  7823. {
  7824. UnicodeString ClipboardText;
  7825. if (NonEmptyTextFromClipboard(ClipboardText))
  7826. {
  7827. if (StoredSessions->IsUrl(ClipboardText))
  7828. {
  7829. Result = true;
  7830. }
  7831. else
  7832. {
  7833. Result = DirViewEnabled(osCurrent);
  7834. }
  7835. }
  7836. }
  7837. return Result;
  7838. }
  7839. //---------------------------------------------------------------------------
  7840. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7841. {
  7842. if (DoesClipboardContainOurFiles())
  7843. {
  7844. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7845. {
  7846. DebugAssert(!IsLocalBrowserMode());
  7847. TTerminalManager * Manager = TTerminalManager::Instance();
  7848. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7849. Manager->ActiveTerminal = FClipboardTerminal;
  7850. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7851. }
  7852. }
  7853. else if (CanPasteToDirViewFromClipBoard())
  7854. {
  7855. DirView(osCurrent)->PasteFromClipBoard();
  7856. }
  7857. else
  7858. {
  7859. UnicodeString ClipboardText;
  7860. if (NonEmptyTextFromClipboard(ClipboardText))
  7861. {
  7862. if (StoredSessions->IsUrl(ClipboardText))
  7863. {
  7864. NewSession(false, ClipboardText);
  7865. }
  7866. else
  7867. {
  7868. DirView(osCurrent)->Path = ClipboardText;
  7869. }
  7870. }
  7871. }
  7872. }
  7873. //---------------------------------------------------------------------------
  7874. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7875. {
  7876. // TBD
  7877. }
  7878. //---------------------------------------------------------------------------
  7879. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7880. {
  7881. TCustomDirView * ADirView = DirView(Side);
  7882. ADirView->SelectAll(Mode);
  7883. ADirView->SetFocus();
  7884. }
  7885. //---------------------------------------------------------------------------
  7886. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7887. {
  7888. TCustomDirView * ADirView = DirView(Side);
  7889. TFileFilter Filter;
  7890. DefaultFileFilter(Filter);
  7891. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7892. {
  7893. Configuration->Usage->Inc(L"MaskSelections");
  7894. ADirView->SelectFiles(Filter, Select);
  7895. ADirView->SetFocus();
  7896. }
  7897. }
  7898. //---------------------------------------------------------------------------
  7899. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7900. {
  7901. TCustomDirView * ADirView = DirView(Side);
  7902. ADirView->RestoreSelectedNames();
  7903. ADirView->SetFocus();
  7904. }
  7905. //---------------------------------------------------------------------------
  7906. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7907. {
  7908. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7909. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7910. {
  7911. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7912. UnicodeString Ext;
  7913. if (!IsSideLocalBrowser(osCurrent))
  7914. {
  7915. Ext = UnixExtractFileExt(FileName);
  7916. }
  7917. else
  7918. {
  7919. Ext = ExtractFileExt(FileName);
  7920. }
  7921. if (Ext.IsEmpty())
  7922. {
  7923. Ext = L".";
  7924. }
  7925. TFileFilter Filter;
  7926. Filter.Masks = FORMAT(L"*%s", (Ext));
  7927. Filter.Directories = false;
  7928. CurrentDirView->SelectFiles(Filter, Select);
  7929. }
  7930. }
  7931. //---------------------------------------------------------------------------
  7932. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7933. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7934. {
  7935. UnicodeString Result;
  7936. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7937. {
  7938. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7939. }
  7940. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7941. {
  7942. // noop
  7943. }
  7944. else
  7945. {
  7946. Result =
  7947. FMTLOAD(FILE_INFO_FORMAT,
  7948. (FormatBytes(FileInfo.SelectedSize),
  7949. FormatBytes(FileInfo.FilesSize),
  7950. FormatNumber(FileInfo.SelectedCount),
  7951. FormatNumber(FileInfo.FilesCount)));
  7952. }
  7953. return Result;
  7954. }
  7955. //---------------------------------------------------------------------------
  7956. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7957. TTBXStatusPanel * Panel, TOperationSide Side)
  7958. {
  7959. if (Panel->Index == 1)
  7960. {
  7961. ToggleShowHiddenFiles();
  7962. }
  7963. else if (Panel->Index == 2)
  7964. {
  7965. Filter(Side);
  7966. }
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7970. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7971. {
  7972. DebugAssert(!StatusBar->SimplePanel);
  7973. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7974. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7975. }
  7976. //---------------------------------------------------------------------------
  7977. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7978. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7979. {
  7980. DebugAssert(StatusBar->Panels->Count >= 3);
  7981. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7982. if (FileInfo.HiddenCount > 0)
  7983. {
  7984. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7985. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7986. }
  7987. else
  7988. {
  7989. HiddenFilesPanel->ViewPriority = 0;
  7990. // not really necessary, just to cleanup no-longer-valid data
  7991. HiddenFilesPanel->Caption = L"";
  7992. }
  7993. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7994. if (FileInfo.FilteredCount > 0)
  7995. {
  7996. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7997. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7998. }
  7999. else
  8000. {
  8001. FilteredFilesPanel->ViewPriority = 0;
  8002. // not really necessary, just to cleanup no-longer-valid data
  8003. FilteredFilesPanel->Caption = L"";
  8004. }
  8005. }
  8006. //---------------------------------------------------------------------------
  8007. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8008. TObject * /*Sender*/)
  8009. {
  8010. if (DirView(osRemote)->Enabled)
  8011. {
  8012. DirView(osRemote)->SetFocus();
  8013. }
  8014. }
  8015. //---------------------------------------------------------------------------
  8016. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8017. {
  8018. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8019. switch (Config.Show)
  8020. {
  8021. case qvShow:
  8022. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8023. {
  8024. Config.Show = qvHide;
  8025. }
  8026. else
  8027. {
  8028. Config.Show = Config.LastHideShow;
  8029. }
  8030. break;
  8031. case qvHideWhenEmpty:
  8032. if (ComponentVisible[fcQueueView])
  8033. {
  8034. Config.Show = qvHide;
  8035. }
  8036. else
  8037. {
  8038. Config.LastHideShow = Config.Show;
  8039. Config.Show = qvShow;
  8040. }
  8041. break;
  8042. case qvHide:
  8043. Config.LastHideShow = Config.Show;
  8044. Config.Show = qvShow;
  8045. break;
  8046. }
  8047. WinConfiguration->QueueView = Config;
  8048. }
  8049. //---------------------------------------------------------------------------
  8050. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8051. {
  8052. UnicodeString Result;
  8053. if (FTerminal != NULL)
  8054. {
  8055. switch (WinConfiguration->PathInCaption)
  8056. {
  8057. case picShort:
  8058. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8059. break;
  8060. case picFull:
  8061. Result = FTerminal->CurrentDirectory;
  8062. break;
  8063. }
  8064. }
  8065. return Result;
  8066. }
  8067. //---------------------------------------------------------------------------
  8068. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8069. {
  8070. TColor Result = GetWindowColor(FSessionColor);
  8071. return Result;
  8072. }
  8073. //---------------------------------------------------------------------------
  8074. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8075. {
  8076. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8077. return Result;
  8078. }
  8079. //---------------------------------------------------------------------------
  8080. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8081. {
  8082. TTerminalManager::Instance()->UpdateAppTitle();
  8083. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8084. // background to gray on Windows 7 (works on Windows 10).
  8085. // See also EnableControl
  8086. if (Showing)
  8087. {
  8088. if (Terminal != NULL)
  8089. {
  8090. // Update path when it changes
  8091. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8092. {
  8093. UpdateSessionTab(SessionsPageControl->ActivePage);
  8094. }
  8095. }
  8096. NonVisualDataModule->ReconnectSessionAction->Update();
  8097. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8098. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8099. CenterReconnectToolbar();
  8100. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  8101. if (HasTerminal)
  8102. {
  8103. // TODO needed yet with second local browser?
  8104. if (!RemoteDirView->Enabled)
  8105. {
  8106. RemoteDirView->Enabled = true;
  8107. if (FRemoteDirViewWasFocused)
  8108. {
  8109. ActiveControl = RemoteDirView;
  8110. }
  8111. }
  8112. RemoteDirView->Color = PanelColor();
  8113. }
  8114. else
  8115. {
  8116. if (RemoteDirView->Enabled)
  8117. {
  8118. // This is first called when the form is being constructed
  8119. // (not anymore due to Showing test above)
  8120. // but the false is overriden in the constructor later.
  8121. // An even later in TScpCommanderForm::DoShow()
  8122. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8123. RemoteDirView->Enabled = false;
  8124. }
  8125. RemoteDirView->Color = DisabledPanelColor();
  8126. }
  8127. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8128. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8129. RemoteDriveView->Color = RemoteDirView->Color;
  8130. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8131. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8132. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8133. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8134. QueueFileList->Enabled = QueueView3->Enabled;
  8135. QueueFileList->Color = QueueView3->Color;
  8136. QueueFileList->Font->Color = QueueView3->Font->Color;
  8137. QueueLabelUpdateStatus();
  8138. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8139. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8140. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8141. }
  8142. }
  8143. //---------------------------------------------------------------------------
  8144. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8145. {
  8146. UpdateControls();
  8147. }
  8148. //---------------------------------------------------------------------------
  8149. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8150. TObject * Sender)
  8151. {
  8152. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8153. DebugAssert(DirView != NULL);
  8154. DoDirViewLoaded(DirView);
  8155. TransferPresetAutoSelect();
  8156. }
  8157. //---------------------------------------------------------------------------
  8158. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8159. {
  8160. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8161. // first run after installation
  8162. if (double(Updates.LastCheck) == 0)
  8163. {
  8164. // make sure next time there will be an update (if enabled)
  8165. Updates.LastCheck = TDateTime(1);
  8166. WinConfiguration->Updates = Updates;
  8167. }
  8168. else if ((double(Updates.Period) > 0) &&
  8169. (Now() - Updates.LastCheck >= Updates.Period))
  8170. {
  8171. TThreadMethod OnUpdatesChecked = NULL;
  8172. if (!IsUWP())
  8173. {
  8174. OnUpdatesChecked = UpdatesChecked;
  8175. }
  8176. StartUpdateThread(OnUpdatesChecked);
  8177. }
  8178. }
  8179. //---------------------------------------------------------------------------
  8180. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8181. {
  8182. UnicodeString Message;
  8183. bool New;
  8184. TQueryType Type;
  8185. GetUpdatesMessage(Message, New, Type, false);
  8186. if (!Message.IsEmpty())
  8187. {
  8188. if (New)
  8189. {
  8190. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8191. }
  8192. if (!New && (Type != qtWarning))
  8193. {
  8194. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8195. }
  8196. else
  8197. {
  8198. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8199. }
  8200. if (New)
  8201. {
  8202. Configuration->Usage->Inc(L"UpdateNotifications");
  8203. }
  8204. }
  8205. }
  8206. //---------------------------------------------------------------------------
  8207. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8208. {
  8209. RestoreApp();
  8210. bool CanDisplay = !NonVisualDataModule->Busy;
  8211. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8212. {
  8213. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8214. }
  8215. if (CanDisplay)
  8216. {
  8217. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8218. CheckForUpdates(true);
  8219. }
  8220. else
  8221. {
  8222. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8223. }
  8224. }
  8225. //---------------------------------------------------------------------------
  8226. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8227. TCopyParamRuleData & Data)
  8228. {
  8229. DebugAssert(Terminal != NULL);
  8230. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8231. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8232. Data.RemoteDirectory = RemoteDirView->PathName;
  8233. }
  8234. //---------------------------------------------------------------------------
  8235. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8236. {
  8237. // Terminal can be null when we are changing local directory implicitly,
  8238. // because it has been deleted, while no session is connected
  8239. // (Login dialog is open)
  8240. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8241. {
  8242. DebugAssert(!IsLocalBrowserMode());
  8243. TCopyParamRuleData Data;
  8244. GetTransferPresetAutoSelectData(Data);
  8245. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8246. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8247. if (CopyParamIndex < 0)
  8248. {
  8249. // there is no preset that matches autoselection
  8250. // set preset that we consider "default"
  8251. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8252. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8253. }
  8254. else
  8255. {
  8256. // there is preset matching autoselection
  8257. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8258. if (CopyParamName == FCopyParamAutoSelected)
  8259. {
  8260. // autoselected the same preset as the last time
  8261. // make no change (i.e. preserve custom user preset, if any)
  8262. }
  8263. else
  8264. {
  8265. // autoselected the different preset then the last time (or there
  8266. // was default preset set)
  8267. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8268. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8269. }
  8270. }
  8271. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8272. {
  8273. if (CopyParamIndex >= 0)
  8274. {
  8275. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8276. }
  8277. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8278. try
  8279. {
  8280. int Fmt =
  8281. (CopyParamIndex < 0) ?
  8282. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8283. COPY_PARAM_AUTOSELECTED;
  8284. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8285. Data->Message = MainInstructions(Message);
  8286. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8287. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8288. CopyParamAttrs);
  8289. if (CopyParamIndex >= 0)
  8290. {
  8291. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8292. Info = FORMAT(L"%s\n \n%s", (Info,
  8293. FMTLOAD(COPY_PARAM_RULE,
  8294. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8295. }
  8296. Data->Message += L"\n\n" + Info;
  8297. if (WinConfiguration->CopyParamAutoSelectNotice)
  8298. {
  8299. TransferPresetNoteMessage(Data, true);
  8300. }
  8301. else
  8302. {
  8303. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8304. Data = NULL; // ownership passed
  8305. }
  8306. }
  8307. __finally
  8308. {
  8309. delete Data;
  8310. }
  8311. }
  8312. }
  8313. }
  8314. //---------------------------------------------------------------------------
  8315. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8316. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8317. {
  8318. DebugAssert(NoteData != NULL);
  8319. DebugAssert(!IsLocalBrowserMode());
  8320. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8321. TQueryButtonAlias Aliases[1];
  8322. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8323. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8324. Params.Aliases = Aliases;
  8325. Params.AliasesCount = LENOF(Aliases);
  8326. unsigned int Result =
  8327. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8328. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8329. switch (Result)
  8330. {
  8331. case qaNeverAskAgain:
  8332. DebugAssert(AllowNeverAskAgain);
  8333. WinConfiguration->CopyParamAutoSelectNotice = false;
  8334. break;
  8335. case qaIgnore:
  8336. PreferencesDialog(pmPresets);
  8337. break;
  8338. }
  8339. }
  8340. //---------------------------------------------------------------------------
  8341. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8342. {
  8343. // as of now useless, as this is used for notes only, never for balloons, ...
  8344. RestoreApp();
  8345. // .. and we should never be busy here
  8346. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8347. {
  8348. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8349. }
  8350. }
  8351. //---------------------------------------------------------------------------
  8352. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8353. TPreferencesMode APreferencesMode)
  8354. {
  8355. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8356. TCopyParamRuleData Data;
  8357. if (Terminal != NULL)
  8358. {
  8359. PreferencesData.reset(new TPreferencesDialogData());
  8360. GetTransferPresetAutoSelectData(Data);
  8361. PreferencesData->CopyParamRuleData = &Data;
  8362. }
  8363. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8364. }
  8365. //---------------------------------------------------------------------------
  8366. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8367. const TCustomCommandType & Command)
  8368. {
  8369. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8370. {
  8371. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8372. }
  8373. }
  8374. //---------------------------------------------------------------------------
  8375. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8376. {
  8377. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8378. TCustomCommandType Command;
  8379. // make sure we use local custom command when remote are not supported
  8380. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8381. {
  8382. Command = FLastCustomCommand;
  8383. }
  8384. else
  8385. {
  8386. Command.Params = Command.Params | ccLocal;
  8387. }
  8388. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8389. FEditingFocusedAdHocCommand = OnFocused;
  8390. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8391. int Options =
  8392. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8393. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8394. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8395. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8396. {
  8397. FLastCustomCommand = Command;
  8398. UpdateCustomCommandsToolbar();
  8399. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8400. }
  8401. }
  8402. //---------------------------------------------------------------------------
  8403. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8404. {
  8405. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8406. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8407. DebugAssert(State > 0);
  8408. if (State <= 0)
  8409. {
  8410. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8411. }
  8412. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8416. TCustomCommandType & Command, int & State)
  8417. {
  8418. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8419. if (Result)
  8420. {
  8421. Command = FLastCustomCommand;
  8422. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8423. }
  8424. return Result;
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8428. {
  8429. ResetIncrementalSearch();
  8430. }
  8431. //---------------------------------------------------------------------------
  8432. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8433. {
  8434. DebugAssert(ComponentVisible[Component]);
  8435. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8436. }
  8437. //---------------------------------------------------------------------------
  8438. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8439. {
  8440. // when queue panel is resized here directly, the status bar is stretched
  8441. // over whole space the panel occupied
  8442. PostComponentHide(fcQueueView);
  8443. }
  8444. //---------------------------------------------------------------------------
  8445. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8446. {
  8447. ComponentVisible[fcQueueFileList] = false;
  8448. }
  8449. //---------------------------------------------------------------------------
  8450. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8451. {
  8452. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8453. RefreshColorMode();
  8454. WinConfiguration->ResetSysDarkTheme();
  8455. ConfigurationChanged();
  8456. ConfigureInterface();
  8457. // Should be called for all controls
  8458. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8459. }
  8460. //---------------------------------------------------------------------------
  8461. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8462. {
  8463. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8464. if (!FInvalid &&
  8465. (Message.LParam != 0) &&
  8466. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8467. {
  8468. ThemeChanged();
  8469. }
  8470. TForm::Dispatch(&Message);
  8471. }
  8472. //---------------------------------------------------------------------------
  8473. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8474. {
  8475. TMessage * M = static_cast<TMessage*>(Message);
  8476. switch (M->Msg)
  8477. {
  8478. case CM_DIALOGCHAR:
  8479. CMDialogChar(*M);
  8480. break;
  8481. case WM_APPCOMMAND:
  8482. WMAppCommand(*M);
  8483. break;
  8484. case WM_SYSCOMMAND:
  8485. WMSysCommand(*M);
  8486. break;
  8487. case WM_QUERYENDSESSION:
  8488. WMQueryEndSession(*M);
  8489. break;
  8490. case WM_ENDSESSION:
  8491. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8492. break;
  8493. #ifdef _DEBUG
  8494. case WM_WINDOWPOSCHANGED:
  8495. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8496. break;
  8497. case CM_CUSTOMSTYLECHANGED:
  8498. TForm::Dispatch(Message);
  8499. break;
  8500. #endif
  8501. case WM_COMPONENT_HIDE:
  8502. {
  8503. Byte Component = static_cast<Byte>(M->WParam);
  8504. // sanity check
  8505. if (ComponentVisible[Component])
  8506. {
  8507. // special treatment
  8508. if (Component == fcQueueView)
  8509. {
  8510. ToggleQueueVisibility();
  8511. DebugAssert(!ComponentVisible[fcQueueView]);
  8512. }
  8513. else
  8514. {
  8515. ComponentVisible[Component] = false;
  8516. }
  8517. }
  8518. }
  8519. break;
  8520. case WM_COPYDATA:
  8521. WMCopyData(*M);
  8522. break;
  8523. case WM_MANAGES_CAPTION:
  8524. // caption managed in TTerminalManager::UpdateAppTitle()
  8525. M->Result = 1;
  8526. break;
  8527. case WM_WANTS_MOUSEWHEEL:
  8528. M->Result = 1;
  8529. break;
  8530. case CM_SHOWINGCHANGED:
  8531. CMShowingChanged(*M);
  8532. break;
  8533. case WM_CLOSE:
  8534. WMClose(*M);
  8535. break;
  8536. case WM_DPICHANGED:
  8537. WMDpiChanged(*M);
  8538. break;
  8539. case CM_DPICHANGED:
  8540. CMDpiChanged(*M);
  8541. break;
  8542. case WM_SETTINGCHANGE:
  8543. WMSettingChange(*M);
  8544. break;
  8545. case CM_DIALOGKEY:
  8546. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8547. break;
  8548. default:
  8549. TForm::Dispatch(Message);
  8550. break;
  8551. }
  8552. }
  8553. //---------------------------------------------------------------------------
  8554. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8555. {
  8556. // noop
  8557. }
  8558. //---------------------------------------------------------------------------
  8559. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8560. {
  8561. TForm::Dispatch(&Message);
  8562. FSessionColors->Clear();
  8563. AddFixedSessionImages();
  8564. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8565. UpdateImages();
  8566. }
  8567. //---------------------------------------------------------------------------
  8568. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8569. {
  8570. TForm::Dispatch(&Message);
  8571. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8572. UpdatePixelsPerInchMainWindowCounter();
  8573. }
  8574. //---------------------------------------------------------------------------
  8575. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8576. {
  8577. // Cannot close window while we are busy.
  8578. // We cannot test this in FormCloseQuery as that is called also from
  8579. // Close(), which is called by CloseApplicationAction. So we can be busy
  8580. // there already even, when it is legitimate to close the application.
  8581. // Possibly a better place to handle this would be WMSysCommand.
  8582. if (NonVisualDataModule->Busy)
  8583. {
  8584. Message.Result = 1;
  8585. }
  8586. else
  8587. {
  8588. TForm::Dispatch(&Message);
  8589. }
  8590. }
  8591. //---------------------------------------------------------------------------
  8592. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8593. {
  8594. TForm::Dispatch(&Message);
  8595. if (Showing && (Terminal == NULL))
  8596. {
  8597. // When we are starting minimized (i.e. from an installer),
  8598. // postpone showing Login dialog until we get restored.
  8599. // Otherwise the Login dialog (and Authentication window) show restored
  8600. // over invisible (minimized) main window.
  8601. if (WindowState == wsMinimized)
  8602. {
  8603. FNeedSession = true;
  8604. }
  8605. else
  8606. {
  8607. // This happens before application ever goes idle, so the toolbars would
  8608. // stay enabled (initial state) until the Login dialog is dismissed.
  8609. UpdateActions();
  8610. NonVisualDataModule->StartBusy();
  8611. try
  8612. {
  8613. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8614. // otherwise the dialog does not receive focus.
  8615. // With Commander interface the ProcessMessages is called already
  8616. // by TDriveView, but with Explorer interface, we need to call it explicily
  8617. Application->ProcessMessages();
  8618. // do not reload sessions, they have been loaded just now (optimization)
  8619. NeedSession(true);
  8620. }
  8621. __finally
  8622. {
  8623. NonVisualDataModule->EndBusy();
  8624. }
  8625. }
  8626. }
  8627. }
  8628. //---------------------------------------------------------------------------
  8629. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8630. {
  8631. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8632. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8633. }
  8634. //---------------------------------------------------------------------------
  8635. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8636. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8637. int & MaxHeight)
  8638. {
  8639. // workaround for bug in TWinControl.CalcConstraints
  8640. // Check for empty rect (restore from iconic state) is done there only after
  8641. // call to AdjustClientRect, which enlarges the rect (for forms).
  8642. TRect R = GetClientRect();
  8643. // when restoring from iconic state, place no restrictions
  8644. if (IsRectEmpty(R))
  8645. {
  8646. MinWidth = 0;
  8647. MinHeight = 0;
  8648. MaxWidth = 32000;
  8649. MaxHeight = 32000;
  8650. }
  8651. }
  8652. //---------------------------------------------------------------------------
  8653. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8654. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8655. {
  8656. // terminal can be already closed (e.g. dropped connection)
  8657. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8658. {
  8659. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8660. try
  8661. {
  8662. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8663. }
  8664. catch(...)
  8665. {
  8666. if (!Terminal->Active)
  8667. {
  8668. Close = true;
  8669. }
  8670. throw;
  8671. }
  8672. }
  8673. }
  8674. //---------------------------------------------------------------------------
  8675. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8676. {
  8677. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8678. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8679. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8680. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8681. {
  8682. OnGetSpaceAvailable = GetSpaceAvailable;
  8683. }
  8684. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8685. OnGetSpaceAvailable);
  8686. }
  8687. //---------------------------------------------------------------------------
  8688. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8689. {
  8690. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8691. Terminal->FillSessionDataForCode(Data.get());
  8692. return Data.release();
  8693. }
  8694. //---------------------------------------------------------------------------
  8695. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8696. {
  8697. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8698. DoGenerateUrlDialog(Data.get(), Paths);
  8699. }
  8700. //---------------------------------------------------------------------------
  8701. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8702. {
  8703. GenerateUrl(NULL);
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8707. {
  8708. std::unique_ptr<TStrings> Paths(new TStringList());
  8709. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8710. GenerateUrl(Paths.get());
  8711. }
  8712. //---------------------------------------------------------------------------
  8713. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8714. {
  8715. FSessionColor = value;
  8716. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8717. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8718. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8719. DebugAssert(ColorItem != NULL);
  8720. ColorItem->Color = C;
  8721. NonVisualDataModule->ColorMenuItem->Color = C;
  8722. UpdateControls();
  8723. }
  8724. //---------------------------------------------------------------------------
  8725. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8726. {
  8727. if (value != FSessionColor)
  8728. {
  8729. UpdateSessionColor(value);
  8730. // Is null when called from LastTerminalClosed
  8731. if (Terminal != NULL)
  8732. {
  8733. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8734. }
  8735. }
  8736. }
  8737. //---------------------------------------------------------------------------
  8738. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8739. {
  8740. bool Result = FNoteTimer->Enabled;
  8741. if (Result)
  8742. {
  8743. // cannot cancel note too early
  8744. bool NotEarly =
  8745. (Now() - FNoteShown >
  8746. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8747. if (Force || NotEarly)
  8748. {
  8749. FNoteTimer->Enabled = false;
  8750. FNote = L"";
  8751. SAFE_DESTROY(FNoteData);
  8752. FOnNoteClick = NULL;
  8753. FNoteHints = FNotes->Text;
  8754. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8755. UpdateStatusBar();
  8756. }
  8757. }
  8758. return Result;
  8759. }
  8760. //---------------------------------------------------------------------------
  8761. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8762. {
  8763. DebugAssert(FNoteTimer->Enabled);
  8764. CancelNote(true);
  8765. }
  8766. //---------------------------------------------------------------------------
  8767. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8768. {
  8769. int P = Note.Pos(L"\n");
  8770. if (P > 0)
  8771. {
  8772. Note.SetLength(P - 1);
  8773. }
  8774. FNotes->Add(FORMAT(L"[%s] %s",
  8775. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8776. while (FNotes->Count > 10)
  8777. {
  8778. FNotes->Delete(0);
  8779. }
  8780. if (UpdateNow)
  8781. {
  8782. FNoteHints = FNotes->Text;
  8783. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8784. UpdateStatusBar();
  8785. }
  8786. }
  8787. //---------------------------------------------------------------------------
  8788. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8789. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8790. {
  8791. int P = Note.Pos(L"\n");
  8792. if (P > 0)
  8793. {
  8794. Note.SetLength(P - 1);
  8795. }
  8796. FNoteHints = FNotes->Text;
  8797. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8798. FNote = Note;
  8799. SAFE_DESTROY(FNoteData);
  8800. FNoteData = NoteData;
  8801. FOnNoteClick = OnNoteClick;
  8802. AddNote(Note, false);
  8803. UpdateStatusBar();
  8804. FNoteShown = Now();
  8805. FNoteTimer->Enabled = false;
  8806. if (Seconds == 0)
  8807. {
  8808. Seconds = WinConfiguration->NotificationsTimeout;
  8809. }
  8810. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8811. FNoteTimer->Enabled = true;
  8812. }
  8813. //---------------------------------------------------------------------------
  8814. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8815. {
  8816. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8817. }
  8818. //---------------------------------------------------------------------------
  8819. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8820. {
  8821. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8822. {
  8823. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8824. }
  8825. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8826. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8827. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8828. 0, NULL, NULL);
  8829. }
  8830. //---------------------------------------------------------------------------
  8831. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8832. {
  8833. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8834. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8835. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8836. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8837. }
  8838. //---------------------------------------------------------------------------
  8839. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8840. {
  8841. WinConfiguration->FormatSizeBytes = Style;
  8842. }
  8843. //---------------------------------------------------------------------------
  8844. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8845. {
  8846. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8847. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8848. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8849. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8850. }
  8851. //---------------------------------------------------------------------------
  8852. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8853. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8854. {
  8855. if (Panel->Index == 0)
  8856. {
  8857. if (FOnNoteClick != NULL)
  8858. {
  8859. // prevent the user data from being freed by possible call
  8860. // to CancelNote or PostNote during call to OnNoteClick
  8861. std::unique_ptr<TObject> NoteData(FNoteData);
  8862. TNotifyEvent OnNoteClick = FOnNoteClick;
  8863. FNoteData = NULL;
  8864. // need to cancel the note as we are going to delete its user data
  8865. CancelNote(true);
  8866. OnNoteClick(NoteData.get());
  8867. }
  8868. }
  8869. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8870. {
  8871. FileSystemInfo();
  8872. }
  8873. }
  8874. //---------------------------------------------------------------------------
  8875. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8876. {
  8877. // workaround:
  8878. // 1) for unknown reason, disabling window, while minimized,
  8879. // prevents it from restoring, even if it was enabled again meanwhile
  8880. // 2) when disabling the main window, while another has focus
  8881. // minimize is no longer possible
  8882. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8883. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8884. // Shouldn't we use IsApplicationMinimized() here?
  8885. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8886. {
  8887. Enabled = false;
  8888. }
  8889. FLockLevel++;
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8893. {
  8894. DebugAssert(FLockLevel > 0);
  8895. FLockLevel--;
  8896. if (FLockLevel == 0)
  8897. {
  8898. DebugAssert(FLockSuspendLevel == 0);
  8899. Enabled = true;
  8900. }
  8901. }
  8902. //---------------------------------------------------------------------------
  8903. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8904. {
  8905. // We need to make sure that window is enabled when the last modal window closes
  8906. // otherwise focus is not restored correctly.
  8907. // So we re-enable the window when modal window opens and
  8908. // disable it back after is closes
  8909. if (FLockLevel > 0)
  8910. {
  8911. // while we have nesting counter, we know that we never be called
  8912. // recursivelly as Application->OnModalBegin is called only
  8913. // for the top-level modal window
  8914. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8915. {
  8916. // won't be disabled when conditions in LockWindow() were not satisfied
  8917. FDisabledOnLockSuspend = !Enabled;
  8918. // When minimized to tray (or actually when set to SW_HIDE),
  8919. // setting Enabled makes the window focusable even when there's
  8920. // modal window over it
  8921. if (!FTrayIcon->Visible)
  8922. {
  8923. Enabled = true;
  8924. }
  8925. }
  8926. FLockSuspendLevel++;
  8927. }
  8928. }
  8929. //---------------------------------------------------------------------------
  8930. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8931. {
  8932. if (FLockSuspendLevel > 0)
  8933. {
  8934. DebugAssert(FLockLevel > 0);
  8935. FLockSuspendLevel--;
  8936. // see comment in SuspendWindowLock
  8937. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8938. {
  8939. // Note that window can be enabled here, when we were minized to tray when
  8940. // was SuspendWindowLock() called.
  8941. // We should possibly do the same check as in LockWindow(),
  8942. // if it is ever possible that the consitions change between
  8943. // SuspendWindowLock() and ResumeWindowLock()
  8944. Enabled = !FDisabledOnLockSuspend;
  8945. }
  8946. }
  8947. }
  8948. //---------------------------------------------------------------------------
  8949. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8950. {
  8951. if (!TextOnly)
  8952. {
  8953. TTBXComboBoxItem * RemotePathComboBox =
  8954. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8955. TStrings * Items = RemotePathComboBox->Strings;
  8956. Items->BeginUpdate();
  8957. try
  8958. {
  8959. Items->Clear();
  8960. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8961. {
  8962. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8963. while (!IsUnixRootPath(APath))
  8964. {
  8965. int P = APath.LastDelimiter(L'/');
  8966. DebugAssert(P >= 0);
  8967. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8968. APath.SetLength(P - 1);
  8969. }
  8970. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8971. }
  8972. }
  8973. __finally
  8974. {
  8975. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8976. // Setting ItemIndex to -1 does not reset its text
  8977. if (Items->Count == 0)
  8978. {
  8979. RemotePathComboBox->Text = L"";
  8980. }
  8981. Items->EndUpdate();
  8982. }
  8983. }
  8984. }
  8985. //---------------------------------------------------------------------------
  8986. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8987. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8988. int & ImageIndex)
  8989. {
  8990. if (AIndex < 0)
  8991. {
  8992. AIndex = Sender->ItemIndex;
  8993. }
  8994. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8995. }
  8996. //---------------------------------------------------------------------------
  8997. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8998. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8999. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9000. {
  9001. ARect.Left += (10 * AIndex);
  9002. }
  9003. //---------------------------------------------------------------------------
  9004. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9005. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9006. {
  9007. AWidth += (10 * AIndex);
  9008. }
  9009. //---------------------------------------------------------------------------
  9010. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9011. TObject * Sender)
  9012. {
  9013. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9014. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9015. int Index = RemotePathComboBox->ItemIndex;
  9016. while (Index < RemotePathComboBox->Strings->Count - 1)
  9017. {
  9018. APath = UnixExtractFileDir(APath);
  9019. Index++;
  9020. }
  9021. // VanDyke style paths
  9022. if (APath.IsEmpty())
  9023. {
  9024. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9025. APath = ROOTDIRECTORY;
  9026. }
  9027. if (RemoteDirView->Path != APath)
  9028. {
  9029. RemoteDirView->Path = APath;
  9030. }
  9031. }
  9032. //---------------------------------------------------------------------------
  9033. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9034. {
  9035. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9036. DebugUsedParam(Sender);
  9037. UpdateRemotePathComboBox(true);
  9038. }
  9039. //---------------------------------------------------------------------------
  9040. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9041. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9042. {
  9043. ResetIncrementalSearch();
  9044. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9045. DebugAssert(DirView != NULL);
  9046. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9047. {
  9048. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9049. // OnEditing is called also from TCustomListView::CanEdit
  9050. if (Edit != NULL)
  9051. {
  9052. EditSelectBaseName(Edit);
  9053. }
  9054. }
  9055. }
  9056. //---------------------------------------------------------------------------
  9057. //---------------------------------------------------------------------------
  9058. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9059. {
  9060. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9061. Result->AutoDetectDnD = false;
  9062. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9063. Result->RenderDataOn = rdoEnterAndDropSync;
  9064. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9065. return Result;
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9069. {
  9070. TForm::CreateWnd();
  9071. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9072. if (FSessionsDragDropFilesEx == NULL)
  9073. {
  9074. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9075. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9076. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9077. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9078. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9079. }
  9080. if (FQueueDragDropFilesEx == NULL)
  9081. {
  9082. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9083. // No need to set OnDragOver as we do not have any restrictions
  9084. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9085. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9086. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9087. }
  9088. }
  9089. //---------------------------------------------------------------------------
  9090. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9091. {
  9092. TForm::DestroyWnd();
  9093. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9094. FQueueDragDropFilesEx->DragDropControl = NULL;
  9095. }
  9096. //---------------------------------------------------------------------------
  9097. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9098. {
  9099. SideEnter(FCurrentSide);
  9100. FEverShown = true;
  9101. }
  9102. //---------------------------------------------------------------------------
  9103. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9104. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9105. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9106. {
  9107. if (!NonVisualDataModule->Busy)
  9108. {
  9109. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9110. Configuration->Usage->Inc(L"FileFinds");
  9111. LockWindow(true);
  9112. NonVisualDataModule->StartBusy();
  9113. WinConfiguration->LockedInterface = true;
  9114. try
  9115. {
  9116. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9117. }
  9118. __finally
  9119. {
  9120. WinConfiguration->LockedInterface = false;
  9121. NonVisualDataModule->EndBusy();
  9122. UnlockWindow();
  9123. }
  9124. }
  9125. }
  9126. //---------------------------------------------------------------------------
  9127. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9128. {
  9129. if (!NonVisualDataModule->Busy)
  9130. {
  9131. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9132. SetFocus();
  9133. RemoteDirView->Path = UnixExtractFilePath(Path);
  9134. UnicodeString FileName = UnixExtractFileName(Path);
  9135. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9136. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9137. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9138. if (Item == NULL)
  9139. {
  9140. ReloadDirectory(osRemote);
  9141. Item = RemoteDirView->FindFileItem(FileName);
  9142. }
  9143. if (Item != NULL)
  9144. {
  9145. RemoteDirView->ItemFocused = Item;
  9146. RemoteDirView->ItemFocused->MakeVisible(false);
  9147. RemoteDirView->SetFocus();
  9148. }
  9149. }
  9150. }
  9151. //---------------------------------------------------------------------------
  9152. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9153. {
  9154. bool Result = !NonVisualDataModule->Busy;
  9155. if (Result)
  9156. {
  9157. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9158. }
  9159. return Result;
  9160. }
  9161. //---------------------------------------------------------------------------
  9162. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9163. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9164. {
  9165. if (CanOperateOnFoundFiles(ATerminal))
  9166. {
  9167. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9168. FOnFileOperationFinished = OnFileOperationFinished;
  9169. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9170. }
  9171. }
  9172. //---------------------------------------------------------------------------
  9173. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9174. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9175. {
  9176. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9177. }
  9178. //---------------------------------------------------------------------------
  9179. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9180. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9181. {
  9182. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9183. }
  9184. //---------------------------------------------------------------------------
  9185. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9186. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9187. {
  9188. if (CanOperateOnFoundFiles(ATerminal))
  9189. {
  9190. for (int Index = 0; Index < FileList->Count; Index++)
  9191. {
  9192. UnicodeString FileName = FileList->Strings[Index];
  9193. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9194. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9195. OnFileOperationFinished(FileName, true);
  9196. }
  9197. }
  9198. }
  9199. //---------------------------------------------------------------------------
  9200. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9201. {
  9202. FFileFindTerminal = Terminal;
  9203. ShowFileFindDialog(
  9204. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9205. DoDownloadFoundFiles, DoEditFoundFiles);
  9206. }
  9207. //---------------------------------------------------------------------------
  9208. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9209. {
  9210. FTaskbarList = TaskbarList;
  9211. }
  9212. //---------------------------------------------------------------------------
  9213. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9214. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9215. {
  9216. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9217. if (Index >= 0)
  9218. {
  9219. if (Button == mbLeft)
  9220. {
  9221. // "Mouse down" is raised only after tab is switched.
  9222. // If switching tab (switching session) takes long enough for user
  9223. // to actually release the button, "mouse down" is still raised,
  9224. // but we do not get "mouse up" event, so dragging is not cancelled,
  9225. // prevent that by not beginning dragging in the first place.
  9226. if (IsKeyPressed(VK_LBUTTON))
  9227. {
  9228. // when user clicks the "+", we get mouse down only after the session
  9229. // is closed, when new session tab is already on X:Y, so dragging
  9230. // starts, prevent that
  9231. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9232. {
  9233. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9234. if (Terminal != NULL)
  9235. {
  9236. SessionsPageControl->BeginDrag(false);
  9237. }
  9238. }
  9239. }
  9240. }
  9241. else if (Button == mbMiddle)
  9242. {
  9243. // ignore middle-click for "New session tab"
  9244. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9245. if (Terminal != NULL)
  9246. {
  9247. CloseSessionTab(Index);
  9248. }
  9249. }
  9250. }
  9251. }
  9252. //---------------------------------------------------------------------------
  9253. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9254. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9255. {
  9256. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9257. // do not allow dropping on the "+" tab
  9258. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9259. if ((TargetTerminal != NULL) &&
  9260. (SessionsPageControl->ActivePage->PageIndex != Index))
  9261. {
  9262. Configuration->Usage->Inc(L"SessionTabMoves");
  9263. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9264. // but we want to actually prevent that to avoid flicker
  9265. SessionsPageControl->ActivePage->PageIndex = Index;
  9266. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9267. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9268. }
  9269. }
  9270. //---------------------------------------------------------------------------
  9271. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9272. TObject * Sender, TObject * Source, int X, int Y,
  9273. TDragState /*State*/, bool & Accept)
  9274. {
  9275. Accept = (Sender == Source);
  9276. if (Accept)
  9277. {
  9278. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9279. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9280. // do not allow dragging to the "+" tab
  9281. Accept = (Terminal != NULL);
  9282. }
  9283. }
  9284. //---------------------------------------------------------------------------
  9285. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9286. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9287. {
  9288. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9289. if (Index < 0)
  9290. {
  9291. Effect = DROPEFFECT_NONE;
  9292. }
  9293. else
  9294. {
  9295. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9296. // do not allow dropping on the "+" tab
  9297. if (TargetTerminal == NULL)
  9298. {
  9299. Effect = DROPEFFECT_NONE;
  9300. }
  9301. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9302. {
  9303. Effect = DROPEFFECT_COPY;
  9304. }
  9305. }
  9306. }
  9307. //---------------------------------------------------------------------------
  9308. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9309. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9310. {
  9311. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9312. // do not allow dropping on the "+" tab
  9313. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9314. if (TargetTerminal != NULL)
  9315. {
  9316. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9317. if (!IsFileControl(DropSourceControl, osRemote))
  9318. {
  9319. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9320. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9321. // Why don't we use Terminal->CurrentDirectory directly?
  9322. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9323. // do not force queue, drag drop
  9324. false, true);
  9325. }
  9326. }
  9327. }
  9328. //---------------------------------------------------------------------------
  9329. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9330. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9331. {
  9332. // Downloads are handled in RemoteFileControlDDEnd
  9333. if (!IsFileControl(DropSourceControl, osRemote))
  9334. {
  9335. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9336. Terminal->CurrentDirectory,
  9337. // force queue, drag drop
  9338. true, true);
  9339. }
  9340. }
  9341. //---------------------------------------------------------------------------
  9342. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9343. {
  9344. FShowing = false;
  9345. // Do not save empty workspace
  9346. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9347. {
  9348. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9349. UnicodeString Name = WorkspaceName();
  9350. DoSaveWorkspace(
  9351. Name, DataList.get(),
  9352. !Configuration->DisablePasswordStoring &&
  9353. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9354. WinConfiguration->LastStoredSession = Name;
  9355. }
  9356. }
  9357. //---------------------------------------------------------------------------
  9358. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9359. {
  9360. TManagedTerminal * ManagedTerminal =
  9361. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9362. if (ManagedTerminal != NULL)
  9363. {
  9364. ManagedTerminal->DirectoryLoaded = Now();
  9365. }
  9366. }
  9367. //---------------------------------------------------------------------------
  9368. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9369. TListItem * /*Item*/, bool /*Selected*/)
  9370. {
  9371. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9372. switch (DirView->LastSelectMethod)
  9373. {
  9374. case smKeyboard:
  9375. Configuration->Usage->Inc(L"KeyboardSelections");
  9376. break;
  9377. case smMouse:
  9378. Configuration->Usage->Inc(L"MouseSelections");
  9379. break;
  9380. }
  9381. }
  9382. //---------------------------------------------------------------------------
  9383. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9384. {
  9385. if (Color != 0)
  9386. {
  9387. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9388. }
  9389. else
  9390. {
  9391. return FSessionTabImageIndex;
  9392. }
  9393. }
  9394. //---------------------------------------------------------------------------
  9395. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9396. {
  9397. TPngImageCollectionItem * Item =
  9398. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9399. FSessionColors->AddPng(Item->PngImage);
  9400. return FSessionColors->Count - 1;
  9401. }
  9402. //---------------------------------------------------------------------------
  9403. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9404. {
  9405. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9406. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9407. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9408. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9409. }
  9410. //---------------------------------------------------------------------------
  9411. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9412. {
  9413. for (int Index = 0; Index < Control->ControlCount; Index++)
  9414. {
  9415. TControl * AControl = Control->Controls[Index];
  9416. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9417. if (WinControl != NULL)
  9418. {
  9419. CollectItemsWithTextDisplayMode(WinControl);
  9420. }
  9421. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9422. if (Toolbar != NULL)
  9423. {
  9424. // we care for top-level items only
  9425. TTBCustomItem * Items = Toolbar->Items;
  9426. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9427. {
  9428. TTBCustomItem * Item = Items->Items[ItemIndex];
  9429. if (((Item->DisplayMode == nbdmImageAndText) ||
  9430. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9431. EligibleForImageDisplayMode(Item))
  9432. {
  9433. FItemsWithTextDisplayMode.insert(Item);
  9434. }
  9435. }
  9436. }
  9437. }
  9438. }
  9439. //---------------------------------------------------------------------------
  9440. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9441. {
  9442. return true;
  9443. }
  9444. //---------------------------------------------------------------------------
  9445. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9446. {
  9447. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9448. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9449. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9450. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9451. bool Result = true;
  9452. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9453. {
  9454. TTBCustomItem * Item = *i;
  9455. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9456. if (Label != NULL)
  9457. {
  9458. // optimization
  9459. if (Label->Visible == SelectiveToolbarText)
  9460. {
  9461. Result = false;
  9462. }
  9463. else
  9464. {
  9465. Label->Visible = SelectiveToolbarText;
  9466. }
  9467. }
  9468. else
  9469. {
  9470. // optimization
  9471. if (Item->DisplayMode == DisplayMode)
  9472. {
  9473. Result = false;
  9474. }
  9475. else
  9476. {
  9477. Item->DisplayMode = DisplayMode;
  9478. }
  9479. }
  9480. ++i;
  9481. }
  9482. if (Result)
  9483. {
  9484. UpdateNewSessionTab();
  9485. }
  9486. return Result;
  9487. }
  9488. //---------------------------------------------------------------------------
  9489. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9490. {
  9491. DebugFail();
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9495. {
  9496. // Among other, a lock level is non zero, while directory is being loaded,
  9497. // even when it happens as a result of dirview navigation,
  9498. // i.e. when TNonVisualDataModule is NOT FBusy.
  9499. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9500. // Among other this prevents a panel auto update to occur while
  9501. // directory is changing.
  9502. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9503. }
  9504. //---------------------------------------------------------------------------
  9505. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9506. {
  9507. // While the window is disabled, we still seem to process menu shortcuts at least,
  9508. // so stop it at least here.
  9509. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9510. return
  9511. (Allowed == aaUpdate) ||
  9512. !NonVisualDataModule->Busy;
  9513. }
  9514. //---------------------------------------------------------------------------
  9515. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9516. {
  9517. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9518. }
  9519. //---------------------------------------------------------------------------
  9520. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9521. {
  9522. // This is somewhat redundant to LockWindow() call from
  9523. // TTerminalManager::TerminalReadDirectoryProgress.
  9524. // But disabling window is known not to block keyboard shorcuts
  9525. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9526. if (Busy > 0)
  9527. {
  9528. if (NonVisualDataModule->Busy)
  9529. {
  9530. State = false;
  9531. }
  9532. else
  9533. {
  9534. NonVisualDataModule->StartBusy();
  9535. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9536. LockWindow();
  9537. }
  9538. }
  9539. else if (Busy < 0)
  9540. {
  9541. UnlockWindow();
  9542. NonVisualDataModule->EndBusy();
  9543. }
  9544. else
  9545. {
  9546. State = NonVisualDataModule->Busy;
  9547. }
  9548. }
  9549. //---------------------------------------------------------------------------
  9550. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9551. {
  9552. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9553. // no context menu for "New session tab"
  9554. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9555. {
  9556. SessionsPageControl->ActivePageIndex = Index;
  9557. if (DebugAlwaysTrue(SessionTabSwitched()))
  9558. {
  9559. // copied from TControl.WMContextMenu
  9560. SendCancelMode(SessionsPageControl);
  9561. // explicit popup instead of using PopupMenu property
  9562. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9563. // while connecting yet not-connected session and hence
  9564. // allowing an access to commands over not-completelly connected session
  9565. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9566. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9567. PopupMenu->PopupComponent = SessionsPageControl;
  9568. PopupMenu->Popup(Point.x, Point.y);
  9569. }
  9570. }
  9571. Handled = true;
  9572. }
  9573. //---------------------------------------------------------------------------
  9574. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9575. {
  9576. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9577. }
  9578. //---------------------------------------------------------------------------
  9579. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9580. {
  9581. Configuration->Usage->Inc(L"PasswordChanges");
  9582. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9583. ChangePasswordData->DisableAuthentationsExceptPassword();
  9584. ChangePasswordData->ChangePassword = true;
  9585. std::unique_ptr<TTerminal> ChangePasswordSession(
  9586. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9587. ChangePasswordSession->AutoReadDirectory = false;
  9588. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9589. {
  9590. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9591. }
  9592. else
  9593. {
  9594. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9595. }
  9596. }
  9597. //---------------------------------------------------------------------------
  9598. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9599. {
  9600. // No nice way to assert SSH2
  9601. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9602. }
  9603. //---------------------------------------------------------------------------
  9604. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9605. {
  9606. TOperationVisualizer OperationVisualizer;
  9607. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9608. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9609. }
  9610. //---------------------------------------------------------------------------
  9611. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9612. {
  9613. TForm::ChangeScale(M, D);
  9614. int APixelsPerInch = GetControlPixelsPerInch(this);
  9615. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9616. try
  9617. {
  9618. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9619. }
  9620. __finally
  9621. {
  9622. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9623. }
  9624. }
  9625. //---------------------------------------------------------------------------
  9626. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9627. {
  9628. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9629. }
  9630. //---------------------------------------------------------------------
  9631. class TPublicControl : public TControl
  9632. {
  9633. friend class TCustomScpExplorerForm;
  9634. };
  9635. //---------------------------------------------------------------------------
  9636. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9637. {
  9638. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9639. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9640. }
  9641. //---------------------------------------------------------------------------
  9642. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9643. {
  9644. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9645. OpenBookmark(Side, Bookmark);
  9646. }
  9647. //---------------------------------------------------------------------------
  9648. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9649. {
  9650. DoBookmarkClick(osLocal, Sender);
  9651. }
  9652. //---------------------------------------------------------------------------
  9653. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9654. {
  9655. DoBookmarkClick(osRemote, Sender);
  9656. }
  9657. //---------------------------------------------------------------------------
  9658. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9659. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9660. {
  9661. // TODO
  9662. if (BookmarkList != NULL)
  9663. {
  9664. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9665. if (!WinConfiguration->UseLocationProfiles)
  9666. {
  9667. std::unique_ptr<TStringList> Directories(new TStringList());
  9668. Directories->CaseSensitive = (Side == osRemote);
  9669. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9670. {
  9671. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9672. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9673. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9674. {
  9675. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9676. Item->Caption = EscapeHotkey(Directory);
  9677. Item->ShortCut = Bookmark->ShortCut;
  9678. Item->OnClick = OnBookmarkClick;
  9679. Item->Tag = reinterpret_cast<int>(Bookmark);
  9680. Directories->Add(Directory);
  9681. Menu->Add(Item.release());
  9682. }
  9683. }
  9684. }
  9685. else
  9686. {
  9687. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9688. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9689. {
  9690. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9691. if (!Bookmark->Node.IsEmpty())
  9692. {
  9693. Folders->Add(Bookmark->Node);
  9694. }
  9695. }
  9696. for (int Index = 0; Index < Folders->Count; Index++)
  9697. {
  9698. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9699. Item->Caption = Folders->Strings[Index];
  9700. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9701. Folders->Objects[Index] = Item.get();
  9702. Menu->Add(Item.release());
  9703. }
  9704. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9705. {
  9706. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9707. TTBCustomItem * Parent;
  9708. if (!Bookmark->Node.IsEmpty())
  9709. {
  9710. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9711. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9712. }
  9713. else
  9714. {
  9715. Parent = Menu;
  9716. }
  9717. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9718. Item->Caption = Bookmark->Name;
  9719. Item->ShortCut = Bookmark->ShortCut;
  9720. Item->OnClick = OnBookmarkClick;
  9721. Item->Tag = reinterpret_cast<int>(Bookmark);
  9722. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9723. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9724. {
  9725. // No hint for location profiles that are actually mere "bookmarks"
  9726. }
  9727. else
  9728. {
  9729. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9730. UnicodeString LongHint;
  9731. if (!Bookmark->Local.IsEmpty())
  9732. {
  9733. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9734. }
  9735. if (!Bookmark->Remote.IsEmpty())
  9736. {
  9737. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9738. }
  9739. AddToList(Hint, LongHint, L"|");
  9740. Item->Hint = Hint;
  9741. }
  9742. Parent->Add(Item.release());
  9743. }
  9744. }
  9745. AddMenuSeparator(Menu);
  9746. }
  9747. }
  9748. //---------------------------------------------------------------------------
  9749. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9750. {
  9751. Menu->Clear();
  9752. std::unique_ptr<TTBCustomItem> Item;
  9753. Item.reset(new TTBXItem(Owner));
  9754. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9755. Item->Options = Item->Options << tboDefault;
  9756. Menu->Add(Item.release());
  9757. AddMenuSeparator(Menu);
  9758. if (Terminal != NULL)
  9759. {
  9760. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9761. }
  9762. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9763. Item.reset(new TTBXItem(Owner));
  9764. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9765. Menu->Add(Item.release());
  9766. }
  9767. //---------------------------------------------------------------------------
  9768. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9769. {
  9770. bool Result = true;
  9771. try
  9772. {
  9773. if (Side == osRemote)
  9774. {
  9775. Terminal->ExceptionOnFail = true;
  9776. }
  9777. try
  9778. {
  9779. DirView(Side)->Path = Path;
  9780. }
  9781. __finally
  9782. {
  9783. if (Side == osRemote)
  9784. {
  9785. Terminal->ExceptionOnFail = false;
  9786. }
  9787. }
  9788. }
  9789. catch (Exception & E)
  9790. {
  9791. if ((Side != osRemote) || Terminal->Active)
  9792. {
  9793. ShowExtendedExceptionEx(Terminal, &E);
  9794. Result = false;
  9795. }
  9796. else
  9797. {
  9798. throw;
  9799. }
  9800. }
  9801. return Result;
  9802. }
  9803. //---------------------------------------------------------------------------
  9804. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9805. {
  9806. // Make sure there some feedback even when loading tiny local folders
  9807. TInstantOperationVisualizer Visualizer;
  9808. DirView(Side)->ReloadDirectory();
  9809. }
  9810. //---------------------------------------------------------------------------
  9811. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9812. {
  9813. if (Index == SessionsPageControl->TabIndex)
  9814. {
  9815. CloseSession();
  9816. }
  9817. else
  9818. {
  9819. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9820. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9821. TTerminalManager * Manager = TTerminalManager::Instance();
  9822. if (!Terminal->Active)
  9823. {
  9824. Manager->FreeTerminal(Terminal);
  9825. }
  9826. else
  9827. {
  9828. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9829. if (CanCloseQueue(Queue))
  9830. {
  9831. Manager->FreeTerminal(Terminal);
  9832. }
  9833. }
  9834. }
  9835. }
  9836. //---------------------------------------------------------------------------
  9837. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9838. {
  9839. CloseSessionTab(Index);
  9840. }
  9841. //---------------------------------------------------------------------------
  9842. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9843. {
  9844. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9845. {
  9846. TInstantOperationVisualizer Visualizer;
  9847. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9848. // before we create a new data object
  9849. ClipboardClear();
  9850. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9851. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9852. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9853. // Intermediate variable to WORKAROUND a crash in compiler
  9854. TObjectList * ClipboardFakeMonitors =
  9855. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9856. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9857. if (FClipboardDragDropFilesEx.get() == NULL)
  9858. {
  9859. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9860. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9861. }
  9862. FClipboardDragDropFilesEx->FileList->Clear();
  9863. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9864. FClipboardDragDropFilesEx->CopyToClipboard();
  9865. FClipboardTerminal = FTerminal;
  9866. // Need full paths, as cwd can be different once files are pasted
  9867. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9868. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9869. {
  9870. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9871. }
  9872. }
  9873. }
  9874. //---------------------------------------------------------------------------
  9875. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9876. {
  9877. if (OpenClipboard(0))
  9878. {
  9879. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9880. CloseClipboard();
  9881. }
  9882. }
  9883. //---------------------------------------------------------------------------
  9884. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9885. {
  9886. return !FClipboardFakeDirectory.IsEmpty();
  9887. }
  9888. //---------------------------------------------------------------------------
  9889. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9890. {
  9891. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9892. FClipboardFakeDirectory = UnicodeString();
  9893. FClipboardTerminal = NULL;
  9894. // Also called in Idle()
  9895. FClipboardFakeMonitors.reset(NULL);
  9896. }
  9897. //---------------------------------------------------------------------------
  9898. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9899. {
  9900. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9901. {
  9902. ClipboardStop();
  9903. }
  9904. }
  9905. //---------------------------------------------------------------------------
  9906. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9907. {
  9908. TTerminalManager * Manager = TTerminalManager::Instance();
  9909. Manager->ActiveTerminal = FClipboardTerminal;
  9910. TTransferOperationParam Params;
  9911. Params.TargetDirectory = TargetDirectory;
  9912. Params.DragDrop = DragDrop;
  9913. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9914. }
  9915. //---------------------------------------------------------------------------
  9916. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9917. {
  9918. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9919. // (as it pumps a Windows message queue while being shutted down)
  9920. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9921. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9922. {
  9923. // Can fail as it can be e.g. locked by AV, so we retry that later
  9924. bool Removed = RemoveDir(ApiPath(FileName));
  9925. try
  9926. {
  9927. if (!NonVisualDataModule->Busy)
  9928. {
  9929. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9930. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9931. }
  9932. }
  9933. __finally
  9934. {
  9935. if (!Removed)
  9936. {
  9937. RemoveDir(ApiPath(FileName));
  9938. }
  9939. }
  9940. }
  9941. }
  9942. //---------------------------------------------------------------------------
  9943. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9944. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9945. {
  9946. TFileMasks::TParams MaskParams;
  9947. MaskParams.Size = Size;
  9948. MaskParams.Modification = Modification;
  9949. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9950. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9951. {
  9952. bool ImplicitMatch;
  9953. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9954. !ImplicitMatch)
  9955. {
  9956. Color = Iter->Color;
  9957. break;
  9958. }
  9959. }
  9960. }
  9961. //---------------------------------------------------------------------------
  9962. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9963. {
  9964. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9965. if (!DirView->IsEditing())
  9966. {
  9967. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9968. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9969. // while searching
  9970. if (Key == VK_BACK)
  9971. {
  9972. if (!FIncrementalSearch.IsEmpty())
  9973. {
  9974. if (FIncrementalSearch.Length() == 1)
  9975. {
  9976. ResetIncrementalSearch();
  9977. }
  9978. else
  9979. {
  9980. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9981. IncrementalSearch(NewText, false, false);
  9982. }
  9983. Key = 0;
  9984. }
  9985. }
  9986. }
  9987. }
  9988. //---------------------------------------------------------------------------
  9989. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9990. {
  9991. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9992. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  9993. {
  9994. // Filter control sequences.
  9995. // When not searching yet, prefer use of the space for toggling file selection
  9996. // (so we cannot incrementally search for a string starting with a space).
  9997. if ((Key > VK_SPACE) ||
  9998. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9999. {
  10000. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10001. Key = 0;
  10002. }
  10003. }
  10004. }
  10005. //---------------------------------------------------------------------------
  10006. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10007. {
  10008. if (!FIncrementalSearch.IsEmpty())
  10009. {
  10010. FIncrementalSearch = L"";
  10011. DirView(osCurrent)->UpdateStatusBar();
  10012. }
  10013. }
  10014. //---------------------------------------------------------------------------
  10015. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10016. {
  10017. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10018. if (Item == NULL)
  10019. {
  10020. MessageBeep(MB_ICONHAND);
  10021. }
  10022. else
  10023. {
  10024. TCustomDirView * ADirView = DirView(osCurrent);
  10025. {
  10026. TAutoNestingCounter Guard(FIncrementalSearching);
  10027. ADirView->FocusItem(Item);
  10028. if (ADirView->NortonLike == nlOff)
  10029. {
  10030. if ((ADirView->Selected != Item) ||
  10031. (ADirView->SelCount > 1))
  10032. {
  10033. ADirView->ClearSelection();
  10034. ADirView->Selected = Item;
  10035. }
  10036. }
  10037. }
  10038. FIncrementalSearch = Text;
  10039. Item->MakeVisible(false);
  10040. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10041. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10042. ADirView->UpdateStatusBar();
  10043. }
  10044. }
  10045. //---------------------------------------------------------------------------
  10046. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10047. {
  10048. int Index = Item->Index;
  10049. if (!Reverse)
  10050. {
  10051. Index++;
  10052. if (Index >= Item->Owner->Count)
  10053. {
  10054. Index = 0;
  10055. }
  10056. }
  10057. else
  10058. {
  10059. Index--;
  10060. if (Index < 0)
  10061. {
  10062. Index = Item->Owner->Count - 1;
  10063. }
  10064. }
  10065. return Item->Owner->Item[Index];
  10066. }
  10067. //---------------------------------------------------------------------------
  10068. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10069. {
  10070. TCustomDirView * ADirView = DirView(osCurrent);
  10071. if (ADirView->Items->Count == 0)
  10072. {
  10073. return NULL;
  10074. }
  10075. else
  10076. {
  10077. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10078. TListItem * Item = CurrentItem;
  10079. if (SkipCurrent)
  10080. {
  10081. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10082. }
  10083. while (true)
  10084. {
  10085. bool Matches = false;
  10086. switch (WinConfiguration->PanelSearch)
  10087. {
  10088. case isNameStartOnly:
  10089. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10090. break;
  10091. case isName:
  10092. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10093. break;
  10094. case isAll:
  10095. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10096. int Index = 0;
  10097. while ((Index < ColCount) && !Matches)
  10098. {
  10099. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10100. if (Visible)
  10101. {
  10102. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10103. }
  10104. Index++;
  10105. }
  10106. break;
  10107. }
  10108. if (Matches)
  10109. {
  10110. return Item;
  10111. }
  10112. Item = GetNextFile(Item, Reverse);
  10113. if (Item == CurrentItem)
  10114. {
  10115. return NULL;
  10116. }
  10117. }
  10118. }
  10119. }
  10120. //---------------------------------------------------------------------------
  10121. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10122. {
  10123. ResetIncrementalSearch();
  10124. }
  10125. //---------------------------------------------------------------------------
  10126. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10127. {
  10128. if (Message.CharCode == VK_TAB)
  10129. {
  10130. if (!FIncrementalSearch.IsEmpty())
  10131. {
  10132. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10133. bool Reverse = Shift.Contains(ssShift);
  10134. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10135. Message.Result = 1;
  10136. return;
  10137. }
  10138. }
  10139. else if (Message.CharCode == VK_ESCAPE)
  10140. {
  10141. if (!FIncrementalSearch.IsEmpty())
  10142. {
  10143. ResetIncrementalSearch();
  10144. Message.Result = 1;
  10145. return;
  10146. }
  10147. }
  10148. TForm::Dispatch(&Message);
  10149. }
  10150. //---------------------------------------------------------------------------
  10151. void __fastcall TCustomScpExplorerForm::Deactivate()
  10152. {
  10153. TForm::Deactivate();
  10154. // E.g. when switching to an internal editor window
  10155. ResetIncrementalSearch();
  10156. }
  10157. //---------------------------------------------------------------------------
  10158. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10159. {
  10160. // When switching to another application
  10161. ResetIncrementalSearch();
  10162. }
  10163. //---------------------------------------------------------------------------
  10164. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10165. {
  10166. ResetIncrementalSearch();
  10167. }
  10168. //---------------------------------------------------------------------------
  10169. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10170. {
  10171. if (FIncrementalSearching <= 0)
  10172. {
  10173. ResetIncrementalSearch();
  10174. }
  10175. }
  10176. //---------------------------------------------------------------------------
  10177. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10178. {
  10179. CountClicksForWindowPrint(this);
  10180. }
  10181. //---------------------------------------------------------------------------
  10182. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10183. {
  10184. CenterReconnectToolbar();
  10185. }
  10186. //---------------------------------------------------------------------------
  10187. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10188. {
  10189. if (RemoteDirView->ItemFocused != NULL)
  10190. {
  10191. RemoteDirView->ItemFocused->Selected = true;
  10192. }
  10193. }
  10194. //---------------------------------------------------------------------------
  10195. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10196. {
  10197. if (!FQueueStatusUpdating)
  10198. {
  10199. bool Refresh;
  10200. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10201. {
  10202. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10203. }
  10204. else
  10205. {
  10206. if (FQueueFileList->GetCount() > 0)
  10207. {
  10208. FQueueFileList->Clear();
  10209. Refresh = true;
  10210. }
  10211. }
  10212. int Count = FQueueFileList->GetCount();
  10213. if (QueueFileList->Items->Count != Count)
  10214. {
  10215. DebugAssert(Refresh);
  10216. QueueFileList->Items->Count = Count;
  10217. }
  10218. if (Refresh)
  10219. {
  10220. QueueFileList->Invalidate();
  10221. }
  10222. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10223. }
  10224. }
  10225. //---------------------------------------------------------------------------
  10226. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10227. {
  10228. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10229. }
  10230. //---------------------------------------------------------------------------
  10231. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10232. {
  10233. // should be improved, once we do not refresh the list when switching between details of the same batch
  10234. if (QueueFileList->Items->Count > 0)
  10235. {
  10236. QueueFileList->Items->Item[0]->MakeVisible(false);
  10237. }
  10238. UpdateQueueFileList();
  10239. }
  10240. //---------------------------------------------------------------------------
  10241. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10242. {
  10243. Active = QueueView3->Focused() || QueueFileList->Focused();
  10244. }
  10245. //---------------------------------------------------------------------------
  10246. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10247. {
  10248. QueueLabelUpdateStatus();
  10249. }
  10250. //---------------------------------------------------------------------------
  10251. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10252. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10253. {
  10254. int State = FQueueFileList->GetState(Item->Index);
  10255. if (State == qfsProcessed)
  10256. {
  10257. Sender->Canvas->Font->Color = clGrayText;
  10258. }
  10259. }
  10260. //---------------------------------------------------------------------------
  10261. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10262. {
  10263. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10264. QueueFileList->Column[0]->Width =
  10265. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10266. }
  10267. //---------------------------------------------------------------------------
  10268. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10269. {
  10270. QueueFileListColumnAutoSize();
  10271. }
  10272. //---------------------------------------------------------------------------
  10273. void __fastcall TCustomScpExplorerForm::CloseApp()
  10274. {
  10275. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10276. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10277. // So we clear the flag here.
  10278. DebugAssert(NonVisualDataModule->Busy);
  10279. NonVisualDataModule->EndBusy();
  10280. try
  10281. {
  10282. Close();
  10283. }
  10284. __finally
  10285. {
  10286. NonVisualDataModule->StartBusy();
  10287. }
  10288. }