CustomScpExplorer.cpp 308 KB

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