CustomScpExplorer.cpp 294 KB

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