CustomScpExplorer.cpp 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474
  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. //---------------------------------------------------------------------------
  33. #pragma package(smart_init)
  34. #pragma link "CustomDirView"
  35. #pragma link "CustomUnixDirView"
  36. #pragma link "IEListView"
  37. #pragma link "NortonLikeListView"
  38. #pragma link "UnixDirView"
  39. #pragma link "CustomDriveView"
  40. #pragma link "UnixDriveView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "TB2Dock"
  43. #pragma link "TBXStatusBars"
  44. #pragma link "TB2Item"
  45. #pragma link "TB2Toolbar"
  46. #pragma link "ThemePageControl"
  47. #pragma link "PathLabel"
  48. #ifndef NO_RESOURCES
  49. #pragma resource "*.dfm"
  50. #endif
  51. //---------------------------------------------------------------------------
  52. #define SAVE_SELECTION(DIRVIEW) \
  53. UnicodeString FocusFile = L""; \
  54. UnicodeString LastFocusedFile = L""; \
  55. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  56. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  57. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  58. #define RESTORE_SELECTION(DIRVIEW) \
  59. if (!LastFocusedFile.IsEmpty() && \
  60. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  61. { \
  62. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  63. if (ItemToSelect) \
  64. { \
  65. DIRVIEW->ItemFocused = ItemToSelect; \
  66. DIRVIEW->ItemFocused->MakeVisible(False); \
  67. } \
  68. }
  69. //---------------------------------------------------------------------------
  70. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  71. static const int SessionPanelCount = 4;
  72. //---------------------------------------------------------------------------
  73. class TMutexGuard
  74. {
  75. public:
  76. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  77. int Timeout = 5000)
  78. {
  79. FMutex = NULL;
  80. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  81. if (WaitResult == WAIT_TIMEOUT)
  82. {
  83. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  84. }
  85. else
  86. {
  87. FMutex = AMutex;
  88. }
  89. }
  90. ~TMutexGuard()
  91. {
  92. if (FMutex != NULL)
  93. {
  94. ReleaseMutex(FMutex);
  95. }
  96. }
  97. private:
  98. HANDLE FMutex;
  99. };
  100. //---------------------------------------------------------------------------
  101. class TWindowLock
  102. {
  103. public:
  104. TWindowLock(TCustomScpExplorerForm * Form) :
  105. FForm(Form)
  106. {
  107. FForm->LockWindow();
  108. }
  109. ~TWindowLock()
  110. {
  111. FForm->UnlockWindow();
  112. }
  113. private:
  114. TCustomScpExplorerForm * FForm;
  115. };
  116. //---------------------------------------------------------------------------
  117. struct TTransferOperationParam
  118. {
  119. TTransferOperationParam();
  120. UnicodeString TargetDirectory;
  121. bool Temp;
  122. bool DragDrop;
  123. int Options;
  124. TAutoSwitch Queue;
  125. };
  126. //---------------------------------------------------------------------------
  127. TTransferOperationParam::TTransferOperationParam()
  128. {
  129. Temp = false;
  130. DragDrop = false;
  131. Options = 0;
  132. Queue = asAuto;
  133. }
  134. //---------------------------------------------------------------------------
  135. class TTransferPresetNoteData : public TObject
  136. {
  137. public:
  138. UnicodeString Message;
  139. };
  140. //---------------------------------------------------------------------------
  141. class TTerminalNoteData : public TObject
  142. {
  143. public:
  144. TTerminal * Terminal;
  145. };
  146. //---------------------------------------------------------------------------
  147. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  148. FFormRestored(false),
  149. TForm(Owner)
  150. {
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. RestoreParams();
  155. ConfigurationChanged();
  156. RemoteDirView->Invalidate();
  157. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  158. NonVisualDataModule->ScpExplorer = this;
  159. FAutoOperation = false;
  160. FOnFileOperationFinished = NULL;
  161. FForceExecution = false;
  162. FIgnoreNextDialogChar = 0;
  163. FErrorList = NULL;
  164. FSynchronizeProgressForm = NULL;
  165. FProgressForm = NULL;
  166. FRefreshLocalDirectory = false;
  167. FRefreshRemoteDirectory = false;
  168. FDDMoveSlipped = false;
  169. FDDExtMapFile = NULL;
  170. // CreateMutexW keeps failing with ERROR_NOACCESS
  171. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  172. DebugAssert(FDDExtMutex != NULL);
  173. FDDTargetControl = NULL;
  174. FDelayedDeletionTimer = NULL;
  175. FDelayedDeletionList = new TStringList();
  176. FDDFileList = NULL;
  177. FPendingTempSpaceWarn = false;
  178. FCapturedLog = NULL;
  179. FDragDropOperation = false;
  180. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  181. FAllowTransferPresetAutoSelect = true;
  182. FCopyParamDefault = L"";
  183. FSynchronizeController = NULL;
  184. FPendingQueueActionItem = NULL;
  185. FLockLevel = 0;
  186. FLockSuspendLevel = 0;
  187. FDisabledOnLockSuspend = false;
  188. FAlternativeDelete = false;
  189. FTrayIcon = new ::TTrayIcon(0);
  190. FTrayIcon->OnClick = TrayIconClick;
  191. FMaxQueueLength = 0;
  192. FLastContextPopupScreenPoint = TPoint(-1, -1);
  193. FTransferResumeList = NULL;
  194. FMoveToQueue = false;
  195. FStandaloneEditing = false;
  196. FOnFeedSynchronizeError = NULL;
  197. FNeedSession = false;
  198. FDoNotIdleCurrentTerminal = false;
  199. FEditorManager = new TEditorManager();
  200. FEditorManager->OnFileChange = ExecutedFileChanged;
  201. FEditorManager->OnFileReload = ExecutedFileReload;
  202. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  203. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  204. FLocalEditors = new TList();
  205. FQueueStatus = NULL;
  206. FQueueStatusSection = new TCriticalSection();
  207. FQueueStatusInvalidated = false;
  208. FQueueItemInvalidated = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueLabel);
  238. UseDesktopFont(RemoteStatusBar);
  239. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  240. QueueSplitter->ShowHint = true;
  241. RemotePanelSplitter->ShowHint = true;
  242. UpdateImages();
  243. FCustomCommandMenu = CreateTBXPopupMenu(this);
  244. FCustomCommandLocalFileList = NULL;
  245. FCustomCommandRemoteFileList = NULL;
  246. FSessionColors = new TPngImageList(this);
  247. FSessionColors->ColorDepth = cd32Bit;
  248. AddFixedSessionImages();
  249. SessionsPageControl->Images = FSessionColors;
  250. QueueLabel->FocusControl = QueueView3;
  251. UpdateQueueLabel();
  252. FRemoteDirViewWasFocused = true;
  253. CreateHiddenWindow();
  254. StartUpdates();
  255. }
  256. //---------------------------------------------------------------------------
  257. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  258. {
  259. // this has to be one of the very first things to do
  260. StopUpdateThread();
  261. SessionsPageControl->Images = NULL;
  262. SAFE_DESTROY(FSessionColors);
  263. SAFE_DESTROY(FSessionsDragDropFilesEx);
  264. delete FCustomCommandLocalFileList;
  265. delete FCustomCommandRemoteFileList;
  266. delete FCustomCommandMenu;
  267. delete FTrayIcon;
  268. FTrayIcon = NULL;
  269. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  270. delete FEditorManager;
  271. ForceCloseLocalEditors();
  272. delete FLocalEditors;
  273. HideFileFindDialog();
  274. if (FDelayedDeletionTimer)
  275. {
  276. DoDelayedDeletion(NULL);
  277. SAFE_DESTROY(FDelayedDeletionTimer);
  278. }
  279. SAFE_DESTROY(FDelayedDeletionList);
  280. // sometimes we do not get DDEnd so the list is not released
  281. SAFE_DESTROY(FDDFileList);
  282. DebugAssert(FSynchronizeController == NULL);
  283. CloseHandle(FDDExtMutex);
  284. FDDExtMutex = NULL;
  285. FreeLibrary(FOle32Library);
  286. FOle32Library = NULL;
  287. FDragMoveCursor = NULL;
  288. DebugAssert(!FErrorList);
  289. if (FEverShown)
  290. {
  291. // when window is never shown (like when running command-line operation),
  292. // particularly window site is not restored correctly (BoundsRect value set
  293. // in RestoreForm gets lost during handle allocation), so we do not want
  294. // it to be stored
  295. StoreParams();
  296. }
  297. Terminal = NULL;
  298. Queue = NULL;
  299. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  300. NonVisualDataModule->ScpExplorer = NULL;
  301. delete FQueueController;
  302. FQueueController = NULL;
  303. delete FQueueStatusSection;
  304. FQueueStatusSection = NULL;
  305. delete FQueueStatus;
  306. FQueueStatus = NULL;
  307. delete FUserActionTimer;
  308. FUserActionTimer = NULL;
  309. delete FNoteTimer;
  310. delete FNotes;
  311. delete FNoteData;
  312. SAFE_DESTROY(FDocks);
  313. SAFE_DESTROY(FHistoryMenu[0][0]);
  314. SAFE_DESTROY(FHistoryMenu[0][1]);
  315. SAFE_DESTROY(FHistoryMenu[1][0]);
  316. SAFE_DESTROY(FHistoryMenu[1][1]);
  317. if (FHiddenWindow != NULL)
  318. {
  319. DestroyWindow(FHiddenWindow);
  320. FHiddenWindow = NULL;
  321. }
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  325. {
  326. std::unique_ptr<TSessionData> Data;
  327. if (!Session.IsEmpty())
  328. {
  329. bool DefaultsOnly;
  330. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  331. }
  332. TTerminalManager * Manager = TTerminalManager::Instance();
  333. for (int Index = 0; Index < Manager->Count; Index++)
  334. {
  335. TTerminal * Terminal = Manager->Terminals[Index];
  336. if (Session.IsEmpty() ||
  337. Terminal->SessionData->IsSameSite(Data.get()))
  338. {
  339. if (Path.IsEmpty())
  340. {
  341. Terminal->ClearCaches();
  342. }
  343. else
  344. {
  345. Terminal->DirectoryModified(Path, true);
  346. }
  347. }
  348. }
  349. // We should flag a pending refresh for the background terminals or busy foreground terminals
  350. if ((Terminal != NULL) && Terminal->Active &&
  351. CanCommandLineFromAnotherInstance() &&
  352. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  353. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  354. {
  355. Terminal->ReloadDirectory();
  356. }
  357. }
  358. //---------------------------------------------------------------------------
  359. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  360. {
  361. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  362. size_t MessageSize = sizeof(TCopyDataMessage);
  363. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  364. if (Result)
  365. {
  366. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  367. Result = (Message.Version == TCopyDataMessage::Version1);
  368. if (Result)
  369. {
  370. switch (Message.Command)
  371. {
  372. case TCopyDataMessage::CommandCanCommandLine:
  373. Result = CanCommandLineFromAnotherInstance();
  374. break;
  375. case TCopyDataMessage::CommandCommandLine:
  376. {
  377. UnicodeString CommandLine(Message.CommandLine);
  378. Result = CommandLineFromAnotherInstance(CommandLine);
  379. }
  380. break;
  381. case TCopyDataMessage::RefreshPanel:
  382. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  383. break;
  384. case TCopyDataMessage::MainWindowCheck:
  385. Result = true;
  386. break;
  387. default:
  388. Result = false;
  389. break;
  390. }
  391. }
  392. }
  393. Message.Result = Result ? 1 : 0;
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  397. {
  398. WNDCLASS WindowClass = {0};
  399. WindowClass.lpfnWndProc = DefWindowProc;
  400. WindowClass.hInstance = HInstance;
  401. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  402. FHiddenWindow = NULL;
  403. if (RegisterClass(&WindowClass))
  404. {
  405. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  406. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  407. }
  408. }
  409. //---------------------------------------------------------------------------
  410. bool __fastcall TCustomScpExplorerForm::CanConsole()
  411. {
  412. return (Terminal != NULL) && (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  416. {
  417. bool Result = !NonVisualDataModule->Busy;
  418. return Result;
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  422. const UnicodeString & CommandLine)
  423. {
  424. TProgramParams Params(CommandLine);
  425. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  426. if (Result)
  427. {
  428. NonVisualDataModule->StartBusy();
  429. try
  430. {
  431. // this action is initiated from another process,
  432. // so it's likely that our window is not visible,
  433. // and user won't see what is going on
  434. Application->BringToFront();
  435. // reload sessions as we may be asked to open a session
  436. // just stored by another instance
  437. StoredSessions->Load();
  438. UnicodeString SessionName = Params.Param[1];
  439. std::unique_ptr<TObjectList> DataList(new TObjectList());
  440. UnicodeString DownloadFile; // unused
  441. try
  442. {
  443. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  444. }
  445. catch (EAbort &)
  446. {
  447. // Happens when opening session in PuTTY and in other situations,
  448. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  449. // to process the command-line on its own (or to pass it to yet another instance)
  450. }
  451. if (DataList->Count > 0)
  452. {
  453. TTerminalManager * Manager = TTerminalManager::Instance();
  454. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  455. }
  456. }
  457. __finally
  458. {
  459. NonVisualDataModule->EndBusy();
  460. }
  461. }
  462. return Result;
  463. }
  464. //---------------------------------------------------------------------------
  465. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  466. {
  467. if (FTerminal != value)
  468. {
  469. TerminalChanging();
  470. FTerminal = value;
  471. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  472. FAllowTransferPresetAutoSelect = false;
  473. try
  474. {
  475. TerminalChanged();
  476. }
  477. __finally
  478. {
  479. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  480. }
  481. if (Terminal != NULL)
  482. {
  483. TransferPresetAutoSelect();
  484. }
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  489. {
  490. if (FTerminal != NULL)
  491. {
  492. UpdateTerminal(Terminal);
  493. }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  497. {
  498. RemoteDirView->Terminal = Terminal;
  499. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  500. TManagedTerminal * ManagedTerminal = NULL;
  501. if (Terminal != NULL)
  502. {
  503. if (Terminal->Active)
  504. {
  505. Terminal->RefreshDirectory();
  506. }
  507. ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  508. DebugAssert(ManagedTerminal != NULL);
  509. if (WinConfiguration->PreservePanelState)
  510. {
  511. if (ManagedTerminal->RemoteExplorerState != NULL)
  512. {
  513. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  514. }
  515. else
  516. {
  517. RemoteDirView->ClearState();
  518. }
  519. }
  520. InitStatusBar();
  521. }
  522. DoTerminalListChanged(false);
  523. if (ManagedTerminal != NULL)
  524. {
  525. // this has to be set only after the tab is switched from DoTerminalListChanged,
  526. // otherwise we are changing color of wrong tab
  527. SessionColor = (TColor)ManagedTerminal->StateData->Color;
  528. }
  529. UpdateTransferList();
  530. // Update panels Enable state before refreshing the labels
  531. UpdateControls();
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  535. {
  536. if (Queue != value)
  537. {
  538. if (FQueue != NULL)
  539. {
  540. FQueue->OnListUpdate = NULL;
  541. FQueue->OnQueueItemUpdate = NULL;
  542. }
  543. FQueue = value;
  544. if (FQueue != NULL)
  545. {
  546. DebugAssert(FQueue->OnListUpdate == NULL);
  547. FQueue->OnListUpdate = QueueListUpdate;
  548. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  549. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  550. }
  551. QueueChanged();
  552. }
  553. }
  554. //---------------------------------------------------------------------------
  555. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  556. TListItem * Item)
  557. {
  558. if (FQueueActedItem == Item)
  559. {
  560. FQueueActedItem = NULL;
  561. if ((QueueView3->PopupMenu != NULL) &&
  562. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  563. {
  564. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  565. ReleaseCapture();
  566. }
  567. }
  568. if (Item->Data == FPendingQueueActionItem)
  569. {
  570. FPendingQueueActionItem = NULL;
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  575. {
  576. {
  577. TGuard Guard(FQueueStatusSection);
  578. FQueueStatusInvalidated = false;
  579. if (FQueue != NULL)
  580. {
  581. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  582. }
  583. }
  584. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  585. {
  586. FMaxQueueLength = FQueueStatus->Count;
  587. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  588. }
  589. FQueueController->UpdateQueueStatus(FQueueStatus);
  590. SetQueueProgress();
  591. UpdateQueueView();
  592. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  593. if (IsEmpty && (Terminal != NULL))
  594. {
  595. TOnceDoneOperation OnceDoneOperation =
  596. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  597. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  598. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  599. {
  600. FQueue->Enabled = false;
  601. }
  602. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  603. {
  604. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  605. }
  606. }
  607. }
  608. //---------------------------------------------------------------------------
  609. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  610. {
  611. UnicodeString Result;
  612. if (FQueueStatus != NULL)
  613. {
  614. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  615. {
  616. TFileOperationProgressType * ProgressData =
  617. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  618. if ((ProgressData != NULL) && ProgressData->InProgress)
  619. {
  620. Result = TProgressForm::ProgressStr(ProgressData);
  621. }
  622. }
  623. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  624. {
  625. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  626. }
  627. }
  628. return Result;
  629. }
  630. //---------------------------------------------------------------------------
  631. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  632. {
  633. ComponentVisible[fcQueueView] =
  634. (WinConfiguration->QueueView.Show == qvShow) ||
  635. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  636. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TCustomScpExplorerForm::QueueChanged()
  640. {
  641. if (FQueueStatus != NULL)
  642. {
  643. delete FQueueStatus;
  644. FQueueStatus = NULL;
  645. }
  646. UpdateQueueStatus(true);
  647. }
  648. //---------------------------------------------------------------------------
  649. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  650. {
  651. if (FQueue == Queue)
  652. {
  653. FQueueStatusInvalidated = true;
  654. }
  655. }
  656. //---------------------------------------------------------------------------
  657. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  658. TQueueItem * Item)
  659. {
  660. if (FQueue == Queue)
  661. {
  662. TGuard Guard(FQueueStatusSection);
  663. // this may be running in parallel with QueueChanged
  664. if (FQueueStatus != NULL)
  665. {
  666. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  667. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  668. {
  669. FRefreshLocalDirectory = (QueueItem == NULL) ||
  670. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  671. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  672. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  673. }
  674. if (QueueItem != NULL)
  675. {
  676. QueueItem->UserData = (void*)true;
  677. FQueueItemInvalidated = true;
  678. }
  679. }
  680. }
  681. }
  682. //---------------------------------------------------------------------------
  683. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  684. {
  685. // during standalone editing, we have no way to see/control queue,
  686. // so we have to always popup prompts automatically
  687. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  691. {
  692. if (FQueueStatus != NULL)
  693. {
  694. bool QueueAutoPopup = IsQueueAutoPopup();
  695. bool NeedRefresh = FQueueController->NeedRefresh();
  696. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  697. FQueueItemInvalidated = false;
  698. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  699. bool Updated = false;
  700. TQueueItemProxy * QueueItem;
  701. bool WasUserAction;
  702. for (int Index = 0; Index < Limit; Index++)
  703. {
  704. bool Update = false;
  705. QueueItem = FQueueStatus->Items[Index];
  706. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  707. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  708. (FPendingQueueActionItem == NULL))
  709. {
  710. FPendingQueueActionItem = QueueItem;
  711. FUserActionTimer->Enabled = true;
  712. }
  713. if ((bool)QueueItem->UserData)
  714. {
  715. QueueItem->UserData = (void*)false;
  716. QueueItem->Update();
  717. Updated = true;
  718. Update = true;
  719. }
  720. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  721. {
  722. Update = true;
  723. }
  724. if (Update)
  725. {
  726. FQueueController->RefreshQueueItem(QueueItem);
  727. }
  728. }
  729. if (Updated)
  730. {
  731. NonVisualDataModule->UpdateNonVisibleActions();
  732. SetQueueProgress();
  733. }
  734. }
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  738. {
  739. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  740. }
  741. //---------------------------------------------------------------------------
  742. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  743. {
  744. if (ProgressData->Operation != foCalculateSize)
  745. {
  746. // implies TBPF_NORMAL
  747. FTaskbarList->SetProgressValue(GetMainForm()->Handle, ProgressData->OverallProgress(), 100);
  748. }
  749. else
  750. {
  751. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  752. }
  753. }
  754. //---------------------------------------------------------------------------
  755. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  756. {
  757. TTerminalManager::Instance()->QueueStatusUpdated();
  758. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  759. {
  760. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  761. {
  762. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  763. {
  764. TFileOperationProgressType * ProgressData = NULL;
  765. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  766. {
  767. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  768. }
  769. if ((ProgressData != NULL) &&
  770. ProgressData->InProgress)
  771. {
  772. SetTaskbarListProgressValue(ProgressData);
  773. }
  774. else
  775. {
  776. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  777. }
  778. }
  779. else
  780. {
  781. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  782. }
  783. }
  784. else
  785. {
  786. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  787. }
  788. }
  789. UpdateQueueLabel();
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  793. {
  794. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  795. if (FQueueStatus != NULL)
  796. {
  797. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  798. if (ActiveAndPendingPrimaryCount > 0)
  799. {
  800. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  801. }
  802. }
  803. QueueLabel->Caption = Caption;
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  807. {
  808. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  809. static_cast<TComponent*>(GetComponent(fcTransferList)));
  810. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  811. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  812. TransferList->Strings->BeginUpdate();
  813. try
  814. {
  815. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  816. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  817. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  818. if (FTransferDropDownHint.IsEmpty())
  819. {
  820. FTransferDropDownHint = TransferDropDown->Hint;
  821. }
  822. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  823. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  824. TransferDropDown->Text = StripHotkey(Name);
  825. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  826. (FTransferDropDownHint, StripHotkey(Name),
  827. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  828. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General))));
  829. // update the label, otherwise when it is updated only on the first draw
  830. // of the list, it is drawn "bold" for some reason
  831. FTransferListHoverIndex = TransferList->ItemIndex;
  832. UpdateTransferLabel();
  833. }
  834. __finally
  835. {
  836. TransferList->Strings->EndUpdate();
  837. }
  838. }
  839. //---------------------------------------------------------------------------
  840. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  841. {
  842. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  843. DebugAssert(Toolbar != NULL);
  844. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  845. }
  846. //---------------------------------------------------------------------------
  847. void __fastcall TCustomScpExplorerForm::UpdateActions()
  848. {
  849. TForm::UpdateActions();
  850. if (ComponentVisible[fcCustomCommandsBand])
  851. {
  852. UpdateCustomCommandsToolbar();
  853. }
  854. }
  855. //---------------------------------------------------------------------------
  856. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  857. {
  858. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  862. {
  863. DebugAssert(Configuration && RemoteDirView);
  864. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  865. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  866. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  867. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  868. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  869. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  870. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  871. {
  872. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  873. // selection is not redrawn automatically when RowSelect changes
  874. RemoteDirView->Invalidate();
  875. }
  876. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  877. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  878. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  879. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  880. UpdateSessionsPageControlHeight();
  881. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  882. UpdateToolbarDisplayMode();
  883. UpdateTransferList();
  884. if (Terminal != NULL)
  885. {
  886. TransferPresetAutoSelect();
  887. }
  888. UpdateQueueView();
  889. UpdateControls();
  890. // this can be called even before constuctor finishes.
  891. if (FEditorManager != NULL)
  892. {
  893. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  894. }
  895. // this can be called even before constuctor finishes.
  896. if (FLocalEditors != NULL)
  897. {
  898. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  899. {
  900. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  901. }
  902. }
  903. if (ComponentVisible[fcCustomCommandsBand])
  904. {
  905. UpdateCustomCommandsToolbar();
  906. }
  907. // show only when keeping queue items forever,
  908. // otherwise, its enough to have in in the context menu
  909. QueueDeleteAllDoneQueueToolbarItem->Visible =
  910. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  914. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  915. void * /*Arg*/)
  916. {
  917. if (Token != NULL)
  918. {
  919. TForm * Editor = dynamic_cast<TForm*>(Token);
  920. DebugAssert(Editor != NULL);
  921. ReconfigureEditorForm(Editor);
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  926. {
  927. WinConfiguration->DDTransferConfirmation = asOn;
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  931. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  932. {
  933. // noop
  934. }
  935. //---------------------------------------------------------------------------
  936. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  937. TTransferDirection Direction, TTransferType Type, bool Temp,
  938. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  939. bool Confirm, bool DragDrop, int Options)
  940. {
  941. bool Result = true;
  942. DebugAssert(Terminal && Terminal->Active);
  943. // Temp means d&d here so far, may change in future!
  944. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  945. !WinConfiguration->DDAllowMove)
  946. {
  947. TMessageParams Params(mpNeverAskAgainCheck);
  948. unsigned int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  949. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  950. if (Answer == qaNeverAskAgain)
  951. {
  952. WinConfiguration->DDAllowMove = true;
  953. }
  954. else if (Answer == qaCancel)
  955. {
  956. Result = false;
  957. }
  958. }
  959. // these parameters are known in advance
  960. int Params =
  961. FLAGMASK(Type == ttMove, cpDelete);
  962. bool ToTemp = (Temp && (Direction == tdToLocal));
  963. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  964. {
  965. bool DisableNewerOnly =
  966. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  967. ToTemp;
  968. Options |=
  969. FLAGMASK(ToTemp, coTemp) |
  970. coDoNotShowAgain;
  971. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  972. int CopyParamAttrs = (Direction == tdToRemote ?
  973. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  974. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  975. int OutputOptions =
  976. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  977. cooDoNotShowAgain);
  978. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  979. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  980. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  981. if (Result)
  982. {
  983. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  984. {
  985. if (DragDrop)
  986. {
  987. if (WinConfiguration->DDTransferConfirmation == asAuto)
  988. {
  989. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  990. NULL, 0, EnableDDTransferConfirmation, NULL);
  991. }
  992. WinConfiguration->DDTransferConfirmation = asOff;
  993. }
  994. else
  995. {
  996. WinConfiguration->ConfirmTransferring = false;
  997. }
  998. }
  999. else
  1000. {
  1001. // User exclicitly unchecked "do not show again",
  1002. // so show him the dialog the next time
  1003. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1004. {
  1005. WinConfiguration->DDTransferConfirmation = asOn;
  1006. }
  1007. }
  1008. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1009. }
  1010. }
  1011. if (Result && CopyParam.Queue && !ToTemp)
  1012. {
  1013. Configuration->Usage->Inc(L"TransfersOnBackground");
  1014. // these parameter are known only after transfer dialog
  1015. Params |=
  1016. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1017. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1018. Result = false;
  1019. ClearTransferSourceSelection(Direction);
  1020. }
  1021. return Result;
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1025. {
  1026. if (FOnFileOperationFinished != NULL)
  1027. {
  1028. FOnFileOperationFinished(UnicodeString(), true);
  1029. }
  1030. else
  1031. {
  1032. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1033. if (HasDirView[Side])
  1034. {
  1035. DirView(Side)->SelectAll(smNone);
  1036. }
  1037. }
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1041. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1042. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1043. int Params)
  1044. {
  1045. DebugAssert(Queue != NULL);
  1046. bool SingleFile = false;
  1047. if (FileList->Count == 1)
  1048. {
  1049. if (Direction == tdToRemote)
  1050. {
  1051. UnicodeString FileName = FileList->Strings[0];
  1052. SingleFile = FileExists(ApiPath(FileName));
  1053. }
  1054. else
  1055. {
  1056. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1057. SingleFile = !File->IsDirectory;
  1058. }
  1059. }
  1060. TQueueItem * QueueItem;
  1061. if (Direction == tdToRemote)
  1062. {
  1063. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1064. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1065. }
  1066. else
  1067. {
  1068. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1069. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1070. }
  1071. AddQueueItem(Queue, QueueItem, Terminal);
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1075. {
  1076. if (Queue->IsEmpty)
  1077. {
  1078. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1079. ManagedTerminal->QueueOperationStart = Now();
  1080. }
  1081. Queue->AddItem(QueueItem);
  1082. }
  1083. //---------------------------------------------------------------------------
  1084. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1085. {
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1089. {
  1090. DebugAssert(FDocks != NULL);
  1091. for (int Index = 0; Index < ComponentCount; Index++)
  1092. {
  1093. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1094. if ((Dock != NULL) && (Dock->Tag == 0))
  1095. {
  1096. FDocks->Add(Dock);
  1097. }
  1098. }
  1099. CollectItemsWithTextDisplayMode(this);
  1100. ConfigurationChanged();
  1101. QueuePanel->Height =
  1102. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1103. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1104. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1105. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. void __fastcall TCustomScpExplorerForm::StoreParams()
  1109. {
  1110. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1111. WinConfiguration->QueueView.HeightPixelsPerInch = GetControlPixelsPerInch(this);
  1112. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1113. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1114. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1115. }
  1116. //---------------------------------------------------------------------------
  1117. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1118. {
  1119. if (!FFormRestored)
  1120. {
  1121. FFormRestored = true;
  1122. RestoreFormParams();
  1123. }
  1124. TForm::CreateParams(Params);
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1128. {
  1129. DebugAssert(FDocks != NULL);
  1130. for (int Index = 0; Index < FDocks->Count; Index++)
  1131. {
  1132. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1133. }
  1134. }
  1135. //---------------------------------------------------------------------------
  1136. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1137. {
  1138. SetDockAllowDrag(true);
  1139. while (!ButtonsStr.IsEmpty())
  1140. {
  1141. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1142. UnicodeString Name = CutToChar(S, L'=', true);
  1143. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1144. {
  1145. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1146. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1147. {
  1148. while (!S.IsEmpty())
  1149. {
  1150. UnicodeString S2 = CutToChar(S, L',', true);
  1151. UnicodeString Name = CutToChar(S2, L':', true);
  1152. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1153. {
  1154. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1155. if (SameText(GetToolbarItemName(Item), Name))
  1156. {
  1157. // forward compatibility
  1158. UnicodeString S3 = CutToChar(S2, L':', true);
  1159. bool Visible = StrToIntDef(S3, 0);
  1160. Item->Visible = Visible;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. }
  1167. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1168. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1172. {
  1173. UnicodeString Result;
  1174. SetDockAllowDrag(true);
  1175. Result = ::GetToolbarsLayoutStr(this);
  1176. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1177. return Result;
  1178. }
  1179. //---------------------------------------------------------------------------
  1180. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1181. {
  1182. UnicodeString Result;
  1183. if (Item->Action != NULL)
  1184. {
  1185. Result = Item->Action->Name;
  1186. Result = RemoveSuffix(Result, L"Action");
  1187. }
  1188. else
  1189. {
  1190. Result = Item->Name;
  1191. Result = RemoveSuffix(Result, L"SubmenuItem");
  1192. Result = RemoveSuffix(Result, L"Item");
  1193. }
  1194. return Result;
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1198. {
  1199. UnicodeString Result;
  1200. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1201. {
  1202. UnicodeString ToolbarStr;
  1203. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1204. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1205. {
  1206. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1207. {
  1208. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1209. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1210. // Once we introduce any buttons that aer hidden by default, we would have to remember their initial state
  1211. // and save the changes here only.
  1212. if (!Item->Visible)
  1213. {
  1214. UnicodeString Name = GetToolbarItemName(Item);
  1215. DebugAssert(Name.Pos(L"TBX") == 0);
  1216. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1217. }
  1218. }
  1219. }
  1220. if (!ToolbarStr.IsEmpty())
  1221. {
  1222. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1223. }
  1224. }
  1225. return Result;
  1226. }
  1227. //---------------------------------------------------------------------------
  1228. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1229. TFileOperationProgressType & ProgressData)
  1230. {
  1231. // Download to temporary local directory
  1232. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1233. {
  1234. bool Continue = true;
  1235. FPendingTempSpaceWarn = false;
  1236. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1237. if (!Continue)
  1238. {
  1239. Abort();
  1240. }
  1241. }
  1242. // operation is being executed and we still didn't show up progress form
  1243. if (ProgressData.InProgress && !FProgressForm)
  1244. {
  1245. bool AllowSkip =
  1246. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1247. Terminal->IsCapable[fsSkipTransfer];
  1248. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip);
  1249. // As progress window has delayed show now, we need to lock ourselves,
  1250. // (at least) until then
  1251. LockWindow();
  1252. FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
  1253. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete) :
  1254. ((Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1255. !Terminal->SessionData->RecycleBinPath.IsEmpty()));
  1256. // When main window is hidden, synchronisation form does not exist,
  1257. // we suppose "/upload" or URL download mode
  1258. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1259. (ProgressData.Operation != foCalculateChecksum) &&
  1260. (FSynchronizeProgressForm == NULL) &&
  1261. !FStandaloneEditing)
  1262. {
  1263. FProgressForm->OnceDoneOperation = odoDisconnect;
  1264. }
  1265. if (FTaskbarList != NULL)
  1266. {
  1267. // Actually, do not know what hides the progress once the operation finishes
  1268. SetTaskbarListProgressState(TBPF_NORMAL);
  1269. }
  1270. }
  1271. // operation is finished (or terminated), so we hide progress form
  1272. else if (!ProgressData.InProgress && FProgressForm)
  1273. {
  1274. UnlockWindow();
  1275. SAFE_DESTROY(FProgressForm);
  1276. SetQueueProgress();
  1277. if (ProgressData.Operation == foCalculateSize)
  1278. {
  1279. // When calculating size before transfer, the abort caused by
  1280. // cancel flag set due to "MoveToQueue" below,
  1281. // is not propagated back to us in ExecuteFileOperation,
  1282. // as it is silently swallowed.
  1283. // So we explicitly (re)throw it here.
  1284. if (FMoveToQueue)
  1285. {
  1286. Abort();
  1287. }
  1288. }
  1289. else
  1290. {
  1291. if ((ProgressData.Cancel == csContinue) &&
  1292. !FAutoOperation)
  1293. {
  1294. OperationComplete(ProgressData.StartTime);
  1295. }
  1296. }
  1297. }
  1298. if (FProgressForm)
  1299. {
  1300. FProgressForm->SetProgressData(ProgressData);
  1301. if (FTaskbarList != NULL)
  1302. {
  1303. DebugAssert(ProgressData.InProgress);
  1304. SetTaskbarListProgressValue(&ProgressData);
  1305. }
  1306. if (FProgressForm->Cancel > csContinue)
  1307. {
  1308. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1309. if (FProgressForm->Cancel == csCancelFile)
  1310. {
  1311. FProgressForm->ClearCancel();
  1312. }
  1313. // cancel cancels even the move
  1314. FMoveToQueue = false;
  1315. }
  1316. else if (FProgressForm->MoveToQueue)
  1317. {
  1318. FMoveToQueue = true;
  1319. ProgressData.SetCancelAtLeast(csCancel);
  1320. }
  1321. if ((FTransferResumeList != NULL) &&
  1322. ProgressData.InProgress &&
  1323. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1324. !ProgressData.FullFileName.IsEmpty())
  1325. {
  1326. if ((FTransferResumeList->Count == 0) ||
  1327. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1328. {
  1329. // note that we do not recognize directories from files here
  1330. FTransferResumeList->Add(ProgressData.FullFileName);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. //---------------------------------------------------------------------------
  1336. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1337. const TDateTime & StartTime)
  1338. {
  1339. if (GUIConfiguration->BeepOnFinish &&
  1340. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1341. {
  1342. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1343. DWORD Sound;
  1344. if (!ExtractFileExt(BeepSound).IsEmpty())
  1345. {
  1346. Sound = SND_FILENAME;
  1347. }
  1348. else
  1349. {
  1350. Sound = SND_ALIAS;
  1351. }
  1352. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1353. }
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1357. TFileOperationProgressType & ProgressData)
  1358. {
  1359. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1360. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1361. TAutoFlag Flag(FDoNotIdleCurrentTerminal);
  1362. FileOperationProgress(ProgressData);
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1366. bool DragDrop)
  1367. {
  1368. return (!DragDrop && (DropSourceControl == NULL)) ||
  1369. (DropSourceControl == RemoteDirView);
  1370. }
  1371. //---------------------------------------------------------------------------
  1372. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1373. TFileOperation Operation, TOperationSide Side,
  1374. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1375. TOnceDoneOperation & OnceDoneOperation)
  1376. {
  1377. if (!FAutoOperation)
  1378. {
  1379. // no selection on "/upload", form servers only as event handler
  1380. // (it is not displayed)
  1381. if (PanelOperation(Side, FDragDropOperation) &&
  1382. Visible && (Operation != foCalculateSize) &&
  1383. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1384. {
  1385. if (FOnFileOperationFinished != NULL)
  1386. {
  1387. FOnFileOperationFinished(FileName, Success);
  1388. }
  1389. else
  1390. {
  1391. TCustomDirView * DView = DirView(Side);
  1392. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1393. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1394. // this can happen when local drive is unplugged in the middle of the operation
  1395. if (Item != NULL)
  1396. {
  1397. if (Success) Item->Selected = false;
  1398. DView->MakeProgressVisible(Item);
  1399. }
  1400. }
  1401. }
  1402. if ((Operation == foCopy) || (Operation == foMove))
  1403. {
  1404. if (Side == osLocal)
  1405. {
  1406. Configuration->Usage->Inc(L"UploadedFiles");
  1407. }
  1408. else
  1409. {
  1410. Configuration->Usage->Inc(L"DownloadedFiles");
  1411. }
  1412. }
  1413. }
  1414. if (Success && (FSynchronizeController != NULL))
  1415. {
  1416. if (Operation == foCopy)
  1417. {
  1418. DebugAssert(Side == osLocal);
  1419. FSynchronizeController->LogOperation(soUpload, FileName);
  1420. }
  1421. else if (Operation == foDelete)
  1422. {
  1423. DebugAssert(Side == osRemote);
  1424. FSynchronizeController->LogOperation(soDelete, FileName);
  1425. }
  1426. }
  1427. if (FProgressForm)
  1428. {
  1429. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1430. }
  1431. }
  1432. //---------------------------------------------------------------------------
  1433. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1434. TFileOperation Operation, TOperationSide Side,
  1435. bool Temp, const UnicodeString & FileName, Boolean Success,
  1436. TOnceDoneOperation & OnceDoneOperation)
  1437. {
  1438. TAutoFlag Flag(FDoNotIdleCurrentTerminal);
  1439. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1440. OnceDoneOperation);
  1441. }
  1442. //---------------------------------------------------------------------------
  1443. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1444. {
  1445. DebugAssert(GetSide(Side) == osRemote);
  1446. DebugUsedParam(Side);
  1447. return RemoteDirView;
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1451. {
  1452. DebugAssert(GetSide(Side) == osRemote);
  1453. DebugUsedParam(Side);
  1454. return (Terminal != NULL);
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1458. TOperationSide Side, int FilesOnly)
  1459. {
  1460. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1464. TOperationSide Side, int FilesOnly)
  1465. {
  1466. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1467. }
  1468. //---------------------------------------------------------------------------
  1469. struct THistoryItemData
  1470. {
  1471. short int Side;
  1472. short int Index;
  1473. };
  1474. //---------------------------------------------------------------------------
  1475. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1476. {
  1477. DirView(Side)->HistoryGo(Index);
  1478. }
  1479. //---------------------------------------------------------------------------
  1480. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1481. {
  1482. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1483. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1484. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1488. bool Back)
  1489. {
  1490. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1491. {
  1492. TCustomDirView * DView = DirView(Side);
  1493. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1494. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1495. if (ICount > 10)
  1496. {
  1497. ICount = 10;
  1498. }
  1499. Menu->Items->Clear();
  1500. THistoryItemData Data;
  1501. Data.Side = Side;
  1502. for (short int i = 1; i <= ICount; i++)
  1503. {
  1504. TTBCustomItem * Item = new TTBXItem(Menu);
  1505. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1506. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1507. Item->Hint = DView->HistoryPath[Data.Index];
  1508. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1509. Item->Tag = *reinterpret_cast<int*>(&Data);
  1510. Item->OnClick = HistoryItemClick;
  1511. Menu->Items->Add(Item);
  1512. }
  1513. }
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1517. TOperationSide Side, bool Back)
  1518. {
  1519. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1520. {
  1521. // workaround
  1522. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1523. // operator new allocates memory in Pascal code, but calls inline
  1524. // contructor in C++, leading in problems, the function does
  1525. // both in Pascal code
  1526. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1527. UpdateHistoryMenu(Side, Back);
  1528. }
  1529. return FHistoryMenu[Side == osLocal][Back];
  1530. }
  1531. //---------------------------------------------------------------------------
  1532. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1533. TCustomDirView *Sender)
  1534. {
  1535. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1536. UpdateHistoryMenu(Side, true);
  1537. UpdateHistoryMenu(Side, false);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1541. {
  1542. // remote custom commands can be executed only if the server supports shell commands
  1543. // or have secondary shell
  1544. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1548. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1549. {
  1550. int Result;
  1551. TFileCustomCommand RemoteCustomCommand;
  1552. TLocalCustomCommand LocalCustomCommand;
  1553. TFileCustomCommand * NonInteractiveCustomCommand =
  1554. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1555. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1556. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1557. if (FLAGCLEAR(Command.Params, ccLocal))
  1558. {
  1559. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1560. // custom command that does not operate with files can be executed anytime ...
  1561. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1562. {
  1563. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1564. {
  1565. // ... but do not show such command in remote file menu (TODO)
  1566. Result = AllowedState;
  1567. }
  1568. else
  1569. {
  1570. Result = -1;
  1571. }
  1572. }
  1573. else
  1574. {
  1575. if ((ListType == ccltAll) || (ListType == ccltFile))
  1576. {
  1577. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1578. }
  1579. else
  1580. {
  1581. Result = -1;
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. // custom command that does not operate with files can be executed anytime
  1588. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1589. {
  1590. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1591. }
  1592. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1593. {
  1594. if ((ListType == ccltAll) || (ListType == ccltFile))
  1595. {
  1596. // special case is "diff"-style command that can be executed over any side,
  1597. // if we have both sides
  1598. Result =
  1599. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1600. // directly (instead of EnableSelectedOperation) to pass
  1601. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1602. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1603. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1604. }
  1605. else if (ListType == ccltBoth)
  1606. {
  1607. Result = 1;
  1608. }
  1609. else
  1610. {
  1611. Result = -1;
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if ((ListType == ccltAll) || (ListType == ccltFile))
  1617. {
  1618. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1619. }
  1620. else
  1621. {
  1622. Result = -1;
  1623. }
  1624. }
  1625. }
  1626. return Result;
  1627. }
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1630. TStrings * FileList, const TCustomCommandType & ACommand,
  1631. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1632. {
  1633. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1634. {
  1635. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1636. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1637. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1638. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1639. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1640. bool Capture =
  1641. FLAGSET(ACommand.Params, ccShowResults) ||
  1642. FLAGSET(ACommand.Params, ccCopyResults) ||
  1643. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1644. TCaptureOutputEvent OutputEvent = NULL;
  1645. DebugAssert(FCapturedLog == NULL);
  1646. if (Capture)
  1647. {
  1648. FCapturedLog = new TStringList();
  1649. OutputEvent = TerminalCaptureLog;
  1650. }
  1651. try
  1652. {
  1653. if (!RemoteCustomCommand.IsFileCommand(Command))
  1654. {
  1655. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1656. OutputEvent);
  1657. }
  1658. else
  1659. {
  1660. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1661. }
  1662. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1663. {
  1664. if (FLAGSET(ACommand.Params, ccCopyResults))
  1665. {
  1666. CopyToClipboard(FCapturedLog);
  1667. }
  1668. if (FLAGSET(ACommand.Params, ccShowResults))
  1669. {
  1670. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1671. }
  1672. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1673. {
  1674. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1675. }
  1676. }
  1677. }
  1678. __finally
  1679. {
  1680. SAFE_DESTROY(FCapturedLog);
  1681. }
  1682. }
  1683. }
  1684. //---------------------------------------------------------------------------
  1685. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1686. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1687. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1688. {
  1689. TStrings * LocalFileList = NULL;
  1690. TStrings * RemoteFileList = NULL;
  1691. TStrings * RemoteFileListFull = NULL;
  1692. try
  1693. {
  1694. if (LocalFileCommand)
  1695. {
  1696. if (ALocalFileList == NULL)
  1697. {
  1698. DebugAssert(HasDirView[osLocal]);
  1699. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1700. // directly (instead of EnableSelectedOperation) to pass
  1701. // false to FocusedFileOnlyWhenFocused
  1702. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1703. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1704. }
  1705. else
  1706. {
  1707. LocalFileList = ALocalFileList;
  1708. }
  1709. if (FileListCommand)
  1710. {
  1711. if (LocalFileList->Count != 1)
  1712. {
  1713. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1714. }
  1715. }
  1716. else
  1717. {
  1718. if ((LocalFileList->Count != 1) &&
  1719. (FileList->Count != 1) &&
  1720. (LocalFileList->Count != FileList->Count))
  1721. {
  1722. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1723. }
  1724. }
  1725. }
  1726. UnicodeString RootTempDir;
  1727. UnicodeString TempDir;
  1728. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1729. if (!RemoteFiles)
  1730. {
  1731. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1732. }
  1733. try
  1734. {
  1735. TDateTimes RemoteFileTimes;
  1736. if (RemoteFiles)
  1737. {
  1738. RemoteFileList = FileList;
  1739. }
  1740. else
  1741. {
  1742. RemoteFileList = new TStringList();
  1743. TMakeLocalFileListParams MakeFileListParam;
  1744. MakeFileListParam.FileList = RemoteFileList;
  1745. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1746. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1747. MakeFileListParam.Recursive =
  1748. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1749. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1750. if (!MakeFileListParam.Recursive)
  1751. {
  1752. RemoteFileTimes.clear();
  1753. RemoteFileListFull = new TStringList();
  1754. MakeFileListParam.FileList = RemoteFileListFull;
  1755. MakeFileListParam.Recursive = true;
  1756. MakeFileListParam.IncludeDirs = false;
  1757. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1758. }
  1759. else
  1760. {
  1761. RemoteFileListFull = RemoteFileList;
  1762. }
  1763. }
  1764. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1765. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1766. if (!NonBlocking)
  1767. {
  1768. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1769. DebugAssert(FProgressForm != NULL);
  1770. FProgressForm->ReadOnly = true;
  1771. }
  1772. try
  1773. {
  1774. if (FileListCommand)
  1775. {
  1776. UnicodeString LocalFile;
  1777. // MakeFileList does not delimit filenames
  1778. UnicodeString FileList = MakeFileList(RemoteFileList);
  1779. if (LocalFileCommand)
  1780. {
  1781. DebugAssert(LocalFileList->Count == 1);
  1782. LocalFile = LocalFileList->Strings[0];
  1783. }
  1784. TLocalCustomCommand CustomCommand(Data,
  1785. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1786. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1787. if (NonBlocking)
  1788. {
  1789. DebugAssert(!POutput);
  1790. ExecuteShellChecked(ShellCommand);
  1791. }
  1792. else
  1793. {
  1794. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1795. }
  1796. }
  1797. else if (LocalFileCommand)
  1798. {
  1799. if (LocalFileList->Count == 1)
  1800. {
  1801. UnicodeString LocalFile = LocalFileList->Strings[0];
  1802. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1803. {
  1804. UnicodeString FileName = RemoteFileList->Strings[Index];
  1805. TLocalCustomCommand CustomCommand(Data,
  1806. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1807. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1808. }
  1809. }
  1810. else if (RemoteFileList->Count == 1)
  1811. {
  1812. UnicodeString FileName = RemoteFileList->Strings[0];
  1813. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1814. {
  1815. TLocalCustomCommand CustomCommand(
  1816. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1817. FileName, LocalFileList->Strings[Index], L"");
  1818. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1819. }
  1820. }
  1821. else
  1822. {
  1823. if (LocalFileList->Count != RemoteFileList->Count)
  1824. {
  1825. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1826. }
  1827. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1828. {
  1829. UnicodeString FileName = RemoteFileList->Strings[Index];
  1830. TLocalCustomCommand CustomCommand(
  1831. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1832. FileName, LocalFileList->Strings[Index], L"");
  1833. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1834. }
  1835. }
  1836. }
  1837. else
  1838. {
  1839. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1840. {
  1841. TLocalCustomCommand CustomCommand(Data,
  1842. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1843. RemoteFileList->Strings[Index], L"", L"");
  1844. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1845. }
  1846. }
  1847. }
  1848. __finally
  1849. {
  1850. if (!NonBlocking)
  1851. {
  1852. Progress.Stop();
  1853. }
  1854. }
  1855. DebugAssert(!FAutoOperation);
  1856. if (!RemoteFiles)
  1857. {
  1858. TempDir = IncludeTrailingBackslash(TempDir);
  1859. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  1860. {
  1861. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  1862. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1863. // Skip directories, process only nested files.
  1864. // The check is redundant as FileAge fails for directories anyway.
  1865. !DirectoryExists(FileName))
  1866. {
  1867. UnicodeString RemoteDir =
  1868. UnixExtractFileDir(
  1869. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1870. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1871. TDateTime NewTime;
  1872. if (FileAge(FileName, NewTime) &&
  1873. (NewTime != RemoteFileTimes[Index]))
  1874. {
  1875. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1876. TemporaryFileCopyParam(CopyParam);
  1877. CopyParam.FileMask = L"";
  1878. FAutoOperation = true;
  1879. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1880. TemporaryFilesList->Add(FileName);
  1881. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. __finally
  1888. {
  1889. FAutoOperation = false;
  1890. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  1891. {
  1892. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  1893. }
  1894. }
  1895. }
  1896. __finally
  1897. {
  1898. if (RemoteFileList != FileList)
  1899. {
  1900. delete RemoteFileList;
  1901. }
  1902. if (LocalFileList != ALocalFileList)
  1903. {
  1904. delete LocalFileList;
  1905. }
  1906. if (RemoteFileListFull != RemoteFileList)
  1907. {
  1908. delete RemoteFileListFull;
  1909. }
  1910. }
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithRemoteFiles(
  1914. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  1915. bool FileListCommand, UnicodeString * POutput)
  1916. {
  1917. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  1918. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  1919. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  1920. {
  1921. UnicodeString FileName = SelectedFileList->Strings[Index];
  1922. if (DirectoryExists(FileName))
  1923. {
  1924. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  1925. {
  1926. LocalFileList->Add(FileName);
  1927. }
  1928. if (FLAGSET(ACommand.Params, ccRecursive))
  1929. {
  1930. TMakeLocalFileListParams MakeFileListParam;
  1931. MakeFileListParam.FileList = LocalFileList.get();
  1932. MakeFileListParam.FileTimes = NULL;
  1933. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1934. MakeFileListParam.Recursive = true;
  1935. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  1936. }
  1937. }
  1938. else
  1939. {
  1940. LocalFileList->Add(FileName);
  1941. }
  1942. }
  1943. if (FileListCommand)
  1944. {
  1945. UnicodeString FileList = MakeFileList(LocalFileList.get());
  1946. TLocalCustomCommand CustomCommand(
  1947. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1948. L"", L"", FileList);
  1949. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1950. }
  1951. else
  1952. {
  1953. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1954. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
  1955. DebugAssert(FProgressForm != NULL);
  1956. FProgressForm->ReadOnly = true;
  1957. try
  1958. {
  1959. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1960. {
  1961. UnicodeString FileName = LocalFileList->Strings[Index];
  1962. TLocalCustomCommand CustomCommand(
  1963. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1964. FileName, L"", L"");
  1965. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1966. }
  1967. }
  1968. __finally
  1969. {
  1970. Progress.Stop();
  1971. }
  1972. }
  1973. }
  1974. //---------------------------------------------------------------------------
  1975. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  1976. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  1977. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1978. {
  1979. TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
  1980. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1981. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  1982. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1983. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  1984. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  1985. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  1986. std::unique_ptr<UnicodeString> POutput;
  1987. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  1988. FLAGSET(ACommand.Params, ccCopyResults))
  1989. {
  1990. POutput.reset(new UnicodeString());
  1991. }
  1992. if (!LocalCustomCommand.IsFileCommand(Command))
  1993. {
  1994. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1995. }
  1996. // remote files?
  1997. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  1998. {
  1999. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2000. }
  2001. // local files
  2002. else
  2003. {
  2004. LocalCustomCommandWithRemoteFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2005. }
  2006. if (POutput.get() != NULL)
  2007. {
  2008. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2009. int P = POutput->Pos(sLineBreak);
  2010. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2011. {
  2012. POutput->SetLength(P - 1);
  2013. }
  2014. // Copy even empty output to clipboard
  2015. if (FLAGSET(ACommand.Params, ccCopyResults))
  2016. {
  2017. CopyToClipboard(*POutput);
  2018. }
  2019. // But do not show an empty message box.
  2020. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2021. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2022. !POutput->IsEmpty())
  2023. {
  2024. TClipboardHandler ClipboardHandler;
  2025. ClipboardHandler.Text = *POutput;
  2026. TMessageParams Params;
  2027. TQueryButtonAlias Aliases[1];
  2028. Aliases[0].Button = qaRetry;
  2029. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2030. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2031. Params.Aliases = Aliases;
  2032. Params.AliasesCount = LENOF(Aliases);
  2033. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2034. }
  2035. }
  2036. }
  2037. //---------------------------------------------------------------------------
  2038. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2039. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2040. {
  2041. TCustomCommandData Data(Terminal);
  2042. UnicodeString Site = Terminal->SessionData->SessionKey;
  2043. UnicodeString HelpKeyword = ACommand.HomePage;
  2044. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2045. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2046. {
  2047. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2048. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2049. {
  2050. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, Terminal->CurrentDirectory));
  2051. }
  2052. else
  2053. {
  2054. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
  2055. }
  2056. if (!DoCustomCommandOptionsDialog(
  2057. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2058. {
  2059. Abort();
  2060. }
  2061. }
  2062. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2063. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2064. {
  2065. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2066. }
  2067. else
  2068. {
  2069. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2070. }
  2071. }
  2072. //---------------------------------------------------------------------------
  2073. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2074. const TCustomCommandType & Command)
  2075. {
  2076. DebugAssert(FCustomCommandLocalFileList != NULL);
  2077. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2078. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2079. TStrings * LocalFileList = new TStringList();
  2080. TStrings * RemoteFileList = new TStringList();
  2081. try
  2082. {
  2083. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2084. {
  2085. LocalFileList->Clear();
  2086. LocalFileList->AddObject(
  2087. FCustomCommandLocalFileList->Strings[Index],
  2088. FCustomCommandLocalFileList->Objects[Index]);
  2089. RemoteFileList->Clear();
  2090. RemoteFileList->AddObject(
  2091. FCustomCommandRemoteFileList->Strings[Index],
  2092. FCustomCommandRemoteFileList->Objects[Index]);
  2093. CustomCommand(RemoteFileList, Command, LocalFileList);
  2094. }
  2095. }
  2096. __finally
  2097. {
  2098. delete LocalFileList;
  2099. delete RemoteFileList;
  2100. }
  2101. }
  2102. //---------------------------------------------------------------------------
  2103. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2104. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2105. {
  2106. delete FCustomCommandLocalFileList;
  2107. delete FCustomCommandRemoteFileList;
  2108. // takeover ownership,
  2109. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2110. FCustomCommandLocalFileList = LocalFileList;
  2111. FCustomCommandRemoteFileList = RemoteFileList;
  2112. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2113. if (Button != NULL)
  2114. {
  2115. FCustomCommandMenu->Items->Clear();
  2116. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  2117. MenuPopup(FCustomCommandMenu, Button);
  2118. }
  2119. else
  2120. {
  2121. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2122. }
  2123. }
  2124. //---------------------------------------------------------------------------
  2125. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2126. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2127. {
  2128. DebugAssert(FCapturedLog != NULL);
  2129. if ((OutputType == cotOutput) || (OutputType == cotError))
  2130. {
  2131. FCapturedLog->Add(AddedLine);
  2132. }
  2133. }
  2134. //---------------------------------------------------------------------------
  2135. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2136. TOperationSide Side)
  2137. {
  2138. return (Side == osRemote) &&
  2139. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2140. }
  2141. //---------------------------------------------------------------------------
  2142. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2143. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2144. {
  2145. TTBItemOptions O;
  2146. O = Item->Options;
  2147. TCustomDirView * DView = DirView(Side);
  2148. if ((DView->ItemFocused != NULL) &&
  2149. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2150. // when resolving links is disabled, default action is to enter the directory,
  2151. // no matter what DoubleClickAction is configured to
  2152. ((Side != osRemote) || Terminal->ResolvingSymlinks) &&
  2153. // Can only Edit files, but can Open/Copy even directories
  2154. ((DoubleClickAction != dcaEdit) ||
  2155. !DView->ItemIsDirectory(DView->ItemFocused)))
  2156. {
  2157. Item->Options = O << tboDefault;
  2158. }
  2159. else
  2160. {
  2161. Item->Options = O >> tboDefault;
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2166. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2167. {
  2168. TCustomDirView * DView = DirView(Side);
  2169. TListItem * Item = DView->ItemFocused;
  2170. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2171. EnableFocusedOperation[Side])
  2172. {
  2173. TPoint ClientPoint;
  2174. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2175. TPoint(0, 0) : MousePos;
  2176. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2177. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2178. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2179. }
  2180. }
  2181. //---------------------------------------------------------------------------
  2182. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2183. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2184. {
  2185. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2186. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2187. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2188. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2189. Handled = true;
  2190. }
  2191. //---------------------------------------------------------------------------
  2192. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2193. {
  2194. }
  2195. //---------------------------------------------------------------------------
  2196. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2197. {
  2198. DebugAssert(FErrorList == NULL);
  2199. if (WinConfiguration->ContinueOnError)
  2200. {
  2201. FErrorList = new TStringList();
  2202. Configuration->Usage->Inc(L"ContinuationsOnError");
  2203. }
  2204. NonVisualDataModule->StartBusy();
  2205. }
  2206. //---------------------------------------------------------------------------
  2207. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2208. {
  2209. NonVisualDataModule->EndBusy();
  2210. if (FErrorList)
  2211. {
  2212. HandleErrorList(FErrorList);
  2213. }
  2214. }
  2215. //---------------------------------------------------------------------------
  2216. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2217. const TCopyParamType & CopyParam)
  2218. {
  2219. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2220. {
  2221. Configuration->Usage->Inc(L"FileMaskUses");
  2222. }
  2223. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2224. {
  2225. Configuration->Usage->Inc(L"OperationMaskUses");
  2226. }
  2227. }
  2228. //---------------------------------------------------------------------------
  2229. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2230. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2231. {
  2232. void * BatchStorage;
  2233. BatchStart(BatchStorage);
  2234. bool Result;
  2235. try
  2236. {
  2237. if ((Operation == foCopy) || (Operation == foMove))
  2238. {
  2239. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2240. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2241. UnicodeString TargetDirectory;
  2242. bool Temp = false;
  2243. bool DragDrop = false;
  2244. int Options = 0;
  2245. TAutoSwitch UseQueue = asAuto;
  2246. if (Param != NULL)
  2247. {
  2248. TTransferOperationParam& TParam =
  2249. *static_cast<TTransferOperationParam*>(Param);
  2250. TargetDirectory = TParam.TargetDirectory;
  2251. Temp = TParam.Temp;
  2252. DragDrop = TParam.DragDrop;
  2253. Options = TParam.Options;
  2254. UseQueue = TParam.Queue;
  2255. }
  2256. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2257. switch (UseQueue)
  2258. {
  2259. case asOn:
  2260. CopyParam.Queue = true;
  2261. break;
  2262. case asOff:
  2263. CopyParam.Queue = false;
  2264. break;
  2265. case asAuto:
  2266. default:
  2267. // keep default
  2268. break;
  2269. }
  2270. Result =
  2271. CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  2272. CopyParam, !NoConfirmation, DragDrop, Options);
  2273. if (Result)
  2274. {
  2275. DebugAssert(Terminal);
  2276. bool SelectionRestored = false;
  2277. TCustomDirView * DView = NULL;
  2278. if (HasDirView[Side])
  2279. {
  2280. DView = DirView(Side);
  2281. DView->SaveSelection();
  2282. DView->SaveSelectedNames();
  2283. }
  2284. UpdateCopyParamCounters(CopyParam);
  2285. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2286. DebugAssert(FTransferResumeList == NULL);
  2287. FTransferResumeList =
  2288. Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2289. FMoveToQueue = false;
  2290. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2291. try
  2292. {
  2293. TStrings * PermanentFileList;
  2294. std::unique_ptr<TStrings> PermanentFileListOwner;
  2295. try
  2296. {
  2297. if (Side == osLocal)
  2298. {
  2299. PermanentFileList = FileList;
  2300. Params |= FLAGMASK(Temp, cpTemporary);
  2301. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params, NULL);
  2302. if (Operation == foMove)
  2303. {
  2304. ReloadLocalDirectory();
  2305. if (DView != NULL)
  2306. {
  2307. DView->RestoreSelection();
  2308. }
  2309. SelectionRestored = true;
  2310. }
  2311. }
  2312. else
  2313. {
  2314. // Clone the file list as it may refer to current directory files,
  2315. // which get destroyed, when the source directory is reloaded after foMove operation.
  2316. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2317. // But for a hotfix, we are not going to do such a big change.
  2318. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2319. PermanentFileList = PermanentFileListOwner.get();
  2320. try
  2321. {
  2322. Terminal->CopyToLocal(
  2323. FileList, TargetDirectory, &CopyParam, Params, NULL);
  2324. }
  2325. __finally
  2326. {
  2327. if (Operation == foMove)
  2328. {
  2329. if (DView != NULL)
  2330. {
  2331. DView->RestoreSelection();
  2332. }
  2333. SelectionRestored = true;
  2334. }
  2335. ReloadLocalDirectory(TargetDirectory);
  2336. }
  2337. }
  2338. }
  2339. catch (EAbort &)
  2340. {
  2341. if (FMoveToQueue)
  2342. {
  2343. Params |=
  2344. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2345. DebugAssert(CopyParam.TransferSkipList == NULL);
  2346. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2347. if (TransferResumeList->Count > 0)
  2348. {
  2349. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2350. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2351. }
  2352. CopyParam.TransferSkipList = TransferResumeList.release();
  2353. // not really needed, just to keep it consistent with TransferResumeList
  2354. FTransferResumeList = NULL;
  2355. FMoveToQueue = false;
  2356. Configuration->Usage->Inc("MovesToBackground");
  2357. AddQueueItem(Queue, Direction, PermanentFileList, TargetDirectory, CopyParam, Params);
  2358. ClearTransferSourceSelection(Direction);
  2359. }
  2360. throw;
  2361. }
  2362. }
  2363. __finally
  2364. {
  2365. if (!SelectionRestored && (DView != NULL))
  2366. {
  2367. DView->DiscardSavedSelection();
  2368. }
  2369. FTransferResumeList = NULL;
  2370. }
  2371. }
  2372. }
  2373. else if (Operation == foRename)
  2374. {
  2375. DebugAssert(DirView(Side)->ItemFocused);
  2376. DirView(Side)->ItemFocused->EditCaption();
  2377. Result = true;
  2378. }
  2379. else if (Operation == foDelete)
  2380. {
  2381. DebugAssert(FileList->Count);
  2382. // We deliberately do not toggle alternative flag (Param), but use OR,
  2383. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2384. // shortcut of CurrentDeleteAlternativeAction
  2385. bool Alternative =
  2386. bool(Param) || UseAlternativeFunction();
  2387. bool Recycle;
  2388. if (Side == osLocal)
  2389. {
  2390. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2391. }
  2392. else
  2393. {
  2394. Recycle = (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2395. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2396. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2397. }
  2398. Result =
  2399. !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2400. if (!Result)
  2401. {
  2402. UnicodeString Query;
  2403. if (FileList->Count == 1)
  2404. {
  2405. if (Side == osLocal)
  2406. {
  2407. Query = ExtractFileName(FileList->Strings[0]);
  2408. }
  2409. else
  2410. {
  2411. Query = UnixExtractFileName(FileList->Strings[0]);
  2412. }
  2413. Query = FMTLOAD(
  2414. (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2415. }
  2416. else
  2417. {
  2418. Query = FMTLOAD(
  2419. (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2420. }
  2421. TMessageParams Params(mpNeverAskAgainCheck);
  2422. Params.ImageName = L"Delete file";
  2423. unsigned int Answer = MessageDialog(MainInstructions(Query), qtConfirmation,
  2424. qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2425. if (Answer == qaNeverAskAgain)
  2426. {
  2427. Result = true;
  2428. if (Recycle)
  2429. {
  2430. WinConfiguration->ConfirmRecycling = false;
  2431. }
  2432. else
  2433. {
  2434. WinConfiguration->ConfirmDeleting = false;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. Result = (Answer == qaOK);
  2440. }
  2441. }
  2442. if (Result)
  2443. {
  2444. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2445. }
  2446. }
  2447. else if (Operation == foSetProperties)
  2448. {
  2449. RemoteDirView->SaveSelectedNames();
  2450. Result = SetProperties(Side, FileList);
  2451. }
  2452. else if (Operation == foCustomCommand)
  2453. {
  2454. DebugAssert(Param);
  2455. DebugAssert(Side == osRemote);
  2456. RemoteDirView->SaveSelectedNames();
  2457. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2458. CustomCommand(FileList, *Command, NULL);
  2459. Result = true;
  2460. }
  2461. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2462. {
  2463. DebugAssert(Side == osRemote);
  2464. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2465. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2466. }
  2467. else if (Operation == foLock)
  2468. {
  2469. DebugAssert(Side == osRemote);
  2470. LockFiles(FileList, true);
  2471. Result = true;
  2472. }
  2473. else if (Operation == foUnlock)
  2474. {
  2475. DebugAssert(Side == osRemote);
  2476. LockFiles(FileList, false);
  2477. Result = true;
  2478. }
  2479. else
  2480. {
  2481. DebugFail();
  2482. }
  2483. }
  2484. __finally
  2485. {
  2486. BatchEnd(BatchStorage);
  2487. }
  2488. return Result;
  2489. }
  2490. //---------------------------------------------------------------------------
  2491. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2492. {
  2493. if (Side == osCurrent)
  2494. {
  2495. Side = FCurrentSide;
  2496. }
  2497. return Side;
  2498. }
  2499. //---------------------------------------------------------------------------
  2500. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2501. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2502. {
  2503. Side = GetSide(Side);
  2504. bool Result;
  2505. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2506. try
  2507. {
  2508. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2509. }
  2510. __finally
  2511. {
  2512. delete FileList;
  2513. }
  2514. return Result;
  2515. }
  2516. //---------------------------------------------------------------------------
  2517. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2518. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2519. bool NoConfirmation, void * Param)
  2520. {
  2521. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2522. {
  2523. if ((Operation == foCopy) || (Operation == foMove))
  2524. {
  2525. if (GetSide(Side) == osLocal)
  2526. {
  2527. Configuration->Usage->Inc(L"UploadsCommand");
  2528. }
  2529. else
  2530. {
  2531. Configuration->Usage->Inc(L"DownloadsCommand");
  2532. }
  2533. }
  2534. }
  2535. }
  2536. //---------------------------------------------------------------------------
  2537. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2538. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2539. {
  2540. TTransferOperationParam Param;
  2541. if ((WinConfiguration->Interface != ifCommander) ||
  2542. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2543. {
  2544. Flags &= ~cocShortCutHint;
  2545. }
  2546. TCustomDirView * DView = DirView(Side);
  2547. Param.Options =
  2548. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2549. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2550. if (FLAGSET(Flags, cocQueue))
  2551. {
  2552. Param.Queue = asOn;
  2553. }
  2554. else if (FLAGSET(Flags, cocNonQueue))
  2555. {
  2556. Param.Queue = asOff;
  2557. }
  2558. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2559. }
  2560. //---------------------------------------------------------------------------
  2561. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2562. {
  2563. try
  2564. {
  2565. if (ErrorList->Count)
  2566. {
  2567. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2568. if (MessageDialog(Message, qtError,
  2569. qaOK | qaCancel, HELP_NONE) == qaOK)
  2570. {
  2571. unsigned int Answer;
  2572. int Index = 0;
  2573. do
  2574. {
  2575. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2576. TQueryButtonAlias Aliases[2];
  2577. Aliases[0].Button = qaYes;
  2578. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2579. Aliases[1].Button = qaNo;
  2580. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2581. TMessageParams Params;
  2582. Params.Aliases = Aliases;
  2583. Params.AliasesCount = LENOF(Aliases);
  2584. Answer = MoreMessageDialog(
  2585. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2586. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2587. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2588. qaOK, HELP_NONE, &Params);
  2589. if (Answer == qaNo)
  2590. {
  2591. Index++;
  2592. }
  2593. if (Answer == qaYes)
  2594. {
  2595. Index--;
  2596. }
  2597. }
  2598. while (Answer != qaOK);
  2599. }
  2600. }
  2601. }
  2602. __finally
  2603. {
  2604. TStrings * List = ErrorList;
  2605. ErrorList = NULL;
  2606. for (int i = 0; i < List->Count; i++)
  2607. {
  2608. delete List->Objects[i];
  2609. }
  2610. delete List;
  2611. }
  2612. }
  2613. //---------------------------------------------------------------------------
  2614. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2615. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2616. {
  2617. // needed for checking filemasks, as there's no directory object
  2618. // associated with the file object
  2619. File->FullFileName = FullFileName;
  2620. TFileMasks::TParams MaskParams;
  2621. MaskParams.Size = File->Size;
  2622. MaskParams.Modification = File->Modification;
  2623. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2624. }
  2625. //---------------------------------------------------------------------------
  2626. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2627. {
  2628. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2629. Side = GetSide(Side);
  2630. TCustomDirView * DView = DirView(Side);
  2631. TListItem * FocusedItem = DView->ItemFocused;
  2632. UnicodeString Name;
  2633. if ((FocusedItem != NULL) && !DView->ItemIsParentDirectory(FocusedItem))
  2634. {
  2635. Name = DView->ItemFileName(FocusedItem);
  2636. }
  2637. else
  2638. {
  2639. Name = LoadStr(NEW_FILE);
  2640. }
  2641. UnicodeString Names = Name;
  2642. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2643. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2644. HELP_EDIT_NEW, History.get(), true))
  2645. {
  2646. while (!Names.IsEmpty())
  2647. {
  2648. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2649. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2650. UnicodeString TargetFileName;
  2651. UnicodeString LocalFileName;
  2652. UnicodeString RootTempDir;
  2653. UnicodeString TempDir;
  2654. UnicodeString RemoteDirectory;
  2655. bool ExistingFile = false;
  2656. if (Side == osRemote)
  2657. {
  2658. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2659. TRemoteFile * File = NULL;
  2660. if (FTerminal->FileExists(Name, &File))
  2661. {
  2662. try
  2663. {
  2664. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2665. ExistingFile = true;
  2666. }
  2667. __finally
  2668. {
  2669. delete File;
  2670. }
  2671. }
  2672. if (!ExistingFile)
  2673. {
  2674. RemoteDirectory = UnixExtractFilePath(Name);
  2675. TemporaryDirectoryForRemoteFiles(
  2676. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2677. TargetFileName = UnixExtractFileName(Name);
  2678. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2679. LocalFileName = TempDir +
  2680. // We probably do not want to trim the VMS version here
  2681. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2682. }
  2683. }
  2684. else
  2685. {
  2686. if (ExtractFilePath(Name).IsEmpty())
  2687. {
  2688. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2689. }
  2690. else
  2691. {
  2692. LocalFileName = ExpandFileName(Name);
  2693. }
  2694. TargetFileName = ExtractFileName(Name);
  2695. }
  2696. if (!ExistingFile)
  2697. {
  2698. if (!FileExists(ApiPath(LocalFileName)))
  2699. {
  2700. int File = FileCreate(ApiPath(LocalFileName));
  2701. if (File < 0)
  2702. {
  2703. if (!RootTempDir.IsEmpty())
  2704. {
  2705. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2706. }
  2707. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2708. }
  2709. else
  2710. {
  2711. FileClose(File);
  2712. }
  2713. }
  2714. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2715. const TEditorData * ExternalEditor = NULL;
  2716. TFileMasks::TParams MaskParams; // size not known
  2717. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2718. false, MaskParams);
  2719. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2720. ExternalEditor, RootTempDir, RemoteDirectory);
  2721. }
  2722. }
  2723. }
  2724. }
  2725. //---------------------------------------------------------------------------
  2726. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2727. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2728. {
  2729. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2730. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2731. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2732. return
  2733. ((ExecuteFileBy == efInternalEditor)) ||
  2734. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2735. }
  2736. //---------------------------------------------------------------------------
  2737. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2738. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2739. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2740. UnicodeString RemoteDirectory)
  2741. {
  2742. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2743. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2744. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2745. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2746. Side = GetSide(Side);
  2747. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2748. if (Side == osRemote)
  2749. {
  2750. Data->Terminal = Terminal;
  2751. Data->Queue = Queue;
  2752. Data->SessionData = CloneCurrentSessionData();
  2753. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2754. Data->RemoteDirectory = RemoteDirectory;
  2755. Data->SessionName = Terminal->SessionData->SessionName;
  2756. Data->LocalRootDirectory = LocalRootDirectory;
  2757. Data->OriginalFileName = OriginalFileName;
  2758. Data->Command = L""; // will be changed later for external editor
  2759. }
  2760. if (ExecuteFileBy == efInternalEditor)
  2761. {
  2762. if (Side == osRemote)
  2763. {
  2764. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2765. L" - " + Terminal->SessionData->SessionName;
  2766. TForm * Editor;
  2767. try
  2768. {
  2769. Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
  2770. FEditorManager->FileReload, FEditorManager->FileClosed,
  2771. SaveAllInternalEditors, AnyInternalEditorModified,
  2772. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
  2773. }
  2774. catch(...)
  2775. {
  2776. if (!LocalRootDirectory.IsEmpty())
  2777. {
  2778. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2779. }
  2780. throw;
  2781. }
  2782. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2783. }
  2784. else
  2785. {
  2786. DebugAssert(!FStandaloneEditing);
  2787. TForm * Editor =
  2788. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2789. SaveAllInternalEditors, AnyInternalEditorModified,
  2790. L"", false, SessionColor, -1);
  2791. FLocalEditors->Add(Editor);
  2792. }
  2793. }
  2794. else
  2795. {
  2796. HANDLE Process;
  2797. if (ExecuteFileBy == efExternalEditor)
  2798. {
  2799. UnicodeString Program, Params, Dir;
  2800. Data->Command = ExternalEditor->ExternalEditor;
  2801. ReformatFileNameCommand(Data->Command);
  2802. SplitCommand(Data->Command, Program, Params, Dir);
  2803. Params = ExpandFileNameCommand(Params, FileName);
  2804. Program = ExpandEnvironmentVariables(Program);
  2805. if (!ExecuteShell(Program, Params, Process))
  2806. {
  2807. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2808. }
  2809. }
  2810. else
  2811. {
  2812. DebugAssert(Side == osRemote);
  2813. if (!ExecuteShell(FileName, L"", Process))
  2814. {
  2815. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2816. }
  2817. }
  2818. if ((Side == osLocal) ||
  2819. ((ExecuteFileBy == efShell) &&
  2820. !WinConfiguration->Editor.SDIShellEditor) ||
  2821. ((ExecuteFileBy == efExternalEditor) &&
  2822. !ExternalEditor->SDIExternalEditor))
  2823. {
  2824. // no need for handle
  2825. if (Process != NULL)
  2826. {
  2827. DebugCheck(CloseHandle(Process));
  2828. }
  2829. Process = INVALID_HANDLE_VALUE;
  2830. }
  2831. else
  2832. {
  2833. if (Process == NULL)
  2834. {
  2835. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2836. }
  2837. }
  2838. if (Side == osRemote)
  2839. {
  2840. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2841. }
  2842. }
  2843. }
  2844. //---------------------------------------------------------------------------
  2845. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2846. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2847. void * /*Arg*/)
  2848. {
  2849. if (Token != NULL)
  2850. {
  2851. EditorFormFileSave(static_cast<TForm *>(Token));
  2852. }
  2853. }
  2854. //---------------------------------------------------------------------------
  2855. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2856. {
  2857. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2858. {
  2859. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2860. }
  2861. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2862. }
  2863. //---------------------------------------------------------------------------
  2864. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2865. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2866. void * Arg)
  2867. {
  2868. if ((Token != NULL) &&
  2869. IsEditorFormModified(static_cast<TForm *>(Token)))
  2870. {
  2871. *static_cast<bool *>(Arg) = true;
  2872. }
  2873. }
  2874. //---------------------------------------------------------------------------
  2875. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2876. TObject * /*Sender*/, bool & Modified)
  2877. {
  2878. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2879. {
  2880. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2881. {
  2882. Modified = true;
  2883. }
  2884. }
  2885. if (!Modified)
  2886. {
  2887. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  2892. {
  2893. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  2894. }
  2895. //---------------------------------------------------------------------------
  2896. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  2897. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  2898. UnicodeString & Result, UnicodeString & RootDirectory)
  2899. {
  2900. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  2901. {
  2902. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  2903. Result = RootDirectory;
  2904. }
  2905. else
  2906. {
  2907. RootDirectory = L"";
  2908. Result = WinConfiguration->ExpandedTemporaryDirectory();
  2909. Result = IncludeTrailingBackslash(Result);
  2910. }
  2911. if (WinConfiguration->TemporaryDirectoryAppendSession)
  2912. {
  2913. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  2914. }
  2915. if (WinConfiguration->TemporaryDirectoryAppendPath)
  2916. {
  2917. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  2918. {
  2919. RemoteDirectory.Delete(1, 1);
  2920. }
  2921. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  2922. }
  2923. if (!ForceDirectories(ApiPath(Result)))
  2924. {
  2925. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  2926. }
  2927. }
  2928. //---------------------------------------------------------------------------
  2929. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  2930. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  2931. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  2932. {
  2933. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2934. if (ForceText)
  2935. {
  2936. CopyParam.TransferMode = tmAscii;
  2937. }
  2938. TemporaryFileCopyParam(CopyParam);
  2939. if (AllFiles)
  2940. {
  2941. CopyParam.IncludeFileMask = TFileMasks();
  2942. }
  2943. if (TempDir.IsEmpty())
  2944. {
  2945. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  2946. }
  2947. DebugAssert(!FAutoOperation);
  2948. FAutoOperation = AutoOperation;
  2949. Terminal->ExceptionOnFail = true;
  2950. try
  2951. {
  2952. try
  2953. {
  2954. // turn off confirmations, as for MDI editors we may possibly download
  2955. // the same file over
  2956. Terminal->CopyToLocal(
  2957. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  2958. if (GetTargetNames)
  2959. {
  2960. for (int i = 0; i < FileList->Count; i++)
  2961. {
  2962. FileList->Strings[i] =
  2963. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  2964. }
  2965. }
  2966. }
  2967. catch(...)
  2968. {
  2969. if (!RootTempDir.IsEmpty())
  2970. {
  2971. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2972. }
  2973. throw;
  2974. }
  2975. }
  2976. __finally
  2977. {
  2978. FAutoOperation = false;
  2979. Terminal->ExceptionOnFail = false;
  2980. }
  2981. }
  2982. //---------------------------------------------------------------------------
  2983. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  2984. {
  2985. // Do not waste time checking for default editor list the next time,
  2986. // or testing if default editor is not notepad.
  2987. bool TryNextTime = false;
  2988. UnicodeString UsageState;
  2989. if (!WinConfiguration->EditorList->IsDefaultList())
  2990. {
  2991. UsageState = "H";
  2992. }
  2993. else
  2994. {
  2995. UnicodeString Executable;
  2996. UnicodeString ExecutableDescription;
  2997. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  2998. {
  2999. UnicodeString Message =
  3000. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3001. unsigned int Answer =
  3002. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3003. if (Answer != qaOK)
  3004. {
  3005. UsageState = "R";
  3006. }
  3007. else
  3008. {
  3009. UsageState = "A";
  3010. TEditorData EditorData;
  3011. EditorData.Editor = edExternal;
  3012. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3013. EditorData.DecideExternalEditorText();
  3014. TEditorList EditorList;
  3015. EditorList = *WinConfiguration->EditorList;
  3016. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3017. WinConfiguration->EditorList = &EditorList;
  3018. }
  3019. }
  3020. }
  3021. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3022. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3023. }
  3024. //---------------------------------------------------------------------------
  3025. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3026. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3027. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3028. {
  3029. if (ExecuteFileBy == efDefaultEditor)
  3030. {
  3031. if (!WinConfiguration->OfferedEditorAutoConfig)
  3032. {
  3033. EditorAutoConfig();
  3034. }
  3035. const TEditorPreferences * Editor =
  3036. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3037. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3038. {
  3039. ExecuteFileBy = efInternalEditor;
  3040. ExternalEditor = NULL;
  3041. }
  3042. else if (Editor->Data->Editor == edOpen)
  3043. {
  3044. ExecuteFileBy = efShell;
  3045. ExternalEditor = NULL;
  3046. }
  3047. else
  3048. {
  3049. ExecuteFileBy = efExternalEditor;
  3050. ExternalEditor = Editor->Data;
  3051. }
  3052. }
  3053. }
  3054. //---------------------------------------------------------------------------
  3055. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3056. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3057. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3058. {
  3059. UnicodeString OriginalFileName;
  3060. UnicodeString LocalRootDirectory;
  3061. UnicodeString RemoteDirectory;
  3062. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3063. (Side == osLocal), MaskParams);
  3064. UnicodeString Counter;
  3065. UnicodeString LocalFileName;
  3066. bool Handled = false;
  3067. if (Side == osRemote)
  3068. {
  3069. // We need to trim VMS version here, so that we use name without version
  3070. // when uploading back to create a new version of the file
  3071. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3072. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3073. TObject * Token = NULL;
  3074. UnicodeString LocalDirectory;
  3075. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3076. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3077. LocalDirectory))
  3078. {
  3079. if (Token != NULL)
  3080. {
  3081. TForm * Form = dynamic_cast<TForm *>(Token);
  3082. if (Form->WindowState == wsMinimized)
  3083. {
  3084. ShowWindow(Form->Handle, SW_RESTORE);
  3085. }
  3086. else
  3087. {
  3088. Form->SetFocus();
  3089. }
  3090. Handled = true;
  3091. }
  3092. else
  3093. {
  3094. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3095. }
  3096. }
  3097. if (!Handled)
  3098. {
  3099. TStringList * FileList1 = new TStringList();
  3100. try
  3101. {
  3102. FileList1->AddObject(FullFileName, Object);
  3103. TemporarilyDownloadFiles(FileList1,
  3104. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3105. LocalRootDirectory, LocalDirectory, true, true, true);
  3106. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3107. }
  3108. __finally
  3109. {
  3110. delete FileList1;
  3111. }
  3112. switch (ExecuteFileBy)
  3113. {
  3114. case efShell:
  3115. Counter = "RemoteFilesExecuted";
  3116. break;
  3117. case efInternalEditor:
  3118. Counter = "RemoteFilesOpenedInInternalEditor";
  3119. break;
  3120. case efExternalEditor:
  3121. Counter = "RemoteFilesOpenedInExternalEditor";
  3122. break;
  3123. default:
  3124. DebugFail();
  3125. }
  3126. }
  3127. }
  3128. else
  3129. {
  3130. LocalFileName = FullFileName;
  3131. OriginalFileName = ExtractFileName(FullFileName);
  3132. switch (ExecuteFileBy)
  3133. {
  3134. case efShell:
  3135. Counter = "LocalFilesExecuted";
  3136. break;
  3137. case efInternalEditor:
  3138. Counter = "LocalFilesOpenedInInternalEditor";
  3139. break;
  3140. case efExternalEditor:
  3141. Counter = "LocalFilesOpenedInExternalEditor";
  3142. break;
  3143. default:
  3144. DebugFail();
  3145. }
  3146. }
  3147. if (!Handled)
  3148. {
  3149. Configuration->Usage->Inc(Counter);
  3150. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3151. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3152. }
  3153. }
  3154. //---------------------------------------------------------------------------
  3155. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3156. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3157. bool AllSelected, bool OnFocused)
  3158. {
  3159. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3160. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3161. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3162. Side = GetSide(Side);
  3163. TCustomDirView * DView = DirView(Side);
  3164. TStrings * FileList = AllSelected ?
  3165. DView->CreateFileList(OnFocused, Side == osLocal) :
  3166. DView->CreateFocusedFileList(Side == osLocal);
  3167. try
  3168. {
  3169. DebugAssert(AllSelected || (FileList->Count == 1));
  3170. for (int i = 0; i < FileList->Count; i++)
  3171. {
  3172. UnicodeString ListFileName = FileList->Strings[i];
  3173. UnicodeString FileNameOnly = (Side == osRemote) ?
  3174. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3175. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3176. if (!DView->ItemIsDirectory(Item))
  3177. {
  3178. UnicodeString FullFileName;
  3179. if (Side == osRemote)
  3180. {
  3181. FullFileName = RemoteDirView->Path + ListFileName;
  3182. }
  3183. else
  3184. {
  3185. FullFileName = ListFileName;
  3186. }
  3187. TFileMasks::TParams MaskParams;
  3188. MaskParams.Size = DView->ItemFileSize(Item);
  3189. TDateTimePrecision Precision;
  3190. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3191. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3192. FileList->Objects[i], MaskParams);
  3193. }
  3194. }
  3195. }
  3196. __finally
  3197. {
  3198. delete FileList;
  3199. }
  3200. }
  3201. //---------------------------------------------------------------------------
  3202. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3203. {
  3204. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3205. CopyParam.FileNameCase = ncNoChange;
  3206. CopyParam.PreserveRights = false;
  3207. CopyParam.PreserveReadOnly = false;
  3208. CopyParam.ReplaceInvalidChars = true;
  3209. CopyParam.IncludeFileMask = TFileMasks();
  3210. CopyParam.NewerOnly = false;
  3211. CopyParam.FileMask = L"";
  3212. }
  3213. //---------------------------------------------------------------------------
  3214. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3215. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3216. {
  3217. TTerminalManager * Manager = TTerminalManager::Instance();
  3218. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3219. {
  3220. if (!NonVisualDataModule->Busy)
  3221. {
  3222. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3223. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3224. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3225. if (Data->Terminal == NULL)
  3226. {
  3227. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3228. if (SameSiteTerminal != NULL)
  3229. {
  3230. UnicodeString Message =
  3231. FMTLOAD(EDIT_SESSION_REATTACH,
  3232. (FileNameOnly, Data->SessionName, FileNameOnly));
  3233. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3234. {
  3235. Data->Terminal = Terminal;
  3236. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3237. Data->SessionName = Terminal->SessionData->SessionName;
  3238. // We might also overwrite session data
  3239. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3240. }
  3241. else
  3242. {
  3243. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3244. Abort();
  3245. }
  3246. }
  3247. }
  3248. // foreground session should reconnect itself
  3249. else if (Terminal != Data->Terminal)
  3250. {
  3251. UnicodeString Message =
  3252. MainInstructions(
  3253. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3254. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3255. {
  3256. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3257. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3258. }
  3259. else
  3260. {
  3261. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3262. Abort();
  3263. }
  3264. }
  3265. }
  3266. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3267. {
  3268. Configuration->Usage->Inc(L"EditInactiveSession");
  3269. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3270. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3271. (ExtractFileName(FileName), Data->SessionName)));
  3272. }
  3273. }
  3274. TStrings * FileList = new TStringList();
  3275. try
  3276. {
  3277. FileList->Add(FileName);
  3278. // consider using the same settings (preset) as when the file was downloaded
  3279. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3280. TemporaryFileCopyParam(CopyParam);
  3281. if (Data->ForceText)
  3282. {
  3283. CopyParam.TransferMode = tmAscii;
  3284. }
  3285. // so i do not need to worry if masking algorithm works in all cases
  3286. // ("" means "copy file name", no masking is actually done)
  3287. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3288. {
  3289. CopyParam.FileMask = L"";
  3290. }
  3291. else
  3292. {
  3293. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3294. }
  3295. DebugAssert(Data->Queue != NULL);
  3296. int Params = cpNoConfirmation | cpTemporary;
  3297. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3298. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3299. QueueItem->CompleteEvent = UploadCompleteEvent;
  3300. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3301. }
  3302. __finally
  3303. {
  3304. delete FileList;
  3305. }
  3306. }
  3307. //---------------------------------------------------------------------------
  3308. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3309. const UnicodeString FileName, const TEditedFileData * Data)
  3310. {
  3311. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3312. DebugAssert(!NonVisualDataModule->Busy);
  3313. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3314. {
  3315. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3316. (ExtractFileName(FileName), Data->SessionName)));
  3317. }
  3318. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3319. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3320. NonVisualDataModule->StartBusy();
  3321. try
  3322. {
  3323. std::unique_ptr<TRemoteFile> File;
  3324. UnicodeString RemoteFileName =
  3325. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3326. FTerminal->ExceptionOnFail = true;
  3327. try
  3328. {
  3329. TRemoteFile * AFile = NULL;
  3330. FTerminal->ReadFile(RemoteFileName, AFile);
  3331. File.reset(AFile);
  3332. if (!File->HaveFullFileName)
  3333. {
  3334. File->FullFileName = RemoteFileName;
  3335. }
  3336. }
  3337. __finally
  3338. {
  3339. FTerminal->ExceptionOnFail = false;
  3340. }
  3341. std::unique_ptr<TStrings> FileList(new TStringList());
  3342. FileList->AddObject(RemoteFileName, File.get());
  3343. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3344. UnicodeString TempDir = ExtractFilePath(FileName);
  3345. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3346. TempDir, true, true, true);
  3347. // sanity check, the target file name should be still the same
  3348. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3349. }
  3350. __finally
  3351. {
  3352. NonVisualDataModule->EndBusy();
  3353. // it actually may not exist anymore...
  3354. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3355. }
  3356. }
  3357. //---------------------------------------------------------------------------
  3358. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3359. const TEditedFileData * Data, bool & KeepOpen)
  3360. {
  3361. // Command is set for external editors only (not for "shell" open).
  3362. if (!Data->Command.IsEmpty())
  3363. {
  3364. bool AnyFound = false;
  3365. bool AnyMDI = false;
  3366. bool AnyNonMDI = false;
  3367. bool AnyDetect = false;
  3368. TEditorList * EditorList = new TEditorList();
  3369. try
  3370. {
  3371. *EditorList = *WinConfiguration->EditorList;
  3372. for (int i = 0; i < EditorList->Count; i++)
  3373. {
  3374. const TEditorPreferences * Editor = EditorList->Editors[i];
  3375. if ((Editor->Data->Editor == edExternal) &&
  3376. (Editor->Data->ExternalEditor == Data->Command))
  3377. {
  3378. AnyFound = true;
  3379. if (Editor->Data->SDIExternalEditor)
  3380. {
  3381. AnyNonMDI = true;
  3382. if (Editor->Data->DetectMDIExternalEditor)
  3383. {
  3384. AnyDetect = true;
  3385. }
  3386. }
  3387. else
  3388. {
  3389. AnyMDI = true;
  3390. }
  3391. }
  3392. }
  3393. bool EnableMDI = false;
  3394. bool DisableDetect = false;
  3395. if (AnyMDI)
  3396. {
  3397. KeepOpen = true;
  3398. if (AnyNonMDI)
  3399. {
  3400. // there is at least one instance of the editor with MDI support enabled,
  3401. // and one with disabled, enable it for all instances
  3402. EnableMDI = true;
  3403. }
  3404. }
  3405. else if (AnyFound && !AnyDetect)
  3406. {
  3407. // at least once instance found but all have MDI autodetection disabled
  3408. // => close the file (default action)
  3409. }
  3410. else
  3411. {
  3412. // no instance of the editor has MDI support enabled
  3413. TMessageParams Params;
  3414. if (AnyFound)
  3415. {
  3416. // there is at least one instance of the editor
  3417. Params.Params |= mpNeverAskAgainCheck;
  3418. }
  3419. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3420. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3421. switch (Answer)
  3422. {
  3423. case qaNeverAskAgain:
  3424. DisableDetect = true;
  3425. break;
  3426. case qaNo:
  3427. EnableMDI = true;
  3428. KeepOpen = true;
  3429. break;
  3430. }
  3431. }
  3432. if (AnyFound && (EnableMDI || DisableDetect))
  3433. {
  3434. bool Changed = false;
  3435. for (int i = 0; i < EditorList->Count; i++)
  3436. {
  3437. const TEditorPreferences * Editor = EditorList->Editors[i];
  3438. if ((Editor->Data->Editor == edExternal) &&
  3439. (Editor->Data->ExternalEditor == Data->Command) &&
  3440. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3441. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3442. {
  3443. Changed = true;
  3444. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3445. if (EnableMDI)
  3446. {
  3447. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3448. }
  3449. if (DisableDetect)
  3450. {
  3451. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3452. }
  3453. EditorList->Change(i, UpdatedEditor);
  3454. }
  3455. }
  3456. if (Changed)
  3457. {
  3458. WinConfiguration->EditorList = EditorList;
  3459. }
  3460. }
  3461. }
  3462. __finally
  3463. {
  3464. delete EditorList;
  3465. }
  3466. }
  3467. else
  3468. {
  3469. // "open" case
  3470. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3471. qaOK, HELP_APP_EARLY_CLOSED);
  3472. }
  3473. }
  3474. //---------------------------------------------------------------------------
  3475. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3476. {
  3477. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3478. }
  3479. //---------------------------------------------------------------------------
  3480. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3481. {
  3482. SideEnter(osRemote);
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3486. {
  3487. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  3488. SideEnter(osRemote);
  3489. }
  3490. //---------------------------------------------------------------------------
  3491. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3492. {
  3493. FCurrentSide = Side;
  3494. if (Visible)
  3495. {
  3496. UpdateControls();
  3497. }
  3498. }
  3499. //---------------------------------------------------------------------------
  3500. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3501. TStrings * FileList, bool Alternative)
  3502. {
  3503. TCustomDirView * DView = DirView(Side);
  3504. DView->SaveSelection();
  3505. DView->SaveSelectedNames();
  3506. DebugAssert(!FAlternativeDelete);
  3507. FAlternativeDelete = Alternative;
  3508. try
  3509. {
  3510. if (Side == osRemote)
  3511. {
  3512. DebugAssert(Terminal != NULL);
  3513. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3514. }
  3515. else
  3516. {
  3517. try
  3518. {
  3519. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3520. }
  3521. __finally
  3522. {
  3523. ReloadLocalDirectory();
  3524. }
  3525. }
  3526. FAlternativeDelete = false;
  3527. }
  3528. catch(...)
  3529. {
  3530. FAlternativeDelete = false;
  3531. DView->DiscardSavedSelection();
  3532. throw;
  3533. }
  3534. DView->RestoreSelection();
  3535. }
  3536. //---------------------------------------------------------------------------
  3537. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3538. {
  3539. DebugAssert(Terminal);
  3540. RemoteDirView->SaveSelection();
  3541. RemoteDirView->SaveSelectedNames();
  3542. try
  3543. {
  3544. if (Lock)
  3545. {
  3546. Terminal->LockFiles(FileList);
  3547. }
  3548. else
  3549. {
  3550. Terminal->UnlockFiles(FileList);
  3551. }
  3552. }
  3553. catch(...)
  3554. {
  3555. RemoteDirView->DiscardSavedSelection();
  3556. throw;
  3557. }
  3558. RemoteDirView->RestoreSelection();
  3559. }
  3560. //---------------------------------------------------------------------------
  3561. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3562. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3563. bool NoConfirmation, bool Move)
  3564. {
  3565. if (RemoteDriveView->DropTarget != NULL)
  3566. {
  3567. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3568. }
  3569. else if (RemoteDirView->DropTarget != NULL)
  3570. {
  3571. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3572. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3573. }
  3574. else
  3575. {
  3576. Target = RemoteDirView->Path;
  3577. }
  3578. if (Session == NULL)
  3579. {
  3580. Session = TTerminalManager::Instance()->ActiveTerminal;
  3581. }
  3582. Target = UnixIncludeTrailingBackslash(Target);
  3583. if (FileList->Count == 1)
  3584. {
  3585. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3586. }
  3587. else
  3588. {
  3589. FileMask = AnyMask;
  3590. }
  3591. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3592. bool Result = true;
  3593. if (!NoConfirmation)
  3594. {
  3595. bool Multi = (FileList->Count > 1);
  3596. if (Move)
  3597. {
  3598. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3599. }
  3600. else
  3601. {
  3602. DebugAssert(Terminal != NULL);
  3603. // update Terminal->StateData->RemoteDirectory
  3604. UpdateTerminal(Terminal);
  3605. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3606. TStrings * Directories = new TStringList;
  3607. try
  3608. {
  3609. for (int Index = 0; Index < Sessions->Count; Index++)
  3610. {
  3611. TManagedTerminal * Terminal =
  3612. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3613. Directories->Add(Terminal->StateData->RemoteDirectory);
  3614. }
  3615. TDirectRemoteCopy AllowDirectCopy;
  3616. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3617. {
  3618. DebugAssert(DirectCopy);
  3619. AllowDirectCopy = drcAllow;
  3620. }
  3621. else if (FTerminal->IsCapable[fcSecondaryShell])
  3622. {
  3623. DebugAssert(DirectCopy);
  3624. AllowDirectCopy = drcConfirmCommandSession;
  3625. }
  3626. else
  3627. {
  3628. DebugAssert(!DirectCopy);
  3629. AllowDirectCopy = drcDisallow;
  3630. }
  3631. void * ASession = Session;
  3632. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3633. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3634. Session = static_cast<TTerminal *>(ASession);
  3635. }
  3636. __finally
  3637. {
  3638. delete Directories;
  3639. }
  3640. }
  3641. }
  3642. return Result;
  3643. }
  3644. //---------------------------------------------------------------------------
  3645. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3646. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3647. {
  3648. bool DirectCopy;
  3649. UnicodeString Target, FileMask;
  3650. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3651. if (Result)
  3652. {
  3653. if (!Move && !DirectCopy)
  3654. {
  3655. Configuration->Usage->Inc("RemoteCopyTemp");
  3656. UnicodeString RootTempDir;
  3657. UnicodeString TempDir;
  3658. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3659. TStrings * TemporaryFilesList = new TStringList();
  3660. try
  3661. {
  3662. TMakeLocalFileListParams MakeFileListParam;
  3663. MakeFileListParam.FileList = TemporaryFilesList;
  3664. MakeFileListParam.FileTimes = NULL;
  3665. MakeFileListParam.IncludeDirs = true;
  3666. MakeFileListParam.Recursive = false;
  3667. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3668. TTerminalManager::Instance()->ActiveTerminal = Session;
  3669. if (TemporaryFilesList->Count > 0)
  3670. {
  3671. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3672. CopyParam.FileMask = FileMask;
  3673. DebugAssert(!FAutoOperation);
  3674. FAutoOperation = true;
  3675. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3676. }
  3677. }
  3678. __finally
  3679. {
  3680. delete TemporaryFilesList;
  3681. FAutoOperation = false;
  3682. if (!RootTempDir.IsEmpty())
  3683. {
  3684. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3685. }
  3686. }
  3687. }
  3688. else
  3689. {
  3690. RemoteDirView->SaveSelection();
  3691. RemoteDirView->SaveSelectedNames();
  3692. try
  3693. {
  3694. if (Move)
  3695. {
  3696. Configuration->Usage->Inc("RemoteMove");
  3697. Terminal->MoveFiles(FileList, Target, FileMask);
  3698. }
  3699. else
  3700. {
  3701. Configuration->Usage->Inc("RemoteCopyDirect");
  3702. DebugAssert(DirectCopy);
  3703. DebugAssert(Session == FTerminal);
  3704. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3705. FTerminal->CommandSessionOpened ||
  3706. CommandSessionFallback())
  3707. {
  3708. Terminal->CopyFiles(FileList, Target, FileMask);
  3709. }
  3710. }
  3711. }
  3712. catch(...)
  3713. {
  3714. RemoteDirView->DiscardSavedSelection();
  3715. throw;
  3716. }
  3717. RemoteDirView->RestoreSelection();
  3718. }
  3719. }
  3720. return Result;
  3721. }
  3722. //---------------------------------------------------------------------------
  3723. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3724. {
  3725. Side = GetSide(Side);
  3726. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3727. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3728. UnicodeString Name = LoadStr(NEW_FOLDER);
  3729. int AllowedChanges =
  3730. FLAGMASK((Side == osRemote) && Terminal->IsCapable[fcModeChanging], cpMode);
  3731. bool SaveSettings = false;
  3732. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3733. {
  3734. TWindowLock Lock(this);
  3735. if (Side == osRemote)
  3736. {
  3737. if (SaveSettings)
  3738. {
  3739. GUIConfiguration->NewDirectoryProperties = Properties;
  3740. }
  3741. RemoteDirView->CreateDirectoryEx(Name, &Properties);
  3742. }
  3743. else
  3744. {
  3745. DirView(Side)->CreateDirectory(Name);
  3746. }
  3747. }
  3748. }
  3749. //---------------------------------------------------------------------------
  3750. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3751. {
  3752. TWindowLock Lock(this);
  3753. DirView(Side)->ExecuteHomeDirectory();
  3754. }
  3755. //---------------------------------------------------------------------------
  3756. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3757. {
  3758. DoOpenDirectoryDialog(odBrowse, Side);
  3759. }
  3760. //---------------------------------------------------------------------------
  3761. bool __fastcall TCustomScpExplorerForm::OpenBookmark(UnicodeString Local, UnicodeString Remote)
  3762. {
  3763. UnicodeString Path;
  3764. if (FCurrentSide == osRemote)
  3765. {
  3766. Path = Remote;
  3767. }
  3768. else
  3769. {
  3770. Path = Local;
  3771. }
  3772. bool Result = !Path.IsEmpty();
  3773. if (Result)
  3774. {
  3775. // While we might get here when the session is closed (from location profiles),
  3776. // it's not a problem as the Path setter is noop then
  3777. DirView(FCurrentSide)->Path = Path;
  3778. }
  3779. return Result;
  3780. }
  3781. //---------------------------------------------------------------------------
  3782. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3783. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3784. bool & Close)
  3785. {
  3786. // terminal can be already closed (e.g. dropped connection)
  3787. if (Terminal != NULL)
  3788. {
  3789. try
  3790. {
  3791. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3792. }
  3793. catch(...)
  3794. {
  3795. if (!Terminal->Active)
  3796. {
  3797. Close = true;
  3798. }
  3799. throw;
  3800. }
  3801. }
  3802. }
  3803. //---------------------------------------------------------------------------
  3804. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3805. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3806. bool & Close)
  3807. {
  3808. // terminal can be already closed (e.g. dropped connection)
  3809. if (Terminal != NULL)
  3810. {
  3811. Configuration->Usage->Inc(L"ChecksumCalculated");
  3812. try
  3813. {
  3814. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3815. }
  3816. catch(...)
  3817. {
  3818. if (!Terminal->Active)
  3819. {
  3820. Close = true;
  3821. }
  3822. throw;
  3823. }
  3824. }
  3825. }
  3826. //---------------------------------------------------------------------------
  3827. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3828. {
  3829. bool Result;
  3830. if (Side == osRemote)
  3831. {
  3832. TRemoteTokenList * GroupList = NULL;
  3833. TRemoteTokenList * UserList = NULL;
  3834. try
  3835. {
  3836. TRemoteProperties CurrentProperties;
  3837. if (Terminal->LoadFilesProperties(FileList))
  3838. {
  3839. RemoteDirView->Invalidate();
  3840. }
  3841. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3842. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3843. if (CapableGroupChanging || CapableOwnerChanging)
  3844. {
  3845. if (CapableGroupChanging)
  3846. {
  3847. GroupList = Terminal->Groups->Duplicate();
  3848. }
  3849. if (CapableOwnerChanging)
  3850. {
  3851. UserList = Terminal->Users->Duplicate();
  3852. }
  3853. TRemoteDirectory * Files = Terminal->Files;
  3854. int Count = Files->Count;
  3855. if (Count > 100)
  3856. {
  3857. Count = 100;
  3858. }
  3859. for (int Index = 0; Index < Count; Index++)
  3860. {
  3861. TRemoteFile * File = Files->Files[Index];
  3862. if (CapableGroupChanging)
  3863. {
  3864. GroupList->AddUnique(File->Group);
  3865. }
  3866. if (CapableOwnerChanging)
  3867. {
  3868. UserList->AddUnique(File->Owner);
  3869. }
  3870. }
  3871. // if we haven't collected tokens for all files in current directory,
  3872. // make sure we collect them at least for all selected files.
  3873. // (note that so far the files in FileList has to be from current direcotry)
  3874. if (Count < Files->Count)
  3875. {
  3876. for (int Index = 0; Index < FileList->Count; Index++)
  3877. {
  3878. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  3879. if (CapableGroupChanging)
  3880. {
  3881. GroupList->AddUnique(File->Group);
  3882. }
  3883. if (CapableOwnerChanging)
  3884. {
  3885. UserList->AddUnique(File->Owner);
  3886. }
  3887. }
  3888. }
  3889. }
  3890. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  3891. int Flags = 0;
  3892. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  3893. if (CapableOwnerChanging) Flags |= cpOwner;
  3894. if (CapableGroupChanging) Flags |= cpGroup;
  3895. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  3896. if (Terminal->IsCapable[fcCalculatingChecksum])
  3897. {
  3898. CalculateChecksumEvent = CalculateChecksum;
  3899. }
  3900. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  3901. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  3902. TRemoteProperties NewProperties = CurrentProperties;
  3903. Result =
  3904. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  3905. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  3906. Terminal->IsCapable[fcGroupOwnerChangingByID],
  3907. CalculateSize, CalculateChecksumEvent);
  3908. if (Result)
  3909. {
  3910. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  3911. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  3912. }
  3913. }
  3914. __finally
  3915. {
  3916. delete GroupList;
  3917. delete UserList;
  3918. }
  3919. }
  3920. else
  3921. {
  3922. DirView(Side)->DisplayPropertiesMenu();
  3923. Result = true;
  3924. }
  3925. return Result;
  3926. }
  3927. //---------------------------------------------------------------------------
  3928. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  3929. {
  3930. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  3931. {
  3932. FIgnoreNextDialogChar = Key;
  3933. }
  3934. Key = 0;
  3935. }
  3936. //---------------------------------------------------------------------------
  3937. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  3938. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  3939. {
  3940. const TCustomCommandType * Command = List->Find(KeyShortCut);
  3941. if (Command != NULL)
  3942. {
  3943. KeyProcessed(Key, Shift);
  3944. if (CustomCommandState(*Command, false, ccltAll) > 0)
  3945. {
  3946. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  3947. false, false, const_cast<TCustomCommandType *>(Command));
  3948. }
  3949. }
  3950. }
  3951. //---------------------------------------------------------------------------
  3952. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  3953. {
  3954. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  3955. {
  3956. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  3957. }
  3958. if (!DirView(osCurrent)->IsEditing())
  3959. {
  3960. TShortCut KeyShortCut = ShortCut(Key, Shift);
  3961. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  3962. {
  3963. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  3964. if (((Action->ShortCut == KeyShortCut) ||
  3965. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  3966. AllowedAction(Action, aaShortCut))
  3967. {
  3968. // Has to be called before the action as the dialog char is already in queue.
  3969. // So when the action consumes message queue, we already need to have the
  3970. // FIgnoreNextDialogChar set
  3971. KeyProcessed(Key, Shift);
  3972. // Reset reference to previous component (when menu/toolbar was clicked).
  3973. // Needed to detect that action was invoked by keyboard shortcut
  3974. // in TNonVisualDataModule::ExplorerActionsExecute
  3975. Action->ActionComponent = NULL;
  3976. Action->Execute();
  3977. return;
  3978. }
  3979. }
  3980. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  3981. {
  3982. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  3983. {
  3984. KeyProcessed(Key, Shift);
  3985. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  3986. return;
  3987. }
  3988. }
  3989. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  3990. {
  3991. KeyProcessed(Key, Shift);
  3992. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  3993. }
  3994. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  3995. if (IsCustomShortCut(CustomShortCut))
  3996. {
  3997. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  3998. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  3999. if (WinConfiguration->SharedBookmarks != NULL)
  4000. {
  4001. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4002. if ((Bookmark != NULL) &&
  4003. OpenBookmark(Bookmark->Local, Bookmark->Remote))
  4004. {
  4005. KeyProcessed(Key, Shift);
  4006. }
  4007. }
  4008. }
  4009. }
  4010. TForm::KeyDown(Key, Shift);
  4011. }
  4012. //---------------------------------------------------------------------------
  4013. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4014. {
  4015. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4016. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4017. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4018. DebugAssert(Terminal);
  4019. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4020. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4021. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4022. // expanded from ?: to avoid memory leaks
  4023. if (SecurityEnabled)
  4024. {
  4025. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4026. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4027. }
  4028. else
  4029. {
  4030. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4031. }
  4032. if (FileSystemInfo.ProtocolName.IsEmpty())
  4033. {
  4034. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4035. }
  4036. else
  4037. {
  4038. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4039. }
  4040. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4041. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4042. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4043. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4044. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4045. UnicodeString CompressionStr = CSCompressionStr;
  4046. if (CSCompressionStr != SCCompressionStr)
  4047. {
  4048. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4049. }
  4050. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4051. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4052. UpdateStatusBar();
  4053. }
  4054. //---------------------------------------------------------------------------
  4055. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4056. {
  4057. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4058. DebugAssert(SessionStatusBar != NULL);
  4059. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4060. {
  4061. // note: (Terminal->Status < sshReady) currently never happens here,
  4062. // so STATUS_CONNECTING is never used
  4063. SessionStatusBar->SimplePanel = true;
  4064. SessionStatusBar->SimpleText = LoadStr(
  4065. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4066. }
  4067. else
  4068. {
  4069. DebugAssert(Terminal);
  4070. SessionStatusBar->SimplePanel = false;
  4071. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4072. if (!FNote.IsEmpty())
  4073. {
  4074. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4075. }
  4076. else
  4077. {
  4078. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4079. }
  4080. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4081. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4082. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4083. }
  4084. }
  4085. //---------------------------------------------------------------------------
  4086. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4087. {
  4088. Panel->Caption = L"";
  4089. }
  4090. //---------------------------------------------------------------------------
  4091. void __fastcall TCustomScpExplorerForm::Idle()
  4092. {
  4093. if (FShowing || FStandaloneEditing)
  4094. {
  4095. FEditorManager->Check();
  4096. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4097. // that needs to know if queue view is visible (and it may be closed after queue update)
  4098. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal);
  4099. }
  4100. if (FShowing)
  4101. {
  4102. if (!NonVisualDataModule->Busy &&
  4103. // Menu is opened or drag&drop is going on
  4104. (Mouse->Capture == NULL))
  4105. {
  4106. if (FRefreshRemoteDirectory)
  4107. {
  4108. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4109. {
  4110. Terminal->RefreshDirectory();
  4111. }
  4112. FRefreshRemoteDirectory = false;
  4113. }
  4114. if (FRefreshLocalDirectory)
  4115. {
  4116. ReloadLocalDirectory();
  4117. FRefreshLocalDirectory = false;
  4118. }
  4119. if (WinConfiguration->RefreshRemotePanel)
  4120. {
  4121. TManagedTerminal * ManagedTerminal =
  4122. dynamic_cast<TManagedTerminal *>(Terminal);
  4123. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  4124. (Now() - ManagedTerminal->DirectoryLoaded >
  4125. WinConfiguration->RefreshRemotePanelInterval))
  4126. {
  4127. RemoteDirView->ReloadDirectory();
  4128. }
  4129. }
  4130. }
  4131. }
  4132. if (FShowing || FStandaloneEditing)
  4133. {
  4134. if (FQueueStatusInvalidated)
  4135. {
  4136. UpdateQueueStatus(false);
  4137. }
  4138. RefreshQueueItems();
  4139. }
  4140. if (FShowing)
  4141. {
  4142. UpdateStatusBar();
  4143. }
  4144. FIgnoreNextDialogChar = 0;
  4145. }
  4146. //---------------------------------------------------------------------------
  4147. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4148. {
  4149. try
  4150. {
  4151. FUserActionTimer->Enabled = false;
  4152. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4153. {
  4154. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4155. {
  4156. FPendingQueueActionItem->ProcessUserAction();
  4157. }
  4158. }
  4159. }
  4160. __finally
  4161. {
  4162. FPendingQueueActionItem = NULL;
  4163. }
  4164. }
  4165. //---------------------------------------------------------------------------
  4166. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4167. {
  4168. if (WinConfiguration->MinimizeToTray)
  4169. {
  4170. UpdateTrayIcon();
  4171. FTrayIcon->Visible = true;
  4172. if (Visible)
  4173. {
  4174. ShowWindow(Handle, SW_HIDE);
  4175. }
  4176. }
  4177. }
  4178. //---------------------------------------------------------------------------
  4179. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4180. {
  4181. // WORKAROUND
  4182. // When restoring maximized window from minimization,
  4183. // rarely some controls do not align properly.
  4184. // Two instances seen (both for Commander):
  4185. // - When restoring, window is temporarily narrower (not maximized),
  4186. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4187. // Once maximized already, top dock shinks back, but the session PageControl,
  4188. // do not align up, leaving space between TopDock and PageControl.
  4189. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4190. for (int Index = 0; Index < ControlCount; Index++)
  4191. {
  4192. RealignControl(Controls[Index]);
  4193. }
  4194. if (FTrayIcon->Visible)
  4195. {
  4196. FTrayIcon->Visible = false;
  4197. if (Visible)
  4198. {
  4199. ShowWindow(Handle, SW_SHOW);
  4200. }
  4201. }
  4202. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4203. {
  4204. FNeedSession = false;
  4205. NonVisualDataModule->StartBusy();
  4206. try
  4207. {
  4208. NeedSession(false);
  4209. }
  4210. __finally
  4211. {
  4212. NonVisualDataModule->EndBusy();
  4213. }
  4214. }
  4215. }
  4216. //---------------------------------------------------------------------------
  4217. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4218. {
  4219. FTrayIcon->Hint = Caption;
  4220. }
  4221. //---------------------------------------------------------------------------
  4222. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4223. {
  4224. UpdateTrayIcon();
  4225. }
  4226. //---------------------------------------------------------------------------
  4227. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4228. {
  4229. // workaround
  4230. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4231. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4232. // But WM_ACTIVATEAPP message can be received even when
  4233. // the main window is minimized to the tray and internal editor window is focused
  4234. // (after another application was previously active)
  4235. if (::IsIconic(Handle))
  4236. {
  4237. if (!IsAppIconic())
  4238. {
  4239. SetAppIconic(true);
  4240. }
  4241. }
  4242. ::ApplicationRestore();
  4243. Application->BringToFront();
  4244. }
  4245. //---------------------------------------------------------------------------
  4246. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4247. {
  4248. RestoreApp();
  4249. }
  4250. //---------------------------------------------------------------------------
  4251. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4252. {
  4253. if (OpenInNewWindow())
  4254. {
  4255. // todo: Pass FromSite
  4256. ExecuteNewInstance(SessionUrl);
  4257. }
  4258. else
  4259. {
  4260. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4261. }
  4262. }
  4263. //---------------------------------------------------------------------------
  4264. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4265. {
  4266. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4267. // current working directories become defaults here, what is not right
  4268. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4269. StoredSessions->NewSession(SessionName, SessionData.get());
  4270. // modified only, explicit
  4271. StoredSessions->Save(false, true);
  4272. // encode session name because of slashes in hierarchical sessions
  4273. return EncodeUrlString(SessionName);
  4274. }
  4275. //---------------------------------------------------------------------------
  4276. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4277. {
  4278. if (OpenInNewWindow())
  4279. {
  4280. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4281. }
  4282. else
  4283. {
  4284. // current working directories become defaults here, what is not right
  4285. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4286. TTerminalManager * Manager = TTerminalManager::Instance();
  4287. TTerminal * Terminal = Manager->NewTerminal(SessionData.get());
  4288. Manager->ActiveTerminal = Terminal;
  4289. }
  4290. }
  4291. //---------------------------------------------------------------------------
  4292. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4293. {
  4294. DebugAssert(FQueue != NULL);
  4295. bool Result = FQueue->IsEmpty;
  4296. if (!Result)
  4297. {
  4298. SetFocus();
  4299. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4300. }
  4301. return Result;
  4302. }
  4303. //---------------------------------------------------------------------------
  4304. void __fastcall TCustomScpExplorerForm::CloseSession()
  4305. {
  4306. if (CanCloseQueue())
  4307. {
  4308. TTerminalManager::Instance()->FreeActiveTerminal();
  4309. }
  4310. }
  4311. //---------------------------------------------------------------------------
  4312. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4313. {
  4314. if (OpenInNewWindow())
  4315. {
  4316. // encode session name because of slashes in hierarchical sessions
  4317. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4318. }
  4319. else
  4320. {
  4321. TTerminalManager * Manager = TTerminalManager::Instance();
  4322. TTerminal * Terminal = Manager->NewTerminal(Data);
  4323. Manager->ActiveTerminal = Terminal;
  4324. }
  4325. }
  4326. //---------------------------------------------------------------------------
  4327. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4328. {
  4329. if (OpenInNewWindow())
  4330. {
  4331. ExecuteNewInstance(Name);
  4332. }
  4333. else
  4334. {
  4335. TTerminalManager * Manager = TTerminalManager::Instance();
  4336. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4337. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4338. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4339. }
  4340. }
  4341. //---------------------------------------------------------------------------
  4342. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4343. bool &CanClose)
  4344. {
  4345. if (Terminal != NULL)
  4346. {
  4347. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4348. {
  4349. unsigned int Result;
  4350. TMessageParams Params(mpNeverAskAgainCheck);
  4351. UnicodeString Message;
  4352. int Answers = qaOK | qaCancel;
  4353. if (TTerminalManager::Instance()->Count > 1)
  4354. {
  4355. if (!WinConfiguration->AutoSaveWorkspace)
  4356. {
  4357. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4358. Answers = qaYes | qaNo | qaCancel;
  4359. }
  4360. else
  4361. {
  4362. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4363. }
  4364. }
  4365. else
  4366. {
  4367. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4368. }
  4369. if (WinConfiguration->AutoSaveWorkspace)
  4370. {
  4371. Message =
  4372. FORMAT("%s\n\n%s", (Message,
  4373. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4374. }
  4375. SetFocus();
  4376. Result = MessageDialog(Message, qtConfirmation,
  4377. Answers, HELP_NONE, &Params);
  4378. if (Result == qaNeverAskAgain)
  4379. {
  4380. WinConfiguration->ConfirmClosingSession = false;
  4381. }
  4382. if (Result == qaNo)
  4383. {
  4384. CanClose = SaveWorkspace(true);
  4385. // note that the workspace will be saved redundatly again from FormClose
  4386. }
  4387. else
  4388. {
  4389. CanClose =
  4390. (Result == qaOK) ||
  4391. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4392. (Result == qaNeverAskAgain);
  4393. }
  4394. }
  4395. if (CanClose)
  4396. {
  4397. CanClose = CanCloseQueue();
  4398. }
  4399. }
  4400. if (CanClose)
  4401. {
  4402. CanClose =
  4403. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4404. FEditorManager->CloseExternalFilesWithoutProcess();
  4405. if (CanClose)
  4406. {
  4407. while (CanClose && (FLocalEditors->Count > 0))
  4408. {
  4409. int PrevCount = FLocalEditors->Count;
  4410. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4411. CanClose = (FLocalEditors->Count < PrevCount);
  4412. }
  4413. if (CanClose)
  4414. {
  4415. CanClose = FEditorManager->Empty(true);
  4416. if (!CanClose)
  4417. {
  4418. SetFocus();
  4419. CanClose =
  4420. (MessageDialog(
  4421. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4422. }
  4423. }
  4424. }
  4425. }
  4426. }
  4427. //---------------------------------------------------------------------------
  4428. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4429. {
  4430. TForm * Form = dynamic_cast<TForm *>(Sender);
  4431. DebugAssert(Form != NULL);
  4432. Form->Close();
  4433. }
  4434. //---------------------------------------------------------------------------
  4435. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4436. {
  4437. TForm * Form = dynamic_cast<TForm *>(Sender);
  4438. delete Form;
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4442. {
  4443. while (FLocalEditors->Count > 0)
  4444. {
  4445. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4446. }
  4447. }
  4448. //---------------------------------------------------------------------------
  4449. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4450. TObject *Sender)
  4451. {
  4452. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4453. try
  4454. {
  4455. SetProperties(osRemote, FileList);
  4456. }
  4457. __finally
  4458. {
  4459. delete FileList;
  4460. }
  4461. }
  4462. //---------------------------------------------------------------------------
  4463. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4464. {
  4465. if (value)
  4466. {
  4467. if (Component == fcCustomCommandsBand)
  4468. {
  4469. UpdateCustomCommandsToolbar();
  4470. }
  4471. }
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4475. {
  4476. TControl * Control = GetComponent(Component);
  4477. DebugAssert(Control);
  4478. bool Changed = (Control->Visible != value);
  4479. if (Changed)
  4480. {
  4481. ComponentShowing(Component, value);
  4482. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4483. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4484. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4485. if (value)
  4486. {
  4487. int RemainingHeight = Control->Parent->ClientHeight;
  4488. int RemainingWidth = Control->Parent->ClientWidth;
  4489. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4490. {
  4491. TControl * ChildControl = Control->Parent->Controls[i];
  4492. if (ChildControl->Visible)
  4493. {
  4494. switch (ChildControl->Align)
  4495. {
  4496. case alTop:
  4497. case alBottom:
  4498. RemainingHeight -= ChildControl->Height;
  4499. break;
  4500. case alLeft:
  4501. case alRight:
  4502. RemainingWidth -= ChildControl->Width;
  4503. break;
  4504. }
  4505. }
  4506. }
  4507. int Reserve = ScaleByTextHeight(this, 32);
  4508. // queue in explorer, trees in commander
  4509. if (Control->Height > RemainingHeight - Reserve)
  4510. {
  4511. Control->Height = RemainingHeight / 2;
  4512. }
  4513. if (Control->Width > RemainingWidth - Reserve)
  4514. {
  4515. Control->Width = RemainingWidth / 2;
  4516. }
  4517. }
  4518. Control->Visible = value;
  4519. if (WasFocused && Visible)
  4520. {
  4521. DirView(osCurrent)->SetFocus();
  4522. }
  4523. FixControlsPlacement();
  4524. }
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4528. {
  4529. TControl * Control = GetComponent(Component);
  4530. if (Control == NULL)
  4531. {
  4532. return false;
  4533. }
  4534. else
  4535. {
  4536. return Control->Visible;
  4537. }
  4538. }
  4539. //---------------------------------------------------------------------------
  4540. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4541. {
  4542. if (RemoteDirView->ItemFocused != NULL)
  4543. {
  4544. RemoteDirView->ItemFocused->MakeVisible(false);
  4545. }
  4546. QueueSplitter->Visible = QueuePanel->Visible;
  4547. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  4548. }
  4549. //---------------------------------------------------------------------------
  4550. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4551. {
  4552. switch (Component) {
  4553. case fcStatusBar: return RemoteStatusBar;
  4554. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4555. case fcQueueView: return QueuePanel;
  4556. case fcQueueToolbar: return QueueDock;
  4557. case fcRemoteTree: return RemoteDriveView;
  4558. case fcSessionsTabs: return SessionsPageControl;
  4559. default: return NULL;
  4560. }
  4561. }
  4562. //---------------------------------------------------------------------------
  4563. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4564. TObject *Sender, TListColumn *Column, TPoint &Point)
  4565. {
  4566. DebugAssert(NonVisualDataModule && Column && Sender);
  4567. NonVisualDataModule->ListColumn = Column;
  4568. TPopupMenu * DirViewColumnMenu;
  4569. if (Sender == RemoteDirView)
  4570. {
  4571. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4572. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4573. (Column->Index == uvName);
  4574. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4575. (Column->Index == uvSize);
  4576. }
  4577. else
  4578. {
  4579. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4580. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4581. (Column->Index == dvName);
  4582. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4583. (Column->Index == dvSize);
  4584. }
  4585. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4586. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4587. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4588. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4589. }
  4590. //---------------------------------------------------------------------------
  4591. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4592. TObject *Sender, TListItem *Item, bool &AllowExec)
  4593. {
  4594. DoDirViewExecFile(Sender, Item, AllowExec);
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4598. TListItem * Item, bool & AllowExec)
  4599. {
  4600. DebugAssert(Sender && Item && Configuration);
  4601. DebugAssert(AllowExec);
  4602. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4603. bool Remote = (ADirView == DirView(osRemote));
  4604. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4605. TOperationSide Side = (Remote ? osRemote : osLocal);
  4606. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4607. // on files only (not directories)
  4608. // and only when symlinks are resolved (apply to remote panel only)
  4609. if (!ADirView->ItemIsDirectory(Item) &&
  4610. (ResolvedSymlinks || FForceExecution))
  4611. {
  4612. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4613. !FForceExecution &&
  4614. ResolvedSymlinks)
  4615. {
  4616. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4617. {
  4618. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4619. UnlockWindow();
  4620. try
  4621. {
  4622. ExecuteFileOperation(
  4623. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4624. }
  4625. __finally
  4626. {
  4627. LockWindow();
  4628. }
  4629. AllowExec = false;
  4630. }
  4631. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4632. {
  4633. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4634. {
  4635. ExecuteFile(Side, efDefaultEditor);
  4636. AllowExec = false;
  4637. }
  4638. }
  4639. else
  4640. {
  4641. DebugFail();
  4642. }
  4643. }
  4644. // if we have not done anything special, fall back to default behavior
  4645. if (AllowExec)
  4646. {
  4647. if (Remote && !WinConfiguration->DisableOpenEdit)
  4648. {
  4649. ExecuteFile(osRemote, efShell);
  4650. AllowExec = false;
  4651. }
  4652. }
  4653. }
  4654. }
  4655. //---------------------------------------------------------------------------
  4656. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4657. {
  4658. return ((Side == osRemote) || (Side == osCurrent));
  4659. }
  4660. //---------------------------------------------------------------------------
  4661. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4662. {
  4663. DebugFail();
  4664. }
  4665. //---------------------------------------------------------------------------
  4666. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4667. {
  4668. DebugFail();
  4669. }
  4670. //---------------------------------------------------------------------------
  4671. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4672. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4673. {
  4674. TSynchronizeParamType Params;
  4675. Params.LocalDirectory = LocalDirectory;
  4676. Params.RemoteDirectory = RemoteDirectory;
  4677. int UnusedParams =
  4678. (GUIConfiguration->SynchronizeParams &
  4679. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4680. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4681. Params.Options = GUIConfiguration->SynchronizeOptions;
  4682. bool SaveSettings = false;
  4683. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4684. &DoSynchronizeTooManyDirectories);
  4685. DebugAssert(FSynchronizeController == NULL);
  4686. FSynchronizeController = &Controller;
  4687. bool Result;
  4688. try
  4689. {
  4690. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4691. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4692. int Options =
  4693. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4694. DebugAssert(FOnFeedSynchronizeError == NULL);
  4695. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4696. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4697. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4698. if (Result)
  4699. {
  4700. if (SaveSettings)
  4701. {
  4702. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4703. GUIConfiguration->SynchronizeOptions = Params.Options;
  4704. }
  4705. else
  4706. {
  4707. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4708. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4709. FLAGSET(Params.Options, soSynchronize))
  4710. {
  4711. GUIConfiguration->SynchronizeOptions =
  4712. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4713. soSynchronize;
  4714. }
  4715. }
  4716. LocalDirectory = Params.LocalDirectory;
  4717. RemoteDirectory = Params.RemoteDirectory;
  4718. }
  4719. }
  4720. __finally
  4721. {
  4722. FSynchronizeController = NULL;
  4723. DebugAssert(FOnFeedSynchronizeError == NULL);
  4724. FOnFeedSynchronizeError = NULL;
  4725. }
  4726. return Result;
  4727. }
  4728. //---------------------------------------------------------------------------
  4729. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4730. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4731. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4732. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4733. TSynchronizeOptions * Options, bool Full)
  4734. {
  4735. if (Terminal->Status == ssOpened)
  4736. {
  4737. try
  4738. {
  4739. int PParams = Params.Params;
  4740. if (!Full)
  4741. {
  4742. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  4743. if (FLAGSET(Params.Options, soRecurse))
  4744. {
  4745. PParams |= TTerminal::spSubDirs;
  4746. }
  4747. }
  4748. else
  4749. {
  4750. // if keepuptodate is non-recursive,
  4751. // full sync before has to be non-recursive as well
  4752. if (FLAGCLEAR(Params.Options, soRecurse))
  4753. {
  4754. PParams |= TTerminal::spNoRecurse;
  4755. }
  4756. }
  4757. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4758. PParams, Checklist, Options);
  4759. }
  4760. catch (Exception & E)
  4761. {
  4762. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4763. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4764. {
  4765. // noop, already logged in MoreMessageDialog
  4766. }
  4767. else
  4768. {
  4769. ShowExtendedExceptionEx(Terminal, &E);
  4770. throw;
  4771. }
  4772. }
  4773. }
  4774. }
  4775. //---------------------------------------------------------------------------
  4776. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4777. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4778. const UnicodeString ErrorStr)
  4779. {
  4780. if (!Directory.IsEmpty())
  4781. {
  4782. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4783. }
  4784. else
  4785. {
  4786. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4787. }
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4791. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4792. {
  4793. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4794. {
  4795. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4796. }
  4797. else
  4798. {
  4799. TMessageParams Params(mpNeverAskAgainCheck);
  4800. unsigned int Result = MessageDialog(
  4801. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4802. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4803. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4804. {
  4805. MaxDirectories *= 2;
  4806. if (Result == qaNeverAskAgain)
  4807. {
  4808. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4809. }
  4810. }
  4811. else
  4812. {
  4813. Abort();
  4814. }
  4815. }
  4816. }
  4817. //---------------------------------------------------------------------------
  4818. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4819. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4820. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4821. TSynchronizeOptions * Options)
  4822. {
  4823. DebugAssert(!FAutoOperation);
  4824. void * BatchStorage;
  4825. BatchStart(BatchStorage);
  4826. FAutoOperation = true;
  4827. bool AnyOperation = false;
  4828. TDateTime StartTime = Now();
  4829. TSynchronizeChecklist * AChecklist = NULL;
  4830. try
  4831. {
  4832. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4833. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4834. {
  4835. FSynchronizeProgressForm->Start();
  4836. }
  4837. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4838. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4839. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4840. Options);
  4841. SAFE_DESTROY(FSynchronizeProgressForm);
  4842. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4843. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4844. {
  4845. FSynchronizeProgressForm->Start();
  4846. }
  4847. for (int Index = 0; !AnyOperation && (Index < AChecklist->Count); Index++)
  4848. {
  4849. AnyOperation = AChecklist->Item[Index]->Checked;
  4850. }
  4851. // No need to call if !AnyOperation
  4852. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  4853. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  4854. }
  4855. __finally
  4856. {
  4857. if (Checklist == NULL)
  4858. {
  4859. delete AChecklist;
  4860. }
  4861. else
  4862. {
  4863. *Checklist = AChecklist;
  4864. }
  4865. FAutoOperation = false;
  4866. SAFE_DESTROY(FSynchronizeProgressForm);
  4867. BatchEnd(BatchStorage);
  4868. ReloadLocalDirectory();
  4869. if (AnyOperation)
  4870. {
  4871. OperationComplete(StartTime);
  4872. }
  4873. }
  4874. }
  4875. //---------------------------------------------------------------------------
  4876. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  4877. {
  4878. // can be called from command line
  4879. return Visible &&
  4880. ((DirView(osRemote)->SelCount > 0) ||
  4881. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  4882. }
  4883. //---------------------------------------------------------------------------
  4884. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  4885. {
  4886. LogSynchronizeEvent(Terminal, Message);
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  4890. int Params, TSynchronizeOptions & Options)
  4891. {
  4892. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  4893. {
  4894. Options.Filter = new TStringList();
  4895. Options.Filter->CaseSensitive = false;
  4896. Options.Filter->Duplicates = Types::dupAccept;
  4897. if (DirView(osRemote)->SelCount > 0)
  4898. {
  4899. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  4900. }
  4901. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  4902. {
  4903. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  4904. }
  4905. Options.Filter->Sort();
  4906. }
  4907. }
  4908. //---------------------------------------------------------------------------
  4909. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  4910. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  4911. {
  4912. UnicodeString SessionName = CreateHiddenDuplicateSession();
  4913. UnicodeString AdditionalParams =
  4914. FORMAT(L"%s \"%s\" \"%s\" %d %d %s", (
  4915. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  4916. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options,
  4917. TProgramParams::FormatSwitch(DEFAULTS_SWITCH)));
  4918. TCopyParamType Defaults;
  4919. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  4920. ConfigStorage->AccessMode = smRead;
  4921. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false, false))
  4922. {
  4923. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  4924. }
  4925. ConfigStorage.reset(NULL);
  4926. std::unique_ptr<TStringList> Options(new TStringList());
  4927. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  4928. GUIConfiguration->SaveCopyParam(OptionsStorage.get(), CopyParams, &Defaults);
  4929. if (Options->Count > 0)
  4930. {
  4931. AdditionalParams +=
  4932. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAW_CONFIG_SWITCH), StringsToParams(Options.get())));
  4933. }
  4934. ExecuteNewInstance(SessionName, AdditionalParams);
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  4938. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  4939. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  4940. {
  4941. bool Result;
  4942. int Params = GUIConfiguration->SynchronizeParams;
  4943. bool SaveSettings = false;
  4944. int Options =
  4945. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  4946. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  4947. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4948. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  4949. Result = UseDefaults ||
  4950. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  4951. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  4952. if (Result)
  4953. {
  4954. Configuration->Usage->Inc(L"Synchronizations");
  4955. UpdateCopyParamCounters(CopyParam);
  4956. TSynchronizeOptions SynchronizeOptions;
  4957. GetSynchronizeOptions(Params, SynchronizeOptions);
  4958. if (SaveSettings)
  4959. {
  4960. GUIConfiguration->SynchronizeParams = Params;
  4961. }
  4962. else
  4963. {
  4964. SaveMode = false;
  4965. }
  4966. TDateTime StartTime = Now();
  4967. TSynchronizeChecklist * Checklist = NULL;
  4968. try
  4969. {
  4970. DebugAssert(!FAutoOperation);
  4971. FAutoOperation = true;
  4972. try
  4973. {
  4974. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4975. FSynchronizeProgressForm->Start();
  4976. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4977. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4978. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4979. &SynchronizeOptions);
  4980. }
  4981. __finally
  4982. {
  4983. FAutoOperation = false;
  4984. SAFE_DESTROY(FSynchronizeProgressForm);
  4985. }
  4986. if (Checklist->Count == 0)
  4987. {
  4988. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  4989. MessageDialog(Message, qtInformation, qaOK,
  4990. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  4991. }
  4992. else if (FLAGCLEAR(Params, TTerminal::spPreviewChanges) ||
  4993. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  4994. LocalDirectory, RemoteDirectory, CustomCommandMenu))
  4995. {
  4996. DebugAssert(!FAutoOperation);
  4997. void * BatchStorage;
  4998. BatchStart(BatchStorage);
  4999. FAutoOperation = true;
  5000. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5001. {
  5002. StartTime = Now();
  5003. }
  5004. try
  5005. {
  5006. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  5007. FSynchronizeProgressForm->Start();
  5008. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  5009. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  5010. }
  5011. __finally
  5012. {
  5013. FAutoOperation = false;
  5014. SAFE_DESTROY(FSynchronizeProgressForm);
  5015. BatchEnd(BatchStorage);
  5016. ReloadLocalDirectory();
  5017. }
  5018. }
  5019. }
  5020. __finally
  5021. {
  5022. delete Checklist;
  5023. }
  5024. OperationComplete(StartTime);
  5025. }
  5026. return Result;
  5027. }
  5028. //---------------------------------------------------------------------------
  5029. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5030. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  5031. bool & Continue, bool /*Collect*/)
  5032. {
  5033. DebugAssert(FSynchronizeProgressForm != NULL);
  5034. if (!FSynchronizeProgressForm->Started)
  5035. {
  5036. FSynchronizeProgressForm->Start();
  5037. }
  5038. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  5039. }
  5040. //---------------------------------------------------------------------------
  5041. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5042. {
  5043. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5044. TRemoteFile * File = NULL;
  5045. Terminal->ReadFile(FullFileName, File);
  5046. if (File != NULL)
  5047. {
  5048. std::unique_ptr<TRemoteFile> FileOwner(File);
  5049. TAutoFlag Flag(FStandaloneEditing);
  5050. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5051. Application->ShowMainForm = false;
  5052. Application->Run();
  5053. }
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5057. {
  5058. DebugFail();
  5059. }
  5060. //---------------------------------------------------------------------------
  5061. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5062. {
  5063. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5064. SessionData->Assign(Terminal->SessionData);
  5065. UpdateSessionData(SessionData.get());
  5066. TTerminalManager::Instance()->UpdateSessionCredentials(SessionData.get());
  5067. if (Terminal->SessionData->IsWorkspace)
  5068. {
  5069. // Have to reset the "Workspace/XXX" name which would become user-visible
  5070. // once IsWorkspace is cleared
  5071. SessionData->Name = UnicodeString();
  5072. SessionData->IsWorkspace = false;
  5073. }
  5074. return SessionData.release();
  5075. }
  5076. //---------------------------------------------------------------------------
  5077. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5078. {
  5079. TSessionData * SessionData = CloneCurrentSessionData();
  5080. try
  5081. {
  5082. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5083. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5084. }
  5085. __finally
  5086. {
  5087. delete SessionData;
  5088. }
  5089. }
  5090. //---------------------------------------------------------------------------
  5091. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5092. {
  5093. TTerminalManager * Manager = TTerminalManager::Instance();
  5094. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5095. if (DebugAlwaysTrue(Terminal != NULL))
  5096. {
  5097. // Update (Managed)Terminal->StateData
  5098. UpdateTerminal(Terminal);
  5099. }
  5100. Manager->SaveWorkspace(DataList.get());
  5101. return DataList.release();
  5102. }
  5103. //---------------------------------------------------------------------------
  5104. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5105. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords)
  5106. {
  5107. WinConfiguration->LastWorkspace = Name;
  5108. if (!SavePasswords)
  5109. {
  5110. for (int Index = 0; Index < DataList->Count; Index++)
  5111. {
  5112. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5113. if (SessionData->Link.IsEmpty())
  5114. {
  5115. SessionData->ClearSessionPasswords();
  5116. }
  5117. }
  5118. }
  5119. StoredSessions->NewWorkspace(Name, DataList);
  5120. // modified only, explicit
  5121. StoredSessions->Save(false, true);
  5122. }
  5123. //---------------------------------------------------------------------------
  5124. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5125. {
  5126. return
  5127. DefaultStr(WinConfiguration->LastWorkspace,
  5128. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5129. }
  5130. //---------------------------------------------------------------------------
  5131. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5132. {
  5133. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5134. bool AnyNonStoredSessionWithPassword = false;
  5135. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5136. bool AllNonStoredSessionsAnonymous = true;
  5137. TTerminalManager * Manager = TTerminalManager::Instance();
  5138. for (int Index = 0; Index < DataList->Count; Index++)
  5139. {
  5140. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5141. if (SessionData->Link.IsEmpty())
  5142. {
  5143. if (SessionData->HasAnySessionPassword())
  5144. {
  5145. AnyNonStoredSessionWithPassword = true;
  5146. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5147. {
  5148. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5149. }
  5150. }
  5151. if (!SameText(SessionData->UserName, AnonymousUserName))
  5152. {
  5153. AllNonStoredSessionsAnonymous = false;
  5154. }
  5155. }
  5156. }
  5157. bool SavePasswords;
  5158. bool * PSavePasswords;
  5159. bool NotRecommendedSavingPasswords =
  5160. !CustomWinConfiguration->UseMasterPassword &&
  5161. !AllNonStoredSessionsAnonymous;
  5162. if (Configuration->DisablePasswordStoring ||
  5163. !AnyNonStoredSessionWithPassword)
  5164. {
  5165. PSavePasswords = NULL;
  5166. SavePasswords = false;
  5167. }
  5168. else
  5169. {
  5170. PSavePasswords = &SavePasswords;
  5171. SavePasswords =
  5172. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5173. !NotRecommendedSavingPasswords;
  5174. }
  5175. UnicodeString Name = WorkspaceName();
  5176. bool CreateShortcut = false;
  5177. bool Result =
  5178. DoSaveWorkspaceDialog(
  5179. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5180. EnableAutoSave);
  5181. if (Result)
  5182. {
  5183. DoSaveWorkspace(Name, DataList.get(), SavePasswords);
  5184. if (CreateShortcut)
  5185. {
  5186. TOperationVisualizer Visualizer;
  5187. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5188. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5189. }
  5190. if (EnableAutoSave)
  5191. {
  5192. WinConfiguration->AutoSaveWorkspace = true;
  5193. WinConfiguration->AutoWorkspace = Name;
  5194. if (PSavePasswords != NULL)
  5195. {
  5196. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5197. }
  5198. }
  5199. }
  5200. return Result;
  5201. }
  5202. //---------------------------------------------------------------------------
  5203. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5204. {
  5205. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5206. DebugAssert(ManagedTerminal != NULL);
  5207. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5208. if (WinConfiguration->PreservePanelState)
  5209. {
  5210. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5211. }
  5212. UpdateSessionData(ManagedTerminal->StateData);
  5213. }
  5214. //---------------------------------------------------------------------------
  5215. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5216. {
  5217. // Keep in sync with TSessionData::CopyStateData
  5218. DebugAssert(Data != NULL);
  5219. // cannot use RemoteDirView->Path, because it is empty if connection
  5220. // was already closed
  5221. // also only peek, we may not be connected at all atm
  5222. // so make sure we do not try retrieving current directory from the server
  5223. // (particularly with FTP)
  5224. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5225. if (!ACurrentDirectory.IsEmpty())
  5226. {
  5227. Data->RemoteDirectory = ACurrentDirectory;
  5228. }
  5229. Data->Color = SessionColor;
  5230. }
  5231. //---------------------------------------------------------------------------
  5232. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5233. {
  5234. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5235. DebugAssert(Toolbar != NULL);
  5236. for (int i = 0; i < Toolbar->Items->Count; i++)
  5237. {
  5238. TTBXCustomDropDownItem * DropDownItem;
  5239. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5240. if (DropDownItem != NULL)
  5241. {
  5242. ToolbarItemResize(DropDownItem,
  5243. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5244. Toolbar->NonClientWidth);
  5245. break;
  5246. }
  5247. }
  5248. }
  5249. //---------------------------------------------------------------------------
  5250. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5251. {
  5252. Item->EditWidth = Width;
  5253. }
  5254. //---------------------------------------------------------------------------
  5255. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5256. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5257. {
  5258. for (int i = 0; i < Toolbar->Items->Count; i++)
  5259. {
  5260. TTBXCustomDropDownItem * DropDownItem;
  5261. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5262. if (DropDownItem != NULL)
  5263. {
  5264. ASize.x -= DropDownItem->EditWidth;
  5265. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5266. }
  5267. }
  5268. }
  5269. //---------------------------------------------------------------------------
  5270. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5271. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5272. {
  5273. if (WinConfiguration->DDWarnLackOfTempSpace)
  5274. {
  5275. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5276. if (!ADrive.IsEmpty())
  5277. {
  5278. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5279. DebugAssert(RequiredSpace >= 0);
  5280. __int64 RequiredWithReserve;
  5281. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5282. if (FreeSpace < RequiredWithReserve)
  5283. {
  5284. unsigned int Result;
  5285. TMessageParams Params(mpNeverAskAgainCheck);
  5286. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5287. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5288. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5289. if (Result == qaNeverAskAgain)
  5290. {
  5291. WinConfiguration->DDWarnLackOfTempSpace = false;
  5292. }
  5293. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5294. }
  5295. }
  5296. }
  5297. }
  5298. //---------------------------------------------------------------------------
  5299. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5300. {
  5301. DoOpenDirectoryDialog(odAddBookmark, Side);
  5302. }
  5303. //---------------------------------------------------------------------------
  5304. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5305. {
  5306. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5307. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5308. try
  5309. {
  5310. TCustomDirView * DView = DirView(Side);
  5311. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5312. {
  5313. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5314. }
  5315. }
  5316. catch (...)
  5317. {
  5318. delete VisitedDirectories;
  5319. throw;
  5320. }
  5321. return VisitedDirectories;
  5322. }
  5323. //---------------------------------------------------------------------------
  5324. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5325. TOpenDirectoryMode Mode, TOperationSide Side)
  5326. {
  5327. bool Continue = true;
  5328. if (Mode == odAddBookmark)
  5329. {
  5330. TMessageParams Params(mpNeverAskAgainCheck);
  5331. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5332. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5333. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5334. unsigned int Answer =
  5335. MessageDialog(Message,
  5336. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5337. if (Answer == qaNeverAskAgain)
  5338. {
  5339. Continue = true;
  5340. WinConfiguration->UseSharedBookmarks = true;
  5341. }
  5342. else if (Answer == qaOK)
  5343. {
  5344. Continue = true;
  5345. WinConfiguration->UseSharedBookmarks = false;
  5346. }
  5347. else
  5348. {
  5349. Continue = false;
  5350. }
  5351. }
  5352. if (Continue)
  5353. {
  5354. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5355. try
  5356. {
  5357. UnicodeString Name = DirView(Side)->PathName;
  5358. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5359. // do not allow switching to location profiles,
  5360. // if we are not connected
  5361. HasDirView[osLocal] && (Terminal != NULL)))
  5362. {
  5363. TWindowLock Lock(this);
  5364. DirView(Side)->Path = Name;
  5365. }
  5366. }
  5367. __finally
  5368. {
  5369. delete VisitedDirectories;
  5370. }
  5371. }
  5372. }
  5373. //---------------------------------------------------------------------------
  5374. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5375. {
  5376. DebugAssert(!FTerminal->CommandSessionOpened);
  5377. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5378. }
  5379. //---------------------------------------------------------------------------
  5380. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5381. {
  5382. bool Result = FTerminal->IsCapable[Capability] ||
  5383. FTerminal->CommandSessionOpened;
  5384. if (!Result)
  5385. {
  5386. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5387. if (!GUIConfiguration->ConfirmCommandSession)
  5388. {
  5389. Result = true;
  5390. }
  5391. else
  5392. {
  5393. TMessageParams Params(mpNeverAskAgainCheck);
  5394. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5395. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5396. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5397. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5398. if (Answer == qaNeverAskAgain)
  5399. {
  5400. GUIConfiguration->ConfirmCommandSession = false;
  5401. Result = true;
  5402. }
  5403. else if (Answer == qaOK)
  5404. {
  5405. Result = true;
  5406. }
  5407. }
  5408. if (Result)
  5409. {
  5410. Result = CommandSessionFallback();
  5411. }
  5412. }
  5413. return Result;
  5414. }
  5415. //---------------------------------------------------------------------------
  5416. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5417. {
  5418. if (EnsureCommandSessionFallback(fcAnyCommand))
  5419. {
  5420. DoConsoleDialog(Terminal, Command);
  5421. }
  5422. }
  5423. //---------------------------------------------------------------------------
  5424. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5425. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5426. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5427. {
  5428. if (IsFileControl(DropSourceControl, osRemote) &&
  5429. (FDDExtMapFile != NULL))
  5430. {
  5431. Accept = true;
  5432. }
  5433. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5434. DebugAssert(FDDTargetControl != NULL);
  5435. }
  5436. //---------------------------------------------------------------------------
  5437. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5438. _di_IDataObject DataObj, int KeyState,
  5439. const TPoint & Point, int & Effect, bool & Accept)
  5440. {
  5441. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5442. }
  5443. //---------------------------------------------------------------------------
  5444. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5445. _di_IDataObject DataObj, int KeyState,
  5446. const TPoint & Point, int & Effect, bool & Accept)
  5447. {
  5448. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5449. }
  5450. //---------------------------------------------------------------------------
  5451. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5452. TObject * Sender)
  5453. {
  5454. DebugUsedParam(Sender);
  5455. DebugAssert(FDDTargetControl == Sender);
  5456. FDDTargetControl = NULL;
  5457. }
  5458. //---------------------------------------------------------------------------
  5459. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5460. {
  5461. FileControlDDDragLeave(SessionsPageControl);
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5465. {
  5466. FileControlDDDragLeave(QueueView3);
  5467. }
  5468. //---------------------------------------------------------------------------
  5469. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5470. {
  5471. DebugAssert(GetSide(Side) == osRemote);
  5472. DebugUsedParam(Side);
  5473. bool Edit = false;
  5474. TRemoteFile * File = NULL;
  5475. UnicodeString FileName;
  5476. UnicodeString PointTo;
  5477. bool SymbolicLink = true;
  5478. if (RemoteDirView->ItemFocused)
  5479. {
  5480. DebugAssert(RemoteDirView->ItemFocused->Data);
  5481. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5482. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5483. if (Edit)
  5484. {
  5485. FileName = File->FileName;
  5486. PointTo = File->LinkTo;
  5487. }
  5488. else
  5489. {
  5490. PointTo = File->FileName;
  5491. }
  5492. }
  5493. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5494. Terminal->IsCapable[fcHardLink]))
  5495. {
  5496. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5497. if (Edit)
  5498. {
  5499. DebugAssert(File->FileName == FileName);
  5500. int Params = dfNoRecursive;
  5501. Terminal->ExceptionOnFail = true;
  5502. try
  5503. {
  5504. Terminal->DeleteFile(L"", File, &Params);
  5505. }
  5506. __finally
  5507. {
  5508. Terminal->ExceptionOnFail = false;
  5509. }
  5510. }
  5511. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5512. }
  5513. }
  5514. //---------------------------------------------------------------------------
  5515. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5516. {
  5517. return
  5518. (Terminal != NULL) &&
  5519. ((GetSide(Side) != osRemote) ||
  5520. (Terminal->ResolvingSymlinks &&
  5521. Terminal->IsCapable[fcSymbolicLink]));
  5522. }
  5523. //---------------------------------------------------------------------------
  5524. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5525. {
  5526. return
  5527. (FCurrentSide == osRemote) &&
  5528. (RemoteDirView->ItemFocused != NULL) &&
  5529. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5530. Terminal->SessionData->ResolveSymlinks;
  5531. }
  5532. //---------------------------------------------------------------------------
  5533. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5534. {
  5535. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5536. FForceExecution = true;
  5537. try
  5538. {
  5539. DirView(osCurrent)->ExecuteCurrentFile();
  5540. }
  5541. __finally
  5542. {
  5543. FForceExecution = false;
  5544. }
  5545. }
  5546. //---------------------------------------------------------------------------
  5547. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5548. {
  5549. TEditorData ExternalEditor;
  5550. ExternalEditor.Editor = edExternal;
  5551. bool Remember = false;
  5552. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5553. (GetSide(osCurrent) == osRemote)))
  5554. {
  5555. if (Remember)
  5556. {
  5557. TEditorList * EditorList = new TEditorList;
  5558. try
  5559. {
  5560. *EditorList = *WinConfiguration->EditorList;
  5561. bool Found = false;
  5562. int i = 0;
  5563. while (!Found && (i < EditorList->Count))
  5564. {
  5565. const TEditorPreferences * Editor = EditorList->Editors[i];
  5566. if ((Editor->Data->Editor == edExternal) &&
  5567. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5568. {
  5569. Found = true;
  5570. }
  5571. i++;
  5572. }
  5573. if (!Found)
  5574. {
  5575. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5576. WinConfiguration->EditorList = EditorList;
  5577. }
  5578. }
  5579. __finally
  5580. {
  5581. delete EditorList;
  5582. }
  5583. }
  5584. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5585. }
  5586. }
  5587. //---------------------------------------------------------------------------
  5588. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5589. {
  5590. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5591. if (FFileFindTerminal == Sender)
  5592. {
  5593. FFileFindTerminal = NULL;
  5594. HideFileFindDialog();
  5595. }
  5596. }
  5597. //---------------------------------------------------------------------------
  5598. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5599. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5600. {
  5601. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5602. DebugAssert(Terminal != NULL);
  5603. if (Data->Terminal == Terminal)
  5604. {
  5605. Data->Terminal = NULL;
  5606. }
  5607. }
  5608. //---------------------------------------------------------------------------
  5609. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5610. {
  5611. UpdateControls();
  5612. SessionColor = TColor(0);
  5613. UpdateRemotePathComboBox(false);
  5614. NeedSession(true);
  5615. }
  5616. //---------------------------------------------------------------------------
  5617. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5618. {
  5619. try
  5620. {
  5621. try
  5622. {
  5623. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5624. }
  5625. __finally
  5626. {
  5627. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5628. (!Terminal || !Terminal->Active))
  5629. {
  5630. TerminateApplication();
  5631. }
  5632. }
  5633. }
  5634. catch (EAbort &)
  5635. {
  5636. // swallow
  5637. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  5638. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  5639. }
  5640. }
  5641. //---------------------------------------------------------------------------
  5642. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged(bool Force)
  5643. {
  5644. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  5645. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5646. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  5647. bool ListChanged = Force || (TerminalList->Count + 1 != SessionsPageControl->PageCount);
  5648. if (!ListChanged)
  5649. {
  5650. int Index = 0;
  5651. while (!ListChanged && (Index < TerminalList->Count))
  5652. {
  5653. ListChanged =
  5654. (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != TerminalList->Objects[Index]) ||
  5655. (SessionsPageControl->Pages[Index]->Caption != TerminalList->Strings[Index]);
  5656. Index++;
  5657. }
  5658. }
  5659. if (ListChanged)
  5660. {
  5661. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  5662. try
  5663. {
  5664. FSessionColors->Clear();
  5665. AddFixedSessionImages();
  5666. while (SessionsPageControl->PageCount > 0)
  5667. {
  5668. delete SessionsPageControl->Pages[0];
  5669. }
  5670. for (int Index = 0; Index < TerminalList->Count; Index++)
  5671. {
  5672. TThemeTabSheet * TabSheet = new TThemeTabSheet(SessionsPageControl);
  5673. TabSheet->Caption = TerminalList->Strings[Index];
  5674. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  5675. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  5676. TabSheet->PageControl = SessionsPageControl;
  5677. UpdateSessionTab(TabSheet);
  5678. }
  5679. TTabSheet * TabSheet = new TTabSheet(SessionsPageControl);
  5680. TabSheet->PageControl = SessionsPageControl;
  5681. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  5682. UpdateNewSessionTab();
  5683. }
  5684. __finally
  5685. {
  5686. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  5687. }
  5688. }
  5689. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  5690. }
  5691. //---------------------------------------------------------------------------
  5692. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  5693. {
  5694. DoTerminalListChanged(false);
  5695. }
  5696. //---------------------------------------------------------------------------
  5697. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  5698. {
  5699. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5700. DebugAssert(TabSheet->ImageIndex == 0);
  5701. TabSheet->Caption =
  5702. WinConfiguration->SelectiveToolbarText ?
  5703. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  5704. UnicodeString();
  5705. }
  5706. //---------------------------------------------------------------------------
  5707. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  5708. {
  5709. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  5710. }
  5711. //---------------------------------------------------------------------------
  5712. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  5713. {
  5714. if (DebugAlwaysTrue(TabSheet != NULL))
  5715. {
  5716. TManagedTerminal * ManagedTerminal =
  5717. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  5718. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  5719. {
  5720. TColor Color =
  5721. (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  5722. TabSheet->ImageIndex = AddSessionColor(Color);
  5723. TabSheet->Caption = TTerminalManager::Instance()->GetTerminalTitle(ManagedTerminal, true);
  5724. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  5725. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  5726. {
  5727. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  5728. }
  5729. }
  5730. }
  5731. }
  5732. //---------------------------------------------------------------------------
  5733. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  5734. {
  5735. DebugAssert(SessionsPageControl->ActivePage != NULL);
  5736. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  5737. bool Result = (Terminal != NULL);
  5738. if (Result)
  5739. {
  5740. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5741. }
  5742. else
  5743. {
  5744. try
  5745. {
  5746. NewSession(false);
  5747. }
  5748. __finally
  5749. {
  5750. DoTerminalListChanged(false);
  5751. }
  5752. FSessionsPageControlNewSessionTime = Now();
  5753. }
  5754. return Result;
  5755. }
  5756. //---------------------------------------------------------------------------
  5757. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  5758. {
  5759. SessionTabSwitched();
  5760. }
  5761. //---------------------------------------------------------------------------
  5762. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  5763. {
  5764. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  5765. DebugAssert(TransferList != NULL);
  5766. UnicodeString Name;
  5767. if (TransferList->ItemIndex <= 0)
  5768. {
  5769. Name = L"";
  5770. }
  5771. else
  5772. {
  5773. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  5774. }
  5775. if (FCopyParamAutoSelected.IsEmpty())
  5776. {
  5777. // if previous preset was not autoselected, make new preset the "default"
  5778. FCopyParamDefault = Name;
  5779. }
  5780. GUIConfiguration->CopyParamCurrent = Name;
  5781. }
  5782. //---------------------------------------------------------------------------
  5783. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  5784. {
  5785. // sanity check
  5786. bool ExistingPreset =
  5787. (FTransferListHoverIndex >= 0) &&
  5788. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  5789. DebugAssert(ExistingPreset);
  5790. if (ExistingPreset)
  5791. {
  5792. HDC DC = GetDC(0);
  5793. TCanvas * Canvas = new TCanvas();
  5794. try
  5795. {
  5796. Canvas->Handle = DC;
  5797. Canvas->Font = GetToolbarFont(this);
  5798. UnicodeString Name;
  5799. if (FTransferListHoverIndex == 0)
  5800. {
  5801. Name = L"";
  5802. }
  5803. else
  5804. {
  5805. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  5806. }
  5807. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  5808. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  5809. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  5810. static_cast<TObject*>(GetComponent(fcTransferList)));
  5811. UnicodeString InfoStr =
  5812. GUIConfiguration->CopyParamPreset[Name].
  5813. GetInfoStr(L"; ",
  5814. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  5815. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  5816. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  5817. {
  5818. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  5819. {
  5820. InfoStr.SetLength(InfoStr.Length() - 1);
  5821. }
  5822. InfoStr += Ellipsis;
  5823. }
  5824. // UpdateCaption does not cause invalidation of whole submenu, while
  5825. // setting Caption property does.
  5826. // also it probably does not resize the label, even if necessary
  5827. // (we do not want that anyway)
  5828. TransferLabel->UpdateCaption(InfoStr);
  5829. }
  5830. __finally
  5831. {
  5832. Canvas->Handle = NULL;
  5833. ReleaseDC(0, DC);
  5834. delete Canvas;
  5835. }
  5836. }
  5837. }
  5838. //---------------------------------------------------------------------------
  5839. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  5840. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  5841. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  5842. {
  5843. if (FTransferListHoverIndex != AHoverIndex)
  5844. {
  5845. FTransferListHoverIndex = AHoverIndex;
  5846. UpdateTransferLabel();
  5847. }
  5848. }
  5849. //---------------------------------------------------------------------------
  5850. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  5851. {
  5852. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  5853. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  5854. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  5855. {
  5856. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  5857. {
  5858. OpenDirectory(GetSide(osCurrent));
  5859. Message.Result = 1;
  5860. }
  5861. else
  5862. {
  5863. TForm::Dispatch(&Message);
  5864. }
  5865. }
  5866. else
  5867. {
  5868. TForm::Dispatch(&Message);
  5869. }
  5870. }
  5871. //---------------------------------------------------------------------------
  5872. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  5873. {
  5874. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  5875. if ((FIgnoreNextDialogChar != 0) &&
  5876. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  5877. {
  5878. Message.Result = 1;
  5879. }
  5880. else
  5881. {
  5882. TForm::Dispatch(&Message);
  5883. }
  5884. FIgnoreNextDialogChar = 0;
  5885. }
  5886. //---------------------------------------------------------------------------
  5887. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  5888. {
  5889. // The four low-order bits are used internally by Windows
  5890. unsigned int Cmd = (Message.WParam & 0xFFF0);
  5891. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  5892. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  5893. // 61730 - restore thru double click - undocumented
  5894. // 61490 - maximize thru double click - undocumented
  5895. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  5896. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  5897. {
  5898. SysResizing(Cmd);
  5899. }
  5900. TForm::Dispatch(&Message);
  5901. }
  5902. //---------------------------------------------------------------------------
  5903. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  5904. {
  5905. // We were actually never able to make ENDSESSION_CRITICAL happen.
  5906. // Also there no point returning TRUE as we are not able to
  5907. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  5908. // Hence the process termination might be safer :)
  5909. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  5910. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  5911. {
  5912. Message.Result = FALSE;
  5913. }
  5914. else
  5915. {
  5916. Message.Result = TRUE;
  5917. }
  5918. // Do not call default handling as that triggers OnCloseQuery,
  5919. // where our implementation will popup confirmation dialogs, what we do not want,
  5920. // as per Vista guidelines:
  5921. // https://msdn.microsoft.com/en-us/library/ms700677.aspx
  5922. }
  5923. //---------------------------------------------------------------------------
  5924. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  5925. {
  5926. if (Message.EndSession && IsApplicationMinimized())
  5927. {
  5928. // WORKAROUND
  5929. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  5930. // when it receives WM_ENDSESSION,
  5931. // but that sometimes (particularly when application is minimized) cause crashes.
  5932. // Crash popups message that blocks log off.
  5933. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  5934. // so we call ExitProcess() immediately, not even trying to cleanup.
  5935. // It still causes beep, so there's likely some popup, but it does not block
  5936. // log off.
  5937. ExitProcess(0);
  5938. }
  5939. TForm::Dispatch(&Message);
  5940. }
  5941. #ifdef _DEBUG
  5942. //---------------------------------------------------------------------------
  5943. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  5944. {
  5945. TForm::Dispatch(&Message);
  5946. }
  5947. #endif
  5948. //---------------------------------------------------------------------------
  5949. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  5950. {
  5951. }
  5952. //---------------------------------------------------------------------------
  5953. void __fastcall TCustomScpExplorerForm::DoShow()
  5954. {
  5955. // only now are the controls resized finally, so the size constraints
  5956. // will not conflict with possibly very small window size
  5957. RestoreFormParams();
  5958. FixControlsPlacement();
  5959. if (Position == poDefaultPosOnly)
  5960. {
  5961. CutFormToDesktop(this);
  5962. }
  5963. TForm::DoShow();
  5964. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  5965. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  5966. if (Terminal == NULL)
  5967. {
  5968. StartingDisconnected();
  5969. }
  5970. UpdatePixelsPerInchMainWindowCounter();
  5971. FShowing = true;
  5972. }
  5973. //---------------------------------------------------------------------------
  5974. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  5975. {
  5976. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  5977. }
  5978. //---------------------------------------------------------------------------
  5979. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  5980. {
  5981. DoTerminalListChanged(true);
  5982. }
  5983. //---------------------------------------------------------------------------
  5984. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  5985. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  5986. TNotifyEvent OnBalloonClick, TObject * UserData)
  5987. {
  5988. bool Do;
  5989. UnicodeString Message;
  5990. if (E == NULL)
  5991. {
  5992. Message = Str;
  5993. Do = true;
  5994. }
  5995. else
  5996. {
  5997. Do = ExceptionMessage(E, Message);
  5998. }
  5999. if (Do && WinConfiguration->BalloonNotifications)
  6000. {
  6001. UnicodeString Title;
  6002. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6003. {
  6004. Message = TrimLeft(Message);
  6005. }
  6006. else
  6007. {
  6008. Message = UnformatMessage(Message);
  6009. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6010. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6011. Title = LoadResourceString(Captions[Type]);
  6012. if (Terminal != NULL)
  6013. {
  6014. Title = FORMAT(L"%s - %s",
  6015. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6016. }
  6017. }
  6018. if (Seconds == 0)
  6019. {
  6020. Seconds = WinConfiguration->NotificationsTimeout;
  6021. }
  6022. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6023. }
  6024. }
  6025. //---------------------------------------------------------------------------
  6026. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6027. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6028. UnicodeString HelpKeyword, const TMessageParams * Params,
  6029. TTerminal * Terminal)
  6030. {
  6031. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6032. (FOnFeedSynchronizeError != NULL)) &&
  6033. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6034. {
  6035. if (FOnFeedSynchronizeError != NULL)
  6036. {
  6037. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6038. }
  6039. else
  6040. {
  6041. DebugAssert(FErrorList != NULL);
  6042. TStringList * MoreMessagesCopy = NULL;
  6043. if (MoreMessages)
  6044. {
  6045. MoreMessagesCopy = new TStringList();
  6046. MoreMessagesCopy->Assign(MoreMessages);
  6047. }
  6048. FErrorList->AddObject(Message, MoreMessagesCopy);
  6049. }
  6050. PopupTrayBalloon(Terminal, Message, Type);
  6051. return ContinueAnswer(Answers);
  6052. }
  6053. else
  6054. {
  6055. bool UseBalloon = FTrayIcon->Visible;
  6056. if (UseBalloon)
  6057. {
  6058. PopupTrayBalloon(Terminal, Message, Type);
  6059. }
  6060. unsigned int Result;
  6061. try
  6062. {
  6063. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6064. }
  6065. __finally
  6066. {
  6067. // cancel only balloon we popped up, otherwise we may cancel notification
  6068. // balloon that was there before the message dialog
  6069. // (such as "dd confirmation opt in balloon)
  6070. if (UseBalloon)
  6071. {
  6072. FTrayIcon->CancelBalloon();
  6073. }
  6074. }
  6075. return Result;
  6076. }
  6077. }
  6078. //---------------------------------------------------------------------------
  6079. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6080. TTerminal * Terminal, Exception * E)
  6081. {
  6082. if (FTrayIcon->Visible)
  6083. {
  6084. PopupTrayBalloon(Terminal, L"", qtError, E);
  6085. }
  6086. // particularly prevent opening new session from jump list,
  6087. // while exception is shown
  6088. NonVisualDataModule->StartBusy();
  6089. try
  6090. {
  6091. ShowExtendedExceptionEx(Terminal, E);
  6092. }
  6093. __finally
  6094. {
  6095. NonVisualDataModule->EndBusy();
  6096. FTrayIcon->CancelBalloon();
  6097. }
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6101. {
  6102. // cannot rely on active page being page for active terminal,
  6103. // as it can happen that active page is the "new session" page
  6104. // (e.g. when reconnecting active terminal, while login dialog
  6105. // invoked from "new session" page is modal)
  6106. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6107. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6108. }
  6109. //---------------------------------------------------------------------------
  6110. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6111. TTerminal * Terminal, Exception * E)
  6112. {
  6113. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6114. if (!Terminal->Active)
  6115. {
  6116. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6117. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6118. {
  6119. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6120. }
  6121. }
  6122. }
  6123. //---------------------------------------------------------------------------
  6124. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6125. UnicodeString Message, TQueryType Type,
  6126. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6127. {
  6128. if ((E == NULL) ||
  6129. ExceptionMessage(E, Message))
  6130. {
  6131. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6132. if (Important)
  6133. {
  6134. Seconds *= 5;
  6135. }
  6136. UnicodeString NoteMessage(UnformatMessage(Message));
  6137. if (Terminal != NULL)
  6138. {
  6139. NoteMessage = FORMAT(L"%s: %s",
  6140. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6141. }
  6142. if (WinConfiguration->BalloonNotifications)
  6143. {
  6144. AddNote(NoteMessage);
  6145. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6146. }
  6147. else
  6148. {
  6149. FlashOnBackground();
  6150. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6151. }
  6152. }
  6153. }
  6154. //---------------------------------------------------------------------------
  6155. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6156. {
  6157. RestoreApp();
  6158. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6159. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6160. !NonVisualDataModule->Busy)
  6161. {
  6162. TTerminal * Terminal = TerminalNoteData->Terminal;
  6163. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6164. if (!ComponentVisible[fcQueueView])
  6165. {
  6166. ToggleQueueVisibility();
  6167. GoToQueue();
  6168. }
  6169. }
  6170. }
  6171. //---------------------------------------------------------------------------
  6172. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  6173. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6174. {
  6175. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6176. UnicodeString Message;
  6177. TNotifyEvent OnClick = NULL;
  6178. TObject * UserData = NULL;
  6179. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6180. switch (Event)
  6181. {
  6182. case qeEmptyButMonitored:
  6183. if ((ATerminal != Terminal) || QueueInvisible)
  6184. {
  6185. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6186. OnClick = QueueEmptyNoteClicked;
  6187. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6188. TerminalNoteData->Terminal = ATerminal;
  6189. UserData = TerminalNoteData;
  6190. }
  6191. break;
  6192. case qeEmpty:
  6193. OperationComplete(ManagedTerminal->QueueOperationStart);
  6194. break;
  6195. case qePendingUserAction:
  6196. if ((ATerminal != Terminal) ||
  6197. (QueueInvisible && !IsQueueAutoPopup()))
  6198. {
  6199. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6200. }
  6201. break;
  6202. default:
  6203. DebugFail();
  6204. }
  6205. if (!Message.IsEmpty())
  6206. {
  6207. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6208. }
  6209. }
  6210. //---------------------------------------------------------------------------
  6211. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6212. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6213. {
  6214. if (FDDExtMapFile != NULL)
  6215. {
  6216. CloseHandle(FDDExtMapFile);
  6217. FDDExtMapFile = NULL;
  6218. }
  6219. if (WinConfiguration->DDExtEnabled)
  6220. {
  6221. if (!WinConfiguration->DDExtInstalled)
  6222. {
  6223. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtNotInstalled");
  6224. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_NOT_INSTALLED2), HELP_DRAGEXT_TARGET_NOT_INSTALLED);
  6225. }
  6226. DDExtInitDrag(FileList, Created);
  6227. }
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  6231. bool & Created)
  6232. {
  6233. FDragExtFakeDirectory =
  6234. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6235. if (!ForceDirectories(ApiPath(FDragExtFakeDirectory)))
  6236. {
  6237. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  6238. }
  6239. FileList->AddItem(NULL, FDragExtFakeDirectory);
  6240. Created = true;
  6241. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6242. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6243. {
  6244. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6245. TDragExtCommStruct* CommStruct;
  6246. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6247. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6248. DebugAssert(CommStruct != NULL);
  6249. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6250. CommStruct->Dragging = true;
  6251. wcsncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  6252. LENOF(CommStruct->DropDest));
  6253. NULL_TERMINATE(CommStruct->DropDest);
  6254. UnmapViewOfFile(CommStruct);
  6255. }
  6256. FDDMoveSlipped = false;
  6257. }
  6258. //---------------------------------------------------------------------------
  6259. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6260. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6261. {
  6262. bool Result;
  6263. if (Sender == RemoteDirView)
  6264. {
  6265. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6266. }
  6267. else
  6268. {
  6269. DebugAssert(Sender == RemoteDriveView);
  6270. TStrings * FileList = RemoteDriveView->DragFileList();
  6271. try
  6272. {
  6273. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6274. }
  6275. __finally
  6276. {
  6277. delete FileList;
  6278. }
  6279. }
  6280. if (FDDTargetControl == RemoteDriveView)
  6281. {
  6282. RemoteDriveView->UpdateDropTarget();
  6283. }
  6284. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6285. // or from tree view to dir view.
  6286. // foMove happens when file/dir is dragged from remote tree view outside of
  6287. // application via dragex
  6288. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6289. (DropSourceControl == RemoteDriveView))
  6290. {
  6291. RemoteDriveView->UpdateDropSource();
  6292. }
  6293. return Result;
  6294. }
  6295. //---------------------------------------------------------------------------
  6296. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6297. {
  6298. // This also handles drops of remote files to queue.
  6299. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6300. SAFE_DESTROY(FDDFileList);
  6301. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6302. {
  6303. try
  6304. {
  6305. TDragResult DDResult = (Sender == RemoteDirView) ?
  6306. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6307. // Focus is moved to the target application,
  6308. // but as we are going to present the UI, we need to steal the focus back.
  6309. // This most likely won't work though (windows does not allow application
  6310. // to steal focus most of the time)
  6311. Application->BringToFront();
  6312. // On older version of Windows we never got drMove here, see also comment below.
  6313. // On Windows 10, we get the "move".
  6314. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6315. {
  6316. UnicodeString TargetDirectory;
  6317. TFileOperation Operation;
  6318. // drInvalid may mean drMove, see comment below
  6319. switch (DDResult)
  6320. {
  6321. case drCopy:
  6322. Operation = foCopy;
  6323. break;
  6324. case drMove:
  6325. Operation = foMove;
  6326. break;
  6327. default:
  6328. DebugFail();
  6329. case drInvalid:
  6330. // prefer "copy" for safety
  6331. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6332. break;
  6333. }
  6334. if (FDDMoveSlipped)
  6335. {
  6336. Operation = foMove;
  6337. }
  6338. TTransferOperationParam Param;
  6339. bool Internal;
  6340. bool ForceQueue;
  6341. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, Internal))
  6342. {
  6343. // we get drInvalid both if d&d was intercepted by ddext,
  6344. // and when users drops on no-drop location.
  6345. // we tell the difference by existence of response from ddext,
  6346. // so we ignore absence of response in this case
  6347. if (DDResult != drInvalid)
  6348. {
  6349. // here we know that the extension is installed,
  6350. // as it is checked as soon as drag&drop starts from
  6351. // RemoteFileControlDDCreateDragFileList
  6352. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6353. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6354. }
  6355. }
  6356. else
  6357. {
  6358. // download using ddext
  6359. Param.Temp = false;
  6360. Param.DragDrop = true;
  6361. if (ForceQueue)
  6362. {
  6363. Param.Queue = asOn;
  6364. }
  6365. if (Sender == RemoteDirView)
  6366. {
  6367. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6368. }
  6369. if (RemoteFileControlFileOperation(Sender, Operation,
  6370. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6371. {
  6372. Configuration->Usage->Inc(
  6373. Internal ? L"DownloadsDragDropInternal" : L"DownloadsDragDropExternalExt");
  6374. }
  6375. }
  6376. }
  6377. }
  6378. __finally
  6379. {
  6380. CloseHandle(FDDExtMapFile);
  6381. FDDExtMapFile = NULL;
  6382. RemoveDir(ApiPath(FDragExtFakeDirectory));
  6383. FDragExtFakeDirectory = L"";
  6384. }
  6385. }
  6386. if (FDragDropSshTerminate.get() != NULL)
  6387. {
  6388. FDragDropSshTerminate->Rethrow();
  6389. }
  6390. }
  6391. //---------------------------------------------------------------------------
  6392. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6393. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  6394. {
  6395. HCURSOR SlippedCopyCursor;
  6396. FDDMoveSlipped =
  6397. (FDragMoveCursor != NULL) &&
  6398. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  6399. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  6400. FTerminal->IsCapable[fcRemoteMove]) ||
  6401. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  6402. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  6403. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  6404. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  6405. // Remember drop effect so we know (when user drops files), if we copy or move
  6406. FLastDropEffect = dwEffect;
  6407. }
  6408. //---------------------------------------------------------------------------
  6409. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6410. UnicodeString & Directory, bool & ForceQueue, bool & Internal)
  6411. {
  6412. bool Result;
  6413. if (FDDTargetControl == QueueView3)
  6414. {
  6415. Directory = DefaultDownloadTargetDirectory();
  6416. Result = true;
  6417. Internal = true;
  6418. ForceQueue = true;
  6419. }
  6420. else
  6421. {
  6422. ForceQueue = false;
  6423. Enabled = false;
  6424. try
  6425. {
  6426. int Timer = 0;
  6427. Result = false;
  6428. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6429. {
  6430. {
  6431. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6432. TDragExtCommStruct* CommStruct;
  6433. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6434. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6435. DebugAssert(CommStruct != NULL);
  6436. Result = !CommStruct->Dragging;
  6437. if (Result)
  6438. {
  6439. Directory = ExtractFilePath(CommStruct->DropDest);
  6440. Internal = false;
  6441. }
  6442. UnmapViewOfFile(CommStruct);
  6443. }
  6444. if (!Result)
  6445. {
  6446. Sleep(50);
  6447. Timer += 50;
  6448. Application->ProcessMessages();
  6449. }
  6450. }
  6451. }
  6452. __finally
  6453. {
  6454. Enabled = true;
  6455. }
  6456. }
  6457. return Result;
  6458. }
  6459. //---------------------------------------------------------------------------
  6460. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6461. const UnicodeString TempDir, int SecDelay)
  6462. {
  6463. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6464. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6465. if (FDelayedDeletionTimer == NULL)
  6466. {
  6467. DebugAssert(HandleAllocated());
  6468. FDelayedDeletionTimer = new TTimer(this);
  6469. FDelayedDeletionTimer->Interval = 10000;
  6470. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6471. }
  6472. else
  6473. {
  6474. FDelayedDeletionTimer->Enabled = true;
  6475. }
  6476. }
  6477. //---------------------------------------------------------------------------
  6478. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6479. {
  6480. DebugAssert(FDelayedDeletionList != NULL);
  6481. TDateTime N = Now();
  6482. TDateTime Alert;
  6483. UnicodeString Directory;
  6484. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6485. {
  6486. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6487. if ((N >= Alert) || (Sender == NULL))
  6488. {
  6489. Directory = FDelayedDeletionList->Strings[Index];
  6490. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6491. {
  6492. FDelayedDeletionList->Delete(Index);
  6493. }
  6494. }
  6495. }
  6496. if (FDelayedDeletionList->Count == 0)
  6497. {
  6498. FDelayedDeletionTimer->Enabled = false;
  6499. }
  6500. }
  6501. //---------------------------------------------------------------------------
  6502. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6503. {
  6504. if (IsFileControl(FDDTargetControl, osRemote) ||
  6505. (FDDTargetControl == SessionsPageControl))
  6506. {
  6507. TTerminal * TargetTerminal = NULL;
  6508. TFileOperation Operation = foNone;
  6509. if (FDDTargetControl == SessionsPageControl)
  6510. {
  6511. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6512. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6513. // do not allow dropping on the "+" tab
  6514. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6515. if (TargetTerminal != NULL)
  6516. {
  6517. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6518. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6519. {
  6520. Operation = foRemoteMove;
  6521. }
  6522. else
  6523. {
  6524. Operation = foRemoteCopy;
  6525. }
  6526. }
  6527. }
  6528. else
  6529. {
  6530. // when move from remote side is disabled, we allow copying inside the remote
  6531. // panel, but we interpret is as moving (we also slip in the move cursor)
  6532. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  6533. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  6534. FDDMoveSlipped))
  6535. {
  6536. Operation = foRemoteMove;
  6537. }
  6538. else if (FLastDropEffect == DROPEFFECT_COPY)
  6539. {
  6540. Operation = foRemoteCopy;
  6541. }
  6542. }
  6543. if (Operation != foNone)
  6544. {
  6545. RemoteFileControlFileOperation(DropSourceControl,
  6546. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6547. }
  6548. // abort drag&drop
  6549. Abort();
  6550. }
  6551. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6552. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6553. (FDDTargetControl != QueueView3))
  6554. {
  6555. DebugAssert(!FDragTempDir.IsEmpty());
  6556. TTransferType Type;
  6557. UnicodeString TempDir = FDragTempDir;
  6558. // We clear FDragTempDir before calling
  6559. // just in case it fail (raises exception)
  6560. FDragTempDir = L"";
  6561. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6562. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6563. // empty directory parameter means temp directory -> don't display it!
  6564. UnicodeString TargetDir = L"";
  6565. int Options = 0;
  6566. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6567. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6568. {
  6569. Abort();
  6570. }
  6571. // TargetDir is set when dropped on local file control
  6572. // (this was workaround for legacy dirview event handling, now it should be
  6573. // made prettier)
  6574. if (TargetDir.IsEmpty())
  6575. {
  6576. TargetDir = TempDir;
  6577. if (ForceDirectories(ApiPath(TargetDir)))
  6578. {
  6579. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6580. FPendingTempSpaceWarn = true;
  6581. try
  6582. {
  6583. FDragDropOperation = true;
  6584. int Params = cpTemporary |
  6585. (Type == ttMove ? cpDelete : 0);
  6586. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6587. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6588. }
  6589. __finally
  6590. {
  6591. FDragDropOperation = false;
  6592. FPendingTempSpaceWarn = false;
  6593. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6594. }
  6595. }
  6596. else
  6597. {
  6598. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6599. }
  6600. }
  6601. }
  6602. }
  6603. //---------------------------------------------------------------------------
  6604. void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
  6605. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params)
  6606. {
  6607. void * BatchStorage;
  6608. BatchStart(BatchStorage);
  6609. try
  6610. {
  6611. UpdateCopyParamCounters(*CopyParam);
  6612. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6613. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6614. {
  6615. RemoteDriveView->UpdateDropSource();
  6616. }
  6617. }
  6618. __finally
  6619. {
  6620. BatchEnd(BatchStorage);
  6621. }
  6622. }
  6623. //---------------------------------------------------------------------------
  6624. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6625. {
  6626. public:
  6627. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6628. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  6629. {
  6630. }
  6631. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  6632. {
  6633. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  6634. TDataObjectFilesEx::AllowData(FormatEtc);
  6635. }
  6636. };
  6637. //---------------------------------------------------------------------------
  6638. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  6639. TObject * Sender, TDataObject *& DataObject)
  6640. {
  6641. if (FDDExtMapFile != NULL)
  6642. {
  6643. TFileList * FileList = DragDropFiles(Sender)->FileList;
  6644. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  6645. {
  6646. Abort();
  6647. }
  6648. if (FileList->Count > 0)
  6649. {
  6650. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  6651. if (!FilesObject->IsValid(true, true))
  6652. {
  6653. FilesObject->_Release();
  6654. }
  6655. else
  6656. {
  6657. DataObject = FilesObject;
  6658. }
  6659. }
  6660. }
  6661. }
  6662. //---------------------------------------------------------------------------
  6663. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  6664. {
  6665. DebugFail();
  6666. }
  6667. //---------------------------------------------------------------------------
  6668. void __fastcall TCustomScpExplorerForm::GoToTree()
  6669. {
  6670. ComponentVisible[fcRemoteTree] = true;
  6671. RemoteDriveView->SetFocus();
  6672. }
  6673. //---------------------------------------------------------------------------
  6674. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6675. TPanelExport Export)
  6676. {
  6677. TCustomDirView * DirView = this->DirView(Side);
  6678. std::unique_ptr<TStrings> ExportData(new TStringList());
  6679. switch (Export)
  6680. {
  6681. case pePath:
  6682. ExportData->Add(DirView->PathName);
  6683. break;
  6684. case peFileList:
  6685. case peFullFileList:
  6686. {
  6687. bool FullPath = (Export == peFullFileList);
  6688. DirView->CreateFileList(false, FullPath, ExportData.get());
  6689. for (int Index = 0; Index < ExportData->Count; Index++)
  6690. {
  6691. if (ExportData->Strings[Index].Pos(L" ") > 0)
  6692. {
  6693. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  6694. }
  6695. }
  6696. }
  6697. break;
  6698. default:
  6699. DebugFail();
  6700. }
  6701. return ExportData.release();
  6702. }
  6703. //---------------------------------------------------------------------------
  6704. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6705. TPanelExport Export, TPanelExportDestination Destination)
  6706. {
  6707. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  6708. PanelExportStore(Side, Export, Destination, ExportData.get());
  6709. }
  6710. //---------------------------------------------------------------------------
  6711. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  6712. TPanelExport /*Export*/, TPanelExportDestination Destination,
  6713. TStrings * ExportData)
  6714. {
  6715. if (Destination == pedClipboard)
  6716. {
  6717. TInstantOperationVisualizer Visualizer;
  6718. CopyToClipboard(ExportData);
  6719. }
  6720. else
  6721. {
  6722. DebugFail();
  6723. }
  6724. }
  6725. //---------------------------------------------------------------------------
  6726. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  6727. {
  6728. TCustomDirView * DirView = this->DirView(Side);
  6729. TFileFilter Filter;
  6730. DefaultFileFilter(Filter);
  6731. Filter.Masks = DirView->Mask;
  6732. if (DoFilterMaskDialog(DirView, &Filter))
  6733. {
  6734. DirView->Mask = TFileMasks::NormalizeMask(Filter.Masks);
  6735. Configuration->Usage->Inc(L"Filters");
  6736. }
  6737. }
  6738. //---------------------------------------------------------------------------
  6739. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  6740. {
  6741. return FQueueController->DefaultOperation();
  6742. }
  6743. //---------------------------------------------------------------------------
  6744. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  6745. TQueueOperation Operation, void ** Param)
  6746. {
  6747. switch (Operation)
  6748. {
  6749. case qoPreferences:
  6750. return true;
  6751. case qoGoTo:
  6752. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  6753. case qoOnceEmpty:
  6754. return !FQueueController->Empty;
  6755. default:
  6756. return FQueueController->AllowOperation(Operation, Param);
  6757. }
  6758. }
  6759. //---------------------------------------------------------------------------
  6760. void __fastcall TCustomScpExplorerForm::GoToQueue()
  6761. {
  6762. if (DebugAlwaysTrue(QueueView3->Visible))
  6763. {
  6764. QueueView3->SetFocus();
  6765. }
  6766. }
  6767. //---------------------------------------------------------------------------
  6768. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  6769. TQueueOperation Operation, void * Param)
  6770. {
  6771. if (Operation == qoGoTo)
  6772. {
  6773. GoToQueue();
  6774. }
  6775. else if (Operation == qoPreferences)
  6776. {
  6777. PreferencesDialog(pmQueue);
  6778. }
  6779. else
  6780. {
  6781. FQueueController->ExecuteOperation(Operation, Param);
  6782. }
  6783. }
  6784. //---------------------------------------------------------------------------
  6785. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  6786. {
  6787. return (Queue != NULL) && Queue->Enabled;
  6788. }
  6789. //---------------------------------------------------------------------------
  6790. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  6791. {
  6792. DebugAssert(Queue != NULL);
  6793. if (Queue != NULL)
  6794. {
  6795. Queue->Enabled = !Queue->Enabled;
  6796. }
  6797. }
  6798. //---------------------------------------------------------------------------
  6799. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  6800. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  6801. {
  6802. FQueueActedItem = QueueView3->ItemFocused;
  6803. }
  6804. //---------------------------------------------------------------------------
  6805. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  6806. {
  6807. return TopDock->Height + QueueSplitter->Height;
  6808. }
  6809. //---------------------------------------------------------------------------
  6810. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  6811. TObject * /*Sender*/, int & NewSize, bool & Accept)
  6812. {
  6813. // when queue is hidden by double-clicking splitter, stray attempt to
  6814. // resize the panel with strange value arrives, make sure it is ignored
  6815. if (ComponentVisible[fcQueueView])
  6816. {
  6817. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  6818. RemotePanel->Constraints->MinHeight;
  6819. if (NewSize > HeightLimit)
  6820. {
  6821. NewSize = HeightLimit;
  6822. }
  6823. }
  6824. else
  6825. {
  6826. Accept = false;
  6827. }
  6828. }
  6829. //---------------------------------------------------------------------------
  6830. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  6831. TDragObject *& /*DragObject*/)
  6832. {
  6833. FQueueActedItem = QueueView3->ItemFocused;
  6834. }
  6835. //---------------------------------------------------------------------------
  6836. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  6837. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  6838. {
  6839. Accept = true;
  6840. if (Source == QueueView3)
  6841. {
  6842. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  6843. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  6844. if (Accept)
  6845. {
  6846. TQueueItemProxy * QueueItem;
  6847. TQueueItemProxy * DestQueueItem;
  6848. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6849. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  6850. Accept = (QueueItem != DestQueueItem) &&
  6851. (QueueItem->Status == TQueueItem::qsPending) &&
  6852. (DestQueueItem->Status == TQueueItem::qsPending);
  6853. }
  6854. }
  6855. }
  6856. //---------------------------------------------------------------------------
  6857. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  6858. TObject * /*Source*/, int /*X*/, int /*Y*/)
  6859. {
  6860. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  6861. {
  6862. TQueueItemProxy * QueueItem;
  6863. TQueueItemProxy * DestQueueItem;
  6864. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6865. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  6866. QueueItem->Move(DestQueueItem);
  6867. }
  6868. }
  6869. //---------------------------------------------------------------------------
  6870. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  6871. {
  6872. if ((QueueView3->ItemFocused == NULL) &&
  6873. (QueueView3->Items->Count > 0))
  6874. {
  6875. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  6876. }
  6877. QueueLabelUpdateStatus();
  6878. }
  6879. //---------------------------------------------------------------------------
  6880. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  6881. {
  6882. QueueLabelUpdateStatus();
  6883. }
  6884. //---------------------------------------------------------------------------
  6885. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  6886. {
  6887. QueueLabel->UpdateStatus();
  6888. }
  6889. //---------------------------------------------------------------------------
  6890. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  6891. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  6892. {
  6893. if (Selected)
  6894. {
  6895. NonVisualDataModule->UpdateNonVisibleActions();
  6896. }
  6897. }
  6898. //---------------------------------------------------------------------------
  6899. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  6900. {
  6901. TDragDropFilesEx * Result = NULL;
  6902. if (Sender == SessionsPageControl)
  6903. {
  6904. Result = FSessionsDragDropFilesEx;
  6905. }
  6906. else if (Sender == QueueView3)
  6907. {
  6908. Result = FQueueDragDropFilesEx;
  6909. }
  6910. else
  6911. {
  6912. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  6913. if (DirView != NULL)
  6914. {
  6915. Result = DirView->DragDropFilesEx;
  6916. }
  6917. else
  6918. {
  6919. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  6920. if (DriveView != NULL)
  6921. {
  6922. Result = DriveView->DragDropFilesEx;
  6923. }
  6924. }
  6925. }
  6926. DebugAssert(Result != NULL);
  6927. return Result;
  6928. }
  6929. //---------------------------------------------------------------------------
  6930. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  6931. {
  6932. return (DView->SelCount == DView->FilesCount);
  6933. }
  6934. //---------------------------------------------------------------------------
  6935. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  6936. {
  6937. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  6938. }
  6939. //---------------------------------------------------------------------------
  6940. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  6941. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue)
  6942. {
  6943. TFileOperation Operation;
  6944. switch (Effect)
  6945. {
  6946. case DROPEFFECT_MOVE:
  6947. Operation = foMove;
  6948. break;
  6949. case DROPEFFECT_COPY:
  6950. // occures on WinXP (reported by user)
  6951. default:
  6952. Operation = foCopy;
  6953. break;
  6954. };
  6955. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  6956. // see a comment in TUnixDirView::PerformItemDragDropOperation
  6957. if (DragDropFilesEx->FileList->Count > 0)
  6958. {
  6959. TStrings * FileList = new TStringList();
  6960. try
  6961. {
  6962. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  6963. {
  6964. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  6965. }
  6966. FDragDropOperation = true;
  6967. TTransferOperationParam Param;
  6968. Param.TargetDirectory = TargetPath;
  6969. // upload, no temp dirs
  6970. Param.Temp = false;
  6971. Param.DragDrop = true;
  6972. Param.Options =
  6973. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  6974. if (ForceQueue)
  6975. {
  6976. Param.Queue = asOn;
  6977. }
  6978. if (ExecuteFileOperation(Operation, osLocal, FileList,
  6979. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6980. {
  6981. if (IsFileControl(DropSourceControl, osLocal))
  6982. {
  6983. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  6984. }
  6985. else
  6986. {
  6987. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  6988. }
  6989. }
  6990. }
  6991. __finally
  6992. {
  6993. FDragDropOperation = false;
  6994. delete FileList;
  6995. }
  6996. }
  6997. }
  6998. //---------------------------------------------------------------------------
  6999. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7000. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7001. UnicodeString TargetPath, bool & /*DoOperation*/)
  7002. {
  7003. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false);
  7004. }
  7005. //---------------------------------------------------------------------------
  7006. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7007. TObject * Sender, int grfKeyState, int & dwEffect)
  7008. {
  7009. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7010. if ((dwEffect != DROPEFFECT_None) &&
  7011. IsFileControl(DropSourceControl, osRemote))
  7012. {
  7013. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7014. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7015. (RemoteDirView->DropTarget == NULL))
  7016. {
  7017. dwEffect = DROPEFFECT_None;
  7018. }
  7019. else
  7020. {
  7021. if (dwEffect == DROPEFFECT_Copy)
  7022. {
  7023. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7024. // currently we support copying always (at least via temporary directory);
  7025. // remove associated checks once this all proves stable and working
  7026. bool CopyCapable = true;
  7027. // if we do not support neither of operations, there's no discussion
  7028. if (!MoveCapable && !CopyCapable)
  7029. {
  7030. dwEffect = DROPEFFECT_None;
  7031. }
  7032. // when moving is disabled, we need to keep effect to "copy",
  7033. // which will be later interpretted as move (with slipped-in cursor)
  7034. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  7035. {
  7036. // no-op, keep copy
  7037. }
  7038. else
  7039. {
  7040. // The default effect inside remote panel is move,
  7041. // unless we do not support it, but support copy
  7042. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7043. {
  7044. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  7045. }
  7046. else
  7047. {
  7048. // with ctrl-down, we want copy unless it is not supported
  7049. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  7050. }
  7051. }
  7052. }
  7053. }
  7054. }
  7055. }
  7056. //---------------------------------------------------------------------------
  7057. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7058. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7059. {
  7060. if (FDDTotalSize >= 0)
  7061. {
  7062. if (File->IsDirectory)
  7063. {
  7064. FDDTotalSize = -1;
  7065. }
  7066. else
  7067. {
  7068. FDDTotalSize += File->Size;
  7069. }
  7070. }
  7071. DebugAssert(!FDragTempDir.IsEmpty());
  7072. // TODO: this is quite ineffective
  7073. // TODO: what if invalid character replacement is disabled?
  7074. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7075. UnicodeString TransferFileName;
  7076. if (Sender == RemoteDriveView)
  7077. {
  7078. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7079. }
  7080. else
  7081. {
  7082. TransferFileName = File->FileName;
  7083. }
  7084. FDDFileList->AddObject(TransferFileName, File);
  7085. }
  7086. //---------------------------------------------------------------------------
  7087. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7088. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7089. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7090. {
  7091. // sometimes we do not get DDEnd so the list is not released
  7092. SAFE_DESTROY(FDDFileList);
  7093. FDDFileList = new TStringList();
  7094. FDragTempDir = WinConfiguration->TemporaryDir();
  7095. FDDTotalSize = 0;
  7096. FDragDropSshTerminate.reset(NULL);
  7097. }
  7098. //---------------------------------------------------------------------------
  7099. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7100. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7101. HRESULT & Result)
  7102. {
  7103. if (Result == DRAGDROP_S_DROP)
  7104. {
  7105. try
  7106. {
  7107. GlobalDragImageList->HideDragImage();
  7108. try
  7109. {
  7110. RemoteFileControlDDTargetDrop();
  7111. }
  7112. catch(ESshTerminate & E)
  7113. {
  7114. FDragDropSshTerminate.reset(E.Clone());
  7115. }
  7116. }
  7117. catch (Exception &E)
  7118. {
  7119. // If downloading fails we need to cancel drag&drop, otherwise
  7120. // Explorer shows error
  7121. // But by the way exception probably never reach this point as
  7122. // it's catched on way.
  7123. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7124. Result = DRAGDROP_S_CANCEL;
  7125. ShowExtendedException(Terminal, &E);
  7126. }
  7127. }
  7128. }
  7129. //---------------------------------------------------------------------------
  7130. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7131. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7132. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7133. {
  7134. TFileMasks::TParams MaskParams;
  7135. MaskParams.Size = Size;
  7136. MaskParams.Modification = Modification;
  7137. // this does not re-parse the mask if it is the same as the last time
  7138. FDirViewMatchMask = Masks;
  7139. bool ImplicitMatch;
  7140. Matches =
  7141. // RecurseInclude parameter has no effect as the Path is empty
  7142. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7143. (AllowImplicitMatches || !ImplicitMatch);
  7144. }
  7145. //---------------------------------------------------------------------------
  7146. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7147. TObject * Sender, TListItem * Item, WORD & Indexes)
  7148. {
  7149. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7150. UnicodeString Ext;
  7151. if (DirView == RemoteDirView)
  7152. {
  7153. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7154. }
  7155. else
  7156. {
  7157. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7158. }
  7159. if (SameText(Ext, Configuration->PartialExt))
  7160. {
  7161. Indexes |= oiPartial;
  7162. }
  7163. }
  7164. //---------------------------------------------------------------------------
  7165. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7166. {
  7167. return
  7168. DirViewEnabled(osCurrent) &&
  7169. DirView(osCurrent)->CanPasteFromClipBoard();
  7170. }
  7171. //---------------------------------------------------------------------------
  7172. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7173. {
  7174. bool Result = false;
  7175. if (CanPasteToDirViewFromClipBoard())
  7176. {
  7177. Result = true;
  7178. }
  7179. else
  7180. {
  7181. UnicodeString ClipboardText;
  7182. if (NonEmptyTextFromClipboard(ClipboardText))
  7183. {
  7184. if (StoredSessions->IsUrl(ClipboardText))
  7185. {
  7186. Result = true;
  7187. }
  7188. else
  7189. {
  7190. Result = DirViewEnabled(osCurrent);
  7191. }
  7192. }
  7193. }
  7194. return Result;
  7195. }
  7196. //---------------------------------------------------------------------------
  7197. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7198. {
  7199. if (CanPasteToDirViewFromClipBoard())
  7200. {
  7201. DirView(osCurrent)->PasteFromClipBoard();
  7202. }
  7203. else
  7204. {
  7205. UnicodeString ClipboardText;
  7206. if (NonEmptyTextFromClipboard(ClipboardText))
  7207. {
  7208. if (StoredSessions->IsUrl(ClipboardText))
  7209. {
  7210. NewSession(false, ClipboardText);
  7211. }
  7212. else
  7213. {
  7214. DirView(osCurrent)->Path = ClipboardText;
  7215. }
  7216. }
  7217. }
  7218. }
  7219. //---------------------------------------------------------------------------
  7220. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7221. {
  7222. // TBD
  7223. }
  7224. //---------------------------------------------------------------------------
  7225. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7226. {
  7227. TCustomDirView * ADirView = DirView(Side);
  7228. ADirView->SelectAll(Mode);
  7229. ADirView->SetFocus();
  7230. }
  7231. //---------------------------------------------------------------------------
  7232. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7233. {
  7234. TCustomDirView * ADirView = DirView(Side);
  7235. TFileFilter Filter;
  7236. DefaultFileFilter(Filter);
  7237. if (DoSelectMaskDialog(ADirView, Select, &Filter, Configuration))
  7238. {
  7239. Configuration->Usage->Inc(L"MaskSelections");
  7240. ADirView->SelectFiles(Filter, Select);
  7241. ADirView->SetFocus();
  7242. }
  7243. }
  7244. //---------------------------------------------------------------------------
  7245. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7246. {
  7247. TCustomDirView * ADirView = DirView(Side);
  7248. ADirView->RestoreSelectedNames();
  7249. ADirView->SetFocus();
  7250. }
  7251. //---------------------------------------------------------------------------
  7252. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7253. {
  7254. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7255. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7256. {
  7257. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7258. UnicodeString Ext;
  7259. if (GetSide(osCurrent) == osRemote)
  7260. {
  7261. Ext = UnixExtractFileExt(FileName);
  7262. }
  7263. else
  7264. {
  7265. Ext = ExtractFileExt(FileName);
  7266. }
  7267. if (Ext.IsEmpty())
  7268. {
  7269. Ext = L".";
  7270. }
  7271. TFileFilter Filter;
  7272. Filter.Masks = FORMAT(L"*%s", (Ext));
  7273. Filter.Directories = false;
  7274. CurrentDirView->SelectFiles(Filter, Select);
  7275. }
  7276. }
  7277. //---------------------------------------------------------------------------
  7278. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7279. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7280. {
  7281. UnicodeString Result;
  7282. if ((Side == osRemote) && (Terminal == NULL))
  7283. {
  7284. // noop
  7285. }
  7286. else
  7287. {
  7288. Result =
  7289. FMTLOAD(FILE_INFO_FORMAT,
  7290. (FormatBytes(FileInfo.SelectedSize),
  7291. FormatBytes(FileInfo.FilesSize),
  7292. FormatNumber(FileInfo.SelectedCount),
  7293. FormatNumber(FileInfo.FilesCount)));
  7294. }
  7295. return Result;
  7296. }
  7297. //---------------------------------------------------------------------------
  7298. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7299. TTBXStatusPanel * Panel, TOperationSide Side)
  7300. {
  7301. if (Panel->Index == 1)
  7302. {
  7303. ToggleShowHiddenFiles();
  7304. }
  7305. else if (Panel->Index == 2)
  7306. {
  7307. Filter(Side);
  7308. }
  7309. }
  7310. //---------------------------------------------------------------------------
  7311. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7312. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7313. {
  7314. DebugAssert(!StatusBar->SimplePanel);
  7315. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7316. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7317. }
  7318. //---------------------------------------------------------------------------
  7319. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7320. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7321. {
  7322. DebugAssert(StatusBar->Panels->Count >= 3);
  7323. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7324. if (FileInfo.HiddenCount > 0)
  7325. {
  7326. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7327. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7328. }
  7329. else
  7330. {
  7331. HiddenFilesPanel->ViewPriority = 0;
  7332. // not really necessary, just to cleanup no-longer-valid data
  7333. HiddenFilesPanel->Caption = L"";
  7334. }
  7335. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7336. if (FileInfo.FilteredCount > 0)
  7337. {
  7338. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7339. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7340. }
  7341. else
  7342. {
  7343. FilteredFilesPanel->ViewPriority = 0;
  7344. // not really necessary, just to cleanup no-longer-valid data
  7345. FilteredFilesPanel->Caption = L"";
  7346. }
  7347. }
  7348. //---------------------------------------------------------------------------
  7349. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7350. TObject * /*Sender*/)
  7351. {
  7352. if (RemoteDirView->Enabled)
  7353. {
  7354. RemoteDirView->SetFocus();
  7355. }
  7356. }
  7357. //---------------------------------------------------------------------------
  7358. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7359. {
  7360. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7361. switch (Config.Show)
  7362. {
  7363. case qvShow:
  7364. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7365. {
  7366. Config.Show = qvHide;
  7367. }
  7368. else
  7369. {
  7370. Config.Show = Config.LastHideShow;
  7371. }
  7372. break;
  7373. case qvHideWhenEmpty:
  7374. if (ComponentVisible[fcQueueView])
  7375. {
  7376. Config.Show = qvHide;
  7377. }
  7378. else
  7379. {
  7380. Config.LastHideShow = Config.Show;
  7381. Config.Show = qvShow;
  7382. }
  7383. break;
  7384. case qvHide:
  7385. Config.LastHideShow = Config.Show;
  7386. Config.Show = qvShow;
  7387. break;
  7388. }
  7389. WinConfiguration->QueueView = Config;
  7390. }
  7391. //---------------------------------------------------------------------------
  7392. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7393. {
  7394. UnicodeString Result;
  7395. if (FTerminal != NULL)
  7396. {
  7397. switch (WinConfiguration->PathInCaption)
  7398. {
  7399. case picShort:
  7400. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  7401. break;
  7402. case picFull:
  7403. Result = FTerminal->CurrentDirectory;
  7404. break;
  7405. }
  7406. }
  7407. return Result;
  7408. }
  7409. //---------------------------------------------------------------------------
  7410. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7411. {
  7412. TTerminalManager::Instance()->UpdateAppTitle();
  7413. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7414. // background to gray on Windows 7 (works on Windows 10).
  7415. // See also EnableControl
  7416. if (Showing)
  7417. {
  7418. bool HasTerminal = (Terminal != NULL);
  7419. if (HasTerminal)
  7420. {
  7421. // Update path when it changes
  7422. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  7423. {
  7424. UpdateSessionTab(SessionsPageControl->ActivePage);
  7425. }
  7426. if (!RemoteDirView->Enabled)
  7427. {
  7428. RemoteDirView->Enabled = true;
  7429. if (FRemoteDirViewWasFocused)
  7430. {
  7431. ActiveControl = RemoteDirView;
  7432. }
  7433. }
  7434. RemoteDriveView->Enabled = true;
  7435. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  7436. RemoteDriveView->Color = RemoteDirView->Color;
  7437. }
  7438. else
  7439. {
  7440. if (RemoteDirView->Enabled)
  7441. {
  7442. // This is first called when the form is being constructed
  7443. // (not anymore due to Showing test above)
  7444. // but the false is overriden in the constructor later.
  7445. // An even later in TScpCommanderForm::DoShow()
  7446. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7447. EnableControl(RemoteDirView, false);
  7448. }
  7449. EnableControl(RemoteDriveView, false);
  7450. }
  7451. EnableControl(QueueView3, HasTerminal);
  7452. QueueLabelUpdateStatus();
  7453. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7454. }
  7455. }
  7456. //---------------------------------------------------------------------------
  7457. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7458. {
  7459. UpdateControls();
  7460. }
  7461. //---------------------------------------------------------------------------
  7462. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7463. TObject * Sender)
  7464. {
  7465. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7466. DebugAssert(DirView != NULL);
  7467. DoDirViewLoaded(DirView);
  7468. TransferPresetAutoSelect();
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7472. {
  7473. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7474. // first run after installation
  7475. if (double(Updates.LastCheck) == 0)
  7476. {
  7477. // make sure next time there will be an update (if enabled)
  7478. Updates.LastCheck = TDateTime(1);
  7479. WinConfiguration->Updates = Updates;
  7480. }
  7481. else if ((double(Updates.Period) > 0) &&
  7482. (Now() - Updates.LastCheck >= Updates.Period))
  7483. {
  7484. StartUpdateThread(UpdatesChecked);
  7485. }
  7486. }
  7487. //---------------------------------------------------------------------------
  7488. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7489. {
  7490. UnicodeString Message;
  7491. bool New;
  7492. TQueryType Type;
  7493. GetUpdatesMessage(Message, New, Type, false);
  7494. if (!Message.IsEmpty())
  7495. {
  7496. if (New)
  7497. {
  7498. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7499. }
  7500. if (!New && (Type != qtWarning))
  7501. {
  7502. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7503. }
  7504. else
  7505. {
  7506. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7507. }
  7508. if (New)
  7509. {
  7510. Configuration->Usage->Inc(L"UpdateNotifications");
  7511. }
  7512. }
  7513. }
  7514. //---------------------------------------------------------------------------
  7515. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7516. {
  7517. RestoreApp();
  7518. bool CanDisplay = !NonVisualDataModule->Busy;
  7519. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7520. {
  7521. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7522. }
  7523. if (CanDisplay)
  7524. {
  7525. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7526. CheckForUpdates(true);
  7527. }
  7528. else
  7529. {
  7530. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7531. }
  7532. }
  7533. //---------------------------------------------------------------------------
  7534. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7535. TCopyParamRuleData & Data)
  7536. {
  7537. DebugAssert(Terminal != NULL);
  7538. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7539. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7540. Data.RemoteDirectory = RemoteDirView->PathName;
  7541. }
  7542. //---------------------------------------------------------------------------
  7543. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7544. {
  7545. // Terminal can be null when we are changing local directory implicitly,
  7546. // because it has been deleted, while no session is connected
  7547. // (Login dialog is open)
  7548. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7549. {
  7550. TCopyParamRuleData Data;
  7551. GetTransferPresetAutoSelectData(Data);
  7552. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7553. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7554. if (CopyParamIndex < 0)
  7555. {
  7556. // there is no preset that matches autoselection
  7557. // set preset that we consider "default"
  7558. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7559. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7560. }
  7561. else
  7562. {
  7563. // there is preset matching autoselection
  7564. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7565. if (CopyParamName == FCopyParamAutoSelected)
  7566. {
  7567. // autoselected the same preset as the last time
  7568. // make no change (i.e. preserve custom user preset, if any)
  7569. }
  7570. else
  7571. {
  7572. // autoselected the different preset then the last time (or there
  7573. // was default preset set)
  7574. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7575. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7576. }
  7577. }
  7578. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7579. {
  7580. if (CopyParamIndex >= 0)
  7581. {
  7582. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7583. }
  7584. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7585. try
  7586. {
  7587. int Fmt =
  7588. (CopyParamIndex < 0) ?
  7589. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7590. COPY_PARAM_AUTOSELECTED;
  7591. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7592. Data->Message = MainInstructions(Message);
  7593. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7594. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7595. CopyParamAttrs);
  7596. if (CopyParamIndex >= 0)
  7597. {
  7598. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7599. Info = FORMAT(L"%s\n \n%s", (Info,
  7600. FMTLOAD(COPY_PARAM_RULE,
  7601. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  7602. }
  7603. Data->Message += L"\n\n" + Info;
  7604. if (WinConfiguration->CopyParamAutoSelectNotice)
  7605. {
  7606. TransferPresetNoteMessage(Data, true);
  7607. }
  7608. else
  7609. {
  7610. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  7611. Data = NULL; // ownership passed
  7612. }
  7613. }
  7614. __finally
  7615. {
  7616. delete Data;
  7617. }
  7618. }
  7619. }
  7620. }
  7621. //---------------------------------------------------------------------------
  7622. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  7623. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  7624. {
  7625. DebugAssert(NoteData != NULL);
  7626. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  7627. TQueryButtonAlias Aliases[1];
  7628. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  7629. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  7630. Params.Aliases = Aliases;
  7631. Params.AliasesCount = LENOF(Aliases);
  7632. unsigned int Result =
  7633. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  7634. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  7635. switch (Result)
  7636. {
  7637. case qaNeverAskAgain:
  7638. DebugAssert(AllowNeverAskAgain);
  7639. WinConfiguration->CopyParamAutoSelectNotice = false;
  7640. break;
  7641. case qaIgnore:
  7642. PreferencesDialog(pmPresets);
  7643. break;
  7644. }
  7645. }
  7646. //---------------------------------------------------------------------------
  7647. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  7648. {
  7649. // as of now useless, as this is used for notes only, never for balloons, ...
  7650. RestoreApp();
  7651. // .. and we should never be busy here
  7652. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  7653. {
  7654. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  7655. }
  7656. }
  7657. //---------------------------------------------------------------------------
  7658. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  7659. TPreferencesMode APreferencesMode)
  7660. {
  7661. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  7662. TCopyParamRuleData Data;
  7663. if (Terminal != NULL)
  7664. {
  7665. PreferencesData.reset(new TPreferencesDialogData());
  7666. GetTransferPresetAutoSelectData(Data);
  7667. PreferencesData->CopyParamRuleData = &Data;
  7668. }
  7669. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  7670. }
  7671. //---------------------------------------------------------------------------
  7672. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  7673. const TCustomCommandType & Command)
  7674. {
  7675. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  7676. {
  7677. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  7678. }
  7679. }
  7680. //---------------------------------------------------------------------------
  7681. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  7682. {
  7683. bool RemoteAllowed = CustomCommandRemoteAllowed();
  7684. TCustomCommandType Command;
  7685. // make sure we use local custom command when remote are not supported
  7686. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  7687. {
  7688. Command = FLastCustomCommand;
  7689. }
  7690. else
  7691. {
  7692. Command.Params = Command.Params | ccLocal;
  7693. }
  7694. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  7695. FEditingFocusedAdHocCommand = OnFocused;
  7696. bool LocalSide = (FCurrentSide == osLocal);
  7697. int Options =
  7698. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  7699. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  7700. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  7701. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  7702. {
  7703. FLastCustomCommand = Command;
  7704. UpdateCustomCommandsToolbar();
  7705. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  7706. }
  7707. }
  7708. //---------------------------------------------------------------------------
  7709. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  7710. {
  7711. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  7712. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7713. DebugAssert(State > 0);
  7714. if (State <= 0)
  7715. {
  7716. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  7717. }
  7718. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  7719. }
  7720. //---------------------------------------------------------------------------
  7721. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  7722. TCustomCommandType & Command, int & State)
  7723. {
  7724. bool Result = !FLastCustomCommand.Command.IsEmpty();
  7725. if (Result)
  7726. {
  7727. Command = FLastCustomCommand;
  7728. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7729. }
  7730. return Result;
  7731. }
  7732. //---------------------------------------------------------------------------
  7733. void __fastcall TCustomScpExplorerForm::BeforeAction()
  7734. {
  7735. if (RemoteDirView->ItemFocused != NULL)
  7736. {
  7737. RemoteDirView->ItemFocused->CancelEdit();
  7738. }
  7739. }
  7740. //---------------------------------------------------------------------------
  7741. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  7742. {
  7743. DebugAssert(ComponentVisible[Component]);
  7744. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  7745. }
  7746. //---------------------------------------------------------------------------
  7747. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  7748. {
  7749. // when queue panel is resized here directly, the status bar is stretched
  7750. // over whole space the panel occupied
  7751. PostComponentHide(fcQueueView);
  7752. }
  7753. //---------------------------------------------------------------------------
  7754. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  7755. {
  7756. TMessage * M = static_cast<TMessage*>(Message);
  7757. switch (M->Msg)
  7758. {
  7759. case CM_DIALOGCHAR:
  7760. CMDialogChar(*M);
  7761. break;
  7762. case WM_APPCOMMAND:
  7763. WMAppCommand(*M);
  7764. break;
  7765. case WM_SYSCOMMAND:
  7766. WMSysCommand(*M);
  7767. break;
  7768. case WM_QUERYENDSESSION:
  7769. WMQueryEndSession(*M);
  7770. break;
  7771. case WM_ENDSESSION:
  7772. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  7773. break;
  7774. #ifdef _DEBUG
  7775. case WM_WINDOWPOSCHANGED:
  7776. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  7777. break;
  7778. case CM_CUSTOMSTYLECHANGED:
  7779. TForm::Dispatch(Message);
  7780. break;
  7781. #endif
  7782. case WM_COMPONENT_HIDE:
  7783. {
  7784. Byte Component = static_cast<Byte>(M->WParam);
  7785. // sanity check
  7786. if (ComponentVisible[Component])
  7787. {
  7788. // special treatment
  7789. if (Component == fcQueueView)
  7790. {
  7791. ToggleQueueVisibility();
  7792. DebugAssert(!ComponentVisible[fcQueueView]);
  7793. }
  7794. else
  7795. {
  7796. ComponentVisible[Component] = false;
  7797. }
  7798. }
  7799. }
  7800. break;
  7801. case WM_COPYDATA:
  7802. WMCopyData(*M);
  7803. break;
  7804. case WM_MANAGES_CAPTION:
  7805. // caption managed in TTerminalManager::UpdateAppTitle()
  7806. M->Result = 1;
  7807. break;
  7808. case WM_WANTS_MOUSEWHEEL:
  7809. M->Result = 1;
  7810. break;
  7811. case CM_SHOWINGCHANGED:
  7812. CMShowingChanged(*M);
  7813. break;
  7814. case WM_CLOSE:
  7815. WMClose(*M);
  7816. break;
  7817. case WM_DPICHANGED:
  7818. WMDpiChanged(*M);
  7819. break;
  7820. case CM_DPICHANGED:
  7821. CMDpiChanged(*M);
  7822. break;
  7823. default:
  7824. TForm::Dispatch(Message);
  7825. break;
  7826. }
  7827. }
  7828. //---------------------------------------------------------------------------
  7829. void __fastcall TCustomScpExplorerForm::UpdateImages()
  7830. {
  7831. // noop
  7832. }
  7833. //---------------------------------------------------------------------------
  7834. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  7835. {
  7836. TForm::Dispatch(&Message);
  7837. // regenerate session images
  7838. DoTerminalListChanged(true);
  7839. UpdateImages();
  7840. }
  7841. //---------------------------------------------------------------------------
  7842. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  7843. {
  7844. TForm::Dispatch(&Message);
  7845. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  7846. UpdatePixelsPerInchMainWindowCounter();
  7847. }
  7848. //---------------------------------------------------------------------------
  7849. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  7850. {
  7851. // Cannot close window while we are busy.
  7852. // We cannot test this in FormCloseQuery as that is called also from
  7853. // Close(), which is called by CloseApplicationAction. So we can be busy
  7854. // there already even, when it is legitimate to close the application.
  7855. // Possibly a better place to handle this would be WMSysCommand.
  7856. if (NonVisualDataModule->Busy)
  7857. {
  7858. Message.Result = 1;
  7859. }
  7860. else
  7861. {
  7862. TForm::Dispatch(&Message);
  7863. }
  7864. }
  7865. //---------------------------------------------------------------------------
  7866. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  7867. {
  7868. TForm::Dispatch(&Message);
  7869. if (Showing && (Terminal == NULL))
  7870. {
  7871. // When we are starting minimized (i.e. from an installer),
  7872. // postpone showing Login dialog until we get restored.
  7873. // Otherwise the Login dialog (and Authentication window) show restored
  7874. // over invidible (minimized) main window.
  7875. if (WindowState == wsMinimized)
  7876. {
  7877. FNeedSession = true;
  7878. }
  7879. else
  7880. {
  7881. // This happens before application ever goes idle, so the toolbars would
  7882. // stay enabled (initial state) until the Login dialog is dismissed.
  7883. UpdateActions();
  7884. NonVisualDataModule->StartBusy();
  7885. try
  7886. {
  7887. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  7888. // otherwise the dialog does not receive focus.
  7889. // With Commander interface the ProcessMessages is called already
  7890. // by TDriveView, but with Explorer interface, we need to call it explicily
  7891. Application->ProcessMessages();
  7892. // do not reload sessions, they have been loaded just now (optimization)
  7893. NeedSession(false);
  7894. }
  7895. __finally
  7896. {
  7897. NonVisualDataModule->EndBusy();
  7898. }
  7899. }
  7900. }
  7901. }
  7902. //---------------------------------------------------------------------------
  7903. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  7904. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  7905. int & MaxHeight)
  7906. {
  7907. // workaround for bug in TWinControl.CalcConstraints
  7908. // Check for empty rect (restore from iconic state) is done there only after
  7909. // call to AdjustClientRect, which enlarges the rect (for forms).
  7910. TRect R = GetClientRect();
  7911. // when restoring from iconic state, place no restrictions
  7912. if (IsRectEmpty(R))
  7913. {
  7914. MinWidth = 0;
  7915. MinHeight = 0;
  7916. MaxWidth = 32000;
  7917. MaxHeight = 32000;
  7918. }
  7919. }
  7920. //---------------------------------------------------------------------------
  7921. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  7922. TSpaceAvailable & ASpaceAvailable, bool & Close)
  7923. {
  7924. // terminal can be already closed (e.g. dropped connection)
  7925. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  7926. {
  7927. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  7928. try
  7929. {
  7930. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  7931. }
  7932. catch(...)
  7933. {
  7934. if (!Terminal->Active)
  7935. {
  7936. Close = true;
  7937. }
  7938. throw;
  7939. }
  7940. }
  7941. }
  7942. //---------------------------------------------------------------------------
  7943. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  7944. {
  7945. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  7946. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  7947. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  7948. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  7949. {
  7950. OnGetSpaceAvailable = GetSpaceAvailable;
  7951. }
  7952. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  7953. OnGetSpaceAvailable);
  7954. }
  7955. //---------------------------------------------------------------------------
  7956. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  7957. {
  7958. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  7959. Terminal->FillSessionDataForCode(Data.get());
  7960. return Data.release();
  7961. }
  7962. //---------------------------------------------------------------------------
  7963. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  7964. {
  7965. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  7966. DoGenerateUrlDialog(Data.get(), Paths);
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  7970. {
  7971. GenerateUrl(NULL);
  7972. }
  7973. //---------------------------------------------------------------------------
  7974. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  7975. {
  7976. std::unique_ptr<TStrings> Paths(new TStringList());
  7977. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  7978. GenerateUrl(Paths.get());
  7979. }
  7980. //---------------------------------------------------------------------------
  7981. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  7982. {
  7983. if (value != FSessionColor)
  7984. {
  7985. FSessionColor = value;
  7986. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  7987. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  7988. static_cast<TObject *>(GetComponent(fcColorMenu)));
  7989. DebugAssert(ColorItem != NULL);
  7990. ColorItem->Color = C;
  7991. NonVisualDataModule->ColorMenuItem->Color = C;
  7992. // Is null when called from LastTerminalClosed
  7993. if (Terminal != NULL)
  7994. {
  7995. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  7996. }
  7997. UpdateControls();
  7998. }
  7999. }
  8000. //---------------------------------------------------------------------------
  8001. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8002. {
  8003. bool Result = FNoteTimer->Enabled;
  8004. if (Result)
  8005. {
  8006. // cannot cancel note too early
  8007. bool NotEarly =
  8008. (Now() - FNoteShown >
  8009. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8010. if (Force || NotEarly)
  8011. {
  8012. FNoteTimer->Enabled = false;
  8013. FNote = L"";
  8014. SAFE_DESTROY(FNoteData);
  8015. FOnNoteClick = NULL;
  8016. FNoteHints = FNotes->Text;
  8017. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8018. UpdateStatusBar();
  8019. }
  8020. }
  8021. return Result;
  8022. }
  8023. //---------------------------------------------------------------------------
  8024. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8025. {
  8026. DebugAssert(FNoteTimer->Enabled);
  8027. CancelNote(true);
  8028. }
  8029. //---------------------------------------------------------------------------
  8030. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8031. {
  8032. int P = Note.Pos(L"\n");
  8033. if (P > 0)
  8034. {
  8035. Note.SetLength(P - 1);
  8036. }
  8037. FNotes->Add(FORMAT(L"[%s] %s",
  8038. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8039. while (FNotes->Count > 10)
  8040. {
  8041. FNotes->Delete(0);
  8042. }
  8043. if (UpdateNow)
  8044. {
  8045. FNoteHints = FNotes->Text;
  8046. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8047. UpdateStatusBar();
  8048. }
  8049. }
  8050. //---------------------------------------------------------------------------
  8051. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8052. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8053. {
  8054. int P = Note.Pos(L"\n");
  8055. if (P > 0)
  8056. {
  8057. Note.SetLength(P - 1);
  8058. }
  8059. FNoteHints = FNotes->Text;
  8060. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8061. FNote = Note;
  8062. SAFE_DESTROY(FNoteData);
  8063. FNoteData = NoteData;
  8064. FOnNoteClick = OnNoteClick;
  8065. AddNote(Note, false);
  8066. UpdateStatusBar();
  8067. FNoteShown = Now();
  8068. FNoteTimer->Enabled = false;
  8069. if (Seconds == 0)
  8070. {
  8071. Seconds = WinConfiguration->NotificationsTimeout;
  8072. }
  8073. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8074. FNoteTimer->Enabled = true;
  8075. }
  8076. //---------------------------------------------------------------------------
  8077. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8078. {
  8079. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8080. }
  8081. //---------------------------------------------------------------------------
  8082. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8083. {
  8084. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8085. {
  8086. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8087. }
  8088. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8089. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8090. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8091. 0, NULL, NULL);
  8092. }
  8093. //---------------------------------------------------------------------------
  8094. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8095. {
  8096. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8097. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8098. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8099. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8100. }
  8101. //---------------------------------------------------------------------------
  8102. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8103. {
  8104. WinConfiguration->FormatSizeBytes = Style;
  8105. }
  8106. //---------------------------------------------------------------------------
  8107. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8108. {
  8109. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8110. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8111. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8112. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8113. }
  8114. //---------------------------------------------------------------------------
  8115. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8116. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8117. {
  8118. if (Panel->Index == 0)
  8119. {
  8120. if (FOnNoteClick != NULL)
  8121. {
  8122. // prevent the user data from being freed by possible call
  8123. // to CancelNote or PostNote during call to OnNoteClick
  8124. std::unique_ptr<TObject> NoteData(FNoteData);
  8125. TNotifyEvent OnNoteClick = FOnNoteClick;
  8126. FNoteData = NULL;
  8127. // need to cancel the note as we are going to delete its user data
  8128. CancelNote(true);
  8129. OnNoteClick(NoteData.get());
  8130. }
  8131. }
  8132. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8133. {
  8134. FileSystemInfo();
  8135. }
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8139. {
  8140. // workaround:
  8141. // 1) for unknown reason, disabling window, while minimized,
  8142. // prevents it from restoring, even if it was enabled again meanwhile
  8143. // 2) when disabling the main window, while another has focus
  8144. // minimize is no longer possible
  8145. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8146. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8147. // Shouldn't we use IsApplicationMinimized() here?
  8148. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8149. {
  8150. Enabled = false;
  8151. }
  8152. FLockLevel++;
  8153. }
  8154. //---------------------------------------------------------------------------
  8155. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8156. {
  8157. DebugAssert(FLockLevel > 0);
  8158. FLockLevel--;
  8159. if (FLockLevel == 0)
  8160. {
  8161. DebugAssert(FLockSuspendLevel == 0);
  8162. Enabled = true;
  8163. }
  8164. }
  8165. //---------------------------------------------------------------------------
  8166. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8167. {
  8168. // We need to make sure that window is enabled when the last modal window closes
  8169. // otherwise focus is not restored correctly.
  8170. // So we re-enable the window when modal window opens and
  8171. // disable it back after is closes
  8172. if (FLockLevel > 0)
  8173. {
  8174. // while we have nesting counter, we know that we never be called
  8175. // recursivelly as Application->OnModalBegin is called only
  8176. // for the top-level modal window
  8177. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8178. {
  8179. // won't be disabled when conditions in LockWindow() were not satisfied
  8180. FDisabledOnLockSuspend = !Enabled;
  8181. // When minimized to tray (or actually when set to SW_HIDE),
  8182. // setting Enabled makes the window focusable even when there's
  8183. // modal window over it
  8184. if (!FTrayIcon->Visible)
  8185. {
  8186. Enabled = true;
  8187. }
  8188. }
  8189. FLockSuspendLevel++;
  8190. }
  8191. }
  8192. //---------------------------------------------------------------------------
  8193. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8194. {
  8195. if (FLockSuspendLevel > 0)
  8196. {
  8197. DebugAssert(FLockLevel > 0);
  8198. FLockSuspendLevel--;
  8199. // see comment in SuspendWindowLock
  8200. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8201. {
  8202. // Note that window can be enabled here, when we were minized to tray when
  8203. // was SuspendWindowLock() called.
  8204. // We should possibly do the same check as in LockWindow(),
  8205. // if it is ever possible that the consitions change between
  8206. // SuspendWindowLock() and ResumeWindowLock()
  8207. Enabled = !FDisabledOnLockSuspend;
  8208. }
  8209. }
  8210. }
  8211. //---------------------------------------------------------------------------
  8212. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8213. {
  8214. if (!TextOnly)
  8215. {
  8216. TTBXComboBoxItem * RemotePathComboBox =
  8217. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8218. TStrings * Items = RemotePathComboBox->Strings;
  8219. Items->BeginUpdate();
  8220. try
  8221. {
  8222. Items->Clear();
  8223. if (Terminal != NULL)
  8224. {
  8225. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8226. while (!IsUnixRootPath(APath))
  8227. {
  8228. int P = APath.LastDelimiter(L'/');
  8229. DebugAssert(P >= 0);
  8230. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8231. APath.SetLength(P - 1);
  8232. }
  8233. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8234. }
  8235. }
  8236. __finally
  8237. {
  8238. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8239. // Setting ItemIndex to -1 does not reset its text
  8240. if (Items->Count == 0)
  8241. {
  8242. RemotePathComboBox->Text = L"";
  8243. }
  8244. Items->EndUpdate();
  8245. }
  8246. }
  8247. }
  8248. //---------------------------------------------------------------------------
  8249. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8250. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8251. int & ImageIndex)
  8252. {
  8253. if (AIndex < 0)
  8254. {
  8255. AIndex = Sender->ItemIndex;
  8256. }
  8257. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8258. }
  8259. //---------------------------------------------------------------------------
  8260. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8261. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8262. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8263. {
  8264. ARect.Left += (10 * AIndex);
  8265. }
  8266. //---------------------------------------------------------------------------
  8267. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8268. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8269. {
  8270. AWidth += (10 * AIndex);
  8271. }
  8272. //---------------------------------------------------------------------------
  8273. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8274. TObject * Sender)
  8275. {
  8276. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8277. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8278. int Index = RemotePathComboBox->ItemIndex;
  8279. while (Index < RemotePathComboBox->Strings->Count - 1)
  8280. {
  8281. APath = UnixExtractFileDir(APath);
  8282. Index++;
  8283. }
  8284. // VanDyke style paths
  8285. if (APath.IsEmpty())
  8286. {
  8287. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8288. APath = ROOTDIRECTORY;
  8289. }
  8290. if (RemoteDirView->Path != APath)
  8291. {
  8292. RemoteDirView->Path = APath;
  8293. }
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8297. {
  8298. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8299. DebugUsedParam(Sender);
  8300. UpdateRemotePathComboBox(true);
  8301. }
  8302. //---------------------------------------------------------------------------
  8303. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8304. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8305. {
  8306. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8307. DebugAssert(DirView != NULL);
  8308. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8309. {
  8310. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8311. // OnEditing is called also from TCustomListView::CanEdit
  8312. if (Edit != NULL)
  8313. {
  8314. EditSelectBaseName(Edit);
  8315. }
  8316. }
  8317. }
  8318. //---------------------------------------------------------------------------
  8319. //---------------------------------------------------------------------------
  8320. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8321. {
  8322. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8323. Result->AutoDetectDnD = false;
  8324. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8325. Result->RenderDataOn = rdoEnterAndDropSync;
  8326. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8327. return Result;
  8328. }
  8329. //---------------------------------------------------------------------------
  8330. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8331. {
  8332. TForm::CreateWnd();
  8333. if (FSessionsDragDropFilesEx == NULL)
  8334. {
  8335. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8336. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8337. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8338. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8339. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8340. }
  8341. if (FQueueDragDropFilesEx == NULL)
  8342. {
  8343. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8344. // No need to set OnDragOver as we do not have any restrictions
  8345. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8346. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8347. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8348. }
  8349. }
  8350. //---------------------------------------------------------------------------
  8351. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8352. {
  8353. TForm::DestroyWnd();
  8354. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8355. FQueueDragDropFilesEx->DragDropControl = NULL;
  8356. }
  8357. //---------------------------------------------------------------------------
  8358. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8359. {
  8360. SideEnter(FCurrentSide);
  8361. FEverShown = true;
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8365. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8366. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8367. {
  8368. if (!NonVisualDataModule->Busy)
  8369. {
  8370. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8371. Configuration->Usage->Inc(L"FileFinds");
  8372. LockWindow(true);
  8373. NonVisualDataModule->StartBusy();
  8374. WinConfiguration->LockedInterface = true;
  8375. try
  8376. {
  8377. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8378. }
  8379. __finally
  8380. {
  8381. WinConfiguration->LockedInterface = false;
  8382. NonVisualDataModule->EndBusy();
  8383. UnlockWindow();
  8384. }
  8385. }
  8386. }
  8387. //---------------------------------------------------------------------------
  8388. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8389. {
  8390. if (!NonVisualDataModule->Busy)
  8391. {
  8392. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8393. SetFocus();
  8394. RemoteDirView->Path = UnixExtractFilePath(Path);
  8395. TListItem * Item = RemoteDirView->FindFileItem(UnixExtractFileName(Path));
  8396. if (Item != NULL)
  8397. {
  8398. RemoteDirView->ItemFocused = Item;
  8399. RemoteDirView->ItemFocused->MakeVisible(false);
  8400. RemoteDirView->SetFocus();
  8401. }
  8402. }
  8403. }
  8404. //---------------------------------------------------------------------------
  8405. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  8406. {
  8407. bool Result = !NonVisualDataModule->Busy;
  8408. if (Result)
  8409. {
  8410. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8411. }
  8412. return Result;
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8416. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8417. {
  8418. if (CanOperateOnFoundFiles(ATerminal))
  8419. {
  8420. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  8421. FOnFileOperationFinished = OnFileOperationFinished;
  8422. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8423. }
  8424. }
  8425. //---------------------------------------------------------------------------
  8426. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8427. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8428. {
  8429. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8430. }
  8431. //---------------------------------------------------------------------------
  8432. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8433. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8434. {
  8435. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8436. }
  8437. //---------------------------------------------------------------------------
  8438. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  8439. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8440. {
  8441. if (CanOperateOnFoundFiles(ATerminal))
  8442. {
  8443. for (int Index = 0; Index < FileList->Count; Index++)
  8444. {
  8445. UnicodeString FileName = FileList->Strings[Index];
  8446. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  8447. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  8448. OnFileOperationFinished(FileName, true);
  8449. }
  8450. }
  8451. }
  8452. //---------------------------------------------------------------------------
  8453. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8454. {
  8455. FFileFindTerminal = Terminal;
  8456. ShowFileFindDialog(
  8457. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  8458. DoDownloadFoundFiles, DoEditFoundFiles);
  8459. }
  8460. //---------------------------------------------------------------------------
  8461. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8462. {
  8463. FTaskbarList = TaskbarList;
  8464. }
  8465. //---------------------------------------------------------------------------
  8466. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8467. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8468. {
  8469. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8470. if (Index >= 0)
  8471. {
  8472. if (Button == mbLeft)
  8473. {
  8474. // "Mouse down" is raised only after tab is switched.
  8475. // If switching tab (switching session) takes long enough for user
  8476. // to actually release the button, "mouse down" is still raised,
  8477. // but we do not get "mouse up" event, so dragging is not cancelled,
  8478. // prevent that by not beginning dragging in the first place.
  8479. if (IsKeyPressed(VK_LBUTTON))
  8480. {
  8481. // when user clicks the "+", we get mouse down only after the session
  8482. // is closed, when new session tab is already on X:Y, so dragging
  8483. // starts, prevent that
  8484. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8485. {
  8486. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8487. if (Terminal != NULL)
  8488. {
  8489. SessionsPageControl->BeginDrag(false);
  8490. }
  8491. }
  8492. }
  8493. }
  8494. else if (Button == mbMiddle)
  8495. {
  8496. // ignore middle-click for "New session tab"
  8497. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8498. if (Terminal != NULL)
  8499. {
  8500. SessionsPageControl->ActivePageIndex = Index;
  8501. // Switch to session tab (has to be session tab, due to previous check)
  8502. if (DebugAlwaysTrue(SessionTabSwitched()))
  8503. {
  8504. CloseSession();
  8505. }
  8506. }
  8507. }
  8508. }
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8512. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8513. {
  8514. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8515. // do not allow dropping on the "+" tab
  8516. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8517. if ((TargetTerminal != NULL) &&
  8518. (SessionsPageControl->ActivePage->PageIndex != Index))
  8519. {
  8520. Configuration->Usage->Inc(L"SessionTabMoves");
  8521. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8522. // but we want to actually prevent that to avoid flicker
  8523. SessionsPageControl->ActivePage->PageIndex = Index;
  8524. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8525. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8526. }
  8527. }
  8528. //---------------------------------------------------------------------------
  8529. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8530. TObject * Sender, TObject * Source, int X, int Y,
  8531. TDragState /*State*/, bool & Accept)
  8532. {
  8533. Accept = (Sender == Source);
  8534. if (Accept)
  8535. {
  8536. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8537. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8538. // do not allow dragging to the "+" tab
  8539. Accept = (Terminal != NULL);
  8540. }
  8541. }
  8542. //---------------------------------------------------------------------------
  8543. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8544. const TPoint & Point, int & Effect)
  8545. {
  8546. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8547. if (Index < 0)
  8548. {
  8549. Effect = DROPEFFECT_None;
  8550. }
  8551. else
  8552. {
  8553. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8554. // do not allow dropping on the "+" tab
  8555. if (TargetTerminal == NULL)
  8556. {
  8557. Effect = DROPEFFECT_None;
  8558. }
  8559. }
  8560. }
  8561. //---------------------------------------------------------------------------
  8562. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8563. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8564. {
  8565. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8566. // do not allow dropping on the "+" tab
  8567. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8568. if (TargetTerminal != NULL)
  8569. {
  8570. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8571. if (!IsFileControl(DropSourceControl, osRemote))
  8572. {
  8573. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8574. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  8575. // Why don't we use Terminal->CurrentDirectory directly?
  8576. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory, false);
  8577. }
  8578. }
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  8582. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  8583. {
  8584. // Downloads are handled in RemoteFileControlDDEnd
  8585. if (!IsFileControl(DropSourceControl, osRemote))
  8586. {
  8587. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  8588. Terminal->CurrentDirectory,
  8589. // force queue
  8590. true);
  8591. }
  8592. }
  8593. //---------------------------------------------------------------------------
  8594. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  8595. {
  8596. FShowing = false;
  8597. // Do not save empty workspace
  8598. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  8599. {
  8600. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  8601. UnicodeString Name = WorkspaceName();
  8602. DoSaveWorkspace(
  8603. Name, DataList.get(),
  8604. !Configuration->DisablePasswordStoring &&
  8605. WinConfiguration->AutoSaveWorkspacePasswords);
  8606. WinConfiguration->LastStoredSession = Name;
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  8611. {
  8612. TManagedTerminal * ManagedTerminal =
  8613. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  8614. if (ManagedTerminal != NULL)
  8615. {
  8616. ManagedTerminal->DirectoryLoaded = Now();
  8617. }
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  8621. TListItem * /*Item*/, bool /*Selected*/)
  8622. {
  8623. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8624. switch (DirView->LastSelectMethod)
  8625. {
  8626. case smKeyboard:
  8627. Configuration->Usage->Inc(L"KeyboardSelections");
  8628. break;
  8629. case smMouse:
  8630. Configuration->Usage->Inc(L"MouseSelections");
  8631. break;
  8632. }
  8633. }
  8634. //---------------------------------------------------------------------------
  8635. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  8636. {
  8637. if (Color != 0)
  8638. {
  8639. AddSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  8640. return FSessionColors->Count - 1;
  8641. }
  8642. else
  8643. {
  8644. return FSessionTabImageIndex;
  8645. }
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  8649. {
  8650. TPngImageCollectionItem * Item =
  8651. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  8652. FSessionColors->AddPng(Item->PngImage);
  8653. return FSessionColors->Count - 1;
  8654. }
  8655. //---------------------------------------------------------------------------
  8656. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  8657. {
  8658. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  8659. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  8660. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  8661. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  8662. }
  8663. //---------------------------------------------------------------------------
  8664. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  8665. {
  8666. for (int Index = 0; Index < Control->ControlCount; Index++)
  8667. {
  8668. TControl * AControl = Control->Controls[Index];
  8669. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  8670. if (WinControl != NULL)
  8671. {
  8672. CollectItemsWithTextDisplayMode(WinControl);
  8673. }
  8674. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  8675. if (Toolbar != NULL)
  8676. {
  8677. // we care for top-level items only
  8678. TTBCustomItem * Items = Toolbar->Items;
  8679. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  8680. {
  8681. TTBCustomItem * Item = Items->Items[ItemIndex];
  8682. if (((Item->DisplayMode == nbdmImageAndText) ||
  8683. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  8684. EligibleForImageDisplayMode(Item))
  8685. {
  8686. FItemsWithTextDisplayMode.insert(Item);
  8687. }
  8688. }
  8689. }
  8690. }
  8691. }
  8692. //---------------------------------------------------------------------------
  8693. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  8694. {
  8695. return true;
  8696. }
  8697. //---------------------------------------------------------------------------
  8698. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  8699. {
  8700. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  8701. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  8702. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  8703. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  8704. bool Result = true;
  8705. while (Result && (i != FItemsWithTextDisplayMode.end()))
  8706. {
  8707. TTBCustomItem * Item = *i;
  8708. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  8709. if (Label != NULL)
  8710. {
  8711. // optimization
  8712. if (Label->Visible == SelectiveToolbarText)
  8713. {
  8714. Result = false;
  8715. }
  8716. else
  8717. {
  8718. Label->Visible = SelectiveToolbarText;
  8719. }
  8720. }
  8721. else
  8722. {
  8723. // optimization
  8724. if (Item->DisplayMode == DisplayMode)
  8725. {
  8726. Result = false;
  8727. }
  8728. else
  8729. {
  8730. Item->DisplayMode = DisplayMode;
  8731. }
  8732. }
  8733. ++i;
  8734. }
  8735. if (Result)
  8736. {
  8737. UpdateNewSessionTab();
  8738. }
  8739. return Result;
  8740. }
  8741. //---------------------------------------------------------------------------
  8742. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  8743. {
  8744. DebugFail();
  8745. }
  8746. //---------------------------------------------------------------------------
  8747. bool __fastcall TCustomScpExplorerForm::IsBusy()
  8748. {
  8749. // Among other, a lock level is non zero, while directory is being loaded,
  8750. // even when it happens as a result of dirview navigation,
  8751. // i.e. when TNonVisualDataModule is NOT FBusy.
  8752. // That's why the TNonVisualDataModule::GetBusy calls this method.
  8753. // Among other this prevents a panel auto update to occur while
  8754. // directory is changing.
  8755. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  8759. {
  8760. // While the window is disabled, we still seem to process menu shortcuts at least,
  8761. // so stop it at least here.
  8762. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  8763. return
  8764. (Allowed == aaUpdate) ||
  8765. !NonVisualDataModule->Busy;
  8766. }
  8767. //---------------------------------------------------------------------------
  8768. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  8769. {
  8770. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  8771. }
  8772. //---------------------------------------------------------------------------
  8773. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  8774. {
  8775. // This is somewhat redundant to LockWindow() call from
  8776. // TTerminalManager::TerminalReadDirectoryProgress.
  8777. // But disabling window is known not to block keyboard shorcuts
  8778. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  8779. if (Busy > 0)
  8780. {
  8781. if (NonVisualDataModule->Busy)
  8782. {
  8783. State = false;
  8784. }
  8785. else
  8786. {
  8787. NonVisualDataModule->StartBusy();
  8788. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  8789. LockWindow();
  8790. }
  8791. }
  8792. else if (Busy < 0)
  8793. {
  8794. UnlockWindow();
  8795. NonVisualDataModule->EndBusy();
  8796. }
  8797. else
  8798. {
  8799. State = NonVisualDataModule->Busy;
  8800. }
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  8804. {
  8805. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  8806. // no context menu for "New session tab"
  8807. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  8808. {
  8809. SessionsPageControl->ActivePageIndex = Index;
  8810. if (DebugAlwaysTrue(SessionTabSwitched()))
  8811. {
  8812. // copied from TControl.WMContextMenu
  8813. SendCancelMode(SessionsPageControl);
  8814. // explicit popup instead of using PopupMenu property
  8815. // to avoid menu to popup somewhere within SessionTabSwitched above,
  8816. // while connecting yet not-connected session and hence
  8817. // allowing an access to commands over not-completelly connected session
  8818. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  8819. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  8820. PopupMenu->PopupComponent = SessionsPageControl;
  8821. PopupMenu->Popup(Point.x, Point.y);
  8822. }
  8823. }
  8824. Handled = true;
  8825. }
  8826. //---------------------------------------------------------------------------
  8827. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  8828. {
  8829. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  8830. }
  8831. //---------------------------------------------------------------------------
  8832. void __fastcall TCustomScpExplorerForm::ChangePassword()
  8833. {
  8834. Configuration->Usage->Inc(L"PasswordChanges");
  8835. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  8836. ChangePasswordData->DisableAuthentationsExceptPassword();
  8837. ChangePasswordData->ChangePassword = true;
  8838. std::unique_ptr<TTerminal> ChangePasswordSession(
  8839. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  8840. ChangePasswordSession->AutoReadDirectory = false;
  8841. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  8842. {
  8843. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  8844. }
  8845. else
  8846. {
  8847. Configuration->Usage->Inc(L"PasswordChangesFailed");
  8848. }
  8849. }
  8850. //---------------------------------------------------------------------------
  8851. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  8852. {
  8853. TForm::ChangeScale(M, D);
  8854. int APixelsPerInch = GetControlPixelsPerInch(this);
  8855. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  8856. try
  8857. {
  8858. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  8859. }
  8860. __finally
  8861. {
  8862. GUIConfiguration->ChangeResourceModule(ResourceModule);
  8863. }
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  8867. {
  8868. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  8869. }
  8870. //---------------------------------------------------------------------
  8871. class TPublicControl : public TControl
  8872. {
  8873. friend class TCustomScpExplorerForm;
  8874. };
  8875. //---------------------------------------------------------------------------
  8876. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  8877. {
  8878. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  8879. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  8880. }
  8881. //---------------------------------------------------------------------------