CustomScpExplorer.cpp 290 KB

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