CustomScpExplorer.cpp 241 KB

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