CustomScpExplorer.cpp 282 KB

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