CustomScpExplorer.cpp 359 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935
  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->DDAllowMove = !WinConfiguration->DDDisableMove;
  932. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  933. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  934. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  935. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  936. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  937. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  938. {
  939. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  940. // selection is not redrawn automatically when RowSelect changes
  941. RemoteDirView->Invalidate();
  942. }
  943. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  944. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  945. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  946. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  947. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  948. UpdateSessionsPageControlHeight();
  949. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  950. UpdateToolbarDisplayMode();
  951. UpdateTransferList();
  952. if (Terminal != NULL)
  953. {
  954. TransferPresetAutoSelect();
  955. }
  956. UpdateQueueView();
  957. UpdateControls();
  958. // this can be called even before constuctor finishes.
  959. if (FEditorManager != NULL)
  960. {
  961. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  962. }
  963. // this can be called even before constuctor finishes.
  964. if (FLocalEditors != NULL)
  965. {
  966. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  967. {
  968. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  969. }
  970. }
  971. if (ComponentVisible[fcCustomCommandsBand])
  972. {
  973. UpdateCustomCommandsToolbar();
  974. }
  975. // show only when keeping queue items forever,
  976. // otherwise, its enough to have in in the context menu
  977. QueueDeleteAllDoneQueueToolbarItem->Visible =
  978. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  979. if (FFileColorsCurrent != WinConfiguration->FileColors)
  980. {
  981. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  982. FFileColorsCurrent = WinConfiguration->FileColors;
  983. FileColorsChanged();
  984. }
  985. }
  986. //---------------------------------------------------------------------------
  987. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  988. {
  989. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  990. DirView->Invalidate();
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  994. {
  995. DoFileColorsChanged(RemoteDirView);
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  999. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1000. void * /*Arg*/)
  1001. {
  1002. if (Token != NULL)
  1003. {
  1004. TForm * Editor = dynamic_cast<TForm*>(Token);
  1005. DebugAssert(Editor != NULL);
  1006. ReconfigureEditorForm(Editor);
  1007. }
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1011. {
  1012. WinConfiguration->DDTransferConfirmation = asOn;
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1016. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1017. {
  1018. // noop
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1022. TTransferDirection Direction, TTransferType Type, bool Temp,
  1023. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1024. bool Confirm, bool DragDrop, int Options)
  1025. {
  1026. bool Result = true;
  1027. DebugAssert(Terminal && Terminal->Active);
  1028. // these parameters are known in advance
  1029. int Params =
  1030. FLAGMASK(Type == ttMove, cpDelete);
  1031. bool ToTemp = (Temp && (Direction == tdToLocal));
  1032. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1033. {
  1034. bool DisableNewerOnly =
  1035. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1036. ToTemp;
  1037. Options |=
  1038. FLAGMASK(ToTemp, coTemp) |
  1039. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1040. coDoNotShowAgain;
  1041. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1042. int CopyParamAttrs = (Direction == tdToRemote ?
  1043. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1044. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1045. int OutputOptions =
  1046. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1047. cooDoNotShowAgain);
  1048. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1049. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1050. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1051. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1052. if (Result)
  1053. {
  1054. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1055. {
  1056. if (DragDrop)
  1057. {
  1058. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1059. {
  1060. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1061. NULL, 0, EnableDDTransferConfirmation, NULL);
  1062. }
  1063. WinConfiguration->DDTransferConfirmation = asOff;
  1064. }
  1065. else
  1066. {
  1067. WinConfiguration->ConfirmTransferring = false;
  1068. }
  1069. }
  1070. else
  1071. {
  1072. // User explicitly unchecked "do not show again",
  1073. // so show him the dialog the next time
  1074. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1075. {
  1076. WinConfiguration->DDTransferConfirmation = asOn;
  1077. }
  1078. }
  1079. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1080. }
  1081. }
  1082. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1083. {
  1084. Configuration->Usage->Inc(L"TransfersOnBackground");
  1085. // these parameter are known only after transfer dialog
  1086. Params |=
  1087. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1088. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1089. Result = false;
  1090. ClearTransferSourceSelection(Direction);
  1091. }
  1092. return Result;
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1096. {
  1097. if (FOnFileOperationFinished != NULL)
  1098. {
  1099. FOnFileOperationFinished(UnicodeString(), true);
  1100. }
  1101. else
  1102. {
  1103. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1104. if (HasDirView[Side])
  1105. {
  1106. DirView(Side)->SelectAll(smNone);
  1107. }
  1108. }
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1112. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1113. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1114. int Params)
  1115. {
  1116. DebugAssert(Queue != NULL);
  1117. bool SingleFile = false;
  1118. if (FileList->Count == 1)
  1119. {
  1120. if (Direction == tdToRemote)
  1121. {
  1122. UnicodeString FileName = FileList->Strings[0];
  1123. SingleFile = FileExists(ApiPath(FileName));
  1124. }
  1125. else
  1126. {
  1127. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1128. SingleFile = !File->IsDirectory;
  1129. }
  1130. }
  1131. TQueueItem * QueueItem;
  1132. if (Direction == tdToRemote)
  1133. {
  1134. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1135. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1136. }
  1137. else
  1138. {
  1139. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1140. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1141. }
  1142. AddQueueItem(Queue, QueueItem, Terminal);
  1143. }
  1144. //---------------------------------------------------------------------------
  1145. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1146. {
  1147. if (Queue->IsEmpty)
  1148. {
  1149. Terminal->QueueOperationStart = Now();
  1150. }
  1151. Queue->AddItem(QueueItem);
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1155. {
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TCustomScpExplorerForm::InitControls()
  1159. {
  1160. DebugAssert(FDocks != NULL);
  1161. for (int Index = 0; Index < ComponentCount; Index++)
  1162. {
  1163. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1164. if ((Dock != NULL) && (Dock->Tag == 0))
  1165. {
  1166. FDocks->Add(Dock);
  1167. }
  1168. }
  1169. CollectItemsWithTextDisplayMode(this);
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1173. {
  1174. ConfigurationChanged();
  1175. QueuePanel->Height =
  1176. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1177. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1178. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1179. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1180. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1181. QueueFileList->Height =
  1182. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1183. if (QueueFileList->Visible)
  1184. {
  1185. AdjustQueueLayout();
  1186. }
  1187. UpdateCustomCommandsToolbar();
  1188. }
  1189. //---------------------------------------------------------------------------
  1190. void __fastcall TCustomScpExplorerForm::StoreParams()
  1191. {
  1192. int APixelsPerInch = GetControlPixelsPerInch(this);
  1193. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1194. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1195. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1196. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1197. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1198. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1199. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1200. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1204. {
  1205. if (!FFormRestored)
  1206. {
  1207. FFormRestored = true;
  1208. RestoreFormParams();
  1209. }
  1210. TForm::CreateParams(Params);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1214. {
  1215. DebugAssert(FDocks != NULL);
  1216. for (int Index = 0; Index < FDocks->Count; Index++)
  1217. {
  1218. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1219. }
  1220. }
  1221. //---------------------------------------------------------------------------
  1222. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1223. {
  1224. SetDockAllowDrag(true);
  1225. while (!ButtonsStr.IsEmpty())
  1226. {
  1227. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1228. UnicodeString Name = CutToChar(S, L'=', true);
  1229. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1230. {
  1231. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1232. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1233. {
  1234. while (!S.IsEmpty())
  1235. {
  1236. UnicodeString S2 = CutToChar(S, L',', true);
  1237. UnicodeString Name = CutToChar(S2, L':', true);
  1238. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1239. {
  1240. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1241. if (SameText(GetToolbarItemName(Item), Name))
  1242. {
  1243. // forward compatibility
  1244. UnicodeString S3 = CutToChar(S2, L':', true);
  1245. bool Visible = StrToIntDef(S3, 0);
  1246. Item->Visible = Visible;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1254. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1258. {
  1259. UnicodeString Result;
  1260. SetDockAllowDrag(true);
  1261. Result = ::GetToolbarsLayoutStr(this);
  1262. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1263. return Result;
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1267. {
  1268. UnicodeString Result;
  1269. if (Item->Action != NULL)
  1270. {
  1271. Result = Item->Action->Name;
  1272. Result = RemoveSuffix(Result, L"Action", true);
  1273. }
  1274. else
  1275. {
  1276. Result = Item->Name;
  1277. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1278. Result = RemoveSuffix(Result, L"Item", true);
  1279. }
  1280. return Result;
  1281. }
  1282. //---------------------------------------------------------------------------
  1283. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1284. {
  1285. UnicodeString Result;
  1286. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1287. {
  1288. UnicodeString ToolbarStr;
  1289. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1290. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1291. {
  1292. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1293. {
  1294. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1295. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1296. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1297. // and save the changes here only.
  1298. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1299. {
  1300. UnicodeString Name = GetToolbarItemName(Item);
  1301. DebugAssert(Name.Pos(L"TBX") == 0);
  1302. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1303. }
  1304. }
  1305. }
  1306. if (!ToolbarStr.IsEmpty())
  1307. {
  1308. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1309. }
  1310. }
  1311. return Result;
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1315. {
  1316. DebugAssert(FProgressForm == NULL);
  1317. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1318. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1319. FProgressForm->DeleteLocalToRecycleBin =
  1320. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1321. FProgressForm->DeleteRemoteToRecycleBin =
  1322. (Terminal != NULL) &&
  1323. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1324. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1325. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1326. LockWindow();
  1327. // Actually, do not know what hides the progress once the operation finishes
  1328. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1329. SetTaskbarListProgressState(TBPF_NORMAL);
  1330. }
  1331. //---------------------------------------------------------------------------
  1332. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1333. {
  1334. UnlockWindow();
  1335. SAFE_DESTROY(FProgressForm);
  1336. SetQueueProgress();
  1337. }
  1338. //---------------------------------------------------------------------------
  1339. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1340. TFileOperationProgressType & ProgressData)
  1341. {
  1342. // Download to temporary local directory
  1343. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1344. {
  1345. bool Continue = true;
  1346. FPendingTempSpaceWarn = false;
  1347. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1348. if (!Continue)
  1349. {
  1350. Abort();
  1351. }
  1352. }
  1353. // operation is being executed and we still didn't show up progress form
  1354. if (ProgressData.InProgress && !FProgressForm)
  1355. {
  1356. CreateProgressForm(NULL);
  1357. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1358. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1359. }
  1360. // operation is finished (or terminated), so we hide progress form
  1361. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1362. {
  1363. DestroyProgressForm();
  1364. if (ProgressData.Operation == foCalculateSize)
  1365. {
  1366. // When calculating size before transfer, the abort caused by
  1367. // cancel flag set due to "MoveToQueue" below,
  1368. // is not propagated back to us in ExecuteFileOperation,
  1369. // as it is silently swallowed.
  1370. // So we explicitly (re)throw it here.
  1371. if (FMoveToQueue)
  1372. {
  1373. Abort();
  1374. }
  1375. }
  1376. else
  1377. {
  1378. if ((ProgressData.Cancel == csContinue) &&
  1379. !FAutoOperation)
  1380. {
  1381. OperationComplete(ProgressData.StartTime);
  1382. }
  1383. }
  1384. }
  1385. if (FProgressForm &&
  1386. // Can happen only during synchronization, when ending one of the operations
  1387. ProgressData.InProgress)
  1388. {
  1389. FProgressForm->SetProgressData(ProgressData);
  1390. DebugAssert(ProgressData.InProgress);
  1391. SetTaskbarListProgressValue(&ProgressData);
  1392. if (FProgressForm->Cancel > csContinue)
  1393. {
  1394. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1395. if (FProgressForm->Cancel == csCancelFile)
  1396. {
  1397. FProgressForm->ClearCancel();
  1398. }
  1399. // cancel cancels even the move
  1400. FMoveToQueue = false;
  1401. }
  1402. else if (FProgressForm->MoveToQueue)
  1403. {
  1404. FMoveToQueue = true;
  1405. ProgressData.SetCancelAtLeast(csCancel);
  1406. }
  1407. if ((FTransferResumeList != NULL) &&
  1408. ProgressData.InProgress &&
  1409. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1410. !ProgressData.FullFileName.IsEmpty())
  1411. {
  1412. if ((FTransferResumeList->Count == 0) ||
  1413. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1414. {
  1415. // note that we do not recognize directories from files here
  1416. FTransferResumeList->Add(ProgressData.FullFileName);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1423. const TDateTime & StartTime)
  1424. {
  1425. if (GUIConfiguration->BeepOnFinish &&
  1426. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1427. {
  1428. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1429. DWORD Sound;
  1430. if (!ExtractFileExt(BeepSound).IsEmpty())
  1431. {
  1432. Sound = SND_FILENAME;
  1433. }
  1434. else
  1435. {
  1436. Sound = SND_ALIAS;
  1437. }
  1438. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1439. }
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1443. TFileOperationProgressType & ProgressData)
  1444. {
  1445. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1446. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1447. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1448. FileOperationProgress(ProgressData);
  1449. }
  1450. //---------------------------------------------------------------------------
  1451. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1452. {
  1453. UnicodeString Result;
  1454. if (FProgressForm != NULL)
  1455. {
  1456. Result = FProgressForm->ProgressStr();
  1457. }
  1458. return Result;
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1462. bool DragDrop)
  1463. {
  1464. return (!DragDrop && (DropSourceControl == NULL)) ||
  1465. (DropSourceControl == DirView(osOther));
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1469. TFileOperation Operation, TOperationSide Side,
  1470. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1471. TOnceDoneOperation & OnceDoneOperation)
  1472. {
  1473. if (!FAutoOperation)
  1474. {
  1475. // no selection on "/upload", form servers only as event handler
  1476. // (it is not displayed)
  1477. if (PanelOperation(Side, FDragDropOperation) &&
  1478. Visible && (Operation != foCalculateSize) &&
  1479. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1480. {
  1481. if (FOnFileOperationFinished != NULL)
  1482. {
  1483. FOnFileOperationFinished(FileName, Success);
  1484. }
  1485. else
  1486. {
  1487. TCustomDirView * DView = DirView(Side);
  1488. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1489. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1490. // this can happen when local drive is unplugged in the middle of the operation
  1491. if (Item != NULL)
  1492. {
  1493. if (Success) Item->Selected = false;
  1494. DView->MakeProgressVisible(Item);
  1495. }
  1496. }
  1497. }
  1498. if ((Operation == foCopy) || (Operation == foMove))
  1499. {
  1500. DebugAssert(!IsLocalBrowserMode()); // TODO
  1501. if (Side == osLocal)
  1502. {
  1503. Configuration->Usage->Inc(L"UploadedFiles");
  1504. }
  1505. else
  1506. {
  1507. Configuration->Usage->Inc(L"DownloadedFiles");
  1508. }
  1509. }
  1510. }
  1511. if (Success && (FSynchronizeController != NULL))
  1512. {
  1513. DebugAssert(!IsSideLocalBrowser(osRemote));
  1514. if (Operation == foCopy)
  1515. {
  1516. DebugAssert(Side == osLocal);
  1517. FSynchronizeController->LogOperation(soUpload, FileName);
  1518. }
  1519. else if (Operation == foDelete)
  1520. {
  1521. DebugAssert(Side == osRemote);
  1522. FSynchronizeController->LogOperation(soDelete, FileName);
  1523. }
  1524. }
  1525. if (FProgressForm)
  1526. {
  1527. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1528. }
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1532. TFileOperation Operation, TOperationSide Side,
  1533. bool Temp, const UnicodeString & FileName, Boolean Success,
  1534. TOnceDoneOperation & OnceDoneOperation)
  1535. {
  1536. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1537. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1538. OnceDoneOperation);
  1539. }
  1540. //---------------------------------------------------------------------------
  1541. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1542. {
  1543. return false;
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1547. {
  1548. return false;
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1552. {
  1553. return NULL;
  1554. }
  1555. //---------------------------------------------------------------------------
  1556. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1557. {
  1558. DebugAssert(GetSide(Side) == osRemote);
  1559. DebugUsedParam(Side);
  1560. return RemoteDirView;
  1561. }
  1562. //---------------------------------------------------------------------------
  1563. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1564. {
  1565. DebugAssert(GetSide(Side) == osRemote);
  1566. DebugUsedParam(Side);
  1567. return RemoteDriveView;
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1571. {
  1572. DebugAssert(GetSide(Side) == osRemote);
  1573. DebugUsedParam(Side);
  1574. return (Terminal != NULL) && Terminal->Active;
  1575. }
  1576. //---------------------------------------------------------------------------
  1577. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1578. TOperationSide Side, int FilesOnly)
  1579. {
  1580. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1584. TOperationSide Side, int FilesOnly)
  1585. {
  1586. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. struct THistoryItemData
  1590. {
  1591. short int Side;
  1592. short int Index;
  1593. };
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1596. {
  1597. DirView(Side)->HistoryGo(Index);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1601. {
  1602. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1603. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1604. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1608. bool Back)
  1609. {
  1610. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1611. {
  1612. TCustomDirView * DView = DirView(Side);
  1613. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1614. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1615. if (ICount > 10)
  1616. {
  1617. ICount = 10;
  1618. }
  1619. Menu->Items->Clear();
  1620. THistoryItemData Data;
  1621. Data.Side = Side;
  1622. for (short int i = 1; i <= ICount; i++)
  1623. {
  1624. TTBCustomItem * Item = new TTBXItem(Menu);
  1625. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1626. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1627. Item->Hint = DView->HistoryPath[Data.Index];
  1628. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1629. Item->Tag = *reinterpret_cast<int*>(&Data);
  1630. Item->OnClick = HistoryItemClick;
  1631. Menu->Items->Add(Item);
  1632. }
  1633. }
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1637. TOperationSide Side, bool Back)
  1638. {
  1639. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1640. {
  1641. // workaround
  1642. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1643. // operator new allocates memory in Pascal code, but calls inline
  1644. // contructor in C++, leading in problems, the function does
  1645. // both in Pascal code
  1646. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1647. UpdateHistoryMenu(Side, Back);
  1648. }
  1649. return FHistoryMenu[Side == osLocal][Back];
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1653. TCustomDirView *Sender)
  1654. {
  1655. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1656. UpdateHistoryMenu(Side, true);
  1657. UpdateHistoryMenu(Side, false);
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1661. {
  1662. // remote custom commands can be executed only if the server supports shell commands
  1663. // or have secondary shell
  1664. return (FTerminal != NULL) && FTerminal->Active && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1668. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1669. {
  1670. int Result;
  1671. TFileCustomCommand RemoteCustomCommand;
  1672. TLocalCustomCommand LocalCustomCommand;
  1673. TFileCustomCommand * NonInteractiveCustomCommand =
  1674. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1675. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1676. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1677. if (FLAGCLEAR(Command.Params, ccLocal))
  1678. {
  1679. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1680. // custom command that does not operate with files can be executed anytime ...
  1681. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1682. {
  1683. // ... but do not show such command in remote file menu
  1684. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1685. {
  1686. Result = AllowedState;
  1687. }
  1688. else
  1689. {
  1690. Result = -1;
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1696. {
  1697. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1698. }
  1699. else
  1700. {
  1701. Result = -1;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. {
  1707. // custom command that does not operate with files can be executed anytime
  1708. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1709. {
  1710. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1711. }
  1712. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1713. {
  1714. if ((ListType == ccltAll) || (ListType == ccltFile))
  1715. {
  1716. // special case is "diff"-style command that can be executed over any side,
  1717. // if we have both sides
  1718. Result =
  1719. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1720. // directly (instead of EnableSelectedOperation) to pass
  1721. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1722. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1723. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1724. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1725. }
  1726. else if (ListType == ccltBoth)
  1727. {
  1728. DebugAssert(!IsLocalBrowserMode());
  1729. Result = 1;
  1730. }
  1731. else
  1732. {
  1733. Result = -1;
  1734. }
  1735. }
  1736. else
  1737. {
  1738. if ((ListType == ccltAll) ||
  1739. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1740. {
  1741. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. }
  1749. return Result;
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1753. TStrings * FileList, const TCustomCommandType & ACommand,
  1754. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1755. {
  1756. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1757. {
  1758. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1759. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1760. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1761. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1762. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1763. bool Capture =
  1764. FLAGSET(ACommand.Params, ccShowResults) ||
  1765. FLAGSET(ACommand.Params, ccCopyResults) ||
  1766. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1767. TCaptureOutputEvent OutputEvent = NULL;
  1768. DebugAssert(FCapturedLog == NULL);
  1769. if (Capture)
  1770. {
  1771. FCapturedLog = new TStringList();
  1772. OutputEvent = TerminalCaptureLog;
  1773. }
  1774. try
  1775. {
  1776. if (!RemoteCustomCommand.IsFileCommand(Command))
  1777. {
  1778. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1779. OutputEvent);
  1780. }
  1781. else
  1782. {
  1783. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1784. }
  1785. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1786. {
  1787. if (FLAGSET(ACommand.Params, ccCopyResults))
  1788. {
  1789. CopyToClipboard(FCapturedLog);
  1790. }
  1791. if (FLAGSET(ACommand.Params, ccShowResults))
  1792. {
  1793. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1794. }
  1795. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1796. {
  1797. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1798. }
  1799. }
  1800. }
  1801. __finally
  1802. {
  1803. SAFE_DESTROY(FCapturedLog);
  1804. }
  1805. }
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1809. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1810. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1811. {
  1812. DebugAssert(!IsLocalBrowserMode());
  1813. TStrings * LocalFileList = NULL;
  1814. TStrings * RemoteFileList = NULL;
  1815. TStrings * RemoteFileListFull = NULL;
  1816. try
  1817. {
  1818. if (LocalFileCommand)
  1819. {
  1820. if (ALocalFileList == NULL)
  1821. {
  1822. DebugAssert(HasDirView[osLocal]);
  1823. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1824. // directly (instead of EnableSelectedOperation) to pass
  1825. // false to FocusedFileOnlyWhenFocused
  1826. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1827. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1828. }
  1829. else
  1830. {
  1831. LocalFileList = ALocalFileList;
  1832. }
  1833. if (FileListCommand)
  1834. {
  1835. if (LocalFileList->Count != 1)
  1836. {
  1837. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1838. }
  1839. }
  1840. else
  1841. {
  1842. if ((LocalFileList->Count != 1) &&
  1843. (FileList->Count != 1) &&
  1844. (LocalFileList->Count != FileList->Count))
  1845. {
  1846. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1847. }
  1848. }
  1849. }
  1850. UnicodeString RootTempDir;
  1851. UnicodeString TempDir;
  1852. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1853. if (!RemoteFiles)
  1854. {
  1855. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1856. }
  1857. try
  1858. {
  1859. TDateTimes RemoteFileTimes;
  1860. if (RemoteFiles)
  1861. {
  1862. RemoteFileList = FileList;
  1863. }
  1864. else
  1865. {
  1866. RemoteFileList = new TStringList();
  1867. TMakeLocalFileListParams MakeFileListParam;
  1868. MakeFileListParam.FileList = RemoteFileList;
  1869. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1870. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1871. MakeFileListParam.Recursive =
  1872. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1873. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1874. if (!MakeFileListParam.Recursive)
  1875. {
  1876. RemoteFileTimes.clear();
  1877. RemoteFileListFull = new TStringList();
  1878. MakeFileListParam.FileList = RemoteFileListFull;
  1879. MakeFileListParam.Recursive = true;
  1880. MakeFileListParam.IncludeDirs = false;
  1881. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1882. }
  1883. else
  1884. {
  1885. RemoteFileListFull = RemoteFileList;
  1886. }
  1887. }
  1888. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1889. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1890. if (!NonBlocking)
  1891. {
  1892. int Count;
  1893. if (FileListCommand)
  1894. {
  1895. Count = 1;
  1896. }
  1897. else if (LocalFileCommand)
  1898. {
  1899. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1900. }
  1901. else
  1902. {
  1903. Count = RemoteFileList->Count;
  1904. }
  1905. Progress.Start(foCustomCommand, osRemote, Count);
  1906. DebugAssert(FProgressForm != NULL);
  1907. FProgressForm->ReadOnly = true;
  1908. }
  1909. try
  1910. {
  1911. if (FileListCommand)
  1912. {
  1913. UnicodeString LocalFile;
  1914. // MakeFileList does not delimit filenames
  1915. UnicodeString FileList = MakeFileList(RemoteFileList);
  1916. if (LocalFileCommand)
  1917. {
  1918. DebugAssert(LocalFileList->Count == 1);
  1919. LocalFile = LocalFileList->Strings[0];
  1920. }
  1921. TLocalCustomCommand CustomCommand(Data,
  1922. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1923. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1924. if (NonBlocking)
  1925. {
  1926. DebugAssert(!POutput);
  1927. ExecuteShellChecked(ShellCommand);
  1928. }
  1929. else
  1930. {
  1931. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1932. }
  1933. }
  1934. else if (LocalFileCommand)
  1935. {
  1936. if (LocalFileList->Count == 1)
  1937. {
  1938. UnicodeString LocalFile = LocalFileList->Strings[0];
  1939. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1940. {
  1941. UnicodeString FileName = RemoteFileList->Strings[Index];
  1942. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1943. Progress.SetFile(FileNameForProgress);
  1944. TLocalCustomCommand CustomCommand(Data,
  1945. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1946. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1947. TOnceDoneOperation OnceDoneOperation;
  1948. // Do not unselect anything, as it won't work with two panels anyway
  1949. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1950. }
  1951. }
  1952. else if (RemoteFileList->Count == 1)
  1953. {
  1954. UnicodeString FileName = RemoteFileList->Strings[0];
  1955. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1956. {
  1957. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1958. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1959. Progress.SetFile(LocalFileNameOnly);
  1960. TLocalCustomCommand CustomCommand(
  1961. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1962. FileName, LocalFileName, L"");
  1963. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1964. TOnceDoneOperation OnceDoneOperation;
  1965. // Do not unselect anything, as it won't work with two panels anyway
  1966. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1967. }
  1968. }
  1969. else
  1970. {
  1971. if (LocalFileList->Count != RemoteFileList->Count)
  1972. {
  1973. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1974. }
  1975. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1976. {
  1977. UnicodeString FileName = RemoteFileList->Strings[Index];
  1978. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1979. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1980. Progress.SetFile(LocalFileNameOnly); // sic
  1981. TLocalCustomCommand CustomCommand(
  1982. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1983. FileName, LocalFileName, L"");
  1984. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1985. TOnceDoneOperation OnceDoneOperation;
  1986. // Do not unselect anything, as it won't work with two panels anyway
  1987. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1994. {
  1995. UnicodeString FileName = RemoteFileList->Strings[Index];
  1996. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1997. Progress.SetFile(FileNameForProgress);
  1998. TLocalCustomCommand CustomCommand(Data,
  1999. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2000. FileName, L"", L"");
  2001. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2002. TOnceDoneOperation OnceDoneOperation;
  2003. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2004. }
  2005. }
  2006. }
  2007. __finally
  2008. {
  2009. if (!NonBlocking)
  2010. {
  2011. Progress.Stop();
  2012. }
  2013. }
  2014. DebugAssert(!FAutoOperation);
  2015. if (!RemoteFiles)
  2016. {
  2017. TempDir = IncludeTrailingBackslash(TempDir);
  2018. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2019. {
  2020. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2021. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2022. // Skip directories, process only nested files.
  2023. // The check is redundant as FileAge fails for directories anyway.
  2024. !DirectoryExists(FileName))
  2025. {
  2026. UnicodeString RemoteDir =
  2027. UnixExtractFileDir(
  2028. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2029. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2030. TDateTime NewTime;
  2031. if (FileAge(FileName, NewTime) &&
  2032. (NewTime != RemoteFileTimes[Index]))
  2033. {
  2034. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2035. TemporaryFileCopyParam(CopyParam);
  2036. CopyParam.FileMask = L"";
  2037. FAutoOperation = true;
  2038. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2039. TemporaryFilesList->Add(FileName);
  2040. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2041. }
  2042. }
  2043. }
  2044. }
  2045. }
  2046. __finally
  2047. {
  2048. FAutoOperation = false;
  2049. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2050. {
  2051. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2052. }
  2053. }
  2054. }
  2055. __finally
  2056. {
  2057. if (RemoteFileList != FileList)
  2058. {
  2059. delete RemoteFileList;
  2060. }
  2061. if (LocalFileList != ALocalFileList)
  2062. {
  2063. delete LocalFileList;
  2064. }
  2065. if (RemoteFileListFull != RemoteFileList)
  2066. {
  2067. delete RemoteFileListFull;
  2068. }
  2069. }
  2070. }
  2071. //---------------------------------------------------------------------------
  2072. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2073. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2074. bool FileListCommand, UnicodeString * POutput)
  2075. {
  2076. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2077. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2078. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2079. {
  2080. UnicodeString FileName = SelectedFileList->Strings[Index];
  2081. if (DirectoryExists(FileName))
  2082. {
  2083. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2084. {
  2085. LocalFileList->Add(FileName);
  2086. }
  2087. if (FLAGSET(ACommand.Params, ccRecursive))
  2088. {
  2089. TMakeLocalFileListParams MakeFileListParam;
  2090. MakeFileListParam.FileList = LocalFileList.get();
  2091. MakeFileListParam.FileTimes = NULL;
  2092. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2093. MakeFileListParam.Recursive = true;
  2094. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2095. }
  2096. }
  2097. else
  2098. {
  2099. LocalFileList->Add(FileName);
  2100. }
  2101. }
  2102. UnicodeString RemotePath;
  2103. if (Terminal != NULL)
  2104. {
  2105. RemotePath = Terminal->CurrentDirectory;
  2106. }
  2107. if (FileListCommand)
  2108. {
  2109. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2110. TLocalCustomCommand CustomCommand(
  2111. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2112. L"", L"", FileList);
  2113. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2114. }
  2115. else
  2116. {
  2117. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2118. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2119. DebugAssert(FProgressForm != NULL);
  2120. FProgressForm->ReadOnly = true;
  2121. try
  2122. {
  2123. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2124. {
  2125. UnicodeString FileName = LocalFileList->Strings[Index];
  2126. Progress.SetFile(FileName);
  2127. TLocalCustomCommand CustomCommand(
  2128. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2129. FileName, L"", L"");
  2130. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2131. TOnceDoneOperation OnceDoneOperation;
  2132. Progress.Finish(FileName, true, OnceDoneOperation);
  2133. }
  2134. }
  2135. __finally
  2136. {
  2137. Progress.Stop();
  2138. }
  2139. }
  2140. }
  2141. //---------------------------------------------------------------------------
  2142. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2143. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2144. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2145. {
  2146. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2147. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2148. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2149. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2150. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2151. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2152. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2153. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2154. std::unique_ptr<UnicodeString> POutput;
  2155. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2156. FLAGSET(ACommand.Params, ccCopyResults))
  2157. {
  2158. POutput.reset(new UnicodeString());
  2159. }
  2160. if (!LocalCustomCommand.IsFileCommand(Command))
  2161. {
  2162. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2163. }
  2164. // remote files?
  2165. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2166. {
  2167. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2168. }
  2169. // local files
  2170. else
  2171. {
  2172. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2173. }
  2174. if (POutput.get() != NULL)
  2175. {
  2176. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2177. int P = POutput->Pos(sLineBreak);
  2178. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2179. {
  2180. POutput->SetLength(P - 1);
  2181. }
  2182. // Copy even empty output to clipboard
  2183. if (FLAGSET(ACommand.Params, ccCopyResults))
  2184. {
  2185. CopyToClipboard(*POutput);
  2186. }
  2187. // But do not show an empty message box.
  2188. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2189. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2190. !POutput->IsEmpty())
  2191. {
  2192. TClipboardHandler ClipboardHandler;
  2193. ClipboardHandler.Text = *POutput;
  2194. TMessageParams Params;
  2195. TQueryButtonAlias Aliases[1];
  2196. Aliases[0].Button = qaRetry;
  2197. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2198. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2199. Params.Aliases = Aliases;
  2200. Params.AliasesCount = LENOF(Aliases);
  2201. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2202. }
  2203. }
  2204. }
  2205. //---------------------------------------------------------------------------
  2206. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2207. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2208. {
  2209. TCustomCommandData Data;
  2210. UnicodeString Site;
  2211. UnicodeString RemotePath;
  2212. if (Terminal != NULL)
  2213. {
  2214. Data = TCustomCommandData(Terminal);
  2215. Site = Terminal->SessionData->SessionKey;
  2216. RemotePath = Terminal->CurrentDirectory;
  2217. }
  2218. UnicodeString HelpKeyword = ACommand.HomePage;
  2219. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2220. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2221. {
  2222. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2223. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2224. {
  2225. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2226. }
  2227. else
  2228. {
  2229. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2230. }
  2231. if (!DoCustomCommandOptionsDialog(
  2232. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2233. {
  2234. Abort();
  2235. }
  2236. }
  2237. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2238. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2239. {
  2240. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2241. }
  2242. else
  2243. {
  2244. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2245. }
  2246. }
  2247. //---------------------------------------------------------------------------
  2248. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2249. const TCustomCommandType & Command)
  2250. {
  2251. DebugAssert(FCustomCommandLocalFileList != NULL);
  2252. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2253. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2254. TStrings * LocalFileList = new TStringList();
  2255. TStrings * RemoteFileList = new TStringList();
  2256. try
  2257. {
  2258. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2259. {
  2260. LocalFileList->Clear();
  2261. LocalFileList->AddObject(
  2262. FCustomCommandLocalFileList->Strings[Index],
  2263. FCustomCommandLocalFileList->Objects[Index]);
  2264. RemoteFileList->Clear();
  2265. RemoteFileList->AddObject(
  2266. FCustomCommandRemoteFileList->Strings[Index],
  2267. FCustomCommandRemoteFileList->Objects[Index]);
  2268. CustomCommand(RemoteFileList, Command, LocalFileList);
  2269. }
  2270. }
  2271. __finally
  2272. {
  2273. delete LocalFileList;
  2274. delete RemoteFileList;
  2275. }
  2276. }
  2277. //---------------------------------------------------------------------------
  2278. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2279. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2280. {
  2281. delete FCustomCommandLocalFileList;
  2282. delete FCustomCommandRemoteFileList;
  2283. // takeover ownership,
  2284. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2285. FCustomCommandLocalFileList = LocalFileList;
  2286. FCustomCommandRemoteFileList = RemoteFileList;
  2287. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2288. if (Button != NULL)
  2289. {
  2290. FCustomCommandMenu->Items->Clear();
  2291. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2292. MenuPopup(FCustomCommandMenu, Button);
  2293. }
  2294. else
  2295. {
  2296. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2297. }
  2298. }
  2299. //---------------------------------------------------------------------------
  2300. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2301. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2302. {
  2303. DebugAssert(FCapturedLog != NULL);
  2304. if ((OutputType == cotOutput) || (OutputType == cotError))
  2305. {
  2306. FCapturedLog->Add(AddedLine);
  2307. }
  2308. }
  2309. //---------------------------------------------------------------------------
  2310. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2311. TOperationSide Side)
  2312. {
  2313. return
  2314. (Side == osOther) &&
  2315. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2316. }
  2317. //---------------------------------------------------------------------------
  2318. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2319. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2320. {
  2321. TTBItemOptions O;
  2322. O = Item->Options;
  2323. TCustomDirView * DView = DirView(Side);
  2324. if ((DView->ItemFocused != NULL) &&
  2325. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2326. // when resolving links is disabled, default action is to enter the directory,
  2327. // no matter what DoubleClickAction is configured to
  2328. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2329. // Can only Edit files, but can Open/Copy even directories
  2330. ((DoubleClickAction != dcaEdit) ||
  2331. !DView->ItemIsDirectory(DView->ItemFocused)))
  2332. {
  2333. Item->Options = O << tboDefault;
  2334. }
  2335. else
  2336. {
  2337. Item->Options = O >> tboDefault;
  2338. }
  2339. }
  2340. //---------------------------------------------------------------------------
  2341. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2342. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2343. {
  2344. TCustomDirView * DView = DirView(Side);
  2345. TListItem * Item = DView->ItemFocused;
  2346. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2347. EnableFocusedOperation[Side])
  2348. {
  2349. TPoint ClientPoint;
  2350. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2351. TPoint(0, 0) : MousePos;
  2352. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2353. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2354. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2355. }
  2356. }
  2357. //---------------------------------------------------------------------------
  2358. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2359. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2360. {
  2361. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2362. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2363. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2364. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2365. Handled = true;
  2366. }
  2367. //---------------------------------------------------------------------------
  2368. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2369. {
  2370. }
  2371. //---------------------------------------------------------------------------
  2372. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2373. {
  2374. DebugAssert(FErrorList == NULL);
  2375. if (WinConfiguration->ContinueOnError)
  2376. {
  2377. FErrorList = new TStringList();
  2378. Configuration->Usage->Inc(L"ContinuationsOnError");
  2379. }
  2380. NonVisualDataModule->StartBusy();
  2381. }
  2382. //---------------------------------------------------------------------------
  2383. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2384. {
  2385. NonVisualDataModule->EndBusy();
  2386. if (FErrorList)
  2387. {
  2388. HandleErrorList(FErrorList);
  2389. }
  2390. }
  2391. //---------------------------------------------------------------------------
  2392. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2393. const TCopyParamType & CopyParam)
  2394. {
  2395. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2396. {
  2397. Configuration->Usage->Inc(L"FileMaskUses");
  2398. }
  2399. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2400. {
  2401. Configuration->Usage->Inc(L"OperationMaskUses");
  2402. }
  2403. }
  2404. //---------------------------------------------------------------------------
  2405. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2406. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2407. {
  2408. DebugAssert(!IsLocalBrowserMode());
  2409. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2410. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2411. TTransferOperationParam DefaultParam;
  2412. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2413. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2414. switch (Param.Queue)
  2415. {
  2416. case asOn:
  2417. CopyParam.Queue = true;
  2418. break;
  2419. case asOff:
  2420. CopyParam.Queue = false;
  2421. break;
  2422. case asAuto:
  2423. default:
  2424. // keep default
  2425. break;
  2426. }
  2427. bool Result =
  2428. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2429. if (Result)
  2430. {
  2431. DebugAssert(Terminal);
  2432. bool SelectionRestored = false;
  2433. TCustomDirView * DView = NULL;
  2434. if (HasDirView[Side])
  2435. {
  2436. DView = DirView(Side);
  2437. DView->SaveSelection();
  2438. DView->SaveSelectedNames();
  2439. }
  2440. UpdateCopyParamCounters(CopyParam);
  2441. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2442. DebugAssert(FTransferResumeList == NULL);
  2443. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2444. FMoveToQueue = false;
  2445. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2446. try
  2447. {
  2448. TStrings * PermanentFileList;
  2449. std::unique_ptr<TStrings> PermanentFileListOwner;
  2450. try
  2451. {
  2452. if (Side == osLocal)
  2453. {
  2454. PermanentFileList = FileList;
  2455. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2456. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2457. if (Operation == foMove)
  2458. {
  2459. ReloadLocalDirectory();
  2460. if (DView != NULL)
  2461. {
  2462. DView->RestoreSelection();
  2463. }
  2464. SelectionRestored = true;
  2465. }
  2466. }
  2467. else
  2468. {
  2469. // Clone the file list as it may refer to current directory files,
  2470. // which get destroyed, when the source directory is reloaded after foMove operation.
  2471. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2472. // But for a hotfix, we are not going to do such a big change.
  2473. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2474. PermanentFileList = PermanentFileListOwner.get();
  2475. try
  2476. {
  2477. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2478. }
  2479. __finally
  2480. {
  2481. if (Operation == foMove)
  2482. {
  2483. if (DView != NULL)
  2484. {
  2485. DView->RestoreSelection();
  2486. }
  2487. SelectionRestored = true;
  2488. }
  2489. ReloadLocalDirectory(Param.TargetDirectory);
  2490. }
  2491. }
  2492. }
  2493. catch (EAbort &)
  2494. {
  2495. if (FMoveToQueue)
  2496. {
  2497. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2498. DebugAssert(CopyParam.TransferSkipList == NULL);
  2499. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2500. if (TransferResumeList->Count > 0)
  2501. {
  2502. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2503. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2504. }
  2505. CopyParam.TransferSkipList = TransferResumeList.release();
  2506. // not really needed, just to keep it consistent with TransferResumeList
  2507. FTransferResumeList = NULL;
  2508. FMoveToQueue = false;
  2509. Configuration->Usage->Inc("MovesToBackground");
  2510. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2511. ClearTransferSourceSelection(Direction);
  2512. }
  2513. throw;
  2514. }
  2515. }
  2516. __finally
  2517. {
  2518. if (!SelectionRestored && (DView != NULL))
  2519. {
  2520. DView->DiscardSavedSelection();
  2521. }
  2522. FTransferResumeList = NULL;
  2523. }
  2524. }
  2525. return Result;
  2526. }
  2527. //---------------------------------------------------------------------------
  2528. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2529. TOperationSide Side, TStrings * FileList, void * Param)
  2530. {
  2531. DebugAssert(FileList->Count);
  2532. // We deliberately do not toggle alternative flag (Param), but use OR,
  2533. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2534. // shortcut of CurrentDeleteAlternativeAction
  2535. bool Alternative =
  2536. bool(Param) || UseAlternativeFunction();
  2537. bool Recycle;
  2538. if (IsSideLocalBrowser(Side))
  2539. {
  2540. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2541. }
  2542. else
  2543. {
  2544. Recycle =
  2545. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2546. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2547. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2548. }
  2549. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2550. if (!Result)
  2551. {
  2552. UnicodeString Query;
  2553. if (FileList->Count == 1)
  2554. {
  2555. if (IsSideLocalBrowser(Side))
  2556. {
  2557. Query = ExtractFileName(FileList->Strings[0]);
  2558. }
  2559. else
  2560. {
  2561. Query = UnixExtractFileName(FileList->Strings[0]);
  2562. }
  2563. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2564. }
  2565. else
  2566. {
  2567. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2568. }
  2569. TMessageParams Params(mpNeverAskAgainCheck);
  2570. Params.ImageName = L"Delete file";
  2571. unsigned int Answer =
  2572. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2573. if (Answer == qaNeverAskAgain)
  2574. {
  2575. Result = true;
  2576. if (Recycle)
  2577. {
  2578. WinConfiguration->ConfirmRecycling = false;
  2579. }
  2580. else
  2581. {
  2582. WinConfiguration->ConfirmDeleting = false;
  2583. }
  2584. }
  2585. else
  2586. {
  2587. Result = (Answer == qaOK);
  2588. }
  2589. }
  2590. if (Result)
  2591. {
  2592. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2593. }
  2594. return Result;
  2595. }
  2596. //---------------------------------------------------------------------------
  2597. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2598. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2599. {
  2600. TAutoBatch AutoBatch(this);
  2601. bool Result;
  2602. if ((Operation == foCopy) || (Operation == foMove))
  2603. {
  2604. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2605. }
  2606. else if (Operation == foRename)
  2607. {
  2608. DebugAssert(DirView(Side)->ItemFocused);
  2609. DirView(Side)->ItemFocused->EditCaption();
  2610. Result = true;
  2611. }
  2612. else if (Operation == foDelete)
  2613. {
  2614. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2615. }
  2616. else if (Operation == foSetProperties)
  2617. {
  2618. DirView(osRemote)->SaveSelectedNames();
  2619. Result = SetProperties(Side, FileList);
  2620. }
  2621. else if (Operation == foCustomCommand)
  2622. {
  2623. DebugAssert(Param);
  2624. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2625. DirView(osRemote)->SaveSelectedNames();
  2626. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2627. CustomCommand(FileList, *Command, NULL);
  2628. Result = true;
  2629. }
  2630. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2631. {
  2632. DebugAssert(!IsSideLocalBrowser(Side));
  2633. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2634. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2635. }
  2636. else if (Operation == foLock)
  2637. {
  2638. DebugAssert(!IsSideLocalBrowser(Side));
  2639. LockFiles(FileList, true);
  2640. Result = true;
  2641. }
  2642. else if (Operation == foUnlock)
  2643. {
  2644. DebugAssert(!IsSideLocalBrowser(Side));
  2645. LockFiles(FileList, false);
  2646. Result = true;
  2647. }
  2648. else
  2649. {
  2650. DebugFail();
  2651. }
  2652. return Result;
  2653. }
  2654. //---------------------------------------------------------------------------
  2655. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2656. {
  2657. if (Side == osCurrent)
  2658. {
  2659. Side = FCurrentSide;
  2660. }
  2661. return Side;
  2662. }
  2663. //---------------------------------------------------------------------------
  2664. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2665. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2666. {
  2667. Side = GetSide(Side);
  2668. bool Result;
  2669. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2670. try
  2671. {
  2672. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2673. }
  2674. __finally
  2675. {
  2676. delete FileList;
  2677. }
  2678. return Result;
  2679. }
  2680. //---------------------------------------------------------------------------
  2681. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2682. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2683. bool NoConfirmation, void * Param)
  2684. {
  2685. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2686. {
  2687. if ((Operation == foCopy) || (Operation == foMove))
  2688. {
  2689. DebugAssert(!IsLocalBrowserMode());
  2690. if (GetSide(Side) == osLocal)
  2691. {
  2692. Configuration->Usage->Inc(L"UploadsCommand");
  2693. }
  2694. else
  2695. {
  2696. Configuration->Usage->Inc(L"DownloadsCommand");
  2697. }
  2698. }
  2699. }
  2700. }
  2701. //---------------------------------------------------------------------------
  2702. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2703. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2704. {
  2705. TTransferOperationParam Param;
  2706. if ((WinConfiguration->Interface != ifCommander) ||
  2707. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2708. {
  2709. Flags &= ~cocShortCutHint;
  2710. }
  2711. TCustomDirView * DView = DirView(Side);
  2712. Param.Options =
  2713. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2714. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2715. if (FLAGSET(Flags, cocQueue))
  2716. {
  2717. Param.Queue = asOn;
  2718. }
  2719. else if (FLAGSET(Flags, cocNonQueue))
  2720. {
  2721. Param.Queue = asOff;
  2722. }
  2723. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2724. }
  2725. //---------------------------------------------------------------------------
  2726. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2727. {
  2728. try
  2729. {
  2730. if (ErrorList->Count)
  2731. {
  2732. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2733. if (MessageDialog(Message, qtError,
  2734. qaOK | qaCancel, HELP_NONE) == qaOK)
  2735. {
  2736. unsigned int Answer;
  2737. int Index = 0;
  2738. do
  2739. {
  2740. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2741. TQueryButtonAlias Aliases[2];
  2742. Aliases[0].Button = qaYes;
  2743. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2744. Aliases[1].Button = qaNo;
  2745. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2746. TMessageParams Params;
  2747. Params.Aliases = Aliases;
  2748. Params.AliasesCount = LENOF(Aliases);
  2749. Answer = MoreMessageDialog(
  2750. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2751. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2752. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2753. qaOK, HELP_NONE, &Params);
  2754. if (Answer == qaNo)
  2755. {
  2756. Index++;
  2757. }
  2758. if (Answer == qaYes)
  2759. {
  2760. Index--;
  2761. }
  2762. }
  2763. while (Answer != qaOK);
  2764. }
  2765. }
  2766. }
  2767. __finally
  2768. {
  2769. TStrings * List = ErrorList;
  2770. ErrorList = NULL;
  2771. for (int i = 0; i < List->Count; i++)
  2772. {
  2773. delete List->Objects[i];
  2774. }
  2775. delete List;
  2776. }
  2777. }
  2778. //---------------------------------------------------------------------------
  2779. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2780. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2781. {
  2782. // needed for checking filemasks, as there's no directory object
  2783. // associated with the file object
  2784. File->FullFileName = FullFileName;
  2785. TFileMasks::TParams MaskParams;
  2786. MaskParams.Size = File->Size;
  2787. MaskParams.Modification = File->Modification;
  2788. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2789. }
  2790. //---------------------------------------------------------------------------
  2791. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2792. {
  2793. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2794. Side = GetSide(Side);
  2795. TCustomDirView * DView = DirView(Side);
  2796. TListItem * FocusedItem = DView->ItemFocused;
  2797. UnicodeString Name;
  2798. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2799. {
  2800. Name = DView->ItemFileName(FocusedItem);
  2801. }
  2802. else
  2803. {
  2804. Name = LoadStr(NEW_FILE);
  2805. }
  2806. UnicodeString Names = Name;
  2807. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2808. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2809. HELP_EDIT_NEW, History.get(), true))
  2810. {
  2811. while (!Names.IsEmpty())
  2812. {
  2813. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2814. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2815. UnicodeString TargetFileName;
  2816. UnicodeString LocalFileName;
  2817. UnicodeString RootTempDir;
  2818. UnicodeString TempDir;
  2819. UnicodeString RemoteDirectory;
  2820. bool ExistingFile = false;
  2821. if (!IsSideLocalBrowser(Side))
  2822. {
  2823. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2824. TRemoteFile * File = NULL;
  2825. if (FTerminal->FileExists(Name, &File) &&
  2826. !File->IsDirectory)
  2827. {
  2828. try
  2829. {
  2830. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2831. ExistingFile = true;
  2832. }
  2833. __finally
  2834. {
  2835. delete File;
  2836. }
  2837. }
  2838. if (!ExistingFile)
  2839. {
  2840. RemoteDirectory = UnixExtractFilePath(Name);
  2841. TemporaryDirectoryForRemoteFiles(
  2842. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2843. TargetFileName = UnixExtractFileName(Name);
  2844. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2845. LocalFileName = TempDir +
  2846. // We probably do not want to trim the VMS version here
  2847. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if (ExtractFilePath(Name).IsEmpty())
  2853. {
  2854. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2855. }
  2856. else
  2857. {
  2858. LocalFileName = ExpandFileName(Name);
  2859. }
  2860. TargetFileName = ExtractFileName(Name);
  2861. }
  2862. if (!ExistingFile)
  2863. {
  2864. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2865. if (NewFile)
  2866. {
  2867. int File = FileCreate(ApiPath(LocalFileName));
  2868. if (File < 0)
  2869. {
  2870. if (!RootTempDir.IsEmpty())
  2871. {
  2872. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2873. }
  2874. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2875. }
  2876. else
  2877. {
  2878. FileClose(File);
  2879. }
  2880. }
  2881. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2882. const TEditorData * ExternalEditor = NULL;
  2883. TFileMasks::TParams MaskParams; // size not known
  2884. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2885. false, MaskParams);
  2886. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2887. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2888. }
  2889. }
  2890. }
  2891. }
  2892. //---------------------------------------------------------------------------
  2893. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2894. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2895. {
  2896. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2897. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2898. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2899. return
  2900. ((ExecuteFileBy == efInternalEditor)) ||
  2901. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2902. }
  2903. //---------------------------------------------------------------------------
  2904. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2905. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2906. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2907. UnicodeString RemoteDirectory, bool NewFile)
  2908. {
  2909. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2910. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2911. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2912. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2913. Side = GetSide(Side);
  2914. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2915. if (!IsSideLocalBrowser(Side))
  2916. {
  2917. Data->Terminal = Terminal;
  2918. Data->Queue = Queue;
  2919. Data->SessionData = CloneCurrentSessionData();
  2920. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2921. Data->RemoteDirectory = RemoteDirectory;
  2922. Data->SessionName = Terminal->SessionData->SessionName;
  2923. Data->LocalRootDirectory = LocalRootDirectory;
  2924. Data->OriginalFileName = OriginalFileName;
  2925. Data->Command = L""; // will be changed later for external editor
  2926. }
  2927. if (ExecuteFileBy == efInternalEditor)
  2928. {
  2929. if (!IsSideLocalBrowser(Side))
  2930. {
  2931. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2932. L" - " + Terminal->SessionData->SessionName;
  2933. TForm * Editor;
  2934. try
  2935. {
  2936. TNotifyEvent OnFileChanged = NULL;
  2937. TNotifyEvent OnSaveAll = NULL;
  2938. TAnyModifiedEvent OnAnyModified = NULL;
  2939. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2940. if (Terminal->IsCapable[fcBackgroundTransfers])
  2941. {
  2942. OnFileChanged = FEditorManager->FileChanged;
  2943. OnSaveAll = SaveAllInternalEditors;
  2944. OnAnyModified = AnyInternalEditorModified;
  2945. }
  2946. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2947. FEditorManager->FileReload, FEditorManager->FileClosed,
  2948. OnSaveAll, OnAnyModified,
  2949. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2950. }
  2951. catch(...)
  2952. {
  2953. if (!LocalRootDirectory.IsEmpty())
  2954. {
  2955. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2956. }
  2957. throw;
  2958. }
  2959. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2960. }
  2961. else
  2962. {
  2963. DebugAssert(!FStandaloneEditing);
  2964. TForm * Editor =
  2965. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2966. SaveAllInternalEditors, AnyInternalEditorModified,
  2967. L"", false, SessionColor, -1, NewFile);
  2968. FLocalEditors->Add(Editor);
  2969. }
  2970. }
  2971. else
  2972. {
  2973. HANDLE Process;
  2974. if (ExecuteFileBy == efExternalEditor)
  2975. {
  2976. UnicodeString Program, Params, Dir;
  2977. Data->Command = ExternalEditor->ExternalEditor;
  2978. ReformatFileNameCommand(Data->Command);
  2979. SplitCommand(Data->Command, Program, Params, Dir);
  2980. Params = ExpandFileNameCommand(Params, FileName);
  2981. Program = ExpandEnvironmentVariables(Program);
  2982. if (!ExecuteShell(Program, Params, Process))
  2983. {
  2984. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2985. }
  2986. }
  2987. else
  2988. {
  2989. DebugAssert(!IsSideLocalBrowser(Side));
  2990. if (!ExecuteShell(FileName, L"", Process))
  2991. {
  2992. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2993. }
  2994. }
  2995. if (IsSideLocalBrowser(Side) ||
  2996. ((ExecuteFileBy == efShell) &&
  2997. !WinConfiguration->Editor.SDIShellEditor) ||
  2998. ((ExecuteFileBy == efExternalEditor) &&
  2999. !ExternalEditor->SDIExternalEditor))
  3000. {
  3001. // no need for handle
  3002. if (Process != NULL)
  3003. {
  3004. DebugCheck(CloseHandle(Process));
  3005. }
  3006. Process = INVALID_HANDLE_VALUE;
  3007. }
  3008. else
  3009. {
  3010. if (Process == NULL)
  3011. {
  3012. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3013. }
  3014. }
  3015. if (!IsSideLocalBrowser(Side))
  3016. {
  3017. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3018. }
  3019. }
  3020. }
  3021. //---------------------------------------------------------------------------
  3022. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3023. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3024. void * /*Arg*/)
  3025. {
  3026. if (Token != NULL)
  3027. {
  3028. EditorFormFileSave(static_cast<TForm *>(Token));
  3029. }
  3030. }
  3031. //---------------------------------------------------------------------------
  3032. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3033. {
  3034. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3035. {
  3036. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3037. }
  3038. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3039. }
  3040. //---------------------------------------------------------------------------
  3041. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3042. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3043. void * Arg)
  3044. {
  3045. if ((Token != NULL) &&
  3046. IsEditorFormModified(static_cast<TForm *>(Token)))
  3047. {
  3048. *static_cast<bool *>(Arg) = true;
  3049. }
  3050. }
  3051. //---------------------------------------------------------------------------
  3052. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3053. TObject * /*Sender*/, bool & Modified)
  3054. {
  3055. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3056. {
  3057. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3058. {
  3059. Modified = true;
  3060. }
  3061. }
  3062. if (!Modified)
  3063. {
  3064. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3065. }
  3066. }
  3067. //---------------------------------------------------------------------------
  3068. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3069. {
  3070. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3071. }
  3072. //---------------------------------------------------------------------------
  3073. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3074. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3075. UnicodeString & Result, UnicodeString & RootDirectory)
  3076. {
  3077. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3078. {
  3079. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3080. Result = RootDirectory;
  3081. }
  3082. else
  3083. {
  3084. RootDirectory = L"";
  3085. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3086. Result = IncludeTrailingBackslash(Result);
  3087. }
  3088. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3089. {
  3090. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3091. }
  3092. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3093. {
  3094. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3095. {
  3096. RemoteDirectory.Delete(1, 1);
  3097. }
  3098. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3099. }
  3100. if (!ForceDirectories(ApiPath(Result)))
  3101. {
  3102. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3103. }
  3104. }
  3105. //---------------------------------------------------------------------------
  3106. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3107. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3108. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3109. {
  3110. DebugAssert(!IsLocalBrowserMode());
  3111. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3112. if (ForceText)
  3113. {
  3114. CopyParam.TransferMode = tmAscii;
  3115. }
  3116. TemporaryFileCopyParam(CopyParam);
  3117. if (AllFiles)
  3118. {
  3119. CopyParam.IncludeFileMask = TFileMasks();
  3120. }
  3121. if (TempDir.IsEmpty())
  3122. {
  3123. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3124. }
  3125. DebugAssert(!FAutoOperation);
  3126. FAutoOperation = AutoOperation;
  3127. Terminal->ExceptionOnFail = true;
  3128. try
  3129. {
  3130. try
  3131. {
  3132. // turn off confirmations, as for MDI editors we may possibly download
  3133. // the same file over
  3134. Terminal->CopyToLocal(
  3135. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3136. if (GetTargetNames)
  3137. {
  3138. for (int i = 0; i < FileList->Count; i++)
  3139. {
  3140. FileList->Strings[i] =
  3141. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3142. }
  3143. }
  3144. }
  3145. catch(...)
  3146. {
  3147. if (!RootTempDir.IsEmpty())
  3148. {
  3149. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3150. }
  3151. throw;
  3152. }
  3153. }
  3154. __finally
  3155. {
  3156. FAutoOperation = false;
  3157. Terminal->ExceptionOnFail = false;
  3158. }
  3159. }
  3160. //---------------------------------------------------------------------------
  3161. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3162. {
  3163. // Do not waste time checking for default editor list the next time,
  3164. // or testing if default editor is not notepad.
  3165. bool TryNextTime = false;
  3166. UnicodeString UsageState;
  3167. if (!WinConfiguration->EditorList->IsDefaultList())
  3168. {
  3169. UsageState = "H";
  3170. }
  3171. else
  3172. {
  3173. UnicodeString Executable;
  3174. UnicodeString ExecutableDescription;
  3175. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3176. {
  3177. UnicodeString Message =
  3178. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3179. unsigned int Answer =
  3180. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3181. if (Answer != qaOK)
  3182. {
  3183. UsageState = "R";
  3184. }
  3185. else
  3186. {
  3187. UsageState = "A";
  3188. TEditorData EditorData;
  3189. EditorData.Editor = edExternal;
  3190. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3191. EditorData.ExternalEditorOptionsAutodetect();
  3192. TEditorList EditorList;
  3193. EditorList = *WinConfiguration->EditorList;
  3194. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3195. WinConfiguration->EditorList = &EditorList;
  3196. }
  3197. }
  3198. }
  3199. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3200. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3201. }
  3202. //---------------------------------------------------------------------------
  3203. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3204. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3205. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3206. {
  3207. if (ExecuteFileBy == efDefaultEditor)
  3208. {
  3209. if (!WinConfiguration->OfferedEditorAutoConfig)
  3210. {
  3211. EditorAutoConfig();
  3212. }
  3213. const TEditorPreferences * Editor =
  3214. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3215. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3216. {
  3217. ExecuteFileBy = efInternalEditor;
  3218. ExternalEditor = NULL;
  3219. }
  3220. else if (Editor->Data->Editor == edOpen)
  3221. {
  3222. ExecuteFileBy = efShell;
  3223. ExternalEditor = NULL;
  3224. }
  3225. else
  3226. {
  3227. ExecuteFileBy = efExternalEditor;
  3228. ExternalEditor = Editor->Data;
  3229. }
  3230. }
  3231. }
  3232. //---------------------------------------------------------------------------
  3233. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3234. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3235. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3236. {
  3237. UnicodeString OriginalFileName;
  3238. UnicodeString LocalRootDirectory;
  3239. UnicodeString RemoteDirectory;
  3240. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3241. IsSideLocalBrowser(Side), MaskParams);
  3242. UnicodeString Counter;
  3243. UnicodeString LocalFileName;
  3244. bool Handled = false;
  3245. if (!IsSideLocalBrowser(Side))
  3246. {
  3247. // We need to trim VMS version here, so that we use name without version
  3248. // when uploading back to create a new version of the file
  3249. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3250. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3251. TObject * Token = NULL;
  3252. UnicodeString LocalDirectory;
  3253. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3254. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3255. LocalDirectory))
  3256. {
  3257. if (Token != NULL)
  3258. {
  3259. TForm * Form = dynamic_cast<TForm *>(Token);
  3260. if (Form->WindowState == wsMinimized)
  3261. {
  3262. ShowWindow(Form->Handle, SW_RESTORE);
  3263. }
  3264. else
  3265. {
  3266. Form->SetFocus();
  3267. }
  3268. Handled = true;
  3269. }
  3270. else
  3271. {
  3272. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3273. }
  3274. }
  3275. if (!Handled)
  3276. {
  3277. TStringList * FileList1 = new TStringList();
  3278. try
  3279. {
  3280. FileList1->AddObject(FullFileName, Object);
  3281. TemporarilyDownloadFiles(FileList1,
  3282. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3283. LocalRootDirectory, LocalDirectory, true, true, true);
  3284. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3285. }
  3286. __finally
  3287. {
  3288. delete FileList1;
  3289. }
  3290. switch (ExecuteFileBy)
  3291. {
  3292. case efShell:
  3293. Counter = "RemoteFilesExecuted";
  3294. break;
  3295. case efInternalEditor:
  3296. Counter = "RemoteFilesOpenedInInternalEditor";
  3297. break;
  3298. case efExternalEditor:
  3299. Counter = "RemoteFilesOpenedInExternalEditor";
  3300. break;
  3301. default:
  3302. DebugFail();
  3303. }
  3304. }
  3305. }
  3306. else
  3307. {
  3308. LocalFileName = FullFileName;
  3309. OriginalFileName = ExtractFileName(FullFileName);
  3310. switch (ExecuteFileBy)
  3311. {
  3312. case efShell:
  3313. Counter = "LocalFilesExecuted";
  3314. break;
  3315. case efInternalEditor:
  3316. Counter = "LocalFilesOpenedInInternalEditor";
  3317. break;
  3318. case efExternalEditor:
  3319. Counter = "LocalFilesOpenedInExternalEditor";
  3320. break;
  3321. default:
  3322. DebugFail();
  3323. }
  3324. }
  3325. if (!Handled)
  3326. {
  3327. Configuration->Usage->Inc(Counter);
  3328. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3329. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3330. }
  3331. }
  3332. //---------------------------------------------------------------------------
  3333. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3334. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3335. bool AllSelected, bool OnFocused)
  3336. {
  3337. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3338. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3339. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3340. Side = GetSide(Side);
  3341. TCustomDirView * DView = DirView(Side);
  3342. TStrings * FileList =
  3343. AllSelected ?
  3344. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3345. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3346. try
  3347. {
  3348. DebugAssert(AllSelected || (FileList->Count == 1));
  3349. for (int i = 0; i < FileList->Count; i++)
  3350. {
  3351. UnicodeString ListFileName = FileList->Strings[i];
  3352. UnicodeString FileNameOnly =
  3353. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3354. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3355. if (!DView->ItemIsDirectory(Item))
  3356. {
  3357. UnicodeString FullFileName;
  3358. if (!IsSideLocalBrowser(Side))
  3359. {
  3360. FullFileName = DirView(Side)->Path + ListFileName;
  3361. }
  3362. else
  3363. {
  3364. FullFileName = ListFileName;
  3365. }
  3366. TFileMasks::TParams MaskParams;
  3367. MaskParams.Size = DView->ItemFileSize(Item);
  3368. TDateTimePrecision Precision;
  3369. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3370. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3371. FileList->Objects[i], MaskParams);
  3372. }
  3373. }
  3374. }
  3375. __finally
  3376. {
  3377. delete FileList;
  3378. }
  3379. }
  3380. //---------------------------------------------------------------------------
  3381. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3382. {
  3383. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3384. CopyParam.FileNameCase = ncNoChange;
  3385. CopyParam.PreserveRights = false;
  3386. CopyParam.PreserveReadOnly = false;
  3387. CopyParam.ReplaceInvalidChars = true;
  3388. CopyParam.IncludeFileMask = TFileMasks();
  3389. CopyParam.NewerOnly = false;
  3390. CopyParam.FileMask = L"";
  3391. }
  3392. //---------------------------------------------------------------------------
  3393. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3394. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3395. {
  3396. TTerminalManager * Manager = TTerminalManager::Instance();
  3397. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3398. {
  3399. if (!NonVisualDataModule->Busy)
  3400. {
  3401. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3402. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3403. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3404. if (Data->Terminal == NULL)
  3405. {
  3406. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3407. if (SameSiteTerminal != NULL)
  3408. {
  3409. UnicodeString Message =
  3410. FMTLOAD(EDIT_SESSION_REATTACH,
  3411. (FileNameOnly, Data->SessionName, FileNameOnly));
  3412. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3413. {
  3414. Data->Terminal = Terminal;
  3415. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3416. Data->SessionName = Terminal->SessionData->SessionName;
  3417. // We might also overwrite session data
  3418. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3419. }
  3420. else
  3421. {
  3422. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3423. Abort();
  3424. }
  3425. }
  3426. }
  3427. // foreground session should reconnect itself
  3428. else if (Terminal != Data->Terminal)
  3429. {
  3430. UnicodeString Message =
  3431. MainInstructions(
  3432. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3433. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3434. {
  3435. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3436. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3437. }
  3438. else
  3439. {
  3440. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3441. Abort();
  3442. }
  3443. }
  3444. }
  3445. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3446. {
  3447. Configuration->Usage->Inc(L"EditInactiveSession");
  3448. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3449. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3450. (ExtractFileName(FileName), Data->SessionName)));
  3451. }
  3452. }
  3453. TStrings * FileList = new TStringList();
  3454. try
  3455. {
  3456. FileList->Add(FileName);
  3457. // consider using the same settings (preset) as when the file was downloaded
  3458. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3459. TemporaryFileCopyParam(CopyParam);
  3460. if (Data->ForceText)
  3461. {
  3462. CopyParam.TransferMode = tmAscii;
  3463. }
  3464. // so i do not need to worry if masking algorithm works in all cases
  3465. // ("" means "copy file name", no masking is actually done)
  3466. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3467. {
  3468. CopyParam.FileMask = L"";
  3469. }
  3470. else
  3471. {
  3472. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3473. }
  3474. DebugAssert(Data->Queue != NULL);
  3475. int Params = cpNoConfirmation | cpTemporary;
  3476. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3477. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3478. QueueItem->CompleteEvent = UploadCompleteEvent;
  3479. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3480. }
  3481. __finally
  3482. {
  3483. delete FileList;
  3484. }
  3485. }
  3486. //---------------------------------------------------------------------------
  3487. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3488. const UnicodeString FileName, const TEditedFileData * Data)
  3489. {
  3490. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3491. DebugAssert(!NonVisualDataModule->Busy);
  3492. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3493. {
  3494. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3495. (ExtractFileName(FileName), Data->SessionName)));
  3496. }
  3497. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3498. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3499. NonVisualDataModule->StartBusy();
  3500. try
  3501. {
  3502. std::unique_ptr<TRemoteFile> File;
  3503. UnicodeString RemoteFileName =
  3504. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3505. FTerminal->ExceptionOnFail = true;
  3506. try
  3507. {
  3508. TRemoteFile * AFile = NULL;
  3509. FTerminal->ReadFile(RemoteFileName, AFile);
  3510. File.reset(AFile);
  3511. if (!File->HaveFullFileName)
  3512. {
  3513. File->FullFileName = RemoteFileName;
  3514. }
  3515. }
  3516. __finally
  3517. {
  3518. FTerminal->ExceptionOnFail = false;
  3519. }
  3520. std::unique_ptr<TStrings> FileList(new TStringList());
  3521. FileList->AddObject(RemoteFileName, File.get());
  3522. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3523. UnicodeString TempDir = ExtractFilePath(FileName);
  3524. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3525. TempDir, true, true, true);
  3526. // sanity check, the target file name should be still the same
  3527. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3528. }
  3529. __finally
  3530. {
  3531. NonVisualDataModule->EndBusy();
  3532. // it actually may not exist anymore...
  3533. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3534. }
  3535. }
  3536. //---------------------------------------------------------------------------
  3537. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3538. const TEditedFileData * Data, bool & KeepOpen)
  3539. {
  3540. // Command is set for external editors only (not for "shell" open).
  3541. if (!Data->Command.IsEmpty())
  3542. {
  3543. bool AnyFound = false;
  3544. bool AnyMDI = false;
  3545. bool AnyNonMDI = false;
  3546. bool AnyDetect = false;
  3547. TEditorList * EditorList = new TEditorList();
  3548. try
  3549. {
  3550. *EditorList = *WinConfiguration->EditorList;
  3551. for (int i = 0; i < EditorList->Count; i++)
  3552. {
  3553. const TEditorPreferences * Editor = EditorList->Editors[i];
  3554. if ((Editor->Data->Editor == edExternal) &&
  3555. (Editor->Data->ExternalEditor == Data->Command))
  3556. {
  3557. AnyFound = true;
  3558. if (Editor->Data->SDIExternalEditor)
  3559. {
  3560. AnyNonMDI = true;
  3561. if (Editor->Data->DetectMDIExternalEditor)
  3562. {
  3563. AnyDetect = true;
  3564. }
  3565. }
  3566. else
  3567. {
  3568. AnyMDI = true;
  3569. }
  3570. }
  3571. }
  3572. bool EnableMDI = false;
  3573. bool DisableDetect = false;
  3574. if (AnyMDI)
  3575. {
  3576. KeepOpen = true;
  3577. if (AnyNonMDI)
  3578. {
  3579. // there is at least one instance of the editor with MDI support enabled,
  3580. // and one with disabled, enable it for all instances
  3581. EnableMDI = true;
  3582. }
  3583. }
  3584. else if (AnyFound && !AnyDetect)
  3585. {
  3586. // at least once instance found but all have MDI autodetection disabled
  3587. // => close the file (default action)
  3588. }
  3589. else
  3590. {
  3591. // no instance of the editor has MDI support enabled
  3592. TMessageParams Params;
  3593. if (AnyFound)
  3594. {
  3595. // there is at least one instance of the editor
  3596. Params.Params |= mpNeverAskAgainCheck;
  3597. }
  3598. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3599. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3600. switch (Answer)
  3601. {
  3602. case qaNeverAskAgain:
  3603. DisableDetect = true;
  3604. break;
  3605. case qaNo:
  3606. EnableMDI = true;
  3607. KeepOpen = true;
  3608. break;
  3609. }
  3610. }
  3611. if (AnyFound && (EnableMDI || DisableDetect))
  3612. {
  3613. bool Changed = false;
  3614. for (int i = 0; i < EditorList->Count; i++)
  3615. {
  3616. const TEditorPreferences * Editor = EditorList->Editors[i];
  3617. if ((Editor->Data->Editor == edExternal) &&
  3618. (Editor->Data->ExternalEditor == Data->Command) &&
  3619. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3620. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3621. {
  3622. Changed = true;
  3623. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3624. if (EnableMDI)
  3625. {
  3626. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3627. }
  3628. if (DisableDetect)
  3629. {
  3630. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3631. }
  3632. EditorList->Change(i, UpdatedEditor);
  3633. }
  3634. }
  3635. if (Changed)
  3636. {
  3637. WinConfiguration->EditorList = EditorList;
  3638. }
  3639. }
  3640. }
  3641. __finally
  3642. {
  3643. delete EditorList;
  3644. }
  3645. }
  3646. else
  3647. {
  3648. // "open" case
  3649. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3650. qaOK, HELP_APP_EARLY_CLOSED);
  3651. }
  3652. }
  3653. //---------------------------------------------------------------------------
  3654. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3655. {
  3656. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3657. }
  3658. //---------------------------------------------------------------------------
  3659. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3660. {
  3661. SideEnter(osRemote);
  3662. }
  3663. //---------------------------------------------------------------------------
  3664. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3665. {
  3666. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3667. SideEnter(osRemote);
  3668. }
  3669. //---------------------------------------------------------------------------
  3670. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3671. {
  3672. FCurrentSide = Side;
  3673. if (Visible)
  3674. {
  3675. UpdateControls();
  3676. }
  3677. }
  3678. //---------------------------------------------------------------------------
  3679. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3680. TStrings * FileList, bool Alternative)
  3681. {
  3682. TCustomDirView * DView = DirView(Side);
  3683. DView->SaveSelection();
  3684. DView->SaveSelectedNames();
  3685. DebugAssert(!FAlternativeDelete);
  3686. FAlternativeDelete = Alternative;
  3687. try
  3688. {
  3689. if (!IsSideLocalBrowser(Side))
  3690. {
  3691. DebugAssert(Terminal != NULL);
  3692. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3693. }
  3694. else
  3695. {
  3696. try
  3697. {
  3698. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3699. }
  3700. __finally
  3701. {
  3702. ReloadLocalDirectory();
  3703. }
  3704. }
  3705. FAlternativeDelete = false;
  3706. }
  3707. catch(...)
  3708. {
  3709. FAlternativeDelete = false;
  3710. DView->DiscardSavedSelection();
  3711. throw;
  3712. }
  3713. DView->RestoreSelection();
  3714. }
  3715. //---------------------------------------------------------------------------
  3716. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3717. {
  3718. DebugAssert(Terminal);
  3719. DebugAssert(!IsLocalBrowserMode());
  3720. RemoteDirView->SaveSelection();
  3721. RemoteDirView->SaveSelectedNames();
  3722. try
  3723. {
  3724. if (Lock)
  3725. {
  3726. Terminal->LockFiles(FileList);
  3727. }
  3728. else
  3729. {
  3730. Terminal->UnlockFiles(FileList);
  3731. }
  3732. }
  3733. catch(...)
  3734. {
  3735. RemoteDirView->DiscardSavedSelection();
  3736. throw;
  3737. }
  3738. RemoteDirView->RestoreSelection();
  3739. }
  3740. //---------------------------------------------------------------------------
  3741. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3742. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3743. bool NoConfirmation, bool Move)
  3744. {
  3745. DebugAssert(Terminal != NULL);
  3746. DebugAssert(!IsLocalBrowserMode());
  3747. // update Terminal->StateData->RemoteDirectory
  3748. UpdateTerminal(Terminal);
  3749. if (Session == NULL)
  3750. {
  3751. Session = TTerminalManager::Instance()->ActiveTerminal;
  3752. }
  3753. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3754. {
  3755. if (RemoteDriveView->DropTarget != NULL)
  3756. {
  3757. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3758. }
  3759. else if (RemoteDirView->DropTarget != NULL)
  3760. {
  3761. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3762. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3763. }
  3764. else
  3765. {
  3766. Target = RemoteDirView->Path;
  3767. }
  3768. }
  3769. else
  3770. {
  3771. Target = Session->StateData->RemoteDirectory;
  3772. }
  3773. Target = UnixIncludeTrailingBackslash(Target);
  3774. if (FileList->Count == 1)
  3775. {
  3776. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3777. }
  3778. else
  3779. {
  3780. FileMask = AnyMask;
  3781. }
  3782. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3783. bool Result = true;
  3784. if (!NoConfirmation)
  3785. {
  3786. bool Multi = (FileList->Count > 1);
  3787. if (Move)
  3788. {
  3789. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3790. }
  3791. else
  3792. {
  3793. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3794. TStrings * Directories = new TStringList;
  3795. try
  3796. {
  3797. for (int Index = 0; Index < Sessions->Count; Index++)
  3798. {
  3799. TManagedTerminal * Terminal =
  3800. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3801. Directories->Add(Terminal->StateData->RemoteDirectory);
  3802. }
  3803. TDirectRemoteCopy AllowDirectCopy;
  3804. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3805. {
  3806. DebugAssert(DirectCopy);
  3807. AllowDirectCopy = drcAllow;
  3808. }
  3809. else if (FTerminal->IsCapable[fcSecondaryShell])
  3810. {
  3811. DebugAssert(DirectCopy);
  3812. AllowDirectCopy = drcConfirmCommandSession;
  3813. }
  3814. else
  3815. {
  3816. DebugAssert(!DirectCopy);
  3817. AllowDirectCopy = drcDisallow;
  3818. }
  3819. void * ASession = Session;
  3820. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3821. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3822. Session = static_cast<TManagedTerminal *>(ASession);
  3823. }
  3824. __finally
  3825. {
  3826. delete Directories;
  3827. }
  3828. }
  3829. }
  3830. return Result;
  3831. }
  3832. //---------------------------------------------------------------------------
  3833. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3834. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3835. {
  3836. DebugAssert(!IsLocalBrowserMode());
  3837. bool DirectCopy;
  3838. UnicodeString Target, FileMask;
  3839. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3840. if (Result)
  3841. {
  3842. if (!Move && !DirectCopy)
  3843. {
  3844. Configuration->Usage->Inc("RemoteCopyTemp");
  3845. UnicodeString RootTempDir;
  3846. UnicodeString TempDir;
  3847. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3848. TStrings * TemporaryFilesList = new TStringList();
  3849. try
  3850. {
  3851. TMakeLocalFileListParams MakeFileListParam;
  3852. MakeFileListParam.FileList = TemporaryFilesList;
  3853. MakeFileListParam.FileTimes = NULL;
  3854. MakeFileListParam.IncludeDirs = true;
  3855. MakeFileListParam.Recursive = false;
  3856. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3857. TTerminalManager::Instance()->ActiveTerminal = Session;
  3858. if (TemporaryFilesList->Count > 0)
  3859. {
  3860. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3861. CopyParam.FileMask = FileMask;
  3862. DebugAssert(!FAutoOperation);
  3863. FAutoOperation = true;
  3864. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3865. }
  3866. }
  3867. __finally
  3868. {
  3869. delete TemporaryFilesList;
  3870. FAutoOperation = false;
  3871. if (!RootTempDir.IsEmpty())
  3872. {
  3873. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3874. }
  3875. }
  3876. }
  3877. else
  3878. {
  3879. RemoteDirView->SaveSelection();
  3880. RemoteDirView->SaveSelectedNames();
  3881. try
  3882. {
  3883. if (Move)
  3884. {
  3885. Configuration->Usage->Inc("RemoteMove");
  3886. Terminal->MoveFiles(FileList, Target, FileMask);
  3887. }
  3888. else
  3889. {
  3890. Configuration->Usage->Inc("RemoteCopyDirect");
  3891. DebugAssert(DirectCopy);
  3892. DebugAssert(Session == FTerminal);
  3893. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3894. FTerminal->CommandSessionOpened ||
  3895. CommandSessionFallback())
  3896. {
  3897. Terminal->CopyFiles(FileList, Target, FileMask);
  3898. }
  3899. }
  3900. }
  3901. catch(...)
  3902. {
  3903. RemoteDirView->DiscardSavedSelection();
  3904. throw;
  3905. }
  3906. RemoteDirView->RestoreSelection();
  3907. }
  3908. }
  3909. return Result;
  3910. }
  3911. //---------------------------------------------------------------------------
  3912. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3913. const UnicodeString & Path, TRemoteProperties & Properties)
  3914. {
  3915. DebugAssert(!IsLocalBrowserMode());
  3916. Properties.Valid = Properties.Valid << vpEncrypt;
  3917. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3918. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3919. }
  3920. //---------------------------------------------------------------------------
  3921. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3922. {
  3923. Side = GetSide(Side);
  3924. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3925. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3926. UnicodeString Name = LoadStr(NEW_FOLDER);
  3927. int AllowedChanges =
  3928. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3929. bool SaveSettings = false;
  3930. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3931. {
  3932. TWindowLock Lock(this);
  3933. if (!IsSideLocalBrowser(Side))
  3934. {
  3935. if (SaveSettings)
  3936. {
  3937. GUIConfiguration->NewDirectoryProperties = Properties;
  3938. }
  3939. CreateRemoteDirectory(Name, Properties);
  3940. }
  3941. else
  3942. {
  3943. DirView(Side)->CreateDirectory(Name);
  3944. }
  3945. }
  3946. }
  3947. //---------------------------------------------------------------------------
  3948. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3949. {
  3950. TWindowLock Lock(this);
  3951. DirView(Side)->ExecuteHomeDirectory();
  3952. }
  3953. //---------------------------------------------------------------------------
  3954. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3955. {
  3956. DoOpenDirectoryDialog(odBrowse, Side);
  3957. }
  3958. //---------------------------------------------------------------------------
  3959. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3960. {
  3961. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3962. bool Result = !Path.IsEmpty();
  3963. if (Result)
  3964. {
  3965. // While we might get here when the session is closed (from location profiles),
  3966. // it's not a problem as the Path setter is noop then
  3967. DirView(Side)->Path = Path;
  3968. }
  3969. return Result;
  3970. }
  3971. //---------------------------------------------------------------------------
  3972. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3973. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3974. bool & Close)
  3975. {
  3976. // terminal can be already closed (e.g. dropped connection)
  3977. if (Terminal != NULL)
  3978. {
  3979. try
  3980. {
  3981. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3982. }
  3983. catch(...)
  3984. {
  3985. if (!Terminal->Active)
  3986. {
  3987. Close = true;
  3988. }
  3989. throw;
  3990. }
  3991. }
  3992. }
  3993. //---------------------------------------------------------------------------
  3994. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3995. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3996. bool & Close)
  3997. {
  3998. // terminal can be already closed (e.g. dropped connection)
  3999. if (Terminal != NULL)
  4000. {
  4001. Configuration->Usage->Inc(L"ChecksumCalculated");
  4002. try
  4003. {
  4004. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4005. }
  4006. catch(...)
  4007. {
  4008. if (!Terminal->Active)
  4009. {
  4010. Close = true;
  4011. }
  4012. throw;
  4013. }
  4014. }
  4015. }
  4016. //---------------------------------------------------------------------------
  4017. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4018. {
  4019. bool Result;
  4020. if (!IsSideLocalBrowser(Side))
  4021. {
  4022. TRemoteTokenList * GroupList = NULL;
  4023. TRemoteTokenList * UserList = NULL;
  4024. try
  4025. {
  4026. TRemoteProperties CurrentProperties;
  4027. if (Terminal->LoadFilesProperties(FileList))
  4028. {
  4029. RemoteDirView->Invalidate();
  4030. }
  4031. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4032. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4033. if (CapableGroupChanging || CapableOwnerChanging)
  4034. {
  4035. if (CapableGroupChanging)
  4036. {
  4037. GroupList = Terminal->Groups->Duplicate();
  4038. }
  4039. if (CapableOwnerChanging)
  4040. {
  4041. UserList = Terminal->Users->Duplicate();
  4042. }
  4043. TRemoteDirectory * Files = Terminal->Files;
  4044. int Count = Files->Count;
  4045. if (Count > 100)
  4046. {
  4047. Count = 100;
  4048. }
  4049. for (int Index = 0; Index < Count; Index++)
  4050. {
  4051. TRemoteFile * File = Files->Files[Index];
  4052. if (CapableGroupChanging)
  4053. {
  4054. GroupList->AddUnique(File->Group);
  4055. }
  4056. if (CapableOwnerChanging)
  4057. {
  4058. UserList->AddUnique(File->Owner);
  4059. }
  4060. }
  4061. // if we haven't collected tokens for all files in current directory,
  4062. // make sure we collect them at least for all selected files.
  4063. // (note that so far the files in FileList has to be from current direcotry)
  4064. if (Count < Files->Count)
  4065. {
  4066. for (int Index = 0; Index < FileList->Count; Index++)
  4067. {
  4068. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4069. if (CapableGroupChanging)
  4070. {
  4071. GroupList->AddUnique(File->Group);
  4072. }
  4073. if (CapableOwnerChanging)
  4074. {
  4075. UserList->AddUnique(File->Owner);
  4076. }
  4077. }
  4078. }
  4079. }
  4080. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4081. int Flags = 0;
  4082. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4083. if (CapableOwnerChanging) Flags |= cpOwner;
  4084. if (CapableGroupChanging) Flags |= cpGroup;
  4085. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4086. if (Terminal->IsCapable[fcCalculatingChecksum])
  4087. {
  4088. CalculateChecksumEvent = CalculateChecksum;
  4089. }
  4090. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4091. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4092. TRemoteProperties NewProperties = CurrentProperties;
  4093. Result =
  4094. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4095. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4096. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4097. CalculateSize, CalculateChecksumEvent);
  4098. if (Result)
  4099. {
  4100. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4101. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4102. }
  4103. }
  4104. __finally
  4105. {
  4106. delete GroupList;
  4107. delete UserList;
  4108. }
  4109. }
  4110. else
  4111. {
  4112. DirView(Side)->DisplayPropertiesMenu();
  4113. Result = true;
  4114. }
  4115. return Result;
  4116. }
  4117. //---------------------------------------------------------------------------
  4118. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4119. {
  4120. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4121. {
  4122. FIgnoreNextDialogChar = Key;
  4123. }
  4124. Key = 0;
  4125. }
  4126. //---------------------------------------------------------------------------
  4127. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4128. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4129. {
  4130. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4131. if (Command != NULL)
  4132. {
  4133. KeyProcessed(Key, Shift);
  4134. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4135. {
  4136. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4137. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4138. false, false, const_cast<TCustomCommandType *>(Command));
  4139. }
  4140. }
  4141. }
  4142. //---------------------------------------------------------------------------
  4143. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4144. {
  4145. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4146. {
  4147. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4148. }
  4149. if (!DirView(osCurrent)->IsEditing())
  4150. {
  4151. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4152. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4153. {
  4154. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4155. if (((Action->ShortCut == KeyShortCut) ||
  4156. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4157. AllowedAction(Action, aaShortCut))
  4158. {
  4159. // Has to be called before the action as the dialog char is already in queue.
  4160. // So when the action consumes message queue, we already need to have the
  4161. // FIgnoreNextDialogChar set
  4162. KeyProcessed(Key, Shift);
  4163. // Reset reference to previous component (when menu/toolbar was clicked).
  4164. // Needed to detect that action was invoked by keyboard shortcut
  4165. // in TNonVisualDataModule::ExplorerActionsExecute
  4166. Action->ActionComponent = NULL;
  4167. Action->Execute();
  4168. return;
  4169. }
  4170. }
  4171. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4172. {
  4173. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4174. {
  4175. KeyProcessed(Key, Shift);
  4176. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4177. return;
  4178. }
  4179. }
  4180. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4181. {
  4182. KeyProcessed(Key, Shift);
  4183. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4184. }
  4185. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4186. if (IsCustomShortCut(CustomShortCut))
  4187. {
  4188. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4189. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4190. if (WinConfiguration->SharedBookmarks != NULL)
  4191. {
  4192. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4193. if ((Bookmark != NULL) &&
  4194. OpenBookmark(FCurrentSide, Bookmark))
  4195. {
  4196. KeyProcessed(Key, Shift);
  4197. }
  4198. }
  4199. }
  4200. }
  4201. TForm::KeyDown(Key, Shift);
  4202. }
  4203. //---------------------------------------------------------------------------
  4204. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4205. {
  4206. DebugAssert(Terminal != NULL);
  4207. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4208. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4209. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4210. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4211. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4212. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4213. // expanded from ?: to avoid memory leaks
  4214. if (SecurityEnabled)
  4215. {
  4216. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4217. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4218. }
  4219. else
  4220. {
  4221. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4222. }
  4223. if (FileSystemInfo.ProtocolName.IsEmpty())
  4224. {
  4225. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4226. }
  4227. else
  4228. {
  4229. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4230. }
  4231. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4232. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4233. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4234. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4235. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4236. UnicodeString CompressionStr = CSCompressionStr;
  4237. if (CSCompressionStr != SCCompressionStr)
  4238. {
  4239. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4240. }
  4241. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4242. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4243. UpdateStatusBar();
  4244. }
  4245. //---------------------------------------------------------------------------
  4246. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4247. {
  4248. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4249. DebugAssert(SessionStatusBar != NULL);
  4250. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4251. {
  4252. // note: (Terminal->Status < sshReady) currently never happens here,
  4253. // so STATUS_CONNECTING is never used
  4254. SessionStatusBar->SimplePanel = true;
  4255. SessionStatusBar->SimpleText = LoadStr(
  4256. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4257. }
  4258. else
  4259. {
  4260. DebugAssert(Terminal);
  4261. SessionStatusBar->SimplePanel = false;
  4262. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4263. if (!FNote.IsEmpty())
  4264. {
  4265. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4266. }
  4267. else
  4268. {
  4269. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4270. }
  4271. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4272. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4273. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4274. }
  4275. }
  4276. //---------------------------------------------------------------------------
  4277. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4278. {
  4279. Panel->Caption = L"";
  4280. }
  4281. //---------------------------------------------------------------------------
  4282. void __fastcall TCustomScpExplorerForm::Idle()
  4283. {
  4284. if (FShowing || FStandaloneEditing)
  4285. {
  4286. FEditorManager->Check();
  4287. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4288. // that needs to know if queue view is visible (and it may be closed after queue update)
  4289. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4290. }
  4291. if (FShowing)
  4292. {
  4293. if (!NonVisualDataModule->Busy &&
  4294. // Menu is opened or drag&drop is going on
  4295. (Mouse->Capture == NULL))
  4296. {
  4297. if (FRefreshRemoteDirectory)
  4298. {
  4299. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4300. {
  4301. Terminal->RefreshDirectory();
  4302. }
  4303. FRefreshRemoteDirectory = false;
  4304. }
  4305. if (FRefreshLocalDirectory)
  4306. {
  4307. ReloadLocalDirectory();
  4308. FRefreshLocalDirectory = false;
  4309. }
  4310. if (WinConfiguration->RefreshRemotePanel)
  4311. {
  4312. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4313. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4314. {
  4315. RemoteDirView->ReloadDirectory();
  4316. }
  4317. }
  4318. }
  4319. }
  4320. if (FShowing || FStandaloneEditing)
  4321. {
  4322. if (FQueueStatusInvalidated)
  4323. {
  4324. UpdateQueueStatus(false);
  4325. }
  4326. RefreshQueueItems();
  4327. }
  4328. if (FShowing)
  4329. {
  4330. UpdateStatusBar();
  4331. }
  4332. FIgnoreNextDialogChar = 0;
  4333. }
  4334. //---------------------------------------------------------------------------
  4335. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4336. {
  4337. try
  4338. {
  4339. FUserActionTimer->Enabled = false;
  4340. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4341. {
  4342. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4343. {
  4344. FPendingQueueActionItem->ProcessUserAction();
  4345. }
  4346. }
  4347. }
  4348. __finally
  4349. {
  4350. FPendingQueueActionItem = NULL;
  4351. }
  4352. }
  4353. //---------------------------------------------------------------------------
  4354. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4355. {
  4356. if (WinConfiguration->MinimizeToTray)
  4357. {
  4358. UpdateTrayIcon();
  4359. FTrayIcon->Visible = true;
  4360. if (Visible)
  4361. {
  4362. ShowWindow(Handle, SW_HIDE);
  4363. }
  4364. }
  4365. }
  4366. //---------------------------------------------------------------------------
  4367. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4368. {
  4369. // WORKAROUND
  4370. // When restoring maximized window from minimization,
  4371. // rarely some controls do not align properly.
  4372. // Two instances seen (both for Commander):
  4373. // - When restoring, window is temporarily narrower (not maximized),
  4374. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4375. // Once maximized already, top dock shinks back, but the session PageControl,
  4376. // do not align up, leaving space between TopDock and PageControl.
  4377. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4378. for (int Index = 0; Index < ControlCount; Index++)
  4379. {
  4380. RealignControl(Controls[Index]);
  4381. }
  4382. if (FTrayIcon->Visible)
  4383. {
  4384. FTrayIcon->Visible = false;
  4385. if (Visible)
  4386. {
  4387. ShowWindow(Handle, SW_SHOW);
  4388. }
  4389. }
  4390. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4391. {
  4392. FNeedSession = false;
  4393. NonVisualDataModule->StartBusy();
  4394. try
  4395. {
  4396. NeedSession(true);
  4397. }
  4398. __finally
  4399. {
  4400. NonVisualDataModule->EndBusy();
  4401. }
  4402. }
  4403. }
  4404. //---------------------------------------------------------------------------
  4405. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4406. {
  4407. FTrayIcon->Hint = GetMainForm()->Caption;
  4408. }
  4409. //---------------------------------------------------------------------------
  4410. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4411. {
  4412. UpdateTrayIcon();
  4413. }
  4414. //---------------------------------------------------------------------------
  4415. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4416. {
  4417. // workaround
  4418. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4419. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4420. // But WM_ACTIVATEAPP message can be received even when
  4421. // the main window is minimized to the tray and internal editor window is focused
  4422. // (after another application was previously active)
  4423. if (::IsIconic(Handle))
  4424. {
  4425. if (!IsAppIconic())
  4426. {
  4427. SetAppIconic(true);
  4428. }
  4429. }
  4430. ::ApplicationRestore();
  4431. Application->BringToFront();
  4432. }
  4433. //---------------------------------------------------------------------------
  4434. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4435. {
  4436. RestoreApp();
  4437. }
  4438. //---------------------------------------------------------------------------
  4439. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4440. {
  4441. if (OpenInNewWindow())
  4442. {
  4443. // todo: Pass FromSite
  4444. ExecuteNewInstance(SessionUrl);
  4445. }
  4446. else
  4447. {
  4448. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4449. }
  4450. }
  4451. //---------------------------------------------------------------------------
  4452. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4453. {
  4454. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4455. StoredSessions->NewSession(SessionName, SessionData);
  4456. // modified only, explicit
  4457. StoredSessions->Save(false, true);
  4458. // encode session name because of slashes in hierarchical sessions
  4459. return EncodeUrlString(SessionName);
  4460. }
  4461. //---------------------------------------------------------------------------
  4462. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4463. {
  4464. // current working directories become defaults here, what is not right
  4465. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4466. return SaveHiddenDuplicateSession(SessionData.get());
  4467. }
  4468. //---------------------------------------------------------------------------
  4469. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4470. {
  4471. if (OpenInNewWindow())
  4472. {
  4473. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4474. }
  4475. else
  4476. {
  4477. // current working directories become defaults here, what is not right
  4478. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4479. TTerminalManager * Manager = TTerminalManager::Instance();
  4480. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4481. Manager->ActiveTerminal = Terminal;
  4482. }
  4483. }
  4484. //---------------------------------------------------------------------------
  4485. void __fastcall TCustomScpExplorerForm::RenameSession()
  4486. {
  4487. UnicodeString Name = Terminal->SessionData->SessionName;
  4488. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4489. {
  4490. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4491. TSessionData::ValidateName(Name);
  4492. // This is inconsistent with how color (for example) is handled.
  4493. Terminal->SessionData->Name = Name;
  4494. UpdateControls();
  4495. // Add/Remove distinguishing paths from sessions of the same name.
  4496. DoTerminalListChanged();
  4497. }
  4498. }
  4499. //---------------------------------------------------------------------------
  4500. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4501. {
  4502. DebugAssert(Queue != NULL);
  4503. bool Result = Queue->IsEmpty;
  4504. if (!Result)
  4505. {
  4506. SetFocus();
  4507. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4508. }
  4509. return Result;
  4510. }
  4511. //---------------------------------------------------------------------------
  4512. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4513. {
  4514. return CanCloseQueue(FQueue);
  4515. }
  4516. //---------------------------------------------------------------------------
  4517. void __fastcall TCustomScpExplorerForm::CloseSession()
  4518. {
  4519. if (CanCloseQueue())
  4520. {
  4521. TTerminalManager::Instance()->FreeActiveTerminal();
  4522. }
  4523. }
  4524. //---------------------------------------------------------------------------
  4525. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4526. {
  4527. if (CanCloseQueue())
  4528. {
  4529. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4530. }
  4531. }
  4532. //---------------------------------------------------------------------------
  4533. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4534. {
  4535. DetachTerminal(Terminal);
  4536. RemoteDirView->Terminal = Terminal;
  4537. UpdateRemotePathComboBox(false);
  4538. UpdateControls();
  4539. }
  4540. //---------------------------------------------------------------------------
  4541. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4542. {
  4543. if (DebugAlwaysTrue(!Terminal->Active))
  4544. {
  4545. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4546. }
  4547. }
  4548. //---------------------------------------------------------------------------
  4549. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4550. {
  4551. if (OpenInNewWindow())
  4552. {
  4553. // encode session name because of slashes in hierarchical sessions
  4554. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4555. }
  4556. else
  4557. {
  4558. TTerminalManager * Manager = TTerminalManager::Instance();
  4559. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4560. Manager->ActiveTerminal = Terminal;
  4561. }
  4562. }
  4563. //---------------------------------------------------------------------------
  4564. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4565. {
  4566. TTerminalManager * Manager = TTerminalManager::Instance();
  4567. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4568. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4569. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4570. // FirstTerminal can be null, if some of the
  4571. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4572. {
  4573. FirstTerminal->Disconnected = true;
  4574. FirstTerminal->DisconnectedTemporarily = true;
  4575. }
  4576. Manager->ActiveTerminal = FirstTerminal;
  4577. }
  4578. //---------------------------------------------------------------------------
  4579. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4580. {
  4581. if (OpenInNewWindow())
  4582. {
  4583. ExecuteNewInstance(Name);
  4584. }
  4585. else
  4586. {
  4587. DoOpenFolderOrWorkspace(Name, true);
  4588. }
  4589. }
  4590. //---------------------------------------------------------------------------
  4591. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4592. bool &CanClose)
  4593. {
  4594. // See the comment in CloseApp()
  4595. if (NonVisualDataModule->Busy)
  4596. {
  4597. CanClose = false;
  4598. }
  4599. else if (Terminal != NULL)
  4600. {
  4601. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4602. {
  4603. unsigned int Result;
  4604. TMessageParams Params(mpNeverAskAgainCheck);
  4605. UnicodeString Message;
  4606. int Answers = qaOK | qaCancel;
  4607. if (TTerminalManager::Instance()->Count > 1)
  4608. {
  4609. if (!WinConfiguration->AutoSaveWorkspace)
  4610. {
  4611. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4612. }
  4613. else
  4614. {
  4615. Message = LoadStr(CLOSE_SESSIONS);
  4616. }
  4617. }
  4618. else
  4619. {
  4620. if (!WinConfiguration->AutoSaveWorkspace)
  4621. {
  4622. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4623. }
  4624. else
  4625. {
  4626. Message = LoadStr(CLOSE_SESSION);
  4627. }
  4628. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4629. }
  4630. UnicodeString Note;
  4631. if (WinConfiguration->AutoSaveWorkspace)
  4632. {
  4633. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4634. }
  4635. else
  4636. {
  4637. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4638. Answers = qaYes | qaNo | qaCancel;
  4639. }
  4640. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4641. SetFocus();
  4642. Result = MessageDialog(Message, qtConfirmation,
  4643. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4644. if (Result == qaNeverAskAgain)
  4645. {
  4646. WinConfiguration->ConfirmClosingSession = false;
  4647. }
  4648. if (Result == qaNo)
  4649. {
  4650. CanClose = SaveWorkspace(true);
  4651. // note that the workspace will be saved redundatly again from FormClose
  4652. }
  4653. else
  4654. {
  4655. CanClose =
  4656. (Result == qaOK) ||
  4657. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4658. (Result == qaNeverAskAgain);
  4659. }
  4660. }
  4661. if (CanClose)
  4662. {
  4663. CanClose = CanCloseQueue();
  4664. }
  4665. }
  4666. if (CanClose)
  4667. {
  4668. CanClose =
  4669. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4670. FEditorManager->CloseExternalFilesWithoutProcess();
  4671. if (CanClose)
  4672. {
  4673. while (CanClose && (FLocalEditors->Count > 0))
  4674. {
  4675. int PrevCount = FLocalEditors->Count;
  4676. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4677. CanClose = (FLocalEditors->Count < PrevCount);
  4678. }
  4679. if (CanClose)
  4680. {
  4681. CanClose = FEditorManager->Empty(true);
  4682. if (!CanClose)
  4683. {
  4684. SetFocus();
  4685. CanClose =
  4686. (MessageDialog(
  4687. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4688. }
  4689. }
  4690. }
  4691. }
  4692. }
  4693. //---------------------------------------------------------------------------
  4694. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4695. {
  4696. TForm * Form = dynamic_cast<TForm *>(Sender);
  4697. DebugAssert(Form != NULL);
  4698. Form->Close();
  4699. }
  4700. //---------------------------------------------------------------------------
  4701. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4702. {
  4703. TForm * Form = dynamic_cast<TForm *>(Sender);
  4704. delete Form;
  4705. }
  4706. //---------------------------------------------------------------------------
  4707. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4708. {
  4709. while (FLocalEditors->Count > 0)
  4710. {
  4711. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4712. }
  4713. }
  4714. //---------------------------------------------------------------------------
  4715. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4716. TObject *Sender)
  4717. {
  4718. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4719. try
  4720. {
  4721. SetProperties(osRemote, FileList);
  4722. }
  4723. __finally
  4724. {
  4725. delete FileList;
  4726. }
  4727. }
  4728. //---------------------------------------------------------------------------
  4729. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4730. {
  4731. if (value)
  4732. {
  4733. if (Component == fcCustomCommandsBand)
  4734. {
  4735. UpdateCustomCommandsToolbar();
  4736. }
  4737. if (Component == fcQueueFileList)
  4738. {
  4739. DebugAssert(!QueueFileListSplitter->Visible);
  4740. AdjustQueueLayout();
  4741. UpdateQueueFileList();
  4742. }
  4743. }
  4744. }
  4745. //---------------------------------------------------------------------------
  4746. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4747. {
  4748. int MinHeightLimit =
  4749. GetStaticQueuePanelComponentsHeight() +
  4750. QueueFileListSplitter->Height +
  4751. QueueFileList->Height +
  4752. GetMinQueueViewHeight();
  4753. if (QueuePanel->ClientHeight < MinHeightLimit)
  4754. {
  4755. QueuePanel->ClientHeight = MinHeightLimit;
  4756. }
  4757. }
  4758. //---------------------------------------------------------------------------
  4759. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4760. {
  4761. TControl * Control = GetComponent(Component);
  4762. DebugAssert(Control);
  4763. bool Changed = (Control->Visible != value);
  4764. if (Changed)
  4765. {
  4766. ComponentShowing(Component, value);
  4767. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4768. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4769. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4770. if (value)
  4771. {
  4772. int RemainingHeight = Control->Parent->ClientHeight;
  4773. int RemainingWidth = Control->Parent->ClientWidth;
  4774. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4775. {
  4776. TControl * ChildControl = Control->Parent->Controls[i];
  4777. if (ChildControl->Visible)
  4778. {
  4779. switch (ChildControl->Align)
  4780. {
  4781. case alTop:
  4782. case alBottom:
  4783. RemainingHeight -= ChildControl->Height;
  4784. break;
  4785. case alLeft:
  4786. case alRight:
  4787. RemainingWidth -= ChildControl->Width;
  4788. break;
  4789. }
  4790. }
  4791. }
  4792. int Reserve = ScaleByTextHeight(this, 32);
  4793. // queue in explorer, trees in commander
  4794. if (Control->Height > RemainingHeight - Reserve)
  4795. {
  4796. Control->Height = RemainingHeight / 2;
  4797. }
  4798. if (Control->Width > RemainingWidth - Reserve)
  4799. {
  4800. Control->Width = RemainingWidth / 2;
  4801. }
  4802. }
  4803. Control->Visible = value;
  4804. if (WasFocused && Visible)
  4805. {
  4806. DirView(osCurrent)->SetFocus();
  4807. }
  4808. FixControlsPlacement();
  4809. }
  4810. }
  4811. //---------------------------------------------------------------------------
  4812. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4813. {
  4814. TControl * Control = GetComponent(Component);
  4815. if (Control == NULL)
  4816. {
  4817. return false;
  4818. }
  4819. else
  4820. {
  4821. return Control->Visible;
  4822. }
  4823. }
  4824. //---------------------------------------------------------------------------
  4825. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4826. {
  4827. bool Result;
  4828. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4829. {
  4830. Result = !IsUWP();
  4831. }
  4832. else
  4833. {
  4834. Result = true;
  4835. }
  4836. return Result;
  4837. }
  4838. //---------------------------------------------------------------------------
  4839. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4840. {
  4841. if (DirView(osOther)->ItemFocused != NULL)
  4842. {
  4843. DirView(osOther)->ItemFocused->MakeVisible(false);
  4844. }
  4845. QueueSplitter->Visible = QueuePanel->Visible;
  4846. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4847. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4848. TControl * QueueControlsOrder[] =
  4849. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4850. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4851. }
  4852. //---------------------------------------------------------------------------
  4853. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4854. {
  4855. switch (Component) {
  4856. case fcStatusBar: return RemoteStatusBar;
  4857. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4858. case fcQueueView: return QueuePanel;
  4859. case fcQueueToolbar: return QueueDock;
  4860. case fcRemoteTree: return RemoteDrivePanel;
  4861. case fcSessionsTabs: return SessionsPageControl;
  4862. case fcQueueFileList: return QueueFileList;
  4863. default: return NULL;
  4864. }
  4865. }
  4866. //---------------------------------------------------------------------------
  4867. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4868. TObject *Sender, TListColumn *Column, TPoint &Point)
  4869. {
  4870. DebugAssert(NonVisualDataModule && Column && Sender);
  4871. NonVisualDataModule->ListColumn = Column;
  4872. TPopupMenu * DirViewColumnMenu;
  4873. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4874. {
  4875. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4876. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4877. (Column->Index == uvName);
  4878. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4879. (Column->Index == uvSize);
  4880. }
  4881. else
  4882. {
  4883. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4884. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4885. (Column->Index == dvName);
  4886. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4887. (Column->Index == dvSize);
  4888. }
  4889. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4890. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4891. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4892. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4893. }
  4894. //---------------------------------------------------------------------------
  4895. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4896. TObject *Sender, TListItem *Item, bool &AllowExec)
  4897. {
  4898. DoDirViewExecFile(Sender, Item, AllowExec);
  4899. }
  4900. //---------------------------------------------------------------------------
  4901. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4902. TListItem * Item, bool & AllowExec)
  4903. {
  4904. DebugAssert(Sender && Item && Configuration);
  4905. DebugAssert(AllowExec);
  4906. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4907. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4908. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4909. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4910. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4911. // on files only (not directories)
  4912. // and only when symlinks are resolved (apply to remote panel only)
  4913. if (!ADirView->ItemIsDirectory(Item) &&
  4914. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4915. {
  4916. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4917. !FForceExecution &&
  4918. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4919. {
  4920. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4921. {
  4922. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4923. UnlockWindow();
  4924. try
  4925. {
  4926. ExecuteFileOperation(
  4927. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4928. }
  4929. __finally
  4930. {
  4931. LockWindow();
  4932. }
  4933. AllowExec = false;
  4934. }
  4935. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4936. {
  4937. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4938. {
  4939. ExecuteFile(Side, efDefaultEditor);
  4940. AllowExec = false;
  4941. }
  4942. }
  4943. else
  4944. {
  4945. DebugFail();
  4946. }
  4947. }
  4948. // if we have not done anything special, fall back to default behavior
  4949. if (AllowExec)
  4950. {
  4951. if (Remote && !WinConfiguration->DisableOpenEdit)
  4952. {
  4953. ExecuteFile(osRemote, efShell);
  4954. AllowExec = false;
  4955. }
  4956. }
  4957. }
  4958. }
  4959. //---------------------------------------------------------------------------
  4960. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4961. {
  4962. return ((Side == osRemote) || (Side == osCurrent));
  4963. }
  4964. //---------------------------------------------------------------------------
  4965. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4966. {
  4967. DebugFail();
  4968. }
  4969. //---------------------------------------------------------------------------
  4970. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4971. {
  4972. DebugFail();
  4973. }
  4974. //---------------------------------------------------------------------------
  4975. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4976. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4977. {
  4978. TSynchronizeParamType Params;
  4979. Params.LocalDirectory = LocalDirectory;
  4980. Params.RemoteDirectory = RemoteDirectory;
  4981. int UnusedParams =
  4982. (GUIConfiguration->SynchronizeParams &
  4983. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4984. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4985. Params.Options = GUIConfiguration->SynchronizeOptions;
  4986. bool SaveSettings = false;
  4987. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4988. &DoSynchronizeTooManyDirectories);
  4989. DebugAssert(FSynchronizeController == NULL);
  4990. FSynchronizeController = &Controller;
  4991. bool Result;
  4992. try
  4993. {
  4994. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4995. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4996. int Options =
  4997. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4998. DebugAssert(FOnFeedSynchronizeError == NULL);
  4999. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5000. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5001. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5002. if (Result)
  5003. {
  5004. if (SaveSettings)
  5005. {
  5006. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5007. GUIConfiguration->SynchronizeOptions = Params.Options;
  5008. }
  5009. else
  5010. {
  5011. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5012. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5013. FLAGSET(Params.Options, soSynchronize))
  5014. {
  5015. GUIConfiguration->SynchronizeOptions =
  5016. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5017. soSynchronize;
  5018. }
  5019. }
  5020. LocalDirectory = Params.LocalDirectory;
  5021. RemoteDirectory = Params.RemoteDirectory;
  5022. }
  5023. }
  5024. __finally
  5025. {
  5026. FSynchronizeController = NULL;
  5027. DebugAssert(FOnFeedSynchronizeError == NULL);
  5028. FOnFeedSynchronizeError = NULL;
  5029. }
  5030. return Result;
  5031. }
  5032. //---------------------------------------------------------------------------
  5033. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5034. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5035. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5036. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5037. TSynchronizeOptions * Options, bool Full)
  5038. {
  5039. // Keep-up-to-date mode
  5040. if (Terminal->Status == ssOpened)
  5041. {
  5042. try
  5043. {
  5044. int PParams = Params.Params;
  5045. if (!Full)
  5046. {
  5047. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5048. if (FLAGSET(Params.Options, soRecurse))
  5049. {
  5050. PParams |= TTerminal::spSubDirs;
  5051. }
  5052. }
  5053. else
  5054. {
  5055. // if keepuptodate is non-recursive,
  5056. // full sync before has to be non-recursive as well
  5057. if (FLAGCLEAR(Params.Options, soRecurse))
  5058. {
  5059. PParams |= TTerminal::spNoRecurse;
  5060. }
  5061. }
  5062. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5063. PParams, Checklist, Options);
  5064. }
  5065. catch (Exception & E)
  5066. {
  5067. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5068. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5069. {
  5070. // noop, already logged in MoreMessageDialog
  5071. }
  5072. else
  5073. {
  5074. ShowExtendedExceptionEx(Terminal, &E);
  5075. throw;
  5076. }
  5077. }
  5078. }
  5079. }
  5080. //---------------------------------------------------------------------------
  5081. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5082. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5083. const UnicodeString ErrorStr)
  5084. {
  5085. if (!Directory.IsEmpty())
  5086. {
  5087. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5088. }
  5089. else
  5090. {
  5091. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5092. }
  5093. }
  5094. //---------------------------------------------------------------------------
  5095. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5096. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5097. {
  5098. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5099. {
  5100. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5101. }
  5102. else
  5103. {
  5104. TMessageParams Params(mpNeverAskAgainCheck);
  5105. unsigned int Result = MessageDialog(
  5106. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5107. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5108. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5109. {
  5110. MaxDirectories *= 2;
  5111. if (Result == qaNeverAskAgain)
  5112. {
  5113. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5114. }
  5115. }
  5116. else
  5117. {
  5118. Abort();
  5119. }
  5120. }
  5121. }
  5122. //---------------------------------------------------------------------------
  5123. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5124. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5125. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5126. TSynchronizeOptions * Options)
  5127. {
  5128. // Keep-up-to-date mode
  5129. DebugAssert(!FAutoOperation);
  5130. void * BatchStorage;
  5131. BatchStart(BatchStorage);
  5132. FAutoOperation = true;
  5133. bool AnyOperation = false;
  5134. TDateTime StartTime = Now();
  5135. TSynchronizeChecklist * AChecklist = NULL;
  5136. try
  5137. {
  5138. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5139. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5140. {
  5141. FSynchronizeProgressForm->Start();
  5142. }
  5143. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5144. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5145. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5146. Options);
  5147. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5148. SAFE_DESTROY(FSynchronizeProgressForm);
  5149. AnyOperation = (AChecklist->CheckedCount > 0);
  5150. if (AnyOperation)
  5151. {
  5152. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5153. CreateProgressForm(&SynchronizeProgress);
  5154. try
  5155. {
  5156. Terminal->SynchronizeApply(
  5157. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5158. SynchronizeProcessedItem, NULL, NULL, NULL);
  5159. }
  5160. __finally
  5161. {
  5162. DestroyProgressForm();
  5163. }
  5164. }
  5165. }
  5166. __finally
  5167. {
  5168. if (Checklist == NULL)
  5169. {
  5170. delete AChecklist;
  5171. }
  5172. else
  5173. {
  5174. *Checklist = AChecklist;
  5175. }
  5176. FAutoOperation = false;
  5177. SAFE_DESTROY(FSynchronizeProgressForm);
  5178. BatchEnd(BatchStorage);
  5179. ReloadLocalDirectory();
  5180. if (AnyOperation)
  5181. {
  5182. OperationComplete(StartTime);
  5183. }
  5184. }
  5185. }
  5186. //---------------------------------------------------------------------------
  5187. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5188. {
  5189. // can be called from command line
  5190. return Visible &&
  5191. ((DirView(osRemote)->SelCount > 0) ||
  5192. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5193. }
  5194. //---------------------------------------------------------------------------
  5195. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5196. {
  5197. LogSynchronizeEvent(Terminal, Message);
  5198. }
  5199. //---------------------------------------------------------------------------
  5200. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5201. int Params, TSynchronizeOptions & Options)
  5202. {
  5203. DebugAssert(!IsLocalBrowserMode());
  5204. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5205. {
  5206. Options.Filter = new TStringList();
  5207. Options.Filter->CaseSensitive = false;
  5208. Options.Filter->Duplicates = Types::dupAccept;
  5209. if (DirView(osRemote)->SelCount > 0)
  5210. {
  5211. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5212. }
  5213. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5214. {
  5215. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5216. }
  5217. Options.Filter->Sort();
  5218. }
  5219. }
  5220. //---------------------------------------------------------------------------
  5221. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5222. {
  5223. TCopyParamType Defaults;
  5224. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5225. ConfigStorage->AccessMode = smRead;
  5226. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5227. {
  5228. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5229. }
  5230. ConfigStorage.reset(NULL);
  5231. std::unique_ptr<TStringList> Options(new TStringList());
  5232. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5233. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5234. UnicodeString Result;
  5235. if (Options->Count > 0)
  5236. {
  5237. Result =
  5238. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5239. }
  5240. return Result;
  5241. }
  5242. //---------------------------------------------------------------------------
  5243. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5244. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5245. {
  5246. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5247. UnicodeString AdditionalParams =
  5248. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5249. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5250. SerializeCopyParamForCommandLine(CopyParams),
  5251. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5252. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5253. ExecuteNewInstance(SessionName, AdditionalParams);
  5254. }
  5255. //---------------------------------------------------------------------------
  5256. struct TSynchronizeParams
  5257. {
  5258. UnicodeString LocalDirectory;
  5259. UnicodeString RemoteDirectory;
  5260. TSynchronizeMode Mode;
  5261. TSynchronizeChecklist * Checklist;
  5262. int Params;
  5263. TCopyParamType * CopyParam;
  5264. TDateTime CollectElapsed;
  5265. TDateTime * StartTime;
  5266. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5267. };
  5268. //---------------------------------------------------------------------------
  5269. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5270. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5271. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5272. {
  5273. DebugAssert(!FAutoOperation);
  5274. void * BatchStorage;
  5275. BatchStart(BatchStorage);
  5276. FAutoOperation = true;
  5277. TFileOperationStatistics Statistics;
  5278. TDateTime Start = Now();
  5279. try
  5280. {
  5281. Params.OnProcessedItem = OnProcessedItem;
  5282. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5283. CreateProgressForm(&SynchronizeProgress);
  5284. Terminal->SynchronizeApply(
  5285. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5286. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5287. &Statistics);
  5288. }
  5289. __finally
  5290. {
  5291. Params.OnProcessedItem = NULL;
  5292. FAutoOperation = false;
  5293. DestroyProgressForm();
  5294. BatchEnd(BatchStorage);
  5295. ReloadLocalDirectory();
  5296. }
  5297. if (WinConfiguration->SynchronizeSummary)
  5298. {
  5299. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5300. // The statistics should be 0 anyway in this case
  5301. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5302. {
  5303. Message += L"\n";
  5304. if (Statistics.FilesUploaded > 0)
  5305. {
  5306. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5307. }
  5308. if (Statistics.FilesDownloaded > 0)
  5309. {
  5310. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5311. }
  5312. if (Statistics.FilesDeletedLocal > 0)
  5313. {
  5314. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5315. }
  5316. if (Statistics.FilesDeletedRemote > 0)
  5317. {
  5318. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5319. }
  5320. }
  5321. TDateTime Elapsed = (Now() - Start);
  5322. Message +=
  5323. L"\n" +
  5324. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5325. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5326. TMessageParams Params(mpNeverAskAgainCheck);
  5327. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5328. if (Result == qaNeverAskAgain)
  5329. {
  5330. WinConfiguration->SynchronizeSummary = false;
  5331. }
  5332. }
  5333. }
  5334. //---------------------------------------------------------------------------
  5335. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5336. {
  5337. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5338. {
  5339. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5340. }
  5341. // Not set in keep-up-to-date mode - Synchronize() method
  5342. if (Token != NULL)
  5343. {
  5344. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5345. if (Params.OnProcessedItem != NULL)
  5346. {
  5347. Params.OnProcessedItem(NULL, ChecklistItem);
  5348. }
  5349. }
  5350. }
  5351. //---------------------------------------------------------------------------
  5352. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5353. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5354. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5355. {
  5356. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5357. *Params.StartTime = Now();
  5358. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5359. }
  5360. //---------------------------------------------------------------------------
  5361. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5362. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5363. {
  5364. // terminal can be already closed (e.g. dropped connection)
  5365. if (Terminal != NULL)
  5366. {
  5367. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5368. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5369. }
  5370. }
  5371. //---------------------------------------------------------------------------
  5372. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5373. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5374. {
  5375. DebugAssert(!IsLocalBrowserMode());
  5376. TAutoBatch AutoBatch(this);
  5377. TAutoFlag AutoOperationFlag(FAutoOperation);
  5378. if (Side == osRemote)
  5379. {
  5380. std::unique_ptr<TStrings> FileList(new TStringList());
  5381. FileList->AddObject(FileName, RemoteFile);
  5382. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5383. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5384. RemoteDirView->SaveSelection();
  5385. RemoteDirView->SaveSelectedNames();
  5386. try
  5387. {
  5388. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5389. }
  5390. catch(...)
  5391. {
  5392. RemoteDirView->DiscardSavedSelection();
  5393. throw;
  5394. }
  5395. RemoteDirView->RestoreSelection();
  5396. }
  5397. else if (DebugAlwaysTrue(Side == osLocal))
  5398. {
  5399. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5400. {
  5401. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5402. }
  5403. UnicodeString Directory = ExtractFileDir(FileName);
  5404. ReloadLocalDirectory(Directory);
  5405. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5406. if (!SamePaths(Directory, NewDirectory))
  5407. {
  5408. ReloadLocalDirectory(NewDirectory);
  5409. }
  5410. }
  5411. }
  5412. //---------------------------------------------------------------------------
  5413. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5414. {
  5415. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5416. if (Side == osLocal)
  5417. {
  5418. if (Action == TSynchronizeChecklist::saDownloadNew)
  5419. {
  5420. OpenFolderInExplorer(LocalPath);
  5421. }
  5422. else
  5423. {
  5424. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5425. }
  5426. }
  5427. else if (DebugAlwaysTrue(Side == osRemote))
  5428. {
  5429. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5430. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5431. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5432. if (!LocalPath.IsEmpty())
  5433. {
  5434. SessionData->LocalDirectory = LocalPath;
  5435. }
  5436. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5437. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5438. }
  5439. }
  5440. //---------------------------------------------------------------------------
  5441. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5442. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5443. const TCopyParamType * CopyParams)
  5444. {
  5445. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5446. UnicodeString AdditionalParams =
  5447. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5448. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5449. SerializeCopyParamForCommandLine(CopyParams),
  5450. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5451. LocalDirectory, RemoteDirectory, Mode, Params));
  5452. ExecuteNewInstance(SessionName, AdditionalParams);
  5453. }
  5454. //---------------------------------------------------------------------------
  5455. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5456. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5457. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5458. {
  5459. int Result;
  5460. bool SaveSettings = false;
  5461. int Options =
  5462. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5463. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5464. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5465. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5466. bool Continue =
  5467. (UseDefaults == 0) ||
  5468. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5469. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5470. if (Continue)
  5471. {
  5472. Configuration->Usage->Inc(L"Synchronizations");
  5473. UpdateCopyParamCounters(CopyParam);
  5474. TSynchronizeOptions SynchronizeOptions;
  5475. GetSynchronizeOptions(Params, SynchronizeOptions);
  5476. if (SaveSettings)
  5477. {
  5478. GUIConfiguration->SynchronizeParams = Params;
  5479. }
  5480. else
  5481. {
  5482. SaveMode = false;
  5483. }
  5484. TDateTime StartTime = Now();
  5485. TSynchronizeChecklist * Checklist = NULL;
  5486. try
  5487. {
  5488. DebugAssert(!FAutoOperation);
  5489. FAutoOperation = true;
  5490. try
  5491. {
  5492. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5493. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5494. int Files = -1;
  5495. if (DataList->Count >= 1)
  5496. {
  5497. Files = StrToIntDef(DataList->Strings[0], Files);
  5498. }
  5499. else
  5500. {
  5501. DataList->Add(UnicodeString());
  5502. }
  5503. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5504. FSynchronizeProgressForm->Start();
  5505. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5506. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5507. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5508. &SynchronizeOptions);
  5509. if (Terminal->SessionData->CacheDirectories)
  5510. {
  5511. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5512. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5513. }
  5514. }
  5515. __finally
  5516. {
  5517. FAutoOperation = false;
  5518. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5519. SAFE_DESTROY(FSynchronizeProgressForm);
  5520. }
  5521. TSynchronizeParams SynchronizeParams;
  5522. SynchronizeParams.LocalDirectory = LocalDirectory;
  5523. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5524. SynchronizeParams.Mode = Mode;
  5525. SynchronizeParams.CopyParam = &CopyParam;
  5526. SynchronizeParams.Params = Params;
  5527. SynchronizeParams.Checklist = Checklist;
  5528. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5529. SynchronizeParams.StartTime = &StartTime;
  5530. SynchronizeParams.OnProcessedItem = NULL;
  5531. Result = Checklist->Count;
  5532. if (Checklist->Count > 0)
  5533. {
  5534. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5535. {
  5536. if (!DoSynchronizeChecklistDialog(
  5537. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5538. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5539. {
  5540. Result = -1;
  5541. }
  5542. }
  5543. else
  5544. {
  5545. FullSynchronize(SynchronizeParams, NULL, NULL);
  5546. }
  5547. }
  5548. else
  5549. {
  5550. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5551. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5552. }
  5553. }
  5554. __finally
  5555. {
  5556. delete Checklist;
  5557. }
  5558. OperationComplete(StartTime);
  5559. }
  5560. else
  5561. {
  5562. Result = -1;
  5563. }
  5564. return Result;
  5565. }
  5566. //---------------------------------------------------------------------------
  5567. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5568. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5569. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5570. {
  5571. if (Collect)
  5572. {
  5573. DebugAssert(FSynchronizeProgressForm != NULL);
  5574. if (!FSynchronizeProgressForm->Started)
  5575. {
  5576. FSynchronizeProgressForm->Start();
  5577. }
  5578. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5579. SetTaskbarListProgressValue(CompareProgress);
  5580. }
  5581. else
  5582. {
  5583. DebugAssert(FSynchronizeProgressForm == NULL);
  5584. DebugAssert(FProgressForm != NULL);
  5585. }
  5586. }
  5587. //---------------------------------------------------------------------------
  5588. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5589. {
  5590. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5591. TRemoteFile * File = NULL;
  5592. Terminal->ReadFile(FullFileName, File);
  5593. if (File != NULL)
  5594. {
  5595. std::unique_ptr<TRemoteFile> FileOwner(File);
  5596. TAutoFlag Flag(FStandaloneEditing);
  5597. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5598. Application->ShowMainForm = false;
  5599. Application->Run();
  5600. }
  5601. }
  5602. //---------------------------------------------------------------------------
  5603. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5604. {
  5605. DebugFail();
  5606. }
  5607. //---------------------------------------------------------------------------
  5608. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5609. {
  5610. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5611. SessionData->Assign(Terminal->SessionData);
  5612. UpdateSessionData(SessionData.get());
  5613. Terminal->UpdateSessionCredentials(SessionData.get());
  5614. if (!Terminal->SessionData->HasSessionName())
  5615. {
  5616. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5617. // once IsWorkspace is cleared
  5618. SessionData->Name = UnicodeString();
  5619. SessionData->IsWorkspace = false;
  5620. }
  5621. return SessionData.release();
  5622. }
  5623. //---------------------------------------------------------------------------
  5624. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5625. {
  5626. TSessionData * SessionData = CloneCurrentSessionData();
  5627. try
  5628. {
  5629. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5630. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5631. }
  5632. __finally
  5633. {
  5634. delete SessionData;
  5635. }
  5636. }
  5637. //---------------------------------------------------------------------------
  5638. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5639. {
  5640. TTerminalManager * Manager = TTerminalManager::Instance();
  5641. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5642. if (DebugAlwaysTrue(Terminal != NULL))
  5643. {
  5644. // Update (Managed)Terminal->StateData
  5645. UpdateTerminal(Terminal);
  5646. }
  5647. Manager->SaveWorkspace(DataList.get());
  5648. return DataList.release();
  5649. }
  5650. //---------------------------------------------------------------------------
  5651. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5652. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5653. {
  5654. WinConfiguration->LastWorkspace = Name;
  5655. if (!SavePasswords)
  5656. {
  5657. for (int Index = 0; Index < DataList->Count; Index++)
  5658. {
  5659. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5660. if (SessionData->Link.IsEmpty())
  5661. {
  5662. SessionData->ClearSessionPasswords();
  5663. }
  5664. }
  5665. }
  5666. StoredSessions->NewWorkspace(Name, DataList);
  5667. // modified only
  5668. StoredSessions->Save(false, Explicit);
  5669. }
  5670. //---------------------------------------------------------------------------
  5671. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5672. {
  5673. return
  5674. DefaultStr(WinConfiguration->LastWorkspace,
  5675. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5676. }
  5677. //---------------------------------------------------------------------------
  5678. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5679. {
  5680. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5681. bool AnyNonStoredSessionWithPassword = false;
  5682. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5683. bool AllNonStoredSessionsAnonymous = true;
  5684. TTerminalManager * Manager = TTerminalManager::Instance();
  5685. for (int Index = 0; Index < DataList->Count; Index++)
  5686. {
  5687. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5688. if (SessionData->Link.IsEmpty())
  5689. {
  5690. if (SessionData->HasAnySessionPassword())
  5691. {
  5692. AnyNonStoredSessionWithPassword = true;
  5693. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5694. {
  5695. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5696. }
  5697. }
  5698. if (!SameText(SessionData->UserName, AnonymousUserName))
  5699. {
  5700. AllNonStoredSessionsAnonymous = false;
  5701. }
  5702. }
  5703. }
  5704. bool SavePasswords;
  5705. bool * PSavePasswords;
  5706. bool NotRecommendedSavingPasswords =
  5707. !CustomWinConfiguration->UseMasterPassword &&
  5708. !AllNonStoredSessionsAnonymous;
  5709. if (Configuration->DisablePasswordStoring ||
  5710. !AnyNonStoredSessionWithPassword)
  5711. {
  5712. PSavePasswords = NULL;
  5713. SavePasswords = false;
  5714. }
  5715. else
  5716. {
  5717. PSavePasswords = &SavePasswords;
  5718. SavePasswords =
  5719. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5720. !NotRecommendedSavingPasswords;
  5721. }
  5722. UnicodeString Name = WorkspaceName();
  5723. bool CreateShortcut = false;
  5724. bool Result =
  5725. DoSaveWorkspaceDialog(
  5726. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5727. EnableAutoSave);
  5728. if (Result)
  5729. {
  5730. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5731. if (CreateShortcut)
  5732. {
  5733. TOperationVisualizer Visualizer;
  5734. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5735. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5736. }
  5737. if (EnableAutoSave)
  5738. {
  5739. WinConfiguration->AutoSaveWorkspace = true;
  5740. WinConfiguration->AutoWorkspace = Name;
  5741. if (PSavePasswords != NULL)
  5742. {
  5743. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5744. }
  5745. }
  5746. }
  5747. return Result;
  5748. }
  5749. //---------------------------------------------------------------------------
  5750. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5751. {
  5752. DebugAssert(!IsLocalBrowserMode());
  5753. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5754. if (WinConfiguration->PreservePanelState)
  5755. {
  5756. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5757. }
  5758. UpdateSessionData(Terminal->StateData);
  5759. }
  5760. //---------------------------------------------------------------------------
  5761. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5762. {
  5763. // Keep in sync with TSessionData::CopyStateData
  5764. DebugAssert(!IsLocalBrowserMode());
  5765. DebugAssert(Data != NULL);
  5766. // This is inconsistent with how color (for example) is handled.
  5767. Data->Name = Terminal->SessionData->Name;
  5768. // cannot use RemoteDirView->Path, because it is empty if connection
  5769. // was already closed
  5770. // also only peek, we may not be connected at all atm
  5771. // so make sure we do not try retrieving current directory from the server
  5772. // (particularly with FTP)
  5773. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5774. if (!ACurrentDirectory.IsEmpty())
  5775. {
  5776. Data->RemoteDirectory = ACurrentDirectory;
  5777. }
  5778. Data->Color = SessionColor;
  5779. }
  5780. //---------------------------------------------------------------------------
  5781. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5782. {
  5783. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5784. DebugAssert(Toolbar != NULL);
  5785. for (int i = 0; i < Toolbar->Items->Count; i++)
  5786. {
  5787. TTBXCustomDropDownItem * DropDownItem;
  5788. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5789. if (DropDownItem != NULL)
  5790. {
  5791. ToolbarItemResize(DropDownItem,
  5792. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5793. Toolbar->NonClientWidth);
  5794. break;
  5795. }
  5796. }
  5797. }
  5798. //---------------------------------------------------------------------------
  5799. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5800. {
  5801. Item->EditWidth = Width;
  5802. }
  5803. //---------------------------------------------------------------------------
  5804. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5805. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5806. {
  5807. for (int i = 0; i < Toolbar->Items->Count; i++)
  5808. {
  5809. TTBXCustomDropDownItem * DropDownItem;
  5810. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5811. if (DropDownItem != NULL)
  5812. {
  5813. ASize.x -= DropDownItem->EditWidth;
  5814. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5815. }
  5816. }
  5817. }
  5818. //---------------------------------------------------------------------------
  5819. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5820. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5821. {
  5822. if (WinConfiguration->DDWarnLackOfTempSpace)
  5823. {
  5824. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5825. if (!ADrive.IsEmpty())
  5826. {
  5827. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5828. DebugAssert(RequiredSpace >= 0);
  5829. __int64 RequiredWithReserve;
  5830. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5831. if (FreeSpace < RequiredWithReserve)
  5832. {
  5833. unsigned int Result;
  5834. TMessageParams Params(mpNeverAskAgainCheck);
  5835. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5836. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5837. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5838. if (Result == qaNeverAskAgain)
  5839. {
  5840. WinConfiguration->DDWarnLackOfTempSpace = false;
  5841. }
  5842. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5843. }
  5844. }
  5845. }
  5846. }
  5847. //---------------------------------------------------------------------------
  5848. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5849. {
  5850. DoOpenDirectoryDialog(odAddBookmark, Side);
  5851. }
  5852. //---------------------------------------------------------------------------
  5853. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5854. {
  5855. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5856. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5857. try
  5858. {
  5859. TCustomDirView * DView = DirView(Side);
  5860. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5861. {
  5862. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5863. }
  5864. }
  5865. catch (...)
  5866. {
  5867. delete VisitedDirectories;
  5868. throw;
  5869. }
  5870. return VisitedDirectories;
  5871. }
  5872. //---------------------------------------------------------------------------
  5873. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5874. TOpenDirectoryMode Mode, TOperationSide Side)
  5875. {
  5876. bool Continue = true;
  5877. if (Mode == odAddBookmark)
  5878. {
  5879. TMessageParams Params(mpNeverAskAgainCheck);
  5880. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5881. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5882. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5883. unsigned int Answer =
  5884. MessageDialog(Message,
  5885. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5886. if (Answer == qaNeverAskAgain)
  5887. {
  5888. Continue = true;
  5889. WinConfiguration->UseSharedBookmarks = true;
  5890. }
  5891. else if (Answer == qaOK)
  5892. {
  5893. Continue = true;
  5894. WinConfiguration->UseSharedBookmarks = false;
  5895. }
  5896. else
  5897. {
  5898. Continue = false;
  5899. }
  5900. }
  5901. if (Continue)
  5902. {
  5903. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5904. try
  5905. {
  5906. UnicodeString Name = DirView(Side)->PathName;
  5907. bool Repeat;
  5908. do
  5909. {
  5910. Repeat = false;
  5911. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5912. // do not allow switching to location profiles,
  5913. // if we are not connected
  5914. HasDirView[osLocal] && (Terminal != NULL)))
  5915. {
  5916. TWindowLock Lock(this);
  5917. if (!TryOpenDirectory(Side, Name))
  5918. {
  5919. Repeat = true;
  5920. Mode = odBrowse;
  5921. }
  5922. }
  5923. }
  5924. while (Repeat);
  5925. }
  5926. __finally
  5927. {
  5928. delete VisitedDirectories;
  5929. }
  5930. }
  5931. }
  5932. //---------------------------------------------------------------------------
  5933. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5934. {
  5935. DebugAssert(!FTerminal->CommandSessionOpened);
  5936. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5937. }
  5938. //---------------------------------------------------------------------------
  5939. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5940. {
  5941. bool Result = FTerminal->IsCapable[Capability] ||
  5942. FTerminal->CommandSessionOpened;
  5943. if (!Result)
  5944. {
  5945. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5946. if (!GUIConfiguration->ConfirmCommandSession)
  5947. {
  5948. Result = true;
  5949. }
  5950. else
  5951. {
  5952. TMessageParams Params(mpNeverAskAgainCheck);
  5953. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5954. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5955. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5956. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5957. if (Answer == qaNeverAskAgain)
  5958. {
  5959. GUIConfiguration->ConfirmCommandSession = false;
  5960. Result = true;
  5961. }
  5962. else if (Answer == qaOK)
  5963. {
  5964. Result = true;
  5965. }
  5966. }
  5967. if (Result)
  5968. {
  5969. Result = CommandSessionFallback();
  5970. }
  5971. }
  5972. return Result;
  5973. }
  5974. //---------------------------------------------------------------------------
  5975. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5976. {
  5977. if (EnsureCommandSessionFallback(fcAnyCommand))
  5978. {
  5979. DoConsoleDialog(Terminal, Command);
  5980. }
  5981. }
  5982. //---------------------------------------------------------------------------
  5983. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5984. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5985. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5986. {
  5987. if (!IsSideLocalBrowser(osRemote) &&
  5988. IsFileControl(DropSourceControl, osRemote) &&
  5989. (FDDExtMapFile != NULL))
  5990. {
  5991. Accept = true;
  5992. }
  5993. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5994. DebugAssert(FDDTargetControl != NULL);
  5995. }
  5996. //---------------------------------------------------------------------------
  5997. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5998. _di_IDataObject DataObj, int KeyState,
  5999. const TPoint & Point, int & Effect, bool & Accept)
  6000. {
  6001. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6002. }
  6003. //---------------------------------------------------------------------------
  6004. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6005. _di_IDataObject DataObj, int KeyState,
  6006. const TPoint & Point, int & Effect, bool & Accept)
  6007. {
  6008. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6009. }
  6010. //---------------------------------------------------------------------------
  6011. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6012. TObject * Sender)
  6013. {
  6014. DebugUsedParam(Sender);
  6015. DebugAssert(FDDTargetControl == Sender);
  6016. FDDTargetControl = NULL;
  6017. }
  6018. //---------------------------------------------------------------------------
  6019. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6020. {
  6021. FileControlDDDragLeave(SessionsPageControl);
  6022. }
  6023. //---------------------------------------------------------------------------
  6024. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6025. {
  6026. FileControlDDDragLeave(QueueView3);
  6027. }
  6028. //---------------------------------------------------------------------------
  6029. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6030. {
  6031. DebugAssert(!IsSideLocalBrowser(Side));
  6032. DebugUsedParam(Side);
  6033. bool Edit = false;
  6034. TRemoteFile * File = NULL;
  6035. UnicodeString FileName;
  6036. UnicodeString PointTo;
  6037. bool SymbolicLink = true;
  6038. if (RemoteDirView->ItemFocused)
  6039. {
  6040. DebugAssert(RemoteDirView->ItemFocused->Data);
  6041. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6042. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6043. if (Edit)
  6044. {
  6045. FileName = File->FileName;
  6046. PointTo = File->LinkTo;
  6047. }
  6048. else
  6049. {
  6050. PointTo = File->FileName;
  6051. }
  6052. }
  6053. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6054. Terminal->IsCapable[fcHardLink]))
  6055. {
  6056. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6057. if (Edit)
  6058. {
  6059. DebugAssert(File->FileName == FileName);
  6060. int Params = dfNoRecursive;
  6061. Terminal->ExceptionOnFail = true;
  6062. try
  6063. {
  6064. Terminal->DeleteFile(L"", File, &Params);
  6065. }
  6066. __finally
  6067. {
  6068. Terminal->ExceptionOnFail = false;
  6069. }
  6070. }
  6071. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6072. }
  6073. }
  6074. //---------------------------------------------------------------------------
  6075. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6076. {
  6077. return
  6078. (IsSideLocalBrowser(Side) ||
  6079. ((Terminal != NULL) &&
  6080. Terminal->Active &&
  6081. Terminal->ResolvingSymlinks &&
  6082. Terminal->IsCapable[fcSymbolicLink]));
  6083. }
  6084. //---------------------------------------------------------------------------
  6085. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6086. {
  6087. return
  6088. !IsSideLocalBrowser(FCurrentSide) &&
  6089. (RemoteDirView->ItemFocused != NULL) &&
  6090. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6091. Terminal->SessionData->ResolveSymlinks;
  6092. }
  6093. //---------------------------------------------------------------------------
  6094. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6095. {
  6096. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6097. FForceExecution = true;
  6098. try
  6099. {
  6100. DirView(osCurrent)->ExecuteCurrentFile();
  6101. }
  6102. __finally
  6103. {
  6104. FForceExecution = false;
  6105. }
  6106. }
  6107. //---------------------------------------------------------------------------
  6108. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6109. {
  6110. TEditorData ExternalEditor;
  6111. ExternalEditor.Editor = edExternal;
  6112. bool Remember = false;
  6113. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6114. {
  6115. if (Remember)
  6116. {
  6117. TEditorList * EditorList = new TEditorList;
  6118. try
  6119. {
  6120. *EditorList = *WinConfiguration->EditorList;
  6121. bool Found = false;
  6122. int i = 0;
  6123. while (!Found && (i < EditorList->Count))
  6124. {
  6125. const TEditorPreferences * Editor = EditorList->Editors[i];
  6126. if ((Editor->Data->Editor == edExternal) &&
  6127. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6128. {
  6129. Found = true;
  6130. }
  6131. i++;
  6132. }
  6133. if (!Found)
  6134. {
  6135. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6136. WinConfiguration->EditorList = EditorList;
  6137. }
  6138. }
  6139. __finally
  6140. {
  6141. delete EditorList;
  6142. }
  6143. }
  6144. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6145. }
  6146. }
  6147. //---------------------------------------------------------------------------
  6148. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6149. {
  6150. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6151. if (FFileFindTerminal == ATerminal)
  6152. {
  6153. FFileFindTerminal = NULL;
  6154. HideFileFindDialog();
  6155. }
  6156. if (FClipboardTerminal == ATerminal)
  6157. {
  6158. ClipboardClear(); // implies ClipboardStop
  6159. }
  6160. }
  6161. //---------------------------------------------------------------------------
  6162. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6163. {
  6164. DetachTerminal(Sender);
  6165. }
  6166. //---------------------------------------------------------------------------
  6167. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6168. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6169. {
  6170. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6171. DebugAssert(Terminal != NULL);
  6172. if (Data->Terminal == Terminal)
  6173. {
  6174. Data->Terminal = NULL;
  6175. }
  6176. }
  6177. //---------------------------------------------------------------------------
  6178. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6179. {
  6180. UpdateControls();
  6181. SessionColor = TColor(0);
  6182. UpdateRemotePathComboBox(false);
  6183. NeedSession(false);
  6184. }
  6185. //---------------------------------------------------------------------------
  6186. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6187. {
  6188. try
  6189. {
  6190. // Cache, as the login dialog can change its value
  6191. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6192. try
  6193. {
  6194. if (ShowLogin)
  6195. {
  6196. bool ReloadSessions = !Startup;
  6197. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6198. }
  6199. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6200. // This detects if workspace was saved the last time the main widow was closed
  6201. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6202. {
  6203. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6204. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6205. }
  6206. }
  6207. __finally
  6208. {
  6209. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6210. // (so there was no chance for the user to open any session yet)
  6211. if ((ShowLogin || !Startup) &&
  6212. !WinConfiguration->KeepOpenWhenNoSession &&
  6213. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6214. {
  6215. TerminateApplication();
  6216. }
  6217. }
  6218. }
  6219. catch (EAbort &)
  6220. {
  6221. // swallow
  6222. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6223. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6224. }
  6225. }
  6226. //---------------------------------------------------------------------------
  6227. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6228. {
  6229. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6230. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6231. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6232. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6233. try
  6234. {
  6235. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6236. // Clear the design time unthemed tab
  6237. ((SessionsPageControl->PageCount > 0) &&
  6238. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6239. {
  6240. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6241. }
  6242. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6243. {
  6244. TThemeTabSheet * TabSheet;
  6245. if (Index >= SessionsPageControl->PageCount)
  6246. {
  6247. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6248. TabSheet->PageControl = SessionsPageControl;
  6249. }
  6250. else
  6251. {
  6252. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6253. }
  6254. bool IsSessionTab = (Index < TerminalList->Count);
  6255. if (IsSessionTab)
  6256. {
  6257. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6258. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6259. UpdateSessionTab(TabSheet);
  6260. }
  6261. else
  6262. {
  6263. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6264. TabSheet->Tag = 0; // not really needed
  6265. TabSheet->Shadowed = false;
  6266. // 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)
  6267. UpdateNewSessionTab();
  6268. }
  6269. TabSheet->ShowCloseButton = IsSessionTab;
  6270. }
  6271. }
  6272. __finally
  6273. {
  6274. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6275. }
  6276. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6277. }
  6278. //---------------------------------------------------------------------------
  6279. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6280. {
  6281. DoTerminalListChanged();
  6282. }
  6283. //---------------------------------------------------------------------------
  6284. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6285. {
  6286. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6287. DebugAssert(TabSheet->ImageIndex == 0);
  6288. TabSheet->Caption =
  6289. WinConfiguration->SelectiveToolbarText ?
  6290. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6291. UnicodeString();
  6292. }
  6293. //---------------------------------------------------------------------------
  6294. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6295. {
  6296. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6297. }
  6298. //---------------------------------------------------------------------------
  6299. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6300. {
  6301. if (DebugAlwaysTrue(TabSheet != NULL))
  6302. {
  6303. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6304. if (DebugAlwaysTrue(ATerminal != NULL))
  6305. {
  6306. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6307. TabSheet->ImageIndex = AddSessionColor(Color);
  6308. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6309. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6310. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6311. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6312. {
  6313. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6314. }
  6315. }
  6316. }
  6317. }
  6318. //---------------------------------------------------------------------------
  6319. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6320. {
  6321. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6322. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6323. bool Result = (Terminal != NULL);
  6324. if (Result)
  6325. {
  6326. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6327. }
  6328. else
  6329. {
  6330. try
  6331. {
  6332. NewSession(false);
  6333. }
  6334. __finally
  6335. {
  6336. DoTerminalListChanged();
  6337. }
  6338. FSessionsPageControlNewSessionTime = Now();
  6339. }
  6340. return Result;
  6341. }
  6342. //---------------------------------------------------------------------------
  6343. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6344. {
  6345. SessionTabSwitched();
  6346. }
  6347. //---------------------------------------------------------------------------
  6348. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6349. {
  6350. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6351. DebugAssert(TransferList != NULL);
  6352. UnicodeString Name;
  6353. if (TransferList->ItemIndex <= 0)
  6354. {
  6355. Name = L"";
  6356. }
  6357. else
  6358. {
  6359. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6360. }
  6361. if (FCopyParamAutoSelected.IsEmpty())
  6362. {
  6363. // if previous preset was not autoselected, make new preset the "default"
  6364. FCopyParamDefault = Name;
  6365. }
  6366. GUIConfiguration->CopyParamCurrent = Name;
  6367. }
  6368. //---------------------------------------------------------------------------
  6369. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6370. {
  6371. // sanity check
  6372. bool ExistingPreset =
  6373. (FTransferListHoverIndex >= 0) &&
  6374. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6375. DebugAssert(ExistingPreset);
  6376. if (ExistingPreset)
  6377. {
  6378. HDC DC = GetDC(0);
  6379. TCanvas * Canvas = new TCanvas();
  6380. try
  6381. {
  6382. Canvas->Handle = DC;
  6383. Canvas->Font = GetToolbarFont(this);
  6384. UnicodeString Name;
  6385. if (FTransferListHoverIndex == 0)
  6386. {
  6387. Name = L"";
  6388. }
  6389. else
  6390. {
  6391. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6392. }
  6393. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6394. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6395. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6396. static_cast<TObject*>(GetComponent(fcTransferList)));
  6397. UnicodeString InfoStr =
  6398. GUIConfiguration->CopyParamPreset[Name].
  6399. GetInfoStr(L"; ",
  6400. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6401. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6402. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6403. {
  6404. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6405. {
  6406. InfoStr.SetLength(InfoStr.Length() - 1);
  6407. }
  6408. InfoStr += Ellipsis;
  6409. }
  6410. // UpdateCaption does not cause invalidation of whole submenu, while
  6411. // setting Caption property does.
  6412. // also it probably does not resize the label, even if necessary
  6413. // (we do not want that anyway)
  6414. TransferLabel->UpdateCaption(InfoStr);
  6415. }
  6416. __finally
  6417. {
  6418. Canvas->Handle = NULL;
  6419. ReleaseDC(0, DC);
  6420. delete Canvas;
  6421. }
  6422. }
  6423. }
  6424. //---------------------------------------------------------------------------
  6425. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6426. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6427. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6428. {
  6429. if (FTransferListHoverIndex != AHoverIndex)
  6430. {
  6431. FTransferListHoverIndex = AHoverIndex;
  6432. UpdateTransferLabel();
  6433. }
  6434. }
  6435. //---------------------------------------------------------------------------
  6436. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6437. {
  6438. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6439. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6440. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6441. {
  6442. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6443. {
  6444. if (!NonVisualDataModule->Busy)
  6445. {
  6446. OpenDirectory(GetSide(osCurrent));
  6447. }
  6448. Message.Result = 1;
  6449. }
  6450. else
  6451. {
  6452. TForm::Dispatch(&Message);
  6453. }
  6454. }
  6455. else
  6456. {
  6457. TForm::Dispatch(&Message);
  6458. }
  6459. }
  6460. //---------------------------------------------------------------------------
  6461. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6462. {
  6463. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6464. if ((FIgnoreNextDialogChar != 0) &&
  6465. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6466. {
  6467. Message.Result = 1;
  6468. }
  6469. else
  6470. {
  6471. TForm::Dispatch(&Message);
  6472. }
  6473. FIgnoreNextDialogChar = 0;
  6474. }
  6475. //---------------------------------------------------------------------------
  6476. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6477. {
  6478. // The four low-order bits are used internally by Windows
  6479. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6480. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6481. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6482. // 61730 - restore thru double click - undocumented
  6483. // 61490 - maximize thru double click - undocumented
  6484. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6485. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6486. {
  6487. SysResizing(Cmd);
  6488. }
  6489. TForm::Dispatch(&Message);
  6490. }
  6491. //---------------------------------------------------------------------------
  6492. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6493. {
  6494. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6495. // Also there no point returning TRUE as we are not able to
  6496. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6497. // Hence the process termination might be safer :)
  6498. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6499. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6500. {
  6501. Message.Result = FALSE;
  6502. }
  6503. else
  6504. {
  6505. Message.Result = TRUE;
  6506. }
  6507. // Do not call default handling as that triggers OnCloseQuery,
  6508. // where our implementation will popup confirmation dialogs, what we do not want,
  6509. // as per Vista guidelines:
  6510. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6511. }
  6512. //---------------------------------------------------------------------------
  6513. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6514. {
  6515. if (Message.EndSession && IsApplicationMinimized())
  6516. {
  6517. // WORKAROUND
  6518. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6519. // when it receives WM_ENDSESSION,
  6520. // but that sometimes (particularly when application is minimized) cause crashes.
  6521. // Crash popups message that blocks log off.
  6522. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6523. // so we call ExitProcess() immediately, not even trying to cleanup.
  6524. // It still causes beep, so there's likely some popup, but it does not block
  6525. // log off.
  6526. ExitProcess(0);
  6527. }
  6528. TForm::Dispatch(&Message);
  6529. }
  6530. #ifdef _DEBUG
  6531. //---------------------------------------------------------------------------
  6532. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6533. {
  6534. TForm::Dispatch(&Message);
  6535. }
  6536. #endif
  6537. //---------------------------------------------------------------------------
  6538. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6539. {
  6540. }
  6541. //---------------------------------------------------------------------------
  6542. void __fastcall TCustomScpExplorerForm::DoShow()
  6543. {
  6544. // only now are the controls resized finally, so the size constraints
  6545. // will not conflict with possibly very small window size
  6546. RestoreFormParams();
  6547. // This indicates that the form was rescaled after parameters were loaded and
  6548. // as most probably the parameters were actually saved with the current form scaling
  6549. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6550. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6551. // and no rounding problems will occur.
  6552. // See also RestoreForm.
  6553. // (we should be safe to call RestoreParams unconditionally)
  6554. if (PixelsPerInch != Screen->PixelsPerInch)
  6555. {
  6556. RestoreParams();
  6557. }
  6558. FixControlsPlacement();
  6559. if (Position == poDefaultPosOnly)
  6560. {
  6561. CutFormToDesktop(this);
  6562. }
  6563. TForm::DoShow();
  6564. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6565. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6566. if (Terminal == NULL)
  6567. {
  6568. StartingDisconnected();
  6569. }
  6570. UpdatePixelsPerInchMainWindowCounter();
  6571. FShowing = true;
  6572. }
  6573. //---------------------------------------------------------------------------
  6574. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6575. {
  6576. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6577. }
  6578. //---------------------------------------------------------------------------
  6579. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6580. {
  6581. DoTerminalListChanged();
  6582. }
  6583. //---------------------------------------------------------------------------
  6584. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6585. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6586. TNotifyEvent OnBalloonClick, TObject * UserData)
  6587. {
  6588. bool Do;
  6589. UnicodeString Message;
  6590. if (E == NULL)
  6591. {
  6592. Message = Str;
  6593. Do = true;
  6594. }
  6595. else
  6596. {
  6597. Do = ExceptionMessage(E, Message);
  6598. }
  6599. if (Do && WinConfiguration->BalloonNotifications)
  6600. {
  6601. UnicodeString Title;
  6602. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6603. {
  6604. Message = TrimLeft(Message);
  6605. }
  6606. else
  6607. {
  6608. Message = UnformatMessage(Message);
  6609. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6610. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6611. Title = LoadResourceString(Captions[Type]);
  6612. if (Terminal != NULL)
  6613. {
  6614. Title = FORMAT(L"%s - %s",
  6615. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6616. }
  6617. }
  6618. if (Seconds == 0)
  6619. {
  6620. Seconds = WinConfiguration->NotificationsTimeout;
  6621. }
  6622. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6623. }
  6624. }
  6625. //---------------------------------------------------------------------------
  6626. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6627. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6628. UnicodeString HelpKeyword, const TMessageParams * Params,
  6629. TTerminal * Terminal)
  6630. {
  6631. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6632. (FOnFeedSynchronizeError != NULL)) &&
  6633. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6634. {
  6635. if (FOnFeedSynchronizeError != NULL)
  6636. {
  6637. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6638. }
  6639. else
  6640. {
  6641. DebugAssert(FErrorList != NULL);
  6642. TStringList * MoreMessagesCopy = NULL;
  6643. if (MoreMessages)
  6644. {
  6645. MoreMessagesCopy = new TStringList();
  6646. MoreMessagesCopy->Assign(MoreMessages);
  6647. }
  6648. FErrorList->AddObject(Message, MoreMessagesCopy);
  6649. }
  6650. PopupTrayBalloon(Terminal, Message, Type);
  6651. return ContinueAnswer(Answers);
  6652. }
  6653. else
  6654. {
  6655. bool UseBalloon = FTrayIcon->Visible;
  6656. if (UseBalloon)
  6657. {
  6658. PopupTrayBalloon(Terminal, Message, Type);
  6659. }
  6660. unsigned int Result;
  6661. try
  6662. {
  6663. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6664. }
  6665. __finally
  6666. {
  6667. // cancel only balloon we popped up, otherwise we may cancel notification
  6668. // balloon that was there before the message dialog
  6669. // (such as "dd confirmation opt in balloon)
  6670. if (UseBalloon)
  6671. {
  6672. FTrayIcon->CancelBalloon();
  6673. }
  6674. }
  6675. return Result;
  6676. }
  6677. }
  6678. //---------------------------------------------------------------------------
  6679. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6680. TTerminal * Terminal, Exception * E)
  6681. {
  6682. if (FTrayIcon->Visible)
  6683. {
  6684. PopupTrayBalloon(Terminal, L"", qtError, E);
  6685. }
  6686. // particularly prevent opening new session from jump list,
  6687. // while exception is shown
  6688. NonVisualDataModule->StartBusy();
  6689. try
  6690. {
  6691. ShowExtendedExceptionEx(Terminal, E);
  6692. }
  6693. __finally
  6694. {
  6695. NonVisualDataModule->EndBusy();
  6696. FTrayIcon->CancelBalloon();
  6697. }
  6698. }
  6699. //---------------------------------------------------------------------------
  6700. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6701. {
  6702. if (Terminal->Active)
  6703. {
  6704. InitStatusBar();
  6705. }
  6706. // cannot rely on active page being page for active terminal,
  6707. // as it can happen that active page is the "new session" page
  6708. // (e.g. when reconnecting active terminal, while login dialog
  6709. // invoked from "new session" page is modal)
  6710. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6711. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6712. }
  6713. //---------------------------------------------------------------------------
  6714. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6715. TTerminal * Terminal, Exception * E)
  6716. {
  6717. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6718. if (!Terminal->Active)
  6719. {
  6720. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6721. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6722. {
  6723. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6724. }
  6725. }
  6726. }
  6727. //---------------------------------------------------------------------------
  6728. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6729. UnicodeString Message, TQueryType Type,
  6730. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6731. {
  6732. if ((E == NULL) ||
  6733. ExceptionMessage(E, Message))
  6734. {
  6735. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6736. if (Important)
  6737. {
  6738. Seconds *= 5;
  6739. }
  6740. UnicodeString NoteMessage(UnformatMessage(Message));
  6741. if (Terminal != NULL)
  6742. {
  6743. NoteMessage = FORMAT(L"%s: %s",
  6744. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6745. }
  6746. if (WinConfiguration->BalloonNotifications)
  6747. {
  6748. AddNote(NoteMessage);
  6749. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6750. }
  6751. else
  6752. {
  6753. FlashOnBackground();
  6754. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6755. }
  6756. }
  6757. }
  6758. //---------------------------------------------------------------------------
  6759. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6760. {
  6761. RestoreApp();
  6762. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6763. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6764. !NonVisualDataModule->Busy)
  6765. {
  6766. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6767. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6768. if (!ComponentVisible[fcQueueView])
  6769. {
  6770. ToggleQueueVisibility();
  6771. GoToQueue();
  6772. }
  6773. }
  6774. }
  6775. //---------------------------------------------------------------------------
  6776. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6777. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6778. {
  6779. UnicodeString Message;
  6780. TNotifyEvent OnClick = NULL;
  6781. TObject * UserData = NULL;
  6782. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6783. switch (Event)
  6784. {
  6785. case qeEmptyButMonitored:
  6786. if ((ATerminal != Terminal) || QueueInvisible)
  6787. {
  6788. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6789. OnClick = QueueEmptyNoteClicked;
  6790. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6791. TerminalNoteData->Terminal = ATerminal;
  6792. UserData = TerminalNoteData;
  6793. }
  6794. break;
  6795. case qeEmpty:
  6796. OperationComplete(ATerminal->QueueOperationStart);
  6797. break;
  6798. case qePendingUserAction:
  6799. if ((ATerminal != Terminal) ||
  6800. (QueueInvisible && !IsQueueAutoPopup()))
  6801. {
  6802. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6803. }
  6804. break;
  6805. default:
  6806. DebugFail();
  6807. }
  6808. if (!Message.IsEmpty())
  6809. {
  6810. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6811. }
  6812. }
  6813. //---------------------------------------------------------------------------
  6814. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6815. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6816. {
  6817. if (FDDExtMapFile != NULL)
  6818. {
  6819. CloseHandle(FDDExtMapFile);
  6820. FDDExtMapFile = NULL;
  6821. }
  6822. if (WinConfiguration->DDFakeFile)
  6823. {
  6824. DDFakeFileInitDrag(FileList, Created);
  6825. }
  6826. }
  6827. //---------------------------------------------------------------------------
  6828. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6829. {
  6830. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6831. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6832. {
  6833. FFakeFileDropTarget = FileName;
  6834. }
  6835. }
  6836. //---------------------------------------------------------------------------
  6837. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6838. {
  6839. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6840. if (!ForceDirectories(ApiPath(Result)))
  6841. {
  6842. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6843. }
  6844. FileSetAttr(ApiPath(Result), faHidden);
  6845. return Result;
  6846. }
  6847. //---------------------------------------------------------------------------
  6848. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6849. bool & Created)
  6850. {
  6851. FFakeFileDropTarget = UnicodeString();
  6852. FDragFakeDirectory = CreateFakeTransferDirectory();
  6853. FileList->AddItem(NULL, FDragFakeDirectory);
  6854. Created = true;
  6855. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6856. {
  6857. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6858. }
  6859. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6860. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6861. {
  6862. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6863. TDragExtCommStruct* CommStruct;
  6864. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6865. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6866. DebugAssert(CommStruct != NULL);
  6867. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6868. CommStruct->Dragging = true;
  6869. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6870. LENOF(CommStruct->DropDest));
  6871. NULL_TERMINATE(CommStruct->DropDest);
  6872. UnmapViewOfFile(CommStruct);
  6873. }
  6874. }
  6875. //---------------------------------------------------------------------------
  6876. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6877. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6878. {
  6879. bool Result;
  6880. DebugAssert(!IsLocalBrowserMode());
  6881. if (Sender == RemoteDirView)
  6882. {
  6883. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6884. }
  6885. else
  6886. {
  6887. DebugAssert(Sender == RemoteDriveView);
  6888. TStrings * FileList = RemoteDriveView->DragFileList();
  6889. try
  6890. {
  6891. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6892. }
  6893. __finally
  6894. {
  6895. delete FileList;
  6896. }
  6897. }
  6898. if (FDDTargetControl == RemoteDriveView)
  6899. {
  6900. RemoteDriveView->UpdateDropTarget();
  6901. }
  6902. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6903. // or from tree view to dir view.
  6904. // foMove happens when file/dir is dragged from remote tree view outside of
  6905. // application via dragex
  6906. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6907. (DropSourceControl == RemoteDriveView))
  6908. {
  6909. RemoteDriveView->UpdateDropSource();
  6910. }
  6911. return Result;
  6912. }
  6913. //---------------------------------------------------------------------------
  6914. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6915. {
  6916. DebugAssert(!IsLocalBrowserMode());
  6917. // This also handles drops of remote files to queue.
  6918. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6919. SAFE_DESTROY(FDDFileList);
  6920. if (!FFakeFileDropTarget.IsEmpty())
  6921. {
  6922. RemoveDir(ApiPath(FFakeFileDropTarget));
  6923. }
  6924. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6925. {
  6926. try
  6927. {
  6928. TDragResult DDResult = (Sender == RemoteDirView) ?
  6929. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6930. // Focus is moved to the target application,
  6931. // but as we are going to present the UI, we need to steal the focus back.
  6932. // This most likely won't work though (windows does not allow application
  6933. // to steal focus most of the time)
  6934. Application->BringToFront();
  6935. // On older version of Windows we never got drMove here, see also comment below.
  6936. // On Windows 10, we get the "move".
  6937. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6938. {
  6939. UnicodeString TargetDirectory;
  6940. TFileOperation Operation;
  6941. // drInvalid may mean drMove, see comment below
  6942. switch (DDResult)
  6943. {
  6944. case drCopy:
  6945. Operation = foCopy;
  6946. break;
  6947. case drMove:
  6948. Operation = foMove;
  6949. break;
  6950. default:
  6951. DebugFail();
  6952. case drInvalid:
  6953. // prefer "copy" for safety
  6954. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6955. break;
  6956. }
  6957. TTransferOperationParam Param;
  6958. UnicodeString CounterName;
  6959. bool ForceQueue;
  6960. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6961. {
  6962. // we get drInvalid both if d&d was intercepted by ddext,
  6963. // and when users drops on no-drop location.
  6964. // we tell the difference by existence of response from ddext,
  6965. // so we ignore absence of response in this case
  6966. if (DDResult != drInvalid)
  6967. {
  6968. // here we know that the extension is installed,
  6969. // as it is checked as soon as drag&drop starts from
  6970. // RemoteFileControlDDCreateDragFileList
  6971. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6972. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6973. {
  6974. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6975. }
  6976. else
  6977. {
  6978. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6979. }
  6980. }
  6981. }
  6982. else
  6983. {
  6984. // download using fake file
  6985. Param.Temp = false;
  6986. Param.DragDrop = true;
  6987. if (ForceQueue)
  6988. {
  6989. Param.Queue = asOn;
  6990. }
  6991. if (Sender == RemoteDirView)
  6992. {
  6993. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6994. }
  6995. if (RemoteFileControlFileOperation(Sender, Operation,
  6996. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6997. {
  6998. Configuration->Usage->Inc(CounterName);
  6999. }
  7000. }
  7001. }
  7002. }
  7003. __finally
  7004. {
  7005. CloseHandle(FDDExtMapFile);
  7006. FDDExtMapFile = NULL;
  7007. delete FDragFakeMonitors;
  7008. FDragFakeMonitors = NULL;
  7009. RemoveDir(ApiPath(FDragFakeDirectory));
  7010. FDragFakeDirectory = L"";
  7011. FFakeFileDropTarget = UnicodeString();
  7012. }
  7013. }
  7014. if (FDragDropSshTerminate.get() != NULL)
  7015. {
  7016. FDragDropSshTerminate->Rethrow();
  7017. }
  7018. }
  7019. //---------------------------------------------------------------------------
  7020. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7021. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7022. {
  7023. // Remember drop effect so we know (when user drops files), if we copy or move
  7024. FLastDropEffect = dwEffect;
  7025. }
  7026. //---------------------------------------------------------------------------
  7027. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7028. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7029. {
  7030. bool Result;
  7031. if (FDDTargetControl == QueueView3)
  7032. {
  7033. Directory = DefaultDownloadTargetDirectory();
  7034. Result = true;
  7035. CounterName = L"DownloadsDragDropQueue";
  7036. ForceQueue = true;
  7037. }
  7038. else if (!FFakeFileDropTarget.IsEmpty())
  7039. {
  7040. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7041. Result = true;
  7042. ForceQueue = false;
  7043. CounterName = L"DownloadsDragDropFakeFile";
  7044. }
  7045. else
  7046. {
  7047. ForceQueue = false;
  7048. Enabled = false;
  7049. try
  7050. {
  7051. int Timer = 0;
  7052. Result = false;
  7053. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7054. {
  7055. {
  7056. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7057. TDragExtCommStruct* CommStruct;
  7058. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7059. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7060. DebugAssert(CommStruct != NULL);
  7061. Result = !CommStruct->Dragging;
  7062. if (Result)
  7063. {
  7064. Directory = ExtractFilePath(CommStruct->DropDest);
  7065. CounterName = L"DownloadsDragDropExternalExt";
  7066. }
  7067. UnmapViewOfFile(CommStruct);
  7068. }
  7069. if (!Result)
  7070. {
  7071. Sleep(50);
  7072. Timer += 50;
  7073. Application->ProcessMessages();
  7074. }
  7075. }
  7076. }
  7077. __finally
  7078. {
  7079. Enabled = true;
  7080. }
  7081. }
  7082. return Result;
  7083. }
  7084. //---------------------------------------------------------------------------
  7085. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7086. const UnicodeString TempDir, int SecDelay)
  7087. {
  7088. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7089. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7090. if (FDelayedDeletionTimer == NULL)
  7091. {
  7092. DebugAssert(HandleAllocated());
  7093. FDelayedDeletionTimer = new TTimer(this);
  7094. FDelayedDeletionTimer->Interval = 10000;
  7095. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7096. }
  7097. else
  7098. {
  7099. FDelayedDeletionTimer->Enabled = true;
  7100. }
  7101. }
  7102. //---------------------------------------------------------------------------
  7103. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7104. {
  7105. DebugAssert(FDelayedDeletionList != NULL);
  7106. TDateTime N = Now();
  7107. TDateTime Alert;
  7108. UnicodeString Directory;
  7109. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7110. {
  7111. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7112. if ((N >= Alert) || (Sender == NULL))
  7113. {
  7114. Directory = FDelayedDeletionList->Strings[Index];
  7115. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7116. {
  7117. FDelayedDeletionList->Delete(Index);
  7118. }
  7119. }
  7120. }
  7121. if (FDelayedDeletionList->Count == 0)
  7122. {
  7123. FDelayedDeletionTimer->Enabled = false;
  7124. }
  7125. }
  7126. //---------------------------------------------------------------------------
  7127. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7128. {
  7129. DebugAssert(!IsLocalBrowserMode());
  7130. if (IsFileControl(FDDTargetControl, osRemote) ||
  7131. (FDDTargetControl == SessionsPageControl))
  7132. {
  7133. TTerminal * TargetTerminal = NULL;
  7134. TFileOperation Operation = foNone;
  7135. if (FDDTargetControl == SessionsPageControl)
  7136. {
  7137. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7138. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7139. // do not allow dropping on the "+" tab
  7140. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7141. if (TargetTerminal != NULL)
  7142. {
  7143. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7144. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7145. {
  7146. Operation = foRemoteMove;
  7147. }
  7148. else
  7149. {
  7150. Operation = foRemoteCopy;
  7151. }
  7152. }
  7153. }
  7154. else
  7155. {
  7156. if (FLastDropEffect == DROPEFFECT_MOVE)
  7157. {
  7158. Operation = foRemoteMove;
  7159. }
  7160. else if (FLastDropEffect == DROPEFFECT_COPY)
  7161. {
  7162. Operation = foRemoteCopy;
  7163. }
  7164. }
  7165. if (Operation != foNone)
  7166. {
  7167. RemoteFileControlFileOperation(DropSourceControl,
  7168. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7169. }
  7170. // abort drag&drop
  7171. Abort();
  7172. }
  7173. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7174. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7175. (FDDTargetControl != QueueView3))
  7176. {
  7177. DebugAssert(!FDragTempDir.IsEmpty());
  7178. TTransferType Type;
  7179. UnicodeString TempDir = FDragTempDir;
  7180. // We clear FDragTempDir before calling
  7181. // just in case it fail (raises exception)
  7182. FDragTempDir = L"";
  7183. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7184. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7185. // empty directory parameter means temp directory -> don't display it!
  7186. UnicodeString TargetDir = L"";
  7187. int Options = 0;
  7188. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7189. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7190. {
  7191. Abort();
  7192. }
  7193. // TargetDir is set when dropped on local file control
  7194. // (this was workaround for legacy dirview event handling, now it should be
  7195. // made prettier)
  7196. if (TargetDir.IsEmpty())
  7197. {
  7198. TargetDir = TempDir;
  7199. if (ForceDirectories(ApiPath(TargetDir)))
  7200. {
  7201. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7202. FPendingTempSpaceWarn = true;
  7203. try
  7204. {
  7205. FDragDropOperation = true;
  7206. int Params = cpTemporary |
  7207. (Type == ttMove ? cpDelete : 0);
  7208. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7209. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7210. }
  7211. __finally
  7212. {
  7213. FDragDropOperation = false;
  7214. FPendingTempSpaceWarn = false;
  7215. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7216. }
  7217. }
  7218. else
  7219. {
  7220. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7221. }
  7222. }
  7223. }
  7224. }
  7225. //---------------------------------------------------------------------------
  7226. void __fastcall TCustomScpExplorerForm::DDDownload(
  7227. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7228. {
  7229. DebugAssert(!IsLocalBrowserMode());
  7230. TAutoBatch AutoBatch(this);
  7231. UpdateCopyParamCounters(*CopyParam);
  7232. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7233. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7234. {
  7235. RemoteDriveView->UpdateDropSource();
  7236. }
  7237. }
  7238. //---------------------------------------------------------------------------
  7239. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7240. {
  7241. public:
  7242. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7243. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7244. {
  7245. }
  7246. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7247. {
  7248. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7249. TDataObjectFilesEx::AllowData(FormatEtc);
  7250. }
  7251. };
  7252. //---------------------------------------------------------------------------
  7253. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7254. TObject * Sender, TDataObject *& DataObject)
  7255. {
  7256. if (FDDExtMapFile != NULL)
  7257. {
  7258. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7259. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7260. {
  7261. Abort();
  7262. }
  7263. if (FileList->Count > 0)
  7264. {
  7265. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7266. if (!FilesObject->IsValid(true, true))
  7267. {
  7268. FilesObject->_Release();
  7269. }
  7270. else
  7271. {
  7272. DataObject = FilesObject;
  7273. }
  7274. }
  7275. }
  7276. }
  7277. //---------------------------------------------------------------------------
  7278. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7279. {
  7280. DebugFail();
  7281. }
  7282. //---------------------------------------------------------------------------
  7283. void __fastcall TCustomScpExplorerForm::GoToTree()
  7284. {
  7285. ComponentVisible[fcRemoteTree] = true;
  7286. DriveView(osRemote)->SetFocus();
  7287. }
  7288. //---------------------------------------------------------------------------
  7289. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7290. TPanelExport Export)
  7291. {
  7292. TCustomDirView * DirView = this->DirView(Side);
  7293. std::unique_ptr<TStrings> ExportData(new TStringList());
  7294. switch (Export)
  7295. {
  7296. case pePath:
  7297. ExportData->Add(DirView->PathName);
  7298. break;
  7299. case peFileList:
  7300. case peFullFileList:
  7301. {
  7302. bool FullPath = (Export == peFullFileList);
  7303. DirView->CreateFileList(false, FullPath, ExportData.get());
  7304. for (int Index = 0; Index < ExportData->Count; Index++)
  7305. {
  7306. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7307. {
  7308. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7309. }
  7310. }
  7311. }
  7312. break;
  7313. default:
  7314. DebugFail();
  7315. }
  7316. return ExportData.release();
  7317. }
  7318. //---------------------------------------------------------------------------
  7319. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7320. TPanelExport Export, TPanelExportDestination Destination)
  7321. {
  7322. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7323. PanelExportStore(Side, Export, Destination, ExportData.get());
  7324. }
  7325. //---------------------------------------------------------------------------
  7326. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7327. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7328. TStrings * ExportData)
  7329. {
  7330. if (Destination == pedClipboard)
  7331. {
  7332. TInstantOperationVisualizer Visualizer;
  7333. CopyToClipboard(ExportData);
  7334. }
  7335. else
  7336. {
  7337. DebugFail();
  7338. }
  7339. }
  7340. //---------------------------------------------------------------------------
  7341. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7342. {
  7343. TCustomDirView * DirView = this->DirView(Side);
  7344. UnicodeString Mask = DirView->Mask;
  7345. if (DoFilterMaskDialog(DirView, Mask))
  7346. {
  7347. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7348. Configuration->Usage->Inc(L"Filters");
  7349. }
  7350. }
  7351. //---------------------------------------------------------------------------
  7352. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7353. {
  7354. return FQueueController->DefaultOperation();
  7355. }
  7356. //---------------------------------------------------------------------------
  7357. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7358. TQueueOperation Operation, void ** Param)
  7359. {
  7360. switch (Operation)
  7361. {
  7362. case qoPreferences:
  7363. return true;
  7364. case qoGoTo:
  7365. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7366. case qoOnceEmpty:
  7367. return IsAnythingQueued();
  7368. default:
  7369. return FQueueController->AllowOperation(Operation, Param);
  7370. }
  7371. }
  7372. //---------------------------------------------------------------------------
  7373. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7374. {
  7375. if (DebugAlwaysTrue(QueueView3->Visible))
  7376. {
  7377. QueueView3->SetFocus();
  7378. }
  7379. }
  7380. //---------------------------------------------------------------------------
  7381. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7382. TQueueOperation Operation, void * Param)
  7383. {
  7384. if (Operation == qoGoTo)
  7385. {
  7386. GoToQueue();
  7387. }
  7388. else if (Operation == qoPreferences)
  7389. {
  7390. PreferencesDialog(pmQueue);
  7391. }
  7392. else
  7393. {
  7394. FQueueController->ExecuteOperation(Operation, Param);
  7395. }
  7396. }
  7397. //---------------------------------------------------------------------------
  7398. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7399. {
  7400. return (Queue != NULL) && Queue->Enabled;
  7401. }
  7402. //---------------------------------------------------------------------------
  7403. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7404. {
  7405. DebugAssert(Queue != NULL);
  7406. if (Queue != NULL)
  7407. {
  7408. Queue->Enabled = !Queue->Enabled;
  7409. }
  7410. }
  7411. //---------------------------------------------------------------------------
  7412. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7413. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7414. {
  7415. FQueueActedItem = QueueView3->ItemFocused;
  7416. }
  7417. //---------------------------------------------------------------------------
  7418. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7419. {
  7420. return TopDock->Height + QueueSplitter->Height;
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7424. {
  7425. return
  7426. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7427. (QueueDock->Visible ? QueueDock->Height : 0) +
  7428. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7429. }
  7430. //---------------------------------------------------------------------------
  7431. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7432. {
  7433. return ScaleByTextHeight(this, 48);
  7434. }
  7435. //---------------------------------------------------------------------------
  7436. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7437. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7438. {
  7439. // when queue is hidden by double-clicking splitter, stray attempt to
  7440. // resize the panel with strange value arrives, make sure it is ignored
  7441. if (ComponentVisible[fcQueueView])
  7442. {
  7443. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7444. if (NewSize > MaxHeightLimit)
  7445. {
  7446. NewSize = MaxHeightLimit;
  7447. }
  7448. int MinHeightLimit =
  7449. GetStaticQueuePanelComponentsHeight() +
  7450. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7451. GetMinQueueViewHeight();
  7452. if (NewSize < MinHeightLimit)
  7453. {
  7454. NewSize = MinHeightLimit;
  7455. }
  7456. }
  7457. else
  7458. {
  7459. Accept = false;
  7460. }
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7464. {
  7465. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7466. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7467. if (QueueViewHeight < GetMinQueueViewHeight())
  7468. {
  7469. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7470. }
  7471. }
  7472. //---------------------------------------------------------------------------
  7473. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7474. TDragObject *& /*DragObject*/)
  7475. {
  7476. FQueueActedItem = QueueView3->ItemFocused;
  7477. }
  7478. //---------------------------------------------------------------------------
  7479. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7480. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7481. {
  7482. Accept = true;
  7483. if (Source == QueueView3)
  7484. {
  7485. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7486. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7487. if (Accept)
  7488. {
  7489. TQueueItemProxy * QueueItem;
  7490. TQueueItemProxy * DestQueueItem;
  7491. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7492. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7493. Accept = (QueueItem != DestQueueItem) &&
  7494. (QueueItem->Status == TQueueItem::qsPending) &&
  7495. (DestQueueItem->Status == TQueueItem::qsPending);
  7496. }
  7497. }
  7498. }
  7499. //---------------------------------------------------------------------------
  7500. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7501. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7502. {
  7503. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7504. {
  7505. TQueueItemProxy * QueueItem;
  7506. TQueueItemProxy * DestQueueItem;
  7507. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7508. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7509. QueueItem->Move(DestQueueItem);
  7510. }
  7511. }
  7512. //---------------------------------------------------------------------------
  7513. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7514. {
  7515. if ((QueueView3->ItemFocused == NULL) &&
  7516. (QueueView3->Items->Count > 0))
  7517. {
  7518. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7519. }
  7520. QueueLabelUpdateStatus();
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7524. {
  7525. QueueLabelUpdateStatus();
  7526. }
  7527. //---------------------------------------------------------------------------
  7528. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7529. {
  7530. QueueLabel->UpdateStatus();
  7531. }
  7532. //---------------------------------------------------------------------------
  7533. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7534. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7535. {
  7536. if (Selected)
  7537. {
  7538. NonVisualDataModule->UpdateNonVisibleActions();
  7539. }
  7540. }
  7541. //---------------------------------------------------------------------------
  7542. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7543. {
  7544. TDragDropFilesEx * Result = NULL;
  7545. if (Sender == SessionsPageControl)
  7546. {
  7547. Result = FSessionsDragDropFilesEx;
  7548. }
  7549. else if (Sender == QueueView3)
  7550. {
  7551. Result = FQueueDragDropFilesEx;
  7552. }
  7553. else
  7554. {
  7555. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7556. if (DirView != NULL)
  7557. {
  7558. Result = DirView->DragDropFilesEx;
  7559. }
  7560. else
  7561. {
  7562. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7563. if (DriveView != NULL)
  7564. {
  7565. Result = DriveView->DragDropFilesEx;
  7566. }
  7567. }
  7568. }
  7569. DebugAssert(Result != NULL);
  7570. return Result;
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7574. {
  7575. return (DView->SelCount == DView->FilesCount);
  7576. }
  7577. //---------------------------------------------------------------------------
  7578. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7579. {
  7580. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7581. }
  7582. //---------------------------------------------------------------------------
  7583. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7584. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7585. {
  7586. DebugAssert(!IsLocalBrowserMode());
  7587. TFileOperation Operation;
  7588. switch (Effect)
  7589. {
  7590. case DROPEFFECT_MOVE:
  7591. Operation = foMove;
  7592. break;
  7593. case DROPEFFECT_COPY:
  7594. // occures on WinXP (reported by user)
  7595. default:
  7596. Operation = foCopy;
  7597. break;
  7598. };
  7599. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7600. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7601. if (DragDropFilesEx->FileList->Count > 0)
  7602. {
  7603. TStrings * FileList = new TStringList();
  7604. try
  7605. {
  7606. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7607. {
  7608. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7609. }
  7610. FDragDropOperation = true;
  7611. TTransferOperationParam Param;
  7612. Param.TargetDirectory = TargetPath;
  7613. // upload, no temp dirs
  7614. Param.Temp = false;
  7615. Param.DragDrop = DragDrop;
  7616. Param.Options =
  7617. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7618. if (ForceQueue)
  7619. {
  7620. Param.Queue = asOn;
  7621. }
  7622. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7623. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7624. {
  7625. if (IsFileControl(DropSourceControl, osLocal))
  7626. {
  7627. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7628. }
  7629. else
  7630. {
  7631. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7632. }
  7633. }
  7634. }
  7635. __finally
  7636. {
  7637. FDragDropOperation = false;
  7638. delete FileList;
  7639. }
  7640. }
  7641. }
  7642. //---------------------------------------------------------------------------
  7643. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7644. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7645. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7646. {
  7647. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7648. }
  7649. //---------------------------------------------------------------------------
  7650. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7651. TObject * Sender, int grfKeyState, int & dwEffect)
  7652. {
  7653. DebugAssert(!IsLocalBrowserMode());
  7654. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7655. if ((dwEffect != DROPEFFECT_NONE) &&
  7656. IsFileControl(DropSourceControl, osRemote))
  7657. {
  7658. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7659. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7660. (RemoteDirView->DropTarget == NULL))
  7661. {
  7662. dwEffect = DROPEFFECT_NONE;
  7663. }
  7664. else
  7665. {
  7666. if (dwEffect == DROPEFFECT_COPY)
  7667. {
  7668. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7669. // currently we support copying always (at least via temporary directory);
  7670. // remove associated checks once this all proves stable and working
  7671. bool CopyCapable = true;
  7672. // if we do not support neither of operations, there's no discussion
  7673. if (!MoveCapable && !CopyCapable)
  7674. {
  7675. dwEffect = DROPEFFECT_NONE;
  7676. }
  7677. else
  7678. {
  7679. // The default effect inside remote panel is move,
  7680. // unless we do not support it, but support copy
  7681. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7682. {
  7683. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7684. }
  7685. else
  7686. {
  7687. // with ctrl-down, we want copy unless it is not supported
  7688. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7689. }
  7690. }
  7691. }
  7692. }
  7693. }
  7694. }
  7695. //---------------------------------------------------------------------------
  7696. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7697. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7698. {
  7699. DebugAssert(!IsLocalBrowserMode());
  7700. if (FDDTotalSize >= 0)
  7701. {
  7702. if (File->IsDirectory)
  7703. {
  7704. FDDTotalSize = -1;
  7705. }
  7706. else
  7707. {
  7708. FDDTotalSize += File->Size;
  7709. }
  7710. }
  7711. DebugAssert(!FDragTempDir.IsEmpty());
  7712. // TODO: this is quite ineffective
  7713. // TODO: what if invalid character replacement is disabled?
  7714. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7715. UnicodeString TransferFileName;
  7716. if (Sender == RemoteDriveView)
  7717. {
  7718. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7719. }
  7720. else
  7721. {
  7722. TransferFileName = File->FileName;
  7723. }
  7724. FDDFileList->AddObject(TransferFileName, File);
  7725. }
  7726. //---------------------------------------------------------------------------
  7727. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7728. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7729. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7730. {
  7731. // sometimes we do not get DDEnd so the list is not released
  7732. SAFE_DESTROY(FDDFileList);
  7733. FDDFileList = new TStringList();
  7734. FDragTempDir = WinConfiguration->TemporaryDir();
  7735. FDDTotalSize = 0;
  7736. FDragDropSshTerminate.reset(NULL);
  7737. }
  7738. //---------------------------------------------------------------------------
  7739. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7740. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7741. HRESULT & Result)
  7742. {
  7743. if (Result == DRAGDROP_S_DROP)
  7744. {
  7745. try
  7746. {
  7747. GlobalDragImageList->HideDragImage();
  7748. try
  7749. {
  7750. RemoteFileControlDDTargetDrop();
  7751. }
  7752. catch(ESshTerminate & E)
  7753. {
  7754. FDragDropSshTerminate.reset(E.Clone());
  7755. }
  7756. }
  7757. catch (Exception &E)
  7758. {
  7759. // If downloading fails we need to cancel drag&drop, otherwise
  7760. // Explorer shows error
  7761. // But by the way exception probably never reach this point as
  7762. // it's catched on way.
  7763. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7764. Result = DRAGDROP_S_CANCEL;
  7765. ShowExtendedException(Terminal, &E);
  7766. }
  7767. }
  7768. }
  7769. //---------------------------------------------------------------------------
  7770. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7771. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7772. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7773. {
  7774. TFileMasks::TParams MaskParams;
  7775. MaskParams.Size = Size;
  7776. MaskParams.Modification = Modification;
  7777. // this does not re-parse the mask if it is the same as the last time
  7778. FDirViewMatchMask = Masks;
  7779. bool ImplicitMatch;
  7780. Matches =
  7781. // RecurseInclude parameter has no effect as the Path is empty
  7782. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7783. (AllowImplicitMatches || !ImplicitMatch);
  7784. }
  7785. //---------------------------------------------------------------------------
  7786. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7787. TObject * Sender, TListItem * Item, WORD & Indexes)
  7788. {
  7789. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7790. UnicodeString Ext;
  7791. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7792. {
  7793. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7794. }
  7795. else
  7796. {
  7797. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7798. }
  7799. if (SameText(Ext, Configuration->PartialExt))
  7800. {
  7801. Indexes |= oiPartial;
  7802. }
  7803. }
  7804. //---------------------------------------------------------------------------
  7805. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7806. {
  7807. return
  7808. DirViewEnabled(osCurrent) &&
  7809. DirView(osCurrent)->CanPasteFromClipBoard();
  7810. }
  7811. //---------------------------------------------------------------------------
  7812. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7813. {
  7814. bool Result = false;
  7815. if (CanPasteToDirViewFromClipBoard())
  7816. {
  7817. Result = true;
  7818. }
  7819. else
  7820. {
  7821. UnicodeString ClipboardText;
  7822. if (NonEmptyTextFromClipboard(ClipboardText))
  7823. {
  7824. if (StoredSessions->IsUrl(ClipboardText))
  7825. {
  7826. Result = true;
  7827. }
  7828. else
  7829. {
  7830. Result = DirViewEnabled(osCurrent);
  7831. }
  7832. }
  7833. }
  7834. return Result;
  7835. }
  7836. //---------------------------------------------------------------------------
  7837. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7838. {
  7839. if (DoesClipboardContainOurFiles())
  7840. {
  7841. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7842. {
  7843. DebugAssert(!IsLocalBrowserMode());
  7844. TTerminalManager * Manager = TTerminalManager::Instance();
  7845. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7846. Manager->ActiveTerminal = FClipboardTerminal;
  7847. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7848. }
  7849. }
  7850. else if (CanPasteToDirViewFromClipBoard())
  7851. {
  7852. DirView(osCurrent)->PasteFromClipBoard();
  7853. }
  7854. else
  7855. {
  7856. UnicodeString ClipboardText;
  7857. if (NonEmptyTextFromClipboard(ClipboardText))
  7858. {
  7859. if (StoredSessions->IsUrl(ClipboardText))
  7860. {
  7861. NewSession(false, ClipboardText);
  7862. }
  7863. else
  7864. {
  7865. DirView(osCurrent)->Path = ClipboardText;
  7866. }
  7867. }
  7868. }
  7869. }
  7870. //---------------------------------------------------------------------------
  7871. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7872. {
  7873. // TBD
  7874. }
  7875. //---------------------------------------------------------------------------
  7876. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7877. {
  7878. TCustomDirView * ADirView = DirView(Side);
  7879. ADirView->SelectAll(Mode);
  7880. ADirView->SetFocus();
  7881. }
  7882. //---------------------------------------------------------------------------
  7883. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7884. {
  7885. TCustomDirView * ADirView = DirView(Side);
  7886. TFileFilter Filter;
  7887. DefaultFileFilter(Filter);
  7888. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7889. {
  7890. Configuration->Usage->Inc(L"MaskSelections");
  7891. ADirView->SelectFiles(Filter, Select);
  7892. ADirView->SetFocus();
  7893. }
  7894. }
  7895. //---------------------------------------------------------------------------
  7896. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7897. {
  7898. TCustomDirView * ADirView = DirView(Side);
  7899. ADirView->RestoreSelectedNames();
  7900. ADirView->SetFocus();
  7901. }
  7902. //---------------------------------------------------------------------------
  7903. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7904. {
  7905. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7906. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7907. {
  7908. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7909. UnicodeString Ext;
  7910. if (!IsSideLocalBrowser(osCurrent))
  7911. {
  7912. Ext = UnixExtractFileExt(FileName);
  7913. }
  7914. else
  7915. {
  7916. Ext = ExtractFileExt(FileName);
  7917. }
  7918. if (Ext.IsEmpty())
  7919. {
  7920. Ext = L".";
  7921. }
  7922. TFileFilter Filter;
  7923. Filter.Masks = FORMAT(L"*%s", (Ext));
  7924. Filter.Directories = false;
  7925. CurrentDirView->SelectFiles(Filter, Select);
  7926. }
  7927. }
  7928. //---------------------------------------------------------------------------
  7929. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7930. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7931. {
  7932. UnicodeString Result;
  7933. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7934. {
  7935. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7936. }
  7937. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7938. {
  7939. // noop
  7940. }
  7941. else
  7942. {
  7943. Result =
  7944. FMTLOAD(FILE_INFO_FORMAT,
  7945. (FormatBytes(FileInfo.SelectedSize),
  7946. FormatBytes(FileInfo.FilesSize),
  7947. FormatNumber(FileInfo.SelectedCount),
  7948. FormatNumber(FileInfo.FilesCount)));
  7949. }
  7950. return Result;
  7951. }
  7952. //---------------------------------------------------------------------------
  7953. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7954. TTBXStatusPanel * Panel, TOperationSide Side)
  7955. {
  7956. if (Panel->Index == 1)
  7957. {
  7958. ToggleShowHiddenFiles();
  7959. }
  7960. else if (Panel->Index == 2)
  7961. {
  7962. Filter(Side);
  7963. }
  7964. }
  7965. //---------------------------------------------------------------------------
  7966. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7967. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7968. {
  7969. DebugAssert(!StatusBar->SimplePanel);
  7970. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7971. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7972. }
  7973. //---------------------------------------------------------------------------
  7974. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7975. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7976. {
  7977. DebugAssert(StatusBar->Panels->Count >= 3);
  7978. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7979. if (FileInfo.HiddenCount > 0)
  7980. {
  7981. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7982. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7983. }
  7984. else
  7985. {
  7986. HiddenFilesPanel->ViewPriority = 0;
  7987. // not really necessary, just to cleanup no-longer-valid data
  7988. HiddenFilesPanel->Caption = L"";
  7989. }
  7990. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7991. if (FileInfo.FilteredCount > 0)
  7992. {
  7993. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7994. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7995. }
  7996. else
  7997. {
  7998. FilteredFilesPanel->ViewPriority = 0;
  7999. // not really necessary, just to cleanup no-longer-valid data
  8000. FilteredFilesPanel->Caption = L"";
  8001. }
  8002. }
  8003. //---------------------------------------------------------------------------
  8004. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8005. TObject * /*Sender*/)
  8006. {
  8007. if (DirView(osRemote)->Enabled)
  8008. {
  8009. DirView(osRemote)->SetFocus();
  8010. }
  8011. }
  8012. //---------------------------------------------------------------------------
  8013. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8014. {
  8015. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8016. switch (Config.Show)
  8017. {
  8018. case qvShow:
  8019. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8020. {
  8021. Config.Show = qvHide;
  8022. }
  8023. else
  8024. {
  8025. Config.Show = Config.LastHideShow;
  8026. }
  8027. break;
  8028. case qvHideWhenEmpty:
  8029. if (ComponentVisible[fcQueueView])
  8030. {
  8031. Config.Show = qvHide;
  8032. }
  8033. else
  8034. {
  8035. Config.LastHideShow = Config.Show;
  8036. Config.Show = qvShow;
  8037. }
  8038. break;
  8039. case qvHide:
  8040. Config.LastHideShow = Config.Show;
  8041. Config.Show = qvShow;
  8042. break;
  8043. }
  8044. WinConfiguration->QueueView = Config;
  8045. }
  8046. //---------------------------------------------------------------------------
  8047. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8048. {
  8049. UnicodeString Result;
  8050. if (FTerminal != NULL)
  8051. {
  8052. switch (WinConfiguration->PathInCaption)
  8053. {
  8054. case picShort:
  8055. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8056. break;
  8057. case picFull:
  8058. Result = FTerminal->CurrentDirectory;
  8059. break;
  8060. }
  8061. }
  8062. return Result;
  8063. }
  8064. //---------------------------------------------------------------------------
  8065. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8066. {
  8067. TColor Result = GetWindowColor(FSessionColor);
  8068. return Result;
  8069. }
  8070. //---------------------------------------------------------------------------
  8071. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8072. {
  8073. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8074. return Result;
  8075. }
  8076. //---------------------------------------------------------------------------
  8077. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8078. {
  8079. TTerminalManager::Instance()->UpdateAppTitle();
  8080. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8081. // background to gray on Windows 7 (works on Windows 10).
  8082. // See also EnableControl
  8083. if (Showing)
  8084. {
  8085. if (Terminal != NULL)
  8086. {
  8087. // Update path when it changes
  8088. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8089. {
  8090. UpdateSessionTab(SessionsPageControl->ActivePage);
  8091. }
  8092. }
  8093. NonVisualDataModule->ReconnectSessionAction->Update();
  8094. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8095. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8096. CenterReconnectToolbar();
  8097. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  8098. if (HasTerminal)
  8099. {
  8100. // TODO needed yet with second local browser?
  8101. if (!RemoteDirView->Enabled)
  8102. {
  8103. RemoteDirView->Enabled = true;
  8104. if (FRemoteDirViewWasFocused)
  8105. {
  8106. ActiveControl = RemoteDirView;
  8107. }
  8108. }
  8109. RemoteDirView->Color = PanelColor();
  8110. }
  8111. else
  8112. {
  8113. if (RemoteDirView->Enabled)
  8114. {
  8115. // This is first called when the form is being constructed
  8116. // (not anymore due to Showing test above)
  8117. // but the false is overriden in the constructor later.
  8118. // An even later in TScpCommanderForm::DoShow()
  8119. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8120. RemoteDirView->Enabled = false;
  8121. }
  8122. RemoteDirView->Color = DisabledPanelColor();
  8123. }
  8124. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8125. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8126. RemoteDriveView->Color = RemoteDirView->Color;
  8127. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8128. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8129. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8130. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8131. QueueFileList->Enabled = QueueView3->Enabled;
  8132. QueueFileList->Color = QueueView3->Color;
  8133. QueueFileList->Font->Color = QueueView3->Font->Color;
  8134. QueueLabelUpdateStatus();
  8135. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8136. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8137. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8138. }
  8139. }
  8140. //---------------------------------------------------------------------------
  8141. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8142. {
  8143. UpdateControls();
  8144. }
  8145. //---------------------------------------------------------------------------
  8146. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8147. TObject * Sender)
  8148. {
  8149. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8150. DebugAssert(DirView != NULL);
  8151. DoDirViewLoaded(DirView);
  8152. TransferPresetAutoSelect();
  8153. }
  8154. //---------------------------------------------------------------------------
  8155. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8156. {
  8157. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8158. // first run after installation
  8159. if (double(Updates.LastCheck) == 0)
  8160. {
  8161. // make sure next time there will be an update (if enabled)
  8162. Updates.LastCheck = TDateTime(1);
  8163. WinConfiguration->Updates = Updates;
  8164. }
  8165. else if ((double(Updates.Period) > 0) &&
  8166. (Now() - Updates.LastCheck >= Updates.Period))
  8167. {
  8168. TThreadMethod OnUpdatesChecked = NULL;
  8169. if (!IsUWP())
  8170. {
  8171. OnUpdatesChecked = UpdatesChecked;
  8172. }
  8173. StartUpdateThread(OnUpdatesChecked);
  8174. }
  8175. }
  8176. //---------------------------------------------------------------------------
  8177. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8178. {
  8179. UnicodeString Message;
  8180. bool New;
  8181. TQueryType Type;
  8182. GetUpdatesMessage(Message, New, Type, false);
  8183. if (!Message.IsEmpty())
  8184. {
  8185. if (New)
  8186. {
  8187. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8188. }
  8189. if (!New && (Type != qtWarning))
  8190. {
  8191. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8192. }
  8193. else
  8194. {
  8195. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8196. }
  8197. if (New)
  8198. {
  8199. Configuration->Usage->Inc(L"UpdateNotifications");
  8200. }
  8201. }
  8202. }
  8203. //---------------------------------------------------------------------------
  8204. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8205. {
  8206. RestoreApp();
  8207. bool CanDisplay = !NonVisualDataModule->Busy;
  8208. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8209. {
  8210. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8211. }
  8212. if (CanDisplay)
  8213. {
  8214. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8215. CheckForUpdates(true);
  8216. }
  8217. else
  8218. {
  8219. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8220. }
  8221. }
  8222. //---------------------------------------------------------------------------
  8223. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8224. TCopyParamRuleData & Data)
  8225. {
  8226. DebugAssert(Terminal != NULL);
  8227. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8228. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8229. Data.RemoteDirectory = RemoteDirView->PathName;
  8230. }
  8231. //---------------------------------------------------------------------------
  8232. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8233. {
  8234. // Terminal can be null when we are changing local directory implicitly,
  8235. // because it has been deleted, while no session is connected
  8236. // (Login dialog is open)
  8237. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8238. {
  8239. DebugAssert(!IsLocalBrowserMode());
  8240. TCopyParamRuleData Data;
  8241. GetTransferPresetAutoSelectData(Data);
  8242. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8243. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8244. if (CopyParamIndex < 0)
  8245. {
  8246. // there is no preset that matches autoselection
  8247. // set preset that we consider "default"
  8248. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8249. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8250. }
  8251. else
  8252. {
  8253. // there is preset matching autoselection
  8254. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8255. if (CopyParamName == FCopyParamAutoSelected)
  8256. {
  8257. // autoselected the same preset as the last time
  8258. // make no change (i.e. preserve custom user preset, if any)
  8259. }
  8260. else
  8261. {
  8262. // autoselected the different preset then the last time (or there
  8263. // was default preset set)
  8264. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8265. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8266. }
  8267. }
  8268. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8269. {
  8270. if (CopyParamIndex >= 0)
  8271. {
  8272. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8273. }
  8274. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8275. try
  8276. {
  8277. int Fmt =
  8278. (CopyParamIndex < 0) ?
  8279. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8280. COPY_PARAM_AUTOSELECTED;
  8281. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8282. Data->Message = MainInstructions(Message);
  8283. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8284. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8285. CopyParamAttrs);
  8286. if (CopyParamIndex >= 0)
  8287. {
  8288. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8289. Info = FORMAT(L"%s\n \n%s", (Info,
  8290. FMTLOAD(COPY_PARAM_RULE,
  8291. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8292. }
  8293. Data->Message += L"\n\n" + Info;
  8294. if (WinConfiguration->CopyParamAutoSelectNotice)
  8295. {
  8296. TransferPresetNoteMessage(Data, true);
  8297. }
  8298. else
  8299. {
  8300. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8301. Data = NULL; // ownership passed
  8302. }
  8303. }
  8304. __finally
  8305. {
  8306. delete Data;
  8307. }
  8308. }
  8309. }
  8310. }
  8311. //---------------------------------------------------------------------------
  8312. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8313. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8314. {
  8315. DebugAssert(NoteData != NULL);
  8316. DebugAssert(!IsLocalBrowserMode());
  8317. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8318. TQueryButtonAlias Aliases[1];
  8319. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8320. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8321. Params.Aliases = Aliases;
  8322. Params.AliasesCount = LENOF(Aliases);
  8323. unsigned int Result =
  8324. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8325. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8326. switch (Result)
  8327. {
  8328. case qaNeverAskAgain:
  8329. DebugAssert(AllowNeverAskAgain);
  8330. WinConfiguration->CopyParamAutoSelectNotice = false;
  8331. break;
  8332. case qaIgnore:
  8333. PreferencesDialog(pmPresets);
  8334. break;
  8335. }
  8336. }
  8337. //---------------------------------------------------------------------------
  8338. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8339. {
  8340. // as of now useless, as this is used for notes only, never for balloons, ...
  8341. RestoreApp();
  8342. // .. and we should never be busy here
  8343. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8344. {
  8345. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8346. }
  8347. }
  8348. //---------------------------------------------------------------------------
  8349. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8350. TPreferencesMode APreferencesMode)
  8351. {
  8352. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8353. TCopyParamRuleData Data;
  8354. if (Terminal != NULL)
  8355. {
  8356. PreferencesData.reset(new TPreferencesDialogData());
  8357. GetTransferPresetAutoSelectData(Data);
  8358. PreferencesData->CopyParamRuleData = &Data;
  8359. }
  8360. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8361. }
  8362. //---------------------------------------------------------------------------
  8363. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8364. const TCustomCommandType & Command)
  8365. {
  8366. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8367. {
  8368. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8369. }
  8370. }
  8371. //---------------------------------------------------------------------------
  8372. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8373. {
  8374. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8375. TCustomCommandType Command;
  8376. // make sure we use local custom command when remote are not supported
  8377. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8378. {
  8379. Command = FLastCustomCommand;
  8380. }
  8381. else
  8382. {
  8383. Command.Params = Command.Params | ccLocal;
  8384. }
  8385. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8386. FEditingFocusedAdHocCommand = OnFocused;
  8387. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8388. int Options =
  8389. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8390. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8391. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8392. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8393. {
  8394. FLastCustomCommand = Command;
  8395. UpdateCustomCommandsToolbar();
  8396. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8397. }
  8398. }
  8399. //---------------------------------------------------------------------------
  8400. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8401. {
  8402. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8403. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8404. DebugAssert(State > 0);
  8405. if (State <= 0)
  8406. {
  8407. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8408. }
  8409. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8410. }
  8411. //---------------------------------------------------------------------------
  8412. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8413. TCustomCommandType & Command, int & State)
  8414. {
  8415. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8416. if (Result)
  8417. {
  8418. Command = FLastCustomCommand;
  8419. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8420. }
  8421. return Result;
  8422. }
  8423. //---------------------------------------------------------------------------
  8424. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8425. {
  8426. ResetIncrementalSearch();
  8427. }
  8428. //---------------------------------------------------------------------------
  8429. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8430. {
  8431. DebugAssert(ComponentVisible[Component]);
  8432. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8433. }
  8434. //---------------------------------------------------------------------------
  8435. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8436. {
  8437. // when queue panel is resized here directly, the status bar is stretched
  8438. // over whole space the panel occupied
  8439. PostComponentHide(fcQueueView);
  8440. }
  8441. //---------------------------------------------------------------------------
  8442. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8443. {
  8444. ComponentVisible[fcQueueFileList] = false;
  8445. }
  8446. //---------------------------------------------------------------------------
  8447. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8448. {
  8449. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8450. RefreshColorMode();
  8451. WinConfiguration->ResetSysDarkTheme();
  8452. ConfigurationChanged();
  8453. ConfigureInterface();
  8454. // Should be called for all controls
  8455. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8456. }
  8457. //---------------------------------------------------------------------------
  8458. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8459. {
  8460. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8461. if (!FInvalid &&
  8462. (Message.LParam != 0) &&
  8463. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8464. {
  8465. ThemeChanged();
  8466. }
  8467. TForm::Dispatch(&Message);
  8468. }
  8469. //---------------------------------------------------------------------------
  8470. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8471. {
  8472. TMessage * M = static_cast<TMessage*>(Message);
  8473. switch (M->Msg)
  8474. {
  8475. case CM_DIALOGCHAR:
  8476. CMDialogChar(*M);
  8477. break;
  8478. case WM_APPCOMMAND:
  8479. WMAppCommand(*M);
  8480. break;
  8481. case WM_SYSCOMMAND:
  8482. WMSysCommand(*M);
  8483. break;
  8484. case WM_QUERYENDSESSION:
  8485. WMQueryEndSession(*M);
  8486. break;
  8487. case WM_ENDSESSION:
  8488. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8489. break;
  8490. #ifdef _DEBUG
  8491. case WM_WINDOWPOSCHANGED:
  8492. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8493. break;
  8494. case CM_CUSTOMSTYLECHANGED:
  8495. TForm::Dispatch(Message);
  8496. break;
  8497. #endif
  8498. case WM_COMPONENT_HIDE:
  8499. {
  8500. Byte Component = static_cast<Byte>(M->WParam);
  8501. // sanity check
  8502. if (ComponentVisible[Component])
  8503. {
  8504. // special treatment
  8505. if (Component == fcQueueView)
  8506. {
  8507. ToggleQueueVisibility();
  8508. DebugAssert(!ComponentVisible[fcQueueView]);
  8509. }
  8510. else
  8511. {
  8512. ComponentVisible[Component] = false;
  8513. }
  8514. }
  8515. }
  8516. break;
  8517. case WM_COPYDATA:
  8518. WMCopyData(*M);
  8519. break;
  8520. case WM_MANAGES_CAPTION:
  8521. // caption managed in TTerminalManager::UpdateAppTitle()
  8522. M->Result = 1;
  8523. break;
  8524. case WM_WANTS_MOUSEWHEEL:
  8525. M->Result = 1;
  8526. break;
  8527. case CM_SHOWINGCHANGED:
  8528. CMShowingChanged(*M);
  8529. break;
  8530. case WM_CLOSE:
  8531. WMClose(*M);
  8532. break;
  8533. case WM_DPICHANGED:
  8534. WMDpiChanged(*M);
  8535. break;
  8536. case CM_DPICHANGED:
  8537. CMDpiChanged(*M);
  8538. break;
  8539. case WM_SETTINGCHANGE:
  8540. WMSettingChange(*M);
  8541. break;
  8542. case CM_DIALOGKEY:
  8543. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8544. break;
  8545. default:
  8546. TForm::Dispatch(Message);
  8547. break;
  8548. }
  8549. }
  8550. //---------------------------------------------------------------------------
  8551. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8552. {
  8553. // noop
  8554. }
  8555. //---------------------------------------------------------------------------
  8556. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8557. {
  8558. TForm::Dispatch(&Message);
  8559. FSessionColors->Clear();
  8560. AddFixedSessionImages();
  8561. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8562. UpdateImages();
  8563. }
  8564. //---------------------------------------------------------------------------
  8565. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8566. {
  8567. TForm::Dispatch(&Message);
  8568. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8569. UpdatePixelsPerInchMainWindowCounter();
  8570. }
  8571. //---------------------------------------------------------------------------
  8572. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8573. {
  8574. // Cannot close window while we are busy.
  8575. // We cannot test this in FormCloseQuery as that is called also from
  8576. // Close(), which is called by CloseApplicationAction. So we can be busy
  8577. // there already even, when it is legitimate to close the application.
  8578. // Possibly a better place to handle this would be WMSysCommand.
  8579. if (NonVisualDataModule->Busy)
  8580. {
  8581. Message.Result = 1;
  8582. }
  8583. else
  8584. {
  8585. TForm::Dispatch(&Message);
  8586. }
  8587. }
  8588. //---------------------------------------------------------------------------
  8589. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8590. {
  8591. TForm::Dispatch(&Message);
  8592. if (Showing && (Terminal == NULL))
  8593. {
  8594. // When we are starting minimized (i.e. from an installer),
  8595. // postpone showing Login dialog until we get restored.
  8596. // Otherwise the Login dialog (and Authentication window) show restored
  8597. // over invisible (minimized) main window.
  8598. if (WindowState == wsMinimized)
  8599. {
  8600. FNeedSession = true;
  8601. }
  8602. else
  8603. {
  8604. // This happens before application ever goes idle, so the toolbars would
  8605. // stay enabled (initial state) until the Login dialog is dismissed.
  8606. UpdateActions();
  8607. NonVisualDataModule->StartBusy();
  8608. try
  8609. {
  8610. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8611. // otherwise the dialog does not receive focus.
  8612. // With Commander interface the ProcessMessages is called already
  8613. // by TDriveView, but with Explorer interface, we need to call it explicily
  8614. Application->ProcessMessages();
  8615. // do not reload sessions, they have been loaded just now (optimization)
  8616. NeedSession(true);
  8617. }
  8618. __finally
  8619. {
  8620. NonVisualDataModule->EndBusy();
  8621. }
  8622. }
  8623. }
  8624. }
  8625. //---------------------------------------------------------------------------
  8626. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8627. {
  8628. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8629. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8630. }
  8631. //---------------------------------------------------------------------------
  8632. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8633. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8634. int & MaxHeight)
  8635. {
  8636. // workaround for bug in TWinControl.CalcConstraints
  8637. // Check for empty rect (restore from iconic state) is done there only after
  8638. // call to AdjustClientRect, which enlarges the rect (for forms).
  8639. TRect R = GetClientRect();
  8640. // when restoring from iconic state, place no restrictions
  8641. if (IsRectEmpty(R))
  8642. {
  8643. MinWidth = 0;
  8644. MinHeight = 0;
  8645. MaxWidth = 32000;
  8646. MaxHeight = 32000;
  8647. }
  8648. }
  8649. //---------------------------------------------------------------------------
  8650. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8651. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8652. {
  8653. // terminal can be already closed (e.g. dropped connection)
  8654. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8655. {
  8656. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8657. try
  8658. {
  8659. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8660. }
  8661. catch(...)
  8662. {
  8663. if (!Terminal->Active)
  8664. {
  8665. Close = true;
  8666. }
  8667. throw;
  8668. }
  8669. }
  8670. }
  8671. //---------------------------------------------------------------------------
  8672. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8673. {
  8674. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8675. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8676. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8677. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8678. {
  8679. OnGetSpaceAvailable = GetSpaceAvailable;
  8680. }
  8681. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8682. OnGetSpaceAvailable);
  8683. }
  8684. //---------------------------------------------------------------------------
  8685. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8686. {
  8687. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8688. Terminal->FillSessionDataForCode(Data.get());
  8689. return Data.release();
  8690. }
  8691. //---------------------------------------------------------------------------
  8692. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8693. {
  8694. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8695. DoGenerateUrlDialog(Data.get(), Paths);
  8696. }
  8697. //---------------------------------------------------------------------------
  8698. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8699. {
  8700. GenerateUrl(NULL);
  8701. }
  8702. //---------------------------------------------------------------------------
  8703. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8704. {
  8705. std::unique_ptr<TStrings> Paths(new TStringList());
  8706. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8707. GenerateUrl(Paths.get());
  8708. }
  8709. //---------------------------------------------------------------------------
  8710. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8711. {
  8712. FSessionColor = value;
  8713. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8714. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8715. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8716. DebugAssert(ColorItem != NULL);
  8717. ColorItem->Color = C;
  8718. NonVisualDataModule->ColorMenuItem->Color = C;
  8719. UpdateControls();
  8720. }
  8721. //---------------------------------------------------------------------------
  8722. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8723. {
  8724. if (value != FSessionColor)
  8725. {
  8726. UpdateSessionColor(value);
  8727. // Is null when called from LastTerminalClosed
  8728. if (Terminal != NULL)
  8729. {
  8730. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8731. }
  8732. }
  8733. }
  8734. //---------------------------------------------------------------------------
  8735. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8736. {
  8737. bool Result = FNoteTimer->Enabled;
  8738. if (Result)
  8739. {
  8740. // cannot cancel note too early
  8741. bool NotEarly =
  8742. (Now() - FNoteShown >
  8743. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8744. if (Force || NotEarly)
  8745. {
  8746. FNoteTimer->Enabled = false;
  8747. FNote = L"";
  8748. SAFE_DESTROY(FNoteData);
  8749. FOnNoteClick = NULL;
  8750. FNoteHints = FNotes->Text;
  8751. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8752. UpdateStatusBar();
  8753. }
  8754. }
  8755. return Result;
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8759. {
  8760. DebugAssert(FNoteTimer->Enabled);
  8761. CancelNote(true);
  8762. }
  8763. //---------------------------------------------------------------------------
  8764. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8765. {
  8766. int P = Note.Pos(L"\n");
  8767. if (P > 0)
  8768. {
  8769. Note.SetLength(P - 1);
  8770. }
  8771. FNotes->Add(FORMAT(L"[%s] %s",
  8772. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8773. while (FNotes->Count > 10)
  8774. {
  8775. FNotes->Delete(0);
  8776. }
  8777. if (UpdateNow)
  8778. {
  8779. FNoteHints = FNotes->Text;
  8780. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8781. UpdateStatusBar();
  8782. }
  8783. }
  8784. //---------------------------------------------------------------------------
  8785. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8786. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8787. {
  8788. int P = Note.Pos(L"\n");
  8789. if (P > 0)
  8790. {
  8791. Note.SetLength(P - 1);
  8792. }
  8793. FNoteHints = FNotes->Text;
  8794. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8795. FNote = Note;
  8796. SAFE_DESTROY(FNoteData);
  8797. FNoteData = NoteData;
  8798. FOnNoteClick = OnNoteClick;
  8799. AddNote(Note, false);
  8800. UpdateStatusBar();
  8801. FNoteShown = Now();
  8802. FNoteTimer->Enabled = false;
  8803. if (Seconds == 0)
  8804. {
  8805. Seconds = WinConfiguration->NotificationsTimeout;
  8806. }
  8807. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8808. FNoteTimer->Enabled = true;
  8809. }
  8810. //---------------------------------------------------------------------------
  8811. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8812. {
  8813. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8814. }
  8815. //---------------------------------------------------------------------------
  8816. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8817. {
  8818. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8819. {
  8820. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8821. }
  8822. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8823. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8824. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8825. 0, NULL, NULL);
  8826. }
  8827. //---------------------------------------------------------------------------
  8828. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8829. {
  8830. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8831. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8832. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8833. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8834. }
  8835. //---------------------------------------------------------------------------
  8836. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8837. {
  8838. WinConfiguration->FormatSizeBytes = Style;
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8842. {
  8843. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8844. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8845. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8846. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8847. }
  8848. //---------------------------------------------------------------------------
  8849. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8850. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8851. {
  8852. if (Panel->Index == 0)
  8853. {
  8854. if (FOnNoteClick != NULL)
  8855. {
  8856. // prevent the user data from being freed by possible call
  8857. // to CancelNote or PostNote during call to OnNoteClick
  8858. std::unique_ptr<TObject> NoteData(FNoteData);
  8859. TNotifyEvent OnNoteClick = FOnNoteClick;
  8860. FNoteData = NULL;
  8861. // need to cancel the note as we are going to delete its user data
  8862. CancelNote(true);
  8863. OnNoteClick(NoteData.get());
  8864. }
  8865. }
  8866. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8867. {
  8868. FileSystemInfo();
  8869. }
  8870. }
  8871. //---------------------------------------------------------------------------
  8872. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8873. {
  8874. // workaround:
  8875. // 1) for unknown reason, disabling window, while minimized,
  8876. // prevents it from restoring, even if it was enabled again meanwhile
  8877. // 2) when disabling the main window, while another has focus
  8878. // minimize is no longer possible
  8879. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8880. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8881. // Shouldn't we use IsApplicationMinimized() here?
  8882. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8883. {
  8884. Enabled = false;
  8885. }
  8886. FLockLevel++;
  8887. }
  8888. //---------------------------------------------------------------------------
  8889. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8890. {
  8891. DebugAssert(FLockLevel > 0);
  8892. FLockLevel--;
  8893. if (FLockLevel == 0)
  8894. {
  8895. DebugAssert(FLockSuspendLevel == 0);
  8896. Enabled = true;
  8897. }
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8901. {
  8902. // We need to make sure that window is enabled when the last modal window closes
  8903. // otherwise focus is not restored correctly.
  8904. // So we re-enable the window when modal window opens and
  8905. // disable it back after is closes
  8906. if (FLockLevel > 0)
  8907. {
  8908. // while we have nesting counter, we know that we never be called
  8909. // recursivelly as Application->OnModalBegin is called only
  8910. // for the top-level modal window
  8911. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8912. {
  8913. // won't be disabled when conditions in LockWindow() were not satisfied
  8914. FDisabledOnLockSuspend = !Enabled;
  8915. // When minimized to tray (or actually when set to SW_HIDE),
  8916. // setting Enabled makes the window focusable even when there's
  8917. // modal window over it
  8918. if (!FTrayIcon->Visible)
  8919. {
  8920. Enabled = true;
  8921. }
  8922. }
  8923. FLockSuspendLevel++;
  8924. }
  8925. }
  8926. //---------------------------------------------------------------------------
  8927. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8928. {
  8929. if (FLockSuspendLevel > 0)
  8930. {
  8931. DebugAssert(FLockLevel > 0);
  8932. FLockSuspendLevel--;
  8933. // see comment in SuspendWindowLock
  8934. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8935. {
  8936. // Note that window can be enabled here, when we were minized to tray when
  8937. // was SuspendWindowLock() called.
  8938. // We should possibly do the same check as in LockWindow(),
  8939. // if it is ever possible that the consitions change between
  8940. // SuspendWindowLock() and ResumeWindowLock()
  8941. Enabled = !FDisabledOnLockSuspend;
  8942. }
  8943. }
  8944. }
  8945. //---------------------------------------------------------------------------
  8946. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8947. {
  8948. if (!TextOnly)
  8949. {
  8950. TTBXComboBoxItem * RemotePathComboBox =
  8951. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8952. TStrings * Items = RemotePathComboBox->Strings;
  8953. Items->BeginUpdate();
  8954. try
  8955. {
  8956. Items->Clear();
  8957. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8958. {
  8959. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8960. while (!IsUnixRootPath(APath))
  8961. {
  8962. int P = APath.LastDelimiter(L'/');
  8963. DebugAssert(P >= 0);
  8964. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8965. APath.SetLength(P - 1);
  8966. }
  8967. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8968. }
  8969. }
  8970. __finally
  8971. {
  8972. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8973. // Setting ItemIndex to -1 does not reset its text
  8974. if (Items->Count == 0)
  8975. {
  8976. RemotePathComboBox->Text = L"";
  8977. }
  8978. Items->EndUpdate();
  8979. }
  8980. }
  8981. }
  8982. //---------------------------------------------------------------------------
  8983. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8984. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8985. int & ImageIndex)
  8986. {
  8987. if (AIndex < 0)
  8988. {
  8989. AIndex = Sender->ItemIndex;
  8990. }
  8991. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8992. }
  8993. //---------------------------------------------------------------------------
  8994. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8995. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8996. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8997. {
  8998. ARect.Left += (10 * AIndex);
  8999. }
  9000. //---------------------------------------------------------------------------
  9001. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9002. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9003. {
  9004. AWidth += (10 * AIndex);
  9005. }
  9006. //---------------------------------------------------------------------------
  9007. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9008. TObject * Sender)
  9009. {
  9010. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9011. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9012. int Index = RemotePathComboBox->ItemIndex;
  9013. while (Index < RemotePathComboBox->Strings->Count - 1)
  9014. {
  9015. APath = UnixExtractFileDir(APath);
  9016. Index++;
  9017. }
  9018. // VanDyke style paths
  9019. if (APath.IsEmpty())
  9020. {
  9021. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9022. APath = ROOTDIRECTORY;
  9023. }
  9024. if (RemoteDirView->Path != APath)
  9025. {
  9026. RemoteDirView->Path = APath;
  9027. }
  9028. }
  9029. //---------------------------------------------------------------------------
  9030. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9031. {
  9032. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9033. DebugUsedParam(Sender);
  9034. UpdateRemotePathComboBox(true);
  9035. }
  9036. //---------------------------------------------------------------------------
  9037. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9038. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9039. {
  9040. ResetIncrementalSearch();
  9041. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9042. DebugAssert(DirView != NULL);
  9043. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9044. {
  9045. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9046. // OnEditing is called also from TCustomListView::CanEdit
  9047. if (Edit != NULL)
  9048. {
  9049. EditSelectBaseName(Edit);
  9050. }
  9051. }
  9052. }
  9053. //---------------------------------------------------------------------------
  9054. //---------------------------------------------------------------------------
  9055. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9056. {
  9057. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9058. Result->AutoDetectDnD = false;
  9059. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9060. Result->RenderDataOn = rdoEnterAndDropSync;
  9061. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9062. return Result;
  9063. }
  9064. //---------------------------------------------------------------------------
  9065. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9066. {
  9067. TForm::CreateWnd();
  9068. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9069. if (FSessionsDragDropFilesEx == NULL)
  9070. {
  9071. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9072. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9073. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9074. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9075. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9076. }
  9077. if (FQueueDragDropFilesEx == NULL)
  9078. {
  9079. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9080. // No need to set OnDragOver as we do not have any restrictions
  9081. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9082. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9083. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9084. }
  9085. }
  9086. //---------------------------------------------------------------------------
  9087. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9088. {
  9089. TForm::DestroyWnd();
  9090. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9091. FQueueDragDropFilesEx->DragDropControl = NULL;
  9092. }
  9093. //---------------------------------------------------------------------------
  9094. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9095. {
  9096. SideEnter(FCurrentSide);
  9097. FEverShown = true;
  9098. }
  9099. //---------------------------------------------------------------------------
  9100. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9101. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9102. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9103. {
  9104. if (!NonVisualDataModule->Busy)
  9105. {
  9106. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9107. Configuration->Usage->Inc(L"FileFinds");
  9108. LockWindow(true);
  9109. NonVisualDataModule->StartBusy();
  9110. WinConfiguration->LockedInterface = true;
  9111. try
  9112. {
  9113. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9114. }
  9115. __finally
  9116. {
  9117. WinConfiguration->LockedInterface = false;
  9118. NonVisualDataModule->EndBusy();
  9119. UnlockWindow();
  9120. }
  9121. }
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9125. {
  9126. if (!NonVisualDataModule->Busy)
  9127. {
  9128. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9129. SetFocus();
  9130. RemoteDirView->Path = UnixExtractFilePath(Path);
  9131. UnicodeString FileName = UnixExtractFileName(Path);
  9132. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9133. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9134. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9135. if (Item == NULL)
  9136. {
  9137. ReloadDirectory(osRemote);
  9138. Item = RemoteDirView->FindFileItem(FileName);
  9139. }
  9140. if (Item != NULL)
  9141. {
  9142. RemoteDirView->ItemFocused = Item;
  9143. RemoteDirView->ItemFocused->MakeVisible(false);
  9144. RemoteDirView->SetFocus();
  9145. }
  9146. }
  9147. }
  9148. //---------------------------------------------------------------------------
  9149. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9150. {
  9151. bool Result = !NonVisualDataModule->Busy;
  9152. if (Result)
  9153. {
  9154. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9155. }
  9156. return Result;
  9157. }
  9158. //---------------------------------------------------------------------------
  9159. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9160. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9161. {
  9162. if (CanOperateOnFoundFiles(ATerminal))
  9163. {
  9164. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9165. FOnFileOperationFinished = OnFileOperationFinished;
  9166. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9167. }
  9168. }
  9169. //---------------------------------------------------------------------------
  9170. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9171. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9172. {
  9173. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9174. }
  9175. //---------------------------------------------------------------------------
  9176. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9177. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9178. {
  9179. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9180. }
  9181. //---------------------------------------------------------------------------
  9182. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9183. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9184. {
  9185. if (CanOperateOnFoundFiles(ATerminal))
  9186. {
  9187. for (int Index = 0; Index < FileList->Count; Index++)
  9188. {
  9189. UnicodeString FileName = FileList->Strings[Index];
  9190. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9191. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9192. OnFileOperationFinished(FileName, true);
  9193. }
  9194. }
  9195. }
  9196. //---------------------------------------------------------------------------
  9197. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9198. {
  9199. FFileFindTerminal = Terminal;
  9200. ShowFileFindDialog(
  9201. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9202. DoDownloadFoundFiles, DoEditFoundFiles);
  9203. }
  9204. //---------------------------------------------------------------------------
  9205. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9206. {
  9207. FTaskbarList = TaskbarList;
  9208. }
  9209. //---------------------------------------------------------------------------
  9210. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9211. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9212. {
  9213. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9214. if (Index >= 0)
  9215. {
  9216. if (Button == mbLeft)
  9217. {
  9218. // "Mouse down" is raised only after tab is switched.
  9219. // If switching tab (switching session) takes long enough for user
  9220. // to actually release the button, "mouse down" is still raised,
  9221. // but we do not get "mouse up" event, so dragging is not cancelled,
  9222. // prevent that by not beginning dragging in the first place.
  9223. if (IsKeyPressed(VK_LBUTTON))
  9224. {
  9225. // when user clicks the "+", we get mouse down only after the session
  9226. // is closed, when new session tab is already on X:Y, so dragging
  9227. // starts, prevent that
  9228. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9229. {
  9230. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9231. if (Terminal != NULL)
  9232. {
  9233. SessionsPageControl->BeginDrag(false);
  9234. }
  9235. }
  9236. }
  9237. }
  9238. else if (Button == mbMiddle)
  9239. {
  9240. // ignore middle-click for "New session tab"
  9241. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9242. if (Terminal != NULL)
  9243. {
  9244. CloseSessionTab(Index);
  9245. }
  9246. }
  9247. }
  9248. }
  9249. //---------------------------------------------------------------------------
  9250. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9251. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9252. {
  9253. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9254. // do not allow dropping on the "+" tab
  9255. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9256. if ((TargetTerminal != NULL) &&
  9257. (SessionsPageControl->ActivePage->PageIndex != Index))
  9258. {
  9259. Configuration->Usage->Inc(L"SessionTabMoves");
  9260. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9261. // but we want to actually prevent that to avoid flicker
  9262. SessionsPageControl->ActivePage->PageIndex = Index;
  9263. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9264. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9265. }
  9266. }
  9267. //---------------------------------------------------------------------------
  9268. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9269. TObject * Sender, TObject * Source, int X, int Y,
  9270. TDragState /*State*/, bool & Accept)
  9271. {
  9272. Accept = (Sender == Source);
  9273. if (Accept)
  9274. {
  9275. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9276. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9277. // do not allow dragging to the "+" tab
  9278. Accept = (Terminal != NULL);
  9279. }
  9280. }
  9281. //---------------------------------------------------------------------------
  9282. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9283. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9284. {
  9285. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9286. if (Index < 0)
  9287. {
  9288. Effect = DROPEFFECT_NONE;
  9289. }
  9290. else
  9291. {
  9292. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9293. // do not allow dropping on the "+" tab
  9294. if (TargetTerminal == NULL)
  9295. {
  9296. Effect = DROPEFFECT_NONE;
  9297. }
  9298. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9299. {
  9300. Effect = DROPEFFECT_COPY;
  9301. }
  9302. }
  9303. }
  9304. //---------------------------------------------------------------------------
  9305. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9306. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9307. {
  9308. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9309. // do not allow dropping on the "+" tab
  9310. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9311. if (TargetTerminal != NULL)
  9312. {
  9313. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9314. if (!IsFileControl(DropSourceControl, osRemote))
  9315. {
  9316. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9317. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9318. // Why don't we use Terminal->CurrentDirectory directly?
  9319. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9320. // do not force queue, drag drop
  9321. false, true);
  9322. }
  9323. }
  9324. }
  9325. //---------------------------------------------------------------------------
  9326. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9327. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9328. {
  9329. // Downloads are handled in RemoteFileControlDDEnd
  9330. if (!IsFileControl(DropSourceControl, osRemote))
  9331. {
  9332. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9333. Terminal->CurrentDirectory,
  9334. // force queue, drag drop
  9335. true, true);
  9336. }
  9337. }
  9338. //---------------------------------------------------------------------------
  9339. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9340. {
  9341. FShowing = false;
  9342. // Do not save empty workspace
  9343. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9344. {
  9345. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9346. UnicodeString Name = WorkspaceName();
  9347. DoSaveWorkspace(
  9348. Name, DataList.get(),
  9349. !Configuration->DisablePasswordStoring &&
  9350. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9351. WinConfiguration->LastStoredSession = Name;
  9352. }
  9353. }
  9354. //---------------------------------------------------------------------------
  9355. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9356. {
  9357. TManagedTerminal * ManagedTerminal =
  9358. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9359. if (ManagedTerminal != NULL)
  9360. {
  9361. ManagedTerminal->DirectoryLoaded = Now();
  9362. }
  9363. }
  9364. //---------------------------------------------------------------------------
  9365. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9366. TListItem * /*Item*/, bool /*Selected*/)
  9367. {
  9368. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9369. switch (DirView->LastSelectMethod)
  9370. {
  9371. case smKeyboard:
  9372. Configuration->Usage->Inc(L"KeyboardSelections");
  9373. break;
  9374. case smMouse:
  9375. Configuration->Usage->Inc(L"MouseSelections");
  9376. break;
  9377. }
  9378. }
  9379. //---------------------------------------------------------------------------
  9380. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9381. {
  9382. if (Color != 0)
  9383. {
  9384. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9385. }
  9386. else
  9387. {
  9388. return FSessionTabImageIndex;
  9389. }
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9393. {
  9394. TPngImageCollectionItem * Item =
  9395. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9396. FSessionColors->AddPng(Item->PngImage);
  9397. return FSessionColors->Count - 1;
  9398. }
  9399. //---------------------------------------------------------------------------
  9400. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9401. {
  9402. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9403. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9404. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9405. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9406. }
  9407. //---------------------------------------------------------------------------
  9408. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9409. {
  9410. for (int Index = 0; Index < Control->ControlCount; Index++)
  9411. {
  9412. TControl * AControl = Control->Controls[Index];
  9413. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9414. if (WinControl != NULL)
  9415. {
  9416. CollectItemsWithTextDisplayMode(WinControl);
  9417. }
  9418. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9419. if (Toolbar != NULL)
  9420. {
  9421. // we care for top-level items only
  9422. TTBCustomItem * Items = Toolbar->Items;
  9423. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9424. {
  9425. TTBCustomItem * Item = Items->Items[ItemIndex];
  9426. if (((Item->DisplayMode == nbdmImageAndText) ||
  9427. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9428. EligibleForImageDisplayMode(Item))
  9429. {
  9430. FItemsWithTextDisplayMode.insert(Item);
  9431. }
  9432. }
  9433. }
  9434. }
  9435. }
  9436. //---------------------------------------------------------------------------
  9437. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9438. {
  9439. return true;
  9440. }
  9441. //---------------------------------------------------------------------------
  9442. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9443. {
  9444. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9445. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9446. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9447. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9448. bool Result = true;
  9449. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9450. {
  9451. TTBCustomItem * Item = *i;
  9452. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9453. if (Label != NULL)
  9454. {
  9455. // optimization
  9456. if (Label->Visible == SelectiveToolbarText)
  9457. {
  9458. Result = false;
  9459. }
  9460. else
  9461. {
  9462. Label->Visible = SelectiveToolbarText;
  9463. }
  9464. }
  9465. else
  9466. {
  9467. // optimization
  9468. if (Item->DisplayMode == DisplayMode)
  9469. {
  9470. Result = false;
  9471. }
  9472. else
  9473. {
  9474. Item->DisplayMode = DisplayMode;
  9475. }
  9476. }
  9477. ++i;
  9478. }
  9479. if (Result)
  9480. {
  9481. UpdateNewSessionTab();
  9482. }
  9483. return Result;
  9484. }
  9485. //---------------------------------------------------------------------------
  9486. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9487. {
  9488. DebugFail();
  9489. }
  9490. //---------------------------------------------------------------------------
  9491. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9492. {
  9493. // Among other, a lock level is non zero, while directory is being loaded,
  9494. // even when it happens as a result of dirview navigation,
  9495. // i.e. when TNonVisualDataModule is NOT FBusy.
  9496. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9497. // Among other this prevents a panel auto update to occur while
  9498. // directory is changing.
  9499. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9500. }
  9501. //---------------------------------------------------------------------------
  9502. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9503. {
  9504. // While the window is disabled, we still seem to process menu shortcuts at least,
  9505. // so stop it at least here.
  9506. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9507. return
  9508. (Allowed == aaUpdate) ||
  9509. !NonVisualDataModule->Busy;
  9510. }
  9511. //---------------------------------------------------------------------------
  9512. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9513. {
  9514. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9515. }
  9516. //---------------------------------------------------------------------------
  9517. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9518. {
  9519. // This is somewhat redundant to LockWindow() call from
  9520. // TTerminalManager::TerminalReadDirectoryProgress.
  9521. // But disabling window is known not to block keyboard shorcuts
  9522. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9523. if (Busy > 0)
  9524. {
  9525. if (NonVisualDataModule->Busy)
  9526. {
  9527. State = false;
  9528. }
  9529. else
  9530. {
  9531. NonVisualDataModule->StartBusy();
  9532. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9533. LockWindow();
  9534. }
  9535. }
  9536. else if (Busy < 0)
  9537. {
  9538. UnlockWindow();
  9539. NonVisualDataModule->EndBusy();
  9540. }
  9541. else
  9542. {
  9543. State = NonVisualDataModule->Busy;
  9544. }
  9545. }
  9546. //---------------------------------------------------------------------------
  9547. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9548. {
  9549. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9550. // no context menu for "New session tab"
  9551. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9552. {
  9553. SessionsPageControl->ActivePageIndex = Index;
  9554. if (DebugAlwaysTrue(SessionTabSwitched()))
  9555. {
  9556. // copied from TControl.WMContextMenu
  9557. SendCancelMode(SessionsPageControl);
  9558. // explicit popup instead of using PopupMenu property
  9559. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9560. // while connecting yet not-connected session and hence
  9561. // allowing an access to commands over not-completelly connected session
  9562. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9563. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9564. PopupMenu->PopupComponent = SessionsPageControl;
  9565. PopupMenu->Popup(Point.x, Point.y);
  9566. }
  9567. }
  9568. Handled = true;
  9569. }
  9570. //---------------------------------------------------------------------------
  9571. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9572. {
  9573. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9574. }
  9575. //---------------------------------------------------------------------------
  9576. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9577. {
  9578. Configuration->Usage->Inc(L"PasswordChanges");
  9579. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9580. ChangePasswordData->DisableAuthentationsExceptPassword();
  9581. ChangePasswordData->ChangePassword = true;
  9582. std::unique_ptr<TTerminal> ChangePasswordSession(
  9583. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9584. ChangePasswordSession->AutoReadDirectory = false;
  9585. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9586. {
  9587. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9588. }
  9589. else
  9590. {
  9591. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9592. }
  9593. }
  9594. //---------------------------------------------------------------------------
  9595. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9596. {
  9597. // No nice way to assert SSH2
  9598. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9599. }
  9600. //---------------------------------------------------------------------------
  9601. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9602. {
  9603. TOperationVisualizer OperationVisualizer;
  9604. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9605. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9606. }
  9607. //---------------------------------------------------------------------------
  9608. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9609. {
  9610. TForm::ChangeScale(M, D);
  9611. int APixelsPerInch = GetControlPixelsPerInch(this);
  9612. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9613. try
  9614. {
  9615. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9616. }
  9617. __finally
  9618. {
  9619. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9620. }
  9621. }
  9622. //---------------------------------------------------------------------------
  9623. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9624. {
  9625. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9626. }
  9627. //---------------------------------------------------------------------
  9628. class TPublicControl : public TControl
  9629. {
  9630. friend class TCustomScpExplorerForm;
  9631. };
  9632. //---------------------------------------------------------------------------
  9633. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9634. {
  9635. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9636. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9637. }
  9638. //---------------------------------------------------------------------------
  9639. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9640. {
  9641. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9642. OpenBookmark(Side, Bookmark);
  9643. }
  9644. //---------------------------------------------------------------------------
  9645. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9646. {
  9647. DoBookmarkClick(osLocal, Sender);
  9648. }
  9649. //---------------------------------------------------------------------------
  9650. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9651. {
  9652. DoBookmarkClick(osRemote, Sender);
  9653. }
  9654. //---------------------------------------------------------------------------
  9655. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9656. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9657. {
  9658. // TODO
  9659. if (BookmarkList != NULL)
  9660. {
  9661. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9662. if (!WinConfiguration->UseLocationProfiles)
  9663. {
  9664. std::unique_ptr<TStringList> Directories(new TStringList());
  9665. Directories->CaseSensitive = (Side == osRemote);
  9666. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9667. {
  9668. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9669. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9670. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9671. {
  9672. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9673. Item->Caption = EscapeHotkey(Directory);
  9674. Item->ShortCut = Bookmark->ShortCut;
  9675. Item->OnClick = OnBookmarkClick;
  9676. Item->Tag = reinterpret_cast<int>(Bookmark);
  9677. Directories->Add(Directory);
  9678. Menu->Add(Item.release());
  9679. }
  9680. }
  9681. }
  9682. else
  9683. {
  9684. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9685. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9686. {
  9687. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9688. if (!Bookmark->Node.IsEmpty())
  9689. {
  9690. Folders->Add(Bookmark->Node);
  9691. }
  9692. }
  9693. for (int Index = 0; Index < Folders->Count; Index++)
  9694. {
  9695. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9696. Item->Caption = Folders->Strings[Index];
  9697. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9698. Folders->Objects[Index] = Item.get();
  9699. Menu->Add(Item.release());
  9700. }
  9701. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9702. {
  9703. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9704. TTBCustomItem * Parent;
  9705. if (!Bookmark->Node.IsEmpty())
  9706. {
  9707. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9708. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9709. }
  9710. else
  9711. {
  9712. Parent = Menu;
  9713. }
  9714. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9715. Item->Caption = Bookmark->Name;
  9716. Item->ShortCut = Bookmark->ShortCut;
  9717. Item->OnClick = OnBookmarkClick;
  9718. Item->Tag = reinterpret_cast<int>(Bookmark);
  9719. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9720. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9721. {
  9722. // No hint for location profiles that are actually mere "bookmarks"
  9723. }
  9724. else
  9725. {
  9726. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9727. UnicodeString LongHint;
  9728. if (!Bookmark->Local.IsEmpty())
  9729. {
  9730. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9731. }
  9732. if (!Bookmark->Remote.IsEmpty())
  9733. {
  9734. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9735. }
  9736. AddToList(Hint, LongHint, L"|");
  9737. Item->Hint = Hint;
  9738. }
  9739. Parent->Add(Item.release());
  9740. }
  9741. }
  9742. AddMenuSeparator(Menu);
  9743. }
  9744. }
  9745. //---------------------------------------------------------------------------
  9746. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9747. {
  9748. Menu->Clear();
  9749. std::unique_ptr<TTBCustomItem> Item;
  9750. Item.reset(new TTBXItem(Owner));
  9751. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9752. Item->Options = Item->Options << tboDefault;
  9753. Menu->Add(Item.release());
  9754. AddMenuSeparator(Menu);
  9755. if (Terminal != NULL)
  9756. {
  9757. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9758. }
  9759. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9760. Item.reset(new TTBXItem(Owner));
  9761. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9762. Menu->Add(Item.release());
  9763. }
  9764. //---------------------------------------------------------------------------
  9765. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9766. {
  9767. bool Result = true;
  9768. try
  9769. {
  9770. if (Side == osRemote)
  9771. {
  9772. Terminal->ExceptionOnFail = true;
  9773. }
  9774. try
  9775. {
  9776. DirView(Side)->Path = Path;
  9777. }
  9778. __finally
  9779. {
  9780. if (Side == osRemote)
  9781. {
  9782. Terminal->ExceptionOnFail = false;
  9783. }
  9784. }
  9785. }
  9786. catch (Exception & E)
  9787. {
  9788. if ((Side != osRemote) || Terminal->Active)
  9789. {
  9790. ShowExtendedExceptionEx(Terminal, &E);
  9791. Result = false;
  9792. }
  9793. else
  9794. {
  9795. throw;
  9796. }
  9797. }
  9798. return Result;
  9799. }
  9800. //---------------------------------------------------------------------------
  9801. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9802. {
  9803. // Make sure there some feedback even when loading tiny local folders
  9804. TInstantOperationVisualizer Visualizer;
  9805. DirView(Side)->ReloadDirectory();
  9806. }
  9807. //---------------------------------------------------------------------------
  9808. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9809. {
  9810. if (Index == SessionsPageControl->TabIndex)
  9811. {
  9812. CloseSession();
  9813. }
  9814. else
  9815. {
  9816. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9817. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9818. TTerminalManager * Manager = TTerminalManager::Instance();
  9819. if (!Terminal->Active)
  9820. {
  9821. Manager->FreeTerminal(Terminal);
  9822. }
  9823. else
  9824. {
  9825. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9826. if (CanCloseQueue(Queue))
  9827. {
  9828. Manager->FreeTerminal(Terminal);
  9829. }
  9830. }
  9831. }
  9832. }
  9833. //---------------------------------------------------------------------------
  9834. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9835. {
  9836. CloseSessionTab(Index);
  9837. }
  9838. //---------------------------------------------------------------------------
  9839. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9840. {
  9841. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9842. {
  9843. TInstantOperationVisualizer Visualizer;
  9844. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9845. // before we create a new data object
  9846. ClipboardClear();
  9847. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9848. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9849. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9850. // Intermediate variable to WORKAROUND a crash in compiler
  9851. TObjectList * ClipboardFakeMonitors =
  9852. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9853. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9854. if (FClipboardDragDropFilesEx.get() == NULL)
  9855. {
  9856. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9857. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9858. }
  9859. FClipboardDragDropFilesEx->FileList->Clear();
  9860. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9861. FClipboardDragDropFilesEx->CopyToClipboard();
  9862. FClipboardTerminal = FTerminal;
  9863. // Need full paths, as cwd can be different once files are pasted
  9864. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9865. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9866. {
  9867. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9868. }
  9869. }
  9870. }
  9871. //---------------------------------------------------------------------------
  9872. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9873. {
  9874. if (OpenClipboard(0))
  9875. {
  9876. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9877. CloseClipboard();
  9878. }
  9879. }
  9880. //---------------------------------------------------------------------------
  9881. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9882. {
  9883. return !FClipboardFakeDirectory.IsEmpty();
  9884. }
  9885. //---------------------------------------------------------------------------
  9886. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9887. {
  9888. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9889. FClipboardFakeDirectory = UnicodeString();
  9890. FClipboardTerminal = NULL;
  9891. // Also called in Idle()
  9892. FClipboardFakeMonitors.reset(NULL);
  9893. }
  9894. //---------------------------------------------------------------------------
  9895. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9896. {
  9897. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9898. {
  9899. ClipboardStop();
  9900. }
  9901. }
  9902. //---------------------------------------------------------------------------
  9903. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9904. {
  9905. TTerminalManager * Manager = TTerminalManager::Instance();
  9906. Manager->ActiveTerminal = FClipboardTerminal;
  9907. TTransferOperationParam Params;
  9908. Params.TargetDirectory = TargetDirectory;
  9909. Params.DragDrop = DragDrop;
  9910. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9911. }
  9912. //---------------------------------------------------------------------------
  9913. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9914. {
  9915. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9916. // (as it pumps a Windows message queue while being shutted down)
  9917. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9918. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9919. {
  9920. // Can fail as it can be e.g. locked by AV, so we retry that later
  9921. bool Removed = RemoveDir(ApiPath(FileName));
  9922. try
  9923. {
  9924. if (!NonVisualDataModule->Busy)
  9925. {
  9926. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9927. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9928. }
  9929. }
  9930. __finally
  9931. {
  9932. if (!Removed)
  9933. {
  9934. RemoveDir(ApiPath(FileName));
  9935. }
  9936. }
  9937. }
  9938. }
  9939. //---------------------------------------------------------------------------
  9940. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9941. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9942. {
  9943. TFileMasks::TParams MaskParams;
  9944. MaskParams.Size = Size;
  9945. MaskParams.Modification = Modification;
  9946. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9947. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9948. {
  9949. bool ImplicitMatch;
  9950. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9951. !ImplicitMatch)
  9952. {
  9953. Color = Iter->Color;
  9954. break;
  9955. }
  9956. }
  9957. }
  9958. //---------------------------------------------------------------------------
  9959. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9960. {
  9961. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9962. if (!DirView->IsEditing())
  9963. {
  9964. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9965. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9966. // while searching
  9967. if (Key == VK_BACK)
  9968. {
  9969. if (!FIncrementalSearch.IsEmpty())
  9970. {
  9971. if (FIncrementalSearch.Length() == 1)
  9972. {
  9973. ResetIncrementalSearch();
  9974. }
  9975. else
  9976. {
  9977. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9978. IncrementalSearch(NewText, false, false);
  9979. }
  9980. Key = 0;
  9981. }
  9982. }
  9983. }
  9984. }
  9985. //---------------------------------------------------------------------------
  9986. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9987. {
  9988. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9989. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  9990. {
  9991. // Filter control sequences.
  9992. // When not searching yet, prefer use of the space for toggling file selection
  9993. // (so we cannot incrementally search for a string starting with a space).
  9994. if ((Key > VK_SPACE) ||
  9995. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9996. {
  9997. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9998. Key = 0;
  9999. }
  10000. }
  10001. }
  10002. //---------------------------------------------------------------------------
  10003. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10004. {
  10005. if (!FIncrementalSearch.IsEmpty())
  10006. {
  10007. FIncrementalSearch = L"";
  10008. DirView(osCurrent)->UpdateStatusBar();
  10009. }
  10010. }
  10011. //---------------------------------------------------------------------------
  10012. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10013. {
  10014. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10015. if (Item == NULL)
  10016. {
  10017. MessageBeep(MB_ICONHAND);
  10018. }
  10019. else
  10020. {
  10021. TCustomDirView * ADirView = DirView(osCurrent);
  10022. {
  10023. TAutoNestingCounter Guard(FIncrementalSearching);
  10024. ADirView->FocusItem(Item);
  10025. if (ADirView->NortonLike == nlOff)
  10026. {
  10027. if ((ADirView->Selected != Item) ||
  10028. (ADirView->SelCount > 1))
  10029. {
  10030. ADirView->ClearSelection();
  10031. ADirView->Selected = Item;
  10032. }
  10033. }
  10034. }
  10035. FIncrementalSearch = Text;
  10036. Item->MakeVisible(false);
  10037. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10038. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10039. ADirView->UpdateStatusBar();
  10040. }
  10041. }
  10042. //---------------------------------------------------------------------------
  10043. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10044. {
  10045. int Index = Item->Index;
  10046. if (!Reverse)
  10047. {
  10048. Index++;
  10049. if (Index >= Item->Owner->Count)
  10050. {
  10051. Index = 0;
  10052. }
  10053. }
  10054. else
  10055. {
  10056. Index--;
  10057. if (Index < 0)
  10058. {
  10059. Index = Item->Owner->Count - 1;
  10060. }
  10061. }
  10062. return Item->Owner->Item[Index];
  10063. }
  10064. //---------------------------------------------------------------------------
  10065. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10066. {
  10067. TCustomDirView * ADirView = DirView(osCurrent);
  10068. if (ADirView->Items->Count == 0)
  10069. {
  10070. return NULL;
  10071. }
  10072. else
  10073. {
  10074. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10075. TListItem * Item = CurrentItem;
  10076. if (SkipCurrent)
  10077. {
  10078. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10079. }
  10080. while (true)
  10081. {
  10082. bool Matches = false;
  10083. switch (WinConfiguration->PanelSearch)
  10084. {
  10085. case isNameStartOnly:
  10086. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10087. break;
  10088. case isName:
  10089. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10090. break;
  10091. case isAll:
  10092. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10093. int Index = 0;
  10094. while ((Index < ColCount) && !Matches)
  10095. {
  10096. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10097. if (Visible)
  10098. {
  10099. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10100. }
  10101. Index++;
  10102. }
  10103. break;
  10104. }
  10105. if (Matches)
  10106. {
  10107. return Item;
  10108. }
  10109. Item = GetNextFile(Item, Reverse);
  10110. if (Item == CurrentItem)
  10111. {
  10112. return NULL;
  10113. }
  10114. }
  10115. }
  10116. }
  10117. //---------------------------------------------------------------------------
  10118. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10119. {
  10120. ResetIncrementalSearch();
  10121. }
  10122. //---------------------------------------------------------------------------
  10123. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10124. {
  10125. if (Message.CharCode == VK_TAB)
  10126. {
  10127. if (!FIncrementalSearch.IsEmpty())
  10128. {
  10129. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10130. bool Reverse = Shift.Contains(ssShift);
  10131. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10132. Message.Result = 1;
  10133. return;
  10134. }
  10135. }
  10136. else if (Message.CharCode == VK_ESCAPE)
  10137. {
  10138. if (!FIncrementalSearch.IsEmpty())
  10139. {
  10140. ResetIncrementalSearch();
  10141. Message.Result = 1;
  10142. return;
  10143. }
  10144. }
  10145. TForm::Dispatch(&Message);
  10146. }
  10147. //---------------------------------------------------------------------------
  10148. void __fastcall TCustomScpExplorerForm::Deactivate()
  10149. {
  10150. TForm::Deactivate();
  10151. // E.g. when switching to an internal editor window
  10152. ResetIncrementalSearch();
  10153. }
  10154. //---------------------------------------------------------------------------
  10155. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10156. {
  10157. // When switching to another application
  10158. ResetIncrementalSearch();
  10159. }
  10160. //---------------------------------------------------------------------------
  10161. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10162. {
  10163. ResetIncrementalSearch();
  10164. }
  10165. //---------------------------------------------------------------------------
  10166. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10167. {
  10168. if (FIncrementalSearching <= 0)
  10169. {
  10170. ResetIncrementalSearch();
  10171. }
  10172. }
  10173. //---------------------------------------------------------------------------
  10174. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10175. {
  10176. CountClicksForWindowPrint(this);
  10177. }
  10178. //---------------------------------------------------------------------------
  10179. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10180. {
  10181. CenterReconnectToolbar();
  10182. }
  10183. //---------------------------------------------------------------------------
  10184. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10185. {
  10186. if (RemoteDirView->ItemFocused != NULL)
  10187. {
  10188. RemoteDirView->ItemFocused->Selected = true;
  10189. }
  10190. }
  10191. //---------------------------------------------------------------------------
  10192. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10193. {
  10194. if (!FQueueStatusUpdating)
  10195. {
  10196. bool Refresh;
  10197. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10198. {
  10199. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10200. }
  10201. else
  10202. {
  10203. if (FQueueFileList->GetCount() > 0)
  10204. {
  10205. FQueueFileList->Clear();
  10206. Refresh = true;
  10207. }
  10208. }
  10209. int Count = FQueueFileList->GetCount();
  10210. if (QueueFileList->Items->Count != Count)
  10211. {
  10212. DebugAssert(Refresh);
  10213. QueueFileList->Items->Count = Count;
  10214. }
  10215. if (Refresh)
  10216. {
  10217. QueueFileList->Invalidate();
  10218. }
  10219. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10220. }
  10221. }
  10222. //---------------------------------------------------------------------------
  10223. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10224. {
  10225. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10226. }
  10227. //---------------------------------------------------------------------------
  10228. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10229. {
  10230. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10231. // See TSynchronizeChecklistDialog::UpdateTimer
  10232. if (QueueFileList->Items->Count > 0)
  10233. {
  10234. QueueFileList->Items->Item[0]->MakeVisible(false);
  10235. }
  10236. UpdateQueueFileList();
  10237. }
  10238. //---------------------------------------------------------------------------
  10239. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10240. {
  10241. Active = QueueView3->Focused() || QueueFileList->Focused();
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10245. {
  10246. QueueLabelUpdateStatus();
  10247. }
  10248. //---------------------------------------------------------------------------
  10249. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10250. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10251. {
  10252. int State = FQueueFileList->GetState(Item->Index);
  10253. if (State == qfsProcessed)
  10254. {
  10255. Sender->Canvas->Font->Color = clGrayText;
  10256. }
  10257. }
  10258. //---------------------------------------------------------------------------
  10259. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10260. {
  10261. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10262. QueueFileList->Column[0]->Width =
  10263. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10267. {
  10268. QueueFileListColumnAutoSize();
  10269. }
  10270. //---------------------------------------------------------------------------
  10271. void __fastcall TCustomScpExplorerForm::CloseApp()
  10272. {
  10273. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10274. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10275. // So we clear the flag here.
  10276. DebugAssert(NonVisualDataModule->Busy);
  10277. NonVisualDataModule->EndBusy();
  10278. try
  10279. {
  10280. Close();
  10281. }
  10282. __finally
  10283. {
  10284. NonVisualDataModule->StartBusy();
  10285. }
  10286. }