CustomScpExplorer.cpp 281 KB

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