CustomScpExplorer.cpp 394 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854
  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 <algorithm>
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.h>
  17. #include <Progress.h>
  18. #include <SynchronizeProgress.h>
  19. #include <DragExt.h>
  20. #include <WinApi.h>
  21. #include "GUITools.h"
  22. #include "NonVisual.h"
  23. #include "Glyphs.h"
  24. #include "Tools.h"
  25. #include "WinConfiguration.h"
  26. #include "TerminalManager.h"
  27. #include "EditorManager.h"
  28. #include "ProgParams.h"
  29. #include "Setup.h"
  30. #include <Consts.hpp>
  31. #include <DateUtils.hpp>
  32. #include <TB2Common.hpp>
  33. #include <DirectoryMonitor.hpp>
  34. #include <System.IOUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. static const int SessionPanelCount = 3;
  55. //---------------------------------------------------------------------------
  56. class TMutexGuard
  57. {
  58. public:
  59. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  60. int Timeout = 5000)
  61. {
  62. FMutex = NULL;
  63. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  64. if (WaitResult == WAIT_TIMEOUT)
  65. {
  66. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  67. }
  68. else
  69. {
  70. FMutex = AMutex;
  71. }
  72. }
  73. ~TMutexGuard()
  74. {
  75. if (FMutex != NULL)
  76. {
  77. ReleaseMutex(FMutex);
  78. }
  79. }
  80. private:
  81. HANDLE FMutex;
  82. };
  83. //---------------------------------------------------------------------------
  84. class TWindowLock
  85. {
  86. public:
  87. TWindowLock(TCustomScpExplorerForm * Form) :
  88. FForm(Form)
  89. {
  90. FForm->LockWindow();
  91. }
  92. ~TWindowLock()
  93. {
  94. FForm->UnlockWindow();
  95. }
  96. private:
  97. TCustomScpExplorerForm * FForm;
  98. };
  99. //---------------------------------------------------------------------------
  100. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  101. FForm(Form)
  102. {
  103. FForm->BatchStart(FBatchStorage);
  104. }
  105. //---------------------------------------------------------------------------
  106. TAutoBatch::~TAutoBatch()
  107. {
  108. FForm->BatchEnd(FBatchStorage);
  109. }
  110. //---------------------------------------------------------------------------
  111. struct TTransferOperationParam
  112. {
  113. TTransferOperationParam();
  114. UnicodeString TargetDirectory;
  115. bool Temp;
  116. bool DragDrop;
  117. int Options;
  118. TAutoSwitch Queue;
  119. };
  120. //---------------------------------------------------------------------------
  121. TTransferOperationParam::TTransferOperationParam()
  122. {
  123. Temp = false;
  124. DragDrop = false;
  125. Options = 0;
  126. Queue = asAuto;
  127. }
  128. //---------------------------------------------------------------------------
  129. class TTransferPresetNoteData : public TObject
  130. {
  131. public:
  132. UnicodeString Message;
  133. };
  134. //---------------------------------------------------------------------------
  135. class TTerminalNoteData : public TObject
  136. {
  137. public:
  138. TManagedTerminal * Terminal;
  139. };
  140. //---------------------------------------------------------------------------
  141. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  142. FFormRestored(false),
  143. TForm(Owner)
  144. {
  145. AddStartupSequence(L"F");
  146. FInvalid = false;
  147. FCurrentSide = osRemote;
  148. FEverShown = false;
  149. FDocks = new TList();
  150. InitControls();
  151. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  152. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  153. NonVisualDataModule->ScpExplorer = this;
  154. RestoreParams();
  155. ConfigurationChanged();
  156. RemoteDirView->Invalidate();
  157. FAutoOperation = false;
  158. FOnFileOperationFinished = NULL;
  159. FPrimaryOperation = foNone;
  160. FForceExecution = false;
  161. FIgnoreNextDialogChar = 0;
  162. FErrorList = NULL;
  163. FSynchronizeProgressForm = NULL;
  164. FProgressForm = NULL;
  165. FRefreshLocalDirectory = false;
  166. FRefreshRemoteDirectory = false;
  167. FDDExtMapFile = NULL;
  168. // CreateMutexW keeps failing with ERROR_NOACCESS
  169. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  170. DebugAssert(FDDExtMutex != NULL);
  171. FDDTargetControl = NULL;
  172. FDelayedDeletionTimer = NULL;
  173. FDelayedDeletionList = new TStringList();
  174. FDDFileList = NULL;
  175. FPendingTempSpaceWarn = false;
  176. FCapturedLog = NULL;
  177. FDragDropOperation = false;
  178. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  179. FAllowTransferPresetAutoSelect = true;
  180. FSessionChanging = false;
  181. FCopyParamDefault = L"";
  182. FSynchronizeController = NULL;
  183. FPendingQueueActionItem = NULL;
  184. FLockLevel = 0;
  185. FLockSuspendLevel = 0;
  186. FDisabledOnLockSuspend = false;
  187. FAlternativeDelete = false;
  188. FTrayIcon = new ::TTrayIcon(0);
  189. FTrayIcon->OnClick = TrayIconClick;
  190. FMaxQueueLength = 0;
  191. FLastContextPopupScreenPoint = TPoint(-1, -1);
  192. FTransferResumeList = NULL;
  193. FDeletedFiles = NULL;
  194. FMoveToQueue = false;
  195. StandaloneOperation = false;
  196. FOnFeedSynchronizeError = NULL;
  197. FOnSynchronizeAbort = NULL;
  198. FSynchronizeTerminal = NULL;
  199. FNeedSession = false;
  200. FDoNotIdleCurrentTerminal = 0;
  201. FIncrementalSearching = 0;
  202. FIncrementalSearchHaveNext = false;
  203. FQueueFileList.reset(new TQueueFileList());
  204. FProgressSide = osCurrent;
  205. FCalculateSizeOperation = NULL;
  206. FDownloadingFromClipboard = false;
  207. FClipboardFakeMonitorsPendingReset = false;
  208. FEditorManager = new TEditorManager();
  209. FEditorManager->OnFileChange = ExecutedFileChanged;
  210. FEditorManager->OnFileReload = ExecutedFileReload;
  211. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  212. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  213. FLocalEditors = new TList();
  214. FQueueStatus = NULL;
  215. FQueueStatusSection = new TCriticalSection();
  216. FQueueStatusInvalidated = false;
  217. FQueueItemInvalidated = false;
  218. FQueueStatusUpdating = false;
  219. FQueueActedItem = NULL;
  220. FQueueController = new TQueueController(QueueView3);
  221. FQueueScrollOnDragOver = new TListViewScrollOnDragOver(QueueView3, true);
  222. FUserActionTimer = new TTimer(this);
  223. FUserActionTimer->Enabled = false;
  224. FUserActionTimer->Interval = 10;
  225. FUserActionTimer->OnTimer = UserActionTimer;
  226. FNotes = new TStringList();
  227. FNoteTimer = new TTimer(this);
  228. FNoteTimer->Enabled = false;
  229. FNoteTimer->OnTimer = NoteTimer;
  230. FOnNoteClick = NULL;
  231. FOle32Library = LoadLibrary(L"Ole32.dll");
  232. FDragMoveCursor = FOle32Library != NULL ?
  233. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  234. UseSystemSettings(this);
  235. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  236. static_cast<TObject*>(GetComponent(fcTransferList)));
  237. DebugAssert(TransferList != NULL);
  238. FTransferListHoverIndex = -1;
  239. TransferList->OnChange = TransferListChange;
  240. TransferList->OnDrawItem = TransferListDrawItem;
  241. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))), true);
  242. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  243. UseDesktopFont(SessionsPageControl);
  244. UpdateSessionsPageControlHeight();
  245. UseDesktopFont(RemoteDirView);
  246. UseDesktopFont(RemoteDriveView);
  247. UseDesktopFont(QueueView3);
  248. UseDesktopFont(QueueFileList);
  249. UseDesktopFont(QueueLabel);
  250. UseDesktopFont(RemoteStatusBar);
  251. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  252. QueueSplitter->ShowHint = true;
  253. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  254. QueueFileListSplitter->ShowHint = true;
  255. RemotePanelSplitter->ShowHint = true;
  256. UpdateImages();
  257. FCustomCommandMenu = CreateTBXPopupMenu(this);
  258. FCustomCommandLocalFileList = NULL;
  259. FCustomCommandRemoteFileList = NULL;
  260. FSessionColors = new TPngImageList(this);
  261. FSessionColors->ColorDepth = cd32Bit;
  262. AddFixedSessionImages();
  263. SessionsPageControl->Images = FSessionColors;
  264. UpdateQueueLabel();
  265. CheckStoreTransition();
  266. CreateHiddenWindow();
  267. StartUpdates();
  268. // Start loading drive data, so that they are ready once we need them for StartCreationDirectoryMonitorsOnEachDrive
  269. // (necessary for "explorer" only, as "commander" loads it for its drive menu)
  270. DriveInfo->NeedData();
  271. }
  272. //---------------------------------------------------------------------------
  273. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  274. {
  275. FInvalid = true;
  276. if (FClipboardTerminal != NULL)
  277. {
  278. ClipboardClear(); // implies ClipboardStop
  279. }
  280. // this has to be one of the very first things to do
  281. StopUpdateThread();
  282. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  283. TTerminalManager::Instance()->ScpExplorer = NULL;
  284. delete FCustomCommandLocalFileList;
  285. delete FCustomCommandRemoteFileList;
  286. delete FCustomCommandMenu;
  287. delete FTrayIcon;
  288. FTrayIcon = NULL;
  289. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  290. delete FEditorManager;
  291. ForceCloseLocalEditors();
  292. delete FLocalEditors;
  293. HideFileFindDialog();
  294. if (FDelayedDeletionTimer)
  295. {
  296. DoDelayedDeletion(NULL);
  297. SAFE_DESTROY(FDelayedDeletionTimer);
  298. }
  299. SAFE_DESTROY(FDelayedDeletionList);
  300. // sometimes we do not get DDEnd so the list is not released
  301. SAFE_DESTROY(FDDFileList);
  302. DebugAssert(FSynchronizeController == NULL);
  303. CloseHandle(FDDExtMutex);
  304. FDDExtMutex = NULL;
  305. FreeLibrary(FOle32Library);
  306. FOle32Library = NULL;
  307. FDragMoveCursor = NULL;
  308. DebugAssert(!FErrorList);
  309. if (FEverShown)
  310. {
  311. // when window is never shown (like when running command-line operation),
  312. // particularly window site is not restored correctly (BoundsRect value set
  313. // in RestoreForm gets lost during handle allocation), so we do not want
  314. // it to be stored
  315. StoreParams();
  316. }
  317. ManagedSession = NULL;
  318. Queue = NULL;
  319. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  320. NonVisualDataModule->ScpExplorer = NULL;
  321. delete FQueueScrollOnDragOver;
  322. FQueueScrollOnDragOver = NULL;
  323. delete FQueueController;
  324. FQueueController = NULL;
  325. delete FQueueStatusSection;
  326. FQueueStatusSection = NULL;
  327. delete FQueueStatus;
  328. FQueueStatus = NULL;
  329. delete FUserActionTimer;
  330. FUserActionTimer = NULL;
  331. delete FNoteTimer;
  332. delete FNotes;
  333. delete FNoteData;
  334. SAFE_DESTROY(FDocks);
  335. SessionsPageControl->Images = NULL;
  336. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  337. SAFE_DESTROY(FSessionColors);
  338. SAFE_DESTROY(FSessionsDragDropFilesEx);
  339. SAFE_DESTROY(FHistoryMenu[0][0]);
  340. SAFE_DESTROY(FHistoryMenu[0][1]);
  341. SAFE_DESTROY(FHistoryMenu[1][0]);
  342. SAFE_DESTROY(FHistoryMenu[1][1]);
  343. if (FHiddenWindow != NULL)
  344. {
  345. DestroyWindow(FHiddenWindow);
  346. FHiddenWindow = NULL;
  347. }
  348. }
  349. //---------------------------------------------------------------------------
  350. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  351. {
  352. std::unique_ptr<TSessionData> Data;
  353. if (!Session.IsEmpty())
  354. {
  355. bool DefaultsOnly;
  356. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  357. }
  358. TTerminalManager * Manager = TTerminalManager::Instance();
  359. for (int Index = 0; Index < Manager->Count; Index++)
  360. {
  361. TTerminal * Terminal = Manager->Sessions[Index];
  362. if (Session.IsEmpty() ||
  363. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  364. {
  365. if (Path.IsEmpty())
  366. {
  367. Terminal->ClearCaches();
  368. }
  369. else
  370. {
  371. Terminal->DirectoryModified(Path, true);
  372. }
  373. }
  374. }
  375. // We should flag a pending refresh for the background terminals or busy foreground terminals
  376. if (HasActiveTerminal() &&
  377. CanCommandLineFromAnotherInstance() &&
  378. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  379. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  380. {
  381. Terminal->ReloadDirectory();
  382. }
  383. }
  384. //---------------------------------------------------------------------------
  385. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  386. {
  387. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  388. AppLogFmt(L"Received copy data message with size %d", (int(CopyData->cbData)));
  389. size_t MessageSize = sizeof(TCopyDataMessage);
  390. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  391. if (Result)
  392. {
  393. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  394. Result = (Message.Version == TCopyDataMessage::Version1);
  395. if (Result)
  396. {
  397. switch (Message.Command)
  398. {
  399. case TCopyDataMessage::CommandCanCommandLine:
  400. Result = CanCommandLineFromAnotherInstance();
  401. if (Result)
  402. {
  403. AppLog(L"Can process command-line from other instance");
  404. }
  405. else
  406. {
  407. AppLog(L"Cannot process command-line from other instance");
  408. }
  409. break;
  410. case TCopyDataMessage::CommandCommandLine:
  411. {
  412. UnicodeString CommandLine(Message.CommandLine);
  413. Result = CommandLineFromAnotherInstance(CommandLine);
  414. }
  415. break;
  416. case TCopyDataMessage::RefreshPanel:
  417. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  418. break;
  419. case TCopyDataMessage::MainWindowCheck:
  420. Result = true;
  421. break;
  422. default:
  423. Result = false;
  424. break;
  425. }
  426. }
  427. }
  428. Message.Result = Result ? 1 : 0;
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  432. {
  433. WNDCLASS WindowClass = {0};
  434. WindowClass.lpfnWndProc = DefWindowProc;
  435. WindowClass.hInstance = HInstance;
  436. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  437. FHiddenWindow = NULL;
  438. if (RegisterClass(&WindowClass))
  439. {
  440. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  441. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  442. }
  443. }
  444. //---------------------------------------------------------------------------
  445. bool __fastcall TCustomScpExplorerForm::CanConsole()
  446. {
  447. return
  448. HasActiveTerminal() &&
  449. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  450. }
  451. //---------------------------------------------------------------------------
  452. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  453. {
  454. bool Result = Visible && !NonVisualDataModule->Busy;
  455. return Result;
  456. }
  457. //---------------------------------------------------------------------------
  458. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  459. const UnicodeString & CommandLine)
  460. {
  461. TProgramParams Params(CommandLine);
  462. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  463. if (Result)
  464. {
  465. NonVisualDataModule->StartBusy();
  466. try
  467. {
  468. // this action is initiated from another process,
  469. // so it's likely that our window is not visible,
  470. // and user won't see what is going on
  471. Application->BringToFront();
  472. // reload sessions as we may be asked to open a session
  473. // just stored by another instance
  474. StoredSessions->Reload();
  475. UnicodeString SessionName = Params.Param[1];
  476. std::unique_ptr<TObjectList> DataList(new TObjectList());
  477. try
  478. {
  479. UnicodeString DownloadFile; // unused
  480. int Flags = GetCommandLineParseUrlFlags(&Params);
  481. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  482. }
  483. catch (EAbort &)
  484. {
  485. // Happens when opening session in PuTTY and in other situations,
  486. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  487. // to process the command-line on its own (or to pass it to yet another instance)
  488. }
  489. if (DataList->Count > 0)
  490. {
  491. TTerminalManager * Manager = TTerminalManager::Instance();
  492. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  493. }
  494. }
  495. __finally
  496. {
  497. NonVisualDataModule->EndBusy();
  498. }
  499. }
  500. return Result;
  501. }
  502. //---------------------------------------------------------------------------
  503. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  504. {
  505. TManagedTerminal * Result;
  506. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  507. {
  508. Result = FManagedSession;
  509. }
  510. else
  511. {
  512. Result = NULL;
  513. }
  514. return Result;
  515. }
  516. //---------------------------------------------------------------------------
  517. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  518. {
  519. if (FManagedSession != value)
  520. {
  521. SessionChanging();
  522. DoSetManagedSession(value, false);
  523. }
  524. }
  525. //---------------------------------------------------------------------------
  526. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  527. {
  528. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  529. FManagedSession = value;
  530. {
  531. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  532. FAllowTransferPresetAutoSelect = false;
  533. TAutoFlag SessionChangingFlag(FSessionChanging);
  534. SessionChanged(Replace);
  535. }
  536. if (Terminal != NULL)
  537. {
  538. TransferPresetAutoSelect();
  539. }
  540. // Update app and tab titles, prevented above by FSessionChanging.
  541. UpdateControls();
  542. }
  543. //---------------------------------------------------------------------------
  544. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  545. {
  546. DoSetManagedSession(value, true);
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TCustomScpExplorerForm::SessionChanging()
  550. {
  551. if (ManagedSession != NULL)
  552. {
  553. UpdateSession(ManagedSession);
  554. }
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  558. {
  559. if (ManagedSession != NULL)
  560. {
  561. UpdateSessionColor(static_cast<TColor>(ManagedSession->StateData->Color));
  562. }
  563. if (!TTerminalManager::Instance()->Updating)
  564. {
  565. SessionListChanged();
  566. }
  567. if (Terminal != NULL)
  568. {
  569. TObject * State = NULL;
  570. if (WinConfiguration->PreservePanelState)
  571. {
  572. State = Terminal->RemoteExplorerState;
  573. DirView(osRemote)->AnnounceState(State);
  574. }
  575. try
  576. {
  577. if (Replaced)
  578. {
  579. RemoteDirView->ReplaceTerminal(Terminal);
  580. }
  581. else
  582. {
  583. RemoteDirView->Terminal = Terminal;
  584. }
  585. if (Terminal->Active)
  586. {
  587. Terminal->RefreshDirectory();
  588. }
  589. if (State != NULL)
  590. {
  591. DirView(osRemote)->RestoreState(State);
  592. }
  593. }
  594. __finally
  595. {
  596. DirView(osRemote)->AnnounceState(NULL);
  597. }
  598. }
  599. else
  600. {
  601. RemoteDirView->Terminal = NULL;
  602. }
  603. InitStatusBar();
  604. UpdateTransferList();
  605. // Update panels Enable state before refreshing the labels
  606. UpdateControls();
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  610. {
  611. if (Queue != value)
  612. {
  613. if (FQueue != NULL)
  614. {
  615. FQueue->OnListUpdate = NULL;
  616. FQueue->OnQueueItemUpdate = NULL;
  617. }
  618. FQueue = value;
  619. if (FQueue != NULL)
  620. {
  621. DebugAssert(FQueue->OnListUpdate == NULL);
  622. FQueue->OnListUpdate = QueueListUpdate;
  623. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  624. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  625. }
  626. QueueChanged();
  627. }
  628. }
  629. //---------------------------------------------------------------------------
  630. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  631. TListItem * Item)
  632. {
  633. if (FQueueActedItem == Item)
  634. {
  635. FQueueActedItem = NULL;
  636. if ((QueueView3->PopupMenu != NULL) &&
  637. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  638. {
  639. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  640. ReleaseCapture();
  641. }
  642. }
  643. if (Item->Data == FPendingQueueActionItem)
  644. {
  645. FPendingQueueActionItem = NULL;
  646. }
  647. }
  648. //---------------------------------------------------------------------------
  649. bool TCustomScpExplorerForm::IsAnythingQueued()
  650. {
  651. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  652. }
  653. //---------------------------------------------------------------------------
  654. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  655. {
  656. {
  657. TGuard Guard(FQueueStatusSection);
  658. FQueueStatusInvalidated = false;
  659. if (FQueue != NULL)
  660. {
  661. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  662. }
  663. }
  664. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  665. {
  666. FMaxQueueLength = FQueueStatus->Count;
  667. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  668. }
  669. {
  670. TAutoFlag Flag(FQueueStatusUpdating);
  671. FQueueController->UpdateQueueStatus(FQueueStatus);
  672. }
  673. UpdateQueueFileList();
  674. SetQueueProgress();
  675. UpdateQueueView();
  676. bool IsEmpty = !IsAnythingQueued();
  677. if (IsEmpty && (Terminal != NULL))
  678. {
  679. TOnceDoneOperation OnceDoneOperation =
  680. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  681. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  682. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  683. {
  684. FQueue->Enabled = false;
  685. }
  686. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  687. {
  688. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  689. }
  690. }
  691. }
  692. //---------------------------------------------------------------------------
  693. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  694. {
  695. UnicodeString Result;
  696. if (FQueueStatus != NULL)
  697. {
  698. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  699. {
  700. TFileOperationProgressType * ProgressData =
  701. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  702. if ((ProgressData != NULL) && ProgressData->InProgress)
  703. {
  704. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  705. }
  706. }
  707. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  708. {
  709. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  710. }
  711. }
  712. return Result;
  713. }
  714. //---------------------------------------------------------------------------
  715. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  716. {
  717. ComponentVisible[fcQueueView] =
  718. !IsLocalBrowserMode() &&
  719. ((WinConfiguration->QueueView.Show == qvShow) ||
  720. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  721. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  722. }
  723. //---------------------------------------------------------------------------
  724. void __fastcall TCustomScpExplorerForm::QueueChanged()
  725. {
  726. if (FQueueStatus != NULL)
  727. {
  728. // UpdateFileList implementation relies on the status being recreated when session changes
  729. delete FQueueStatus;
  730. FQueueStatus = NULL;
  731. }
  732. UpdateQueueStatus(true);
  733. }
  734. //---------------------------------------------------------------------------
  735. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  736. {
  737. if (FQueue == Queue)
  738. {
  739. FQueueStatusInvalidated = true;
  740. }
  741. }
  742. //---------------------------------------------------------------------------
  743. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  744. TQueueItem * Item)
  745. {
  746. if (FQueue == Queue)
  747. {
  748. TGuard Guard(FQueueStatusSection);
  749. // this may be running in parallel with QueueChanged
  750. if (FQueueStatus != NULL)
  751. {
  752. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  753. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  754. {
  755. FRefreshLocalDirectory = (QueueItem == NULL) ||
  756. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  757. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  758. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  759. }
  760. if (QueueItem != NULL)
  761. {
  762. QueueItem->UserData = (void*)true;
  763. FQueueItemInvalidated = true;
  764. }
  765. }
  766. }
  767. }
  768. //---------------------------------------------------------------------------
  769. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  770. {
  771. // during standalone editing, we have no way to see/control queue,
  772. // so we have to always popup prompts automatically
  773. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  774. }
  775. //---------------------------------------------------------------------------
  776. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  777. {
  778. if (FQueueStatus != NULL)
  779. {
  780. bool QueueAutoPopup = IsQueueAutoPopup();
  781. bool NeedRefresh = FQueueController->NeedRefresh();
  782. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  783. FQueueItemInvalidated = false;
  784. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  785. bool Updated = false;
  786. TQueueItemProxy * QueueItem;
  787. bool WasUserAction;
  788. for (int Index = 0; Index < Limit; Index++)
  789. {
  790. bool Update = false;
  791. QueueItem = FQueueStatus->Items[Index];
  792. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  793. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  794. (FPendingQueueActionItem == NULL))
  795. {
  796. FPendingQueueActionItem = QueueItem;
  797. FUserActionTimer->Enabled = true;
  798. }
  799. if ((bool)QueueItem->UserData)
  800. {
  801. QueueItem->UserData = (void*)false;
  802. QueueItem->Update();
  803. Updated = true;
  804. Update = true;
  805. }
  806. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  807. {
  808. Update = true;
  809. }
  810. if (Update)
  811. {
  812. FQueueController->RefreshQueueItem(QueueItem);
  813. }
  814. }
  815. if (Updated)
  816. {
  817. NonVisualDataModule->UpdateNonVisibleActions();
  818. SetQueueProgress();
  819. UpdateQueueFileList();
  820. }
  821. }
  822. }
  823. //---------------------------------------------------------------------------
  824. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  825. {
  826. if (FTaskbarList != NULL)
  827. {
  828. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  829. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  830. }
  831. }
  832. //---------------------------------------------------------------------------
  833. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  834. {
  835. if (Progress >= 0)
  836. {
  837. if (FTaskbarList != NULL)
  838. {
  839. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  840. }
  841. }
  842. else
  843. {
  844. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  845. }
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  849. {
  850. int OverallProgress;
  851. // FProgressForm is null when this is called from SetQueueProgress
  852. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  853. {
  854. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  855. }
  856. else if (!ProgressData->IsIndeterminate())
  857. {
  858. OverallProgress = ProgressData->OverallProgress();
  859. }
  860. else
  861. {
  862. OverallProgress = -1;
  863. }
  864. SetTaskbarListProgressValue(OverallProgress);
  865. }
  866. //---------------------------------------------------------------------------
  867. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  868. {
  869. TTerminalManager::Instance()->QueueStatusUpdated();
  870. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  871. {
  872. // Do not animate task bar button, when items are queued, but processing is disabled
  873. if ((FQueueStatus != NULL) && (FQueueStatus->ActivePrimaryCount > 0))
  874. {
  875. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  876. {
  877. TFileOperationProgressType * ProgressData = NULL;
  878. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  879. {
  880. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  881. }
  882. if ((ProgressData != NULL) &&
  883. ProgressData->InProgress)
  884. {
  885. SetTaskbarListProgressValue(ProgressData);
  886. }
  887. else
  888. {
  889. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  890. }
  891. }
  892. else
  893. {
  894. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  895. }
  896. }
  897. else
  898. {
  899. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  900. }
  901. }
  902. UpdateQueueLabel();
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  906. {
  907. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  908. if (FQueueStatus != NULL)
  909. {
  910. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  911. if (ActiveAndPendingPrimaryCount > 0)
  912. {
  913. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  914. }
  915. }
  916. QueueLabel->Caption = Caption;
  917. }
  918. //---------------------------------------------------------------------------
  919. void TCustomScpExplorerForm::CheckStoreTransition()
  920. {
  921. if (WinConfiguration->StoreTransition == stInit)
  922. {
  923. if (IsUWP())
  924. {
  925. WinConfiguration->StoreTransition = stStoreFresh;
  926. AppLog(L"Fresh UWP/store installation");
  927. }
  928. else
  929. {
  930. WinConfiguration->StoreTransition = stStandard;
  931. AppLog(L"Fresh standard installation");
  932. }
  933. }
  934. else if ((WinConfiguration->StoreTransition == stStandard) && IsUWP())
  935. {
  936. WinConfiguration->StoreTransition = stStoreMigrated;
  937. WinConfiguration->FirstRun = WinConfiguration->FirstRun + L"=>" + StandardDatestamp();
  938. AppLog(L"Standard installation migrated to store installation");
  939. }
  940. if (WinConfiguration->StoreTransition == stStoreMigrated)
  941. {
  942. TTBXToolbar * Toolbar = new TTBXToolbar(MessageDock);
  943. Toolbar->Parent = MessageDock;
  944. Toolbar->FullSize = true;
  945. Toolbar->Color = Application->HintColor;
  946. TTBXLabelItem * LabelItem;
  947. LabelItem = new TTBXLabelItem(Toolbar);
  948. LabelItem->Margin = ScaleByTextHeight(MessageDock, 2); // Is this automatically rescaled?
  949. LabelItem->Caption = LoadStr(STORE_MIGRATION_THANKS);
  950. Toolbar->Items->Add(LabelItem);
  951. TTBXCustomItem * LinkItem = new TTBXItem(Toolbar);
  952. LinkItem->FontSettings->Color = LinkColor;
  953. LinkItem->Caption = LoadStr(STORE_MIGRATION_LEARN);
  954. LinkItem->OnClick = StoreTransitionLinkClick;
  955. Toolbar->Items->Add(LinkItem);
  956. AddMenuSeparator(Toolbar->Items);
  957. TTBCustomItem * CloseItem = new TTBXItem(Toolbar);
  958. CloseItem->Caption = LoadStr(MESSAGE_DISMISS);
  959. CloseItem->OnClick = StoreTransitionCloseClick;
  960. Toolbar->Items->Add(CloseItem);
  961. GiveTBItemPriority(CloseItem);
  962. }
  963. }
  964. //---------------------------------------------------------------------------
  965. void __fastcall TCustomScpExplorerForm::StoreTransitionLinkClick(TObject *)
  966. {
  967. ShowHelp(HELP_STORE_TRANSITION);
  968. }
  969. //---------------------------------------------------------------------------
  970. void __fastcall TCustomScpExplorerForm::StoreTransitionCloseClick(TObject * Sender)
  971. {
  972. TTBCustomItem * Item = DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender));
  973. TTBXToolbar * Toolbar = DebugNotNull(dynamic_cast<TTBXToolbar *>(DebugNotNull(DebugNotNull(Item->Parent)->ParentComponent)));
  974. delete Toolbar;
  975. WinConfiguration->StoreTransition = stStoreAcknowledged;
  976. UpdateControls();
  977. }
  978. //---------------------------------------------------------------------------
  979. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  980. {
  981. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  982. static_cast<TComponent*>(GetComponent(fcTransferList)));
  983. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  984. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  985. TransferList->Strings->BeginUpdate();
  986. try
  987. {
  988. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  989. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  990. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  991. if (FTransferDropDownHint.IsEmpty())
  992. {
  993. FTransferDropDownHint = TransferDropDown->Hint;
  994. }
  995. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  996. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  997. TransferDropDown->Text = StripHotkey(Name);
  998. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  999. (FTransferDropDownHint, StripHotkey(Name),
  1000. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  1001. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  1002. // update the label, otherwise when it is updated only on the first draw
  1003. // of the list, it is drawn "bold" for some reason
  1004. FTransferListHoverIndex = TransferList->ItemIndex;
  1005. UpdateTransferLabel();
  1006. }
  1007. __finally
  1008. {
  1009. TransferList->Strings->EndUpdate();
  1010. }
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  1014. {
  1015. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  1016. DebugAssert(Toolbar != NULL);
  1017. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. void __fastcall TCustomScpExplorerForm::UpdateActions()
  1021. {
  1022. TForm::UpdateActions();
  1023. if (ComponentVisible[fcCustomCommandsBand])
  1024. {
  1025. UpdateCustomCommandsToolbar();
  1026. }
  1027. }
  1028. //---------------------------------------------------------------------------
  1029. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  1030. {
  1031. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  1035. {
  1036. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  1037. {
  1038. DirView->RowSelect = WinConfiguration->FullRowSelect;
  1039. // Without this, the panel turns gray and unused part of header turns black
  1040. DirView->Perform(CM_COLORCHANGED, 0, 0);
  1041. }
  1042. }
  1043. //---------------------------------------------------------------------------
  1044. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  1045. {
  1046. Color = GetBtnFaceColor();
  1047. DebugAssert(Configuration && RemoteDirView);
  1048. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1049. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  1050. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  1051. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  1052. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1053. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1054. RemoteDirView->AlwaysSortDirectoriesByName = WinConfiguration->AlwaysSortDirectoriesByName;
  1055. UpdateRowSelect(RemoteDirView);
  1056. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1057. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  1058. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  1059. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1060. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1061. UpdateSessionsPageControlHeight();
  1062. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1063. UpdateToolbarDisplayMode();
  1064. UpdateTransferList();
  1065. if (Terminal != NULL)
  1066. {
  1067. TransferPresetAutoSelect();
  1068. }
  1069. UpdateQueueView();
  1070. UpdateControls();
  1071. // this can be called even before constuctor finishes.
  1072. if (FEditorManager != NULL)
  1073. {
  1074. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  1075. }
  1076. // this can be called even before constuctor finishes.
  1077. if (FLocalEditors != NULL)
  1078. {
  1079. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  1080. {
  1081. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  1082. }
  1083. }
  1084. if (ComponentVisible[fcCustomCommandsBand])
  1085. {
  1086. UpdateCustomCommandsToolbar();
  1087. }
  1088. // show only when keeping queue items forever,
  1089. // otherwise, it's enough to have it in the context menu
  1090. QueueDeleteAllDoneQueueToolbarItem->Visible =
  1091. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  1092. if (FFileColorsCurrent != WinConfiguration->FileColors)
  1093. {
  1094. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  1095. FFileColorsCurrent = WinConfiguration->FileColors;
  1096. FileColorsChanged();
  1097. }
  1098. }
  1099. //---------------------------------------------------------------------------
  1100. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1101. {
  1102. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1103. DirView->Invalidate();
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1107. {
  1108. DoFileColorsChanged(RemoteDirView);
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1112. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1113. void * /*Arg*/)
  1114. {
  1115. if (Token != NULL)
  1116. {
  1117. TForm * Editor = dynamic_cast<TForm*>(Token);
  1118. DebugAssert(Editor != NULL);
  1119. ReconfigureEditorForm(Editor);
  1120. }
  1121. }
  1122. //---------------------------------------------------------------------------
  1123. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1124. {
  1125. WinConfiguration->DDTransferConfirmation = asOn;
  1126. }
  1127. //---------------------------------------------------------------------------
  1128. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1129. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1130. {
  1131. // noop
  1132. }
  1133. //---------------------------------------------------------------------------
  1134. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1135. {
  1136. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1137. }
  1138. //---------------------------------------------------------------------------
  1139. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1140. {
  1141. if (DoNotShowAgain)
  1142. {
  1143. if (DragDrop)
  1144. {
  1145. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1146. {
  1147. PopupTrayBalloon(
  1148. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1149. }
  1150. WinConfiguration->DDTransferConfirmation = asOff;
  1151. }
  1152. else
  1153. {
  1154. WinConfiguration->ConfirmTransferring = false;
  1155. }
  1156. }
  1157. else
  1158. {
  1159. // User explicitly unchecked "do not show again",
  1160. // so show him the dialog the next time
  1161. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1162. {
  1163. WinConfiguration->DDTransferConfirmation = asOn;
  1164. }
  1165. }
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1169. TTransferDirection Direction, TTransferType Type, bool Temp,
  1170. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1171. bool Confirm, bool DragDrop, int Options)
  1172. {
  1173. bool Result = true;
  1174. DebugAssert(HasActiveTerminal());
  1175. // these parameters are known in advance
  1176. int Params =
  1177. FLAGMASK(Type == ttMove, cpDelete);
  1178. bool ToTemp = (Temp && (Direction == tdToLocal));
  1179. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1180. {
  1181. bool DisableNewerOnly =
  1182. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1183. ToTemp;
  1184. Options |=
  1185. FLAGMASK(ToTemp, coTemp) |
  1186. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1187. coDoNotShowAgain;
  1188. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1189. int CopyParamAttrs = (Direction == tdToRemote ?
  1190. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1191. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1192. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1193. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1194. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1195. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1196. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1197. if (Result)
  1198. {
  1199. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1200. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1201. }
  1202. }
  1203. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1204. {
  1205. Configuration->Usage->Inc(L"TransfersOnBackground");
  1206. // these parameter are known only after transfer dialog
  1207. Params |=
  1208. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1209. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1210. Result = false;
  1211. ClearTransferSourceSelection(Direction);
  1212. }
  1213. return Result;
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void TCustomScpExplorerForm::ClearOperationSelection(TOperationSide Side)
  1217. {
  1218. if (FOnFileOperationFinished != NULL)
  1219. {
  1220. FOnFileOperationFinished(Side, UnicodeString(), true);
  1221. }
  1222. else
  1223. {
  1224. if (HasDirView[Side])
  1225. {
  1226. DirView(Side)->SelectAll(smNone);
  1227. }
  1228. }
  1229. }
  1230. //---------------------------------------------------------------------------
  1231. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1232. {
  1233. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1234. ClearOperationSelection(Side);
  1235. }
  1236. //---------------------------------------------------------------------------
  1237. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1238. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1239. const UnicodeString TargetDirectory, TGUICopyParamType & CopyParam,
  1240. int Params)
  1241. {
  1242. DebugAssert(Queue != NULL);
  1243. bool SingleFile = false;
  1244. if (FileList->Count == 1)
  1245. {
  1246. if (Direction == tdToRemote)
  1247. {
  1248. UnicodeString FileName = FileList->Strings[0];
  1249. SingleFile = FileExists(ApiPath(FileName));
  1250. }
  1251. else
  1252. {
  1253. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1254. SingleFile = !File->IsDirectory;
  1255. }
  1256. }
  1257. TQueueItem * QueueItem;
  1258. if (Direction == tdToRemote)
  1259. {
  1260. CopyParam.IncludeFileMask.SetRoots(FileList, TargetDirectory);
  1261. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1262. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1263. }
  1264. else
  1265. {
  1266. CopyParam.IncludeFileMask.SetRoots(TargetDirectory, FileList);
  1267. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1268. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1269. }
  1270. AddQueueItem(Queue, QueueItem, Terminal);
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1274. {
  1275. if (Queue->IsEmpty)
  1276. {
  1277. Terminal->QueueOperationStart = Now();
  1278. }
  1279. Queue->AddItem(QueueItem);
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1283. {
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. void __fastcall TCustomScpExplorerForm::InitControls()
  1287. {
  1288. DebugAssert(FDocks != NULL);
  1289. for (int Index = 0; Index < ComponentCount; Index++)
  1290. {
  1291. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1292. if ((Dock != NULL) && (Dock->Tag == 0))
  1293. {
  1294. FDocks->Add(Dock);
  1295. }
  1296. }
  1297. CollectItemsWithTextDisplayMode(this);
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1301. {
  1302. ConfigurationChanged();
  1303. QueuePanel->Height =
  1304. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1305. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1306. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1307. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1308. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1309. QueueFileList->Height =
  1310. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1311. if (QueueFileList->Visible)
  1312. {
  1313. AdjustQueueLayout();
  1314. }
  1315. UpdateCustomCommandsToolbar();
  1316. }
  1317. //---------------------------------------------------------------------------
  1318. void __fastcall TCustomScpExplorerForm::StoreParams()
  1319. {
  1320. int APixelsPerInch = GetControlPixelsPerInch(this);
  1321. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1322. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1323. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1324. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1325. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1326. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1327. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1328. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1332. {
  1333. if (!FFormRestored)
  1334. {
  1335. FFormRestored = true;
  1336. RestoreFormParams();
  1337. }
  1338. TForm::CreateParams(Params);
  1339. }
  1340. //---------------------------------------------------------------------------
  1341. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1342. {
  1343. DebugAssert(FDocks != NULL);
  1344. for (int Index = 0; Index < FDocks->Count; Index++)
  1345. {
  1346. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1347. }
  1348. }
  1349. //---------------------------------------------------------------------------
  1350. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1351. {
  1352. SetDockAllowDrag(true);
  1353. while (!ButtonsStr.IsEmpty())
  1354. {
  1355. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1356. UnicodeString Name = CutToChar(S, L'=', true);
  1357. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1358. {
  1359. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1360. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1361. {
  1362. while (!S.IsEmpty())
  1363. {
  1364. UnicodeString S2 = CutToChar(S, L',', true);
  1365. UnicodeString Name = CutToChar(S2, L':', true);
  1366. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1367. {
  1368. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1369. if (SameText(GetToolbarItemName(Item), Name))
  1370. {
  1371. // forward compatibility
  1372. UnicodeString S3 = CutToChar(S2, L':', true);
  1373. bool Visible = StrToIntDef(S3, 0);
  1374. Item->Visible = Visible;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1382. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1386. {
  1387. UnicodeString Result;
  1388. SetDockAllowDrag(true);
  1389. Result = ::GetToolbarsLayoutStr(this);
  1390. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1391. return Result;
  1392. }
  1393. //---------------------------------------------------------------------------
  1394. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1395. {
  1396. UnicodeString Result;
  1397. if (Item->Action != NULL)
  1398. {
  1399. Result = Item->Action->Name;
  1400. Result = RemoveSuffix(Result, L"Action", true);
  1401. }
  1402. else
  1403. {
  1404. Result = Item->Name;
  1405. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1406. Result = RemoveSuffix(Result, L"Item", true);
  1407. }
  1408. return Result;
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1412. {
  1413. UnicodeString Result;
  1414. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1415. {
  1416. UnicodeString ToolbarStr;
  1417. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1418. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1419. {
  1420. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1421. {
  1422. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1423. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1424. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1425. // and save the changes here only.
  1426. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1427. {
  1428. UnicodeString Name = GetToolbarItemName(Item);
  1429. DebugAssert(Name.Pos(L"TBX") == 0);
  1430. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1431. }
  1432. }
  1433. }
  1434. if (!ToolbarStr.IsEmpty())
  1435. {
  1436. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1437. }
  1438. }
  1439. return Result;
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1443. {
  1444. DebugAssert(FProgressForm == NULL);
  1445. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1446. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1447. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1448. FProgressForm->DeleteLocalToRecycleBin =
  1449. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1450. FProgressForm->DeleteRemoteToRecycleBin =
  1451. HasActiveTerminal() &&
  1452. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1453. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1454. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1455. LockWindow();
  1456. // Actually, do not know what hides the progress once the operation finishes
  1457. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1458. SetTaskbarListProgressState(TBPF_NORMAL);
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1462. {
  1463. SAFE_DESTROY(FProgressForm);
  1464. UnlockWindow();
  1465. SetQueueProgress();
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1469. TFileOperationProgressType & ProgressData)
  1470. {
  1471. // Download to temporary local directory
  1472. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1473. {
  1474. bool Continue = true;
  1475. FPendingTempSpaceWarn = false;
  1476. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1477. if (!Continue)
  1478. {
  1479. Abort();
  1480. }
  1481. }
  1482. // operation is being executed and we still didn't show up progress form
  1483. if (ProgressData.InProgress && !FProgressForm)
  1484. {
  1485. CreateProgressForm(NULL);
  1486. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1487. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1488. }
  1489. // operation is finished (or terminated), so we hide progress form
  1490. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1491. {
  1492. DestroyProgressForm();
  1493. if (ProgressData.Operation == foCalculateSize)
  1494. {
  1495. // When calculating size before transfer, the abort caused by
  1496. // cancel flag set due to "MoveToQueue" below,
  1497. // is not propagated back to us in ExecuteFileOperation,
  1498. // as it is silently swallowed.
  1499. // So we explicitly (re)throw it here.
  1500. if (FMoveToQueue)
  1501. {
  1502. Abort();
  1503. }
  1504. }
  1505. else
  1506. {
  1507. if ((ProgressData.Cancel == csContinue) &&
  1508. !FAutoOperation)
  1509. {
  1510. OperationComplete(ProgressData.StartTime);
  1511. }
  1512. }
  1513. }
  1514. if (FProgressForm &&
  1515. // Can happen only during synchronization, when ending one of the operations
  1516. ProgressData.InProgress)
  1517. {
  1518. FProgressForm->SetProgressData(ProgressData);
  1519. DebugAssert(ProgressData.InProgress);
  1520. SetTaskbarListProgressValue(&ProgressData);
  1521. if (FProgressForm->Cancel > csContinue)
  1522. {
  1523. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1524. if (FProgressForm->Cancel == csCancelFile)
  1525. {
  1526. FProgressForm->ClearCancel();
  1527. }
  1528. // cancel cancels even the move
  1529. FMoveToQueue = false;
  1530. }
  1531. else if (FProgressForm->MoveToQueue)
  1532. {
  1533. FMoveToQueue = true;
  1534. ProgressData.SetCancelAtLeast(csCancel);
  1535. }
  1536. if ((FTransferResumeList != NULL) &&
  1537. ProgressData.InProgress &&
  1538. ProgressData.IsTransfer() &&
  1539. !ProgressData.FullFileName.IsEmpty())
  1540. {
  1541. if ((FTransferResumeList->Count == 0) ||
  1542. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1543. {
  1544. // note that we do not recognize directories from files here
  1545. FTransferResumeList->Add(ProgressData.FullFileName);
  1546. }
  1547. }
  1548. }
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1552. const TDateTime & StartTime)
  1553. {
  1554. if (GUIConfiguration->BeepOnFinish &&
  1555. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1556. {
  1557. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1558. DWORD Sound;
  1559. if (!ExtractFileExt(BeepSound).IsEmpty())
  1560. {
  1561. Sound = SND_FILENAME;
  1562. }
  1563. else
  1564. {
  1565. Sound = SND_ALIAS;
  1566. }
  1567. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1568. }
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1572. TFileOperationProgressType & ProgressData)
  1573. {
  1574. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1575. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1576. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1577. FileOperationProgress(ProgressData);
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1581. {
  1582. UnicodeString Result;
  1583. if (FProgressForm != NULL)
  1584. {
  1585. Result = FProgressForm->ProgressStr();
  1586. }
  1587. return Result;
  1588. }
  1589. //---------------------------------------------------------------------------
  1590. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1591. bool DragDrop)
  1592. {
  1593. return (!DragDrop && (DropSourceControl == NULL)) ||
  1594. (DropSourceControl == DirView(osOther));
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1598. {
  1599. TCustomDirView * ADirView = DirView(Side);
  1600. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1601. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1602. // this can happen when local drive is unplugged in the middle of the operation
  1603. if (Item != NULL)
  1604. {
  1605. if (Unselect)
  1606. {
  1607. Item->Selected = false;
  1608. }
  1609. ADirView->MakeProgressVisible(Item);
  1610. }
  1611. return Item;
  1612. }
  1613. //---------------------------------------------------------------------------
  1614. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1615. TFileOperation Operation, TOperationSide Side,
  1616. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1617. TOnceDoneOperation & OnceDoneOperation)
  1618. {
  1619. if (!FAutoOperation)
  1620. {
  1621. // no selection on "/upload", form serves only as event handler
  1622. // (it is not displayed)
  1623. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1624. ((Operation == FPrimaryOperation) ||
  1625. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1626. {
  1627. TOperationSide DViewSide;
  1628. if ((FProgressSide != osCurrent) &&
  1629. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1630. {
  1631. // assume the operation is over the focused panel
  1632. DViewSide = FProgressSide;
  1633. }
  1634. else
  1635. {
  1636. DViewSide = Side;
  1637. }
  1638. if (FOnFileOperationFinished != NULL)
  1639. {
  1640. FOnFileOperationFinished(DViewSide, FileName, Success);
  1641. }
  1642. else
  1643. {
  1644. VisualiseOperationFinished(DViewSide, FileName, Success);
  1645. }
  1646. }
  1647. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1648. {
  1649. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1650. {
  1651. if (Side == osLocal)
  1652. {
  1653. Configuration->Usage->Inc(L"UploadedFiles");
  1654. }
  1655. else
  1656. {
  1657. Configuration->Usage->Inc(L"DownloadedFiles");
  1658. }
  1659. }
  1660. }
  1661. }
  1662. if (Success && (FSynchronizeController != NULL))
  1663. {
  1664. DebugAssert(!IsSideLocalBrowser(osRemote));
  1665. if (Operation == foCopy)
  1666. {
  1667. DebugAssert(Side == osLocal);
  1668. FSynchronizeController->LogOperation(soUpload, FileName);
  1669. }
  1670. else if (Operation == foDelete)
  1671. {
  1672. DebugAssert(Side == osRemote);
  1673. FSynchronizeController->LogOperation(soDelete, FileName);
  1674. }
  1675. }
  1676. if (FProgressForm)
  1677. {
  1678. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1679. }
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1683. TFileOperation Operation, TOperationSide Side,
  1684. bool Temp, const UnicodeString & FileName, Boolean Success,
  1685. TOnceDoneOperation & OnceDoneOperation)
  1686. {
  1687. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1688. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1689. OnceDoneOperation);
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1693. {
  1694. return false;
  1695. }
  1696. //---------------------------------------------------------------------------
  1697. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1698. {
  1699. return false;
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1703. {
  1704. return false;
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1708. {
  1709. return NULL;
  1710. }
  1711. //---------------------------------------------------------------------------
  1712. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1713. {
  1714. DebugAssert(GetSide(Side) == osRemote);
  1715. DebugUsedParam(Side);
  1716. return RemoteDirView;
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1720. {
  1721. DebugAssert(GetSide(Side) == osRemote);
  1722. DebugUsedParam(Side);
  1723. return RemoteDriveView;
  1724. }
  1725. //---------------------------------------------------------------------------
  1726. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1727. {
  1728. DebugAssert(GetSide(Side) == osRemote);
  1729. DebugUsedParam(Side);
  1730. return HasActiveTerminal();
  1731. }
  1732. //---------------------------------------------------------------------------
  1733. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1734. TOperationSide Side, int FilesOnly)
  1735. {
  1736. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1737. }
  1738. //---------------------------------------------------------------------------
  1739. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1740. TOperationSide Side, int FilesOnly)
  1741. {
  1742. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1743. }
  1744. //---------------------------------------------------------------------------
  1745. struct THistoryItemData
  1746. {
  1747. short int Side;
  1748. short int Index;
  1749. };
  1750. //---------------------------------------------------------------------------
  1751. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1752. {
  1753. DirView(Side)->HistoryGo(Index);
  1754. }
  1755. //---------------------------------------------------------------------------
  1756. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1757. {
  1758. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1759. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1760. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1761. }
  1762. //---------------------------------------------------------------------------
  1763. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1764. bool Back)
  1765. {
  1766. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1767. {
  1768. TCustomDirView * DView = DirView(Side);
  1769. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1770. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1771. if (ICount > 10)
  1772. {
  1773. ICount = 10;
  1774. }
  1775. Menu->Items->Clear();
  1776. THistoryItemData Data;
  1777. Data.Side = Side;
  1778. for (short int i = 1; i <= ICount; i++)
  1779. {
  1780. TTBCustomItem * Item = new TTBXItem(Menu);
  1781. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1782. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1783. Item->Hint = DView->HistoryPath[Data.Index];
  1784. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1785. Item->Tag = *reinterpret_cast<int*>(&Data);
  1786. Item->OnClick = HistoryItemClick;
  1787. Menu->Items->Add(Item);
  1788. }
  1789. }
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1793. TOperationSide Side, bool Back)
  1794. {
  1795. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1796. {
  1797. // workaround
  1798. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1799. // operator new allocates memory in Pascal code, but calls inline
  1800. // contructor in C++, leading in problems, the function does
  1801. // both in Pascal code
  1802. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1803. UpdateHistoryMenu(Side, Back);
  1804. }
  1805. return FHistoryMenu[Side == osLocal][Back];
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1809. TCustomDirView *Sender)
  1810. {
  1811. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1812. UpdateHistoryMenu(Side, true);
  1813. UpdateHistoryMenu(Side, false);
  1814. }
  1815. //---------------------------------------------------------------------------
  1816. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1817. {
  1818. // remote custom commands can be executed only if the server supports shell commands
  1819. // or have secondary shell
  1820. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1821. }
  1822. //---------------------------------------------------------------------------
  1823. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1824. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1825. {
  1826. // -1 = hidden, 0 = disabled, 1 = enabled
  1827. int Result;
  1828. TFileCustomCommand RemoteCustomCommand;
  1829. TLocalCustomCommand LocalCustomCommand;
  1830. TFileCustomCommand * NonInteractiveCustomCommand =
  1831. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1832. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1833. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1834. if (FLAGCLEAR(Command.Params, ccLocal))
  1835. {
  1836. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1837. // custom command that does not operate with files can be executed anytime ...
  1838. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1839. {
  1840. // ... but do not show such command in remote file menu
  1841. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1842. {
  1843. Result = AllowedState;
  1844. }
  1845. else
  1846. {
  1847. Result = -1;
  1848. }
  1849. }
  1850. else
  1851. {
  1852. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1853. {
  1854. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1855. }
  1856. else
  1857. {
  1858. Result = -1;
  1859. }
  1860. }
  1861. }
  1862. else
  1863. {
  1864. // custom command that does not operate with files can be executed anytime
  1865. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1866. {
  1867. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1868. }
  1869. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1870. {
  1871. if ((ListType == ccltAll) || (ListType == ccltFile))
  1872. {
  1873. // special case is "diff"-style command that can be executed over any side,
  1874. // if we have both sides
  1875. Result =
  1876. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1877. // directly (instead of EnableSelectedOperation) to pass
  1878. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1879. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1880. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1881. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1882. }
  1883. else if (ListType == ccltBoth)
  1884. {
  1885. DebugAssert(!IsLocalBrowserMode());
  1886. Result = 1;
  1887. }
  1888. else
  1889. {
  1890. Result = -1;
  1891. }
  1892. }
  1893. else
  1894. {
  1895. if ((ListType == ccltAll) ||
  1896. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1897. {
  1898. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1899. }
  1900. else
  1901. {
  1902. Result = -1;
  1903. }
  1904. }
  1905. if ((Result > 0) &&
  1906. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1907. !HasActiveTerminal())
  1908. {
  1909. Result = 0;
  1910. }
  1911. }
  1912. return Result;
  1913. }
  1914. //---------------------------------------------------------------------------
  1915. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1916. TStrings * FileList, const TCustomCommandType & ACommand,
  1917. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1918. {
  1919. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1920. {
  1921. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1922. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1923. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1924. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1925. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1926. bool Capture =
  1927. FLAGSET(ACommand.Params, ccShowResults) ||
  1928. FLAGSET(ACommand.Params, ccCopyResults) ||
  1929. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1930. TCaptureOutputEvent OutputEvent = NULL;
  1931. DebugAssert(FCapturedLog == NULL);
  1932. if (Capture)
  1933. {
  1934. FCapturedLog = new TStringList();
  1935. OutputEvent = TerminalCaptureLog;
  1936. }
  1937. try
  1938. {
  1939. if (!RemoteCustomCommand.IsFileCommand(Command))
  1940. {
  1941. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1942. OutputEvent);
  1943. }
  1944. else
  1945. {
  1946. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1947. }
  1948. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1949. {
  1950. if (FLAGSET(ACommand.Params, ccCopyResults))
  1951. {
  1952. CopyToClipboard(FCapturedLog);
  1953. }
  1954. if (FLAGSET(ACommand.Params, ccShowResults))
  1955. {
  1956. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1957. }
  1958. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1959. {
  1960. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1961. }
  1962. }
  1963. }
  1964. __finally
  1965. {
  1966. SAFE_DESTROY(FCapturedLog);
  1967. }
  1968. }
  1969. }
  1970. //---------------------------------------------------------------------------
  1971. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1972. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1973. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1974. {
  1975. DebugAssert(!IsLocalBrowserMode());
  1976. TStrings * LocalFileList = NULL;
  1977. TStrings * RemoteFileList = NULL;
  1978. TStrings * RemoteFileListFull = NULL;
  1979. try
  1980. {
  1981. if (LocalFileCommand)
  1982. {
  1983. if (ALocalFileList == NULL)
  1984. {
  1985. DebugAssert(HasDirView[osLocal]);
  1986. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1987. // directly (instead of EnableSelectedOperation) to pass
  1988. // false to FocusedFileOnlyWhenFocused
  1989. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1990. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1991. }
  1992. else
  1993. {
  1994. LocalFileList = ALocalFileList;
  1995. }
  1996. if (FileListCommand)
  1997. {
  1998. if (LocalFileList->Count != 1)
  1999. {
  2000. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  2001. }
  2002. }
  2003. else
  2004. {
  2005. if ((LocalFileList->Count != 1) &&
  2006. (FileList->Count != 1) &&
  2007. (LocalFileList->Count != FileList->Count))
  2008. {
  2009. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  2010. }
  2011. }
  2012. }
  2013. UnicodeString RootTempDir;
  2014. UnicodeString TempDir;
  2015. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  2016. if (!RemoteFiles)
  2017. {
  2018. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, true, true);
  2019. }
  2020. try
  2021. {
  2022. TDateTimes RemoteFileTimes;
  2023. if (RemoteFiles)
  2024. {
  2025. RemoteFileList = FileList;
  2026. }
  2027. else
  2028. {
  2029. RemoteFileList = new TStringList();
  2030. TMakeLocalFileListParams MakeFileListParam;
  2031. MakeFileListParam.FileList = RemoteFileList;
  2032. MakeFileListParam.FileTimes = &RemoteFileTimes;
  2033. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2034. MakeFileListParam.Recursive =
  2035. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  2036. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2037. if (!MakeFileListParam.Recursive)
  2038. {
  2039. RemoteFileTimes.clear();
  2040. RemoteFileListFull = new TStringList();
  2041. MakeFileListParam.FileList = RemoteFileListFull;
  2042. MakeFileListParam.Recursive = true;
  2043. MakeFileListParam.IncludeDirs = false;
  2044. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2045. }
  2046. else
  2047. {
  2048. RemoteFileListFull = RemoteFileList;
  2049. }
  2050. }
  2051. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  2052. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2053. if (!NonBlocking)
  2054. {
  2055. int Count;
  2056. if (FileListCommand)
  2057. {
  2058. Count = 1;
  2059. }
  2060. else if (LocalFileCommand)
  2061. {
  2062. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  2063. }
  2064. else
  2065. {
  2066. Count = RemoteFileList->Count;
  2067. }
  2068. Progress.Start(foCustomCommand, osRemote, Count);
  2069. DebugAssert(FProgressForm != NULL);
  2070. FProgressForm->ReadOnly = true;
  2071. }
  2072. try
  2073. {
  2074. if (FileListCommand)
  2075. {
  2076. UnicodeString LocalFile;
  2077. // MakeFileList does not delimit filenames
  2078. UnicodeString FileList = MakeFileList(RemoteFileList);
  2079. if (LocalFileCommand)
  2080. {
  2081. DebugAssert(LocalFileList->Count == 1);
  2082. LocalFile = LocalFileList->Strings[0];
  2083. }
  2084. TLocalCustomCommand CustomCommand(Data,
  2085. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  2086. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2087. if (NonBlocking)
  2088. {
  2089. DebugAssert(!POutput);
  2090. ExecuteShellChecked(ShellCommand);
  2091. }
  2092. else
  2093. {
  2094. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2095. }
  2096. }
  2097. else if (LocalFileCommand)
  2098. {
  2099. if (LocalFileList->Count == 1)
  2100. {
  2101. UnicodeString LocalFile = LocalFileList->Strings[0];
  2102. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2103. {
  2104. UnicodeString FileName = RemoteFileList->Strings[Index];
  2105. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2106. Progress.SetFile(FileNameForProgress);
  2107. TLocalCustomCommand CustomCommand(Data,
  2108. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2109. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2110. TOnceDoneOperation OnceDoneOperation;
  2111. // Do not unselect anything, as it won't work with two panels anyway
  2112. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2113. }
  2114. }
  2115. else if (RemoteFileList->Count == 1)
  2116. {
  2117. UnicodeString FileName = RemoteFileList->Strings[0];
  2118. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2119. {
  2120. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2121. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2122. Progress.SetFile(LocalFileNameOnly);
  2123. TLocalCustomCommand CustomCommand(
  2124. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2125. FileName, LocalFileName, L"");
  2126. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2127. TOnceDoneOperation OnceDoneOperation;
  2128. // Do not unselect anything, as it won't work with two panels anyway
  2129. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2130. }
  2131. }
  2132. else
  2133. {
  2134. if (LocalFileList->Count != RemoteFileList->Count)
  2135. {
  2136. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2137. }
  2138. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2139. {
  2140. UnicodeString FileName = RemoteFileList->Strings[Index];
  2141. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2142. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2143. Progress.SetFile(LocalFileNameOnly); // sic
  2144. TLocalCustomCommand CustomCommand(
  2145. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2146. FileName, LocalFileName, L"");
  2147. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2148. TOnceDoneOperation OnceDoneOperation;
  2149. // Do not unselect anything, as it won't work with two panels anyway
  2150. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2151. }
  2152. }
  2153. }
  2154. else
  2155. {
  2156. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2157. {
  2158. UnicodeString FileName = RemoteFileList->Strings[Index];
  2159. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2160. Progress.SetFile(FileNameForProgress);
  2161. TLocalCustomCommand CustomCommand(Data,
  2162. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2163. FileName, L"", L"");
  2164. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2165. TOnceDoneOperation OnceDoneOperation;
  2166. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2167. }
  2168. }
  2169. }
  2170. __finally
  2171. {
  2172. if (!NonBlocking)
  2173. {
  2174. Progress.Stop();
  2175. }
  2176. }
  2177. DebugAssert(!FAutoOperation);
  2178. if (!RemoteFiles)
  2179. {
  2180. TempDir = IncludeTrailingBackslash(TempDir);
  2181. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2182. {
  2183. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2184. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2185. // Skip directories, process only nested files.
  2186. // The check is redundant as FileAge fails for directories anyway.
  2187. !DirectoryExists(FileName))
  2188. {
  2189. UnicodeString RemoteDir =
  2190. UnixExtractFileDir(
  2191. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2192. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2193. TDateTime NewTime;
  2194. if (FileAge(FileName, NewTime) &&
  2195. (NewTime != RemoteFileTimes[Index]))
  2196. {
  2197. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2198. TemporaryFileCopyParam(CopyParam);
  2199. CopyParam.FileMask = L"";
  2200. FAutoOperation = true;
  2201. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2202. TemporaryFilesList->Add(FileName);
  2203. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. __finally
  2210. {
  2211. FAutoOperation = false;
  2212. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2213. {
  2214. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2215. }
  2216. }
  2217. }
  2218. __finally
  2219. {
  2220. if (RemoteFileList != FileList)
  2221. {
  2222. delete RemoteFileList;
  2223. }
  2224. if (LocalFileList != ALocalFileList)
  2225. {
  2226. delete LocalFileList;
  2227. }
  2228. if (RemoteFileListFull != RemoteFileList)
  2229. {
  2230. delete RemoteFileListFull;
  2231. }
  2232. }
  2233. }
  2234. //---------------------------------------------------------------------------
  2235. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2236. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2237. bool FileListCommand, UnicodeString * POutput)
  2238. {
  2239. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2240. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2241. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2242. {
  2243. UnicodeString FileName = SelectedFileList->Strings[Index];
  2244. if (DirectoryExists(FileName))
  2245. {
  2246. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2247. {
  2248. LocalFileList->Add(FileName);
  2249. }
  2250. if (FLAGSET(ACommand.Params, ccRecursive))
  2251. {
  2252. TMakeLocalFileListParams MakeFileListParam;
  2253. MakeFileListParam.FileList = LocalFileList.get();
  2254. MakeFileListParam.FileTimes = NULL;
  2255. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2256. MakeFileListParam.Recursive = true;
  2257. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2258. }
  2259. }
  2260. else
  2261. {
  2262. LocalFileList->Add(FileName);
  2263. }
  2264. }
  2265. UnicodeString RemotePath;
  2266. if (Terminal != NULL)
  2267. {
  2268. RemotePath = Terminal->CurrentDirectory;
  2269. }
  2270. if (FileListCommand)
  2271. {
  2272. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2273. TLocalCustomCommand CustomCommand(
  2274. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2275. L"", L"", FileList);
  2276. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2277. }
  2278. else
  2279. {
  2280. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2281. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2282. DebugAssert(FProgressForm != NULL);
  2283. FProgressForm->ReadOnly = true;
  2284. try
  2285. {
  2286. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2287. {
  2288. UnicodeString FileName = LocalFileList->Strings[Index];
  2289. Progress.SetFile(FileName);
  2290. TLocalCustomCommand CustomCommand(
  2291. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2292. FileName, L"", L"");
  2293. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2294. TOnceDoneOperation OnceDoneOperation;
  2295. Progress.Finish(FileName, true, OnceDoneOperation);
  2296. }
  2297. }
  2298. __finally
  2299. {
  2300. Progress.Stop();
  2301. }
  2302. }
  2303. }
  2304. //---------------------------------------------------------------------------
  2305. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2306. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2307. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2308. {
  2309. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2310. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2311. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2312. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2313. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2314. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2315. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2316. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2317. std::unique_ptr<UnicodeString> POutput;
  2318. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2319. FLAGSET(ACommand.Params, ccCopyResults))
  2320. {
  2321. POutput.reset(new UnicodeString());
  2322. }
  2323. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2324. FProgressSide = FCurrentSide;
  2325. if (!LocalCustomCommand.IsFileCommand(Command))
  2326. {
  2327. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2328. }
  2329. // remote files?
  2330. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2331. {
  2332. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2333. }
  2334. // local files
  2335. else
  2336. {
  2337. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2338. }
  2339. if (POutput.get() != NULL)
  2340. {
  2341. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2342. int P = POutput->Pos(sLineBreak);
  2343. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2344. {
  2345. POutput->SetLength(P - 1);
  2346. }
  2347. // Copy even empty output to clipboard
  2348. if (FLAGSET(ACommand.Params, ccCopyResults))
  2349. {
  2350. CopyToClipboard(*POutput);
  2351. }
  2352. // But do not show an empty message box.
  2353. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2354. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2355. !POutput->IsEmpty())
  2356. {
  2357. TClipboardHandler ClipboardHandler;
  2358. ClipboardHandler.Text = *POutput;
  2359. TMessageParams Params;
  2360. TQueryButtonAlias Aliases[1];
  2361. Aliases[0].Button = qaRetry;
  2362. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2363. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2364. Params.Aliases = Aliases;
  2365. Params.AliasesCount = LENOF(Aliases);
  2366. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2367. }
  2368. }
  2369. }
  2370. //---------------------------------------------------------------------------
  2371. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2372. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2373. {
  2374. TCustomCommandData Data;
  2375. UnicodeString Site;
  2376. UnicodeString RemotePath;
  2377. if (HasActiveTerminal())
  2378. {
  2379. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2380. Data = TCustomCommandData(SessionData.get());
  2381. Site = Terminal->SessionData->SessionKey;
  2382. RemotePath = Terminal->CurrentDirectory;
  2383. }
  2384. UnicodeString HelpKeyword = ACommand.HomePage;
  2385. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2386. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2387. {
  2388. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2389. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2390. {
  2391. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2392. }
  2393. else
  2394. {
  2395. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2396. }
  2397. if (!DoCustomCommandOptionsDialog(
  2398. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2399. {
  2400. Abort();
  2401. }
  2402. }
  2403. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2404. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2405. {
  2406. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2407. }
  2408. else
  2409. {
  2410. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2411. }
  2412. }
  2413. //---------------------------------------------------------------------------
  2414. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2415. const TCustomCommandType & Command)
  2416. {
  2417. DebugAssert(FCustomCommandLocalFileList != NULL);
  2418. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2419. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2420. TStrings * LocalFileList = new TStringList();
  2421. TStrings * RemoteFileList = new TStringList();
  2422. try
  2423. {
  2424. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2425. {
  2426. LocalFileList->Clear();
  2427. LocalFileList->AddObject(
  2428. FCustomCommandLocalFileList->Strings[Index],
  2429. FCustomCommandLocalFileList->Objects[Index]);
  2430. RemoteFileList->Clear();
  2431. RemoteFileList->AddObject(
  2432. FCustomCommandRemoteFileList->Strings[Index],
  2433. FCustomCommandRemoteFileList->Objects[Index]);
  2434. CustomCommand(RemoteFileList, Command, LocalFileList);
  2435. }
  2436. }
  2437. __finally
  2438. {
  2439. delete LocalFileList;
  2440. delete RemoteFileList;
  2441. }
  2442. }
  2443. //---------------------------------------------------------------------------
  2444. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2445. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2446. {
  2447. delete FCustomCommandLocalFileList;
  2448. delete FCustomCommandRemoteFileList;
  2449. // takeover ownership,
  2450. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2451. FCustomCommandLocalFileList = LocalFileList;
  2452. FCustomCommandRemoteFileList = RemoteFileList;
  2453. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2454. if (Button != NULL)
  2455. {
  2456. FCustomCommandMenu->Items->Clear();
  2457. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2458. MenuPopup(FCustomCommandMenu, Button);
  2459. }
  2460. else
  2461. {
  2462. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2463. }
  2464. }
  2465. //---------------------------------------------------------------------------
  2466. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2467. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2468. {
  2469. DebugAssert(FCapturedLog != NULL);
  2470. if ((OutputType == cotOutput) || (OutputType == cotError))
  2471. {
  2472. FCapturedLog->Add(AddedLine);
  2473. }
  2474. }
  2475. //---------------------------------------------------------------------------
  2476. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2477. TOperationSide Side)
  2478. {
  2479. return
  2480. (Side == osOther) &&
  2481. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2482. }
  2483. //---------------------------------------------------------------------------
  2484. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2485. TOperationSide Side, TTBXCustomItem * Item,
  2486. TResolvedDoubleClickAction DoubleClickAction1, TResolvedDoubleClickAction DoubleClickAction2)
  2487. {
  2488. TCustomDirView * DView = DirView(Side);
  2489. bool IsDefault = false;
  2490. if (DView->ItemFocused != NULL)
  2491. {
  2492. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  2493. TResolvedDoubleClickAction DefaultAction =
  2494. WinConfiguration->ResolveDoubleClickAction(DView->ItemIsDirectory(DView->ItemFocused), ATerminal);
  2495. IsDefault = (DefaultAction == DoubleClickAction1) || (DefaultAction == DoubleClickAction2);
  2496. }
  2497. TTBItemOptions O = Item->Options;
  2498. if (IsDefault)
  2499. {
  2500. Item->Options = O << tboDefault;
  2501. }
  2502. else
  2503. {
  2504. Item->Options = O >> tboDefault;
  2505. }
  2506. }
  2507. //---------------------------------------------------------------------------
  2508. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2509. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2510. {
  2511. TCustomDirView * DView = DirView(Side);
  2512. TListItem * Item = DView->ItemFocused;
  2513. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2514. EnableFocusedOperation[Side])
  2515. {
  2516. TPoint ClientPoint;
  2517. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2518. TPoint(0, 0) : MousePos;
  2519. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2520. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2521. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2522. }
  2523. }
  2524. //---------------------------------------------------------------------------
  2525. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2526. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2527. {
  2528. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, rdcaChangeDir, rdcaOpen);
  2529. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, rdcaEdit, rdcaNone);
  2530. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, rdcaCopy, rdcaNone);
  2531. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2532. Handled = true;
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2536. {
  2537. }
  2538. //---------------------------------------------------------------------------
  2539. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2540. {
  2541. DebugAssert(FErrorList == NULL);
  2542. if (WinConfiguration->ContinueOnError)
  2543. {
  2544. FErrorList = new TStringList();
  2545. Configuration->Usage->Inc(L"ContinuationsOnError");
  2546. }
  2547. NonVisualDataModule->StartBusy();
  2548. }
  2549. //---------------------------------------------------------------------------
  2550. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2551. {
  2552. NonVisualDataModule->EndBusy();
  2553. if (FErrorList)
  2554. {
  2555. HandleErrorList(FErrorList);
  2556. }
  2557. }
  2558. //---------------------------------------------------------------------------
  2559. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2560. const TCopyParamType & CopyParam)
  2561. {
  2562. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2563. {
  2564. Configuration->Usage->Inc(L"FileMaskUses");
  2565. }
  2566. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2567. {
  2568. Configuration->Usage->Inc(L"OperationMaskUses");
  2569. }
  2570. }
  2571. //---------------------------------------------------------------------------
  2572. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2573. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2574. {
  2575. DebugAssert(!IsLocalBrowserMode());
  2576. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2577. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2578. TTransferOperationParam DefaultParam;
  2579. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2580. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2581. switch (Param.Queue)
  2582. {
  2583. case asOn:
  2584. CopyParam.Queue = true;
  2585. break;
  2586. case asOff:
  2587. CopyParam.Queue = false;
  2588. break;
  2589. case asAuto:
  2590. default:
  2591. // keep default
  2592. break;
  2593. }
  2594. bool Result =
  2595. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2596. if (Result)
  2597. {
  2598. DebugAssert(Terminal);
  2599. bool SelectionRestored = false;
  2600. TCustomDirView * DView = NULL;
  2601. if (HasDirView[Side])
  2602. {
  2603. DView = DirView(Side);
  2604. DView->SaveSelection();
  2605. DView->SaveSelectedNames();
  2606. }
  2607. UpdateCopyParamCounters(CopyParam);
  2608. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2609. DebugAssert(FTransferResumeList == NULL);
  2610. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2611. FMoveToQueue = false;
  2612. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2613. try
  2614. {
  2615. TStrings * PermanentFileList;
  2616. std::unique_ptr<TStrings> PermanentFileListOwner;
  2617. try
  2618. {
  2619. if (Side == osLocal)
  2620. {
  2621. PermanentFileList = FileList;
  2622. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2623. CopyParam.IncludeFileMask.SetRoots(FileList, Param.TargetDirectory);
  2624. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2625. if (Operation == foMove)
  2626. {
  2627. ReloadLocalDirectory();
  2628. if (DView != NULL)
  2629. {
  2630. DView->RestoreSelection();
  2631. }
  2632. SelectionRestored = true;
  2633. }
  2634. }
  2635. else
  2636. {
  2637. // Clone the file list as it may refer to current directory files,
  2638. // which get destroyed, when the source directory is reloaded after foMove operation.
  2639. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2640. // But for a hotfix, we are not going to do such a big change.
  2641. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2642. PermanentFileList = PermanentFileListOwner.get();
  2643. try
  2644. {
  2645. CopyParam.IncludeFileMask.SetRoots(Param.TargetDirectory, FileList);
  2646. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2647. }
  2648. __finally
  2649. {
  2650. if (Operation == foMove)
  2651. {
  2652. if (DView != NULL)
  2653. {
  2654. DView->RestoreSelection();
  2655. }
  2656. SelectionRestored = true;
  2657. }
  2658. ReloadLocalDirectory(Param.TargetDirectory);
  2659. }
  2660. }
  2661. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2662. if (FMoveToQueue)
  2663. {
  2664. Abort();
  2665. }
  2666. }
  2667. catch (EAbort &)
  2668. {
  2669. if (FMoveToQueue)
  2670. {
  2671. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2672. DebugAssert(CopyParam.TransferSkipList == NULL);
  2673. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2674. if (TransferResumeList->Count > 0)
  2675. {
  2676. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2677. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2678. }
  2679. CopyParam.TransferSkipList = TransferResumeList.release();
  2680. // not really needed, just to keep it consistent with TransferResumeList
  2681. FTransferResumeList = NULL;
  2682. FMoveToQueue = false;
  2683. Configuration->Usage->Inc("MovesToBackground");
  2684. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2685. ClearTransferSourceSelection(Direction);
  2686. }
  2687. throw;
  2688. }
  2689. }
  2690. __finally
  2691. {
  2692. if (!SelectionRestored && (DView != NULL))
  2693. {
  2694. DView->DiscardSavedSelection();
  2695. }
  2696. FTransferResumeList = NULL;
  2697. }
  2698. }
  2699. return Result;
  2700. }
  2701. //---------------------------------------------------------------------------
  2702. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2703. TOperationSide Side, TStrings * FileList, void * Param)
  2704. {
  2705. DebugAssert(FileList->Count);
  2706. // We deliberately do not toggle alternative flag (Param), but use OR,
  2707. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2708. // shortcut of CurrentDeleteAlternativeAction
  2709. bool Alternative =
  2710. bool(Param) || UseAlternativeFunction();
  2711. bool Recycle;
  2712. if (IsSideLocalBrowser(Side))
  2713. {
  2714. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2715. }
  2716. else
  2717. {
  2718. Recycle =
  2719. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2720. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2721. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2722. }
  2723. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2724. if (!Result)
  2725. {
  2726. UnicodeString Query;
  2727. if (FileList->Count == 1)
  2728. {
  2729. if (IsSideLocalBrowser(Side))
  2730. {
  2731. Query = ExtractFileName(FileList->Strings[0]);
  2732. }
  2733. else
  2734. {
  2735. Query = UnixExtractFileName(FileList->Strings[0]);
  2736. }
  2737. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2738. }
  2739. else
  2740. {
  2741. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2742. }
  2743. TMessageParams Params(mpNeverAskAgainCheck);
  2744. Params.ImageName = L"Delete file";
  2745. unsigned int Answer =
  2746. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2747. if (Answer == qaNeverAskAgain)
  2748. {
  2749. Result = true;
  2750. if (Recycle)
  2751. {
  2752. WinConfiguration->ConfirmRecycling = false;
  2753. }
  2754. else
  2755. {
  2756. WinConfiguration->ConfirmDeleting = false;
  2757. }
  2758. }
  2759. else
  2760. {
  2761. Result = (Answer == qaOK);
  2762. }
  2763. }
  2764. if (Result)
  2765. {
  2766. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2767. }
  2768. return Result;
  2769. }
  2770. //---------------------------------------------------------------------------
  2771. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2772. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2773. {
  2774. TAutoBatch AutoBatch(this);
  2775. bool Result;
  2776. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2777. {
  2778. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2779. }
  2780. else if (Operation == foRename)
  2781. {
  2782. DebugAssert(DirView(Side)->ItemFocused);
  2783. DirView(Side)->ItemFocused->EditCaption();
  2784. Result = true;
  2785. }
  2786. else if (Operation == foDelete)
  2787. {
  2788. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2789. }
  2790. else if (Operation == foSetProperties)
  2791. {
  2792. DirView(osRemote)->SaveSelectedNames();
  2793. Result = SetProperties(Side, FileList);
  2794. }
  2795. else if (Operation == foCustomCommand)
  2796. {
  2797. DebugAssert(Param);
  2798. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2799. DirView(osRemote)->SaveSelectedNames();
  2800. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2801. CustomCommand(FileList, *Command, NULL);
  2802. Result = true;
  2803. }
  2804. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2805. {
  2806. DebugAssert(!IsSideLocalBrowser(Side));
  2807. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2808. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2809. }
  2810. else if (Operation == foLock)
  2811. {
  2812. DebugAssert(!IsSideLocalBrowser(Side));
  2813. LockFiles(FileList, true);
  2814. Result = true;
  2815. }
  2816. else if (Operation == foUnlock)
  2817. {
  2818. DebugAssert(!IsSideLocalBrowser(Side));
  2819. LockFiles(FileList, false);
  2820. Result = true;
  2821. }
  2822. else
  2823. {
  2824. DebugFail();
  2825. }
  2826. return Result;
  2827. }
  2828. //---------------------------------------------------------------------------
  2829. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2830. {
  2831. if (Side == osCurrent)
  2832. {
  2833. Side = FCurrentSide;
  2834. }
  2835. return Side;
  2836. }
  2837. //---------------------------------------------------------------------------
  2838. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2839. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2840. {
  2841. Side = GetSide(Side);
  2842. bool FullPath = IsSideLocalBrowser(Side);
  2843. TCustomDirView * ADirView = DirView(Side);
  2844. std::unique_ptr<TStringList> FileList(new TStringList());
  2845. ADirView->CreateFileList(OnFocused, FullPath, FileList.get());
  2846. bool ReloadProperties =
  2847. !IsSideLocalBrowser(Side) && (Operation == foSetProperties) &&
  2848. DebugAlwaysTrue(HasActiveTerminal()) && Terminal->IsCapable[fcLoadingAdditionalProperties];
  2849. bool Result = ExecuteFileOperation(Operation, Side, FileList.get(), NoConfirmation, Param);
  2850. if (Result && ReloadProperties)
  2851. {
  2852. std::unique_ptr<TStringList> FileList2(new TStringList());
  2853. FileList->CaseSensitive = true;
  2854. FileList->Sort();
  2855. for (int Index = 0; Index < ADirView->Items->Count; Index++)
  2856. {
  2857. TListItem * Item = ADirView->Items->Item[Index];
  2858. UnicodeString FileName = ADirView->ItemFileName(Item);
  2859. int Index2;
  2860. if (FileList->Find(FileName, Index2))
  2861. {
  2862. FileList2->AddObject(FileName, ADirView->ItemData(Item));
  2863. }
  2864. }
  2865. LoadFilesProperties(FileList2.get());
  2866. }
  2867. return Result;
  2868. }
  2869. //---------------------------------------------------------------------------
  2870. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2871. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2872. bool NoConfirmation, void * Param)
  2873. {
  2874. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2875. {
  2876. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2877. {
  2878. DebugAssert(!IsLocalBrowserMode());
  2879. if (GetSide(Side) == osLocal)
  2880. {
  2881. Configuration->Usage->Inc(L"UploadsCommand");
  2882. }
  2883. else
  2884. {
  2885. Configuration->Usage->Inc(L"DownloadsCommand");
  2886. }
  2887. }
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2892. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2893. {
  2894. TTransferOperationParam Param;
  2895. if ((WinConfiguration->Interface != ifCommander) ||
  2896. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2897. {
  2898. Flags &= ~cocShortCutHint;
  2899. }
  2900. TCustomDirView * DView = DirView(Side);
  2901. Param.Options =
  2902. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2903. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2904. if (FLAGSET(Flags, cocQueue))
  2905. {
  2906. Param.Queue = asOn;
  2907. }
  2908. else if (FLAGSET(Flags, cocNonQueue))
  2909. {
  2910. Param.Queue = asOff;
  2911. }
  2912. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2913. }
  2914. //---------------------------------------------------------------------------
  2915. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2916. {
  2917. int Count = ErrorList->Count;
  2918. try
  2919. {
  2920. if (ErrorList->Count)
  2921. {
  2922. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2923. if (MessageDialog(Message, qtError,
  2924. qaOK | qaCancel, HELP_NONE) == qaOK)
  2925. {
  2926. unsigned int Answer;
  2927. int Index = 0;
  2928. do
  2929. {
  2930. DebugAssert(Index >= 0 && Index < Count);
  2931. TQueryButtonAlias Aliases[2];
  2932. Aliases[0].Button = qaYes;
  2933. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2934. Aliases[1].Button = qaNo;
  2935. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2936. TMessageParams Params;
  2937. Params.Aliases = Aliases;
  2938. Params.AliasesCount = LENOF(Aliases);
  2939. int No = Index + 1;
  2940. UnicodeString Message = ErrorList->Strings[Index];
  2941. UnicodeString AMainInstructions;
  2942. UnicodeString Details;
  2943. if (ExtractMainInstructions(Message, AMainInstructions))
  2944. {
  2945. Details = Message;
  2946. Message = AMainInstructions;
  2947. }
  2948. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  2949. Answer = MoreMessageDialog(
  2950. Message,
  2951. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2952. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  2953. qaOK, HELP_NONE, &Params);
  2954. if (Answer == qaNo)
  2955. {
  2956. Index++;
  2957. }
  2958. if (Answer == qaYes)
  2959. {
  2960. Index--;
  2961. }
  2962. }
  2963. while (Answer != qaOK);
  2964. }
  2965. }
  2966. }
  2967. __finally
  2968. {
  2969. TStrings * List = ErrorList;
  2970. ErrorList = NULL;
  2971. for (int i = 0; i < Count; i++)
  2972. {
  2973. delete List->Objects[i];
  2974. }
  2975. delete List;
  2976. }
  2977. }
  2978. //---------------------------------------------------------------------------
  2979. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2980. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2981. {
  2982. // needed for checking filemasks, as there's no directory object
  2983. // associated with the file object
  2984. File->FullFileName = FullFileName;
  2985. TFileMasks::TParams MaskParams;
  2986. MaskParams.Size = File->Size;
  2987. MaskParams.Modification = File->Modification;
  2988. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2989. }
  2990. //---------------------------------------------------------------------------
  2991. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2992. {
  2993. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2994. Side = GetSide(Side);
  2995. TCustomDirView * DView = DirView(Side);
  2996. TListItem * FocusedItem = DView->ItemFocused;
  2997. UnicodeString Name;
  2998. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2999. {
  3000. Name = DView->ItemFileName(FocusedItem);
  3001. }
  3002. else
  3003. {
  3004. Name = LoadStr(NEW_FILE);
  3005. }
  3006. UnicodeString Names = Name;
  3007. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  3008. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  3009. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  3010. {
  3011. while (!Names.IsEmpty())
  3012. {
  3013. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  3014. CustomWinConfiguration->History[L"EditFile"] = History.get();
  3015. UnicodeString TargetFileName;
  3016. UnicodeString LocalFileName;
  3017. UnicodeString RootTempDir;
  3018. UnicodeString TempDir;
  3019. UnicodeString RemoteDirectory;
  3020. bool ExistingFile = false;
  3021. if (!IsSideLocalBrowser(Side))
  3022. {
  3023. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  3024. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(Name));
  3025. if ((File.get() != NULL) &&
  3026. !File->IsDirectory)
  3027. {
  3028. ExecuteRemoteFile(Name, File.get(), efDefaultEditor);
  3029. ExistingFile = true;
  3030. }
  3031. File.reset(NULL);
  3032. if (!ExistingFile)
  3033. {
  3034. RemoteDirectory = UnixExtractFilePath(Name);
  3035. TemporaryDirectoryForRemoteFiles(
  3036. RemoteDirectory, GUIConfiguration->CurrentCopyParam, false, TempDir, RootTempDir);
  3037. TargetFileName = UnixExtractFileName(Name);
  3038. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3039. LocalFileName = TempDir +
  3040. // We probably do not want to trim the VMS version here
  3041. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  3042. }
  3043. }
  3044. else
  3045. {
  3046. if (ExtractFilePath(Name).IsEmpty())
  3047. {
  3048. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  3049. }
  3050. else
  3051. {
  3052. LocalFileName = ExpandFileName(Name);
  3053. }
  3054. TargetFileName = ExtractFileName(Name);
  3055. }
  3056. if (!ExistingFile)
  3057. {
  3058. bool NewFile = !FileExists(ApiPath(LocalFileName));
  3059. if (NewFile)
  3060. {
  3061. int File = FileCreate(ApiPath(LocalFileName));
  3062. if (File < 0)
  3063. {
  3064. if (!RootTempDir.IsEmpty())
  3065. {
  3066. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3067. }
  3068. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  3069. }
  3070. else
  3071. {
  3072. FileClose(File);
  3073. }
  3074. }
  3075. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  3076. const TEditorData * ExternalEditor = NULL;
  3077. TFileMasks::TParams MaskParams; // size not known
  3078. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  3079. false, MaskParams);
  3080. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  3081. ExternalEditor, RootTempDir, RemoteDirectory, NewFile, TDateTime());
  3082. }
  3083. }
  3084. }
  3085. }
  3086. //---------------------------------------------------------------------------
  3087. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  3088. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  3089. {
  3090. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3091. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3092. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3093. return
  3094. ((ExecuteFileBy == efInternalEditor)) ||
  3095. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  3096. }
  3097. //---------------------------------------------------------------------------
  3098. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3099. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3100. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3101. UnicodeString RemoteDirectory, bool NewFile, const TDateTime & SourceTimestamp)
  3102. {
  3103. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3104. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3105. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3106. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3107. Side = GetSide(Side);
  3108. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3109. if (!IsSideLocalBrowser(Side))
  3110. {
  3111. Data->Terminal = Terminal;
  3112. Data->Queue = Queue;
  3113. Data->SessionData = CloneCurrentSessionData();
  3114. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3115. Data->RemoteDirectory = RemoteDirectory;
  3116. Data->SessionName = Terminal->SessionData->SessionName;
  3117. Data->LocalRootDirectory = LocalRootDirectory;
  3118. Data->OriginalFileName = OriginalFileName;
  3119. Data->Command = L""; // will be changed later for external editor
  3120. // Empty SourceTimestamp indicates that checking was disabled when the file was opened
  3121. if (WinConfiguration->EditorCheckNotModified)
  3122. {
  3123. Data->SourceTimestamp = SourceTimestamp;
  3124. }
  3125. }
  3126. if (ExecuteFileBy == efInternalEditor)
  3127. {
  3128. if (!IsSideLocalBrowser(Side))
  3129. {
  3130. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3131. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3132. TForm * Editor;
  3133. try
  3134. {
  3135. Editor =
  3136. ShowEditorForm(
  3137. FileName, this,
  3138. FEditorManager->FileChanged, FEditorManager->FileReload, FEditorManager->FileClosed,
  3139. SaveAllInternalEditors, AnyInternalEditorModified,
  3140. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3141. }
  3142. catch(...)
  3143. {
  3144. if (!LocalRootDirectory.IsEmpty())
  3145. {
  3146. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  3147. }
  3148. throw;
  3149. }
  3150. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3151. AppLogFmt(L"Opened internal editor with \"%s\"", (FileName));
  3152. }
  3153. else
  3154. {
  3155. DebugAssert(!StandaloneOperation);
  3156. TForm * Editor =
  3157. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3158. SaveAllInternalEditors, AnyInternalEditorModified,
  3159. L"", false, SessionColor, -1, NewFile);
  3160. FLocalEditors->Add(Editor);
  3161. }
  3162. }
  3163. else
  3164. {
  3165. HANDLE Process;
  3166. if (ExecuteFileBy == efExternalEditor)
  3167. {
  3168. UnicodeString Program, Params, Dir;
  3169. Data->Command = ExternalEditor->ExternalEditor;
  3170. ReformatFileNameCommand(Data->Command);
  3171. SplitCommand(Data->Command, Program, Params, Dir);
  3172. Params = ExpandFileNameCommand(Params, FileName);
  3173. Program = ExpandEnvironmentVariables(Program);
  3174. if (!ExecuteShell(Program, Params, Process))
  3175. {
  3176. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3177. }
  3178. }
  3179. else
  3180. {
  3181. DebugAssert(!IsSideLocalBrowser(Side));
  3182. if (!ExecuteShell(FileName, L"", Process))
  3183. {
  3184. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3185. }
  3186. }
  3187. if (IsSideLocalBrowser(Side) ||
  3188. ((ExecuteFileBy == efShell) &&
  3189. !WinConfiguration->Editor.SDIShellEditor) ||
  3190. ((ExecuteFileBy == efExternalEditor) &&
  3191. !ExternalEditor->SDIExternalEditor))
  3192. {
  3193. // no need for handle
  3194. if (Process != NULL)
  3195. {
  3196. DebugCheck(CloseHandle(Process));
  3197. }
  3198. Process = INVALID_HANDLE_VALUE;
  3199. }
  3200. else
  3201. {
  3202. if (Process == NULL)
  3203. {
  3204. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3205. }
  3206. }
  3207. if (!IsSideLocalBrowser(Side))
  3208. {
  3209. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3210. AppLogFmt(L"Opened external editor with remote file \"%s\".", (FileName));
  3211. }
  3212. }
  3213. }
  3214. //---------------------------------------------------------------------------
  3215. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3216. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3217. void * /*Arg*/)
  3218. {
  3219. if (Token != NULL)
  3220. {
  3221. EditorFormFileSave(static_cast<TForm *>(Token));
  3222. }
  3223. }
  3224. //---------------------------------------------------------------------------
  3225. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3226. {
  3227. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3228. {
  3229. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3230. }
  3231. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3232. }
  3233. //---------------------------------------------------------------------------
  3234. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3235. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3236. void * Arg)
  3237. {
  3238. if ((Token != NULL) &&
  3239. IsEditorFormModified(static_cast<TForm *>(Token)))
  3240. {
  3241. *static_cast<bool *>(Arg) = true;
  3242. }
  3243. }
  3244. //---------------------------------------------------------------------------
  3245. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3246. TObject * /*Sender*/, bool & Modified)
  3247. {
  3248. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3249. {
  3250. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3251. {
  3252. Modified = true;
  3253. }
  3254. }
  3255. if (!Modified)
  3256. {
  3257. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3258. }
  3259. }
  3260. //---------------------------------------------------------------------------
  3261. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3262. {
  3263. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3264. }
  3265. //---------------------------------------------------------------------------
  3266. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3267. const UnicodeString & RemoteDirectory, const TCopyParamType & CopyParam, bool Simple,
  3268. UnicodeString & Result, UnicodeString & RootDirectory)
  3269. {
  3270. if (!WinConfiguration->TemporaryDirectoryDeterministic || Simple)
  3271. {
  3272. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3273. Result = RootDirectory;
  3274. }
  3275. else
  3276. {
  3277. RootDirectory = L"";
  3278. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3279. Result = IncludeTrailingBackslash(Result);
  3280. }
  3281. if (WinConfiguration->TemporaryDirectoryAppendSession && !Simple)
  3282. {
  3283. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3284. }
  3285. if (WinConfiguration->TemporaryDirectoryAppendPath && !Simple)
  3286. {
  3287. UnicodeString ARemoteDirectory = RemoteDirectory;
  3288. if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory[1] == L'/'))
  3289. {
  3290. ARemoteDirectory.Delete(1, 1);
  3291. }
  3292. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(ARemoteDirectory)));
  3293. }
  3294. if (!ForceDirectories(ApiPath(Result)))
  3295. {
  3296. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3297. }
  3298. }
  3299. //---------------------------------------------------------------------------
  3300. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3301. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3302. bool GetTargetNames, bool AutoOperation, bool SimpleTempDir)
  3303. {
  3304. DebugAssert(!IsLocalBrowserMode());
  3305. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3306. if (ForceText)
  3307. {
  3308. CopyParam.TransferMode = tmAscii;
  3309. }
  3310. TemporaryFileCopyParam(CopyParam);
  3311. if (TempDir.IsEmpty())
  3312. {
  3313. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, SimpleTempDir, TempDir, RootTempDir);
  3314. }
  3315. DebugAssert(!FAutoOperation);
  3316. FAutoOperation = AutoOperation;
  3317. Terminal->ExceptionOnFail = true;
  3318. try
  3319. {
  3320. try
  3321. {
  3322. // turn off confirmations, as for MDI editors we may possibly download
  3323. // the same file over
  3324. Terminal->CopyToLocal(
  3325. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3326. if (GetTargetNames)
  3327. {
  3328. for (int i = 0; i < FileList->Count; i++)
  3329. {
  3330. FileList->Strings[i] =
  3331. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3332. }
  3333. }
  3334. }
  3335. catch(...)
  3336. {
  3337. if (!RootTempDir.IsEmpty())
  3338. {
  3339. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3340. }
  3341. throw;
  3342. }
  3343. }
  3344. __finally
  3345. {
  3346. FAutoOperation = false;
  3347. Terminal->ExceptionOnFail = false;
  3348. }
  3349. }
  3350. //---------------------------------------------------------------------------
  3351. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3352. {
  3353. // Do not waste time checking for default editor list the next time,
  3354. // or testing if default editor is not notepad.
  3355. bool TryNextTime = false;
  3356. UnicodeString UsageState;
  3357. if (!WinConfiguration->EditorList->IsDefaultList())
  3358. {
  3359. UsageState = "H";
  3360. }
  3361. else
  3362. {
  3363. UnicodeString Executable;
  3364. UnicodeString ExecutableDescription;
  3365. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3366. {
  3367. UnicodeString Message =
  3368. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3369. unsigned int Answer =
  3370. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3371. if (Answer != qaOK)
  3372. {
  3373. UsageState = "R";
  3374. }
  3375. else
  3376. {
  3377. UsageState = "A";
  3378. TEditorData EditorData;
  3379. EditorData.Editor = edExternal;
  3380. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3381. EditorData.ExternalEditorOptionsAutodetect();
  3382. TEditorList EditorList;
  3383. EditorList = *WinConfiguration->EditorList;
  3384. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3385. WinConfiguration->EditorList = &EditorList;
  3386. }
  3387. }
  3388. }
  3389. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3390. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3391. }
  3392. //---------------------------------------------------------------------------
  3393. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3394. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3395. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3396. {
  3397. if (ExecuteFileBy == efDefaultEditor)
  3398. {
  3399. if (!WinConfiguration->OfferedEditorAutoConfig)
  3400. {
  3401. EditorAutoConfig();
  3402. }
  3403. const TEditorPreferences * Editor =
  3404. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3405. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3406. {
  3407. ExecuteFileBy = efInternalEditor;
  3408. ExternalEditor = NULL;
  3409. }
  3410. else if (Editor->Data->Editor == edOpen)
  3411. {
  3412. ExecuteFileBy = efShell;
  3413. ExternalEditor = NULL;
  3414. }
  3415. else
  3416. {
  3417. ExecuteFileBy = efExternalEditor;
  3418. ExternalEditor = Editor->Data;
  3419. }
  3420. }
  3421. }
  3422. //---------------------------------------------------------------------------
  3423. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3424. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3425. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3426. {
  3427. UnicodeString OriginalFileName;
  3428. UnicodeString LocalRootDirectory;
  3429. UnicodeString RemoteDirectory;
  3430. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3431. IsSideLocalBrowser(Side), MaskParams);
  3432. UnicodeString Counter;
  3433. UnicodeString LocalFileName;
  3434. bool Handled = false;
  3435. if (!IsSideLocalBrowser(Side))
  3436. {
  3437. // We need to trim VMS version here, so that we use name without version
  3438. // when uploading back to create a new version of the file
  3439. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3440. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3441. TObject * Token = NULL;
  3442. UnicodeString LocalDirectory;
  3443. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3444. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3445. LocalDirectory))
  3446. {
  3447. if (Token != NULL)
  3448. {
  3449. TForm * Form = dynamic_cast<TForm *>(Token);
  3450. if (Form->WindowState == wsMinimized)
  3451. {
  3452. ShowWindow(Form->Handle, SW_RESTORE);
  3453. }
  3454. else
  3455. {
  3456. Form->SetFocus();
  3457. }
  3458. Handled = true;
  3459. }
  3460. else
  3461. {
  3462. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3463. }
  3464. }
  3465. if (!Handled)
  3466. {
  3467. TStringList * FileList1 = new TStringList();
  3468. try
  3469. {
  3470. FileList1->AddObject(FullFileName, Object);
  3471. TemporarilyDownloadFiles(FileList1,
  3472. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3473. LocalRootDirectory, LocalDirectory, true, true, false);
  3474. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3475. }
  3476. __finally
  3477. {
  3478. delete FileList1;
  3479. }
  3480. switch (ExecuteFileBy)
  3481. {
  3482. case efShell:
  3483. Counter = "RemoteFilesExecuted";
  3484. break;
  3485. case efInternalEditor:
  3486. Counter = "RemoteFilesOpenedInInternalEditor";
  3487. break;
  3488. case efExternalEditor:
  3489. Counter = "RemoteFilesOpenedInExternalEditor";
  3490. break;
  3491. default:
  3492. DebugFail();
  3493. }
  3494. }
  3495. }
  3496. else
  3497. {
  3498. LocalFileName = FullFileName;
  3499. OriginalFileName = ExtractFileName(FullFileName);
  3500. switch (ExecuteFileBy)
  3501. {
  3502. case efShell:
  3503. Counter = "LocalFilesExecuted";
  3504. break;
  3505. case efInternalEditor:
  3506. Counter = "LocalFilesOpenedInInternalEditor";
  3507. break;
  3508. case efExternalEditor:
  3509. Counter = "LocalFilesOpenedInExternalEditor";
  3510. break;
  3511. default:
  3512. DebugFail();
  3513. }
  3514. }
  3515. if (!Handled)
  3516. {
  3517. Configuration->Usage->Inc(Counter);
  3518. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3519. ExternalEditor, LocalRootDirectory, RemoteDirectory, false, MaskParams.Modification);
  3520. }
  3521. }
  3522. //---------------------------------------------------------------------------
  3523. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3524. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3525. bool AllSelected, bool OnFocused)
  3526. {
  3527. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3528. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3529. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3530. Side = GetSide(Side);
  3531. TCustomDirView * DView = DirView(Side);
  3532. TStrings * FileList =
  3533. AllSelected ?
  3534. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3535. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3536. try
  3537. {
  3538. DebugAssert(AllSelected || (FileList->Count == 1));
  3539. for (int i = 0; i < FileList->Count; i++)
  3540. {
  3541. UnicodeString ListFileName = FileList->Strings[i];
  3542. UnicodeString FileNameOnly =
  3543. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3544. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3545. if (!DView->ItemIsDirectory(Item))
  3546. {
  3547. UnicodeString FullFileName;
  3548. if (!IsSideLocalBrowser(Side))
  3549. {
  3550. FullFileName = DirView(Side)->Path + ListFileName;
  3551. }
  3552. else
  3553. {
  3554. FullFileName = ListFileName;
  3555. }
  3556. TObject * Object = FileList->Objects[i];
  3557. TFileMasks::TParams MaskParams;
  3558. MaskParams.Size = DView->ItemFileSize(Item);
  3559. TDateTimePrecision Precision;
  3560. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3561. std::unique_ptr<TRemoteFile> File;
  3562. if (!IsSideLocalBrowser(Side))
  3563. {
  3564. File.reset(Terminal->TryReadFile(FullFileName));
  3565. if (File.get() != NULL)
  3566. {
  3567. File->FullFileName = FullFileName;
  3568. Object = File.get();
  3569. MaskParams.Size = File->Size;
  3570. MaskParams.Modification = File->Modification;
  3571. }
  3572. }
  3573. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName, Object, MaskParams);
  3574. }
  3575. }
  3576. }
  3577. __finally
  3578. {
  3579. delete FileList;
  3580. }
  3581. }
  3582. //---------------------------------------------------------------------------
  3583. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3584. {
  3585. CopyParam.FileNameCase = ncNoChange;
  3586. CopyParam.PreserveRights = false;
  3587. CopyParam.PreserveReadOnly = false;
  3588. CopyParam.ReplaceInvalidChars = true;
  3589. CopyParam.IncludeFileMask = TFileMasks();
  3590. CopyParam.NewerOnly = false;
  3591. CopyParam.FileMask = L"";
  3592. }
  3593. //---------------------------------------------------------------------------
  3594. bool TCustomScpExplorerForm::EditorCheckNotModified(const TEditedFileData * Data)
  3595. {
  3596. return WinConfiguration->EditorCheckNotModified && (Data->SourceTimestamp != TDateTime());
  3597. }
  3598. //---------------------------------------------------------------------------
  3599. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(
  3600. const UnicodeString & FileName, TEditedFileData * Data, HANDLE UploadCompleteEvent, bool & Retry)
  3601. {
  3602. TTerminalManager * Manager = TTerminalManager::Instance();
  3603. if (!IsActiveTerminal(Data->Terminal))
  3604. {
  3605. if (!NonVisualDataModule->Busy)
  3606. {
  3607. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3608. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3609. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3610. if (Data->Terminal == NULL)
  3611. {
  3612. TManagedTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3613. if (SameSiteTerminal != NULL)
  3614. {
  3615. UnicodeString Message =
  3616. FMTLOAD(EDIT_SESSION_REATTACH,
  3617. (FileNameOnly, Data->SessionName, FileNameOnly));
  3618. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3619. {
  3620. Data->Terminal = SameSiteTerminal;
  3621. Data->Queue = Manager->FindQueueForTerminal(SameSiteTerminal);
  3622. Data->SessionName = SameSiteTerminal->SessionData->SessionName;
  3623. // We might also overwrite session data
  3624. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3625. }
  3626. else
  3627. {
  3628. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3629. Abort();
  3630. }
  3631. }
  3632. }
  3633. // Foreground session should reconnect itself (except for those disconnected explicitly by the user)
  3634. else if (DebugAlwaysTrue(Terminal->Disconnected || (Terminal != Data->Terminal)))
  3635. {
  3636. UnicodeString Message =
  3637. MainInstructions(
  3638. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3639. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3640. {
  3641. if (Terminal->Disconnected)
  3642. {
  3643. Manager->ActiveSession = Terminal;
  3644. ReconnectSession();
  3645. DebugAssert(Terminal == Data->Terminal);
  3646. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3647. }
  3648. else
  3649. {
  3650. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3651. }
  3652. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3653. }
  3654. else
  3655. {
  3656. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3657. Abort();
  3658. }
  3659. }
  3660. }
  3661. if (!IsActiveTerminal(Data->Terminal))
  3662. {
  3663. Configuration->Usage->Inc(L"EditInactiveSession");
  3664. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3665. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3666. (ExtractFileName(FileName), Data->SessionName)));
  3667. }
  3668. }
  3669. if (EditorCheckNotModified(Data))
  3670. {
  3671. UnicodeString RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3672. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(RemoteFilePath));
  3673. if (File.get() != NULL)
  3674. {
  3675. AppLogFmt(L"Edited remote file timestamp: %s, Original timestamp: %s", (StandardTimestamp(File->Modification), StandardTimestamp(Data->SourceTimestamp)));
  3676. if (File->Modification != Data->SourceTimestamp)
  3677. {
  3678. UnicodeString Message = MainInstructions(LoadStr(EDIT_CHANGED_EXTERNALLY));
  3679. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) != qaOK)
  3680. {
  3681. Abort();
  3682. }
  3683. }
  3684. }
  3685. }
  3686. TStrings * FileList = new TStringList();
  3687. try
  3688. {
  3689. FileList->Add(FileName);
  3690. // Consider using the same settings (preset) as when the file was downloaded.
  3691. // More over this does not reflect the actual session that will do the upload.
  3692. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3693. TemporaryFileCopyParam(CopyParam);
  3694. if (Data->ForceText)
  3695. {
  3696. CopyParam.TransferMode = tmAscii;
  3697. }
  3698. // so i do not need to worry if masking algorithm works in all cases
  3699. // ("" means "copy file name", no masking is actually done)
  3700. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3701. {
  3702. CopyParam.FileMask = L"";
  3703. }
  3704. else
  3705. {
  3706. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3707. }
  3708. int Params = cpNoConfirmation | cpTemporary;
  3709. if (Data->Terminal->IsCapable[fcBackgroundTransfers])
  3710. {
  3711. DebugAssert(Data->Queue != NULL);
  3712. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3713. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3714. QueueItem->CompleteEvent = UploadCompleteEvent;
  3715. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3716. }
  3717. else
  3718. {
  3719. if (NonVisualDataModule->Busy)
  3720. {
  3721. Retry = true;
  3722. }
  3723. else
  3724. {
  3725. Data->Terminal->CopyToRemote(FileList, Data->RemoteDirectory, &CopyParam, Params, NULL);
  3726. SetEvent(UploadCompleteEvent);
  3727. }
  3728. }
  3729. }
  3730. __finally
  3731. {
  3732. delete FileList;
  3733. }
  3734. }
  3735. //---------------------------------------------------------------------------
  3736. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3737. const UnicodeString & FileName, TEditedFileData * Data)
  3738. {
  3739. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3740. DebugAssert(!NonVisualDataModule->Busy);
  3741. if (!IsActiveTerminal(Data->Terminal))
  3742. {
  3743. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3744. (ExtractFileName(FileName), Data->SessionName)));
  3745. }
  3746. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3747. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3748. NonVisualDataModule->StartBusy();
  3749. try
  3750. {
  3751. std::unique_ptr<TRemoteFile> File;
  3752. UnicodeString RemoteFileName =
  3753. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3754. Terminal->ExceptionOnFail = true;
  3755. try
  3756. {
  3757. File.reset(Terminal->ReadFile(RemoteFileName));
  3758. if (!File->HaveFullFileName)
  3759. {
  3760. File->FullFileName = RemoteFileName;
  3761. }
  3762. }
  3763. __finally
  3764. {
  3765. Terminal->ExceptionOnFail = false;
  3766. }
  3767. std::unique_ptr<TStrings> FileList(new TStringList());
  3768. FileList->AddObject(RemoteFileName, File.get());
  3769. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3770. UnicodeString TempDir = ExtractFilePath(FileName);
  3771. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir, TempDir, true, true, false);
  3772. if (EditorCheckNotModified(Data))
  3773. {
  3774. Data->SourceTimestamp = File->Modification;
  3775. }
  3776. // sanity check, the target file name should be still the same
  3777. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3778. }
  3779. __finally
  3780. {
  3781. NonVisualDataModule->EndBusy();
  3782. // it actually may not exist anymore...
  3783. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3784. }
  3785. }
  3786. //---------------------------------------------------------------------------
  3787. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3788. const TEditedFileData * Data, bool & KeepOpen)
  3789. {
  3790. // Command is set for external editors only (not for "shell" open).
  3791. if (!Data->Command.IsEmpty())
  3792. {
  3793. bool AnyFound = false;
  3794. bool AnyMDI = false;
  3795. bool AnyNonMDI = false;
  3796. bool AnyDetect = false;
  3797. TEditorList * EditorList = new TEditorList();
  3798. try
  3799. {
  3800. *EditorList = *WinConfiguration->EditorList;
  3801. for (int i = 0; i < EditorList->Count; i++)
  3802. {
  3803. const TEditorPreferences * Editor = EditorList->Editors[i];
  3804. if ((Editor->Data->Editor == edExternal) &&
  3805. (Editor->Data->ExternalEditor == Data->Command))
  3806. {
  3807. AnyFound = true;
  3808. if (Editor->Data->SDIExternalEditor)
  3809. {
  3810. AnyNonMDI = true;
  3811. if (Editor->Data->DetectMDIExternalEditor)
  3812. {
  3813. AnyDetect = true;
  3814. }
  3815. }
  3816. else
  3817. {
  3818. AnyMDI = true;
  3819. }
  3820. }
  3821. }
  3822. bool EnableMDI = false;
  3823. bool DisableDetect = false;
  3824. if (AnyMDI)
  3825. {
  3826. KeepOpen = true;
  3827. if (AnyNonMDI)
  3828. {
  3829. // there is at least one instance of the editor with MDI support enabled,
  3830. // and one with disabled, enable it for all instances
  3831. EnableMDI = true;
  3832. }
  3833. }
  3834. else if (AnyFound && !AnyDetect)
  3835. {
  3836. // at least once instance found but all have MDI autodetection disabled
  3837. // => close the file (default action)
  3838. }
  3839. else
  3840. {
  3841. // no instance of the editor has MDI support enabled
  3842. TMessageParams Params;
  3843. if (AnyFound)
  3844. {
  3845. // there is at least one instance of the editor
  3846. Params.Params |= mpNeverAskAgainCheck;
  3847. }
  3848. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3849. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3850. switch (Answer)
  3851. {
  3852. case qaNeverAskAgain:
  3853. DisableDetect = true;
  3854. break;
  3855. case qaNo:
  3856. EnableMDI = true;
  3857. KeepOpen = true;
  3858. break;
  3859. }
  3860. }
  3861. if (AnyFound && (EnableMDI || DisableDetect))
  3862. {
  3863. bool Changed = false;
  3864. for (int i = 0; i < EditorList->Count; i++)
  3865. {
  3866. const TEditorPreferences * Editor = EditorList->Editors[i];
  3867. if ((Editor->Data->Editor == edExternal) &&
  3868. (Editor->Data->ExternalEditor == Data->Command) &&
  3869. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3870. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3871. {
  3872. Changed = true;
  3873. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3874. if (EnableMDI)
  3875. {
  3876. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3877. }
  3878. if (DisableDetect)
  3879. {
  3880. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3881. }
  3882. EditorList->Change(i, UpdatedEditor);
  3883. }
  3884. }
  3885. if (Changed)
  3886. {
  3887. WinConfiguration->EditorList = EditorList;
  3888. }
  3889. }
  3890. }
  3891. __finally
  3892. {
  3893. delete EditorList;
  3894. }
  3895. }
  3896. else
  3897. {
  3898. // "open" case
  3899. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3900. qaOK, HELP_APP_EARLY_CLOSED);
  3901. }
  3902. }
  3903. //---------------------------------------------------------------------------
  3904. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TEditedFileData * Data, TObject * Sender, bool Failed)
  3905. {
  3906. if (!Failed && EditorCheckNotModified(Data))
  3907. {
  3908. UnicodeString RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3909. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(RemoteFilePath));
  3910. if (File.get() != NULL)
  3911. {
  3912. Data->SourceTimestamp = File->Modification;
  3913. AppLogFmt(L"Uploaded edited remote file timestamp: %s: ", (StandardTimestamp(Data->SourceTimestamp)));
  3914. }
  3915. }
  3916. if (Sender != NULL)
  3917. {
  3918. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3919. }
  3920. }
  3921. //---------------------------------------------------------------------------
  3922. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3923. {
  3924. SideEnter(osRemote);
  3925. }
  3926. //---------------------------------------------------------------------------
  3927. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3928. {
  3929. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3930. SideEnter(osRemote);
  3931. }
  3932. //---------------------------------------------------------------------------
  3933. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3934. {
  3935. FCurrentSide = Side;
  3936. if (Visible)
  3937. {
  3938. UpdateControls();
  3939. }
  3940. }
  3941. //---------------------------------------------------------------------------
  3942. void __fastcall TCustomScpExplorerForm::FileDeleted(TOperationSide Side, const UnicodeString & FileName, bool Success)
  3943. {
  3944. VisualiseOperationFinished(Side, FileName, Success);
  3945. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  3946. {
  3947. FDeletedFiles->Add(FileName);
  3948. }
  3949. }
  3950. //---------------------------------------------------------------------------
  3951. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3952. TStrings * FileList, bool Alternative)
  3953. {
  3954. TCustomDirView * DView = DirView(Side);
  3955. DView->SaveSelection();
  3956. DView->SaveSelectedNames();
  3957. DebugAssert(!FAlternativeDelete);
  3958. FAlternativeDelete = Alternative;
  3959. try
  3960. {
  3961. if (!IsSideLocalBrowser(Side))
  3962. {
  3963. DebugAssert(Terminal != NULL);
  3964. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  3965. std::unique_ptr<TStrings> PermanentFileList(TRemoteFileList::CloneStrings(FileList));
  3966. std::unique_ptr<TStringList> DeletedFiles(new TStringList());
  3967. DeletedFiles->CaseSensitive = DebugAlwaysTrue(!IsSideLocalBrowser(Side));
  3968. int Params = FLAGMASK(Alternative, dfAlternative);
  3969. try
  3970. {
  3971. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles);
  3972. DebugAssert(FDeletedFiles == NULL);
  3973. FDeletedFiles = DeletedFiles.get();
  3974. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  3975. FOnFileOperationFinished = FileDeleted;
  3976. FMoveToQueue = false;
  3977. Terminal->DeleteFiles(FileList, Params);
  3978. // Probably not needed for deleting, just for consistency with transfer code
  3979. if (FMoveToQueue)
  3980. {
  3981. Abort();
  3982. }
  3983. }
  3984. catch (EAbort &)
  3985. {
  3986. if (FMoveToQueue)
  3987. {
  3988. DeletedFiles->Sorted = true;
  3989. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  3990. {
  3991. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  3992. {
  3993. // We should always be deleting the first item => what can be used to optimize this code, if needed
  3994. DebugAssert(Index == 0);
  3995. PermanentFileList->Delete(Index);
  3996. Index--;
  3997. }
  3998. }
  3999. Configuration->Usage->Inc("MovesToBackgroundDelete");
  4000. TQueueItem * QueueItem = new TDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  4001. AddQueueItem(Queue, QueueItem, Terminal);
  4002. ClearOperationSelection(osRemote);
  4003. }
  4004. }
  4005. }
  4006. else
  4007. {
  4008. if (IsLocalBrowserMode())
  4009. {
  4010. Configuration->Usage->Inc(L"LocalLocalDeletes");
  4011. }
  4012. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  4013. FProgressSide = FCurrentSide;
  4014. try
  4015. {
  4016. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  4017. }
  4018. __finally
  4019. {
  4020. ReloadLocalDirectory();
  4021. }
  4022. }
  4023. FAlternativeDelete = false;
  4024. }
  4025. catch(...)
  4026. {
  4027. FAlternativeDelete = false;
  4028. DView->DiscardSavedSelection();
  4029. throw;
  4030. }
  4031. DView->RestoreSelection();
  4032. }
  4033. //---------------------------------------------------------------------------
  4034. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  4035. {
  4036. DebugAssert(Terminal);
  4037. DebugAssert(!IsLocalBrowserMode());
  4038. RemoteDirView->SaveSelection();
  4039. RemoteDirView->SaveSelectedNames();
  4040. try
  4041. {
  4042. if (Lock)
  4043. {
  4044. Terminal->LockFiles(FileList);
  4045. }
  4046. else
  4047. {
  4048. Terminal->UnlockFiles(FileList);
  4049. }
  4050. }
  4051. catch(...)
  4052. {
  4053. RemoteDirView->DiscardSavedSelection();
  4054. throw;
  4055. }
  4056. RemoteDirView->RestoreSelection();
  4057. }
  4058. //---------------------------------------------------------------------------
  4059. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  4060. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  4061. bool NoConfirmation, bool Move)
  4062. {
  4063. DebugAssert(Terminal != NULL);
  4064. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  4065. DebugAssert(!IsLocalBrowserMode());
  4066. if (Session == NULL)
  4067. {
  4068. Session = Terminal;
  4069. }
  4070. if (Session == Terminal)
  4071. {
  4072. if (RemoteDriveView->DropTarget != NULL)
  4073. {
  4074. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  4075. }
  4076. else if (RemoteDirView->DropTarget != NULL)
  4077. {
  4078. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  4079. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  4080. }
  4081. else
  4082. {
  4083. Target = RemoteDirView->Path;
  4084. }
  4085. }
  4086. else
  4087. {
  4088. Target = GetSessionPath(Session, osRemote);
  4089. }
  4090. Target = UnixIncludeTrailingBackslash(Target);
  4091. if (FileList->Count == 1)
  4092. {
  4093. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  4094. }
  4095. else
  4096. {
  4097. FileMask = AnyMask;
  4098. }
  4099. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  4100. bool Result = true;
  4101. if (!NoConfirmation)
  4102. {
  4103. bool Multi = (FileList->Count > 1);
  4104. if (Move)
  4105. {
  4106. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  4107. }
  4108. else
  4109. {
  4110. std::unique_ptr<TStrings> Sessions(new TStringList);
  4111. std::unique_ptr<TStrings> Directories(new TStringList);
  4112. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  4113. for (int Index = 0; Index < SessionList->Count; Index++)
  4114. {
  4115. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  4116. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  4117. {
  4118. Sessions->AddObject(SessionList->Strings[Index], ASession);
  4119. Directories->Add(GetSessionPath(ASession, osRemote));
  4120. }
  4121. }
  4122. TDirectRemoteCopy AllowDirectCopy;
  4123. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  4124. {
  4125. DebugAssert(DirectCopy);
  4126. AllowDirectCopy = drcAllow;
  4127. }
  4128. else if (Terminal->IsCapable[fcSecondaryShell])
  4129. {
  4130. DebugAssert(DirectCopy);
  4131. AllowDirectCopy = drcConfirmCommandSession;
  4132. }
  4133. else
  4134. {
  4135. DebugAssert(!DirectCopy);
  4136. AllowDirectCopy = drcDisallow;
  4137. }
  4138. void * ASession = Session;
  4139. Result = DoRemoteCopyDialog(
  4140. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal);
  4141. Session = static_cast<TManagedTerminal *>(ASession);
  4142. }
  4143. }
  4144. return Result;
  4145. }
  4146. //---------------------------------------------------------------------------
  4147. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  4148. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  4149. {
  4150. DebugAssert(!IsLocalBrowserMode());
  4151. bool DirectCopy;
  4152. UnicodeString Target, FileMask;
  4153. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  4154. if (Result)
  4155. {
  4156. if (!Move && !DirectCopy)
  4157. {
  4158. Configuration->Usage->Inc("RemoteCopyTemp");
  4159. UnicodeString RootTempDir;
  4160. UnicodeString TempDir;
  4161. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  4162. TStrings * TemporaryFilesList = new TStringList();
  4163. try
  4164. {
  4165. TMakeLocalFileListParams MakeFileListParam;
  4166. MakeFileListParam.FileList = TemporaryFilesList;
  4167. MakeFileListParam.FileTimes = NULL;
  4168. MakeFileListParam.IncludeDirs = true;
  4169. MakeFileListParam.Recursive = false;
  4170. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4171. TTerminalManager::Instance()->ActiveSession = Session;
  4172. if (TemporaryFilesList->Count > 0)
  4173. {
  4174. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4175. CopyParam.FileMask = FileMask;
  4176. DebugAssert(!FAutoOperation);
  4177. FAutoOperation = true;
  4178. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4179. }
  4180. }
  4181. __finally
  4182. {
  4183. delete TemporaryFilesList;
  4184. FAutoOperation = false;
  4185. if (!RootTempDir.IsEmpty())
  4186. {
  4187. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  4188. }
  4189. }
  4190. }
  4191. else
  4192. {
  4193. RemoteDirView->SaveSelection();
  4194. RemoteDirView->SaveSelectedNames();
  4195. try
  4196. {
  4197. if (Move)
  4198. {
  4199. Configuration->Usage->Inc("RemoteMove");
  4200. Terminal->MoveFiles(FileList, Target, FileMask, false);
  4201. }
  4202. else
  4203. {
  4204. Configuration->Usage->Inc("RemoteCopyDirect");
  4205. DebugAssert(DirectCopy);
  4206. DebugAssert(Session == Terminal);
  4207. if (Terminal->IsCapable[fcRemoteCopy] ||
  4208. Terminal->CommandSessionOpened ||
  4209. CommandSessionFallback())
  4210. {
  4211. Terminal->CopyFiles(FileList, Target, FileMask);
  4212. }
  4213. }
  4214. }
  4215. catch(...)
  4216. {
  4217. RemoteDirView->DiscardSavedSelection();
  4218. throw;
  4219. }
  4220. RemoteDirView->RestoreSelection();
  4221. }
  4222. }
  4223. return Result;
  4224. }
  4225. //---------------------------------------------------------------------------
  4226. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4227. const UnicodeString & Path, TRemoteProperties & Properties)
  4228. {
  4229. DebugAssert(!IsLocalBrowserMode());
  4230. Properties.Valid = Properties.Valid << vpEncrypt;
  4231. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4232. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4233. }
  4234. //---------------------------------------------------------------------------
  4235. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4236. {
  4237. Side = GetSide(Side);
  4238. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4239. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4240. UnicodeString Name = LoadStr(NEW_FOLDER);
  4241. int AllowedChanges =
  4242. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4243. bool SaveSettings = false;
  4244. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4245. {
  4246. TWindowLock Lock(this);
  4247. if (!IsSideLocalBrowser(Side))
  4248. {
  4249. if (SaveSettings)
  4250. {
  4251. GUIConfiguration->NewDirectoryProperties = Properties;
  4252. }
  4253. CreateRemoteDirectory(Name, Properties);
  4254. }
  4255. else
  4256. {
  4257. DirView(Side)->CreateDirectory(Name);
  4258. }
  4259. }
  4260. }
  4261. //---------------------------------------------------------------------------
  4262. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4263. {
  4264. TWindowLock Lock(this);
  4265. DirView(Side)->ExecuteHomeDirectory();
  4266. }
  4267. //---------------------------------------------------------------------------
  4268. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4269. {
  4270. DoOpenDirectoryDialog(odBrowse, Side);
  4271. }
  4272. //---------------------------------------------------------------------------
  4273. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4274. {
  4275. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4276. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4277. bool Result = !Path.IsEmpty();
  4278. if (Result)
  4279. {
  4280. TryOpenDirectory(Side, Path);
  4281. }
  4282. return Result;
  4283. }
  4284. //---------------------------------------------------------------------------
  4285. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4286. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4287. bool & Close)
  4288. {
  4289. // terminal can be already closed (e.g. dropped connection)
  4290. if (Terminal != NULL)
  4291. {
  4292. try
  4293. {
  4294. TCalculateSizeParams Params;
  4295. Params.Stats = &Stats;
  4296. Terminal->CalculateFilesSize(FileList, Size, Params);
  4297. }
  4298. catch(...)
  4299. {
  4300. if (!Terminal->Active)
  4301. {
  4302. Close = true;
  4303. }
  4304. throw;
  4305. }
  4306. }
  4307. }
  4308. //---------------------------------------------------------------------------
  4309. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4310. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4311. bool & Close)
  4312. {
  4313. if ((Terminal != NULL) && // terminal can be already closed (e.g. dropped connection)
  4314. EnsureCommandSessionFallback(fcCalculatingChecksum))
  4315. {
  4316. Configuration->Usage->Inc(L"ChecksumCalculated");
  4317. try
  4318. {
  4319. Terminal->CalculateFilesChecksum(Alg, FileList, OnCalculatedChecksum);
  4320. }
  4321. catch(...)
  4322. {
  4323. if (!Terminal->Active)
  4324. {
  4325. Close = true;
  4326. }
  4327. throw;
  4328. }
  4329. }
  4330. }
  4331. //---------------------------------------------------------------------------
  4332. void TCustomScpExplorerForm::LoadFilesProperties(TStrings * FileList)
  4333. {
  4334. if (Terminal->LoadFilesProperties(FileList))
  4335. {
  4336. RemoteDirView->Invalidate();
  4337. }
  4338. }
  4339. //---------------------------------------------------------------------------
  4340. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4341. {
  4342. bool Result;
  4343. if (!IsSideLocalBrowser(Side))
  4344. {
  4345. TRemoteTokenList * GroupList = NULL;
  4346. TRemoteTokenList * UserList = NULL;
  4347. try
  4348. {
  4349. TRemoteProperties CurrentProperties;
  4350. LoadFilesProperties(FileList);
  4351. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4352. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4353. if (CapableGroupChanging || CapableOwnerChanging)
  4354. {
  4355. if (CapableGroupChanging)
  4356. {
  4357. GroupList = Terminal->Groups->Duplicate();
  4358. }
  4359. if (CapableOwnerChanging)
  4360. {
  4361. UserList = Terminal->Users->Duplicate();
  4362. }
  4363. TRemoteDirectory * Files = Terminal->Files;
  4364. int Count = Files->Count;
  4365. if (Count > 100)
  4366. {
  4367. Count = 100;
  4368. }
  4369. for (int Index = 0; Index < Count; Index++)
  4370. {
  4371. TRemoteFile * File = Files->Files[Index];
  4372. if (CapableGroupChanging)
  4373. {
  4374. GroupList->AddUnique(File->Group);
  4375. }
  4376. if (CapableOwnerChanging)
  4377. {
  4378. UserList->AddUnique(File->Owner);
  4379. }
  4380. }
  4381. // if we haven't collected tokens for all files in current directory,
  4382. // make sure we collect them at least for all selected files.
  4383. // (note that so far the files in FileList has to be from current direcotry)
  4384. if (Count < Files->Count)
  4385. {
  4386. for (int Index = 0; Index < FileList->Count; Index++)
  4387. {
  4388. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4389. if (CapableGroupChanging)
  4390. {
  4391. GroupList->AddUnique(File->Group);
  4392. }
  4393. if (CapableOwnerChanging)
  4394. {
  4395. UserList->AddUnique(File->Owner);
  4396. }
  4397. }
  4398. }
  4399. }
  4400. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4401. bool CapableAclChanging = Terminal->IsCapable[fcAclChangingFiles];
  4402. for (int Index = 0; (Index < FileList->Count) && CapableAclChanging; Index++)
  4403. {
  4404. if (dynamic_cast<TRemoteFile *>(FileList->Objects[Index])->IsDirectory)
  4405. {
  4406. CapableAclChanging = false;
  4407. CurrentProperties.Valid = CurrentProperties.Valid >> vpRights;
  4408. }
  4409. }
  4410. int Flags = 0;
  4411. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4412. if (CapableAclChanging) Flags |= cpAcl;
  4413. if (CapableOwnerChanging) Flags |= cpOwner;
  4414. if (CapableGroupChanging) Flags |= cpGroup;
  4415. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4416. if (Terminal->IsCapable[fcCalculatingChecksum] ||
  4417. (Terminal->IsCapable[fcSecondaryShell] && !Terminal->IsEncryptingFiles()))
  4418. {
  4419. CalculateChecksumEvent = CalculateChecksum;
  4420. }
  4421. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4422. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4423. TRemoteProperties NewProperties = CurrentProperties;
  4424. Result =
  4425. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4426. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4427. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4428. CalculateSize, CalculateChecksumEvent);
  4429. if (Result)
  4430. {
  4431. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4432. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4433. }
  4434. }
  4435. __finally
  4436. {
  4437. delete GroupList;
  4438. delete UserList;
  4439. }
  4440. }
  4441. else
  4442. {
  4443. DirView(Side)->DisplayPropertiesMenu();
  4444. Result = true;
  4445. }
  4446. return Result;
  4447. }
  4448. //---------------------------------------------------------------------------
  4449. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4450. {
  4451. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4452. {
  4453. FIgnoreNextDialogChar = Key;
  4454. }
  4455. Key = 0;
  4456. }
  4457. //---------------------------------------------------------------------------
  4458. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4459. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4460. {
  4461. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4462. if (Command != NULL)
  4463. {
  4464. KeyProcessed(Key, Shift);
  4465. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4466. {
  4467. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4468. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4469. false, false, const_cast<TCustomCommandType *>(Command));
  4470. }
  4471. }
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4475. {
  4476. if (!NonVisualDataModule->Busy)
  4477. {
  4478. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4479. {
  4480. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4481. }
  4482. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4483. {
  4484. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4485. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4486. {
  4487. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4488. // But so far it's not a problem, as it does what we want.
  4489. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4490. if (((Action->ShortCut == KeyShortCut) ||
  4491. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4492. AllowedAction(Action, aaShortCut))
  4493. {
  4494. // Has to be called before the action as the dialog char is already in queue.
  4495. // So when the action consumes message queue, we already need to have the
  4496. // FIgnoreNextDialogChar set
  4497. KeyProcessed(Key, Shift);
  4498. // Reset reference to previous component (when menu/toolbar was clicked).
  4499. // Needed to detect that action was invoked by keyboard shortcut
  4500. // in TNonVisualDataModule::ExplorerActionsExecute
  4501. Action->ActionComponent = NULL;
  4502. Action->Execute();
  4503. return;
  4504. }
  4505. }
  4506. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4507. {
  4508. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4509. {
  4510. KeyProcessed(Key, Shift);
  4511. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4512. return;
  4513. }
  4514. }
  4515. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4516. {
  4517. KeyProcessed(Key, Shift);
  4518. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4519. }
  4520. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4521. if (IsCustomShortCut(CustomShortCut))
  4522. {
  4523. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4524. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4525. if (WinConfiguration->SharedBookmarks != NULL)
  4526. {
  4527. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4528. if ((Bookmark != NULL) &&
  4529. OpenBookmark(FCurrentSide, Bookmark))
  4530. {
  4531. KeyProcessed(Key, Shift);
  4532. }
  4533. }
  4534. }
  4535. }
  4536. }
  4537. TForm::KeyDown(Key, Shift);
  4538. }
  4539. //---------------------------------------------------------------------------
  4540. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4541. {
  4542. bool OpenedTerminal = false;
  4543. UnicodeString ProtocolName;
  4544. UnicodeString ProtocolNameHint;
  4545. UnicodeString SecurityProtocolName;
  4546. UnicodeString DurationHint;
  4547. // See the comment in TScpCommanderForm::UpdateControls()
  4548. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4549. if (ActiveTerminal != NULL)
  4550. {
  4551. // Active is not enough here
  4552. if (ActiveTerminal->Status == ssOpened)
  4553. {
  4554. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4555. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4556. if (FileSystemInfo.ProtocolName.IsEmpty())
  4557. {
  4558. ProtocolName = SessionInfo.ProtocolName;
  4559. }
  4560. else
  4561. {
  4562. ProtocolName = FileSystemInfo.ProtocolName;
  4563. }
  4564. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4565. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4566. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4567. OpenedTerminal = true;
  4568. }
  4569. else if (ActiveTerminal->Status > ssClosed)
  4570. {
  4571. ProtocolName = LoadStr(STATUS_CONNECTING);
  4572. }
  4573. else
  4574. {
  4575. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4576. }
  4577. }
  4578. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4579. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4580. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4581. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4582. if (ProtocolStatusPanel->Caption != ProtocolName)
  4583. {
  4584. ProtocolStatusPanel->Caption = ProtocolName;
  4585. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4586. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4587. }
  4588. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4589. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4590. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4591. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4592. SecurityStatusPanel->Enabled = SecurityEnabled;
  4593. UnicodeString SecurityProtocolHint;
  4594. if (SecurityEnabled)
  4595. {
  4596. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4597. }
  4598. else
  4599. {
  4600. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4601. }
  4602. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4603. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4604. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4605. DurationStatusPanel->Hint = DurationHint;
  4606. UpdateStatusBar();
  4607. }
  4608. //---------------------------------------------------------------------------
  4609. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4610. {
  4611. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4612. DebugAssert(SessionStatusBar != NULL);
  4613. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4614. if (!FNote.IsEmpty())
  4615. {
  4616. NoteStatusPanel->Caption = FNote;
  4617. }
  4618. else
  4619. {
  4620. UpdateStatusPanelText(NoteStatusPanel);
  4621. }
  4622. NoteStatusPanel->Hint = FNoteHints;
  4623. UnicodeString LoginTime;
  4624. // See the comment in TScpCommanderForm::UpdateControls()
  4625. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4626. // Active is not enough here
  4627. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4628. {
  4629. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4630. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4631. }
  4632. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4633. DurationStatusPanel->Caption = LoginTime;
  4634. }
  4635. //---------------------------------------------------------------------------
  4636. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4637. {
  4638. Panel->Caption = L"";
  4639. }
  4640. //---------------------------------------------------------------------------
  4641. void __fastcall TCustomScpExplorerForm::Idle()
  4642. {
  4643. if (FShowing ||
  4644. // Particularly for
  4645. // - Standalone editing
  4646. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4647. // while "keeping remote directory up to date".
  4648. StandaloneOperation)
  4649. {
  4650. FEditorManager->Check();
  4651. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4652. // that needs to know if queue view is visible (and it may be closed after queue update)
  4653. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4654. }
  4655. if (FShowing)
  4656. {
  4657. if (!NonVisualDataModule->Busy &&
  4658. // Menu is opened or drag&drop is going on
  4659. (Mouse->Capture == NULL))
  4660. {
  4661. if (FRefreshRemoteDirectory)
  4662. {
  4663. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4664. {
  4665. Terminal->RefreshDirectory();
  4666. }
  4667. FRefreshRemoteDirectory = false;
  4668. }
  4669. if (FRefreshLocalDirectory)
  4670. {
  4671. ReloadLocalDirectory();
  4672. FRefreshLocalDirectory = false;
  4673. }
  4674. if (WinConfiguration->RefreshRemotePanel)
  4675. {
  4676. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4677. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4678. {
  4679. RemoteDirView->ReloadDirectory();
  4680. }
  4681. }
  4682. }
  4683. // TB2 shows accels on Alt key down, but hides it only after menu modal loop finishes.
  4684. // But if Alt is used to switch apps or for keyboard shortcut, the menu modal loop does not happen and accelerators stay displayed.
  4685. // It's difficult to fix this in TB2, as there's no "up" equivalent to CM_DIALOGKEY, which shows the accels.
  4686. // And the Alt key can be released even when other window or application is active, so handling the key up in explorer window won't do either.
  4687. TTBCustomToolbar * MenuToolbar = DebugNotNull(dynamic_cast<TTBCustomToolbar *>(GetComponent(fcMenu)));
  4688. MenuToolbar->Idle();
  4689. }
  4690. if (FShowing || StandaloneOperation)
  4691. {
  4692. if (FQueueStatusInvalidated)
  4693. {
  4694. UpdateQueueStatus(false);
  4695. }
  4696. RefreshQueueItems();
  4697. }
  4698. if (FShowing)
  4699. {
  4700. UpdateStatusBar();
  4701. }
  4702. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4703. {
  4704. FClipboardFakeMonitorsPendingReset = false;
  4705. FClipboardFakeMonitors.reset(NULL);
  4706. }
  4707. FIgnoreNextDialogChar = 0;
  4708. }
  4709. //---------------------------------------------------------------------------
  4710. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4711. {
  4712. try
  4713. {
  4714. FUserActionTimer->Enabled = false;
  4715. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4716. {
  4717. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4718. {
  4719. FPendingQueueActionItem->ProcessUserAction();
  4720. }
  4721. }
  4722. }
  4723. __finally
  4724. {
  4725. FPendingQueueActionItem = NULL;
  4726. }
  4727. }
  4728. //---------------------------------------------------------------------------
  4729. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4730. {
  4731. if (WinConfiguration->MinimizeToTray)
  4732. {
  4733. UpdateTrayIcon();
  4734. FTrayIcon->Visible = true;
  4735. if (Visible)
  4736. {
  4737. ShowWindow(Handle, SW_HIDE);
  4738. }
  4739. }
  4740. }
  4741. //---------------------------------------------------------------------------
  4742. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4743. {
  4744. // WORKAROUND
  4745. // When restoring maximized window from minimization,
  4746. // rarely some controls do not align properly.
  4747. // Two instances seen (both for Commander):
  4748. // - When restoring, window is temporarily narrower (not maximized),
  4749. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4750. // Once maximized already, top dock shinks back, but the session PageControl,
  4751. // do not align up, leaving space between TopDock and PageControl.
  4752. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4753. for (int Index = 0; Index < ControlCount; Index++)
  4754. {
  4755. RealignControl(Controls[Index]);
  4756. }
  4757. if (FTrayIcon->Visible)
  4758. {
  4759. FTrayIcon->Visible = false;
  4760. if (Visible)
  4761. {
  4762. ShowWindow(Handle, SW_SHOW);
  4763. }
  4764. }
  4765. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4766. {
  4767. FNeedSession = false;
  4768. NonVisualDataModule->StartBusy();
  4769. try
  4770. {
  4771. NeedSession(true);
  4772. }
  4773. __finally
  4774. {
  4775. NonVisualDataModule->EndBusy();
  4776. }
  4777. }
  4778. }
  4779. //---------------------------------------------------------------------------
  4780. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4781. {
  4782. FTrayIcon->Hint = GetMainForm()->Caption;
  4783. }
  4784. //---------------------------------------------------------------------------
  4785. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4786. {
  4787. UpdateTrayIcon();
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4791. {
  4792. // workaround
  4793. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4794. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4795. // But WM_ACTIVATEAPP message can be received even when
  4796. // the main window is minimized to the tray and internal editor window is focused
  4797. // (after another application was previously active)
  4798. if (::IsIconic(Handle))
  4799. {
  4800. if (!IsAppIconic())
  4801. {
  4802. SetAppIconic(true);
  4803. }
  4804. }
  4805. ::ApplicationRestore();
  4806. Application->BringToFront();
  4807. }
  4808. //---------------------------------------------------------------------------
  4809. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4810. {
  4811. RestoreApp();
  4812. }
  4813. //---------------------------------------------------------------------------
  4814. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4815. {
  4816. if (OpenInNewWindow())
  4817. {
  4818. ExecuteNewInstance(SessionUrl);
  4819. }
  4820. else
  4821. {
  4822. TTerminalManager::Instance()->NewSession(SessionUrl);
  4823. }
  4824. }
  4825. //---------------------------------------------------------------------------
  4826. void TCustomScpExplorerForm::NewTab(TOperationSide, bool)
  4827. {
  4828. NewSession();
  4829. }
  4830. //---------------------------------------------------------------------------
  4831. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4832. {
  4833. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4834. StoredSessions->NewSession(SessionName, SessionData);
  4835. // modified only, explicit
  4836. StoredSessions->Save(false, true);
  4837. // encode session name because of slashes in hierarchical sessions
  4838. return EncodeUrlString(SessionName);
  4839. }
  4840. //---------------------------------------------------------------------------
  4841. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4842. {
  4843. // current working directories become defaults here, what is not right
  4844. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4845. return SaveHiddenDuplicateSession(SessionData.get());
  4846. }
  4847. //---------------------------------------------------------------------------
  4848. void __fastcall TCustomScpExplorerForm::DuplicateTab()
  4849. {
  4850. if (OpenInNewWindow())
  4851. {
  4852. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4853. }
  4854. else
  4855. {
  4856. // current working directories become defaults here, what is not right
  4857. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4858. TTerminalManager * Manager = TTerminalManager::Instance();
  4859. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  4860. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  4861. // We definitelly want these
  4862. ASession->Disconnected = ManagedSession->Disconnected;
  4863. // Not sure about these two
  4864. ASession->Permanent = ManagedSession->Permanent;
  4865. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  4866. Manager->ActiveSession = ASession;
  4867. }
  4868. }
  4869. //---------------------------------------------------------------------------
  4870. void __fastcall TCustomScpExplorerForm::RenameTab()
  4871. {
  4872. UnicodeString Name = ManagedSession->SessionData->SessionName;
  4873. if (InputDialog(LoadStr(RENAME_TAB_TITLE), LoadStr(RENAME_TAB_PROMPT), Name, HELP_TAB_RENAME) &&
  4874. // When submitting the default name, do not fix it
  4875. (Name != ManagedSession->SessionData->SessionName))
  4876. {
  4877. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4878. TSessionData::ValidateName(Name);
  4879. // This is inconsistent with how color (for example) is handled.
  4880. ManagedSession->SessionData->Name = Name;
  4881. UpdateControls();
  4882. // Add/Remove distinguishing paths from sessions of the same name.
  4883. SessionListChanged();
  4884. }
  4885. }
  4886. //---------------------------------------------------------------------------
  4887. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4888. {
  4889. DebugAssert(Queue != NULL);
  4890. bool Result = Queue->IsEmpty;
  4891. if (!Result)
  4892. {
  4893. SetFocus();
  4894. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4895. }
  4896. return Result;
  4897. }
  4898. //---------------------------------------------------------------------------
  4899. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4900. {
  4901. return CanCloseQueue(FQueue);
  4902. }
  4903. //---------------------------------------------------------------------------
  4904. void __fastcall TCustomScpExplorerForm::CloseTab()
  4905. {
  4906. if (CanCloseQueue())
  4907. {
  4908. TTerminalManager::Instance()->FreeActiveTerminal();
  4909. }
  4910. }
  4911. //---------------------------------------------------------------------------
  4912. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4913. {
  4914. if (CanCloseQueue())
  4915. {
  4916. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4917. }
  4918. }
  4919. //---------------------------------------------------------------------------
  4920. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4921. {
  4922. DetachTerminal(Terminal);
  4923. RemoteDirView->Terminal = Terminal;
  4924. UpdateRemotePathComboBox(false);
  4925. InitStatusBar();
  4926. UpdateControls();
  4927. }
  4928. //---------------------------------------------------------------------------
  4929. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4930. {
  4931. InitStatusBar();
  4932. }
  4933. //---------------------------------------------------------------------------
  4934. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4935. {
  4936. if (DebugAlwaysTrue(!Terminal->Active))
  4937. {
  4938. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4939. }
  4940. }
  4941. //---------------------------------------------------------------------------
  4942. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4943. {
  4944. if (OpenInNewWindow())
  4945. {
  4946. // encode session name because of slashes in hierarchical sessions
  4947. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4948. }
  4949. else
  4950. {
  4951. TTerminalManager * Manager = TTerminalManager::Instance();
  4952. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4953. Manager->ActiveSession = Terminal;
  4954. }
  4955. }
  4956. //---------------------------------------------------------------------------
  4957. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  4958. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  4959. {
  4960. TTerminalManager * Manager = TTerminalManager::Instance();
  4961. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4962. // This asks for a master password. Maybe we should postpone asking until a connection is actually opened.
  4963. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4964. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  4965. {
  4966. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  4967. // FirstSession can be null, if none of the workspace sites exist anymore
  4968. // or if all workspace sessions are not suported by the interface
  4969. // (when trying to open all local-local workspace in "explorer" interface)
  4970. if (FirstSession != NULL)
  4971. {
  4972. if (!ConnectFirstTerminal)
  4973. {
  4974. FirstSession->Disconnected = true;
  4975. FirstSession->DisconnectedTemporarily = true;
  4976. }
  4977. Manager->ActiveSession = FirstSession;
  4978. }
  4979. }
  4980. }
  4981. //---------------------------------------------------------------------------
  4982. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4983. {
  4984. if (OpenInNewWindow())
  4985. {
  4986. ExecuteNewInstance(Name);
  4987. }
  4988. else
  4989. {
  4990. DoOpenFolderOrWorkspace(Name, true, false);
  4991. }
  4992. }
  4993. //---------------------------------------------------------------------------
  4994. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4995. bool &CanClose)
  4996. {
  4997. // See the comment in CloseApp()
  4998. if (NonVisualDataModule->Busy)
  4999. {
  5000. CanClose = false;
  5001. }
  5002. else
  5003. {
  5004. TTerminalManager * Manager = TTerminalManager::Instance();
  5005. int ActiveSessions = 0;
  5006. for (int Index = 0; Index < Manager->Count; Index++)
  5007. {
  5008. if (Manager->Sessions[Index]->Active)
  5009. {
  5010. ActiveSessions++;
  5011. }
  5012. }
  5013. // Confirm, when there's at least one active remote session or
  5014. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  5015. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  5016. WinConfiguration->ConfirmClosingSession)
  5017. {
  5018. unsigned int Result;
  5019. TMessageParams Params(mpNeverAskAgainCheck);
  5020. UnicodeString Message;
  5021. int Answers = qaOK | qaCancel;
  5022. // The current session is the only active session
  5023. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  5024. {
  5025. if (!WinConfiguration->AutoSaveWorkspace)
  5026. {
  5027. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  5028. }
  5029. else
  5030. {
  5031. Message = LoadStr(CLOSE_SESSION);
  5032. }
  5033. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  5034. }
  5035. // Multiple active sessions or one active session, but it's not the current one
  5036. else if (ActiveSessions > 0)
  5037. {
  5038. if (!WinConfiguration->AutoSaveWorkspace)
  5039. {
  5040. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  5041. }
  5042. else
  5043. {
  5044. Message = LoadStr(CLOSE_SESSIONS);
  5045. }
  5046. }
  5047. // Multiple tabs, but all are inactive or local, and saving of worspace is not enabled
  5048. else
  5049. {
  5050. DebugAlwaysTrue(Manager->Count > 1);
  5051. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  5052. Message = LoadStr(CLOSE_WORKSPACE);
  5053. }
  5054. UnicodeString Note;
  5055. if (WinConfiguration->AutoSaveWorkspace)
  5056. {
  5057. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  5058. }
  5059. else
  5060. {
  5061. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  5062. Answers = qaYes | qaNo | qaCancel;
  5063. }
  5064. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  5065. SetFocus();
  5066. Result = MessageDialog(Message, qtConfirmation,
  5067. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  5068. if (Result == qaNeverAskAgain)
  5069. {
  5070. WinConfiguration->ConfirmClosingSession = false;
  5071. }
  5072. if (Result == qaNo)
  5073. {
  5074. CanClose = SaveWorkspace(true);
  5075. // note that the workspace will be saved redundatly again from FormClose
  5076. }
  5077. else
  5078. {
  5079. CanClose =
  5080. (Result == qaOK) ||
  5081. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  5082. (Result == qaNeverAskAgain);
  5083. }
  5084. }
  5085. if (CanClose && HasActiveTerminal())
  5086. {
  5087. CanClose = CanCloseQueue();
  5088. }
  5089. }
  5090. if (CanClose)
  5091. {
  5092. CanClose =
  5093. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  5094. FEditorManager->CloseExternalFilesWithoutProcess();
  5095. if (CanClose)
  5096. {
  5097. while (CanClose && (FLocalEditors->Count > 0))
  5098. {
  5099. int PrevCount = FLocalEditors->Count;
  5100. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  5101. CanClose = (FLocalEditors->Count < PrevCount);
  5102. }
  5103. if (CanClose)
  5104. {
  5105. CanClose = FEditorManager->Empty(true);
  5106. if (!CanClose)
  5107. {
  5108. SetFocus();
  5109. CanClose =
  5110. (MessageDialog(
  5111. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  5112. }
  5113. }
  5114. }
  5115. }
  5116. }
  5117. //---------------------------------------------------------------------------
  5118. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  5119. {
  5120. TForm * Form = dynamic_cast<TForm *>(Sender);
  5121. DebugAssert(Form != NULL);
  5122. Form->Close();
  5123. }
  5124. //---------------------------------------------------------------------------
  5125. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  5126. {
  5127. TForm * Form = dynamic_cast<TForm *>(Sender);
  5128. delete Form;
  5129. }
  5130. //---------------------------------------------------------------------------
  5131. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  5132. {
  5133. while (FLocalEditors->Count > 0)
  5134. {
  5135. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  5136. }
  5137. }
  5138. //---------------------------------------------------------------------------
  5139. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  5140. TObject *Sender)
  5141. {
  5142. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  5143. try
  5144. {
  5145. SetProperties(osRemote, FileList);
  5146. }
  5147. __finally
  5148. {
  5149. delete FileList;
  5150. }
  5151. }
  5152. //---------------------------------------------------------------------------
  5153. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  5154. {
  5155. if (value)
  5156. {
  5157. if (Component == fcCustomCommandsBand)
  5158. {
  5159. UpdateCustomCommandsToolbar();
  5160. }
  5161. if (Component == fcQueueFileList)
  5162. {
  5163. DebugAssert(!QueueFileListSplitter->Visible);
  5164. AdjustQueueLayout();
  5165. UpdateQueueFileList();
  5166. }
  5167. }
  5168. }
  5169. //---------------------------------------------------------------------------
  5170. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5171. {
  5172. int MinHeightLimit =
  5173. GetStaticQueuePanelComponentsHeight() +
  5174. QueueFileListSplitter->Height +
  5175. QueueFileList->Height +
  5176. GetMinQueueViewHeight();
  5177. if (QueuePanel->ClientHeight < MinHeightLimit)
  5178. {
  5179. QueuePanel->ClientHeight = MinHeightLimit;
  5180. }
  5181. }
  5182. //---------------------------------------------------------------------------
  5183. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5184. {
  5185. TControl * Control = GetComponent(Component);
  5186. DebugAssert(Control);
  5187. bool Changed = (Control->Visible != value);
  5188. if (Changed)
  5189. {
  5190. ComponentShowing(Component, value);
  5191. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5192. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5193. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5194. if (value)
  5195. {
  5196. int RemainingHeight = Control->Parent->ClientHeight;
  5197. int RemainingWidth = Control->Parent->ClientWidth;
  5198. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5199. {
  5200. TControl * ChildControl = Control->Parent->Controls[i];
  5201. if (ChildControl->Visible)
  5202. {
  5203. switch (ChildControl->Align)
  5204. {
  5205. case alTop:
  5206. case alBottom:
  5207. RemainingHeight -= ChildControl->Height;
  5208. break;
  5209. case alLeft:
  5210. case alRight:
  5211. RemainingWidth -= ChildControl->Width;
  5212. break;
  5213. }
  5214. }
  5215. }
  5216. int Reserve = ScaleByTextHeight(this, 32);
  5217. // queue in explorer, trees in commander
  5218. if (Control->Height > RemainingHeight - Reserve)
  5219. {
  5220. Control->Height = RemainingHeight / 2;
  5221. }
  5222. if (Control->Width > RemainingWidth - Reserve)
  5223. {
  5224. Control->Width = RemainingWidth / 2;
  5225. }
  5226. }
  5227. Control->Visible = value;
  5228. if (WasFocused && Visible)
  5229. {
  5230. DirView(osCurrent)->SetFocus();
  5231. }
  5232. FixControlsPlacement();
  5233. }
  5234. }
  5235. //---------------------------------------------------------------------------
  5236. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5237. {
  5238. TControl * Control = GetComponent(Component);
  5239. if (Control == NULL)
  5240. {
  5241. return false;
  5242. }
  5243. else
  5244. {
  5245. return Control->Visible;
  5246. }
  5247. }
  5248. //---------------------------------------------------------------------------
  5249. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5250. {
  5251. bool Result;
  5252. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5253. {
  5254. Result = !IsUWP();
  5255. }
  5256. else
  5257. {
  5258. Result = true;
  5259. }
  5260. return Result;
  5261. }
  5262. //---------------------------------------------------------------------------
  5263. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5264. {
  5265. if (DirView->ItemFocused != NULL)
  5266. {
  5267. DirView->ItemFocused->MakeVisible(false);
  5268. }
  5269. }
  5270. //---------------------------------------------------------------------------
  5271. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5272. {
  5273. MakeFocusedItemVisible(RemoteDirView);
  5274. QueueSplitter->Visible = QueuePanel->Visible;
  5275. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5276. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5277. TControl * TopControlsOrder[] =
  5278. { TopDock, MessageDock, SessionsPageControl };
  5279. SetVerticalControlsOrder(TopControlsOrder, LENOF(TopControlsOrder));
  5280. TControl * QueueControlsOrder[] =
  5281. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5282. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5283. }
  5284. //---------------------------------------------------------------------------
  5285. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5286. {
  5287. switch (Component) {
  5288. case fcStatusBar: return RemoteStatusBar;
  5289. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5290. case fcQueueView: return QueuePanel;
  5291. case fcQueueToolbar: return QueueDock;
  5292. case fcRemoteTree: return RemoteDrivePanel;
  5293. case fcSessionsTabs: return SessionsPageControl;
  5294. case fcQueueFileList: return QueueFileList;
  5295. default: return NULL;
  5296. }
  5297. }
  5298. //---------------------------------------------------------------------------
  5299. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5300. TObject *Sender, TListColumn *Column, TPoint &Point)
  5301. {
  5302. DebugAssert(NonVisualDataModule && Column && Sender);
  5303. NonVisualDataModule->ListColumn = Column;
  5304. TPopupMenu * DirViewColumnMenu;
  5305. if (Sender == DirView(osOther))
  5306. {
  5307. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5308. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible = (Column->Index == uvName);
  5309. bool SizeColumn = (Column->Index == uvSize);
  5310. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible = SizeColumn;
  5311. NonVisualDataModule->RemoteCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5312. }
  5313. else
  5314. {
  5315. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5316. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible = (Column->Index == dvName);
  5317. bool SizeColumn = (Column->Index == dvSize);
  5318. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible = SizeColumn;
  5319. NonVisualDataModule->LocalCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5320. }
  5321. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5322. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5323. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5324. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5325. }
  5326. //---------------------------------------------------------------------------
  5327. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5328. TObject *Sender, TListItem *Item, bool &AllowExec)
  5329. {
  5330. DoDirViewExecFile(Sender, Item, AllowExec);
  5331. }
  5332. //---------------------------------------------------------------------------
  5333. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5334. TListItem * Item, bool & AllowExec)
  5335. {
  5336. DebugAssert(Sender && Item && Configuration);
  5337. DebugAssert(AllowExec);
  5338. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5339. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5340. bool Remote = !IsSideLocalBrowser(Side);
  5341. DebugAssert(Item == ADirView->ItemFocused);
  5342. bool IsDirectory = ADirView->ItemIsDirectory(Item);
  5343. TResolvedDoubleClickAction Action;
  5344. if (FForceExecution)
  5345. {
  5346. Action = IsDirectory ? rdcaChangeDir : rdcaOpen;
  5347. }
  5348. else
  5349. {
  5350. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  5351. Action = WinConfiguration->ResolveDoubleClickAction(IsDirectory, ATerminal);
  5352. }
  5353. if (Action == rdcaCopy)
  5354. {
  5355. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5356. UnlockWindow();
  5357. try
  5358. {
  5359. if (IsLocalBrowserMode())
  5360. {
  5361. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5362. }
  5363. else
  5364. {
  5365. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5366. }
  5367. }
  5368. __finally
  5369. {
  5370. LockWindow();
  5371. }
  5372. AllowExec = false;
  5373. }
  5374. else if (Action == rdcaEdit)
  5375. {
  5376. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5377. {
  5378. ExecuteFile(Side, efDefaultEditor);
  5379. AllowExec = false;
  5380. }
  5381. }
  5382. else if (Action == rdcaOpen)
  5383. {
  5384. if (DebugAlwaysTrue(!IsDirectory) && Remote && !WinConfiguration->DisableOpenEdit)
  5385. {
  5386. ExecuteFile(osRemote, efShell);
  5387. AllowExec = false;
  5388. }
  5389. }
  5390. }
  5391. //---------------------------------------------------------------------------
  5392. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5393. {
  5394. return ((Side == osRemote) || (Side == osCurrent));
  5395. }
  5396. //---------------------------------------------------------------------------
  5397. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5398. {
  5399. DebugFail();
  5400. }
  5401. //---------------------------------------------------------------------------
  5402. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5403. {
  5404. DebugFail();
  5405. }
  5406. //---------------------------------------------------------------------------
  5407. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5408. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5409. {
  5410. TSynchronizeParamType Params;
  5411. Params.LocalDirectory = LocalDirectory;
  5412. Params.RemoteDirectory = RemoteDirectory;
  5413. int UnusedParams =
  5414. (GUIConfiguration->SynchronizeParams &
  5415. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5416. TTerminal::spCaseSensitive));
  5417. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5418. Params.Options = GUIConfiguration->SynchronizeOptions;
  5419. bool SaveSettings = false;
  5420. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5421. &DoSynchronizeTooManyDirectories);
  5422. DebugAssert(FSynchronizeController == NULL);
  5423. FSynchronizeController = &Controller;
  5424. bool Result;
  5425. try
  5426. {
  5427. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5428. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5429. int Options =
  5430. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5431. DebugAssert(FOnFeedSynchronizeError == NULL);
  5432. DebugAssert(FOnSynchronizeAbort == NULL);
  5433. DebugAssert(FSynchronizeTerminal == NULL);
  5434. FSynchronizeTerminal = Terminal;
  5435. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5436. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5437. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5438. if (Result)
  5439. {
  5440. if (SaveSettings)
  5441. {
  5442. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5443. GUIConfiguration->SynchronizeOptions = Params.Options;
  5444. }
  5445. else
  5446. {
  5447. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5448. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5449. FLAGSET(Params.Options, soSynchronize))
  5450. {
  5451. GUIConfiguration->SynchronizeOptions =
  5452. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5453. soSynchronize;
  5454. }
  5455. }
  5456. LocalDirectory = Params.LocalDirectory;
  5457. RemoteDirectory = Params.RemoteDirectory;
  5458. }
  5459. }
  5460. __finally
  5461. {
  5462. FSynchronizeController = NULL;
  5463. DebugAssert(FOnFeedSynchronizeError == NULL);
  5464. FOnFeedSynchronizeError = NULL;
  5465. DebugAssert(FOnSynchronizeAbort == NULL);
  5466. FOnSynchronizeAbort = NULL;
  5467. FSynchronizeTerminal = NULL;
  5468. }
  5469. return Result;
  5470. }
  5471. //---------------------------------------------------------------------------
  5472. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5473. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5474. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5475. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5476. TSynchronizeOptions * Options, bool Full)
  5477. {
  5478. // Keep-up-to-date mode
  5479. if (Terminal->Status == ssOpened)
  5480. {
  5481. try
  5482. {
  5483. int PParams = Params.Params;
  5484. if (!Full)
  5485. {
  5486. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5487. if (FLAGSET(Params.Options, soRecurse))
  5488. {
  5489. PParams |= TTerminal::spSubDirs;
  5490. }
  5491. }
  5492. else
  5493. {
  5494. // if keepuptodate is non-recursive,
  5495. // full sync before has to be non-recursive as well
  5496. if (FLAGCLEAR(Params.Options, soRecurse))
  5497. {
  5498. PParams |= TTerminal::spNoRecurse;
  5499. }
  5500. }
  5501. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5502. PParams, Checklist, Options);
  5503. }
  5504. catch (Exception & E)
  5505. {
  5506. if (!Terminal->Active)
  5507. {
  5508. ShowExtendedExceptionEx(Terminal, &E);
  5509. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5510. if (!Terminal->Active)
  5511. {
  5512. throw;
  5513. }
  5514. }
  5515. else
  5516. {
  5517. if (FLAGSET(Params.Options, soContinueOnError) &&
  5518. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5519. {
  5520. // noop, already logged in MoreMessageDialog
  5521. }
  5522. else
  5523. {
  5524. // We get mostly EAbort here, so this is noop.
  5525. // Exception is an error when listing directories while looking for differences.
  5526. ShowExtendedExceptionEx(Terminal, &E);
  5527. throw;
  5528. }
  5529. }
  5530. }
  5531. }
  5532. }
  5533. //---------------------------------------------------------------------------
  5534. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5535. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5536. const UnicodeString ErrorStr)
  5537. {
  5538. if (!Directory.IsEmpty())
  5539. {
  5540. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5541. }
  5542. else
  5543. {
  5544. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5545. }
  5546. }
  5547. //---------------------------------------------------------------------------
  5548. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5549. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5550. {
  5551. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5552. {
  5553. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5554. }
  5555. else
  5556. {
  5557. TMessageParams Params(mpNeverAskAgainCheck);
  5558. unsigned int Result = MessageDialog(
  5559. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5560. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5561. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5562. {
  5563. MaxDirectories *= 2;
  5564. if (Result == qaNeverAskAgain)
  5565. {
  5566. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5567. }
  5568. }
  5569. else
  5570. {
  5571. Abort();
  5572. }
  5573. }
  5574. }
  5575. //---------------------------------------------------------------------------
  5576. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5577. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5578. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5579. TSynchronizeOptions * Options)
  5580. {
  5581. // Keep-up-to-date mode
  5582. DebugAssert(!FAutoOperation);
  5583. void * BatchStorage;
  5584. BatchStart(BatchStorage);
  5585. FAutoOperation = true;
  5586. bool AnyOperation = false;
  5587. TDateTime StartTime = Now();
  5588. TSynchronizeChecklist * AChecklist = NULL;
  5589. try
  5590. {
  5591. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5592. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5593. {
  5594. FSynchronizeProgressForm->Start();
  5595. }
  5596. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5597. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5598. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5599. Options);
  5600. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5601. SAFE_DESTROY(FSynchronizeProgressForm);
  5602. AnyOperation = (AChecklist->CheckedCount > 0);
  5603. if (AnyOperation)
  5604. {
  5605. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5606. CreateProgressForm(&SynchronizeProgress);
  5607. try
  5608. {
  5609. Terminal->SynchronizeApply(
  5610. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5611. SynchronizeProcessedItem, NULL, NULL, NULL);
  5612. }
  5613. __finally
  5614. {
  5615. DestroyProgressForm();
  5616. }
  5617. }
  5618. }
  5619. __finally
  5620. {
  5621. if (Checklist == NULL)
  5622. {
  5623. delete AChecklist;
  5624. }
  5625. else
  5626. {
  5627. *Checklist = AChecklist;
  5628. }
  5629. FAutoOperation = false;
  5630. SAFE_DESTROY(FSynchronizeProgressForm);
  5631. BatchEnd(BatchStorage);
  5632. ReloadLocalDirectory();
  5633. if (AnyOperation)
  5634. {
  5635. OperationComplete(StartTime);
  5636. }
  5637. }
  5638. }
  5639. //---------------------------------------------------------------------------
  5640. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5641. {
  5642. // can be called from command line
  5643. return Visible &&
  5644. ((DirView(osRemote)->SelCount > 0) ||
  5645. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5646. }
  5647. //---------------------------------------------------------------------------
  5648. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5649. {
  5650. LogSynchronizeEvent(Terminal, Message);
  5651. }
  5652. //---------------------------------------------------------------------------
  5653. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5654. int Params, TSynchronizeOptions & Options)
  5655. {
  5656. DebugAssert(!IsLocalBrowserMode());
  5657. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5658. {
  5659. Options.Filter = new TStringList();
  5660. Options.Filter->CaseSensitive = false;
  5661. Options.Filter->Duplicates = Types::dupAccept;
  5662. if (DirView(osRemote)->SelCount > 0)
  5663. {
  5664. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5665. }
  5666. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5667. {
  5668. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5669. }
  5670. Options.Filter->Sort();
  5671. }
  5672. }
  5673. //---------------------------------------------------------------------------
  5674. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5675. {
  5676. TCopyParamType Defaults;
  5677. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5678. ConfigStorage->AccessMode = smRead;
  5679. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5680. {
  5681. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5682. }
  5683. ConfigStorage.reset(NULL);
  5684. std::unique_ptr<TStringList> Options(new TStringList());
  5685. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5686. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5687. UnicodeString Result;
  5688. if (Options->Count > 0)
  5689. {
  5690. Result =
  5691. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5692. }
  5693. return Result;
  5694. }
  5695. //---------------------------------------------------------------------------
  5696. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5697. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5698. {
  5699. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5700. UnicodeString AdditionalParams =
  5701. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5702. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5703. SerializeCopyParamForCommandLine(CopyParams),
  5704. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5705. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5706. ExecuteNewInstance(SessionName, AdditionalParams);
  5707. }
  5708. //---------------------------------------------------------------------------
  5709. struct TSynchronizeParams
  5710. {
  5711. UnicodeString LocalDirectory;
  5712. UnicodeString RemoteDirectory;
  5713. TSynchronizeMode Mode;
  5714. TSynchronizeChecklist * Checklist;
  5715. int Params;
  5716. TCopyParamType * CopyParam;
  5717. TDateTime CollectElapsed;
  5718. TDateTime * StartTime;
  5719. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5720. };
  5721. //---------------------------------------------------------------------------
  5722. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5723. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5724. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5725. {
  5726. DebugAssert(!FAutoOperation);
  5727. void * BatchStorage;
  5728. BatchStart(BatchStorage);
  5729. FAutoOperation = true;
  5730. TFileOperationStatistics Statistics;
  5731. TDateTime Start = Now();
  5732. try
  5733. {
  5734. Params.OnProcessedItem = OnProcessedItem;
  5735. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5736. CreateProgressForm(&SynchronizeProgress);
  5737. Terminal->SynchronizeApply(
  5738. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5739. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5740. &Statistics);
  5741. }
  5742. __finally
  5743. {
  5744. Params.OnProcessedItem = NULL;
  5745. FAutoOperation = false;
  5746. DestroyProgressForm();
  5747. BatchEnd(BatchStorage);
  5748. ReloadLocalDirectory();
  5749. }
  5750. if (WinConfiguration->SynchronizeSummary)
  5751. {
  5752. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5753. // The statistics should be 0 anyway in this case
  5754. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5755. {
  5756. Message += L"\n";
  5757. if (Statistics.FilesUploaded > 0)
  5758. {
  5759. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5760. }
  5761. if (Statistics.FilesDownloaded > 0)
  5762. {
  5763. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5764. }
  5765. if (Statistics.FilesDeletedLocal > 0)
  5766. {
  5767. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5768. }
  5769. if (Statistics.FilesDeletedRemote > 0)
  5770. {
  5771. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5772. }
  5773. }
  5774. TDateTime Elapsed = (Now() - Start);
  5775. Message +=
  5776. L"\n" +
  5777. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5778. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5779. TMessageParams Params(mpNeverAskAgainCheck);
  5780. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5781. if (Result == qaNeverAskAgain)
  5782. {
  5783. WinConfiguration->SynchronizeSummary = false;
  5784. }
  5785. }
  5786. }
  5787. //---------------------------------------------------------------------------
  5788. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5789. {
  5790. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5791. {
  5792. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5793. }
  5794. // Not set in keep-up-to-date mode - Synchronize() method
  5795. if (Token != NULL)
  5796. {
  5797. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5798. if (Params.OnProcessedItem != NULL)
  5799. {
  5800. Params.OnProcessedItem(NULL, ChecklistItem);
  5801. }
  5802. }
  5803. }
  5804. //---------------------------------------------------------------------------
  5805. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5806. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5807. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5808. {
  5809. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5810. *Params.StartTime = Now();
  5811. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5812. }
  5813. //---------------------------------------------------------------------------
  5814. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5815. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5816. {
  5817. // terminal can be already closed (e.g. dropped connection)
  5818. if (Terminal != NULL)
  5819. {
  5820. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5821. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5822. }
  5823. }
  5824. //---------------------------------------------------------------------------
  5825. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5826. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5827. {
  5828. DebugAssert(!IsLocalBrowserMode());
  5829. TAutoBatch AutoBatch(this);
  5830. TAutoFlag AutoOperationFlag(FAutoOperation);
  5831. if (Side == osRemote)
  5832. {
  5833. std::unique_ptr<TStrings> FileList(new TStringList());
  5834. FileList->AddObject(FileName, RemoteFile);
  5835. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5836. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5837. RemoteDirView->SaveSelection();
  5838. RemoteDirView->SaveSelectedNames();
  5839. try
  5840. {
  5841. Terminal->MoveFiles(FileList.get(), Target, FileMask, false);
  5842. }
  5843. catch(...)
  5844. {
  5845. RemoteDirView->DiscardSavedSelection();
  5846. throw;
  5847. }
  5848. RemoteDirView->RestoreSelection();
  5849. }
  5850. else if (DebugAlwaysTrue(Side == osLocal))
  5851. {
  5852. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5853. {
  5854. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5855. }
  5856. UnicodeString Directory = ExtractFileDir(FileName);
  5857. ReloadLocalDirectory(Directory);
  5858. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5859. if (!SamePaths(Directory, NewDirectory))
  5860. {
  5861. ReloadLocalDirectory(NewDirectory);
  5862. }
  5863. }
  5864. }
  5865. //---------------------------------------------------------------------------
  5866. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5867. {
  5868. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5869. if (Side == osLocal)
  5870. {
  5871. if (Action == TSynchronizeChecklist::saDownloadNew)
  5872. {
  5873. OpenFolderInExplorer(LocalPath);
  5874. }
  5875. else
  5876. {
  5877. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5878. }
  5879. }
  5880. else if (DebugAlwaysTrue(Side == osRemote))
  5881. {
  5882. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5883. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5884. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5885. if (!LocalPath.IsEmpty())
  5886. {
  5887. SessionData->LocalDirectory = LocalPath;
  5888. }
  5889. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5890. ExecuteNewInstance(SessionName, FORMAT(L"%s=\"%s\"", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5891. }
  5892. }
  5893. //---------------------------------------------------------------------------
  5894. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5895. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5896. const TCopyParamType * CopyParams)
  5897. {
  5898. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5899. UnicodeString AdditionalParams =
  5900. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5901. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5902. SerializeCopyParamForCommandLine(CopyParams),
  5903. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5904. LocalDirectory, RemoteDirectory, Mode, Params));
  5905. ExecuteNewInstance(SessionName, AdditionalParams);
  5906. }
  5907. //---------------------------------------------------------------------------
  5908. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5909. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5910. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5911. {
  5912. int Result;
  5913. bool SaveSettings = false;
  5914. int Options =
  5915. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5916. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5917. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5918. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5919. bool Continue =
  5920. (UseDefaults == 0) ||
  5921. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5922. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5923. if (Continue)
  5924. {
  5925. Configuration->Usage->Inc(L"Synchronizations");
  5926. CopyParam.IncludeFileMask.SetRoots(LocalDirectory, RemoteDirectory);
  5927. UpdateCopyParamCounters(CopyParam);
  5928. TSynchronizeOptions SynchronizeOptions;
  5929. GetSynchronizeOptions(Params, SynchronizeOptions);
  5930. if (SaveSettings)
  5931. {
  5932. GUIConfiguration->SynchronizeParams = Params;
  5933. }
  5934. else
  5935. {
  5936. SaveMode = false;
  5937. }
  5938. TDateTime StartTime = Now();
  5939. TSynchronizeChecklist * Checklist = NULL;
  5940. try
  5941. {
  5942. DebugAssert(!FAutoOperation);
  5943. FAutoOperation = true;
  5944. try
  5945. {
  5946. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5947. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5948. int Files = -1;
  5949. if (DataList->Count >= 1)
  5950. {
  5951. Files = StrToIntDef(DataList->Strings[0], Files);
  5952. }
  5953. else
  5954. {
  5955. DataList->Add(UnicodeString());
  5956. }
  5957. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5958. FSynchronizeProgressForm->Start();
  5959. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5960. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5961. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5962. &SynchronizeOptions);
  5963. if (Terminal->SessionData->CacheDirectories)
  5964. {
  5965. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5966. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5967. }
  5968. }
  5969. __finally
  5970. {
  5971. FAutoOperation = false;
  5972. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5973. SAFE_DESTROY(FSynchronizeProgressForm);
  5974. }
  5975. TSynchronizeParams SynchronizeParams;
  5976. SynchronizeParams.LocalDirectory = LocalDirectory;
  5977. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5978. SynchronizeParams.Mode = Mode;
  5979. SynchronizeParams.CopyParam = &CopyParam;
  5980. SynchronizeParams.Params = Params;
  5981. SynchronizeParams.Checklist = Checklist;
  5982. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5983. SynchronizeParams.StartTime = &StartTime;
  5984. SynchronizeParams.OnProcessedItem = NULL;
  5985. Result = Checklist->Count;
  5986. if (Checklist->Count > 0)
  5987. {
  5988. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5989. {
  5990. if (!DoSynchronizeChecklistDialog(
  5991. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5992. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5993. {
  5994. Result = -1;
  5995. }
  5996. }
  5997. else
  5998. {
  5999. FullSynchronize(SynchronizeParams, NULL, NULL);
  6000. }
  6001. }
  6002. else
  6003. {
  6004. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  6005. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  6006. }
  6007. }
  6008. __finally
  6009. {
  6010. delete Checklist;
  6011. }
  6012. OperationComplete(StartTime);
  6013. }
  6014. else
  6015. {
  6016. Result = -1;
  6017. }
  6018. return Result;
  6019. }
  6020. //---------------------------------------------------------------------------
  6021. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  6022. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6023. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  6024. {
  6025. if (Collect)
  6026. {
  6027. DebugAssert(FSynchronizeProgressForm != NULL);
  6028. if (!FSynchronizeProgressForm->Started)
  6029. {
  6030. FSynchronizeProgressForm->Start();
  6031. }
  6032. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  6033. SetTaskbarListProgressValue(CompareProgress);
  6034. }
  6035. else
  6036. {
  6037. DebugAssert(FSynchronizeProgressForm == NULL);
  6038. DebugAssert(FProgressForm != NULL);
  6039. }
  6040. }
  6041. //---------------------------------------------------------------------------
  6042. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  6043. {
  6044. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  6045. std::unique_ptr<TRemoteFile> File(Terminal->ReadFile(FullFileName));
  6046. if (File.get() != NULL)
  6047. {
  6048. ExecuteRemoteFile(FullFileName, File.get(), efInternalEditor);
  6049. Application->ShowMainForm = false;
  6050. Application->Run();
  6051. }
  6052. }
  6053. //---------------------------------------------------------------------------
  6054. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  6055. {
  6056. DebugFail();
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  6060. {
  6061. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  6062. SessionData->Assign(ManagedSession->SessionData);
  6063. UpdateSessionData(SessionData.get());
  6064. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  6065. if (IsActiveTerminal(ManagedSession))
  6066. {
  6067. ManagedSession->UpdateSessionCredentials(SessionData.get());
  6068. }
  6069. if (!ManagedSession->SessionData->HasSessionName())
  6070. {
  6071. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  6072. // once IsWorkspace is cleared
  6073. SessionData->Name = UnicodeString();
  6074. }
  6075. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  6076. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  6077. SessionData->IsWorkspace = false;
  6078. return SessionData.release();
  6079. }
  6080. //---------------------------------------------------------------------------
  6081. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  6082. {
  6083. TSessionData * SessionData = CloneCurrentSessionData();
  6084. try
  6085. {
  6086. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  6087. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  6088. }
  6089. __finally
  6090. {
  6091. delete SessionData;
  6092. }
  6093. }
  6094. //---------------------------------------------------------------------------
  6095. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  6096. {
  6097. TTerminalManager * Manager = TTerminalManager::Instance();
  6098. std::unique_ptr<TObjectList> DataList(new TObjectList());
  6099. if (DebugAlwaysTrue(ManagedSession != NULL))
  6100. {
  6101. // Update ManagedSession->StateData
  6102. UpdateSession(ManagedSession);
  6103. }
  6104. Manager->SaveWorkspace(DataList.get());
  6105. return DataList.release();
  6106. }
  6107. //---------------------------------------------------------------------------
  6108. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  6109. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  6110. {
  6111. WinConfiguration->LastWorkspace = Name;
  6112. if (!SavePasswords)
  6113. {
  6114. for (int Index = 0; Index < DataList->Count; Index++)
  6115. {
  6116. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6117. if (SessionData->Link.IsEmpty())
  6118. {
  6119. SessionData->ClearSessionPasswords();
  6120. }
  6121. }
  6122. }
  6123. StoredSessions->NewWorkspace(Name, DataList);
  6124. // modified only
  6125. StoredSessions->Save(false, Explicit);
  6126. }
  6127. //---------------------------------------------------------------------------
  6128. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  6129. {
  6130. return
  6131. DefaultStr(WinConfiguration->LastWorkspace,
  6132. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  6133. }
  6134. //---------------------------------------------------------------------------
  6135. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  6136. {
  6137. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  6138. bool AnyNonStoredSessionWithPassword = false;
  6139. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  6140. bool AllNonStoredSessionsAnonymous = true;
  6141. TTerminalManager * Manager = TTerminalManager::Instance();
  6142. for (int Index = 0; Index < DataList->Count; Index++)
  6143. {
  6144. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6145. if (SessionData->Link.IsEmpty())
  6146. {
  6147. if (SessionData->HasAnySessionPassword())
  6148. {
  6149. AnyNonStoredSessionWithPassword = true;
  6150. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  6151. {
  6152. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  6153. }
  6154. }
  6155. if (!SameText(SessionData->UserName, AnonymousUserName))
  6156. {
  6157. AllNonStoredSessionsAnonymous = false;
  6158. }
  6159. }
  6160. }
  6161. bool SavePasswords;
  6162. bool * PSavePasswords;
  6163. bool NotRecommendedSavingPasswords =
  6164. !CustomWinConfiguration->UseMasterPassword &&
  6165. !AllNonStoredSessionsAnonymous;
  6166. if (Configuration->DisablePasswordStoring ||
  6167. !AnyNonStoredSessionWithPassword)
  6168. {
  6169. PSavePasswords = NULL;
  6170. SavePasswords = false;
  6171. }
  6172. else
  6173. {
  6174. PSavePasswords = &SavePasswords;
  6175. SavePasswords =
  6176. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6177. !NotRecommendedSavingPasswords;
  6178. }
  6179. UnicodeString Name = WorkspaceName();
  6180. bool CreateShortcut = false;
  6181. bool Result =
  6182. DoSaveWorkspaceDialog(
  6183. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6184. EnableAutoSave);
  6185. if (Result)
  6186. {
  6187. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6188. if (CreateShortcut)
  6189. {
  6190. TOperationVisualizer Visualizer;
  6191. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6192. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6193. }
  6194. if (EnableAutoSave)
  6195. {
  6196. WinConfiguration->AutoSaveWorkspace = true;
  6197. WinConfiguration->AutoWorkspace = Name;
  6198. if (PSavePasswords != NULL)
  6199. {
  6200. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6201. }
  6202. }
  6203. }
  6204. return Result;
  6205. }
  6206. //---------------------------------------------------------------------------
  6207. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6208. {
  6209. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6210. DebugAssert(Session == ManagedSession);
  6211. if (!IsLocalBrowserMode())
  6212. {
  6213. SAFE_DESTROY(Session->RemoteExplorerState);
  6214. if (WinConfiguration->PreservePanelState)
  6215. {
  6216. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6217. }
  6218. }
  6219. UpdateSessionData(Session->StateData);
  6220. }
  6221. //---------------------------------------------------------------------------
  6222. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6223. {
  6224. // Keep in sync with TSessionData::CopyStateData
  6225. DebugAssert(Data != NULL);
  6226. // This is inconsistent with how color (for example) is handled.
  6227. Data->Name = ManagedSession->SessionData->Name;
  6228. if (!IsLocalBrowserMode())
  6229. {
  6230. // cannot use RemoteDirView->Path, because it is empty if connection
  6231. // was already closed
  6232. // also only peek, we may not be connected at all atm
  6233. // so make sure we do not try retrieving current directory from the server
  6234. // (particularly with FTP)
  6235. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6236. if (!ACurrentDirectory.IsEmpty())
  6237. {
  6238. Data->RemoteDirectory = ACurrentDirectory;
  6239. }
  6240. }
  6241. Data->Color = SessionColor;
  6242. }
  6243. //---------------------------------------------------------------------------
  6244. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6245. {
  6246. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6247. DebugAssert(Toolbar != NULL);
  6248. for (int i = 0; i < Toolbar->Items->Count; i++)
  6249. {
  6250. TTBXCustomDropDownItem * DropDownItem;
  6251. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6252. if (DropDownItem != NULL)
  6253. {
  6254. ToolbarItemResize(DropDownItem,
  6255. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6256. Toolbar->NonClientWidth);
  6257. break;
  6258. }
  6259. }
  6260. }
  6261. //---------------------------------------------------------------------------
  6262. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6263. {
  6264. Item->EditWidth = Width;
  6265. }
  6266. //---------------------------------------------------------------------------
  6267. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6268. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6269. {
  6270. for (int i = 0; i < Toolbar->Items->Count; i++)
  6271. {
  6272. TTBXCustomDropDownItem * DropDownItem;
  6273. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6274. if (DropDownItem != NULL)
  6275. {
  6276. ASize.x -= DropDownItem->EditWidth;
  6277. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  6278. }
  6279. }
  6280. }
  6281. //---------------------------------------------------------------------------
  6282. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6283. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6284. {
  6285. if (WinConfiguration->DDWarnLackOfTempSpace)
  6286. {
  6287. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6288. if (!ADrive.IsEmpty())
  6289. {
  6290. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6291. DebugAssert(RequiredSpace >= 0);
  6292. __int64 RequiredWithReserve;
  6293. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6294. if (FreeSpace < RequiredWithReserve)
  6295. {
  6296. unsigned int Result;
  6297. TMessageParams Params(mpNeverAskAgainCheck);
  6298. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6299. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6300. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6301. if (Result == qaNeverAskAgain)
  6302. {
  6303. WinConfiguration->DDWarnLackOfTempSpace = false;
  6304. }
  6305. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6306. }
  6307. }
  6308. }
  6309. }
  6310. //---------------------------------------------------------------------------
  6311. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6312. {
  6313. DoOpenDirectoryDialog(odAddBookmark, Side);
  6314. }
  6315. //---------------------------------------------------------------------------
  6316. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6317. {
  6318. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6319. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6320. try
  6321. {
  6322. TCustomDirView * DView = DirView(Side);
  6323. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6324. {
  6325. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6326. }
  6327. }
  6328. catch (...)
  6329. {
  6330. delete VisitedDirectories;
  6331. throw;
  6332. }
  6333. return VisitedDirectories;
  6334. }
  6335. //---------------------------------------------------------------------------
  6336. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6337. TOpenDirectoryMode Mode, TOperationSide Side)
  6338. {
  6339. bool Continue = true;
  6340. if (Mode == odAddBookmark)
  6341. {
  6342. TMessageParams Params(mpNeverAskAgainCheck);
  6343. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6344. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6345. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6346. unsigned int Answer =
  6347. MessageDialog(Message,
  6348. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6349. if (Answer == qaNeverAskAgain)
  6350. {
  6351. Continue = true;
  6352. WinConfiguration->UseSharedBookmarks = true;
  6353. }
  6354. else if (Answer == qaOK)
  6355. {
  6356. Continue = true;
  6357. WinConfiguration->UseSharedBookmarks = false;
  6358. }
  6359. else
  6360. {
  6361. Continue = false;
  6362. }
  6363. }
  6364. if (Continue)
  6365. {
  6366. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6367. try
  6368. {
  6369. UnicodeString Name = DirView(Side)->PathName;
  6370. bool Repeat;
  6371. do
  6372. {
  6373. Repeat = false;
  6374. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6375. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6376. // do not allow switching to location profiles,
  6377. // if we are not connected
  6378. HasDirView[osLocal] && (Terminal != NULL)))
  6379. {
  6380. TWindowLock Lock(this);
  6381. if (!TryOpenDirectory(Side, Name))
  6382. {
  6383. Repeat = true;
  6384. Mode = odBrowse;
  6385. }
  6386. }
  6387. }
  6388. while (Repeat);
  6389. }
  6390. __finally
  6391. {
  6392. delete VisitedDirectories;
  6393. }
  6394. }
  6395. }
  6396. //---------------------------------------------------------------------------
  6397. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6398. {
  6399. DebugAssert(!Terminal->CommandSessionOpened);
  6400. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6401. }
  6402. //---------------------------------------------------------------------------
  6403. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6404. {
  6405. bool Result = Terminal->IsCapable[Capability] ||
  6406. Terminal->CommandSessionOpened;
  6407. if (!Result)
  6408. {
  6409. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6410. if (!GUIConfiguration->ConfirmCommandSession)
  6411. {
  6412. Result = true;
  6413. }
  6414. else
  6415. {
  6416. TMessageParams Params(mpNeverAskAgainCheck);
  6417. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6418. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6419. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6420. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6421. if (Answer == qaNeverAskAgain)
  6422. {
  6423. GUIConfiguration->ConfirmCommandSession = false;
  6424. Result = true;
  6425. }
  6426. else if (Answer == qaOK)
  6427. {
  6428. Result = true;
  6429. }
  6430. }
  6431. if (Result)
  6432. {
  6433. Result = CommandSessionFallback();
  6434. }
  6435. }
  6436. return Result;
  6437. }
  6438. //---------------------------------------------------------------------------
  6439. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6440. {
  6441. if (EnsureCommandSessionFallback(fcAnyCommand))
  6442. {
  6443. DoConsoleDialog(Terminal, Command);
  6444. }
  6445. }
  6446. //---------------------------------------------------------------------------
  6447. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6448. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6449. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6450. {
  6451. if (!IsSideLocalBrowser(osRemote) &&
  6452. IsFileControl(DropSourceControl, osRemote) &&
  6453. (FDDExtMapFile != NULL))
  6454. {
  6455. Accept = true;
  6456. }
  6457. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6458. DebugAssert(FDDTargetControl != NULL);
  6459. }
  6460. //---------------------------------------------------------------------------
  6461. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6462. _di_IDataObject DataObj, int KeyState,
  6463. const TPoint & Point, int & Effect, bool & Accept)
  6464. {
  6465. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6466. }
  6467. //---------------------------------------------------------------------------
  6468. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6469. _di_IDataObject DataObj, int KeyState,
  6470. const TPoint & Point, int & Effect, bool & Accept)
  6471. {
  6472. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6473. }
  6474. //---------------------------------------------------------------------------
  6475. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6476. TObject * Sender)
  6477. {
  6478. DebugUsedParam(Sender);
  6479. DebugAssert(FDDTargetControl == Sender);
  6480. FDDTargetControl = NULL;
  6481. }
  6482. //---------------------------------------------------------------------------
  6483. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6484. {
  6485. FileControlDDDragLeave(SessionsPageControl);
  6486. }
  6487. //---------------------------------------------------------------------------
  6488. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6489. {
  6490. FileControlDDDragLeave(QueueView3);
  6491. }
  6492. //---------------------------------------------------------------------------
  6493. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6494. {
  6495. DebugAssert(!IsSideLocalBrowser(Side));
  6496. DebugUsedParam(Side);
  6497. bool Edit = false;
  6498. TRemoteFile * File = NULL;
  6499. UnicodeString FileName;
  6500. UnicodeString PointTo;
  6501. bool SymbolicLink = true;
  6502. if (RemoteDirView->ItemFocused)
  6503. {
  6504. DebugAssert(RemoteDirView->ItemFocused->Data);
  6505. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6506. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6507. if (Edit)
  6508. {
  6509. FileName = File->FileName;
  6510. PointTo = File->LinkTo;
  6511. }
  6512. else if (!File->IsParentDirectory)
  6513. {
  6514. PointTo = File->FileName;
  6515. }
  6516. }
  6517. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6518. Terminal->IsCapable[fcHardLink]))
  6519. {
  6520. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6521. if (Edit)
  6522. {
  6523. DebugAssert(File->FileName == FileName);
  6524. int Params = dfNoRecursive;
  6525. Terminal->ExceptionOnFail = true;
  6526. try
  6527. {
  6528. Terminal->DeleteFile(L"", File, &Params);
  6529. }
  6530. __finally
  6531. {
  6532. Terminal->ExceptionOnFail = false;
  6533. }
  6534. }
  6535. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6536. }
  6537. }
  6538. //---------------------------------------------------------------------------
  6539. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6540. {
  6541. return
  6542. (IsSideLocalBrowser(Side) ||
  6543. (HasActiveTerminal() &&
  6544. Terminal->ResolvingSymlinks &&
  6545. Terminal->IsCapable[fcSymbolicLink]));
  6546. }
  6547. //---------------------------------------------------------------------------
  6548. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6549. {
  6550. return
  6551. !IsSideLocalBrowser(FCurrentSide) &&
  6552. (RemoteDirView->ItemFocused != NULL) &&
  6553. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6554. Terminal->SessionData->ResolveSymlinks;
  6555. }
  6556. //---------------------------------------------------------------------------
  6557. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6558. {
  6559. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6560. FForceExecution = true;
  6561. try
  6562. {
  6563. DirView(osCurrent)->ExecuteCurrentFile();
  6564. }
  6565. __finally
  6566. {
  6567. FForceExecution = false;
  6568. }
  6569. }
  6570. //---------------------------------------------------------------------------
  6571. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6572. {
  6573. TEditorData ExternalEditor;
  6574. ExternalEditor.Editor = edExternal;
  6575. bool Remember = false;
  6576. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6577. {
  6578. if (Remember)
  6579. {
  6580. TEditorList * EditorList = new TEditorList;
  6581. try
  6582. {
  6583. *EditorList = *WinConfiguration->EditorList;
  6584. bool Found = false;
  6585. int i = 0;
  6586. while (!Found && (i < EditorList->Count))
  6587. {
  6588. const TEditorPreferences * Editor = EditorList->Editors[i];
  6589. if ((Editor->Data->Editor == edExternal) &&
  6590. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6591. {
  6592. Found = true;
  6593. }
  6594. i++;
  6595. }
  6596. if (!Found)
  6597. {
  6598. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6599. WinConfiguration->EditorList = EditorList;
  6600. }
  6601. }
  6602. __finally
  6603. {
  6604. delete EditorList;
  6605. }
  6606. }
  6607. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6608. }
  6609. }
  6610. //---------------------------------------------------------------------------
  6611. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6612. {
  6613. if (FFileFindTerminal == ATerminal)
  6614. {
  6615. FFileFindTerminal = NULL;
  6616. HideFileFindDialog();
  6617. }
  6618. if (FClipboardTerminal == ATerminal)
  6619. {
  6620. ClipboardClear(); // implies ClipboardStop
  6621. }
  6622. if ((FOnSynchronizeAbort != NULL) &&
  6623. (ATerminal == FManagedSession))
  6624. {
  6625. FOnSynchronizeAbort(NULL);
  6626. }
  6627. }
  6628. //---------------------------------------------------------------------------
  6629. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6630. {
  6631. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6632. DetachTerminal(Sender);
  6633. }
  6634. //---------------------------------------------------------------------------
  6635. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6636. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6637. {
  6638. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6639. DebugAssert(Terminal != NULL);
  6640. if (Data->Terminal == Terminal)
  6641. {
  6642. Data->Terminal = NULL;
  6643. }
  6644. }
  6645. //---------------------------------------------------------------------------
  6646. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6647. {
  6648. return NULL;
  6649. }
  6650. //---------------------------------------------------------------------------
  6651. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6652. {
  6653. UpdateControls();
  6654. SessionColor = TColor(0);
  6655. UpdateRemotePathComboBox(false);
  6656. NeedSession(false);
  6657. }
  6658. //---------------------------------------------------------------------------
  6659. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6660. {
  6661. try
  6662. {
  6663. // Cache, as the login dialog can change its value.
  6664. // See also DoShow. Also see TTerminalManager::NewSession.
  6665. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6666. try
  6667. {
  6668. if (ShowLogin)
  6669. {
  6670. bool ReloadSessions = !Startup;
  6671. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6672. }
  6673. }
  6674. __finally
  6675. {
  6676. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6677. // (so there was no chance for the user to open any session yet)
  6678. if ((ShowLogin || !Startup) &&
  6679. !WinConfiguration->KeepOpenWhenNoSession &&
  6680. // this rules out the implicit Commander's local-local browser
  6681. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6682. {
  6683. TerminateApplication();
  6684. }
  6685. }
  6686. }
  6687. catch (EAbort &)
  6688. {
  6689. // swallow
  6690. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6691. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6692. }
  6693. }
  6694. //---------------------------------------------------------------------------
  6695. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6696. {
  6697. TTerminalManager * Manager = TTerminalManager::Instance();
  6698. DebugAssert(!Manager->Updating);
  6699. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6700. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6701. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6702. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6703. try
  6704. {
  6705. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6706. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6707. {
  6708. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6709. }
  6710. for (int Index = 0; Index <= Manager->Count; Index++)
  6711. {
  6712. TThemeTabSheet * TabSheet;
  6713. if (Index >= SessionsPageControl->PageCount)
  6714. {
  6715. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6716. TabSheet->PageControl = SessionsPageControl;
  6717. }
  6718. else
  6719. {
  6720. TabSheet = SessionsPageControl->Pages[Index];
  6721. }
  6722. bool IsSessionTab = (Index < Manager->Count);
  6723. if (IsSessionTab)
  6724. {
  6725. TTerminal * Terminal = Manager->Sessions[Index];
  6726. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6727. TabSheet->CaptionTruncation = tttEllipsis;
  6728. UpdateSessionTab(TabSheet);
  6729. }
  6730. else
  6731. {
  6732. TabSheet->Tag = 0; // not really needed
  6733. TabSheet->Shadowed = false;
  6734. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6735. TabSheet->CaptionTruncation = tttNoText;
  6736. // 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)
  6737. UpdateNewTabTab();
  6738. }
  6739. }
  6740. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6741. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6742. {
  6743. SessionsPageControl->UpdateTabsCaptionTruncation();
  6744. }
  6745. }
  6746. __finally
  6747. {
  6748. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6749. }
  6750. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6751. }
  6752. //---------------------------------------------------------------------------
  6753. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6754. {
  6755. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6756. }
  6757. //---------------------------------------------------------------------------
  6758. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6759. {
  6760. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6761. UnicodeString TabCaption;
  6762. if (WinConfiguration->SelectiveToolbarText)
  6763. {
  6764. TabCaption = GetNewTabTabCaption();
  6765. }
  6766. TabSheet->BaseCaption = TabCaption;
  6767. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6768. }
  6769. //---------------------------------------------------------------------------
  6770. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6771. {
  6772. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6773. }
  6774. //---------------------------------------------------------------------------
  6775. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6776. {
  6777. DebugFail();
  6778. return UnicodeString();
  6779. }
  6780. //---------------------------------------------------------------------------
  6781. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  6782. {
  6783. if (DebugAlwaysTrue(TabSheet != NULL))
  6784. {
  6785. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6786. if (DebugAlwaysTrue(ASession != NULL))
  6787. {
  6788. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6789. if (ASession->LocalBrowser)
  6790. {
  6791. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6792. }
  6793. else
  6794. {
  6795. TabSheet->ImageIndex = AddSessionColor(Color);
  6796. }
  6797. TTerminalManager * Manager = TTerminalManager::Instance();
  6798. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  6799. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  6800. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  6801. }
  6802. }
  6803. }
  6804. //---------------------------------------------------------------------------
  6805. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  6806. {
  6807. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  6808. }
  6809. //---------------------------------------------------------------------------
  6810. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6811. {
  6812. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6813. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6814. bool Result = (Session != NULL);
  6815. if (Result)
  6816. {
  6817. TTerminalManager::Instance()->ActiveSession = Session;
  6818. }
  6819. else
  6820. {
  6821. try
  6822. {
  6823. NewTab();
  6824. }
  6825. __finally
  6826. {
  6827. SessionListChanged();
  6828. }
  6829. FSessionsPageControlNewTabTime = Now();
  6830. }
  6831. return Result;
  6832. }
  6833. //---------------------------------------------------------------------------
  6834. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6835. {
  6836. TWindowLock Lock(this);
  6837. SessionTabSwitched();
  6838. }
  6839. //---------------------------------------------------------------------------
  6840. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6841. {
  6842. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6843. DebugAssert(TransferList != NULL);
  6844. UnicodeString Name;
  6845. if (TransferList->ItemIndex <= 0)
  6846. {
  6847. Name = L"";
  6848. }
  6849. else
  6850. {
  6851. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6852. }
  6853. if (FCopyParamAutoSelected.IsEmpty())
  6854. {
  6855. // if previous preset was not autoselected, make new preset the "default"
  6856. FCopyParamDefault = Name;
  6857. }
  6858. GUIConfiguration->CopyParamCurrent = Name;
  6859. }
  6860. //---------------------------------------------------------------------------
  6861. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6862. {
  6863. // sanity check
  6864. bool ExistingPreset =
  6865. (FTransferListHoverIndex >= 0) &&
  6866. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6867. DebugAssert(ExistingPreset);
  6868. if (ExistingPreset)
  6869. {
  6870. HDC DC = GetDC(0);
  6871. TCanvas * Canvas = new TCanvas();
  6872. try
  6873. {
  6874. Canvas->Handle = DC;
  6875. Canvas->Font = GetToolbarFont(this);
  6876. UnicodeString Name;
  6877. if (FTransferListHoverIndex == 0)
  6878. {
  6879. Name = L"";
  6880. }
  6881. else
  6882. {
  6883. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6884. }
  6885. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6886. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6887. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6888. static_cast<TObject*>(GetComponent(fcTransferList)));
  6889. UnicodeString InfoStr =
  6890. GUIConfiguration->CopyParamPreset[Name].
  6891. GetInfoStr(L"; ",
  6892. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6893. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6894. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6895. {
  6896. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6897. {
  6898. InfoStr.SetLength(InfoStr.Length() - 1);
  6899. }
  6900. InfoStr += Ellipsis;
  6901. }
  6902. // UpdateCaption does not cause invalidation of whole submenu, while
  6903. // setting Caption property does.
  6904. // also it probably does not resize the label, even if necessary
  6905. // (we do not want that anyway)
  6906. TransferLabel->UpdateCaption(InfoStr);
  6907. }
  6908. __finally
  6909. {
  6910. Canvas->Handle = NULL;
  6911. ReleaseDC(0, DC);
  6912. delete Canvas;
  6913. }
  6914. }
  6915. }
  6916. //---------------------------------------------------------------------------
  6917. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6918. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6919. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6920. {
  6921. if (FTransferListHoverIndex != AHoverIndex)
  6922. {
  6923. FTransferListHoverIndex = AHoverIndex;
  6924. UpdateTransferLabel();
  6925. }
  6926. }
  6927. //---------------------------------------------------------------------------
  6928. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6929. {
  6930. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6931. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6932. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6933. {
  6934. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6935. {
  6936. if (!NonVisualDataModule->Busy)
  6937. {
  6938. OpenDirectory(GetSide(osCurrent));
  6939. }
  6940. Message.Result = 1;
  6941. }
  6942. else
  6943. {
  6944. TForm::Dispatch(&Message);
  6945. }
  6946. }
  6947. else
  6948. {
  6949. TForm::Dispatch(&Message);
  6950. }
  6951. }
  6952. //---------------------------------------------------------------------------
  6953. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6954. {
  6955. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6956. if ((FIgnoreNextDialogChar != 0) &&
  6957. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6958. {
  6959. Message.Result = 1;
  6960. }
  6961. else
  6962. {
  6963. TForm::Dispatch(&Message);
  6964. }
  6965. FIgnoreNextDialogChar = 0;
  6966. }
  6967. //---------------------------------------------------------------------------
  6968. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6969. {
  6970. // The four low-order bits are used internally by Windows
  6971. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6972. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6973. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6974. // 61730 - restore thru double click - undocumented
  6975. // 61490 - maximize thru double click - undocumented
  6976. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6977. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6978. {
  6979. SysResizing(Cmd);
  6980. }
  6981. TForm::Dispatch(&Message);
  6982. }
  6983. //---------------------------------------------------------------------------
  6984. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6985. {
  6986. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6987. // Also there no point returning TRUE as we are not able to
  6988. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6989. // Hence the process termination might be safer :)
  6990. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6991. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6992. {
  6993. Message.Result = FALSE;
  6994. }
  6995. else
  6996. {
  6997. Message.Result = TRUE;
  6998. }
  6999. // Do not call default handling as that triggers OnCloseQuery,
  7000. // where our implementation will popup confirmation dialogs, what we do not want,
  7001. // as per Vista guidelines:
  7002. // https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  7003. }
  7004. //---------------------------------------------------------------------------
  7005. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  7006. {
  7007. if (Message.EndSession && IsApplicationMinimized())
  7008. {
  7009. // WORKAROUND
  7010. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  7011. // when it receives WM_ENDSESSION,
  7012. // but that sometimes (particularly when application is minimized) cause crashes.
  7013. // Crash popups message that blocks log off.
  7014. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  7015. // so we call ExitProcess() immediately, not even trying to cleanup.
  7016. // It still causes beep, so there's likely some popup, but it does not block
  7017. // log off.
  7018. ExitProcess(0);
  7019. }
  7020. TForm::Dispatch(&Message);
  7021. }
  7022. #ifdef _DEBUG
  7023. //---------------------------------------------------------------------------
  7024. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  7025. {
  7026. TForm::Dispatch(&Message);
  7027. }
  7028. #endif
  7029. //---------------------------------------------------------------------------
  7030. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  7031. {
  7032. }
  7033. //---------------------------------------------------------------------------
  7034. void __fastcall TCustomScpExplorerForm::DoShow()
  7035. {
  7036. // Called from TCustomScpExplorerForm::CMShowingChanged
  7037. // only now are the controls resized finally, so the size constraints
  7038. // will not conflict with possibly very small window size
  7039. RestoreFormParams();
  7040. // This indicates that the form was rescaled after parameters were loaded and
  7041. // as most probably the parameters were actually saved with the current form scaling
  7042. // (windows was the last time likely closed on the same monitor, where it is starting now),
  7043. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  7044. // and no rounding problems will occur.
  7045. // See also RestoreForm.
  7046. // (we should be safe to call RestoreParams unconditionally)
  7047. if (PixelsPerInch != Screen->PixelsPerInch)
  7048. {
  7049. RestoreParams();
  7050. }
  7051. FixControlsPlacement();
  7052. if (Position == poDefaultPosOnly)
  7053. {
  7054. CutFormToDesktop(this);
  7055. }
  7056. TForm::DoShow();
  7057. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  7058. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  7059. // This was previously in NeedSession, where other related code is.
  7060. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  7061. // unpleasantly shows briefly.
  7062. if ((ManagedSession == NULL) &&
  7063. !WinConfiguration->ShowLoginWhenNoSession &&
  7064. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  7065. // This detects if workspace was saved the last time the main widow was closed
  7066. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  7067. {
  7068. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  7069. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  7070. }
  7071. // Before main window displays
  7072. if (ManagedSession == NULL)
  7073. {
  7074. StartingWithoutSession();
  7075. }
  7076. UpdatePixelsPerInchMainWindowCounter();
  7077. FShowing = true;
  7078. }
  7079. //---------------------------------------------------------------------------
  7080. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  7081. {
  7082. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  7083. }
  7084. //---------------------------------------------------------------------------
  7085. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  7086. {
  7087. SessionListChanged();
  7088. InitStatusBar();
  7089. UpdateControls();
  7090. }
  7091. //---------------------------------------------------------------------------
  7092. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  7093. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  7094. TNotifyEvent OnBalloonClick, TObject * UserData)
  7095. {
  7096. bool Do;
  7097. UnicodeString Message;
  7098. if (E == NULL)
  7099. {
  7100. Message = Str;
  7101. Do = true;
  7102. }
  7103. else
  7104. {
  7105. Do = ExceptionMessage(E, Message);
  7106. }
  7107. if (Do && WinConfiguration->BalloonNotifications)
  7108. {
  7109. UnicodeString Title;
  7110. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  7111. {
  7112. Message = TrimLeft(Message);
  7113. }
  7114. else
  7115. {
  7116. Message = UnformatMessage(Message);
  7117. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  7118. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  7119. Title = LoadResourceString(Captions[Type]);
  7120. if (Terminal != NULL)
  7121. {
  7122. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7123. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  7124. }
  7125. }
  7126. if (Seconds == 0)
  7127. {
  7128. Seconds = WinConfiguration->NotificationsTimeout;
  7129. }
  7130. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  7131. }
  7132. }
  7133. //---------------------------------------------------------------------------
  7134. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  7135. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  7136. UnicodeString HelpKeyword, const TMessageParams * Params,
  7137. TTerminal * Terminal)
  7138. {
  7139. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  7140. (FOnFeedSynchronizeError != NULL)) &&
  7141. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  7142. {
  7143. if (FOnFeedSynchronizeError != NULL)
  7144. {
  7145. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  7146. }
  7147. else
  7148. {
  7149. DebugAssert(FErrorList != NULL);
  7150. TStringList * MoreMessagesCopy = NULL;
  7151. if (MoreMessages)
  7152. {
  7153. MoreMessagesCopy = new TStringList();
  7154. MoreMessagesCopy->Assign(MoreMessages);
  7155. }
  7156. FErrorList->AddObject(Message, MoreMessagesCopy);
  7157. }
  7158. PopupTrayBalloon(Terminal, Message, Type);
  7159. return ContinueAnswer(Answers);
  7160. }
  7161. else
  7162. {
  7163. bool UseBalloon = FTrayIcon->Visible;
  7164. if (UseBalloon)
  7165. {
  7166. PopupTrayBalloon(Terminal, Message, Type);
  7167. }
  7168. unsigned int Result;
  7169. try
  7170. {
  7171. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7172. }
  7173. __finally
  7174. {
  7175. // cancel only balloon we popped up, otherwise we may cancel notification
  7176. // balloon that was there before the message dialog
  7177. // (such as "dd confirmation opt in balloon)
  7178. if (UseBalloon)
  7179. {
  7180. FTrayIcon->CancelBalloon();
  7181. }
  7182. }
  7183. return Result;
  7184. }
  7185. }
  7186. //---------------------------------------------------------------------------
  7187. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7188. TTerminal * Terminal, Exception * E)
  7189. {
  7190. if (FTrayIcon->Visible)
  7191. {
  7192. PopupTrayBalloon(Terminal, L"", qtError, E);
  7193. }
  7194. // particularly prevent opening new session from jump list,
  7195. // while exception is shown
  7196. NonVisualDataModule->StartBusy();
  7197. try
  7198. {
  7199. ShowExtendedExceptionEx(Terminal, E);
  7200. }
  7201. __finally
  7202. {
  7203. NonVisualDataModule->EndBusy();
  7204. FTrayIcon->CancelBalloon();
  7205. }
  7206. }
  7207. //---------------------------------------------------------------------------
  7208. void __fastcall TCustomScpExplorerForm::SessionReady()
  7209. {
  7210. InitStatusBar();
  7211. // cannot rely on active page being page for active terminal,
  7212. // as it can happen that active page is the "new session" page
  7213. // (e.g. when reconnecting active terminal, while login dialog
  7214. // invoked from "new session" page is modal)
  7215. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7216. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7217. }
  7218. //---------------------------------------------------------------------------
  7219. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7220. TTerminal * Terminal, Exception * E)
  7221. {
  7222. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7223. if (!Terminal->Active)
  7224. {
  7225. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7226. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7227. {
  7228. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7229. }
  7230. }
  7231. }
  7232. //---------------------------------------------------------------------------
  7233. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7234. UnicodeString Message, TQueryType Type,
  7235. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7236. {
  7237. if ((E == NULL) ||
  7238. ExceptionMessage(E, Message))
  7239. {
  7240. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7241. if (Important)
  7242. {
  7243. Seconds *= 5;
  7244. }
  7245. UnicodeString NoteMessage(UnformatMessage(Message));
  7246. if (Terminal != NULL)
  7247. {
  7248. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7249. NoteMessage = FORMAT(L"%s: %s",
  7250. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7251. }
  7252. if (WinConfiguration->BalloonNotifications)
  7253. {
  7254. AddNote(NoteMessage);
  7255. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7256. }
  7257. else
  7258. {
  7259. FlashOnBackground();
  7260. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7261. }
  7262. }
  7263. }
  7264. //---------------------------------------------------------------------------
  7265. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7266. {
  7267. RestoreApp();
  7268. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7269. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7270. !NonVisualDataModule->Busy)
  7271. {
  7272. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7273. TTerminalManager::Instance()->ActiveSession = Terminal;
  7274. if (!ComponentVisible[fcQueueView])
  7275. {
  7276. ToggleQueueVisibility();
  7277. GoToQueue();
  7278. }
  7279. }
  7280. }
  7281. //---------------------------------------------------------------------------
  7282. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7283. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7284. {
  7285. UnicodeString Message;
  7286. TNotifyEvent OnClick = NULL;
  7287. TObject * UserData = NULL;
  7288. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7289. switch (Event)
  7290. {
  7291. case qeEmptyButMonitored:
  7292. if ((ATerminal != Terminal) || QueueInvisible)
  7293. {
  7294. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7295. OnClick = QueueEmptyNoteClicked;
  7296. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7297. TerminalNoteData->Terminal = ATerminal;
  7298. UserData = TerminalNoteData;
  7299. }
  7300. break;
  7301. case qeEmpty:
  7302. OperationComplete(ATerminal->QueueOperationStart);
  7303. break;
  7304. case qePendingUserAction:
  7305. if ((ATerminal != Terminal) ||
  7306. (QueueInvisible && !IsQueueAutoPopup()))
  7307. {
  7308. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7309. }
  7310. break;
  7311. default:
  7312. DebugFail();
  7313. }
  7314. if (!Message.IsEmpty())
  7315. {
  7316. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7317. }
  7318. }
  7319. //---------------------------------------------------------------------------
  7320. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7321. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7322. {
  7323. if (FDDExtMapFile != NULL)
  7324. {
  7325. CloseHandle(FDDExtMapFile);
  7326. FDDExtMapFile = NULL;
  7327. }
  7328. if (WinConfiguration->DDFakeFile)
  7329. {
  7330. DDFakeFileInitDrag(FileList, Created);
  7331. }
  7332. }
  7333. //---------------------------------------------------------------------------
  7334. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7335. {
  7336. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7337. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7338. {
  7339. FFakeFileDropTarget = FileName;
  7340. }
  7341. }
  7342. //---------------------------------------------------------------------------
  7343. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7344. {
  7345. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7346. if (!ForceDirectories(ApiPath(Result)))
  7347. {
  7348. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7349. }
  7350. FileSetAttr(ApiPath(Result), faHidden);
  7351. return Result;
  7352. }
  7353. //---------------------------------------------------------------------------
  7354. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7355. bool & Created)
  7356. {
  7357. FFakeFileDropTarget = UnicodeString();
  7358. FDragFakeDirectory = CreateFakeTransferDirectory();
  7359. FileList->AddItem(NULL, FDragFakeDirectory);
  7360. Created = true;
  7361. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7362. {
  7363. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7364. }
  7365. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7366. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7367. {
  7368. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7369. TDragExtCommStruct* CommStruct;
  7370. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7371. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7372. DebugAssert(CommStruct != NULL);
  7373. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7374. CommStruct->Dragging = true;
  7375. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7376. LENOF(CommStruct->DropDest));
  7377. NULL_TERMINATE(CommStruct->DropDest);
  7378. UnmapViewOfFile(CommStruct);
  7379. }
  7380. }
  7381. //---------------------------------------------------------------------------
  7382. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7383. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7384. {
  7385. bool Result;
  7386. DebugAssert(!IsLocalBrowserMode());
  7387. if (Sender == RemoteDirView)
  7388. {
  7389. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7390. }
  7391. else
  7392. {
  7393. DebugAssert(Sender == RemoteDriveView);
  7394. TStrings * FileList = RemoteDriveView->DragFileList();
  7395. try
  7396. {
  7397. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7398. }
  7399. __finally
  7400. {
  7401. delete FileList;
  7402. }
  7403. }
  7404. if (FDDTargetControl == RemoteDriveView)
  7405. {
  7406. RemoteDriveView->UpdateDropTarget();
  7407. }
  7408. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7409. // or from tree view to dir view.
  7410. // foMove happens when file/dir is dragged from remote tree view outside of
  7411. // application via dragex
  7412. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7413. (DropSourceControl == RemoteDriveView))
  7414. {
  7415. RemoteDriveView->UpdateDropSource();
  7416. }
  7417. return Result;
  7418. }
  7419. //---------------------------------------------------------------------------
  7420. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7421. {
  7422. DebugAssert(!IsLocalBrowserMode());
  7423. // This also handles drops of remote files to queue.
  7424. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7425. SAFE_DESTROY(FDDFileList);
  7426. if (!FFakeFileDropTarget.IsEmpty())
  7427. {
  7428. RemoveDir(ApiPath(FFakeFileDropTarget));
  7429. }
  7430. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7431. {
  7432. try
  7433. {
  7434. TDragResult DDResult = (Sender == RemoteDirView) ?
  7435. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7436. // Focus is moved to the target application,
  7437. // but as we are going to present the UI, we need to steal the focus back.
  7438. // This most likely won't work though (windows does not allow application
  7439. // to steal focus most of the time)
  7440. Application->BringToFront();
  7441. // On older version of Windows we never got drMove here, see also comment below.
  7442. // On Windows 10, we get the "move".
  7443. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7444. {
  7445. UnicodeString TargetDirectory;
  7446. TFileOperation Operation;
  7447. // drInvalid may mean drMove, see comment below
  7448. switch (DDResult)
  7449. {
  7450. case drCopy:
  7451. Operation = foCopy;
  7452. break;
  7453. case drMove:
  7454. Operation = foMove;
  7455. break;
  7456. default:
  7457. DebugFail();
  7458. case drInvalid:
  7459. // prefer "copy" for safety
  7460. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7461. break;
  7462. }
  7463. TTransferOperationParam Param;
  7464. UnicodeString CounterName;
  7465. bool ForceQueue;
  7466. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7467. {
  7468. // we get drInvalid both if d&d was intercepted by ddext,
  7469. // and when users drops on no-drop location.
  7470. // we tell the difference by existence of response from ddext,
  7471. // so we ignore absence of response in this case
  7472. if (DDResult != drInvalid)
  7473. {
  7474. // here we know that the extension is installed,
  7475. // as it is checked as soon as drag&drop starts from
  7476. // RemoteFileControlDDCreateDragFileList
  7477. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7478. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7479. {
  7480. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7481. }
  7482. else
  7483. {
  7484. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7485. }
  7486. }
  7487. }
  7488. else
  7489. {
  7490. // download using fake file
  7491. Param.Temp = false;
  7492. Param.DragDrop = true;
  7493. if (ForceQueue)
  7494. {
  7495. Param.Queue = asOn;
  7496. }
  7497. if (Sender == RemoteDirView)
  7498. {
  7499. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7500. }
  7501. if (RemoteFileControlFileOperation(Sender, Operation,
  7502. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7503. {
  7504. Configuration->Usage->Inc(CounterName);
  7505. }
  7506. }
  7507. }
  7508. }
  7509. __finally
  7510. {
  7511. CloseHandle(FDDExtMapFile);
  7512. FDDExtMapFile = NULL;
  7513. delete FDragFakeMonitors;
  7514. FDragFakeMonitors = NULL;
  7515. RemoveDir(ApiPath(FDragFakeDirectory));
  7516. FDragFakeDirectory = L"";
  7517. FFakeFileDropTarget = UnicodeString();
  7518. }
  7519. }
  7520. if (FDragDropSshTerminate.get() != NULL)
  7521. {
  7522. FDragDropSshTerminate->Rethrow();
  7523. }
  7524. }
  7525. //---------------------------------------------------------------------------
  7526. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7527. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7528. {
  7529. // Remember drop effect so we know (when user drops files), if we copy or move
  7530. FLastDropEffect = dwEffect;
  7531. }
  7532. //---------------------------------------------------------------------------
  7533. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7534. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7535. {
  7536. bool Result;
  7537. if (FDDTargetControl == QueueView3)
  7538. {
  7539. Directory = DefaultDownloadTargetDirectory();
  7540. Result = true;
  7541. CounterName = L"DownloadsDragDropQueue";
  7542. ForceQueue = true;
  7543. }
  7544. else if (!FFakeFileDropTarget.IsEmpty())
  7545. {
  7546. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7547. Result = true;
  7548. ForceQueue = false;
  7549. CounterName = L"DownloadsDragDropFakeFile";
  7550. }
  7551. else
  7552. {
  7553. ForceQueue = false;
  7554. Enabled = false;
  7555. try
  7556. {
  7557. int Timer = 0;
  7558. Result = false;
  7559. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7560. {
  7561. {
  7562. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7563. TDragExtCommStruct* CommStruct;
  7564. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7565. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7566. DebugAssert(CommStruct != NULL);
  7567. Result = !CommStruct->Dragging;
  7568. if (Result)
  7569. {
  7570. Directory = ExtractFilePath(CommStruct->DropDest);
  7571. CounterName = L"DownloadsDragDropExternalExt";
  7572. }
  7573. UnmapViewOfFile(CommStruct);
  7574. }
  7575. if (!Result)
  7576. {
  7577. Sleep(50);
  7578. Timer += 50;
  7579. Application->ProcessMessages();
  7580. }
  7581. }
  7582. }
  7583. __finally
  7584. {
  7585. Enabled = true;
  7586. }
  7587. }
  7588. return Result;
  7589. }
  7590. //---------------------------------------------------------------------------
  7591. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7592. const UnicodeString TempDir, int SecDelay)
  7593. {
  7594. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7595. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7596. if (FDelayedDeletionTimer == NULL)
  7597. {
  7598. DebugAssert(HandleAllocated());
  7599. FDelayedDeletionTimer = new TTimer(this);
  7600. FDelayedDeletionTimer->Interval = 10000;
  7601. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7602. }
  7603. else
  7604. {
  7605. FDelayedDeletionTimer->Enabled = true;
  7606. }
  7607. }
  7608. //---------------------------------------------------------------------------
  7609. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7610. {
  7611. DebugAssert(FDelayedDeletionList != NULL);
  7612. TDateTime N = Now();
  7613. TDateTime Alert;
  7614. UnicodeString Directory;
  7615. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7616. {
  7617. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7618. if ((N >= Alert) || (Sender == NULL))
  7619. {
  7620. Directory = FDelayedDeletionList->Strings[Index];
  7621. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7622. {
  7623. FDelayedDeletionList->Delete(Index);
  7624. }
  7625. }
  7626. }
  7627. if (FDelayedDeletionList->Count == 0)
  7628. {
  7629. FDelayedDeletionTimer->Enabled = false;
  7630. }
  7631. }
  7632. //---------------------------------------------------------------------------
  7633. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7634. {
  7635. DebugAssert(!IsLocalBrowserMode());
  7636. if (IsFileControl(FDDTargetControl, osRemote) ||
  7637. (FDDTargetControl == SessionsPageControl))
  7638. {
  7639. TManagedTerminal * TargetTerminal = NULL;
  7640. TFileOperation Operation = foNone;
  7641. if (FDDTargetControl == SessionsPageControl)
  7642. {
  7643. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7644. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7645. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7646. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7647. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7648. {
  7649. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7650. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7651. {
  7652. Operation = foRemoteMove;
  7653. }
  7654. else
  7655. {
  7656. Operation = foRemoteCopy;
  7657. }
  7658. }
  7659. }
  7660. else
  7661. {
  7662. if (FLastDropEffect == DROPEFFECT_MOVE)
  7663. {
  7664. Operation = foRemoteMove;
  7665. }
  7666. else if (FLastDropEffect == DROPEFFECT_COPY)
  7667. {
  7668. Operation = foRemoteCopy;
  7669. }
  7670. }
  7671. if (Operation != foNone)
  7672. {
  7673. RemoteFileControlFileOperation(DropSourceControl,
  7674. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7675. }
  7676. // abort drag&drop
  7677. Abort();
  7678. }
  7679. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7680. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7681. (FDDTargetControl != QueueView3))
  7682. {
  7683. DebugAssert(!FDragTempDir.IsEmpty());
  7684. TTransferType Type;
  7685. UnicodeString TempDir = FDragTempDir;
  7686. // We clear FDragTempDir before calling
  7687. // just in case it fail (raises exception)
  7688. FDragTempDir = L"";
  7689. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7690. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7691. // empty directory parameter means temp directory -> don't display it!
  7692. UnicodeString TargetDir = L"";
  7693. int Options = 0;
  7694. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7695. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7696. {
  7697. Abort();
  7698. }
  7699. // TargetDir is set when dropped on local file control
  7700. // (this was workaround for legacy dirview event handling, now it should be
  7701. // made prettier)
  7702. if (TargetDir.IsEmpty())
  7703. {
  7704. TargetDir = TempDir;
  7705. if (ForceDirectories(ApiPath(TargetDir)))
  7706. {
  7707. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7708. FPendingTempSpaceWarn = true;
  7709. try
  7710. {
  7711. FDragDropOperation = true;
  7712. int Params = cpTemporary |
  7713. (Type == ttMove ? cpDelete : 0);
  7714. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7715. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7716. }
  7717. __finally
  7718. {
  7719. FDragDropOperation = false;
  7720. FPendingTempSpaceWarn = false;
  7721. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7722. }
  7723. }
  7724. else
  7725. {
  7726. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7727. }
  7728. }
  7729. }
  7730. }
  7731. //---------------------------------------------------------------------------
  7732. void __fastcall TCustomScpExplorerForm::DDDownload(
  7733. TStrings * FilesToCopy, const UnicodeString & TargetDir, TCopyParamType * CopyParam, int Params)
  7734. {
  7735. DebugAssert(!IsLocalBrowserMode());
  7736. TAutoBatch AutoBatch(this);
  7737. CopyParam->IncludeFileMask.SetRoots(TargetDir, FilesToCopy);
  7738. UpdateCopyParamCounters(*CopyParam);
  7739. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7740. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7741. {
  7742. RemoteDriveView->UpdateDropSource();
  7743. }
  7744. }
  7745. //---------------------------------------------------------------------------
  7746. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7747. {
  7748. public:
  7749. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7750. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7751. {
  7752. }
  7753. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7754. {
  7755. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7756. TDataObjectFilesEx::AllowData(FormatEtc);
  7757. }
  7758. };
  7759. //---------------------------------------------------------------------------
  7760. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7761. TObject * Sender, TDataObject *& DataObject)
  7762. {
  7763. if (FDDExtMapFile != NULL)
  7764. {
  7765. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7766. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7767. {
  7768. Abort();
  7769. }
  7770. if (FileList->Count > 0)
  7771. {
  7772. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7773. if (!FilesObject->IsValid(true, true))
  7774. {
  7775. FilesObject->_Release();
  7776. }
  7777. else
  7778. {
  7779. DataObject = FilesObject;
  7780. }
  7781. }
  7782. }
  7783. }
  7784. //---------------------------------------------------------------------------
  7785. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7786. {
  7787. DebugFail();
  7788. }
  7789. //---------------------------------------------------------------------------
  7790. void __fastcall TCustomScpExplorerForm::GoToTree()
  7791. {
  7792. ComponentVisible[fcRemoteTree] = true;
  7793. DriveView(osRemote)->SetFocus();
  7794. }
  7795. //---------------------------------------------------------------------------
  7796. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7797. TPanelExport Export)
  7798. {
  7799. TCustomDirView * DirView = this->DirView(Side);
  7800. std::unique_ptr<TStrings> ExportData(new TStringList());
  7801. switch (Export)
  7802. {
  7803. case pePath:
  7804. ExportData->Add(DirView->PathName);
  7805. break;
  7806. case peFileList:
  7807. case peFullFileList:
  7808. {
  7809. bool FullPath = (Export == peFullFileList);
  7810. DirView->CreateFileList(false, FullPath, ExportData.get());
  7811. for (int Index = 0; Index < ExportData->Count; Index++)
  7812. {
  7813. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7814. {
  7815. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7816. }
  7817. }
  7818. }
  7819. break;
  7820. default:
  7821. DebugFail();
  7822. }
  7823. return ExportData.release();
  7824. }
  7825. //---------------------------------------------------------------------------
  7826. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7827. TPanelExport Export, TPanelExportDestination Destination)
  7828. {
  7829. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7830. PanelExportStore(Side, Export, Destination, ExportData.get());
  7831. }
  7832. //---------------------------------------------------------------------------
  7833. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7834. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7835. TStrings * ExportData)
  7836. {
  7837. if (Destination == pedClipboard)
  7838. {
  7839. TInstantOperationVisualizer Visualizer;
  7840. CopyToClipboard(ExportData);
  7841. }
  7842. else
  7843. {
  7844. DebugFail();
  7845. }
  7846. }
  7847. //---------------------------------------------------------------------------
  7848. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7849. {
  7850. TCustomDirView * DirView = this->DirView(Side);
  7851. UnicodeString Mask = DirView->Mask;
  7852. if (DoFilterMaskDialog(DirView, Mask))
  7853. {
  7854. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7855. Configuration->Usage->Inc(L"Filters");
  7856. }
  7857. }
  7858. //---------------------------------------------------------------------------
  7859. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7860. {
  7861. return FQueueController->DefaultOperation();
  7862. }
  7863. //---------------------------------------------------------------------------
  7864. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7865. TQueueOperation Operation, void ** Param)
  7866. {
  7867. switch (Operation)
  7868. {
  7869. case qoPreferences:
  7870. return true;
  7871. case qoGoTo:
  7872. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7873. case qoOnceEmpty:
  7874. return IsAnythingQueued();
  7875. default:
  7876. return FQueueController->AllowOperation(Operation, Param);
  7877. }
  7878. }
  7879. //---------------------------------------------------------------------------
  7880. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7881. {
  7882. if (DebugAlwaysTrue(QueueView3->Visible))
  7883. {
  7884. QueueView3->SetFocus();
  7885. }
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7889. TQueueOperation Operation, void * Param)
  7890. {
  7891. if (Operation == qoGoTo)
  7892. {
  7893. GoToQueue();
  7894. }
  7895. else if (Operation == qoPreferences)
  7896. {
  7897. PreferencesDialog(pmQueue);
  7898. }
  7899. else
  7900. {
  7901. FQueueController->ExecuteOperation(Operation, Param);
  7902. }
  7903. }
  7904. //---------------------------------------------------------------------------
  7905. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7906. {
  7907. return (Queue != NULL) && Queue->Enabled;
  7908. }
  7909. //---------------------------------------------------------------------------
  7910. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7911. {
  7912. DebugAssert(Queue != NULL);
  7913. if (Queue != NULL)
  7914. {
  7915. Queue->Enabled = !Queue->Enabled;
  7916. }
  7917. }
  7918. //---------------------------------------------------------------------------
  7919. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7920. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7921. {
  7922. FQueueActedItem = QueueView3->ItemFocused;
  7923. }
  7924. //---------------------------------------------------------------------------
  7925. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7926. {
  7927. return TopDock->Height + (MessageDock->Visible ? MessageDock->Height : 0) + QueueSplitter->Height;
  7928. }
  7929. //---------------------------------------------------------------------------
  7930. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7931. {
  7932. return
  7933. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7934. (QueueDock->Visible ? QueueDock->Height : 0) +
  7935. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7936. }
  7937. //---------------------------------------------------------------------------
  7938. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7939. {
  7940. return ScaleByTextHeight(this, 48);
  7941. }
  7942. //---------------------------------------------------------------------------
  7943. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7944. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7945. {
  7946. // when queue is hidden by double-clicking splitter, stray attempt to
  7947. // resize the panel with strange value arrives, make sure it is ignored
  7948. if (ComponentVisible[fcQueueView])
  7949. {
  7950. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7951. if (NewSize > MaxHeightLimit)
  7952. {
  7953. NewSize = MaxHeightLimit;
  7954. }
  7955. int MinHeightLimit =
  7956. GetStaticQueuePanelComponentsHeight() +
  7957. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7958. GetMinQueueViewHeight();
  7959. if (NewSize < MinHeightLimit)
  7960. {
  7961. NewSize = MinHeightLimit;
  7962. }
  7963. }
  7964. else
  7965. {
  7966. Accept = false;
  7967. }
  7968. }
  7969. //---------------------------------------------------------------------------
  7970. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7971. {
  7972. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7973. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7974. if (QueueViewHeight < GetMinQueueViewHeight())
  7975. {
  7976. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7977. }
  7978. }
  7979. //---------------------------------------------------------------------------
  7980. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7981. TDragObject *& /*DragObject*/)
  7982. {
  7983. FQueueActedItem = QueueView3->ItemFocused;
  7984. FQueueScrollOnDragOver->StartDrag();
  7985. }
  7986. //---------------------------------------------------------------------------
  7987. void __fastcall TCustomScpExplorerForm::QueueView3EndDrag(
  7988. TObject *, TObject * DebugUsedArg(Target), int DebugUsedArg(X), int DebugUsedArg(Y))
  7989. {
  7990. FQueueScrollOnDragOver->EndDrag();
  7991. }
  7992. //---------------------------------------------------------------------------
  7993. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7994. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7995. {
  7996. Accept = true;
  7997. if (Source == QueueView3)
  7998. {
  7999. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  8000. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  8001. if (Accept)
  8002. {
  8003. TQueueItemProxy * QueueItem;
  8004. TQueueItemProxy * DestQueueItem;
  8005. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8006. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  8007. Accept = (QueueItem != DestQueueItem) &&
  8008. (QueueItem->Status == TQueueItem::qsPending) &&
  8009. (DestQueueItem->Status == TQueueItem::qsPending);
  8010. }
  8011. FQueueScrollOnDragOver->DragOver(TPoint(X, Y));
  8012. }
  8013. }
  8014. //---------------------------------------------------------------------------
  8015. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  8016. TObject * /*Source*/, int /*X*/, int /*Y*/)
  8017. {
  8018. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  8019. {
  8020. TQueueItemProxy * QueueItem;
  8021. TQueueItemProxy * DestQueueItem;
  8022. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8023. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  8024. QueueItem->Move(DestQueueItem);
  8025. }
  8026. }
  8027. //---------------------------------------------------------------------------
  8028. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  8029. {
  8030. if ((QueueView3->ItemFocused == NULL) &&
  8031. (QueueView3->Items->Count > 0))
  8032. {
  8033. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  8034. }
  8035. QueueLabelUpdateStatus();
  8036. }
  8037. //---------------------------------------------------------------------------
  8038. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  8039. {
  8040. QueueLabelUpdateStatus();
  8041. }
  8042. //---------------------------------------------------------------------------
  8043. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  8044. {
  8045. QueueLabel->UpdateStatus();
  8046. }
  8047. //---------------------------------------------------------------------------
  8048. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  8049. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  8050. {
  8051. if (Selected)
  8052. {
  8053. NonVisualDataModule->UpdateNonVisibleActions();
  8054. }
  8055. }
  8056. //---------------------------------------------------------------------------
  8057. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  8058. {
  8059. TDragDropFilesEx * Result = NULL;
  8060. if (Sender == SessionsPageControl)
  8061. {
  8062. Result = FSessionsDragDropFilesEx;
  8063. }
  8064. else if (Sender == QueueView3)
  8065. {
  8066. Result = FQueueDragDropFilesEx;
  8067. }
  8068. else
  8069. {
  8070. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8071. if (DirView != NULL)
  8072. {
  8073. Result = DirView->DragDropFilesEx;
  8074. }
  8075. else
  8076. {
  8077. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  8078. if (DriveView != NULL)
  8079. {
  8080. Result = DriveView->DragDropFilesEx;
  8081. }
  8082. }
  8083. }
  8084. DebugAssert(Result != NULL);
  8085. return Result;
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  8089. {
  8090. return (DView->SelCount == DView->FilesCount);
  8091. }
  8092. //---------------------------------------------------------------------------
  8093. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  8094. {
  8095. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  8096. }
  8097. //---------------------------------------------------------------------------
  8098. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  8099. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  8100. {
  8101. DebugAssert(!IsLocalBrowserMode());
  8102. TFileOperation Operation;
  8103. switch (Effect)
  8104. {
  8105. case DROPEFFECT_MOVE:
  8106. Operation = foMove;
  8107. break;
  8108. case DROPEFFECT_COPY:
  8109. // occures on WinXP (reported by user)
  8110. default:
  8111. Operation = foCopy;
  8112. break;
  8113. };
  8114. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  8115. // see a comment in TUnixDirView::PerformItemDragDropOperation
  8116. if (DragDropFilesEx->FileList->Count > 0)
  8117. {
  8118. TStrings * FileList = new TStringList();
  8119. try
  8120. {
  8121. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  8122. {
  8123. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  8124. }
  8125. FDragDropOperation = true;
  8126. TTransferOperationParam Param;
  8127. Param.TargetDirectory = TargetPath;
  8128. // upload, no temp dirs
  8129. Param.Temp = false;
  8130. Param.DragDrop = DragDrop;
  8131. Param.Options =
  8132. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  8133. if (ForceQueue)
  8134. {
  8135. Param.Queue = asOn;
  8136. }
  8137. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  8138. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  8139. {
  8140. if (IsFileControl(DropSourceControl, osLocal))
  8141. {
  8142. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  8143. }
  8144. else
  8145. {
  8146. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  8147. }
  8148. }
  8149. }
  8150. __finally
  8151. {
  8152. FDragDropOperation = false;
  8153. delete FileList;
  8154. }
  8155. }
  8156. }
  8157. //---------------------------------------------------------------------------
  8158. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  8159. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  8160. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  8161. {
  8162. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  8163. }
  8164. //---------------------------------------------------------------------------
  8165. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  8166. TObject * Sender, int grfKeyState, int & dwEffect)
  8167. {
  8168. DebugAssert(!IsLocalBrowserMode());
  8169. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  8170. if ((dwEffect != DROPEFFECT_NONE) &&
  8171. IsFileControl(DropSourceControl, osRemote))
  8172. {
  8173. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8174. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8175. (RemoteDirView->DropTarget == NULL))
  8176. {
  8177. dwEffect = DROPEFFECT_NONE;
  8178. }
  8179. else
  8180. {
  8181. if (dwEffect == DROPEFFECT_COPY)
  8182. {
  8183. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8184. // currently we support copying always (at least via temporary directory);
  8185. // remove associated checks once this all proves stable and working
  8186. bool CopyCapable = true;
  8187. // if we do not support neither of operations, there's no discussion
  8188. if (!MoveCapable && !CopyCapable)
  8189. {
  8190. dwEffect = DROPEFFECT_NONE;
  8191. }
  8192. else
  8193. {
  8194. // The default effect inside remote panel is move,
  8195. // unless we do not support it, but support copy
  8196. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8197. {
  8198. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8199. }
  8200. else
  8201. {
  8202. // with ctrl-down, we want copy unless it is not supported
  8203. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8204. }
  8205. }
  8206. }
  8207. }
  8208. }
  8209. }
  8210. //---------------------------------------------------------------------------
  8211. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8212. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8213. {
  8214. DebugAssert(!IsLocalBrowserMode());
  8215. if (FDDTotalSize >= 0)
  8216. {
  8217. if (File->IsDirectory)
  8218. {
  8219. FDDTotalSize = -1;
  8220. }
  8221. else
  8222. {
  8223. FDDTotalSize += File->Size;
  8224. }
  8225. }
  8226. DebugAssert(!FDragTempDir.IsEmpty());
  8227. // TODO: this is quite ineffective
  8228. // TODO: what if invalid character replacement is disabled?
  8229. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8230. UnicodeString TransferFileName;
  8231. if (Sender == RemoteDriveView)
  8232. {
  8233. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8234. }
  8235. else
  8236. {
  8237. TransferFileName = File->FileName;
  8238. }
  8239. FDDFileList->AddObject(TransferFileName, File);
  8240. }
  8241. //---------------------------------------------------------------------------
  8242. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8243. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8244. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8245. {
  8246. // sometimes we do not get DDEnd so the list is not released
  8247. SAFE_DESTROY(FDDFileList);
  8248. FDDFileList = new TStringList();
  8249. FDragTempDir = WinConfiguration->TemporaryDir();
  8250. FDDTotalSize = 0;
  8251. FDragDropSshTerminate.reset(NULL);
  8252. }
  8253. //---------------------------------------------------------------------------
  8254. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8255. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  8256. HRESULT & Result)
  8257. {
  8258. if (Result == DRAGDROP_S_DROP)
  8259. {
  8260. try
  8261. {
  8262. GlobalDragImageList->HideDragImage();
  8263. try
  8264. {
  8265. RemoteFileControlDDTargetDrop();
  8266. }
  8267. catch(ESshTerminate & E)
  8268. {
  8269. FDragDropSshTerminate.reset(E.Clone());
  8270. }
  8271. }
  8272. catch (Exception &E)
  8273. {
  8274. // If downloading fails we need to cancel drag&drop, otherwise
  8275. // Explorer shows error
  8276. // But by the way exception probably never reach this point as
  8277. // it's catched on way.
  8278. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8279. Result = DRAGDROP_S_CANCEL;
  8280. ShowExtendedException(Terminal, &E);
  8281. }
  8282. }
  8283. }
  8284. //---------------------------------------------------------------------------
  8285. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8286. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8287. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8288. {
  8289. TFileMasks::TParams MaskParams;
  8290. MaskParams.Size = Size;
  8291. MaskParams.Modification = Modification;
  8292. // this does not re-parse the mask if it is the same as the last time
  8293. FDirViewMatchMask = Masks;
  8294. bool ImplicitMatch;
  8295. Matches =
  8296. // Local and RecurseInclude parameters have no effect as there's no path.
  8297. // This should use potential MatchesFileName overload with ImplicitMatch argument.
  8298. FDirViewMatchMask.Matches(FileName, false, Directory, &MaskParams, true, ImplicitMatch) &&
  8299. (AllowImplicitMatches || !ImplicitMatch);
  8300. }
  8301. //---------------------------------------------------------------------------
  8302. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8303. TObject * Sender, TListItem * Item, WORD & Indexes)
  8304. {
  8305. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8306. UnicodeString Ext;
  8307. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  8308. {
  8309. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  8310. }
  8311. else
  8312. {
  8313. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  8314. }
  8315. if (SameText(Ext, Configuration->PartialExt))
  8316. {
  8317. Indexes |= oiPartial;
  8318. }
  8319. }
  8320. //---------------------------------------------------------------------------
  8321. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8322. {
  8323. return
  8324. DirViewEnabled(osCurrent) &&
  8325. DirView(osCurrent)->CanPasteFromClipBoard();
  8326. }
  8327. //---------------------------------------------------------------------------
  8328. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8329. {
  8330. bool Result = false;
  8331. if (CanPasteToDirViewFromClipBoard())
  8332. {
  8333. Result = true;
  8334. }
  8335. else
  8336. {
  8337. UnicodeString ClipboardText;
  8338. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8339. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8340. {
  8341. if (StoredSessions->IsUrl(ClipboardText))
  8342. {
  8343. Result = true;
  8344. }
  8345. else
  8346. {
  8347. Result = DirViewEnabled(osCurrent);
  8348. }
  8349. }
  8350. }
  8351. return Result;
  8352. }
  8353. //---------------------------------------------------------------------------
  8354. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8355. {
  8356. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8357. if (DoesClipboardContainOurFiles())
  8358. {
  8359. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8360. {
  8361. DebugAssert(!IsLocalBrowserMode());
  8362. TTerminalManager * Manager = TTerminalManager::Instance();
  8363. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8364. Manager->ActiveSession = FClipboardTerminal;
  8365. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8366. }
  8367. }
  8368. else if (CanPasteToDirViewFromClipBoard())
  8369. {
  8370. DirView(osCurrent)->PasteFromClipBoard();
  8371. }
  8372. else
  8373. {
  8374. UnicodeString ClipboardText;
  8375. if (NonEmptyTextFromClipboard(ClipboardText))
  8376. {
  8377. if (StoredSessions->IsUrl(ClipboardText))
  8378. {
  8379. NewSession(ClipboardText);
  8380. }
  8381. else
  8382. {
  8383. DirView(osCurrent)->Path = ClipboardText;
  8384. }
  8385. }
  8386. }
  8387. }
  8388. //---------------------------------------------------------------------------
  8389. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8390. {
  8391. // TBD
  8392. }
  8393. //---------------------------------------------------------------------------
  8394. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8395. {
  8396. TCustomDirView * ADirView = DirView(Side);
  8397. ADirView->SelectAll(Mode);
  8398. ADirView->SetFocus();
  8399. }
  8400. //---------------------------------------------------------------------------
  8401. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8402. {
  8403. TCustomDirView * ADirView = DirView(Side);
  8404. TFileFilter Filter;
  8405. DefaultFileFilter(Filter);
  8406. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8407. {
  8408. Configuration->Usage->Inc(L"MaskSelections");
  8409. ADirView->SelectFiles(Filter, Select);
  8410. ADirView->SetFocus();
  8411. }
  8412. }
  8413. //---------------------------------------------------------------------------
  8414. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8415. {
  8416. TCustomDirView * ADirView = DirView(Side);
  8417. ADirView->RestoreSelectedNames();
  8418. ADirView->SetFocus();
  8419. }
  8420. //---------------------------------------------------------------------------
  8421. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8422. {
  8423. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8424. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8425. {
  8426. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8427. UnicodeString Ext;
  8428. if (!IsSideLocalBrowser(osCurrent))
  8429. {
  8430. Ext = UnixExtractFileExt(FileName);
  8431. }
  8432. else
  8433. {
  8434. Ext = ExtractFileExt(FileName);
  8435. }
  8436. if (Ext.IsEmpty())
  8437. {
  8438. Ext = L".";
  8439. }
  8440. TFileFilter Filter;
  8441. Filter.Masks = FORMAT(L"*%s", (Ext));
  8442. Filter.Directories = false;
  8443. CurrentDirView->SelectFiles(Filter, Select);
  8444. }
  8445. }
  8446. //---------------------------------------------------------------------------
  8447. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8448. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8449. {
  8450. UnicodeString Result;
  8451. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8452. {
  8453. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8454. }
  8455. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8456. {
  8457. // noop
  8458. }
  8459. else
  8460. {
  8461. Result =
  8462. FMTLOAD(FILE_INFO_FORMAT,
  8463. (FormatBytes(FileInfo.SelectedSize),
  8464. FormatBytes(FileInfo.FilesSize),
  8465. FormatNumber(FileInfo.SelectedCount),
  8466. FormatNumber(FileInfo.FilesCount)));
  8467. }
  8468. return Result;
  8469. }
  8470. //---------------------------------------------------------------------------
  8471. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8472. TTBXStatusPanel * Panel, TOperationSide Side)
  8473. {
  8474. if (Panel->Index == 1)
  8475. {
  8476. ToggleShowHiddenFiles();
  8477. }
  8478. else if (Panel->Index == 2)
  8479. {
  8480. Filter(Side);
  8481. }
  8482. }
  8483. //---------------------------------------------------------------------------
  8484. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8485. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8486. {
  8487. DebugAssert(!StatusBar->SimplePanel);
  8488. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8489. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8490. }
  8491. //---------------------------------------------------------------------------
  8492. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8493. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8494. {
  8495. DebugAssert(StatusBar->Panels->Count >= 3);
  8496. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8497. if (FileInfo.HiddenCount > 0)
  8498. {
  8499. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8500. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8501. }
  8502. else
  8503. {
  8504. HiddenFilesPanel->ViewPriority = 0;
  8505. // not really necessary, just to cleanup no-longer-valid data
  8506. HiddenFilesPanel->Caption = L"";
  8507. }
  8508. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8509. if (FileInfo.FilteredCount > 0)
  8510. {
  8511. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8512. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8513. }
  8514. else
  8515. {
  8516. FilteredFilesPanel->ViewPriority = 0;
  8517. // not really necessary, just to cleanup no-longer-valid data
  8518. FilteredFilesPanel->Caption = L"";
  8519. }
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8523. TObject * /*Sender*/)
  8524. {
  8525. if (DirView(osOther)->Enabled)
  8526. {
  8527. DirView(osOther)->SetFocus();
  8528. }
  8529. }
  8530. //---------------------------------------------------------------------------
  8531. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8532. {
  8533. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8534. switch (Config.Show)
  8535. {
  8536. case qvShow:
  8537. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8538. {
  8539. Config.Show = qvHide;
  8540. }
  8541. else
  8542. {
  8543. Config.Show = Config.LastHideShow;
  8544. }
  8545. break;
  8546. case qvHideWhenEmpty:
  8547. if (ComponentVisible[fcQueueView])
  8548. {
  8549. Config.Show = qvHide;
  8550. }
  8551. else
  8552. {
  8553. Config.LastHideShow = Config.Show;
  8554. Config.Show = qvShow;
  8555. }
  8556. break;
  8557. case qvHide:
  8558. Config.LastHideShow = Config.Show;
  8559. Config.Show = qvShow;
  8560. break;
  8561. }
  8562. WinConfiguration->QueueView = Config;
  8563. }
  8564. //---------------------------------------------------------------------------
  8565. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8566. {
  8567. UnicodeString Result;
  8568. if (Terminal != NULL)
  8569. {
  8570. switch (WinConfiguration->PathInCaption)
  8571. {
  8572. case picShort:
  8573. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8574. break;
  8575. case picFull:
  8576. Result = Terminal->CurrentDirectory;
  8577. break;
  8578. }
  8579. }
  8580. return Result;
  8581. }
  8582. //---------------------------------------------------------------------------
  8583. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8584. {
  8585. TColor Result = GetWindowColor(FSessionColor);
  8586. return Result;
  8587. }
  8588. //---------------------------------------------------------------------------
  8589. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8590. {
  8591. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8592. return Result;
  8593. }
  8594. //---------------------------------------------------------------------------
  8595. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8596. {
  8597. if (!FSessionChanging)
  8598. {
  8599. TTerminalManager::Instance()->UpdateAppTitle();
  8600. }
  8601. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8602. // background to gray on Windows 7 (works on Windows 10).
  8603. // See also EnableControl
  8604. if (Showing)
  8605. {
  8606. if (ManagedSession != NULL)
  8607. {
  8608. // Update path when it changes
  8609. if ((SessionsPageControl->ActivePage != NULL) &&
  8610. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8611. {
  8612. UpdateSessionTab(SessionsPageControl->ActivePage);
  8613. }
  8614. }
  8615. NonVisualDataModule->ReconnectSessionAction->Update();
  8616. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8617. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8618. CenterReconnectToolbar();
  8619. bool HasTerminal = HasActiveTerminal();
  8620. RemoteDirView->Enabled = HasTerminal;
  8621. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8622. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8623. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8624. RemoteDriveView->Color = RemoteDirView->Color;
  8625. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8626. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8627. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8628. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8629. QueueFileList->Enabled = QueueView3->Enabled;
  8630. QueueFileList->Color = QueueView3->Color;
  8631. QueueFileList->Font->Color = QueueView3->Font->Color;
  8632. QueueLabelUpdateStatus();
  8633. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8634. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8635. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8636. {
  8637. UpdateDarkMode();
  8638. }
  8639. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8640. MessageDock->Visible = (MessageDock->ToolbarCount > 0);
  8641. }
  8642. }
  8643. //---------------------------------------------------------------------------
  8644. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8645. {
  8646. UpdateControls();
  8647. }
  8648. //---------------------------------------------------------------------------
  8649. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8650. TObject * Sender)
  8651. {
  8652. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8653. DebugAssert(DirView != NULL);
  8654. DoDirViewLoaded(DirView);
  8655. TransferPresetAutoSelect();
  8656. }
  8657. //---------------------------------------------------------------------------
  8658. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8659. {
  8660. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8661. // first run after installation
  8662. if (double(Updates.LastCheck) == 0)
  8663. {
  8664. AppLog(L"First run, scheduling updates check for the next run");
  8665. // make sure next time there will be an update (if enabled)
  8666. Updates.LastCheck = TDateTime(1);
  8667. WinConfiguration->Updates = Updates;
  8668. }
  8669. else
  8670. {
  8671. TDateTime Period;
  8672. if (IsUWP() && !IsOfficialPackage())
  8673. {
  8674. Period = DefaultUpdatesPeriod;
  8675. AppLog(L"Thirdparty UWP package, using default updates check period");
  8676. }
  8677. else
  8678. {
  8679. Period = Updates.Period;
  8680. }
  8681. AppLogFmt(L"Updates check period: %.2f", (double(Period)));
  8682. if (double(Period) > 0)
  8683. {
  8684. TDateTime Interval = Now() - Updates.LastCheck;
  8685. AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
  8686. if (Interval >= Period)
  8687. {
  8688. StartUpdateThread(UpdatesChecked);
  8689. }
  8690. }
  8691. }
  8692. }
  8693. //---------------------------------------------------------------------------
  8694. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8695. {
  8696. AppLog(L"Updates check done");
  8697. UnicodeString Message;
  8698. bool New;
  8699. TQueryType Type;
  8700. GetUpdatesMessage(Message, New, Type, false);
  8701. if (!Message.IsEmpty())
  8702. {
  8703. AppLogFmt(L"Updates check message: %s", (Message));
  8704. if (New)
  8705. {
  8706. AppLog(L"New version detected");
  8707. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8708. }
  8709. if (!New && (Type != qtWarning))
  8710. {
  8711. AppLog(L"Posting non-critical updates note");
  8712. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8713. }
  8714. else
  8715. {
  8716. AppLog(L"Posting new version or critical message notification");
  8717. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8718. }
  8719. if (New)
  8720. {
  8721. Configuration->Usage->Inc(L"UpdateNotifications");
  8722. }
  8723. }
  8724. }
  8725. //---------------------------------------------------------------------------
  8726. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8727. {
  8728. RestoreApp();
  8729. bool CanDisplay = !NonVisualDataModule->Busy;
  8730. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8731. {
  8732. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8733. }
  8734. if (CanDisplay)
  8735. {
  8736. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8737. // Probably not needed as CheckForUpdates is blocking since we started using neon for HTTP implementation.
  8738. NonVisualDataModule->StartBusy();
  8739. try
  8740. {
  8741. CheckForUpdates(true);
  8742. }
  8743. __finally
  8744. {
  8745. NonVisualDataModule->EndBusy();
  8746. }
  8747. }
  8748. else
  8749. {
  8750. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8751. }
  8752. }
  8753. //---------------------------------------------------------------------------
  8754. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8755. TCopyParamRuleData & Data)
  8756. {
  8757. DebugAssert(Terminal != NULL);
  8758. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8759. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8760. Data.RemoteDirectory = RemoteDirView->PathName;
  8761. }
  8762. //---------------------------------------------------------------------------
  8763. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8764. {
  8765. // Terminal can be null when we are changing local directory implicitly,
  8766. // because it has been deleted, while no session is connected
  8767. // (Login dialog is open)
  8768. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8769. {
  8770. DebugAssert(!IsLocalBrowserMode());
  8771. TCopyParamRuleData Data;
  8772. GetTransferPresetAutoSelectData(Data);
  8773. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8774. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8775. if (CopyParamIndex < 0)
  8776. {
  8777. // there is no preset that matches autoselection
  8778. // set preset that we consider "default"
  8779. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8780. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8781. }
  8782. else
  8783. {
  8784. // there is preset matching autoselection
  8785. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8786. if (CopyParamName == FCopyParamAutoSelected)
  8787. {
  8788. // autoselected the same preset as the last time
  8789. // make no change (i.e. preserve custom user preset, if any)
  8790. }
  8791. else
  8792. {
  8793. // autoselected the different preset then the last time (or there
  8794. // was default preset set)
  8795. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8796. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8797. }
  8798. }
  8799. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8800. {
  8801. if (CopyParamIndex >= 0)
  8802. {
  8803. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8804. }
  8805. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8806. try
  8807. {
  8808. int Fmt =
  8809. (CopyParamIndex < 0) ?
  8810. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8811. COPY_PARAM_AUTOSELECTED;
  8812. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8813. Data->Message = MainInstructions(Message);
  8814. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8815. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8816. CopyParamAttrs);
  8817. if (CopyParamIndex >= 0)
  8818. {
  8819. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8820. Info = FORMAT(L"%s\n \n%s", (Info,
  8821. FMTLOAD(COPY_PARAM_RULE,
  8822. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8823. }
  8824. Data->Message += L"\n\n" + Info;
  8825. if (WinConfiguration->CopyParamAutoSelectNotice)
  8826. {
  8827. TransferPresetNoteMessage(Data, true);
  8828. }
  8829. else
  8830. {
  8831. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8832. Data = NULL; // ownership passed
  8833. }
  8834. }
  8835. __finally
  8836. {
  8837. delete Data;
  8838. }
  8839. }
  8840. }
  8841. }
  8842. //---------------------------------------------------------------------------
  8843. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8844. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8845. {
  8846. DebugAssert(NoteData != NULL);
  8847. DebugAssert(!IsLocalBrowserMode());
  8848. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8849. TQueryButtonAlias Aliases[1];
  8850. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8851. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8852. Params.Aliases = Aliases;
  8853. Params.AliasesCount = LENOF(Aliases);
  8854. unsigned int Result =
  8855. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8856. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8857. switch (Result)
  8858. {
  8859. case qaNeverAskAgain:
  8860. DebugAssert(AllowNeverAskAgain);
  8861. WinConfiguration->CopyParamAutoSelectNotice = false;
  8862. break;
  8863. case qaIgnore:
  8864. PreferencesDialog(pmPresets);
  8865. break;
  8866. }
  8867. }
  8868. //---------------------------------------------------------------------------
  8869. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8870. {
  8871. // as of now useless, as this is used for notes only, never for balloons, ...
  8872. RestoreApp();
  8873. // .. and we should never be busy here
  8874. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8875. {
  8876. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8877. }
  8878. }
  8879. //---------------------------------------------------------------------------
  8880. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8881. TPreferencesMode APreferencesMode)
  8882. {
  8883. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8884. TCopyParamRuleData Data;
  8885. if (Terminal != NULL)
  8886. {
  8887. PreferencesData.reset(new TPreferencesDialogData());
  8888. GetTransferPresetAutoSelectData(Data);
  8889. PreferencesData->CopyParamRuleData = &Data;
  8890. }
  8891. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8892. }
  8893. //---------------------------------------------------------------------------
  8894. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8895. const TCustomCommandType & Command)
  8896. {
  8897. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8898. {
  8899. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8900. }
  8901. }
  8902. //---------------------------------------------------------------------------
  8903. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8904. {
  8905. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8906. TCustomCommandType Command;
  8907. // make sure we use local custom command when remote are not supported
  8908. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8909. {
  8910. Command = FLastCustomCommand;
  8911. }
  8912. else
  8913. {
  8914. Command.Params = Command.Params | ccLocal;
  8915. }
  8916. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8917. FEditingFocusedAdHocCommand = OnFocused;
  8918. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8919. int Options =
  8920. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8921. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8922. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8923. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8924. {
  8925. FLastCustomCommand = Command;
  8926. UpdateCustomCommandsToolbar();
  8927. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8928. }
  8929. }
  8930. //---------------------------------------------------------------------------
  8931. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8932. {
  8933. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8934. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8935. DebugAssert(State > 0);
  8936. if (State <= 0)
  8937. {
  8938. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8939. }
  8940. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8941. }
  8942. //---------------------------------------------------------------------------
  8943. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8944. TCustomCommandType & Command, int & State)
  8945. {
  8946. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8947. if (Result)
  8948. {
  8949. Command = FLastCustomCommand;
  8950. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8951. }
  8952. return Result;
  8953. }
  8954. //---------------------------------------------------------------------------
  8955. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8956. {
  8957. ResetIncrementalSearch();
  8958. }
  8959. //---------------------------------------------------------------------------
  8960. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8961. {
  8962. DebugAssert(ComponentVisible[Component]);
  8963. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8964. }
  8965. //---------------------------------------------------------------------------
  8966. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8967. {
  8968. // when queue panel is resized here directly, the status bar is stretched
  8969. // over whole space the panel occupied
  8970. PostComponentHide(fcQueueView);
  8971. }
  8972. //---------------------------------------------------------------------------
  8973. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8974. {
  8975. ComponentVisible[fcQueueFileList] = false;
  8976. }
  8977. //---------------------------------------------------------------------------
  8978. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8979. {
  8980. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8981. RefreshColorMode();
  8982. ResetSysDarkTheme();
  8983. ConfigurationChanged();
  8984. ConfigureInterface();
  8985. // Should be called for all controls
  8986. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8987. }
  8988. //---------------------------------------------------------------------------
  8989. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8990. {
  8991. // Do not handle, when shutting down anyway (maybe also when not setup completely yet?)
  8992. if (!FInvalid &&
  8993. (Message.LParam != 0) &&
  8994. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8995. {
  8996. ThemeChanged();
  8997. }
  8998. TForm::Dispatch(&Message);
  8999. }
  9000. //---------------------------------------------------------------------------
  9001. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  9002. {
  9003. TMessage * M = static_cast<TMessage*>(Message);
  9004. switch (M->Msg)
  9005. {
  9006. case CM_DIALOGCHAR:
  9007. CMDialogChar(*M);
  9008. break;
  9009. case WM_APPCOMMAND:
  9010. WMAppCommand(*M);
  9011. break;
  9012. case WM_SYSCOMMAND:
  9013. WMSysCommand(*M);
  9014. break;
  9015. case WM_QUERYENDSESSION:
  9016. WMQueryEndSession(*M);
  9017. break;
  9018. case WM_ENDSESSION:
  9019. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  9020. break;
  9021. #ifdef _DEBUG
  9022. case WM_WINDOWPOSCHANGED:
  9023. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  9024. break;
  9025. case CM_CUSTOMSTYLECHANGED:
  9026. TForm::Dispatch(Message);
  9027. break;
  9028. #endif
  9029. case WM_COMPONENT_HIDE:
  9030. {
  9031. Byte Component = static_cast<Byte>(M->WParam);
  9032. // sanity check
  9033. if (ComponentVisible[Component])
  9034. {
  9035. // special treatment
  9036. if (Component == fcQueueView)
  9037. {
  9038. ToggleQueueVisibility();
  9039. DebugAssert(!ComponentVisible[fcQueueView]);
  9040. }
  9041. else
  9042. {
  9043. ComponentVisible[Component] = false;
  9044. }
  9045. }
  9046. }
  9047. break;
  9048. case WM_COPYDATA:
  9049. WMCopyData(*M);
  9050. break;
  9051. case WM_MANAGES_CAPTION:
  9052. // caption managed in TTerminalManager::UpdateAppTitle()
  9053. M->Result = 1;
  9054. break;
  9055. case WM_WANTS_MOUSEWHEEL:
  9056. M->Result = 1;
  9057. break;
  9058. case CM_SHOWINGCHANGED:
  9059. CMShowingChanged(*M);
  9060. break;
  9061. case WM_CLOSE:
  9062. WMClose(*M);
  9063. break;
  9064. case WM_DPICHANGED:
  9065. WMDpiChanged(*M);
  9066. break;
  9067. case CM_DPICHANGED:
  9068. CMDpiChanged(*M);
  9069. break;
  9070. case WM_SETTINGCHANGE:
  9071. WMSettingChange(*M);
  9072. break;
  9073. case CM_DIALOGKEY:
  9074. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  9075. break;
  9076. default:
  9077. TForm::Dispatch(Message);
  9078. break;
  9079. }
  9080. }
  9081. //---------------------------------------------------------------------------
  9082. void __fastcall TCustomScpExplorerForm::UpdateImages()
  9083. {
  9084. // noop
  9085. }
  9086. //---------------------------------------------------------------------------
  9087. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  9088. {
  9089. TForm::Dispatch(&Message);
  9090. FSessionColors->Clear();
  9091. AddFixedSessionImages();
  9092. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  9093. UpdateImages();
  9094. }
  9095. //---------------------------------------------------------------------------
  9096. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  9097. {
  9098. TForm::Dispatch(&Message);
  9099. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  9100. UpdatePixelsPerInchMainWindowCounter();
  9101. }
  9102. //---------------------------------------------------------------------------
  9103. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  9104. {
  9105. // Cannot close window while we are busy.
  9106. // We cannot test this in FormCloseQuery as that is called also from
  9107. // Close(), which is called by CloseApplicationAction. So we can be busy
  9108. // there already even, when it is legitimate to close the application.
  9109. // Possibly a better place to handle this would be WMSysCommand.
  9110. if (NonVisualDataModule->Busy)
  9111. {
  9112. Message.Result = 1;
  9113. }
  9114. else
  9115. {
  9116. TForm::Dispatch(&Message);
  9117. }
  9118. }
  9119. //---------------------------------------------------------------------------
  9120. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  9121. {
  9122. if (!FShowingChanged)
  9123. {
  9124. AddStartupSequence(L"D");
  9125. FShowingChanged = true;
  9126. }
  9127. // Ignoring implicit local-local browser of Commander, opened from DoShow
  9128. bool NoSession = (ManagedSession == NULL);
  9129. // This calls TCustomScpExplorerForm::DoShow
  9130. TForm::Dispatch(&Message);
  9131. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  9132. if (Showing && !FStarted)
  9133. {
  9134. FStarted = true;
  9135. InterfaceStarted();
  9136. }
  9137. if (Showing && NoSession)
  9138. {
  9139. // When we are starting minimized (i.e. from an installer),
  9140. // postpone showing Login dialog until we get restored.
  9141. // Otherwise the Login dialog (and Authentication window) show restored
  9142. // over invisible (minimized) main window.
  9143. if (WindowState == wsMinimized)
  9144. {
  9145. FNeedSession = true;
  9146. }
  9147. else
  9148. {
  9149. // This happens before application ever goes idle, so the toolbars would
  9150. // stay enabled (initial state) until the Login dialog is dismissed.
  9151. UpdateActions();
  9152. NonVisualDataModule->StartBusy();
  9153. try
  9154. {
  9155. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  9156. // otherwise the dialog does not receive focus.
  9157. // With Commander interface the ProcessMessages is called already
  9158. // by TDriveView, but with Explorer interface, we need to call it explicily
  9159. Application->ProcessMessages();
  9160. // do not reload sessions, they have been loaded just now (optimization)
  9161. NeedSession(true);
  9162. }
  9163. __finally
  9164. {
  9165. NonVisualDataModule->EndBusy();
  9166. }
  9167. }
  9168. }
  9169. }
  9170. //---------------------------------------------------------------------------
  9171. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  9172. {
  9173. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  9174. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  9178. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  9179. int & MaxHeight)
  9180. {
  9181. // workaround for bug in TWinControl.CalcConstraints
  9182. // Check for empty rect (restore from iconic state) is done there only after
  9183. // call to AdjustClientRect, which enlarges the rect (for forms).
  9184. TRect R = GetClientRect();
  9185. // when restoring from iconic state, place no restrictions
  9186. if (IsRectEmpty(R))
  9187. {
  9188. MinWidth = 0;
  9189. MinHeight = 0;
  9190. MaxWidth = 32000;
  9191. MaxHeight = 32000;
  9192. }
  9193. }
  9194. //---------------------------------------------------------------------------
  9195. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  9196. TSpaceAvailable & ASpaceAvailable, bool & Close)
  9197. {
  9198. // terminal can be already closed (e.g. dropped connection)
  9199. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  9200. {
  9201. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  9202. try
  9203. {
  9204. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  9205. }
  9206. catch(...)
  9207. {
  9208. if (!Terminal->Active)
  9209. {
  9210. Close = true;
  9211. }
  9212. throw;
  9213. }
  9214. }
  9215. }
  9216. //---------------------------------------------------------------------------
  9217. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9218. {
  9219. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9220. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9221. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9222. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9223. {
  9224. OnGetSpaceAvailable = GetSpaceAvailable;
  9225. }
  9226. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9227. OnGetSpaceAvailable);
  9228. }
  9229. //---------------------------------------------------------------------------
  9230. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9231. {
  9232. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9233. Terminal->FillSessionDataForCode(Data.get());
  9234. return Data.release();
  9235. }
  9236. //---------------------------------------------------------------------------
  9237. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9238. {
  9239. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9240. DoGenerateUrlDialog(Data.get(), Paths);
  9241. }
  9242. //---------------------------------------------------------------------------
  9243. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9244. {
  9245. GenerateUrl(NULL);
  9246. }
  9247. //---------------------------------------------------------------------------
  9248. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9249. {
  9250. std::unique_ptr<TStrings> Paths(new TStringList());
  9251. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9252. GenerateUrl(Paths.get());
  9253. }
  9254. //---------------------------------------------------------------------------
  9255. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9256. {
  9257. FSessionColor = value;
  9258. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9259. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9260. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9261. DebugAssert(ColorItem != NULL);
  9262. ColorItem->Color = C;
  9263. NonVisualDataModule->ColorMenuItem->Color = C;
  9264. UpdateControls();
  9265. }
  9266. //---------------------------------------------------------------------------
  9267. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9268. {
  9269. if (value != FSessionColor)
  9270. {
  9271. UpdateSessionColor(value);
  9272. // Is null when called from LastTerminalClosed
  9273. if (Terminal != NULL)
  9274. {
  9275. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9276. }
  9277. }
  9278. }
  9279. //---------------------------------------------------------------------------
  9280. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9281. {
  9282. bool Result = FNoteTimer->Enabled;
  9283. if (Result)
  9284. {
  9285. // cannot cancel note too early
  9286. bool NotEarly =
  9287. (Now() - FNoteShown >
  9288. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9289. if (Force || NotEarly)
  9290. {
  9291. FNoteTimer->Enabled = false;
  9292. FNote = L"";
  9293. SAFE_DESTROY(FNoteData);
  9294. FOnNoteClick = NULL;
  9295. FNoteHints = FNotes->Text;
  9296. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9297. UpdateStatusBar();
  9298. }
  9299. }
  9300. return Result;
  9301. }
  9302. //---------------------------------------------------------------------------
  9303. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9304. {
  9305. DebugAssert(FNoteTimer->Enabled);
  9306. CancelNote(true);
  9307. }
  9308. //---------------------------------------------------------------------------
  9309. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9310. {
  9311. FNoteHints = FNotes->Text.TrimRight();
  9312. }
  9313. //---------------------------------------------------------------------------
  9314. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9315. {
  9316. int P = Note.Pos(L"\n");
  9317. if (P > 0)
  9318. {
  9319. Note.SetLength(P - 1);
  9320. }
  9321. FNotes->Add(FORMAT(L"[%s] %s",
  9322. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9323. while (FNotes->Count > 10)
  9324. {
  9325. FNotes->Delete(0);
  9326. }
  9327. if (UpdateNow)
  9328. {
  9329. UpdateNoteHints();
  9330. UpdateStatusBar();
  9331. }
  9332. }
  9333. //---------------------------------------------------------------------------
  9334. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9335. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9336. {
  9337. int P = Note.Pos(L"\n");
  9338. if (P > 0)
  9339. {
  9340. Note.SetLength(P - 1);
  9341. }
  9342. UpdateNoteHints();
  9343. FNote = Note;
  9344. SAFE_DESTROY(FNoteData);
  9345. FNoteData = NoteData;
  9346. FOnNoteClick = OnNoteClick;
  9347. AddNote(Note, false);
  9348. UpdateStatusBar();
  9349. FNoteShown = Now();
  9350. FNoteTimer->Enabled = false;
  9351. if (Seconds == 0)
  9352. {
  9353. Seconds = WinConfiguration->NotificationsTimeout;
  9354. }
  9355. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9356. FNoteTimer->Enabled = true;
  9357. }
  9358. //---------------------------------------------------------------------------
  9359. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9360. {
  9361. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9362. }
  9363. //---------------------------------------------------------------------------
  9364. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9365. {
  9366. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9367. {
  9368. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9369. }
  9370. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9371. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9372. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9373. 0, NULL, NULL);
  9374. }
  9375. //---------------------------------------------------------------------------
  9376. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9377. {
  9378. bool NewShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9379. UnicodeString Note =
  9380. FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1), (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, (NewShowHiddenFiles ? 2 : 3))));
  9381. PostNote(Note, 0, NULL, NULL);
  9382. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9383. WinConfiguration->ShowHiddenFiles = NewShowHiddenFiles;
  9384. }
  9385. //---------------------------------------------------------------------------
  9386. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9387. {
  9388. WinConfiguration->FormatSizeBytes = Style;
  9389. }
  9390. //---------------------------------------------------------------------------
  9391. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9392. {
  9393. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9394. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9395. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9396. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9397. }
  9398. //---------------------------------------------------------------------------
  9399. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9400. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9401. {
  9402. if (Panel->Index == 0)
  9403. {
  9404. if (FOnNoteClick != NULL)
  9405. {
  9406. // prevent the user data from being freed by possible call
  9407. // to CancelNote or PostNote during call to OnNoteClick
  9408. std::unique_ptr<TObject> NoteData(FNoteData);
  9409. TNotifyEvent OnNoteClick = FOnNoteClick;
  9410. FNoteData = NULL;
  9411. // need to cancel the note as we are going to delete its user data
  9412. CancelNote(true);
  9413. OnNoteClick(NoteData.get());
  9414. }
  9415. }
  9416. if (HasActiveTerminal() &&
  9417. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9418. {
  9419. FileSystemInfo();
  9420. }
  9421. }
  9422. //---------------------------------------------------------------------------
  9423. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9424. {
  9425. // workaround:
  9426. // 1) for unknown reason, disabling window, while minimized,
  9427. // prevents it from restoring, even if it was enabled again meanwhile
  9428. // 2) when disabling the main window, while another has focus
  9429. // minimize is no longer possible
  9430. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9431. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9432. // Shouldn't we use IsApplicationMinimized() here?
  9433. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9434. {
  9435. Enabled = false;
  9436. }
  9437. FLockLevel++;
  9438. }
  9439. //---------------------------------------------------------------------------
  9440. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9441. {
  9442. DebugAssert(FLockLevel > 0);
  9443. FLockLevel--;
  9444. if (FLockLevel == 0)
  9445. {
  9446. DebugAssert(FLockSuspendLevel == 0);
  9447. Enabled = true;
  9448. }
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9452. {
  9453. // We need to make sure that window is enabled when the last modal window closes
  9454. // otherwise focus is not restored correctly.
  9455. // So we re-enable the window when modal window opens and
  9456. // disable it back after is closes
  9457. if (FLockLevel > 0)
  9458. {
  9459. // while we have nesting counter, we know that we never be called
  9460. // recursivelly as Application->OnModalBegin is called only
  9461. // for the top-level modal window
  9462. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9463. {
  9464. // won't be disabled when conditions in LockWindow() were not satisfied
  9465. FDisabledOnLockSuspend = !Enabled;
  9466. // When minimized to tray (or actually when set to SW_HIDE),
  9467. // setting Enabled makes the window focusable even when there's
  9468. // modal window over it
  9469. if (!FTrayIcon->Visible)
  9470. {
  9471. Enabled = true;
  9472. }
  9473. }
  9474. FLockSuspendLevel++;
  9475. }
  9476. }
  9477. //---------------------------------------------------------------------------
  9478. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9479. {
  9480. if (FLockSuspendLevel > 0)
  9481. {
  9482. DebugAssert(FLockLevel > 0);
  9483. FLockSuspendLevel--;
  9484. // see comment in SuspendWindowLock
  9485. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9486. {
  9487. // Note that window can be enabled here, when we were minized to tray when
  9488. // was SuspendWindowLock() called.
  9489. // We should possibly do the same check as in LockWindow(),
  9490. // if it is ever possible that the consitions change between
  9491. // SuspendWindowLock() and ResumeWindowLock()
  9492. Enabled = !FDisabledOnLockSuspend;
  9493. }
  9494. }
  9495. }
  9496. //---------------------------------------------------------------------------
  9497. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9498. {
  9499. TTBXComboBoxItem * RemotePathComboBox =
  9500. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9501. if (!TextOnly)
  9502. {
  9503. TStrings * Items = RemotePathComboBox->Strings;
  9504. Items->BeginUpdate();
  9505. try
  9506. {
  9507. Items->Clear();
  9508. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9509. {
  9510. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9511. while (!IsUnixRootPath(APath))
  9512. {
  9513. int P = APath.LastDelimiter(L'/');
  9514. DebugAssert(P >= 0);
  9515. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9516. APath.SetLength(P - 1);
  9517. }
  9518. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9519. }
  9520. }
  9521. __finally
  9522. {
  9523. Items->EndUpdate();
  9524. }
  9525. }
  9526. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9527. // Setting ItemIndex to -1 does not reset its text
  9528. if (RemotePathComboBox->Strings->Count == 0)
  9529. {
  9530. RemotePathComboBox->Text = L"";
  9531. }
  9532. }
  9533. //---------------------------------------------------------------------------
  9534. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9535. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9536. {
  9537. if (AIndex < 0)
  9538. {
  9539. AIndex = Sender->ItemIndex;
  9540. }
  9541. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9542. }
  9543. //---------------------------------------------------------------------------
  9544. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9545. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9546. int & ImageIndex)
  9547. {
  9548. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9549. }
  9550. //---------------------------------------------------------------------------
  9551. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9552. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9553. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9554. {
  9555. if (!IsLocalBrowserMode())
  9556. {
  9557. ARect.Left += (10 * AIndex);
  9558. }
  9559. }
  9560. //---------------------------------------------------------------------------
  9561. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9562. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9563. {
  9564. AWidth += (10 * AIndex);
  9565. }
  9566. //---------------------------------------------------------------------------
  9567. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9568. {
  9569. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9570. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9571. int Index = RemotePathComboBox->ItemIndex;
  9572. while (Index < RemotePathComboBox->Strings->Count - 1)
  9573. {
  9574. APath = UnixExtractFileDir(APath);
  9575. Index++;
  9576. }
  9577. // VanDyke style paths
  9578. if (APath.IsEmpty())
  9579. {
  9580. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9581. APath = ROOTDIRECTORY;
  9582. }
  9583. if (RemoteDirView->Path != APath)
  9584. {
  9585. RemoteDirView->Path = APath;
  9586. }
  9587. }
  9588. //---------------------------------------------------------------------------
  9589. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9590. {
  9591. DoRemotePathComboBoxItemClick(Sender);
  9592. }
  9593. //---------------------------------------------------------------------------
  9594. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9595. {
  9596. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9597. DebugUsedParam(Sender);
  9598. UpdateRemotePathComboBox(true);
  9599. }
  9600. //---------------------------------------------------------------------------
  9601. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9602. {
  9603. DoRemotePathComboBoxCancel(Sender);
  9604. }
  9605. //---------------------------------------------------------------------------
  9606. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9607. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9608. {
  9609. ResetIncrementalSearch();
  9610. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9611. DebugAssert(DirView != NULL);
  9612. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9613. {
  9614. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9615. // OnEditing is called also from TCustomListView::CanEdit
  9616. if (Edit != NULL)
  9617. {
  9618. EditSelectBaseName(Edit);
  9619. }
  9620. }
  9621. }
  9622. //---------------------------------------------------------------------------
  9623. //---------------------------------------------------------------------------
  9624. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9625. {
  9626. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9627. Result->AutoDetectDnD = false;
  9628. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9629. Result->RenderDataOn = rdoEnterAndDropSync;
  9630. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9631. return Result;
  9632. }
  9633. //---------------------------------------------------------------------------
  9634. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9635. {
  9636. if (IsWin10Build(2004))
  9637. {
  9638. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9639. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9640. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9641. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9642. }
  9643. }
  9644. //---------------------------------------------------------------------------
  9645. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9646. {
  9647. TForm::CreateWnd();
  9648. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9649. UpdateDarkMode();
  9650. if (FSessionsDragDropFilesEx == NULL)
  9651. {
  9652. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9653. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9654. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9655. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9656. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9657. }
  9658. if (FQueueDragDropFilesEx == NULL)
  9659. {
  9660. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9661. // No need to set OnDragOver as we do not have any restrictions
  9662. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9663. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9664. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9665. }
  9666. }
  9667. //---------------------------------------------------------------------------
  9668. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9669. {
  9670. TForm::DestroyWnd();
  9671. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9672. FQueueDragDropFilesEx->DragDropControl = NULL;
  9673. }
  9674. //---------------------------------------------------------------------------
  9675. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9676. {
  9677. SideEnter(FCurrentSide);
  9678. FEverShown = true;
  9679. }
  9680. //---------------------------------------------------------------------------
  9681. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9682. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9683. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9684. {
  9685. if (!NonVisualDataModule->Busy)
  9686. {
  9687. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9688. Configuration->Usage->Inc(L"FileFinds");
  9689. LockWindow(true);
  9690. NonVisualDataModule->StartBusy();
  9691. WinConfiguration->LockedInterface = true;
  9692. try
  9693. {
  9694. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9695. }
  9696. __finally
  9697. {
  9698. WinConfiguration->LockedInterface = false;
  9699. NonVisualDataModule->EndBusy();
  9700. UnlockWindow();
  9701. }
  9702. }
  9703. }
  9704. //---------------------------------------------------------------------------
  9705. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9706. {
  9707. if (!NonVisualDataModule->Busy)
  9708. {
  9709. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9710. SetFocus();
  9711. RemoteDirView->Path = UnixExtractFilePath(Path);
  9712. UnicodeString FileName = UnixExtractFileName(Path);
  9713. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9714. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9715. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9716. if (Item == NULL)
  9717. {
  9718. ReloadDirectory(osRemote);
  9719. Item = RemoteDirView->FindFileItem(FileName);
  9720. }
  9721. if (Item != NULL)
  9722. {
  9723. RemoteDirView->ItemFocused = Item;
  9724. RemoteDirView->ItemFocused->MakeVisible(false);
  9725. RemoteDirView->SetFocus();
  9726. }
  9727. }
  9728. }
  9729. //---------------------------------------------------------------------------
  9730. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9731. {
  9732. bool Result = !NonVisualDataModule->Busy;
  9733. if (Result)
  9734. {
  9735. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9736. }
  9737. return Result;
  9738. }
  9739. //---------------------------------------------------------------------------
  9740. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9741. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9742. {
  9743. if (CanOperateOnFoundFiles(ATerminal))
  9744. {
  9745. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9746. FOnFileOperationFinished = OnFileOperationFinished;
  9747. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9748. }
  9749. }
  9750. //---------------------------------------------------------------------------
  9751. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9752. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9753. {
  9754. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9755. }
  9756. //---------------------------------------------------------------------------
  9757. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9758. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9759. {
  9760. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9761. }
  9762. //---------------------------------------------------------------------------
  9763. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9764. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9765. {
  9766. if (CanOperateOnFoundFiles(ATerminal))
  9767. {
  9768. for (int Index = 0; Index < FileList->Count; Index++)
  9769. {
  9770. UnicodeString FileName = FileList->Strings[Index];
  9771. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9772. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9773. OnFileOperationFinished(osRemote, FileName, true);
  9774. }
  9775. }
  9776. }
  9777. //---------------------------------------------------------------------------
  9778. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9779. {
  9780. FFileFindTerminal = Terminal;
  9781. ShowFileFindDialog(
  9782. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9783. DoDownloadFoundFiles, DoEditFoundFiles);
  9784. }
  9785. //---------------------------------------------------------------------------
  9786. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9787. {
  9788. FTaskbarList = TaskbarList;
  9789. }
  9790. //---------------------------------------------------------------------------
  9791. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9792. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9793. {
  9794. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9795. if (Index >= 0)
  9796. {
  9797. if (Button == mbLeft)
  9798. {
  9799. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  9800. // If switching tab (switching session) takes long enough for user
  9801. // to actually release the button, "mouse down" is still raised,
  9802. // but we do not get "mouse up" event, so dragging is not cancelled,
  9803. // prevent that by not beginning dragging in the first place.
  9804. int Key = ((GetSystemMetrics(SM_SWAPBUTTON) == 0) ? VK_LBUTTON : VK_RBUTTON);
  9805. if (IsKeyPressed(Key))
  9806. {
  9807. // when user clicks the "+", we get mouse down only after the session
  9808. // is closed, when new session tab is already on X:Y, so dragging
  9809. // starts, prevent that
  9810. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  9811. {
  9812. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9813. if (Terminal != NULL)
  9814. {
  9815. SessionsPageControl->BeginDrag(false);
  9816. }
  9817. }
  9818. }
  9819. }
  9820. else if (Button == mbMiddle)
  9821. {
  9822. // ignore middle-click for "New session tab" and the last local-local tab
  9823. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9824. if ((Session != NULL) && CanCloseSession(Session))
  9825. {
  9826. CloseSessionTab(Index);
  9827. }
  9828. }
  9829. }
  9830. }
  9831. //---------------------------------------------------------------------------
  9832. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9833. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9834. {
  9835. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9836. // do not allow dropping on the "+" tab
  9837. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9838. if ((TargetTerminal != NULL) &&
  9839. (SessionsPageControl->ActivePage->PageIndex != Index))
  9840. {
  9841. Configuration->Usage->Inc(L"SessionTabMoves");
  9842. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9843. // but we want to actually prevent that to avoid flicker
  9844. SessionsPageControl->ActivePage->PageIndex = Index;
  9845. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9846. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9847. }
  9848. }
  9849. //---------------------------------------------------------------------------
  9850. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9851. TObject * Sender, TObject * Source, int X, int Y,
  9852. TDragState /*State*/, bool & Accept)
  9853. {
  9854. Accept = (Sender == Source);
  9855. if (Accept)
  9856. {
  9857. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9858. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9859. // do not allow dragging to the "+" tab
  9860. Accept = (Terminal != NULL);
  9861. }
  9862. }
  9863. //---------------------------------------------------------------------------
  9864. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9865. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9866. {
  9867. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9868. if (Index < 0)
  9869. {
  9870. Effect = DROPEFFECT_NONE;
  9871. }
  9872. else
  9873. {
  9874. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9875. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  9876. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  9877. {
  9878. Effect = DROPEFFECT_NONE;
  9879. }
  9880. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  9881. {
  9882. Effect = DROPEFFECT_COPY;
  9883. }
  9884. }
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9888. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9889. {
  9890. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9891. // do not allow dropping on local-local, disconnected and the "+" tab
  9892. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  9893. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9894. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  9895. {
  9896. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9897. if (!IsFileControl(DropSourceControl, osRemote))
  9898. {
  9899. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9900. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9901. // Why don't we use Terminal->CurrentDirectory directly?
  9902. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9903. // do not force queue, drag drop
  9904. false, true);
  9905. }
  9906. }
  9907. }
  9908. //---------------------------------------------------------------------------
  9909. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9910. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9911. {
  9912. // Downloads are handled in RemoteFileControlDDEnd
  9913. if (!IsFileControl(DropSourceControl, osRemote))
  9914. {
  9915. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9916. Terminal->CurrentDirectory,
  9917. // force queue, drag drop
  9918. true, true);
  9919. }
  9920. }
  9921. //---------------------------------------------------------------------------
  9922. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9923. {
  9924. FShowing = false;
  9925. // Do not save empty workspace
  9926. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  9927. {
  9928. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9929. UnicodeString Name = WorkspaceName();
  9930. DoSaveWorkspace(
  9931. Name, DataList.get(),
  9932. !Configuration->DisablePasswordStoring &&
  9933. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9934. WinConfiguration->LastStoredSession = Name;
  9935. }
  9936. }
  9937. //---------------------------------------------------------------------------
  9938. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9939. {
  9940. TManagedTerminal * ManagedTerminal =
  9941. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9942. if (ManagedTerminal != NULL)
  9943. {
  9944. ManagedTerminal->DirectoryLoaded = Now();
  9945. }
  9946. }
  9947. //---------------------------------------------------------------------------
  9948. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9949. TListItem * /*Item*/, bool /*Selected*/)
  9950. {
  9951. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9952. switch (DirView->LastSelectMethod)
  9953. {
  9954. case smKeyboard:
  9955. Configuration->Usage->Inc(L"KeyboardSelections");
  9956. break;
  9957. case smMouse:
  9958. Configuration->Usage->Inc(L"MouseSelections");
  9959. break;
  9960. }
  9961. }
  9962. //---------------------------------------------------------------------------
  9963. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9964. {
  9965. if (Color != 0)
  9966. {
  9967. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9968. }
  9969. else
  9970. {
  9971. return FSessionTabImageIndex;
  9972. }
  9973. }
  9974. //---------------------------------------------------------------------------
  9975. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9976. {
  9977. TPngImageCollectionItem * Item =
  9978. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9979. FSessionColors->AddPng(Item->PngImage);
  9980. return FSessionColors->Count - 1;
  9981. }
  9982. //---------------------------------------------------------------------------
  9983. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9984. {
  9985. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9986. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  9987. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  9988. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9989. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9990. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  9991. }
  9992. //---------------------------------------------------------------------------
  9993. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  9994. {
  9995. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  9996. }
  9997. //---------------------------------------------------------------------------
  9998. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  9999. {
  10000. switch (Side)
  10001. {
  10002. case osLocal:
  10003. return FNewLocalTabTabImageIndex;
  10004. case osRemote:
  10005. case osCurrent:
  10006. return FNewRemoteTabTabImageIndex;
  10007. default:
  10008. DebugFail();
  10009. return -1;
  10010. }
  10011. }
  10012. //---------------------------------------------------------------------------
  10013. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  10014. {
  10015. for (int Index = 0; Index < Control->ControlCount; Index++)
  10016. {
  10017. TControl * AControl = Control->Controls[Index];
  10018. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  10019. if (WinControl != NULL)
  10020. {
  10021. CollectItemsWithTextDisplayMode(WinControl);
  10022. }
  10023. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  10024. if (Toolbar != NULL)
  10025. {
  10026. // we care for top-level items only
  10027. TTBCustomItem * Items = Toolbar->Items;
  10028. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  10029. {
  10030. TTBCustomItem * Item = Items->Items[ItemIndex];
  10031. if (((Item->DisplayMode == nbdmImageAndText) ||
  10032. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  10033. EligibleForImageDisplayMode(Item))
  10034. {
  10035. FItemsWithTextDisplayMode.insert(Item);
  10036. }
  10037. }
  10038. }
  10039. }
  10040. }
  10041. //---------------------------------------------------------------------------
  10042. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  10043. {
  10044. return true;
  10045. }
  10046. //---------------------------------------------------------------------------
  10047. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  10048. {
  10049. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  10050. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  10051. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  10052. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  10053. bool Result = true;
  10054. while (Result && (i != FItemsWithTextDisplayMode.end()))
  10055. {
  10056. TTBCustomItem * Item = *i;
  10057. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  10058. if (Label != NULL)
  10059. {
  10060. // optimization
  10061. if (Label->Visible == SelectiveToolbarText)
  10062. {
  10063. Result = false;
  10064. }
  10065. else
  10066. {
  10067. Label->Visible = SelectiveToolbarText;
  10068. }
  10069. }
  10070. else
  10071. {
  10072. // optimization
  10073. if (Item->DisplayMode == DisplayMode)
  10074. {
  10075. Result = false;
  10076. }
  10077. else
  10078. {
  10079. Item->DisplayMode = DisplayMode;
  10080. }
  10081. }
  10082. ++i;
  10083. }
  10084. UpdateNewTabTab();
  10085. return Result;
  10086. }
  10087. //---------------------------------------------------------------------------
  10088. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  10089. {
  10090. DebugFail();
  10091. }
  10092. //---------------------------------------------------------------------------
  10093. bool __fastcall TCustomScpExplorerForm::IsBusy()
  10094. {
  10095. // Among other, a lock level is non zero, while directory is being loaded,
  10096. // even when it happens as a result of dirview navigation,
  10097. // i.e. when TNonVisualDataModule is NOT FBusy.
  10098. // That's why the TNonVisualDataModule::GetBusy calls this method.
  10099. // Among other this prevents a panel auto update to occur while
  10100. // directory is changing.
  10101. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  10102. }
  10103. //---------------------------------------------------------------------------
  10104. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  10105. {
  10106. // While the window is disabled, we still seem to process menu shortcuts at least,
  10107. // so stop it at least here.
  10108. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  10109. bool Result;
  10110. if (Allowed == aaUpdate)
  10111. {
  10112. Result = true;
  10113. }
  10114. else
  10115. {
  10116. Result = !NonVisualDataModule->Busy;
  10117. if (Result && (Allowed == aaShortCut))
  10118. {
  10119. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  10120. Action->Update();
  10121. Result = Action->Enabled;
  10122. }
  10123. }
  10124. return Result;
  10125. }
  10126. //---------------------------------------------------------------------------
  10127. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  10128. {
  10129. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  10130. }
  10131. //---------------------------------------------------------------------------
  10132. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  10133. {
  10134. // This is somewhat redundant to LockWindow() call from
  10135. // TTerminalManager::TerminalReadDirectoryProgress.
  10136. // But disabling window is known not to block keyboard shorcuts
  10137. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  10138. if (Busy > 0)
  10139. {
  10140. if (NonVisualDataModule->Busy)
  10141. {
  10142. State = false;
  10143. }
  10144. else
  10145. {
  10146. NonVisualDataModule->StartBusy();
  10147. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  10148. LockWindow();
  10149. }
  10150. }
  10151. else if (Busy < 0)
  10152. {
  10153. UnlockWindow();
  10154. NonVisualDataModule->EndBusy();
  10155. }
  10156. else
  10157. {
  10158. State = NonVisualDataModule->Busy;
  10159. }
  10160. }
  10161. //---------------------------------------------------------------------------
  10162. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  10163. {
  10164. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  10165. if (Index >= 0)
  10166. {
  10167. TPopupMenu * PopupMenu = NULL;
  10168. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10169. if (Session != NULL)
  10170. {
  10171. SessionsPageControl->ActivePageIndex = Index;
  10172. if (DebugAlwaysTrue(SessionTabSwitched()))
  10173. {
  10174. // copied from TControl.WMContextMenu
  10175. SendCancelMode(SessionsPageControl);
  10176. // explicit popup instead of using PopupMenu property
  10177. // to avoid menu to popup somewhere within SessionTabSwitched above,
  10178. // while connecting yet not-connected session and hence
  10179. // allowing an access to commands over not-completely connected session
  10180. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  10181. }
  10182. }
  10183. else
  10184. {
  10185. if (SupportsLocalBrowser())
  10186. {
  10187. PopupMenu = NonVisualDataModule->NewTabPopup;
  10188. }
  10189. }
  10190. if (PopupMenu != NULL)
  10191. {
  10192. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  10193. PopupMenu->PopupComponent = SessionsPageControl;
  10194. PopupMenu->Popup(Point.x, Point.y);
  10195. }
  10196. }
  10197. Handled = true;
  10198. }
  10199. //---------------------------------------------------------------------------
  10200. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  10201. {
  10202. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  10203. }
  10204. //---------------------------------------------------------------------------
  10205. void __fastcall TCustomScpExplorerForm::ChangePassword()
  10206. {
  10207. Configuration->Usage->Inc(L"PasswordChanges");
  10208. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  10209. ChangePasswordData->DisableAuthentationsExceptPassword();
  10210. ChangePasswordData->ChangePassword = true;
  10211. std::unique_ptr<TTerminal> ChangePasswordSession(
  10212. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10213. ChangePasswordSession->AutoReadDirectory = false;
  10214. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10215. {
  10216. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10217. }
  10218. else
  10219. {
  10220. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10221. }
  10222. }
  10223. //---------------------------------------------------------------------------
  10224. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10225. {
  10226. // No nice way to assert SSH2
  10227. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10228. }
  10229. //---------------------------------------------------------------------------
  10230. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10231. {
  10232. TOperationVisualizer OperationVisualizer;
  10233. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10234. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  10238. {
  10239. TForm::ChangeScale(M, D);
  10240. int APixelsPerInch = GetControlPixelsPerInch(this);
  10241. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  10242. try
  10243. {
  10244. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  10245. }
  10246. __finally
  10247. {
  10248. GUIConfiguration->ChangeResourceModule(ResourceModule);
  10249. }
  10250. }
  10251. //---------------------------------------------------------------------------
  10252. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10253. {
  10254. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10255. }
  10256. //---------------------------------------------------------------------
  10257. class TPublicControl : public TControl
  10258. {
  10259. friend class TCustomScpExplorerForm;
  10260. };
  10261. //---------------------------------------------------------------------------
  10262. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10263. {
  10264. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10265. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10266. }
  10267. //---------------------------------------------------------------------------
  10268. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10269. {
  10270. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10271. OpenBookmark(Side, Bookmark);
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10275. {
  10276. DoBookmarkClick(osLocal, Sender);
  10277. }
  10278. //---------------------------------------------------------------------------
  10279. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10280. {
  10281. DoBookmarkClick(osRemote, Sender);
  10282. }
  10283. //---------------------------------------------------------------------------
  10284. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10285. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10286. {
  10287. if (BookmarkList != NULL)
  10288. {
  10289. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10290. if (IsLocalBrowserMode())
  10291. {
  10292. Side = osLocal;
  10293. }
  10294. if (!WinConfiguration->UseLocationProfiles)
  10295. {
  10296. std::unique_ptr<TStringList> Directories(new TStringList());
  10297. Directories->CaseSensitive = (Side == osRemote);
  10298. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10299. {
  10300. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10301. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10302. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10303. {
  10304. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10305. Item->Caption = EscapeHotkey(Directory);
  10306. Item->ShortCut = Bookmark->ShortCut;
  10307. Item->OnClick = OnBookmarkClick;
  10308. Item->Tag = reinterpret_cast<int>(Bookmark);
  10309. Directories->Add(Directory);
  10310. Menu->Add(Item.release());
  10311. }
  10312. }
  10313. }
  10314. else
  10315. {
  10316. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10317. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10318. {
  10319. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10320. if (!Bookmark->Node.IsEmpty())
  10321. {
  10322. Folders->Add(Bookmark->Node);
  10323. }
  10324. }
  10325. for (int Index = 0; Index < Folders->Count; Index++)
  10326. {
  10327. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10328. Item->Caption = Folders->Strings[Index];
  10329. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10330. Folders->Objects[Index] = Item.get();
  10331. Menu->Add(Item.release());
  10332. }
  10333. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10334. {
  10335. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10336. TTBCustomItem * Parent;
  10337. if (!Bookmark->Node.IsEmpty())
  10338. {
  10339. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10340. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10341. }
  10342. else
  10343. {
  10344. Parent = Menu;
  10345. }
  10346. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10347. Item->Caption = Bookmark->Name;
  10348. Item->ShortCut = Bookmark->ShortCut;
  10349. Item->OnClick = OnBookmarkClick;
  10350. Item->Tag = reinterpret_cast<int>(Bookmark);
  10351. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10352. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10353. {
  10354. // No hint for location profiles that are actually mere "bookmarks"
  10355. }
  10356. else
  10357. {
  10358. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10359. UnicodeString LongHint;
  10360. if (!Bookmark->Local.IsEmpty())
  10361. {
  10362. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10363. }
  10364. if (!Bookmark->Remote.IsEmpty())
  10365. {
  10366. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10367. }
  10368. AddToList(Hint, LongHint, L"|");
  10369. Item->Hint = Hint;
  10370. }
  10371. Parent->Add(Item.release());
  10372. }
  10373. }
  10374. AddMenuSeparator(Menu);
  10375. }
  10376. }
  10377. //---------------------------------------------------------------------------
  10378. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10379. {
  10380. Menu->Clear();
  10381. std::unique_ptr<TTBCustomItem> Item;
  10382. Item.reset(new TTBXItem(Owner));
  10383. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10384. Item->Options = Item->Options << tboDefault;
  10385. Menu->Add(Item.release());
  10386. AddMenuSeparator(Menu);
  10387. if (Terminal != NULL)
  10388. {
  10389. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10390. }
  10391. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10392. Item.reset(new TTBXItem(Owner));
  10393. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10394. Menu->Add(Item.release());
  10395. }
  10396. //---------------------------------------------------------------------------
  10397. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10398. {
  10399. bool Result = true;
  10400. bool Remote = !IsSideLocalBrowser(Side);
  10401. try
  10402. {
  10403. UnicodeString APath = Path;
  10404. if (Remote)
  10405. {
  10406. Terminal->ExceptionOnFail = true;
  10407. }
  10408. else
  10409. {
  10410. APath = ExpandEnvironmentVariables(Path);
  10411. }
  10412. try
  10413. {
  10414. DirView(Side)->Path = APath;
  10415. }
  10416. __finally
  10417. {
  10418. if (Remote)
  10419. {
  10420. Terminal->ExceptionOnFail = false;
  10421. }
  10422. }
  10423. }
  10424. catch (Exception & E)
  10425. {
  10426. if (!Remote || Terminal->Active)
  10427. {
  10428. ShowExtendedExceptionEx(Terminal, &E);
  10429. Result = false;
  10430. }
  10431. else
  10432. {
  10433. throw;
  10434. }
  10435. }
  10436. return Result;
  10437. }
  10438. //---------------------------------------------------------------------------
  10439. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10440. {
  10441. // Make sure there some feedback even when loading tiny local folders
  10442. TInstantOperationVisualizer Visualizer;
  10443. DirView(Side)->ReloadDirectory();
  10444. }
  10445. //---------------------------------------------------------------------------
  10446. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10447. {
  10448. if (Index == SessionsPageControl->TabIndex)
  10449. {
  10450. CloseTab();
  10451. }
  10452. else
  10453. {
  10454. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10455. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10456. TTerminalManager * Manager = TTerminalManager::Instance();
  10457. if (!Terminal->Active)
  10458. {
  10459. Manager->FreeTerminal(Terminal);
  10460. }
  10461. else
  10462. {
  10463. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10464. if (CanCloseQueue(Queue))
  10465. {
  10466. Manager->FreeTerminal(Terminal);
  10467. }
  10468. }
  10469. }
  10470. }
  10471. //---------------------------------------------------------------------------
  10472. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10473. {
  10474. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10475. if (Session == NULL)
  10476. {
  10477. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10478. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10479. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10480. //P = SessionsPageControl->ClientToScreen(P);
  10481. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10482. }
  10483. else
  10484. {
  10485. CloseSessionTab(Index);
  10486. }
  10487. }
  10488. //---------------------------------------------------------------------------
  10489. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10490. {
  10491. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10492. {
  10493. TInstantOperationVisualizer Visualizer;
  10494. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10495. // before we create a new data object
  10496. ClipboardClear();
  10497. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10498. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10499. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10500. // Intermediate variable to WORKAROUND a crash in compiler
  10501. TObjectList * ClipboardFakeMonitors =
  10502. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10503. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10504. if (FClipboardDragDropFilesEx.get() == NULL)
  10505. {
  10506. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10507. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10508. }
  10509. FClipboardDragDropFilesEx->FileList->Clear();
  10510. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10511. FClipboardDragDropFilesEx->CopyToClipboard();
  10512. FClipboardTerminal = Terminal;
  10513. // Need full paths, as cwd can be different once files are pasted
  10514. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10515. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10516. {
  10517. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10518. }
  10519. }
  10520. }
  10521. //---------------------------------------------------------------------------
  10522. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10523. {
  10524. if (OpenClipboard(0))
  10525. {
  10526. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10527. CloseClipboard();
  10528. }
  10529. }
  10530. //---------------------------------------------------------------------------
  10531. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10532. {
  10533. return !FClipboardFakeDirectory.IsEmpty();
  10534. }
  10535. //---------------------------------------------------------------------------
  10536. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10537. {
  10538. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10539. FClipboardFakeDirectory = UnicodeString();
  10540. FClipboardTerminal = NULL;
  10541. if (FDownloadingFromClipboard)
  10542. {
  10543. // We are called by the monitor, so attempt to release it would deadlock
  10544. FClipboardFakeMonitorsPendingReset = true;
  10545. }
  10546. else
  10547. {
  10548. FClipboardFakeMonitors.reset(NULL);
  10549. }
  10550. }
  10551. //---------------------------------------------------------------------------
  10552. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10553. {
  10554. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10555. {
  10556. ClipboardStop();
  10557. }
  10558. }
  10559. //---------------------------------------------------------------------------
  10560. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10561. {
  10562. TTerminalManager * Manager = TTerminalManager::Instance();
  10563. Manager->ActiveSession = FClipboardTerminal;
  10564. TTransferOperationParam Params;
  10565. Params.TargetDirectory = TargetDirectory;
  10566. Params.DragDrop = DragDrop;
  10567. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10568. }
  10569. //---------------------------------------------------------------------------
  10570. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10571. {
  10572. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10573. // (as it pumps a Windows message queue while being shutted down)
  10574. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10575. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10576. {
  10577. // Can fail as it can be e.g. locked by AV, so we retry that later
  10578. bool Removed = RemoveDir(ApiPath(FileName));
  10579. try
  10580. {
  10581. if (!NonVisualDataModule->Busy)
  10582. {
  10583. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10584. FClipboardFakeMonitorsPendingReset = false;
  10585. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10586. TAutoFlag Flag(FDownloadingFromClipboard);
  10587. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10588. }
  10589. }
  10590. __finally
  10591. {
  10592. if (!Removed)
  10593. {
  10594. RemoveDir(ApiPath(FileName));
  10595. }
  10596. }
  10597. }
  10598. }
  10599. //---------------------------------------------------------------------------
  10600. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10601. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10602. {
  10603. TFileMasks::TParams MaskParams;
  10604. MaskParams.Size = Size;
  10605. MaskParams.Modification = Modification;
  10606. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10607. bool Local = (dynamic_cast<TUnixDirView *>(DirView) == NULL);
  10608. // TUnixDirView::ItemFullFileName returns trailing backslash for directories, what filemask cannot deal with
  10609. if (!Local && Directory)
  10610. {
  10611. FileName = UnixExcludeTrailingBackslash(FileName);
  10612. }
  10613. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10614. {
  10615. bool ImplicitMatch;
  10616. if (Iter->FileMask.Matches(FileName, Local, Directory, &MaskParams, false, ImplicitMatch) &&
  10617. !ImplicitMatch)
  10618. {
  10619. Color = Iter->Color;
  10620. break;
  10621. }
  10622. }
  10623. }
  10624. //---------------------------------------------------------------------------
  10625. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10626. {
  10627. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10628. if (!DirView->IsEditing())
  10629. {
  10630. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10631. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10632. // while searching
  10633. if (Key == VK_BACK)
  10634. {
  10635. if (!FIncrementalSearch.IsEmpty())
  10636. {
  10637. if (FIncrementalSearch.Length() == 1)
  10638. {
  10639. ResetIncrementalSearch();
  10640. }
  10641. else
  10642. {
  10643. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10644. IncrementalSearch(NewText, false, false);
  10645. }
  10646. Key = 0;
  10647. }
  10648. }
  10649. }
  10650. }
  10651. //---------------------------------------------------------------------------
  10652. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10653. {
  10654. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10655. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10656. {
  10657. // Filter control sequences.
  10658. // When not searching yet, prefer use of the space for toggling file selection
  10659. // (so we cannot incrementally search for a string starting with a space).
  10660. if ((Key > VK_SPACE) ||
  10661. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10662. {
  10663. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10664. Key = 0;
  10665. }
  10666. }
  10667. }
  10668. //---------------------------------------------------------------------------
  10669. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10670. {
  10671. if (!FIncrementalSearch.IsEmpty())
  10672. {
  10673. FIncrementalSearch = L"";
  10674. DirView(osCurrent)->UpdateStatusBar();
  10675. }
  10676. }
  10677. //---------------------------------------------------------------------------
  10678. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10679. {
  10680. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10681. if (Item == NULL)
  10682. {
  10683. MessageBeep(MB_ICONHAND);
  10684. }
  10685. else
  10686. {
  10687. TCustomDirView * ADirView = DirView(osCurrent);
  10688. {
  10689. TAutoNestingCounter Guard(FIncrementalSearching);
  10690. ADirView->FocusItem(Item);
  10691. if (ADirView->NortonLike == nlOff)
  10692. {
  10693. if ((ADirView->Selected != Item) ||
  10694. (ADirView->SelCount > 1))
  10695. {
  10696. ADirView->ClearSelection();
  10697. ADirView->Selected = Item;
  10698. }
  10699. }
  10700. }
  10701. FIncrementalSearch = Text;
  10702. Item->MakeVisible(false);
  10703. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10704. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10705. ADirView->UpdateStatusBar();
  10706. }
  10707. }
  10708. //---------------------------------------------------------------------------
  10709. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10710. {
  10711. int Index = Item->Index;
  10712. if (!Reverse)
  10713. {
  10714. Index++;
  10715. if (Index >= Item->Owner->Count)
  10716. {
  10717. Index = 0;
  10718. }
  10719. }
  10720. else
  10721. {
  10722. Index--;
  10723. if (Index < 0)
  10724. {
  10725. Index = Item->Owner->Count - 1;
  10726. }
  10727. }
  10728. return Item->Owner->Item[Index];
  10729. }
  10730. //---------------------------------------------------------------------------
  10731. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10732. {
  10733. TCustomDirView * ADirView = DirView(osCurrent);
  10734. if (ADirView->Items->Count == 0)
  10735. {
  10736. return NULL;
  10737. }
  10738. else
  10739. {
  10740. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10741. TListItem * Item = CurrentItem;
  10742. if (SkipCurrent)
  10743. {
  10744. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10745. }
  10746. while (true)
  10747. {
  10748. bool Matches = false;
  10749. switch (WinConfiguration->PanelSearch)
  10750. {
  10751. case isNameStartOnly:
  10752. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item).SubString(1, Text.Length()), Text);
  10753. break;
  10754. case isName:
  10755. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item), Text);
  10756. break;
  10757. case isAll:
  10758. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10759. int Index = 0;
  10760. while ((Index < ColCount) && !Matches)
  10761. {
  10762. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10763. if (Visible)
  10764. {
  10765. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10766. }
  10767. Index++;
  10768. }
  10769. break;
  10770. }
  10771. if (Matches)
  10772. {
  10773. return Item;
  10774. }
  10775. Item = GetNextFile(Item, Reverse);
  10776. if (Item == CurrentItem)
  10777. {
  10778. return NULL;
  10779. }
  10780. }
  10781. }
  10782. }
  10783. //---------------------------------------------------------------------------
  10784. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10785. {
  10786. ResetIncrementalSearch();
  10787. }
  10788. //---------------------------------------------------------------------------
  10789. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10790. {
  10791. if (Message.CharCode == VK_TAB)
  10792. {
  10793. if (!FIncrementalSearch.IsEmpty())
  10794. {
  10795. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10796. bool Reverse = Shift.Contains(ssShift);
  10797. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10798. Message.Result = 1;
  10799. return;
  10800. }
  10801. }
  10802. else if (Message.CharCode == VK_ESCAPE)
  10803. {
  10804. if (!FIncrementalSearch.IsEmpty())
  10805. {
  10806. ResetIncrementalSearch();
  10807. Message.Result = 1;
  10808. return;
  10809. }
  10810. }
  10811. TForm::Dispatch(&Message);
  10812. }
  10813. //---------------------------------------------------------------------------
  10814. void __fastcall TCustomScpExplorerForm::Deactivate()
  10815. {
  10816. TForm::Deactivate();
  10817. // E.g. when switching to an internal editor window
  10818. ResetIncrementalSearch();
  10819. }
  10820. //---------------------------------------------------------------------------
  10821. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10822. {
  10823. // When switching to another application
  10824. ResetIncrementalSearch();
  10825. }
  10826. //---------------------------------------------------------------------------
  10827. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10828. {
  10829. ResetIncrementalSearch();
  10830. }
  10831. //---------------------------------------------------------------------------
  10832. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10833. {
  10834. if (FIncrementalSearching <= 0)
  10835. {
  10836. ResetIncrementalSearch();
  10837. }
  10838. }
  10839. //---------------------------------------------------------------------------
  10840. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10841. {
  10842. CountClicksForWindowPrint(this);
  10843. }
  10844. //---------------------------------------------------------------------------
  10845. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10846. {
  10847. CenterReconnectToolbar();
  10848. }
  10849. //---------------------------------------------------------------------------
  10850. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10851. {
  10852. if (RemoteDirView->ItemFocused != NULL)
  10853. {
  10854. RemoteDirView->ItemFocused->Selected = true;
  10855. }
  10856. }
  10857. //---------------------------------------------------------------------------
  10858. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10859. {
  10860. if (!FQueueStatusUpdating)
  10861. {
  10862. bool Refresh;
  10863. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10864. {
  10865. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10866. }
  10867. else
  10868. {
  10869. if (FQueueFileList->GetCount() > 0)
  10870. {
  10871. FQueueFileList->Clear();
  10872. Refresh = true;
  10873. }
  10874. }
  10875. int Count = FQueueFileList->GetCount();
  10876. if (QueueFileList->Items->Count != Count)
  10877. {
  10878. DebugAssert(Refresh);
  10879. QueueFileList->Items->Count = Count;
  10880. }
  10881. if (Refresh)
  10882. {
  10883. QueueFileList->Invalidate();
  10884. }
  10885. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10886. }
  10887. }
  10888. //---------------------------------------------------------------------------
  10889. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10890. {
  10891. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10892. }
  10893. //---------------------------------------------------------------------------
  10894. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10895. {
  10896. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10897. // See TSynchronizeChecklistDialog::UpdateTimer
  10898. if (QueueFileList->Items->Count > 0)
  10899. {
  10900. QueueFileList->Items->Item[0]->MakeVisible(false);
  10901. }
  10902. UpdateQueueFileList();
  10903. }
  10904. //---------------------------------------------------------------------------
  10905. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10906. {
  10907. Active = QueueView3->Focused() || QueueFileList->Focused();
  10908. }
  10909. //---------------------------------------------------------------------------
  10910. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10911. {
  10912. QueueLabelUpdateStatus();
  10913. }
  10914. //---------------------------------------------------------------------------
  10915. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10916. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10917. {
  10918. int State = FQueueFileList->GetState(Item->Index);
  10919. if (State == qfsProcessed)
  10920. {
  10921. Sender->Canvas->Font->Color = clGrayText;
  10922. }
  10923. }
  10924. //---------------------------------------------------------------------------
  10925. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10926. {
  10927. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10928. QueueFileList->Column[0]->Width =
  10929. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10930. }
  10931. //---------------------------------------------------------------------------
  10932. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10933. {
  10934. QueueFileListColumnAutoSize();
  10935. }
  10936. //---------------------------------------------------------------------------
  10937. void __fastcall TCustomScpExplorerForm::CloseApp()
  10938. {
  10939. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10940. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10941. // So we clear the flag here.
  10942. DebugAssert(NonVisualDataModule->Busy);
  10943. NonVisualDataModule->EndBusy();
  10944. try
  10945. {
  10946. Close();
  10947. }
  10948. __finally
  10949. {
  10950. NonVisualDataModule->StartBusy();
  10951. }
  10952. }
  10953. //---------------------------------------------------------------------------
  10954. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10955. {
  10956. return (Terminal != NULL) && Terminal->Active;
  10957. }
  10958. //---------------------------------------------------------------------------
  10959. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10960. {
  10961. return (ManagedSession != NULL);
  10962. }
  10963. //---------------------------------------------------------------------------
  10964. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10965. {
  10966. return IsActiveTerminal(Terminal);
  10967. }
  10968. //---------------------------------------------------------------------------
  10969. void TCustomScpExplorerForm::LocalLocalCopy(
  10970. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10971. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10972. {
  10973. DebugFail();
  10974. }
  10975. //---------------------------------------------------------------------------
  10976. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10977. {
  10978. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10979. }
  10980. //---------------------------------------------------------------------------
  10981. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  10982. {
  10983. // 1) Changing tab list triggers the OnResize.
  10984. // 2) Is called in TForm constructor, when we are not ready to call SessionListChanged (particularly when starting with colored session)
  10985. if (!FUpdatingSessionTabs && (FSessionColors != NULL))
  10986. {
  10987. // UpdateTabsCaptionTruncation should be enough
  10988. SessionListChanged(true);
  10989. }
  10990. }
  10991. //---------------------------------------------------------------------------
  10992. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  10993. {
  10994. if (ASession == ManagedSession)
  10995. {
  10996. UpdateSession(ASession);
  10997. }
  10998. TSessionData * Data = ASession->StateData;
  10999. UnicodeString Result;
  11000. if (Side == osLocal)
  11001. {
  11002. Result = Data->LocalDirectory;
  11003. }
  11004. else if (DebugAlwaysTrue(Side == osOther))
  11005. {
  11006. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  11007. }
  11008. return Result;
  11009. }
  11010. //---------------------------------------------------------------------------
  11011. UnicodeString TCustomScpExplorerForm::GetTabHintSessionDetails(TManagedTerminal * ASession)
  11012. {
  11013. UnicodeString Title = TTerminalManager::Instance()->GetSessionTitle(ASession, false);
  11014. UnicodeString Result = ASession->SessionData->DefaultSessionName;
  11015. if (Title == Result)
  11016. {
  11017. Result = EmptyStr;
  11018. }
  11019. else
  11020. {
  11021. Result += L"\n";
  11022. }
  11023. return Result;
  11024. }
  11025. //---------------------------------------------------------------------------
  11026. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  11027. {
  11028. UnicodeString Result = GetTabHintSessionDetails(ASession);
  11029. if (!ASession->Active)
  11030. {
  11031. Result += LoadStr(STATUS_NOT_CONNECTED2);
  11032. }
  11033. else
  11034. {
  11035. Result += GetSessionPath(ASession, osRemote);
  11036. }
  11037. return Result;
  11038. }
  11039. //---------------------------------------------------------------------------
  11040. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  11041. {
  11042. return LoadStr(NEW_REMOTE_TAB_HINT);
  11043. }
  11044. //---------------------------------------------------------------------------
  11045. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  11046. {
  11047. if (Index >= 0)
  11048. {
  11049. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  11050. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  11051. if (TabSession == NULL)
  11052. {
  11053. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  11054. if (NewTabTabCaption != TabSheet->Caption)
  11055. {
  11056. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  11057. }
  11058. }
  11059. else
  11060. {
  11061. TTerminalManager * Manager = TTerminalManager::Instance();
  11062. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  11063. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  11064. }
  11065. }
  11066. }
  11067. //---------------------------------------------------------------------------
  11068. typedef std::vector<TListItem *> TListItemsVector;
  11069. struct TCalculateSizeOperation
  11070. {
  11071. TCalculateSizeStats Stats;
  11072. TListItemsVector ListItems;
  11073. size_t Index;
  11074. };
  11075. //---------------------------------------------------------------------------
  11076. void TCustomScpExplorerForm::CalculateDirectorySizes(TOperationSide Side)
  11077. {
  11078. TCalculateSizeOperation CalculateSizeOperation;
  11079. Side = GetSide(Side);
  11080. TCustomDirView * ADirView = DirView(Side);
  11081. bool LocalSide = IsSideLocalBrowser(Side);
  11082. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, LocalSide, NULL, true));
  11083. std::unique_ptr<TStrings> FileList(new TStringList());
  11084. for (int Index = 0; Index < AllFileList->Count; Index++)
  11085. {
  11086. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  11087. if (ADirView->ItemIsDirectory(Item))
  11088. {
  11089. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  11090. CalculateSizeOperation.ListItems.push_back(Item);
  11091. }
  11092. }
  11093. CalculateSizeOperation.Index = 0;
  11094. __int64 Size = 0;
  11095. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation);
  11096. FCalculateSizeOperation = &CalculateSizeOperation;
  11097. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  11098. FOnFileOperationFinished = DirectorySizeCalculated;
  11099. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation);
  11100. FPrimaryOperation = foCalculateSize;
  11101. TCalculatedSizes CalculatedSizes;
  11102. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  11103. if (LocalSide)
  11104. {
  11105. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  11106. FProgressSide = Side;
  11107. ManagedSession->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  11108. }
  11109. else
  11110. {
  11111. TCalculateSizeParams Params;
  11112. Params.Stats = &CalculateSizeOperation.Stats;
  11113. Params.UseCache = true;
  11114. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  11115. }
  11116. }
  11117. //---------------------------------------------------------------------------
  11118. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(TOperationSide Side, const UnicodeString & FileName, bool Success)
  11119. {
  11120. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  11121. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  11122. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  11123. // optimization
  11124. bool GotExpectedItem =
  11125. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  11126. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  11127. int Index = -1;
  11128. if (DebugAlwaysTrue(GotExpectedItem))
  11129. {
  11130. Index = FCalculateSizeOperation->Index;
  11131. FCalculateSizeOperation->Index++;
  11132. }
  11133. else
  11134. {
  11135. TListItemsVector::iterator I =
  11136. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  11137. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  11138. {
  11139. Index = I - FCalculateSizeOperation->ListItems.begin();
  11140. }
  11141. }
  11142. if (DebugAlwaysTrue(Index >= 0) && Success)
  11143. {
  11144. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  11145. ADirView->SetItemCalculatedSize(Item, Size);
  11146. }
  11147. }
  11148. //---------------------------------------------------------------------------
  11149. void __fastcall TCustomScpExplorerForm::MessageDockRequestDock(TObject *, TTBCustomDockableWindow *, bool & Accept)
  11150. {
  11151. Accept = false;
  11152. }
  11153. //---------------------------------------------------------------------------