CustomScpExplorer.cpp 361 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983
  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 <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.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. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if (HasActiveTerminal() &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. HasActiveTerminal() &&
  425. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  429. {
  430. bool Result = Visible && !NonVisualDataModule->Busy;
  431. return Result;
  432. }
  433. //---------------------------------------------------------------------------
  434. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  435. const UnicodeString & CommandLine)
  436. {
  437. TProgramParams Params(CommandLine);
  438. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  439. if (Result)
  440. {
  441. NonVisualDataModule->StartBusy();
  442. try
  443. {
  444. // this action is initiated from another process,
  445. // so it's likely that our window is not visible,
  446. // and user won't see what is going on
  447. Application->BringToFront();
  448. // reload sessions as we may be asked to open a session
  449. // just stored by another instance
  450. StoredSessions->Reload();
  451. UnicodeString SessionName = Params.Param[1];
  452. std::unique_ptr<TObjectList> DataList(new TObjectList());
  453. UnicodeString DownloadFile; // unused
  454. try
  455. {
  456. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  457. }
  458. catch (EAbort &)
  459. {
  460. // Happens when opening session in PuTTY and in other situations,
  461. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  462. // to process the command-line on its own (or to pass it to yet another instance)
  463. }
  464. if (DataList->Count > 0)
  465. {
  466. TTerminalManager * Manager = TTerminalManager::Instance();
  467. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  468. }
  469. }
  470. __finally
  471. {
  472. NonVisualDataModule->EndBusy();
  473. }
  474. }
  475. return Result;
  476. }
  477. //---------------------------------------------------------------------------
  478. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  479. {
  480. if (FTerminal != value)
  481. {
  482. TerminalChanging();
  483. DoSetTerminal(value, false);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  488. {
  489. FTerminal = value;
  490. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  491. FAllowTransferPresetAutoSelect = false;
  492. try
  493. {
  494. TerminalChanged(Replace);
  495. }
  496. __finally
  497. {
  498. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  499. }
  500. if (Terminal != NULL)
  501. {
  502. TransferPresetAutoSelect();
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  507. {
  508. DoSetTerminal(value, true);
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  512. {
  513. if (FTerminal != NULL)
  514. {
  515. UpdateTerminal(Terminal);
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  520. {
  521. if (Terminal != NULL)
  522. {
  523. UpdateSessionColor((TColor)Terminal->StateData->Color);
  524. }
  525. DoTerminalListChanged();
  526. DebugAssert(!IsLocalBrowserMode()); // TODO
  527. if (Replaced)
  528. {
  529. RemoteDirView->ReplaceTerminal(Terminal);
  530. }
  531. else
  532. {
  533. RemoteDirView->Terminal = Terminal;
  534. }
  535. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  536. if (Terminal != NULL)
  537. {
  538. if (Terminal->Active)
  539. {
  540. Terminal->RefreshDirectory();
  541. }
  542. if (WinConfiguration->PreservePanelState)
  543. {
  544. if (Terminal->RemoteExplorerState != NULL)
  545. {
  546. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  547. }
  548. else
  549. {
  550. DirView(osRemote)->ClearState();
  551. }
  552. }
  553. if (!Replaced && Terminal->Active)
  554. {
  555. InitStatusBar();
  556. }
  557. }
  558. UpdateTransferList();
  559. // Update panels Enable state before refreshing the labels
  560. UpdateControls();
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  564. {
  565. if (Queue != value)
  566. {
  567. if (FQueue != NULL)
  568. {
  569. FQueue->OnListUpdate = NULL;
  570. FQueue->OnQueueItemUpdate = NULL;
  571. }
  572. FQueue = value;
  573. if (FQueue != NULL)
  574. {
  575. DebugAssert(FQueue->OnListUpdate == NULL);
  576. FQueue->OnListUpdate = QueueListUpdate;
  577. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  578. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  579. }
  580. QueueChanged();
  581. }
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  585. TListItem * Item)
  586. {
  587. if (FQueueActedItem == Item)
  588. {
  589. FQueueActedItem = NULL;
  590. if ((QueueView3->PopupMenu != NULL) &&
  591. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  592. {
  593. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  594. ReleaseCapture();
  595. }
  596. }
  597. if (Item->Data == FPendingQueueActionItem)
  598. {
  599. FPendingQueueActionItem = NULL;
  600. }
  601. }
  602. //---------------------------------------------------------------------------
  603. bool TCustomScpExplorerForm::IsAnythingQueued()
  604. {
  605. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  609. {
  610. {
  611. TGuard Guard(FQueueStatusSection);
  612. FQueueStatusInvalidated = false;
  613. if (FQueue != NULL)
  614. {
  615. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  616. }
  617. }
  618. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  619. {
  620. FMaxQueueLength = FQueueStatus->Count;
  621. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  622. }
  623. {
  624. TAutoFlag Flag(FQueueStatusUpdating);
  625. FQueueController->UpdateQueueStatus(FQueueStatus);
  626. }
  627. UpdateQueueFileList();
  628. SetQueueProgress();
  629. UpdateQueueView();
  630. bool IsEmpty = !IsAnythingQueued();
  631. if (IsEmpty && (Terminal != NULL))
  632. {
  633. TOnceDoneOperation OnceDoneOperation =
  634. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  635. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  636. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  637. {
  638. FQueue->Enabled = false;
  639. }
  640. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  641. {
  642. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  643. }
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  648. {
  649. UnicodeString Result;
  650. if (FQueueStatus != NULL)
  651. {
  652. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  653. {
  654. TFileOperationProgressType * ProgressData =
  655. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  656. if ((ProgressData != NULL) && ProgressData->InProgress)
  657. {
  658. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  659. }
  660. }
  661. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  662. {
  663. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  664. }
  665. }
  666. return Result;
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  670. {
  671. ComponentVisible[fcQueueView] =
  672. (WinConfiguration->QueueView.Show == qvShow) ||
  673. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  674. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::QueueChanged()
  678. {
  679. if (FQueueStatus != NULL)
  680. {
  681. // UpdateFileList implementation relies on the status being recreated when session changes
  682. delete FQueueStatus;
  683. FQueueStatus = NULL;
  684. }
  685. UpdateQueueStatus(true);
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. FQueueStatusInvalidated = true;
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  697. TQueueItem * Item)
  698. {
  699. if (FQueue == Queue)
  700. {
  701. TGuard Guard(FQueueStatusSection);
  702. // this may be running in parallel with QueueChanged
  703. if (FQueueStatus != NULL)
  704. {
  705. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  706. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  707. {
  708. FRefreshLocalDirectory = (QueueItem == NULL) ||
  709. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  710. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  711. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  712. }
  713. if (QueueItem != NULL)
  714. {
  715. QueueItem->UserData = (void*)true;
  716. FQueueItemInvalidated = true;
  717. }
  718. }
  719. }
  720. }
  721. //---------------------------------------------------------------------------
  722. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  723. {
  724. // during standalone editing, we have no way to see/control queue,
  725. // so we have to always popup prompts automatically
  726. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  730. {
  731. if (FQueueStatus != NULL)
  732. {
  733. bool QueueAutoPopup = IsQueueAutoPopup();
  734. bool NeedRefresh = FQueueController->NeedRefresh();
  735. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  736. FQueueItemInvalidated = false;
  737. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  738. bool Updated = false;
  739. TQueueItemProxy * QueueItem;
  740. bool WasUserAction;
  741. for (int Index = 0; Index < Limit; Index++)
  742. {
  743. bool Update = false;
  744. QueueItem = FQueueStatus->Items[Index];
  745. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  746. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  747. (FPendingQueueActionItem == NULL))
  748. {
  749. FPendingQueueActionItem = QueueItem;
  750. FUserActionTimer->Enabled = true;
  751. }
  752. if ((bool)QueueItem->UserData)
  753. {
  754. QueueItem->UserData = (void*)false;
  755. QueueItem->Update();
  756. Updated = true;
  757. Update = true;
  758. }
  759. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  760. {
  761. Update = true;
  762. }
  763. if (Update)
  764. {
  765. FQueueController->RefreshQueueItem(QueueItem);
  766. }
  767. }
  768. if (Updated)
  769. {
  770. NonVisualDataModule->UpdateNonVisibleActions();
  771. SetQueueProgress();
  772. UpdateQueueFileList();
  773. }
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  778. {
  779. if (FTaskbarList != NULL)
  780. {
  781. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  782. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  787. {
  788. if (Progress >= 0)
  789. {
  790. if (FTaskbarList != NULL)
  791. {
  792. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  793. }
  794. }
  795. else
  796. {
  797. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  802. {
  803. int OverallProgress;
  804. // FProgressForm is null when this is called from SetQueueProgress
  805. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  806. {
  807. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  808. }
  809. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  810. {
  811. OverallProgress = ProgressData->OverallProgress();
  812. }
  813. else
  814. {
  815. OverallProgress = -1;
  816. }
  817. SetTaskbarListProgressValue(OverallProgress);
  818. }
  819. //---------------------------------------------------------------------------
  820. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  821. {
  822. TTerminalManager::Instance()->QueueStatusUpdated();
  823. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  824. {
  825. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  826. {
  827. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  828. {
  829. TFileOperationProgressType * ProgressData = NULL;
  830. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  831. {
  832. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  833. }
  834. if ((ProgressData != NULL) &&
  835. ProgressData->InProgress)
  836. {
  837. SetTaskbarListProgressValue(ProgressData);
  838. }
  839. else
  840. {
  841. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  842. }
  843. }
  844. else
  845. {
  846. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  847. }
  848. }
  849. else
  850. {
  851. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  852. }
  853. }
  854. UpdateQueueLabel();
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  858. {
  859. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  860. if (FQueueStatus != NULL)
  861. {
  862. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  863. if (ActiveAndPendingPrimaryCount > 0)
  864. {
  865. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  866. }
  867. }
  868. QueueLabel->Caption = Caption;
  869. }
  870. //---------------------------------------------------------------------------
  871. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  872. {
  873. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  874. static_cast<TComponent*>(GetComponent(fcTransferList)));
  875. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  876. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  877. TransferList->Strings->BeginUpdate();
  878. try
  879. {
  880. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  881. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  882. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  883. if (FTransferDropDownHint.IsEmpty())
  884. {
  885. FTransferDropDownHint = TransferDropDown->Hint;
  886. }
  887. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  888. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  889. TransferDropDown->Text = StripHotkey(Name);
  890. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  891. (FTransferDropDownHint, StripHotkey(Name),
  892. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  893. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  894. // update the label, otherwise when it is updated only on the first draw
  895. // of the list, it is drawn "bold" for some reason
  896. FTransferListHoverIndex = TransferList->ItemIndex;
  897. UpdateTransferLabel();
  898. }
  899. __finally
  900. {
  901. TransferList->Strings->EndUpdate();
  902. }
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  906. {
  907. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  908. DebugAssert(Toolbar != NULL);
  909. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateActions()
  913. {
  914. TForm::UpdateActions();
  915. if (ComponentVisible[fcCustomCommandsBand])
  916. {
  917. UpdateCustomCommandsToolbar();
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  922. {
  923. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  927. {
  928. Color = GetBtnFaceColor();
  929. DebugAssert(Configuration && RemoteDirView);
  930. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  931. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  932. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  933. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  934. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  935. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  936. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. RemoteDirView->Invalidate();
  941. }
  942. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  943. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  944. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  945. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateSessionsPageControlHeight();
  948. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  949. UpdateToolbarDisplayMode();
  950. UpdateTransferList();
  951. if (Terminal != NULL)
  952. {
  953. TransferPresetAutoSelect();
  954. }
  955. UpdateQueueView();
  956. UpdateControls();
  957. // this can be called even before constuctor finishes.
  958. if (FEditorManager != NULL)
  959. {
  960. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  961. }
  962. // this can be called even before constuctor finishes.
  963. if (FLocalEditors != NULL)
  964. {
  965. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  966. {
  967. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  968. }
  969. }
  970. if (ComponentVisible[fcCustomCommandsBand])
  971. {
  972. UpdateCustomCommandsToolbar();
  973. }
  974. // show only when keeping queue items forever,
  975. // otherwise, its enough to have in in the context menu
  976. QueueDeleteAllDoneQueueToolbarItem->Visible =
  977. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  978. if (FFileColorsCurrent != WinConfiguration->FileColors)
  979. {
  980. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  981. FFileColorsCurrent = WinConfiguration->FileColors;
  982. FileColorsChanged();
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  987. {
  988. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  989. DirView->Invalidate();
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  993. {
  994. DoFileColorsChanged(RemoteDirView);
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  998. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  999. void * /*Arg*/)
  1000. {
  1001. if (Token != NULL)
  1002. {
  1003. TForm * Editor = dynamic_cast<TForm*>(Token);
  1004. DebugAssert(Editor != NULL);
  1005. ReconfigureEditorForm(Editor);
  1006. }
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1010. {
  1011. WinConfiguration->DDTransferConfirmation = asOn;
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1015. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1016. {
  1017. // noop
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1021. TTransferDirection Direction, TTransferType Type, bool Temp,
  1022. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1023. bool Confirm, bool DragDrop, int Options)
  1024. {
  1025. bool Result = true;
  1026. DebugAssert(HasActiveTerminal());
  1027. // these parameters are known in advance
  1028. int Params =
  1029. FLAGMASK(Type == ttMove, cpDelete);
  1030. bool ToTemp = (Temp && (Direction == tdToLocal));
  1031. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1032. {
  1033. bool DisableNewerOnly =
  1034. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1035. ToTemp;
  1036. Options |=
  1037. FLAGMASK(ToTemp, coTemp) |
  1038. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1039. coDoNotShowAgain;
  1040. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1041. int CopyParamAttrs = (Direction == tdToRemote ?
  1042. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1043. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1044. int OutputOptions =
  1045. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1046. cooDoNotShowAgain);
  1047. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1048. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1049. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1050. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1051. if (Result)
  1052. {
  1053. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1054. {
  1055. if (DragDrop)
  1056. {
  1057. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1058. {
  1059. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1060. NULL, 0, EnableDDTransferConfirmation, NULL);
  1061. }
  1062. WinConfiguration->DDTransferConfirmation = asOff;
  1063. }
  1064. else
  1065. {
  1066. WinConfiguration->ConfirmTransferring = false;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. // User explicitly unchecked "do not show again",
  1072. // so show him the dialog the next time
  1073. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1074. {
  1075. WinConfiguration->DDTransferConfirmation = asOn;
  1076. }
  1077. }
  1078. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1079. }
  1080. }
  1081. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1082. {
  1083. Configuration->Usage->Inc(L"TransfersOnBackground");
  1084. // these parameter are known only after transfer dialog
  1085. Params |=
  1086. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1087. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1088. Result = false;
  1089. ClearTransferSourceSelection(Direction);
  1090. }
  1091. return Result;
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1095. {
  1096. if (FOnFileOperationFinished != NULL)
  1097. {
  1098. FOnFileOperationFinished(UnicodeString(), true);
  1099. }
  1100. else
  1101. {
  1102. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1103. if (HasDirView[Side])
  1104. {
  1105. DirView(Side)->SelectAll(smNone);
  1106. }
  1107. }
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1111. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1112. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1113. int Params)
  1114. {
  1115. DebugAssert(Queue != NULL);
  1116. bool SingleFile = false;
  1117. if (FileList->Count == 1)
  1118. {
  1119. if (Direction == tdToRemote)
  1120. {
  1121. UnicodeString FileName = FileList->Strings[0];
  1122. SingleFile = FileExists(ApiPath(FileName));
  1123. }
  1124. else
  1125. {
  1126. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1127. SingleFile = !File->IsDirectory;
  1128. }
  1129. }
  1130. TQueueItem * QueueItem;
  1131. if (Direction == tdToRemote)
  1132. {
  1133. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1134. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1135. }
  1136. else
  1137. {
  1138. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1139. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1140. }
  1141. AddQueueItem(Queue, QueueItem, Terminal);
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1145. {
  1146. if (Queue->IsEmpty)
  1147. {
  1148. Terminal->QueueOperationStart = Now();
  1149. }
  1150. Queue->AddItem(QueueItem);
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1154. {
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::InitControls()
  1158. {
  1159. DebugAssert(FDocks != NULL);
  1160. for (int Index = 0; Index < ComponentCount; Index++)
  1161. {
  1162. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1163. if ((Dock != NULL) && (Dock->Tag == 0))
  1164. {
  1165. FDocks->Add(Dock);
  1166. }
  1167. }
  1168. CollectItemsWithTextDisplayMode(this);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1172. {
  1173. ConfigurationChanged();
  1174. QueuePanel->Height =
  1175. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1176. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1177. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1178. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1179. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1180. QueueFileList->Height =
  1181. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1182. if (QueueFileList->Visible)
  1183. {
  1184. AdjustQueueLayout();
  1185. }
  1186. UpdateCustomCommandsToolbar();
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TCustomScpExplorerForm::StoreParams()
  1190. {
  1191. int APixelsPerInch = GetControlPixelsPerInch(this);
  1192. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1193. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1194. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1195. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1196. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1197. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1198. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1199. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1203. {
  1204. if (!FFormRestored)
  1205. {
  1206. FFormRestored = true;
  1207. RestoreFormParams();
  1208. }
  1209. TForm::CreateParams(Params);
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1213. {
  1214. DebugAssert(FDocks != NULL);
  1215. for (int Index = 0; Index < FDocks->Count; Index++)
  1216. {
  1217. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1218. }
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1222. {
  1223. SetDockAllowDrag(true);
  1224. while (!ButtonsStr.IsEmpty())
  1225. {
  1226. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1227. UnicodeString Name = CutToChar(S, L'=', true);
  1228. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1229. {
  1230. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1231. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1232. {
  1233. while (!S.IsEmpty())
  1234. {
  1235. UnicodeString S2 = CutToChar(S, L',', true);
  1236. UnicodeString Name = CutToChar(S2, L':', true);
  1237. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1238. {
  1239. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1240. if (SameText(GetToolbarItemName(Item), Name))
  1241. {
  1242. // forward compatibility
  1243. UnicodeString S3 = CutToChar(S2, L':', true);
  1244. bool Visible = StrToIntDef(S3, 0);
  1245. Item->Visible = Visible;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1253. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1257. {
  1258. UnicodeString Result;
  1259. SetDockAllowDrag(true);
  1260. Result = ::GetToolbarsLayoutStr(this);
  1261. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1262. return Result;
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1266. {
  1267. UnicodeString Result;
  1268. if (Item->Action != NULL)
  1269. {
  1270. Result = Item->Action->Name;
  1271. Result = RemoveSuffix(Result, L"Action", true);
  1272. }
  1273. else
  1274. {
  1275. Result = Item->Name;
  1276. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1277. Result = RemoveSuffix(Result, L"Item", true);
  1278. }
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1283. {
  1284. UnicodeString Result;
  1285. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1286. {
  1287. UnicodeString ToolbarStr;
  1288. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1289. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1290. {
  1291. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1292. {
  1293. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1294. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1295. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1296. // and save the changes here only.
  1297. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1298. {
  1299. UnicodeString Name = GetToolbarItemName(Item);
  1300. DebugAssert(Name.Pos(L"TBX") == 0);
  1301. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1302. }
  1303. }
  1304. }
  1305. if (!ToolbarStr.IsEmpty())
  1306. {
  1307. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1308. }
  1309. }
  1310. return Result;
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1314. {
  1315. DebugAssert(FProgressForm == NULL);
  1316. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1317. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1318. FProgressForm->DeleteLocalToRecycleBin =
  1319. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1320. FProgressForm->DeleteRemoteToRecycleBin =
  1321. (Terminal != NULL) &&
  1322. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1323. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1324. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1325. LockWindow();
  1326. // Actually, do not know what hides the progress once the operation finishes
  1327. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1328. SetTaskbarListProgressState(TBPF_NORMAL);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1332. {
  1333. UnlockWindow();
  1334. SAFE_DESTROY(FProgressForm);
  1335. SetQueueProgress();
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1339. TFileOperationProgressType & ProgressData)
  1340. {
  1341. // Download to temporary local directory
  1342. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1343. {
  1344. bool Continue = true;
  1345. FPendingTempSpaceWarn = false;
  1346. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1347. if (!Continue)
  1348. {
  1349. Abort();
  1350. }
  1351. }
  1352. // operation is being executed and we still didn't show up progress form
  1353. if (ProgressData.InProgress && !FProgressForm)
  1354. {
  1355. CreateProgressForm(NULL);
  1356. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1357. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1358. }
  1359. // operation is finished (or terminated), so we hide progress form
  1360. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1361. {
  1362. DestroyProgressForm();
  1363. if (ProgressData.Operation == foCalculateSize)
  1364. {
  1365. // When calculating size before transfer, the abort caused by
  1366. // cancel flag set due to "MoveToQueue" below,
  1367. // is not propagated back to us in ExecuteFileOperation,
  1368. // as it is silently swallowed.
  1369. // So we explicitly (re)throw it here.
  1370. if (FMoveToQueue)
  1371. {
  1372. Abort();
  1373. }
  1374. }
  1375. else
  1376. {
  1377. if ((ProgressData.Cancel == csContinue) &&
  1378. !FAutoOperation)
  1379. {
  1380. OperationComplete(ProgressData.StartTime);
  1381. }
  1382. }
  1383. }
  1384. if (FProgressForm &&
  1385. // Can happen only during synchronization, when ending one of the operations
  1386. ProgressData.InProgress)
  1387. {
  1388. FProgressForm->SetProgressData(ProgressData);
  1389. DebugAssert(ProgressData.InProgress);
  1390. SetTaskbarListProgressValue(&ProgressData);
  1391. if (FProgressForm->Cancel > csContinue)
  1392. {
  1393. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1394. if (FProgressForm->Cancel == csCancelFile)
  1395. {
  1396. FProgressForm->ClearCancel();
  1397. }
  1398. // cancel cancels even the move
  1399. FMoveToQueue = false;
  1400. }
  1401. else if (FProgressForm->MoveToQueue)
  1402. {
  1403. FMoveToQueue = true;
  1404. ProgressData.SetCancelAtLeast(csCancel);
  1405. }
  1406. if ((FTransferResumeList != NULL) &&
  1407. ProgressData.InProgress &&
  1408. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1409. !ProgressData.FullFileName.IsEmpty())
  1410. {
  1411. if ((FTransferResumeList->Count == 0) ||
  1412. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1413. {
  1414. // note that we do not recognize directories from files here
  1415. FTransferResumeList->Add(ProgressData.FullFileName);
  1416. }
  1417. }
  1418. }
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1422. const TDateTime & StartTime)
  1423. {
  1424. if (GUIConfiguration->BeepOnFinish &&
  1425. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1426. {
  1427. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1428. DWORD Sound;
  1429. if (!ExtractFileExt(BeepSound).IsEmpty())
  1430. {
  1431. Sound = SND_FILENAME;
  1432. }
  1433. else
  1434. {
  1435. Sound = SND_ALIAS;
  1436. }
  1437. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1438. }
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1442. TFileOperationProgressType & ProgressData)
  1443. {
  1444. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1445. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1446. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1447. FileOperationProgress(ProgressData);
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1451. {
  1452. UnicodeString Result;
  1453. if (FProgressForm != NULL)
  1454. {
  1455. Result = FProgressForm->ProgressStr();
  1456. }
  1457. return Result;
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1461. bool DragDrop)
  1462. {
  1463. return (!DragDrop && (DropSourceControl == NULL)) ||
  1464. (DropSourceControl == DirView(osOther));
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1468. TFileOperation Operation, TOperationSide Side,
  1469. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1470. TOnceDoneOperation & OnceDoneOperation)
  1471. {
  1472. if (!FAutoOperation)
  1473. {
  1474. // no selection on "/upload", form serves only as event handler
  1475. // (it is not displayed)
  1476. if (PanelOperation(Side, FDragDropOperation) &&
  1477. Visible && (Operation != foCalculateSize) &&
  1478. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1479. {
  1480. if (FOnFileOperationFinished != NULL)
  1481. {
  1482. FOnFileOperationFinished(FileName, Success);
  1483. }
  1484. else
  1485. {
  1486. TCustomDirView * DView = DirView(Side);
  1487. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1488. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1489. // this can happen when local drive is unplugged in the middle of the operation
  1490. if (Item != NULL)
  1491. {
  1492. if (Success) Item->Selected = false;
  1493. DView->MakeProgressVisible(Item);
  1494. }
  1495. }
  1496. }
  1497. if ((Operation == foCopy) || (Operation == foMove))
  1498. {
  1499. DebugAssert(!IsLocalBrowserMode()); // TODO
  1500. if (Side == osLocal)
  1501. {
  1502. Configuration->Usage->Inc(L"UploadedFiles");
  1503. }
  1504. else
  1505. {
  1506. Configuration->Usage->Inc(L"DownloadedFiles");
  1507. }
  1508. }
  1509. }
  1510. if (Success && (FSynchronizeController != NULL))
  1511. {
  1512. DebugAssert(!IsSideLocalBrowser(osRemote));
  1513. if (Operation == foCopy)
  1514. {
  1515. DebugAssert(Side == osLocal);
  1516. FSynchronizeController->LogOperation(soUpload, FileName);
  1517. }
  1518. else if (Operation == foDelete)
  1519. {
  1520. DebugAssert(Side == osRemote);
  1521. FSynchronizeController->LogOperation(soDelete, FileName);
  1522. }
  1523. }
  1524. if (FProgressForm)
  1525. {
  1526. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1527. }
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1531. TFileOperation Operation, TOperationSide Side,
  1532. bool Temp, const UnicodeString & FileName, Boolean Success,
  1533. TOnceDoneOperation & OnceDoneOperation)
  1534. {
  1535. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1536. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1537. OnceDoneOperation);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1541. {
  1542. return false;
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1546. {
  1547. return false;
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1551. {
  1552. return NULL;
  1553. }
  1554. //---------------------------------------------------------------------------
  1555. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1556. {
  1557. DebugAssert(GetSide(Side) == osRemote);
  1558. DebugUsedParam(Side);
  1559. return RemoteDirView;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1563. {
  1564. DebugAssert(GetSide(Side) == osRemote);
  1565. DebugUsedParam(Side);
  1566. return RemoteDriveView;
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1570. {
  1571. DebugAssert(GetSide(Side) == osRemote);
  1572. DebugUsedParam(Side);
  1573. return HasActiveTerminal();
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1577. TOperationSide Side, int FilesOnly)
  1578. {
  1579. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1583. TOperationSide Side, int FilesOnly)
  1584. {
  1585. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. struct THistoryItemData
  1589. {
  1590. short int Side;
  1591. short int Index;
  1592. };
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1595. {
  1596. DirView(Side)->HistoryGo(Index);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1600. {
  1601. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1602. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1603. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1607. bool Back)
  1608. {
  1609. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1610. {
  1611. TCustomDirView * DView = DirView(Side);
  1612. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1613. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1614. if (ICount > 10)
  1615. {
  1616. ICount = 10;
  1617. }
  1618. Menu->Items->Clear();
  1619. THistoryItemData Data;
  1620. Data.Side = Side;
  1621. for (short int i = 1; i <= ICount; i++)
  1622. {
  1623. TTBCustomItem * Item = new TTBXItem(Menu);
  1624. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1625. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1626. Item->Hint = DView->HistoryPath[Data.Index];
  1627. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1628. Item->Tag = *reinterpret_cast<int*>(&Data);
  1629. Item->OnClick = HistoryItemClick;
  1630. Menu->Items->Add(Item);
  1631. }
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1636. TOperationSide Side, bool Back)
  1637. {
  1638. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1639. {
  1640. // workaround
  1641. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1642. // operator new allocates memory in Pascal code, but calls inline
  1643. // contructor in C++, leading in problems, the function does
  1644. // both in Pascal code
  1645. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1646. UpdateHistoryMenu(Side, Back);
  1647. }
  1648. return FHistoryMenu[Side == osLocal][Back];
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1652. TCustomDirView *Sender)
  1653. {
  1654. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1655. UpdateHistoryMenu(Side, true);
  1656. UpdateHistoryMenu(Side, false);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1660. {
  1661. // remote custom commands can be executed only if the server supports shell commands
  1662. // or have secondary shell
  1663. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1664. }
  1665. //---------------------------------------------------------------------------
  1666. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1667. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1668. {
  1669. // -1 = hidden, 0 = disabled, 1 = enabled
  1670. int Result;
  1671. TFileCustomCommand RemoteCustomCommand;
  1672. TLocalCustomCommand LocalCustomCommand;
  1673. TFileCustomCommand * NonInteractiveCustomCommand =
  1674. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1675. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1676. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1677. if (FLAGCLEAR(Command.Params, ccLocal))
  1678. {
  1679. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1680. // custom command that does not operate with files can be executed anytime ...
  1681. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1682. {
  1683. // ... but do not show such command in remote file menu
  1684. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1685. {
  1686. Result = AllowedState;
  1687. }
  1688. else
  1689. {
  1690. Result = -1;
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1696. {
  1697. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1698. }
  1699. else
  1700. {
  1701. Result = -1;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. {
  1707. // custom command that does not operate with files can be executed anytime
  1708. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1709. {
  1710. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1711. }
  1712. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1713. {
  1714. if ((ListType == ccltAll) || (ListType == ccltFile))
  1715. {
  1716. // special case is "diff"-style command that can be executed over any side,
  1717. // if we have both sides
  1718. Result =
  1719. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1720. // directly (instead of EnableSelectedOperation) to pass
  1721. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1722. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1723. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1724. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1725. }
  1726. else if (ListType == ccltBoth)
  1727. {
  1728. DebugAssert(!IsLocalBrowserMode());
  1729. Result = 1;
  1730. }
  1731. else
  1732. {
  1733. Result = -1;
  1734. }
  1735. }
  1736. else
  1737. {
  1738. if ((ListType == ccltAll) ||
  1739. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1740. {
  1741. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. if ((Result > 0) &&
  1749. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1750. !HasActiveTerminal())
  1751. {
  1752. Result = 0;
  1753. }
  1754. }
  1755. return Result;
  1756. }
  1757. //---------------------------------------------------------------------------
  1758. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1759. TStrings * FileList, const TCustomCommandType & ACommand,
  1760. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1761. {
  1762. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1763. {
  1764. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1765. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1766. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1767. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1768. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1769. bool Capture =
  1770. FLAGSET(ACommand.Params, ccShowResults) ||
  1771. FLAGSET(ACommand.Params, ccCopyResults) ||
  1772. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1773. TCaptureOutputEvent OutputEvent = NULL;
  1774. DebugAssert(FCapturedLog == NULL);
  1775. if (Capture)
  1776. {
  1777. FCapturedLog = new TStringList();
  1778. OutputEvent = TerminalCaptureLog;
  1779. }
  1780. try
  1781. {
  1782. if (!RemoteCustomCommand.IsFileCommand(Command))
  1783. {
  1784. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1785. OutputEvent);
  1786. }
  1787. else
  1788. {
  1789. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1790. }
  1791. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1792. {
  1793. if (FLAGSET(ACommand.Params, ccCopyResults))
  1794. {
  1795. CopyToClipboard(FCapturedLog);
  1796. }
  1797. if (FLAGSET(ACommand.Params, ccShowResults))
  1798. {
  1799. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1800. }
  1801. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1802. {
  1803. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1804. }
  1805. }
  1806. }
  1807. __finally
  1808. {
  1809. SAFE_DESTROY(FCapturedLog);
  1810. }
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1815. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1816. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1817. {
  1818. DebugAssert(!IsLocalBrowserMode());
  1819. TStrings * LocalFileList = NULL;
  1820. TStrings * RemoteFileList = NULL;
  1821. TStrings * RemoteFileListFull = NULL;
  1822. try
  1823. {
  1824. if (LocalFileCommand)
  1825. {
  1826. if (ALocalFileList == NULL)
  1827. {
  1828. DebugAssert(HasDirView[osLocal]);
  1829. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1830. // directly (instead of EnableSelectedOperation) to pass
  1831. // false to FocusedFileOnlyWhenFocused
  1832. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1833. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1834. }
  1835. else
  1836. {
  1837. LocalFileList = ALocalFileList;
  1838. }
  1839. if (FileListCommand)
  1840. {
  1841. if (LocalFileList->Count != 1)
  1842. {
  1843. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1844. }
  1845. }
  1846. else
  1847. {
  1848. if ((LocalFileList->Count != 1) &&
  1849. (FileList->Count != 1) &&
  1850. (LocalFileList->Count != FileList->Count))
  1851. {
  1852. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1853. }
  1854. }
  1855. }
  1856. UnicodeString RootTempDir;
  1857. UnicodeString TempDir;
  1858. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1859. if (!RemoteFiles)
  1860. {
  1861. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1862. }
  1863. try
  1864. {
  1865. TDateTimes RemoteFileTimes;
  1866. if (RemoteFiles)
  1867. {
  1868. RemoteFileList = FileList;
  1869. }
  1870. else
  1871. {
  1872. RemoteFileList = new TStringList();
  1873. TMakeLocalFileListParams MakeFileListParam;
  1874. MakeFileListParam.FileList = RemoteFileList;
  1875. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1876. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1877. MakeFileListParam.Recursive =
  1878. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1879. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1880. if (!MakeFileListParam.Recursive)
  1881. {
  1882. RemoteFileTimes.clear();
  1883. RemoteFileListFull = new TStringList();
  1884. MakeFileListParam.FileList = RemoteFileListFull;
  1885. MakeFileListParam.Recursive = true;
  1886. MakeFileListParam.IncludeDirs = false;
  1887. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1888. }
  1889. else
  1890. {
  1891. RemoteFileListFull = RemoteFileList;
  1892. }
  1893. }
  1894. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1895. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1896. if (!NonBlocking)
  1897. {
  1898. int Count;
  1899. if (FileListCommand)
  1900. {
  1901. Count = 1;
  1902. }
  1903. else if (LocalFileCommand)
  1904. {
  1905. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1906. }
  1907. else
  1908. {
  1909. Count = RemoteFileList->Count;
  1910. }
  1911. Progress.Start(foCustomCommand, osRemote, Count);
  1912. DebugAssert(FProgressForm != NULL);
  1913. FProgressForm->ReadOnly = true;
  1914. }
  1915. try
  1916. {
  1917. if (FileListCommand)
  1918. {
  1919. UnicodeString LocalFile;
  1920. // MakeFileList does not delimit filenames
  1921. UnicodeString FileList = MakeFileList(RemoteFileList);
  1922. if (LocalFileCommand)
  1923. {
  1924. DebugAssert(LocalFileList->Count == 1);
  1925. LocalFile = LocalFileList->Strings[0];
  1926. }
  1927. TLocalCustomCommand CustomCommand(Data,
  1928. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1929. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1930. if (NonBlocking)
  1931. {
  1932. DebugAssert(!POutput);
  1933. ExecuteShellChecked(ShellCommand);
  1934. }
  1935. else
  1936. {
  1937. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1938. }
  1939. }
  1940. else if (LocalFileCommand)
  1941. {
  1942. if (LocalFileList->Count == 1)
  1943. {
  1944. UnicodeString LocalFile = LocalFileList->Strings[0];
  1945. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1946. {
  1947. UnicodeString FileName = RemoteFileList->Strings[Index];
  1948. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1949. Progress.SetFile(FileNameForProgress);
  1950. TLocalCustomCommand CustomCommand(Data,
  1951. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1952. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1953. TOnceDoneOperation OnceDoneOperation;
  1954. // Do not unselect anything, as it won't work with two panels anyway
  1955. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1956. }
  1957. }
  1958. else if (RemoteFileList->Count == 1)
  1959. {
  1960. UnicodeString FileName = RemoteFileList->Strings[0];
  1961. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1962. {
  1963. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1964. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1965. Progress.SetFile(LocalFileNameOnly);
  1966. TLocalCustomCommand CustomCommand(
  1967. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1968. FileName, LocalFileName, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else
  1976. {
  1977. if (LocalFileList->Count != RemoteFileList->Count)
  1978. {
  1979. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1980. }
  1981. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1982. {
  1983. UnicodeString FileName = RemoteFileList->Strings[Index];
  1984. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1985. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1986. Progress.SetFile(LocalFileNameOnly); // sic
  1987. TLocalCustomCommand CustomCommand(
  1988. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1989. FileName, LocalFileName, L"");
  1990. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1991. TOnceDoneOperation OnceDoneOperation;
  1992. // Do not unselect anything, as it won't work with two panels anyway
  1993. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1994. }
  1995. }
  1996. }
  1997. else
  1998. {
  1999. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2000. {
  2001. UnicodeString FileName = RemoteFileList->Strings[Index];
  2002. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2003. Progress.SetFile(FileNameForProgress);
  2004. TLocalCustomCommand CustomCommand(Data,
  2005. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, L"", L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2010. }
  2011. }
  2012. }
  2013. __finally
  2014. {
  2015. if (!NonBlocking)
  2016. {
  2017. Progress.Stop();
  2018. }
  2019. }
  2020. DebugAssert(!FAutoOperation);
  2021. if (!RemoteFiles)
  2022. {
  2023. TempDir = IncludeTrailingBackslash(TempDir);
  2024. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2025. {
  2026. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2027. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2028. // Skip directories, process only nested files.
  2029. // The check is redundant as FileAge fails for directories anyway.
  2030. !DirectoryExists(FileName))
  2031. {
  2032. UnicodeString RemoteDir =
  2033. UnixExtractFileDir(
  2034. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2035. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2036. TDateTime NewTime;
  2037. if (FileAge(FileName, NewTime) &&
  2038. (NewTime != RemoteFileTimes[Index]))
  2039. {
  2040. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2041. TemporaryFileCopyParam(CopyParam);
  2042. CopyParam.FileMask = L"";
  2043. FAutoOperation = true;
  2044. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2045. TemporaryFilesList->Add(FileName);
  2046. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. __finally
  2053. {
  2054. FAutoOperation = false;
  2055. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2056. {
  2057. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2058. }
  2059. }
  2060. }
  2061. __finally
  2062. {
  2063. if (RemoteFileList != FileList)
  2064. {
  2065. delete RemoteFileList;
  2066. }
  2067. if (LocalFileList != ALocalFileList)
  2068. {
  2069. delete LocalFileList;
  2070. }
  2071. if (RemoteFileListFull != RemoteFileList)
  2072. {
  2073. delete RemoteFileListFull;
  2074. }
  2075. }
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2079. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2080. bool FileListCommand, UnicodeString * POutput)
  2081. {
  2082. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2083. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2084. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2085. {
  2086. UnicodeString FileName = SelectedFileList->Strings[Index];
  2087. if (DirectoryExists(FileName))
  2088. {
  2089. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2090. {
  2091. LocalFileList->Add(FileName);
  2092. }
  2093. if (FLAGSET(ACommand.Params, ccRecursive))
  2094. {
  2095. TMakeLocalFileListParams MakeFileListParam;
  2096. MakeFileListParam.FileList = LocalFileList.get();
  2097. MakeFileListParam.FileTimes = NULL;
  2098. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2099. MakeFileListParam.Recursive = true;
  2100. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2101. }
  2102. }
  2103. else
  2104. {
  2105. LocalFileList->Add(FileName);
  2106. }
  2107. }
  2108. UnicodeString RemotePath;
  2109. if (Terminal != NULL)
  2110. {
  2111. RemotePath = Terminal->CurrentDirectory;
  2112. }
  2113. if (FileListCommand)
  2114. {
  2115. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2116. TLocalCustomCommand CustomCommand(
  2117. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2118. L"", L"", FileList);
  2119. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2120. }
  2121. else
  2122. {
  2123. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2124. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2125. DebugAssert(FProgressForm != NULL);
  2126. FProgressForm->ReadOnly = true;
  2127. try
  2128. {
  2129. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2130. {
  2131. UnicodeString FileName = LocalFileList->Strings[Index];
  2132. Progress.SetFile(FileName);
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. FileName, L"", L"");
  2136. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. TOnceDoneOperation OnceDoneOperation;
  2138. Progress.Finish(FileName, true, OnceDoneOperation);
  2139. }
  2140. }
  2141. __finally
  2142. {
  2143. Progress.Stop();
  2144. }
  2145. }
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2149. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2150. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2151. {
  2152. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2153. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2154. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2155. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2156. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2157. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2158. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2159. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2160. std::unique_ptr<UnicodeString> POutput;
  2161. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2162. FLAGSET(ACommand.Params, ccCopyResults))
  2163. {
  2164. POutput.reset(new UnicodeString());
  2165. }
  2166. if (!LocalCustomCommand.IsFileCommand(Command))
  2167. {
  2168. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2169. }
  2170. // remote files?
  2171. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2172. {
  2173. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2174. }
  2175. // local files
  2176. else
  2177. {
  2178. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2179. }
  2180. if (POutput.get() != NULL)
  2181. {
  2182. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2183. int P = POutput->Pos(sLineBreak);
  2184. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2185. {
  2186. POutput->SetLength(P - 1);
  2187. }
  2188. // Copy even empty output to clipboard
  2189. if (FLAGSET(ACommand.Params, ccCopyResults))
  2190. {
  2191. CopyToClipboard(*POutput);
  2192. }
  2193. // But do not show an empty message box.
  2194. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2195. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2196. !POutput->IsEmpty())
  2197. {
  2198. TClipboardHandler ClipboardHandler;
  2199. ClipboardHandler.Text = *POutput;
  2200. TMessageParams Params;
  2201. TQueryButtonAlias Aliases[1];
  2202. Aliases[0].Button = qaRetry;
  2203. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2204. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2205. Params.Aliases = Aliases;
  2206. Params.AliasesCount = LENOF(Aliases);
  2207. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2208. }
  2209. }
  2210. }
  2211. //---------------------------------------------------------------------------
  2212. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2213. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2214. {
  2215. TCustomCommandData Data;
  2216. UnicodeString Site;
  2217. UnicodeString RemotePath;
  2218. if (HasActiveTerminal())
  2219. {
  2220. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2221. Data = TCustomCommandData(SessionData.get());
  2222. Site = Terminal->SessionData->SessionKey;
  2223. RemotePath = Terminal->CurrentDirectory;
  2224. }
  2225. UnicodeString HelpKeyword = ACommand.HomePage;
  2226. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2227. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2228. {
  2229. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2230. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2231. {
  2232. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2233. }
  2234. else
  2235. {
  2236. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2237. }
  2238. if (!DoCustomCommandOptionsDialog(
  2239. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2240. {
  2241. Abort();
  2242. }
  2243. }
  2244. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2245. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2246. {
  2247. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2248. }
  2249. else
  2250. {
  2251. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2252. }
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2256. const TCustomCommandType & Command)
  2257. {
  2258. DebugAssert(FCustomCommandLocalFileList != NULL);
  2259. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2260. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2261. TStrings * LocalFileList = new TStringList();
  2262. TStrings * RemoteFileList = new TStringList();
  2263. try
  2264. {
  2265. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2266. {
  2267. LocalFileList->Clear();
  2268. LocalFileList->AddObject(
  2269. FCustomCommandLocalFileList->Strings[Index],
  2270. FCustomCommandLocalFileList->Objects[Index]);
  2271. RemoteFileList->Clear();
  2272. RemoteFileList->AddObject(
  2273. FCustomCommandRemoteFileList->Strings[Index],
  2274. FCustomCommandRemoteFileList->Objects[Index]);
  2275. CustomCommand(RemoteFileList, Command, LocalFileList);
  2276. }
  2277. }
  2278. __finally
  2279. {
  2280. delete LocalFileList;
  2281. delete RemoteFileList;
  2282. }
  2283. }
  2284. //---------------------------------------------------------------------------
  2285. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2286. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2287. {
  2288. delete FCustomCommandLocalFileList;
  2289. delete FCustomCommandRemoteFileList;
  2290. // takeover ownership,
  2291. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2292. FCustomCommandLocalFileList = LocalFileList;
  2293. FCustomCommandRemoteFileList = RemoteFileList;
  2294. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2295. if (Button != NULL)
  2296. {
  2297. FCustomCommandMenu->Items->Clear();
  2298. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2299. MenuPopup(FCustomCommandMenu, Button);
  2300. }
  2301. else
  2302. {
  2303. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2304. }
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2308. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2309. {
  2310. DebugAssert(FCapturedLog != NULL);
  2311. if ((OutputType == cotOutput) || (OutputType == cotError))
  2312. {
  2313. FCapturedLog->Add(AddedLine);
  2314. }
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2318. TOperationSide Side)
  2319. {
  2320. return
  2321. (Side == osOther) &&
  2322. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2323. }
  2324. //---------------------------------------------------------------------------
  2325. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2326. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2327. {
  2328. TTBItemOptions O;
  2329. O = Item->Options;
  2330. TCustomDirView * DView = DirView(Side);
  2331. if ((DView->ItemFocused != NULL) &&
  2332. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2333. // when resolving links is disabled, default action is to enter the directory,
  2334. // no matter what DoubleClickAction is configured to
  2335. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2336. // Can only Edit files, but can Open/Copy even directories
  2337. ((DoubleClickAction != dcaEdit) ||
  2338. !DView->ItemIsDirectory(DView->ItemFocused)))
  2339. {
  2340. Item->Options = O << tboDefault;
  2341. }
  2342. else
  2343. {
  2344. Item->Options = O >> tboDefault;
  2345. }
  2346. }
  2347. //---------------------------------------------------------------------------
  2348. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2349. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2350. {
  2351. TCustomDirView * DView = DirView(Side);
  2352. TListItem * Item = DView->ItemFocused;
  2353. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2354. EnableFocusedOperation[Side])
  2355. {
  2356. TPoint ClientPoint;
  2357. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2358. TPoint(0, 0) : MousePos;
  2359. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2360. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2361. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2362. }
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2366. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2367. {
  2368. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2369. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2370. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2371. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2372. Handled = true;
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2376. {
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2380. {
  2381. DebugAssert(FErrorList == NULL);
  2382. if (WinConfiguration->ContinueOnError)
  2383. {
  2384. FErrorList = new TStringList();
  2385. Configuration->Usage->Inc(L"ContinuationsOnError");
  2386. }
  2387. NonVisualDataModule->StartBusy();
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2391. {
  2392. NonVisualDataModule->EndBusy();
  2393. if (FErrorList)
  2394. {
  2395. HandleErrorList(FErrorList);
  2396. }
  2397. }
  2398. //---------------------------------------------------------------------------
  2399. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2400. const TCopyParamType & CopyParam)
  2401. {
  2402. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2403. {
  2404. Configuration->Usage->Inc(L"FileMaskUses");
  2405. }
  2406. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2407. {
  2408. Configuration->Usage->Inc(L"OperationMaskUses");
  2409. }
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2413. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2414. {
  2415. DebugAssert(!IsLocalBrowserMode());
  2416. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2417. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2418. TTransferOperationParam DefaultParam;
  2419. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2420. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2421. switch (Param.Queue)
  2422. {
  2423. case asOn:
  2424. CopyParam.Queue = true;
  2425. break;
  2426. case asOff:
  2427. CopyParam.Queue = false;
  2428. break;
  2429. case asAuto:
  2430. default:
  2431. // keep default
  2432. break;
  2433. }
  2434. bool Result =
  2435. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2436. if (Result)
  2437. {
  2438. DebugAssert(Terminal);
  2439. bool SelectionRestored = false;
  2440. TCustomDirView * DView = NULL;
  2441. if (HasDirView[Side])
  2442. {
  2443. DView = DirView(Side);
  2444. DView->SaveSelection();
  2445. DView->SaveSelectedNames();
  2446. }
  2447. UpdateCopyParamCounters(CopyParam);
  2448. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2449. DebugAssert(FTransferResumeList == NULL);
  2450. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2451. FMoveToQueue = false;
  2452. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2453. try
  2454. {
  2455. TStrings * PermanentFileList;
  2456. std::unique_ptr<TStrings> PermanentFileListOwner;
  2457. try
  2458. {
  2459. if (Side == osLocal)
  2460. {
  2461. PermanentFileList = FileList;
  2462. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2463. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2464. if (Operation == foMove)
  2465. {
  2466. ReloadLocalDirectory();
  2467. if (DView != NULL)
  2468. {
  2469. DView->RestoreSelection();
  2470. }
  2471. SelectionRestored = true;
  2472. }
  2473. }
  2474. else
  2475. {
  2476. // Clone the file list as it may refer to current directory files,
  2477. // which get destroyed, when the source directory is reloaded after foMove operation.
  2478. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2479. // But for a hotfix, we are not going to do such a big change.
  2480. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2481. PermanentFileList = PermanentFileListOwner.get();
  2482. try
  2483. {
  2484. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2485. }
  2486. __finally
  2487. {
  2488. if (Operation == foMove)
  2489. {
  2490. if (DView != NULL)
  2491. {
  2492. DView->RestoreSelection();
  2493. }
  2494. SelectionRestored = true;
  2495. }
  2496. ReloadLocalDirectory(Param.TargetDirectory);
  2497. }
  2498. }
  2499. }
  2500. catch (EAbort &)
  2501. {
  2502. if (FMoveToQueue)
  2503. {
  2504. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2505. DebugAssert(CopyParam.TransferSkipList == NULL);
  2506. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2507. if (TransferResumeList->Count > 0)
  2508. {
  2509. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2510. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2511. }
  2512. CopyParam.TransferSkipList = TransferResumeList.release();
  2513. // not really needed, just to keep it consistent with TransferResumeList
  2514. FTransferResumeList = NULL;
  2515. FMoveToQueue = false;
  2516. Configuration->Usage->Inc("MovesToBackground");
  2517. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2518. ClearTransferSourceSelection(Direction);
  2519. }
  2520. throw;
  2521. }
  2522. }
  2523. __finally
  2524. {
  2525. if (!SelectionRestored && (DView != NULL))
  2526. {
  2527. DView->DiscardSavedSelection();
  2528. }
  2529. FTransferResumeList = NULL;
  2530. }
  2531. }
  2532. return Result;
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2536. TOperationSide Side, TStrings * FileList, void * Param)
  2537. {
  2538. DebugAssert(FileList->Count);
  2539. // We deliberately do not toggle alternative flag (Param), but use OR,
  2540. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2541. // shortcut of CurrentDeleteAlternativeAction
  2542. bool Alternative =
  2543. bool(Param) || UseAlternativeFunction();
  2544. bool Recycle;
  2545. if (IsSideLocalBrowser(Side))
  2546. {
  2547. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2548. }
  2549. else
  2550. {
  2551. Recycle =
  2552. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2553. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2554. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2555. }
  2556. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2557. if (!Result)
  2558. {
  2559. UnicodeString Query;
  2560. if (FileList->Count == 1)
  2561. {
  2562. if (IsSideLocalBrowser(Side))
  2563. {
  2564. Query = ExtractFileName(FileList->Strings[0]);
  2565. }
  2566. else
  2567. {
  2568. Query = UnixExtractFileName(FileList->Strings[0]);
  2569. }
  2570. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2571. }
  2572. else
  2573. {
  2574. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2575. }
  2576. TMessageParams Params(mpNeverAskAgainCheck);
  2577. Params.ImageName = L"Delete file";
  2578. unsigned int Answer =
  2579. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2580. if (Answer == qaNeverAskAgain)
  2581. {
  2582. Result = true;
  2583. if (Recycle)
  2584. {
  2585. WinConfiguration->ConfirmRecycling = false;
  2586. }
  2587. else
  2588. {
  2589. WinConfiguration->ConfirmDeleting = false;
  2590. }
  2591. }
  2592. else
  2593. {
  2594. Result = (Answer == qaOK);
  2595. }
  2596. }
  2597. if (Result)
  2598. {
  2599. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2600. }
  2601. return Result;
  2602. }
  2603. //---------------------------------------------------------------------------
  2604. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2605. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2606. {
  2607. TAutoBatch AutoBatch(this);
  2608. bool Result;
  2609. if ((Operation == foCopy) || (Operation == foMove))
  2610. {
  2611. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2612. }
  2613. else if (Operation == foRename)
  2614. {
  2615. DebugAssert(DirView(Side)->ItemFocused);
  2616. DirView(Side)->ItemFocused->EditCaption();
  2617. Result = true;
  2618. }
  2619. else if (Operation == foDelete)
  2620. {
  2621. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2622. }
  2623. else if (Operation == foSetProperties)
  2624. {
  2625. DirView(osRemote)->SaveSelectedNames();
  2626. Result = SetProperties(Side, FileList);
  2627. }
  2628. else if (Operation == foCustomCommand)
  2629. {
  2630. DebugAssert(Param);
  2631. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2632. DirView(osRemote)->SaveSelectedNames();
  2633. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2634. CustomCommand(FileList, *Command, NULL);
  2635. Result = true;
  2636. }
  2637. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2638. {
  2639. DebugAssert(!IsSideLocalBrowser(Side));
  2640. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2641. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2642. }
  2643. else if (Operation == foLock)
  2644. {
  2645. DebugAssert(!IsSideLocalBrowser(Side));
  2646. LockFiles(FileList, true);
  2647. Result = true;
  2648. }
  2649. else if (Operation == foUnlock)
  2650. {
  2651. DebugAssert(!IsSideLocalBrowser(Side));
  2652. LockFiles(FileList, false);
  2653. Result = true;
  2654. }
  2655. else
  2656. {
  2657. DebugFail();
  2658. }
  2659. return Result;
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2663. {
  2664. if (Side == osCurrent)
  2665. {
  2666. Side = FCurrentSide;
  2667. }
  2668. return Side;
  2669. }
  2670. //---------------------------------------------------------------------------
  2671. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2672. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2673. {
  2674. Side = GetSide(Side);
  2675. bool Result;
  2676. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2677. try
  2678. {
  2679. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2680. }
  2681. __finally
  2682. {
  2683. delete FileList;
  2684. }
  2685. return Result;
  2686. }
  2687. //---------------------------------------------------------------------------
  2688. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2689. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2690. bool NoConfirmation, void * Param)
  2691. {
  2692. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2693. {
  2694. if ((Operation == foCopy) || (Operation == foMove))
  2695. {
  2696. DebugAssert(!IsLocalBrowserMode());
  2697. if (GetSide(Side) == osLocal)
  2698. {
  2699. Configuration->Usage->Inc(L"UploadsCommand");
  2700. }
  2701. else
  2702. {
  2703. Configuration->Usage->Inc(L"DownloadsCommand");
  2704. }
  2705. }
  2706. }
  2707. }
  2708. //---------------------------------------------------------------------------
  2709. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2710. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2711. {
  2712. TTransferOperationParam Param;
  2713. if ((WinConfiguration->Interface != ifCommander) ||
  2714. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2715. {
  2716. Flags &= ~cocShortCutHint;
  2717. }
  2718. TCustomDirView * DView = DirView(Side);
  2719. Param.Options =
  2720. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2721. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2722. if (FLAGSET(Flags, cocQueue))
  2723. {
  2724. Param.Queue = asOn;
  2725. }
  2726. else if (FLAGSET(Flags, cocNonQueue))
  2727. {
  2728. Param.Queue = asOff;
  2729. }
  2730. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2731. }
  2732. //---------------------------------------------------------------------------
  2733. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2734. {
  2735. try
  2736. {
  2737. if (ErrorList->Count)
  2738. {
  2739. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2740. if (MessageDialog(Message, qtError,
  2741. qaOK | qaCancel, HELP_NONE) == qaOK)
  2742. {
  2743. unsigned int Answer;
  2744. int Index = 0;
  2745. do
  2746. {
  2747. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2748. TQueryButtonAlias Aliases[2];
  2749. Aliases[0].Button = qaYes;
  2750. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2751. Aliases[1].Button = qaNo;
  2752. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2753. TMessageParams Params;
  2754. Params.Aliases = Aliases;
  2755. Params.AliasesCount = LENOF(Aliases);
  2756. Answer = MoreMessageDialog(
  2757. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2758. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2759. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2760. qaOK, HELP_NONE, &Params);
  2761. if (Answer == qaNo)
  2762. {
  2763. Index++;
  2764. }
  2765. if (Answer == qaYes)
  2766. {
  2767. Index--;
  2768. }
  2769. }
  2770. while (Answer != qaOK);
  2771. }
  2772. }
  2773. }
  2774. __finally
  2775. {
  2776. TStrings * List = ErrorList;
  2777. ErrorList = NULL;
  2778. for (int i = 0; i < List->Count; i++)
  2779. {
  2780. delete List->Objects[i];
  2781. }
  2782. delete List;
  2783. }
  2784. }
  2785. //---------------------------------------------------------------------------
  2786. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2787. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2788. {
  2789. // needed for checking filemasks, as there's no directory object
  2790. // associated with the file object
  2791. File->FullFileName = FullFileName;
  2792. TFileMasks::TParams MaskParams;
  2793. MaskParams.Size = File->Size;
  2794. MaskParams.Modification = File->Modification;
  2795. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2796. }
  2797. //---------------------------------------------------------------------------
  2798. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2799. {
  2800. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2801. Side = GetSide(Side);
  2802. TCustomDirView * DView = DirView(Side);
  2803. TListItem * FocusedItem = DView->ItemFocused;
  2804. UnicodeString Name;
  2805. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2806. {
  2807. Name = DView->ItemFileName(FocusedItem);
  2808. }
  2809. else
  2810. {
  2811. Name = LoadStr(NEW_FILE);
  2812. }
  2813. UnicodeString Names = Name;
  2814. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2815. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2816. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2817. {
  2818. while (!Names.IsEmpty())
  2819. {
  2820. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2821. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2822. UnicodeString TargetFileName;
  2823. UnicodeString LocalFileName;
  2824. UnicodeString RootTempDir;
  2825. UnicodeString TempDir;
  2826. UnicodeString RemoteDirectory;
  2827. bool ExistingFile = false;
  2828. if (!IsSideLocalBrowser(Side))
  2829. {
  2830. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2831. TRemoteFile * File = NULL;
  2832. if (FTerminal->FileExists(Name, &File) &&
  2833. !File->IsDirectory)
  2834. {
  2835. try
  2836. {
  2837. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2838. ExistingFile = true;
  2839. }
  2840. __finally
  2841. {
  2842. delete File;
  2843. }
  2844. }
  2845. if (!ExistingFile)
  2846. {
  2847. RemoteDirectory = UnixExtractFilePath(Name);
  2848. TemporaryDirectoryForRemoteFiles(
  2849. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2850. TargetFileName = UnixExtractFileName(Name);
  2851. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2852. LocalFileName = TempDir +
  2853. // We probably do not want to trim the VMS version here
  2854. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if (ExtractFilePath(Name).IsEmpty())
  2860. {
  2861. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2862. }
  2863. else
  2864. {
  2865. LocalFileName = ExpandFileName(Name);
  2866. }
  2867. TargetFileName = ExtractFileName(Name);
  2868. }
  2869. if (!ExistingFile)
  2870. {
  2871. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2872. if (NewFile)
  2873. {
  2874. int File = FileCreate(ApiPath(LocalFileName));
  2875. if (File < 0)
  2876. {
  2877. if (!RootTempDir.IsEmpty())
  2878. {
  2879. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2880. }
  2881. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2882. }
  2883. else
  2884. {
  2885. FileClose(File);
  2886. }
  2887. }
  2888. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2889. const TEditorData * ExternalEditor = NULL;
  2890. TFileMasks::TParams MaskParams; // size not known
  2891. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2892. false, MaskParams);
  2893. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2894. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2895. }
  2896. }
  2897. }
  2898. }
  2899. //---------------------------------------------------------------------------
  2900. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2901. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2902. {
  2903. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2904. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2905. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2906. return
  2907. ((ExecuteFileBy == efInternalEditor)) ||
  2908. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2909. }
  2910. //---------------------------------------------------------------------------
  2911. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2912. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2913. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2914. UnicodeString RemoteDirectory, bool NewFile)
  2915. {
  2916. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2917. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2918. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2919. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2920. Side = GetSide(Side);
  2921. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2922. if (!IsSideLocalBrowser(Side))
  2923. {
  2924. Data->Terminal = Terminal;
  2925. Data->Queue = Queue;
  2926. Data->SessionData = CloneCurrentSessionData();
  2927. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2928. Data->RemoteDirectory = RemoteDirectory;
  2929. Data->SessionName = Terminal->SessionData->SessionName;
  2930. Data->LocalRootDirectory = LocalRootDirectory;
  2931. Data->OriginalFileName = OriginalFileName;
  2932. Data->Command = L""; // will be changed later for external editor
  2933. }
  2934. if (ExecuteFileBy == efInternalEditor)
  2935. {
  2936. if (!IsSideLocalBrowser(Side))
  2937. {
  2938. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2939. L" - " + Terminal->SessionData->SessionName;
  2940. TForm * Editor;
  2941. try
  2942. {
  2943. TNotifyEvent OnFileChanged = NULL;
  2944. TNotifyEvent OnSaveAll = NULL;
  2945. TAnyModifiedEvent OnAnyModified = NULL;
  2946. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2947. if (Terminal->IsCapable[fcBackgroundTransfers])
  2948. {
  2949. OnFileChanged = FEditorManager->FileChanged;
  2950. OnSaveAll = SaveAllInternalEditors;
  2951. OnAnyModified = AnyInternalEditorModified;
  2952. }
  2953. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2954. FEditorManager->FileReload, FEditorManager->FileClosed,
  2955. OnSaveAll, OnAnyModified,
  2956. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2957. }
  2958. catch(...)
  2959. {
  2960. if (!LocalRootDirectory.IsEmpty())
  2961. {
  2962. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2963. }
  2964. throw;
  2965. }
  2966. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2967. }
  2968. else
  2969. {
  2970. DebugAssert(!FStandaloneEditing);
  2971. TForm * Editor =
  2972. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2973. SaveAllInternalEditors, AnyInternalEditorModified,
  2974. L"", false, SessionColor, -1, NewFile);
  2975. FLocalEditors->Add(Editor);
  2976. }
  2977. }
  2978. else
  2979. {
  2980. HANDLE Process;
  2981. if (ExecuteFileBy == efExternalEditor)
  2982. {
  2983. UnicodeString Program, Params, Dir;
  2984. Data->Command = ExternalEditor->ExternalEditor;
  2985. ReformatFileNameCommand(Data->Command);
  2986. SplitCommand(Data->Command, Program, Params, Dir);
  2987. Params = ExpandFileNameCommand(Params, FileName);
  2988. Program = ExpandEnvironmentVariables(Program);
  2989. if (!ExecuteShell(Program, Params, Process))
  2990. {
  2991. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2992. }
  2993. }
  2994. else
  2995. {
  2996. DebugAssert(!IsSideLocalBrowser(Side));
  2997. if (!ExecuteShell(FileName, L"", Process))
  2998. {
  2999. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3000. }
  3001. }
  3002. if (IsSideLocalBrowser(Side) ||
  3003. ((ExecuteFileBy == efShell) &&
  3004. !WinConfiguration->Editor.SDIShellEditor) ||
  3005. ((ExecuteFileBy == efExternalEditor) &&
  3006. !ExternalEditor->SDIExternalEditor))
  3007. {
  3008. // no need for handle
  3009. if (Process != NULL)
  3010. {
  3011. DebugCheck(CloseHandle(Process));
  3012. }
  3013. Process = INVALID_HANDLE_VALUE;
  3014. }
  3015. else
  3016. {
  3017. if (Process == NULL)
  3018. {
  3019. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3020. }
  3021. }
  3022. if (!IsSideLocalBrowser(Side))
  3023. {
  3024. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3025. }
  3026. }
  3027. }
  3028. //---------------------------------------------------------------------------
  3029. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3030. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3031. void * /*Arg*/)
  3032. {
  3033. if (Token != NULL)
  3034. {
  3035. EditorFormFileSave(static_cast<TForm *>(Token));
  3036. }
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3040. {
  3041. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3042. {
  3043. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3044. }
  3045. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * Arg)
  3051. {
  3052. if ((Token != NULL) &&
  3053. IsEditorFormModified(static_cast<TForm *>(Token)))
  3054. {
  3055. *static_cast<bool *>(Arg) = true;
  3056. }
  3057. }
  3058. //---------------------------------------------------------------------------
  3059. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3060. TObject * /*Sender*/, bool & Modified)
  3061. {
  3062. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3063. {
  3064. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3065. {
  3066. Modified = true;
  3067. }
  3068. }
  3069. if (!Modified)
  3070. {
  3071. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3072. }
  3073. }
  3074. //---------------------------------------------------------------------------
  3075. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3076. {
  3077. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3078. }
  3079. //---------------------------------------------------------------------------
  3080. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3081. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3082. UnicodeString & Result, UnicodeString & RootDirectory)
  3083. {
  3084. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3085. {
  3086. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3087. Result = RootDirectory;
  3088. }
  3089. else
  3090. {
  3091. RootDirectory = L"";
  3092. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3093. Result = IncludeTrailingBackslash(Result);
  3094. }
  3095. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3096. {
  3097. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3098. }
  3099. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3100. {
  3101. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3102. {
  3103. RemoteDirectory.Delete(1, 1);
  3104. }
  3105. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3106. }
  3107. if (!ForceDirectories(ApiPath(Result)))
  3108. {
  3109. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3110. }
  3111. }
  3112. //---------------------------------------------------------------------------
  3113. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3114. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3115. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3116. {
  3117. DebugAssert(!IsLocalBrowserMode());
  3118. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3119. if (ForceText)
  3120. {
  3121. CopyParam.TransferMode = tmAscii;
  3122. }
  3123. TemporaryFileCopyParam(CopyParam);
  3124. if (AllFiles)
  3125. {
  3126. CopyParam.IncludeFileMask = TFileMasks();
  3127. }
  3128. if (TempDir.IsEmpty())
  3129. {
  3130. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3131. }
  3132. DebugAssert(!FAutoOperation);
  3133. FAutoOperation = AutoOperation;
  3134. Terminal->ExceptionOnFail = true;
  3135. try
  3136. {
  3137. try
  3138. {
  3139. // turn off confirmations, as for MDI editors we may possibly download
  3140. // the same file over
  3141. Terminal->CopyToLocal(
  3142. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3143. if (GetTargetNames)
  3144. {
  3145. for (int i = 0; i < FileList->Count; i++)
  3146. {
  3147. FileList->Strings[i] =
  3148. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3149. }
  3150. }
  3151. }
  3152. catch(...)
  3153. {
  3154. if (!RootTempDir.IsEmpty())
  3155. {
  3156. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3157. }
  3158. throw;
  3159. }
  3160. }
  3161. __finally
  3162. {
  3163. FAutoOperation = false;
  3164. Terminal->ExceptionOnFail = false;
  3165. }
  3166. }
  3167. //---------------------------------------------------------------------------
  3168. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3169. {
  3170. // Do not waste time checking for default editor list the next time,
  3171. // or testing if default editor is not notepad.
  3172. bool TryNextTime = false;
  3173. UnicodeString UsageState;
  3174. if (!WinConfiguration->EditorList->IsDefaultList())
  3175. {
  3176. UsageState = "H";
  3177. }
  3178. else
  3179. {
  3180. UnicodeString Executable;
  3181. UnicodeString ExecutableDescription;
  3182. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3183. {
  3184. UnicodeString Message =
  3185. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3186. unsigned int Answer =
  3187. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3188. if (Answer != qaOK)
  3189. {
  3190. UsageState = "R";
  3191. }
  3192. else
  3193. {
  3194. UsageState = "A";
  3195. TEditorData EditorData;
  3196. EditorData.Editor = edExternal;
  3197. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3198. EditorData.ExternalEditorOptionsAutodetect();
  3199. TEditorList EditorList;
  3200. EditorList = *WinConfiguration->EditorList;
  3201. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3202. WinConfiguration->EditorList = &EditorList;
  3203. }
  3204. }
  3205. }
  3206. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3207. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3208. }
  3209. //---------------------------------------------------------------------------
  3210. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3211. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3212. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3213. {
  3214. if (ExecuteFileBy == efDefaultEditor)
  3215. {
  3216. if (!WinConfiguration->OfferedEditorAutoConfig)
  3217. {
  3218. EditorAutoConfig();
  3219. }
  3220. const TEditorPreferences * Editor =
  3221. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3222. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3223. {
  3224. ExecuteFileBy = efInternalEditor;
  3225. ExternalEditor = NULL;
  3226. }
  3227. else if (Editor->Data->Editor == edOpen)
  3228. {
  3229. ExecuteFileBy = efShell;
  3230. ExternalEditor = NULL;
  3231. }
  3232. else
  3233. {
  3234. ExecuteFileBy = efExternalEditor;
  3235. ExternalEditor = Editor->Data;
  3236. }
  3237. }
  3238. }
  3239. //---------------------------------------------------------------------------
  3240. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3241. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3242. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3243. {
  3244. UnicodeString OriginalFileName;
  3245. UnicodeString LocalRootDirectory;
  3246. UnicodeString RemoteDirectory;
  3247. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3248. IsSideLocalBrowser(Side), MaskParams);
  3249. UnicodeString Counter;
  3250. UnicodeString LocalFileName;
  3251. bool Handled = false;
  3252. if (!IsSideLocalBrowser(Side))
  3253. {
  3254. // We need to trim VMS version here, so that we use name without version
  3255. // when uploading back to create a new version of the file
  3256. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3257. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3258. TObject * Token = NULL;
  3259. UnicodeString LocalDirectory;
  3260. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3261. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3262. LocalDirectory))
  3263. {
  3264. if (Token != NULL)
  3265. {
  3266. TForm * Form = dynamic_cast<TForm *>(Token);
  3267. if (Form->WindowState == wsMinimized)
  3268. {
  3269. ShowWindow(Form->Handle, SW_RESTORE);
  3270. }
  3271. else
  3272. {
  3273. Form->SetFocus();
  3274. }
  3275. Handled = true;
  3276. }
  3277. else
  3278. {
  3279. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3280. }
  3281. }
  3282. if (!Handled)
  3283. {
  3284. TStringList * FileList1 = new TStringList();
  3285. try
  3286. {
  3287. FileList1->AddObject(FullFileName, Object);
  3288. TemporarilyDownloadFiles(FileList1,
  3289. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3290. LocalRootDirectory, LocalDirectory, true, true, true);
  3291. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3292. }
  3293. __finally
  3294. {
  3295. delete FileList1;
  3296. }
  3297. switch (ExecuteFileBy)
  3298. {
  3299. case efShell:
  3300. Counter = "RemoteFilesExecuted";
  3301. break;
  3302. case efInternalEditor:
  3303. Counter = "RemoteFilesOpenedInInternalEditor";
  3304. break;
  3305. case efExternalEditor:
  3306. Counter = "RemoteFilesOpenedInExternalEditor";
  3307. break;
  3308. default:
  3309. DebugFail();
  3310. }
  3311. }
  3312. }
  3313. else
  3314. {
  3315. LocalFileName = FullFileName;
  3316. OriginalFileName = ExtractFileName(FullFileName);
  3317. switch (ExecuteFileBy)
  3318. {
  3319. case efShell:
  3320. Counter = "LocalFilesExecuted";
  3321. break;
  3322. case efInternalEditor:
  3323. Counter = "LocalFilesOpenedInInternalEditor";
  3324. break;
  3325. case efExternalEditor:
  3326. Counter = "LocalFilesOpenedInExternalEditor";
  3327. break;
  3328. default:
  3329. DebugFail();
  3330. }
  3331. }
  3332. if (!Handled)
  3333. {
  3334. Configuration->Usage->Inc(Counter);
  3335. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3336. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3337. }
  3338. }
  3339. //---------------------------------------------------------------------------
  3340. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3341. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3342. bool AllSelected, bool OnFocused)
  3343. {
  3344. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3345. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3346. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3347. Side = GetSide(Side);
  3348. TCustomDirView * DView = DirView(Side);
  3349. TStrings * FileList =
  3350. AllSelected ?
  3351. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3352. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3353. try
  3354. {
  3355. DebugAssert(AllSelected || (FileList->Count == 1));
  3356. for (int i = 0; i < FileList->Count; i++)
  3357. {
  3358. UnicodeString ListFileName = FileList->Strings[i];
  3359. UnicodeString FileNameOnly =
  3360. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3361. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3362. if (!DView->ItemIsDirectory(Item))
  3363. {
  3364. UnicodeString FullFileName;
  3365. if (!IsSideLocalBrowser(Side))
  3366. {
  3367. FullFileName = DirView(Side)->Path + ListFileName;
  3368. }
  3369. else
  3370. {
  3371. FullFileName = ListFileName;
  3372. }
  3373. TFileMasks::TParams MaskParams;
  3374. MaskParams.Size = DView->ItemFileSize(Item);
  3375. TDateTimePrecision Precision;
  3376. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3377. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3378. FileList->Objects[i], MaskParams);
  3379. }
  3380. }
  3381. }
  3382. __finally
  3383. {
  3384. delete FileList;
  3385. }
  3386. }
  3387. //---------------------------------------------------------------------------
  3388. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3389. {
  3390. CopyParam.FileNameCase = ncNoChange;
  3391. CopyParam.PreserveRights = false;
  3392. CopyParam.PreserveReadOnly = false;
  3393. CopyParam.ReplaceInvalidChars = true;
  3394. CopyParam.IncludeFileMask = TFileMasks();
  3395. CopyParam.NewerOnly = false;
  3396. CopyParam.FileMask = L"";
  3397. }
  3398. //---------------------------------------------------------------------------
  3399. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3400. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3401. {
  3402. TTerminalManager * Manager = TTerminalManager::Instance();
  3403. if (!IsActiveTerminal(Data->Terminal))
  3404. {
  3405. if (!NonVisualDataModule->Busy)
  3406. {
  3407. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3408. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3409. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3410. if (Data->Terminal == NULL)
  3411. {
  3412. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3413. if (SameSiteTerminal != NULL)
  3414. {
  3415. UnicodeString Message =
  3416. FMTLOAD(EDIT_SESSION_REATTACH,
  3417. (FileNameOnly, Data->SessionName, FileNameOnly));
  3418. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3419. {
  3420. Data->Terminal = Terminal;
  3421. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3422. Data->SessionName = Terminal->SessionData->SessionName;
  3423. // We might also overwrite session data
  3424. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3425. }
  3426. else
  3427. {
  3428. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3429. Abort();
  3430. }
  3431. }
  3432. }
  3433. // foreground session should reconnect itself
  3434. else if (Terminal != Data->Terminal)
  3435. {
  3436. UnicodeString Message =
  3437. MainInstructions(
  3438. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3439. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3440. {
  3441. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3442. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3443. }
  3444. else
  3445. {
  3446. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3447. Abort();
  3448. }
  3449. }
  3450. }
  3451. if (!IsActiveTerminal(Data->Terminal))
  3452. {
  3453. Configuration->Usage->Inc(L"EditInactiveSession");
  3454. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3455. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3456. (ExtractFileName(FileName), Data->SessionName)));
  3457. }
  3458. }
  3459. TStrings * FileList = new TStringList();
  3460. try
  3461. {
  3462. FileList->Add(FileName);
  3463. // consider using the same settings (preset) as when the file was downloaded
  3464. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3465. TemporaryFileCopyParam(CopyParam);
  3466. if (Data->ForceText)
  3467. {
  3468. CopyParam.TransferMode = tmAscii;
  3469. }
  3470. // so i do not need to worry if masking algorithm works in all cases
  3471. // ("" means "copy file name", no masking is actually done)
  3472. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3473. {
  3474. CopyParam.FileMask = L"";
  3475. }
  3476. else
  3477. {
  3478. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3479. }
  3480. DebugAssert(Data->Queue != NULL);
  3481. int Params = cpNoConfirmation | cpTemporary;
  3482. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3483. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3484. QueueItem->CompleteEvent = UploadCompleteEvent;
  3485. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3486. }
  3487. __finally
  3488. {
  3489. delete FileList;
  3490. }
  3491. }
  3492. //---------------------------------------------------------------------------
  3493. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3494. const UnicodeString FileName, const TEditedFileData * Data)
  3495. {
  3496. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3497. DebugAssert(!NonVisualDataModule->Busy);
  3498. if (!IsActiveTerminal(Data->Terminal))
  3499. {
  3500. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3501. (ExtractFileName(FileName), Data->SessionName)));
  3502. }
  3503. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3504. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3505. NonVisualDataModule->StartBusy();
  3506. try
  3507. {
  3508. std::unique_ptr<TRemoteFile> File;
  3509. UnicodeString RemoteFileName =
  3510. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3511. FTerminal->ExceptionOnFail = true;
  3512. try
  3513. {
  3514. TRemoteFile * AFile = NULL;
  3515. FTerminal->ReadFile(RemoteFileName, AFile);
  3516. File.reset(AFile);
  3517. if (!File->HaveFullFileName)
  3518. {
  3519. File->FullFileName = RemoteFileName;
  3520. }
  3521. }
  3522. __finally
  3523. {
  3524. FTerminal->ExceptionOnFail = false;
  3525. }
  3526. std::unique_ptr<TStrings> FileList(new TStringList());
  3527. FileList->AddObject(RemoteFileName, File.get());
  3528. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3529. UnicodeString TempDir = ExtractFilePath(FileName);
  3530. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3531. TempDir, true, true, true);
  3532. // sanity check, the target file name should be still the same
  3533. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3534. }
  3535. __finally
  3536. {
  3537. NonVisualDataModule->EndBusy();
  3538. // it actually may not exist anymore...
  3539. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3540. }
  3541. }
  3542. //---------------------------------------------------------------------------
  3543. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3544. const TEditedFileData * Data, bool & KeepOpen)
  3545. {
  3546. // Command is set for external editors only (not for "shell" open).
  3547. if (!Data->Command.IsEmpty())
  3548. {
  3549. bool AnyFound = false;
  3550. bool AnyMDI = false;
  3551. bool AnyNonMDI = false;
  3552. bool AnyDetect = false;
  3553. TEditorList * EditorList = new TEditorList();
  3554. try
  3555. {
  3556. *EditorList = *WinConfiguration->EditorList;
  3557. for (int i = 0; i < EditorList->Count; i++)
  3558. {
  3559. const TEditorPreferences * Editor = EditorList->Editors[i];
  3560. if ((Editor->Data->Editor == edExternal) &&
  3561. (Editor->Data->ExternalEditor == Data->Command))
  3562. {
  3563. AnyFound = true;
  3564. if (Editor->Data->SDIExternalEditor)
  3565. {
  3566. AnyNonMDI = true;
  3567. if (Editor->Data->DetectMDIExternalEditor)
  3568. {
  3569. AnyDetect = true;
  3570. }
  3571. }
  3572. else
  3573. {
  3574. AnyMDI = true;
  3575. }
  3576. }
  3577. }
  3578. bool EnableMDI = false;
  3579. bool DisableDetect = false;
  3580. if (AnyMDI)
  3581. {
  3582. KeepOpen = true;
  3583. if (AnyNonMDI)
  3584. {
  3585. // there is at least one instance of the editor with MDI support enabled,
  3586. // and one with disabled, enable it for all instances
  3587. EnableMDI = true;
  3588. }
  3589. }
  3590. else if (AnyFound && !AnyDetect)
  3591. {
  3592. // at least once instance found but all have MDI autodetection disabled
  3593. // => close the file (default action)
  3594. }
  3595. else
  3596. {
  3597. // no instance of the editor has MDI support enabled
  3598. TMessageParams Params;
  3599. if (AnyFound)
  3600. {
  3601. // there is at least one instance of the editor
  3602. Params.Params |= mpNeverAskAgainCheck;
  3603. }
  3604. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3605. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3606. switch (Answer)
  3607. {
  3608. case qaNeverAskAgain:
  3609. DisableDetect = true;
  3610. break;
  3611. case qaNo:
  3612. EnableMDI = true;
  3613. KeepOpen = true;
  3614. break;
  3615. }
  3616. }
  3617. if (AnyFound && (EnableMDI || DisableDetect))
  3618. {
  3619. bool Changed = false;
  3620. for (int i = 0; i < EditorList->Count; i++)
  3621. {
  3622. const TEditorPreferences * Editor = EditorList->Editors[i];
  3623. if ((Editor->Data->Editor == edExternal) &&
  3624. (Editor->Data->ExternalEditor == Data->Command) &&
  3625. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3626. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3627. {
  3628. Changed = true;
  3629. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3630. if (EnableMDI)
  3631. {
  3632. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3633. }
  3634. if (DisableDetect)
  3635. {
  3636. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3637. }
  3638. EditorList->Change(i, UpdatedEditor);
  3639. }
  3640. }
  3641. if (Changed)
  3642. {
  3643. WinConfiguration->EditorList = EditorList;
  3644. }
  3645. }
  3646. }
  3647. __finally
  3648. {
  3649. delete EditorList;
  3650. }
  3651. }
  3652. else
  3653. {
  3654. // "open" case
  3655. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3656. qaOK, HELP_APP_EARLY_CLOSED);
  3657. }
  3658. }
  3659. //---------------------------------------------------------------------------
  3660. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3661. {
  3662. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3663. }
  3664. //---------------------------------------------------------------------------
  3665. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3666. {
  3667. SideEnter(osRemote);
  3668. }
  3669. //---------------------------------------------------------------------------
  3670. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3671. {
  3672. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3673. SideEnter(osRemote);
  3674. }
  3675. //---------------------------------------------------------------------------
  3676. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3677. {
  3678. FCurrentSide = Side;
  3679. if (Visible)
  3680. {
  3681. UpdateControls();
  3682. }
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3686. TStrings * FileList, bool Alternative)
  3687. {
  3688. TCustomDirView * DView = DirView(Side);
  3689. DView->SaveSelection();
  3690. DView->SaveSelectedNames();
  3691. DebugAssert(!FAlternativeDelete);
  3692. FAlternativeDelete = Alternative;
  3693. try
  3694. {
  3695. if (!IsSideLocalBrowser(Side))
  3696. {
  3697. DebugAssert(Terminal != NULL);
  3698. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3699. }
  3700. else
  3701. {
  3702. try
  3703. {
  3704. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3705. }
  3706. __finally
  3707. {
  3708. ReloadLocalDirectory();
  3709. }
  3710. }
  3711. FAlternativeDelete = false;
  3712. }
  3713. catch(...)
  3714. {
  3715. FAlternativeDelete = false;
  3716. DView->DiscardSavedSelection();
  3717. throw;
  3718. }
  3719. DView->RestoreSelection();
  3720. }
  3721. //---------------------------------------------------------------------------
  3722. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3723. {
  3724. DebugAssert(Terminal);
  3725. DebugAssert(!IsLocalBrowserMode());
  3726. RemoteDirView->SaveSelection();
  3727. RemoteDirView->SaveSelectedNames();
  3728. try
  3729. {
  3730. if (Lock)
  3731. {
  3732. Terminal->LockFiles(FileList);
  3733. }
  3734. else
  3735. {
  3736. Terminal->UnlockFiles(FileList);
  3737. }
  3738. }
  3739. catch(...)
  3740. {
  3741. RemoteDirView->DiscardSavedSelection();
  3742. throw;
  3743. }
  3744. RemoteDirView->RestoreSelection();
  3745. }
  3746. //---------------------------------------------------------------------------
  3747. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3748. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3749. bool NoConfirmation, bool Move)
  3750. {
  3751. DebugAssert(Terminal != NULL);
  3752. DebugAssert(!IsLocalBrowserMode());
  3753. // update Terminal->StateData->RemoteDirectory
  3754. UpdateTerminal(Terminal);
  3755. if (Session == NULL)
  3756. {
  3757. Session = TTerminalManager::Instance()->ActiveTerminal;
  3758. }
  3759. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3760. {
  3761. if (RemoteDriveView->DropTarget != NULL)
  3762. {
  3763. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3764. }
  3765. else if (RemoteDirView->DropTarget != NULL)
  3766. {
  3767. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3768. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3769. }
  3770. else
  3771. {
  3772. Target = RemoteDirView->Path;
  3773. }
  3774. }
  3775. else
  3776. {
  3777. Target = Session->StateData->RemoteDirectory;
  3778. }
  3779. Target = UnixIncludeTrailingBackslash(Target);
  3780. if (FileList->Count == 1)
  3781. {
  3782. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3783. }
  3784. else
  3785. {
  3786. FileMask = AnyMask;
  3787. }
  3788. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3789. bool Result = true;
  3790. if (!NoConfirmation)
  3791. {
  3792. bool Multi = (FileList->Count > 1);
  3793. if (Move)
  3794. {
  3795. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3796. }
  3797. else
  3798. {
  3799. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3800. TStrings * Directories = new TStringList;
  3801. try
  3802. {
  3803. for (int Index = 0; Index < Sessions->Count; Index++)
  3804. {
  3805. TManagedTerminal * Terminal =
  3806. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3807. Directories->Add(Terminal->StateData->RemoteDirectory);
  3808. }
  3809. TDirectRemoteCopy AllowDirectCopy;
  3810. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3811. {
  3812. DebugAssert(DirectCopy);
  3813. AllowDirectCopy = drcAllow;
  3814. }
  3815. else if (FTerminal->IsCapable[fcSecondaryShell])
  3816. {
  3817. DebugAssert(DirectCopy);
  3818. AllowDirectCopy = drcConfirmCommandSession;
  3819. }
  3820. else
  3821. {
  3822. DebugAssert(!DirectCopy);
  3823. AllowDirectCopy = drcDisallow;
  3824. }
  3825. void * ASession = Session;
  3826. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3827. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3828. Session = static_cast<TManagedTerminal *>(ASession);
  3829. }
  3830. __finally
  3831. {
  3832. delete Directories;
  3833. }
  3834. }
  3835. }
  3836. return Result;
  3837. }
  3838. //---------------------------------------------------------------------------
  3839. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3840. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3841. {
  3842. DebugAssert(!IsLocalBrowserMode());
  3843. bool DirectCopy;
  3844. UnicodeString Target, FileMask;
  3845. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3846. if (Result)
  3847. {
  3848. if (!Move && !DirectCopy)
  3849. {
  3850. Configuration->Usage->Inc("RemoteCopyTemp");
  3851. UnicodeString RootTempDir;
  3852. UnicodeString TempDir;
  3853. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3854. TStrings * TemporaryFilesList = new TStringList();
  3855. try
  3856. {
  3857. TMakeLocalFileListParams MakeFileListParam;
  3858. MakeFileListParam.FileList = TemporaryFilesList;
  3859. MakeFileListParam.FileTimes = NULL;
  3860. MakeFileListParam.IncludeDirs = true;
  3861. MakeFileListParam.Recursive = false;
  3862. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3863. TTerminalManager::Instance()->ActiveTerminal = Session;
  3864. if (TemporaryFilesList->Count > 0)
  3865. {
  3866. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3867. CopyParam.FileMask = FileMask;
  3868. DebugAssert(!FAutoOperation);
  3869. FAutoOperation = true;
  3870. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3871. }
  3872. }
  3873. __finally
  3874. {
  3875. delete TemporaryFilesList;
  3876. FAutoOperation = false;
  3877. if (!RootTempDir.IsEmpty())
  3878. {
  3879. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3880. }
  3881. }
  3882. }
  3883. else
  3884. {
  3885. RemoteDirView->SaveSelection();
  3886. RemoteDirView->SaveSelectedNames();
  3887. try
  3888. {
  3889. if (Move)
  3890. {
  3891. Configuration->Usage->Inc("RemoteMove");
  3892. Terminal->MoveFiles(FileList, Target, FileMask);
  3893. }
  3894. else
  3895. {
  3896. Configuration->Usage->Inc("RemoteCopyDirect");
  3897. DebugAssert(DirectCopy);
  3898. DebugAssert(Session == FTerminal);
  3899. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3900. FTerminal->CommandSessionOpened ||
  3901. CommandSessionFallback())
  3902. {
  3903. Terminal->CopyFiles(FileList, Target, FileMask);
  3904. }
  3905. }
  3906. }
  3907. catch(...)
  3908. {
  3909. RemoteDirView->DiscardSavedSelection();
  3910. throw;
  3911. }
  3912. RemoteDirView->RestoreSelection();
  3913. }
  3914. }
  3915. return Result;
  3916. }
  3917. //---------------------------------------------------------------------------
  3918. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3919. const UnicodeString & Path, TRemoteProperties & Properties)
  3920. {
  3921. DebugAssert(!IsLocalBrowserMode());
  3922. Properties.Valid = Properties.Valid << vpEncrypt;
  3923. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3924. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3925. }
  3926. //---------------------------------------------------------------------------
  3927. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3928. {
  3929. Side = GetSide(Side);
  3930. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3931. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3932. UnicodeString Name = LoadStr(NEW_FOLDER);
  3933. int AllowedChanges =
  3934. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3935. bool SaveSettings = false;
  3936. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3937. {
  3938. TWindowLock Lock(this);
  3939. if (!IsSideLocalBrowser(Side))
  3940. {
  3941. if (SaveSettings)
  3942. {
  3943. GUIConfiguration->NewDirectoryProperties = Properties;
  3944. }
  3945. CreateRemoteDirectory(Name, Properties);
  3946. }
  3947. else
  3948. {
  3949. DirView(Side)->CreateDirectory(Name);
  3950. }
  3951. }
  3952. }
  3953. //---------------------------------------------------------------------------
  3954. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3955. {
  3956. TWindowLock Lock(this);
  3957. DirView(Side)->ExecuteHomeDirectory();
  3958. }
  3959. //---------------------------------------------------------------------------
  3960. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3961. {
  3962. DoOpenDirectoryDialog(odBrowse, Side);
  3963. }
  3964. //---------------------------------------------------------------------------
  3965. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3966. {
  3967. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3968. bool Result = !Path.IsEmpty();
  3969. if (Result)
  3970. {
  3971. // While we might get here when the session is closed (from location profiles),
  3972. // it's not a problem as the Path setter is noop then
  3973. DirView(Side)->Path = Path;
  3974. }
  3975. return Result;
  3976. }
  3977. //---------------------------------------------------------------------------
  3978. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3979. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3980. bool & Close)
  3981. {
  3982. // terminal can be already closed (e.g. dropped connection)
  3983. if (Terminal != NULL)
  3984. {
  3985. try
  3986. {
  3987. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3988. }
  3989. catch(...)
  3990. {
  3991. if (!Terminal->Active)
  3992. {
  3993. Close = true;
  3994. }
  3995. throw;
  3996. }
  3997. }
  3998. }
  3999. //---------------------------------------------------------------------------
  4000. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4001. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4002. bool & Close)
  4003. {
  4004. // terminal can be already closed (e.g. dropped connection)
  4005. if (Terminal != NULL)
  4006. {
  4007. Configuration->Usage->Inc(L"ChecksumCalculated");
  4008. try
  4009. {
  4010. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4011. }
  4012. catch(...)
  4013. {
  4014. if (!Terminal->Active)
  4015. {
  4016. Close = true;
  4017. }
  4018. throw;
  4019. }
  4020. }
  4021. }
  4022. //---------------------------------------------------------------------------
  4023. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4024. {
  4025. bool Result;
  4026. if (!IsSideLocalBrowser(Side))
  4027. {
  4028. TRemoteTokenList * GroupList = NULL;
  4029. TRemoteTokenList * UserList = NULL;
  4030. try
  4031. {
  4032. TRemoteProperties CurrentProperties;
  4033. if (Terminal->LoadFilesProperties(FileList))
  4034. {
  4035. RemoteDirView->Invalidate();
  4036. }
  4037. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4038. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4039. if (CapableGroupChanging || CapableOwnerChanging)
  4040. {
  4041. if (CapableGroupChanging)
  4042. {
  4043. GroupList = Terminal->Groups->Duplicate();
  4044. }
  4045. if (CapableOwnerChanging)
  4046. {
  4047. UserList = Terminal->Users->Duplicate();
  4048. }
  4049. TRemoteDirectory * Files = Terminal->Files;
  4050. int Count = Files->Count;
  4051. if (Count > 100)
  4052. {
  4053. Count = 100;
  4054. }
  4055. for (int Index = 0; Index < Count; Index++)
  4056. {
  4057. TRemoteFile * File = Files->Files[Index];
  4058. if (CapableGroupChanging)
  4059. {
  4060. GroupList->AddUnique(File->Group);
  4061. }
  4062. if (CapableOwnerChanging)
  4063. {
  4064. UserList->AddUnique(File->Owner);
  4065. }
  4066. }
  4067. // if we haven't collected tokens for all files in current directory,
  4068. // make sure we collect them at least for all selected files.
  4069. // (note that so far the files in FileList has to be from current direcotry)
  4070. if (Count < Files->Count)
  4071. {
  4072. for (int Index = 0; Index < FileList->Count; Index++)
  4073. {
  4074. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4075. if (CapableGroupChanging)
  4076. {
  4077. GroupList->AddUnique(File->Group);
  4078. }
  4079. if (CapableOwnerChanging)
  4080. {
  4081. UserList->AddUnique(File->Owner);
  4082. }
  4083. }
  4084. }
  4085. }
  4086. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4087. int Flags = 0;
  4088. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4089. if (CapableOwnerChanging) Flags |= cpOwner;
  4090. if (CapableGroupChanging) Flags |= cpGroup;
  4091. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4092. if (Terminal->IsCapable[fcCalculatingChecksum])
  4093. {
  4094. CalculateChecksumEvent = CalculateChecksum;
  4095. }
  4096. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4097. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4098. TRemoteProperties NewProperties = CurrentProperties;
  4099. Result =
  4100. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4101. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4102. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4103. CalculateSize, CalculateChecksumEvent);
  4104. if (Result)
  4105. {
  4106. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4107. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4108. }
  4109. }
  4110. __finally
  4111. {
  4112. delete GroupList;
  4113. delete UserList;
  4114. }
  4115. }
  4116. else
  4117. {
  4118. DirView(Side)->DisplayPropertiesMenu();
  4119. Result = true;
  4120. }
  4121. return Result;
  4122. }
  4123. //---------------------------------------------------------------------------
  4124. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4125. {
  4126. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4127. {
  4128. FIgnoreNextDialogChar = Key;
  4129. }
  4130. Key = 0;
  4131. }
  4132. //---------------------------------------------------------------------------
  4133. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4134. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4135. {
  4136. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4137. if (Command != NULL)
  4138. {
  4139. KeyProcessed(Key, Shift);
  4140. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4141. {
  4142. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4143. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4144. false, false, const_cast<TCustomCommandType *>(Command));
  4145. }
  4146. }
  4147. }
  4148. //---------------------------------------------------------------------------
  4149. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4150. {
  4151. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4152. {
  4153. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4154. }
  4155. if (!DirView(osCurrent)->IsEditing())
  4156. {
  4157. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4158. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4159. {
  4160. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4161. if (((Action->ShortCut == KeyShortCut) ||
  4162. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4163. AllowedAction(Action, aaShortCut))
  4164. {
  4165. // Has to be called before the action as the dialog char is already in queue.
  4166. // So when the action consumes message queue, we already need to have the
  4167. // FIgnoreNextDialogChar set
  4168. KeyProcessed(Key, Shift);
  4169. // Reset reference to previous component (when menu/toolbar was clicked).
  4170. // Needed to detect that action was invoked by keyboard shortcut
  4171. // in TNonVisualDataModule::ExplorerActionsExecute
  4172. Action->ActionComponent = NULL;
  4173. Action->Execute();
  4174. return;
  4175. }
  4176. }
  4177. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4178. {
  4179. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4180. {
  4181. KeyProcessed(Key, Shift);
  4182. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4183. return;
  4184. }
  4185. }
  4186. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4187. {
  4188. KeyProcessed(Key, Shift);
  4189. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4190. }
  4191. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4192. if (IsCustomShortCut(CustomShortCut))
  4193. {
  4194. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4195. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4196. if (WinConfiguration->SharedBookmarks != NULL)
  4197. {
  4198. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4199. if ((Bookmark != NULL) &&
  4200. OpenBookmark(FCurrentSide, Bookmark))
  4201. {
  4202. KeyProcessed(Key, Shift);
  4203. }
  4204. }
  4205. }
  4206. }
  4207. TForm::KeyDown(Key, Shift);
  4208. }
  4209. //---------------------------------------------------------------------------
  4210. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4211. {
  4212. DebugAssert(Terminal != NULL);
  4213. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4214. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4215. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4216. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4217. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4218. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4219. // expanded from ?: to avoid memory leaks
  4220. if (SecurityEnabled)
  4221. {
  4222. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4223. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4224. }
  4225. else
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4228. }
  4229. if (FileSystemInfo.ProtocolName.IsEmpty())
  4230. {
  4231. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4232. }
  4233. else
  4234. {
  4235. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4236. }
  4237. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4238. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4239. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4240. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4241. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4242. UnicodeString CompressionStr = CSCompressionStr;
  4243. if (CSCompressionStr != SCCompressionStr)
  4244. {
  4245. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4246. }
  4247. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4248. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4249. UpdateStatusBar();
  4250. }
  4251. //---------------------------------------------------------------------------
  4252. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4253. {
  4254. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4255. DebugAssert(SessionStatusBar != NULL);
  4256. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4257. {
  4258. // note: (Terminal->Status < sshReady) currently never happens here,
  4259. // so STATUS_CONNECTING is never used
  4260. SessionStatusBar->SimplePanel = true;
  4261. SessionStatusBar->SimpleText = LoadStr(
  4262. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4263. }
  4264. else
  4265. {
  4266. DebugAssert(Terminal);
  4267. SessionStatusBar->SimplePanel = false;
  4268. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4269. if (!FNote.IsEmpty())
  4270. {
  4271. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4272. }
  4273. else
  4274. {
  4275. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4276. }
  4277. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4278. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4279. }
  4280. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4281. }
  4282. //---------------------------------------------------------------------------
  4283. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4284. {
  4285. Panel->Caption = L"";
  4286. }
  4287. //---------------------------------------------------------------------------
  4288. void __fastcall TCustomScpExplorerForm::Idle()
  4289. {
  4290. if (FShowing || FStandaloneEditing)
  4291. {
  4292. FEditorManager->Check();
  4293. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4294. // that needs to know if queue view is visible (and it may be closed after queue update)
  4295. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4296. }
  4297. if (FShowing)
  4298. {
  4299. if (!NonVisualDataModule->Busy &&
  4300. // Menu is opened or drag&drop is going on
  4301. (Mouse->Capture == NULL))
  4302. {
  4303. if (FRefreshRemoteDirectory)
  4304. {
  4305. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4306. {
  4307. Terminal->RefreshDirectory();
  4308. }
  4309. FRefreshRemoteDirectory = false;
  4310. }
  4311. if (FRefreshLocalDirectory)
  4312. {
  4313. ReloadLocalDirectory();
  4314. FRefreshLocalDirectory = false;
  4315. }
  4316. if (WinConfiguration->RefreshRemotePanel)
  4317. {
  4318. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4319. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4320. {
  4321. RemoteDirView->ReloadDirectory();
  4322. }
  4323. }
  4324. }
  4325. }
  4326. if (FShowing || FStandaloneEditing)
  4327. {
  4328. if (FQueueStatusInvalidated)
  4329. {
  4330. UpdateQueueStatus(false);
  4331. }
  4332. RefreshQueueItems();
  4333. }
  4334. if (FShowing)
  4335. {
  4336. UpdateStatusBar();
  4337. }
  4338. FIgnoreNextDialogChar = 0;
  4339. }
  4340. //---------------------------------------------------------------------------
  4341. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4342. {
  4343. try
  4344. {
  4345. FUserActionTimer->Enabled = false;
  4346. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4347. {
  4348. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4349. {
  4350. FPendingQueueActionItem->ProcessUserAction();
  4351. }
  4352. }
  4353. }
  4354. __finally
  4355. {
  4356. FPendingQueueActionItem = NULL;
  4357. }
  4358. }
  4359. //---------------------------------------------------------------------------
  4360. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4361. {
  4362. if (WinConfiguration->MinimizeToTray)
  4363. {
  4364. UpdateTrayIcon();
  4365. FTrayIcon->Visible = true;
  4366. if (Visible)
  4367. {
  4368. ShowWindow(Handle, SW_HIDE);
  4369. }
  4370. }
  4371. }
  4372. //---------------------------------------------------------------------------
  4373. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4374. {
  4375. // WORKAROUND
  4376. // When restoring maximized window from minimization,
  4377. // rarely some controls do not align properly.
  4378. // Two instances seen (both for Commander):
  4379. // - When restoring, window is temporarily narrower (not maximized),
  4380. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4381. // Once maximized already, top dock shinks back, but the session PageControl,
  4382. // do not align up, leaving space between TopDock and PageControl.
  4383. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4384. for (int Index = 0; Index < ControlCount; Index++)
  4385. {
  4386. RealignControl(Controls[Index]);
  4387. }
  4388. if (FTrayIcon->Visible)
  4389. {
  4390. FTrayIcon->Visible = false;
  4391. if (Visible)
  4392. {
  4393. ShowWindow(Handle, SW_SHOW);
  4394. }
  4395. }
  4396. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4397. {
  4398. FNeedSession = false;
  4399. NonVisualDataModule->StartBusy();
  4400. try
  4401. {
  4402. NeedSession(true);
  4403. }
  4404. __finally
  4405. {
  4406. NonVisualDataModule->EndBusy();
  4407. }
  4408. }
  4409. }
  4410. //---------------------------------------------------------------------------
  4411. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4412. {
  4413. FTrayIcon->Hint = GetMainForm()->Caption;
  4414. }
  4415. //---------------------------------------------------------------------------
  4416. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4417. {
  4418. UpdateTrayIcon();
  4419. }
  4420. //---------------------------------------------------------------------------
  4421. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4422. {
  4423. // workaround
  4424. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4425. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4426. // But WM_ACTIVATEAPP message can be received even when
  4427. // the main window is minimized to the tray and internal editor window is focused
  4428. // (after another application was previously active)
  4429. if (::IsIconic(Handle))
  4430. {
  4431. if (!IsAppIconic())
  4432. {
  4433. SetAppIconic(true);
  4434. }
  4435. }
  4436. ::ApplicationRestore();
  4437. Application->BringToFront();
  4438. }
  4439. //---------------------------------------------------------------------------
  4440. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4441. {
  4442. RestoreApp();
  4443. }
  4444. //---------------------------------------------------------------------------
  4445. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4446. {
  4447. if (OpenInNewWindow())
  4448. {
  4449. ExecuteNewInstance(SessionUrl);
  4450. }
  4451. else
  4452. {
  4453. TTerminalManager::Instance()->NewSession(SessionUrl);
  4454. }
  4455. }
  4456. //---------------------------------------------------------------------------
  4457. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4458. {
  4459. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4460. StoredSessions->NewSession(SessionName, SessionData);
  4461. // modified only, explicit
  4462. StoredSessions->Save(false, true);
  4463. // encode session name because of slashes in hierarchical sessions
  4464. return EncodeUrlString(SessionName);
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4468. {
  4469. // current working directories become defaults here, what is not right
  4470. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4471. return SaveHiddenDuplicateSession(SessionData.get());
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4475. {
  4476. if (OpenInNewWindow())
  4477. {
  4478. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4479. }
  4480. else
  4481. {
  4482. // current working directories become defaults here, what is not right
  4483. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4484. TTerminalManager * Manager = TTerminalManager::Instance();
  4485. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4486. // We definitelly want this
  4487. ATerminal->Disconnected = Terminal->Disconnected;
  4488. // Not sure about these two
  4489. ATerminal->Permanent = Terminal->Permanent;
  4490. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4491. Manager->ActiveTerminal = ATerminal;
  4492. }
  4493. }
  4494. //---------------------------------------------------------------------------
  4495. void __fastcall TCustomScpExplorerForm::RenameSession()
  4496. {
  4497. UnicodeString Name = Terminal->SessionData->SessionName;
  4498. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4499. {
  4500. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4501. TSessionData::ValidateName(Name);
  4502. // This is inconsistent with how color (for example) is handled.
  4503. Terminal->SessionData->Name = Name;
  4504. UpdateControls();
  4505. // Add/Remove distinguishing paths from sessions of the same name.
  4506. DoTerminalListChanged();
  4507. }
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4511. {
  4512. DebugAssert(Queue != NULL);
  4513. bool Result = Queue->IsEmpty;
  4514. if (!Result)
  4515. {
  4516. SetFocus();
  4517. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4518. }
  4519. return Result;
  4520. }
  4521. //---------------------------------------------------------------------------
  4522. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4523. {
  4524. return CanCloseQueue(FQueue);
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. void __fastcall TCustomScpExplorerForm::CloseSession()
  4528. {
  4529. if (CanCloseQueue())
  4530. {
  4531. TTerminalManager::Instance()->FreeActiveTerminal();
  4532. }
  4533. }
  4534. //---------------------------------------------------------------------------
  4535. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4536. {
  4537. if (CanCloseQueue())
  4538. {
  4539. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4540. }
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4544. {
  4545. DetachTerminal(Terminal);
  4546. RemoteDirView->Terminal = Terminal;
  4547. UpdateRemotePathComboBox(false);
  4548. UpdateControls();
  4549. }
  4550. //---------------------------------------------------------------------------
  4551. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4552. {
  4553. if (DebugAlwaysTrue(!Terminal->Active))
  4554. {
  4555. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4556. }
  4557. }
  4558. //---------------------------------------------------------------------------
  4559. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4560. {
  4561. if (OpenInNewWindow())
  4562. {
  4563. // encode session name because of slashes in hierarchical sessions
  4564. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4565. }
  4566. else
  4567. {
  4568. TTerminalManager * Manager = TTerminalManager::Instance();
  4569. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4570. Manager->ActiveTerminal = Terminal;
  4571. }
  4572. }
  4573. //---------------------------------------------------------------------------
  4574. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4575. {
  4576. TTerminalManager * Manager = TTerminalManager::Instance();
  4577. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4578. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4579. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4580. // FirstTerminal can be null, if some of the
  4581. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4582. {
  4583. FirstTerminal->Disconnected = true;
  4584. FirstTerminal->DisconnectedTemporarily = true;
  4585. }
  4586. Manager->ActiveTerminal = FirstTerminal;
  4587. }
  4588. //---------------------------------------------------------------------------
  4589. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4590. {
  4591. if (OpenInNewWindow())
  4592. {
  4593. ExecuteNewInstance(Name);
  4594. }
  4595. else
  4596. {
  4597. DoOpenFolderOrWorkspace(Name, true);
  4598. }
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4602. bool &CanClose)
  4603. {
  4604. // See the comment in CloseApp()
  4605. if (NonVisualDataModule->Busy)
  4606. {
  4607. CanClose = false;
  4608. }
  4609. else if (Terminal != NULL)
  4610. {
  4611. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4612. {
  4613. unsigned int Result;
  4614. TMessageParams Params(mpNeverAskAgainCheck);
  4615. UnicodeString Message;
  4616. int Answers = qaOK | qaCancel;
  4617. if (TTerminalManager::Instance()->Count > 1)
  4618. {
  4619. if (!WinConfiguration->AutoSaveWorkspace)
  4620. {
  4621. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4622. }
  4623. else
  4624. {
  4625. Message = LoadStr(CLOSE_SESSIONS);
  4626. }
  4627. }
  4628. else
  4629. {
  4630. if (!WinConfiguration->AutoSaveWorkspace)
  4631. {
  4632. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4633. }
  4634. else
  4635. {
  4636. Message = LoadStr(CLOSE_SESSION);
  4637. }
  4638. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4639. }
  4640. UnicodeString Note;
  4641. if (WinConfiguration->AutoSaveWorkspace)
  4642. {
  4643. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4644. }
  4645. else
  4646. {
  4647. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4648. Answers = qaYes | qaNo | qaCancel;
  4649. }
  4650. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4651. SetFocus();
  4652. Result = MessageDialog(Message, qtConfirmation,
  4653. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4654. if (Result == qaNeverAskAgain)
  4655. {
  4656. WinConfiguration->ConfirmClosingSession = false;
  4657. }
  4658. if (Result == qaNo)
  4659. {
  4660. CanClose = SaveWorkspace(true);
  4661. // note that the workspace will be saved redundatly again from FormClose
  4662. }
  4663. else
  4664. {
  4665. CanClose =
  4666. (Result == qaOK) ||
  4667. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4668. (Result == qaNeverAskAgain);
  4669. }
  4670. }
  4671. if (CanClose)
  4672. {
  4673. CanClose = CanCloseQueue();
  4674. }
  4675. }
  4676. if (CanClose)
  4677. {
  4678. CanClose =
  4679. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4680. FEditorManager->CloseExternalFilesWithoutProcess();
  4681. if (CanClose)
  4682. {
  4683. while (CanClose && (FLocalEditors->Count > 0))
  4684. {
  4685. int PrevCount = FLocalEditors->Count;
  4686. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4687. CanClose = (FLocalEditors->Count < PrevCount);
  4688. }
  4689. if (CanClose)
  4690. {
  4691. CanClose = FEditorManager->Empty(true);
  4692. if (!CanClose)
  4693. {
  4694. SetFocus();
  4695. CanClose =
  4696. (MessageDialog(
  4697. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4698. }
  4699. }
  4700. }
  4701. }
  4702. }
  4703. //---------------------------------------------------------------------------
  4704. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4705. {
  4706. TForm * Form = dynamic_cast<TForm *>(Sender);
  4707. DebugAssert(Form != NULL);
  4708. Form->Close();
  4709. }
  4710. //---------------------------------------------------------------------------
  4711. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4712. {
  4713. TForm * Form = dynamic_cast<TForm *>(Sender);
  4714. delete Form;
  4715. }
  4716. //---------------------------------------------------------------------------
  4717. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4718. {
  4719. while (FLocalEditors->Count > 0)
  4720. {
  4721. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4722. }
  4723. }
  4724. //---------------------------------------------------------------------------
  4725. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4726. TObject *Sender)
  4727. {
  4728. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4729. try
  4730. {
  4731. SetProperties(osRemote, FileList);
  4732. }
  4733. __finally
  4734. {
  4735. delete FileList;
  4736. }
  4737. }
  4738. //---------------------------------------------------------------------------
  4739. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4740. {
  4741. if (value)
  4742. {
  4743. if (Component == fcCustomCommandsBand)
  4744. {
  4745. UpdateCustomCommandsToolbar();
  4746. }
  4747. if (Component == fcQueueFileList)
  4748. {
  4749. DebugAssert(!QueueFileListSplitter->Visible);
  4750. AdjustQueueLayout();
  4751. UpdateQueueFileList();
  4752. }
  4753. }
  4754. }
  4755. //---------------------------------------------------------------------------
  4756. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4757. {
  4758. int MinHeightLimit =
  4759. GetStaticQueuePanelComponentsHeight() +
  4760. QueueFileListSplitter->Height +
  4761. QueueFileList->Height +
  4762. GetMinQueueViewHeight();
  4763. if (QueuePanel->ClientHeight < MinHeightLimit)
  4764. {
  4765. QueuePanel->ClientHeight = MinHeightLimit;
  4766. }
  4767. }
  4768. //---------------------------------------------------------------------------
  4769. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4770. {
  4771. TControl * Control = GetComponent(Component);
  4772. DebugAssert(Control);
  4773. bool Changed = (Control->Visible != value);
  4774. if (Changed)
  4775. {
  4776. ComponentShowing(Component, value);
  4777. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4778. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4779. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4780. if (value)
  4781. {
  4782. int RemainingHeight = Control->Parent->ClientHeight;
  4783. int RemainingWidth = Control->Parent->ClientWidth;
  4784. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4785. {
  4786. TControl * ChildControl = Control->Parent->Controls[i];
  4787. if (ChildControl->Visible)
  4788. {
  4789. switch (ChildControl->Align)
  4790. {
  4791. case alTop:
  4792. case alBottom:
  4793. RemainingHeight -= ChildControl->Height;
  4794. break;
  4795. case alLeft:
  4796. case alRight:
  4797. RemainingWidth -= ChildControl->Width;
  4798. break;
  4799. }
  4800. }
  4801. }
  4802. int Reserve = ScaleByTextHeight(this, 32);
  4803. // queue in explorer, trees in commander
  4804. if (Control->Height > RemainingHeight - Reserve)
  4805. {
  4806. Control->Height = RemainingHeight / 2;
  4807. }
  4808. if (Control->Width > RemainingWidth - Reserve)
  4809. {
  4810. Control->Width = RemainingWidth / 2;
  4811. }
  4812. }
  4813. Control->Visible = value;
  4814. if (WasFocused && Visible)
  4815. {
  4816. DirView(osCurrent)->SetFocus();
  4817. }
  4818. FixControlsPlacement();
  4819. }
  4820. }
  4821. //---------------------------------------------------------------------------
  4822. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4823. {
  4824. TControl * Control = GetComponent(Component);
  4825. if (Control == NULL)
  4826. {
  4827. return false;
  4828. }
  4829. else
  4830. {
  4831. return Control->Visible;
  4832. }
  4833. }
  4834. //---------------------------------------------------------------------------
  4835. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4836. {
  4837. bool Result;
  4838. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4839. {
  4840. Result = !IsUWP();
  4841. }
  4842. else
  4843. {
  4844. Result = true;
  4845. }
  4846. return Result;
  4847. }
  4848. //---------------------------------------------------------------------------
  4849. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4850. {
  4851. if (DirView(osOther)->ItemFocused != NULL)
  4852. {
  4853. DirView(osOther)->ItemFocused->MakeVisible(false);
  4854. }
  4855. QueueSplitter->Visible = QueuePanel->Visible;
  4856. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4857. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4858. TControl * QueueControlsOrder[] =
  4859. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4860. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4861. }
  4862. //---------------------------------------------------------------------------
  4863. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4864. {
  4865. switch (Component) {
  4866. case fcStatusBar: return RemoteStatusBar;
  4867. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4868. case fcQueueView: return QueuePanel;
  4869. case fcQueueToolbar: return QueueDock;
  4870. case fcRemoteTree: return RemoteDrivePanel;
  4871. case fcSessionsTabs: return SessionsPageControl;
  4872. case fcQueueFileList: return QueueFileList;
  4873. default: return NULL;
  4874. }
  4875. }
  4876. //---------------------------------------------------------------------------
  4877. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4878. TObject *Sender, TListColumn *Column, TPoint &Point)
  4879. {
  4880. DebugAssert(NonVisualDataModule && Column && Sender);
  4881. NonVisualDataModule->ListColumn = Column;
  4882. TPopupMenu * DirViewColumnMenu;
  4883. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4884. {
  4885. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4886. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4887. (Column->Index == uvName);
  4888. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4889. (Column->Index == uvSize);
  4890. }
  4891. else
  4892. {
  4893. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4894. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4895. (Column->Index == dvName);
  4896. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4897. (Column->Index == dvSize);
  4898. }
  4899. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4900. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4901. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4902. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4903. }
  4904. //---------------------------------------------------------------------------
  4905. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4906. TObject *Sender, TListItem *Item, bool &AllowExec)
  4907. {
  4908. DoDirViewExecFile(Sender, Item, AllowExec);
  4909. }
  4910. //---------------------------------------------------------------------------
  4911. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4912. TListItem * Item, bool & AllowExec)
  4913. {
  4914. DebugAssert(Sender && Item && Configuration);
  4915. DebugAssert(AllowExec);
  4916. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4917. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4918. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4919. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4920. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4921. // on files only (not directories)
  4922. // and only when symlinks are resolved (apply to remote panel only)
  4923. if (!ADirView->ItemIsDirectory(Item) &&
  4924. (ResolvedSymlinks || FForceExecution))
  4925. {
  4926. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4927. !FForceExecution && ResolvedSymlinks)
  4928. {
  4929. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4930. {
  4931. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4932. UnlockWindow();
  4933. try
  4934. {
  4935. ExecuteFileOperation(
  4936. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4937. }
  4938. __finally
  4939. {
  4940. LockWindow();
  4941. }
  4942. AllowExec = false;
  4943. }
  4944. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4945. {
  4946. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4947. {
  4948. ExecuteFile(Side, efDefaultEditor);
  4949. AllowExec = false;
  4950. }
  4951. }
  4952. else
  4953. {
  4954. DebugFail();
  4955. }
  4956. }
  4957. // if we have not done anything special, fall back to default behavior
  4958. if (AllowExec)
  4959. {
  4960. if (Remote && !WinConfiguration->DisableOpenEdit)
  4961. {
  4962. ExecuteFile(osRemote, efShell);
  4963. AllowExec = false;
  4964. }
  4965. }
  4966. }
  4967. }
  4968. //---------------------------------------------------------------------------
  4969. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4970. {
  4971. return ((Side == osRemote) || (Side == osCurrent));
  4972. }
  4973. //---------------------------------------------------------------------------
  4974. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4975. {
  4976. DebugFail();
  4977. }
  4978. //---------------------------------------------------------------------------
  4979. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4980. {
  4981. DebugFail();
  4982. }
  4983. //---------------------------------------------------------------------------
  4984. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4985. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4986. {
  4987. TSynchronizeParamType Params;
  4988. Params.LocalDirectory = LocalDirectory;
  4989. Params.RemoteDirectory = RemoteDirectory;
  4990. int UnusedParams =
  4991. (GUIConfiguration->SynchronizeParams &
  4992. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  4993. TTerminal::spCaseSensitive));
  4994. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4995. Params.Options = GUIConfiguration->SynchronizeOptions;
  4996. bool SaveSettings = false;
  4997. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4998. &DoSynchronizeTooManyDirectories);
  4999. DebugAssert(FSynchronizeController == NULL);
  5000. FSynchronizeController = &Controller;
  5001. bool Result;
  5002. try
  5003. {
  5004. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5005. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5006. int Options =
  5007. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5008. DebugAssert(FOnFeedSynchronizeError == NULL);
  5009. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5010. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5011. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5012. if (Result)
  5013. {
  5014. if (SaveSettings)
  5015. {
  5016. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5017. GUIConfiguration->SynchronizeOptions = Params.Options;
  5018. }
  5019. else
  5020. {
  5021. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5022. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5023. FLAGSET(Params.Options, soSynchronize))
  5024. {
  5025. GUIConfiguration->SynchronizeOptions =
  5026. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5027. soSynchronize;
  5028. }
  5029. }
  5030. LocalDirectory = Params.LocalDirectory;
  5031. RemoteDirectory = Params.RemoteDirectory;
  5032. }
  5033. }
  5034. __finally
  5035. {
  5036. FSynchronizeController = NULL;
  5037. DebugAssert(FOnFeedSynchronizeError == NULL);
  5038. FOnFeedSynchronizeError = NULL;
  5039. }
  5040. return Result;
  5041. }
  5042. //---------------------------------------------------------------------------
  5043. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5044. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5045. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5046. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5047. TSynchronizeOptions * Options, bool Full)
  5048. {
  5049. // Keep-up-to-date mode
  5050. if (Terminal->Status == ssOpened)
  5051. {
  5052. try
  5053. {
  5054. int PParams = Params.Params;
  5055. if (!Full)
  5056. {
  5057. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5058. if (FLAGSET(Params.Options, soRecurse))
  5059. {
  5060. PParams |= TTerminal::spSubDirs;
  5061. }
  5062. }
  5063. else
  5064. {
  5065. // if keepuptodate is non-recursive,
  5066. // full sync before has to be non-recursive as well
  5067. if (FLAGCLEAR(Params.Options, soRecurse))
  5068. {
  5069. PParams |= TTerminal::spNoRecurse;
  5070. }
  5071. }
  5072. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5073. PParams, Checklist, Options);
  5074. }
  5075. catch (Exception & E)
  5076. {
  5077. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5078. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5079. {
  5080. // noop, already logged in MoreMessageDialog
  5081. }
  5082. else
  5083. {
  5084. ShowExtendedExceptionEx(Terminal, &E);
  5085. throw;
  5086. }
  5087. }
  5088. }
  5089. }
  5090. //---------------------------------------------------------------------------
  5091. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5092. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5093. const UnicodeString ErrorStr)
  5094. {
  5095. if (!Directory.IsEmpty())
  5096. {
  5097. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5098. }
  5099. else
  5100. {
  5101. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5102. }
  5103. }
  5104. //---------------------------------------------------------------------------
  5105. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5106. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5107. {
  5108. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5109. {
  5110. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5111. }
  5112. else
  5113. {
  5114. TMessageParams Params(mpNeverAskAgainCheck);
  5115. unsigned int Result = MessageDialog(
  5116. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5117. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5118. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5119. {
  5120. MaxDirectories *= 2;
  5121. if (Result == qaNeverAskAgain)
  5122. {
  5123. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5124. }
  5125. }
  5126. else
  5127. {
  5128. Abort();
  5129. }
  5130. }
  5131. }
  5132. //---------------------------------------------------------------------------
  5133. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5134. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5135. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5136. TSynchronizeOptions * Options)
  5137. {
  5138. // Keep-up-to-date mode
  5139. DebugAssert(!FAutoOperation);
  5140. void * BatchStorage;
  5141. BatchStart(BatchStorage);
  5142. FAutoOperation = true;
  5143. bool AnyOperation = false;
  5144. TDateTime StartTime = Now();
  5145. TSynchronizeChecklist * AChecklist = NULL;
  5146. try
  5147. {
  5148. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5149. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5150. {
  5151. FSynchronizeProgressForm->Start();
  5152. }
  5153. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5154. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5155. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5156. Options);
  5157. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5158. SAFE_DESTROY(FSynchronizeProgressForm);
  5159. AnyOperation = (AChecklist->CheckedCount > 0);
  5160. if (AnyOperation)
  5161. {
  5162. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5163. CreateProgressForm(&SynchronizeProgress);
  5164. try
  5165. {
  5166. Terminal->SynchronizeApply(
  5167. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5168. SynchronizeProcessedItem, NULL, NULL, NULL);
  5169. }
  5170. __finally
  5171. {
  5172. DestroyProgressForm();
  5173. }
  5174. }
  5175. }
  5176. __finally
  5177. {
  5178. if (Checklist == NULL)
  5179. {
  5180. delete AChecklist;
  5181. }
  5182. else
  5183. {
  5184. *Checklist = AChecklist;
  5185. }
  5186. FAutoOperation = false;
  5187. SAFE_DESTROY(FSynchronizeProgressForm);
  5188. BatchEnd(BatchStorage);
  5189. ReloadLocalDirectory();
  5190. if (AnyOperation)
  5191. {
  5192. OperationComplete(StartTime);
  5193. }
  5194. }
  5195. }
  5196. //---------------------------------------------------------------------------
  5197. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5198. {
  5199. // can be called from command line
  5200. return Visible &&
  5201. ((DirView(osRemote)->SelCount > 0) ||
  5202. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5203. }
  5204. //---------------------------------------------------------------------------
  5205. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5206. {
  5207. LogSynchronizeEvent(Terminal, Message);
  5208. }
  5209. //---------------------------------------------------------------------------
  5210. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5211. int Params, TSynchronizeOptions & Options)
  5212. {
  5213. DebugAssert(!IsLocalBrowserMode());
  5214. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5215. {
  5216. Options.Filter = new TStringList();
  5217. Options.Filter->CaseSensitive = false;
  5218. Options.Filter->Duplicates = Types::dupAccept;
  5219. if (DirView(osRemote)->SelCount > 0)
  5220. {
  5221. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5222. }
  5223. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5224. {
  5225. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5226. }
  5227. Options.Filter->Sort();
  5228. }
  5229. }
  5230. //---------------------------------------------------------------------------
  5231. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5232. {
  5233. TCopyParamType Defaults;
  5234. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5235. ConfigStorage->AccessMode = smRead;
  5236. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5237. {
  5238. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5239. }
  5240. ConfigStorage.reset(NULL);
  5241. std::unique_ptr<TStringList> Options(new TStringList());
  5242. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5243. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5244. UnicodeString Result;
  5245. if (Options->Count > 0)
  5246. {
  5247. Result =
  5248. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5249. }
  5250. return Result;
  5251. }
  5252. //---------------------------------------------------------------------------
  5253. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5254. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5255. {
  5256. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5257. UnicodeString AdditionalParams =
  5258. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5259. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5260. SerializeCopyParamForCommandLine(CopyParams),
  5261. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5262. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5263. ExecuteNewInstance(SessionName, AdditionalParams);
  5264. }
  5265. //---------------------------------------------------------------------------
  5266. struct TSynchronizeParams
  5267. {
  5268. UnicodeString LocalDirectory;
  5269. UnicodeString RemoteDirectory;
  5270. TSynchronizeMode Mode;
  5271. TSynchronizeChecklist * Checklist;
  5272. int Params;
  5273. TCopyParamType * CopyParam;
  5274. TDateTime CollectElapsed;
  5275. TDateTime * StartTime;
  5276. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5277. };
  5278. //---------------------------------------------------------------------------
  5279. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5280. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5281. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5282. {
  5283. DebugAssert(!FAutoOperation);
  5284. void * BatchStorage;
  5285. BatchStart(BatchStorage);
  5286. FAutoOperation = true;
  5287. TFileOperationStatistics Statistics;
  5288. TDateTime Start = Now();
  5289. try
  5290. {
  5291. Params.OnProcessedItem = OnProcessedItem;
  5292. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5293. CreateProgressForm(&SynchronizeProgress);
  5294. Terminal->SynchronizeApply(
  5295. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5296. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5297. &Statistics);
  5298. }
  5299. __finally
  5300. {
  5301. Params.OnProcessedItem = NULL;
  5302. FAutoOperation = false;
  5303. DestroyProgressForm();
  5304. BatchEnd(BatchStorage);
  5305. ReloadLocalDirectory();
  5306. }
  5307. if (WinConfiguration->SynchronizeSummary)
  5308. {
  5309. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5310. // The statistics should be 0 anyway in this case
  5311. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5312. {
  5313. Message += L"\n";
  5314. if (Statistics.FilesUploaded > 0)
  5315. {
  5316. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5317. }
  5318. if (Statistics.FilesDownloaded > 0)
  5319. {
  5320. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5321. }
  5322. if (Statistics.FilesDeletedLocal > 0)
  5323. {
  5324. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5325. }
  5326. if (Statistics.FilesDeletedRemote > 0)
  5327. {
  5328. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5329. }
  5330. }
  5331. TDateTime Elapsed = (Now() - Start);
  5332. Message +=
  5333. L"\n" +
  5334. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5335. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5336. TMessageParams Params(mpNeverAskAgainCheck);
  5337. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5338. if (Result == qaNeverAskAgain)
  5339. {
  5340. WinConfiguration->SynchronizeSummary = false;
  5341. }
  5342. }
  5343. }
  5344. //---------------------------------------------------------------------------
  5345. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5346. {
  5347. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5348. {
  5349. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5350. }
  5351. // Not set in keep-up-to-date mode - Synchronize() method
  5352. if (Token != NULL)
  5353. {
  5354. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5355. if (Params.OnProcessedItem != NULL)
  5356. {
  5357. Params.OnProcessedItem(NULL, ChecklistItem);
  5358. }
  5359. }
  5360. }
  5361. //---------------------------------------------------------------------------
  5362. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5363. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5364. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5365. {
  5366. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5367. *Params.StartTime = Now();
  5368. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5369. }
  5370. //---------------------------------------------------------------------------
  5371. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5372. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5373. {
  5374. // terminal can be already closed (e.g. dropped connection)
  5375. if (Terminal != NULL)
  5376. {
  5377. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5378. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5379. }
  5380. }
  5381. //---------------------------------------------------------------------------
  5382. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5383. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5384. {
  5385. DebugAssert(!IsLocalBrowserMode());
  5386. TAutoBatch AutoBatch(this);
  5387. TAutoFlag AutoOperationFlag(FAutoOperation);
  5388. if (Side == osRemote)
  5389. {
  5390. std::unique_ptr<TStrings> FileList(new TStringList());
  5391. FileList->AddObject(FileName, RemoteFile);
  5392. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5393. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5394. RemoteDirView->SaveSelection();
  5395. RemoteDirView->SaveSelectedNames();
  5396. try
  5397. {
  5398. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5399. }
  5400. catch(...)
  5401. {
  5402. RemoteDirView->DiscardSavedSelection();
  5403. throw;
  5404. }
  5405. RemoteDirView->RestoreSelection();
  5406. }
  5407. else if (DebugAlwaysTrue(Side == osLocal))
  5408. {
  5409. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5410. {
  5411. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5412. }
  5413. UnicodeString Directory = ExtractFileDir(FileName);
  5414. ReloadLocalDirectory(Directory);
  5415. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5416. if (!SamePaths(Directory, NewDirectory))
  5417. {
  5418. ReloadLocalDirectory(NewDirectory);
  5419. }
  5420. }
  5421. }
  5422. //---------------------------------------------------------------------------
  5423. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5424. {
  5425. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5426. if (Side == osLocal)
  5427. {
  5428. if (Action == TSynchronizeChecklist::saDownloadNew)
  5429. {
  5430. OpenFolderInExplorer(LocalPath);
  5431. }
  5432. else
  5433. {
  5434. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5435. }
  5436. }
  5437. else if (DebugAlwaysTrue(Side == osRemote))
  5438. {
  5439. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5440. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5441. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5442. if (!LocalPath.IsEmpty())
  5443. {
  5444. SessionData->LocalDirectory = LocalPath;
  5445. }
  5446. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5447. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5448. }
  5449. }
  5450. //---------------------------------------------------------------------------
  5451. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5452. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5453. const TCopyParamType * CopyParams)
  5454. {
  5455. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5456. UnicodeString AdditionalParams =
  5457. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5458. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5459. SerializeCopyParamForCommandLine(CopyParams),
  5460. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5461. LocalDirectory, RemoteDirectory, Mode, Params));
  5462. ExecuteNewInstance(SessionName, AdditionalParams);
  5463. }
  5464. //---------------------------------------------------------------------------
  5465. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5466. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5467. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5468. {
  5469. int Result;
  5470. bool SaveSettings = false;
  5471. int Options =
  5472. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5473. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5474. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5475. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5476. bool Continue =
  5477. (UseDefaults == 0) ||
  5478. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5479. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5480. if (Continue)
  5481. {
  5482. Configuration->Usage->Inc(L"Synchronizations");
  5483. UpdateCopyParamCounters(CopyParam);
  5484. TSynchronizeOptions SynchronizeOptions;
  5485. GetSynchronizeOptions(Params, SynchronizeOptions);
  5486. if (SaveSettings)
  5487. {
  5488. GUIConfiguration->SynchronizeParams = Params;
  5489. }
  5490. else
  5491. {
  5492. SaveMode = false;
  5493. }
  5494. TDateTime StartTime = Now();
  5495. TSynchronizeChecklist * Checklist = NULL;
  5496. try
  5497. {
  5498. DebugAssert(!FAutoOperation);
  5499. FAutoOperation = true;
  5500. try
  5501. {
  5502. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5503. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5504. int Files = -1;
  5505. if (DataList->Count >= 1)
  5506. {
  5507. Files = StrToIntDef(DataList->Strings[0], Files);
  5508. }
  5509. else
  5510. {
  5511. DataList->Add(UnicodeString());
  5512. }
  5513. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5514. FSynchronizeProgressForm->Start();
  5515. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5516. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5517. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5518. &SynchronizeOptions);
  5519. if (Terminal->SessionData->CacheDirectories)
  5520. {
  5521. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5522. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5523. }
  5524. }
  5525. __finally
  5526. {
  5527. FAutoOperation = false;
  5528. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5529. SAFE_DESTROY(FSynchronizeProgressForm);
  5530. }
  5531. TSynchronizeParams SynchronizeParams;
  5532. SynchronizeParams.LocalDirectory = LocalDirectory;
  5533. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5534. SynchronizeParams.Mode = Mode;
  5535. SynchronizeParams.CopyParam = &CopyParam;
  5536. SynchronizeParams.Params = Params;
  5537. SynchronizeParams.Checklist = Checklist;
  5538. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5539. SynchronizeParams.StartTime = &StartTime;
  5540. SynchronizeParams.OnProcessedItem = NULL;
  5541. Result = Checklist->Count;
  5542. if (Checklist->Count > 0)
  5543. {
  5544. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5545. {
  5546. if (!DoSynchronizeChecklistDialog(
  5547. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5548. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5549. {
  5550. Result = -1;
  5551. }
  5552. }
  5553. else
  5554. {
  5555. FullSynchronize(SynchronizeParams, NULL, NULL);
  5556. }
  5557. }
  5558. else
  5559. {
  5560. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5561. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5562. }
  5563. }
  5564. __finally
  5565. {
  5566. delete Checklist;
  5567. }
  5568. OperationComplete(StartTime);
  5569. }
  5570. else
  5571. {
  5572. Result = -1;
  5573. }
  5574. return Result;
  5575. }
  5576. //---------------------------------------------------------------------------
  5577. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5578. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5579. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5580. {
  5581. if (Collect)
  5582. {
  5583. DebugAssert(FSynchronizeProgressForm != NULL);
  5584. if (!FSynchronizeProgressForm->Started)
  5585. {
  5586. FSynchronizeProgressForm->Start();
  5587. }
  5588. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5589. SetTaskbarListProgressValue(CompareProgress);
  5590. }
  5591. else
  5592. {
  5593. DebugAssert(FSynchronizeProgressForm == NULL);
  5594. DebugAssert(FProgressForm != NULL);
  5595. }
  5596. }
  5597. //---------------------------------------------------------------------------
  5598. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5599. {
  5600. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5601. TRemoteFile * File = NULL;
  5602. Terminal->ReadFile(FullFileName, File);
  5603. if (File != NULL)
  5604. {
  5605. std::unique_ptr<TRemoteFile> FileOwner(File);
  5606. TAutoFlag Flag(FStandaloneEditing);
  5607. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5608. Application->ShowMainForm = false;
  5609. Application->Run();
  5610. }
  5611. }
  5612. //---------------------------------------------------------------------------
  5613. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5614. {
  5615. DebugFail();
  5616. }
  5617. //---------------------------------------------------------------------------
  5618. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5619. {
  5620. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5621. SessionData->Assign(Terminal->SessionData);
  5622. UpdateSessionData(SessionData.get());
  5623. Terminal->UpdateSessionCredentials(SessionData.get());
  5624. if (!Terminal->SessionData->HasSessionName())
  5625. {
  5626. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5627. // once IsWorkspace is cleared
  5628. SessionData->Name = UnicodeString();
  5629. SessionData->IsWorkspace = false;
  5630. }
  5631. return SessionData.release();
  5632. }
  5633. //---------------------------------------------------------------------------
  5634. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5635. {
  5636. TSessionData * SessionData = CloneCurrentSessionData();
  5637. try
  5638. {
  5639. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5640. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5641. }
  5642. __finally
  5643. {
  5644. delete SessionData;
  5645. }
  5646. }
  5647. //---------------------------------------------------------------------------
  5648. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5649. {
  5650. TTerminalManager * Manager = TTerminalManager::Instance();
  5651. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5652. if (DebugAlwaysTrue(Terminal != NULL))
  5653. {
  5654. // Update (Managed)Terminal->StateData
  5655. UpdateTerminal(Terminal);
  5656. }
  5657. Manager->SaveWorkspace(DataList.get());
  5658. return DataList.release();
  5659. }
  5660. //---------------------------------------------------------------------------
  5661. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5662. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5663. {
  5664. WinConfiguration->LastWorkspace = Name;
  5665. if (!SavePasswords)
  5666. {
  5667. for (int Index = 0; Index < DataList->Count; Index++)
  5668. {
  5669. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5670. if (SessionData->Link.IsEmpty())
  5671. {
  5672. SessionData->ClearSessionPasswords();
  5673. }
  5674. }
  5675. }
  5676. StoredSessions->NewWorkspace(Name, DataList);
  5677. // modified only
  5678. StoredSessions->Save(false, Explicit);
  5679. }
  5680. //---------------------------------------------------------------------------
  5681. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5682. {
  5683. return
  5684. DefaultStr(WinConfiguration->LastWorkspace,
  5685. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5686. }
  5687. //---------------------------------------------------------------------------
  5688. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5689. {
  5690. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5691. bool AnyNonStoredSessionWithPassword = false;
  5692. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5693. bool AllNonStoredSessionsAnonymous = true;
  5694. TTerminalManager * Manager = TTerminalManager::Instance();
  5695. for (int Index = 0; Index < DataList->Count; Index++)
  5696. {
  5697. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5698. if (SessionData->Link.IsEmpty())
  5699. {
  5700. if (SessionData->HasAnySessionPassword())
  5701. {
  5702. AnyNonStoredSessionWithPassword = true;
  5703. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5704. {
  5705. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5706. }
  5707. }
  5708. if (!SameText(SessionData->UserName, AnonymousUserName))
  5709. {
  5710. AllNonStoredSessionsAnonymous = false;
  5711. }
  5712. }
  5713. }
  5714. bool SavePasswords;
  5715. bool * PSavePasswords;
  5716. bool NotRecommendedSavingPasswords =
  5717. !CustomWinConfiguration->UseMasterPassword &&
  5718. !AllNonStoredSessionsAnonymous;
  5719. if (Configuration->DisablePasswordStoring ||
  5720. !AnyNonStoredSessionWithPassword)
  5721. {
  5722. PSavePasswords = NULL;
  5723. SavePasswords = false;
  5724. }
  5725. else
  5726. {
  5727. PSavePasswords = &SavePasswords;
  5728. SavePasswords =
  5729. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5730. !NotRecommendedSavingPasswords;
  5731. }
  5732. UnicodeString Name = WorkspaceName();
  5733. bool CreateShortcut = false;
  5734. bool Result =
  5735. DoSaveWorkspaceDialog(
  5736. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5737. EnableAutoSave);
  5738. if (Result)
  5739. {
  5740. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5741. if (CreateShortcut)
  5742. {
  5743. TOperationVisualizer Visualizer;
  5744. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5745. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5746. }
  5747. if (EnableAutoSave)
  5748. {
  5749. WinConfiguration->AutoSaveWorkspace = true;
  5750. WinConfiguration->AutoWorkspace = Name;
  5751. if (PSavePasswords != NULL)
  5752. {
  5753. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5754. }
  5755. }
  5756. }
  5757. return Result;
  5758. }
  5759. //---------------------------------------------------------------------------
  5760. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5761. {
  5762. DebugAssert(!IsLocalBrowserMode());
  5763. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5764. if (WinConfiguration->PreservePanelState)
  5765. {
  5766. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5767. }
  5768. UpdateSessionData(Terminal->StateData);
  5769. }
  5770. //---------------------------------------------------------------------------
  5771. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5772. {
  5773. // Keep in sync with TSessionData::CopyStateData
  5774. DebugAssert(!IsLocalBrowserMode());
  5775. DebugAssert(Data != NULL);
  5776. // This is inconsistent with how color (for example) is handled.
  5777. Data->Name = Terminal->SessionData->Name;
  5778. // cannot use RemoteDirView->Path, because it is empty if connection
  5779. // was already closed
  5780. // also only peek, we may not be connected at all atm
  5781. // so make sure we do not try retrieving current directory from the server
  5782. // (particularly with FTP)
  5783. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5784. if (!ACurrentDirectory.IsEmpty())
  5785. {
  5786. Data->RemoteDirectory = ACurrentDirectory;
  5787. }
  5788. Data->Color = SessionColor;
  5789. }
  5790. //---------------------------------------------------------------------------
  5791. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5792. {
  5793. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5794. DebugAssert(Toolbar != NULL);
  5795. for (int i = 0; i < Toolbar->Items->Count; i++)
  5796. {
  5797. TTBXCustomDropDownItem * DropDownItem;
  5798. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5799. if (DropDownItem != NULL)
  5800. {
  5801. ToolbarItemResize(DropDownItem,
  5802. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5803. Toolbar->NonClientWidth);
  5804. break;
  5805. }
  5806. }
  5807. }
  5808. //---------------------------------------------------------------------------
  5809. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5810. {
  5811. Item->EditWidth = Width;
  5812. }
  5813. //---------------------------------------------------------------------------
  5814. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5815. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5816. {
  5817. for (int i = 0; i < Toolbar->Items->Count; i++)
  5818. {
  5819. TTBXCustomDropDownItem * DropDownItem;
  5820. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5821. if (DropDownItem != NULL)
  5822. {
  5823. ASize.x -= DropDownItem->EditWidth;
  5824. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5825. }
  5826. }
  5827. }
  5828. //---------------------------------------------------------------------------
  5829. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5830. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5831. {
  5832. if (WinConfiguration->DDWarnLackOfTempSpace)
  5833. {
  5834. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5835. if (!ADrive.IsEmpty())
  5836. {
  5837. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5838. DebugAssert(RequiredSpace >= 0);
  5839. __int64 RequiredWithReserve;
  5840. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5841. if (FreeSpace < RequiredWithReserve)
  5842. {
  5843. unsigned int Result;
  5844. TMessageParams Params(mpNeverAskAgainCheck);
  5845. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5846. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5847. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5848. if (Result == qaNeverAskAgain)
  5849. {
  5850. WinConfiguration->DDWarnLackOfTempSpace = false;
  5851. }
  5852. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5853. }
  5854. }
  5855. }
  5856. }
  5857. //---------------------------------------------------------------------------
  5858. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5859. {
  5860. DoOpenDirectoryDialog(odAddBookmark, Side);
  5861. }
  5862. //---------------------------------------------------------------------------
  5863. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5864. {
  5865. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5866. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5867. try
  5868. {
  5869. TCustomDirView * DView = DirView(Side);
  5870. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5871. {
  5872. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5873. }
  5874. }
  5875. catch (...)
  5876. {
  5877. delete VisitedDirectories;
  5878. throw;
  5879. }
  5880. return VisitedDirectories;
  5881. }
  5882. //---------------------------------------------------------------------------
  5883. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5884. TOpenDirectoryMode Mode, TOperationSide Side)
  5885. {
  5886. bool Continue = true;
  5887. if (Mode == odAddBookmark)
  5888. {
  5889. TMessageParams Params(mpNeverAskAgainCheck);
  5890. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5891. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5892. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5893. unsigned int Answer =
  5894. MessageDialog(Message,
  5895. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5896. if (Answer == qaNeverAskAgain)
  5897. {
  5898. Continue = true;
  5899. WinConfiguration->UseSharedBookmarks = true;
  5900. }
  5901. else if (Answer == qaOK)
  5902. {
  5903. Continue = true;
  5904. WinConfiguration->UseSharedBookmarks = false;
  5905. }
  5906. else
  5907. {
  5908. Continue = false;
  5909. }
  5910. }
  5911. if (Continue)
  5912. {
  5913. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5914. try
  5915. {
  5916. UnicodeString Name = DirView(Side)->PathName;
  5917. bool Repeat;
  5918. do
  5919. {
  5920. Repeat = false;
  5921. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5922. // do not allow switching to location profiles,
  5923. // if we are not connected
  5924. HasDirView[osLocal] && (Terminal != NULL)))
  5925. {
  5926. TWindowLock Lock(this);
  5927. if (!TryOpenDirectory(Side, Name))
  5928. {
  5929. Repeat = true;
  5930. Mode = odBrowse;
  5931. }
  5932. }
  5933. }
  5934. while (Repeat);
  5935. }
  5936. __finally
  5937. {
  5938. delete VisitedDirectories;
  5939. }
  5940. }
  5941. }
  5942. //---------------------------------------------------------------------------
  5943. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5944. {
  5945. DebugAssert(!FTerminal->CommandSessionOpened);
  5946. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5947. }
  5948. //---------------------------------------------------------------------------
  5949. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5950. {
  5951. bool Result = FTerminal->IsCapable[Capability] ||
  5952. FTerminal->CommandSessionOpened;
  5953. if (!Result)
  5954. {
  5955. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5956. if (!GUIConfiguration->ConfirmCommandSession)
  5957. {
  5958. Result = true;
  5959. }
  5960. else
  5961. {
  5962. TMessageParams Params(mpNeverAskAgainCheck);
  5963. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5964. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5965. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5966. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5967. if (Answer == qaNeverAskAgain)
  5968. {
  5969. GUIConfiguration->ConfirmCommandSession = false;
  5970. Result = true;
  5971. }
  5972. else if (Answer == qaOK)
  5973. {
  5974. Result = true;
  5975. }
  5976. }
  5977. if (Result)
  5978. {
  5979. Result = CommandSessionFallback();
  5980. }
  5981. }
  5982. return Result;
  5983. }
  5984. //---------------------------------------------------------------------------
  5985. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5986. {
  5987. if (EnsureCommandSessionFallback(fcAnyCommand))
  5988. {
  5989. DoConsoleDialog(Terminal, Command);
  5990. }
  5991. }
  5992. //---------------------------------------------------------------------------
  5993. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5994. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5995. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5996. {
  5997. if (!IsSideLocalBrowser(osRemote) &&
  5998. IsFileControl(DropSourceControl, osRemote) &&
  5999. (FDDExtMapFile != NULL))
  6000. {
  6001. Accept = true;
  6002. }
  6003. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6004. DebugAssert(FDDTargetControl != NULL);
  6005. }
  6006. //---------------------------------------------------------------------------
  6007. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6008. _di_IDataObject DataObj, int KeyState,
  6009. const TPoint & Point, int & Effect, bool & Accept)
  6010. {
  6011. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6012. }
  6013. //---------------------------------------------------------------------------
  6014. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6015. _di_IDataObject DataObj, int KeyState,
  6016. const TPoint & Point, int & Effect, bool & Accept)
  6017. {
  6018. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6019. }
  6020. //---------------------------------------------------------------------------
  6021. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6022. TObject * Sender)
  6023. {
  6024. DebugUsedParam(Sender);
  6025. DebugAssert(FDDTargetControl == Sender);
  6026. FDDTargetControl = NULL;
  6027. }
  6028. //---------------------------------------------------------------------------
  6029. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6030. {
  6031. FileControlDDDragLeave(SessionsPageControl);
  6032. }
  6033. //---------------------------------------------------------------------------
  6034. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6035. {
  6036. FileControlDDDragLeave(QueueView3);
  6037. }
  6038. //---------------------------------------------------------------------------
  6039. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6040. {
  6041. DebugAssert(!IsSideLocalBrowser(Side));
  6042. DebugUsedParam(Side);
  6043. bool Edit = false;
  6044. TRemoteFile * File = NULL;
  6045. UnicodeString FileName;
  6046. UnicodeString PointTo;
  6047. bool SymbolicLink = true;
  6048. if (RemoteDirView->ItemFocused)
  6049. {
  6050. DebugAssert(RemoteDirView->ItemFocused->Data);
  6051. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6052. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6053. if (Edit)
  6054. {
  6055. FileName = File->FileName;
  6056. PointTo = File->LinkTo;
  6057. }
  6058. else
  6059. {
  6060. PointTo = File->FileName;
  6061. }
  6062. }
  6063. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6064. Terminal->IsCapable[fcHardLink]))
  6065. {
  6066. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6067. if (Edit)
  6068. {
  6069. DebugAssert(File->FileName == FileName);
  6070. int Params = dfNoRecursive;
  6071. Terminal->ExceptionOnFail = true;
  6072. try
  6073. {
  6074. Terminal->DeleteFile(L"", File, &Params);
  6075. }
  6076. __finally
  6077. {
  6078. Terminal->ExceptionOnFail = false;
  6079. }
  6080. }
  6081. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6082. }
  6083. }
  6084. //---------------------------------------------------------------------------
  6085. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6086. {
  6087. return
  6088. (IsSideLocalBrowser(Side) ||
  6089. (HasActiveTerminal() &&
  6090. Terminal->ResolvingSymlinks &&
  6091. Terminal->IsCapable[fcSymbolicLink]));
  6092. }
  6093. //---------------------------------------------------------------------------
  6094. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6095. {
  6096. return
  6097. !IsSideLocalBrowser(FCurrentSide) &&
  6098. (RemoteDirView->ItemFocused != NULL) &&
  6099. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6100. Terminal->SessionData->ResolveSymlinks;
  6101. }
  6102. //---------------------------------------------------------------------------
  6103. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6104. {
  6105. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6106. FForceExecution = true;
  6107. try
  6108. {
  6109. DirView(osCurrent)->ExecuteCurrentFile();
  6110. }
  6111. __finally
  6112. {
  6113. FForceExecution = false;
  6114. }
  6115. }
  6116. //---------------------------------------------------------------------------
  6117. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6118. {
  6119. TEditorData ExternalEditor;
  6120. ExternalEditor.Editor = edExternal;
  6121. bool Remember = false;
  6122. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6123. {
  6124. if (Remember)
  6125. {
  6126. TEditorList * EditorList = new TEditorList;
  6127. try
  6128. {
  6129. *EditorList = *WinConfiguration->EditorList;
  6130. bool Found = false;
  6131. int i = 0;
  6132. while (!Found && (i < EditorList->Count))
  6133. {
  6134. const TEditorPreferences * Editor = EditorList->Editors[i];
  6135. if ((Editor->Data->Editor == edExternal) &&
  6136. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6137. {
  6138. Found = true;
  6139. }
  6140. i++;
  6141. }
  6142. if (!Found)
  6143. {
  6144. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6145. WinConfiguration->EditorList = EditorList;
  6146. }
  6147. }
  6148. __finally
  6149. {
  6150. delete EditorList;
  6151. }
  6152. }
  6153. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6154. }
  6155. }
  6156. //---------------------------------------------------------------------------
  6157. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6158. {
  6159. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6160. if (FFileFindTerminal == ATerminal)
  6161. {
  6162. FFileFindTerminal = NULL;
  6163. HideFileFindDialog();
  6164. }
  6165. if (FClipboardTerminal == ATerminal)
  6166. {
  6167. ClipboardClear(); // implies ClipboardStop
  6168. }
  6169. }
  6170. //---------------------------------------------------------------------------
  6171. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6172. {
  6173. DetachTerminal(Sender);
  6174. }
  6175. //---------------------------------------------------------------------------
  6176. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6177. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6178. {
  6179. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6180. DebugAssert(Terminal != NULL);
  6181. if (Data->Terminal == Terminal)
  6182. {
  6183. Data->Terminal = NULL;
  6184. }
  6185. }
  6186. //---------------------------------------------------------------------------
  6187. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6188. {
  6189. UpdateControls();
  6190. SessionColor = TColor(0);
  6191. UpdateRemotePathComboBox(false);
  6192. NeedSession(false);
  6193. }
  6194. //---------------------------------------------------------------------------
  6195. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6196. {
  6197. try
  6198. {
  6199. // Cache, as the login dialog can change its value
  6200. // See also DoShow. Also see TTerminalManager::NewSession.
  6201. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6202. try
  6203. {
  6204. if (ShowLogin)
  6205. {
  6206. bool ReloadSessions = !Startup;
  6207. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6208. }
  6209. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6210. // This detects if workspace was saved the last time the main widow was closed
  6211. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6212. {
  6213. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6214. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6215. }
  6216. }
  6217. __finally
  6218. {
  6219. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6220. // (so there was no chance for the user to open any session yet)
  6221. if ((ShowLogin || !Startup) &&
  6222. !WinConfiguration->KeepOpenWhenNoSession &&
  6223. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6224. {
  6225. TerminateApplication();
  6226. }
  6227. }
  6228. }
  6229. catch (EAbort &)
  6230. {
  6231. // swallow
  6232. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6233. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6234. }
  6235. }
  6236. //---------------------------------------------------------------------------
  6237. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6238. {
  6239. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6240. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6241. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6242. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6243. try
  6244. {
  6245. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6246. // Clear the design time unthemed tab
  6247. ((SessionsPageControl->PageCount > 0) &&
  6248. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6249. {
  6250. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6251. }
  6252. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6253. {
  6254. TThemeTabSheet * TabSheet;
  6255. if (Index >= SessionsPageControl->PageCount)
  6256. {
  6257. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6258. TabSheet->PageControl = SessionsPageControl;
  6259. }
  6260. else
  6261. {
  6262. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6263. }
  6264. bool IsSessionTab = (Index < TerminalList->Count);
  6265. if (IsSessionTab)
  6266. {
  6267. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6268. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6269. UpdateSessionTab(TabSheet);
  6270. }
  6271. else
  6272. {
  6273. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6274. TabSheet->Tag = 0; // not really needed
  6275. TabSheet->Shadowed = false;
  6276. // We know that we are at the last page, otherwise we could not call this (it assumes that new session tab is the last one)
  6277. UpdateNewSessionTab();
  6278. }
  6279. TabSheet->ShowCloseButton = IsSessionTab;
  6280. }
  6281. }
  6282. __finally
  6283. {
  6284. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6285. }
  6286. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6287. }
  6288. //---------------------------------------------------------------------------
  6289. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6290. {
  6291. DoTerminalListChanged();
  6292. }
  6293. //---------------------------------------------------------------------------
  6294. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6295. {
  6296. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6297. DebugAssert(TabSheet->ImageIndex == 0);
  6298. TabSheet->Caption =
  6299. WinConfiguration->SelectiveToolbarText ?
  6300. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6301. UnicodeString();
  6302. }
  6303. //---------------------------------------------------------------------------
  6304. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6305. {
  6306. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6307. }
  6308. //---------------------------------------------------------------------------
  6309. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6310. {
  6311. if (DebugAlwaysTrue(TabSheet != NULL))
  6312. {
  6313. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6314. if (DebugAlwaysTrue(ATerminal != NULL))
  6315. {
  6316. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6317. TabSheet->ImageIndex = AddSessionColor(Color);
  6318. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6319. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6320. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6321. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6322. {
  6323. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6324. }
  6325. }
  6326. }
  6327. }
  6328. //---------------------------------------------------------------------------
  6329. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6330. {
  6331. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6332. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6333. bool Result = (Terminal != NULL);
  6334. if (Result)
  6335. {
  6336. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6337. }
  6338. else
  6339. {
  6340. try
  6341. {
  6342. NewSession();
  6343. }
  6344. __finally
  6345. {
  6346. DoTerminalListChanged();
  6347. }
  6348. FSessionsPageControlNewSessionTime = Now();
  6349. }
  6350. return Result;
  6351. }
  6352. //---------------------------------------------------------------------------
  6353. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6354. {
  6355. SessionTabSwitched();
  6356. }
  6357. //---------------------------------------------------------------------------
  6358. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6359. {
  6360. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6361. DebugAssert(TransferList != NULL);
  6362. UnicodeString Name;
  6363. if (TransferList->ItemIndex <= 0)
  6364. {
  6365. Name = L"";
  6366. }
  6367. else
  6368. {
  6369. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6370. }
  6371. if (FCopyParamAutoSelected.IsEmpty())
  6372. {
  6373. // if previous preset was not autoselected, make new preset the "default"
  6374. FCopyParamDefault = Name;
  6375. }
  6376. GUIConfiguration->CopyParamCurrent = Name;
  6377. }
  6378. //---------------------------------------------------------------------------
  6379. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6380. {
  6381. // sanity check
  6382. bool ExistingPreset =
  6383. (FTransferListHoverIndex >= 0) &&
  6384. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6385. DebugAssert(ExistingPreset);
  6386. if (ExistingPreset)
  6387. {
  6388. HDC DC = GetDC(0);
  6389. TCanvas * Canvas = new TCanvas();
  6390. try
  6391. {
  6392. Canvas->Handle = DC;
  6393. Canvas->Font = GetToolbarFont(this);
  6394. UnicodeString Name;
  6395. if (FTransferListHoverIndex == 0)
  6396. {
  6397. Name = L"";
  6398. }
  6399. else
  6400. {
  6401. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6402. }
  6403. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6404. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6405. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6406. static_cast<TObject*>(GetComponent(fcTransferList)));
  6407. UnicodeString InfoStr =
  6408. GUIConfiguration->CopyParamPreset[Name].
  6409. GetInfoStr(L"; ",
  6410. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6411. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6412. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6413. {
  6414. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6415. {
  6416. InfoStr.SetLength(InfoStr.Length() - 1);
  6417. }
  6418. InfoStr += Ellipsis;
  6419. }
  6420. // UpdateCaption does not cause invalidation of whole submenu, while
  6421. // setting Caption property does.
  6422. // also it probably does not resize the label, even if necessary
  6423. // (we do not want that anyway)
  6424. TransferLabel->UpdateCaption(InfoStr);
  6425. }
  6426. __finally
  6427. {
  6428. Canvas->Handle = NULL;
  6429. ReleaseDC(0, DC);
  6430. delete Canvas;
  6431. }
  6432. }
  6433. }
  6434. //---------------------------------------------------------------------------
  6435. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6436. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6437. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6438. {
  6439. if (FTransferListHoverIndex != AHoverIndex)
  6440. {
  6441. FTransferListHoverIndex = AHoverIndex;
  6442. UpdateTransferLabel();
  6443. }
  6444. }
  6445. //---------------------------------------------------------------------------
  6446. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6447. {
  6448. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6449. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6450. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6451. {
  6452. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6453. {
  6454. if (!NonVisualDataModule->Busy)
  6455. {
  6456. OpenDirectory(GetSide(osCurrent));
  6457. }
  6458. Message.Result = 1;
  6459. }
  6460. else
  6461. {
  6462. TForm::Dispatch(&Message);
  6463. }
  6464. }
  6465. else
  6466. {
  6467. TForm::Dispatch(&Message);
  6468. }
  6469. }
  6470. //---------------------------------------------------------------------------
  6471. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6472. {
  6473. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6474. if ((FIgnoreNextDialogChar != 0) &&
  6475. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6476. {
  6477. Message.Result = 1;
  6478. }
  6479. else
  6480. {
  6481. TForm::Dispatch(&Message);
  6482. }
  6483. FIgnoreNextDialogChar = 0;
  6484. }
  6485. //---------------------------------------------------------------------------
  6486. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6487. {
  6488. // The four low-order bits are used internally by Windows
  6489. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6490. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6491. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6492. // 61730 - restore thru double click - undocumented
  6493. // 61490 - maximize thru double click - undocumented
  6494. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6495. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6496. {
  6497. SysResizing(Cmd);
  6498. }
  6499. TForm::Dispatch(&Message);
  6500. }
  6501. //---------------------------------------------------------------------------
  6502. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6503. {
  6504. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6505. // Also there no point returning TRUE as we are not able to
  6506. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6507. // Hence the process termination might be safer :)
  6508. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6509. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6510. {
  6511. Message.Result = FALSE;
  6512. }
  6513. else
  6514. {
  6515. Message.Result = TRUE;
  6516. }
  6517. // Do not call default handling as that triggers OnCloseQuery,
  6518. // where our implementation will popup confirmation dialogs, what we do not want,
  6519. // as per Vista guidelines:
  6520. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6521. }
  6522. //---------------------------------------------------------------------------
  6523. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6524. {
  6525. if (Message.EndSession && IsApplicationMinimized())
  6526. {
  6527. // WORKAROUND
  6528. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6529. // when it receives WM_ENDSESSION,
  6530. // but that sometimes (particularly when application is minimized) cause crashes.
  6531. // Crash popups message that blocks log off.
  6532. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6533. // so we call ExitProcess() immediately, not even trying to cleanup.
  6534. // It still causes beep, so there's likely some popup, but it does not block
  6535. // log off.
  6536. ExitProcess(0);
  6537. }
  6538. TForm::Dispatch(&Message);
  6539. }
  6540. #ifdef _DEBUG
  6541. //---------------------------------------------------------------------------
  6542. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6543. {
  6544. TForm::Dispatch(&Message);
  6545. }
  6546. #endif
  6547. //---------------------------------------------------------------------------
  6548. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6549. {
  6550. }
  6551. //---------------------------------------------------------------------------
  6552. void __fastcall TCustomScpExplorerForm::DoShow()
  6553. {
  6554. // only now are the controls resized finally, so the size constraints
  6555. // will not conflict with possibly very small window size
  6556. RestoreFormParams();
  6557. // This indicates that the form was rescaled after parameters were loaded and
  6558. // as most probably the parameters were actually saved with the current form scaling
  6559. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6560. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6561. // and no rounding problems will occur.
  6562. // See also RestoreForm.
  6563. // (we should be safe to call RestoreParams unconditionally)
  6564. if (PixelsPerInch != Screen->PixelsPerInch)
  6565. {
  6566. RestoreParams();
  6567. }
  6568. FixControlsPlacement();
  6569. if (Position == poDefaultPosOnly)
  6570. {
  6571. CutFormToDesktop(this);
  6572. }
  6573. TForm::DoShow();
  6574. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6575. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6576. if (Terminal == NULL)
  6577. {
  6578. StartingDisconnected();
  6579. }
  6580. UpdatePixelsPerInchMainWindowCounter();
  6581. FShowing = true;
  6582. }
  6583. //---------------------------------------------------------------------------
  6584. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6585. {
  6586. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6587. }
  6588. //---------------------------------------------------------------------------
  6589. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6590. {
  6591. DoTerminalListChanged();
  6592. }
  6593. //---------------------------------------------------------------------------
  6594. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6595. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6596. TNotifyEvent OnBalloonClick, TObject * UserData)
  6597. {
  6598. bool Do;
  6599. UnicodeString Message;
  6600. if (E == NULL)
  6601. {
  6602. Message = Str;
  6603. Do = true;
  6604. }
  6605. else
  6606. {
  6607. Do = ExceptionMessage(E, Message);
  6608. }
  6609. if (Do && WinConfiguration->BalloonNotifications)
  6610. {
  6611. UnicodeString Title;
  6612. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6613. {
  6614. Message = TrimLeft(Message);
  6615. }
  6616. else
  6617. {
  6618. Message = UnformatMessage(Message);
  6619. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6620. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6621. Title = LoadResourceString(Captions[Type]);
  6622. if (Terminal != NULL)
  6623. {
  6624. Title = FORMAT(L"%s - %s",
  6625. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6626. }
  6627. }
  6628. if (Seconds == 0)
  6629. {
  6630. Seconds = WinConfiguration->NotificationsTimeout;
  6631. }
  6632. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6633. }
  6634. }
  6635. //---------------------------------------------------------------------------
  6636. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6637. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6638. UnicodeString HelpKeyword, const TMessageParams * Params,
  6639. TTerminal * Terminal)
  6640. {
  6641. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6642. (FOnFeedSynchronizeError != NULL)) &&
  6643. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6644. {
  6645. if (FOnFeedSynchronizeError != NULL)
  6646. {
  6647. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6648. }
  6649. else
  6650. {
  6651. DebugAssert(FErrorList != NULL);
  6652. TStringList * MoreMessagesCopy = NULL;
  6653. if (MoreMessages)
  6654. {
  6655. MoreMessagesCopy = new TStringList();
  6656. MoreMessagesCopy->Assign(MoreMessages);
  6657. }
  6658. FErrorList->AddObject(Message, MoreMessagesCopy);
  6659. }
  6660. PopupTrayBalloon(Terminal, Message, Type);
  6661. return ContinueAnswer(Answers);
  6662. }
  6663. else
  6664. {
  6665. bool UseBalloon = FTrayIcon->Visible;
  6666. if (UseBalloon)
  6667. {
  6668. PopupTrayBalloon(Terminal, Message, Type);
  6669. }
  6670. unsigned int Result;
  6671. try
  6672. {
  6673. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6674. }
  6675. __finally
  6676. {
  6677. // cancel only balloon we popped up, otherwise we may cancel notification
  6678. // balloon that was there before the message dialog
  6679. // (such as "dd confirmation opt in balloon)
  6680. if (UseBalloon)
  6681. {
  6682. FTrayIcon->CancelBalloon();
  6683. }
  6684. }
  6685. return Result;
  6686. }
  6687. }
  6688. //---------------------------------------------------------------------------
  6689. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6690. TTerminal * Terminal, Exception * E)
  6691. {
  6692. if (FTrayIcon->Visible)
  6693. {
  6694. PopupTrayBalloon(Terminal, L"", qtError, E);
  6695. }
  6696. // particularly prevent opening new session from jump list,
  6697. // while exception is shown
  6698. NonVisualDataModule->StartBusy();
  6699. try
  6700. {
  6701. ShowExtendedExceptionEx(Terminal, E);
  6702. }
  6703. __finally
  6704. {
  6705. NonVisualDataModule->EndBusy();
  6706. FTrayIcon->CancelBalloon();
  6707. }
  6708. }
  6709. //---------------------------------------------------------------------------
  6710. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6711. {
  6712. if (Terminal->Active)
  6713. {
  6714. InitStatusBar();
  6715. }
  6716. // cannot rely on active page being page for active terminal,
  6717. // as it can happen that active page is the "new session" page
  6718. // (e.g. when reconnecting active terminal, while login dialog
  6719. // invoked from "new session" page is modal)
  6720. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6721. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6722. }
  6723. //---------------------------------------------------------------------------
  6724. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6725. TTerminal * Terminal, Exception * E)
  6726. {
  6727. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6728. if (!Terminal->Active)
  6729. {
  6730. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6731. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6732. {
  6733. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6734. }
  6735. }
  6736. }
  6737. //---------------------------------------------------------------------------
  6738. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6739. UnicodeString Message, TQueryType Type,
  6740. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6741. {
  6742. if ((E == NULL) ||
  6743. ExceptionMessage(E, Message))
  6744. {
  6745. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6746. if (Important)
  6747. {
  6748. Seconds *= 5;
  6749. }
  6750. UnicodeString NoteMessage(UnformatMessage(Message));
  6751. if (Terminal != NULL)
  6752. {
  6753. NoteMessage = FORMAT(L"%s: %s",
  6754. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6755. }
  6756. if (WinConfiguration->BalloonNotifications)
  6757. {
  6758. AddNote(NoteMessage);
  6759. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6760. }
  6761. else
  6762. {
  6763. FlashOnBackground();
  6764. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6765. }
  6766. }
  6767. }
  6768. //---------------------------------------------------------------------------
  6769. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6770. {
  6771. RestoreApp();
  6772. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6773. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6774. !NonVisualDataModule->Busy)
  6775. {
  6776. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6777. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6778. if (!ComponentVisible[fcQueueView])
  6779. {
  6780. ToggleQueueVisibility();
  6781. GoToQueue();
  6782. }
  6783. }
  6784. }
  6785. //---------------------------------------------------------------------------
  6786. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6787. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6788. {
  6789. UnicodeString Message;
  6790. TNotifyEvent OnClick = NULL;
  6791. TObject * UserData = NULL;
  6792. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6793. switch (Event)
  6794. {
  6795. case qeEmptyButMonitored:
  6796. if ((ATerminal != Terminal) || QueueInvisible)
  6797. {
  6798. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6799. OnClick = QueueEmptyNoteClicked;
  6800. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6801. TerminalNoteData->Terminal = ATerminal;
  6802. UserData = TerminalNoteData;
  6803. }
  6804. break;
  6805. case qeEmpty:
  6806. OperationComplete(ATerminal->QueueOperationStart);
  6807. break;
  6808. case qePendingUserAction:
  6809. if ((ATerminal != Terminal) ||
  6810. (QueueInvisible && !IsQueueAutoPopup()))
  6811. {
  6812. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6813. }
  6814. break;
  6815. default:
  6816. DebugFail();
  6817. }
  6818. if (!Message.IsEmpty())
  6819. {
  6820. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6821. }
  6822. }
  6823. //---------------------------------------------------------------------------
  6824. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6825. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6826. {
  6827. if (FDDExtMapFile != NULL)
  6828. {
  6829. CloseHandle(FDDExtMapFile);
  6830. FDDExtMapFile = NULL;
  6831. }
  6832. if (WinConfiguration->DDFakeFile)
  6833. {
  6834. DDFakeFileInitDrag(FileList, Created);
  6835. }
  6836. }
  6837. //---------------------------------------------------------------------------
  6838. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6839. {
  6840. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6841. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6842. {
  6843. FFakeFileDropTarget = FileName;
  6844. }
  6845. }
  6846. //---------------------------------------------------------------------------
  6847. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6848. {
  6849. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6850. if (!ForceDirectories(ApiPath(Result)))
  6851. {
  6852. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6853. }
  6854. FileSetAttr(ApiPath(Result), faHidden);
  6855. return Result;
  6856. }
  6857. //---------------------------------------------------------------------------
  6858. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6859. bool & Created)
  6860. {
  6861. FFakeFileDropTarget = UnicodeString();
  6862. FDragFakeDirectory = CreateFakeTransferDirectory();
  6863. FileList->AddItem(NULL, FDragFakeDirectory);
  6864. Created = true;
  6865. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6866. {
  6867. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6868. }
  6869. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6870. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6871. {
  6872. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6873. TDragExtCommStruct* CommStruct;
  6874. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6875. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6876. DebugAssert(CommStruct != NULL);
  6877. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6878. CommStruct->Dragging = true;
  6879. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6880. LENOF(CommStruct->DropDest));
  6881. NULL_TERMINATE(CommStruct->DropDest);
  6882. UnmapViewOfFile(CommStruct);
  6883. }
  6884. }
  6885. //---------------------------------------------------------------------------
  6886. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6887. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6888. {
  6889. bool Result;
  6890. DebugAssert(!IsLocalBrowserMode());
  6891. if (Sender == RemoteDirView)
  6892. {
  6893. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6894. }
  6895. else
  6896. {
  6897. DebugAssert(Sender == RemoteDriveView);
  6898. TStrings * FileList = RemoteDriveView->DragFileList();
  6899. try
  6900. {
  6901. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6902. }
  6903. __finally
  6904. {
  6905. delete FileList;
  6906. }
  6907. }
  6908. if (FDDTargetControl == RemoteDriveView)
  6909. {
  6910. RemoteDriveView->UpdateDropTarget();
  6911. }
  6912. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6913. // or from tree view to dir view.
  6914. // foMove happens when file/dir is dragged from remote tree view outside of
  6915. // application via dragex
  6916. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6917. (DropSourceControl == RemoteDriveView))
  6918. {
  6919. RemoteDriveView->UpdateDropSource();
  6920. }
  6921. return Result;
  6922. }
  6923. //---------------------------------------------------------------------------
  6924. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6925. {
  6926. DebugAssert(!IsLocalBrowserMode());
  6927. // This also handles drops of remote files to queue.
  6928. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6929. SAFE_DESTROY(FDDFileList);
  6930. if (!FFakeFileDropTarget.IsEmpty())
  6931. {
  6932. RemoveDir(ApiPath(FFakeFileDropTarget));
  6933. }
  6934. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6935. {
  6936. try
  6937. {
  6938. TDragResult DDResult = (Sender == RemoteDirView) ?
  6939. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6940. // Focus is moved to the target application,
  6941. // but as we are going to present the UI, we need to steal the focus back.
  6942. // This most likely won't work though (windows does not allow application
  6943. // to steal focus most of the time)
  6944. Application->BringToFront();
  6945. // On older version of Windows we never got drMove here, see also comment below.
  6946. // On Windows 10, we get the "move".
  6947. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6948. {
  6949. UnicodeString TargetDirectory;
  6950. TFileOperation Operation;
  6951. // drInvalid may mean drMove, see comment below
  6952. switch (DDResult)
  6953. {
  6954. case drCopy:
  6955. Operation = foCopy;
  6956. break;
  6957. case drMove:
  6958. Operation = foMove;
  6959. break;
  6960. default:
  6961. DebugFail();
  6962. case drInvalid:
  6963. // prefer "copy" for safety
  6964. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6965. break;
  6966. }
  6967. TTransferOperationParam Param;
  6968. UnicodeString CounterName;
  6969. bool ForceQueue;
  6970. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6971. {
  6972. // we get drInvalid both if d&d was intercepted by ddext,
  6973. // and when users drops on no-drop location.
  6974. // we tell the difference by existence of response from ddext,
  6975. // so we ignore absence of response in this case
  6976. if (DDResult != drInvalid)
  6977. {
  6978. // here we know that the extension is installed,
  6979. // as it is checked as soon as drag&drop starts from
  6980. // RemoteFileControlDDCreateDragFileList
  6981. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6982. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6983. {
  6984. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6985. }
  6986. else
  6987. {
  6988. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6989. }
  6990. }
  6991. }
  6992. else
  6993. {
  6994. // download using fake file
  6995. Param.Temp = false;
  6996. Param.DragDrop = true;
  6997. if (ForceQueue)
  6998. {
  6999. Param.Queue = asOn;
  7000. }
  7001. if (Sender == RemoteDirView)
  7002. {
  7003. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7004. }
  7005. if (RemoteFileControlFileOperation(Sender, Operation,
  7006. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7007. {
  7008. Configuration->Usage->Inc(CounterName);
  7009. }
  7010. }
  7011. }
  7012. }
  7013. __finally
  7014. {
  7015. CloseHandle(FDDExtMapFile);
  7016. FDDExtMapFile = NULL;
  7017. delete FDragFakeMonitors;
  7018. FDragFakeMonitors = NULL;
  7019. RemoveDir(ApiPath(FDragFakeDirectory));
  7020. FDragFakeDirectory = L"";
  7021. FFakeFileDropTarget = UnicodeString();
  7022. }
  7023. }
  7024. if (FDragDropSshTerminate.get() != NULL)
  7025. {
  7026. FDragDropSshTerminate->Rethrow();
  7027. }
  7028. }
  7029. //---------------------------------------------------------------------------
  7030. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7031. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7032. {
  7033. // Remember drop effect so we know (when user drops files), if we copy or move
  7034. FLastDropEffect = dwEffect;
  7035. }
  7036. //---------------------------------------------------------------------------
  7037. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7038. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7039. {
  7040. bool Result;
  7041. if (FDDTargetControl == QueueView3)
  7042. {
  7043. Directory = DefaultDownloadTargetDirectory();
  7044. Result = true;
  7045. CounterName = L"DownloadsDragDropQueue";
  7046. ForceQueue = true;
  7047. }
  7048. else if (!FFakeFileDropTarget.IsEmpty())
  7049. {
  7050. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7051. Result = true;
  7052. ForceQueue = false;
  7053. CounterName = L"DownloadsDragDropFakeFile";
  7054. }
  7055. else
  7056. {
  7057. ForceQueue = false;
  7058. Enabled = false;
  7059. try
  7060. {
  7061. int Timer = 0;
  7062. Result = false;
  7063. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7064. {
  7065. {
  7066. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7067. TDragExtCommStruct* CommStruct;
  7068. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7069. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7070. DebugAssert(CommStruct != NULL);
  7071. Result = !CommStruct->Dragging;
  7072. if (Result)
  7073. {
  7074. Directory = ExtractFilePath(CommStruct->DropDest);
  7075. CounterName = L"DownloadsDragDropExternalExt";
  7076. }
  7077. UnmapViewOfFile(CommStruct);
  7078. }
  7079. if (!Result)
  7080. {
  7081. Sleep(50);
  7082. Timer += 50;
  7083. Application->ProcessMessages();
  7084. }
  7085. }
  7086. }
  7087. __finally
  7088. {
  7089. Enabled = true;
  7090. }
  7091. }
  7092. return Result;
  7093. }
  7094. //---------------------------------------------------------------------------
  7095. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7096. const UnicodeString TempDir, int SecDelay)
  7097. {
  7098. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7099. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7100. if (FDelayedDeletionTimer == NULL)
  7101. {
  7102. DebugAssert(HandleAllocated());
  7103. FDelayedDeletionTimer = new TTimer(this);
  7104. FDelayedDeletionTimer->Interval = 10000;
  7105. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7106. }
  7107. else
  7108. {
  7109. FDelayedDeletionTimer->Enabled = true;
  7110. }
  7111. }
  7112. //---------------------------------------------------------------------------
  7113. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7114. {
  7115. DebugAssert(FDelayedDeletionList != NULL);
  7116. TDateTime N = Now();
  7117. TDateTime Alert;
  7118. UnicodeString Directory;
  7119. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7120. {
  7121. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7122. if ((N >= Alert) || (Sender == NULL))
  7123. {
  7124. Directory = FDelayedDeletionList->Strings[Index];
  7125. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7126. {
  7127. FDelayedDeletionList->Delete(Index);
  7128. }
  7129. }
  7130. }
  7131. if (FDelayedDeletionList->Count == 0)
  7132. {
  7133. FDelayedDeletionTimer->Enabled = false;
  7134. }
  7135. }
  7136. //---------------------------------------------------------------------------
  7137. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7138. {
  7139. DebugAssert(!IsLocalBrowserMode());
  7140. if (IsFileControl(FDDTargetControl, osRemote) ||
  7141. (FDDTargetControl == SessionsPageControl))
  7142. {
  7143. TTerminal * TargetTerminal = NULL;
  7144. TFileOperation Operation = foNone;
  7145. if (FDDTargetControl == SessionsPageControl)
  7146. {
  7147. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7148. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7149. // do not allow dropping on the "+" tab
  7150. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7151. if (TargetTerminal != NULL)
  7152. {
  7153. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7154. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7155. {
  7156. Operation = foRemoteMove;
  7157. }
  7158. else
  7159. {
  7160. Operation = foRemoteCopy;
  7161. }
  7162. }
  7163. }
  7164. else
  7165. {
  7166. if (FLastDropEffect == DROPEFFECT_MOVE)
  7167. {
  7168. Operation = foRemoteMove;
  7169. }
  7170. else if (FLastDropEffect == DROPEFFECT_COPY)
  7171. {
  7172. Operation = foRemoteCopy;
  7173. }
  7174. }
  7175. if (Operation != foNone)
  7176. {
  7177. RemoteFileControlFileOperation(DropSourceControl,
  7178. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7179. }
  7180. // abort drag&drop
  7181. Abort();
  7182. }
  7183. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7184. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7185. (FDDTargetControl != QueueView3))
  7186. {
  7187. DebugAssert(!FDragTempDir.IsEmpty());
  7188. TTransferType Type;
  7189. UnicodeString TempDir = FDragTempDir;
  7190. // We clear FDragTempDir before calling
  7191. // just in case it fail (raises exception)
  7192. FDragTempDir = L"";
  7193. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7194. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7195. // empty directory parameter means temp directory -> don't display it!
  7196. UnicodeString TargetDir = L"";
  7197. int Options = 0;
  7198. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7199. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7200. {
  7201. Abort();
  7202. }
  7203. // TargetDir is set when dropped on local file control
  7204. // (this was workaround for legacy dirview event handling, now it should be
  7205. // made prettier)
  7206. if (TargetDir.IsEmpty())
  7207. {
  7208. TargetDir = TempDir;
  7209. if (ForceDirectories(ApiPath(TargetDir)))
  7210. {
  7211. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7212. FPendingTempSpaceWarn = true;
  7213. try
  7214. {
  7215. FDragDropOperation = true;
  7216. int Params = cpTemporary |
  7217. (Type == ttMove ? cpDelete : 0);
  7218. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7219. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7220. }
  7221. __finally
  7222. {
  7223. FDragDropOperation = false;
  7224. FPendingTempSpaceWarn = false;
  7225. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7226. }
  7227. }
  7228. else
  7229. {
  7230. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7231. }
  7232. }
  7233. }
  7234. }
  7235. //---------------------------------------------------------------------------
  7236. void __fastcall TCustomScpExplorerForm::DDDownload(
  7237. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7238. {
  7239. DebugAssert(!IsLocalBrowserMode());
  7240. TAutoBatch AutoBatch(this);
  7241. UpdateCopyParamCounters(*CopyParam);
  7242. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7243. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7244. {
  7245. RemoteDriveView->UpdateDropSource();
  7246. }
  7247. }
  7248. //---------------------------------------------------------------------------
  7249. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7250. {
  7251. public:
  7252. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7253. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7254. {
  7255. }
  7256. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7257. {
  7258. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7259. TDataObjectFilesEx::AllowData(FormatEtc);
  7260. }
  7261. };
  7262. //---------------------------------------------------------------------------
  7263. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7264. TObject * Sender, TDataObject *& DataObject)
  7265. {
  7266. if (FDDExtMapFile != NULL)
  7267. {
  7268. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7269. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7270. {
  7271. Abort();
  7272. }
  7273. if (FileList->Count > 0)
  7274. {
  7275. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7276. if (!FilesObject->IsValid(true, true))
  7277. {
  7278. FilesObject->_Release();
  7279. }
  7280. else
  7281. {
  7282. DataObject = FilesObject;
  7283. }
  7284. }
  7285. }
  7286. }
  7287. //---------------------------------------------------------------------------
  7288. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7289. {
  7290. DebugFail();
  7291. }
  7292. //---------------------------------------------------------------------------
  7293. void __fastcall TCustomScpExplorerForm::GoToTree()
  7294. {
  7295. ComponentVisible[fcRemoteTree] = true;
  7296. DriveView(osRemote)->SetFocus();
  7297. }
  7298. //---------------------------------------------------------------------------
  7299. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7300. TPanelExport Export)
  7301. {
  7302. TCustomDirView * DirView = this->DirView(Side);
  7303. std::unique_ptr<TStrings> ExportData(new TStringList());
  7304. switch (Export)
  7305. {
  7306. case pePath:
  7307. ExportData->Add(DirView->PathName);
  7308. break;
  7309. case peFileList:
  7310. case peFullFileList:
  7311. {
  7312. bool FullPath = (Export == peFullFileList);
  7313. DirView->CreateFileList(false, FullPath, ExportData.get());
  7314. for (int Index = 0; Index < ExportData->Count; Index++)
  7315. {
  7316. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7317. {
  7318. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7319. }
  7320. }
  7321. }
  7322. break;
  7323. default:
  7324. DebugFail();
  7325. }
  7326. return ExportData.release();
  7327. }
  7328. //---------------------------------------------------------------------------
  7329. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7330. TPanelExport Export, TPanelExportDestination Destination)
  7331. {
  7332. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7333. PanelExportStore(Side, Export, Destination, ExportData.get());
  7334. }
  7335. //---------------------------------------------------------------------------
  7336. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7337. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7338. TStrings * ExportData)
  7339. {
  7340. if (Destination == pedClipboard)
  7341. {
  7342. TInstantOperationVisualizer Visualizer;
  7343. CopyToClipboard(ExportData);
  7344. }
  7345. else
  7346. {
  7347. DebugFail();
  7348. }
  7349. }
  7350. //---------------------------------------------------------------------------
  7351. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7352. {
  7353. TCustomDirView * DirView = this->DirView(Side);
  7354. UnicodeString Mask = DirView->Mask;
  7355. if (DoFilterMaskDialog(DirView, Mask))
  7356. {
  7357. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7358. Configuration->Usage->Inc(L"Filters");
  7359. }
  7360. }
  7361. //---------------------------------------------------------------------------
  7362. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7363. {
  7364. return FQueueController->DefaultOperation();
  7365. }
  7366. //---------------------------------------------------------------------------
  7367. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7368. TQueueOperation Operation, void ** Param)
  7369. {
  7370. switch (Operation)
  7371. {
  7372. case qoPreferences:
  7373. return true;
  7374. case qoGoTo:
  7375. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7376. case qoOnceEmpty:
  7377. return IsAnythingQueued();
  7378. default:
  7379. return FQueueController->AllowOperation(Operation, Param);
  7380. }
  7381. }
  7382. //---------------------------------------------------------------------------
  7383. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7384. {
  7385. if (DebugAlwaysTrue(QueueView3->Visible))
  7386. {
  7387. QueueView3->SetFocus();
  7388. }
  7389. }
  7390. //---------------------------------------------------------------------------
  7391. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7392. TQueueOperation Operation, void * Param)
  7393. {
  7394. if (Operation == qoGoTo)
  7395. {
  7396. GoToQueue();
  7397. }
  7398. else if (Operation == qoPreferences)
  7399. {
  7400. PreferencesDialog(pmQueue);
  7401. }
  7402. else
  7403. {
  7404. FQueueController->ExecuteOperation(Operation, Param);
  7405. }
  7406. }
  7407. //---------------------------------------------------------------------------
  7408. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7409. {
  7410. return (Queue != NULL) && Queue->Enabled;
  7411. }
  7412. //---------------------------------------------------------------------------
  7413. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7414. {
  7415. DebugAssert(Queue != NULL);
  7416. if (Queue != NULL)
  7417. {
  7418. Queue->Enabled = !Queue->Enabled;
  7419. }
  7420. }
  7421. //---------------------------------------------------------------------------
  7422. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7423. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7424. {
  7425. FQueueActedItem = QueueView3->ItemFocused;
  7426. }
  7427. //---------------------------------------------------------------------------
  7428. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7429. {
  7430. return TopDock->Height + QueueSplitter->Height;
  7431. }
  7432. //---------------------------------------------------------------------------
  7433. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7434. {
  7435. return
  7436. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7437. (QueueDock->Visible ? QueueDock->Height : 0) +
  7438. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7439. }
  7440. //---------------------------------------------------------------------------
  7441. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7442. {
  7443. return ScaleByTextHeight(this, 48);
  7444. }
  7445. //---------------------------------------------------------------------------
  7446. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7447. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7448. {
  7449. // when queue is hidden by double-clicking splitter, stray attempt to
  7450. // resize the panel with strange value arrives, make sure it is ignored
  7451. if (ComponentVisible[fcQueueView])
  7452. {
  7453. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7454. if (NewSize > MaxHeightLimit)
  7455. {
  7456. NewSize = MaxHeightLimit;
  7457. }
  7458. int MinHeightLimit =
  7459. GetStaticQueuePanelComponentsHeight() +
  7460. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7461. GetMinQueueViewHeight();
  7462. if (NewSize < MinHeightLimit)
  7463. {
  7464. NewSize = MinHeightLimit;
  7465. }
  7466. }
  7467. else
  7468. {
  7469. Accept = false;
  7470. }
  7471. }
  7472. //---------------------------------------------------------------------------
  7473. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7474. {
  7475. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7476. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7477. if (QueueViewHeight < GetMinQueueViewHeight())
  7478. {
  7479. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7480. }
  7481. }
  7482. //---------------------------------------------------------------------------
  7483. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7484. TDragObject *& /*DragObject*/)
  7485. {
  7486. FQueueActedItem = QueueView3->ItemFocused;
  7487. }
  7488. //---------------------------------------------------------------------------
  7489. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7490. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7491. {
  7492. Accept = true;
  7493. if (Source == QueueView3)
  7494. {
  7495. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7496. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7497. if (Accept)
  7498. {
  7499. TQueueItemProxy * QueueItem;
  7500. TQueueItemProxy * DestQueueItem;
  7501. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7502. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7503. Accept = (QueueItem != DestQueueItem) &&
  7504. (QueueItem->Status == TQueueItem::qsPending) &&
  7505. (DestQueueItem->Status == TQueueItem::qsPending);
  7506. }
  7507. }
  7508. }
  7509. //---------------------------------------------------------------------------
  7510. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7511. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7512. {
  7513. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7514. {
  7515. TQueueItemProxy * QueueItem;
  7516. TQueueItemProxy * DestQueueItem;
  7517. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7518. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7519. QueueItem->Move(DestQueueItem);
  7520. }
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7524. {
  7525. if ((QueueView3->ItemFocused == NULL) &&
  7526. (QueueView3->Items->Count > 0))
  7527. {
  7528. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7529. }
  7530. QueueLabelUpdateStatus();
  7531. }
  7532. //---------------------------------------------------------------------------
  7533. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7534. {
  7535. QueueLabelUpdateStatus();
  7536. }
  7537. //---------------------------------------------------------------------------
  7538. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7539. {
  7540. QueueLabel->UpdateStatus();
  7541. }
  7542. //---------------------------------------------------------------------------
  7543. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7544. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7545. {
  7546. if (Selected)
  7547. {
  7548. NonVisualDataModule->UpdateNonVisibleActions();
  7549. }
  7550. }
  7551. //---------------------------------------------------------------------------
  7552. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7553. {
  7554. TDragDropFilesEx * Result = NULL;
  7555. if (Sender == SessionsPageControl)
  7556. {
  7557. Result = FSessionsDragDropFilesEx;
  7558. }
  7559. else if (Sender == QueueView3)
  7560. {
  7561. Result = FQueueDragDropFilesEx;
  7562. }
  7563. else
  7564. {
  7565. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7566. if (DirView != NULL)
  7567. {
  7568. Result = DirView->DragDropFilesEx;
  7569. }
  7570. else
  7571. {
  7572. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7573. if (DriveView != NULL)
  7574. {
  7575. Result = DriveView->DragDropFilesEx;
  7576. }
  7577. }
  7578. }
  7579. DebugAssert(Result != NULL);
  7580. return Result;
  7581. }
  7582. //---------------------------------------------------------------------------
  7583. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7584. {
  7585. return (DView->SelCount == DView->FilesCount);
  7586. }
  7587. //---------------------------------------------------------------------------
  7588. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7589. {
  7590. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7591. }
  7592. //---------------------------------------------------------------------------
  7593. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7594. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7595. {
  7596. DebugAssert(!IsLocalBrowserMode());
  7597. TFileOperation Operation;
  7598. switch (Effect)
  7599. {
  7600. case DROPEFFECT_MOVE:
  7601. Operation = foMove;
  7602. break;
  7603. case DROPEFFECT_COPY:
  7604. // occures on WinXP (reported by user)
  7605. default:
  7606. Operation = foCopy;
  7607. break;
  7608. };
  7609. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7610. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7611. if (DragDropFilesEx->FileList->Count > 0)
  7612. {
  7613. TStrings * FileList = new TStringList();
  7614. try
  7615. {
  7616. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7617. {
  7618. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7619. }
  7620. FDragDropOperation = true;
  7621. TTransferOperationParam Param;
  7622. Param.TargetDirectory = TargetPath;
  7623. // upload, no temp dirs
  7624. Param.Temp = false;
  7625. Param.DragDrop = DragDrop;
  7626. Param.Options =
  7627. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7628. if (ForceQueue)
  7629. {
  7630. Param.Queue = asOn;
  7631. }
  7632. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7633. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7634. {
  7635. if (IsFileControl(DropSourceControl, osLocal))
  7636. {
  7637. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7638. }
  7639. else
  7640. {
  7641. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7642. }
  7643. }
  7644. }
  7645. __finally
  7646. {
  7647. FDragDropOperation = false;
  7648. delete FileList;
  7649. }
  7650. }
  7651. }
  7652. //---------------------------------------------------------------------------
  7653. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7654. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7655. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7656. {
  7657. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7658. }
  7659. //---------------------------------------------------------------------------
  7660. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7661. TObject * Sender, int grfKeyState, int & dwEffect)
  7662. {
  7663. DebugAssert(!IsLocalBrowserMode());
  7664. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7665. if ((dwEffect != DROPEFFECT_NONE) &&
  7666. IsFileControl(DropSourceControl, osRemote))
  7667. {
  7668. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7669. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7670. (RemoteDirView->DropTarget == NULL))
  7671. {
  7672. dwEffect = DROPEFFECT_NONE;
  7673. }
  7674. else
  7675. {
  7676. if (dwEffect == DROPEFFECT_COPY)
  7677. {
  7678. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7679. // currently we support copying always (at least via temporary directory);
  7680. // remove associated checks once this all proves stable and working
  7681. bool CopyCapable = true;
  7682. // if we do not support neither of operations, there's no discussion
  7683. if (!MoveCapable && !CopyCapable)
  7684. {
  7685. dwEffect = DROPEFFECT_NONE;
  7686. }
  7687. else
  7688. {
  7689. // The default effect inside remote panel is move,
  7690. // unless we do not support it, but support copy
  7691. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7692. {
  7693. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7694. }
  7695. else
  7696. {
  7697. // with ctrl-down, we want copy unless it is not supported
  7698. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7699. }
  7700. }
  7701. }
  7702. }
  7703. }
  7704. }
  7705. //---------------------------------------------------------------------------
  7706. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7707. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7708. {
  7709. DebugAssert(!IsLocalBrowserMode());
  7710. if (FDDTotalSize >= 0)
  7711. {
  7712. if (File->IsDirectory)
  7713. {
  7714. FDDTotalSize = -1;
  7715. }
  7716. else
  7717. {
  7718. FDDTotalSize += File->Size;
  7719. }
  7720. }
  7721. DebugAssert(!FDragTempDir.IsEmpty());
  7722. // TODO: this is quite ineffective
  7723. // TODO: what if invalid character replacement is disabled?
  7724. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7725. UnicodeString TransferFileName;
  7726. if (Sender == RemoteDriveView)
  7727. {
  7728. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7729. }
  7730. else
  7731. {
  7732. TransferFileName = File->FileName;
  7733. }
  7734. FDDFileList->AddObject(TransferFileName, File);
  7735. }
  7736. //---------------------------------------------------------------------------
  7737. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7738. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7739. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7740. {
  7741. // sometimes we do not get DDEnd so the list is not released
  7742. SAFE_DESTROY(FDDFileList);
  7743. FDDFileList = new TStringList();
  7744. FDragTempDir = WinConfiguration->TemporaryDir();
  7745. FDDTotalSize = 0;
  7746. FDragDropSshTerminate.reset(NULL);
  7747. }
  7748. //---------------------------------------------------------------------------
  7749. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7750. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7751. HRESULT & Result)
  7752. {
  7753. if (Result == DRAGDROP_S_DROP)
  7754. {
  7755. try
  7756. {
  7757. GlobalDragImageList->HideDragImage();
  7758. try
  7759. {
  7760. RemoteFileControlDDTargetDrop();
  7761. }
  7762. catch(ESshTerminate & E)
  7763. {
  7764. FDragDropSshTerminate.reset(E.Clone());
  7765. }
  7766. }
  7767. catch (Exception &E)
  7768. {
  7769. // If downloading fails we need to cancel drag&drop, otherwise
  7770. // Explorer shows error
  7771. // But by the way exception probably never reach this point as
  7772. // it's catched on way.
  7773. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7774. Result = DRAGDROP_S_CANCEL;
  7775. ShowExtendedException(Terminal, &E);
  7776. }
  7777. }
  7778. }
  7779. //---------------------------------------------------------------------------
  7780. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7781. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7782. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7783. {
  7784. TFileMasks::TParams MaskParams;
  7785. MaskParams.Size = Size;
  7786. MaskParams.Modification = Modification;
  7787. // this does not re-parse the mask if it is the same as the last time
  7788. FDirViewMatchMask = Masks;
  7789. bool ImplicitMatch;
  7790. Matches =
  7791. // RecurseInclude parameter has no effect as the Path is empty
  7792. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7793. (AllowImplicitMatches || !ImplicitMatch);
  7794. }
  7795. //---------------------------------------------------------------------------
  7796. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7797. TObject * Sender, TListItem * Item, WORD & Indexes)
  7798. {
  7799. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7800. UnicodeString Ext;
  7801. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7802. {
  7803. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7804. }
  7805. else
  7806. {
  7807. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7808. }
  7809. if (SameText(Ext, Configuration->PartialExt))
  7810. {
  7811. Indexes |= oiPartial;
  7812. }
  7813. }
  7814. //---------------------------------------------------------------------------
  7815. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7816. {
  7817. return
  7818. DirViewEnabled(osCurrent) &&
  7819. DirView(osCurrent)->CanPasteFromClipBoard();
  7820. }
  7821. //---------------------------------------------------------------------------
  7822. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7823. {
  7824. bool Result = false;
  7825. if (CanPasteToDirViewFromClipBoard())
  7826. {
  7827. Result = true;
  7828. }
  7829. else
  7830. {
  7831. UnicodeString ClipboardText;
  7832. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7833. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7834. {
  7835. if (StoredSessions->IsUrl(ClipboardText))
  7836. {
  7837. Result = true;
  7838. }
  7839. else
  7840. {
  7841. Result = DirViewEnabled(osCurrent);
  7842. }
  7843. }
  7844. }
  7845. return Result;
  7846. }
  7847. //---------------------------------------------------------------------------
  7848. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7849. {
  7850. if (DoesClipboardContainOurFiles())
  7851. {
  7852. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7853. {
  7854. DebugAssert(!IsLocalBrowserMode());
  7855. TTerminalManager * Manager = TTerminalManager::Instance();
  7856. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7857. Manager->ActiveTerminal = FClipboardTerminal;
  7858. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7859. }
  7860. }
  7861. else if (CanPasteToDirViewFromClipBoard())
  7862. {
  7863. DirView(osCurrent)->PasteFromClipBoard();
  7864. }
  7865. else
  7866. {
  7867. UnicodeString ClipboardText;
  7868. if (NonEmptyTextFromClipboard(ClipboardText))
  7869. {
  7870. if (StoredSessions->IsUrl(ClipboardText))
  7871. {
  7872. NewSession(ClipboardText);
  7873. }
  7874. else
  7875. {
  7876. DirView(osCurrent)->Path = ClipboardText;
  7877. }
  7878. }
  7879. }
  7880. }
  7881. //---------------------------------------------------------------------------
  7882. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7883. {
  7884. // TBD
  7885. }
  7886. //---------------------------------------------------------------------------
  7887. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7888. {
  7889. TCustomDirView * ADirView = DirView(Side);
  7890. ADirView->SelectAll(Mode);
  7891. ADirView->SetFocus();
  7892. }
  7893. //---------------------------------------------------------------------------
  7894. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7895. {
  7896. TCustomDirView * ADirView = DirView(Side);
  7897. TFileFilter Filter;
  7898. DefaultFileFilter(Filter);
  7899. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7900. {
  7901. Configuration->Usage->Inc(L"MaskSelections");
  7902. ADirView->SelectFiles(Filter, Select);
  7903. ADirView->SetFocus();
  7904. }
  7905. }
  7906. //---------------------------------------------------------------------------
  7907. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7908. {
  7909. TCustomDirView * ADirView = DirView(Side);
  7910. ADirView->RestoreSelectedNames();
  7911. ADirView->SetFocus();
  7912. }
  7913. //---------------------------------------------------------------------------
  7914. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7915. {
  7916. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7917. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7918. {
  7919. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7920. UnicodeString Ext;
  7921. if (!IsSideLocalBrowser(osCurrent))
  7922. {
  7923. Ext = UnixExtractFileExt(FileName);
  7924. }
  7925. else
  7926. {
  7927. Ext = ExtractFileExt(FileName);
  7928. }
  7929. if (Ext.IsEmpty())
  7930. {
  7931. Ext = L".";
  7932. }
  7933. TFileFilter Filter;
  7934. Filter.Masks = FORMAT(L"*%s", (Ext));
  7935. Filter.Directories = false;
  7936. CurrentDirView->SelectFiles(Filter, Select);
  7937. }
  7938. }
  7939. //---------------------------------------------------------------------------
  7940. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7941. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7942. {
  7943. UnicodeString Result;
  7944. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7945. {
  7946. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7947. }
  7948. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7949. {
  7950. // noop
  7951. }
  7952. else
  7953. {
  7954. Result =
  7955. FMTLOAD(FILE_INFO_FORMAT,
  7956. (FormatBytes(FileInfo.SelectedSize),
  7957. FormatBytes(FileInfo.FilesSize),
  7958. FormatNumber(FileInfo.SelectedCount),
  7959. FormatNumber(FileInfo.FilesCount)));
  7960. }
  7961. return Result;
  7962. }
  7963. //---------------------------------------------------------------------------
  7964. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7965. TTBXStatusPanel * Panel, TOperationSide Side)
  7966. {
  7967. if (Panel->Index == 1)
  7968. {
  7969. ToggleShowHiddenFiles();
  7970. }
  7971. else if (Panel->Index == 2)
  7972. {
  7973. Filter(Side);
  7974. }
  7975. }
  7976. //---------------------------------------------------------------------------
  7977. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7978. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7979. {
  7980. DebugAssert(!StatusBar->SimplePanel);
  7981. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7982. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7983. }
  7984. //---------------------------------------------------------------------------
  7985. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7986. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7987. {
  7988. DebugAssert(StatusBar->Panels->Count >= 3);
  7989. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7990. if (FileInfo.HiddenCount > 0)
  7991. {
  7992. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7993. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7994. }
  7995. else
  7996. {
  7997. HiddenFilesPanel->ViewPriority = 0;
  7998. // not really necessary, just to cleanup no-longer-valid data
  7999. HiddenFilesPanel->Caption = L"";
  8000. }
  8001. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8002. if (FileInfo.FilteredCount > 0)
  8003. {
  8004. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8005. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8006. }
  8007. else
  8008. {
  8009. FilteredFilesPanel->ViewPriority = 0;
  8010. // not really necessary, just to cleanup no-longer-valid data
  8011. FilteredFilesPanel->Caption = L"";
  8012. }
  8013. }
  8014. //---------------------------------------------------------------------------
  8015. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8016. TObject * /*Sender*/)
  8017. {
  8018. if (DirView(osRemote)->Enabled)
  8019. {
  8020. DirView(osRemote)->SetFocus();
  8021. }
  8022. }
  8023. //---------------------------------------------------------------------------
  8024. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8025. {
  8026. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8027. switch (Config.Show)
  8028. {
  8029. case qvShow:
  8030. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8031. {
  8032. Config.Show = qvHide;
  8033. }
  8034. else
  8035. {
  8036. Config.Show = Config.LastHideShow;
  8037. }
  8038. break;
  8039. case qvHideWhenEmpty:
  8040. if (ComponentVisible[fcQueueView])
  8041. {
  8042. Config.Show = qvHide;
  8043. }
  8044. else
  8045. {
  8046. Config.LastHideShow = Config.Show;
  8047. Config.Show = qvShow;
  8048. }
  8049. break;
  8050. case qvHide:
  8051. Config.LastHideShow = Config.Show;
  8052. Config.Show = qvShow;
  8053. break;
  8054. }
  8055. WinConfiguration->QueueView = Config;
  8056. }
  8057. //---------------------------------------------------------------------------
  8058. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8059. {
  8060. UnicodeString Result;
  8061. if (FTerminal != NULL)
  8062. {
  8063. switch (WinConfiguration->PathInCaption)
  8064. {
  8065. case picShort:
  8066. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8067. break;
  8068. case picFull:
  8069. Result = FTerminal->CurrentDirectory;
  8070. break;
  8071. }
  8072. }
  8073. return Result;
  8074. }
  8075. //---------------------------------------------------------------------------
  8076. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8077. {
  8078. TColor Result = GetWindowColor(FSessionColor);
  8079. return Result;
  8080. }
  8081. //---------------------------------------------------------------------------
  8082. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8083. {
  8084. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8085. return Result;
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8089. {
  8090. TTerminalManager::Instance()->UpdateAppTitle();
  8091. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8092. // background to gray on Windows 7 (works on Windows 10).
  8093. // See also EnableControl
  8094. if (Showing)
  8095. {
  8096. if (Terminal != NULL)
  8097. {
  8098. // Update path when it changes
  8099. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8100. {
  8101. UpdateSessionTab(SessionsPageControl->ActivePage);
  8102. }
  8103. }
  8104. NonVisualDataModule->ReconnectSessionAction->Update();
  8105. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8106. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8107. CenterReconnectToolbar();
  8108. bool HasTerminal = HasActiveTerminal();
  8109. if (HasTerminal)
  8110. {
  8111. // TODO needed yet with second local browser?
  8112. if (!RemoteDirView->Enabled)
  8113. {
  8114. RemoteDirView->Enabled = true;
  8115. if (FRemoteDirViewWasFocused)
  8116. {
  8117. ActiveControl = RemoteDirView;
  8118. }
  8119. }
  8120. RemoteDirView->Color = PanelColor();
  8121. }
  8122. else
  8123. {
  8124. if (RemoteDirView->Enabled)
  8125. {
  8126. // This is first called when the form is being constructed
  8127. // (not anymore due to Showing test above)
  8128. // but the false is overriden in the constructor later.
  8129. // An even later in TScpCommanderForm::DoShow()
  8130. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8131. RemoteDirView->Enabled = false;
  8132. }
  8133. RemoteDirView->Color = DisabledPanelColor();
  8134. }
  8135. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8136. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8137. RemoteDriveView->Color = RemoteDirView->Color;
  8138. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8139. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8140. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8141. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8142. QueueFileList->Enabled = QueueView3->Enabled;
  8143. QueueFileList->Color = QueueView3->Color;
  8144. QueueFileList->Font->Color = QueueView3->Font->Color;
  8145. QueueLabelUpdateStatus();
  8146. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8147. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8148. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8149. {
  8150. UpdateDarkMode();
  8151. }
  8152. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8153. }
  8154. }
  8155. //---------------------------------------------------------------------------
  8156. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8157. {
  8158. UpdateControls();
  8159. }
  8160. //---------------------------------------------------------------------------
  8161. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8162. TObject * Sender)
  8163. {
  8164. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8165. DebugAssert(DirView != NULL);
  8166. DoDirViewLoaded(DirView);
  8167. TransferPresetAutoSelect();
  8168. }
  8169. //---------------------------------------------------------------------------
  8170. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8171. {
  8172. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8173. // first run after installation
  8174. if (double(Updates.LastCheck) == 0)
  8175. {
  8176. // make sure next time there will be an update (if enabled)
  8177. Updates.LastCheck = TDateTime(1);
  8178. WinConfiguration->Updates = Updates;
  8179. }
  8180. else if ((double(Updates.Period) > 0) &&
  8181. (Now() - Updates.LastCheck >= Updates.Period))
  8182. {
  8183. TThreadMethod OnUpdatesChecked = NULL;
  8184. if (!IsUWP())
  8185. {
  8186. OnUpdatesChecked = UpdatesChecked;
  8187. }
  8188. StartUpdateThread(OnUpdatesChecked);
  8189. }
  8190. }
  8191. //---------------------------------------------------------------------------
  8192. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8193. {
  8194. UnicodeString Message;
  8195. bool New;
  8196. TQueryType Type;
  8197. GetUpdatesMessage(Message, New, Type, false);
  8198. if (!Message.IsEmpty())
  8199. {
  8200. if (New)
  8201. {
  8202. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8203. }
  8204. if (!New && (Type != qtWarning))
  8205. {
  8206. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8207. }
  8208. else
  8209. {
  8210. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8211. }
  8212. if (New)
  8213. {
  8214. Configuration->Usage->Inc(L"UpdateNotifications");
  8215. }
  8216. }
  8217. }
  8218. //---------------------------------------------------------------------------
  8219. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8220. {
  8221. RestoreApp();
  8222. bool CanDisplay = !NonVisualDataModule->Busy;
  8223. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8224. {
  8225. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8226. }
  8227. if (CanDisplay)
  8228. {
  8229. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8230. CheckForUpdates(true);
  8231. }
  8232. else
  8233. {
  8234. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8235. }
  8236. }
  8237. //---------------------------------------------------------------------------
  8238. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8239. TCopyParamRuleData & Data)
  8240. {
  8241. DebugAssert(Terminal != NULL);
  8242. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8243. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8244. Data.RemoteDirectory = RemoteDirView->PathName;
  8245. }
  8246. //---------------------------------------------------------------------------
  8247. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8248. {
  8249. // Terminal can be null when we are changing local directory implicitly,
  8250. // because it has been deleted, while no session is connected
  8251. // (Login dialog is open)
  8252. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8253. {
  8254. DebugAssert(!IsLocalBrowserMode());
  8255. TCopyParamRuleData Data;
  8256. GetTransferPresetAutoSelectData(Data);
  8257. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8258. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8259. if (CopyParamIndex < 0)
  8260. {
  8261. // there is no preset that matches autoselection
  8262. // set preset that we consider "default"
  8263. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8264. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8265. }
  8266. else
  8267. {
  8268. // there is preset matching autoselection
  8269. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8270. if (CopyParamName == FCopyParamAutoSelected)
  8271. {
  8272. // autoselected the same preset as the last time
  8273. // make no change (i.e. preserve custom user preset, if any)
  8274. }
  8275. else
  8276. {
  8277. // autoselected the different preset then the last time (or there
  8278. // was default preset set)
  8279. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8280. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8281. }
  8282. }
  8283. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8284. {
  8285. if (CopyParamIndex >= 0)
  8286. {
  8287. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8288. }
  8289. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8290. try
  8291. {
  8292. int Fmt =
  8293. (CopyParamIndex < 0) ?
  8294. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8295. COPY_PARAM_AUTOSELECTED;
  8296. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8297. Data->Message = MainInstructions(Message);
  8298. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8299. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8300. CopyParamAttrs);
  8301. if (CopyParamIndex >= 0)
  8302. {
  8303. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8304. Info = FORMAT(L"%s\n \n%s", (Info,
  8305. FMTLOAD(COPY_PARAM_RULE,
  8306. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8307. }
  8308. Data->Message += L"\n\n" + Info;
  8309. if (WinConfiguration->CopyParamAutoSelectNotice)
  8310. {
  8311. TransferPresetNoteMessage(Data, true);
  8312. }
  8313. else
  8314. {
  8315. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8316. Data = NULL; // ownership passed
  8317. }
  8318. }
  8319. __finally
  8320. {
  8321. delete Data;
  8322. }
  8323. }
  8324. }
  8325. }
  8326. //---------------------------------------------------------------------------
  8327. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8328. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8329. {
  8330. DebugAssert(NoteData != NULL);
  8331. DebugAssert(!IsLocalBrowserMode());
  8332. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8333. TQueryButtonAlias Aliases[1];
  8334. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8335. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8336. Params.Aliases = Aliases;
  8337. Params.AliasesCount = LENOF(Aliases);
  8338. unsigned int Result =
  8339. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8340. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8341. switch (Result)
  8342. {
  8343. case qaNeverAskAgain:
  8344. DebugAssert(AllowNeverAskAgain);
  8345. WinConfiguration->CopyParamAutoSelectNotice = false;
  8346. break;
  8347. case qaIgnore:
  8348. PreferencesDialog(pmPresets);
  8349. break;
  8350. }
  8351. }
  8352. //---------------------------------------------------------------------------
  8353. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8354. {
  8355. // as of now useless, as this is used for notes only, never for balloons, ...
  8356. RestoreApp();
  8357. // .. and we should never be busy here
  8358. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8359. {
  8360. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8361. }
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8365. TPreferencesMode APreferencesMode)
  8366. {
  8367. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8368. TCopyParamRuleData Data;
  8369. if (Terminal != NULL)
  8370. {
  8371. PreferencesData.reset(new TPreferencesDialogData());
  8372. GetTransferPresetAutoSelectData(Data);
  8373. PreferencesData->CopyParamRuleData = &Data;
  8374. }
  8375. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8376. }
  8377. //---------------------------------------------------------------------------
  8378. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8379. const TCustomCommandType & Command)
  8380. {
  8381. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8382. {
  8383. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8384. }
  8385. }
  8386. //---------------------------------------------------------------------------
  8387. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8388. {
  8389. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8390. TCustomCommandType Command;
  8391. // make sure we use local custom command when remote are not supported
  8392. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8393. {
  8394. Command = FLastCustomCommand;
  8395. }
  8396. else
  8397. {
  8398. Command.Params = Command.Params | ccLocal;
  8399. }
  8400. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8401. FEditingFocusedAdHocCommand = OnFocused;
  8402. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8403. int Options =
  8404. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8405. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8406. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8407. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8408. {
  8409. FLastCustomCommand = Command;
  8410. UpdateCustomCommandsToolbar();
  8411. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8412. }
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8416. {
  8417. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8418. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8419. DebugAssert(State > 0);
  8420. if (State <= 0)
  8421. {
  8422. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8423. }
  8424. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8428. TCustomCommandType & Command, int & State)
  8429. {
  8430. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8431. if (Result)
  8432. {
  8433. Command = FLastCustomCommand;
  8434. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8435. }
  8436. return Result;
  8437. }
  8438. //---------------------------------------------------------------------------
  8439. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8440. {
  8441. ResetIncrementalSearch();
  8442. }
  8443. //---------------------------------------------------------------------------
  8444. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8445. {
  8446. DebugAssert(ComponentVisible[Component]);
  8447. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8448. }
  8449. //---------------------------------------------------------------------------
  8450. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8451. {
  8452. // when queue panel is resized here directly, the status bar is stretched
  8453. // over whole space the panel occupied
  8454. PostComponentHide(fcQueueView);
  8455. }
  8456. //---------------------------------------------------------------------------
  8457. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8458. {
  8459. ComponentVisible[fcQueueFileList] = false;
  8460. }
  8461. //---------------------------------------------------------------------------
  8462. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8463. {
  8464. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8465. RefreshColorMode();
  8466. ResetSysDarkTheme();
  8467. ConfigurationChanged();
  8468. ConfigureInterface();
  8469. // Should be called for all controls
  8470. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8471. }
  8472. //---------------------------------------------------------------------------
  8473. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8474. {
  8475. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8476. if (!FInvalid &&
  8477. (Message.LParam != 0) &&
  8478. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8479. {
  8480. ThemeChanged();
  8481. }
  8482. TForm::Dispatch(&Message);
  8483. }
  8484. //---------------------------------------------------------------------------
  8485. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8486. {
  8487. TMessage * M = static_cast<TMessage*>(Message);
  8488. switch (M->Msg)
  8489. {
  8490. case CM_DIALOGCHAR:
  8491. CMDialogChar(*M);
  8492. break;
  8493. case WM_APPCOMMAND:
  8494. WMAppCommand(*M);
  8495. break;
  8496. case WM_SYSCOMMAND:
  8497. WMSysCommand(*M);
  8498. break;
  8499. case WM_QUERYENDSESSION:
  8500. WMQueryEndSession(*M);
  8501. break;
  8502. case WM_ENDSESSION:
  8503. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8504. break;
  8505. #ifdef _DEBUG
  8506. case WM_WINDOWPOSCHANGED:
  8507. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8508. break;
  8509. case CM_CUSTOMSTYLECHANGED:
  8510. TForm::Dispatch(Message);
  8511. break;
  8512. #endif
  8513. case WM_COMPONENT_HIDE:
  8514. {
  8515. Byte Component = static_cast<Byte>(M->WParam);
  8516. // sanity check
  8517. if (ComponentVisible[Component])
  8518. {
  8519. // special treatment
  8520. if (Component == fcQueueView)
  8521. {
  8522. ToggleQueueVisibility();
  8523. DebugAssert(!ComponentVisible[fcQueueView]);
  8524. }
  8525. else
  8526. {
  8527. ComponentVisible[Component] = false;
  8528. }
  8529. }
  8530. }
  8531. break;
  8532. case WM_COPYDATA:
  8533. WMCopyData(*M);
  8534. break;
  8535. case WM_MANAGES_CAPTION:
  8536. // caption managed in TTerminalManager::UpdateAppTitle()
  8537. M->Result = 1;
  8538. break;
  8539. case WM_WANTS_MOUSEWHEEL:
  8540. M->Result = 1;
  8541. break;
  8542. case CM_SHOWINGCHANGED:
  8543. CMShowingChanged(*M);
  8544. break;
  8545. case WM_CLOSE:
  8546. WMClose(*M);
  8547. break;
  8548. case WM_DPICHANGED:
  8549. WMDpiChanged(*M);
  8550. break;
  8551. case CM_DPICHANGED:
  8552. CMDpiChanged(*M);
  8553. break;
  8554. case WM_SETTINGCHANGE:
  8555. WMSettingChange(*M);
  8556. break;
  8557. case CM_DIALOGKEY:
  8558. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8559. break;
  8560. default:
  8561. TForm::Dispatch(Message);
  8562. break;
  8563. }
  8564. }
  8565. //---------------------------------------------------------------------------
  8566. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8567. {
  8568. // noop
  8569. }
  8570. //---------------------------------------------------------------------------
  8571. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8572. {
  8573. TForm::Dispatch(&Message);
  8574. FSessionColors->Clear();
  8575. AddFixedSessionImages();
  8576. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8577. UpdateImages();
  8578. }
  8579. //---------------------------------------------------------------------------
  8580. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8581. {
  8582. TForm::Dispatch(&Message);
  8583. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8584. UpdatePixelsPerInchMainWindowCounter();
  8585. }
  8586. //---------------------------------------------------------------------------
  8587. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8588. {
  8589. // Cannot close window while we are busy.
  8590. // We cannot test this in FormCloseQuery as that is called also from
  8591. // Close(), which is called by CloseApplicationAction. So we can be busy
  8592. // there already even, when it is legitimate to close the application.
  8593. // Possibly a better place to handle this would be WMSysCommand.
  8594. if (NonVisualDataModule->Busy)
  8595. {
  8596. Message.Result = 1;
  8597. }
  8598. else
  8599. {
  8600. TForm::Dispatch(&Message);
  8601. }
  8602. }
  8603. //---------------------------------------------------------------------------
  8604. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8605. {
  8606. TForm::Dispatch(&Message);
  8607. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8608. if (Showing && !FStarted)
  8609. {
  8610. FStarted = true;
  8611. InterfaceStarted();
  8612. }
  8613. if (Showing && (Terminal == NULL))
  8614. {
  8615. // When we are starting minimized (i.e. from an installer),
  8616. // postpone showing Login dialog until we get restored.
  8617. // Otherwise the Login dialog (and Authentication window) show restored
  8618. // over invisible (minimized) main window.
  8619. if (WindowState == wsMinimized)
  8620. {
  8621. FNeedSession = true;
  8622. }
  8623. else
  8624. {
  8625. // This happens before application ever goes idle, so the toolbars would
  8626. // stay enabled (initial state) until the Login dialog is dismissed.
  8627. UpdateActions();
  8628. NonVisualDataModule->StartBusy();
  8629. try
  8630. {
  8631. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8632. // otherwise the dialog does not receive focus.
  8633. // With Commander interface the ProcessMessages is called already
  8634. // by TDriveView, but with Explorer interface, we need to call it explicily
  8635. Application->ProcessMessages();
  8636. // do not reload sessions, they have been loaded just now (optimization)
  8637. NeedSession(true);
  8638. }
  8639. __finally
  8640. {
  8641. NonVisualDataModule->EndBusy();
  8642. }
  8643. }
  8644. }
  8645. }
  8646. //---------------------------------------------------------------------------
  8647. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8648. {
  8649. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8650. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8651. }
  8652. //---------------------------------------------------------------------------
  8653. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8654. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8655. int & MaxHeight)
  8656. {
  8657. // workaround for bug in TWinControl.CalcConstraints
  8658. // Check for empty rect (restore from iconic state) is done there only after
  8659. // call to AdjustClientRect, which enlarges the rect (for forms).
  8660. TRect R = GetClientRect();
  8661. // when restoring from iconic state, place no restrictions
  8662. if (IsRectEmpty(R))
  8663. {
  8664. MinWidth = 0;
  8665. MinHeight = 0;
  8666. MaxWidth = 32000;
  8667. MaxHeight = 32000;
  8668. }
  8669. }
  8670. //---------------------------------------------------------------------------
  8671. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8672. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8673. {
  8674. // terminal can be already closed (e.g. dropped connection)
  8675. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8676. {
  8677. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8678. try
  8679. {
  8680. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8681. }
  8682. catch(...)
  8683. {
  8684. if (!Terminal->Active)
  8685. {
  8686. Close = true;
  8687. }
  8688. throw;
  8689. }
  8690. }
  8691. }
  8692. //---------------------------------------------------------------------------
  8693. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8694. {
  8695. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8696. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8697. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8698. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8699. {
  8700. OnGetSpaceAvailable = GetSpaceAvailable;
  8701. }
  8702. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8703. OnGetSpaceAvailable);
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8707. {
  8708. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8709. Terminal->FillSessionDataForCode(Data.get());
  8710. return Data.release();
  8711. }
  8712. //---------------------------------------------------------------------------
  8713. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8714. {
  8715. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8716. DoGenerateUrlDialog(Data.get(), Paths);
  8717. }
  8718. //---------------------------------------------------------------------------
  8719. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8720. {
  8721. GenerateUrl(NULL);
  8722. }
  8723. //---------------------------------------------------------------------------
  8724. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8725. {
  8726. std::unique_ptr<TStrings> Paths(new TStringList());
  8727. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8728. GenerateUrl(Paths.get());
  8729. }
  8730. //---------------------------------------------------------------------------
  8731. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8732. {
  8733. FSessionColor = value;
  8734. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8735. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8736. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8737. DebugAssert(ColorItem != NULL);
  8738. ColorItem->Color = C;
  8739. NonVisualDataModule->ColorMenuItem->Color = C;
  8740. UpdateControls();
  8741. }
  8742. //---------------------------------------------------------------------------
  8743. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8744. {
  8745. if (value != FSessionColor)
  8746. {
  8747. UpdateSessionColor(value);
  8748. // Is null when called from LastTerminalClosed
  8749. if (Terminal != NULL)
  8750. {
  8751. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8752. }
  8753. }
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8757. {
  8758. bool Result = FNoteTimer->Enabled;
  8759. if (Result)
  8760. {
  8761. // cannot cancel note too early
  8762. bool NotEarly =
  8763. (Now() - FNoteShown >
  8764. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8765. if (Force || NotEarly)
  8766. {
  8767. FNoteTimer->Enabled = false;
  8768. FNote = L"";
  8769. SAFE_DESTROY(FNoteData);
  8770. FOnNoteClick = NULL;
  8771. FNoteHints = FNotes->Text;
  8772. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8773. UpdateStatusBar();
  8774. }
  8775. }
  8776. return Result;
  8777. }
  8778. //---------------------------------------------------------------------------
  8779. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8780. {
  8781. DebugAssert(FNoteTimer->Enabled);
  8782. CancelNote(true);
  8783. }
  8784. //---------------------------------------------------------------------------
  8785. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8786. {
  8787. FNoteHints = FNotes->Text.TrimRight();
  8788. }
  8789. //---------------------------------------------------------------------------
  8790. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8791. {
  8792. int P = Note.Pos(L"\n");
  8793. if (P > 0)
  8794. {
  8795. Note.SetLength(P - 1);
  8796. }
  8797. FNotes->Add(FORMAT(L"[%s] %s",
  8798. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8799. while (FNotes->Count > 10)
  8800. {
  8801. FNotes->Delete(0);
  8802. }
  8803. if (UpdateNow)
  8804. {
  8805. UpdateNoteHints();
  8806. UpdateStatusBar();
  8807. }
  8808. }
  8809. //---------------------------------------------------------------------------
  8810. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8811. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8812. {
  8813. int P = Note.Pos(L"\n");
  8814. if (P > 0)
  8815. {
  8816. Note.SetLength(P - 1);
  8817. }
  8818. UpdateNoteHints();
  8819. FNote = Note;
  8820. SAFE_DESTROY(FNoteData);
  8821. FNoteData = NoteData;
  8822. FOnNoteClick = OnNoteClick;
  8823. AddNote(Note, false);
  8824. UpdateStatusBar();
  8825. FNoteShown = Now();
  8826. FNoteTimer->Enabled = false;
  8827. if (Seconds == 0)
  8828. {
  8829. Seconds = WinConfiguration->NotificationsTimeout;
  8830. }
  8831. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8832. FNoteTimer->Enabled = true;
  8833. }
  8834. //---------------------------------------------------------------------------
  8835. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8836. {
  8837. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8838. }
  8839. //---------------------------------------------------------------------------
  8840. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8841. {
  8842. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8843. {
  8844. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8845. }
  8846. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8847. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8848. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8849. 0, NULL, NULL);
  8850. }
  8851. //---------------------------------------------------------------------------
  8852. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8853. {
  8854. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8855. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8856. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8857. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8858. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8859. }
  8860. //---------------------------------------------------------------------------
  8861. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8862. {
  8863. WinConfiguration->FormatSizeBytes = Style;
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8867. {
  8868. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8869. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8870. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8871. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8872. }
  8873. //---------------------------------------------------------------------------
  8874. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8875. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8876. {
  8877. if (Panel->Index == 0)
  8878. {
  8879. if (FOnNoteClick != NULL)
  8880. {
  8881. // prevent the user data from being freed by possible call
  8882. // to CancelNote or PostNote during call to OnNoteClick
  8883. std::unique_ptr<TObject> NoteData(FNoteData);
  8884. TNotifyEvent OnNoteClick = FOnNoteClick;
  8885. FNoteData = NULL;
  8886. // need to cancel the note as we are going to delete its user data
  8887. CancelNote(true);
  8888. OnNoteClick(NoteData.get());
  8889. }
  8890. }
  8891. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8892. {
  8893. FileSystemInfo();
  8894. }
  8895. }
  8896. //---------------------------------------------------------------------------
  8897. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8898. {
  8899. // workaround:
  8900. // 1) for unknown reason, disabling window, while minimized,
  8901. // prevents it from restoring, even if it was enabled again meanwhile
  8902. // 2) when disabling the main window, while another has focus
  8903. // minimize is no longer possible
  8904. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8905. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8906. // Shouldn't we use IsApplicationMinimized() here?
  8907. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8908. {
  8909. Enabled = false;
  8910. }
  8911. FLockLevel++;
  8912. }
  8913. //---------------------------------------------------------------------------
  8914. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8915. {
  8916. DebugAssert(FLockLevel > 0);
  8917. FLockLevel--;
  8918. if (FLockLevel == 0)
  8919. {
  8920. DebugAssert(FLockSuspendLevel == 0);
  8921. Enabled = true;
  8922. }
  8923. }
  8924. //---------------------------------------------------------------------------
  8925. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8926. {
  8927. // We need to make sure that window is enabled when the last modal window closes
  8928. // otherwise focus is not restored correctly.
  8929. // So we re-enable the window when modal window opens and
  8930. // disable it back after is closes
  8931. if (FLockLevel > 0)
  8932. {
  8933. // while we have nesting counter, we know that we never be called
  8934. // recursivelly as Application->OnModalBegin is called only
  8935. // for the top-level modal window
  8936. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8937. {
  8938. // won't be disabled when conditions in LockWindow() were not satisfied
  8939. FDisabledOnLockSuspend = !Enabled;
  8940. // When minimized to tray (or actually when set to SW_HIDE),
  8941. // setting Enabled makes the window focusable even when there's
  8942. // modal window over it
  8943. if (!FTrayIcon->Visible)
  8944. {
  8945. Enabled = true;
  8946. }
  8947. }
  8948. FLockSuspendLevel++;
  8949. }
  8950. }
  8951. //---------------------------------------------------------------------------
  8952. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8953. {
  8954. if (FLockSuspendLevel > 0)
  8955. {
  8956. DebugAssert(FLockLevel > 0);
  8957. FLockSuspendLevel--;
  8958. // see comment in SuspendWindowLock
  8959. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8960. {
  8961. // Note that window can be enabled here, when we were minized to tray when
  8962. // was SuspendWindowLock() called.
  8963. // We should possibly do the same check as in LockWindow(),
  8964. // if it is ever possible that the consitions change between
  8965. // SuspendWindowLock() and ResumeWindowLock()
  8966. Enabled = !FDisabledOnLockSuspend;
  8967. }
  8968. }
  8969. }
  8970. //---------------------------------------------------------------------------
  8971. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8972. {
  8973. TTBXComboBoxItem * RemotePathComboBox =
  8974. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8975. if (!TextOnly)
  8976. {
  8977. TStrings * Items = RemotePathComboBox->Strings;
  8978. Items->BeginUpdate();
  8979. try
  8980. {
  8981. Items->Clear();
  8982. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8983. {
  8984. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8985. while (!IsUnixRootPath(APath))
  8986. {
  8987. int P = APath.LastDelimiter(L'/');
  8988. DebugAssert(P >= 0);
  8989. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8990. APath.SetLength(P - 1);
  8991. }
  8992. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8993. }
  8994. }
  8995. __finally
  8996. {
  8997. Items->EndUpdate();
  8998. }
  8999. }
  9000. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9001. // Setting ItemIndex to -1 does not reset its text
  9002. if (RemotePathComboBox->Strings->Count == 0)
  9003. {
  9004. RemotePathComboBox->Text = L"";
  9005. }
  9006. }
  9007. //---------------------------------------------------------------------------
  9008. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9009. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9010. int & ImageIndex)
  9011. {
  9012. if (AIndex < 0)
  9013. {
  9014. AIndex = Sender->ItemIndex;
  9015. }
  9016. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9017. }
  9018. //---------------------------------------------------------------------------
  9019. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9020. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9021. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9022. {
  9023. ARect.Left += (10 * AIndex);
  9024. }
  9025. //---------------------------------------------------------------------------
  9026. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9027. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9028. {
  9029. AWidth += (10 * AIndex);
  9030. }
  9031. //---------------------------------------------------------------------------
  9032. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9033. TObject * Sender)
  9034. {
  9035. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9036. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9037. int Index = RemotePathComboBox->ItemIndex;
  9038. while (Index < RemotePathComboBox->Strings->Count - 1)
  9039. {
  9040. APath = UnixExtractFileDir(APath);
  9041. Index++;
  9042. }
  9043. // VanDyke style paths
  9044. if (APath.IsEmpty())
  9045. {
  9046. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9047. APath = ROOTDIRECTORY;
  9048. }
  9049. if (RemoteDirView->Path != APath)
  9050. {
  9051. RemoteDirView->Path = APath;
  9052. }
  9053. }
  9054. //---------------------------------------------------------------------------
  9055. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9056. {
  9057. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9058. DebugUsedParam(Sender);
  9059. UpdateRemotePathComboBox(true);
  9060. }
  9061. //---------------------------------------------------------------------------
  9062. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9063. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9064. {
  9065. ResetIncrementalSearch();
  9066. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9067. DebugAssert(DirView != NULL);
  9068. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9069. {
  9070. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9071. // OnEditing is called also from TCustomListView::CanEdit
  9072. if (Edit != NULL)
  9073. {
  9074. EditSelectBaseName(Edit);
  9075. }
  9076. }
  9077. }
  9078. //---------------------------------------------------------------------------
  9079. //---------------------------------------------------------------------------
  9080. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9081. {
  9082. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9083. Result->AutoDetectDnD = false;
  9084. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9085. Result->RenderDataOn = rdoEnterAndDropSync;
  9086. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9087. return Result;
  9088. }
  9089. //---------------------------------------------------------------------------
  9090. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9091. {
  9092. if (IsWin10Build(2004))
  9093. {
  9094. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9095. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9096. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9097. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9098. }
  9099. }
  9100. //---------------------------------------------------------------------------
  9101. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9102. {
  9103. TForm::CreateWnd();
  9104. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9105. UpdateDarkMode();
  9106. if (FSessionsDragDropFilesEx == NULL)
  9107. {
  9108. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9109. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9110. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9111. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9112. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9113. }
  9114. if (FQueueDragDropFilesEx == NULL)
  9115. {
  9116. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9117. // No need to set OnDragOver as we do not have any restrictions
  9118. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9119. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9120. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9121. }
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9125. {
  9126. TForm::DestroyWnd();
  9127. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9128. FQueueDragDropFilesEx->DragDropControl = NULL;
  9129. }
  9130. //---------------------------------------------------------------------------
  9131. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9132. {
  9133. SideEnter(FCurrentSide);
  9134. FEverShown = true;
  9135. }
  9136. //---------------------------------------------------------------------------
  9137. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9138. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9139. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9140. {
  9141. if (!NonVisualDataModule->Busy)
  9142. {
  9143. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9144. Configuration->Usage->Inc(L"FileFinds");
  9145. LockWindow(true);
  9146. NonVisualDataModule->StartBusy();
  9147. WinConfiguration->LockedInterface = true;
  9148. try
  9149. {
  9150. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9151. }
  9152. __finally
  9153. {
  9154. WinConfiguration->LockedInterface = false;
  9155. NonVisualDataModule->EndBusy();
  9156. UnlockWindow();
  9157. }
  9158. }
  9159. }
  9160. //---------------------------------------------------------------------------
  9161. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9162. {
  9163. if (!NonVisualDataModule->Busy)
  9164. {
  9165. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9166. SetFocus();
  9167. RemoteDirView->Path = UnixExtractFilePath(Path);
  9168. UnicodeString FileName = UnixExtractFileName(Path);
  9169. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9170. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9171. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9172. if (Item == NULL)
  9173. {
  9174. ReloadDirectory(osRemote);
  9175. Item = RemoteDirView->FindFileItem(FileName);
  9176. }
  9177. if (Item != NULL)
  9178. {
  9179. RemoteDirView->ItemFocused = Item;
  9180. RemoteDirView->ItemFocused->MakeVisible(false);
  9181. RemoteDirView->SetFocus();
  9182. }
  9183. }
  9184. }
  9185. //---------------------------------------------------------------------------
  9186. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9187. {
  9188. bool Result = !NonVisualDataModule->Busy;
  9189. if (Result)
  9190. {
  9191. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9192. }
  9193. return Result;
  9194. }
  9195. //---------------------------------------------------------------------------
  9196. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9197. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9198. {
  9199. if (CanOperateOnFoundFiles(ATerminal))
  9200. {
  9201. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9202. FOnFileOperationFinished = OnFileOperationFinished;
  9203. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9204. }
  9205. }
  9206. //---------------------------------------------------------------------------
  9207. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9208. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9209. {
  9210. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9211. }
  9212. //---------------------------------------------------------------------------
  9213. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9214. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9215. {
  9216. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9217. }
  9218. //---------------------------------------------------------------------------
  9219. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9220. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9221. {
  9222. if (CanOperateOnFoundFiles(ATerminal))
  9223. {
  9224. for (int Index = 0; Index < FileList->Count; Index++)
  9225. {
  9226. UnicodeString FileName = FileList->Strings[Index];
  9227. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9228. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9229. OnFileOperationFinished(FileName, true);
  9230. }
  9231. }
  9232. }
  9233. //---------------------------------------------------------------------------
  9234. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9235. {
  9236. FFileFindTerminal = Terminal;
  9237. ShowFileFindDialog(
  9238. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9239. DoDownloadFoundFiles, DoEditFoundFiles);
  9240. }
  9241. //---------------------------------------------------------------------------
  9242. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9243. {
  9244. FTaskbarList = TaskbarList;
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9248. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9249. {
  9250. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9251. if (Index >= 0)
  9252. {
  9253. if (Button == mbLeft)
  9254. {
  9255. // "Mouse down" is raised only after tab is switched.
  9256. // If switching tab (switching session) takes long enough for user
  9257. // to actually release the button, "mouse down" is still raised,
  9258. // but we do not get "mouse up" event, so dragging is not cancelled,
  9259. // prevent that by not beginning dragging in the first place.
  9260. if (IsKeyPressed(VK_LBUTTON))
  9261. {
  9262. // when user clicks the "+", we get mouse down only after the session
  9263. // is closed, when new session tab is already on X:Y, so dragging
  9264. // starts, prevent that
  9265. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9266. {
  9267. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9268. if (Terminal != NULL)
  9269. {
  9270. SessionsPageControl->BeginDrag(false);
  9271. }
  9272. }
  9273. }
  9274. }
  9275. else if (Button == mbMiddle)
  9276. {
  9277. // ignore middle-click for "New session tab"
  9278. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9279. if (Terminal != NULL)
  9280. {
  9281. CloseSessionTab(Index);
  9282. }
  9283. }
  9284. }
  9285. }
  9286. //---------------------------------------------------------------------------
  9287. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9288. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9289. {
  9290. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9291. // do not allow dropping on the "+" tab
  9292. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9293. if ((TargetTerminal != NULL) &&
  9294. (SessionsPageControl->ActivePage->PageIndex != Index))
  9295. {
  9296. Configuration->Usage->Inc(L"SessionTabMoves");
  9297. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9298. // but we want to actually prevent that to avoid flicker
  9299. SessionsPageControl->ActivePage->PageIndex = Index;
  9300. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9301. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9302. }
  9303. }
  9304. //---------------------------------------------------------------------------
  9305. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9306. TObject * Sender, TObject * Source, int X, int Y,
  9307. TDragState /*State*/, bool & Accept)
  9308. {
  9309. Accept = (Sender == Source);
  9310. if (Accept)
  9311. {
  9312. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9313. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9314. // do not allow dragging to the "+" tab
  9315. Accept = (Terminal != NULL);
  9316. }
  9317. }
  9318. //---------------------------------------------------------------------------
  9319. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9320. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9321. {
  9322. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9323. if (Index < 0)
  9324. {
  9325. Effect = DROPEFFECT_NONE;
  9326. }
  9327. else
  9328. {
  9329. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9330. // do not allow dropping on the "+" tab
  9331. if (TargetTerminal == NULL)
  9332. {
  9333. Effect = DROPEFFECT_NONE;
  9334. }
  9335. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9336. {
  9337. Effect = DROPEFFECT_COPY;
  9338. }
  9339. }
  9340. }
  9341. //---------------------------------------------------------------------------
  9342. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9343. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9344. {
  9345. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9346. // do not allow dropping on the "+" tab
  9347. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9348. if (TargetTerminal != NULL)
  9349. {
  9350. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9351. if (!IsFileControl(DropSourceControl, osRemote))
  9352. {
  9353. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9354. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9355. // Why don't we use Terminal->CurrentDirectory directly?
  9356. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9357. // do not force queue, drag drop
  9358. false, true);
  9359. }
  9360. }
  9361. }
  9362. //---------------------------------------------------------------------------
  9363. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9364. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9365. {
  9366. // Downloads are handled in RemoteFileControlDDEnd
  9367. if (!IsFileControl(DropSourceControl, osRemote))
  9368. {
  9369. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9370. Terminal->CurrentDirectory,
  9371. // force queue, drag drop
  9372. true, true);
  9373. }
  9374. }
  9375. //---------------------------------------------------------------------------
  9376. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9377. {
  9378. FShowing = false;
  9379. // Do not save empty workspace
  9380. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9381. {
  9382. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9383. UnicodeString Name = WorkspaceName();
  9384. DoSaveWorkspace(
  9385. Name, DataList.get(),
  9386. !Configuration->DisablePasswordStoring &&
  9387. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9388. WinConfiguration->LastStoredSession = Name;
  9389. }
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9393. {
  9394. TManagedTerminal * ManagedTerminal =
  9395. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9396. if (ManagedTerminal != NULL)
  9397. {
  9398. ManagedTerminal->DirectoryLoaded = Now();
  9399. }
  9400. }
  9401. //---------------------------------------------------------------------------
  9402. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9403. TListItem * /*Item*/, bool /*Selected*/)
  9404. {
  9405. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9406. switch (DirView->LastSelectMethod)
  9407. {
  9408. case smKeyboard:
  9409. Configuration->Usage->Inc(L"KeyboardSelections");
  9410. break;
  9411. case smMouse:
  9412. Configuration->Usage->Inc(L"MouseSelections");
  9413. break;
  9414. }
  9415. }
  9416. //---------------------------------------------------------------------------
  9417. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9418. {
  9419. if (Color != 0)
  9420. {
  9421. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9422. }
  9423. else
  9424. {
  9425. return FSessionTabImageIndex;
  9426. }
  9427. }
  9428. //---------------------------------------------------------------------------
  9429. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9430. {
  9431. TPngImageCollectionItem * Item =
  9432. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9433. FSessionColors->AddPng(Item->PngImage);
  9434. return FSessionColors->Count - 1;
  9435. }
  9436. //---------------------------------------------------------------------------
  9437. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9438. {
  9439. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9440. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9441. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9442. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9443. }
  9444. //---------------------------------------------------------------------------
  9445. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9446. {
  9447. for (int Index = 0; Index < Control->ControlCount; Index++)
  9448. {
  9449. TControl * AControl = Control->Controls[Index];
  9450. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9451. if (WinControl != NULL)
  9452. {
  9453. CollectItemsWithTextDisplayMode(WinControl);
  9454. }
  9455. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9456. if (Toolbar != NULL)
  9457. {
  9458. // we care for top-level items only
  9459. TTBCustomItem * Items = Toolbar->Items;
  9460. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9461. {
  9462. TTBCustomItem * Item = Items->Items[ItemIndex];
  9463. if (((Item->DisplayMode == nbdmImageAndText) ||
  9464. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9465. EligibleForImageDisplayMode(Item))
  9466. {
  9467. FItemsWithTextDisplayMode.insert(Item);
  9468. }
  9469. }
  9470. }
  9471. }
  9472. }
  9473. //---------------------------------------------------------------------------
  9474. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9475. {
  9476. return true;
  9477. }
  9478. //---------------------------------------------------------------------------
  9479. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9480. {
  9481. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9482. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9483. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9484. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9485. bool Result = true;
  9486. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9487. {
  9488. TTBCustomItem * Item = *i;
  9489. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9490. if (Label != NULL)
  9491. {
  9492. // optimization
  9493. if (Label->Visible == SelectiveToolbarText)
  9494. {
  9495. Result = false;
  9496. }
  9497. else
  9498. {
  9499. Label->Visible = SelectiveToolbarText;
  9500. }
  9501. }
  9502. else
  9503. {
  9504. // optimization
  9505. if (Item->DisplayMode == DisplayMode)
  9506. {
  9507. Result = false;
  9508. }
  9509. else
  9510. {
  9511. Item->DisplayMode = DisplayMode;
  9512. }
  9513. }
  9514. ++i;
  9515. }
  9516. if (Result)
  9517. {
  9518. UpdateNewSessionTab();
  9519. }
  9520. return Result;
  9521. }
  9522. //---------------------------------------------------------------------------
  9523. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9524. {
  9525. DebugFail();
  9526. }
  9527. //---------------------------------------------------------------------------
  9528. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9529. {
  9530. // Among other, a lock level is non zero, while directory is being loaded,
  9531. // even when it happens as a result of dirview navigation,
  9532. // i.e. when TNonVisualDataModule is NOT FBusy.
  9533. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9534. // Among other this prevents a panel auto update to occur while
  9535. // directory is changing.
  9536. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9537. }
  9538. //---------------------------------------------------------------------------
  9539. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9540. {
  9541. // While the window is disabled, we still seem to process menu shortcuts at least,
  9542. // so stop it at least here.
  9543. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9544. return
  9545. (Allowed == aaUpdate) ||
  9546. !NonVisualDataModule->Busy;
  9547. }
  9548. //---------------------------------------------------------------------------
  9549. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9550. {
  9551. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9552. }
  9553. //---------------------------------------------------------------------------
  9554. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9555. {
  9556. // This is somewhat redundant to LockWindow() call from
  9557. // TTerminalManager::TerminalReadDirectoryProgress.
  9558. // But disabling window is known not to block keyboard shorcuts
  9559. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9560. if (Busy > 0)
  9561. {
  9562. if (NonVisualDataModule->Busy)
  9563. {
  9564. State = false;
  9565. }
  9566. else
  9567. {
  9568. NonVisualDataModule->StartBusy();
  9569. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9570. LockWindow();
  9571. }
  9572. }
  9573. else if (Busy < 0)
  9574. {
  9575. UnlockWindow();
  9576. NonVisualDataModule->EndBusy();
  9577. }
  9578. else
  9579. {
  9580. State = NonVisualDataModule->Busy;
  9581. }
  9582. }
  9583. //---------------------------------------------------------------------------
  9584. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9585. {
  9586. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9587. // no context menu for "New session tab"
  9588. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9589. {
  9590. SessionsPageControl->ActivePageIndex = Index;
  9591. if (DebugAlwaysTrue(SessionTabSwitched()))
  9592. {
  9593. // copied from TControl.WMContextMenu
  9594. SendCancelMode(SessionsPageControl);
  9595. // explicit popup instead of using PopupMenu property
  9596. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9597. // while connecting yet not-connected session and hence
  9598. // allowing an access to commands over not-completelly connected session
  9599. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9600. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9601. PopupMenu->PopupComponent = SessionsPageControl;
  9602. PopupMenu->Popup(Point.x, Point.y);
  9603. }
  9604. }
  9605. Handled = true;
  9606. }
  9607. //---------------------------------------------------------------------------
  9608. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9609. {
  9610. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9611. }
  9612. //---------------------------------------------------------------------------
  9613. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9614. {
  9615. Configuration->Usage->Inc(L"PasswordChanges");
  9616. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9617. ChangePasswordData->DisableAuthentationsExceptPassword();
  9618. ChangePasswordData->ChangePassword = true;
  9619. std::unique_ptr<TTerminal> ChangePasswordSession(
  9620. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9621. ChangePasswordSession->AutoReadDirectory = false;
  9622. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9623. {
  9624. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9625. }
  9626. else
  9627. {
  9628. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9629. }
  9630. }
  9631. //---------------------------------------------------------------------------
  9632. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9633. {
  9634. // No nice way to assert SSH2
  9635. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9636. }
  9637. //---------------------------------------------------------------------------
  9638. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9639. {
  9640. TOperationVisualizer OperationVisualizer;
  9641. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9642. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9643. }
  9644. //---------------------------------------------------------------------------
  9645. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9646. {
  9647. TForm::ChangeScale(M, D);
  9648. int APixelsPerInch = GetControlPixelsPerInch(this);
  9649. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9650. try
  9651. {
  9652. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9653. }
  9654. __finally
  9655. {
  9656. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9657. }
  9658. }
  9659. //---------------------------------------------------------------------------
  9660. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9661. {
  9662. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9663. }
  9664. //---------------------------------------------------------------------
  9665. class TPublicControl : public TControl
  9666. {
  9667. friend class TCustomScpExplorerForm;
  9668. };
  9669. //---------------------------------------------------------------------------
  9670. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9671. {
  9672. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9673. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9674. }
  9675. //---------------------------------------------------------------------------
  9676. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9677. {
  9678. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9679. OpenBookmark(Side, Bookmark);
  9680. }
  9681. //---------------------------------------------------------------------------
  9682. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9683. {
  9684. DoBookmarkClick(osLocal, Sender);
  9685. }
  9686. //---------------------------------------------------------------------------
  9687. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9688. {
  9689. DoBookmarkClick(osRemote, Sender);
  9690. }
  9691. //---------------------------------------------------------------------------
  9692. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9693. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9694. {
  9695. // TODO
  9696. if (BookmarkList != NULL)
  9697. {
  9698. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9699. if (!WinConfiguration->UseLocationProfiles)
  9700. {
  9701. std::unique_ptr<TStringList> Directories(new TStringList());
  9702. Directories->CaseSensitive = (Side == osRemote);
  9703. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9704. {
  9705. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9706. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9707. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9708. {
  9709. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9710. Item->Caption = EscapeHotkey(Directory);
  9711. Item->ShortCut = Bookmark->ShortCut;
  9712. Item->OnClick = OnBookmarkClick;
  9713. Item->Tag = reinterpret_cast<int>(Bookmark);
  9714. Directories->Add(Directory);
  9715. Menu->Add(Item.release());
  9716. }
  9717. }
  9718. }
  9719. else
  9720. {
  9721. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9722. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9723. {
  9724. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9725. if (!Bookmark->Node.IsEmpty())
  9726. {
  9727. Folders->Add(Bookmark->Node);
  9728. }
  9729. }
  9730. for (int Index = 0; Index < Folders->Count; Index++)
  9731. {
  9732. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9733. Item->Caption = Folders->Strings[Index];
  9734. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9735. Folders->Objects[Index] = Item.get();
  9736. Menu->Add(Item.release());
  9737. }
  9738. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9739. {
  9740. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9741. TTBCustomItem * Parent;
  9742. if (!Bookmark->Node.IsEmpty())
  9743. {
  9744. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9745. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9746. }
  9747. else
  9748. {
  9749. Parent = Menu;
  9750. }
  9751. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9752. Item->Caption = Bookmark->Name;
  9753. Item->ShortCut = Bookmark->ShortCut;
  9754. Item->OnClick = OnBookmarkClick;
  9755. Item->Tag = reinterpret_cast<int>(Bookmark);
  9756. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9757. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9758. {
  9759. // No hint for location profiles that are actually mere "bookmarks"
  9760. }
  9761. else
  9762. {
  9763. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9764. UnicodeString LongHint;
  9765. if (!Bookmark->Local.IsEmpty())
  9766. {
  9767. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9768. }
  9769. if (!Bookmark->Remote.IsEmpty())
  9770. {
  9771. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9772. }
  9773. AddToList(Hint, LongHint, L"|");
  9774. Item->Hint = Hint;
  9775. }
  9776. Parent->Add(Item.release());
  9777. }
  9778. }
  9779. AddMenuSeparator(Menu);
  9780. }
  9781. }
  9782. //---------------------------------------------------------------------------
  9783. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9784. {
  9785. Menu->Clear();
  9786. std::unique_ptr<TTBCustomItem> Item;
  9787. Item.reset(new TTBXItem(Owner));
  9788. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9789. Item->Options = Item->Options << tboDefault;
  9790. Menu->Add(Item.release());
  9791. AddMenuSeparator(Menu);
  9792. if (Terminal != NULL)
  9793. {
  9794. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9795. }
  9796. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9797. Item.reset(new TTBXItem(Owner));
  9798. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9799. Menu->Add(Item.release());
  9800. }
  9801. //---------------------------------------------------------------------------
  9802. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9803. {
  9804. bool Result = true;
  9805. try
  9806. {
  9807. if (Side == osRemote)
  9808. {
  9809. Terminal->ExceptionOnFail = true;
  9810. }
  9811. try
  9812. {
  9813. DirView(Side)->Path = Path;
  9814. }
  9815. __finally
  9816. {
  9817. if (Side == osRemote)
  9818. {
  9819. Terminal->ExceptionOnFail = false;
  9820. }
  9821. }
  9822. }
  9823. catch (Exception & E)
  9824. {
  9825. if ((Side != osRemote) || Terminal->Active)
  9826. {
  9827. ShowExtendedExceptionEx(Terminal, &E);
  9828. Result = false;
  9829. }
  9830. else
  9831. {
  9832. throw;
  9833. }
  9834. }
  9835. return Result;
  9836. }
  9837. //---------------------------------------------------------------------------
  9838. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9839. {
  9840. // Make sure there some feedback even when loading tiny local folders
  9841. TInstantOperationVisualizer Visualizer;
  9842. DirView(Side)->ReloadDirectory();
  9843. }
  9844. //---------------------------------------------------------------------------
  9845. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9846. {
  9847. if (Index == SessionsPageControl->TabIndex)
  9848. {
  9849. CloseSession();
  9850. }
  9851. else
  9852. {
  9853. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9854. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9855. TTerminalManager * Manager = TTerminalManager::Instance();
  9856. if (!Terminal->Active)
  9857. {
  9858. Manager->FreeTerminal(Terminal);
  9859. }
  9860. else
  9861. {
  9862. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9863. if (CanCloseQueue(Queue))
  9864. {
  9865. Manager->FreeTerminal(Terminal);
  9866. }
  9867. }
  9868. }
  9869. }
  9870. //---------------------------------------------------------------------------
  9871. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9872. {
  9873. CloseSessionTab(Index);
  9874. }
  9875. //---------------------------------------------------------------------------
  9876. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9877. {
  9878. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9879. {
  9880. TInstantOperationVisualizer Visualizer;
  9881. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9882. // before we create a new data object
  9883. ClipboardClear();
  9884. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9885. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9886. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9887. // Intermediate variable to WORKAROUND a crash in compiler
  9888. TObjectList * ClipboardFakeMonitors =
  9889. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9890. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9891. if (FClipboardDragDropFilesEx.get() == NULL)
  9892. {
  9893. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9894. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9895. }
  9896. FClipboardDragDropFilesEx->FileList->Clear();
  9897. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9898. FClipboardDragDropFilesEx->CopyToClipboard();
  9899. FClipboardTerminal = FTerminal;
  9900. // Need full paths, as cwd can be different once files are pasted
  9901. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9902. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9903. {
  9904. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9905. }
  9906. }
  9907. }
  9908. //---------------------------------------------------------------------------
  9909. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9910. {
  9911. if (OpenClipboard(0))
  9912. {
  9913. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9914. CloseClipboard();
  9915. }
  9916. }
  9917. //---------------------------------------------------------------------------
  9918. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9919. {
  9920. return !FClipboardFakeDirectory.IsEmpty();
  9921. }
  9922. //---------------------------------------------------------------------------
  9923. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9924. {
  9925. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9926. FClipboardFakeDirectory = UnicodeString();
  9927. FClipboardTerminal = NULL;
  9928. // Also called in Idle()
  9929. FClipboardFakeMonitors.reset(NULL);
  9930. }
  9931. //---------------------------------------------------------------------------
  9932. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9933. {
  9934. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9935. {
  9936. ClipboardStop();
  9937. }
  9938. }
  9939. //---------------------------------------------------------------------------
  9940. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9941. {
  9942. TTerminalManager * Manager = TTerminalManager::Instance();
  9943. Manager->ActiveTerminal = FClipboardTerminal;
  9944. TTransferOperationParam Params;
  9945. Params.TargetDirectory = TargetDirectory;
  9946. Params.DragDrop = DragDrop;
  9947. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9948. }
  9949. //---------------------------------------------------------------------------
  9950. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9951. {
  9952. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9953. // (as it pumps a Windows message queue while being shutted down)
  9954. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9955. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9956. {
  9957. // Can fail as it can be e.g. locked by AV, so we retry that later
  9958. bool Removed = RemoveDir(ApiPath(FileName));
  9959. try
  9960. {
  9961. if (!NonVisualDataModule->Busy)
  9962. {
  9963. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9964. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9965. }
  9966. }
  9967. __finally
  9968. {
  9969. if (!Removed)
  9970. {
  9971. RemoveDir(ApiPath(FileName));
  9972. }
  9973. }
  9974. }
  9975. }
  9976. //---------------------------------------------------------------------------
  9977. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9978. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9979. {
  9980. TFileMasks::TParams MaskParams;
  9981. MaskParams.Size = Size;
  9982. MaskParams.Modification = Modification;
  9983. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9984. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9985. {
  9986. bool ImplicitMatch;
  9987. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9988. !ImplicitMatch)
  9989. {
  9990. Color = Iter->Color;
  9991. break;
  9992. }
  9993. }
  9994. }
  9995. //---------------------------------------------------------------------------
  9996. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9997. {
  9998. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9999. if (!DirView->IsEditing())
  10000. {
  10001. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10002. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10003. // while searching
  10004. if (Key == VK_BACK)
  10005. {
  10006. if (!FIncrementalSearch.IsEmpty())
  10007. {
  10008. if (FIncrementalSearch.Length() == 1)
  10009. {
  10010. ResetIncrementalSearch();
  10011. }
  10012. else
  10013. {
  10014. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10015. IncrementalSearch(NewText, false, false);
  10016. }
  10017. Key = 0;
  10018. }
  10019. }
  10020. }
  10021. }
  10022. //---------------------------------------------------------------------------
  10023. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10024. {
  10025. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10026. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10027. {
  10028. // Filter control sequences.
  10029. // When not searching yet, prefer use of the space for toggling file selection
  10030. // (so we cannot incrementally search for a string starting with a space).
  10031. if ((Key > VK_SPACE) ||
  10032. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10033. {
  10034. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10035. Key = 0;
  10036. }
  10037. }
  10038. }
  10039. //---------------------------------------------------------------------------
  10040. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10041. {
  10042. if (!FIncrementalSearch.IsEmpty())
  10043. {
  10044. FIncrementalSearch = L"";
  10045. DirView(osCurrent)->UpdateStatusBar();
  10046. }
  10047. }
  10048. //---------------------------------------------------------------------------
  10049. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10050. {
  10051. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10052. if (Item == NULL)
  10053. {
  10054. MessageBeep(MB_ICONHAND);
  10055. }
  10056. else
  10057. {
  10058. TCustomDirView * ADirView = DirView(osCurrent);
  10059. {
  10060. TAutoNestingCounter Guard(FIncrementalSearching);
  10061. ADirView->FocusItem(Item);
  10062. if (ADirView->NortonLike == nlOff)
  10063. {
  10064. if ((ADirView->Selected != Item) ||
  10065. (ADirView->SelCount > 1))
  10066. {
  10067. ADirView->ClearSelection();
  10068. ADirView->Selected = Item;
  10069. }
  10070. }
  10071. }
  10072. FIncrementalSearch = Text;
  10073. Item->MakeVisible(false);
  10074. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10075. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10076. ADirView->UpdateStatusBar();
  10077. }
  10078. }
  10079. //---------------------------------------------------------------------------
  10080. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10081. {
  10082. int Index = Item->Index;
  10083. if (!Reverse)
  10084. {
  10085. Index++;
  10086. if (Index >= Item->Owner->Count)
  10087. {
  10088. Index = 0;
  10089. }
  10090. }
  10091. else
  10092. {
  10093. Index--;
  10094. if (Index < 0)
  10095. {
  10096. Index = Item->Owner->Count - 1;
  10097. }
  10098. }
  10099. return Item->Owner->Item[Index];
  10100. }
  10101. //---------------------------------------------------------------------------
  10102. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10103. {
  10104. TCustomDirView * ADirView = DirView(osCurrent);
  10105. if (ADirView->Items->Count == 0)
  10106. {
  10107. return NULL;
  10108. }
  10109. else
  10110. {
  10111. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10112. TListItem * Item = CurrentItem;
  10113. if (SkipCurrent)
  10114. {
  10115. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10116. }
  10117. while (true)
  10118. {
  10119. bool Matches = false;
  10120. switch (WinConfiguration->PanelSearch)
  10121. {
  10122. case isNameStartOnly:
  10123. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10124. break;
  10125. case isName:
  10126. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10127. break;
  10128. case isAll:
  10129. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10130. int Index = 0;
  10131. while ((Index < ColCount) && !Matches)
  10132. {
  10133. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10134. if (Visible)
  10135. {
  10136. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10137. }
  10138. Index++;
  10139. }
  10140. break;
  10141. }
  10142. if (Matches)
  10143. {
  10144. return Item;
  10145. }
  10146. Item = GetNextFile(Item, Reverse);
  10147. if (Item == CurrentItem)
  10148. {
  10149. return NULL;
  10150. }
  10151. }
  10152. }
  10153. }
  10154. //---------------------------------------------------------------------------
  10155. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10156. {
  10157. ResetIncrementalSearch();
  10158. }
  10159. //---------------------------------------------------------------------------
  10160. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10161. {
  10162. if (Message.CharCode == VK_TAB)
  10163. {
  10164. if (!FIncrementalSearch.IsEmpty())
  10165. {
  10166. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10167. bool Reverse = Shift.Contains(ssShift);
  10168. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10169. Message.Result = 1;
  10170. return;
  10171. }
  10172. }
  10173. else if (Message.CharCode == VK_ESCAPE)
  10174. {
  10175. if (!FIncrementalSearch.IsEmpty())
  10176. {
  10177. ResetIncrementalSearch();
  10178. Message.Result = 1;
  10179. return;
  10180. }
  10181. }
  10182. TForm::Dispatch(&Message);
  10183. }
  10184. //---------------------------------------------------------------------------
  10185. void __fastcall TCustomScpExplorerForm::Deactivate()
  10186. {
  10187. TForm::Deactivate();
  10188. // E.g. when switching to an internal editor window
  10189. ResetIncrementalSearch();
  10190. }
  10191. //---------------------------------------------------------------------------
  10192. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10193. {
  10194. // When switching to another application
  10195. ResetIncrementalSearch();
  10196. }
  10197. //---------------------------------------------------------------------------
  10198. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10199. {
  10200. ResetIncrementalSearch();
  10201. }
  10202. //---------------------------------------------------------------------------
  10203. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10204. {
  10205. if (FIncrementalSearching <= 0)
  10206. {
  10207. ResetIncrementalSearch();
  10208. }
  10209. }
  10210. //---------------------------------------------------------------------------
  10211. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10212. {
  10213. CountClicksForWindowPrint(this);
  10214. }
  10215. //---------------------------------------------------------------------------
  10216. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10217. {
  10218. CenterReconnectToolbar();
  10219. }
  10220. //---------------------------------------------------------------------------
  10221. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10222. {
  10223. if (RemoteDirView->ItemFocused != NULL)
  10224. {
  10225. RemoteDirView->ItemFocused->Selected = true;
  10226. }
  10227. }
  10228. //---------------------------------------------------------------------------
  10229. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10230. {
  10231. if (!FQueueStatusUpdating)
  10232. {
  10233. bool Refresh;
  10234. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10235. {
  10236. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10237. }
  10238. else
  10239. {
  10240. if (FQueueFileList->GetCount() > 0)
  10241. {
  10242. FQueueFileList->Clear();
  10243. Refresh = true;
  10244. }
  10245. }
  10246. int Count = FQueueFileList->GetCount();
  10247. if (QueueFileList->Items->Count != Count)
  10248. {
  10249. DebugAssert(Refresh);
  10250. QueueFileList->Items->Count = Count;
  10251. }
  10252. if (Refresh)
  10253. {
  10254. QueueFileList->Invalidate();
  10255. }
  10256. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10257. }
  10258. }
  10259. //---------------------------------------------------------------------------
  10260. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10261. {
  10262. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10263. }
  10264. //---------------------------------------------------------------------------
  10265. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10266. {
  10267. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10268. // See TSynchronizeChecklistDialog::UpdateTimer
  10269. if (QueueFileList->Items->Count > 0)
  10270. {
  10271. QueueFileList->Items->Item[0]->MakeVisible(false);
  10272. }
  10273. UpdateQueueFileList();
  10274. }
  10275. //---------------------------------------------------------------------------
  10276. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10277. {
  10278. Active = QueueView3->Focused() || QueueFileList->Focused();
  10279. }
  10280. //---------------------------------------------------------------------------
  10281. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10282. {
  10283. QueueLabelUpdateStatus();
  10284. }
  10285. //---------------------------------------------------------------------------
  10286. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10287. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10288. {
  10289. int State = FQueueFileList->GetState(Item->Index);
  10290. if (State == qfsProcessed)
  10291. {
  10292. Sender->Canvas->Font->Color = clGrayText;
  10293. }
  10294. }
  10295. //---------------------------------------------------------------------------
  10296. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10297. {
  10298. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10299. QueueFileList->Column[0]->Width =
  10300. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10301. }
  10302. //---------------------------------------------------------------------------
  10303. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10304. {
  10305. QueueFileListColumnAutoSize();
  10306. }
  10307. //---------------------------------------------------------------------------
  10308. void __fastcall TCustomScpExplorerForm::CloseApp()
  10309. {
  10310. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10311. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10312. // So we clear the flag here.
  10313. DebugAssert(NonVisualDataModule->Busy);
  10314. NonVisualDataModule->EndBusy();
  10315. try
  10316. {
  10317. Close();
  10318. }
  10319. __finally
  10320. {
  10321. NonVisualDataModule->StartBusy();
  10322. }
  10323. }
  10324. //---------------------------------------------------------------------------
  10325. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10326. {
  10327. return (Terminal != NULL) && Terminal->Active;
  10328. }
  10329. //---------------------------------------------------------------------------
  10330. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10331. {
  10332. return IsActiveTerminal(Terminal);
  10333. }