CustomScpExplorer.cpp 295 KB

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