CustomScpExplorer.cpp 295 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186
  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. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::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. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4624. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4625. {
  4626. // noop, already logged in MoreMessageDialog
  4627. }
  4628. else
  4629. {
  4630. ShowExtendedExceptionEx(Terminal, &E);
  4631. throw;
  4632. }
  4633. }
  4634. }
  4635. }
  4636. //---------------------------------------------------------------------------
  4637. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4638. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4639. const UnicodeString ErrorStr)
  4640. {
  4641. if (!Directory.IsEmpty())
  4642. {
  4643. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4644. }
  4645. else
  4646. {
  4647. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4648. }
  4649. }
  4650. //---------------------------------------------------------------------------
  4651. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4652. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4653. {
  4654. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4655. {
  4656. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4657. }
  4658. else
  4659. {
  4660. TMessageParams Params(mpNeverAskAgainCheck);
  4661. unsigned int Result = MessageDialog(
  4662. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4663. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4664. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4665. {
  4666. MaxDirectories *= 2;
  4667. if (Result == qaNeverAskAgain)
  4668. {
  4669. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4670. }
  4671. }
  4672. else
  4673. {
  4674. Abort();
  4675. }
  4676. }
  4677. }
  4678. //---------------------------------------------------------------------------
  4679. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4680. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4681. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4682. TSynchronizeOptions * Options)
  4683. {
  4684. DebugAssert(!FAutoOperation);
  4685. void * BatchStorage;
  4686. BatchStart(BatchStorage);
  4687. FAutoOperation = true;
  4688. bool AnyOperation = false;
  4689. TDateTime StartTime = Now();
  4690. TSynchronizeChecklist * AChecklist = NULL;
  4691. try
  4692. {
  4693. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4694. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4695. {
  4696. FSynchronizeProgressForm->Start();
  4697. }
  4698. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4699. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4700. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4701. Options);
  4702. SAFE_DESTROY(FSynchronizeProgressForm);
  4703. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4704. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4705. {
  4706. FSynchronizeProgressForm->Start();
  4707. }
  4708. for (int Index = 0; !AnyOperation && (Index < AChecklist->Count); Index++)
  4709. {
  4710. AnyOperation = AChecklist->Item[Index]->Checked;
  4711. }
  4712. // No need to call if !AnyOperation
  4713. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  4714. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  4715. }
  4716. __finally
  4717. {
  4718. if (Checklist == NULL)
  4719. {
  4720. delete AChecklist;
  4721. }
  4722. else
  4723. {
  4724. *Checklist = AChecklist;
  4725. }
  4726. FAutoOperation = false;
  4727. SAFE_DESTROY(FSynchronizeProgressForm);
  4728. BatchEnd(BatchStorage);
  4729. ReloadLocalDirectory();
  4730. if (AnyOperation)
  4731. {
  4732. OperationComplete(StartTime);
  4733. }
  4734. }
  4735. }
  4736. //---------------------------------------------------------------------------
  4737. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  4738. {
  4739. // can be called from command line
  4740. return Visible &&
  4741. ((DirView(osRemote)->SelCount > 0) ||
  4742. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  4743. }
  4744. //---------------------------------------------------------------------------
  4745. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  4746. {
  4747. LogSynchronizeEvent(Terminal, Message);
  4748. }
  4749. //---------------------------------------------------------------------------
  4750. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  4751. int Params, TSynchronizeOptions & Options)
  4752. {
  4753. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  4754. {
  4755. Options.Filter = new TStringList();
  4756. Options.Filter->CaseSensitive = false;
  4757. Options.Filter->Duplicates = Types::dupAccept;
  4758. if (DirView(osRemote)->SelCount > 0)
  4759. {
  4760. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  4761. }
  4762. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  4763. {
  4764. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  4765. }
  4766. Options.Filter->Sort();
  4767. }
  4768. }
  4769. //---------------------------------------------------------------------------
  4770. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  4771. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  4772. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  4773. {
  4774. bool Result;
  4775. int Params = GUIConfiguration->SynchronizeParams;
  4776. bool SaveSettings = false;
  4777. int Options =
  4778. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  4779. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  4780. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4781. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  4782. Result = UseDefaults ||
  4783. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  4784. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  4785. if (Result)
  4786. {
  4787. Configuration->Usage->Inc(L"Synchronizations");
  4788. UpdateCopyParamCounters(CopyParam);
  4789. TSynchronizeOptions SynchronizeOptions;
  4790. GetSynchronizeOptions(Params, SynchronizeOptions);
  4791. if (SaveSettings)
  4792. {
  4793. GUIConfiguration->SynchronizeParams = Params;
  4794. }
  4795. else
  4796. {
  4797. SaveMode = false;
  4798. }
  4799. TDateTime StartTime = Now();
  4800. TSynchronizeChecklist * Checklist = NULL;
  4801. try
  4802. {
  4803. DebugAssert(!FAutoOperation);
  4804. FAutoOperation = true;
  4805. try
  4806. {
  4807. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4808. FSynchronizeProgressForm->Start();
  4809. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4810. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4811. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4812. &SynchronizeOptions);
  4813. }
  4814. __finally
  4815. {
  4816. FAutoOperation = false;
  4817. SAFE_DESTROY(FSynchronizeProgressForm);
  4818. }
  4819. if (Checklist->Count == 0)
  4820. {
  4821. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  4822. MessageDialog(Message, qtInformation, qaOK,
  4823. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  4824. }
  4825. else if (FLAGCLEAR(Params, TTerminal::spPreviewChanges) ||
  4826. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  4827. LocalDirectory, RemoteDirectory, CustomCommandMenu))
  4828. {
  4829. DebugAssert(!FAutoOperation);
  4830. void * BatchStorage;
  4831. BatchStart(BatchStorage);
  4832. FAutoOperation = true;
  4833. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  4834. {
  4835. StartTime = Now();
  4836. }
  4837. try
  4838. {
  4839. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4840. FSynchronizeProgressForm->Start();
  4841. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  4842. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  4843. }
  4844. __finally
  4845. {
  4846. FAutoOperation = false;
  4847. SAFE_DESTROY(FSynchronizeProgressForm);
  4848. BatchEnd(BatchStorage);
  4849. ReloadLocalDirectory();
  4850. }
  4851. }
  4852. }
  4853. __finally
  4854. {
  4855. delete Checklist;
  4856. }
  4857. OperationComplete(StartTime);
  4858. }
  4859. return Result;
  4860. }
  4861. //---------------------------------------------------------------------------
  4862. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  4863. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  4864. bool & Continue, bool /*Collect*/)
  4865. {
  4866. DebugAssert(FSynchronizeProgressForm != NULL);
  4867. if (!FSynchronizeProgressForm->Started)
  4868. {
  4869. FSynchronizeProgressForm->Start();
  4870. }
  4871. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  4872. }
  4873. //---------------------------------------------------------------------------
  4874. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  4875. {
  4876. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  4877. TRemoteFile * File = NULL;
  4878. Terminal->ReadFile(FullFileName, File);
  4879. if (File != NULL)
  4880. {
  4881. std::unique_ptr<TRemoteFile> FileOwner(File);
  4882. TAutoFlag Flag(FStandaloneEditing);
  4883. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  4884. Application->ShowMainForm = false;
  4885. Application->Run();
  4886. }
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  4890. {
  4891. DebugFail();
  4892. }
  4893. //---------------------------------------------------------------------------
  4894. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  4895. {
  4896. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  4897. SessionData->Assign(Terminal->SessionData);
  4898. UpdateSessionData(SessionData.get());
  4899. TTerminalManager::Instance()->UpdateSessionCredentials(SessionData.get());
  4900. if (Terminal->SessionData->IsWorkspace)
  4901. {
  4902. // Have to reset the "Workspace/XXX" name which would become user-visible
  4903. // once IsWorkspace is cleared
  4904. SessionData->Name = UnicodeString();
  4905. SessionData->IsWorkspace = false;
  4906. }
  4907. return SessionData.release();
  4908. }
  4909. //---------------------------------------------------------------------------
  4910. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  4911. {
  4912. TSessionData * SessionData = CloneCurrentSessionData();
  4913. try
  4914. {
  4915. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  4916. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  4917. }
  4918. __finally
  4919. {
  4920. delete SessionData;
  4921. }
  4922. }
  4923. //---------------------------------------------------------------------------
  4924. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  4925. {
  4926. TTerminalManager * Manager = TTerminalManager::Instance();
  4927. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4928. if (DebugAlwaysTrue(Terminal != NULL))
  4929. {
  4930. // Update (Managed)Terminal->StateData
  4931. UpdateTerminal(Terminal);
  4932. }
  4933. Manager->SaveWorkspace(DataList.get());
  4934. return DataList.release();
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  4938. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords)
  4939. {
  4940. WinConfiguration->LastWorkspace = Name;
  4941. if (!SavePasswords)
  4942. {
  4943. for (int Index = 0; Index < DataList->Count; Index++)
  4944. {
  4945. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  4946. if (SessionData->Link.IsEmpty())
  4947. {
  4948. SessionData->ClearSessionPasswords();
  4949. }
  4950. }
  4951. }
  4952. StoredSessions->NewWorkspace(Name, DataList);
  4953. // modified only, explicit
  4954. StoredSessions->Save(false, true);
  4955. }
  4956. //---------------------------------------------------------------------------
  4957. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  4958. {
  4959. return
  4960. DefaultStr(WinConfiguration->LastWorkspace,
  4961. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  4962. }
  4963. //---------------------------------------------------------------------------
  4964. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  4965. {
  4966. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  4967. bool AnyNonStoredSessionWithPassword = false;
  4968. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  4969. bool AllNonStoredSessionsAnonymous = true;
  4970. TTerminalManager * Manager = TTerminalManager::Instance();
  4971. for (int Index = 0; Index < DataList->Count; Index++)
  4972. {
  4973. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  4974. if (SessionData->Link.IsEmpty())
  4975. {
  4976. if (SessionData->HasAnySessionPassword())
  4977. {
  4978. AnyNonStoredSessionWithPassword = true;
  4979. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  4980. {
  4981. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  4982. }
  4983. }
  4984. if (!SameText(SessionData->UserName, AnonymousUserName))
  4985. {
  4986. AllNonStoredSessionsAnonymous = false;
  4987. }
  4988. }
  4989. }
  4990. bool SavePasswords;
  4991. bool * PSavePasswords;
  4992. bool NotRecommendedSavingPasswords =
  4993. !CustomWinConfiguration->UseMasterPassword &&
  4994. !AllNonStoredSessionsAnonymous;
  4995. if (Configuration->DisablePasswordStoring ||
  4996. !AnyNonStoredSessionWithPassword)
  4997. {
  4998. PSavePasswords = NULL;
  4999. SavePasswords = false;
  5000. }
  5001. else
  5002. {
  5003. PSavePasswords = &SavePasswords;
  5004. SavePasswords =
  5005. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5006. !NotRecommendedSavingPasswords;
  5007. }
  5008. UnicodeString Name = WorkspaceName();
  5009. bool CreateShortcut = false;
  5010. bool Result =
  5011. DoSaveWorkspaceDialog(
  5012. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5013. EnableAutoSave);
  5014. if (Result)
  5015. {
  5016. DoSaveWorkspace(Name, DataList.get(), SavePasswords);
  5017. if (CreateShortcut)
  5018. {
  5019. TOperationVisualizer Visualizer;
  5020. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5021. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5022. }
  5023. if (EnableAutoSave)
  5024. {
  5025. WinConfiguration->AutoSaveWorkspace = true;
  5026. WinConfiguration->AutoWorkspace = Name;
  5027. if (PSavePasswords != NULL)
  5028. {
  5029. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5030. }
  5031. }
  5032. }
  5033. return Result;
  5034. }
  5035. //---------------------------------------------------------------------------
  5036. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5037. {
  5038. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5039. DebugAssert(ManagedTerminal != NULL);
  5040. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5041. if (WinConfiguration->PreservePanelState)
  5042. {
  5043. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5044. }
  5045. UpdateSessionData(ManagedTerminal->StateData);
  5046. }
  5047. //---------------------------------------------------------------------------
  5048. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5049. {
  5050. // Keep in sync with TSessionData::CopyStateData
  5051. DebugAssert(Data != NULL);
  5052. // cannot use RemoteDirView->Path, because it is empty if connection
  5053. // was already closed
  5054. // also only peek, we may not be connected at all atm
  5055. // so make sure we do not try retrieving current directory from the server
  5056. // (particularly with FTP)
  5057. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5058. if (!ACurrentDirectory.IsEmpty())
  5059. {
  5060. Data->RemoteDirectory = ACurrentDirectory;
  5061. }
  5062. Data->Color = SessionColor;
  5063. }
  5064. //---------------------------------------------------------------------------
  5065. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5066. {
  5067. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5068. DebugAssert(Toolbar != NULL);
  5069. for (int i = 0; i < Toolbar->Items->Count; i++)
  5070. {
  5071. TTBXCustomDropDownItem * DropDownItem;
  5072. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5073. if (DropDownItem != NULL)
  5074. {
  5075. ToolbarItemResize(DropDownItem,
  5076. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5077. Toolbar->NonClientWidth);
  5078. break;
  5079. }
  5080. }
  5081. }
  5082. //---------------------------------------------------------------------------
  5083. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5084. {
  5085. Item->EditWidth = Width;
  5086. }
  5087. //---------------------------------------------------------------------------
  5088. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5089. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5090. {
  5091. for (int i = 0; i < Toolbar->Items->Count; i++)
  5092. {
  5093. TTBXCustomDropDownItem * DropDownItem;
  5094. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5095. if (DropDownItem != NULL)
  5096. {
  5097. ASize.x -= DropDownItem->EditWidth;
  5098. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5099. }
  5100. }
  5101. }
  5102. //---------------------------------------------------------------------------
  5103. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5104. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5105. {
  5106. if (WinConfiguration->DDWarnLackOfTempSpace)
  5107. {
  5108. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5109. if (!ADrive.IsEmpty())
  5110. {
  5111. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5112. DebugAssert(RequiredSpace >= 0);
  5113. __int64 RequiredWithReserve;
  5114. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5115. if (FreeSpace < RequiredWithReserve)
  5116. {
  5117. unsigned int Result;
  5118. TMessageParams Params(mpNeverAskAgainCheck);
  5119. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5120. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5121. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5122. if (Result == qaNeverAskAgain)
  5123. {
  5124. WinConfiguration->DDWarnLackOfTempSpace = false;
  5125. }
  5126. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5127. }
  5128. }
  5129. }
  5130. }
  5131. //---------------------------------------------------------------------------
  5132. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5133. {
  5134. DoOpenDirectoryDialog(odAddBookmark, Side);
  5135. }
  5136. //---------------------------------------------------------------------------
  5137. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5138. {
  5139. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5140. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5141. try
  5142. {
  5143. TCustomDirView * DView = DirView(Side);
  5144. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5145. {
  5146. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5147. }
  5148. }
  5149. catch (...)
  5150. {
  5151. delete VisitedDirectories;
  5152. throw;
  5153. }
  5154. return VisitedDirectories;
  5155. }
  5156. //---------------------------------------------------------------------------
  5157. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5158. TOpenDirectoryMode Mode, TOperationSide Side)
  5159. {
  5160. bool Continue = true;
  5161. if (Mode == odAddBookmark)
  5162. {
  5163. TMessageParams Params(mpNeverAskAgainCheck);
  5164. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5165. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5166. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5167. unsigned int Answer =
  5168. MessageDialog(Message,
  5169. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5170. if (Answer == qaNeverAskAgain)
  5171. {
  5172. Continue = true;
  5173. WinConfiguration->UseSharedBookmarks = true;
  5174. }
  5175. else if (Answer == qaOK)
  5176. {
  5177. Continue = true;
  5178. WinConfiguration->UseSharedBookmarks = false;
  5179. }
  5180. else
  5181. {
  5182. Continue = false;
  5183. }
  5184. }
  5185. if (Continue)
  5186. {
  5187. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5188. try
  5189. {
  5190. UnicodeString Name = DirView(Side)->PathName;
  5191. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5192. // do not allow switching to location profiles,
  5193. // if we are not connected
  5194. HasDirView[osLocal] && (Terminal != NULL)))
  5195. {
  5196. TWindowLock Lock(this);
  5197. DirView(Side)->Path = Name;
  5198. }
  5199. }
  5200. __finally
  5201. {
  5202. delete VisitedDirectories;
  5203. }
  5204. }
  5205. }
  5206. //---------------------------------------------------------------------------
  5207. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5208. {
  5209. DebugAssert(!FTerminal->CommandSessionOpened);
  5210. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5211. }
  5212. //---------------------------------------------------------------------------
  5213. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5214. {
  5215. bool Result = FTerminal->IsCapable[Capability] ||
  5216. FTerminal->CommandSessionOpened;
  5217. if (!Result)
  5218. {
  5219. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5220. if (!GUIConfiguration->ConfirmCommandSession)
  5221. {
  5222. Result = true;
  5223. }
  5224. else
  5225. {
  5226. TMessageParams Params(mpNeverAskAgainCheck);
  5227. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5228. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5229. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5230. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5231. if (Answer == qaNeverAskAgain)
  5232. {
  5233. GUIConfiguration->ConfirmCommandSession = false;
  5234. Result = true;
  5235. }
  5236. else if (Answer == qaOK)
  5237. {
  5238. Result = true;
  5239. }
  5240. }
  5241. if (Result)
  5242. {
  5243. Result = CommandSessionFallback();
  5244. }
  5245. }
  5246. return Result;
  5247. }
  5248. //---------------------------------------------------------------------------
  5249. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5250. {
  5251. if (EnsureCommandSessionFallback(fcAnyCommand))
  5252. {
  5253. DoConsoleDialog(Terminal, Command);
  5254. }
  5255. }
  5256. //---------------------------------------------------------------------------
  5257. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5258. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5259. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5260. {
  5261. if (IsFileControl(DropSourceControl, osRemote) &&
  5262. (FDDExtMapFile != NULL))
  5263. {
  5264. Accept = true;
  5265. }
  5266. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5267. DebugAssert(FDDTargetControl != NULL);
  5268. }
  5269. //---------------------------------------------------------------------------
  5270. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5271. _di_IDataObject DataObj, int KeyState,
  5272. const TPoint & Point, int & Effect, bool & Accept)
  5273. {
  5274. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5275. }
  5276. //---------------------------------------------------------------------------
  5277. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5278. _di_IDataObject DataObj, int KeyState,
  5279. const TPoint & Point, int & Effect, bool & Accept)
  5280. {
  5281. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5282. }
  5283. //---------------------------------------------------------------------------
  5284. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5285. TObject * Sender)
  5286. {
  5287. DebugUsedParam(Sender);
  5288. DebugAssert(FDDTargetControl == Sender);
  5289. FDDTargetControl = NULL;
  5290. }
  5291. //---------------------------------------------------------------------------
  5292. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5293. {
  5294. FileControlDDDragLeave(SessionsPageControl);
  5295. }
  5296. //---------------------------------------------------------------------------
  5297. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5298. {
  5299. FileControlDDDragLeave(QueueView3);
  5300. }
  5301. //---------------------------------------------------------------------------
  5302. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5303. {
  5304. DebugAssert(GetSide(Side) == osRemote);
  5305. DebugUsedParam(Side);
  5306. bool Edit = false;
  5307. TRemoteFile * File = NULL;
  5308. UnicodeString FileName;
  5309. UnicodeString PointTo;
  5310. bool SymbolicLink = true;
  5311. if (RemoteDirView->ItemFocused)
  5312. {
  5313. DebugAssert(RemoteDirView->ItemFocused->Data);
  5314. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5315. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5316. if (Edit)
  5317. {
  5318. FileName = File->FileName;
  5319. PointTo = File->LinkTo;
  5320. }
  5321. else
  5322. {
  5323. PointTo = File->FileName;
  5324. }
  5325. }
  5326. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5327. Terminal->IsCapable[fcHardLink]))
  5328. {
  5329. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5330. if (Edit)
  5331. {
  5332. DebugAssert(File->FileName == FileName);
  5333. int Params = dfNoRecursive;
  5334. Terminal->ExceptionOnFail = true;
  5335. try
  5336. {
  5337. Terminal->DeleteFile(L"", File, &Params);
  5338. }
  5339. __finally
  5340. {
  5341. Terminal->ExceptionOnFail = false;
  5342. }
  5343. }
  5344. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5345. }
  5346. }
  5347. //---------------------------------------------------------------------------
  5348. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5349. {
  5350. return
  5351. (Terminal != NULL) &&
  5352. ((GetSide(Side) != osRemote) ||
  5353. (Terminal->ResolvingSymlinks &&
  5354. Terminal->IsCapable[fcSymbolicLink]));
  5355. }
  5356. //---------------------------------------------------------------------------
  5357. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5358. {
  5359. return
  5360. (FCurrentSide == osRemote) &&
  5361. (RemoteDirView->ItemFocused != NULL) &&
  5362. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5363. Terminal->SessionData->ResolveSymlinks;
  5364. }
  5365. //---------------------------------------------------------------------------
  5366. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5367. {
  5368. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5369. FForceExecution = true;
  5370. try
  5371. {
  5372. DirView(osCurrent)->ExecuteCurrentFile();
  5373. }
  5374. __finally
  5375. {
  5376. FForceExecution = false;
  5377. }
  5378. }
  5379. //---------------------------------------------------------------------------
  5380. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5381. {
  5382. TEditorData ExternalEditor;
  5383. ExternalEditor.Editor = edExternal;
  5384. bool Remember = false;
  5385. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5386. (GetSide(osCurrent) == osRemote)))
  5387. {
  5388. if (Remember)
  5389. {
  5390. TEditorList * EditorList = new TEditorList;
  5391. try
  5392. {
  5393. *EditorList = *WinConfiguration->EditorList;
  5394. bool Found = false;
  5395. int i = 0;
  5396. while (!Found && (i < EditorList->Count))
  5397. {
  5398. const TEditorPreferences * Editor = EditorList->Editors[i];
  5399. if ((Editor->Data->Editor == edExternal) &&
  5400. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5401. {
  5402. Found = true;
  5403. }
  5404. i++;
  5405. }
  5406. if (!Found)
  5407. {
  5408. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5409. WinConfiguration->EditorList = EditorList;
  5410. }
  5411. }
  5412. __finally
  5413. {
  5414. delete EditorList;
  5415. }
  5416. }
  5417. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5418. }
  5419. }
  5420. //---------------------------------------------------------------------------
  5421. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5422. {
  5423. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5424. if (FFileFindTerminal == Sender)
  5425. {
  5426. FFileFindTerminal = NULL;
  5427. HideFileFindDialog();
  5428. }
  5429. }
  5430. //---------------------------------------------------------------------------
  5431. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5432. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5433. {
  5434. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5435. DebugAssert(Terminal != NULL);
  5436. if (Data->Terminal == Terminal)
  5437. {
  5438. Data->Terminal = NULL;
  5439. }
  5440. }
  5441. //---------------------------------------------------------------------------
  5442. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5443. {
  5444. UpdateControls();
  5445. SessionColor = TColor(0);
  5446. UpdateRemotePathComboBox(false);
  5447. try
  5448. {
  5449. NeedSession(true);
  5450. }
  5451. catch (EAbort &)
  5452. {
  5453. // swallow
  5454. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect
  5455. }
  5456. }
  5457. //---------------------------------------------------------------------------
  5458. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5459. {
  5460. try
  5461. {
  5462. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5463. }
  5464. __finally
  5465. {
  5466. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5467. (!Terminal || !Terminal->Active))
  5468. {
  5469. TerminateApplication();
  5470. }
  5471. }
  5472. }
  5473. //---------------------------------------------------------------------------
  5474. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged(bool Force)
  5475. {
  5476. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  5477. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5478. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  5479. bool ListChanged = Force || (TerminalList->Count + 1 != SessionsPageControl->PageCount);
  5480. if (!ListChanged)
  5481. {
  5482. int Index = 0;
  5483. while (!ListChanged && (Index < TerminalList->Count))
  5484. {
  5485. ListChanged =
  5486. (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != TerminalList->Objects[Index]) ||
  5487. (SessionsPageControl->Pages[Index]->Caption != TerminalList->Strings[Index]);
  5488. Index++;
  5489. }
  5490. }
  5491. if (ListChanged)
  5492. {
  5493. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  5494. try
  5495. {
  5496. FSessionColors->Clear();
  5497. AddFixedSessionImages();
  5498. while (SessionsPageControl->PageCount > 0)
  5499. {
  5500. delete SessionsPageControl->Pages[0];
  5501. }
  5502. for (int Index = 0; Index < TerminalList->Count; Index++)
  5503. {
  5504. TThemeTabSheet * TabSheet = new TThemeTabSheet(SessionsPageControl);
  5505. TabSheet->Caption = TerminalList->Strings[Index];
  5506. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  5507. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  5508. TabSheet->PageControl = SessionsPageControl;
  5509. UpdateSessionTab(TabSheet);
  5510. }
  5511. TTabSheet * TabSheet = new TTabSheet(SessionsPageControl);
  5512. TabSheet->PageControl = SessionsPageControl;
  5513. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  5514. UpdateNewSessionTab();
  5515. }
  5516. __finally
  5517. {
  5518. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  5519. }
  5520. }
  5521. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  5522. }
  5523. //---------------------------------------------------------------------------
  5524. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  5525. {
  5526. DoTerminalListChanged(false);
  5527. }
  5528. //---------------------------------------------------------------------------
  5529. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  5530. {
  5531. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5532. DebugAssert(TabSheet->ImageIndex == 0);
  5533. TabSheet->Caption =
  5534. WinConfiguration->SelectiveToolbarText ?
  5535. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  5536. UnicodeString();
  5537. }
  5538. //---------------------------------------------------------------------------
  5539. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  5540. {
  5541. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  5542. }
  5543. //---------------------------------------------------------------------------
  5544. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  5545. {
  5546. if (DebugAlwaysTrue(TabSheet != NULL))
  5547. {
  5548. TManagedTerminal * ManagedTerminal =
  5549. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  5550. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  5551. {
  5552. TColor Color =
  5553. (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  5554. TabSheet->ImageIndex = AddSessionColor(Color);
  5555. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  5556. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  5557. {
  5558. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  5559. }
  5560. }
  5561. }
  5562. }
  5563. //---------------------------------------------------------------------------
  5564. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  5565. {
  5566. DebugAssert(SessionsPageControl->ActivePage != NULL);
  5567. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  5568. bool Result = (Terminal != NULL);
  5569. if (Result)
  5570. {
  5571. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5572. }
  5573. else
  5574. {
  5575. try
  5576. {
  5577. NewSession(false);
  5578. }
  5579. __finally
  5580. {
  5581. DoTerminalListChanged(false);
  5582. }
  5583. FSessionsPageControlNewSessionTime = Now();
  5584. }
  5585. return Result;
  5586. }
  5587. //---------------------------------------------------------------------------
  5588. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  5589. {
  5590. SessionTabSwitched();
  5591. }
  5592. //---------------------------------------------------------------------------
  5593. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  5594. {
  5595. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  5596. DebugAssert(TransferList != NULL);
  5597. UnicodeString Name;
  5598. if (TransferList->ItemIndex <= 0)
  5599. {
  5600. Name = L"";
  5601. }
  5602. else
  5603. {
  5604. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  5605. }
  5606. if (FCopyParamAutoSelected.IsEmpty())
  5607. {
  5608. // if previous preset was not autoselected, make new preset the "default"
  5609. FCopyParamDefault = Name;
  5610. }
  5611. GUIConfiguration->CopyParamCurrent = Name;
  5612. }
  5613. //---------------------------------------------------------------------------
  5614. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  5615. {
  5616. // sanity check
  5617. bool ExistingPreset =
  5618. (FTransferListHoverIndex >= 0) &&
  5619. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  5620. DebugAssert(ExistingPreset);
  5621. if (ExistingPreset)
  5622. {
  5623. HDC DC = GetDC(0);
  5624. TCanvas * Canvas = new TCanvas();
  5625. try
  5626. {
  5627. Canvas->Handle = DC;
  5628. Canvas->Font = ToolbarFont;
  5629. UnicodeString Name;
  5630. if (FTransferListHoverIndex == 0)
  5631. {
  5632. Name = L"";
  5633. }
  5634. else
  5635. {
  5636. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  5637. }
  5638. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  5639. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  5640. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  5641. static_cast<TObject*>(GetComponent(fcTransferList)));
  5642. UnicodeString InfoStr =
  5643. GUIConfiguration->CopyParamPreset[Name].
  5644. GetInfoStr(L"; ",
  5645. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  5646. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  5647. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  5648. {
  5649. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  5650. {
  5651. InfoStr.SetLength(InfoStr.Length() - 1);
  5652. }
  5653. InfoStr += Ellipsis;
  5654. }
  5655. // UpdateCaption does not cause invalidation of whole submenu, while
  5656. // setting Caption property does.
  5657. // also it probably does not resize the label, even if necessary
  5658. // (we do not want that anyway)
  5659. TransferLabel->UpdateCaption(InfoStr);
  5660. }
  5661. __finally
  5662. {
  5663. Canvas->Handle = NULL;
  5664. ReleaseDC(0, DC);
  5665. delete Canvas;
  5666. }
  5667. }
  5668. }
  5669. //---------------------------------------------------------------------------
  5670. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  5671. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  5672. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  5673. {
  5674. if (FTransferListHoverIndex != AHoverIndex)
  5675. {
  5676. FTransferListHoverIndex = AHoverIndex;
  5677. UpdateTransferLabel();
  5678. }
  5679. }
  5680. //---------------------------------------------------------------------------
  5681. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  5682. {
  5683. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  5684. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  5685. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  5686. {
  5687. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  5688. {
  5689. OpenDirectory(GetSide(osCurrent));
  5690. Message.Result = 1;
  5691. }
  5692. else
  5693. {
  5694. TForm::Dispatch(&Message);
  5695. }
  5696. }
  5697. else
  5698. {
  5699. TForm::Dispatch(&Message);
  5700. }
  5701. }
  5702. //---------------------------------------------------------------------------
  5703. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  5704. {
  5705. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  5706. if ((FIgnoreNextDialogChar != 0) &&
  5707. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  5708. {
  5709. Message.Result = 1;
  5710. }
  5711. else
  5712. {
  5713. TForm::Dispatch(&Message);
  5714. }
  5715. FIgnoreNextDialogChar = 0;
  5716. }
  5717. //---------------------------------------------------------------------------
  5718. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  5719. {
  5720. // The four low-order bits are used internally by Windows
  5721. unsigned int Cmd = (Message.WParam & 0xFFF0);
  5722. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  5723. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  5724. // 61730 - restore thru double click - undocumented
  5725. // 61490 - maximize thru double click - undocumented
  5726. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  5727. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  5728. {
  5729. SysResizing(Cmd);
  5730. }
  5731. TForm::Dispatch(&Message);
  5732. }
  5733. //---------------------------------------------------------------------------
  5734. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  5735. {
  5736. // We were actually never able to make ENDSESSION_CRITICAL happen.
  5737. // Also there no point returning TRUE as we are not able to
  5738. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  5739. // Hence the process termination might be safer :)
  5740. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  5741. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  5742. {
  5743. Message.Result = FALSE;
  5744. }
  5745. else
  5746. {
  5747. Message.Result = TRUE;
  5748. }
  5749. // Do not call default handling as that triggers OnCloseQuery,
  5750. // where our implementation will popup confirmation dialogs, what we do not want,
  5751. // as per Vista guidelines:
  5752. // https://msdn.microsoft.com/en-us/library/ms700677.aspx
  5753. }
  5754. //---------------------------------------------------------------------------
  5755. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  5756. {
  5757. if (Message.EndSession && IsApplicationMinimized())
  5758. {
  5759. // WORKAROUND
  5760. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  5761. // when it receives WM_ENDSESSION,
  5762. // but that sometimes (particularly when application is minimized) cause crashes.
  5763. // Crash popups message that blocks log off.
  5764. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  5765. // so we call ExitProcess() immediately, not even trying to cleanup.
  5766. // It still causes beep, so there's likely some popup, but it does not block
  5767. // log off.
  5768. ExitProcess(0);
  5769. }
  5770. TForm::Dispatch(&Message);
  5771. }
  5772. #ifdef _DEBUG
  5773. //---------------------------------------------------------------------------
  5774. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  5775. {
  5776. TForm::Dispatch(&Message);
  5777. }
  5778. #endif
  5779. //---------------------------------------------------------------------------
  5780. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  5781. {
  5782. }
  5783. //---------------------------------------------------------------------------
  5784. void __fastcall TCustomScpExplorerForm::DoShow()
  5785. {
  5786. // only now are the controls resized finally, so the size constraints
  5787. // will not conflict with possibly very small window size
  5788. RestoreFormParams();
  5789. FixControlsPlacement();
  5790. if (Position == poDefaultPosOnly)
  5791. {
  5792. CutFormToDesktop(this);
  5793. }
  5794. TForm::DoShow();
  5795. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  5796. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  5797. if (Terminal == NULL)
  5798. {
  5799. StartingDisconnected();
  5800. }
  5801. FShowing = true;
  5802. }
  5803. //---------------------------------------------------------------------------
  5804. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  5805. {
  5806. DoTerminalListChanged(true);
  5807. }
  5808. //---------------------------------------------------------------------------
  5809. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  5810. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  5811. TNotifyEvent OnBalloonClick, TObject * UserData)
  5812. {
  5813. bool Do;
  5814. UnicodeString Message;
  5815. if (E == NULL)
  5816. {
  5817. Message = Str;
  5818. Do = true;
  5819. }
  5820. else
  5821. {
  5822. Do = ExceptionMessage(E, Message);
  5823. }
  5824. if (Do && WinConfiguration->BalloonNotifications)
  5825. {
  5826. UnicodeString Title;
  5827. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  5828. {
  5829. Message = TrimLeft(Message);
  5830. }
  5831. else
  5832. {
  5833. Message = UnformatMessage(Message);
  5834. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  5835. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  5836. Title = LoadResourceString(Captions[Type]);
  5837. if (Terminal != NULL)
  5838. {
  5839. Title = FORMAT(L"%s - %s",
  5840. (TTerminalManager::Instance()->TerminalTitle(Terminal), Title));
  5841. }
  5842. }
  5843. if (Seconds == 0)
  5844. {
  5845. Seconds = WinConfiguration->NotificationsTimeout;
  5846. }
  5847. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  5848. }
  5849. }
  5850. //---------------------------------------------------------------------------
  5851. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  5852. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  5853. UnicodeString HelpKeyword, const TMessageParams * Params,
  5854. TTerminal * Terminal)
  5855. {
  5856. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  5857. (FOnFeedSynchronizeError != NULL)) &&
  5858. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  5859. {
  5860. if (FOnFeedSynchronizeError != NULL)
  5861. {
  5862. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  5863. }
  5864. else
  5865. {
  5866. DebugAssert(FErrorList != NULL);
  5867. TStringList * MoreMessagesCopy = NULL;
  5868. if (MoreMessages)
  5869. {
  5870. MoreMessagesCopy = new TStringList();
  5871. MoreMessagesCopy->Assign(MoreMessages);
  5872. }
  5873. FErrorList->AddObject(Message, MoreMessagesCopy);
  5874. }
  5875. PopupTrayBalloon(Terminal, Message, Type);
  5876. return ContinueAnswer(Answers);
  5877. }
  5878. else
  5879. {
  5880. bool UseBalloon = FTrayIcon->Visible;
  5881. if (UseBalloon)
  5882. {
  5883. PopupTrayBalloon(Terminal, Message, Type);
  5884. }
  5885. unsigned int Result;
  5886. try
  5887. {
  5888. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  5889. }
  5890. __finally
  5891. {
  5892. // cancel only balloon we popped up, otherwise we may cancel notification
  5893. // balloon that was there before the message dialog
  5894. // (such as "dd confirmation opt in balloon)
  5895. if (UseBalloon)
  5896. {
  5897. FTrayIcon->CancelBalloon();
  5898. }
  5899. }
  5900. return Result;
  5901. }
  5902. }
  5903. //---------------------------------------------------------------------------
  5904. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  5905. TTerminal * Terminal, Exception * E)
  5906. {
  5907. if (FTrayIcon->Visible)
  5908. {
  5909. PopupTrayBalloon(Terminal, L"", qtError, E);
  5910. }
  5911. // particularly prevent opening new session from jump list,
  5912. // while exception is shown
  5913. NonVisualDataModule->StartBusy();
  5914. try
  5915. {
  5916. ShowExtendedExceptionEx(Terminal, E);
  5917. }
  5918. __finally
  5919. {
  5920. NonVisualDataModule->EndBusy();
  5921. FTrayIcon->CancelBalloon();
  5922. }
  5923. }
  5924. //---------------------------------------------------------------------------
  5925. void __fastcall TCustomScpExplorerForm::TerminalReady()
  5926. {
  5927. // cannot rely on active page being page for active terminal,
  5928. // as it can happen that active page is the "new session" page
  5929. // (e.g. when reconnecting active terminal, while login dialog
  5930. // invoked from "new session" page is modal)
  5931. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5932. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  5933. }
  5934. //---------------------------------------------------------------------------
  5935. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  5936. TTerminal * Terminal, Exception * E)
  5937. {
  5938. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  5939. if (!Terminal->Active)
  5940. {
  5941. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  5942. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  5943. {
  5944. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  5945. }
  5946. }
  5947. }
  5948. //---------------------------------------------------------------------------
  5949. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  5950. UnicodeString Message, TQueryType Type,
  5951. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  5952. {
  5953. if ((E == NULL) ||
  5954. ExceptionMessage(E, Message))
  5955. {
  5956. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  5957. if (Important)
  5958. {
  5959. Seconds *= 5;
  5960. }
  5961. UnicodeString NoteMessage(UnformatMessage(Message));
  5962. if (Terminal != NULL)
  5963. {
  5964. NoteMessage = FORMAT(L"%s: %s",
  5965. (TTerminalManager::Instance()->TerminalTitle(Terminal), NoteMessage));
  5966. }
  5967. if (WinConfiguration->BalloonNotifications)
  5968. {
  5969. AddNote(NoteMessage);
  5970. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  5971. }
  5972. else
  5973. {
  5974. FlashOnBackground();
  5975. PostNote(NoteMessage, Seconds, OnClick, UserData);
  5976. }
  5977. }
  5978. }
  5979. //---------------------------------------------------------------------------
  5980. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  5981. {
  5982. RestoreApp();
  5983. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  5984. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  5985. !NonVisualDataModule->Busy)
  5986. {
  5987. TTerminal * Terminal = TerminalNoteData->Terminal;
  5988. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5989. if (!ComponentVisible[fcQueueView])
  5990. {
  5991. ToggleQueueVisibility();
  5992. GoToQueue();
  5993. }
  5994. }
  5995. }
  5996. //---------------------------------------------------------------------------
  5997. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  5998. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  5999. {
  6000. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6001. UnicodeString Message;
  6002. TNotifyEvent OnClick = NULL;
  6003. TObject * UserData = NULL;
  6004. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6005. switch (Event)
  6006. {
  6007. case qeEmptyButMonitored:
  6008. if ((ATerminal != Terminal) || QueueInvisible)
  6009. {
  6010. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6011. OnClick = QueueEmptyNoteClicked;
  6012. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6013. TerminalNoteData->Terminal = ATerminal;
  6014. UserData = TerminalNoteData;
  6015. }
  6016. break;
  6017. case qeEmpty:
  6018. OperationComplete(ManagedTerminal->QueueOperationStart);
  6019. break;
  6020. case qePendingUserAction:
  6021. if ((ATerminal != Terminal) ||
  6022. (QueueInvisible && !IsQueueAutoPopup()))
  6023. {
  6024. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6025. }
  6026. break;
  6027. default:
  6028. DebugFail();
  6029. }
  6030. if (!Message.IsEmpty())
  6031. {
  6032. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6033. }
  6034. }
  6035. //---------------------------------------------------------------------------
  6036. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6037. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6038. {
  6039. if (FDDExtMapFile != NULL)
  6040. {
  6041. CloseHandle(FDDExtMapFile);
  6042. FDDExtMapFile = NULL;
  6043. }
  6044. if (WinConfiguration->DDExtEnabled)
  6045. {
  6046. if (!WinConfiguration->DDExtInstalled)
  6047. {
  6048. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtNotInstalled");
  6049. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_NOT_INSTALLED2), HELP_DRAGEXT_TARGET_NOT_INSTALLED);
  6050. }
  6051. DDExtInitDrag(FileList, Created);
  6052. }
  6053. }
  6054. //---------------------------------------------------------------------------
  6055. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  6056. bool & Created)
  6057. {
  6058. FDragExtFakeDirectory =
  6059. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6060. if (!ForceDirectories(ApiPath(FDragExtFakeDirectory)))
  6061. {
  6062. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  6063. }
  6064. FileList->AddItem(NULL, FDragExtFakeDirectory);
  6065. Created = true;
  6066. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6067. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6068. {
  6069. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6070. TDragExtCommStruct* CommStruct;
  6071. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6072. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6073. DebugAssert(CommStruct != NULL);
  6074. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6075. CommStruct->Dragging = true;
  6076. wcsncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  6077. LENOF(CommStruct->DropDest));
  6078. NULL_TERMINATE(CommStruct->DropDest);
  6079. UnmapViewOfFile(CommStruct);
  6080. }
  6081. FDDMoveSlipped = false;
  6082. }
  6083. //---------------------------------------------------------------------------
  6084. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6085. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6086. {
  6087. bool Result;
  6088. if (Sender == RemoteDirView)
  6089. {
  6090. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6091. }
  6092. else
  6093. {
  6094. DebugAssert(Sender == RemoteDriveView);
  6095. TStrings * FileList = RemoteDriveView->DragFileList();
  6096. try
  6097. {
  6098. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6099. }
  6100. __finally
  6101. {
  6102. delete FileList;
  6103. }
  6104. }
  6105. if (FDDTargetControl == RemoteDriveView)
  6106. {
  6107. RemoteDriveView->UpdateDropTarget();
  6108. }
  6109. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6110. // or from tree view to dir view.
  6111. // foMove happens when file/dir is dragged from remote tree view outside of
  6112. // application via dragex
  6113. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6114. (DropSourceControl == RemoteDriveView))
  6115. {
  6116. RemoteDriveView->UpdateDropSource();
  6117. }
  6118. return Result;
  6119. }
  6120. //---------------------------------------------------------------------------
  6121. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6122. {
  6123. // This also handles drops of remote files to queue.
  6124. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6125. SAFE_DESTROY(FDDFileList);
  6126. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6127. {
  6128. try
  6129. {
  6130. TDragResult DDResult = (Sender == RemoteDirView) ?
  6131. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6132. // Focus is moved to the target application,
  6133. // but as we are going to present the UI, we need to steal the focus back.
  6134. // This most likely won't work though (windows does not allow application
  6135. // to steal focus most of the time)
  6136. Application->BringToFront();
  6137. // On older version of Windows we never got drMove here, see also comment below.
  6138. // On Windows 10, we get the "move".
  6139. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6140. {
  6141. UnicodeString TargetDirectory;
  6142. TFileOperation Operation;
  6143. // drInvalid may mean drMove, see comment below
  6144. switch (DDResult)
  6145. {
  6146. case drCopy:
  6147. Operation = foCopy;
  6148. break;
  6149. case drMove:
  6150. Operation = foMove;
  6151. break;
  6152. default:
  6153. DebugFail();
  6154. case drInvalid:
  6155. // prefer "copy" for safety
  6156. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6157. break;
  6158. }
  6159. if (FDDMoveSlipped)
  6160. {
  6161. Operation = foMove;
  6162. }
  6163. TTransferOperationParam Param;
  6164. bool Internal;
  6165. bool ForceQueue;
  6166. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, Internal))
  6167. {
  6168. // we get drInvalid both if d&d was intercepted by ddext,
  6169. // and when users drops on no-drop location.
  6170. // we tell the difference by existence of response from ddext,
  6171. // so we ignore absence of response in this case
  6172. if (DDResult != drInvalid)
  6173. {
  6174. // here we know that the extension is installed,
  6175. // as it is checked as soon as drag&drop starts from
  6176. // RemoteFileControlDDCreateDragFileList
  6177. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6178. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6179. }
  6180. }
  6181. else
  6182. {
  6183. // download using ddext
  6184. Param.Temp = false;
  6185. Param.DragDrop = true;
  6186. if (ForceQueue)
  6187. {
  6188. Param.Queue = asOn;
  6189. }
  6190. if (Sender == RemoteDirView)
  6191. {
  6192. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6193. }
  6194. if (RemoteFileControlFileOperation(Sender, Operation,
  6195. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6196. {
  6197. Configuration->Usage->Inc(
  6198. Internal ? L"DownloadsDragDropInternal" : L"DownloadsDragDropExternalExt");
  6199. }
  6200. }
  6201. }
  6202. }
  6203. __finally
  6204. {
  6205. CloseHandle(FDDExtMapFile);
  6206. FDDExtMapFile = NULL;
  6207. RemoveDir(ApiPath(FDragExtFakeDirectory));
  6208. FDragExtFakeDirectory = L"";
  6209. }
  6210. }
  6211. if (!FDragDropSshTerminate.IsEmpty())
  6212. {
  6213. throw ESshTerminate(NULL, FDragDropSshTerminate, FDragDropOnceDoneOperation);
  6214. }
  6215. }
  6216. //---------------------------------------------------------------------------
  6217. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6218. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  6219. {
  6220. HCURSOR SlippedCopyCursor;
  6221. FDDMoveSlipped =
  6222. (FDragMoveCursor != NULL) &&
  6223. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  6224. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  6225. FTerminal->IsCapable[fcRemoteMove]) ||
  6226. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  6227. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  6228. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  6229. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  6230. // Remember drop effect so we know (when user drops files), if we copy or move
  6231. FLastDropEffect = dwEffect;
  6232. }
  6233. //---------------------------------------------------------------------------
  6234. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6235. UnicodeString & Directory, bool & ForceQueue, bool & Internal)
  6236. {
  6237. bool Result;
  6238. if (FDDTargetControl == QueueView3)
  6239. {
  6240. Directory = DefaultDownloadTargetDirectory();
  6241. Result = true;
  6242. Internal = true;
  6243. ForceQueue = true;
  6244. }
  6245. else
  6246. {
  6247. ForceQueue = false;
  6248. Enabled = false;
  6249. try
  6250. {
  6251. int Timer = 0;
  6252. Result = false;
  6253. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6254. {
  6255. {
  6256. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6257. TDragExtCommStruct* CommStruct;
  6258. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6259. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6260. DebugAssert(CommStruct != NULL);
  6261. Result = !CommStruct->Dragging;
  6262. if (Result)
  6263. {
  6264. Directory = ExtractFilePath(CommStruct->DropDest);
  6265. Internal = false;
  6266. }
  6267. UnmapViewOfFile(CommStruct);
  6268. }
  6269. if (!Result)
  6270. {
  6271. Sleep(50);
  6272. Timer += 50;
  6273. Application->ProcessMessages();
  6274. }
  6275. }
  6276. }
  6277. __finally
  6278. {
  6279. Enabled = true;
  6280. }
  6281. }
  6282. return Result;
  6283. }
  6284. //---------------------------------------------------------------------------
  6285. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6286. const UnicodeString TempDir, int SecDelay)
  6287. {
  6288. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6289. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6290. if (FDelayedDeletionTimer == NULL)
  6291. {
  6292. DebugAssert(HandleAllocated());
  6293. FDelayedDeletionTimer = new TTimer(this);
  6294. FDelayedDeletionTimer->Interval = 10000;
  6295. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6296. }
  6297. else
  6298. {
  6299. FDelayedDeletionTimer->Enabled = true;
  6300. }
  6301. }
  6302. //---------------------------------------------------------------------------
  6303. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6304. {
  6305. DebugAssert(FDelayedDeletionList != NULL);
  6306. TDateTime N = Now();
  6307. TDateTime Alert;
  6308. UnicodeString Directory;
  6309. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6310. {
  6311. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6312. if ((N >= Alert) || (Sender == NULL))
  6313. {
  6314. Directory = FDelayedDeletionList->Strings[Index];
  6315. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6316. {
  6317. FDelayedDeletionList->Delete(Index);
  6318. }
  6319. }
  6320. }
  6321. if (FDelayedDeletionList->Count == 0)
  6322. {
  6323. FDelayedDeletionTimer->Enabled = false;
  6324. }
  6325. }
  6326. //---------------------------------------------------------------------------
  6327. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6328. {
  6329. if (IsFileControl(FDDTargetControl, osRemote) ||
  6330. (FDDTargetControl == SessionsPageControl))
  6331. {
  6332. TTerminal * TargetTerminal = NULL;
  6333. TFileOperation Operation = foNone;
  6334. if (FDDTargetControl == SessionsPageControl)
  6335. {
  6336. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6337. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6338. // do not allow dropping on the "+" tab
  6339. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6340. if (TargetTerminal != NULL)
  6341. {
  6342. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6343. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6344. {
  6345. Operation = foRemoteMove;
  6346. }
  6347. else
  6348. {
  6349. Operation = foRemoteCopy;
  6350. }
  6351. }
  6352. }
  6353. else
  6354. {
  6355. // when move from remote side is disabled, we allow copying inside the remote
  6356. // panel, but we interpret is as moving (we also slip in the move cursor)
  6357. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  6358. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  6359. FDDMoveSlipped))
  6360. {
  6361. Operation = foRemoteMove;
  6362. }
  6363. else if (FLastDropEffect == DROPEFFECT_COPY)
  6364. {
  6365. Operation = foRemoteCopy;
  6366. }
  6367. }
  6368. if (Operation != foNone)
  6369. {
  6370. RemoteFileControlFileOperation(DropSourceControl,
  6371. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6372. }
  6373. // abort drag&drop
  6374. Abort();
  6375. }
  6376. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6377. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6378. (FDDTargetControl != QueueView3))
  6379. {
  6380. DebugAssert(!FDragTempDir.IsEmpty());
  6381. TTransferType Type;
  6382. UnicodeString TempDir = FDragTempDir;
  6383. // We clear FDragTempDir before calling
  6384. // just in case it fail (raises exception)
  6385. FDragTempDir = L"";
  6386. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6387. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6388. // empty directory parameter means temp directory -> don't display it!
  6389. UnicodeString TargetDir = L"";
  6390. int Options = 0;
  6391. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6392. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6393. {
  6394. Abort();
  6395. }
  6396. // TargetDir is set when dropped on local file control
  6397. // (this was workaround for legacy dirview event handling, now it should be
  6398. // made prettier)
  6399. if (TargetDir.IsEmpty())
  6400. {
  6401. TargetDir = TempDir;
  6402. if (ForceDirectories(ApiPath(TargetDir)))
  6403. {
  6404. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6405. FPendingTempSpaceWarn = true;
  6406. try
  6407. {
  6408. FDragDropOperation = true;
  6409. int Params = cpTemporary |
  6410. (Type == ttMove ? cpDelete : 0);
  6411. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6412. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6413. }
  6414. __finally
  6415. {
  6416. FDragDropOperation = false;
  6417. FPendingTempSpaceWarn = false;
  6418. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6419. }
  6420. }
  6421. else
  6422. {
  6423. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6424. }
  6425. }
  6426. }
  6427. }
  6428. //---------------------------------------------------------------------------
  6429. void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
  6430. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params)
  6431. {
  6432. void * BatchStorage;
  6433. BatchStart(BatchStorage);
  6434. try
  6435. {
  6436. UpdateCopyParamCounters(*CopyParam);
  6437. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6438. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6439. {
  6440. RemoteDriveView->UpdateDropSource();
  6441. }
  6442. }
  6443. __finally
  6444. {
  6445. BatchEnd(BatchStorage);
  6446. }
  6447. }
  6448. //---------------------------------------------------------------------------
  6449. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6450. {
  6451. public:
  6452. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6453. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  6454. {
  6455. }
  6456. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  6457. {
  6458. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  6459. TDataObjectFilesEx::AllowData(FormatEtc);
  6460. }
  6461. };
  6462. //---------------------------------------------------------------------------
  6463. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  6464. TObject * Sender, TDataObject *& DataObject)
  6465. {
  6466. if (FDDExtMapFile != NULL)
  6467. {
  6468. TFileList * FileList = DragDropFiles(Sender)->FileList;
  6469. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  6470. {
  6471. Abort();
  6472. }
  6473. if (FileList->Count > 0)
  6474. {
  6475. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  6476. if (!FilesObject->IsValid(true, true))
  6477. {
  6478. FilesObject->_Release();
  6479. }
  6480. else
  6481. {
  6482. DataObject = FilesObject;
  6483. }
  6484. }
  6485. }
  6486. }
  6487. //---------------------------------------------------------------------------
  6488. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  6489. {
  6490. DebugFail();
  6491. }
  6492. //---------------------------------------------------------------------------
  6493. void __fastcall TCustomScpExplorerForm::GoToTree()
  6494. {
  6495. ComponentVisible[fcRemoteTree] = true;
  6496. RemoteDriveView->SetFocus();
  6497. }
  6498. //---------------------------------------------------------------------------
  6499. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6500. TPanelExport Export)
  6501. {
  6502. TCustomDirView * DirView = this->DirView(Side);
  6503. std::unique_ptr<TStrings> ExportData(new TStringList());
  6504. switch (Export)
  6505. {
  6506. case pePath:
  6507. ExportData->Add(DirView->PathName);
  6508. break;
  6509. case peFileList:
  6510. case peFullFileList:
  6511. {
  6512. bool FullPath = (Export == peFullFileList);
  6513. DirView->CreateFileList(false, FullPath, ExportData.get());
  6514. for (int Index = 0; Index < ExportData->Count; Index++)
  6515. {
  6516. if (ExportData->Strings[Index].Pos(L" ") > 0)
  6517. {
  6518. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  6519. }
  6520. }
  6521. }
  6522. break;
  6523. default:
  6524. DebugFail();
  6525. }
  6526. return ExportData.release();
  6527. }
  6528. //---------------------------------------------------------------------------
  6529. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6530. TPanelExport Export, TPanelExportDestination Destination)
  6531. {
  6532. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  6533. PanelExportStore(Side, Export, Destination, ExportData.get());
  6534. }
  6535. //---------------------------------------------------------------------------
  6536. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  6537. TPanelExport /*Export*/, TPanelExportDestination Destination,
  6538. TStrings * ExportData)
  6539. {
  6540. if (Destination == pedClipboard)
  6541. {
  6542. TInstantOperationVisualizer Visualizer;
  6543. CopyToClipboard(ExportData);
  6544. }
  6545. else
  6546. {
  6547. DebugFail();
  6548. }
  6549. }
  6550. //---------------------------------------------------------------------------
  6551. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  6552. {
  6553. TCustomDirView * DirView = this->DirView(Side);
  6554. TFileFilter Filter;
  6555. DefaultFileFilter(Filter);
  6556. Filter.Masks = DirView->Mask;
  6557. if (DoFilterMaskDialog(DirView, &Filter))
  6558. {
  6559. DirView->Mask = TFileMasks::NormalizeMask(Filter.Masks);
  6560. Configuration->Usage->Inc(L"Filters");
  6561. }
  6562. }
  6563. //---------------------------------------------------------------------------
  6564. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  6565. {
  6566. return FQueueController->DefaultOperation();
  6567. }
  6568. //---------------------------------------------------------------------------
  6569. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  6570. TQueueOperation Operation, void ** Param)
  6571. {
  6572. switch (Operation)
  6573. {
  6574. case qoPreferences:
  6575. return true;
  6576. case qoGoTo:
  6577. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  6578. case qoOnceEmpty:
  6579. return !FQueueController->Empty;
  6580. default:
  6581. return FQueueController->AllowOperation(Operation, Param);
  6582. }
  6583. }
  6584. //---------------------------------------------------------------------------
  6585. void __fastcall TCustomScpExplorerForm::GoToQueue()
  6586. {
  6587. if (DebugAlwaysTrue(QueueView3->Visible))
  6588. {
  6589. QueueView3->SetFocus();
  6590. }
  6591. }
  6592. //---------------------------------------------------------------------------
  6593. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  6594. TQueueOperation Operation, void * Param)
  6595. {
  6596. if (Operation == qoGoTo)
  6597. {
  6598. GoToQueue();
  6599. }
  6600. else if (Operation == qoPreferences)
  6601. {
  6602. PreferencesDialog(pmQueue);
  6603. }
  6604. else
  6605. {
  6606. FQueueController->ExecuteOperation(Operation, Param);
  6607. }
  6608. }
  6609. //---------------------------------------------------------------------------
  6610. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  6611. {
  6612. return (Queue != NULL) && Queue->Enabled;
  6613. }
  6614. //---------------------------------------------------------------------------
  6615. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  6616. {
  6617. DebugAssert(Queue != NULL);
  6618. if (Queue != NULL)
  6619. {
  6620. Queue->Enabled = !Queue->Enabled;
  6621. }
  6622. }
  6623. //---------------------------------------------------------------------------
  6624. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  6625. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  6626. {
  6627. FQueueActedItem = QueueView3->ItemFocused;
  6628. }
  6629. //---------------------------------------------------------------------------
  6630. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  6631. {
  6632. return TopDock->Height + QueueSplitter->Height;
  6633. }
  6634. //---------------------------------------------------------------------------
  6635. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  6636. TObject * /*Sender*/, int & NewSize, bool & Accept)
  6637. {
  6638. // when queue is hidden by double-clicking splitter, stray attempt to
  6639. // resize the panel with strange value arrives, make sure it is ignored
  6640. if (ComponentVisible[fcQueueView])
  6641. {
  6642. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  6643. RemotePanel->Constraints->MinHeight;
  6644. if (NewSize > HeightLimit)
  6645. {
  6646. NewSize = HeightLimit;
  6647. }
  6648. }
  6649. else
  6650. {
  6651. Accept = false;
  6652. }
  6653. }
  6654. //---------------------------------------------------------------------------
  6655. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  6656. TDragObject *& /*DragObject*/)
  6657. {
  6658. FQueueActedItem = QueueView3->ItemFocused;
  6659. }
  6660. //---------------------------------------------------------------------------
  6661. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  6662. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  6663. {
  6664. Accept = true;
  6665. if (Source == QueueView3)
  6666. {
  6667. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  6668. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  6669. if (Accept)
  6670. {
  6671. TQueueItemProxy * QueueItem;
  6672. TQueueItemProxy * DestQueueItem;
  6673. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6674. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  6675. Accept = (QueueItem != DestQueueItem) &&
  6676. (QueueItem->Status == TQueueItem::qsPending) &&
  6677. (DestQueueItem->Status == TQueueItem::qsPending);
  6678. }
  6679. }
  6680. }
  6681. //---------------------------------------------------------------------------
  6682. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  6683. TObject * /*Source*/, int /*X*/, int /*Y*/)
  6684. {
  6685. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  6686. {
  6687. TQueueItemProxy * QueueItem;
  6688. TQueueItemProxy * DestQueueItem;
  6689. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6690. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  6691. QueueItem->Move(DestQueueItem);
  6692. }
  6693. }
  6694. //---------------------------------------------------------------------------
  6695. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  6696. {
  6697. if ((QueueView3->ItemFocused == NULL) &&
  6698. (QueueView3->Items->Count > 0))
  6699. {
  6700. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  6701. }
  6702. QueueLabelUpdateStatus();
  6703. }
  6704. //---------------------------------------------------------------------------
  6705. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  6706. {
  6707. QueueLabelUpdateStatus();
  6708. }
  6709. //---------------------------------------------------------------------------
  6710. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  6711. {
  6712. QueueLabel->UpdateStatus();
  6713. }
  6714. //---------------------------------------------------------------------------
  6715. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  6716. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  6717. {
  6718. if (Selected)
  6719. {
  6720. NonVisualDataModule->UpdateNonVisibleActions();
  6721. }
  6722. }
  6723. //---------------------------------------------------------------------------
  6724. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  6725. {
  6726. TDragDropFilesEx * Result = NULL;
  6727. if (Sender == SessionsPageControl)
  6728. {
  6729. Result = FSessionsDragDropFilesEx;
  6730. }
  6731. else if (Sender == QueueView3)
  6732. {
  6733. Result = FQueueDragDropFilesEx;
  6734. }
  6735. else
  6736. {
  6737. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  6738. if (DirView != NULL)
  6739. {
  6740. Result = DirView->DragDropFilesEx;
  6741. }
  6742. else
  6743. {
  6744. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  6745. if (DriveView != NULL)
  6746. {
  6747. Result = DriveView->DragDropFilesEx;
  6748. }
  6749. }
  6750. }
  6751. DebugAssert(Result != NULL);
  6752. return Result;
  6753. }
  6754. //---------------------------------------------------------------------------
  6755. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  6756. {
  6757. return (DView->SelCount == DView->FilesCount);
  6758. }
  6759. //---------------------------------------------------------------------------
  6760. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  6761. {
  6762. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  6763. }
  6764. //---------------------------------------------------------------------------
  6765. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  6766. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue)
  6767. {
  6768. TFileOperation Operation;
  6769. switch (Effect)
  6770. {
  6771. case DROPEFFECT_MOVE:
  6772. Operation = foMove;
  6773. break;
  6774. case DROPEFFECT_COPY:
  6775. // occures on WinXP (reported by user)
  6776. default:
  6777. Operation = foCopy;
  6778. break;
  6779. };
  6780. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  6781. // see a comment in TUnixDirView::PerformItemDragDropOperation
  6782. if (DragDropFilesEx->FileList->Count > 0)
  6783. {
  6784. TStrings * FileList = new TStringList();
  6785. try
  6786. {
  6787. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  6788. {
  6789. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  6790. }
  6791. FDragDropOperation = true;
  6792. TTransferOperationParam Param;
  6793. Param.TargetDirectory = TargetPath;
  6794. // upload, no temp dirs
  6795. Param.Temp = false;
  6796. Param.DragDrop = true;
  6797. Param.Options =
  6798. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  6799. if (ForceQueue)
  6800. {
  6801. Param.Queue = asOn;
  6802. }
  6803. if (ExecuteFileOperation(Operation, osLocal, FileList,
  6804. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6805. {
  6806. if (IsFileControl(DropSourceControl, osLocal))
  6807. {
  6808. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  6809. }
  6810. else
  6811. {
  6812. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  6813. }
  6814. }
  6815. }
  6816. __finally
  6817. {
  6818. FDragDropOperation = false;
  6819. delete FileList;
  6820. }
  6821. }
  6822. }
  6823. //---------------------------------------------------------------------------
  6824. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  6825. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  6826. UnicodeString TargetPath, bool & /*DoOperation*/)
  6827. {
  6828. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false);
  6829. }
  6830. //---------------------------------------------------------------------------
  6831. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  6832. TObject * Sender, int grfKeyState, int & dwEffect)
  6833. {
  6834. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  6835. if ((dwEffect != DROPEFFECT_None) &&
  6836. IsFileControl(DropSourceControl, osRemote))
  6837. {
  6838. // do not allow drop on remote panel (on free space, still allow drop on directories)
  6839. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  6840. (RemoteDirView->DropTarget == NULL))
  6841. {
  6842. dwEffect = DROPEFFECT_None;
  6843. }
  6844. else
  6845. {
  6846. if (dwEffect == DROPEFFECT_Copy)
  6847. {
  6848. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  6849. // currently we support copying always (at least via temporary directory);
  6850. // remove associated checks once this all proves stable and working
  6851. bool CopyCapable = true;
  6852. // if we do not support neither of operations, there's no discussion
  6853. if (!MoveCapable && !CopyCapable)
  6854. {
  6855. dwEffect = DROPEFFECT_None;
  6856. }
  6857. // when moving is disabled, we need to keep effect to "copy",
  6858. // which will be later interpretted as move (with slipped-in cursor)
  6859. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  6860. {
  6861. // no-op, keep copy
  6862. }
  6863. else
  6864. {
  6865. // The default effect inside remote panel is move,
  6866. // unless we do not support it, but support copy
  6867. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  6868. {
  6869. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  6870. }
  6871. else
  6872. {
  6873. // with ctrl-down, we want copy unless it is not supported
  6874. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  6875. }
  6876. }
  6877. }
  6878. }
  6879. }
  6880. }
  6881. //---------------------------------------------------------------------------
  6882. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  6883. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  6884. {
  6885. if (FDDTotalSize >= 0)
  6886. {
  6887. if (File->IsDirectory)
  6888. {
  6889. FDDTotalSize = -1;
  6890. }
  6891. else
  6892. {
  6893. FDDTotalSize += File->Size;
  6894. }
  6895. }
  6896. DebugAssert(!FDragTempDir.IsEmpty());
  6897. // TODO: this is quite ineffective
  6898. // TODO: what if invalid character replacement is disabled?
  6899. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  6900. UnicodeString TransferFileName;
  6901. if (Sender == RemoteDriveView)
  6902. {
  6903. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  6904. }
  6905. else
  6906. {
  6907. TransferFileName = File->FileName;
  6908. }
  6909. FDDFileList->AddObject(TransferFileName, File);
  6910. }
  6911. //---------------------------------------------------------------------------
  6912. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  6913. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  6914. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  6915. {
  6916. // sometimes we do not get DDEnd so the list is not released
  6917. SAFE_DESTROY(FDDFileList);
  6918. FDDFileList = new TStringList();
  6919. FDragTempDir = WinConfiguration->TemporaryDir();
  6920. FDDTotalSize = 0;
  6921. FDragDropSshTerminate = L"";
  6922. FDragDropOnceDoneOperation = odoIdle;
  6923. }
  6924. //---------------------------------------------------------------------------
  6925. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  6926. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  6927. HRESULT & Result)
  6928. {
  6929. if (Result == DRAGDROP_S_DROP)
  6930. {
  6931. try
  6932. {
  6933. GlobalDragImageList->HideDragImage();
  6934. try
  6935. {
  6936. RemoteFileControlDDTargetDrop();
  6937. }
  6938. catch(ESshTerminate & E)
  6939. {
  6940. DebugAssert(E.MoreMessages == NULL); // not supported
  6941. DebugAssert(!E.Message.IsEmpty());
  6942. FDragDropSshTerminate = E.Message;
  6943. FDragDropOnceDoneOperation = E.Operation;
  6944. }
  6945. }
  6946. catch (Exception &E)
  6947. {
  6948. // If downloading fails we need to cancel drag&drop, otherwise
  6949. // Explorer shows error
  6950. // But by the way exception probably never reach this point as
  6951. // it's catched on way.
  6952. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  6953. Result = DRAGDROP_S_CANCEL;
  6954. ShowExtendedException(Terminal, &E);
  6955. }
  6956. }
  6957. }
  6958. //---------------------------------------------------------------------------
  6959. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  6960. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  6961. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  6962. {
  6963. TFileMasks::TParams MaskParams;
  6964. MaskParams.Size = Size;
  6965. MaskParams.Modification = Modification;
  6966. // this does not re-parse the mask if it is the same as the last time
  6967. FDirViewMatchMask = Masks;
  6968. bool ImplicitMatch;
  6969. Matches =
  6970. // RecurseInclude parameter has no effect as the Path is empty
  6971. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  6972. (AllowImplicitMatches || !ImplicitMatch);
  6973. }
  6974. //---------------------------------------------------------------------------
  6975. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  6976. TObject * Sender, TListItem * Item, WORD & Indexes)
  6977. {
  6978. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  6979. UnicodeString Ext;
  6980. if (DirView == RemoteDirView)
  6981. {
  6982. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  6983. }
  6984. else
  6985. {
  6986. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  6987. }
  6988. if (SameText(Ext, Configuration->PartialExt))
  6989. {
  6990. Indexes |= oiPartial;
  6991. }
  6992. }
  6993. //---------------------------------------------------------------------------
  6994. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  6995. {
  6996. return
  6997. DirViewEnabled(osCurrent) &&
  6998. DirView(osCurrent)->CanPasteFromClipBoard();
  6999. }
  7000. //---------------------------------------------------------------------------
  7001. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7002. {
  7003. bool Result = false;
  7004. if (CanPasteToDirViewFromClipBoard())
  7005. {
  7006. Result = true;
  7007. }
  7008. else
  7009. {
  7010. UnicodeString ClipboardText;
  7011. if (NonEmptyTextFromClipboard(ClipboardText))
  7012. {
  7013. if (StoredSessions->IsUrl(ClipboardText))
  7014. {
  7015. Result = true;
  7016. }
  7017. else
  7018. {
  7019. Result = DirViewEnabled(osCurrent);
  7020. }
  7021. }
  7022. }
  7023. return Result;
  7024. }
  7025. //---------------------------------------------------------------------------
  7026. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7027. {
  7028. if (CanPasteToDirViewFromClipBoard())
  7029. {
  7030. DirView(osCurrent)->PasteFromClipBoard();
  7031. }
  7032. else
  7033. {
  7034. UnicodeString ClipboardText;
  7035. if (NonEmptyTextFromClipboard(ClipboardText))
  7036. {
  7037. if (StoredSessions->IsUrl(ClipboardText))
  7038. {
  7039. NewSession(false, ClipboardText);
  7040. }
  7041. else
  7042. {
  7043. DirView(osCurrent)->Path = ClipboardText;
  7044. }
  7045. }
  7046. }
  7047. }
  7048. //---------------------------------------------------------------------------
  7049. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7050. {
  7051. // TBD
  7052. }
  7053. //---------------------------------------------------------------------------
  7054. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7055. {
  7056. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7057. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7058. {
  7059. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7060. UnicodeString Ext;
  7061. if (GetSide(osCurrent) == osRemote)
  7062. {
  7063. Ext = UnixExtractFileExt(FileName);
  7064. }
  7065. else
  7066. {
  7067. Ext = ExtractFileExt(FileName);
  7068. }
  7069. if (Ext.IsEmpty())
  7070. {
  7071. Ext = L".";
  7072. }
  7073. TFileFilter Filter;
  7074. Filter.Masks = FORMAT(L"*%s", (Ext));
  7075. Filter.Directories = false;
  7076. CurrentDirView->SelectFiles(Filter, Select);
  7077. }
  7078. }
  7079. //---------------------------------------------------------------------------
  7080. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7081. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7082. {
  7083. UnicodeString Result;
  7084. if ((Side == osRemote) && (Terminal == NULL))
  7085. {
  7086. // noop
  7087. }
  7088. else
  7089. {
  7090. Result =
  7091. FMTLOAD(FILE_INFO_FORMAT,
  7092. (FormatBytes(FileInfo.SelectedSize),
  7093. FormatBytes(FileInfo.FilesSize),
  7094. FormatNumber(FileInfo.SelectedCount),
  7095. FormatNumber(FileInfo.FilesCount)));
  7096. }
  7097. return Result;
  7098. }
  7099. //---------------------------------------------------------------------------
  7100. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7101. TTBXStatusPanel * Panel, TOperationSide Side)
  7102. {
  7103. if (Panel->Index == 1)
  7104. {
  7105. ToggleShowHiddenFiles();
  7106. }
  7107. else if (Panel->Index == 2)
  7108. {
  7109. Filter(Side);
  7110. }
  7111. }
  7112. //---------------------------------------------------------------------------
  7113. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7114. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7115. {
  7116. DebugAssert(!StatusBar->SimplePanel);
  7117. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7118. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7119. }
  7120. //---------------------------------------------------------------------------
  7121. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7122. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7123. {
  7124. DebugAssert(StatusBar->Panels->Count >= 3);
  7125. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7126. if (FileInfo.HiddenCount > 0)
  7127. {
  7128. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7129. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7130. }
  7131. else
  7132. {
  7133. HiddenFilesPanel->ViewPriority = 0;
  7134. // not really necessary, just to cleanup no-longer-valid data
  7135. HiddenFilesPanel->Caption = L"";
  7136. }
  7137. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7138. if (FileInfo.FilteredCount > 0)
  7139. {
  7140. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7141. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7142. }
  7143. else
  7144. {
  7145. FilteredFilesPanel->ViewPriority = 0;
  7146. // not really necessary, just to cleanup no-longer-valid data
  7147. FilteredFilesPanel->Caption = L"";
  7148. }
  7149. }
  7150. //---------------------------------------------------------------------------
  7151. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7152. TObject * /*Sender*/)
  7153. {
  7154. if (RemoteDirView->Enabled)
  7155. {
  7156. RemoteDirView->SetFocus();
  7157. }
  7158. }
  7159. //---------------------------------------------------------------------------
  7160. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7161. {
  7162. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7163. switch (Config.Show)
  7164. {
  7165. case qvShow:
  7166. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7167. {
  7168. Config.Show = qvHide;
  7169. }
  7170. else
  7171. {
  7172. Config.Show = Config.LastHideShow;
  7173. }
  7174. break;
  7175. case qvHideWhenEmpty:
  7176. if (ComponentVisible[fcQueueView])
  7177. {
  7178. Config.Show = qvHide;
  7179. }
  7180. else
  7181. {
  7182. Config.LastHideShow = Config.Show;
  7183. Config.Show = qvShow;
  7184. }
  7185. break;
  7186. case qvHide:
  7187. Config.LastHideShow = Config.Show;
  7188. Config.Show = qvShow;
  7189. break;
  7190. }
  7191. WinConfiguration->QueueView = Config;
  7192. }
  7193. //---------------------------------------------------------------------------
  7194. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7195. {
  7196. UnicodeString Result;
  7197. if (FTerminal != NULL)
  7198. {
  7199. switch (WinConfiguration->PathInCaption)
  7200. {
  7201. case picShort:
  7202. {
  7203. Result = UnixExtractFileName(FTerminal->CurrentDirectory);
  7204. if (Result.IsEmpty())
  7205. {
  7206. Result = FTerminal->CurrentDirectory;
  7207. }
  7208. }
  7209. break;
  7210. case picFull:
  7211. Result = FTerminal->CurrentDirectory;
  7212. break;
  7213. }
  7214. }
  7215. return Result;
  7216. }
  7217. //---------------------------------------------------------------------------
  7218. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7219. {
  7220. TTerminalManager::Instance()->UpdateAppTitle();
  7221. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7222. // background to gray on Windows 7 (works on Windows 10).
  7223. // See also EnableControl
  7224. if (Showing)
  7225. {
  7226. bool HasTerminal = (Terminal != NULL);
  7227. if (HasTerminal)
  7228. {
  7229. if (!RemoteDirView->Enabled)
  7230. {
  7231. RemoteDirView->Enabled = true;
  7232. if (FRemoteDirViewWasFocused)
  7233. {
  7234. ActiveControl = RemoteDirView;
  7235. }
  7236. }
  7237. RemoteDriveView->Enabled = true;
  7238. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  7239. RemoteDriveView->Color = RemoteDirView->Color;
  7240. }
  7241. else
  7242. {
  7243. if (RemoteDirView->Enabled)
  7244. {
  7245. // This is first called when the form is being constructed
  7246. // (not anymore due to Showing test above)
  7247. // but the false is overriden in the constructor later.
  7248. // An even later in TScpCommanderForm::DoShow()
  7249. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7250. EnableControl(RemoteDirView, false);
  7251. }
  7252. EnableControl(RemoteDriveView, false);
  7253. }
  7254. EnableControl(QueueView3, HasTerminal);
  7255. QueueLabelUpdateStatus();
  7256. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7257. }
  7258. }
  7259. //---------------------------------------------------------------------------
  7260. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7261. {
  7262. UpdateControls();
  7263. }
  7264. //---------------------------------------------------------------------------
  7265. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7266. TObject * Sender)
  7267. {
  7268. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7269. DebugAssert(DirView != NULL);
  7270. DoDirViewLoaded(DirView);
  7271. TransferPresetAutoSelect();
  7272. }
  7273. //---------------------------------------------------------------------------
  7274. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7275. {
  7276. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7277. // first run after installation
  7278. if (double(Updates.LastCheck) == 0)
  7279. {
  7280. // make sure next time there will be an update (if enabled)
  7281. Updates.LastCheck = TDateTime(1);
  7282. WinConfiguration->Updates = Updates;
  7283. }
  7284. else if ((double(Updates.Period) > 0) &&
  7285. (Now() - Updates.LastCheck >= Updates.Period))
  7286. {
  7287. StartUpdateThread(UpdatesChecked);
  7288. }
  7289. }
  7290. //---------------------------------------------------------------------------
  7291. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7292. {
  7293. UnicodeString Message;
  7294. bool New;
  7295. TQueryType Type;
  7296. GetUpdatesMessage(Message, New, Type, false);
  7297. if (!Message.IsEmpty())
  7298. {
  7299. if (New)
  7300. {
  7301. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7302. }
  7303. if (!New && (Type != qtWarning))
  7304. {
  7305. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7306. }
  7307. else
  7308. {
  7309. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7310. }
  7311. if (New)
  7312. {
  7313. Configuration->Usage->Inc(L"UpdateNotifications");
  7314. }
  7315. }
  7316. }
  7317. //---------------------------------------------------------------------------
  7318. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7319. {
  7320. RestoreApp();
  7321. bool CanDisplay = !NonVisualDataModule->Busy;
  7322. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7323. {
  7324. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7325. }
  7326. if (CanDisplay)
  7327. {
  7328. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7329. CheckForUpdates(true);
  7330. }
  7331. else
  7332. {
  7333. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7334. }
  7335. }
  7336. //---------------------------------------------------------------------------
  7337. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7338. TCopyParamRuleData & Data)
  7339. {
  7340. DebugAssert(Terminal != NULL);
  7341. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7342. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7343. Data.RemoteDirectory = RemoteDirView->PathName;
  7344. }
  7345. //---------------------------------------------------------------------------
  7346. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7347. {
  7348. // Terminal can be null when we are changing local directory implicitly,
  7349. // because it has been deleted, while no session is connected
  7350. // (Login dialog is open)
  7351. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7352. {
  7353. TCopyParamRuleData Data;
  7354. GetTransferPresetAutoSelectData(Data);
  7355. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7356. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7357. if (CopyParamIndex < 0)
  7358. {
  7359. // there is no preset that matches autoselection
  7360. // set preset that we consider "default"
  7361. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7362. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7363. }
  7364. else
  7365. {
  7366. // there is preset matching autoselection
  7367. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7368. if (CopyParamName == FCopyParamAutoSelected)
  7369. {
  7370. // autoselected the same preset as the last time
  7371. // make no change (i.e. preserve custom user preset, if any)
  7372. }
  7373. else
  7374. {
  7375. // autoselected the different preset then the last time (or there
  7376. // was default preset set)
  7377. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7378. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7379. }
  7380. }
  7381. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7382. {
  7383. if (CopyParamIndex >= 0)
  7384. {
  7385. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7386. }
  7387. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7388. try
  7389. {
  7390. int Fmt =
  7391. (CopyParamIndex < 0) ?
  7392. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7393. COPY_PARAM_AUTOSELECTED;
  7394. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7395. Data->Message = MainInstructions(Message);
  7396. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7397. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7398. CopyParamAttrs);
  7399. if (CopyParamIndex >= 0)
  7400. {
  7401. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7402. Info = FORMAT(L"%s\n \n%s", (Info,
  7403. FMTLOAD(COPY_PARAM_RULE,
  7404. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  7405. }
  7406. Data->Message += L"\n\n" + Info;
  7407. if (WinConfiguration->CopyParamAutoSelectNotice)
  7408. {
  7409. TransferPresetNoteMessage(Data, true);
  7410. }
  7411. else
  7412. {
  7413. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  7414. Data = NULL; // ownership passed
  7415. }
  7416. }
  7417. __finally
  7418. {
  7419. delete Data;
  7420. }
  7421. }
  7422. }
  7423. }
  7424. //---------------------------------------------------------------------------
  7425. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  7426. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  7427. {
  7428. DebugAssert(NoteData != NULL);
  7429. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  7430. TQueryButtonAlias Aliases[1];
  7431. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  7432. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  7433. Params.Aliases = Aliases;
  7434. Params.AliasesCount = LENOF(Aliases);
  7435. unsigned int Result =
  7436. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  7437. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  7438. switch (Result)
  7439. {
  7440. case qaNeverAskAgain:
  7441. DebugAssert(AllowNeverAskAgain);
  7442. WinConfiguration->CopyParamAutoSelectNotice = false;
  7443. break;
  7444. case qaIgnore:
  7445. PreferencesDialog(pmPresets);
  7446. break;
  7447. }
  7448. }
  7449. //---------------------------------------------------------------------------
  7450. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  7451. {
  7452. // as of now useless, as this is used for notes only, never for balloons, ...
  7453. RestoreApp();
  7454. // .. and we should never be busy here
  7455. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  7456. {
  7457. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  7458. }
  7459. }
  7460. //---------------------------------------------------------------------------
  7461. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  7462. TPreferencesMode APreferencesMode)
  7463. {
  7464. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  7465. TCopyParamRuleData Data;
  7466. if (Terminal != NULL)
  7467. {
  7468. PreferencesData.reset(new TPreferencesDialogData());
  7469. GetTransferPresetAutoSelectData(Data);
  7470. PreferencesData->CopyParamRuleData = &Data;
  7471. }
  7472. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  7473. }
  7474. //---------------------------------------------------------------------------
  7475. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  7476. const TCustomCommandType & Command)
  7477. {
  7478. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  7479. {
  7480. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  7481. }
  7482. }
  7483. //---------------------------------------------------------------------------
  7484. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  7485. {
  7486. bool RemoteAllowed = CustomCommandRemoteAllowed();
  7487. TCustomCommandType Command;
  7488. // make sure we use local custom command when remote are not supported
  7489. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  7490. {
  7491. Command = FLastCustomCommand;
  7492. }
  7493. else
  7494. {
  7495. Command.Params = Command.Params | ccLocal;
  7496. }
  7497. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  7498. FEditingFocusedAdHocCommand = OnFocused;
  7499. bool LocalSide = (FCurrentSide == osLocal);
  7500. int Options =
  7501. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  7502. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  7503. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  7504. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  7505. {
  7506. FLastCustomCommand = Command;
  7507. UpdateCustomCommandsToolbar();
  7508. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  7509. }
  7510. }
  7511. //---------------------------------------------------------------------------
  7512. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  7513. {
  7514. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  7515. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7516. DebugAssert(State > 0);
  7517. if (State <= 0)
  7518. {
  7519. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  7520. }
  7521. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  7522. }
  7523. //---------------------------------------------------------------------------
  7524. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  7525. TCustomCommandType & Command, int & State)
  7526. {
  7527. bool Result = !FLastCustomCommand.Command.IsEmpty();
  7528. if (Result)
  7529. {
  7530. Command = FLastCustomCommand;
  7531. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7532. }
  7533. return Result;
  7534. }
  7535. //---------------------------------------------------------------------------
  7536. void __fastcall TCustomScpExplorerForm::BeforeAction()
  7537. {
  7538. if (RemoteDirView->ItemFocused != NULL)
  7539. {
  7540. RemoteDirView->ItemFocused->CancelEdit();
  7541. }
  7542. }
  7543. //---------------------------------------------------------------------------
  7544. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  7545. {
  7546. DebugAssert(ComponentVisible[Component]);
  7547. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  7548. }
  7549. //---------------------------------------------------------------------------
  7550. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  7551. {
  7552. // when queue panel is resized here directly, the status bar is stretched
  7553. // over whole space the panel occupied
  7554. PostComponentHide(fcQueueView);
  7555. }
  7556. //---------------------------------------------------------------------------
  7557. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  7558. {
  7559. TMessage * M = static_cast<TMessage*>(Message);
  7560. switch (M->Msg)
  7561. {
  7562. case CM_DIALOGCHAR:
  7563. CMDialogChar(*M);
  7564. break;
  7565. case WM_APPCOMMAND:
  7566. WMAppCommand(*M);
  7567. break;
  7568. case WM_SYSCOMMAND:
  7569. WMSysCommand(*M);
  7570. break;
  7571. case WM_QUERYENDSESSION:
  7572. WMQueryEndSession(*M);
  7573. break;
  7574. case WM_ENDSESSION:
  7575. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  7576. break;
  7577. #ifdef _DEBUG
  7578. case WM_WINDOWPOSCHANGED:
  7579. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  7580. break;
  7581. case CM_CUSTOMSTYLECHANGED:
  7582. TForm::Dispatch(Message);
  7583. break;
  7584. #endif
  7585. case WM_COMPONENT_HIDE:
  7586. {
  7587. Byte Component = static_cast<Byte>(M->WParam);
  7588. // sanity check
  7589. if (ComponentVisible[Component])
  7590. {
  7591. // special treatment
  7592. if (Component == fcQueueView)
  7593. {
  7594. ToggleQueueVisibility();
  7595. DebugAssert(!ComponentVisible[fcQueueView]);
  7596. }
  7597. else
  7598. {
  7599. ComponentVisible[Component] = false;
  7600. }
  7601. }
  7602. }
  7603. break;
  7604. case WM_COPYDATA:
  7605. WMCopyData(*M);
  7606. break;
  7607. case WM_MANAGES_CAPTION:
  7608. // caption managed in TTerminalManager::UpdateAppTitle()
  7609. M->Result = 1;
  7610. break;
  7611. case WM_WANTS_MOUSEWHEEL:
  7612. M->Result = 1;
  7613. break;
  7614. case CM_SHOWINGCHANGED:
  7615. CMShowingChanged(*M);
  7616. break;
  7617. case WM_CLOSE:
  7618. WMClose(*M);
  7619. break;
  7620. case WM_DPICHANGED:
  7621. WMDpiChanged(*M);
  7622. break;
  7623. default:
  7624. TForm::Dispatch(Message);
  7625. break;
  7626. }
  7627. }
  7628. //---------------------------------------------------------------------------
  7629. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  7630. {
  7631. TForm::Dispatch(&Message);
  7632. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  7633. }
  7634. //---------------------------------------------------------------------------
  7635. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  7636. {
  7637. // Cannot close window while we are busy.
  7638. // We cannot test this in FormCloseQuery as that is called also from
  7639. // Close(), which is called by CloseApplicationAction. So we can be busy
  7640. // there already even, when it is legitimate to close the application.
  7641. // Possibly a better place to handle this would be WMSysCommand.
  7642. if (NonVisualDataModule->Busy)
  7643. {
  7644. Message.Result = 1;
  7645. }
  7646. else
  7647. {
  7648. TForm::Dispatch(&Message);
  7649. }
  7650. }
  7651. //---------------------------------------------------------------------------
  7652. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  7653. {
  7654. TForm::Dispatch(&Message);
  7655. if (Showing && (Terminal == NULL))
  7656. {
  7657. // When we are starting minimized (i.e. from an installer),
  7658. // postpone showing Login dialog until we get restored.
  7659. // Otherwise the Login dialog (and Authentication window) show restored
  7660. // over invidible (minimized) main window.
  7661. if (WindowState == wsMinimized)
  7662. {
  7663. FNeedSession = true;
  7664. }
  7665. else
  7666. {
  7667. // This happens before application ever goes idle, so the toolbars would
  7668. // stay enabled (initial state) until the Login dialog is dismissed.
  7669. UpdateActions();
  7670. NonVisualDataModule->StartBusy();
  7671. try
  7672. {
  7673. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  7674. // otherwise the dialog does not receive focus.
  7675. // With Commander interface the ProcessMessages is called already
  7676. // by TDriveView, but with Explorer interface, we need to call it explicily
  7677. Application->ProcessMessages();
  7678. // do not reload sessions, they have been loaded just now (optimization)
  7679. NeedSession(false);
  7680. }
  7681. __finally
  7682. {
  7683. NonVisualDataModule->EndBusy();
  7684. }
  7685. }
  7686. }
  7687. }
  7688. //---------------------------------------------------------------------------
  7689. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  7690. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  7691. int & MaxHeight)
  7692. {
  7693. // workaround for bug in TWinControl.CalcConstraints
  7694. // Check for empty rect (restore from iconic state) is done there only after
  7695. // call to AdjustClientRect, which enlarges the rect (for forms).
  7696. TRect R = GetClientRect();
  7697. // when restoring from iconic state, place no restrictions
  7698. if (IsRectEmpty(R))
  7699. {
  7700. MinWidth = 0;
  7701. MinHeight = 0;
  7702. MaxWidth = 32000;
  7703. MaxHeight = 32000;
  7704. }
  7705. }
  7706. //---------------------------------------------------------------------------
  7707. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  7708. TSpaceAvailable & ASpaceAvailable, bool & Close)
  7709. {
  7710. // terminal can be already closed (e.g. dropped connection)
  7711. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  7712. {
  7713. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  7714. try
  7715. {
  7716. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  7717. }
  7718. catch(...)
  7719. {
  7720. if (!Terminal->Active)
  7721. {
  7722. Close = true;
  7723. }
  7724. throw;
  7725. }
  7726. }
  7727. }
  7728. //---------------------------------------------------------------------------
  7729. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  7730. {
  7731. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  7732. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  7733. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  7734. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  7735. {
  7736. OnGetSpaceAvailable = GetSpaceAvailable;
  7737. }
  7738. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  7739. OnGetSpaceAvailable);
  7740. }
  7741. //---------------------------------------------------------------------------
  7742. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  7743. {
  7744. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  7745. Terminal->FillSessionDataForCode(Data.get());
  7746. return Data.release();
  7747. }
  7748. //---------------------------------------------------------------------------
  7749. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  7750. {
  7751. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  7752. DoGenerateUrlDialog(Data.get(), Paths);
  7753. }
  7754. //---------------------------------------------------------------------------
  7755. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  7756. {
  7757. GenerateUrl(NULL);
  7758. }
  7759. //---------------------------------------------------------------------------
  7760. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  7761. {
  7762. std::unique_ptr<TStrings> Paths(new TStringList());
  7763. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  7764. GenerateUrl(Paths.get());
  7765. }
  7766. //---------------------------------------------------------------------------
  7767. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  7768. {
  7769. if (value != FSessionColor)
  7770. {
  7771. FSessionColor = value;
  7772. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  7773. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  7774. static_cast<TObject *>(GetComponent(fcColorMenu)));
  7775. DebugAssert(ColorItem != NULL);
  7776. ColorItem->Color = C;
  7777. NonVisualDataModule->ColorMenuItem->Color = C;
  7778. // Is null when called from LastTerminalClosed
  7779. if (Terminal != NULL)
  7780. {
  7781. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  7782. }
  7783. UpdateControls();
  7784. }
  7785. }
  7786. //---------------------------------------------------------------------------
  7787. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  7788. {
  7789. bool Result = FNoteTimer->Enabled;
  7790. if (Result)
  7791. {
  7792. // cannot cancel note too early
  7793. bool NotEarly =
  7794. (Now() - FNoteShown >
  7795. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  7796. if (Force || NotEarly)
  7797. {
  7798. FNoteTimer->Enabled = false;
  7799. FNote = L"";
  7800. SAFE_DESTROY(FNoteData);
  7801. FOnNoteClick = NULL;
  7802. FNoteHints = FNotes->Text;
  7803. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7804. UpdateStatusBar();
  7805. }
  7806. }
  7807. return Result;
  7808. }
  7809. //---------------------------------------------------------------------------
  7810. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  7811. {
  7812. DebugAssert(FNoteTimer->Enabled);
  7813. CancelNote(true);
  7814. }
  7815. //---------------------------------------------------------------------------
  7816. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  7817. {
  7818. int P = Note.Pos(L"\n");
  7819. if (P > 0)
  7820. {
  7821. Note.SetLength(P - 1);
  7822. }
  7823. FNotes->Add(FORMAT(L"[%s] %s",
  7824. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  7825. while (FNotes->Count > 10)
  7826. {
  7827. FNotes->Delete(0);
  7828. }
  7829. if (UpdateNow)
  7830. {
  7831. FNoteHints = FNotes->Text;
  7832. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7833. UpdateStatusBar();
  7834. }
  7835. }
  7836. //---------------------------------------------------------------------------
  7837. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  7838. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  7839. {
  7840. int P = Note.Pos(L"\n");
  7841. if (P > 0)
  7842. {
  7843. Note.SetLength(P - 1);
  7844. }
  7845. FNoteHints = FNotes->Text;
  7846. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7847. FNote = Note;
  7848. SAFE_DESTROY(FNoteData);
  7849. FNoteData = NoteData;
  7850. FOnNoteClick = OnNoteClick;
  7851. AddNote(Note, false);
  7852. UpdateStatusBar();
  7853. FNoteShown = Now();
  7854. FNoteTimer->Enabled = false;
  7855. if (Seconds == 0)
  7856. {
  7857. Seconds = WinConfiguration->NotificationsTimeout;
  7858. }
  7859. FNoteTimer->Interval = Seconds * MSecsPerSec;
  7860. FNoteTimer->Enabled = true;
  7861. }
  7862. //---------------------------------------------------------------------------
  7863. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  7864. {
  7865. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  7866. }
  7867. //---------------------------------------------------------------------------
  7868. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  7869. {
  7870. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  7871. {
  7872. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  7873. }
  7874. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  7875. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  7876. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  7877. 0, NULL, NULL);
  7878. }
  7879. //---------------------------------------------------------------------------
  7880. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  7881. {
  7882. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  7883. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  7884. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  7885. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  7889. {
  7890. WinConfiguration->FormatSizeBytes = Style;
  7891. }
  7892. //---------------------------------------------------------------------------
  7893. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  7894. {
  7895. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  7896. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  7897. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  7898. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  7899. }
  7900. //---------------------------------------------------------------------------
  7901. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  7902. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  7903. {
  7904. if (Panel->Index == 0)
  7905. {
  7906. if (FOnNoteClick != NULL)
  7907. {
  7908. // prevent the user data from being freed by possible call
  7909. // to CancelNote or PostNote during call to OnNoteClick
  7910. std::unique_ptr<TObject> NoteData(FNoteData);
  7911. TNotifyEvent OnNoteClick = FOnNoteClick;
  7912. FNoteData = NULL;
  7913. // need to cancel the note as we are going to delete its user data
  7914. CancelNote(true);
  7915. OnNoteClick(NoteData.get());
  7916. }
  7917. }
  7918. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  7919. {
  7920. FileSystemInfo();
  7921. }
  7922. }
  7923. //---------------------------------------------------------------------------
  7924. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  7925. {
  7926. // workaround:
  7927. // 1) for unknown reason, disabling window, while minimized,
  7928. // prevents it from restoring, even if it was enabled again meanwhile
  7929. // 2) when disabling the main window, while another has focus
  7930. // minimize is no longer possible
  7931. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  7932. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  7933. // Shouldn't we use IsApplicationMinimized() here?
  7934. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  7935. {
  7936. Enabled = false;
  7937. }
  7938. FLockLevel++;
  7939. }
  7940. //---------------------------------------------------------------------------
  7941. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  7942. {
  7943. DebugAssert(FLockLevel > 0);
  7944. FLockLevel--;
  7945. if (FLockLevel == 0)
  7946. {
  7947. DebugAssert(FLockSuspendLevel == 0);
  7948. Enabled = true;
  7949. }
  7950. }
  7951. //---------------------------------------------------------------------------
  7952. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  7953. {
  7954. // We need to make sure that window is enabled when the last modal window closes
  7955. // otherwise focus is not restored correctly.
  7956. // So we re-enable the window when modal window opens and
  7957. // disable it back after is closes
  7958. if (FLockLevel > 0)
  7959. {
  7960. // while we have nesting counter, we know that we never be called
  7961. // recursivelly as Application->OnModalBegin is called only
  7962. // for the top-level modal window
  7963. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  7964. {
  7965. // won't be disabled when conditions in LockWindow() were not satisfied
  7966. FDisabledOnLockSuspend = !Enabled;
  7967. // When minimized to tray (or actually when set to SW_HIDE),
  7968. // setting Enabled makes the window focusable even when there's
  7969. // modal window over it
  7970. if (!FTrayIcon->Visible)
  7971. {
  7972. Enabled = true;
  7973. }
  7974. }
  7975. FLockSuspendLevel++;
  7976. }
  7977. }
  7978. //---------------------------------------------------------------------------
  7979. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  7980. {
  7981. if (FLockSuspendLevel > 0)
  7982. {
  7983. DebugAssert(FLockLevel > 0);
  7984. FLockSuspendLevel--;
  7985. // see comment in SuspendWindowLock
  7986. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  7987. {
  7988. // Note that window can be enabled here, when we were minized to tray when
  7989. // was SuspendWindowLock() called.
  7990. // We should possibly do the same check as in LockWindow(),
  7991. // if it is ever possible that the consitions change between
  7992. // SuspendWindowLock() and ResumeWindowLock()
  7993. Enabled = !FDisabledOnLockSuspend;
  7994. }
  7995. }
  7996. }
  7997. //---------------------------------------------------------------------------
  7998. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  7999. {
  8000. if (!TextOnly)
  8001. {
  8002. TTBXComboBoxItem * RemotePathComboBox =
  8003. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8004. TStrings * Items = RemotePathComboBox->Strings;
  8005. Items->BeginUpdate();
  8006. try
  8007. {
  8008. Items->Clear();
  8009. if (Terminal != NULL)
  8010. {
  8011. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8012. while (!IsUnixRootPath(APath))
  8013. {
  8014. int P = APath.LastDelimiter(L'/');
  8015. DebugAssert(P >= 0);
  8016. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8017. APath.SetLength(P - 1);
  8018. }
  8019. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8020. }
  8021. }
  8022. __finally
  8023. {
  8024. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8025. // Setting ItemIndex to -1 does not reset its text
  8026. if (Items->Count == 0)
  8027. {
  8028. RemotePathComboBox->Text = L"";
  8029. }
  8030. Items->EndUpdate();
  8031. }
  8032. }
  8033. }
  8034. //---------------------------------------------------------------------------
  8035. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8036. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8037. int & ImageIndex)
  8038. {
  8039. if (AIndex < 0)
  8040. {
  8041. AIndex = Sender->ItemIndex;
  8042. }
  8043. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8044. }
  8045. //---------------------------------------------------------------------------
  8046. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8047. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8048. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8049. {
  8050. ARect.Left += (10 * AIndex);
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8054. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8055. {
  8056. AWidth += (10 * AIndex);
  8057. }
  8058. //---------------------------------------------------------------------------
  8059. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8060. TObject * Sender)
  8061. {
  8062. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8063. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8064. int Index = RemotePathComboBox->ItemIndex;
  8065. while (Index < RemotePathComboBox->Strings->Count - 1)
  8066. {
  8067. APath = UnixExtractFileDir(APath);
  8068. Index++;
  8069. }
  8070. // VanDyke style paths
  8071. if (APath.IsEmpty())
  8072. {
  8073. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8074. APath = ROOTDIRECTORY;
  8075. }
  8076. if (RemoteDirView->Path != APath)
  8077. {
  8078. RemoteDirView->Path = APath;
  8079. }
  8080. }
  8081. //---------------------------------------------------------------------------
  8082. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8083. {
  8084. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8085. DebugUsedParam(Sender);
  8086. UpdateRemotePathComboBox(true);
  8087. }
  8088. //---------------------------------------------------------------------------
  8089. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8090. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8091. {
  8092. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8093. DebugAssert(DirView != NULL);
  8094. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8095. {
  8096. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8097. // OnEditing is called also from TCustomListView::CanEdit
  8098. if (Edit != NULL)
  8099. {
  8100. EditSelectBaseName(Edit);
  8101. }
  8102. }
  8103. }
  8104. //---------------------------------------------------------------------------
  8105. //---------------------------------------------------------------------------
  8106. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8107. {
  8108. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8109. Result->AutoDetectDnD = false;
  8110. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8111. Result->RenderDataOn = rdoEnterAndDropSync;
  8112. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8113. return Result;
  8114. }
  8115. //---------------------------------------------------------------------------
  8116. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8117. {
  8118. TForm::CreateWnd();
  8119. if (FSessionsDragDropFilesEx == NULL)
  8120. {
  8121. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8122. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8123. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8124. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8125. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8126. }
  8127. if (FQueueDragDropFilesEx == NULL)
  8128. {
  8129. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8130. // No need to set OnDragOver as we do not have any restrictions
  8131. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8132. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8133. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8134. }
  8135. }
  8136. //---------------------------------------------------------------------------
  8137. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8138. {
  8139. TForm::DestroyWnd();
  8140. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8141. FQueueDragDropFilesEx->DragDropControl = NULL;
  8142. }
  8143. //---------------------------------------------------------------------------
  8144. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8145. {
  8146. SideEnter(FCurrentSide);
  8147. FEverShown = true;
  8148. }
  8149. //---------------------------------------------------------------------------
  8150. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8151. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8152. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8153. {
  8154. if (!NonVisualDataModule->Busy)
  8155. {
  8156. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8157. Configuration->Usage->Inc(L"FileFinds");
  8158. LockWindow(true);
  8159. NonVisualDataModule->StartBusy();
  8160. WinConfiguration->LockedInterface = true;
  8161. try
  8162. {
  8163. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8164. }
  8165. __finally
  8166. {
  8167. WinConfiguration->LockedInterface = false;
  8168. NonVisualDataModule->EndBusy();
  8169. UnlockWindow();
  8170. }
  8171. }
  8172. }
  8173. //---------------------------------------------------------------------------
  8174. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8175. {
  8176. if (!NonVisualDataModule->Busy)
  8177. {
  8178. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8179. SetFocus();
  8180. RemoteDirView->Path = UnixExtractFilePath(Path);
  8181. TListItem * Item = RemoteDirView->FindFileItem(UnixExtractFileName(Path));
  8182. if (Item != NULL)
  8183. {
  8184. RemoteDirView->ItemFocused = Item;
  8185. RemoteDirView->ItemFocused->MakeVisible(false);
  8186. RemoteDirView->SetFocus();
  8187. }
  8188. }
  8189. }
  8190. //---------------------------------------------------------------------------
  8191. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8192. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8193. {
  8194. if (!NonVisualDataModule->Busy)
  8195. {
  8196. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8197. DebugAssert(FOnFileOperationFinished == NULL);
  8198. FOnFileOperationFinished = OnFileOperationFinished;
  8199. try
  8200. {
  8201. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8202. }
  8203. __finally
  8204. {
  8205. FOnFileOperationFinished = NULL;
  8206. }
  8207. }
  8208. }
  8209. //---------------------------------------------------------------------------
  8210. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8211. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8212. {
  8213. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8214. }
  8215. //---------------------------------------------------------------------------
  8216. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8217. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8218. {
  8219. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8220. }
  8221. //---------------------------------------------------------------------------
  8222. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8223. {
  8224. FFileFindTerminal = Terminal;
  8225. ShowFileFindDialog(Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles, DoDownloadFoundFiles);
  8226. }
  8227. //---------------------------------------------------------------------------
  8228. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8229. {
  8230. FTaskbarList = TaskbarList;
  8231. }
  8232. //---------------------------------------------------------------------------
  8233. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8234. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8235. {
  8236. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8237. if (Index >= 0)
  8238. {
  8239. if (Button == mbLeft)
  8240. {
  8241. // "Mouse down" is raised only after tab is switched.
  8242. // If switching tab (switching session) takes long enough for user
  8243. // to actually release the button, "mouse down" is still raised,
  8244. // but we do not get "mouse up" event, so dragging is not cancelled,
  8245. // prevent that by not beginning dragging in the first place.
  8246. if (IsKeyPressed(VK_LBUTTON))
  8247. {
  8248. // when user clicks the "+", we get mouse down only after the session
  8249. // is closed, when new session tab is already on X:Y, so dragging
  8250. // starts, prevent that
  8251. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8252. {
  8253. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8254. if (Terminal != NULL)
  8255. {
  8256. SessionsPageControl->BeginDrag(false);
  8257. }
  8258. }
  8259. }
  8260. }
  8261. else if (Button == mbMiddle)
  8262. {
  8263. // ignore middle-click for "New session tab"
  8264. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8265. if (Terminal != NULL)
  8266. {
  8267. SessionsPageControl->ActivePageIndex = Index;
  8268. // Switch to session tab (has to be session tab, due to previous check)
  8269. if (DebugAlwaysTrue(SessionTabSwitched()))
  8270. {
  8271. CloseSession();
  8272. }
  8273. }
  8274. }
  8275. }
  8276. }
  8277. //---------------------------------------------------------------------------
  8278. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8279. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8280. {
  8281. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8282. // do not allow dropping on the "+" tab
  8283. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8284. if ((TargetTerminal != NULL) &&
  8285. (SessionsPageControl->ActivePage->PageIndex != Index))
  8286. {
  8287. Configuration->Usage->Inc(L"SessionTabMoves");
  8288. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8289. // but we want to actually prevent that to avoid flicker
  8290. SessionsPageControl->ActivePage->PageIndex = Index;
  8291. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8292. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8293. }
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8297. TObject * Sender, TObject * Source, int X, int Y,
  8298. TDragState /*State*/, bool & Accept)
  8299. {
  8300. Accept = (Sender == Source);
  8301. if (Accept)
  8302. {
  8303. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8304. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8305. // do not allow dragging to the "+" tab
  8306. Accept = (Terminal != NULL);
  8307. }
  8308. }
  8309. //---------------------------------------------------------------------------
  8310. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8311. const TPoint & Point, int & Effect)
  8312. {
  8313. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8314. if (Index < 0)
  8315. {
  8316. Effect = DROPEFFECT_None;
  8317. }
  8318. else
  8319. {
  8320. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8321. // do not allow dropping on the "+" tab
  8322. if (TargetTerminal == NULL)
  8323. {
  8324. Effect = DROPEFFECT_None;
  8325. }
  8326. }
  8327. }
  8328. //---------------------------------------------------------------------------
  8329. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8330. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8331. {
  8332. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8333. // do not allow dropping on the "+" tab
  8334. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8335. if (TargetTerminal != NULL)
  8336. {
  8337. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8338. if (!IsFileControl(DropSourceControl, osRemote))
  8339. {
  8340. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8341. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  8342. // Why don't we use Terminal->CurrentDirectory directly?
  8343. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory, false);
  8344. }
  8345. }
  8346. }
  8347. //---------------------------------------------------------------------------
  8348. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  8349. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  8350. {
  8351. // Downloads are handled in RemoteFileControlDDEnd
  8352. if (!IsFileControl(DropSourceControl, osRemote))
  8353. {
  8354. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  8355. Terminal->CurrentDirectory,
  8356. // force queue
  8357. true);
  8358. }
  8359. }
  8360. //---------------------------------------------------------------------------
  8361. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  8362. {
  8363. FShowing = false;
  8364. // Do not save empty workspace
  8365. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  8366. {
  8367. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  8368. UnicodeString Name = WorkspaceName();
  8369. DoSaveWorkspace(
  8370. Name, DataList.get(),
  8371. !Configuration->DisablePasswordStoring &&
  8372. WinConfiguration->AutoSaveWorkspacePasswords);
  8373. WinConfiguration->LastStoredSession = Name;
  8374. }
  8375. }
  8376. //---------------------------------------------------------------------------
  8377. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  8378. {
  8379. TManagedTerminal * ManagedTerminal =
  8380. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  8381. if (ManagedTerminal != NULL)
  8382. {
  8383. ManagedTerminal->DirectoryLoaded = Now();
  8384. }
  8385. }
  8386. //---------------------------------------------------------------------------
  8387. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  8388. TListItem * /*Item*/, bool /*Selected*/)
  8389. {
  8390. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8391. switch (DirView->LastSelectMethod)
  8392. {
  8393. case smKeyboard:
  8394. Configuration->Usage->Inc(L"KeyboardSelections");
  8395. break;
  8396. case smMouse:
  8397. Configuration->Usage->Inc(L"MouseSelections");
  8398. break;
  8399. }
  8400. }
  8401. //---------------------------------------------------------------------------
  8402. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  8403. {
  8404. if (Color != 0)
  8405. {
  8406. AddSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  8407. return FSessionColors->Count - 1;
  8408. }
  8409. else
  8410. {
  8411. return FSessionTabImageIndex;
  8412. }
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  8416. {
  8417. TPngImageCollectionItem * Item =
  8418. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  8419. FSessionColors->AddPng(Item->PngImage);
  8420. return FSessionColors->Count - 1;
  8421. }
  8422. //---------------------------------------------------------------------------
  8423. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  8424. {
  8425. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  8426. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  8427. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  8428. }
  8429. //---------------------------------------------------------------------------
  8430. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  8431. {
  8432. for (int Index = 0; Index < Control->ControlCount; Index++)
  8433. {
  8434. TControl * AControl = Control->Controls[Index];
  8435. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  8436. if (WinControl != NULL)
  8437. {
  8438. CollectItemsWithTextDisplayMode(WinControl);
  8439. }
  8440. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  8441. if (Toolbar != NULL)
  8442. {
  8443. // we care for top-level items only
  8444. TTBCustomItem * Items = Toolbar->Items;
  8445. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  8446. {
  8447. TTBCustomItem * Item = Items->Items[ItemIndex];
  8448. if (((Item->DisplayMode == nbdmImageAndText) ||
  8449. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  8450. EligibleForImageDisplayMode(Item))
  8451. {
  8452. FItemsWithTextDisplayMode.insert(Item);
  8453. }
  8454. }
  8455. }
  8456. }
  8457. }
  8458. //---------------------------------------------------------------------------
  8459. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  8460. {
  8461. return true;
  8462. }
  8463. //---------------------------------------------------------------------------
  8464. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  8465. {
  8466. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  8467. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  8468. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  8469. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  8470. bool Result = true;
  8471. while (Result && (i != FItemsWithTextDisplayMode.end()))
  8472. {
  8473. TTBCustomItem * Item = *i;
  8474. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  8475. if (Label != NULL)
  8476. {
  8477. // optimization
  8478. if (Label->Visible == SelectiveToolbarText)
  8479. {
  8480. Result = false;
  8481. }
  8482. else
  8483. {
  8484. Label->Visible = SelectiveToolbarText;
  8485. }
  8486. }
  8487. else
  8488. {
  8489. // optimization
  8490. if (Item->DisplayMode == DisplayMode)
  8491. {
  8492. Result = false;
  8493. }
  8494. else
  8495. {
  8496. Item->DisplayMode = DisplayMode;
  8497. }
  8498. }
  8499. ++i;
  8500. }
  8501. if (Result)
  8502. {
  8503. UpdateNewSessionTab();
  8504. }
  8505. return Result;
  8506. }
  8507. //---------------------------------------------------------------------------
  8508. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  8509. {
  8510. DebugFail();
  8511. }
  8512. //---------------------------------------------------------------------------
  8513. bool __fastcall TCustomScpExplorerForm::IsBusy()
  8514. {
  8515. // Among other, a lock level is non zero, while directory is being loaded,
  8516. // even when it happens as a result of dirview navigation,
  8517. // i.e. when TNonVisualDataModule is NOT FBusy.
  8518. // That's why the TNonVisualDataModule::GetBusy calls this method.
  8519. // Among other this prevents a panel auto update to occur while
  8520. // directory is changing.
  8521. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  8522. }
  8523. //---------------------------------------------------------------------------
  8524. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  8525. {
  8526. // While the window is disabled, we still seem to process menu shortcuts at least,
  8527. // so stop it at least here.
  8528. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  8529. return
  8530. (Allowed == aaUpdate) ||
  8531. !NonVisualDataModule->Busy;
  8532. }
  8533. //---------------------------------------------------------------------------
  8534. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  8535. {
  8536. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  8537. }
  8538. //---------------------------------------------------------------------------
  8539. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  8540. {
  8541. // This is somewhat redundant to LockWindow() call from
  8542. // TTerminalManager::TerminalReadDirectoryProgress.
  8543. // But disabling window is known not to block keyboard shorcuts
  8544. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  8545. if (Busy > 0)
  8546. {
  8547. if (NonVisualDataModule->Busy)
  8548. {
  8549. State = false;
  8550. }
  8551. else
  8552. {
  8553. NonVisualDataModule->StartBusy();
  8554. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  8555. LockWindow();
  8556. }
  8557. }
  8558. else if (Busy < 0)
  8559. {
  8560. UnlockWindow();
  8561. NonVisualDataModule->EndBusy();
  8562. }
  8563. else
  8564. {
  8565. State = NonVisualDataModule->Busy;
  8566. }
  8567. }
  8568. //---------------------------------------------------------------------------
  8569. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  8570. {
  8571. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  8572. // no context menu for "New session tab"
  8573. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  8574. {
  8575. SessionsPageControl->ActivePageIndex = Index;
  8576. if (DebugAlwaysTrue(SessionTabSwitched()))
  8577. {
  8578. // copied from TControl.WMContextMenu
  8579. SendCancelMode(SessionsPageControl);
  8580. // explicit popup instead of using PopupMenu property
  8581. // to avoid menu to popup somewhere within SessionTabSwitched above,
  8582. // while connecting yet not-connected session and hence
  8583. // allowing an access to commands over not-completelly connected session
  8584. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  8585. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  8586. PopupMenu->PopupComponent = SessionsPageControl;
  8587. PopupMenu->Popup(Point.x, Point.y);
  8588. }
  8589. }
  8590. Handled = true;
  8591. }
  8592. //---------------------------------------------------------------------------
  8593. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  8594. {
  8595. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  8596. }
  8597. //---------------------------------------------------------------------------
  8598. void __fastcall TCustomScpExplorerForm::ChangePassword()
  8599. {
  8600. Configuration->Usage->Inc(L"PasswordChanges");
  8601. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  8602. ChangePasswordData->DisableAuthentationsExceptPassword();
  8603. ChangePasswordData->ChangePassword = true;
  8604. std::unique_ptr<TTerminal> ChangePasswordSession(
  8605. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  8606. ChangePasswordSession->AutoReadDirectory = false;
  8607. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  8608. {
  8609. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  8610. }
  8611. else
  8612. {
  8613. Configuration->Usage->Inc(L"PasswordChangesFailed");
  8614. }
  8615. }