CustomScpExplorer.cpp 266 KB

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